Geant4-11
Macros | Functions | Variables
nf_gammaFunctions.cc File Reference
#include "nf_specialFunctions.h"

Go to the source code of this file.

Macros

#define MAXGAM   171.624376956302725
 
#define MAXLGM   2.556348e305
 
#define MAXSTIR   143.01608
 

Functions

static double lgam (double x, int *sgngam, nfu_status *status)
 
double nf_gammaFunction (double x, nfu_status *status)
 
double nf_logGammaFunction (double x, nfu_status *status)
 
static double stirf (double x, nfu_status *status)
 

Variables

static double A []
 
static double B []
 
static double C []
 
static double LOGPI = 1.14472988584940017414
 
static double LS2PI = 0.91893853320467274178
 
static double P []
 
static double Q []
 
static double SQTPI = 2.50662827463100050242E0
 
static double STIR [5] = { 7.873113957930936284e-4, -2.2954996161337812638e-4, -2.6813261780578123283e-3, 3.472222216054586673e-3, 8.3333333333348225713e-2 }
 

Macro Definition Documentation

◆ MAXGAM

#define MAXGAM   171.624376956302725

Definition at line 93 of file nf_gammaFunctions.cc.

◆ MAXLGM

#define MAXLGM   2.556348e305

Definition at line 201 of file nf_gammaFunctions.cc.

◆ MAXSTIR

#define MAXSTIR   143.01608

Definition at line 99 of file nf_gammaFunctions.cc.

Function Documentation

◆ lgam()

static double lgam ( double  x,
int *  sgngam,
nfu_status status 
)
static

Definition at line 219 of file nf_gammaFunctions.cc.

219 {
220
221 double p, q, u, w, z;
222 int i;
223
224 *sgngam = 1;
225
226 if( x < -34.0 ) {
227 q = -x;
228 w = lgam( q, sgngam, status ); /* note this modifies *sgngam! */
229 p = floor( q );
230 if( p == q ) goto lgsing;
231 i = (int) p;
232 if( ( i & 1 ) == 0 ) {
233 *sgngam = -1; }
234 else {
235 *sgngam = 1;
236 }
237 z = q - p;
238 if( z > 0.5 ) {
239 p += 1.0;
240 z = p - q;
241 }
242 z = q * sin( M_PI * z );
243 if( z == 0.0 ) goto lgsing;
244 z = LOGPI - G4Log( z ) - w;
245 return( z );
246 }
247
248 if( x < 13.0 ) {
249 z = 1.0;
250 p = 0.0;
251 u = x;
252 while( u >= 3.0 ) {
253 p -= 1.0;
254 u = x + p;
255 z *= u;
256 } // Loop checking, 11.06.2015, T. Koi
257 while( u < 2.0 ) {
258 if( u == 0.0 ) goto lgsing;
259 z /= u;
260 p += 1.0;
261 u = x + p;
262 } // Loop checking, 11.06.2015, T. Koi
263 if( z < 0.0 ) {
264 *sgngam = -1;
265 z = -z; }
266 else {
267 *sgngam = 1;
268 }
269 if( u == 2.0 ) return( G4Log( z ) );
270 p -= 2.0;
271 x = x + p;
272 p = x * nf_polevl( x, B, 5 ) / nf_p1evl( x, C, 6);
273 return( G4Log( z ) + p );
274 }
275
276 if( x > MAXLGM ) goto lgsing;
277 q = ( x - 0.5 ) * G4Log( x ) - x + LS2PI;
278 if( x > 1.0e8 ) return( q );
279
280 p = 1.0 / ( x * x );
281 if( x >= 1000.0 ) {
282 q += ( ( 7.9365079365079365079365e-4 * p - 2.7777777777777777777778e-3 ) * p + 0.0833333333333333333333 ) / x; }
283 else {
284 q += nf_polevl( p, A, 4 ) / x;
285 }
286 return( q );
287
288lgsing:
289 return( *sgngam * DBL_MAX );
290}
G4double G4Log(G4double x)
Definition: G4Log.hh:226
#define M_PI
Definition: SbMath.h:33
static double C[]
#define MAXLGM
static double lgam(double x, int *sgngam, nfu_status *status)
static double B[]
static double LS2PI
static double A[]
static double LOGPI
double nf_polevl(double x, double coef[], int N)
Definition: nf_polevl.cc:46
double nf_p1evl(double x, double coef[], int N)
Definition: nf_polevl.cc:67
#define DBL_MAX
Definition: templates.hh:62

References A, B, C, DBL_MAX, G4Log(), lgam(), LOGPI, LS2PI, M_PI, MAXLGM, nf_p1evl(), and nf_polevl().

Referenced by lgam(), and nf_logGammaFunction().

◆ nf_gammaFunction()

double nf_gammaFunction ( double  x,
nfu_status status 
)

Definition at line 126 of file nf_gammaFunctions.cc.

126 {
127
128 double p, q, z;
129 int i, sgngam = 1;
130
131 *status = nfu_badInput;
132 if( !isfinite( x ) ) return( x );
133 *status = nfu_Okay;
134
135 q = fabs( x );
136
137 if( q > 33.0 ) {
138 if( x < 0.0 ) {
139 p = floor( q );
140 if( p == q ) goto goverf;
141 i = (int) p;
142 if( ( i & 1 ) == 0 ) sgngam = -1;
143 z = q - p;
144 if( z > 0.5 ) {
145 p += 1.0;
146 z = q - p;
147 }
148 z = q * sin( M_PI * z );
149 if( z == 0.0 ) goto goverf;
150 z = M_PI / ( fabs( z ) * stirf( q, status ) );
151 }
152 else {
153 z = stirf( x, status );
154 }
155 return( sgngam * z );
156 }
157
158 z = 1.0;
159 while( x >= 3.0 ) {
160 x -= 1.0;
161 z *= x;
162 } // Loop checking, 11.06.2015, T. Koi
163
164 while( x < 0.0 ) {
165 if( x > -1.E-9 ) goto small;
166 z /= x;
167 x += 1.0;
168 } // Loop checking, 11.06.2015, T. Koi
169
170 while( x < 2.0 ) {
171 if( x < 1.e-9 ) goto small;
172 z /= x;
173 x += 1.0;
174 } // Loop checking, 11.06.2015, T. Koi
175
176 if( x == 2.0 ) return( z );
177
178 x -= 2.0;
179 p = nf_polevl( x, P, 6 );
180 q = nf_polevl( x, Q, 7 );
181 return( z * p / q );
182
183small:
184 if( x == 0.0 ) goto goverf;
185 return( z / ( ( 1.0 + 0.5772156649015329 * x ) * x ) );
186
187goverf:
188 return( sgngam * DBL_MAX );
189}
static double Q[]
static double P[]
static double stirf(double x, nfu_status *status)
#define isfinite
@ nfu_Okay
Definition: nf_utilities.h:25
@ nfu_badInput
Definition: nf_utilities.h:29

References DBL_MAX, isfinite, M_PI, nf_polevl(), nfu_badInput, nfu_Okay, P, Q, and stirf().

Referenced by nf_incompleteGammaFunction(), and nf_incompleteGammaFunctionComplementary().

◆ nf_logGammaFunction()

double nf_logGammaFunction ( double  x,
nfu_status status 
)

Definition at line 206 of file nf_gammaFunctions.cc.

206 {
207/* Logarithm of gamma function */
208
209 int sgngam;
210
211 *status = nfu_badInput;
212 if( !isfinite( x ) ) return( x );
213 *status = nfu_Okay;
214 return( lgam( x, &sgngam, status ) );
215}

References isfinite, lgam(), nfu_badInput, and nfu_Okay.

◆ stirf()

static double stirf ( double  x,
nfu_status status 
)
static

Definition at line 106 of file nf_gammaFunctions.cc.

106 {
107/* Gamma function computed by Stirling's formula. The polynomial STIR is valid for 33 <= x <= 172. */
108
109 double y, w, v;
110
111 w = 1.0 / x;
112 w = 1.0 + w * nf_polevl( w, STIR, 4 );
113 y = G4Exp( x );
114 if( x > MAXSTIR ) { /* Avoid overflow in pow() */
115 v = G4Pow::GetInstance()->powA( x, 0.5 * x - 0.25 );
116 y = v * (v / y); }
117 else {
118 y = G4Pow::GetInstance()->powA( x, x - 0.5 ) / y;
119 }
120 y = SQTPI * y * w;
121 return( y );
122}
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition: G4Exp.hh:179
static G4Pow * GetInstance()
Definition: G4Pow.cc:41
G4double powA(G4double A, G4double y) const
Definition: G4Pow.hh:230
#define MAXSTIR
static double STIR[5]
static double SQTPI

References G4Exp(), G4Pow::GetInstance(), MAXSTIR, nf_polevl(), G4Pow::powA(), SQTPI, and STIR.

Referenced by nf_gammaFunction().

Variable Documentation

◆ A

double A[]
static
Initial value:
= { 8.11614167470508450300E-4, -5.95061904284301438324E-4, 7.93650340457716943945E-4,
-2.77777777730099687205E-3, 8.33333333333331927722E-2 }

Definition at line 194 of file nf_gammaFunctions.cc.

Referenced by lgam().

◆ B

double B[]
static
Initial value:
= { -1.37825152569120859100E3, -3.88016315134637840924E4, -3.31612992738871184744E5,
-1.16237097492762307383E6, -1.72173700820839662146E6, -8.53555664245765465627E5 }

Definition at line 196 of file nf_gammaFunctions.cc.

Referenced by lgam().

◆ C

double C[]
static
Initial value:
= { -3.51815701436523470549E2, -1.70642106651881159223E4, -2.20528590553854454839E5,
-1.13933444367982507207E6, -2.53252307177582951285E6, -2.01889141433532773231E6 }

Definition at line 198 of file nf_gammaFunctions.cc.

Referenced by lgam().

◆ LOGPI

double LOGPI = 1.14472988584940017414
static

Definition at line 94 of file nf_gammaFunctions.cc.

Referenced by lgam().

◆ LS2PI

double LS2PI = 0.91893853320467274178
static

Definition at line 200 of file nf_gammaFunctions.cc.

Referenced by lgam().

◆ P

double P[]
static
Initial value:
= { 1.60119522476751861407E-4, 1.19135147006586384913E-3, 1.04213797561761569935E-2, 4.76367800457137231464E-2,
2.07448227648435975150E-1, 4.94214826801497100753E-1, 9.99999999999999996796E-1 }

Definition at line 89 of file nf_gammaFunctions.cc.

Referenced by G4VarNtp::addParticle(), G4LFission::ApplyYourself(), G4LEHadronProtonElastic::ApplyYourself(), G4LEnp::ApplyYourself(), G4LEpp::ApplyYourself(), G4DNAMolecularReactionData::ArrehniusParam(), G4QuasiElRatios::CalcQF2IN_Ratio(), G4ChipsAntiBaryonInelasticXS::CalculateCrossSection(), G4ChipsHyperonInelasticXS::CalculateCrossSection(), G4ChipsKaonMinusInelasticXS::CalculateCrossSection(), G4ChipsKaonPlusInelasticXS::CalculateCrossSection(), G4ChipsNeutronInelasticXS::CalculateCrossSection(), G4ChipsPionMinusInelasticXS::CalculateCrossSection(), G4ChipsPionPlusInelasticXS::CalculateCrossSection(), G4ChipsProtonInelasticXS::CalculateCrossSection(), G4GNASHTransitions::CalculateProbability(), G4PreCompoundTransitions::CalculateProbability(), G4QuasiElRatios::ChExer(), G4DiffractiveExcitation::ChooseP(), G4QGSDiffractiveExcitation::ChooseP(), G4GeomTools::ClosestPointOnSegment(), G4GeomTools::ClosestPointOnTriangle(), G4NistManager::ConstructNewIdealGasMaterial(), G4NistManager::ConstructNewMaterial(), G4ChipsAntiBaryonInelasticXS::CrossSectionFormula(), G4ChipsHyperonInelasticXS::CrossSectionFormula(), G4ChipsKaonMinusInelasticXS::CrossSectionFormula(), G4ChipsKaonPlusInelasticXS::CrossSectionFormula(), G4ChipsNeutronInelasticXS::CrossSectionFormula(), G4ChipsPionMinusInelasticXS::CrossSectionFormula(), G4ChipsPionPlusInelasticXS::CrossSectionFormula(), G4ChipsProtonInelasticXS::CrossSectionFormula(), G4ChipsAntiBaryonInelasticXS::CrossSectionLin(), G4ChipsHyperonInelasticXS::CrossSectionLin(), G4ChipsKaonMinusInelasticXS::CrossSectionLin(), G4ChipsKaonPlusInelasticXS::CrossSectionLin(), G4ChipsNeutronInelasticXS::CrossSectionLin(), G4ChipsPionMinusInelasticXS::CrossSectionLin(), G4ChipsPionPlusInelasticXS::CrossSectionLin(), G4ChipsProtonInelasticXS::CrossSectionLin(), G4ChipsAntiBaryonInelasticXS::CrossSectionLog(), G4ChipsHyperonInelasticXS::CrossSectionLog(), G4ChipsKaonMinusInelasticXS::CrossSectionLog(), G4ChipsKaonPlusInelasticXS::CrossSectionLog(), G4ChipsNeutronInelasticXS::CrossSectionLog(), G4ChipsPionMinusInelasticXS::CrossSectionLog(), G4ChipsPionPlusInelasticXS::CrossSectionLog(), G4ChipsProtonInelasticXS::CrossSectionLog(), G4MicroElecLOPhononModel::CrossSectionPerVolume(), G4FermiPhaseSpaceDecay::Decay(), G4GeomTools::DistancePointSegment(), G4PreCompoundAlpha::FactorialFactor(), G4PreCompoundDeuteron::FactorialFactor(), G4PreCompoundHe3::FactorialFactor(), G4PreCompoundTriton::FactorialFactor(), G4INCL::Particle::getBeta(), G4DELPHIMagField::GetFieldValue(), G4HadronNucleonXsc::HadronNucleonXscPDG(), G4HETCFragment::IntegrateEmissionProbability(), G4HETCAlpha::K(), G4HETCDeuteron::K(), G4HETCHe3::K(), G4HETCNeutron::K(), G4HETCProton::K(), G4HETCTriton::K(), G4INCL::NKbElasticChannel::KaonMomentum(), G4INCL::NKbToLpiChannel::KaonMomentum(), G4INCL::NKbToNKbChannel::KaonMomentum(), G4INCL::NKbToSpiChannel::KaonMomentum(), G4INCL::NpiToLKChannel::KaonMomentum(), G4INCL::NpiToSKChannel::KaonMomentum(), G4GDMLReadMaterials::MaterialRead(), nf_gammaFunction(), nf_Legendre_evauluateAtMu(), nf_Legendre_to_ptwXY2(), G4KL3DecayChannel::PhaseSpace(), G4GeomTools::PointInTriangle(), G4DNAMolecularReactionData::PolynomialParam(), G4PreCompoundIon::ProbabilityDistributionFunction(), G4PreCompoundNucleon::ProbabilityDistributionFunction(), G4FermiPhaseSpaceDecay::PtwoBody(), G4GDMLWriteMaterials::PWrite(), G4StatMFChannel::RotateMomentum(), G4QuasiElRatios::Scatter(), G4DNAMolecularReactionData::SetArrehniusParameterization(), G4ReactionTableMessenger::SetNewValue(), G4DNAMolecularReactionData::SetPolynomialParameterization(), and G4GDMLWriteStructure::TraverseVolumeTree().

◆ Q

double Q[]
static

◆ SQTPI

double SQTPI = 2.50662827463100050242E0
static

Definition at line 95 of file nf_gammaFunctions.cc.

Referenced by stirf().

◆ STIR

double STIR[5] = { 7.873113957930936284e-4, -2.2954996161337812638e-4, -2.6813261780578123283e-3, 3.472222216054586673e-3, 8.3333333333348225713e-2 }
static

Definition at line 98 of file nf_gammaFunctions.cc.

Referenced by stirf().