24 #include "RConfigure.h" 53 fParNames(
std::vector<
std::string>(npar))
55 for (
int i = 0; i < npar; ++i) {
61 fParameters(rhs.fParameters),
62 fParNames(rhs.fParNames)
67 if (&rhs ==
this)
return *
this;
77 return (CheckIndex(iparam)) ? fParameters[iparam] : 0;
81 return GetParameter(GetParNumber(name));
85 return fParameters.data();
92 Int_t GetParNumber(
const char *
name)
const;
96 return (CheckIndex(iparam)) ? fParNames[iparam].c_str() :
"";
103 if (!CheckIndex(iparam))
return;
104 fParameters[iparam] = value;
108 std::copy(params, params + fParameters.size(), fParameters.begin());
116 SetParameter(GetParNumber(name), value);
120 if (!CheckIndex(iparam))
return;
121 fParNames[iparam] = std::string(name);
123 void SetParNames(
const char *name0 =
"p0",
const char *name1 =
"p1",
const char *name2 =
"p2",
124 const char *name3 =
"p3",
const char *name4 =
"p4",
const char *name5 =
"p5",
125 const char *name6 =
"p6",
const char *name7 =
"p7",
const char *name8 =
"p8",
126 const char *name9 =
"p9",
const char *name10 =
"p10");
135 return (i >= 0 && i <
int(fParameters.size()));
148 static void Build(
TF1 *
f, Func func);
153 static void Build(
TF1 *
f, Func *func);
162 template<
typename F,
typename T>
167 template<
typename F,
typename T>
172 template<
typename F,
typename T>
177 template<
typename F,
typename T>
184 template<
typename T,
typename F>
190 template<
typename T,
typename F>
191 auto GetTheRightOp(
T(
F::*opPtr)(
const T *,
const double *)
const) -> decltype(opPtr)
196 template<
typename T,
typename F>
202 template<
typename T,
typename F>
268 fType(functionType), fParErrors(npar), fParMin(npar), fParMax(npar), fFunctor(functor), fParams(params)
270 DoInitialize(addToGlobList);
277 TString &formula,
int termStart,
int termEnd,
279 int TermCoeffLength(
TString &term);
302 void IntegrateForNormalization();
325 fType = std::is_same<T, double>::value ? TF1::EFType::kTemplScalar : TF1::EFType::kTemplVec;
356 template <
typename Func>
358 TF1(
EFType::kTemplScalar, name, xmin, xmax, npar, ndim, addToGlobList)
365 template <
typename Func>
381 template <
class PtrObj,
typename MemFn>
387 template <
class PtrObj,
typename MemFn>
397 if (fFormula) fFormula->AddParameter(name, value);
412 virtual TF1 *DrawCopy(
Option_t *option =
"")
const;
419 template <
class T>
T EvalPar(
const T *x,
const Double_t *params = 0);
426 return (
fType == EFType::kTemplVec) || (
fType == EFType::kFormula && fFormula && fFormula->IsVectorized());
432 virtual TH1 *GetHistogram()
const;
435 return DoCreateHistogram(fXmin, fXmax);
447 return (fFormula) ? fFormula->GetExpFormula(option) :
"";
451 return (fFormula) ? fFormula->GetLinearPart(i) :
nullptr;
473 virtual Int_t GetNDF()
const;
484 return (fFormula) ? fFormula->GetNumber() : 0;
486 virtual Int_t GetNumberFreeParameters()
const;
491 virtual char *GetObjectInfo(
Int_t px,
Int_t py)
const;
498 return (fFormula) ? fFormula->GetParameter(ipar) : fParams->GetParameter(ipar);
502 return (fFormula) ? fFormula->GetParameter(name) : fParams->GetParameter(name);
506 return (fFormula) ? fFormula->GetParameters() :
const_cast<Double_t *
>(fParams->GetParameters());
510 if (fFormula) fFormula->GetParameters(params);
511 else std::copy(fParams->ParamsVec().begin(), fParams->ParamsVec().end(), params);
515 return (fFormula) ? fFormula->GetParName(ipar) : fParams->GetParName(ipar);
519 return (fFormula) ? fFormula->GetParNumber(name) : fParams->GetParNumber(name);
524 return fParErrors.data();
544 TAxis *GetXaxis()
const ;
545 TAxis *GetYaxis()
const ;
546 TAxis *GetZaxis()
const ;
549 return (fFormula) ? fFormula->GetVariable(name) : 0;
559 void GradientPar(
const T *x,
T *grad,
Double_t eps = 0.01);
561 void GradientParTempl(
const T *x,
T *grad,
Double_t eps = 0.01);
564 static void InitStandardFunctions();
574 return IntegralMultiple(n, a, b, maxpts, epsrel, epsrel, relerr, nfnevl, ifail);
584 return !((x[0] < fXmin) || (x[0] > fXmax));
588 return (fFormula) ? fFormula->IsLinear() :
false;
590 virtual Bool_t IsValid()
const;
592 virtual void Paint(
Option_t *option =
"");
593 virtual void ReleaseParameter(
Int_t ipar);
595 virtual void SavePrimitive(std::ostream &out,
Option_t *option =
"");
601 template <
class PtrObj,
typename MemFn>
602 void SetFunction(PtrObj &p, MemFn memFn);
603 template <
typename Func>
604 void SetFunction(Func f);
605 virtual void SetMaximum(
Double_t maximum = -1111);
606 virtual void SetMinimum(
Double_t minimum = -1111);
607 virtual void SetNDF(
Int_t ndf);
617 virtual void SetNpx(
Int_t npx = 100);
620 (fFormula) ? fFormula->SetParameter(param, value) : fParams->SetParameter(param, value);
625 (fFormula) ? fFormula->SetParameter(name, value) : fParams->SetParameter(name, value);
630 (fFormula) ? fFormula->SetParameters(params) : fParams->SetParameters(params);
637 if (fFormula) fFormula->SetParameters(p0, p1,
p2,
p3, p4, p5, p6, p7, p8, p9, p10);
638 else fParams->SetParameters(p0, p1,
p2,
p3, p4, p5, p6, p7, p8, p9, p10);
641 virtual void SetParName(
Int_t ipar,
const char *name);
642 virtual void SetParNames(
const char *name0 =
"p0",
const char *name1 =
"p1",
const char *name2 =
"p2",
643 const char *name3 =
"p3",
const char *name4 =
"p4",
const char *name5 =
"p5",
644 const char *name6 =
"p6",
const char *name7 =
"p7",
const char *name8 =
"p8",
645 const char *name9 =
"p9",
const char *name10 =
"p10");
647 virtual void SetParErrors(
const Double_t *errors);
657 virtual void SetTitle(
const char *title =
"");
660 if (
fType == EFType::kFormula && fFormula)
661 fFormula->SetVectorized(vectorized);
663 Warning(
"SetVectorized",
"Can only set vectorized flag on formula-based TF1");
665 virtual void Update();
667 static TF1 *GetCurrent();
670 static Bool_t RejectedPoint();
671 static void SetCurrent(
TF1 *f1);
678 return Moment(1, a, b, params,
epsilon);
682 return CentralMoment(2, a, b, params,
epsilon);
694 #ifdef R__HAS_VECCORE 708 f->
fType = std::is_same<Fnc_t, double>::value? TF1::EFType::kTemplScalar : TF1::EFType::kTemplVec;
717 f->
fType = std::is_same<Fnc_t, double>::value? TF1::EFType::kTemplScalar : TF1::EFType::kTemplVec;
728 f->
fType = TF1::EFType::kFormula;
730 TString formulaExpression(formula);
733 TString title = formulaExpression(first, last - first);
742 return Eval(x, y, z, t);
748 return EvalPar(x, params);
756 if (
fType == EFType::kTemplVec ||
fType == EFType::kTemplScalar) {
757 return EvalParTempl(x, params);
758 }
else if (
fType == EFType::kFormula) {
759 return fFormula->EvalPar(x, params);
781 assert(
fType == EFType::kTemplScalar ||
fType == EFType::kTemplVec);
782 if (!params) params = (
Double_t *)fParams->GetParameters();
791 #ifdef R__HAS_VECCORE 795 assert(
fType == EFType::kTemplVec);
796 std::vector<ROOT::Double_v>
d(fNdim);
799 for(
auto i=0; i<fNdim; i++) {
809 return vecCore::Get<ROOT::Double_v>(res, 0);
822 template <
typename Func>
826 fType = EFType::kPtrScalarFreeFcn;
829 template <
class PtrObj,
typename MemFn>
833 fType = EFType::kPtrScalarFreeFcn;
840 if (
fType == EFType::kTemplVec ||
fType == EFType::kTemplScalar) {
841 return GradientParTempl<T>(ipar,
x, eps);
843 return GradientParTempl<Double_t>(ipar, (
const Double_t *)x, eps);
852 if (eps < 1e-10 || eps > 1) {
853 Warning(
"Derivative",
"parameter esp=%g out of allowed range[1e-10,1], reset to 0.01", eps);
864 std::vector<Double_t> parametersCopy;
866 parametersCopy.resize(GetNpar());
867 std::copy(parameters, parameters + GetNpar(), parametersCopy.begin());
868 parameters = parametersCopy.data();
872 T f1, f2, g1, g2, d0, d2;
875 if (al * bl != 0 && al >= bl) {
889 parameters[ipar] = par0 +
h;
890 f1 = func->
EvalPar(x, parameters);
891 parameters[ipar] = par0 -
h;
892 f2 = func->
EvalPar(x, parameters);
893 parameters[ipar] = par0 + h / 2;
894 g1 = func->
EvalPar(x, parameters);
895 parameters[ipar] = par0 - h / 2;
896 g2 = func->
EvalPar(x, parameters);
903 T grad = h2 * (4 * d2 - d0) / 3.;
906 parameters[ipar] = par0;
914 if (
fType == EFType::kTemplVec ||
fType == EFType::kTemplScalar) {
915 GradientParTempl<T>(
x, grad, eps);
923 if (eps < 1e-10 || eps > 1) {
924 Warning(
"Derivative",
"parameter esp=%g out of allowed range[1e-10,1], reset to 0.01", eps);
928 for (
Int_t ipar = 0; ipar < GetNpar(); ipar++) {
929 grad[ipar] = GradientParTempl<T>(ipar,
x, eps);
TF1(EFType functionType, const char *name, Double_t xmin, Double_t xmax, Int_t npar, Int_t ndim, EAddToList addToGlobList, TF1Parameters *params=nullptr, TF1FunctorPointer *functor=nullptr)
General constructor for TF1. Most of the other constructors delegate on it.
TF1(const char *name, std::function< T(const T *data, const Double_t *param)> &fcn, Double_t xmin=0, Double_t xmax=1, Int_t npar=0, Int_t ndim=1, EAddToList addToGlobList=EAddToList::kDefault)
virtual TString GetExpFormula(Option_t *option="") const
virtual void SetParameters(Double_t p0, Double_t p1, Double_t p2=0, Double_t p3=0, Double_t p4=0, Double_t p5=0, Double_t p6=0, Double_t p7=0, Double_t p8=0, Double_t p9=0, Double_t p10=0)
TF1Parameters(Int_t npar)
UInt_t GetImplicitMTPoolSize()
Returns the size of the pool used for implicit multi-threading.
virtual void AddParameter(const TString &name, Double_t value)
virtual void SetParameters(const Double_t *params)
virtual Double_t operator()(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Param Functor class for Multidimensional functions.
virtual TFormula * GetFormula()
virtual Int_t GetNpx() const
static double p3(double t, double a, double b, double c, double d)
Namespace for new ROOT classes and functions.
ROOT::Math::ParamFunctorTempl< T > fImpl
static std::atomic< Bool_t > fgAbsValue
TF1(const char *name, const PtrObj &p, MemFn memFn, Double_t xmin, Double_t xmax, Int_t npar, const char *, const char *, EAddToList addToGlobList=EAddToList::kDefault)
TMethodCall * GetMethodCall() const
virtual Double_t GetMinimumStored() const
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
std::vector< std::string > fParNames
virtual void SetNumberFitPoints(Int_t npfits)
void SetParameter(const char *name, Double_t value)
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
void SetFunction(PtrObj &p, MemFn memFn)
Internal class used by TF1 for defining template specialization for different TF1 constructors...
virtual void SetNormalized(Bool_t flag)
TRObject operator()(const T1 &t1) const
TF1(const char *name, T(*fcn)(const T *, const Double_t *), Double_t xmin=0, Double_t xmax=1, Int_t npar=0, Int_t ndim=1, EAddToList addToGlobList=EAddToList::kDefault)
Constructor using a pointer to function.
Double_t GetParameter(Int_t iparam) const
TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar, const char *, EAddToList addToGlobList=EAddToList::kDefault)
virtual void SetParent(TObject *p=0)
TFormula * fFormula
Functor object to wrap any C++ callable object.
Fill Area Attributes class.
void SetParameters(TFitEditor::FuncParams_t &pars, TF1 *func)
Restore the parameters from pars into the function.
#define ClassDef(name, id)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
The TNamed class is the base class for all named ROOT classes.
const char * GetParName(Int_t iparam) const
virtual Double_t GetVariable(const TString &name)
virtual void GetParameters(Double_t *params)
bool CheckIndex(Int_t i) const
static double p2(double t, double a, double b, double c)
void SetParameters(const Double_t *params)
virtual Double_t IntegralMultiple(Int_t n, const Double_t *a, const Double_t *b, Int_t, Int_t maxpts, Double_t epsrel, Double_t &relerr, Int_t &nfnevl, Int_t &ifail)
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
virtual Int_t GetNdim() const
Method or function calling interface.
virtual Double_t GetMaximumStored() const
static void GetRange(const char *comments, Double_t &xmin, Double_t &xmax, Double_t &factor)
Parse comments to search for a range specifier of the style: [xmin,xmax] or [xmin,xmax,nbits] [0,1] [-10,100]; [-pi,pi], [-pi/2,pi/4],[-2pi,2*pi] [-10,100,16] [0,0,8] if nbits is not specified, or nbits <2 or nbits>32 it is set to 32 if (xmin==0 and xmax==0 and nbits <=16) the double word will be converted to a float and its mantissa truncated to nbits significative bits.
TF1Parameters & operator=(const TF1Parameters &rhs)
std::vector< Double_t > fIntegral
virtual Double_t GradientPar(Int_t ipar, const Double_t *x, Double_t eps=0.01)
Compute the gradient (derivative) wrt a parameter ipar.
virtual const char * GetParName(Int_t ipar) const
Using a TBrowser one can browse all ROOT objects.
TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar, Int_t ndim=1, EAddToList addToGlobList=EAddToList::kDefault)
virtual void SetChisquare(Double_t chi2)
static Bool_t fgRejectPoint
std::vector< Double_t > fParameters
virtual const Double_t * GetParErrors() const
Class to manage histogram axis.
virtual Int_t GetNumberFitPoints() const
double IntegralError(TF1 *func, Int_t ndim, const double *a, const double *b, const double *params, const double *covmat, double epsilon)
virtual const TObject * GetLinearPart(Int_t i) const
std::unique_ptr< TF1AbsComposition > fComposition
virtual Bool_t IsLinear() const
Double_t GetParameter(const char *name) const
virtual const TFormula * GetFormula() const
void GetParameters(TFitEditor::FuncParams_t &pars, TF1 *func)
Stores the parameters of the given function into pars.
static double p1(double t, double a, double b)
const std::vector< double > & ParamsVec() const
virtual Double_t GetParameter(const TString &name) const
Double_t SignalingNaN()
Returns a signaling NaN as defined by IEEE 754](http://en.wikipedia.org/wiki/NaN#Signaling_NaN) ...
virtual Double_t GetXmin() const
void Warning(const char *location, const char *msgfmt,...)
virtual void SetParameter(const TString &name, Double_t value)
constexpr Double_t E()
Base of natural log: .
void SetParameter(Int_t iparam, Double_t value)
virtual Double_t Mean(Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001)
TF1FunctorPointerImpl(const ROOT::Math::ParamFunctorTempl< T > &func)
virtual Bool_t IsEvalNormalized() const
virtual void SetTitle(const char *title="")
Set function title if title has the form "fffffff;xxxx;yyyy", it is assumed that the function title i...
TF1(const char *name, const PtrObj &p, MemFn memFn, Double_t xmin, Double_t xmax, Int_t npar, Int_t ndim=1, EAddToList addToGlobList=EAddToList::kDefault)
Double_t GetChisquare() const
class containg the result of the fit and all the related information (fitted parameter values...
T EvalParTempl(const T *data, const Double_t *params=0)
Eval for vectorized functions.
void Copy(void *source, void *dest)
void Print(std::ostream &os, const OptionType &opt)
std::vector< Double_t > fSave
Ssiz_t Last(char c) const
Find last occurrence of a character c.
std::vector< Double_t > fParErrors
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
void SetParName(Int_t iparam, const char *name)
TF1FunctorPointer * fFunctor
std::vector< Double_t > fGamma
Array beta. is approximated by x = alpha +beta*r *gamma*r**2.
virtual Double_t Variance(Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001)
virtual Double_t GetXmax() const
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
std::vector< Double_t > fAlpha
Integral of function binned on fNpx bins.
Namespace for new Math classes and functions.
std::vector< Double_t > fBeta
Array alpha. for each bin in x the deconvolution r of fIntegral.
TObject * GetParent() const
Binding & operator=(OUT(*fun)(void))
Mother of all ROOT objects.
you should not use this method at all Int_t Int_t z
auto GetTheRightOp(T(F::*opPtr)(T *, double *)) -> decltype(opPtr)
virtual Bool_t IsInside(const Double_t *x) const
return kTRUE if the point is inside the function range
virtual TH1 * CreateHistogram()
RooCmdArg Save(Bool_t flag=kTRUE)
virtual Int_t GetNpar() const
virtual void GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const
Return limits for parameter ipar.
virtual void SetVectorized(Bool_t vectorized)
static void Build(TF1 *f, Func func)
virtual Double_t GetParameter(Int_t ipar) const
static void Build(TF1 *f, const char *formula)
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
const Double_t * GetParameters() const
static std::atomic< Bool_t > fgAddToGlobList
virtual Double_t * GetParameters() const
virtual void SetParameter(Int_t param, Double_t value)
ParamFunctorTempl< double > ParamFunctor
T GradientParTempl(Int_t ipar, const T *x, Double_t eps=0.01)
std::vector< Double_t > fParMax
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=0)
Evaluate function with given coordinates and parameters.
virtual Int_t GetNumber() const
std::vector< Double_t > fParMin
virtual Int_t GetParNumber(const char *name) const
TF1Parameters(const TF1Parameters &rhs)