Logo ROOT  
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
33
34#include "Math/IFunctionfwd.h"
35
36#include "Math/IFunction.h"
37
38#include "Math/MCParameters.h"
39
41
42#include <iostream>
43
44
45namespace ROOT {
46namespace Math {
47
48
49
50 class GSLMCIntegrationWorkspace;
51 class GSLMonteFunctionWrapper;
52 class GSLRandomEngine;
53 class GSLRngWrapper;
54
55
56 /**
57 @defgroup MCIntegration Numerical Monte Carlo Integration Classes
58 Classes implementing method for Monte Carlo Integration.
59 @ingroup Integration
60
61 Class for performing numerical integration of a multidimensional function.
62 It uses the numerical integration algorithms of GSL, which reimplements the
63 algorithms used in the QUADPACK, a numerical integration package written in Fortran.
64
65 Plain MC, MISER and VEGAS integration algorithms are supported for integration over finite (hypercubic) ranges.
66
67 <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_16.html#SEC248">GSL Manual</A>.
68
69 It implements also the interface ROOT::Math::VirtualIntegratorMultiDim so it can be
70 instantiate using the plugin manager (plugin name is "GSLMCIntegrator")
71 */
72
73
75
76 public:
77
79
80 // constructors
81
82
83// /**
84// constructor of GSL MCIntegrator using all the default options
85// */
86// GSLMCIntegrator( );
87
88
89 /** constructor of GSL MCIntegrator. VEGAS MC is set as default integration type
90
91 @param type type of integration. The possible types are defined in the MCIntegration::Type enumeration
92 Default is VEGAS
93 @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)
94 @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)
95 @param calls maximum number of function calls
96
97 NOTE: When the default values are used , the options are taken from the static method of ROOT::Math::IntegratorMultiDimOptions
98 */
99 explicit
100 GSLMCIntegrator(MCIntegration::Type type = MCIntegration::kVEGAS, double absTol = -1, double relTol = -1, unsigned int calls = 0 );
101
102 /** constructor of GSL MCIntegrator. VEGAS MC is set as default integration type
103
104 @param type type of integration using a char * (required by plug-in manager)
105 @param absTol desired absolute Error
106 @param relTol desired relative Error
107 @param calls maximum number of function calls
108 */
109 GSLMCIntegrator(const char * type, double absTol, double relTol, unsigned int calls);
110
111
112 /**
113 destructor
114 */
115 virtual ~GSLMCIntegrator();
116
117 // disable copy ctrs
118
119private:
120
122
124
125public:
126
127
128 // template methods for generic functors
129
130 /**
131 method to set the a generic integration function
132
133 @param f integration function. The function type must implement the assignment operator, <em> double operator() ( double x ) </em>
134
135 */
136
137
138 void SetFunction(const IMultiGenFunction &f);
139
140
141 typedef double ( * GSLMonteFuncPointer ) ( double *, size_t, void *);
142
143 void SetFunction( GSLMonteFuncPointer f, unsigned int dim, void * p = 0 );
144
145 // methods using GSLMonteFuncPointer
146
147 /**
148 evaluate the Integral of a function f over the defined hypercube (a,b)
149 @param f integration function. The function type must implement the mathlib::IGenFunction interface
150 @param a lower value of the integration interval
151 @param b upper value of the integration interval
152 */
153
154 double Integral(const GSLMonteFuncPointer & f, unsigned int dim, double* a, double* b, void * p = 0);
155
156
157 /**
158 evaluate the integral using the previously defined function
159 */
160 double Integral(const double* a, const double* b);
161
162
163 // to be added later
164 //double Integral(const GSLMonteFuncPointer & f);
165
166 //double Integral(GSLMonteFuncPointer f, void * p, double* a, double* b);
167
168 /**
169 return the type of the integration used
170 */
171 //MCIntegration::Type MCType() const;
172
173 /**
174 return the Result of the last Integral calculation
175 */
176 double Result() const;
177
178 /**
179 return the estimate of the absolute Error of the last Integral calculation
180 */
181 double Error() const;
182
183 /**
184 return the Error Status of the last Integral calculation
185 */
186 int Status() const;
187
188
189 /**
190 return number of function evaluations in calculating the integral
191 (This is an fixed by the user)
192 */
193 int NEval() const { return fCalls; }
194
195
196 // setter for control Parameters (getters are not needed so far )
197
198 /**
199 set the desired relative Error
200 */
201 void SetRelTolerance(double relTolerance);
202
203
204 /**
205 set the desired absolute Error
206 */
207 void SetAbsTolerance(double absTolerance);
208
209 /**
210 set the integration options
211 */
213
214
215 /**
216 set random number generator
217 */
219
220 /**
221 set integration method
222 */
224
225 /**
226 set integration method using a name instead of an enumeration
227 */
228 void SetTypeName(const char * typeName);
229
230
231 /**
232 set integration mode for VEGAS method
233 The possible MODE are :
234 MCIntegration::kIMPORTANCE (default) : VEGAS will use importance sampling
235 MCIntegration::kSTRATIFIED : VEGAS will use stratified sampling if certain condition are satisfied
236 MCIntegration::kIMPORTANCE_ONLY : VEGAS will always use importance smapling
237 */
238
239 void SetMode(MCIntegration::Mode mode);
240
241 /**
242 set default parameters for VEGAS method
243 */
244 void SetParameters(const VegasParameters &p);
245
246
247 /**
248 set default parameters for MISER method
249 */
250 void SetParameters(const MiserParameters &p);
251
252 /**
253 set parameters for PLAIN method
254 */
255 //void SetPParameters(const PlainParameters &p);
256
257 /**
258 returns the error sigma from the last iteration of the Vegas algorithm
259 */
260 double Sigma();
261
262 /**
263 returns chi-squared per degree of freedom for the estimate of the integral in the Vegas algorithm
264 */
265 double ChiSqr();
266
267 /**
268 return the type
269 (need to be called GetType to avoid a conflict with typedef)
270 */
272
273 /**
274 return the name
275 */
276 const char * GetTypeName() const;
277
278 /**
279 get the option used for the integration
280 */
282
283 /**
284 get the specific options (for Vegas or Miser)
285 in term of string- name
286 */
288
289
290 protected:
291
292 // internal method to check validity of GSL function pointer
293 bool CheckFunction();
294
295 // set internally the type of integration method
296 void DoInitialize( );
297
298
299 private:
300 //type of integration method
302
304
305 unsigned int fDim;
306 unsigned int fCalls;
307 double fAbsTol;
308 double fRelTol;
309
310 // cache Error, Result and Status of integration
311
312 double fResult;
313 double fError;
315 bool fExtGen; // flag indicating if class uses an external generator provided by the user
316
317
320
321 };
322
323
324
325
326
327} // namespace Math
328} // namespace ROOT
329
330
331#endif /* ROOT_Math_GSLMCIntegrator */
double
Definition: Converters.cxx:939
ROOT::R::TRInterface & r
Definition: Object.C:4
#define b(i)
Definition: RSha256.hxx:100
#define f(i)
Definition: RSha256.hxx:104
int type
Definition: TGX11.cxx:121
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)
double Error() const
return the estimate of the absolute Error of the last Integral calculation
GSLMonteFunctionWrapper * fFunction
MCIntegration::Type Type
GSLMCIntegrator(MCIntegration::Type type=MCIntegration::kVEGAS, double absTol=-1, double relTol=-1, unsigned int calls=0)
constructor of GSL MCIntegrator.
const char * GetTypeName() const
return the name
GSLMCIntegrator & operator=(const GSLMCIntegrator &)
double Result() const
return the type of the integration used
void SetOptions(const ROOT::Math::IntegratorMultiDimOptions &opt)
set the integration options
double(* GSLMonteFuncPointer)(double *, size_t, void *)
void SetParameters(const VegasParameters &p)
set default parameters for VEGAS method
void SetGenerator(GSLRandomEngine &r)
set random number generator
int NEval() const
return number of function evaluations in calculating the integral (This is an fixed by the user)
ROOT::Math::IntegratorMultiDimOptions Options() const
get the option used for the integration
ROOT::Math::IOptions * ExtraOptions() const
get the specific options (for Vegas or Miser) in term of string- name
GSLMCIntegrationWorkspace * fWorkspace
void SetMode(MCIntegration::Mode mode)
set integration mode for VEGAS method The possible MODE are : MCIntegration::kIMPORTANCE (default) : ...
void SetTypeName(const char *typeName)
set integration method using a name instead of an enumeration
void SetRelTolerance(double relTolerance)
set the desired relative Error
virtual ~GSLMCIntegrator()
destructor
double Sigma()
set parameters for PLAIN method
MCIntegration::Type GetType() const
return the type (need to be called GetType to avoid a conflict with typedef)
double ChiSqr()
returns chi-squared per degree of freedom for the estimate of the integral in the Vegas algorithm
int Status() const
return the Error Status of the last Integral calculation
void SetAbsTolerance(double absTolerance)
set the desired absolute Error
void SetFunction(const IMultiGenFunction &f)
method to set the a generic integration function
void SetType(MCIntegration::Type type)
set integration method
MCIntegration::Type fType
wrapper to a multi-dim function withtout derivatives for Monte Carlo multi-dimensional integration al...
GSLRandomEngine Base class for all GSL random engines, normally user instantiate the derived classes ...
GSLRngWrapper class to wrap gsl_rng structure.
Definition: GSLRngWrapper.h:25
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:62
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:31
Numerical multi dimensional integration options.
Interface (abstract) class for multi numerical integration It must be implemented by the concrete Int...
Type
enumeration specifying the integration types.
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
structures collecting parameters for MISER multidimensional integration
Definition: MCParameters.h:76
structures collecting parameters for VEGAS multidimensional integration FOr implementation of default...
Definition: MCParameters.h:45
auto * a
Definition: textangle.C:12