Logo ROOT   6.08/07
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 GSLRandomEngine;
69  class GSLRngWrapper;
70 
71 
72  /**
73  @defgroup MCIntegration Numerical Monte Carlo Integration Classes
74  Classes implementing method for Monte Carlo Integration.
75  @ingroup Integration
76 
77  Class for performing numerical integration of a multidimensional function.
78  It uses the numerical integration algorithms of GSL, which reimplements the
79  algorithms used in the QUADPACK, a numerical integration package written in Fortran.
80 
81  Plain MC, MISER and VEGAS integration algorithms are supported for integration over finite (hypercubic) ranges.
82 
83  <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_16.html#SEC248">GSL Manual</A>.
84 
85  It implements also the interface ROOT::Math::VirtualIntegratorMultiDim so it can be
86  instantiate using the plugin manager (plugin name is "GSLMCIntegrator")
87  */
88 
89 
91 
92  public:
93 
95 
96  // constructors
97 
98 
99 // /**
100 // constructor of GSL MCIntegrator using all the default options
101 // */
102 // GSLMCIntegrator( );
103 
104 
105  /** constructor of GSL MCIntegrator. VEGAS MC is set as default integration type
106 
107  @param type type of integration. The possible types are defined in the MCIntegration::Type enumeration
108  Default is VEGAS
109  @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)
110  @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)
111  @param calls maximum number of function calls
112 
113  NOTE: When the default values are used , the options are taken from teh static method of ROOT::Math::IntegratorMultiDimOptions
114  */
115  explicit
116  GSLMCIntegrator(MCIntegration::Type type = MCIntegration::kVEGAS, double absTol = -1, double relTol = -1, unsigned int calls = 0 );
117 
118  /** constructor of GSL MCIntegrator. VEGAS MC is set as default integration type
119 
120  @param type type of integration using a char * (required by plug-in manager)
121  @param absTol desired absolute Error
122  @param relTol desired relative Error
123  @param calls maximum number of function calls
124  */
125  GSLMCIntegrator(const char * type, double absTol, double relTol, unsigned int calls);
126 
127 
128  /**
129  destructor
130  */
131  virtual ~GSLMCIntegrator();
132 
133  // disable copy ctrs
134 
135 private:
136 
138 
140 
141 public:
142 
143 
144  // template methods for generic functors
145 
146  /**
147  method to set the a generic integration function
148 
149  @param f integration function. The function type must implement the assigment operator, <em> double operator() ( double x ) </em>
150 
151  */
152 
153 
154  void SetFunction(const IMultiGenFunction &f);
155 
156 
157  typedef double ( * GSLMonteFuncPointer ) ( double *, size_t, void *);
158 
159  void SetFunction( GSLMonteFuncPointer f, unsigned int dim, void * p = 0 );
160 
161  // methods using GSLMonteFuncPointer
162 
163  /**
164  evaluate the Integral of a function f over the defined hypercube (a,b)
165  @param f integration function. The function type must implement the mathlib::IGenFunction interface
166  @param a lower value of the integration interval
167  @param b upper value of the integration interval
168  */
169 
170  double Integral(const GSLMonteFuncPointer & f, unsigned int dim, double* a, double* b, void * p = 0);
171 
172 
173  /**
174  evaluate the integral using the previously defined function
175  */
176  double Integral(const double* a, const double* b);
177 
178 
179  // to be added later
180  //double Integral(const GSLMonteFuncPointer & f);
181 
182  //double Integral(GSLMonteFuncPointer f, void * p, double* a, double* b);
183 
184  /**
185  return the type of the integration used
186  */
187  //MCIntegration::Type MCType() const;
188 
189  /**
190  return the Result of the last Integral calculation
191  */
192  double Result() const;
193 
194  /**
195  return the estimate of the absolute Error of the last Integral calculation
196  */
197  double Error() const;
198 
199  /**
200  return the Error Status of the last Integral calculation
201  */
202  int Status() const;
203 
204 
205  /**
206  return number of function evaluations in calculating the integral
207  (This is an fixed by the user)
208  */
209  int NEval() const { return fCalls; }
210 
211 
212  // setter for control Parameters (getters are not needed so far )
213 
214  /**
215  set the desired relative Error
216  */
217  void SetRelTolerance(double relTolerance);
218 
219 
220  /**
221  set the desired absolute Error
222  */
223  void SetAbsTolerance(double absTolerance);
224 
225  /**
226  set the integration options
227  */
229 
230 
231  /**
232  set random number generator
233  */
235 
236  /**
237  set integration method
238  */
240 
241  /**
242  set integration method using a name instead of an enumeration
243  */
244  void SetTypeName(const char * typeName);
245 
246 
247  /**
248  set integration mode for VEGAS method
249  The possible MODE are :
250  MCIntegration::kIMPORTANCE (default) : VEGAS will use importance sampling
251  MCIntegration::kSTRATIFIED : VEGAS will use stratified sampling if certain condition are satisfied
252  MCIntegration::kIMPORTANCE_ONLY : VEGAS will always use importance smapling
253  */
254 
255  void SetMode(MCIntegration::Mode mode);
256 
257  /**
258  set default parameters for VEGAS method
259  */
260  void SetParameters(const VegasParameters &p);
261 
262 
263  /**
264  set default parameters for MISER method
265  */
266  void SetParameters(const MiserParameters &p);
267 
268  /**
269  set parameters for PLAIN method
270  */
271  //void SetPParameters(const PlainParameters &p);
272 
273  /**
274  returns the error sigma from the last iteration of the Vegas algorithm
275  */
276  double Sigma();
277 
278  /**
279  returns chi-squared per degree of freedom for the estimate of the integral in the Vegas algorithm
280  */
281  double ChiSqr();
282 
283  /**
284  return the type
285  (need to be called GetType to avois a conflict with typedef)
286  */
287  MCIntegration::Type GetType() const { return fType; }
288 
289  /**
290  return the name
291  */
292  const char * GetTypeName() const;
293 
294  /**
295  get the option used for the integration
296  */
298 
299  /**
300  get the specific options (for Vegas or Miser)
301  in term of string- name
302  */
304 
305 
306  protected:
307 
308  // internal method to check validity of GSL function pointer
309  bool CheckFunction();
310 
311  // set internally the type of integration method
312  void DoInitialize( );
313 
314 
315  private:
316  //type of intergation method
318 
320 
321  unsigned int fDim;
322  unsigned int fCalls;
323  double fAbsTol;
324  double fRelTol;
325 
326  // cache Error, Result and Status of integration
327 
328  double fResult;
329  double fError;
330  int fStatus;
331  bool fExtGen; // flag indicating if class uses an external generator provided by the user
332 
333 
336 
337  };
338 
339 
340 
341 
342 
343 } // namespace Math
344 } // namespace ROOT
345 
346 
347 #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
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
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 ...
GSLRandomEngine Base class for all GSL random engines, normally user instantiate the derived classes ...
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.
TRandom2 r(17)
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 &)
void SetGenerator(GSLRandomEngine &r)
set random number generator
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 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
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
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) ...