Skip to content

Commit c42bcea

Browse files
[math] Add missing overloads for addToGlobList
* [math] missing overloads for addToGlobList noticed by makortel in root-project#19645 (comment) TFN's (name,formula, ...) constructors should have an overload similar to these of TF1: TF1(const char *name, const char *formula, Double_t xmin = 0, Double_t xmax = 1, EAddToList addToGlobList = EAddToList::kDefault, bool vectorize = false); TF1(const char *name, const char *formula, Double_t xmin, Double_t xmax, Option_t * option); // same as above but using a string for option These were missed when adding the different overloads on TF2 and TF3 * [nfc] fix docu typos * [nfc] add comment on purposely swapped max min as suggested by hageboeck * [hist] Apply clang-format --------- Co-authored-by: Stephan Hageboeck <stephan.hageboeck@cern.ch>
1 parent 17dde31 commit c42bcea

File tree

5 files changed

+82
-19
lines changed

5 files changed

+82
-19
lines changed

hist/hist/inc/TF2.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ class TF2 : public TF1 {
3636

3737
public:
3838
TF2();
39-
TF2(const char *name, const char *formula, Double_t xmin=0, Double_t xmax=1, Double_t ymin=0, Double_t ymax=1, Option_t * opt = nullptr);
39+
TF2(const char *name, const char *formula, Double_t xmin = 0, Double_t xmax = 1, Double_t ymin = 0,
40+
Double_t ymax = 1, EAddToList addToGlobList = EAddToList::kDefault, bool vectorize = false);
41+
TF2(const char *name, const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax,
42+
Option_t *opt); // same as above but using a string for option
4043
TF2(const char *name, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar, Int_t ndim = 2, EAddToList addToGlobList = EAddToList::kDefault);
4144
TF2(const char *name, Double_t (*fcn)(Double_t *, Double_t *), Double_t xmin=0, Double_t xmax=1, Double_t ymin=0, Double_t ymax=1, Int_t npar=0,Int_t ndim = 2, EAddToList addToGlobList = EAddToList::kDefault);
4245
TF2(const char *name, Double_t (*fcn)(const Double_t *, const Double_t *), Double_t xmin=0, Double_t xmax=1, Double_t ymin=0, Double_t ymax=1, Int_t npar=0, Int_t ndim = 2, EAddToList addToGlobList = EAddToList::kDefault);

hist/hist/inc/TF3.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ class TF3 : public TF2 {
3535
Double_t fClipBox[3]; ///<! Coordinates of clipbox
3636
public:
3737
TF3();
38-
TF3(const char *name, const char *formula, Double_t xmin=0, Double_t xmax=1, Double_t ymin=0,
39-
Double_t ymax=1, Double_t zmin=0, Double_t zmax=1, Option_t * opt = nullptr);
38+
TF3(const char *name, const char *formula, Double_t xmin = 0, Double_t xmax = 1, Double_t ymin = 0,
39+
Double_t ymax = 1, Double_t zmin = 0, Double_t zmax = 1, EAddToList addToGlobList = EAddToList::kDefault,
40+
bool vectorize = false);
41+
TF3(const char *name, const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin,
42+
Double_t zmax, Option_t *opt); // same as above but using a string for option
4043
TF3(const char *name, Double_t (*fcn)(Double_t *, Double_t *), Double_t xmin=0, Double_t xmax=1, Double_t ymin=0,
4144
Double_t ymax=1, Double_t zmin=0, Double_t zmax=1, Int_t npar=0, Int_t ndim = 3, EAddToList addToGlobList = EAddToList::kDefault);
4245
TF3(const char *name, Double_t (*fcn)(const Double_t *, const Double_t *), Double_t xmin=0, Double_t xmax=1, Double_t ymin=0,

hist/hist/src/TF1.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ TF1::TF1(const char *name, const char *formula, Double_t xmin, Double_t xmax, Op
699699
{}
700700

701701
////////////////////////////////////////////////////////////////////////////////
702-
/// F1 constructor using name of an interpreted function.
702+
/// TF1 constructor using name of an interpreted function.
703703
///
704704
/// Creates a function of type C between xmin and xmax.
705705
/// name is the name of an interpreted C++ function.

hist/hist/src/TF2.cxx

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,18 @@ TF2::TF2(): fYmin(0),fYmax(0),fNpy(100)
8383
{
8484
}
8585

86-
8786
////////////////////////////////////////////////////////////////////////////////
88-
/// F2 constructor using a formula definition
87+
/// TF2 constructor using a formula definition and string option args
8988
///
9089
/// See TFormula constructor for explanation of the formula syntax.
9190
///
9291
/// If formula has the form "fffffff;xxxx;yyyy", it is assumed that
9392
/// the formula string is "fffffff" and "xxxx" and "yyyy" are the
9493
/// titles for the X and Y axis respectively.
9594

96-
TF2::TF2(const char *name, const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Option_t * opt)
97-
:TF1(name, formula, xmax, xmin, opt)
95+
TF2::TF2(const char *name, const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax,
96+
Option_t *opt)
97+
: TF1(name, formula, xmax, xmin, opt) // purposely swapped xmax, xmin to signal that TFormula may be 1D or 2D
9898
{
9999
if (ymin < ymax) {
100100
fYmin = ymin;
@@ -116,9 +116,43 @@ TF2::TF2(const char *name, const char *formula, Double_t xmin, Double_t xmax, Do
116116
}
117117
}
118118

119+
////////////////////////////////////////////////////////////////////////////////
120+
/// TF2 constructor using a formula definition and explicit option args
121+
///
122+
/// See TFormula constructor for explanation of the formula syntax.
123+
///
124+
/// If formula has the form "fffffff;xxxx;yyyy", it is assumed that
125+
/// the formula string is "fffffff" and "xxxx" and "yyyy" are the
126+
/// titles for the X and Y axis respectively.
127+
128+
TF2::TF2(const char *name, const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax,
129+
EAddToList addToGlobList, bool vectorize)
130+
: TF1(name, formula, xmax, xmin, addToGlobList,
131+
vectorize) // purposely swapped xmax, xmin to signal that TFormula may be 1D or 2D
132+
{
133+
if (ymin < ymax) {
134+
fYmin = ymin;
135+
fYmax = ymax;
136+
} else {
137+
fYmin = ymax;
138+
fYmax = ymin;
139+
}
140+
fNpx = 30;
141+
fNpy = 30;
142+
fContour.Set(0);
143+
// accept 1-d formula
144+
if (GetNdim() < 2)
145+
fNdim = 2;
146+
// dimension is obtained by TFormula
147+
// accept cases where formula dim is less than 2
148+
if (GetNdim() > 2 && xmin < xmax && ymin < ymax) {
149+
Error("TF2", "function: %s/%s has dimension %d instead of 2", name, formula, GetNdim());
150+
MakeZombie();
151+
}
152+
}
119153

120154
////////////////////////////////////////////////////////////////////////////////
121-
/// F2 constructor using a pointer to a compiled function
155+
/// TF2 constructor using a pointer to a compiled function
122156
///
123157
/// npar is the number of free parameters used by the function
124158
///
@@ -147,9 +181,8 @@ TF2::TF2(const char *name, Double_t xmin, Double_t xmax, Double_t ymin, Double_t
147181
fContour.Set(0);
148182
}
149183

150-
151184
////////////////////////////////////////////////////////////////////////////////
152-
/// F2 constructor using a pointer to a compiled function
185+
/// TF2 constructor using a pointer to a compiled function
153186
///
154187
/// npar is the number of free parameters used by the function
155188
///
@@ -170,7 +203,7 @@ TF2::TF2(const char *name, Double_t (*fcn)(const Double_t *, const Double_t *),
170203
}
171204

172205
////////////////////////////////////////////////////////////////////////////////
173-
/// F2 constructor using a ParamFunctor,
206+
/// TF2 constructor using a ParamFunctor,
174207
/// a functor class implementing operator() (double *, double *)
175208
///
176209
/// npar is the number of free parameters used by the function

hist/hist/src/TF3.cxx

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ TF3::TF3()
5959
fZmax = 1;
6060
}
6161

62-
6362
////////////////////////////////////////////////////////////////////////////////
64-
/// F3 constructor using a formula definition
63+
/// TF3 constructor using a formula definition and string option args
6564
///
6665
/// See TFormula constructor for explanation of the formula syntax.
6766

68-
TF3::TF3(const char *name,const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax, Option_t * opt)
69-
:TF2(name,formula,xmin,xmax,ymax,ymin,opt)
67+
TF3::TF3(const char *name, const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax,
68+
Double_t zmin, Double_t zmax, Option_t *opt)
69+
: TF2(name, formula, xmin, xmax, ymax, ymin,
70+
opt) // purposely swapped ymax, ymin to signal that TFormula may be 1D or 2D or 3D
7071
{
7172
fZmin = zmin;
7273
fZmax = zmax;
@@ -81,7 +82,30 @@ TF3::TF3(const char *name,const char *formula, Double_t xmin, Double_t xmax, Dou
8182
}
8283

8384
////////////////////////////////////////////////////////////////////////////////
84-
/// F3 constructor using a pointer to real function
85+
/// TF3 constructor using a formula definition and explicit option args
86+
///
87+
/// See TFormula constructor for explanation of the formula syntax.
88+
89+
TF3::TF3(const char *name, const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax,
90+
Double_t zmin, Double_t zmax, EAddToList addToGlobList, bool vectorize)
91+
: TF2(name, formula, xmin, xmax, ymax, ymin, addToGlobList,
92+
vectorize) // purposely swapped ymax, ymin to signal that TFormula may be 1D or 2D or 3D
93+
{
94+
fZmin = zmin;
95+
fZmax = zmax;
96+
fNpz = 30;
97+
Int_t ndim = GetNdim();
98+
// accept 1-d or 2-d formula
99+
if (ndim < 3)
100+
fNdim = 3;
101+
if (ndim > 3 && xmin < xmax && ymin < ymax && zmin < zmax) {
102+
Error("TF3", "function: %s/%s has dimension %d instead of 3", name, formula, ndim);
103+
MakeZombie();
104+
}
105+
}
106+
107+
////////////////////////////////////////////////////////////////////////////////
108+
/// TF3 constructor using a pointer to real function
85109
///
86110
/// \param[in] name object name
87111
/// \param[in] fcn pointer to real function
@@ -108,7 +132,7 @@ TF3::TF3(const char *name,Double_t (*fcn)(Double_t *, Double_t *), Double_t xmin
108132
}
109133

110134
////////////////////////////////////////////////////////////////////////////////
111-
/// F3 constructor using a pointer to real function---
135+
/// TF3 constructor using a pointer to real function---
112136
///
113137
/// \param[in] name object name
114138
/// \param[in] fcn pointer to real function
@@ -135,7 +159,7 @@ TF3::TF3(const char *name,Double_t (*fcn)(const Double_t *, const Double_t *), D
135159
}
136160

137161
////////////////////////////////////////////////////////////////////////////////
138-
/// F3 constructor using a ParamFunctor
162+
/// TF3 constructor using a ParamFunctor
139163
///
140164
/// a functor class implementing operator() (double *, double *)
141165
///

0 commit comments

Comments
 (0)