Logo ROOT  
Reference Guide
TF1.h
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun 18/08/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11// ---------------------------------- F1.h
12
13#ifndef ROOT_TF1
14#define ROOT_TF1
15
16//////////////////////////////////////////////////////////////////////////
17// //
18// TF1 //
19// //
20// The Parametric 1-D function //
21// //
22//////////////////////////////////////////////////////////////////////////
23
24#include "RConfigure.h"
25#include <functional>
26#include <cassert>
27#include "TFormula.h"
28#include "TAttLine.h"
29#include "TAttFill.h"
30#include "TAttMarker.h"
31#include "TROOT.h"
32#include "TF1AbsComposition.h"
33#include "TMath.h"
34#include "Math/Types.h"
35#include "Math/ParamFunctor.h"
36
37class TF1;
38class TH1;
39class TAxis;
40class TMethodCall;
41
42namespace ROOT {
43 namespace Fit {
44 class FitResult;
45 }
46}
47
49public:
50 TF1Parameters() {} // needed for the I/O
52 fParameters(std::vector<Double_t>(npar)),
53 fParNames(std::vector<std::string>(npar))
54 {
55 for (int i = 0; i < npar; ++i) {
56 fParNames[i] = std::string(TString::Format("p%d", i).Data());
57 }
58 }
59 // copy constructor
63 {}
64 // assignment
66 {
67 if (&rhs == this) return *this;
69 fParNames = rhs.fParNames;
70 return *this;
71 }
72 virtual ~TF1Parameters() {}
73
74 // getter methods
76 {
77 return (CheckIndex(iparam)) ? fParameters[iparam] : 0;
78 }
79 Double_t GetParameter(const char *name) const
80 {
82 }
83 const Double_t *GetParameters() const
84 {
85 return fParameters.data();
86 }
87 const std::vector<double> &ParamsVec() const
88 {
89 return fParameters;
90 }
91
92 Int_t GetParNumber(const char *name) const;
93
94 const char *GetParName(Int_t iparam) const
95 {
96 return (CheckIndex(iparam)) ? fParNames[iparam].c_str() : "";
97 }
98
99
100 // setter methods
101 void SetParameter(Int_t iparam, Double_t value)
102 {
103 if (!CheckIndex(iparam)) return;
104 fParameters[iparam] = value;
105 }
106 void SetParameters(const Double_t *params)
107 {
108 std::copy(params, params + fParameters.size(), fParameters.begin());
109 }
110 void SetParameters(Double_t p0, Double_t p1, Double_t p2 = 0, Double_t p3 = 0, Double_t p4 = 0,
111 Double_t p5 = 0, Double_t p6 = 0, Double_t p7 = 0, Double_t p8 = 0,
112 Double_t p9 = 0, Double_t p10 = 0);
113
114 void SetParameter(const char *name, Double_t value)
115 {
117 }
118 void SetParName(Int_t iparam, const char *name)
119 {
120 if (!CheckIndex(iparam)) return;
121 fParNames[iparam] = std::string(name);
122 }
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");
127
128
129
130 ClassDef(TF1Parameters, 1) // The Parameters of a parameteric function
131private:
132
133 bool CheckIndex(Int_t i) const
134 {
135 return (i >= 0 && i < int(fParameters.size()));
136 }
137
138 std::vector<Double_t> fParameters; // parameter values
139 std::vector<std::string> fParNames; // parameter names
140};
141
142namespace ROOT {
143 namespace Internal {
144 /// Internal class used by TF1 for defining
145 /// template specialization for different TF1 constructors
146 template<class Func>
147 struct TF1Builder {
148 static void Build(TF1 *f, Func func);
149 };
150
151 template<class Func>
152 struct TF1Builder<Func *> {
153 static void Build(TF1 *f, Func *func);
154 };
155
156 // Internal class used by TF1 for obtaining the type from a functor
157 // out of the set of valid operator() signatures.
158 template<typename T>
160 };
161
162 template<typename F, typename T>
163 struct GetFunctorType<T(F::*)(const T *, const double *)> {
164 using type = T;
165 };
166
167 template<typename F, typename T>
168 struct GetFunctorType<T(F::*)(const T *, const double *) const> {
169 using type = T;
170 };
171
172 template<typename F, typename T>
173 struct GetFunctorType<T(F::*)(T *, double *)> {
174 using type = T;
175 };
176
177 template<typename F, typename T>
178 struct GetFunctorType<T(F::*)(T *, double *) const> {
179 using type = T;
180 };
181
182 // Internal class used by TF1 to get the right operator() signature
183 // from a Functor with several ones.
184 template<typename T, typename F>
185 auto GetTheRightOp(T(F::*opPtr)(const T *, const double *)) -> decltype(opPtr)
186 {
187 return opPtr;
188 }
189
190 template<typename T, typename F>
191 auto GetTheRightOp(T(F::*opPtr)(const T *, const double *) const) -> decltype(opPtr)
192 {
193 return opPtr;
194 }
195
196 template<typename T, typename F>
197 auto GetTheRightOp(T(F::*opPtr)(T *, double *)) -> decltype(opPtr)
198 {
199 return opPtr;
200 }
201
202 template<typename T, typename F>
203 auto GetTheRightOp(T(F::*opPtr)(T *, double *) const) -> decltype(opPtr)
204 {
205 return opPtr;
206 }
207 }
208}
209
210
211class TF1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
212
213 template<class Func>
215
216public:
217 // Add to list behavior
218 enum class EAddToList {
219 kDefault,
220 kAdd,
221 kNo
222 };
223
224protected:
225
228 virtual TF1FunctorPointer * Clone() const = 0;
229 };
230
231
232 enum EFType {
233 kFormula = 0, // formula functions which can be stored,
234 kPtrScalarFreeFcn, // pointer to scalar free function,
235 kInterpreted, // interpreted functions constructed by name,
236 kTemplVec, // vectorized free functions or TemplScalar functors evaluating on vectorized parameters,
237 kTemplScalar, // TemplScalar functors evaluating on scalar parameters
239 }; // formula based on composition class (e.g. NSUM, CONV)
240
241 Double_t fXmin{-1111}; //Lower bounds for the range
242 Double_t fXmax{-1111}; //Upper bounds for the range
243 Int_t fNpar{}; //Number of parameters
244 Int_t fNdim{}; //Function dimension
245 Int_t fNpx{100}; //Number of points used for the graphical representation
246 EFType fType{EFType::kTemplScalar};
247 Int_t fNpfits{}; //Number of points used in the fit
248 Int_t fNDF{}; //Number of degrees of freedom in the fit
249 Double_t fChisquare{}; //Function fit chisquare
250 Double_t fMinimum{-1111}; //Minimum value for plotting
251 Double_t fMaximum{-1111}; //Maximum value for plotting
252 std::vector<Double_t> fParErrors; //Array of errors of the fNpar parameters
253 std::vector<Double_t> fParMin; //Array of lower limits of the fNpar parameters
254 std::vector<Double_t> fParMax; //Array of upper limits of the fNpar parameters
255 std::vector<Double_t> fSave; //Array of fNsave function values
256 std::vector<Double_t> fIntegral; //!Integral of function binned on fNpx bins
257 std::vector<Double_t> fAlpha; //!Array alpha. for each bin in x the deconvolution r of fIntegral
258 std::vector<Double_t> fBeta; //!Array beta. is approximated by x = alpha +beta*r *gamma*r**2
259 std::vector<Double_t> fGamma; //!Array gamma.
260 TObject *fParent{nullptr}; //!Parent object hooking this function (if one)
261 TH1 *fHistogram{nullptr}; //!Pointer to histogram used for visualisation
262 TMethodCall *fMethodCall{nullptr}; //!Pointer to MethodCall in case of interpreted function
263 Bool_t fNormalized{false}; //Normalization option (false by default)
264 Double_t fNormIntegral{}; //Integral of the function before being normalized
265 TF1FunctorPointer *fFunctor{nullptr}; //! Functor object to wrap any C++ callable object
266 TFormula *fFormula{nullptr}; //Pointer to TFormula in case when user define formula
267 TF1Parameters *fParams{nullptr}; //Pointer to Function parameters object (exists only for not-formula functions)
268 std::unique_ptr<TF1AbsComposition> fComposition; //! Pointer to composition (NSUM or CONV)
269 TF1AbsComposition *fComposition_ptr{nullptr}; // saved pointer (unique_ptr is transient)
270
271 /// General constructor for TF1. Most of the other constructors delegate on it
272 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):
273 TNamed(name, name), TAttLine(), TAttFill(), TAttMarker(), fXmin(xmin), fXmax(xmax), fNpar(npar), fNdim(ndim),
274 fType(functionType), fParErrors(npar), fParMin(npar), fParMax(npar), fFunctor(functor), fParams(params)
275 {
276 DoInitialize(addToGlobList);
277 };
278
279private:
280 // NSUM parsing helper functions
281 void DefineNSUMTerm(TObjArray *newFuncs, TObjArray *coeffNames,
282 TString &fullFormula,
283 TString &formula, int termStart, int termEnd,
285 int TermCoeffLength(TString &term);
286
287protected:
288
289 template <class T>
292 TF1FunctorPointerImpl(const std::function<T(const T *f, const Double_t *param)> &func) : fImpl(func){};
294 virtual TF1FunctorPointer * Clone() const { return new TF1FunctorPointerImpl<T>(fImpl); }
296 };
297
298
299
300
301 static std::atomic<Bool_t> fgAbsValue; //use absolute value of function when computing integral
302 static Bool_t fgRejectPoint; //True if point must be rejected in a fit
303 static std::atomic<Bool_t> fgAddToGlobList; //True if we want to register the function in the global list
304 static TF1 *fgCurrent; //pointer to current function being processed
305
306
307 //void CreateFromFunctor(const char *name, Int_t npar, Int_t ndim = 1);
308 void DoInitialize(EAddToList addToGlobList);
309
311
312 virtual Double_t GetMinMaxNDim(Double_t *x , Bool_t findmax, Double_t epsilon = 0, Int_t maxiter = 0) const;
313 virtual void GetRange(Double_t *xmin, Double_t *xmax) const;
315
316public:
317
318 // TF1 status bits
320 kNotGlobal = BIT(10), // don't register in global list of functions
321 kNotDraw = BIT(9) // don't draw the function when in a TH1
322 };
323
324 TF1();
325 TF1(const char *name, const char *formula, Double_t xmin = 0, Double_t xmax = 1, EAddToList addToGlobList = EAddToList::kDefault, bool vectorize = false);
326 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
327 TF1(const char *name, Double_t xmin, Double_t xmax, Int_t npar, Int_t ndim = 1, EAddToList addToGlobList = EAddToList::kDefault);
328 TF1(const char *name, Double_t (*fcn)(Double_t *, Double_t *), Double_t xmin = 0, Double_t xmax = 1, Int_t npar = 0, Int_t ndim = 1, EAddToList addToGlobList = EAddToList::kDefault);
329 TF1(const char *name, Double_t (*fcn)(const Double_t *, const Double_t *), Double_t xmin = 0, Double_t xmax = 1, Int_t npar = 0, Int_t ndim = 1, EAddToList addToGlobList = EAddToList::kDefault);
330
331 template <class T>
332 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):
333 TF1(EFType::kTemplScalar, name, xmin, xmax, npar, ndim, addToGlobList, new TF1Parameters(npar), new TF1FunctorPointerImpl<T>(fcn))
334 {
335 fType = std::is_same<T, double>::value ? TF1::EFType::kTemplScalar : TF1::EFType::kTemplVec;
336 }
337
338 ////////////////////////////////////////////////////////////////////////////////
339 /// Constructor using a pointer to function.
340 ///
341 /// \param npar is the number of free parameters used by the function
342 ///
343 /// This constructor creates a function of type C when invoked
344 /// with the normal C++ compiler.
345 ///
346 ///
347 /// WARNING! A function created with this constructor cannot be Cloned
348
349
350 template <class T>
351 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):
352 TF1(EFType::kTemplVec, name, xmin, xmax, npar, ndim, addToGlobList, new TF1Parameters(npar), new TF1FunctorPointerImpl<T>(fcn))
353 {}
354
355 // Constructors using functors (compiled mode only)
356 TF1(const char *name, ROOT::Math::ParamFunctor f, Double_t xmin = 0, Double_t xmax = 1, Int_t npar = 0, Int_t ndim = 1, EAddToList addToGlobList = EAddToList::kDefault);
357
358 // Template constructors from any C++ callable object, defining the operator() (double * , double *)
359 // and returning a double.
360 // The class name is not needed when using compile code, while it is required when using
361 // interpreted code via the specialized constructor with void *.
362 // An instance of the C++ function class or its pointer can both be used. The former is reccomended when using
363 // C++ compiled code, but if CINT compatibility is needed, then a pointer to the function class must be used.
364 // xmin and xmax specify the plotting range, npar is the number of parameters.
365 // See the tutorial math/exampleFunctor.C for an example of using this constructor
366 template <typename Func>
367 TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar, Int_t ndim = 1, EAddToList addToGlobList = EAddToList::kDefault) :
368 TF1(EFType::kTemplScalar, name, xmin, xmax, npar, ndim, addToGlobList)
369 {
370 //actual fType set in TF1Builder
372 }
373
374 // backward compatible interface
375 template <typename Func>
376 TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar, const char *, EAddToList addToGlobList = EAddToList::kDefault) :
377 TF1(EFType::kTemplScalar, name, xmin, xmax, npar, 1, addToGlobList, new TF1Parameters(npar))
378 {
380 }
381
382
383 // Template constructors from a pointer to any C++ class of type PtrObj with a specific member function of type
384 // MemFn.
385 // The member function must have the signature of (double * , double *) and returning a double.
386 // The class name and the method name are not needed when using compile code
387 // (the member function pointer is used in this case), while they are required when using interpreted
388 // code via the specialized constructor with void *.
389 // xmin and xmax specify the plotting range, npar is the number of parameters.
390 // See the tutorial math/exampleFunctor.C for an example of using this constructor
391 template <class PtrObj, typename MemFn>
392 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) :
393 TF1(EFType::kTemplScalar, name, xmin, xmax, npar, ndim, addToGlobList, new TF1Parameters(npar), new TF1FunctorPointerImpl<double>(ROOT::Math::ParamFunctor(p, memFn)))
394 {}
395
396 // backward compatible interface
397 template <class PtrObj, typename MemFn>
398 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) :
399 TF1(EFType::kTemplScalar, name, xmin, xmax, npar, 1, addToGlobList, new TF1Parameters(npar), new TF1FunctorPointerImpl<double>(ROOT::Math::ParamFunctor(p, memFn)))
400 {}
401
402 TF1(const TF1 &f1);
403 TF1 &operator=(const TF1 &rhs);
404 virtual ~TF1();
405 virtual void AddParameter(const TString &name, Double_t value)
406 {
407 if (fFormula) fFormula->AddParameter(name, value);
408 }
409 // virtual void AddParameters(const pair<TString,Double_t> *pairs, Int_t size) { fFormula->AddParameters(pairs,size); }
410 // virtual void AddVariable(const TString &name, Double_t value = 0) { if (fFormula) fFormula->AddVariable(name,value); }
411 // virtual void AddVariables(const TString *vars, Int_t size) { if (fFormula) fFormula->AddVariables(vars,size); }
412 virtual Bool_t AddToGlobalList(Bool_t on = kTRUE);
414 virtual void Browse(TBrowser *b);
415 virtual void Copy(TObject &f1) const;
416 virtual Double_t Derivative(Double_t x, Double_t *params = 0, Double_t epsilon = 0.001) const;
417 virtual Double_t Derivative2(Double_t x, Double_t *params = 0, Double_t epsilon = 0.001) const;
418 virtual Double_t Derivative3(Double_t x, Double_t *params = 0, Double_t epsilon = 0.001) const;
419 static Double_t DerivativeError();
420 virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
421 virtual void Draw(Option_t *option = "");
422 virtual TF1 *DrawCopy(Option_t *option = "") const;
423 virtual TObject *DrawDerivative(Option_t *option = "al"); // *MENU*
424 virtual TObject *DrawIntegral(Option_t *option = "al"); // *MENU*
425 virtual void DrawF1(Double_t xmin, Double_t xmax, Option_t *option = "");
426 virtual Double_t Eval(Double_t x, Double_t y = 0, Double_t z = 0, Double_t t = 0) const;
427 //template <class T> T Eval(T x, T y = 0, T z = 0, T t = 0) const;
428 virtual Double_t EvalPar(const Double_t *x, const Double_t *params = 0);
429 template <class T> T EvalPar(const T *x, const Double_t *params = 0);
430 virtual Double_t operator()(Double_t x, Double_t y = 0, Double_t z = 0, Double_t t = 0) const;
431 template <class T> T operator()(const T *x, const Double_t *params = nullptr);
432 virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
433 virtual void FixParameter(Int_t ipar, Double_t value);
435 {
436 return (fType == EFType::kTemplVec) || (fType == EFType::kFormula && fFormula && fFormula->IsVectorized());
437 }
439 {
440 return fChisquare;
441 }
442 virtual TH1 *GetHistogram() const;
444 {
446 }
448 {
449 return fFormula;
450 }
451 virtual const TFormula *GetFormula() const
452 {
453 return fFormula;
454 }
455 virtual TString GetExpFormula(Option_t *option = "") const
456 {
457 return (fFormula) ? fFormula->GetExpFormula(option) : "";
458 }
459 virtual const TObject *GetLinearPart(Int_t i) const
460 {
461 return (fFormula) ? fFormula->GetLinearPart(i) : nullptr;
462 }
463 virtual Double_t GetMaximum(Double_t xmin = 0, Double_t xmax = 0, Double_t epsilon = 1.E-10, Int_t maxiter = 100, Bool_t logx = false) const;
464 virtual Double_t GetMinimum(Double_t xmin = 0, Double_t xmax = 0, Double_t epsilon = 1.E-10, Int_t maxiter = 100, Bool_t logx = false) const;
465 virtual Double_t GetMaximumX(Double_t xmin = 0, Double_t xmax = 0, Double_t epsilon = 1.E-10, Int_t maxiter = 100, Bool_t logx = false) const;
466 virtual Double_t GetMinimumX(Double_t xmin = 0, Double_t xmax = 0, Double_t epsilon = 1.E-10, Int_t maxiter = 100, Bool_t logx = false) const;
468 {
469 return fMaximum;
470 }
472 {
473 return fMinimum;
474 }
475 virtual Int_t GetNpar() const
476 {
477 return fNpar;
478 }
479 virtual Int_t GetNdim() const
480 {
481 return fNdim;
482 }
483 virtual Int_t GetNDF() const;
484 virtual Int_t GetNpx() const
485 {
486 return fNpx;
487 }
489 {
490 return fMethodCall;
491 }
492 virtual Int_t GetNumber() const
493 {
494 return (fFormula) ? fFormula->GetNumber() : 0;
495 }
496 virtual Int_t GetNumberFreeParameters() const;
497 virtual Int_t GetNumberFitPoints() const
498 {
499 return fNpfits;
500 }
501 virtual char *GetObjectInfo(Int_t px, Int_t py) const;
503 {
504 return fParent;
505 }
506 virtual Double_t GetParameter(Int_t ipar) const
507 {
508 return (fFormula) ? fFormula->GetParameter(ipar) : fParams->GetParameter(ipar);
509 }
510 virtual Double_t GetParameter(const TString &name) const
511 {
513 }
514 virtual Double_t *GetParameters() const
515 {
516 return (fFormula) ? fFormula->GetParameters() : const_cast<Double_t *>(fParams->GetParameters());
517 }
518 virtual void GetParameters(Double_t *params)
519 {
520 if (fFormula) fFormula->GetParameters(params);
521 else std::copy(fParams->ParamsVec().begin(), fParams->ParamsVec().end(), params);
522 }
523 virtual const char *GetParName(Int_t ipar) const
524 {
525 return (fFormula) ? fFormula->GetParName(ipar) : fParams->GetParName(ipar);
526 }
527 virtual Int_t GetParNumber(const char *name) const
528 {
530 }
531 virtual Double_t GetParError(Int_t ipar) const;
532 virtual const Double_t *GetParErrors() const
533 {
534 return fParErrors.data();
535 }
536 virtual void GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const;
537 virtual Double_t GetProb() const;
538 virtual Int_t GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum);
539 virtual Double_t GetRandom();
541 virtual void GetRange(Double_t &xmin, Double_t &xmax) const;
542 virtual void GetRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const;
543 virtual void GetRange(Double_t &xmin, Double_t &ymin, Double_t &zmin, Double_t &xmax, Double_t &ymax, Double_t &zmax) const;
544 virtual Double_t GetSave(const Double_t *x);
545 virtual Double_t GetX(Double_t y, Double_t xmin = 0, Double_t xmax = 0, Double_t epsilon = 1.E-10, Int_t maxiter = 100, Bool_t logx = false) const;
546 virtual Double_t GetXmin() const
547 {
548 return fXmin;
549 }
550 virtual Double_t GetXmax() const
551 {
552 return fXmax;
553 }
554 TAxis *GetXaxis() const ;
555 TAxis *GetYaxis() const ;
556 TAxis *GetZaxis() const ;
558 {
559 return (fFormula) ? fFormula->GetVariable(name) : 0;
560 }
561 virtual Double_t GradientPar(Int_t ipar, const Double_t *x, Double_t eps = 0.01);
562 template <class T>
563 T GradientPar(Int_t ipar, const T *x, Double_t eps = 0.01);
564 template <class T>
565 T GradientParTempl(Int_t ipar, const T *x, Double_t eps = 0.01);
566
567 virtual void GradientPar(const Double_t *x, Double_t *grad, Double_t eps = 0.01);
568 template <class T>
569 void GradientPar(const T *x, T *grad, Double_t eps = 0.01);
570 template <class T>
571 void GradientParTempl(const T *x, T *grad, Double_t eps = 0.01);
572
573 virtual void InitArgs(const Double_t *x, const Double_t *params);
574 static void InitStandardFunctions();
575 virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel = 1.e-12);
576 virtual Double_t IntegralOneDim(Double_t a, Double_t b, Double_t epsrel, Double_t epsabs, Double_t &err);
577 virtual Double_t IntegralError(Double_t a, Double_t b, const Double_t *params = 0, const Double_t *covmat = 0, Double_t epsilon = 1.E-2);
578 virtual Double_t IntegralError(Int_t n, const Double_t *a, const Double_t *b, const Double_t *params = 0, const Double_t *covmat = 0, Double_t epsilon = 1.E-2);
579 // virtual Double_t IntegralFast(const TGraph *g, Double_t a, Double_t b, Double_t *params=0);
580 virtual Double_t IntegralFast(Int_t num, Double_t *x, Double_t *w, Double_t a, Double_t b, Double_t *params = 0, Double_t epsilon = 1e-12);
581 virtual Double_t IntegralMultiple(Int_t n, const Double_t *a, const Double_t *b, Int_t maxpts, Double_t epsrel, Double_t epsabs , Double_t &relerr, Int_t &nfnevl, Int_t &ifail);
582 virtual Double_t IntegralMultiple(Int_t n, const Double_t *a, const Double_t *b, Int_t /*minpts*/, Int_t maxpts, Double_t epsrel, Double_t &relerr, Int_t &nfnevl, Int_t &ifail)
583 {
584 return IntegralMultiple(n, a, b, maxpts, epsrel, epsrel, relerr, nfnevl, ifail);
585 }
586 virtual Double_t IntegralMultiple(Int_t n, const Double_t *a, const Double_t *b, Double_t epsrel, Double_t &relerr);
587 virtual Bool_t IsEvalNormalized() const
588 {
589 return fNormalized;
590 }
591 /// return kTRUE if the point is inside the function range
592 virtual Bool_t IsInside(const Double_t *x) const
593 {
594 return !((x[0] < fXmin) || (x[0] > fXmax));
595 }
596 virtual Bool_t IsLinear() const
597 {
598 return (fFormula) ? fFormula->IsLinear() : false;
599 }
600 virtual Bool_t IsValid() const;
601 virtual void Print(Option_t *option = "") const;
602 virtual void Paint(Option_t *option = "");
603 virtual void ReleaseParameter(Int_t ipar);
605 virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
606 virtual void SetChisquare(Double_t chi2)
607 {
608 fChisquare = chi2;
609 }
610 virtual void SetFitResult(const ROOT::Fit::FitResult &result, const Int_t *indpar = 0);
611 template <class PtrObj, typename MemFn>
612 void SetFunction(PtrObj &p, MemFn memFn);
613 template <typename Func>
614 void SetFunction(Func f);
615 virtual void SetMaximum(Double_t maximum = -1111); // *MENU*
616 virtual void SetMinimum(Double_t minimum = -1111); // *MENU*
617 virtual void SetNDF(Int_t ndf);
618 virtual void SetNumberFitPoints(Int_t npfits)
619 {
620 fNpfits = npfits;
621 }
622 virtual void SetNormalized(Bool_t flag)
623 {
624 fNormalized = flag;
625 Update();
626 }
627 virtual void SetNpx(Int_t npx = 100); // *MENU*
628 virtual void SetParameter(Int_t param, Double_t value)
629 {
630 (fFormula) ? fFormula->SetParameter(param, value) : fParams->SetParameter(param, value);
631 Update();
632 }
633 virtual void SetParameter(const TString &name, Double_t value)
634 {
636 Update();
637 }
638 virtual void SetParameters(const Double_t *params)
639 {
640 (fFormula) ? fFormula->SetParameters(params) : fParams->SetParameters(params);
641 Update();
642 }
643 virtual void SetParameters(Double_t p0, Double_t p1, Double_t p2 = 0, Double_t p3 = 0, Double_t p4 = 0,
644 Double_t p5 = 0, Double_t p6 = 0, Double_t p7 = 0, Double_t p8 = 0,
645 Double_t p9 = 0, Double_t p10 = 0)
646 {
647 if (fFormula) fFormula->SetParameters(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
648 else fParams->SetParameters(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
649 Update();
650 } // *MENU*
651 virtual void SetParName(Int_t ipar, const char *name);
652 virtual void SetParNames(const char *name0 = "p0", const char *name1 = "p1", const char *name2 = "p2",
653 const char *name3 = "p3", const char *name4 = "p4", const char *name5 = "p5",
654 const char *name6 = "p6", const char *name7 = "p7", const char *name8 = "p8",
655 const char *name9 = "p9", const char *name10 = "p10"); // *MENU*
656 virtual void SetParError(Int_t ipar, Double_t error);
657 virtual void SetParErrors(const Double_t *errors);
658 virtual void SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax);
659 virtual void SetParent(TObject *p = 0)
660 {
661 fParent = p;
662 }
663 virtual void SetRange(Double_t xmin, Double_t xmax); // *MENU*
666 virtual void SetSavedPoint(Int_t point, Double_t value);
667 virtual void SetTitle(const char *title = ""); // *MENU*
668 virtual void SetVectorized(Bool_t vectorized)
669 {
670 if (fType == EFType::kFormula && fFormula)
671 fFormula->SetVectorized(vectorized);
672 else
673 Warning("SetVectorized", "Can only set vectorized flag on formula-based TF1");
674 }
675 virtual void Update();
676
677 static TF1 *GetCurrent();
678 static void AbsValue(Bool_t reject = kTRUE);
679 static void RejectPoint(Bool_t reject = kTRUE);
680 static Bool_t RejectedPoint();
681 static void SetCurrent(TF1 *f1);
682
683 //Moments
684 virtual Double_t Moment(Double_t n, Double_t a, Double_t b, const Double_t *params = 0, Double_t epsilon = 0.000001);
685 virtual Double_t CentralMoment(Double_t n, Double_t a, Double_t b, const Double_t *params = 0, Double_t epsilon = 0.000001);
686 virtual Double_t Mean(Double_t a, Double_t b, const Double_t *params = 0, Double_t epsilon = 0.000001)
687 {
688 return Moment(1, a, b, params, epsilon);
689 }
690 virtual Double_t Variance(Double_t a, Double_t b, const Double_t *params = 0, Double_t epsilon = 0.000001)
691 {
692 return CentralMoment(2, a, b, params, epsilon);
693 }
694
695 //some useful static utility functions to compute sampling points for Integral
696 //static void CalcGaussLegendreSamplingPoints(TGraph *g, Double_t eps=3.0e-11);
697 //static TGraph *CalcGaussLegendreSamplingPoints(Int_t num=21, Double_t eps=3.0e-11);
698 static void CalcGaussLegendreSamplingPoints(Int_t num, Double_t *x, Double_t *w, Double_t eps = 3.0e-11);
699
700private:
701 template <class T>
702 T EvalParTempl(const T *data, const Double_t *params = 0);
703
704#ifdef R__HAS_VECCORE
705 inline double EvalParVec(const Double_t *data, const Double_t *params);
706#endif
707
708 ClassDef(TF1, 10) // The Parametric 1-D function
709};
710
711namespace ROOT {
712 namespace Internal {
713
714 template<class Func>
715 void TF1Builder<Func>::Build(TF1 *f, Func func)
716 {
717 using Fnc_t = typename ROOT::Internal::GetFunctorType<decltype(ROOT::Internal::GetTheRightOp(&Func::operator()))>::type;
718 f->fType = std::is_same<Fnc_t, double>::value? TF1::EFType::kTemplScalar : TF1::EFType::kTemplVec;
720 f->fParams = new TF1Parameters(f->fNpar);
721 }
722
723 template<class Func>
724 void TF1Builder<Func *>::Build(TF1 *f, Func *func)
725 {
726 using Fnc_t = typename ROOT::Internal::GetFunctorType<decltype(ROOT::Internal::GetTheRightOp(&Func::operator()))>::type;
727 f->fType = std::is_same<Fnc_t, double>::value? TF1::EFType::kTemplScalar : TF1::EFType::kTemplVec;
729 f->fParams = new TF1Parameters(f->fNpar);
730 }
731
732 /// TF1 building from a string
733 /// used to build a TFormula based on a lambda function
734 template<>
735 struct TF1Builder<const char *> {
736 static void Build(TF1 *f, const char *formula)
737 {
738 f->fType = TF1::EFType::kFormula;
739 f->fFormula = new TFormula("tf1lambda", formula, f->fNdim, f->fNpar, false);
740 TString formulaExpression(formula);
741 Ssiz_t first = formulaExpression.Index("return") + 7;
742 Ssiz_t last = formulaExpression.Last(';');
743 TString title = formulaExpression(first, last - first);
744 f->SetTitle(title);
745 }
746 };
747 }
748}
749
751{
752 return Eval(x, y, z, t);
753}
754
755template <class T>
756inline T TF1::operator()(const T *x, const Double_t *params)
757{
758 return EvalPar(x, params);
759}
760
761////////////////////////////////////////////////////////////////////////////////
762/// EvalPar for vectorized
763template <class T>
764T TF1::EvalPar(const T *x, const Double_t *params)
765{
766 if (fType == EFType::kTemplVec || fType == EFType::kTemplScalar) {
767 return EvalParTempl(x, params);
768 } else if (fType == EFType::kFormula) {
769 return fFormula->EvalPar(x, params);
770 } else
771 return TF1::EvalPar((double *)x, params);
772}
773
774////////////////////////////////////////////////////////////////////////////////
775/// Eval for vectorized functions
776// template <class T>
777// T TF1::Eval(T x, T y, T z, T t) const
778// {
779// if (fType == EFType::kFormula)
780// return fFormula->Eval(x, y, z, t);
781
782// T xx[] = {x, y, z, t};
783// Double_t *pp = (Double_t *)fParams->GetParameters();
784// return ((TF1 *)this)->EvalPar(xx, pp);
785// }
786
787// Internal to TF1. Evaluates Templated interfaces
788template <class T>
789inline T TF1::EvalParTempl(const T *data, const Double_t *params)
790{
791 assert(fType == EFType::kTemplScalar || fType == EFType::kTemplVec);
792 if (!params) params = (Double_t *)fParams->GetParameters();
793 if (fFunctor)
794 return ((TF1FunctorPointerImpl<T> *)fFunctor)->fImpl(data, params);
795
796 // this should throw an error
797 // we nned to implement a vectorized GetSave(x)
798 return TMath::SignalingNaN();
799}
800
801#ifdef R__HAS_VECCORE
802// Internal to TF1. Evaluates Vectorized TF1 on data of type Double_v
803inline double TF1::EvalParVec(const Double_t *data, const Double_t *params)
804{
805 assert(fType == EFType::kTemplVec);
806 std::vector<ROOT::Double_v> d(fNdim);
807 ROOT::Double_v res;
808
809 for(auto i=0; i<fNdim; i++) {
810 d[i] = ROOT::Double_v(data[i]);
811 }
812
813 if (fFunctor) {
814 res = ((TF1FunctorPointerImpl<ROOT::Double_v> *) fFunctor)->fImpl(d.data(), params);
815 } else {
816 // res = GetSave(x);
817 return TMath::SignalingNaN();
818 }
819 return vecCore::Get<ROOT::Double_v>(res, 0);
820}
821#endif
822
824{
826}
828{
830}
831
832template <typename Func>
834{
835 // set function from a generic C++ callable object
836 fType = EFType::kPtrScalarFreeFcn;
838}
839template <class PtrObj, typename MemFn>
840void TF1::SetFunction(PtrObj &p, MemFn memFn)
841{
842 // set from a pointer to a member function
843 fType = EFType::kPtrScalarFreeFcn;
845}
846
847template <class T>
848inline T TF1::GradientPar(Int_t ipar, const T *x, Double_t eps)
849{
850 if (fType == EFType::kTemplVec || fType == EFType::kTemplScalar) {
851 return GradientParTempl<T>(ipar, x, eps);
852 } else
853 return GradientParTempl<Double_t>(ipar, (const Double_t *)x, eps);
854}
855
856template <class T>
857inline T TF1::GradientParTempl(Int_t ipar, const T *x, Double_t eps)
858{
859 if (GetNpar() == 0)
860 return 0;
861
862 if (eps < 1e-10 || eps > 1) {
863 Warning("Derivative", "parameter esp=%g out of allowed range[1e-10,1], reset to 0.01", eps);
864 eps = 0.01;
865 }
866 Double_t h;
867 TF1 *func = (TF1 *)this;
868 Double_t *parameters = GetParameters();
869
870 // Copy parameters for thread safety
871 std::vector<Double_t> parametersCopy(parameters, parameters + GetNpar());
872 parameters = parametersCopy.data();
873
874 Double_t al, bl, h2;
875 T f1, f2, g1, g2, d0, d2;
876
877 ((TF1 *)this)->GetParLimits(ipar, al, bl);
878 if (al * bl != 0 && al >= bl) {
879 // this parameter is fixed
880 return 0;
881 }
882
883 // check if error has been computer (is not zero)
884 if (func->GetParError(ipar) != 0)
885 h = eps * func->GetParError(ipar);
886 else
887 h = eps;
888
889 // save original parameters
890 Double_t par0 = parameters[ipar];
891
892 parameters[ipar] = par0 + h;
893 f1 = func->EvalPar(x, parameters);
894 parameters[ipar] = par0 - h;
895 f2 = func->EvalPar(x, parameters);
896 parameters[ipar] = par0 + h / 2;
897 g1 = func->EvalPar(x, parameters);
898 parameters[ipar] = par0 - h / 2;
899 g2 = func->EvalPar(x, parameters);
900
901 // compute the central differences
902 h2 = 1 / (2. * h);
903 d0 = f1 - f2;
904 d2 = 2 * (g1 - g2);
905
906 T grad = h2 * (4 * d2 - d0) / 3.;
907
908 // restore original value
909 parameters[ipar] = par0;
910
911 return grad;
912}
913
914template <class T>
915inline void TF1::GradientPar(const T *x, T *grad, Double_t eps)
916{
917 if (fType == EFType::kTemplVec || fType == EFType::kTemplScalar) {
918 GradientParTempl<T>(x, grad, eps);
919 } else
920 GradientParTempl<Double_t>((const Double_t *)x, (Double_t *)grad, eps);
921}
922
923template <class T>
924inline void TF1::GradientParTempl(const T *x, T *grad, Double_t eps)
925{
926 if (eps < 1e-10 || eps > 1) {
927 Warning("Derivative", "parameter esp=%g out of allowed range[1e-10,1], reset to 0.01", eps);
928 eps = 0.01;
929 }
930
931 for (Int_t ipar = 0; ipar < GetNpar(); ipar++) {
932 grad[ipar] = GradientParTempl<T>(ipar, x, eps);
933 }
934}
935
936#endif
#define d(i)
Definition: RSha256.hxx:102
#define b(i)
Definition: RSha256.hxx:100
#define f(i)
Definition: RSha256.hxx:104
#define h(i)
Definition: RSha256.hxx:106
#define e(i)
Definition: RSha256.hxx:103
int Int_t
Definition: RtypesCore.h:41
int Ssiz_t
Definition: RtypesCore.h:63
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:326
#define BIT(n)
Definition: Rtypes.h:83
char name[80]
Definition: TGX11.cxx:109
int type
Definition: TGX11.cxx:120
float xmin
Definition: THbookFile.cxx:93
float * q
Definition: THbookFile.cxx:87
float ymin
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
float ymax
Definition: THbookFile.cxx:93
@ kDefault
Definition: TSystem.h:231
class containg the result of the fit and all the related information (fitted parameter values,...
Definition: FitResult.h:48
Param Functor class for Multidimensional functions.
Definition: ParamFunctor.h:274
Fill Area Attributes class.
Definition: TAttFill.h:19
Line Attributes class.
Definition: TAttLine.h:18
Marker Attributes class.
Definition: TAttMarker.h:19
Class to manage histogram axis.
Definition: TAxis.h:30
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
TF1 Parameters class.
Definition: TF1.h:48
std::vector< Double_t > fParameters
Definition: TF1.h:138
const char * GetParName(Int_t iparam) const
Definition: TF1.h:94
const std::vector< double > & ParamsVec() const
Definition: TF1.h:87
virtual ~TF1Parameters()
Definition: TF1.h:72
Double_t GetParameter(const char *name) const
Definition: TF1.h:79
Double_t GetParameter(Int_t iparam) const
Definition: TF1.h:75
void SetParName(Int_t iparam, const char *name)
Definition: TF1.h:118
void SetParNames(const char *name0="p0", const char *name1="p1", const char *name2="p2", const char *name3="p3", const char *name4="p4", const char *name5="p5", const char *name6="p6", const char *name7="p7", const char *name8="p8", const char *name9="p9", const char *name10="p10")
Set parameter names.
Definition: TF1.cxx:3845
TF1Parameters & operator=(const TF1Parameters &rhs)
Definition: TF1.h:65
void SetParameter(Int_t iparam, Double_t value)
Definition: TF1.h:101
void SetParameter(const char *name, Double_t value)
Definition: TF1.h:114
TF1Parameters(Int_t npar)
Definition: TF1.h:51
std::vector< std::string > fParNames
Definition: TF1.h:139
TF1Parameters()
Definition: TF1.h:50
bool CheckIndex(Int_t i) const
Definition: TF1.h:133
void SetParameters(const Double_t *params)
Definition: TF1.h:106
Int_t GetParNumber(const char *name) const
Returns the parameter number given a name not very efficient but list of parameters is typically smal...
Definition: TF1.cxx:3813
TF1Parameters(const TF1Parameters &rhs)
Definition: TF1.h:60
const Double_t * GetParameters() const
Definition: TF1.h:83
1-Dim function class
Definition: TF1.h:211
virtual Double_t GetMinimumX(Double_t xmin=0, Double_t xmax=0, Double_t epsilon=1.E-10, Int_t maxiter=100, Bool_t logx=false) const
Returns the X value corresponding to the minimum value of the function on the (xmin,...
Definition: TF1.cxx:1803
virtual Double_t GetMinimum(Double_t xmin=0, Double_t xmax=0, Double_t epsilon=1.E-10, Int_t maxiter=100, Bool_t logx=false) const
Returns the minimum value of the function on the (xmin, xmax) interval.
Definition: TF1.cxx:1676
virtual Double_t GetXmax() const
Definition: TF1.h:550
virtual void ReleaseParameter(Int_t ipar)
Release parameter number ipar If used in a fit, the parameter can vary freely.
Definition: TF1.cxx:3123
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Redefines TObject::GetObjectInfo.
Definition: TF1.cxx:1898
virtual void SetParError(Int_t ipar, Double_t error)
Set error for parameter number ipar.
Definition: TF1.cxx:3472
TF1AbsComposition * fComposition_ptr
Pointer to composition (NSUM or CONV)
Definition: TF1.h:269
static void RejectPoint(Bool_t reject=kTRUE)
Static function to set the global flag to reject points the fgRejectPoint global flag is tested by al...
Definition: TF1.cxx:3650
EAddToList
Definition: TF1.h:218
virtual const Double_t * GetParErrors() const
Definition: TF1.h:532
virtual Int_t GetNumber() const
Definition: TF1.h:492
virtual Int_t GetNDF() const
Return the number of degrees of freedom in the fit the fNDF parameter has been previously computed du...
Definition: TF1.cxx:1869
std::vector< Double_t > fParErrors
Definition: TF1.h:252
Int_t fNdim
Definition: TF1.h:244
static void CalcGaussLegendreSamplingPoints(Int_t num, Double_t *x, Double_t *w, Double_t eps=3.0e-11)
Type safe interface (static method) The number of sampling points are taken from the TGraph.
Definition: TF1.cxx:3793
static void AbsValue(Bool_t reject=kTRUE)
Static function: set the fgAbsValue flag.
Definition: TF1.cxx:974
virtual TH1 * GetHistogram() const
Return a pointer to the histogram used to visualise the function.
Definition: TF1.cxx:1564
virtual const TFormula * GetFormula() const
Definition: TF1.h:451
virtual void GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const
Return limits for parameter ipar.
Definition: TF1.cxx:1920
virtual Double_t Derivative2(Double_t x, Double_t *params=0, Double_t epsilon=0.001) const
Returns the second derivative of the function at point x, computed by Richardson's extrapolation meth...
Definition: TF1.cxx:1162
Int_t fNpar
Definition: TF1.h:243
TMethodCall * fMethodCall
Pointer to histogram used for visualisation.
Definition: TF1.h:262
virtual Double_t GetParameter(const TString &name) const
Definition: TF1.h:510
TAxis * GetYaxis() const
Get y axis of the function.
Definition: TF1.cxx:2393
virtual void GetParameters(Double_t *params)
Definition: TF1.h:518
virtual void SetNDF(Int_t ndf)
Set the number of degrees of freedom ndf should be the number of points used in a fit - the number of...
Definition: TF1.cxx:3418
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
Definition: TF1.cxx:1910
static std::atomic< Bool_t > fgAddToGlobList
Definition: TF1.h:303
virtual Bool_t IsEvalNormalized() const
Definition: TF1.h:587
virtual Double_t GetVariable(const TString &name)
Definition: TF1.h:557
virtual Double_t Moment(Double_t n, Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001)
Return nth moment of function between a and b.
Definition: TF1.cxx:3669
virtual void SetChisquare(Double_t chi2)
Definition: TF1.h:606
Double_t fNormIntegral
Definition: TF1.h:264
Double_t GetChisquare() const
Definition: TF1.h:438
virtual void SetMaximum(Double_t maximum=-1111)
Set the maximum value along Y for this function In case the function is already drawn,...
Definition: TF1.cxx:3393
T GradientParTempl(Int_t ipar, const T *x, Double_t eps=0.01)
Definition: TF1.h:857
virtual TH1 * CreateHistogram()
Definition: TF1.h:443
Double_t fXmin
Definition: TF1.h:241
virtual void Copy(TObject &f1) const
Copy this F1 to a new F1.
Definition: TF1.cxx:995
virtual void Update()
Called by functions such as SetRange, SetNpx, SetParameters to force the deletion of the associated h...
Definition: TF1.cxx:3615
virtual Double_t GetProb() const
Return the fit probability.
Definition: TF1.cxx:1935
void IntegrateForNormalization()
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)
Definition: TF1.h:332
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...
Definition: TF1.cxx:3548
virtual void SetFitResult(const ROOT::Fit::FitResult &result, const Int_t *indpar=0)
Set the result from the fit parameter values, errors, chi2, etc... Optionally a pointer to a vector (...
Definition: TF1.cxx:3354
virtual Double_t GradientPar(Int_t ipar, const Double_t *x, Double_t eps=0.01)
Compute the gradient (derivative) wrt a parameter ipar.
Definition: TF1.cxx:2427
TAxis * GetZaxis() const
Get z axis of the function. (In case this object is a TF2 or TF3)
Definition: TF1.cxx:2404
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition: TF1.cxx:3518
virtual Double_t Mean(Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001)
Definition: TF1.h:686
virtual void SetParent(TObject *p=0)
Definition: TF1.h:659
virtual Double_t GetMaximumStored() const
Definition: TF1.h:467
virtual Int_t GetNpar() const
Definition: TF1.h:475
virtual TString GetExpFormula(Option_t *option="") const
Definition: TF1.h:455
std::vector< Double_t > fBeta
Array alpha. for each bin in x the deconvolution r of fIntegral.
Definition: TF1.h:258
Int_t fNDF
Definition: TF1.h:248
TH1 * fHistogram
Parent object hooking this function (if one)
Definition: TF1.h:261
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)
Definition: TF1.h:582
std::unique_ptr< TF1AbsComposition > fComposition
Definition: TF1.h:268
virtual void SetParErrors(const Double_t *errors)
Set errors for all active parameters when calling this function, the array errors must have at least ...
Definition: TF1.cxx:3483
virtual TH1 * DoCreateHistogram(Double_t xmin, Double_t xmax, Bool_t recreate=kFALSE)
Create histogram with bin content equal to function value computed at the bin center This histogram w...
Definition: TF1.cxx:3022
virtual Double_t CentralMoment(Double_t n, Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001)
Return nth central moment of function between a and b (i.e the n-th moment around the mean value)
Definition: TF1.cxx:3706
TObject * GetParent() const
Definition: TF1.h:502
Int_t fNpfits
Definition: TF1.h:247
virtual Double_t Variance(Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001)
Definition: TF1.h:690
static void SetCurrent(TF1 *f1)
Static function setting the current function.
Definition: TF1.cxx:3342
void SetFunction(PtrObj &p, MemFn memFn)
Definition: TF1.h:840
std::vector< Double_t > fAlpha
Integral of function binned on fNpx bins.
Definition: TF1.h:257
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)
Definition: TF1.h:398
virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel=1.e-12)
IntegralOneDim or analytical integral.
Definition: TF1.cxx:2502
virtual Double_t Derivative(Double_t x, Double_t *params=0, Double_t epsilon=0.001) const
Returns the first derivative of the function at point x, computed by Richardson's extrapolation metho...
Definition: TF1.cxx:1097
virtual Int_t GetNumberFitPoints() const
Definition: TF1.h:497
static Double_t DerivativeError()
Static function returning the error of the last call to the of Derivative's functions.
Definition: TF1.cxx:1261
virtual void Paint(Option_t *option="")
Paint this function with its current attributes.
Definition: TF1.cxx:2923
std::vector< Double_t > fParMin
Definition: TF1.h:253
static void InitStandardFunctions()
Create the basic function objects.
Definition: TF1.cxx:2469
Double_t fMaximum
Definition: TF1.h:251
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition: TF1.cxx:3432
virtual Double_t * GetParameters() const
Definition: TF1.h:514
Double_t fMinimum
Definition: TF1.h:250
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a function.
Definition: TF1.cxx:1277
int TermCoeffLength(TString &term)
Definition: TF1.cxx:909
static Bool_t fgRejectPoint
Definition: TF1.h:302
virtual ~TF1()
TF1 default destructor.
Definition: TF1.cxx:939
virtual void SetNumberFitPoints(Int_t npfits)
Definition: TF1.h:618
virtual Double_t GetMinimumStored() const
Definition: TF1.h:471
virtual void SetNormalized(Bool_t flag)
Definition: TF1.h:622
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=0)
Evaluate function with given coordinates and parameters.
Definition: TF1.cxx:1458
TF1 & operator=(const TF1 &rhs)
Operator =.
Definition: TF1.cxx:927
virtual Int_t GetNumberFreeParameters() const
Return the number of free parameters.
Definition: TF1.cxx:1880
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)
Definition: TF1.h:392
Double_t fChisquare
Definition: TF1.h:249
@ kNotGlobal
Definition: TF1.h:320
@ kNotDraw
Definition: TF1.h:321
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TF1.cxx:3186
virtual TFormula * GetFormula()
Definition: TF1.h:447
virtual void InitArgs(const Double_t *x, const Double_t *params)
Initialize parameters addresses.
Definition: TF1.cxx:2454
TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar, const char *, EAddToList addToGlobList=EAddToList::kDefault)
Definition: TF1.h:376
virtual Double_t IntegralMultiple(Int_t n, const Double_t *a, const Double_t *b, Int_t maxpts, Double_t epsrel, Double_t epsabs, Double_t &relerr, Int_t &nfnevl, Int_t &ifail)
This function computes, to an attempted specified accuracy, the value of the integral.
Definition: TF1.cxx:2821
TMethodCall * GetMethodCall() const
Definition: TF1.h:488
virtual Double_t operator()(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Definition: TF1.h:750
EFType fType
Definition: TF1.h:246
Bool_t fNormalized
Pointer to MethodCall in case of interpreted function.
Definition: TF1.h:263
TF1FunctorPointer * fFunctor
Definition: TF1.h:265
virtual void SetMinimum(Double_t minimum=-1111)
Set the minimum value along Y for this function In case the function is already drawn,...
Definition: TF1.cxx:3406
virtual void AddParameter(const TString &name, Double_t value)
Definition: TF1.h:405
virtual void GetRange(Double_t *xmin, Double_t *xmax) const
Return range of a generic N-D function.
Definition: TF1.cxx:2263
virtual void Print(Option_t *option="") const
Print TNamed name and title.
Definition: TF1.cxx:2867
TFormula * fFormula
Functor object to wrap any C++ callable object.
Definition: TF1.h:266
virtual Double_t IntegralFast(Int_t num, Double_t *x, Double_t *w, Double_t a, Double_t b, Double_t *params=0, Double_t epsilon=1e-12)
Gauss-Legendre integral, see CalcGaussLegendreSamplingPoints.
Definition: TF1.cxx:2748
virtual const char * GetParName(Int_t ipar) const
Definition: TF1.h:523
static TF1 * fgCurrent
Definition: TF1.h:304
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.
Definition: TF1.h:272
Int_t fNpx
Definition: TF1.h:245
virtual void SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax)
Set limits for parameter ipar.
Definition: TF1.cxx:3497
void DoInitialize(EAddToList addToGlobList)
Common initialization of the TF1.
Definition: TF1.cxx:787
virtual Double_t GetX(Double_t y, Double_t xmin=0, Double_t xmax=0, Double_t epsilon=1.E-10, Int_t maxiter=100, Bool_t logx=false) const
Returns the X value corresponding to the function value fy for (xmin<x<xmax).
Definition: TF1.cxx:1843
static TF1 * GetCurrent()
Static function returning the current function being processed.
Definition: TF1.cxx:1554
virtual Int_t GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum)
Compute Quantiles for density distribution of this function.
Definition: TF1.cxx:1973
virtual void SetParName(Int_t ipar, const char *name)
Set name of parameter number ipar.
Definition: TF1.cxx:3449
virtual Double_t GetSave(const Double_t *x)
Get value corresponding to X in array of fSave values.
Definition: TF1.cxx:2326
static std::atomic< Bool_t > fgAbsValue
Definition: TF1.h:301
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1317
virtual Bool_t IsLinear() const
Definition: TF1.h:596
virtual Double_t GetRandom()
Return a random number following this function shape.
Definition: TF1.cxx:2074
TF1()
TF1 default constructor.
Definition: TF1.cxx:491
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes.
Definition: TF1.cxx:1347
std::vector< Double_t > fParMax
Definition: TF1.h:254
bool IsVectorized()
Definition: TF1.h:434
virtual Bool_t IsValid() const
Return kTRUE if the function is valid.
Definition: TF1.cxx:2852
static Bool_t DefaultAddToGlobalList(Bool_t on=kTRUE)
Static method to add/avoid to add automatically functions to the global list (gROOT->GetListOfFunctio...
Definition: TF1.cxx:823
std::vector< Double_t > fSave
Definition: TF1.h:255
static Bool_t RejectedPoint()
See TF1::RejectPoint above.
Definition: TF1.cxx:3659
void DefineNSUMTerm(TObjArray *newFuncs, TObjArray *coeffNames, TString &fullFormula, TString &formula, int termStart, int termEnd, Double_t xmin, Double_t xmax)
Helper functions for NSUM parsing.
Definition: TF1.cxx:868
std::vector< Double_t > fGamma
Array beta. is approximated by x = alpha +beta*r *gamma*r**2.
Definition: TF1.h:259
TObject * fParent
Array gamma.
Definition: TF1.h:260
virtual Double_t GetMinMaxNDim(Double_t *x, Bool_t findmax, Double_t epsilon=0, Int_t maxiter=0) const
Find the minimum of a function of whatever dimension.
Definition: TF1.cxx:1703
virtual void DrawF1(Double_t xmin, Double_t xmax, Option_t *option="")
Draw function between xmin and xmax.
Definition: TF1.cxx:1410
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)
Definition: TF1.h:643
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:638
virtual TObject * DrawIntegral(Option_t *option="al")
Draw integral of this function.
Definition: TF1.cxx:1394
std::vector< Double_t > fIntegral
Definition: TF1.h:256
virtual void SetParNames(const char *name0="p0", const char *name1="p1", const char *name2="p2", const char *name3="p3", const char *name4="p4", const char *name5="p5", const char *name6="p6", const char *name7="p7", const char *name8="p8", const char *name9="p9", const char *name10="p10")
Set up to 10 parameter names.
Definition: TF1.cxx:3461
T EvalParTempl(const T *data, const Double_t *params=0)
Eval for vectorized functions.
Definition: TF1.h:789
virtual TObject * DrawDerivative(Option_t *option="al")
Draw derivative of this function.
Definition: TF1.cxx:1369
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Evaluate this function.
Definition: TF1.cxx:1429
virtual Double_t GetMaximum(Double_t xmin=0, Double_t xmax=0, Double_t epsilon=1.E-10, Int_t maxiter=100, Bool_t logx=false) const
Returns the maximum value of the function.
Definition: TF1.cxx:1594
virtual void SetParameter(const TString &name, Double_t value)
Definition: TF1.h:633
virtual void SetParameter(Int_t param, Double_t value)
Definition: TF1.h:628
virtual void Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax)
Save values of function in array fSave.
Definition: TF1.cxx:3133
EFType
Definition: TF1.h:232
@ kCompositionFcn
Definition: TF1.h:238
@ kFormula
Definition: TF1.h:233
@ kPtrScalarFreeFcn
Definition: TF1.h:234
@ kTemplScalar
Definition: TF1.h:237
@ kTemplVec
Definition: TF1.h:236
@ kInterpreted
Definition: TF1.h:235
virtual void SetSavedPoint(Int_t point, Double_t value)
Restore value of function saved at point.
Definition: TF1.cxx:3532
virtual void FixParameter(Int_t ipar, Double_t value)
Fix the value of a parameter The specified value will be used in a fit operation.
Definition: TF1.cxx:1542
virtual Bool_t IsInside(const Double_t *x) const
return kTRUE if the point is inside the function range
Definition: TF1.h:592
virtual Int_t GetNpx() const
Definition: TF1.h:484
Double_t fXmax
Definition: TF1.h:242
virtual Double_t GetMaximumX(Double_t xmin=0, Double_t xmax=0, Double_t epsilon=1.E-10, Int_t maxiter=100, Bool_t logx=false) const
Returns the X value corresponding to the maximum value of the function.
Definition: TF1.cxx:1635
TF1Parameters * fParams
Definition: TF1.h:267
virtual Int_t GetNdim() const
Definition: TF1.h:479
virtual Double_t GetXmin() const
Definition: TF1.h:546
virtual Double_t Derivative3(Double_t x, Double_t *params=0, Double_t epsilon=0.001) const
Returns the third derivative of the function at point x, computed by Richardson's extrapolation metho...
Definition: TF1.cxx:1227
virtual Bool_t AddToGlobalList(Bool_t on=kTRUE)
Add to global list of functions (gROOT->GetListOfFunctions() ) return previous status (true if the fu...
Definition: TF1.cxx:832
virtual const TObject * GetLinearPart(Int_t i) const
Definition: TF1.h:459
virtual void SetVectorized(Bool_t vectorized)
Definition: TF1.h:668
virtual Double_t IntegralOneDim(Double_t a, Double_t b, Double_t epsrel, Double_t epsabs, Double_t &err)
Return Integral of function between a and b using the given parameter values and relative and absolut...
Definition: TF1.cxx:2592
virtual void Browse(TBrowser *b)
Browse.
Definition: TF1.cxx:983
TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar, Int_t ndim=1, EAddToList addToGlobList=EAddToList::kDefault)
Definition: TF1.h:367
virtual Double_t GetParameter(Int_t ipar) const
Definition: TF1.h:506
virtual Double_t IntegralError(Double_t a, Double_t b, const Double_t *params=0, const Double_t *covmat=0, Double_t epsilon=1.E-2)
Return Error on Integral of a parametric function between a and b due to the parameter uncertainties.
Definition: TF1.cxx:2689
virtual Int_t GetParNumber(const char *name) const
Definition: TF1.h:527
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.
Definition: TF1.h:351
TAxis * GetXaxis() const
Get x axis of the function.
Definition: TF1.cxx:2382
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TF1.cxx:1526
The Formula class.
Definition: TFormula.h:84
Double_t GetParameter(const char *name) const
Returns parameter value given by string.
Definition: TFormula.cxx:2805
const TObject * GetLinearPart(Int_t i) const
Return linear part.
Definition: TFormula.cxx:2525
Bool_t IsLinear() const
Definition: TFormula.h:235
Int_t GetParNumber(const char *name) const
Return parameter index given a name (return -1 for not existing parameters) non need to print an erro...
Definition: TFormula.cxx:2793
Double_t * GetParameters() const
Definition: TFormula.cxx:2845
Double_t EvalPar(const Double_t *x, const Double_t *params=0) const
Definition: TFormula.cxx:3102
Double_t GetVariable(const char *name) const
Returns variable value.
Definition: TFormula.cxx:2658
void SetVectorized(Bool_t vectorized)
Definition: TFormula.cxx:3068
const char * GetParName(Int_t ipar) const
Return parameter name given by integer.
Definition: TFormula.cxx:2831
Int_t GetNumber() const
Definition: TFormula.h:223
void SetParameters(const Double_t *params)
Set a vector of parameters value.
Definition: TFormula.cxx:2942
void AddParameter(const TString &name, Double_t value=0)
Definition: TFormula.h:184
void SetParameter(const char *name, Double_t value)
Sets parameter value.
Definition: TFormula.cxx:2865
TString GetExpFormula(Option_t *option="") const
Return the expression formula.
Definition: TFormula.cxx:3486
Bool_t IsVectorized() const
Definition: TFormula.h:234
The TH1 histogram class.
Definition: TH1.h:56
Method or function calling interface.
Definition: TMethodCall.h:37
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
An array of TObjects.
Definition: TObjArray.h:37
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:866
EStatusBits
Definition: TObject.h:57
Basic string class.
Definition: TString.h:131
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition: TString.cxx:892
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition: TString.cxx:2311
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:634
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
TF1 * f1
Definition: legend1.C:11
#define F(x, y, z)
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:134
Namespace for new Math classes and functions.
auto GetTheRightOp(T(F::*opPtr)(const T *, const double *)) -> decltype(opPtr)
Definition: TF1.h:185
double T(double x)
Definition: ChebyshevPol.h:34
ParamFunctorTempl< double > ParamFunctor
Definition: ParamFunctor.h:388
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:151
VSD Structures.
Definition: StringConv.hxx:21
Double_t Double_v
Definition: Types.h:50
Double_t SignalingNaN()
Returns a signaling NaN as defined by IEEE 754](http://en.wikipedia.org/wiki/NaN#Signaling_NaN)
Definition: TMath.h:898
Definition: first.py:1
static void Build(TF1 *f, const char *formula)
Definition: TF1.h:736
Internal class used by TF1 for defining template specialization for different TF1 constructors.
Definition: TF1.h:147
static void Build(TF1 *f, Func func)
Definition: TF1.h:715
virtual TF1FunctorPointer * Clone() const
Definition: TF1.h:294
ROOT::Math::ParamFunctorTempl< T > fImpl
Definition: TF1.h:295
TF1FunctorPointerImpl(const std::function< T(const T *f, const Double_t *param)> &func)
Definition: TF1.h:292
TF1FunctorPointerImpl(const ROOT::Math::ParamFunctorTempl< T > &func)
Definition: TF1.h:291
virtual ~TF1FunctorPointerImpl()
Definition: TF1.h:293
virtual ~TF1FunctorPointer()
Definition: TF1.h:227
virtual TF1FunctorPointer * Clone() const =0
auto * a
Definition: textangle.C:12
REAL epsilon
Definition: triangle.c:617