Logo ROOT  
Reference Guide
TUnuranContDist.h
Go to the documentation of this file.
1// @(#)root/unuran:$Id$
2// Authors: L. Moneta, J. Leydold Wed Feb 28 2007
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for class TUnuranContDist
12
13
14#ifndef ROOT_Math_TUnuranContDist
15#define ROOT_Math_TUnuranContDist
16
17#include "TUnuranBaseDist.h"
18
19#include "Math/IFunctionfwd.h"
20
21class TF1;
22
23
24
25
26/**
27 \class TUnuranContDist
28 \ingroup Unuran
29
30 TUnuranContDist class describing one dimensional continuous distribution.
31 It is used by TUnuran to generate random numbers according to this distribution via
32 TUnuran::Sample()
33
34 The class can be constructed from a function (TF1) representing the probability density
35 function of the distribution. Optionally the derivative of the pdf can also be passed.
36
37 It provides a method to set the domain of the distribution ( SetDomain ) which will correspond to the range
38 of the generated random numbers. By default the domain is (-inf, + inf), indipendently of the
39 range set in the TF1 class used to construct the distribution.
40
41 In addition, some UNURAN methods requires extra information (cdf function, distribution mode,
42 area of pdf, etc...). This information can as well be set.
43 Some methods require instead of the pdf the log of the pdf.
44 This can also be controlled by setting a flag when constructing this class.
45*/
46
47
49
50public:
51
52
53 /**
54 Constructor from a TF1 objects specifying the pdf and optionally from another function
55 representing the derivative of the pdf. The flag isLogPdf can be used to pass instead of the pdf
56 (and its derivative) the log (and the derivative of the log) of the pdf.
57 By default the distribution has not domain set (it is defined between [-inf,+inf], no mode, no pdf area and no
58 cdf explicity defined. UnuRan, if needed, can compute some of this quantities, but the user if they know them can
59 set them in order to speed up the algorithm. For example in case of the Cdf, if the user has not set it, a numerical
60 integration algorithm is used to estimate the Cdf from the Pdf.
61 In case an algorithm requires only the Cdf (no Pdf), an empty distribution can be constructed and then the user must
62 set afterwards the Cdf.
63 */
64 explicit TUnuranContDist (TF1 * pdf = 0, TF1 * deriv = 0, bool isLogPdf = false );
65
66 /**
67 Constructor as before but from a generic function object interface for one-dim functions
68 */
69 explicit TUnuranContDist (const ROOT::Math::IGenFunction & pdf, const ROOT::Math::IGenFunction * dpdf = 0, bool isLogPdf = false, bool copyFunc = false);
70
71
72 /**
73 Destructor
74 */
75 virtual ~TUnuranContDist ();
76
77
78 /**
79 Copy constructor
80 */
82
83 /**
84 Assignment operator
85 */
87
88 /**
89 Clone (required by base class)
90 */
91 virtual TUnuranContDist * Clone() const { return new TUnuranContDist(*this); }
92
93
94 /**
95 set cdf distribution. If a method requires it
96 and is not set it is then estimated using numerical
97 integration from the pdf
98 */
99 void SetCdf(TF1 * cdf);
100
101 /**
102 set cdf distribution using a generic function interface
103 */
104 void SetCdf(const ROOT::Math::IGenFunction & cdf);
105
106 /**
107 Set the distribution domain. If min < max a domain is defined otherwise is undefined
108 */
109 void SetDomain(double xmin, double xmax) {
110 fXmin = xmin;
111 fXmax = xmax;
112 if (fXmin < fXmax)
113 fHasDomain = true;
114 else
115 fHasDomain = false;
116 }
117
118 /**
119 set the distribution mode (x position of its maximum)
120 */
121 void SetMode(double mode) { fMode = mode; fHasMode=true;}
122
123 /**
124 set the area below the pdf
125 */
126 void SetPdfArea(double area) { fArea = area; fHasArea=true;}
127
128 /**
129 check if distribution has a defined domain and return in case its domain
130 */
131 bool GetDomain(double & xmin, double & xmax) const {
132 xmin = fXmin;
133 xmax = fXmax;
134 return fHasDomain;
135 }
136
137 /**
138 check if a cdf function is provided for the distribution
139 */
140 bool HasCdf() const { return fCdf != 0; }
141
142 /**
143 check if distribution has a pre-computed mode
144 */
145 bool HasMode() const { return fHasMode; }
146
147
148 /**
149 check if distribution has a pre-computed area below the Pdf
150 */
151 bool HasPdfArea() const { return fHasArea; }
152
153 /**
154 return the mode (x location of maximum of the pdf)
155 */
156 double Mode() const { return fMode; }
157
158 /**
159 return area below the pdf
160 */
161 double PdfArea() const { return fArea; }
162
163
164 /**
165 flag to control if given function represent the log of a pdf
166 */
167 bool IsLogPdf() const { return fIsLogPdf; }
168
169 /**
170 evaluate the Probability Density function. Used by the UnuRan algorithms
171 */
172 double Pdf ( double x) const;
173
174 /**
175 evaluate the derivative of the pdf. Used by UnuRan
176 */
177 double DPdf( double x) const;
178
179 /**
180 evaluate the integral (cdf) on the domain. Used by Unuran algorithm
181 */
182 double Cdf(double x) const;
183
184
185protected:
186
187
188private:
189
190
191 const ROOT::Math::IGenFunction * fPdf; // pointer to the pdf
192 const ROOT::Math::IGenFunction * fDPdf; //pointer to the derivative of the pdf
193 const ROOT::Math::IGenFunction * fCdf; //pointer to the cdf (cumulative dist.)
194
195 double fXmin; //lower value of the domain
196 double fXmax; //upper value of the domain
197 double fMode; //mode of the distribution
198 double fArea; //area below pdf
199
200 // flags
201 bool fIsLogPdf; //flag to control if function pointer represent log of pdf
202 bool fHasDomain; //flag to control if distribution has a defined domain (otherwise is [-inf,+inf]
203 bool fHasMode; //flag to control if distribution has a pre-computed mode
204 bool fHasArea; //flag to control if distribution has a pre-computed area below the pdf
205 bool fOwnFunc; // flag to indicate if class manages the function pointers
206 //mutable double fX[1]; //! cached vector for using TF1::EvalPar
207
208 ClassDef(TUnuranContDist,1) //Wrapper class for one dimensional continuous distribution
209
210
211};
212
213
214
215#endif /* ROOT_Math_TUnuranContDist */
#define ClassDef(name, id)
Definition: Rtypes.h:326
float xmin
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:135
1-Dim function class
Definition: TF1.h:211
TUnuranBaseDist, base class for Unuran distribution classees such as TUnuranContDist (for one-dimensi...
TUnuranContDist class describing one dimensional continuous distribution.
const ROOT::Math::IGenFunction * fDPdf
double Mode() const
return the mode (x location of maximum of the pdf)
bool HasPdfArea() const
check if distribution has a pre-computed area below the Pdf
double DPdf(double x) const
evaluate the derivative of the pdf.
const ROOT::Math::IGenFunction * fPdf
TUnuranContDist(TF1 *pdf=0, TF1 *deriv=0, bool isLogPdf=false)
Constructor from a TF1 objects specifying the pdf and optionally from another function representing t...
double Pdf(double x) const
evaluate the Probability Density function.
virtual TUnuranContDist * Clone() const
Clone (required by base class)
const ROOT::Math::IGenFunction * fCdf
void SetMode(double mode)
set the distribution mode (x position of its maximum)
double Cdf(double x) const
evaluate the integral (cdf) on the domain.
double PdfArea() const
return area below the pdf
bool GetDomain(double &xmin, double &xmax) const
check if distribution has a defined domain and return in case its domain
void SetCdf(TF1 *cdf)
set cdf distribution.
void SetDomain(double xmin, double xmax)
Set the distribution domain.
virtual ~TUnuranContDist()
Destructor.
bool IsLogPdf() const
flag to control if given function represent the log of a pdf
void SetPdfArea(double area)
set the area below the pdf
bool HasMode() const
check if distribution has a pre-computed mode
TUnuranContDist & operator=(const TUnuranContDist &rhs)
Assignment operator.
bool HasCdf() const
check if a cdf function is provided for the distribution
Double_t x[n]
Definition: legend1.C:17