CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
funct::GaussLegendreIntegrator Class Reference

#include <NumericalIntegration.h>

Public Member Functions

 GaussLegendreIntegrator ()
 
 GaussLegendreIntegrator (unsigned int samples, double epsilon)
 
template<typename F >
double operator() (const F &f, double min, double max) const
 

Private Attributes

double a0
 
double b0
 
unsigned int i
 
double result
 
unsigned int samples_
 
std::vector< double > w
 
std::vector< double > x
 

Detailed Description

Definition at line 41 of file NumericalIntegration.h.

Constructor & Destructor Documentation

funct::GaussLegendreIntegrator::GaussLegendreIntegrator ( )
inline

Definition at line 43 of file NumericalIntegration.h.

43 : samples_(0) { }
funct::GaussLegendreIntegrator::GaussLegendreIntegrator ( unsigned int  samples,
double  epsilon 
)

Definition at line 5 of file NumericalIntegration.cc.

References edm::errors::Configuration, funct::cos(), edm::hlt::Exception, i, j, funct::m, p1, p2, p3, createTree::pp, w, x, and detailsBasic3DVector::z.

5  :
6  samples_(samples) {
7  if (samples <= 0)
9  << "gauss_legendre_integral: number of samples must be positive\n";
10  if(epsilon <= 0)
12  << "gauss_legendre_integral: numerical precision must be positive\n";
13 
14  x.resize(samples);
15  w.resize(samples);
16  const unsigned int m = (samples + 1)/2;
17 
18  double z, zSqr, pp, p1, p2, p3;
19 
20  for (unsigned int i = 0; i < m; ++i) {
21  z = std::cos(3.14159265358979323846 * (i + 0.75)/(samples + 0.5));
22  zSqr = z*z;
23  do {
24  p1 = 1.0;
25  p2 = 0.0;
26  for (unsigned int j = 0; j < samples; ++j) {
27  p3 = p2;
28  p2 = p1;
29  p1 = ((2.0*j + 1.0)*z*p2 - j*p3)/(j + 1.0);
30  }
31  pp = samples*(z*p1 - p2)/(zSqr - 1.0);
32  z -= p1/pp;
33  } while (std::fabs(p1/pp) > epsilon);
34 
35  x[i] = -z;
36  x[samples - i - 1] = z;
37  w[i] = 2.0/((1.0 - zSqr)*pp*pp);
38  w[samples - i -1] = w[i];
39  }
40 }
tuple pp
Definition: createTree.py:15
float float float z
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
int j
Definition: DBlmapReader.cc:9
double p2[4]
Definition: TauolaWrapper.h:90
double p1[4]
Definition: TauolaWrapper.h:89
const double epsilon
double p3[4]
Definition: TauolaWrapper.h:91

Member Function Documentation

template<typename F >
double funct::GaussLegendreIntegrator::operator() ( const F f,
double  min,
double  max 
) const
inline

Definition at line 46 of file NumericalIntegration.h.

References a0, b0, f, i, min(), result, samples_, w, and x.

46  {
47  a0 = 0.5*(max + min);
48  b0 = 0.5*(max - min);
49  result = 0.0;
50  for (i = 0; i < samples_; ++i) {
51  result += w[i] * f(a0 + b0*x[i]);
52  }
53 
54  return result * b0;
55  }
double f[11][100]
T min(T a, T b)
Definition: MathUtil.h:58

Member Data Documentation

double funct::GaussLegendreIntegrator::a0
mutableprivate

Definition at line 59 of file NumericalIntegration.h.

Referenced by operator()().

double funct::GaussLegendreIntegrator::b0
mutableprivate

Definition at line 59 of file NumericalIntegration.h.

Referenced by operator()().

unsigned int funct::GaussLegendreIntegrator::i
mutableprivate

Definition at line 60 of file NumericalIntegration.h.

Referenced by GaussLegendreIntegrator(), and operator()().

double funct::GaussLegendreIntegrator::result
mutableprivate

Definition at line 59 of file NumericalIntegration.h.

Referenced by operator()().

unsigned int funct::GaussLegendreIntegrator::samples_
private

Definition at line 57 of file NumericalIntegration.h.

Referenced by operator()().

std::vector<double> funct::GaussLegendreIntegrator::w
private

Definition at line 58 of file NumericalIntegration.h.

Referenced by GaussLegendreIntegrator(), and operator()().

std::vector<double> funct::GaussLegendreIntegrator::x
private