ROOT  6.06/09
Reference Guide
IntegratorMultiDim.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Authors: M. Slawinska 08/2007
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2007 , LCG ROOT MathLib Team *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header source file for class IntegratorMultiDim
12 
13 
14 #ifndef ROOT_Math_IntegratorMultiDim
15 #define ROOT_Math_IntegratorMultiDim
16 
17 
18 #ifndef ROOT_Math_IFunctionfwd
19 #include "Math/IFunctionfwd.h"
20 #endif
21 
22 #ifndef ROOT_Math_IntegrationTypes
24 #endif
25 
26 #ifndef ROOT_Math_IntegratorOptions
27 #include "Math/IntegratorOptions.h"
28 #endif
29 
30 #ifndef ROOT_Math_VirtualIntegrator
31 #include "Math/VirtualIntegrator.h"
32 #endif
33 
34 #ifndef __CINT__
35 
36 #ifndef ROOT_Math_WrappedFunction
37 #include "Math/WrappedFunction.h"
38 #endif
39 
40 #endif
41 
42 #include <memory>
43 
44 namespace ROOT {
45 namespace Math {
46 
47 //___________________________________________________________________________________________
48 /**
49  User class for performing multidimensional integration
50 
51  By default uses adaptive multi-dimensional integration using the algorithm from Genz Mallik
52  implemented in the class ROOT::Math::AdaptiveIntegratorMultiDim otherwise it can uses via the
53  plug-in manager the MC integration class (ROOT::Math::GSLMCIntegration) from MathMore.
54 
55  @ingroup Integration
56 
57 
58  */
59 
61 
62 public:
63 
64  typedef IntegrationMultiDim::Type Type; // for the enumerations defining the types
65 
66 
67  /** Generic constructor of multi dimensional Integrator. By default uses the Adaptive integration method
68 
69  @param type integration type (adaptive, MC methods, etc..)
70  @param absTol desired absolute Error
71  @param relTol desired relative Error
72  @param size maximum number of sub-intervals
73 
74  In case no parameter values are passed the default ones used in IntegratorMultiDimOptions are used
75  */
76  explicit
77  IntegratorMultiDim(IntegrationMultiDim::Type type = IntegrationMultiDim::kDEFAULT, double absTol = -1, double relTol = -1, unsigned int ncall = 0) :
78  fIntegrator(0), fFunc(0)
79  {
81  }
82 
83  /** Generic Constructor of multi dimensional Integrator passing a function. By default uses the adaptive integration method
84 
85  @param f integration function (multi-dim interface)
86  @param type integration type (adaptive, MC methods, etc..)
87  @param absTol desired absolute Error
88  @param relTol desired relative Error
89  @param ncall number of function calls (apply only to MC integratioon methods)
90  */
91  explicit
92  IntegratorMultiDim(const IMultiGenFunction &f, IntegrationMultiDim::Type type = IntegrationMultiDim::kDEFAULT, double absTol = -1, double relTol = -1, unsigned int ncall = 0) :
93  fIntegrator(0), fFunc(0)
94  {
96  SetFunction(f);
97  }
98 
99  // remove template constructor since is ambigous
100 
101  /** Template Constructor of multi dimensional Integrator passing a generic function. By default uses the adaptive integration method
102 
103  @param f integration function (generic function implementin operator()(const double *)
104  @param dim function dimension
105  @param type integration type (adaptive, MC methods, etc..)
106  @param absTol desired absolute Error
107  @param relTol desired relative Error
108  @param ncall number of function calls (apply only to MC integratioon methods)
109  */
110 // this is ambigous
111 // template<class Function>
112 // IntegratorMultiDim(Function & f, unsigned int dim, IntegrationMultiDim::Type type = IntegrationMultiDim::kADAPTIVE, double absTol = 1.E-9, double relTol = 1E-6, unsigned int ncall = 100000) {
113 // fIntegrator = CreateIntegrator(type, absTol, relTol, ncall);
114 // SetFunction(f, dim);
115 // }
116 
117  /// destructor
119  if (fIntegrator) delete fIntegrator;
120  }
121 
122 
123  // disable copy constructur and assignment operator
124 
125 private:
127  IntegratorMultiDim & operator=(const IntegratorMultiDim &) { return *this; }
128 
129 public:
130 
131 
132  /**
133  evaluate the integral with the previously given function between xmin[] and xmax[]
134  */
135  double Integral(const double* xmin, const double * xmax) {
136  return fIntegrator == 0 ? 0 : fIntegrator->Integral(xmin,xmax);
137  }
138 
139  /// evaluate the integral passing a new function
140  double Integral(const IMultiGenFunction &f, const double* xmin, const double * xmax) {
141  SetFunction(f);
142  return Integral(xmin,xmax);
143  }
144 
145  /// evaluate the integral passing a new generic function
146  template<class Function>
147  double Integral(Function & f , unsigned int dim, const double* xmin, const double * xmax) {
148  SetFunction<Function>(f,dim);
149  return Integral(xmin, xmax);
150  }
151 
152 
153  /**
154  set integration function using a generic function implementing the operator()(double *x)
155  The dimension of the function is in this case required
156  */
157  template <class Function>
158  void SetFunction(Function & f, unsigned int dim) {
159  fFunc = std::auto_ptr<IMultiGenFunction>(new WrappedMultiFunction<Function &> (f, dim) );
161  }
162 
163  // set the function without cloning it
166  }
167 
168  /// return result of last integration
169  double Result() const { return fIntegrator == 0 ? 0 : fIntegrator->Result(); }
170 
171  /// return integration error
172  double Error() const { return fIntegrator == 0 ? 0 : fIntegrator->Error(); }
173 
174  /// return the Error Status of the last Integral calculation
175  int Status() const { return fIntegrator == 0 ? -1 : fIntegrator->Status(); }
176 
177  // return number of function evaluations in calculating the integral
178  //unsigned int NEval() const { return fNEval; }
179 
180  /// set the relative tolerance
181  void SetRelTolerance(double relTol) { if (fIntegrator) fIntegrator->SetRelTolerance(relTol); }
182 
183  /// set absolute tolerance
185 
186  /// set the options
188 
189  /// retrieve the options
191 
192  /// return a pointer to integrator object
194 
195  /// return name of integrator
196  std::string Name() const { return (fIntegrator) ? Options().Integrator() : std::string(""); }
197 
198  /// static function to get the enumeration from a string
199  static IntegrationMultiDim::Type GetType(const char * name);
200 
201  /// static function to get a string from the enumeration
202  static std::string GetName(IntegrationMultiDim::Type);
203 
204 protected:
205 
206  VirtualIntegratorMultiDim * CreateIntegrator(IntegrationMultiDim::Type type , double absTol, double relTol, unsigned int ncall);
207 
208  private:
209 
210  VirtualIntegratorMultiDim * fIntegrator; // pointer to multi-dimensional integrator base class
211  std::auto_ptr<IMultiGenFunction> fFunc; // pointer to owned function
212 
213 
214 };
215 
216 }//namespace Math
217 }//namespace ROOT
218 
219 #endif /* ROOT_Math_IntegratorMultiDim */
virtual void SetRelTolerance(double)=0
set the desired relative Error
static IntegrationMultiDim::Type GetType(const char *name)
static function to get the enumeration from a string
Definition: Integrator.cxx:79
float xmin
Definition: THbookFile.cxx:93
const double absTol
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
IntegratorMultiDim & operator=(const IntegratorMultiDim &)
Type
enumeration specifying the integration types.
virtual double Result() const =0
return the Result of the last Integral calculation
VirtualIntegratorMultiDim * fIntegrator
double Integral(const double *xmin, const double *xmax)
evaluate the integral with the previously given function between xmin[] and xmax[] ...
double Result() const
return result of last integration
double Integral(Function &f, unsigned int dim, const double *xmin, const double *xmax)
evaluate the integral passing a new generic function
virtual double Error() const =0
return the estimate of the absolute Error of the last Integral calculation
IntegrationMultiDim::Type Type
virtual ~IntegratorMultiDim()
Template Constructor of multi dimensional Integrator passing a generic function.
virtual ROOT::Math::IntegratorMultiDimOptions Options() const =0
get the option used for the integration impelement by derived class otherwise return default ones ...
double Error() const
return integration error
int Status() const
return the Error Status of the last Integral calculation
double Integral(const IMultiGenFunction &f, const double *xmin, const double *xmax)
evaluate the integral passing a new function
void SetFunction(Function &f, unsigned int dim)
set integration function using a generic function implementing the operator()(double *x) The dimensio...
virtual void SetFunction(const IMultiGenFunction &)=0
setting a multi-dim function
std::auto_ptr< IMultiGenFunction > fFunc
Numerical multi dimensional integration options.
std::string Name() const
return name of integrator
Interface (abstract) class for multi numerical integration It must be implemented by the concrete Int...
VirtualIntegratorMultiDim * GetIntegrator()
return a pointer to integrator object
IntegratorMultiDim(const IMultiGenFunction &f, IntegrationMultiDim::Type type=IntegrationMultiDim::kDEFAULT, double absTol=-1, double relTol=-1, unsigned int ncall=0)
Generic Constructor of multi dimensional Integrator passing a function.
static std::string GetName(IntegrationMultiDim::Type)
static function to get a string from the enumeration
Definition: Integrator.cxx:91
void SetOptions(const ROOT::Math::IntegratorMultiDimOptions &opt)
set the options
float xmax
Definition: THbookFile.cxx:93
int ncall
Definition: stressTF1.cxx:20
virtual int Status() const =0
return the Error Status of the last Integral calculation
double f(double x)
void SetRelTolerance(double relTol)
set the relative tolerance
std::string Integrator() const
name of multi-dim integrator
int type
Definition: TGX11.cxx:120
Template class to wrap any C++ callable object implementing operator() (const double * x) in a multi-...
virtual void SetOptions(const ROOT::Math::IntegratorMultiDimOptions &opt)
set the options (if needed must be re-implemented by derived classes)
Namespace for new Math classes and functions.
#define name(a, b)
Definition: linkTestLib0.cpp:5
VirtualIntegratorMultiDim * CreateIntegrator(IntegrationMultiDim::Type type, double absTol, double relTol, unsigned int ncall)
Definition: Integrator.cxx:179
virtual void SetAbsTolerance(double)=0
set the desired absolute Error
User class for performing multidimensional integration.
void SetFunction(const IMultiGenFunction &f)
IntegratorMultiDim(IntegrationMultiDim::Type type=IntegrationMultiDim::kDEFAULT, double absTol=-1, double relTol=-1, unsigned int ncall=0)
Generic constructor of multi dimensional Integrator.
virtual double Integral(const double *, const double *)=0
evaluate multi-dim integral
void SetAbsTolerance(double absTol)
set absolute tolerance
ROOT::Math::IntegratorMultiDimOptions Options() const
retrieve the options
IntegratorMultiDim(const IntegratorMultiDim &)
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:63