ROOT logo
// @(#)root/hist:$Id: TF1.h 26166 2008-11-12 16:25:31Z brun $
// Author: Rene Brun   18/08/95

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/
// ---------------------------------- F1.h

#ifndef ROOT_TF1
#define ROOT_TF1



//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TF1                                                                  //
//                                                                      //
// The Parametric 1-D function                                          //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TFormula
#include "TFormula.h"
#endif
#ifndef ROOT_TAttLine
#include "TAttLine.h"
#endif
#ifndef ROOT_TAttFill
#include "TAttFill.h"
#endif
#ifndef ROOT_TAttMarker
#include "TAttMarker.h"
#endif

#ifndef ROOT_Math_ParamFunctor
#include "Math/ParamFunctor.h"
#endif

class TF1;
class TH1;
class TAxis;
class TMethodCall;

class TF1 : public TFormula, public TAttLine, public TAttFill, public TAttMarker {

protected:
   Double_t    fXmin;        //Lower bounds for the range
   Double_t    fXmax;        //Upper bounds for the range
   Int_t       fNpx;         //Number of points used for the graphical representation
   Int_t       fType;        //(=0 for standard functions, 1 if pointer to function)
   Int_t       fNpfits;      //Number of points used in the fit
   Int_t       fNDF;         //Number of degrees of freedom in the fit
   Int_t       fNsave;       //Number of points used to fill array fSave
   Double_t    fChisquare;   //Function fit chisquare
   Double_t    *fIntegral;   //![fNpx] Integral of function binned on fNpx bins
   Double_t    *fParErrors;  //[fNpar] Array of errors of the fNpar parameters
   Double_t    *fParMin;     //[fNpar] Array of lower limits of the fNpar parameters
   Double_t    *fParMax;     //[fNpar] Array of upper limits of the fNpar parameters
   Double_t    *fSave;       //[fNsave] Array of fNsave function values
   Double_t    *fAlpha;      //!Array alpha. for each bin in x the deconvolution r of fIntegral
   Double_t    *fBeta;       //!Array beta.  is approximated by x = alpha +beta*r *gamma*r**2
   Double_t    *fGamma;      //!Array gamma.
   TObject     *fParent;     //!Parent object hooking this function (if one)
   TH1         *fHistogram;  //!Pointer to histogram used for visualisation
   Double_t     fMaximum;    //Maximum value for plotting
   Double_t     fMinimum;    //Minimum value for plotting
   TMethodCall *fMethodCall; //!Pointer to MethodCall in case of interpreted function
   void        *fCintFunc;              //! pointer to interpreted function class
   ROOT::Math::ParamFunctor fFunctor;   //! Functor object to wrap any C++ callable object

   static Bool_t fgAbsValue;  //use absolute value of function when computing integral
   static Bool_t fgRejectPoint;  //True if point must be rejected in a fit
   static TF1   *fgCurrent;   //pointer to current function being processed

   void CreateFromFunctor(const char *name, Int_t npar);
   void CreateFromCintClass(const char *name, void * ptr, Double_t xmin, Double_t xmax, Int_t npar, const char * cname, const char * fname);

public:
    // TF1 status bits
    enum {
       kNotDraw     = BIT(9)  // don't draw the function when in a TH1
    };

   TF1();
   TF1(const char *name, const char *formula, Double_t xmin=0, Double_t xmax=1);
   TF1(const char *name, Double_t xmin, Double_t xmax, Int_t npar);
   TF1(const char *name, void *fcn, Double_t xmin, Double_t xmax, Int_t npar);
#ifndef __CINT__
   TF1(const char *name, Double_t (*fcn)(Double_t *, Double_t *), Double_t xmin=0, Double_t xmax=1, Int_t npar=0);
   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);
#endif

   // Constructors using functors (compiled mode only)
   TF1(const char *name, ROOT::Math::ParamFunctor f, Double_t xmin = 0, Double_t xmax = 1, Int_t npar = 0);

   // Template constructors from any  C++ callable object,  defining  the operator() (double * , double *)
   // and returning a double.
   // The class name is not needed when using compile code, while it is required when using
   // interpreted code via the specialized constructor with void *.
   // An instance of the C++ function class or its pointer can both be used. The former is reccomended when using
   // C++ compiled code, but if CINT compatibility is needed, then a pointer to the function class must be used.
   // xmin and xmax specify the plotting range,  npar is the number of parameters.
   // See the tutorial math/exampleFunctor.C for an example of using this constructor
   template <typename Func>
   TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar, const char * = 0  ) :
      TFormula(),
      TAttLine(),
      TAttFill(),
      TAttMarker(),
      fXmin      ( xmin ),
      fXmax      ( xmax ),
      fNpx       ( 100 ),
      fType      ( 1 ),
      fNpfits    ( 0 ),
      fNDF       ( 0 ),
      fNsave     ( 0 ),
      fChisquare ( 0 ),
      fIntegral  ( 0 ),
      fParErrors ( 0 ),
      fParMin    ( 0 ),
      fParMax    ( 0 ),
      fSave      ( 0 ),
      fAlpha     ( 0 ),
      fBeta      ( 0 ),
      fGamma     ( 0 ),
      fParent    ( 0 ),
      fHistogram ( 0 ),
      fMaximum   ( -1111 ),
      fMinimum   ( -1111 ),
      fMethodCall ( 0),
      fCintFunc  ( 0 ),
      fFunctor( ROOT::Math::ParamFunctor(f) )
   {
      CreateFromFunctor(name, npar);
   }

   // Template constructors from a pointer to any C++ class of type PtrObj with a specific member function of type
   // MemFn.
   // The member function must have the signature of  (double * , double *) and returning a double.
   // The class name and the method name are not needed when using compile code
   // (the member function pointer is used in this case), while they are required when using interpreted
   // code via the specialized constructor with void *.
   // xmin and xmax specify the plotting range,  npar is the number of parameters.
   // See the tutorial math/exampleFunctor.C for an example of using this constructor
   template <class PtrObj, typename MemFn>
   TF1(const char *name, const  PtrObj& p, MemFn memFn, Double_t xmin, Double_t xmax, Int_t npar, const char * = 0, const char * = 0) :
      TFormula(),
      TAttLine(),
      TAttFill(),
      TAttMarker(),
      fXmin      ( xmin ),
      fXmax      ( xmax ),
      fNpx       ( 100 ),
      fType      ( 1 ),
      fNpfits    ( 0 ),
      fNDF       ( 0 ),
      fNsave     ( 0 ),
      fChisquare ( 0 ),
      fIntegral  ( 0 ),
      fParErrors ( 0 ),
      fParMin    ( 0 ),
      fParMax    ( 0 ),
      fSave      ( 0 ),
      fAlpha     ( 0 ),
      fBeta      ( 0 ),
      fGamma     ( 0 ),
      fParent    ( 0 ),
      fHistogram ( 0 ),
      fMaximum   ( -1111 ),
      fMinimum   ( -1111 ),
      fMethodCall( 0 ),
      fCintFunc  ( 0 ),
      fFunctor   ( ROOT::Math::ParamFunctor(p,memFn) )
   {
      CreateFromFunctor(name, npar);
   }

   // constructor used by CINT
   TF1(const char *name, void *ptr, Double_t xmin, Double_t xmax, Int_t npar, const char *className );
   TF1(const char *name, void *ptr, void *,Double_t xmin, Double_t xmax, Int_t npar, const char *className, const char *methodName = 0);

   TF1(const TF1 &f1);
   TF1& operator=(const TF1 &rhs);
   virtual   ~TF1();
   virtual void     Browse(TBrowser *b);
   virtual void     Copy(TObject &f1) const;
   virtual Double_t Derivative (Double_t x, Double_t *params=0, Double_t epsilon=0.001) const;
   virtual Double_t Derivative2(Double_t x, Double_t *params=0, Double_t epsilon=0.001) const;
   virtual Double_t Derivative3(Double_t x, Double_t *params=0, Double_t epsilon=0.001) const;
   static  Double_t DerivativeError();
   virtual Int_t    DistancetoPrimitive(Int_t px, Int_t py);
   virtual void     Draw(Option_t *option="");
   virtual TF1     *DrawCopy(Option_t *option="") const;
   virtual void     DrawDerivative(Option_t *option="al"); // *MENU*
   virtual void     DrawIntegral(Option_t *option="al");   // *MENU*
   virtual void     DrawF1(const char *formula, Double_t xmin, Double_t xmax, Option_t *option="");
   virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const;
   virtual Double_t EvalPar(const Double_t *x, const Double_t *params=0);
   // for using TF1 as a callable object (functor)
   virtual Double_t operator()(Double_t x, Double_t y=0, Double_t z = 0, Double_t t = 0) const; 
   virtual Double_t operator()(const Double_t *x, const Double_t *params=0);  
   virtual void     ExecuteEvent(Int_t event, Int_t px, Int_t py);
   virtual void     FixParameter(Int_t ipar, Double_t value);
       Double_t     GetChisquare() const {return fChisquare;}
           TH1     *GetHistogram() const;
   virtual Double_t GetMaximum(Double_t xmin=0, Double_t xmax=0) const;
   virtual Double_t GetMinimum(Double_t xmin=0, Double_t xmax=0) const;
   virtual Double_t GetMaximumX(Double_t xmin=0, Double_t xmax=0) const;
   virtual Double_t GetMinimumX(Double_t xmin=0, Double_t xmax=0) const;
   virtual Int_t    GetNDF() const;
   virtual Int_t    GetNpx() const {return fNpx;}
    TMethodCall    *GetMethodCall() const {return fMethodCall;}
   virtual Int_t    GetNumberFreeParameters() const;
   virtual Int_t    GetNumberFitPoints() const {return fNpfits;}
   virtual char    *GetObjectInfo(Int_t px, Int_t py) const;
        TObject    *GetParent() const {return fParent;}
   virtual Double_t GetParError(Int_t ipar) const;
   virtual Double_t *GetParErrors() const {return fParErrors;}
   virtual void     GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const;
   virtual Double_t GetProb() const;
   virtual Int_t    GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum);
   virtual Double_t GetRandom();
   virtual Double_t GetRandom(Double_t xmin, Double_t xmax);
   virtual void     GetRange(Double_t &xmin, Double_t &xmax) const;
   virtual void     GetRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const;
   virtual void     GetRange(Double_t &xmin, Double_t &ymin, Double_t &zmin, Double_t &xmax, Double_t &ymax, Double_t &zmax) const;
   virtual Double_t GetSave(const Double_t *x);
   virtual Double_t GetX(Double_t y, Double_t xmin=0, Double_t xmax=0) const;
   virtual Double_t GetXmin() const {return fXmin;}
   virtual Double_t GetXmax() const {return fXmax;}
   TAxis           *GetXaxis() const ;
   TAxis           *GetYaxis() const ;
   TAxis           *GetZaxis() const ;
   virtual Double_t GradientPar(Int_t ipar, const Double_t *x, Double_t eps=0.01);
   virtual void     GradientPar(const Double_t *x, Double_t *grad, Double_t eps=0.01);
   virtual void     InitArgs(const Double_t *x, const Double_t *params);
   static  void     InitStandardFunctions();
   virtual Double_t Integral(Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=1e-12);
   virtual Double_t Integral(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=1e-12);
   virtual Double_t Integral(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t az, Double_t bz, Double_t epsilon=1e-12);
   virtual Double_t IntegralError(Double_t a, Double_t b, Double_t epsilon=1e-12);
   //virtual Double_t IntegralFast(const TGraph *g, Double_t a, Double_t b, Double_t *params=0);
   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);
   virtual Double_t IntegralMultiple(Int_t n, const Double_t *a, const Double_t *b, Int_t minpts, Int_t maxpts, Double_t epsilon, Double_t &relerr,Int_t &nfnevl, Int_t &ifail);
   virtual Double_t IntegralMultiple(Int_t n, const Double_t *a, const Double_t *b, Double_t epsilon, Double_t &relerr);
   virtual Bool_t   IsInside(const Double_t *x) const;
   virtual void     Paint(Option_t *option="");
   virtual void     Print(Option_t *option="") const;
   virtual void     ReleaseParameter(Int_t ipar);
   virtual void     Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax);
   virtual void     SavePrimitive(ostream &out, Option_t *option = "");
   virtual void     SetChisquare(Double_t chi2) {fChisquare = chi2;}
   template <class PtrObj, typename MemFn> 
   void SetFunction( PtrObj& p, MemFn memFn );
   template <typename Func> 
   void SetFunction( Func f );
   virtual void     SetMaximum(Double_t maximum=-1111); // *MENU*
   virtual void     SetMinimum(Double_t minimum=-1111); // *MENU*
   virtual void     SetNDF(Int_t ndf);
   virtual void     SetNumberFitPoints(Int_t npfits) {fNpfits = npfits;}
   virtual void     SetNpx(Int_t npx=100); // *MENU*
   virtual void     SetParError(Int_t ipar, Double_t error);
   virtual void     SetParErrors(const Double_t *errors);
   virtual void     SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax);
   virtual void     SetParent(TObject *p=0) {fParent = p;}
   virtual void     SetRange(Double_t xmin, Double_t xmax); // *MENU*
   virtual void     SetRange(Double_t xmin, Double_t ymin,  Double_t xmax, Double_t ymax);
   virtual void     SetRange(Double_t xmin, Double_t ymin, Double_t zmin,  Double_t xmax, Double_t ymax, Double_t zmax);
   virtual void     SetSavedPoint(Int_t point, Double_t value);
   virtual void     SetTitle(const char *title=""); // *MENU*
   virtual void     Update();

   static  TF1     *GetCurrent();
   static  void     AbsValue(Bool_t reject=kTRUE);
   static  void     RejectPoint(Bool_t reject=kTRUE);
   static  Bool_t   RejectedPoint();
   static  void     SetCurrent(TF1 *f1);

   //Moments
   virtual Double_t Moment(Double_t n, Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001);
   virtual Double_t CentralMoment(Double_t n, Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001);
   virtual Double_t Mean(Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001) {return Moment(1,a,b,params,epsilon);}
   virtual Double_t Variance(Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001) {return CentralMoment(2,a,b,params,epsilon);}

   //some useful static utility functions to compute sampling points for Integral
   //static  void     CalcGaussLegendreSamplingPoints(TGraph *g, Double_t eps=3.0e-11);
   //static  TGraph  *CalcGaussLegendreSamplingPoints(Int_t num=21, Double_t eps=3.0e-11);
   static  void     CalcGaussLegendreSamplingPoints(Int_t num, Double_t *x, Double_t *w, Double_t eps=3.0e-11);

   ClassDef(TF1,7)  //The Parametric 1-D function
};

inline Double_t TF1::operator()(Double_t x, Double_t y, Double_t z, Double_t t) const  
   { return Eval(x,y,z,t); }
inline Double_t TF1::operator()(const Double_t *x, const Double_t *params)
   { 
      if (fMethodCall) InitArgs(x,params);
      return EvalPar(x,params); 
   }


inline void TF1::SetRange(Double_t xmin, Double_t,  Double_t xmax, Double_t)
   { TF1::SetRange(xmin, xmax); }
inline void TF1::SetRange(Double_t xmin, Double_t, Double_t,  Double_t xmax, Double_t, Double_t)
   { TF1::SetRange(xmin, xmax); }

template <typename Func> 
void TF1::SetFunction( Func f )    {
   // set function from a generic C++ callable object 
   fType = 1; 
   fFunctor = ROOT::Math::ParamFunctor(f); 
} 
template <class PtrObj, typename MemFn> 
void TF1::SetFunction( PtrObj& p, MemFn memFn )   { 
   // set from a pointer to a member function
   fType = 1; 
   fFunctor = ROOT::Math::ParamFunctor(p,memFn); 
} 

#endif
 TF1.h:1
 TF1.h:2
 TF1.h:3
 TF1.h:4
 TF1.h:5
 TF1.h:6
 TF1.h:7
 TF1.h:8
 TF1.h:9
 TF1.h:10
 TF1.h:11
 TF1.h:12
 TF1.h:13
 TF1.h:14
 TF1.h:15
 TF1.h:16
 TF1.h:17
 TF1.h:18
 TF1.h:19
 TF1.h:20
 TF1.h:21
 TF1.h:22
 TF1.h:23
 TF1.h:24
 TF1.h:25
 TF1.h:26
 TF1.h:27
 TF1.h:28
 TF1.h:29
 TF1.h:30
 TF1.h:31
 TF1.h:32
 TF1.h:33
 TF1.h:34
 TF1.h:35
 TF1.h:36
 TF1.h:37
 TF1.h:38
 TF1.h:39
 TF1.h:40
 TF1.h:41
 TF1.h:42
 TF1.h:43
 TF1.h:44
 TF1.h:45
 TF1.h:46
 TF1.h:47
 TF1.h:48
 TF1.h:49
 TF1.h:50
 TF1.h:51
 TF1.h:52
 TF1.h:53
 TF1.h:54
 TF1.h:55
 TF1.h:56
 TF1.h:57
 TF1.h:58
 TF1.h:59
 TF1.h:60
 TF1.h:61
 TF1.h:62
 TF1.h:63
 TF1.h:64
 TF1.h:65
 TF1.h:66
 TF1.h:67
 TF1.h:68
 TF1.h:69
 TF1.h:70
 TF1.h:71
 TF1.h:72
 TF1.h:73
 TF1.h:74
 TF1.h:75
 TF1.h:76
 TF1.h:77
 TF1.h:78
 TF1.h:79
 TF1.h:80
 TF1.h:81
 TF1.h:82
 TF1.h:83
 TF1.h:84
 TF1.h:85
 TF1.h:86
 TF1.h:87
 TF1.h:88
 TF1.h:89
 TF1.h:90
 TF1.h:91
 TF1.h:92
 TF1.h:93
 TF1.h:94
 TF1.h:95
 TF1.h:96
 TF1.h:97
 TF1.h:98
 TF1.h:99
 TF1.h:100
 TF1.h:101
 TF1.h:102
 TF1.h:103
 TF1.h:104
 TF1.h:105
 TF1.h:106
 TF1.h:107
 TF1.h:108
 TF1.h:109
 TF1.h:110
 TF1.h:111
 TF1.h:112
 TF1.h:113
 TF1.h:114
 TF1.h:115
 TF1.h:116
 TF1.h:117
 TF1.h:118
 TF1.h:119
 TF1.h:120
 TF1.h:121
 TF1.h:122
 TF1.h:123
 TF1.h:124
 TF1.h:125
 TF1.h:126
 TF1.h:127
 TF1.h:128
 TF1.h:129
 TF1.h:130
 TF1.h:131
 TF1.h:132
 TF1.h:133
 TF1.h:134
 TF1.h:135
 TF1.h:136
 TF1.h:137
 TF1.h:138
 TF1.h:139
 TF1.h:140
 TF1.h:141
 TF1.h:142
 TF1.h:143
 TF1.h:144
 TF1.h:145
 TF1.h:146
 TF1.h:147
 TF1.h:148
 TF1.h:149
 TF1.h:150
 TF1.h:151
 TF1.h:152
 TF1.h:153
 TF1.h:154
 TF1.h:155
 TF1.h:156
 TF1.h:157
 TF1.h:158
 TF1.h:159
 TF1.h:160
 TF1.h:161
 TF1.h:162
 TF1.h:163
 TF1.h:164
 TF1.h:165
 TF1.h:166
 TF1.h:167
 TF1.h:168
 TF1.h:169
 TF1.h:170
 TF1.h:171
 TF1.h:172
 TF1.h:173
 TF1.h:174
 TF1.h:175
 TF1.h:176
 TF1.h:177
 TF1.h:178
 TF1.h:179
 TF1.h:180
 TF1.h:181
 TF1.h:182
 TF1.h:183
 TF1.h:184
 TF1.h:185
 TF1.h:186
 TF1.h:187
 TF1.h:188
 TF1.h:189
 TF1.h:190
 TF1.h:191
 TF1.h:192
 TF1.h:193
 TF1.h:194
 TF1.h:195
 TF1.h:196
 TF1.h:197
 TF1.h:198
 TF1.h:199
 TF1.h:200
 TF1.h:201
 TF1.h:202
 TF1.h:203
 TF1.h:204
 TF1.h:205
 TF1.h:206
 TF1.h:207
 TF1.h:208
 TF1.h:209
 TF1.h:210
 TF1.h:211
 TF1.h:212
 TF1.h:213
 TF1.h:214
 TF1.h:215
 TF1.h:216
 TF1.h:217
 TF1.h:218
 TF1.h:219
 TF1.h:220
 TF1.h:221
 TF1.h:222
 TF1.h:223
 TF1.h:224
 TF1.h:225
 TF1.h:226
 TF1.h:227
 TF1.h:228
 TF1.h:229
 TF1.h:230
 TF1.h:231
 TF1.h:232
 TF1.h:233
 TF1.h:234
 TF1.h:235
 TF1.h:236
 TF1.h:237
 TF1.h:238
 TF1.h:239
 TF1.h:240
 TF1.h:241
 TF1.h:242
 TF1.h:243
 TF1.h:244
 TF1.h:245
 TF1.h:246
 TF1.h:247
 TF1.h:248
 TF1.h:249
 TF1.h:250
 TF1.h:251
 TF1.h:252
 TF1.h:253
 TF1.h:254
 TF1.h:255
 TF1.h:256
 TF1.h:257
 TF1.h:258
 TF1.h:259
 TF1.h:260
 TF1.h:261
 TF1.h:262
 TF1.h:263
 TF1.h:264
 TF1.h:265
 TF1.h:266
 TF1.h:267
 TF1.h:268
 TF1.h:269
 TF1.h:270
 TF1.h:271
 TF1.h:272
 TF1.h:273
 TF1.h:274
 TF1.h:275
 TF1.h:276
 TF1.h:277
 TF1.h:278
 TF1.h:279
 TF1.h:280
 TF1.h:281
 TF1.h:282
 TF1.h:283
 TF1.h:284
 TF1.h:285
 TF1.h:286
 TF1.h:287
 TF1.h:288
 TF1.h:289
 TF1.h:290
 TF1.h:291
 TF1.h:292
 TF1.h:293
 TF1.h:294
 TF1.h:295
 TF1.h:296
 TF1.h:297
 TF1.h:298
 TF1.h:299
 TF1.h:300
 TF1.h:301
 TF1.h:302
 TF1.h:303
 TF1.h:304
 TF1.h:305
 TF1.h:306
 TF1.h:307
 TF1.h:308
 TF1.h:309
 TF1.h:310
 TF1.h:311
 TF1.h:312
 TF1.h:313
 TF1.h:314
 TF1.h:315
 TF1.h:316
 TF1.h:317
 TF1.h:318
 TF1.h:319
 TF1.h:320
 TF1.h:321
 TF1.h:322
 TF1.h:323
 TF1.h:324