CMS 3D CMS Logo

Functions

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/CommonTools/Statistics/src/GammaContinuedFraction.h File Reference

Go to the source code of this file.

Functions

float GammaContinuedFraction (float a, float x)

Function Documentation

float GammaContinuedFraction ( float  a,
float  x 
)

Returns the continued fraction summation of the (complement of the) incomplete gamma function P(a,x) evaluated by its continued fraction representation. source: Numerical Recipes

Definition at line 10 of file GammaContinuedFraction.cc.

References a, b, trackerHits::c, dtNoiseDBValidation_cfg::cerr, EPS, FPMIN, h, i, and ITMAX.

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

{
  int i;
  float an,del;

  /* Set up for evaluating continued fraction by modified Lentz's method (par.5.2
     in Numerical Recipes in C) with b_0 = 0 */
  double b = x+1.0-a;
  double c = 1.0/FPMIN;
  double d = 1.0/b;
  double h = d;
  for (i=1;i<=ITMAX;i++) {
    an = -i*(i-a);
    b += 2.0;
    d=an*d+b;
    if (fabs(d) < FPMIN) d=FPMIN;
    c=b+an/c;
    if (fabs(c) < FPMIN) c=FPMIN;
    d=1.0/d;
    del=d*c;
    h *= del;
    if (fabs(del-1.0) < EPS) break;
  }
  if( i > ITMAX ) std::cerr << "GammaContinuedFraction::a too large, "
                       << "ITMAX too small" << std::endl;
  return h;
}