Logo ROOT   6.08/07
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 #ifndef ROOT_TF1
27 #include "TF1.h"
28 #endif
29 #ifndef ROOT_TArrayD
30 #include "TArrayD.h"
31 #endif
32 
33 class TF2 : public TF1 {
34 
35 protected:
36  Double_t fYmin; //Lower bound for the range in y
37  Double_t fYmax; //Upper bound for the range in y
38  Int_t fNpy; //Number of points along y used for the graphical representation
39  TArrayD fContour; //Array to display contour levels
40 
41 public:
42  TF2();
43  TF2(const char *name, const char *formula, Double_t xmin=0, Double_t xmax=1, Double_t ymin=0, Double_t ymax=1);
44 #ifndef __CINT__
45  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);
46  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);
47 #endif
48 
49  // constructor using a functor
50 
51  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);
52 
53 
54  // Template constructors from a pointer to any C++ class of type PtrObj with a specific member function of type
55  // MemFn.
56  template <class PtrObj, typename MemFn>
57  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) :
58  TF1(name,p,memFn,xmin,xmax,npar,ndim),
59  fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
60  {
61  fNpx = 30;
62  }
63  /// backward compatible ctor
64  template <class PtrObj, typename MemFn>
65  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 *) :
66  TF1(name,p,memFn,xmin,xmax,npar,2),
67  fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
68  {
69  fNpx = 30;
70  }
71 
72  // Template constructors from any C++ callable object, defining the operator() (double * , double *)
73  // and returning a double.
74  template <typename Func>
75  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) :
76  TF1(name,f,xmin,xmax,npar,ndim),
77  fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
78  {
79  fNpx = 30;
80  }
81  /// backward compatible ctor
82  template <typename Func>
83  TF2(const char *name, Func f, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar,const char *) :
84  TF1(name,f,xmin,xmax,npar,2),
85  fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
86  {
87  fNpx = 30;
88  }
89 
90 
91  TF2(const TF2 &f2);
92  TF2 &operator=(const TF2& rhs);
93  virtual ~TF2();
94  virtual void Copy(TObject &f2) const;
95  virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
96  virtual void Draw(Option_t *option="");
97  virtual TF1 *DrawCopy(Option_t *option="") const;
98  virtual TObject *DrawDerivative(Option_t * ="al") {return 0;}
99  virtual TObject *DrawIntegral(Option_t * ="al") {return 0;}
100  //virtual void DrawF2(const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Option_t *option="");
101  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
102  virtual Int_t GetContour(Double_t *levels=0);
103  virtual Double_t GetContourLevel(Int_t level) const;
104  Int_t GetNpy() const {return fNpy;}
105  virtual char *GetObjectInfo(Int_t px, Int_t py) const;
108  virtual void GetRandom2(Double_t &xrandom, Double_t &yrandom);
109  using TF1::GetRange;
110  virtual void GetRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const;
111  virtual void GetRange(Double_t &xmin, Double_t &ymin, Double_t &zmin, Double_t &xmax, Double_t &ymax, Double_t &zmax) const;
112  virtual Double_t GetSave(const Double_t *x);
113  virtual Double_t GetMinimumXY(Double_t &x, Double_t &y) const;
114  virtual Double_t GetMaximumXY(Double_t &x, Double_t &y) const;
115  using TF1::GetMinimum;
116  using TF1::GetMaximum;
117  virtual Double_t GetMinimum(Double_t *x ) const;
118  virtual Double_t GetMaximum(Double_t *x ) const;
119  virtual Double_t GetYmin() const {return fYmin;}
120  virtual Double_t GetYmax() const {return fYmax;}
121  using TF1::Integral;
122  virtual Double_t Integral(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsrel=1.e-6);
123  virtual Bool_t IsInside(const Double_t *x) const;
124  virtual TH1 *CreateHistogram();
125  virtual void Paint(Option_t *option="");
126  virtual void Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax);
127  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
128  virtual void SetNpy(Int_t npy=100); // *MENU*
129  virtual void SetContour(Int_t nlevels=20, const Double_t *levels=0);
130  virtual void SetContourLevel(Int_t level, Double_t value);
131  virtual void SetRange(Double_t xmin, Double_t xmax);
132  virtual void SetRange(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax); // *MENU*
133  virtual void SetRange(Double_t xmin, Double_t ymin, Double_t zmin, Double_t xmax, Double_t ymax, Double_t zmax);
134 
135  //Moments
136  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);
137  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);
138 
139  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);}
140  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);}
141 
142  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);}
143  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);}
144 
145  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);}
146 
147 protected:
148 
149  virtual Double_t FindMinMax(Double_t* x, bool findmax) const;
150 
151  ClassDef(TF2,4) //The Parametric 2-D function
152 };
153 
155  { TF1::SetRange(xmin, xmax); }
157  { SetRange(xmin, ymin, xmax, ymax); }
158 
159 #endif
const int nx
Definition: kalman.C:16
Int_t GetNpy() const
Definition: TF2.h:104
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:1338
Int_t fNpx
Definition: TF1.h:167
float xmin
Definition: THbookFile.cxx:93
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF2.cxx:216
virtual Double_t GetContourLevel(Int_t level) const
Return the number of contour levels.
Definition: TF2.cxx:295
const char Option_t
Definition: RtypesCore.h:62
float ymin
Definition: THbookFile.cxx:93
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:984
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:57
virtual Double_t GetMinimum(Double_t *x) const
Return minimum/maximum value of the function.
Definition: TF2.cxx:422
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition: TF1.cxx:3240
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:75
virtual void GetRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const
Return range of a 2-D function.
Definition: TF2.cxx:554
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Double_t GetYmax() const
Definition: TF2.h:120
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a function.
Definition: TF2.cxx:185
virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel=1.e-12)
IntegralOneDim or analytical integral.
Definition: TF1.cxx:2277
virtual Bool_t IsInside(const Double_t *x) const
Return kTRUE is the point is inside the function range.
Definition: TF2.cxx:640
Double_t fYmin
Definition: TF2.h:36
virtual Double_t Integral(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsrel=1.e-6)
Return Integral of a 2d function in range [ax,bx],[ay,by] with desired relative accuracy (default val...
Definition: TF2.cxx:619
virtual Double_t Mean2X(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition: TF2.h:139
TArrayD fContour
Definition: TF2.h:39
virtual void SetContourLevel(Int_t level, Double_t value)
Set value for one contour level.
Definition: TF2.cxx:893
virtual Double_t GetYmin() const
Definition: TF2.h:119
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual void Copy(TObject &f2) const
Copy this F2 to a new F2.
Definition: TF2.cxx:167
const int ny
Definition: kalman.C:17
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Redefines TObject::GetObjectInfo.
Definition: TF2.cxx:443
Double_t fYmax
Definition: TF2.h:37
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:397
virtual TH1 * CreateHistogram()
Create a histogram from function.
Definition: TF2.cxx:652
virtual Double_t Variance2X(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition: TF2.h:142
virtual Int_t GetContour(Double_t *levels=0)
Return contour values into array levels.
Definition: TF2.cxx:283
float ymax
Definition: THbookFile.cxx:93
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:1414
IParamFunction interface (abstract class) describing multi-dimensional parameteric functions It is a ...
virtual Double_t Variance2Y(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition: TF2.h:143
Double_t GetRandom()
Return a random number following this function shape.
Definition: TF2.cxx:469
TF2()
TF2 default constructor.
Definition: TF2.cxx:43
virtual Double_t FindMinMax(Double_t *x, bool findmax) const
Return minimum/maximum value of the function.
Definition: TF2.cxx:320
virtual ~TF2()
F2 default destructor.
Definition: TF2.cxx:152
virtual Double_t Covariance2XY(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition: TF2.h:145
virtual void SetNpy(Int_t npy=100)
Set the number of points used to draw the function.
Definition: TF2.cxx:907
float xmax
Definition: THbookFile.cxx:93
A 2-Dim function with parameters.
Definition: TF2.h:33
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TF2.cxx:273
TF2 & operator=(const TF2 &rhs)
Operator =.
Definition: TF2.cxx:141
REAL epsilon
Definition: triangle.c:617
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition: TF2.h:154
double f(double x)
double Double_t
Definition: RtypesCore.h:55
virtual void GetRandom2(Double_t &xrandom, Double_t &yrandom)
Return 2 random numbers following this function shape.
Definition: TF2.cxx:504
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes-*.
Definition: TF2.cxx:243
Double_t y[n]
Definition: legend1.C:17
virtual void SetContour(Int_t nlevels=20, const Double_t *levels=0)
Set the number and values of contour levels.
Definition: TF2.cxx:872
The TH1 histogram class.
Definition: TH1.h:80
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
virtual void Paint(Option_t *option="")
Paint this 2-D function with its current attributes.
Definition: TF2.cxx:697
Array of doubles (64 bits per element).
Definition: TArrayD.h:29
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TF2.cxx:795
Mother of all ROOT objects.
Definition: TObject.h:37
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:65
virtual Double_t Mean2Y(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition: TF2.h:140
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:83
double f2(const double *x)
virtual void GetRange(Double_t *xmin, Double_t *xmax) const
Return range of a generic N-D function.
Definition: TF1.cxx:1989
virtual Double_t GetSave(const Double_t *x)
Get value corresponding to X in array of fSave values.
Definition: TF2.cxx:579
1-Dim function class
Definition: TF1.h:149
Param Functor class for Multidimensional functions.
Definition: ParamFunctor.h:209
virtual TObject * DrawIntegral(Option_t *="al")
Draw integral of this function.
Definition: TF2.h:99
virtual Double_t GetMaximum(Double_t *x) const
Return maximum value of the function See TF2::GetMinimum.
Definition: TF2.cxx:431
char name[80]
Definition: TGX11.cxx:109
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:382
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:751
Int_t fNpy
Definition: TF2.h:38
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:1000
virtual TObject * DrawDerivative(Option_t *="al")
Draw derivative of this function.
Definition: TF2.h:98