Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
29class TF2 : public TF1 {
30
31protected:
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
37public:
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 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);
47
48 /// Template constructors from a pointer to any C++ class of type PtrObj with a specific member function of type MemFn.
49 template <class PtrObj, typename MemFn>
50 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) :
51 TF1(name,p,memFn,xmin,xmax,npar,ndim),
52 fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
53 {
54 fNpx = 30;
55 }
56
57 /// Backward compatible ctor
58 template <class PtrObj, typename MemFn>
59 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 *) :
60 TF1(name,p,memFn,xmin,xmax,npar,2),
61 fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
62 {
63 fNpx = 30;
64 }
65
66 /// Template constructors from any C++ callable object, defining the operator() (double * , double *) and returning a double.
67 template <typename Func>
68 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) :
69 TF1(name,f,xmin,xmax,npar,ndim),
70 fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
71 {
72 fNpx = 30;
73 }
74
75 /// Backward compatible ctor
76 template <typename Func>
77 TF2(const char *name, Func f, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t npar,const char *) :
78 TF1(name,f,xmin,xmax,npar,2),
79 fYmin(ymin), fYmax(ymax), fNpy(30), fContour(0)
80 {
81 fNpx = 30;
82 }
83
84
85 TF2(const TF2 &f2);
86 TF2 &operator=(const TF2& rhs);
87 ~TF2() override;
88 void Copy(TObject &f2) const override;
89 Int_t DistancetoPrimitive(Int_t px, Int_t py) override;
90 void Draw(Option_t *option="") override;
91 TF1 *DrawCopy(Option_t *option="") const override;
92 TObject *DrawDerivative(Option_t * ="al") override {return nullptr;}
93 TObject *DrawIntegral(Option_t * ="al") override {return nullptr;}
94 //virtual void DrawF2(const char *formula, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Option_t *option="");
95 void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
96 virtual Int_t GetContour(Double_t *levels=nullptr);
97 virtual Double_t GetContourLevel(Int_t level) const;
98 Int_t GetNpy() const {return fNpy;}
99 char *GetObjectInfo(Int_t px, Int_t py) const override;
100 Double_t GetRandom(TRandom * rng = nullptr, Option_t * opt = nullptr) override;
101 Double_t GetRandom(Double_t xmin, Double_t xmax, TRandom * rng = nullptr, Option_t * opt = nullptr) override;
102 virtual void GetRandom2(Double_t &xrandom, Double_t &yrandom, TRandom * rng = nullptr);
103 using TF1::GetRange;
104 void GetRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const override;
105 void GetRange(Double_t &xmin, Double_t &ymin, Double_t &zmin, Double_t &xmax, Double_t &ymax, Double_t &zmax) const override;
106 Double_t GetSave(const Double_t *x) override;
107 virtual Double_t GetMinimumXY(Double_t &x, Double_t &y) const;
108 virtual Double_t GetMaximumXY(Double_t &x, Double_t &y) const;
109 using TF1::GetMinimum;
110 using TF1::GetMaximum;
111 virtual Double_t GetMinimum(Double_t *x ) const;
112 virtual Double_t GetMaximum(Double_t *x ) const;
113 virtual Double_t GetYmin() const {return fYmin;}
114 virtual Double_t GetYmax() const {return fYmax;}
115 using TF1::Integral;
116 virtual Double_t Integral(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsrel=1.e-6);
117 Bool_t IsInside(const Double_t *x) const override;
118 TH1 *CreateHistogram() override;
119 void Paint(Option_t *option="") override;
120 void Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax) override;
121 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
122 virtual void SetNpy(Int_t npy=100); // *MENU*
123 virtual void SetContour(Int_t nlevels=20, const Double_t *levels=nullptr);
124 virtual void SetContourLevel(Int_t level, Double_t value);
125 void SetRange(Double_t xmin, Double_t xmax) override;
126 void SetRange(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax) override; // *MENU*
128
129 //Moments
130 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);
131 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);
132
133 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);}
134 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);}
135
136 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);}
137 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);}
138
139 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);}
140
141protected:
142
143 virtual Double_t FindMinMax(Double_t* x, bool findmax) const;
144
145 ClassDefOverride(TF2,4) //The Parametric 2-D function
146};
147
149 { TF1::SetRange(xmin, xmax); }
151 { SetRange(xmin, ymin, xmax, ymax); }
152
153#endif
#define f(i)
Definition RSha256.hxx:104
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:110
float xmin
float ymin
float xmax
float ymax
Param Functor class for Multidimensional functions.
Array of doubles (64 bits per element).
Definition TArrayD.h:27
1-Dim function class
Definition TF1.h:214
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:1698
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition TF1.cxx:3522
virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel=1.e-12)
IntegralOneDim or analytical integral.
Definition TF1.cxx:2531
virtual void GetRange(Double_t *xmin, Double_t *xmax) const
Return range of a generic N-D function.
Definition TF1.cxx:2281
Int_t fNpx
Number of points used for the graphical representation.
Definition TF1.h:248
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:1616
A 2-Dim function with parameters.
Definition TF2.h:29
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:440
virtual Double_t FindMinMax(Double_t *x, bool findmax) const
Return minimum/maximum value of the function.
Definition TF2.cxx:363
~TF2() override
F2 default destructor.
Definition TF2.cxx:195
virtual Double_t GetMinimum(Double_t *x) const
Return minimum/maximum value of the function.
Definition TF2.cxx:465
void Copy(TObject &f2) const override
Copy this F2 to a new F2.
Definition TF2.cxx:210
virtual void GetRandom2(Double_t &xrandom, Double_t &yrandom, TRandom *rng=nullptr)
Return 2 random numbers following this function shape.
Definition TF2.cxx:547
Double_t GetSave(const Double_t *x) override
Get value corresponding to X in array of fSave values.
Definition TF2.cxx:623
virtual Double_t Mean2X(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition TF2.h:133
virtual Double_t Variance2X(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition TF2.h:136
void Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax) override
Save values of function in array fSave.
Definition TF2.cxx:796
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a function.
Definition TF2.cxx:228
virtual void SetContour(Int_t nlevels=20, const Double_t *levels=nullptr)
Set the number and values of contour levels.
Definition TF2.cxx:892
TH1 * CreateHistogram() override
Create a histogram from function.
Definition TF2.cxx:697
void GetRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const override
Return range of a 2-D function.
Definition TF2.cxx:598
virtual Int_t GetContour(Double_t *levels=nullptr)
Return contour values into array levels.
Definition TF2.cxx:326
Bool_t IsInside(const Double_t *x) const override
Return kTRUE is the point is inside the function range.
Definition TF2.cxx:685
virtual void SetNpy(Int_t npy=100)
Set the number of points used to draw the function.
Definition TF2.cxx:927
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:1004
virtual Double_t Mean2Y(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition TF2.h:134
TF1 * DrawCopy(Option_t *option="") const override
Draw a copy of this function with its current attributes-*.
Definition TF2.cxx:286
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:425
Int_t fNpy
Number of points along y used for the graphical representation.
Definition TF2.h:34
void Paint(Option_t *option="") override
Paint this 2-D function with its current attributes.
Definition TF2.cxx:742
TArrayD fContour
Array to display contour levels.
Definition TF2.h:35
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:59
virtual Double_t GetYmax() const
Definition TF2.h:114
virtual Double_t Covariance2XY(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition TF2.h:139
virtual Double_t GetYmin() const
Definition TF2.h:113
Double_t fYmax
Upper bound for the range in y.
Definition TF2.h:33
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)
Template constructors from any C++ callable object, defining the operator() (double * ,...
Definition TF2.h:68
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)
Template constructors from a pointer to any C++ class of type PtrObj with a specific member function ...
Definition TF2.h:50
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TF2.cxx:841
TF2 & operator=(const TF2 &rhs)
Operator =.
Definition TF2.cxx:185
TObject * DrawIntegral(Option_t *="al") override
Draw integral of this function.
Definition TF2.h:93
char * GetObjectInfo(Int_t px, Int_t py) const override
Redefines TObject::GetObjectInfo.
Definition TF2.cxx:486
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 (defined by ...
Definition TF2.cxx:661
TObject * DrawDerivative(Option_t *="al") override
Draw derivative of this function.
Definition TF2.h:92
virtual Double_t Variance2Y(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsilon=0.000001)
Definition TF2.h:137
Double_t fYmin
Lower bound for the range in y.
Definition TF2.h:32
Int_t GetNpy() const
Definition TF2.h:98
virtual Double_t GetContourLevel(Int_t level) const
Return the number of contour levels.
Definition TF2.cxx:338
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:1028
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TF2.cxx:316
virtual void SetContourLevel(Int_t level, Double_t value)
Set value for one contour level.
Definition TF2.cxx:913
TF2()
TF2 default constructor.
Definition TF2.cxx:83
virtual Double_t GetMaximum(Double_t *x) const
Return maximum value of the function See TF2::GetMinimum.
Definition TF2.cxx:474
Double_t GetRandom(TRandom *rng=nullptr, Option_t *opt=nullptr) override
Return a random number following this function shape.
Definition TF2.cxx:512
void SetRange(Double_t xmin, Double_t xmax) override
Initialize the upper and lower bounds to draw the function.
Definition TF2.h:148
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:77
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
Mother of all ROOT objects.
Definition TObject.h:41
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
th1 Draw()
double epsilon
Definition triangle.c:618