Skip to content

Commit 4e4cdfb

Browse files
committed
Add a backward compatible template constructor taking name of functor object and member function name (needed for CINT). Remove instead the names from the new template constructor taking the function dimension.
1 parent f9977bb commit 4e4cdfb

File tree

5 files changed

+61
-16
lines changed

5 files changed

+61
-16
lines changed

hist/hist/inc/TF1.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class TF1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
205205
// xmin and xmax specify the plotting range, npar is the number of parameters.
206206
// See the tutorial math/exampleFunctor.C for an example of using this constructor
207207
template <typename Func>
208-
TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar,Int_t ndim = 1, const char * = 0 ) :
208+
TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar,Int_t ndim = 1 ) :
209209
TNamed(name,name), TAttLine(), TAttFill(), TAttMarker(),
210210
fXmin(xmin), fXmax(xmax),
211211
fNpar(npar), fNdim(ndim),
@@ -223,6 +223,13 @@ class TF1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
223223
{
224224
DoInitialize();
225225
}
226+
// backward compatible interface
227+
template <typename Func>
228+
TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar, const char * ) {
229+
TF1 tmp(name,f,xmin,xmax,npar,1);
230+
*this = tmp;
231+
}
232+
226233

227234
// Template constructors from a pointer to any C++ class of type PtrObj with a specific member function of type
228235
// MemFn.
@@ -233,7 +240,7 @@ class TF1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
233240
// xmin and xmax specify the plotting range, npar is the number of parameters.
234241
// See the tutorial math/exampleFunctor.C for an example of using this constructor
235242
template <class PtrObj, typename MemFn>
236-
TF1(const char *name, const PtrObj& p, MemFn memFn, Double_t xmin, Double_t xmax, Int_t npar,Int_t ndim = 1, const char * = 0, const char * = 0) :
243+
TF1(const char *name, const PtrObj& p, MemFn memFn, Double_t xmin, Double_t xmax, Int_t npar,Int_t ndim = 1) :
237244
TNamed(name,name), TAttLine(), TAttFill(), TAttMarker(),
238245
fXmin(xmin), fXmax(xmax),
239246
fNpar(npar), fNdim(ndim),
@@ -251,6 +258,12 @@ class TF1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
251258
{
252259
DoInitialize();
253260
}
261+
// backward compatible interface
262+
template <class PtrObj, typename MemFn>
263+
TF1(const char *name, const PtrObj& p, MemFn memFn, Double_t xmin, Double_t xmax, Int_t npar,const char * , const char * ) {
264+
TF1 tmp(name,p, memFn,xmin,xmax,npar,1);
265+
*this = tmp;
266+
}
254267

255268
TF1(const TF1 &f1);
256269
TF1& operator=(const TF1 &rhs);

hist/hist/inc/TF2.h

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,39 @@ class TF2 : public TF1 {
5454
// Template constructors from a pointer to any C++ class of type PtrObj with a specific member function of type
5555
// MemFn.
5656
template <class PtrObj, typename MemFn>
57-
TF2(const char *name, const PtrObj& p, MemFn memFn, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar, Int_t ndim = 2, const char * c1 = 0, const char * c2 = 0) :
58-
TF1(name,p,memFn,xmin,xmax,npar,ndim,c1,c2),
57+
TF2(const char *name, const PtrObj& p, MemFn memFn, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar, Int_t ndim = 2) :
58+
TF1(name,p,memFn,xmin,xmax,npar,ndim),
5959
fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
6060
{
6161
fNpx = 30;
62-
}
62+
}
63+
/// backward compatible ctor
64+
template <class PtrObj, typename MemFn>
65+
TF2(const char *name, const PtrObj& p, MemFn memFn, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar, const char * , const char *) :
66+
TF1(name,p,memFn,xmin,xmax,npar,2),
67+
fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
68+
{
69+
fNpx = 30;
70+
}
71+
6372
// Template constructors from any C++ callable object, defining the operator() (double * , double *)
6473
// and returning a double.
6574
template <typename Func>
66-
TF2(const char *name, Func f, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar,Int_t ndim = 2, const char * tmp = 0 ) :
67-
TF1(name,f,xmin,xmax,npar,ndim,tmp),
75+
TF2(const char *name, Func f, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar,Int_t ndim = 2) :
76+
TF1(name,f,xmin,xmax,npar,ndim),
6877
fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
6978
{
7079
fNpx = 30;
71-
}
80+
}
81+
/// backward compatible ctor
82+
template <typename Func>
83+
TF2(const char *name, Func f, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar,const char *) :
84+
TF1(name,f,xmin,xmax,npar,2),
85+
fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
86+
{
87+
fNpx = 30;
88+
}
89+
7290

7391
TF2(const TF2 &f2);
7492
TF2 &operator=(const TF2& rhs);

hist/hist/inc/TF3.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,30 @@ class TF3 : public TF2 {
5454
// MemFn.
5555
template <class PtrObj, typename MemFn>
5656
TF3(const char *name, const PtrObj& p, MemFn memFn, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax, Int_t npar,
57-
Int_t ndim = 3, const char * c1 = 0, const char * c2 = 0) :
58-
TF2(name,p,memFn,xmin,xmax,ymin,ymax,npar,ndim,c1,c2),
57+
Int_t ndim = 3) :
58+
TF2(name,p,memFn,xmin,xmax,ymin,ymax,npar,ndim),
59+
fZmin(zmin), fZmax(zmax), fNpz(30)
60+
{ }
61+
/// Backward compatible ctor
62+
template <class PtrObj, typename MemFn>
63+
TF3(const char *name, const PtrObj& p, MemFn memFn, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax, Int_t npar,
64+
const char * , const char * ) :
65+
TF2(name,p,memFn,xmin,xmax,ymin,ymax,npar,3),
5966
fZmin(zmin), fZmax(zmax), fNpz(30)
6067
{ }
6168
// Template constructors from any C++ callable object, defining the operator() (double * , double *)
6269
// and returning a double.
6370
template <typename Func>
6471
TF3(const char *name, Func f, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax, Int_t npar,
65-
Int_t ndim = 3, const char * c1 = 0 ) :
66-
TF2(name,f,xmin,xmax,ymin,ymax,npar,ndim,c1),
72+
Int_t ndim = 3 ) :
73+
TF2(name,f,xmin,xmax,ymin,ymax,npar,ndim),
74+
fZmin(zmin), fZmax(zmax), fNpz(30)
75+
{ }
76+
/// backward compatible ctor
77+
template <typename Func>
78+
TF3(const char *name, Func f, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax, Int_t npar,
79+
const char * ) :
80+
TF2(name,f,xmin,xmax,ymin,ymax,npar,3),
6781
fZmin(zmin), fZmax(zmax), fNpz(30)
6882
{ }
6983

hist/hist/src/TKDE.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ TF1* TKDE::GetPDFUpperConfidenceInterval(Double_t confidenceLevel, UInt_t npx, D
10001000
TString name;
10011001
name.Form("KDE_UpperCL%f5.3_%s",confidenceLevel,GetName());
10021002
if (xMin >= xMax) { xMin = fXMin; xMax = fXMax; }
1003-
TF1 * upperPDF = new TF1(name, this, &TKDE::UpperConfidenceInterval, xMin, xMax, 1,1, "TKDE", "UpperConfidenceInterval");
1003+
TF1 * upperPDF = new TF1(name, this, &TKDE::UpperConfidenceInterval, xMin, xMax, 1);
10041004
upperPDF->SetParameter(0, confidenceLevel);
10051005
if (npx > 0) upperPDF->SetNpx(npx);
10061006
TF1 * f = (TF1*)upperPDF->Clone();

roofit/roofitcore/src/RooAbsReal.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4078,22 +4078,22 @@ TF1* RooAbsReal::asTF(const RooArgList& obs, const RooArgList& pars, const RooAr
40784078
case 1: {
40794079
RooRealVar* x = (RooRealVar*)obs.at(0) ;
40804080
f = functor(obs,pars,nset) ;
4081-
tf = new TF1(GetName(),f,x->getMin(),x->getMax(),pars.getSize(),1,"RooFunctor") ;
4081+
tf = new TF1(GetName(),f,x->getMin(),x->getMax(),pars.getSize()) ;
40824082
break ;
40834083
}
40844084
case 2: {
40854085
RooRealVar* x = (RooRealVar*)obs.at(0) ;
40864086
RooRealVar* y = (RooRealVar*)obs.at(1) ;
40874087
f = functor(obs,pars,nset) ;
4088-
tf = new TF2(GetName(),f,x->getMin(),x->getMax(),y->getMin(),y->getMax(),pars.getSize(),2,"RooFunctor") ;
4088+
tf = new TF2(GetName(),f,x->getMin(),x->getMax(),y->getMin(),y->getMax(),pars.getSize()) ;
40894089
break ;
40904090
}
40914091
case 3: {
40924092
RooRealVar* x = (RooRealVar*)obs.at(0) ;
40934093
RooRealVar* y = (RooRealVar*)obs.at(1) ;
40944094
RooRealVar* z = (RooRealVar*)obs.at(2) ;
40954095
f = functor(obs,pars,nset) ;
4096-
tf = new TF3(GetName(),f,x->getMin(),x->getMax(),y->getMin(),y->getMax(),z->getMin(),z->getMax(),pars.getSize(),3,"RooFunctor") ;
4096+
tf = new TF3(GetName(),f,x->getMin(),x->getMax(),y->getMin(),y->getMax(),z->getMin(),z->getMax(),pars.getSize()) ;
40974097
break ;
40984098
}
40994099
default:

0 commit comments

Comments
 (0)