ROOT  6.06/09
Reference Guide
AdaptiveIntegratorMultiDim.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: 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 AdaptiveIntegratorMultiDim
12 
13 
14 #ifndef ROOT_Math_AdaptiveIntegratorMultiDim
15 #define ROOT_Math_AdaptiveIntegratorMultiDim
16 
17 #ifndef ROOT_Math_IFunctionfwd
18 #include "Math/IFunctionfwd.h"
19 #endif
20 
21 #include "Math/VirtualIntegrator.h"
22 
23 namespace ROOT {
24 namespace Math {
25 
26 
27 //__________________________________________________________________________________________
28 /**
29  class for adaptive quadrature integration in multi-dimensions using rectangular regions.
30  Algorithm from A.C. Genz, A.A. Malik, An adaptive algorithm for numerical integration over
31  an N-dimensional rectangular region, J. Comput. Appl. Math. 6 (1980) 295-302.
32 
33  Converted/adapted by R.Brun to C++ from Fortran CERNLIB routine RADMUL (D120)
34  The new code features many changes compared to the Fortran version.
35 
36  Control parameters are:
37 
38  minpts: Minimum number of function evaluations requested. Must not exceed maxpts.
39  if minpts < 1 minpts is set to 2^n +2*n*(n+1) +1 where n is the function dimension
40  maxpts: Maximum number of function evaluations to be allowed.
41  maxpts >= 2^n +2*n*(n+1) +1
42  if maxpts<minpts, maxpts is set to 10*minpts
43  epstol, epsrel : Specified relative and absolute accuracy.
44 
45  The integral will stop if the relative error is less than relative tolerance OR the
46  absolute error is less than the absolute tolerance
47 
48  The class computes in addition to the integral of the function is the desired interval:
49 
50  an estimation of the relative accuracy of the result.
51  number of function evaluations performed.
52  status code :
53  0 Normal exit. . At least minpts and at most maxpts calls to the function were performed.
54  1 maxpts is too small for the specified accuracy eps.
55  The result and relerr contain the values obtainable for the
56  specified value of maxpts.
57  3 n<2 or n>15
58 
59  Method:
60 
61  An integration rule of degree seven is used together with a certain
62  strategy of subdivision.
63  For a more detailed description of the method see References.
64 
65  Notes:
66 
67  1.Multi-dimensional integration is time-consuming. For each rectangular
68  subregion, the routine requires function evaluations.
69  Careful programming of the integrand might result in substantial saving
70  of time.
71  2.Numerical integration usually works best for smooth functions.
72  Some analysis or suitable transformations of the integral prior to
73  numerical work may contribute to numerical efficiency.
74 
75  References:
76 
77  1.A.C. Genz and A.A. Malik, Remarks on algorithm 006:
78  An adaptive algorithm for numerical integration over
79  an N-dimensional rectangular region, J. Comput. Appl. Math. 6 (1980) 295-302.
80  2.A. van Doren and L. de Ridder, An adaptive algorithm for numerical
81  integration over an n-dimensional cube, J.Comput. Appl. Math. 2 (1976) 207-217.
82 
83 
84  @ingroup Integration
85 
86 
87 */
88 
90 
91 public:
92 
93  /**
94  construct given optionally tolerance (absolute and relative), maximum number of function evaluation (maxpts) and
95  size of the working array.
96  The integration will stop when the absolute error is less than the absolute tolerance OR when the relative error is less
97  than the relative tolerance. The absolute tolerance by defult is not used (it is equal to zero).
98  The size of working array represents the number of sub-division used for calculating the integral.
99  Higher the dimension, larger sizes are required for getting the same accuracy.
100  The size must be larger than >= (2N + 3) * (1 + MAXPTS/(2**N + 2N(N + 1) + 1))/2). For smaller value passed, the
101  minimum allowed will be used
102  */
103  explicit
104  AdaptiveIntegratorMultiDim(double absTol = 0.0, double relTol = 1E-9, unsigned int maxpts = 100000, unsigned int size = 0);
105 
106  /**
107  Construct with a reference to the integrand function and given optionally
108  tolerance (absolute and relative), maximum number of function evaluation (maxpts) and
109  size of the working array.
110  */
111  explicit
112  AdaptiveIntegratorMultiDim(const IMultiGenFunction &f, double absTol = 0.0, double relTol = 1E-9, unsigned int maxcall = 100000, unsigned int size = 0);
113 
114  /**
115  destructor (no operations)
116  */
118 
119 
120  /**
121  evaluate the integral with the previously given function between xmin[] and xmax[]
122  */
123  double Integral(const double* xmin, const double * xmax) {
124  return DoIntegral(xmin,xmax, false);
125  }
126 
127 
128  /// evaluate the integral passing a new function
129  double Integral(const IMultiGenFunction &f, const double* xmin, const double * xmax);
130 
131  /// set the integration function (must implement multi-dim function interface: IBaseFunctionMultiDim)
132  void SetFunction(const IMultiGenFunction &f);
133 
134  /// return result of integration
135  double Result() const { return fResult; }
136 
137  /// return integration error
138  double Error() const { return fError; }
139 
140  /// return relative error
141  double RelError() const { return fRelError; }
142 
143  /// return status of integration
144  int Status() const { return fStatus; }
145 
146  /// return number of function evaluations in calculating the integral
147  int NEval() const { return fNEval; }
148 
149  /// set relative tolerance
150  void SetRelTolerance(double relTol);
151 
152  /// set absolute tolerance
153  void SetAbsTolerance(double absTol);
154 
155  ///set workspace size
156  void SetSize(unsigned int size) { fSize = size; }
157 
158  ///set min points
159  void SetMinPts(unsigned int n) { fMinPts = n; }
160 
161  ///set max points
162  void SetMaxPts(unsigned int n) { fMaxPts = n; }
163 
164  /// set the options
166 
167  /// get the option used for the integration
169 
170 protected:
171 
172  // internal function to compute the integral (if absVal is true compute abs value of function integral
173  double DoIntegral(const double* xmin, const double * xmax, bool absVal = false);
174 
175  private:
176 
177  unsigned int fDim; // dimentionality of integrand
178  unsigned int fMinPts; // minimum number of function evaluation requested
179  unsigned int fMaxPts; // maximum number of function evaluation requested
180  unsigned int fSize; // max size of working array (explode with dimension)
181  double fAbsTol; // absolute tolerance
182  double fRelTol; // relative tolerance
183 
184  double fResult; // last integration result
185  double fError; // integration error
186  double fRelError; // Relative error
187  int fNEval; // number of function evaluation
188  int fStatus; // status of algorithm (error if not zero)
189 
190  const IMultiGenFunction* fFun; // pointer to integrand function
191 
192 };
193 
194 }//namespace Math
195 }//namespace ROOT
196 
197 #endif /* ROOT_Math_AdaptiveIntegratorMultiDim */
double DoIntegral(const double *xmin, const double *xmax, bool absVal=false)
int NEval() const
return number of function evaluations in calculating the integral
float xmin
Definition: THbookFile.cxx:93
const double absTol
void SetFunction(const IMultiGenFunction &f)
set the integration function (must implement multi-dim function interface: IBaseFunctionMultiDim) ...
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
int Status() const
return status of integration
double RelError() const
return relative error
void SetMaxPts(unsigned int n)
set max points
double Result() const
return result of integration
void SetAbsTolerance(double absTol)
set absolute tolerance
virtual ~AdaptiveIntegratorMultiDim()
destructor (no operations)
void SetRelTolerance(double relTol)
set relative tolerance
double Integral(const double *xmin, const double *xmax)
evaluate the integral with the previously given function between xmin[] and xmax[] ...
Numerical multi dimensional integration options.
Interface (abstract) class for multi numerical integration It must be implemented by the concrete Int...
Double_t E()
Definition: TMath.h:54
float xmax
Definition: THbookFile.cxx:93
double Error() const
return integration error
double f(double x)
ROOT::Math::IntegratorMultiDimOptions Options() const
get the option used for the integration
Namespace for new Math classes and functions.
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:63
void SetSize(unsigned int size)
set workspace size
void SetOptions(const ROOT::Math::IntegratorMultiDimOptions &opt)
set the options
const Int_t n
Definition: legend1.C:16
AdaptiveIntegratorMultiDim(double absTol=0.0, double relTol=1E-9, unsigned int maxpts=100000, unsigned int size=0)
construct given optionally tolerance (absolute and relative), maximum number of function evaluation (...
class for adaptive quadrature integration in multi-dimensions using rectangular regions.
void SetMinPts(unsigned int n)
set min points