#include <PhysicsTools/Utilities/interface/NumericalIntegration.h>
Public Member Functions | |
GaussLegendreIntegrator (unsigned int samples, double epsilon) | |
GaussLegendreIntegrator () | |
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 |
Definition at line 41 of file NumericalIntegration.h.
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(), i, j, funct::m, p1, p2, p3, w, x, and z.
00005 : 00006 samples_(samples) { 00007 if (samples <= 0) 00008 throw edm::Exception(edm::errors::Configuration) 00009 << "gauss_legendre_integral: number of samples must be positive\n"; 00010 if(epsilon <= 0) 00011 throw edm::Exception(edm::errors::Configuration) 00012 << "gauss_legendre_integral: numerical precision must be positive\n"; 00013 00014 x.resize(samples); 00015 w.resize(samples); 00016 const unsigned int m = (samples + 1)/2; 00017 00018 double z, zSqr, pp, p1, p2, p3; 00019 00020 for (unsigned int i = 0; i < m; ++i) { 00021 z = std::cos(3.14159265358979323846 * (i + 0.75)/(samples + 0.5)); 00022 zSqr = z*z; 00023 do { 00024 p1 = 1.0; 00025 p2 = 0.0; 00026 for (unsigned int j = 0; j < samples; ++j) { 00027 p3 = p2; 00028 p2 = p1; 00029 p1 = ((2.0*j + 1.0)*z*p2 - j*p3)/(j + 1.0); 00030 } 00031 pp = samples*(z*p1 - p2)/(zSqr - 1.0); 00032 z -= p1/pp; 00033 } while (std::fabs(p1/pp) > epsilon); 00034 00035 x[i] = -z; 00036 x[samples - i - 1] = z; 00037 w[i] = 2.0/((1.0 - zSqr)*pp*pp); 00038 w[samples - i -1] = w[i]; 00039 } 00040 }
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, result, samples_, w, and x.
00046 { 00047 a0 = 0.5*(max + min); 00048 b0 = 0.5*(max - min); 00049 result = 0.0; 00050 for (i = 0; i < samples_; ++i) { 00051 result += w[i] * f(a0 + b0*x[i]); 00052 } 00053 00054 return result * b0; 00055 }
double funct::GaussLegendreIntegrator::a0 [mutable, private] |
double funct::GaussLegendreIntegrator::b0 [mutable, private] |
unsigned int funct::GaussLegendreIntegrator::i [mutable, private] |
Definition at line 60 of file NumericalIntegration.h.
Referenced by GaussLegendreIntegrator(), and operator()().
double funct::GaussLegendreIntegrator::result [mutable, private] |
unsigned int funct::GaussLegendreIntegrator::samples_ [private] |
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] |
Definition at line 58 of file NumericalIntegration.h.
Referenced by GaussLegendreIntegrator(), and operator()().