|
1 | 1 | // Tests for the RooFormula
|
2 | 2 | // Authors: Stephan Hageboeck, CERN 2020
|
3 | 3 | // Jonas Rembser, CERN 2023
|
| 4 | +// Andrea Germinario, CERN 2025 |
4 | 5 |
|
5 | 6 | #include "../src/RooFormula.h"
|
6 | 7 | #include <RooFormulaVar.h>
|
7 | 8 | #include <RooRealVar.h>
|
| 9 | +#include <RooConstVar.h> |
8 | 10 |
|
9 | 11 | #include <ROOT/TestSupport.hxx>
|
10 | 12 |
|
@@ -56,7 +58,7 @@ TEST(RooFormula, TestDangerousVariableNames)
|
56 | 58 | {
|
57 | 59 | RooRealVar dt("dt", "dt", -10, 10);
|
58 | 60 | RooRealVar x("x", "x", 1.547);
|
59 |
| - RooRealVar zero("0", "0", 0); |
| 61 | + RooConstVar zero("0", "0", 0); |
60 | 62 |
|
61 | 63 | // Create the formula, triggers an error if the formula doesn't compile
|
62 | 64 | // correctly because the dangerous variable names haven't been treated right.
|
@@ -89,3 +91,21 @@ TEST(RooFormula, UndefinedVariables)
|
89 | 91 | ASSERT_ANY_THROW(RooFormulaVar f2("f2", "r + B + y", {r, B})) << "Formulae with missing (x,)y in arg list cannot work.";
|
90 | 92 | ASSERT_NO_THROW(RooFormulaVar f2("f2", "r + B + y", {r, B, y})) << "Formula with specified y must work.";
|
91 | 93 | }
|
| 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