Skip to content

Commit b365a5e

Browse files
committed
[math] allow TH2::FillRandom xygaus
Fixes #20719
1 parent fd2caca commit b365a5e

File tree

10 files changed

+55
-5
lines changed

10 files changed

+55
-5
lines changed

core/base/src/TROOT.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ TObject *TROOT::GetFunction(const char *name) const
16071607
// and restart after this thread has finished the initialization (i.e. a rare case),
16081608
// the only penalty we pay is a spurious 2nd lookup for an unknown function.
16091609
[[maybe_unused]] static const auto _res = []() {
1610-
gROOT->ProcessLine("TF1::InitStandardFunctions();");
1610+
gROOT->ProcessLine("TF1::InitStandardFunctions(); TF2::InitStandardFunctions(); TF3::InitStandardFunctions();");
16111611
isInited = true;
16121612
return true;
16131613
}();

gui/fitpanel/src/CommonDefs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ enum EFitPanel {
1111
kFP_CHEB0, kFP_CHEB1, kFP_CHEB2, kFP_CHEB3, kFP_CHEB4, kFP_CHEB5,
1212
kFP_CHEB6, kFP_CHEB7, kFP_CHEB8, kFP_CHEB9,
1313
kFP_XYGAUS, kFP_BIGAUS, kFP_XYEXP, kFP_XYLAN, kFP_XYLANN,
14-
// Above here -> All editable formulaes!
14+
kFP_XYZGAUS,
15+
// Above here -> All editable formulaes!
1516
kFP_USER,
1617
kFP_NONE, kFP_ADD, kFP_NORMADD, kFP_CONV, kFP_FILE, kFP_PARS, kFP_RBUST, kFP_EMPW1,
1718
kFP_INTEG, kFP_IMERR, kFP_USERG, kFP_ADDLS, kFP_ALLW1, kFP_IFITR, kFP_NOCHI,

gui/fitpanel/src/TFitEditor.cxx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,11 +1664,21 @@ void TFitEditor::FillFunctionList(Int_t)
16641664

16651665
// Select Gaus2D by default
16661666
fFuncList->Select(kFP_XYGAUS);
1667+
} else if (fTypeFit->GetSelected() == kFP_PRED3D && fDim == 3) {
1668+
fFuncList->AddEntry("xyzgaus", kFP_XYZGAUS);
1669+
1670+
// Need to be setted this way, otherwise when the functions
1671+
// are removed, the list doesn't show them.x
1672+
TGListBox *lb = fFuncList->GetListBox();
1673+
lb->Resize(lb->GetWidth(), 200);
1674+
1675+
// Select Gaus3D by default
1676+
fFuncList->Select(kFP_XYZGAUS);
16671677
}
16681678
// Case for user defined functions. References to these functions
16691679
// are kept by the fitpanel, so the information is gathered from
16701680
// there.
1671-
else if ( fTypeFit->GetSelected() == kFP_UFUNC ) {
1681+
else if (fTypeFit->GetSelected() == kFP_UFUNC) {
16721682
Int_t newid = kFP_ALTFUNC;
16731683

16741684
// Add system functions
@@ -1701,7 +1711,7 @@ void TFitEditor::FillFunctionList(Int_t)
17011711
}
17021712
}
17031713
// Case for previously used functions.
1704-
else if ( fTypeFit->GetSelected() == kFP_PREVFIT ) {
1714+
else if (fTypeFit->GetSelected() == kFP_PREVFIT) {
17051715
Int_t newid = kFP_ALTFUNC;
17061716

17071717
// Look only for those functions used in the selected object

gui/fitpanelv7/src/RFitPanel.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ void RFitPanel::UpdateFunctionsList()
284284
{"cheb0"}, {"cheb1"}, {"cheb2"}, {"cheb3"}, {"cheb4"}, {"cheb5"}, {"cheb6"}, {"cheb7"}, {"cheb8"}, {"cheb9"} };
285285
} else if (m.fDim == 2) {
286286
m.fFuncList = { {"xygaus"}, {"bigaus"}, {"xyexpo"}, {"xylandau"}, {"xylandaun"} };
287+
} else if (m.fDim == 3) {
288+
m.fFuncList = {{"xyzgaus"}};
287289
}
288290

289291
for (auto &func : fSystemFuncs) {

hist/hist/inc/TF2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class TF2 : public TF1 {
111111
virtual Double_t GetMaximum(Double_t *x ) const;
112112
virtual Double_t GetYmin() const {return fYmin;}
113113
virtual Double_t GetYmax() const {return fYmax;}
114+
static void InitStandardFunctions();
114115
using TF1::Integral;
115116
virtual Double_t Integral(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsrel=1.e-6);
116117
Bool_t IsInside(const Double_t *x) const override;

hist/hist/inc/TF3.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class TF3 : public TF2 {
9797
Double_t GetSave(const Double_t *x) override;
9898
virtual Double_t GetZmin() const {return fZmin;}
9999
virtual Double_t GetZmax() const {return fZmax;}
100+
static void InitStandardFunctions();
100101
using TF2::Integral;
101102
virtual Double_t Integral(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t az, Double_t bz, Double_t epsrel=1.e-6);
102103
Bool_t IsInside(const Double_t *x) const override;

hist/hist/src/TF1.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,6 +2550,7 @@ void TF1::InitStandardFunctions()
25502550

25512551
}
25522552
}
2553+
25532554
////////////////////////////////////////////////////////////////////////////////
25542555
/// IntegralOneDim or analytical integral
25552556

hist/hist/src/TF2.cxx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,27 @@ Double_t TF2::GetSave(const Double_t *xx)
663663
return z;
664664
}
665665

666+
////////////////////////////////////////////////////////////////////////////////
667+
/// Create the basic function objects
668+
669+
void TF2::InitStandardFunctions()
670+
{
671+
TF2 *f2;
672+
R__LOCKGUARD(gROOTMutex);
673+
if (!gROOT->GetListOfFunctions()->FindObject("xygaus")) {
674+
f2 = new TF2("xygaus", "xygaus", -1, 1, -1, 1);
675+
f2->SetParameters(1, 0, 1, 0, 1);
676+
f2 = new TF2("bigaus", "bigaus", -1, 1, -1, 1);
677+
f2->SetParameters(1, 0, 1, 0, 1, 0);
678+
f2 = new TF2("xyexpo", "xyexpo", -1, 1, -1, 1);
679+
f2->SetParameters(1, 0, 1, 1, 0, 1);
680+
f2 = new TF2("xylandau", "xylandau", -1, 1, -1, 1);
681+
f2->SetParameters(1, 0, 1, 1, 0, 1);
682+
f2 = new TF2("xylandaun", "xylandaun", -1, 1, -1, 1);
683+
f2->SetParameters(1, 0, 1, 1, 0, 1);
684+
}
685+
}
686+
666687
////////////////////////////////////////////////////////////////////////////////
667688
/// Return Integral of a 2d function in range [ax,bx],[ay,by]
668689
/// with desired relative accuracy (defined by eps)

hist/hist/src/TF3.cxx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,19 @@ Double_t TF3::GetSave(const Double_t *xx)
479479
return r;
480480
}
481481

482+
////////////////////////////////////////////////////////////////////////////////
483+
/// Create the basic function objects
484+
485+
void TF3::InitStandardFunctions()
486+
{
487+
TF3 *f3;
488+
R__LOCKGUARD(gROOTMutex);
489+
if (!gROOT->GetListOfFunctions()->FindObject("xyzgaus")) {
490+
f3 = new TF3("xyzgaus", "xyzgaus", -1, 1, -1, 1, -1, 1);
491+
f3->SetParameters(1, 0, 1, 0, 1, 0, 1);
492+
}
493+
}
494+
482495
////////////////////////////////////////////////////////////////////////////////
483496
/// Return Integral of a 3d function in range [ax,bx],[ay,by],[az,bz]
484497
/// with a desired relative accuracy.

hist/hist/src/TFormula.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,7 @@ void TFormula::FillParametrizedFunctions(map<pair<TString, Int_t>, pair<TString,
25482548
// 3-dimensional function
25492549
functions.insert(
25502550
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)", "")));
2551-
// gaussian with correlations
2551+
// 2-d gaussian with correlations
25522552
functions.insert(
25532553
make_pair(make_pair("bigaus", 2), make_pair("[0]*ROOT::Math::bigaussian_pdf({V0},{V1},[2],[4],[5],[1],[3])",
25542554
"[0]*ROOT::Math::bigaussian_pdf({V0},{V1},[2],[4],[5],[1],[3])")));

0 commit comments

Comments
 (0)