ROOT  6.06/08
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 
88 
90 
91  public:
92 
94 
95  // constructors
96 
97 
98 // /**
99 // constructor of GSL MCIntegrator using all the default options
100 // */
101 // GSLMCIntegrator( );
102 
103 
104  /** constructor of GSL MCIntegrator. VEGAS MC is set as default integration type
105 
106  @param type type of integration. The possible types are defined in the MCIntegration::Type enumeration
107  Default is VEGAS
108  @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)
109  @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)
110  @param calls maximum number of function calls
111 
112  NOTE: When the default values are used , the options are taken from teh static method of ROOT::Math::IntegratorMultiDimOptions
113  */
114  explicit
115  GSLMCIntegrator(MCIntegration::Type type = MCIntegration::kVEGAS, double absTol = -1, double relTol = -1, unsigned int calls = 0 );
116 
117  /** constructor of GSL MCIntegrator. VEGAS MC is set as default integration type
118 
119  @param type type of integration using a char * (required by plug-in manager)
120  @param absTol desired absolute Error
121  @param relTol desired relative Error
122  @param calls maximum number of function calls
123  */
124  GSLMCIntegrator(const char * type, double absTol, double relTol, unsigned int calls);
125 
126 
127  /**
128  destructor
129  */
130  virtual ~GSLMCIntegrator();
131 
132  // disable copy ctrs
133 
134 private:
135 
137 
139 
140 public:
141 
142 
143  // template methods for generic functors
144 
145  /**
146  method to set the a generic integration function
147 
148  @param f integration function. The function type must implement the assigment operator, <em> double operator() ( double x ) </em>
149 
150  */
151 
152 
153  void SetFunction(const IMultiGenFunction &f);
154 
155 
156  typedef double ( * GSLMonteFuncPointer ) ( double *, size_t, void *);
157 
158  void SetFunction( GSLMonteFuncPointer f, unsigned int dim, void * p = 0 );
159 
160  // methods using GSLMonteFuncPointer
161 
162  /**
163  evaluate the Integral of a function f over the defined hypercube (a,b)
164  @param f integration function. The function type must implement the mathlib::IGenFunction interface
165  @param a lower value of the integration interval
166  @param b upper value of the integration interval
167  */
168 
169  double Integral(const GSLMonteFuncPointer & f, unsigned int dim, double* a, double* b, void * p = 0);
170 
171 
172  /**
173  evaluate the integral using the previously defined function
174  */
175  double Integral(const double* a, const double* b);
176 
177 
178  // to be added later
179  //double Integral(const GSLMonteFuncPointer & f);
180 
181  //double Integral(GSLMonteFuncPointer f, void * p, double* a, double* b);
182 
183  /**
184  return the type of the integration used
185  */
186  //MCIntegration::Type MCType() const;
187 
188  /**
189  return the Result of the last Integral calculation
190  */
191  double Result() const;
192 
193  /**
194  return the estimate of the absolute Error of the last Integral calculation
195  */
196  double Error() const;
197 
198  /**
199  return the Error Status of the last Integral calculation
200  */
201  int Status() const;
202 
203 
204  /**
205  return number of function evaluations in calculating the integral
206  (This is an fixed by the user)
207  */
208  int NEval() const { return fCalls; }
209 
210 
211  // setter for control Parameters (getters are not needed so far )
212 
213  /**
214  set the desired relative Error
215  */
216  void SetRelTolerance(double relTolerance);
217 
218 
219  /**
220  set the desired absolute Error
221  */
222  void SetAbsTolerance(double absTolerance);
223 
224  /**
225  set the integration options
226  */
228 
229 
230  /**
231  set random number generator
232  */
234 
235  /**
236  set integration method
237  */
239 
240  /**
241  set integration method using a name instead of an enumeration
242  */
243  void SetTypeName(const char * typeName);
244 
245 
246  /**
247  set integration mode for VEGAS method
248  The possible MODE are :
249  MCIntegration::kIMPORTANCE (default) : VEGAS will use importance sampling
250  MCIntegration::kSTRATIFIED : VEGAS will use stratified sampling if certain condition are satisfied
251  MCIntegration::kIMPORTANCE_ONLY : VEGAS will always use importance smapling
252  */
253 
254  void SetMode(MCIntegration::Mode mode);
255 
256  /**
257  set default parameters for VEGAS method
258  */
259  void SetParameters(const VegasParameters &p);
260 
261 
262  /**
263  set default parameters for MISER method
264  */
265  void SetParameters(const MiserParameters &p);
266 
267  /**
268  set parameters for PLAIN method
269  */
270  //void SetPParameters(const PlainParameters &p);
271 
272  /**
273  returns the error sigma from the last iteration of the Vegas algorithm
274  */
275  double Sigma();
276 
277  /**
278  returns chi-squared per degree of freedom for the estimate of the integral in the Vegas algorithm
279  */
280  double ChiSqr();
281 
282  /**
283  return the type
284  (need to be called GetType to avois a conflict with typedef)
285  */
286  MCIntegration::Type GetType() const { return fType; }
287 
288  /**
289  return the name
290  */
291  const char * GetTypeName() const;
292 
293  /**
294  get the option used for the integration
295  */
297 
298  /**
299  get the specific options (for Vegas or Miser)
300  in term of string- name
301  */
303 
304 
305  protected:
306 
307  // internal method to check validity of GSL function pointer
308  bool CheckFunction();
309 
310  // set internally the type of integration method
311  void DoInitialize( );
312 
313 
314  private:
315  //type of intergation method
317 
319 
320  unsigned int fDim;
321  unsigned int fCalls;
322  double fAbsTol;
323  double fRelTol;
324 
325  // cache Error, Result and Status of integration
326 
327  double fResult;
328  double fError;
329  int fStatus;
330 
331 
334 
335  };
336 
337 
338 
339 
340 
341 } // namespace Math
342 } // namespace ROOT
343 
344 
345 #endif /* ROOT_Math_GSLMCIntegrator */
MCIntegration::Type GetType() const
return the type (need to be called GetType to avois a conflict with typedef)
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.
int Status() const
return the Error Status of the last Integral calculation
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
structures collecting parameters for VEGAS multidimensional integration FOr implementation of default...
Definition: MCParameters.h:45
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 ...
virtual ~GSLMCIntegrator()
destructor
GSLMCIntegrationWorkspace * fWorkspace
GSLRngWrapper class to wrap gsl_rng structure.
Definition: GSLRngWrapper.h:25
ROOT::Math::IntegratorMultiDimOptions Options() const
get the option used for the integration
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
ROOT::Math::IOptions * ExtraOptions() const
get the specific options (for Vegas or Miser) in term of string- name
void SetType(MCIntegration::Type type)
set integration method
double Result() const
return the type of the integration used
void SetTypeName(const char *typeName)
set integration method using a name instead of an enumeration
double f(double x)
GSLMCIntegrator & operator=(const GSLMCIntegrator &)
const char * GetTypeName() const
return the name
int type
Definition: TGX11.cxx:120
double Sigma()
set parameters for PLAIN method
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
double Error() const
return the estimate of the absolute Error of the last Integral calculation
int NEval() const
return number of function evaluations in calculating the integral (This is an fixed by the user) ...