Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:15:36

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, Double_t ymax=1, Option_t * opt = nullptr);
0040    TF2(const char *name, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar, Int_t ndim = 2);
0041    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);
0042    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);
0043 
0044    // Constructor using a functor
0045    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);
0046 
0047    /// Template constructors from a pointer to any C++ class of type PtrObj with a specific member function of type MemFn.
0048    template <class PtrObj, typename MemFn>
0049    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) :
0050       TF1(name,p,memFn,xmin,xmax,npar,ndim),
0051    fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
0052    {
0053       fNpx = 30;
0054    }
0055 
0056    /// Backward compatible ctor
0057    template <class PtrObj, typename MemFn>
0058    TF2(const char *name, const  PtrObj& p, MemFn memFn, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar, const char * , const char *) :
0059       TF1(name,p,memFn,xmin,xmax,npar,2),
0060    fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
0061    {
0062       fNpx = 30;
0063    }
0064 
0065    /// Template constructors from any  C++ callable object,  defining  the operator() (double * , double *) and returning a double.
0066    template <typename Func>
0067    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) :
0068       TF1(name,f,xmin,xmax,npar,ndim),
0069    fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
0070    {
0071       fNpx = 30;
0072    }
0073 
0074    /// Backward compatible ctor
0075    template <typename Func>
0076    TF2(const char *name, Func f, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar,const char *) :
0077       TF1(name,f,xmin,xmax,npar,2),
0078    fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
0079    {
0080       fNpx = 30;
0081    }
0082 
0083 
0084    TF2(const TF2 &f2);
0085    TF2 &operator=(const TF2& rhs);
0086      ~TF2() override;
0087    void     Copy(TObject &f2) const override;
0088    Int_t    DistancetoPrimitive(Int_t px, Int_t py) override;
0089    void     Draw(Option_t *option="") override;
0090    TF1     *DrawCopy(Option_t *option="") const override;
0091    TObject *DrawDerivative(Option_t * ="al") override {return nullptr;}
0092    TObject *DrawIntegral(Option_t * ="al") override   {return nullptr;}
0093    //virtual void     DrawF2(const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Option_t *option="");
0094    void     ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
0095    virtual Int_t    GetContour(Double_t *levels=nullptr);
0096    virtual Double_t GetContourLevel(Int_t level) const;
0097           Int_t     GetNpy() const {return fNpy;}
0098    char    *GetObjectInfo(Int_t px, Int_t py) const override;
0099    Double_t GetRandom(TRandom * rng = nullptr, Option_t * opt = nullptr) override;
0100    Double_t GetRandom(Double_t xmin, Double_t xmax, TRandom * rng = nullptr, Option_t * opt = nullptr) override;
0101    virtual void     GetRandom2(Double_t &xrandom, Double_t &yrandom, TRandom * rng = nullptr);
0102    using TF1::GetRange;
0103    void     GetRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const override;
0104    void     GetRange(Double_t &xmin, Double_t &ymin, Double_t &zmin, Double_t &xmax, Double_t &ymax, Double_t &zmax) const override;
0105    Double_t GetSave(const Double_t *x) override;
0106    virtual Double_t GetMinimumXY(Double_t &x, Double_t &y) const;
0107    virtual Double_t GetMaximumXY(Double_t &x, Double_t &y) const;
0108    using TF1::GetMinimum;
0109    using TF1::GetMaximum;
0110    virtual Double_t GetMinimum(Double_t *x ) const;
0111    virtual Double_t GetMaximum(Double_t *x ) const;
0112    virtual Double_t GetYmin() const {return fYmin;}
0113    virtual Double_t GetYmax() const {return fYmax;}
0114    using TF1::Integral;
0115    virtual Double_t Integral(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsrel=1.e-6);
0116    Bool_t   IsInside(const Double_t *x) const override;
0117    TH1     *CreateHistogram() override;
0118    void     Paint(Option_t *option="") override;
0119    void     Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax) override;
0120    void     SavePrimitive(std::ostream &out, Option_t *option = "") override;
0121    virtual void     SetNpy(Int_t npy=100); // *MENU*
0122    virtual void     SetContour(Int_t nlevels=20, const Double_t *levels=nullptr);
0123    virtual void     SetContourLevel(Int_t level, Double_t value);
0124    void     SetRange(Double_t xmin, Double_t xmax) override;
0125    void     SetRange(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax) override; // *MENU*
0126    void     SetRange(Double_t xmin, Double_t ymin, Double_t zmin, Double_t xmax, Double_t ymax, Double_t zmax) override;
0127    void     SetSavedPoint(Int_t point, Double_t value) override;
0128 
0129    //Moments
0130    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);
0131    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);
0132 
0133    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);}
0134    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);}
0135 
0136    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);}
0137    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);}
0138 
0139    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);}
0140 
0141 protected:
0142 
0143    virtual Double_t FindMinMax(Double_t* x, bool findmax) const;
0144 
0145    ClassDefOverride(TF2,4)  //The Parametric 2-D function
0146 };
0147 
0148 inline void TF2::SetRange(Double_t xmin, Double_t xmax)
0149    { TF1::SetRange(xmin, xmax); }
0150 inline void TF2::SetRange(Double_t xmin, Double_t ymin, Double_t, Double_t xmax, Double_t ymax, Double_t)
0151    { SetRange(xmin, ymin, xmax, ymax); }
0152 
0153 #endif