Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <string>
28#include <vector>
29#include "TFormula.h"
30#include "TMethodCall.h"
31#include "TAttLine.h"
32#include "TAttFill.h"
33#include "TAttMarker.h"
34#include "TF1AbsComposition.h"
35#include "TMath.h"
36#include "Math/Types.h"
37#include "Math/ParamFunctor.h"
38
39class TF1;
40class TH1;
41class TAxis;
42class TRandom;
43
44namespace ROOT {
45 namespace Fit {
46 class FitResult;
47 }
48}
49
51public:
52 TF1Parameters() {} // needed for the I/O
54 fParameters(std::vector<Double_t>(npar)),
55 fParNames(std::vector<std::string>(npar))
56 {
57 for (int i = 0; i < npar; ++i) {
58 fParNames[i] = std::string(TString::Format("p%d", i).Data());
59 }
60 }
61 // copy constructor
65 {}
66 // assignment
68 {
69 if (&rhs == this) return *this;
71 fParNames = rhs.fParNames;
72 return *this;
73 }
74 virtual ~TF1Parameters() {}
75
76 // getter methods
78 {
79 return (CheckIndex(iparam)) ? fParameters[iparam] : 0;
80 }
81 Double_t GetParameter(const char *name) const
82 {
84 }
85 const Double_t *GetParameters() const
86 {
87 return fParameters.data();
88 }
89 const std::vector<double> &ParamsVec() const
90 {
91 return fParameters;
92 }
93
94 Int_t GetParNumber(const char *name) const;
95
96 const char *GetParName(Int_t iparam) const
97 {
98 return (CheckIndex(iparam)) ? fParNames[iparam].c_str() : "";
99 }
100
101
102 // setter methods
103 void SetParameter(Int_t iparam, Double_t value)
104 {
105 if (!CheckIndex(iparam)) return;
106 fParameters[iparam] = value;
107 }
108 void SetParameters(const Double_t *params)
109 {
110 std::copy(params, params + fParameters.size(), fParameters.begin());
111 }
112 void SetParameters(Double_t p0, Double_t p1, Double_t p2 = 0, Double_t p3 = 0, Double_t p4 = 0,
113 Double_t p5 = 0, Double_t p6 = 0, Double_t p7 = 0, Double_t p8 = 0,
114 Double_t p9 = 0, Double_t p10 = 0);
115
116 void SetParameter(const char *name, Double_t value)
117 {
119 }
120 void SetParName(Int_t iparam, const char *name)
121 {
122 if (!CheckIndex(iparam)) return;
123 fParNames[iparam] = std::string(name);
124 }
125 void SetParNames(const char *name0 = "p0", const char *name1 = "p1", const char *name2 = "p2",
126 const char *name3 = "p3", const char *name4 = "p4", const char *name5 = "p5",
127 const char *name6 = "p6", const char *name7 = "p7", const char *name8 = "p8",
128 const char *name9 = "p9", const char *name10 = "p10");
129
130
131
132 ClassDef(TF1Parameters, 1) // The Parameters of a parameteric function
133private:
134
135 bool CheckIndex(Int_t i) const
136 {
137 return (i >= 0 && i < int(fParameters.size()));
138 }
139
140 std::vector<Double_t> fParameters; // parameter values
141 std::vector<std::string> fParNames; // parameter names
142};
143
144namespace ROOT {
145 namespace Internal {
146 /// Internal class used by TF1 for defining
147 /// template specialization for different TF1 constructors
148 template<class Func>
149 struct TF1Builder {
150 static void Build(TF1 *f, Func func);
151 };
152
153 template<class Func>
154 struct TF1Builder<Func *> {
155 static void Build(TF1 *f, Func *func);
156 };
157
158 // Internal class used by TF1 for obtaining the type from a functor
159 // out of the set of valid operator() signatures.
160 template<typename T>
162 };
163
164 template<typename F, typename T>
165 struct GetFunctorType<T(F::*)(const T *, const double *)> {
166 using type = T;
167 };
168
169 template<typename F, typename T>
170 struct GetFunctorType<T(F::*)(const T *, const double *) const> {
171 using type = T;
172 };
173
174 template<typename F, typename T>
175 struct GetFunctorType<T(F::*)(T *, double *)> {
176 using type = T;
177 };
178
179 template<typename F, typename T>
180 struct GetFunctorType<T(F::*)(T *, double *) const> {
181 using type = T;
182 };
183
184 // Internal class used by TF1 to get the right operator() signature
185 // from a Functor with several ones.
186 template<typename T, typename F>
187 auto GetTheRightOp(T(F::*opPtr)(const T *, const double *)) -> decltype(opPtr)
188 {
189 return opPtr;
190 }
191
192 template<typename T, typename F>
193 auto GetTheRightOp(T(F::*opPtr)(const T *, const double *) const) -> decltype(opPtr)
194 {
195 return opPtr;
196 }
197
198 template<typename T, typename F>
199 auto GetTheRightOp(T(F::*opPtr)(T *, double *)) -> decltype(opPtr)
200 {
201 return opPtr;
202 }
203
204 template<typename T, typename F>
205 auto GetTheRightOp(T(F::*opPtr)(T *, double *) const) -> decltype(opPtr)
206 {
207 return opPtr;
208 }
209 }
210}
211
212
213class TF1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
214
215 template<class Func>
217
218public:
219 // Add to list behavior
220 enum class EAddToList {
221 kDefault,
222 kAdd,
223 kNo
224 };
225
226
229 virtual TF1FunctorPointer * Clone() const = 0;
230 };
231
232protected:
233
234 enum EFType {
235 kFormula = 0, // formula functions which can be stored,
236 kPtrScalarFreeFcn, // pointer to scalar free function,
237 kInterpreted, // interpreted functions constructed by name,
238 kTemplVec, // vectorized free functions or TemplScalar functors evaluating on vectorized parameters,
239 kTemplScalar, // TemplScalar functors evaluating on scalar parameters
241 }; // formula based on composition class (e.g. NSUM, CONV)
242
243 Double_t fXmin{-1111}; //Lower bounds for the range
244 Double_t fXmax{-1111}; //Upper bounds for the range
245 Int_t fNpar{}; //Number of parameters
246 Int_t fNdim{}; //Function dimension
247 Int_t fNpx{100}; //Number of points used for the graphical representation
249 Int_t fNpfits{}; //Number of points used in the fit
250 Int_t fNDF{}; //Number of degrees of freedom in the fit
251 Double_t fChisquare{}; //Function fit chisquare
252 Double_t fMinimum{-1111}; //Minimum value for plotting
253 Double_t fMaximum{-1111}; //Maximum value for plotting
254 std::vector<Double_t> fParErrors; //Array of errors of the fNpar parameters
255 std::vector<Double_t> fParMin; //Array of lower limits of the fNpar parameters
256 std::vector<Double_t> fParMax; //Array of upper limits of the fNpar parameters
257 std::vector<Double_t> fSave; //Array of fNsave function values
258 std::vector<Double_t> fIntegral; //!Integral of function binned on fNpx bins
259 std::vector<Double_t> fAlpha; //!Array alpha. for each bin in x the deconvolution r of fIntegral
260 std::vector<Double_t> fBeta; //!Array beta. is approximated by x = alpha +beta*r *gamma*r**2
261 std::vector<Double_t> fGamma; //!Array gamma.
262 TObject *fParent{nullptr}; //!Parent object hooking this function (if one)
263 TH1 *fHistogram{nullptr}; //!Pointer to histogram used for visualisation
264 std::unique_ptr<TMethodCall> fMethodCall; //!Pointer to MethodCall in case of interpreted function
265 Bool_t fNormalized{false}; //Normalization option (false by default)
266 Double_t fNormIntegral{}; //Integral of the function before being normalized
267 std::unique_ptr<TF1FunctorPointer> fFunctor; //! Functor object to wrap any C++ callable object
268 std::unique_ptr<TFormula> fFormula; //Pointer to TFormula in case when user define formula
269 std::unique_ptr<TF1Parameters> fParams; //Pointer to Function parameters object (exists only for not-formula functions)
270 std::unique_ptr<TF1AbsComposition> fComposition; //Pointer to composition (NSUM or CONV)
271
272 /// General constructor for TF1. Most of the other constructors delegate on it
273 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):
274 TNamed(name, name), TAttLine(), TAttFill(), TAttMarker(), fXmin(xmin), fXmax(xmax), fNpar(npar), fNdim(ndim),
275 fType(functionType), fParErrors(npar), fParMin(npar), fParMax(npar)
276 {
277 fParams.reset(params);
278 fFunctor.reset(functor);
279 DoInitialize(addToGlobList);
280 }
281
282private:
283 // NSUM parsing helper functions
284 void DefineNSUMTerm(TObjArray *newFuncs, TObjArray *coeffNames,
285 TString &fullFormula,
286 TString &formula, int termStart, int termEnd,
288 int TermCoeffLength(TString &term);
289
290protected:
291
292 template <class T>
295 TF1FunctorPointerImpl(const std::function<T(const T *f, const Double_t *param)> &func) : fImpl(func){};
297 virtual TF1FunctorPointer * Clone() const { return new TF1FunctorPointerImpl<T>(fImpl); }
299 };
300
301
302
303
304 static std::atomic<Bool_t> fgAbsValue; //use absolute value of function when computing integral
305 static Bool_t fgRejectPoint; //True if point must be rejected in a fit
306 static std::atomic<Bool_t> fgAddToGlobList; //True if we want to register the function in the global list
307 static TF1 *fgCurrent; //pointer to current function being processed
308
309
310 //void CreateFromFunctor(const char *name, Int_t npar, Int_t ndim = 1);
311 void DoInitialize(EAddToList addToGlobList);
312
314 // tabulate the cumulative function integral at fNpx points. Used by GetRandom
316
317 virtual Double_t GetMinMaxNDim(Double_t *x , Bool_t findmax, Double_t epsilon = 0, Int_t maxiter = 0) const;
318 virtual void GetRange(Double_t *xmin, Double_t *xmax) const;
320
321public:
322
323 // TF1 status bits
325 kNotGlobal = BIT(10), // don't register in global list of functions
326 kNotDraw = BIT(9) // don't draw the function when in a TH1
327 };
328
329 TF1();
330 TF1(const char *name, const char *formula, Double_t xmin = 0, Double_t xmax = 1, EAddToList addToGlobList = EAddToList::kDefault, bool vectorize = false);
331 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
332 TF1(const char *name, Double_t xmin, Double_t xmax, Int_t npar, Int_t ndim = 1, EAddToList addToGlobList = EAddToList::kDefault);
333 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);
334 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);
335
336 template <class T>
337 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):
338 TF1(EFType::kTemplScalar, name, xmin, xmax, npar, ndim, addToGlobList, new TF1Parameters(npar), new TF1FunctorPointerImpl<T>(fcn))
339 {
340 fType = std::is_same<T, double>::value ? TF1::EFType::kTemplScalar : TF1::EFType::kTemplVec;
341 }
342
343 ////////////////////////////////////////////////////////////////////////////////
344 /// Constructor using a pointer to function.
345 ///
346 /// \param npar is the number of free parameters used by the function
347 ///
348 /// This constructor creates a function of type C when invoked
349 /// with the normal C++ compiler.
350 ///
351 ///
352 /// WARNING! A function created with this constructor cannot be Cloned
353
354
355 template <class T>
356 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):
357 TF1(EFType::kTemplVec, name, xmin, xmax, npar, ndim, addToGlobList, new TF1Parameters(npar), new TF1FunctorPointerImpl<T>(fcn))
358 {}
359
360 // Constructors using functors (compiled mode only)
361 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);
362
363 // Template constructors from any C++ callable object, defining the operator() (double * , double *)
364 // and returning a double.
365 // The class name is not needed when using compile code, while it is required when using
366 // interpreted code via the specialized constructor with void *.
367 // An instance of the C++ function class or its pointer can both be used. The former is reccomended when using
368 // C++ compiled code, but if CINT compatibility is needed, then a pointer to the function class must be used.
369 // xmin and xmax specify the plotting range, npar is the number of parameters.
370 // See the tutorial math/exampleFunctor.C for an example of using this constructor
371 template <typename Func>
372 TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar, Int_t ndim = 1, EAddToList addToGlobList = EAddToList::kDefault) :
373 TF1(EFType::kTemplScalar, name, xmin, xmax, npar, ndim, addToGlobList)
374 {
375 //actual fType set in TF1Builder
377 }
378
379 // backward compatible interface
380 template <typename Func>
381 TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar, const char *, EAddToList addToGlobList = EAddToList::kDefault) :
382 TF1(EFType::kTemplScalar, name, xmin, xmax, npar, 1, addToGlobList, new TF1Parameters(npar))
383 {
385 }
386
387
388 // Template constructors from a pointer to any C++ class of type PtrObj with a specific member function of type
389 // MemFn.
390 // The member function must have the signature of (double * , double *) and returning a double.
391 // The class name and the method name are not needed when using compile code
392 // (the member function pointer is used in this case), while they are required when using interpreted
393 // code via the specialized constructor with void *.
394 // xmin and xmax specify the plotting range, npar is the number of parameters.
395 // See the tutorial math/exampleFunctor.C for an example of using this constructor
396 template <class PtrObj, typename MemFn>
397 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) :
398 TF1(EFType::kTemplScalar, name, xmin, xmax, npar, ndim, addToGlobList, new TF1Parameters(npar), new TF1FunctorPointerImpl<double>(ROOT::Math::ParamFunctor(p, memFn)))
399 {}
400
401 // backward compatible interface
402 template <class PtrObj, typename MemFn>
403 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) :
404 TF1(EFType::kTemplScalar, name, xmin, xmax, npar, 1, addToGlobList, new TF1Parameters(npar), new TF1FunctorPointerImpl<double>(ROOT::Math::ParamFunctor(p, memFn)))
405 {}
406
407 TF1(const TF1 &f1);
408 TF1 &operator=(const TF1 &rhs);
409 virtual ~TF1();
410 virtual void AddParameter(const TString &name, Double_t value)
411 {
412 if (fFormula) fFormula->AddParameter(name, value);
413 }
414 // virtual void AddParameters(const pair<TString,Double_t> *pairs, Int_t size) { fFormula->AddParameters(pairs,size); }
415 // virtual void AddVariable(const TString &name, Double_t value = 0) { if (fFormula) fFormula->AddVariable(name,value); }
416 // virtual void AddVariables(const TString *vars, Int_t size) { if (fFormula) fFormula->AddVariables(vars,size); }
417 virtual Bool_t AddToGlobalList(Bool_t on = kTRUE);
419 virtual void Browse(TBrowser *b);
420 virtual void Copy(TObject &f1) const;
421 TObject* Clone(const char* newname=0) const;
422 virtual Double_t Derivative(Double_t x, Double_t *params = 0, Double_t epsilon = 0.001) const;
423 virtual Double_t Derivative2(Double_t x, Double_t *params = 0, Double_t epsilon = 0.001) const;
424 virtual Double_t Derivative3(Double_t x, Double_t *params = 0, Double_t epsilon = 0.001) const;
425 static Double_t DerivativeError();
426 virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
427 virtual void Draw(Option_t *option = "");
428 virtual TF1 *DrawCopy(Option_t *option = "") const;
429 virtual TObject *DrawDerivative(Option_t *option = "al"); // *MENU*
430 virtual TObject *DrawIntegral(Option_t *option = "al"); // *MENU*
431 virtual void DrawF1(Double_t xmin, Double_t xmax, Option_t *option = "");
432 virtual Double_t Eval(Double_t x, Double_t y = 0, Double_t z = 0, Double_t t = 0) const;
433 //template <class T> T Eval(T x, T y = 0, T z = 0, T t = 0) const;
434 virtual Double_t EvalPar(const Double_t *x, const Double_t *params = 0);
435 template <class T> T EvalPar(const T *x, const Double_t *params = 0);
436 virtual Double_t operator()(Double_t x, Double_t y = 0, Double_t z = 0, Double_t t = 0) const;
437 template <class T> T operator()(const T *x, const Double_t *params = nullptr);
438 virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
439 virtual void FixParameter(Int_t ipar, Double_t value);
441 {
442 return (fType == EFType::kTemplVec) || (fType == EFType::kFormula && fFormula && fFormula->IsVectorized());
443 }
445 {
446 return fChisquare;
447 }
448 virtual TH1 *GetHistogram() const;
450 {
452 }
454 {
455 return fFormula.get();
456 }
457 virtual const TFormula *GetFormula() const
458 {
459 return fFormula.get();
460 }
461 virtual TString GetExpFormula(Option_t *option = "") const
462 {
463 return (fFormula) ? fFormula->GetExpFormula(option) : "";
464 }
465 virtual const TObject *GetLinearPart(Int_t i) const
466 {
467 return (fFormula) ? fFormula->GetLinearPart(i) : nullptr;
468 }
469 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;
470 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;
471 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;
472 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;
474 {
475 return fMaximum;
476 }
478 {
479 return fMinimum;
480 }
481 virtual Int_t GetNpar() const
482 {
483 return fNpar;
484 }
485 virtual Int_t GetNdim() const
486 {
487 return fNdim;
488 }
489 virtual Int_t GetNDF() const;
490 virtual Int_t GetNpx() const
491 {
492 return fNpx;
493 }
495 {
496 return fMethodCall.get();
497 }
498 virtual Int_t GetNumber() const
499 {
500 return (fFormula) ? fFormula->GetNumber() : 0;
501 }
502 virtual Int_t GetNumberFreeParameters() const;
503 virtual Int_t GetNumberFitPoints() const
504 {
505 return fNpfits;
506 }
507 virtual char *GetObjectInfo(Int_t px, Int_t py) const;
509 {
510 return fParent;
511 }
512 virtual Double_t GetParameter(Int_t ipar) const
513 {
514 return (fFormula) ? fFormula->GetParameter(ipar) : fParams->GetParameter(ipar);
515 }
516 virtual Double_t GetParameter(const TString &name) const
517 {
518 return (fFormula) ? fFormula->GetParameter(name) : fParams->GetParameter(name);
519 }
520 virtual Double_t *GetParameters() const
521 {
522 return (fFormula) ? fFormula->GetParameters() : const_cast<Double_t *>(fParams->GetParameters());
523 }
524 virtual void GetParameters(Double_t *params)
525 {
526 if (fFormula) fFormula->GetParameters(params);
527 else std::copy(fParams->ParamsVec().begin(), fParams->ParamsVec().end(), params);
528 }
529 virtual const char *GetParName(Int_t ipar) const
530 {
531 return (fFormula) ? fFormula->GetParName(ipar) : fParams->GetParName(ipar);
532 }
533 virtual Int_t GetParNumber(const char *name) const
534 {
535 return (fFormula) ? fFormula->GetParNumber(name) : fParams->GetParNumber(name);
536 }
537 virtual Double_t GetParError(Int_t ipar) const;
538 virtual const Double_t *GetParErrors() const
539 {
540 return fParErrors.data();
541 }
542 virtual void GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const;
543 virtual Double_t GetProb() const;
544 virtual Int_t GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum);
545 virtual Double_t GetRandom(TRandom * rng = nullptr, Option_t * opt = nullptr);
546 virtual Double_t GetRandom(Double_t xmin, Double_t xmax, TRandom * rng = nullptr, Option_t * opt = nullptr);
547 virtual void GetRange(Double_t &xmin, Double_t &xmax) const;
548 virtual void GetRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const;
549 virtual void GetRange(Double_t &xmin, Double_t &ymin, Double_t &zmin, Double_t &xmax, Double_t &ymax, Double_t &zmax) const;
550 virtual Double_t GetSave(const Double_t *x);
551 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;
552 virtual Double_t GetXmin() const
553 {
554 return fXmin;
555 }
556 virtual Double_t GetXmax() const
557 {
558 return fXmax;
559 }
560 TAxis *GetXaxis() const ;
561 TAxis *GetYaxis() const ;
562 TAxis *GetZaxis() const ;
564 {
565 return (fFormula) ? fFormula->GetVariable(name) : 0;
566 }
567 virtual Double_t GradientPar(Int_t ipar, const Double_t *x, Double_t eps = 0.01);
568 template <class T>
569 T GradientPar(Int_t ipar, const T *x, Double_t eps = 0.01);
570 template <class T>
571 T GradientParTempl(Int_t ipar, const T *x, Double_t eps = 0.01);
572
573 virtual void GradientPar(const Double_t *x, Double_t *grad, Double_t eps = 0.01);
574 template <class T>
575 void GradientPar(const T *x, T *grad, Double_t eps = 0.01);
576 template <class T>
577 void GradientParTempl(const T *x, T *grad, Double_t eps = 0.01);
578
579 virtual void InitArgs(const Double_t *x, const Double_t *params);
580 static void InitStandardFunctions();
581 virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel = 1.e-12);
582 virtual Double_t IntegralOneDim(Double_t a, Double_t b, Double_t epsrel, Double_t epsabs, Double_t &err);
583 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);
584 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);
585 // virtual Double_t IntegralFast(const TGraph *g, Double_t a, Double_t b, Double_t *params=0);
586 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);
587 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);
588 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)
589 {
590 return IntegralMultiple(n, a, b, maxpts, epsrel, epsrel, relerr, nfnevl, ifail);
591 }
592 virtual Double_t IntegralMultiple(Int_t n, const Double_t *a, const Double_t *b, Double_t epsrel, Double_t &relerr);
593 virtual Bool_t IsEvalNormalized() const
594 {
595 return fNormalized;
596 }
597 /// return kTRUE if the point is inside the function range
598 virtual Bool_t IsInside(const Double_t *x) const
599 {
600 return !((x[0] < fXmin) || (x[0] > fXmax));
601 }
602 virtual Bool_t IsLinear() const
603 {
604 return (fFormula) ? fFormula->IsLinear() : false;
605 }
606 virtual Bool_t IsValid() const;
607 virtual void Print(Option_t *option = "") const;
608 virtual void Paint(Option_t *option = "");
609 virtual void ReleaseParameter(Int_t ipar);
611 virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
612 virtual void SetChisquare(Double_t chi2)
613 {
614 fChisquare = chi2;
615 }
616 virtual void SetFitResult(const ROOT::Fit::FitResult &result, const Int_t *indpar = 0);
617 template <class PtrObj, typename MemFn>
618 void SetFunction(PtrObj &p, MemFn memFn);
619 template <typename Func>
620 void SetFunction(Func f);
621 virtual void SetMaximum(Double_t maximum = -1111); // *MENU*
622 virtual void SetMinimum(Double_t minimum = -1111); // *MENU*
623 virtual void SetNDF(Int_t ndf);
624 virtual void SetNumberFitPoints(Int_t npfits)
625 {
626 fNpfits = npfits;
627 }
628 virtual void SetNormalized(Bool_t flag)
629 {
630 fNormalized = flag;
631 Update();
632 }
633 virtual void SetNpx(Int_t npx = 100); // *MENU*
634 virtual void SetParameter(Int_t param, Double_t value)
635 {
636 (fFormula) ? fFormula->SetParameter(param, value) : fParams->SetParameter(param, value);
637 Update();
638 }
639 virtual void SetParameter(const TString &name, Double_t value)
640 {
641 (fFormula) ? fFormula->SetParameter(name, value) : fParams->SetParameter(name, value);
642 Update();
643 }
644 virtual void SetParameters(const Double_t *params)
645 {
646 (fFormula) ? fFormula->SetParameters(params) : fParams->SetParameters(params);
647 Update();
648 }
649 virtual void SetParameters(Double_t p0, Double_t p1, Double_t p2 = 0, Double_t p3 = 0, Double_t p4 = 0,
650 Double_t p5 = 0, Double_t p6 = 0, Double_t p7 = 0, Double_t p8 = 0,
651 Double_t p9 = 0, Double_t p10 = 0)
652 {
653 if (fFormula) fFormula->SetParameters(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
654 else fParams->SetParameters(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
655 Update();
656 } // *MENU*
657 virtual void SetParName(Int_t ipar, const char *name);
658 virtual void SetParNames(const char *name0 = "p0", const char *name1 = "p1", const char *name2 = "p2",
659 const char *name3 = "p3", const char *name4 = "p4", const char *name5 = "p5",
660 const char *name6 = "p6", const char *name7 = "p7", const char *name8 = "p8",
661 const char *name9 = "p9", const char *name10 = "p10"); // *MENU*
662 virtual void SetParError(Int_t ipar, Double_t error);
663 virtual void SetParErrors(const Double_t *errors);
664 virtual void SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax);
665 virtual void SetParent(TObject *p = 0)
666 {
667 fParent = p;
668 }
669 virtual void SetRange(Double_t xmin, Double_t xmax); // *MENU*
672 virtual void SetSavedPoint(Int_t point, Double_t value);
673 virtual void SetTitle(const char *title = ""); // *MENU*
674 virtual void SetVectorized(Bool_t vectorized)
675 {
677 fFormula->SetVectorized(vectorized);
678 else
679 Warning("SetVectorized", "Can only set vectorized flag on formula-based TF1");
680 }
681 virtual void Update();
682
683 static TF1 *GetCurrent();
684 static void AbsValue(Bool_t reject = kTRUE);
685 static void RejectPoint(Bool_t reject = kTRUE);
686 static Bool_t RejectedPoint();
687 static void SetCurrent(TF1 *f1);
688
689 //Moments
690 virtual Double_t Moment(Double_t n, Double_t a, Double_t b, const Double_t *params = 0, Double_t epsilon = 0.000001);
691 virtual Double_t CentralMoment(Double_t n, Double_t a, Double_t b, const Double_t *params = 0, Double_t epsilon = 0.000001);
692 virtual Double_t Mean(Double_t a, Double_t b, const Double_t *params = 0, Double_t epsilon = 0.000001)
693 {
694 return Moment(1, a, b, params, epsilon);
695 }
696 virtual Double_t Variance(Double_t a, Double_t b, const Double_t *params = 0, Double_t epsilon = 0.000001)
697 {
698 return CentralMoment(2, a, b, params, epsilon);
699 }
700
701 //some useful static utility functions to compute sampling points for Integral
702 //static void CalcGaussLegendreSamplingPoints(TGraph *g, Double_t eps=3.0e-11);
703 //static TGraph *CalcGaussLegendreSamplingPoints(Int_t num=21, Double_t eps=3.0e-11);
704 static void CalcGaussLegendreSamplingPoints(Int_t num, Double_t *x, Double_t *w, Double_t eps = 3.0e-11);
705
706private:
707 template <class T>
708 T EvalParTempl(const T *data, const Double_t *params = 0);
709
710#ifdef R__HAS_VECCORE
711 inline double EvalParVec(const Double_t *data, const Double_t *params);
712#endif
713
714 ClassDef(TF1, 12) // The Parametric 1-D function
715};
716
717namespace ROOT {
718 namespace Internal {
719
720 template<class Func>
721 void TF1Builder<Func>::Build(TF1 *f, Func func)
722 {
723 using Fnc_t = typename ROOT::Internal::GetFunctorType<decltype(ROOT::Internal::GetTheRightOp(&Func::operator()))>::type;
724 f->fType = std::is_same<Fnc_t, double>::value? TF1::EFType::kTemplScalar : TF1::EFType::kTemplVec;
726 f->fParams.reset(new TF1Parameters(f->fNpar));
727 }
728
729 template<class Func>
730 void TF1Builder<Func *>::Build(TF1 *f, Func *func)
731 {
732 using Fnc_t = typename ROOT::Internal::GetFunctorType<decltype(ROOT::Internal::GetTheRightOp(&Func::operator()))>::type;
733 f->fType = std::is_same<Fnc_t, double>::value? TF1::EFType::kTemplScalar : TF1::EFType::kTemplVec;
735 f->fParams.reset(new TF1Parameters(f->fNpar));
736 }
737
738 /// TF1 building from a string
739 /// used to build a TFormula based on a lambda function
740 template<>
741 struct TF1Builder<const char *> {
742 static void Build(TF1 *f, const char *formula)
743 {
744 f->fType = TF1::EFType::kFormula;
745 f->fFormula.reset(new TFormula("tf1lambda", formula, f->fNdim, f->fNpar, false));
746 TString formulaExpression(formula);
747 Ssiz_t first = formulaExpression.Index("return") + 7;
748 Ssiz_t last = formulaExpression.Last(';');
749 TString title = formulaExpression(first, last - first);
750 f->SetTitle(title);
751 }
752 };
753 }
754}
755
757{
758 return Eval(x, y, z, t);
759}
760
761template <class T>
762inline T TF1::operator()(const T *x, const Double_t *params)
763{
764 return EvalPar(x, params);
765}
766
767////////////////////////////////////////////////////////////////////////////////
768/// EvalPar for vectorized
769template <class T>
770T TF1::EvalPar(const T *x, const Double_t *params)
771{
773 return EvalParTempl(x, params);
774 } else if (fType == EFType::kFormula) {
775 return fFormula->EvalPar(x, params);
776 } else
777 return TF1::EvalPar((double *)x, params);
778}
779
780////////////////////////////////////////////////////////////////////////////////
781/// Eval for vectorized functions
782// template <class T>
783// T TF1::Eval(T x, T y, T z, T t) const
784// {
785// if (fType == EFType::kFormula)
786// return fFormula->Eval(x, y, z, t);
787
788// T xx[] = {x, y, z, t};
789// Double_t *pp = (Double_t *)fParams->GetParameters();
790// return ((TF1 *)this)->EvalPar(xx, pp);
791// }
792
793// Internal to TF1. Evaluates Templated interfaces
794template <class T>
795inline T TF1::EvalParTempl(const T *data, const Double_t *params)
796{
798 if (!params) params = (Double_t *)fParams->GetParameters();
799 if (fFunctor)
800 return ((TF1FunctorPointerImpl<T> *)fFunctor.get())->fImpl(data, params);
801
802 // this should throw an error
803 // we nned to implement a vectorized GetSave(x)
804 return TMath::SignalingNaN();
805}
806
807#ifdef R__HAS_VECCORE
808// Internal to TF1. Evaluates Vectorized TF1 on data of type Double_v
809inline double TF1::EvalParVec(const Double_t *data, const Double_t *params)
810{
811 assert(fType == EFType::kTemplVec);
812 std::vector<ROOT::Double_v> d(fNdim);
813 ROOT::Double_v res;
814
815 for(auto i=0; i<fNdim; i++) {
816 d[i] = ROOT::Double_v(data[i]);
817 }
818
819 if (fFunctor) {
820 res = ((TF1FunctorPointerImpl<ROOT::Double_v> *) fFunctor.get())->fImpl(d.data(), params);
821 } else {
822 // res = GetSave(x);
823 return TMath::SignalingNaN();
824 }
825 return vecCore::Get<ROOT::Double_v>(res, 0);
826}
827#endif
828
830{
832}
834{
836}
837
838template <typename Func>
840{
841 // set function from a generic C++ callable object
844}
845template <class PtrObj, typename MemFn>
846void TF1::SetFunction(PtrObj &p, MemFn memFn)
847{
848 // set from a pointer to a member function
851}
852
853template <class T>
854inline T TF1::GradientPar(Int_t ipar, const T *x, Double_t eps)
855{
857 return GradientParTempl<T>(ipar, x, eps);
858 } else
859 return GradientParTempl<Double_t>(ipar, (const Double_t *)x, eps);
860}
861
862template <class T>
863inline T TF1::GradientParTempl(Int_t ipar, const T *x, Double_t eps)
864{
865 if (GetNpar() == 0)
866 return 0;
867
868 if (eps < 1e-10 || eps > 1) {
869 Warning("Derivative", "parameter esp=%g out of allowed range[1e-10,1], reset to 0.01", eps);
870 eps = 0.01;
871 }
872 Double_t h;
873 TF1 *func = (TF1 *)this;
874 Double_t *parameters = GetParameters();
875
876 // Copy parameters for thread safety
877 std::vector<Double_t> parametersCopy(parameters, parameters + GetNpar());
878 parameters = parametersCopy.data();
879
880 Double_t al, bl, h2;
881 T f1, f2, g1, g2, d0, d2;
882
883 ((TF1 *)this)->GetParLimits(ipar, al, bl);
884 if (al * bl != 0 && al >= bl) {
885 // this parameter is fixed
886 return 0;
887 }
888
889 // check if error has been computer (is not zero)
890 if (func->GetParError(ipar) != 0)
891 h = eps * func->GetParError(ipar);
892 else
893 h = eps;
894
895 // save original parameters
896 Double_t par0 = parameters[ipar];
897
898 parameters[ipar] = par0 + h;
899 f1 = func->EvalPar(x, parameters);
900 parameters[ipar] = par0 - h;
901 f2 = func->EvalPar(x, parameters);
902 parameters[ipar] = par0 + h / 2;
903 g1 = func->EvalPar(x, parameters);
904 parameters[ipar] = par0 - h / 2;
905 g2 = func->EvalPar(x, parameters);
906
907 // compute the central differences
908 h2 = 1 / (2. * h);
909 d0 = f1 - f2;
910 d2 = 2 * (g1 - g2);
911
912 T grad = h2 * (4 * d2 - d0) / 3.;
913
914 // restore original value
915 parameters[ipar] = par0;
916
917 return grad;
918}
919
920template <class T>
921inline void TF1::GradientPar(const T *x, T *grad, Double_t eps)
922{
924 GradientParTempl<T>(x, grad, eps);
925 } else
926 GradientParTempl<Double_t>((const Double_t *)x, (Double_t *)grad, eps);
927}
928
929template <class T>
930inline void TF1::GradientParTempl(const T *x, T *grad, Double_t eps)
931{
932 if (eps < 1e-10 || eps > 1) {
933 Warning("Derivative", "parameter esp=%g out of allowed range[1e-10,1], reset to 0.01", eps);
934 eps = 0.01;
935 }
936
937 for (Int_t ipar = 0; ipar < GetNpar(); ipar++) {
938 grad[ipar] = GradientParTempl<T>(ipar, x, eps);
939 }
940}
941
942#endif
double
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:92
bool Bool_t
Definition RtypesCore.h:63
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassDef(name, id)
Definition Rtypes.h:325
#define BIT(n)
Definition Rtypes.h:85
char name[80]
Definition TGX11.cxx:110
int type
Definition TGX11.cxx:121
float xmin
float * q
float ymin
float xmax
float ymax
class containg the result of the fit and all the related information (fitted parameter values,...
Definition FitResult.h:47
Param Functor class for Multidimensional functions.
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:50
std::vector< Double_t > fParameters
Definition TF1.h:140
const char * GetParName(Int_t iparam) const
Definition TF1.h:96
const std::vector< double > & ParamsVec() const
Definition TF1.h:89
virtual ~TF1Parameters()
Definition TF1.h:74
Double_t GetParameter(const char *name) const
Definition TF1.h:81
Double_t GetParameter(Int_t iparam) const
Definition TF1.h:77
void SetParName(Int_t iparam, const char *name)
Definition TF1.h:120
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:3853
TF1Parameters & operator=(const TF1Parameters &rhs)
Definition TF1.h:67
void SetParameter(Int_t iparam, Double_t value)
Definition TF1.h:103
void SetParameter(const char *name, Double_t value)
Definition TF1.h:116
TF1Parameters(Int_t npar)
Definition TF1.h:53
std::vector< std::string > fParNames
Definition TF1.h:141
TF1Parameters()
Definition TF1.h:52
bool CheckIndex(Int_t i) const
Definition TF1.h:135
void SetParameters(const Double_t *params)
Definition TF1.h:108
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:3821
TF1Parameters(const TF1Parameters &rhs)
Definition TF1.h:62
const Double_t * GetParameters() const
Definition TF1.h:85
1-Dim function class
Definition TF1.h:213
std::unique_ptr< TF1FunctorPointer > fFunctor
Definition TF1.h:267
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:1813
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:1686
virtual Double_t GetXmax() const
Definition TF1.h:556
virtual void ReleaseParameter(Int_t ipar)
Release parameter number ipar If used in a fit, the parameter can vary freely.
Definition TF1.cxx:3137
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Redefines TObject::GetObjectInfo.
Definition TF1.cxx:1908
virtual void SetParError(Int_t ipar, Double_t error)
Set error for parameter number ipar.
Definition TF1.cxx:3486
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:3658
EAddToList
Definition TF1.h:220
virtual const Double_t * GetParErrors() const
Definition TF1.h:538
virtual Int_t GetNumber() const
Definition TF1.h:498
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:1879
std::vector< Double_t > fParErrors
Definition TF1.h:254
Int_t fNdim
Definition TF1.h:246
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:3801
static void AbsValue(Bool_t reject=kTRUE)
Static function: set the fgAbsValue flag.
Definition TF1.cxx:973
virtual TH1 * GetHistogram() const
Return a pointer to the histogram used to visualise the function Note that this histogram is managed ...
Definition TF1.cxx:1574
virtual const TFormula * GetFormula() const
Definition TF1.h:457
virtual void GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const
Return limits for parameter ipar.
Definition TF1.cxx:1930
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:1167
Int_t fNpar
Definition TF1.h:245
virtual Double_t GetParameter(const TString &name) const
Definition TF1.h:516
TAxis * GetYaxis() const
Get y axis of the function.
Definition TF1.cxx:2399
virtual void GetParameters(Double_t *params)
Definition TF1.h:524
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:3432
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
Definition TF1.cxx:1920
static std::atomic< Bool_t > fgAddToGlobList
Definition TF1.h:306
virtual Bool_t IsEvalNormalized() const
Definition TF1.h:593
virtual Double_t GetVariable(const TString &name)
Definition TF1.h:563
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:3677
virtual void SetChisquare(Double_t chi2)
Definition TF1.h:612
Double_t fNormIntegral
Definition TF1.h:266
Double_t GetChisquare() const
Definition TF1.h:444
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:3407
T GradientParTempl(Int_t ipar, const T *x, Double_t eps=0.01)
Definition TF1.h:863
virtual TH1 * CreateHistogram()
Definition TF1.h:449
Double_t fXmin
Definition TF1.h:243
std::unique_ptr< TMethodCall > fMethodCall
Pointer to histogram used for visualisation.
Definition TF1.h:264
virtual void Copy(TObject &f1) const
Copy this F1 to a new F1.
Definition TF1.cxx:994
virtual void Update()
Called by functions such as SetRange, SetNpx, SetParameters to force the deletion of the associated h...
Definition TF1.cxx:3623
virtual Double_t GetProb() const
Return the fit probability.
Definition TF1.cxx:1945
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:337
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:3562
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:3368
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:2433
TAxis * GetZaxis() const
Get z axis of the function. (In case this object is a TF2 or TF3)
Definition TF1.cxx:2410
virtual Double_t GetRandom(TRandom *rng=nullptr, Option_t *opt=nullptr)
Return a random number following this function shape.
Definition TF1.cxx:2180
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition TF1.cxx:3532
virtual Double_t Mean(Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001)
Definition TF1.h:692
virtual void SetParent(TObject *p=0)
Definition TF1.h:665
virtual Double_t GetMaximumStored() const
Definition TF1.h:473
virtual Int_t GetNpar() const
Definition TF1.h:481
virtual TString GetExpFormula(Option_t *option="") const
Definition TF1.h:461
std::vector< Double_t > fBeta
Array alpha. for each bin in x the deconvolution r of fIntegral.
Definition TF1.h:260
Int_t fNDF
Definition TF1.h:250
TH1 * fHistogram
Parent object hooking this function (if one)
Definition TF1.h:263
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:588
std::unique_ptr< TF1AbsComposition > fComposition
Definition TF1.h:270
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:3497
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:3036
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:3714
TObject * GetParent() const
Definition TF1.h:508
Int_t fNpfits
Definition TF1.h:249
virtual Double_t Variance(Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001)
Definition TF1.h:696
static void SetCurrent(TF1 *f1)
Static function setting the current function.
Definition TF1.cxx:3356
void SetFunction(PtrObj &p, MemFn memFn)
Definition TF1.h:846
std::vector< Double_t > fAlpha
Integral of function binned on fNpx bins.
Definition TF1.h:259
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:403
virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel=1.e-12)
IntegralOneDim or analytical integral.
Definition TF1.cxx:2515
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:1102
virtual Int_t GetNumberFitPoints() const
Definition TF1.h:503
std::unique_ptr< TFormula > fFormula
Functor object to wrap any C++ callable object.
Definition TF1.h:268
static Double_t DerivativeError()
Static function returning the error of the last call to the of Derivative's functions.
Definition TF1.cxx:1266
virtual void Paint(Option_t *option="")
Paint this function with its current attributes.
Definition TF1.cxx:2937
std::vector< Double_t > fParMin
Definition TF1.h:255
static void InitStandardFunctions()
Create the basic function objects.
Definition TF1.cxx:2482
Double_t fMaximum
Definition TF1.h:253
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition TF1.cxx:3446
virtual Double_t * GetParameters() const
Definition TF1.h:520
Double_t fMinimum
Definition TF1.h:252
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a function.
Definition TF1.cxx:1282
int TermCoeffLength(TString &term)
Definition TF1.cxx:912
static Bool_t fgRejectPoint
Definition TF1.h:305
virtual ~TF1()
TF1 default destructor.
Definition TF1.cxx:942
virtual void SetNumberFitPoints(Int_t npfits)
Definition TF1.h:624
virtual Double_t GetMinimumStored() const
Definition TF1.h:477
virtual void SetNormalized(Bool_t flag)
Definition TF1.h:628
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=0)
Evaluate function with given coordinates and parameters.
Definition TF1.cxx:1463
TF1 & operator=(const TF1 &rhs)
Operator =.
Definition TF1.cxx:930
virtual Int_t GetNumberFreeParameters() const
Return the number of free parameters.
Definition TF1.cxx:1890
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:397
Double_t fChisquare
Definition TF1.h:251
EStatusBits
Definition TF1.h:324
@ kNotGlobal
Definition TF1.h:325
@ kNotDraw
Definition TF1.h:326
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition TF1.cxx:3200
virtual TFormula * GetFormula()
Definition TF1.h:453
virtual void InitArgs(const Double_t *x, const Double_t *params)
Initialize parameters addresses.
Definition TF1.cxx:2467
TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar, const char *, EAddToList addToGlobList=EAddToList::kDefault)
Definition TF1.h:381
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:2835
TMethodCall * GetMethodCall() const
Definition TF1.h:494
virtual Double_t operator()(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Definition TF1.h:756
EFType fType
Definition TF1.h:248
Bool_t fNormalized
Pointer to MethodCall in case of interpreted function.
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:3420
virtual void AddParameter(const TString &name, Double_t value)
Definition TF1.h:410
virtual void GetRange(Double_t *xmin, Double_t *xmax) const
Return range of a generic N-D function.
Definition TF1.cxx:2269
virtual void Print(Option_t *option="") const
Print TNamed name and title.
Definition TF1.cxx:2881
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:2762
virtual const char * GetParName(Int_t ipar) const
Definition TF1.h:529
static TF1 * fgCurrent
Definition TF1.h:307
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:273
Int_t fNpx
Definition TF1.h:247
virtual void SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax)
Set limits for parameter ipar.
Definition TF1.cxx:3511
void DoInitialize(EAddToList addToGlobList)
Common initialization of the TF1.
Definition TF1.cxx:790
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:1853
static TF1 * GetCurrent()
Static function returning the current function being processed.
Definition TF1.cxx:1559
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:1982
virtual void SetParName(Int_t ipar, const char *name)
Set name of parameter number ipar.
Definition TF1.cxx:3463
virtual Double_t GetSave(const Double_t *x)
Get value corresponding to X in array of fSave values.
Definition TF1.cxx:2332
static std::atomic< Bool_t > fgAbsValue
Definition TF1.h:304
virtual Bool_t IsLinear() const
Definition TF1.h:602
TF1()
TF1 default constructor.
Definition TF1.cxx:494
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes.
Definition TF1.cxx:1352
std::vector< Double_t > fParMax
Definition TF1.h:256
bool IsVectorized()
Definition TF1.h:440
virtual Bool_t IsValid() const
Return kTRUE if the function is valid.
Definition TF1.cxx:2866
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:826
std::vector< Double_t > fSave
Definition TF1.h:257
static Bool_t RejectedPoint()
See TF1::RejectPoint above.
Definition TF1.cxx:3667
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:871
std::vector< Double_t > fGamma
Array beta. is approximated by x = alpha +beta*r *gamma*r**2.
Definition TF1.h:261
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
Definition TF1.cxx:1053
TObject * fParent
Array gamma.
Definition TF1.h:262
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:1713
virtual void DrawF1(Double_t xmin, Double_t xmax, Option_t *option="")
Draw function between xmin and xmax.
Definition TF1.cxx:1415
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:649
Bool_t ComputeCdfTable(Option_t *opt)
Compute the cumulative function at fNpx points between fXmin and fXmax.
Definition TF1.cxx:2069
virtual void SetParameters(const Double_t *params)
Definition TF1.h:644
virtual TObject * DrawIntegral(Option_t *option="al")
Draw integral of this function.
Definition TF1.cxx:1399
std::vector< Double_t > fIntegral
Definition TF1.h:258
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:3475
T EvalParTempl(const T *data, const Double_t *params=0)
Eval for vectorized functions.
Definition TF1.h:795
virtual TObject * DrawDerivative(Option_t *option="al")
Draw derivative of this function.
Definition TF1.cxx:1374
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:1434
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:1604
std::unique_ptr< TF1Parameters > fParams
Definition TF1.h:269
virtual void SetParameter(const TString &name, Double_t value)
Definition TF1.h:639
virtual void SetParameter(Int_t param, Double_t value)
Definition TF1.h:634
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:3147
EFType
Definition TF1.h:234
@ kCompositionFcn
Definition TF1.h:240
@ kFormula
Definition TF1.h:235
@ kPtrScalarFreeFcn
Definition TF1.h:236
@ kTemplScalar
Definition TF1.h:239
@ kTemplVec
Definition TF1.h:238
@ kInterpreted
Definition TF1.h:237
virtual void SetSavedPoint(Int_t point, Double_t value)
Restore value of function saved at point.
Definition TF1.cxx:3546
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:1547
virtual Bool_t IsInside(const Double_t *x) const
return kTRUE if the point is inside the function range
Definition TF1.h:598
virtual Int_t GetNpx() const
Definition TF1.h:490
Double_t fXmax
Definition TF1.h:244
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:1645
virtual Int_t GetNdim() const
Definition TF1.h:485
virtual Double_t GetXmin() const
Definition TF1.h:552
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:1232
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:835
virtual const TObject * GetLinearPart(Int_t i) const
Definition TF1.h:465
virtual void SetVectorized(Bool_t vectorized)
Definition TF1.h:674
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:2605
virtual void Browse(TBrowser *b)
Browse.
Definition TF1.cxx:982
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:372
virtual Double_t GetParameter(Int_t ipar) const
Definition TF1.h:512
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:2692
virtual Int_t GetParNumber(const char *name) const
Definition TF1.h:533
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:356
TAxis * GetXaxis() const
Get x axis of the function.
Definition TF1.cxx:2388
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition TF1.cxx:1531
The Formula class.
Definition TFormula.h:87
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
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:879
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
Basic string class.
Definition TString.h:136
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition TString.cxx:912
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:2331
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:639
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:133
Namespace for new Math classes and functions.
auto GetTheRightOp(T(F::*opPtr)(const T *, const double *)) -> decltype(opPtr)
Definition TF1.h:187
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Double_t Double_v
Definition Types.h:51
Double_t SignalingNaN()
Returns a signaling NaN as defined by IEEE 754](http://en.wikipedia.org/wiki/NaN#Signaling_NaN)
Definition TMath.h:908
Definition first.py:1
static void Build(TF1 *f, const char *formula)
Definition TF1.h:742
Internal class used by TF1 for defining template specialization for different TF1 constructors.
Definition TF1.h:149
static void Build(TF1 *f, Func func)
Definition TF1.h:721
virtual TF1FunctorPointer * Clone() const
Definition TF1.h:297
ROOT::Math::ParamFunctorTempl< T > fImpl
Definition TF1.h:298
TF1FunctorPointerImpl(const std::function< T(const T *f, const Double_t *param)> &func)
Definition TF1.h:295
TF1FunctorPointerImpl(const ROOT::Math::ParamFunctorTempl< T > &func)
Definition TF1.h:294
virtual ~TF1FunctorPointerImpl()
Definition TF1.h:296
virtual ~TF1FunctorPointer()
Definition TF1.h:228
virtual TF1FunctorPointer * Clone() const =0
th1 Draw()
REAL epsilon
Definition triangle.c:617