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.

44 : samples_(0) {}

◆ GaussLegendreIntegrator() [2/2]

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

Definition at line 5 of file NumericalIntegration.cc.

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 }

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

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.

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  }

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

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
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
min
T min(T a, T b)
Definition: MathUtil.h:58
funct::GaussLegendreIntegrator::b0
double b0
Definition: NumericalIntegration.h:61
geometryDiff.epsilon
int epsilon
Definition: geometryDiff.py:26
EgammaValidation_cff.samples
samples
Definition: EgammaValidation_cff.py:18
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DDAxes::z
p2
double p2[4]
Definition: TauolaWrapper.h:90
funct::m
m
Definition: Factorize.h:45
funct::GaussLegendreIntegrator::result
double result
Definition: NumericalIntegration.h:61
funct::GaussLegendreIntegrator::samples_
unsigned int samples_
Definition: NumericalIntegration.h:59
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
funct::GaussLegendreIntegrator::i
unsigned int i
Definition: NumericalIntegration.h:62
p1
double p1[4]
Definition: TauolaWrapper.h:89
Exception
Definition: hltDiff.cc:245
p3
double p3[4]
Definition: TauolaWrapper.h:91
funct::GaussLegendreIntegrator::a0
double a0
Definition: NumericalIntegration.h:61
funct::GaussLegendreIntegrator::w
std::vector< double > w
Definition: NumericalIntegration.h:60
createTree.pp
pp
Definition: createTree.py:17
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
funct::GaussLegendreIntegrator::x
std::vector< double > x
Definition: NumericalIntegration.h:60
edm::errors::Configuration
Definition: EDMException.h:36