Logo ROOT  
Reference Guide
TF2.h
Go to the documentation of this file.
1 // @(#)root/hist:$Id$
2 // Author: Rene Brun 23/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 // ---------------------------------- F2.h
12 
13 #ifndef ROOT_TF2
14 #define ROOT_TF2
15 
16 
17 
18 //////////////////////////////////////////////////////////////////////////
19 // //
20 // TF2 //
21 // //
22 // The Parametric 2-D function //
23 // //
24 //////////////////////////////////////////////////////////////////////////
25 
26 #include "TF1.h"
27 #include "TArrayD.h"
28 
29 class TF2 : public TF1 {
30 
31 protected:
32  Double_t fYmin; //Lower bound for the range in y
33  Double_t fYmax; //Upper bound for the range in y
34  Int_t fNpy; //Number of points along y used for the graphical representation
35  TArrayD fContour; //Array to display contour levels
36 
37 public:
38  TF2();
39  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);
40 #ifndef __CINT__
41  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);
42  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);
43 #endif
44 
45  // constructor using a functor
46 
47  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);
48 
49 
50  // Template constructors from a pointer to any C++ class of type PtrObj with a specific member function of type
51  // MemFn.
52  template <class PtrObj, typename MemFn>
53  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) :
54  TF1(name,p,memFn,xmin,xmax,npar,ndim),
55  fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
56  {
57  fNpx = 30;
58  }
59  /// backward compatible ctor
60  template <class PtrObj, typename MemFn>
61  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 *) :
62  TF1(name,p,memFn,xmin,xmax,npar,2),
63  fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
64  {
65  fNpx = 30;
66  }
67 
68  // Template constructors from any C++ callable object, defining the operator() (double * , double *)
69  // and returning a double.
70  template <typename Func>
71  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) :
72  TF1(name,f,xmin,xmax,npar,ndim),
73  fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
74  {
75  fNpx = 30;
76  }
77  /// backward compatible ctor
78  template <typename Func>
79  TF2(const char *name, Func f, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar,const char *) :
80  TF1(name,f,xmin,xmax,npar,2),
81  fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
82  {
83  fNpx = 30;
84  }
85 
86 
87  TF2(const TF2 &f2);
88  TF2 &operator=(const TF2& rhs);
89  virtual ~TF2();
90  virtual void Copy(TObject &f2) const;
91  virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
92  virtual void Draw(Option_t *option="");
93  virtual TF1 *DrawCopy(Option_t *option="") const;
94  virtual TObject *DrawDerivative(Option_t * ="al") {return 0;}
95  virtual TObject *DrawIntegral(Option_t * ="al") {return 0;}
96  //virtual void DrawF2(const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Option_t *option="");
97  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
98  virtual Int_t GetContour(Double_t *levels=0);
99  virtual Double_t GetContourLevel(Int_t level) const;
100  Int_t GetNpy() const {return fNpy;}
101  virtual char *GetObjectInfo(Int_t px, Int_t py) const;
102  Double_t GetRandom(TRandom * rng = nullptr, Option_t * opt = nullptr);
103  Double_t GetRandom(Double_t xmin, Double_t xmax, TRandom * rng = nullptr, Option_t * opt = nullptr);
104  virtual void GetRandom2(Double_t &xrandom, Double_t &yrandom, TRandom * rng = nullptr);
105  using TF1::GetRange;
106  virtual void GetRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const;
107  virtual void GetRange(Double_t &xmin, Double_t &ymin, Double_t &zmin, Double_t &xmax, Double_t &ymax, Double_t &zmax) const;
108  virtual Double_t GetSave(const Double_t *x);
109  virtual Double_t GetMinimumXY(Double_t &x, Double_t &y) const;
110  virtual Double_t GetMaximumXY(Double_t &x, Double_t &y) const;
111  using TF1::GetMinimum;
112  using TF1::GetMaximum;
113  virtual Double_t GetMinimum(Double_t *x ) const;
114  virtual Double_t GetMaximum(Double_t *x ) const;
115  virtual Double_t GetYmin() const {return fYmin;}
116  virtual Double_t GetYmax() const {return fYmax;}
117  using TF1::Integral;
118  virtual Double_t Integral(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsrel=1.e-6);
119  virtual Bool_t IsInside(const Double_t *x) const;
120  virtual TH1 *CreateHistogram();
121  virtual void Paint(Option_t *option="");
122  virtual void Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax);
123  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
124  virtual void SetNpy(Int_t npy=100); // *MENU*
125  virtual void SetContour(Int_t nlevels=20, const Double_t *levels=0);
126  virtual void SetContourLevel(Int_t level, Double_t value);
127  virtual void SetRange(Double_t xmin, Double_t xmax);
128  virtual void SetRange(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax); // *MENU*
130 
131  //Moments
132  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);
133  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);
134 
135  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);}
136  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);}
137 
138  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);}
139  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);}
140 
141  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);}
142 
143 protected:
144 
145  virtual Double_t FindMinMax(Double_t* x, bool findmax) const;
146 
147  ClassDef(TF2,4) //The Parametric 2-D function
148 };
149 
151  { TF1::SetRange(xmin, xmax); }
153  { SetRange(xmin, ymin, xmax, ymax); }
154 
155 #endif
TF2::Copy
virtual void Copy(TObject &f2) const
Copy this F2 to a new F2.
Definition: TF2.cxx:192
TF2::Variance2Y
virtual Double_t Variance2Y(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition: TF2.h:139
ymax
float ymax
Definition: THbookFile.cxx:95
f
#define f(i)
Definition: RSha256.hxx:104
TF1::GetMaximum
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:1615
Option_t
const char Option_t
Definition: RtypesCore.h:66
TF1::Integral
virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel=1.e-12)
IntegralOneDim or analytical integral.
Definition: TF1.cxx:2519
TF2::fYmin
Double_t fYmin
Definition: TF2.h:32
TF2::SetNpy
virtual void SetNpy(Int_t npy=100)
Set the number of points used to draw the function.
Definition: TF2.cxx:936
TF2::CreateHistogram
virtual TH1 * CreateHistogram()
Create a histogram from function.
Definition: TF2.cxx:681
xmax
float xmax
Definition: THbookFile.cxx:95
TF2::GetMinimum
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:1697
TF2::FindMinMax
virtual Double_t FindMinMax(Double_t *x, bool findmax) const
Return minimum/maximum value of the function.
Definition: TF2.cxx:345
TF2::GetYmin
virtual Double_t GetYmin() const
Definition: TF2.h:115
Int_t
int Int_t
Definition: RtypesCore.h:45
TF2::Save
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: TF2.cxx:780
TF2::SetContour
virtual void SetContour(Int_t nlevels=20, const Double_t *levels=0)
Set the number and values of contour levels.
Definition: TF2.cxx:901
TF2::fContour
TArrayD fContour
Definition: TF2.h:35
x
Double_t x[n]
Definition: legend1.C:17
TF2::Mean2Y
virtual Double_t Mean2Y(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition: TF2.h:136
TF2::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TF2.cxx:824
TF2::DistancetoPrimitive
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a function.
Definition: TF2.cxx:210
TF2::DrawIntegral
virtual TObject * DrawIntegral(Option_t *="al")
Draw integral of this function.
Definition: TF2.h:95
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TF2::GetSave
virtual Double_t GetSave(const Double_t *x)
Get value corresponding to X in array of fSave values.
Definition: TF2.cxx:605
TF2::Integral
virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel=1.e-12)
IntegralOneDim or analytical integral.
Definition: TF1.cxx:2519
TF2::Mean2X
virtual Double_t Mean2X(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition: TF2.h:135
TF1::GetRange
virtual void GetRange(Double_t *xmin, Double_t *xmax) const
Return range of a generic N-D function.
Definition: TF1.cxx:2280
TF2::TF2
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)
Definition: TF2.h:53
TArrayD.h
TF2::GetRandom2
virtual void GetRandom2(Double_t &xrandom, Double_t &yrandom, TRandom *rng=nullptr)
Return 2 random numbers following this function shape.
Definition: TF2.cxx:529
TRandom
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
TF2::GetMaximum
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:1615
xmin
float xmin
Definition: THbookFile.cxx:95
TF2::GetNpy
Int_t GetNpy() const
Definition: TF2.h:100
TF2::TF2
TF2(const char *name, Func f, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar, const char *)
backward compatible ctor
Definition: TF2.h:79
TF2::GetContourLevel
virtual Double_t GetContourLevel(Int_t level) const
Return the number of contour levels.
Definition: TF2.cxx:320
epsilon
REAL epsilon
Definition: triangle.c:617
TF2::Covariance2XY
virtual Double_t Covariance2XY(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition: TF2.h:141
TF2::GetMinimumXY
virtual Double_t GetMinimumXY(Double_t &x, Double_t &y) const
Compute the X and Y values corresponding to the minimum value of the function.
Definition: TF2.cxx:407
TF2::operator=
TF2 & operator=(const TF2 &rhs)
Operator =.
Definition: TF2.cxx:166
TF2::SetContourLevel
virtual void SetContourLevel(Int_t level, Double_t value)
Set value for one contour level.
Definition: TF2.cxx:922
TF2::GetYmax
virtual Double_t GetYmax() const
Definition: TF2.h:116
TF2::Draw
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF2.cxx:241
y
Double_t y[n]
Definition: legend1.C:17
TF2::SetRange
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition: TF2.h:150
TF2::Paint
virtual void Paint(Option_t *option="")
Paint this 2-D function with its current attributes.
Definition: TF2.cxx:726
TF2::TF2
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)
Definition: TF2.h:71
TF2::~TF2
virtual ~TF2()
F2 default destructor.
Definition: TF2.cxx:177
TF1::SetRange
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition: TF1.cxx:3536
ymin
float ymin
Definition: THbookFile.cxx:95
TF2::TF2
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 *)
backward compatible ctor
Definition: TF2.h:61
TF2
A 2-Dim function with parameters.
Definition: TF2.h:29
TF2::TF2
TF2()
TF2 default constructor.
Definition: TF2.cxx:64
Double_t
double Double_t
Definition: RtypesCore.h:59
TF2::fYmax
Double_t fYmax
Definition: TF2.h:33
TF1.h
TF2::IsInside
virtual Bool_t IsInside(const Double_t *x) const
Return kTRUE is the point is inside the function range.
Definition: TF2.cxx:669
TF2::GetMaximumXY
virtual Double_t GetMaximumXY(Double_t &x, Double_t &y) const
Compute the X and Y values corresponding to the maximum value of the function.
Definition: TF2.cxx:422
TF1::GetMinimum
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:1697
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TF2::DrawCopy
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes-*.
Definition: TF2.cxx:268
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TH1
TH1 is the base class of all histogramm classes in ROOT.
Definition: TH1.h:58
TF2::GetRange
virtual void GetRange(Double_t *xmin, Double_t *xmax) const
Return range of a generic N-D function.
Definition: TF1.cxx:2280
TF2::GetRandom
Double_t GetRandom(TRandom *rng=nullptr, Option_t *opt=nullptr)
Return a random number following this function shape.
Definition: TF2.cxx:494
name
char name[80]
Definition: TGX11.cxx:110
TF2::GetObjectInfo
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Redefines TObject::GetObjectInfo.
Definition: TF2.cxx:468
TF2::CentralMoment2
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)
Return x^nx * y^ny central moment of a 2d function in range [ax,bx],[ay,by].
Definition: TF2.cxx:1037
TF2::Moment2
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)
Return x^nx * y^ny moment of a 2d function in range [ax,bx],[ay,by].
Definition: TF2.cxx:1013
TF2::ExecuteEvent
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TF2.cxx:298
TF1
1-Dim function class
Definition: TF1.h:213
TArrayD
Array of doubles (64 bits per element).
Definition: TArrayD.h:27
TF2::Variance2X
virtual Double_t Variance2X(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition: TF2.h:138
ROOT::Math::ParamFunctorTempl
Param Functor class for Multidimensional functions.
Definition: ParamFunctor.h:273
TF2::fNpy
Int_t fNpy
Definition: TF2.h:34
TF2::DrawDerivative
virtual TObject * DrawDerivative(Option_t *="al")
Draw derivative of this function.
Definition: TF2.h:94
TF1::fNpx
Int_t fNpx
Definition: TF1.h:247
TF2::GetContour
virtual Int_t GetContour(Double_t *levels=0)
Return contour values into array levels.
Definition: TF2.cxx:308
int