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

◆ GaussLegendreIntegrator() [1/2]

funct::GaussLegendreIntegrator::GaussLegendreIntegrator ( )
inline

Definition at line 44 of file NumericalIntegration.h.

◆ GaussLegendreIntegrator() [2/2]

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

Definition at line 5 of file NumericalIntegration.cc.

References edm::errors::Configuration, funct::cos(), geometryDiff::epsilon, Exception, i, dqmiolumiharvest::j, funct::m, LaserDQM_cfg::p1, SiStripOfflineCRack_cfg::p2, chargedHadronTrackResolutionFilter_cfi::p3, createTree::pp, EgammaValidation_cff::samples, w, and 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

Member Function Documentation

◆ operator()()

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 a0, b0, f, i, SiStripPI::max, SiStripPI::min, result, samples_, w, and x.

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]

Member Data Documentation

◆ a0

double funct::GaussLegendreIntegrator::a0
mutableprivate

Definition at line 61 of file NumericalIntegration.h.

Referenced by operator()().

◆ b0

double funct::GaussLegendreIntegrator::b0
mutableprivate

Definition at line 61 of file NumericalIntegration.h.

Referenced by operator()().

◆ i

unsigned int funct::GaussLegendreIntegrator::i
mutableprivate

Definition at line 62 of file NumericalIntegration.h.

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

◆ result

double funct::GaussLegendreIntegrator::result
mutableprivate

Definition at line 61 of file NumericalIntegration.h.

Referenced by operator()().

◆ samples_

unsigned int funct::GaussLegendreIntegrator::samples_
private

Definition at line 59 of file NumericalIntegration.h.

Referenced by operator()().

◆ w

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

Definition at line 60 of file NumericalIntegration.h.

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

◆ x

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