List of all members | Public Member Functions | Private Member Functions | Private Attributes
utl::Integrator< Functor > Class Template Reference

Class for integration of functions with one independent parameter. More...

#include "utl/Integrator.h"

Inheritance diagram for utl::Integrator< Functor >:
Inheritance graph
[legend]

Public Member Functions

double GetIntegral (const double a, const double b) const
 call this method when you do not care about the specific implementation More...
 
double GetRombergIntegral (const double a, const double b, const int order=5, const int maxIterations=20) const
 Romberg integration Setting order to 2 is equivalent to the Simpson's method. More...
 
double GetSimpsonIntegral (const double a, const double b, const int minLevel=4, const int maxLevel=20) const
 Simpson improvement build on top of the trapezoidal integration. More...
 
double GetTrapezoidalIntegral (const double a, const double b, const int minLevel=4, const int maxLevel=20) const
 basic trapezoidal integration More...
 
 Integrator (Functor &functor, const double accuracy=1e-5)
 
void SetAccuracy (const double accuracy)
 final accuracy goal of the integration More...
 

Private Member Functions

 for (int i=0;i< n;++i)
 
double GetTrapezoidalAverage (const double previousApproximation, const double a, const double delta, const int level) const
 Calculates succsessive approximations to the function average. More...
 

Private Attributes

double const
 average of a function represented with equidistant boxes More...
 
double fAccuracy
 
Functor & fFunctor
 
return sum n
 

Detailed Description

template<class Functor>
class utl::Integrator< Functor >

Class for integration of functions with one independent parameter.

Author
Darko Veberic
Date
15 Mar 2007

Example of usage:

// define function through the functor class
class SinFunctor {
public:
SinFunctor(const double frequency, const double amplitude)
: fFrequency(frequency), fAmplitude(amplitude) { }
double operator()(const double x) const
{ return fAmplitude * sin(fFrequency * x); }
private:
const double fFrequency;
const double fAmplitude;
};
...
// one time integration
SinFunctor sinf(3.1415, 2);
const double intSin = MakeIntegrator(sinf).GetIntegral(0, 1);
...
// repeated use of the integrator
double result = 0;
SinFunctor sinf(3.1415, 10);
const utl::Integrator<SinFunctor> integrator(sinf);
for (double d = 0; d < 100; d += 3)
result += integrator.GetIntegral(d, d+3);
...
// use lambda to hide parameters
const double frequency = 3.1415;
const double amplitude = 10;
auto sinf = [&frequency, &amplitude](const double x) { return amplitude * sin(frequency * x); }
const double res = MakeIntegrator(sinf).GetIntegral(1, 2);

Simple functions that do not need initialization or additional parameters can be used directly (without the functor):

double MyLog(const double x) { return std::log(x); }
const double res = MakeIntegrator(MyLog).GetIntegral(1, 2);

Note that some built-in function do not have a static binding (like log(), exp() etc) and have to be wrapped in functor or function.

Definition at line 72 of file Integrator.h.

Constructor & Destructor Documentation

template<class Functor>
utl::Integrator< Functor >::Integrator ( Functor &  functor,
const double  accuracy = 1e-5 
)
inline

Definition at line 75 of file Integrator.h.

Member Function Documentation

template<class Functor>
utl::Integrator< Functor >::for ( )
inlineprivate

Definition at line 219 of file Integrator.h.

template<class Functor>
double utl::Integrator< Functor >::GetIntegral ( const double  a,
const double  b 
) const
inline

call this method when you do not care about the specific implementation

Definition at line 82 of file Integrator.h.

template<class Functor>
double utl::Integrator< Functor >::GetRombergIntegral ( const double  a,
const double  b,
const int  order = 5,
const int  maxIterations = 20 
) const
inline
template<class Functor>
double utl::Integrator< Functor >::GetSimpsonIntegral ( const double  a,
const double  b,
const int  minLevel = 4,
const int  maxLevel = 20 
) const
inline

Simpson improvement build on top of the trapezoidal integration.

Definition at line 124 of file Integrator.h.

Referenced by IntegratorTest::testSpeed().

template<class Functor>
double utl::Integrator< Functor >::GetTrapezoidalAverage ( const double  previousApproximation,
const double  a,
const double  delta,
const int  level 
) const
inlineprivate

Calculates succsessive approximations to the function average.

Parameters
previousApproximation,:result of the level-1 call
a,:start of the integration interval
delta,:width of the integration interval (b - a)
level,:should be greater or equal to 1 (see point scheme below)

The evaluation points are generated according to the following scheme:

interval
level a b n
0 x x 2 <-- done by GetBoxAverage()
1 | x | 1
2 | x x | 2
3 | x x x x | 4
4 | x x x x x x x x | 8
5 |x x x x x x x x x x x x x x x x| 16
x = function evaluation

Definition at line 203 of file Integrator.h.

Referenced by utl::Integrator< utl::MuonArrivalTime::TimePDFArg >::GetRombergIntegral(), utl::Integrator< utl::MuonArrivalTime::TimePDFArg >::GetSimpsonIntegral(), and utl::Integrator< utl::MuonArrivalTime::TimePDFArg >::GetTrapezoidalIntegral().

template<class Functor>
double utl::Integrator< Functor >::GetTrapezoidalIntegral ( const double  a,
const double  b,
const int  minLevel = 4,
const int  maxLevel = 20 
) const
inline

basic trapezoidal integration

Definition at line 155 of file Integrator.h.

Referenced by IntegratorTest::testSpeed().

template<class Functor>
void utl::Integrator< Functor >::SetAccuracy ( const double  accuracy)
inline

final accuracy goal of the integration

Definition at line 79 of file Integrator.h.

Member Data Documentation

template<class Functor>
double utl::Integrator< Functor >::const
private
Initial value:
{
double sum = 0

average of a function represented with equidistant boxes

Definition at line 217 of file Integrator.h.

template<class Functor>
double utl::Integrator< Functor >::fAccuracy
private
template<class Functor>
Functor& utl::Integrator< Functor >::fFunctor
private
template<class Functor>
return sum utl::Integrator< Functor >::n
private

The documentation for this class was generated from the following file:

, generated on Tue Sep 26 2023.