23 GaussLegendreIntegrator::GaussLegendreIntegrator(
int num,
double eps) :
24 GaussIntegrator(eps, eps)
31 CalcGaussLegendreSamplingPoints();
34 GaussLegendreIntegrator::~GaussLegendreIntegrator()
43 void GaussLegendreIntegrator::SetNumberPoints(
int num)
48 CalcGaussLegendreSamplingPoints();
51 void GaussLegendreIntegrator::GetWeightVectors(
double *x,
double *w)
const
55 std::copy(fX,fX+fNum, x);
56 std::copy(fW,fW+fNum, w);
60 double GaussLegendreIntegrator::DoIntegral(
double a,
double b,
const IGenFunction*
function)
64 if (fNum<=0 || fX == 0 || fW == 0)
69 const double a0 = (b + a)/2;
70 const double b0 = (b - a)/2;
75 for (
int i=0; i<fNum; i++)
77 xx[0] = a0 + b0*fX[i];
78 result += fW[i] * (*function)(xx);
81 fLastResult = result*b0;
86 void GaussLegendreIntegrator::SetRelTolerance (
double eps)
90 CalcGaussLegendreSamplingPoints();
93 void GaussLegendreIntegrator::SetAbsTolerance (
double)
94 { MATH_WARN_MSG(
"ROOT::Math::GaussLegendreIntegrator",
"There is no Absolute Tolerance!"); }
98 void GaussLegendreIntegrator::CalcGaussLegendreSamplingPoints()
103 if (fNum<=0 || fEpsRel<=0)
112 fX =
new double[fNum];
113 fW =
new double[fNum];
116 const unsigned int m = (fNum+1)/2;
118 double z, pp, p1,p2, p3;
121 for (
unsigned int i=0; i<m; i++) {
122 z = std::cos(3.14159265358979323846*(i+0.75)/(fNum+0.5));
132 for (
int j=0; j<fNum; j++)
136 p1 = ((2.0*j+1.0)*z*p2-j*p3)/(j+1.0);
141 pp = fNum*(z*p1-p2)/(z*z-1.0);
145 }
while (std::fabs(p1/pp) > fEpsRel);
152 fW[i] = 2.0/((1.0-z*z)*pp*pp);
153 fW[fNum-i-1] = fW[i];
157 ROOT::Math::IntegratorOneDimOptions GaussLegendreIntegrator::Options()
const {
158 ROOT::Math::IntegratorOneDimOptions opt;
159 opt.SetAbsTolerance(0);
160 opt.SetRelTolerance(fEpsRel);
162 opt.SetNPoints(fNum);
163 opt.SetIntegrator(
"GaussLegendre");
167 void GaussLegendreIntegrator::SetOptions(
const ROOT::Math::IntegratorOneDimOptions & opt)
173 fEpsRel = opt.RelTolerance();
175 fNum = opt.NPoints();
176 if (fNum <= 7) MATH_WARN_MSGVAL(
"GaussLegendreIntegrator::SetOptions",
"setting a low number of points ",fNum);
177 CalcGaussLegendreSamplingPoints();