Skip to content

Commit 7c65b3c

Browse files
committed
[math] Properly treat the xyexpo,xygausn,xylandaun 2D functions
and add a unit test. Fixes #20733
1 parent 154968d commit 7c65b3c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

hist/hist/src/TFormula.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,15 +1205,17 @@ void TFormula::HandleParametrizedFunctions(TString &formula)
12051205

12061206
// replace old names xygaus -> gaus[x,y]
12071207
formula.ReplaceAll("xyzgaus","gaus[x,y,z]");
1208+
formula.ReplaceAll("xygausn","gausn[x,y]");
12081209
formula.ReplaceAll("xygaus","gaus[x,y]");
12091210
formula.ReplaceAll("xgaus","gaus[x]");
12101211
formula.ReplaceAll("ygaus","gaus[y]");
12111212
formula.ReplaceAll("zgaus","gaus[z]");
1213+
formula.ReplaceAll("xyexpo","expo[x,y]");
12121214
formula.ReplaceAll("xexpo","expo[x]");
12131215
formula.ReplaceAll("yexpo","expo[y]");
12141216
formula.ReplaceAll("zexpo","expo[z]");
1217+
formula.ReplaceAll("xylandaun","landaun[x,y]");
12151218
formula.ReplaceAll("xylandau","landau[x,y]");
1216-
formula.ReplaceAll("xyexpo","expo[x,y]");
12171219
// at the moment pre-defined functions have no more than 3 dimensions
12181220
const char * defaultVariableNames[] = { "x","y","z"};
12191221

@@ -2543,8 +2545,10 @@ void TFormula::FillParametrizedFunctions(map<pair<TString, Int_t>, pair<TString,
25432545
make_pair(make_pair("gaus", 2), make_pair("[0]*exp(-0.5*(({V0}-[1])/[2])^2 - 0.5*(({V1}-[3])/[4])^2)", "")));
25442546
functions.insert(
25452547
make_pair(make_pair("landau", 2),
2546-
make_pair("[0]*TMath::Landau({V0},[1],[2],false)*TMath::Landau({V1},[3],[4],false)", "")));
2547-
functions.insert(make_pair(make_pair("expo", 2), make_pair("exp([0]+[1]*{V0})", "exp([0]+[1]*{V0}+[2]*{V1})")));
2548+
make_pair("[0]*TMath::Landau({V0},[1],[2],false)*TMath::Landau({V1},[3],[4],false)", "TMath::Landau({V0},[0],[1],true)*TMath::Landau({V1},[2],[3],true)")));
2549+
functions.insert(
2550+
make_pair(make_pair("expo", 2),
2551+
make_pair("exp([0]+[1]*{V0}+[2]*{V1})", "")));
25482552
// 3-dimensional function
25492553
functions.insert(
25502554
make_pair(make_pair("gaus", 3), make_pair("[0]*exp(-0.5*(({V0}-[1])/[2])^2 - 0.5*(({V1}-[3])/[4])^2 - 0.5*(({V2}-[5])/[6])^2)", "")));

hist/hist/test/test_TFormula.cxx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ TEST(TFormula, Interp)
1313
TFormula f("func", "TGeoBBox::DeclFileLine()");
1414
}
1515

16+
TEST(TFormula, 2dFunctions)
17+
{
18+
TFormula xyexpo("f2xyexpo", "xyexpo");
19+
EXPECT_EQ(xyexpo.GetExpFormula(), TString("exp([p0]+[p1]*x+[p2]*y)"));
20+
TFormula xylandau("f2xylandau", "xylandau");
21+
EXPECT_EQ(xylandau.GetExpFormula(), TString("[p0]*TMath::Landau(x,[p1],[p2],false)*TMath::Landau(y,[p3],[p4],false)"));
22+
TFormula xylandaun("f2xylandaun", "xylandaun");
23+
EXPECT_EQ(xylandaun.GetExpFormula(), TString("TMath::Landau(x,[p0],[p1],true)*TMath::Landau(y,[p2],[p3],true)"));
24+
}
25+
1626
// Test for TFormula Extended syntax support
1727
TEST(TFormulaPolTest, BasicPolynomialConstruction)
1828
{

0 commit comments

Comments
 (0)