Logo ROOT   6.12/07
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 #include "Math/IFunctionfwd.h"
19 
21 
22 #include "Math/IntegratorOptions.h"
23 
24 #include "Math/VirtualIntegrator.h"
25 
26 #ifndef __CINT__
27 
28 #include "Math/WrappedFunction.h"
29 
30 #endif
31 
32 #include <memory>
33 
34 namespace ROOT {
35 namespace Math {
36 
37 //___________________________________________________________________________________________
38 /**
39  User class for performing multidimensional integration
40 
41  By default uses adaptive multi-dimensional integration using the algorithm from Genz Mallik
42  implemented in the class ROOT::Math::AdaptiveIntegratorMultiDim otherwise it can uses via the
43  plug-in manager the MC integration class (ROOT::Math::GSLMCIntegration) from MathMore.
44 
45  @ingroup Integration
46 
47 
48  */
49 
51 
52 public:
53 
54  typedef IntegrationMultiDim::Type Type; // for the enumerations defining the types
55 
56 
57  /** Generic constructor of multi dimensional Integrator. By default uses the Adaptive integration method
58 
59  @param type integration type (adaptive, MC methods, etc..)
60  @param absTol desired absolute Error
61  @param relTol desired relative Error
62  @param size maximum number of sub-intervals
63 
64  In case no parameter values are passed the default ones used in IntegratorMultiDimOptions are used
65  */
66  explicit
67  IntegratorMultiDim(IntegrationMultiDim::Type type = IntegrationMultiDim::kDEFAULT, double absTol = -1, double relTol = -1, unsigned int ncall = 0) :
68  fIntegrator(0)
69  {
70  fIntegrator = CreateIntegrator(type, absTol, relTol, ncall);
71  }
72 
73  /** Generic Constructor of multi dimensional Integrator passing a function. By default uses the adaptive integration method
74 
75  @param f integration function (multi-dim interface)
76  @param type integration type (adaptive, MC methods, etc..)
77  @param absTol desired absolute Error
78  @param relTol desired relative Error
79  @param ncall number of function calls (apply only to MC integratioon methods)
80  */
81  explicit
82  IntegratorMultiDim(const IMultiGenFunction &f, IntegrationMultiDim::Type type = IntegrationMultiDim::kDEFAULT, double absTol = -1, double relTol = -1, unsigned int ncall = 0) :
83  fIntegrator(0)
84  {
85  fIntegrator = CreateIntegrator(type, absTol, relTol, ncall);
86  SetFunction(f);
87  }
88 
89  // remove template constructor since is ambigous
90 
91  /** Template Constructor of multi dimensional Integrator passing a generic function. By default uses the adaptive integration method
92 
93  @param f integration function (generic function implementin operator()(const double *)
94  @param dim function dimension
95  @param type integration type (adaptive, MC methods, etc..)
96  @param absTol desired absolute Error
97  @param relTol desired relative Error
98  @param ncall number of function calls (apply only to MC integratioon methods)
99  */
100 // this is ambigous
101 // template<class Function>
102 // IntegratorMultiDim(Function & f, unsigned int dim, IntegrationMultiDim::Type type = IntegrationMultiDim::kADAPTIVE, double absTol = 1.E-9, double relTol = 1E-6, unsigned int ncall = 100000) {
103 // fIntegrator = CreateIntegrator(type, absTol, relTol, ncall);
104 // SetFunction(f, dim);
105 // }
106 
107  /// destructor
109  if (fIntegrator) delete fIntegrator;
110  }
111 
112 
113  // disable copy constructur and assignment operator
114 
115 private:
117  IntegratorMultiDim & operator=(const IntegratorMultiDim &) { return *this; }
118 
119 public:
120 
121 
122  /**
123  evaluate the integral with the previously given function between xmin[] and xmax[]
124  */
125  double Integral(const double* xmin, const double * xmax) {
126  return fIntegrator == 0 ? 0 : fIntegrator->Integral(xmin,xmax);
127  }
128 
129  /// evaluate the integral passing a new function
130  double Integral(const IMultiGenFunction &f, const double* xmin, const double * xmax) {
131  SetFunction(f);
132  return Integral(xmin,xmax);
133  }
134 
135  /// evaluate the integral passing a new generic function
136  template<class Function>
137  double Integral(Function & f , unsigned int dim, const double* xmin, const double * xmax) {
138  SetFunction<Function>(f,dim);
139  return Integral(xmin, xmax);
140  }
141 
142 
143  /**
144  set integration function using a generic function implementing the operator()(double *x)
145  The dimension of the function is in this case required
146  */
147  template <class Function>
148  void SetFunction(Function & f, unsigned int dim) {
149  fFunc.reset(new WrappedMultiFunction<Function &> (f, dim) );
151  }
152 
153  // set the function without cloning it
156  }
157 
158  /// return result of last integration
159  double Result() const { return fIntegrator == 0 ? 0 : fIntegrator->Result(); }
160 
161  /// return integration error
162  double Error() const { return fIntegrator == 0 ? 0 : fIntegrator->Error(); }
163 
164  /// return the Error Status of the last Integral calculation
165  int Status() const { return fIntegrator == 0 ? -1 : fIntegrator->Status(); }
166 
167  // return number of function evaluations in calculating the integral
168  //unsigned int NEval() const { return fNEval; }
169 
170  /// set the relative tolerance
171  void SetRelTolerance(double relTol) { if (fIntegrator) fIntegrator->SetRelTolerance(relTol); }
172 
173  /// set absolute tolerance
174  void SetAbsTolerance(double absTol) { if (fIntegrator) fIntegrator->SetAbsTolerance(absTol); }
175 
176  /// set the options
178 
179  /// retrieve the options
181 
182  /// return a pointer to integrator object
184 
185  /// return name of integrator
186  std::string Name() const { return (fIntegrator) ? Options().Integrator() : std::string(""); }
187 
188  /// static function to get the enumeration from a string
189  static IntegrationMultiDim::Type GetType(const char * name);
190 
191  /// static function to get a string from the enumeration
192  static std::string GetName(IntegrationMultiDim::Type);
193 
194 protected:
195 
196  VirtualIntegratorMultiDim * CreateIntegrator(IntegrationMultiDim::Type type , double absTol, double relTol, unsigned int ncall);
197 
198  private:
199 
200  VirtualIntegratorMultiDim * fIntegrator; // pointer to multi-dimensional integrator base class
201  std::unique_ptr<IMultiGenFunction> fFunc; // pointer to owned function
202 
203 
204 };
205 
206 }//namespace Math
207 }//namespace ROOT
208 
209 #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:78
float xmin
Definition: THbookFile.cxx:93
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
IntegratorMultiDim & operator=(const IntegratorMultiDim &)
Type
enumeration specifying the integration types.
ROOT::Math::IntegratorMultiDimOptions Options() const
retrieve the options
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 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 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
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:62
std::string Integrator() const
name of multi-dim integrator
Numerical multi dimensional integration options.
Interface (abstract) class for multi numerical integration It must be implemented by the concrete Int...
Double_t(* Function)(Double_t)
Definition: Functor.C:4
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:90
int Status() const
return the Error Status of the last Integral calculation
void SetOptions(const ROOT::Math::IntegratorMultiDimOptions &opt)
set the options
float xmax
Definition: THbookFile.cxx:93
virtual int Status() const =0
return the Error Status of the last Integral calculation
double Result() const
return result of last integration
double Error() const
return integration error
void SetRelTolerance(double relTol)
set the relative tolerance
std::unique_ptr< IMultiGenFunction > fFunc
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.
VirtualIntegratorMultiDim * CreateIntegrator(IntegrationMultiDim::Type type, double absTol, double relTol, unsigned int ncall)
Definition: Integrator.cxx:178
virtual void SetAbsTolerance(double)=0
set the desired absolute Error
std::string Name() const
return name of integrator
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
IntegratorMultiDim(const IntegratorMultiDim &)
char name[80]
Definition: TGX11.cxx:109