Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 ~GSLMCIntegrator() override;
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) override;
139
140
141 typedef double ( * GSLMonteFuncPointer ) ( double *, size_t, void *);
142
143 void SetFunction( GSLMonteFuncPointer f, unsigned int dim, void * p = nullptr );
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 dim the dimension
151 @param a lower value of the integration interval
152 @param b upper value of the integration interval
153 @param p pointer to parameter array
154 */
155
156 double Integral(const GSLMonteFuncPointer & f, unsigned int dim, double* a, double* b, void * p = nullptr);
157
158
159 /**
160 evaluate the integral using the previously defined function
161 */
162 double Integral(const double* a, const double* b) override;
163
164
165 // to be added later
166 //double Integral(const GSLMonteFuncPointer & f);
167
168 //double Integral(GSLMonteFuncPointer f, void * p, double* a, double* b);
169
170 /**
171 return the type of the integration used
172 */
173 //MCIntegration::Type MCType() const;
174
175 /**
176 return the Result of the last Integral calculation
177 */
178 double Result() const override;
179
180 /**
181 return the estimate of the absolute Error of the last Integral calculation
182 */
183 double Error() const override;
184
185 /**
186 return the Error Status of the last Integral calculation
187 */
188 int Status() const override;
189
190
191 /**
192 return number of function evaluations in calculating the integral
193 (This is an fixed by the user)
194 */
195 int NEval() const override { return fCalls; }
196
197
198 // setter for control Parameters (getters are not needed so far )
199
200 /**
201 set the desired relative Error
202 */
203 void SetRelTolerance(double relTolerance) override;
204
205
206 /**
207 set the desired absolute Error
208 */
209 void SetAbsTolerance(double absTolerance) override;
210
211 /**
212 set the integration options
213 */
214 void SetOptions(const ROOT::Math::IntegratorMultiDimOptions & opt) override;
215
216
217 /**
218 set random number generator
219 */
221
222 /**
223 set integration method
224 */
226
227 /**
228 set integration method using a name instead of an enumeration
229 */
230 void SetTypeName(const char * typeName);
231
232
233 /**
234 set integration mode for VEGAS method
235 The possible MODE are :
236 MCIntegration::kIMPORTANCE (default) : VEGAS will use importance sampling
237 MCIntegration::kSTRATIFIED : VEGAS will use stratified sampling if certain condition are satisfied
238 MCIntegration::kIMPORTANCE_ONLY : VEGAS will always use importance sampling
239 */
240
242
243 /**
244 set default parameters for VEGAS method
245 */
246 void SetParameters(const VegasParameters &p);
247
248
249 /**
250 set default parameters for MISER method
251 */
252 void SetParameters(const MiserParameters &p);
253
254 /**
255 set parameters for PLAIN method
256 */
257 //void SetParameters(const PlainParameters &p);
258
259 /**
260 returns the error sigma from the last iteration of the Vegas algorithm
261 */
262 double Sigma();
263
264 /**
265 returns chi-squared per degree of freedom for the estimate of the integral in the Vegas algorithm
266 */
267 double ChiSqr();
268
269 /**
270 return the type
271 (need to be called GetType to avoid a conflict with typedef)
272 */
274
275 /**
276 return the name
277 */
278 const char * GetTypeName() const;
279
280 /**
281 get the option used for the integration
282 */
284
285 /**
286 get the specific options (for Vegas or Miser)
287 in term of string- name. This is for querying existing options and
288 return object is managed by the user
289 */
290 std::unique_ptr<ROOT::Math::IOptions> ExtraOptions() const;
291
292 /**
293 * Set the extra options for Vegas and Miser.
294 */
295 void SetExtraOptions(const ROOT::Math::IOptions & opt);
296
297
298 protected:
299
300 // internal method to check validity of GSL function pointer
301 bool CheckFunction();
302
303 // set internally the type of integration method
304 void DoInitialize( );
305
306
307 private:
308 //type of integration method
310
312
313 unsigned int fDim;
314 unsigned int fCalls;
315 double fAbsTol;
316 double fRelTol;
317
318 // cache Error, Result and Status of integration
319
320 double fResult;
321 double fError;
323 bool fExtGen; // flag indicating if class uses an external generator provided by the user
324
325
328
329 };
330
331
332
333
334
335} // namespace Math
336} // namespace ROOT
337
338
339#endif /* ROOT_Math_GSLMCIntegrator */
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define a(i)
Definition RSha256.hxx:99
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
void SetExtraOptions(const ROOT::Math::IOptions &opt)
Set the extra options for Vegas and Miser.
double Result() const override
return the type of the integration used
GSLMonteFunctionWrapper * fFunction
ROOT::Math::IntegratorMultiDimOptions Options() const override
get the option used for the integration
double Integral(const GSLMonteFuncPointer &f, unsigned int dim, double *a, double *b, void *p=nullptr)
evaluate the Integral of a function f over the defined hypercube (a,b)
const char * GetTypeName() const
return the name
GSLMCIntegrator & operator=(const GSLMCIntegrator &)
int NEval() const override
return number of function evaluations in calculating the integral (This is an fixed by the user)
void SetFunction(const IMultiGenFunction &f) override
method to set the a generic integration function
~GSLMCIntegrator() override
destructor
double(* GSLMonteFuncPointer)(double *, size_t, void *)
void SetRelTolerance(double relTolerance) override
set the desired relative Error
void SetOptions(const ROOT::Math::IntegratorMultiDimOptions &opt) override
set the integration options
void SetParameters(const VegasParameters &p)
set default parameters for VEGAS method
void SetGenerator(GSLRandomEngine &r)
set random number generator
void SetAbsTolerance(double absTolerance) override
set the desired absolute Error
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
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
double Error() const override
return the estimate of the absolute Error of the last Integral calculation
int Status() const override
return the Error Status of the last Integral calculation
void SetType(MCIntegration::Type type)
set integration method
std::unique_ptr< ROOT::Math::IOptions > ExtraOptions() const
get the specific options (for Vegas or Miser) in term of string- name.
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.
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:61
Generic interface for defining configuration options of a numerical algorithm.
Definition IOptions.h:28
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...
Structure collecting parameters for MISER multidimensional integration.
Structures collecting parameters for VEGAS multidimensional integration For implementation of default...