// @(#)root/mathcore:$Id$ // Authors: David Gonzalez Maline 01/2008 /********************************************************************** * * * Copyright (c) 2006 , LCG ROOT MathLib Team * * * * * **********************************************************************/ #include "Math/GaussLegendreIntegrator.h" #include #include #include namespace ROOT { namespace Math { GaussLegendreIntegrator::GaussLegendreIntegrator(int num, double eps) : GaussIntegrator(eps) { // Basic contructor fNum = num; fX = 0; fW = 0; CalcGaussLegendreSamplingPoints(); } GaussLegendreIntegrator::~GaussLegendreIntegrator() { // Default Destructor delete [] fX; delete [] fW; } void GaussLegendreIntegrator::SetNumberPoints(int num) { // Set the number of points used in the calculation of the integral fNum = num; CalcGaussLegendreSamplingPoints(); } void GaussLegendreIntegrator::GetWeightVectors(double *x, double *w) const { // Returns the arrays x and w. std::copy(fX,fX+fNum, x); std::copy(fW,fW+fNum, w); } double GaussLegendreIntegrator::DoIntegral(double a, double b, const IGenFunction* function) { // Gauss-Legendre integral, see CalcGaussLegendreSamplingPoints. if (fNum<=0 || fX == 0 || fW == 0) return 0; fUsedOnce = true; const double a0 = (b + a)/2; const double b0 = (b - a)/2; double xx[1]; double result = 0.0; for (int i=0; i fEpsilon); // Put root and its symmetric counterpart fX[i] = -z; fX[fNum-i-1] = z; // Compute the weight and put its symmetric counterpart fW[i] = 2.0/((1.0-z*z)*pp*pp); fW[fNum-i-1] = fW[i]; } } ROOT::Math::IntegratorOneDimOptions GaussLegendreIntegrator::Options() const { ROOT::Math::IntegratorOneDimOptions opt; opt.SetAbsTolerance(fEpsilon); opt.SetRelTolerance(fEpsilon); opt.SetWKSize(0); opt.SetNPoints(fNum); opt.SetIntegrator("GaussLegendre"); return opt; } void GaussLegendreIntegrator::SetOptions(const ROOT::Math::IntegratorOneDimOptions & opt) { // set integration options // std::cout << "fEpsilon = " << fEpsilon << std::endl; // std::cout << opt.RelTolerance() << " abs " << opt.AbsTolerance() << std::endl; //double tol = opt.RelTolerance(); fEpsilon = tol; fEpsilon = opt.RelTolerance(); // std::cout << "fEpsilon = " << fEpsilon << std::endl; fNum = opt.NPoints(); if (fNum <= 7) MATH_WARN_MSGVAL("GaussLegendreIntegrator::SetOptions","setting a low number of points ",fNum); CalcGaussLegendreSamplingPoints(); } } // end namespace Math } // end namespace ROOT