39double RandPoisson::status_st[3] = {0., 0., 0.};
40double RandPoisson::oldm_st = -1.0;
41const double RandPoisson::meanMax_st = 2.0E9;
51 return double(
fire( mean ));
60 static double cof[6] = {76.18009172947146,-86.50532032941677,
61 24.01409824083091, -1.231739572450155,
62 0.1208650973866179e-2, -0.5395239384953e-5};
66 tmp -= (x + 0.5) * std::log(tmp);
67 double ser = 1.000000000190015;
69 for ( j = 0; j <= 5; j++ ) {
73 return -tmp + std::log(2.5066282746310005*ser);
77double normal (HepRandomEngine* eptr)
82 v1 = 2.0 * eptr->flat() - 1.0;
83 v2 = 2.0 * eptr->flat() - 1.0;
87 fac = std::sqrt(-2.0*std::log(r)/r);
108 if( xm == -1 )
return 0;
118 t *= anEngine->
flat();
124 sq = std::sqrt(2.0*xm);
126 g1 = xm*alxm -
gammln(xm + 1.0);
130 y = std::tan(CLHEP::pi*anEngine->
flat());
134 t = 0.9*(1.0 + y*y)* std::exp(em*alxm -
gammln(em + 1.0) - g1);
135 }
while( anEngine->
flat() > t );
138 em = xm + std::sqrt(xm) * normal (anEngine);
139 if (
static_cast<long>(em) < 0 )
140 em =
static_cast<long>(xm) >= 0 ? xm :
getMaxMean();
148 for(
long* v = vect; v != vect + size; ++v )
168 if( xm == -1 )
return 0;
178 t *= anEngine->
flat();
184 sq = std::sqrt(2.0*xm);
186 g1 = xm*alxm -
gammln(xm + 1.0);
190 y = std::tan(CLHEP::pi*anEngine->
flat());
194 t = 0.9*(1.0 + y*y)* std::exp(em*alxm -
gammln(em + 1.0) - g1);
195 }
while( anEngine->
flat() > t );
198 em = xm + std::sqrt(xm) * normal (anEngine);
199 if (
static_cast<long>(em) < 0 )
200 em =
static_cast<long>(xm) >= 0 ? xm :
getMaxMean();
207 long* vect,
double m1)
209 for(
long* v = vect; v != vect + size; ++v )
210 *v =
shoot(anEngine,m1);
231 if( xm == -1 )
return 0;
241 t *= localEngine->flat();
247 sq = std::sqrt(2.0*xm);
249 g1 = xm*alxm -
gammln(xm + 1.0);
253 y = std::tan(CLHEP::pi*localEngine->flat());
257 t = 0.9*(1.0 + y*y)* std::exp(em*alxm -
gammln(em + 1.0) - g1);
258 }
while( localEngine->flat() > t );
261 em = xm + std::sqrt(xm) * normal (localEngine.get());
262 if (
static_cast<long>(em) < 0 )
263 em =
static_cast<long>(xm) >= 0 ? xm :
getMaxMean();
265 status[0] = sq; status[1] = alxm; status[2] = g1;
271 for(
long* v = vect; v != vect + size; ++v )
277 for(
long* v = vect; v != vect + size; ++v )
282 int pr=os.precision(20);
283 std::vector<unsigned long> t(2);
284 os <<
" " <<
name() <<
"\n";
285 os <<
"Uvec" <<
"\n";
287 os <<
meanMax <<
" " << t[0] <<
" " << t[1] <<
"\n";
289 os <<
defaultMean <<
" " << t[0] <<
" " << t[1] <<
"\n";
291 os << status[0] <<
" " << t[0] <<
" " << t[1] <<
"\n";
293 os << status[1] <<
" " << t[0] <<
" " << t[1] <<
"\n";
295 os << status[2] <<
" " << t[0] <<
" " << t[1] <<
"\n";
297 os << oldm <<
" " << t[0] <<
" " << t[1] <<
"\n";
305 if (inName !=
name()) {
306 is.clear(std::ios::badbit | is.rdstate());
307 std::cerr <<
"Mismatch when expecting to read state of a "
308 <<
name() <<
" distribution\n"
309 <<
"Name found was " << inName
310 <<
"\nistream is left in the badbit state\n";
314 std::vector<unsigned long> t(2);
324 is >>
defaultMean >> status[0] >> status[1] >> status[2];
static double longs2double(const std::vector< unsigned long > &v)
static std::vector< unsigned long > dto2longs(double d)
static HepRandomEngine * getTheEngine()
std::ostream & put(std::ostream &os) const
static double getOldMean()
static double getMaxMean()
static long shoot(double m=1.0)
static void setOldMean(double val)
static void setPStatus(double sq, double alxm, double g1)
static void shootArray(const int size, long *vect, double m=1.0)
void fireArray(const int size, long *vect)
static double * getPStatus()
std::istream & get(std::istream &is)
HepRandomEngine & engine()
bool possibleKeywordInput(IS &is, const std::string &key, T &t)