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