CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
GammaSeries.h File Reference

Go to the source code of this file.

Functions

float GammaSeries (float a, float x)
 

Function Documentation

float GammaSeries ( float  a,
float  x 
)

Returns the series summation of the series representation of the incomplete gamma function P(a,x). source: Numerical Recipes

Definition at line 8 of file GammaSeries.cc.

References a, ecal_dqm_sourceclient-live_cfg::cerr, EPS, cmsHarvester::index, and ITMAX.

Referenced by IncompleteGammaComplement::ln(), and IncompleteGammaComplement::value().

9 {
10  if( x < 0.0 )
11  std::cerr << "GammaSeries::negative argument x" << std::endl;
12 
13  if( x == 0. )
14  return 0.;
15 
16  if( a == 0. ) // this happens at the end, but save all the iterations
17  return 0.;
18 
19  // coefficient c_n of x^n is Gamma(a)/Gamma(a+1+n), which leads to the
20  // recurrence relation c_n = c_(n-1) / (a+n-1) with c_0 = 1/a
21  double term = 1/a;
22  double sum = term;
23  double aplus = a;
24  for( int index = 1; index <= ITMAX; index++) {
25  ++aplus;
26  term *= x/aplus;
27  sum += term;
28  if( fabs(term) < fabs(sum)*EPS )
29  // global coefficient e^-x * x^a / Gamma(a)
30  return sum;
31  }
32  std::cerr << "GammaSeries::a too large, ITMAX too small" << std::endl;
33  return 0.;
34 }
#define ITMAX
Definition: GammaSeries.cc:5
T x() const
Cartesian x coordinate.
#define EPS
Definition: GammaSeries.cc:6
double a
Definition: hdecay.h:121