Main Page
Namespaces
Classes
Package Documentation
CommonTools
Statistics
src
GammaSeries.cc
Go to the documentation of this file.
1
#include "
CommonTools/Statistics/src/GammaSeries.h
"
2
#include <iostream>
3
#include <cmath>
4
5
#define ITMAX 100 // maximum allowed number of iterations
6
#define EPS 3.0e-7 // relative accuracy
7
8
float
GammaSeries
(
float
a
,
float
x
)
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
}
35
GammaSeries.h
ITMAX
#define ITMAX
Definition:
GammaSeries.cc:5
MessageLogger_cfi.cerr
cerr
Definition:
MessageLogger_cfi.py:547
x
T x() const
Cartesian x coordinate.
Definition:
Basic3DVectorLD.h:127
diffTreeTool.index
index
Definition:
diffTreeTool.py:159
EPS
#define EPS
Definition:
GammaSeries.cc:6
a
double a
Definition:
hdecay.h:121
GammaSeries
float GammaSeries(float a, float x)
Definition:
GammaSeries.cc:8
Generated for CMSSW Reference Manual by
1.8.11