ROOT  6.06/09
Reference Guide
GSLMCIntegrator.h
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Author: Magdalena Slawinska 08/2007
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2007 ROOT Foundation, CERN/PH-SFT *
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU General Public License *
10  * as published by the Free Software Foundation; either version 2 *
11  * of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this library (see file COPYING); if not, write *
20  * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
21  * 330, Boston, MA 02111-1307 USA, or contact the author. *
22  * *
23  **********************************************************************/
24 //
25 // Header file for class GSLMCIntegrator
26 //
27 //
28 
29 #ifndef ROOT_Math_GSLMCIntegrator
30 #define ROOT_Math_GSLMCIntegrator
31 
32 #ifndef ROOT_Math_MCIntegrationTypes
34 #endif
35 
36 #ifndef ROOT_Math_IFunctionfwd
37 #include "Math/IFunctionfwd.h"
38 #endif
39 
40 #ifndef ROOT_Math_IFunction
41 #include "Math/IFunction.h"
42 #endif
43 
44 
45 #ifndef ROOT_Math_MCIntegrationTypes
47 #endif
48 
49 
50 #ifndef ROOT_Math_MCParameters
51 #include "Math/MCParameters.h"
52 #endif
53 
54 #ifndef ROOT_Math_VirtualIntegrator
55 #include "Math/VirtualIntegrator.h"
56 #endif
57 
58 #include <iostream>
59 
60 
61 namespace ROOT {
62 namespace Math {
63 
64 
65 
66  class GSLMCIntegrationWorkspace;
67  class GSLMonteFunctionWrapper;
68  class GSLRngWrapper;
69 
70 
71  /**
72  @defgroup MCIntegration Numerical Monte Carlo Integration Classes
73  Classes implementing method for Monte Carlo Integration.
74  @ingroup Integration
75 
76  Class for performing numerical integration of a multidimensional function.
77  It uses the numerical integration algorithms of GSL, which reimplements the
78  algorithms used in the QUADPACK, a numerical integration package written in Fortran.
79 
80  Plain MC, MISER and VEGAS integration algorithms are supported for integration over finite (hypercubic) ranges.
81 
82  <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_16.html#SEC248">GSL Manual</A>.
83 
84  It implements also the interface ROOT::Math::VirtualIntegratorMultiDim so it can be
85  instantiate using the plugin manager (plugin name is "GSLMCIntegrator")
86 
87  @ingroup MCIntegration
88 
89  */
90 
91 
93 
94  public:
95 
97 
98  // constructors
99 
100 
101 // /**
102 // constructor of GSL MCIntegrator using all the default options
103 // */
104 // GSLMCIntegrator( );
105 
106 
107  /** constructor of GSL MCIntegrator. VEGAS MC is set as default integration type
108 
109  @param type type of integration. The possible types are defined in the MCIntegration::Type enumeration
110  Default is VEGAS
111  @param absTol desired absolute Error (this parameter is actually not used and it can be ignored. The tolerance is fixed by the number of given calls)
112  @param relTol desired relative Error (this parameter is actually not used and it can be ignored. The tolerance is fixed by the number of given calls)
113  @param calls maximum number of function calls
114 
115  NOTE: When the default values are used , the options are taken from teh static method of ROOT::Math::IntegratorMultiDimOptions
116  */
117  explicit
118  GSLMCIntegrator(MCIntegration::Type type = MCIntegration::kVEGAS, double absTol = -1, double relTol = -1, unsigned int calls = 0 );
119 
120  /** constructor of GSL MCIntegrator. VEGAS MC is set as default integration type
121 
122  @param type type of integration using a char * (required by plug-in manager)
123  @param absTol desired absolute Error
124  @param relTol desired relative Error
125  @param calls maximum number of function calls
126  */
127  GSLMCIntegrator(const char * type, double absTol, double relTol, unsigned int calls);
128 
129 
130  /**
131  destructor
132  */
133  virtual ~GSLMCIntegrator();
134 
135  // disable copy ctrs
136 
137 private:
138 
140 
142 
143 public:
144 
145 
146  // template methods for generic functors
147 
148  /**
149  method to set the a generic integration function
150 
151  @param f integration function. The function type must implement the assigment operator, <em> double operator() ( double x ) </em>
152 
153  */
154 
155 
156  void SetFunction(const IMultiGenFunction &f);
157 
158 
159  typedef double ( * GSLMonteFuncPointer ) ( double *, size_t, void *);
160 
161  void SetFunction( GSLMonteFuncPointer f, unsigned int dim, void * p = 0 );
162 
163  // methods using GSLMonteFuncPointer
164 
165  /**
166  evaluate the Integral of a function f over the defined hypercube (a,b)
167  @param f integration function. The function type must implement the mathlib::IGenFunction interface
168  @param a lower value of the integration interval
169  @param b upper value of the integration interval
170  */
171 
172  double Integral(const GSLMonteFuncPointer & f, unsigned int dim, double* a, double* b, void * p = 0);
173 
174 
175  /**
176  evaluate the integral using the previously defined function
177  */
178  double Integral(const double* a, const double* b);
179 
180 
181  // to be added later
182  //double Integral(const GSLMonteFuncPointer & f);
183 
184  //double Integral(GSLMonteFuncPointer f, void * p, double* a, double* b);
185 
186  /**
187  return the type of the integration used
188  */
189  //MCIntegration::Type MCType() const;
190 
191  /**
192  return the Result of the last Integral calculation
193  */
194  double Result() const;
195 
196  /**
197  return the estimate of the absolute Error of the last Integral calculation
198  */
199  double Error() const;
200 
201  /**
202  return the Error Status of the last Integral calculation
203  */
204  int Status() const;
205 
206 
207  /**
208  return number of function evaluations in calculating the integral
209  (This is an fixed by the user)
210  */
211  int NEval() const { return fCalls; }
212 
213 
214  // setter for control Parameters (getters are not needed so far )
215 
216  /**
217  set the desired relative Error
218  */
219  void SetRelTolerance(double relTolerance);
220 
221 
222  /**
223  set the desired absolute Error
224  */
225  void SetAbsTolerance(double absTolerance);
226 
227  /**
228  set the integration options
229  */
231 
232 
233  /**
234  set random number generator
235  */
237 
238  /**
239  set integration method
240  */
242 
243  /**
244  set integration method using a name instead of an enumeration
245  */
246  void SetTypeName(const char * typeName);
247 
248 
249  /**
250  set integration mode for VEGAS method
251  The possible MODE are :
252  MCIntegration::kIMPORTANCE (default) : VEGAS will use importance sampling
253  MCIntegration::kSTRATIFIED : VEGAS will use stratified sampling if certain condition are satisfied
254  MCIntegration::kIMPORTANCE_ONLY : VEGAS will always use importance smapling
255  */
256 
257  void SetMode(MCIntegration::Mode mode);
258 
259  /**
260  set default parameters for VEGAS method
261  */
262  void SetParameters(const VegasParameters &p);
263 
264 
265  /**
266  set default parameters for MISER method
267  */
268  void SetParameters(const MiserParameters &p);
269 
270  /**
271  set parameters for PLAIN method
272  */
273  //void SetPParameters(const PlainParameters &p);
274 
275  /**
276  returns the error sigma from the last iteration of the Vegas algorithm
277  */
278  double Sigma();
279 
280  /**
281  returns chi-squared per degree of freedom for the estimate of the integral in the Vegas algorithm
282  */
283  double ChiSqr();
284 
285  /**
286  return the type
287  (need to be called GetType to avois a conflict with typedef)
288  */
289  MCIntegration::Type GetType() const { return fType; }
290 
291  /**
292  return the name
293  */
294  const char * GetTypeName() const;
295 
296  /**
297  get the option used for the integration
298  */
300 
301  /**
302  get the specific options (for Vegas or Miser)
303  in term of string- name
304  */
306 
307 
308  protected:
309 
310  // internal method to check validity of GSL function pointer
311  bool CheckFunction();
312 
313  // set internally the type of integration method
314  void DoInitialize( );
315 
316 
317  private:
318  //type of intergation method
320 
322 
323  unsigned int fDim;
324  unsigned int fCalls;
325  double fAbsTol;
326  double fRelTol;
327 
328  // cache Error, Result and Status of integration
329 
330  double fResult;
331  double fError;
332  int fStatus;
333 
334 
337 
338  };
339 
340 
341 
342 
343 
344 } // namespace Math
345 } // namespace ROOT
346 
347 
348 #endif /* ROOT_Math_GSLMCIntegrator */
ROOT::Math::IntegratorMultiDimOptions Options() const
get the option used for the integration
double Result() const
return the type of the integration used
GSLMCIntegrator(MCIntegration::Type type=MCIntegration::kVEGAS, double absTol=-1, double relTol=-1, unsigned int calls=0)
constructor of GSL MCIntegrator using all the default options
double(* GSLMonteFuncPointer)(double *, size_t, void *)
const double absTol
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
GSLMonteFunctionWrapper * fFunction
double Integral(const GSLMonteFuncPointer &f, unsigned int dim, double *a, double *b, void *p=0)
evaluate the Integral of a function f over the defined hypercube (a,b)
Type
enumeration specifying the integration types.
MCIntegration::Type GetType() const
return the type (need to be called GetType to avois a conflict with typedef)
MCIntegration::Type Type
structures collecting parameters for MISER multidimensional integration
Definition: MCParameters.h:76
TArc * a
Definition: textangle.C:12
void SetFunction(const IMultiGenFunction &f)
method to set the a generic integration function
size_t
Definition: TBuffer.cxx:28
structures collecting parameters for VEGAS multidimensional integration FOr implementation of default...
Definition: MCParameters.h:45
int NEval() const
return number of function evaluations in calculating the integral (This is an fixed by the user) ...
double Error() const
return the estimate of the absolute Error of the last Integral calculation
void SetRelTolerance(double relTolerance)
set the desired relative Error
double ChiSqr()
returns chi-squared per degree of freedom for the estimate of the integral in the Vegas algorithm ...
const char * GetTypeName() const
return the name
virtual ~GSLMCIntegrator()
destructor
GSLMCIntegrationWorkspace * fWorkspace
GSLRngWrapper class to wrap gsl_rng structure.
Definition: GSLRngWrapper.h:25
Numerical multi dimensional integration options.
ROOT::R::TRInterface & r
Definition: Object.C:4
Interface (abstract) class for multi numerical integration It must be implemented by the concrete Int...
MCIntegration::Type fType
void SetParameters(const VegasParameters &p)
set default parameters for VEGAS method
void SetOptions(const ROOT::Math::IntegratorMultiDimOptions &opt)
set the integration options
void SetType(MCIntegration::Type type)
set integration method
void SetTypeName(const char *typeName)
set integration method using a name instead of an enumeration
double f(double x)
GSLMCIntegrator & operator=(const GSLMCIntegrator &)
int type
Definition: TGX11.cxx:120
int Status() const
return the Error Status of the last Integral calculation
double Sigma()
set parameters for PLAIN method
ROOT::Math::IOptions * ExtraOptions() const
get the specific options (for Vegas or Miser) in term of string- name
Namespace for new Math classes and functions.
void SetGenerator(GSLRngWrapper *r)
set random number generator
void SetMode(MCIntegration::Mode mode)
set integration mode for VEGAS method The possible MODE are : MCIntegration::kIMPORTANCE (default) : ...
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:32
wrapper to a multi-dim function withtout derivatives for Monte Carlo multi-dimensional integration al...
void SetAbsTolerance(double absTolerance)
set the desired absolute Error
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:63