Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:36:46

0001 // @(#)root/hist:$Id$
0002 // Author: Rene Brun   23/08/95
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 // ---------------------------------- F2.h
0012 
0013 #ifndef ROOT_TF2
0014 #define ROOT_TF2
0015 
0016 
0017 
0018 //////////////////////////////////////////////////////////////////////////
0019 //                                                                      //
0020 // TF2                                                                  //
0021 //                                                                      //
0022 // The Parametric 2-D function                                          //
0023 //                                                                      //
0024 //////////////////////////////////////////////////////////////////////////
0025 
0026 #include "TF1.h"
0027 #include "TArrayD.h"
0028 
0029 class TF2 : public TF1 {
0030 
0031 protected:
0032    Double_t  fYmin;        ///< Lower bound for the range in y
0033    Double_t  fYmax;        ///< Upper bound for the range in y
0034    Int_t     fNpy;         ///< Number of points along y used for the graphical representation
0035    TArrayD   fContour;     ///< Array to display contour levels
0036 
0037 public:
0038    TF2();
0039    TF2(const char *name, const char *formula, Double_t xmin = 0, Double_t xmax = 1, Double_t ymin = 0,
0040        Double_t ymax = 1, EAddToList addToGlobList = EAddToList::kDefault, bool vectorize = false);
0041    TF2(const char *name, const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax,
0042        Option_t *opt); // same as above but using a string for option
0043    TF2(const char *name, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar, Int_t ndim = 2, EAddToList addToGlobList = EAddToList::kDefault);
0044    TF2(const char *name, Double_t (*fcn)(Double_t *, Double_t *), Double_t xmin=0, Double_t xmax=1, Double_t ymin=0, Double_t ymax=1, Int_t npar=0,Int_t ndim = 2, EAddToList addToGlobList = EAddToList::kDefault);
0045    TF2(const char *name, Double_t (*fcn)(const Double_t *, const Double_t *), Double_t xmin=0, Double_t xmax=1, Double_t ymin=0, Double_t ymax=1, Int_t npar=0, Int_t ndim = 2, EAddToList addToGlobList = EAddToList::kDefault);
0046 
0047    // Constructor using a functor
0048    TF2(const char *name, ROOT::Math::ParamFunctor f, Double_t xmin = 0, Double_t xmax = 1, Double_t ymin = 0, Double_t ymax = 1, Int_t npar = 0, Int_t ndim = 2, EAddToList addToGlobList = EAddToList::kDefault);
0049 
0050    /// Template constructors from a pointer to any C++ class of type PtrObj with a specific member function of type MemFn.
0051    template <class PtrObj, typename MemFn>
0052    TF2(const char *name, const  PtrObj& p, MemFn memFn, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar, Int_t ndim = 2, EAddToList addToGlobList = EAddToList::kDefault) :
0053       TF1(name,p,memFn,xmin,xmax,npar,ndim, addToGlobList),
0054    fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
0055    {
0056       fNpx = 30;
0057    }
0058 
0059    /// Template constructors from any  C++ callable object,  defining  the operator() (double * , double *) and returning a double.
0060    template <typename Func>
0061    TF2(const char *name, Func f, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar,Int_t ndim = 2, EAddToList addToGlobList = EAddToList::kDefault) :
0062       TF1(name,f,xmin,xmax,npar,ndim, addToGlobList),
0063    fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
0064    {
0065       fNpx = 30;
0066    }
0067 
0068    TF2(const TF2 &f2);
0069    TF2 &operator=(const TF2& rhs);
0070      ~TF2() override;
0071    void     Copy(TObject &f2) const override;
0072    Int_t    DistancetoPrimitive(Int_t px, Int_t py) override;
0073    void     Draw(Option_t *option="") override;
0074    TF1     *DrawCopy(Option_t *option="") const override;
0075    TObject *DrawDerivative(Option_t * ="al") override {return nullptr;}
0076    TObject *DrawIntegral(Option_t * ="al") override   {return nullptr;}
0077    //virtual void     DrawF2(const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Option_t *option="");
0078    void     ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
0079    virtual Int_t    GetContour(Double_t *levels=nullptr);
0080    virtual Double_t GetContourLevel(Int_t level) const;
0081           Int_t     GetNpy() const {return fNpy;}
0082    char    *GetObjectInfo(Int_t px, Int_t py) const override;
0083    Double_t GetRandom(TRandom * rng = nullptr, Option_t * opt = nullptr) override;
0084    Double_t GetRandom(Double_t xmin, Double_t xmax, TRandom * rng = nullptr, Option_t * opt = nullptr) override;
0085    virtual void     GetRandom2(Double_t &xrandom, Double_t &yrandom, TRandom * rng = nullptr);
0086    using TF1::GetRange;
0087    void     GetRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const override;
0088    void     GetRange(Double_t &xmin, Double_t &ymin, Double_t &zmin, Double_t &xmax, Double_t &ymax, Double_t &zmax) const override;
0089    Double_t GetSave(const Double_t *x) override;
0090    virtual Double_t GetMinimumXY(Double_t &x, Double_t &y) const;
0091    virtual Double_t GetMaximumXY(Double_t &x, Double_t &y) const;
0092    using TF1::GetMinimum;
0093    using TF1::GetMaximum;
0094    virtual Double_t GetMinimum(Double_t *x ) const;
0095    virtual Double_t GetMaximum(Double_t *x ) const;
0096    virtual Double_t GetYmin() const {return fYmin;}
0097    virtual Double_t GetYmax() const {return fYmax;}
0098    static void InitStandardFunctions();
0099    using TF1::Integral;
0100    virtual Double_t Integral(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsrel=1.e-6);
0101    Bool_t   IsInside(const Double_t *x) const override;
0102    TH1     *CreateHistogram() override;
0103    void     Paint(Option_t *option="") override;
0104    void     Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax) override;
0105    void     SavePrimitive(std::ostream &out, Option_t *option = "") override;
0106    virtual void     SetNpy(Int_t npy=100); // *MENU*
0107    virtual void     SetContour(Int_t nlevels=20, const Double_t *levels=nullptr);
0108    virtual void     SetContourLevel(Int_t level, Double_t value);
0109    void     SetRange(Double_t xmin, Double_t xmax) override;
0110    void     SetRange(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax) override; // *MENU*
0111    void     SetRange(Double_t xmin, Double_t ymin, Double_t zmin, Double_t xmax, Double_t ymax, Double_t zmax) override;
0112    void     SetSavedPoint(Int_t point, Double_t value) override;
0113 
0114    //Moments
0115    virtual Double_t Moment2(Double_t nx, Double_t ax, Double_t bx, Double_t ny, Double_t ay, Double_t by, Double_t epsilon=0.000001);
0116    virtual Double_t CentralMoment2(Double_t nx, Double_t ax, Double_t bx, Double_t ny, Double_t ay, Double_t by, Double_t epsilon=0.000001);
0117 
0118    virtual Double_t Mean2X(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001) {return Moment2(1,ax,bx,0,ay,by,epsilon);}
0119    virtual Double_t Mean2Y(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001) {return Moment2(0,ax,bx,1,ay,by,epsilon);}
0120 
0121    virtual Double_t Variance2X(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001) {return CentralMoment2(2,ax,bx,0,ay,by,epsilon);}
0122    virtual Double_t Variance2Y(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001) {return CentralMoment2(0,ax,bx,2,ay,by,epsilon);}
0123 
0124    virtual Double_t Covariance2XY(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001) {return CentralMoment2(1,ax,bx,1,ay,by,epsilon);}
0125 
0126 protected:
0127 
0128    virtual Double_t FindMinMax(Double_t* x, bool findmax) const;
0129 
0130    ClassDefOverride(TF2,4)  //The Parametric 2-D function
0131 };
0132 
0133 inline void TF2::SetRange(Double_t xmin, Double_t xmax)
0134    { TF1::SetRange(xmin, xmax); }
0135 inline void TF2::SetRange(Double_t xmin, Double_t ymin, Double_t, Double_t xmax, Double_t ymax, Double_t)
0136    { SetRange(xmin, ymin, xmax, ymax); }
0137 
0138 #endif