CMS 3D CMS Logo

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 42 of file NumericalIntegration.h.

Constructor & Destructor Documentation

funct::GaussLegendreIntegrator::GaussLegendreIntegrator ( )
inline
funct::GaussLegendreIntegrator::GaussLegendreIntegrator ( unsigned int  samples,
double  epsilon 
)

Definition at line 5 of file NumericalIntegration.cc.

References edm::errors::Configuration, funct::cos(), Exception, i, dqmiolumiharvest::j, funct::GaussIntegrator::kCST, funct::GaussIntegrator::kHF, funct::m, p1, p2, p3, createTree::pp, EgammaValidation_cff::samples, w, funct::GaussIntegrator::w, x, and funct::GaussIntegrator::x.

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

References parametrizedMagneticField_OAE85l_cfi::b0, f, mps_fire::i, min(), mps_fire::result, funct::TrapezoidIntegrator::samples_, and w.

47  {
48  a0 = 0.5 * (max + min);
49  b0 = 0.5 * (max - min);
50  result = 0.0;
51  for (i = 0; i < samples_; ++i) {
52  result += w[i] * f(a0 + b0 * x[i]);
53  }
54 
55  return result * b0;
56  }
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 61 of file NumericalIntegration.h.

double funct::GaussLegendreIntegrator::b0
mutableprivate

Definition at line 61 of file NumericalIntegration.h.

unsigned int funct::GaussLegendreIntegrator::i
mutableprivate

Definition at line 62 of file NumericalIntegration.h.

Referenced by GaussLegendreIntegrator().

double funct::GaussLegendreIntegrator::result
mutableprivate

Definition at line 61 of file NumericalIntegration.h.

unsigned int funct::GaussLegendreIntegrator::samples_
private

Definition at line 59 of file NumericalIntegration.h.

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

Definition at line 60 of file NumericalIntegration.h.

Referenced by GaussLegendreIntegrator().

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