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