Skip to content

Commit 7786787

Browse files
Ban42guitargeek
authored andcommitted
[RF] Update testRooFormula to mirror arguments substitution rules changes
1 parent 24bc34e commit 7786787

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

roofit/roofitcore/test/testRooFormula.cxx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// Tests for the RooFormula
22
// Authors: Stephan Hageboeck, CERN 2020
33
// Jonas Rembser, CERN 2023
4+
// Andrea Germinario, CERN 2025
45

56
#include "../src/RooFormula.h"
67
#include <RooFormulaVar.h>
78
#include <RooRealVar.h>
9+
#include <RooConstVar.h>
810

911
#include <ROOT/TestSupport.hxx>
1012

@@ -56,7 +58,7 @@ TEST(RooFormula, TestDangerousVariableNames)
5658
{
5759
RooRealVar dt("dt", "dt", -10, 10);
5860
RooRealVar x("x", "x", 1.547);
59-
RooRealVar zero("0", "0", 0);
61+
RooConstVar zero("0", "0", 0);
6062

6163
// Create the formula, triggers an error if the formula doesn't compile
6264
// correctly because the dangerous variable names haven't been treated right.
@@ -89,3 +91,21 @@ TEST(RooFormula, UndefinedVariables)
8991
ASSERT_ANY_THROW(RooFormulaVar f2("f2", "r + B + y", {r, B})) << "Formulae with missing (x,)y in arg list cannot work.";
9092
ASSERT_NO_THROW(RooFormulaVar f2("f2", "r + B + y", {r, B, y})) << "Formula with specified y must work.";
9193
}
94+
95+
TEST(RooFormula, RooConstVarSafeSubstitution)
96+
{
97+
// Check RooConst are substituted only by index
98+
ASSERT_NO_THROW(RooFormulaVar f("f", "2.7*@0", RooFit::RooConst(2.)))
99+
<< "Formulae with RooConstVar argument should be substituted only by index.";
100+
101+
// Check that constant values to be used in RooFormulaVar have to be RooConstVar
102+
RooRealVar x("x", "x", 1.547);
103+
RooRealVar zero("0", "0", 0); // Constant values should be RooConstVar
104+
ASSERT_ANY_THROW(RooFormulaVar f1("f1", "x + 0", {x, zero}))
105+
<< "Const arguments in a RooFormula should be of type RooConstVar";
106+
107+
// Check that RooConstVar having a value as name has value==(double)name
108+
RooConstVar troubleConst("3.4", "troubleConst", 2.1);
109+
ASSERT_ANY_THROW(RooFormulaVar f1("f1", "x + 0", {x, zero}))
110+
<< "RooConst variables, if having numeric name, should have name value equal to actual value.";
111+
}

0 commit comments

Comments
 (0)