Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
23
25
26#ifndef __CINT__
27
29
30#endif
31
32#include <memory>
33#include <string>
34
35namespace ROOT {
36namespace 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
52
53public:
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) :
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) :
85 {
86 fIntegrator = CreateIntegrator(type, absTol, relTol, ncall);
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
110 if (fIntegrator) delete fIntegrator;
111 }
112
113
114 // disable copy constructur and assignment operator
115
116private:
119
120public:
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) {
132 SetFunction(f);
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
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
195protected:
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 */
#define f(i)
Definition RSha256.hxx:104
char name[80]
Definition TGX11.cxx:110
int type
Definition TGX11.cxx:121
float xmin
float xmax
Double_t(* Function)(Double_t)
Definition Functor.C:4
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:62
Numerical multi dimensional integration options.
std::string Integrator() const
name of multi-dim integrator
User class for performing multidimensional integration.
double Integral(const double *xmin, const double *xmax)
evaluate the integral with the previously given function between xmin[] and xmax[]
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
void SetOptions(const ROOT::Math::IntegratorMultiDimOptions &opt)
set the options
IntegrationMultiDim::Type Type
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...
static IntegrationMultiDim::Type GetType(const char *name)
static function to get the enumeration from a string
VirtualIntegratorMultiDim * fIntegrator
double Result() const
return result of last integration
virtual ~IntegratorMultiDim()
Template Constructor of multi dimensional Integrator passing a generic function.
int Status() const
return the Error Status of the last Integral calculation
void SetRelTolerance(double relTol)
set the relative tolerance
VirtualIntegratorMultiDim * GetIntegrator()
return a pointer to integrator object
IntegratorMultiDim(IntegrationMultiDim::Type type=IntegrationMultiDim::kDEFAULT, double absTol=-1, double relTol=-1, unsigned int ncall=0)
Generic constructor of multi dimensional Integrator.
std::string Name() const
return name of integrator
std::unique_ptr< IMultiGenFunction > fFunc
IntegratorMultiDim & operator=(const IntegratorMultiDim &)
VirtualIntegratorMultiDim * CreateIntegrator(IntegrationMultiDim::Type type, double absTol, double relTol, unsigned int ncall)
void SetFunction(const IMultiGenFunction &f)
ROOT::Math::IntegratorMultiDimOptions Options() const
retrieve the options
double Error() const
return integration error
IntegratorMultiDim(const IntegratorMultiDim &)
double Integral(Function &f, unsigned int dim, const double *xmin, const double *xmax)
evaluate the integral passing a new generic function
void SetAbsTolerance(double absTol)
set absolute tolerance
Interface (abstract) class for multi numerical integration It must be implemented by the concrete Int...
virtual void SetOptions(const ROOT::Math::IntegratorMultiDimOptions &opt)
set the options (if needed must be re-implemented by derived classes)
virtual double Integral(const double *, const double *)=0
evaluate multi-dim integral
virtual ROOT::Math::IntegratorMultiDimOptions Options() const =0
get the option used for the integration impelement by derived class otherwise return default ones
virtual void SetFunction(const IMultiGenFunction &)=0
setting a multi-dim function
virtual void SetRelTolerance(double)=0
set the desired relative Error
virtual void SetAbsTolerance(double)=0
set the desired absolute Error
virtual double Error() const =0
return the estimate of the absolute Error of the last Integral calculation
virtual double Result() const =0
return the Result of the last Integral calculation
virtual int Status() const =0
return the Error Status of the last Integral calculation
Template class to wrap any C++ callable object implementing operator() (const double * x) in a multi-...
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...