29 #ifdef G4MULTITHREADED
41 return genGamma( anEngine, k, lambda );
46 return genGamma( anEngine, k, lambda );
58 for (i=0; i<size; ++i)
59 vect[i] =
shoot(k,lambda);
68 for (i=0; i<size; ++i)
69 vect[i] =
shoot(anEngine,k,lambda);
76 for (i=0; i<size; ++i)
85 for (i=0; i<size; ++i)
86 vect[i] =
fire(k,lambda);
96 static G4ThreadLocal G4double aa = -1.0, aaa = -1.0, b, c, d, e, r,
s, si, ss, q0,
97 q1 = 0.0416666664, q2 = 0.0208333723, q3 = 0.0079849875,
98 q4 = 0.0015746717, q5 = -0.0003349403, q6 = 0.0003340332,
99 q7 = 0.0006053049, q8 = -0.0004701849, q9 = 0.0001710320,
100 a1 = 0.333333333,
a2 = -0.249999949,
a3 = 0.199999867,
101 a4 =-0.166677482,
a5 = 0.142873973, a6 =-0.124385581,
102 a7 = 0.110368310, a8 = -0.112750886, a9 = 0.104089866,
103 e1 = 1.000000000,
e2 = 0.499999994,
e3 = 0.166666848,
104 e4 = 0.041664508, e5 = 0.008345522, e6 = 0.001353826,
112 if( a <= 0.0 )
return (-1.0);
113 if( lambda <= 0.0 )
return (-1.0);
117 b = 1.0 + 0.36788794412 *
a;
120 p = b * anEngine->flat();
123 gds = std::exp(std::log(p) / a);
124 if (std::log(anEngine->flat()) <= -gds)
return(gds/lambda);
128 gds = - std::log ((b - p) / a);
129 if (std::log(anEngine->flat()) <= ((a - 1.0) * std::log(gds)))
return(gds/lambda);
140 d = 5.656854249 - 12.0 *
s;
144 v1 = 2.0 * anEngine->flat() - 1.0;
145 v2 = 2.0 * anEngine->flat() - 1.0;
147 }
while ( v12 > 1.0 );
148 t = v1*std::sqrt(-2.0*std::log(v12)/v12);
151 if (t >= 0.0)
return(gds/lambda);
153 u = anEngine->flat();
154 if (d * u <= t * t * t)
return(gds/lambda);
160 q0 = ((((((((q9 * r + q8) * r + q7) * r + q6) * r + q5) * r + q4) *
161 r + q3) * r + q2) * r + q1) * r;
172 b = 1.654 + 0.0076 * ss;
173 si = 1.68 / s + 0.275;
174 c = 0.062 / s + 0.024;
179 b = 0.463 + s - 0.178 * ss;
181 c = 0.195 / s - 0.079 + 0.016 *
s;
187 if (std::fabs(v) > 0.25)
189 q = q0 - s * t + 0.25 * t * t + (ss + ss) * std::log(1.0 + v);
193 q = q0 + 0.5 * t * t * ((((((((a9 * v + a8) * v + a7) * v + a6) *
194 v +
a5) * v +
a4) * v +
a3) * v +
a2) * v +
a1) * v;
196 if (std::log(1.0 - u) <= q)
return(gds/lambda);
203 e = -std::log(anEngine->flat());
204 u = anEngine->flat();
206 sign_u = (u > 0)? 1.0 : -1.0;
207 t = b + (e * si) * sign_u;
209 while (t <= -0.71874483771719);
211 if (std::fabs(v) > 0.25)
213 q = q0 - s * t + 0.25 * t * t + (ss + ss) * std::log(1.0 + v);
217 q = q0 + 0.5 * t * t * ((((((((a9 * v + a8) * v + a7) * v + a6) *
218 v +
a5) * v +
a4) * v +
a3) * v +
a2) * v +
a1) * v;
220 if (q <= 0.0)
continue;
223 w = std::exp(q) - 1.0;
227 w = ((((((e7 * q + e6) * q + e5) * q +
e4) * q +
e3) * q +
e2) *
230 if ( c * u * sign_u <= w * std::exp(e - 0.5 * t * t))
static CLHEP::HepRandomEngine * getTheEngine()
void fireArray(const G4int size, G4double *vect)
CLHEP::HepRandomEngine * localEngine
static void shootArray(const G4int size, G4double *vect, G4double k=1.0, G4double lambda=1.0)
static G4double genGamma(CLHEP::HepRandomEngine *anEngine, G4double k, G4double lambda)