CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
NumericalIntegration.cc
Go to the documentation of this file.
3 #include <cmath>
4 
5 funct::GaussLegendreIntegrator::GaussLegendreIntegrator(unsigned int samples, double epsilon) : 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 }
39 
40 const double funct::GaussIntegrator::x[12] = {0.96028985649753623,
41  0.79666647741362674,
42  0.52553240991632899,
43  0.18343464249564980,
44  0.98940093499164993,
45  0.94457502307323258,
46  0.86563120238783174,
47  0.75540440835500303,
48  0.61787624440264375,
49  0.45801677765722739,
50  0.28160355077925891,
51  0.09501250983763744};
52 
53 const double funct::GaussIntegrator::w[12] = {0.10122853629037626,
54  0.22238103445337447,
55  0.31370664587788729,
56  0.36268378337836198,
57  0.02715245941175409,
58  0.06225352393864789,
59  0.09515851168249278,
60  0.12462897125553387,
61  0.14959598881657673,
62  0.16915651939500254,
63  0.18260341504492359,
64  0.18945061045506850};
65 
66 const double funct::GaussIntegrator::kHF = 0.5;
67 const double funct::GaussIntegrator::kCST = 5. / 1000;
tuple pp
Definition: createTree.py:17
const TString p2
Definition: fwPaths.cc:13
static const double kCST
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
const TString p1
Definition: fwPaths.cc:12
static const double w[12]
static const double x[12]