Geant4-11
Public Member Functions | Private Member Functions | Static Private Member Functions
MyGamma Class Reference

#include <Gamma.hh>

Public Member Functions

double Gamma (double a, double x)
 
double Gamma (double z)
 
 MyGamma ()
 
 ~MyGamma ()
 

Private Member Functions

double GamCf (double a, double x)
 
double GamSer (double a, double x)
 

Static Private Member Functions

static double Abs (double d)
 
static float Abs (float d)
 
static int Abs (int d)
 
static long Abs (long d)
 
static short Abs (short d)
 
static double Exp (double x)
 
static double LnGamma (double z)
 
static double Log (double x)
 

Detailed Description

Definition at line 45 of file Gamma.hh.

Constructor & Destructor Documentation

◆ MyGamma()

MyGamma::MyGamma ( )

Definition at line 36 of file Gamma.cc.

36{}

◆ ~MyGamma()

MyGamma::~MyGamma ( )

Definition at line 38 of file Gamma.cc.

38{}

Member Function Documentation

◆ Abs() [1/5]

static double MyGamma::Abs ( double  d)
inlinestaticprivate

Definition at line 65 of file Gamma.hh.

65{ return (d > 0) ? d : -d; }

◆ Abs() [2/5]

static float MyGamma::Abs ( float  d)
inlinestaticprivate

Definition at line 64 of file Gamma.hh.

64{ return (d > 0) ? d : -d; }

◆ Abs() [3/5]

static int MyGamma::Abs ( int  d)
inlinestaticprivate

Definition at line 62 of file Gamma.hh.

62{ return (d > 0) ? d : -d; }

◆ Abs() [4/5]

static long MyGamma::Abs ( long  d)
inlinestaticprivate

Definition at line 63 of file Gamma.hh.

63{ return (d > 0) ? d : -d; }

◆ Abs() [5/5]

static short MyGamma::Abs ( short  d)
inlinestaticprivate

Definition at line 61 of file Gamma.hh.

61{ return (d > 0) ? d : -d; }

Referenced by GamCf(), and GamSer().

◆ Exp()

static double MyGamma::Exp ( double  x)
inlinestaticprivate

Definition at line 68 of file Gamma.hh.

68{ return std::exp(x); }

Referenced by GamCf(), and GamSer().

◆ GamCf()

double MyGamma::GamCf ( double  a,
double  x 
)
private

Definition at line 66 of file Gamma.cc.

67{
68 // Computation of the incomplete gamma function P(a,x)
69 // via its continued fraction representation.
70 //
71 // The algorithm is based on the formulas and code as denoted in
72 // Numerical Recipes 2nd ed. on p. 210-212 (W.H.Press et al.).
73 //
74 //--- Nve 14-nov-1998 UU-SAP Utrecht
75
76 int itmax = 100; // Maximum number of iterations
77 double eps = 3.e-7; // Relative accuracy
78 double fpmin = 1.e-30; // Smallest double value allowed here
79
80 if (a <= 0 || x <= 0) return 0;
81
82 double gln = LnGamma(a);
83 double b = x+1-a;
84 double c = 1/fpmin;
85 double d = 1/b;
86 double h = d;
87 double an,del;
88 for (int i=1; i<=itmax; i++) {
89 an = double(-i)*(double(i)-a);
90 b += 2;
91 d = an*d+b;
92 if (Abs(d) < fpmin) d = fpmin;
93 c = b+an/c;
94 if (Abs(c) < fpmin) c = fpmin;
95 d = 1/d;
96 del = d*c;
97 h = h*del;
98 if (Abs(del-1) < eps) break;
99 //if (i==itmax) cout << "*GamCf(a,x)* a too large or itmax too small" << endl;
100 }
101 double v = Exp(-x+a*Log(x)-gln)*h;
102 return (1-v);
103}
static const G4double eps
static short Abs(short d)
Definition: Gamma.hh:61
static double LnGamma(double z)
Definition: Gamma.cc:137
static double Log(double x)
Definition: Gamma.hh:67
static double Exp(double x)
Definition: Gamma.hh:68

References Abs(), G4InuclParticleNames::an, eps, Exp(), LnGamma(), and Log().

Referenced by Gamma().

◆ Gamma() [1/2]

double MyGamma::Gamma ( double  a,
double  x 
)

Definition at line 50 of file Gamma.cc.

51{
52 // Computation of the incomplete gamma function P(a,x)
53 //
54 // The algorithm is based on the formulas and code as denoted in
55 // Numerical Recipes 2nd ed. on p. 210-212 (W.H.Press et al.).
56 //
57 //--- Nve 14-nov-1998 UU-SAP Utrecht
58
59 if (a <= 0 || x <= 0) return 0;
60
61 if (x < (a+1)) return GamSer(a,x);
62 else return GamCf(a,x);
63}
double GamCf(double a, double x)
Definition: Gamma.cc:66
double GamSer(double a, double x)
Definition: Gamma.cc:106

References GamCf(), and GamSer().

◆ Gamma() [2/2]

double MyGamma::Gamma ( double  z)

Definition at line 41 of file Gamma.cc.

42{
43 if (z <= 0)
44 return 0;
45
46 return std::tgamma(z);
47}

Referenced by GVFlashShowerParameterisation::gam().

◆ GamSer()

double MyGamma::GamSer ( double  a,
double  x 
)
private

Definition at line 106 of file Gamma.cc.

107{
108 // Computation of the incomplete gamma function P(a,x)
109 // via its series representation.
110 //
111 // The algorithm is based on the formulas and code as denoted in
112 // Numerical Recipes 2nd ed. on p. 210-212 (W.H.Press et al.).
113 //
114 //--- Nve 14-nov-1998 UU-SAP Utrecht
115
116 int itmax = 100; // Maximum number of iterations
117 double eps = 3.e-7; // Relative accuracy
118
119 if (a <= 0 || x <= 0) return 0;
120
121 double gln = LnGamma(a);
122 double ap = a;
123 double sum = 1/a;
124 double del = sum;
125 for (int n=1; n<=itmax; n++) {
126 ap += 1;
127 del = del*x/ap;
128 sum += del;
129 if (MyGamma::Abs(del) < Abs(sum*eps)) break;
130 //if (n==itmax) cout << "*GamSer(a,x)* a too large or itmax too small" << endl;
131 }
132 double v = sum*Exp(-x+a*Log(x)-gln);
133 return v;
134}

References Abs(), G4InuclParticleNames::ap, eps, Exp(), LnGamma(), Log(), and CLHEP::detail::n.

Referenced by Gamma().

◆ LnGamma()

double MyGamma::LnGamma ( double  z)
staticprivate

Definition at line 137 of file Gamma.cc.

138{
139 if (z <= 0)
140 return 0;
141
142 return std::lgamma(z);
143}

Referenced by GamCf(), and GamSer().

◆ Log()

static double MyGamma::Log ( double  x)
inlinestaticprivate

Definition at line 67 of file Gamma.hh.

67{ return std::log(x); }

Referenced by GamCf(), and GamSer().


The documentation for this class was generated from the following files: