Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
GaussIntegrator.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Authors: David Gonzalez Maline 01/2008
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 , LCG ROOT MathLib Team *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for GaussIntegrator
12//
13// Created by: David Gonzalez Maline : Wed Jan 16 2008
14//
15
16#ifndef ROOT_Math_GaussIntegrator
17#define ROOT_Math_GaussIntegrator
18
19#include "Math/IFunction.h"
20
22
23#include <vector>
24
25namespace ROOT {
26namespace Math {
27
28
29//___________________________________________________________________________________________
30/**
31 User class for performing function integration.
32
33 It will use the Gauss Method for function integration in a given interval.
34 This class is implemented from TF1::Integral().
35
36 @ingroup Integration
37
38 */
39
41
42
43public:
44
45 /** Destructor */
46 ~GaussIntegrator() override;
47
48 /** Default Constructor.
49 If the tolerance are not given, use default values specified in ROOT::Math::IntegratorOneDimOptions
50 */
51 GaussIntegrator(double absTol = -1, double relTol = -1);
52
53
54 /** Static function: set the fgAbsValue flag.
55 By default TF1::Integral uses the original function value to compute the integral
56 However, TF1::Moment, CentralMoment require to compute the integral
57 using the absolute value of the function.
58 */
59 void AbsValue(bool flag);
60
61
62 // Implementing VirtualIntegrator Interface
63
64 /** Set the desired relative Error. */
65 void SetRelTolerance (double eps) override { fEpsRel = eps; }
66
67 /** This method is not implemented. */
68 void SetAbsTolerance (double eps) override { fEpsAbs = eps; }
69
70 /** Returns the result of the last Integral calculation. */
71 double Result () const override;
72
73 /** Return the estimate of the absolute Error of the last Integral calculation. */
74 double Error () const override;
75
76 /** return the status of the last integration - 0 in case of success */
77 int Status () const override;
78
79 // Implementing VirtualIntegratorOneDim Interface
80
81 /**
82 Returns Integral of function between a and b.
83 Based on original CERNLIB routine DGAUSS by Sigfried Kolbig
84 converted to C++ by Rene Brun
85
86 This function computes, to an attempted specified accuracy, the value
87 of the integral.
88
89 Method:
90 For any interval [a,b] we define g8(a,b) and g16(a,b) to be the 8-point
91 and 16-point Gaussian quadrature approximations to
92 \f[
93 I = \int^{b}_{a} f(x)dx
94 \f]
95 and define
96 \f[
97 r(a,b) = \frac{\left|g_{16}(a,b)-g_{8}(a,b)\right|}{1+\left|g_{16}(a,b)\right|}
98 \f]
99 Then,
100 \f[
101 G = \sum_{i=1}^{k}g_{16}(x_{i-1},x_{i})
102 \f]
103 where, starting with \f$x_{0} = A\f$ and finishing with \f$x_{k} = B\f$,
104 the subdivision points \f$x_{i}(i=1,2,...)\f$ are given by
105 \f[
106 x_{i} = x_{i-1} + \lambda(B-x_{i-1})
107 \f]
108 \f$\lambda\f$ is equal to the first member of the
109 sequence 1,1/2,1/4,... for which \f$r(x_{i-1}, x_{i}) < EPS\f$.
110 If, at any stage in the process of subdivision, the ratio
111 \f[
112 q = \left|\frac{x_{i}-x_{i-1}}{B-A}\right|
113 \f]
114 is so small that 1+0.005q is indistinguishable from 1 to
115 machine accuracy, an error exit occurs with the function value
116 set equal to zero.
117
118 Accuracy:
119 The user provides absolute and relative error bounds (epsrel and epsabs) and the
120 algorithm will stop when the estimated error is less than the epsabs OR is less
121 than |I| * epsrel.
122 Unless there is severe cancellation of positive and negative values of
123 f(x) over the interval [A,B], the relative error may be considered as
124 specifying a bound on the <I>relative</I> error of I in the case
125 |I|&gt;1, and a bound on the absolute error in the case |I|&lt;1. More
126 precisely, if k is the number of sub-intervals contributing to the
127 approximation (see Method), and if
128 \f[
129 I_{abs} = \int^{B}_{A} \left|f(x)\right|dx
130 \f]
131 then the relation
132 \f[
133 \frac{\left|G-I\right|}{I_{abs}+k} < EPS
134 \f]
135 will nearly always be true, provided the routine terminates without
136 printing an error message. For functions f having no singularities in
137 the closed interval [A,B] the accuracy will usually be much higher than
138 this.
139
140 Error handling:
141 The requested accuracy cannot be obtained (see Method).
142 The function value is set equal to zero.
143
144 Note 1:
145 Values of the function f(x) at the interval end-points A and B are not
146 required. The subprogram may therefore be used when these values are
147 undefined
148 */
149 double Integral (double a, double b) override;
150
151 /** Returns Integral of function on an infinite interval.
152 This function computes, to an attempted specified accuracy, the value of the integral:
153 \f[
154 I = \int^{\infty}_{-\infty} f(x)dx
155 \f]
156 Usage:
157 In any arithmetic expression, this function has the approximate value
158 of the integral I.
159
160 The integral is mapped onto [0,1] using a transformation then integral computation is surrogated to DoIntegral.
161 */
162 double Integral () override;
163
164 /** Returns Integral of function on an upper semi-infinite interval.
165 This function computes, to an attempted specified accuracy, the value of the integral:
166 \f[
167 I = \int^{\infty}_{A} f(x)dx
168 \f]
169 Usage:
170 In any arithmetic expression, this function has the approximate value
171 of the integral I.
172 - A: lower end-point of integration interval.
173
174 The integral is mapped onto [0,1] using a transformation then integral computation is surrogated to DoIntegral.
175 */
176 double IntegralUp (double a) override;
177
178 /** Returns Integral of function on a lower semi-infinite interval.
179 This function computes, to an attempted specified accuracy, the value of the integral:
180 \f[
181 I = \int^{B}_{-\infty} f(x)dx
182 \f]
183 Usage:
184 In any arithmetic expression, this function has the approximate value
185 of the integral I.
186 - B: upper end-point of integration interval.
187
188 The integral is mapped onto [0,1] using a transformation then integral computation is surrogated to DoIntegral.
189 */
190 double IntegralLow (double b) override;
191
192
193 /** Set integration function (flag control if function must be copied inside).
194 \@param f Function to be used in the calculations.
195 */
196 void SetFunction (const IGenFunction &) override;
197
198 /** This method is not implemented. */
199 double Integral (const std::vector< double > &pts) override;
200
201 /** This method is not implemented. */
202 double IntegralCauchy (double a, double b, double c) override;
203
204 /// get the option used for the integration
206
207 // set the options
208 void SetOptions(const ROOT::Math::IntegratorOneDimOptions & opt) override;
209
210private:
211
212 /**
213 Integration surrogate method. Return integral of passed function in interval [a,b]
214 Derived class (like GaussLegendreIntegrator) can re-implement this method to modify to use
215 an improved algorithm
216 */
217 virtual double DoIntegral (double a, double b, const IGenFunction* func);
218
219protected:
220
221 static bool fgAbsValue; ///< AbsValue used for the calculation of the integral
222 double fEpsRel; ///< Relative error.
223 double fEpsAbs; ///< Absolute error.
224 bool fUsedOnce; ///< Bool value to check if the function was at least called once.
225 double fLastResult; ///< Result from the last estimation.
226 double fLastError; ///< Error from the last estimation.
227 const IGenFunction* fFunction; ///< Pointer to function used.
228
229};
230
231/**
232 Auxiliary inner class for mapping infinite and semi-infinite integrals
233*/
235public:
236 enum ESemiInfinitySign {kMinus = -1, kPlus = +1};
237 IntegrandTransform(const IGenFunction* integrand);
238 IntegrandTransform(const double boundary, ESemiInfinitySign sign, const IGenFunction* integrand);
239 double operator()(double x) const;
240 double DoEval(double x) const override;
241 IGenFunction* Clone() const override;
242private:
245 double fBoundary;
247 double DoEval(double x, double boundary, int sign) const;
248};
249
250
251
252} // end namespace Math
253
254} // end namespace ROOT
255
256#endif /* ROOT_Math_GaussIntegrator */
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
User class for performing function integration.
bool fUsedOnce
Bool value to check if the function was at least called once.
double Error() const override
Return the estimate of the absolute Error of the last Integral calculation.
double Integral() override
Returns Integral of function on an infinite interval.
double IntegralCauchy(double a, double b, double c) override
This method is not implemented.
~GaussIntegrator() override
Destructor.
double fLastResult
Result from the last estimation.
void SetRelTolerance(double eps) override
Set the desired relative Error.
void SetOptions(const ROOT::Math::IntegratorOneDimOptions &opt) override
set the options (should be re-implemented by derived classes -if more options than tolerance exist
double fLastError
Error from the last estimation.
virtual double DoIntegral(double a, double b, const IGenFunction *func)
Integration surrogate method.
double fEpsAbs
Absolute error.
void SetAbsTolerance(double eps) override
This method is not implemented.
ROOT::Math::IntegratorOneDimOptions Options() const override
get the option used for the integration
double IntegralUp(double a) override
Returns Integral of function on an upper semi-infinite interval.
static bool fgAbsValue
AbsValue used for the calculation of the integral.
double Result() const override
Returns the result of the last Integral calculation.
void SetFunction(const IGenFunction &) override
Set integration function (flag control if function must be copied inside).
double IntegralLow(double b) override
Returns Integral of function on a lower semi-infinite interval.
int Status() const override
return the status of the last integration - 0 in case of success
const IGenFunction * fFunction
Pointer to function used.
void AbsValue(bool flag)
Static function: set the fgAbsValue flag.
double fEpsRel
Relative error.
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition IFunction.h:112
Auxiliary inner class for mapping infinite and semi-infinite integrals.
double DoEval(double x) const override
implementation of the evaluation function. Must be implemented by derived classes
IGenFunction * Clone() const override
Clone a function.
const IGenFunction * fIntegrand
double operator()(double x) const
Numerical one dimensional integration options.
Interface (abstract) class for 1D numerical integration It must be implemented by the concrete Integr...
Double_t x[n]
Definition legend1.C:17
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...