TF1.h

Go to the documentation of this file.
00001 // @(#)root/hist:$Id: TF1.h 36906 2010-11-24 15:52:01Z moneta $
00002 // Author: Rene Brun   18/08/95
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 // ---------------------------------- F1.h
00012 
00013 #ifndef ROOT_TF1
00014 #define ROOT_TF1
00015 
00016 
00017 
00018 //////////////////////////////////////////////////////////////////////////
00019 //                                                                      //
00020 // TF1                                                                  //
00021 //                                                                      //
00022 // The Parametric 1-D function                                          //
00023 //                                                                      //
00024 //////////////////////////////////////////////////////////////////////////
00025 
00026 #ifndef ROOT_TFormula
00027 #include "TFormula.h"
00028 #endif
00029 #ifndef ROOT_TAttLine
00030 #include "TAttLine.h"
00031 #endif
00032 #ifndef ROOT_TAttFill
00033 #include "TAttFill.h"
00034 #endif
00035 #ifndef ROOT_TAttMarker
00036 #include "TAttMarker.h"
00037 #endif
00038 
00039 #ifndef ROOT_Math_ParamFunctor
00040 #include "Math/ParamFunctor.h"
00041 #endif
00042 
00043 class TF1;
00044 class TH1;
00045 class TAxis;
00046 class TMethodCall;
00047 
00048 namespace ROOT { 
00049    namespace Fit { 
00050       class FitResult; 
00051    }
00052 }
00053 
00054 class TF1 : public TFormula, public TAttLine, public TAttFill, public TAttMarker {
00055 
00056 protected:
00057    Double_t    fXmin;        //Lower bounds for the range
00058    Double_t    fXmax;        //Upper bounds for the range
00059    Int_t       fNpx;         //Number of points used for the graphical representation
00060    Int_t       fType;        //(=0 for standard functions, 1 if pointer to function)
00061    Int_t       fNpfits;      //Number of points used in the fit
00062    Int_t       fNDF;         //Number of degrees of freedom in the fit
00063    Int_t       fNsave;       //Number of points used to fill array fSave
00064    Double_t    fChisquare;   //Function fit chisquare
00065    Double_t    *fIntegral;   //![fNpx] Integral of function binned on fNpx bins
00066    Double_t    *fParErrors;  //[fNpar] Array of errors of the fNpar parameters
00067    Double_t    *fParMin;     //[fNpar] Array of lower limits of the fNpar parameters
00068    Double_t    *fParMax;     //[fNpar] Array of upper limits of the fNpar parameters
00069    Double_t    *fSave;       //[fNsave] Array of fNsave function values
00070    Double_t    *fAlpha;      //!Array alpha. for each bin in x the deconvolution r of fIntegral
00071    Double_t    *fBeta;       //!Array beta.  is approximated by x = alpha +beta*r *gamma*r**2
00072    Double_t    *fGamma;      //!Array gamma.
00073    TObject     *fParent;     //!Parent object hooking this function (if one)
00074    TH1         *fHistogram;  //!Pointer to histogram used for visualisation
00075    Double_t     fMaximum;    //Maximum value for plotting
00076    Double_t     fMinimum;    //Minimum value for plotting
00077    TMethodCall *fMethodCall; //!Pointer to MethodCall in case of interpreted function
00078    void        *fCintFunc;              //! pointer to interpreted function class
00079    ROOT::Math::ParamFunctor fFunctor;   //! Functor object to wrap any C++ callable object
00080 
00081    static Bool_t fgAbsValue;  //use absolute value of function when computing integral
00082    static Bool_t fgRejectPoint;  //True if point must be rejected in a fit
00083    static TF1   *fgCurrent;   //pointer to current function being processed
00084 
00085    void CreateFromFunctor(const char *name, Int_t npar);
00086    void CreateFromCintClass(const char *name, void * ptr, Double_t xmin, Double_t xmax, Int_t npar, const char * cname, const char * fname);
00087 
00088 public:
00089     // TF1 status bits
00090     enum {
00091        kNotDraw     = BIT(9)  // don't draw the function when in a TH1
00092     };
00093 
00094    TF1();
00095    TF1(const char *name, const char *formula, Double_t xmin=0, Double_t xmax=1);
00096    TF1(const char *name, Double_t xmin, Double_t xmax, Int_t npar);
00097    TF1(const char *name, void *fcn, Double_t xmin, Double_t xmax, Int_t npar);
00098 #ifndef __CINT__
00099    TF1(const char *name, Double_t (*fcn)(Double_t *, Double_t *), Double_t xmin=0, Double_t xmax=1, Int_t npar=0);
00100    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);
00101 #endif
00102 
00103    // Constructors using functors (compiled mode only)
00104    TF1(const char *name, ROOT::Math::ParamFunctor f, Double_t xmin = 0, Double_t xmax = 1, Int_t npar = 0);
00105 
00106    // Template constructors from any  C++ callable object,  defining  the operator() (double * , double *)
00107    // and returning a double.
00108    // The class name is not needed when using compile code, while it is required when using
00109    // interpreted code via the specialized constructor with void *.
00110    // An instance of the C++ function class or its pointer can both be used. The former is reccomended when using
00111    // C++ compiled code, but if CINT compatibility is needed, then a pointer to the function class must be used.
00112    // xmin and xmax specify the plotting range,  npar is the number of parameters.
00113    // See the tutorial math/exampleFunctor.C for an example of using this constructor
00114    template <typename Func>
00115    TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar, const char * = 0  ) :
00116       TFormula(),
00117       TAttLine(),
00118       TAttFill(),
00119       TAttMarker(),
00120       fXmin      ( xmin ),
00121       fXmax      ( xmax ),
00122       fNpx       ( 100 ),
00123       fType      ( 1 ),
00124       fNpfits    ( 0 ),
00125       fNDF       ( 0 ),
00126       fNsave     ( 0 ),
00127       fChisquare ( 0 ),
00128       fIntegral  ( 0 ),
00129       fParErrors ( 0 ),
00130       fParMin    ( 0 ),
00131       fParMax    ( 0 ),
00132       fSave      ( 0 ),
00133       fAlpha     ( 0 ),
00134       fBeta      ( 0 ),
00135       fGamma     ( 0 ),
00136       fParent    ( 0 ),
00137       fHistogram ( 0 ),
00138       fMaximum   ( -1111 ),
00139       fMinimum   ( -1111 ),
00140       fMethodCall ( 0),
00141       fCintFunc  ( 0 ),
00142       fFunctor( ROOT::Math::ParamFunctor(f) )
00143    {
00144       CreateFromFunctor(name, npar);
00145    }
00146 
00147    // Template constructors from a pointer to any C++ class of type PtrObj with a specific member function of type
00148    // MemFn.
00149    // The member function must have the signature of  (double * , double *) and returning a double.
00150    // The class name and the method name are not needed when using compile code
00151    // (the member function pointer is used in this case), while they are required when using interpreted
00152    // code via the specialized constructor with void *.
00153    // xmin and xmax specify the plotting range,  npar is the number of parameters.
00154    // See the tutorial math/exampleFunctor.C for an example of using this constructor
00155    template <class PtrObj, typename MemFn>
00156    TF1(const char *name, const  PtrObj& p, MemFn memFn, Double_t xmin, Double_t xmax, Int_t npar, const char * = 0, const char * = 0) :
00157       TFormula(),
00158       TAttLine(),
00159       TAttFill(),
00160       TAttMarker(),
00161       fXmin      ( xmin ),
00162       fXmax      ( xmax ),
00163       fNpx       ( 100 ),
00164       fType      ( 1 ),
00165       fNpfits    ( 0 ),
00166       fNDF       ( 0 ),
00167       fNsave     ( 0 ),
00168       fChisquare ( 0 ),
00169       fIntegral  ( 0 ),
00170       fParErrors ( 0 ),
00171       fParMin    ( 0 ),
00172       fParMax    ( 0 ),
00173       fSave      ( 0 ),
00174       fAlpha     ( 0 ),
00175       fBeta      ( 0 ),
00176       fGamma     ( 0 ),
00177       fParent    ( 0 ),
00178       fHistogram ( 0 ),
00179       fMaximum   ( -1111 ),
00180       fMinimum   ( -1111 ),
00181       fMethodCall( 0 ),
00182       fCintFunc  ( 0 ),
00183       fFunctor   ( ROOT::Math::ParamFunctor(p,memFn) )
00184    {
00185       CreateFromFunctor(name, npar);
00186    }
00187 
00188    // constructor used by CINT
00189    TF1(const char *name, void *ptr, Double_t xmin, Double_t xmax, Int_t npar, const char *className );
00190    TF1(const char *name, void *ptr, void *,Double_t xmin, Double_t xmax, Int_t npar, const char *className, const char *methodName = 0);
00191 
00192    TF1(const TF1 &f1);
00193    TF1& operator=(const TF1 &rhs);
00194    virtual   ~TF1();
00195    virtual void     Browse(TBrowser *b);
00196    virtual void     Copy(TObject &f1) const;
00197    virtual Double_t Derivative (Double_t x, Double_t *params=0, Double_t epsilon=0.001) const;
00198    virtual Double_t Derivative2(Double_t x, Double_t *params=0, Double_t epsilon=0.001) const;
00199    virtual Double_t Derivative3(Double_t x, Double_t *params=0, Double_t epsilon=0.001) const;
00200    static  Double_t DerivativeError();
00201    virtual Int_t    DistancetoPrimitive(Int_t px, Int_t py);
00202    virtual void     Draw(Option_t *option="");
00203    virtual TF1     *DrawCopy(Option_t *option="") const;
00204    virtual TObject *DrawDerivative(Option_t *option="al"); // *MENU*
00205    virtual TObject *DrawIntegral(Option_t *option="al");   // *MENU*
00206    virtual void     DrawF1(const char *formula, Double_t xmin, Double_t xmax, Option_t *option="");
00207    virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const;
00208    virtual Double_t EvalPar(const Double_t *x, const Double_t *params=0);
00209    // for using TF1 as a callable object (functor)
00210    virtual Double_t operator()(Double_t x, Double_t y=0, Double_t z = 0, Double_t t = 0) const; 
00211    virtual Double_t operator()(const Double_t *x, const Double_t *params=0);  
00212    virtual void     ExecuteEvent(Int_t event, Int_t px, Int_t py);
00213    virtual void     FixParameter(Int_t ipar, Double_t value);
00214        Double_t     GetChisquare() const {return fChisquare;}
00215            TH1     *GetHistogram() const;
00216    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;
00217    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;
00218    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;
00219    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;
00220    virtual Int_t    GetNDF() const;
00221    virtual Int_t    GetNpx() const {return fNpx;}
00222     TMethodCall    *GetMethodCall() const {return fMethodCall;}
00223    virtual Int_t    GetNumberFreeParameters() const;
00224    virtual Int_t    GetNumberFitPoints() const {return fNpfits;}
00225    virtual char    *GetObjectInfo(Int_t px, Int_t py) const;
00226         TObject    *GetParent() const {return fParent;}
00227    virtual Double_t GetParError(Int_t ipar) const;
00228    virtual Double_t *GetParErrors() const {return fParErrors;}
00229    virtual void     GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const;
00230    virtual Double_t GetProb() const;
00231    virtual Int_t    GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum);
00232    virtual Double_t GetRandom();
00233    virtual Double_t GetRandom(Double_t xmin, Double_t xmax);
00234    virtual void     GetRange(Double_t &xmin, Double_t &xmax) const;
00235    virtual void     GetRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const;
00236    virtual void     GetRange(Double_t &xmin, Double_t &ymin, Double_t &zmin, Double_t &xmax, Double_t &ymax, Double_t &zmax) const;
00237    virtual Double_t GetSave(const Double_t *x);
00238    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;
00239    virtual Double_t GetXmin() const {return fXmin;}
00240    virtual Double_t GetXmax() const {return fXmax;}
00241    TAxis           *GetXaxis() const ;
00242    TAxis           *GetYaxis() const ;
00243    TAxis           *GetZaxis() const ;
00244    virtual Double_t GradientPar(Int_t ipar, const Double_t *x, Double_t eps=0.01);
00245    virtual void     GradientPar(const Double_t *x, Double_t *grad, Double_t eps=0.01);
00246    virtual void     InitArgs(const Double_t *x, const Double_t *params);
00247    static  void     InitStandardFunctions();
00248    virtual Double_t Integral(Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=1e-12);
00249    virtual Double_t Integral(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=1e-12);
00250    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);
00251    virtual Double_t IntegralError(Double_t a, Double_t b, const Double_t *params=0, const Double_t *covmat=0, Double_t epsilon=1e-12);
00252    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=1e-12);
00253    //virtual Double_t IntegralFast(const TGraph *g, Double_t a, Double_t b, Double_t *params=0);
00254    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);
00255    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);
00256    virtual Double_t IntegralMultiple(Int_t n, const Double_t *a, const Double_t *b, Double_t epsilon, Double_t &relerr);
00257    virtual Bool_t   IsInside(const Double_t *x) const;
00258    virtual void     Paint(Option_t *option="");
00259    virtual void     Print(Option_t *option="") const;
00260    virtual void     ReleaseParameter(Int_t ipar);
00261    virtual void     Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax);
00262    virtual void     SavePrimitive(ostream &out, Option_t *option = "");
00263    virtual void     SetChisquare(Double_t chi2) {fChisquare = chi2;}
00264    virtual void     SetFitResult(const ROOT::Fit::FitResult & result, const Int_t * indpar = 0);
00265    template <class PtrObj, typename MemFn> 
00266    void SetFunction( PtrObj& p, MemFn memFn );
00267    template <typename Func> 
00268    void SetFunction( Func f );
00269    virtual void     SetMaximum(Double_t maximum=-1111); // *MENU*
00270    virtual void     SetMinimum(Double_t minimum=-1111); // *MENU*
00271    virtual void     SetNDF(Int_t ndf);
00272    virtual void     SetNumberFitPoints(Int_t npfits) {fNpfits = npfits;}
00273    virtual void     SetNpx(Int_t npx=100); // *MENU*
00274    virtual void     SetParError(Int_t ipar, Double_t error);
00275    virtual void     SetParErrors(const Double_t *errors);
00276    virtual void     SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax);
00277    virtual void     SetParent(TObject *p=0) {fParent = p;}
00278    virtual void     SetRange(Double_t xmin, Double_t xmax); // *MENU*
00279    virtual void     SetRange(Double_t xmin, Double_t ymin,  Double_t xmax, Double_t ymax);
00280    virtual void     SetRange(Double_t xmin, Double_t ymin, Double_t zmin,  Double_t xmax, Double_t ymax, Double_t zmax);
00281    virtual void     SetSavedPoint(Int_t point, Double_t value);
00282    virtual void     SetTitle(const char *title=""); // *MENU*
00283    virtual void     Update();
00284 
00285    static  TF1     *GetCurrent();
00286    static  void     AbsValue(Bool_t reject=kTRUE);
00287    static  void     RejectPoint(Bool_t reject=kTRUE);
00288    static  Bool_t   RejectedPoint();
00289    static  void     SetCurrent(TF1 *f1);
00290 
00291    //Moments
00292    virtual Double_t Moment(Double_t n, Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001);
00293    virtual Double_t CentralMoment(Double_t n, Double_t a, Double_t b, const Double_t *params=0, Double_t epsilon=0.000001);
00294    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);}
00295    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);}
00296 
00297    //some useful static utility functions to compute sampling points for Integral
00298    //static  void     CalcGaussLegendreSamplingPoints(TGraph *g, Double_t eps=3.0e-11);
00299    //static  TGraph  *CalcGaussLegendreSamplingPoints(Int_t num=21, Double_t eps=3.0e-11);
00300    static  void     CalcGaussLegendreSamplingPoints(Int_t num, Double_t *x, Double_t *w, Double_t eps=3.0e-11);
00301 
00302    ClassDef(TF1,7)  //The Parametric 1-D function
00303 };
00304 
00305 inline Double_t TF1::operator()(Double_t x, Double_t y, Double_t z, Double_t t) const  
00306    { return Eval(x,y,z,t); }
00307 inline Double_t TF1::operator()(const Double_t *x, const Double_t *params)
00308    { 
00309       if (fMethodCall) InitArgs(x,params);
00310       return EvalPar(x,params); 
00311    }
00312 
00313 
00314 inline void TF1::SetRange(Double_t xmin, Double_t,  Double_t xmax, Double_t)
00315    { TF1::SetRange(xmin, xmax); }
00316 inline void TF1::SetRange(Double_t xmin, Double_t, Double_t,  Double_t xmax, Double_t, Double_t)
00317    { TF1::SetRange(xmin, xmax); }
00318 
00319 template <typename Func> 
00320 void TF1::SetFunction( Func f )    {
00321    // set function from a generic C++ callable object 
00322    fType = 1; 
00323    fFunctor = ROOT::Math::ParamFunctor(f); 
00324 } 
00325 template <class PtrObj, typename MemFn> 
00326 void TF1::SetFunction( PtrObj& p, MemFn memFn )   { 
00327    // set from a pointer to a member function
00328    fType = 1; 
00329    fFunctor = ROOT::Math::ParamFunctor(p,memFn); 
00330 } 
00331 
00332 #endif

Generated on Tue Jul 5 14:22:48 2011 for ROOT_528-00b_version by  doxygen 1.5.1