// -*- C++ -*- // $Id: DefiniteIntegral.cc,v 1.6 2010/06/16 18:22:01 garren Exp $ #include #include "CLHEP/GenericFunctions/DefiniteIntegral.hh" #include "CLHEP/GenericFunctions/AbsFunction.hh" namespace Genfun { const int DefiniteIntegral::_K =5; const int DefiniteIntegral::_KP=_K+1; DefiniteIntegral::DefiniteIntegral(double a, double b): _a(a), _b(b) {} DefiniteIntegral::~DefiniteIntegral() { } #define FANCY double DefiniteIntegral::operator [] (const AbsFunction & function) const { const int MAXITERATIONS=40; // Maximum number of iterations const double EPS=1.0E-6; // Precision #ifdef FANCY double s[MAXITERATIONS+2],h[MAXITERATIONS+2]; h[1]=1.0; for (int j=1;j<=MAXITERATIONS;j++) { s[j]=_trapzd(function, _a, _b, j); if (j>=_K) { double ss, dss; _polint(h+j-_K,s+j-_K,0.0,ss, dss); if (fabs(dss) <= EPS*fabs(ss)) return ss; } s[j+1]=s[j]; h[j+1]=0.25*h[j]; } #else double olds = -1E-30; for (int j=1;j