43const double RandPoisson::meanMax_st = 2.0E9;
53 return double(
fire( mean ));
62 static const double cof[6] = {76.18009172947146,-86.50532032941677,
63 24.01409824083091, -1.231739572450155,
64 0.1208650973866179e-2, -0.5395239384953e-5};
68 tmp -= (x + 0.5) * std::log(tmp);
69 double ser = 1.000000000190015;
71 for ( j = 0; j <= 5; j++ ) {
75 return -tmp + std::log(2.5066282746310005*ser);
79double normal (HepRandomEngine* eptr)
84 v1 = 2.0 * eptr->flat() - 1.0;
85 v2 = 2.0 * eptr->flat() - 1.0;
89 fac = std::sqrt(-2.0*std::log(r)/r);
110 if( xm == -1 )
return 0;
120 t *= anEngine->
flat();
126 sq = std::sqrt(2.0*xm);
128 g1 = xm*alxm -
gammln(xm + 1.0);
132 y = std::tan(CLHEP::pi*anEngine->
flat());
136 t = 0.9*(1.0 + y*y)* std::exp(em*alxm -
gammln(em + 1.0) - g1);
137 }
while( anEngine->
flat() > t );
140 em = xm + std::sqrt(xm) * normal (anEngine);
141 if (
static_cast<long>(em) < 0 )
142 em =
static_cast<long>(xm) >= 0 ? xm :
getMaxMean();
150 for(
long* v = vect; v != vect + size; ++v )
170 if( xm == -1 )
return 0;
180 t *= anEngine->
flat();
186 sq = std::sqrt(2.0*xm);
188 g1 = xm*alxm -
gammln(xm + 1.0);
192 y = std::tan(CLHEP::pi*anEngine->
flat());
196 t = 0.9*(1.0 + y*y)* std::exp(em*alxm -
gammln(em + 1.0) - g1);
197 }
while( anEngine->
flat() > t );
200 em = xm + std::sqrt(xm) * normal (anEngine);
201 if (
static_cast<long>(em) < 0 )
202 em =
static_cast<long>(xm) >= 0 ? xm :
getMaxMean();
209 long* vect,
double m1)
211 for(
long* v = vect; v != vect + size; ++v )
212 *v =
shoot(anEngine,m1);
233 if( xm == -1 )
return 0;
243 t *= localEngine->flat();
249 sq = std::sqrt(2.0*xm);
251 g1 = xm*alxm -
gammln(xm + 1.0);
255 y = std::tan(CLHEP::pi*localEngine->flat());
259 t = 0.9*(1.0 + y*y)* std::exp(em*alxm -
gammln(em + 1.0) - g1);
260 }
while( localEngine->flat() > t );
263 em = xm + std::sqrt(xm) * normal (localEngine.get());
264 if (
static_cast<long>(em) < 0 )
265 em =
static_cast<long>(xm) >= 0 ? xm :
getMaxMean();
267 status[0] = sq; status[1] = alxm; status[2] = g1;
273 for(
long* v = vect; v != vect + size; ++v )
279 for(
long* v = vect; v != vect + size; ++v )
284 long pr=os.precision(20);
285 std::vector<unsigned long> t(2);
286 os <<
" " <<
name() <<
"\n";
287 os <<
"Uvec" <<
"\n";
289 os <<
meanMax <<
" " << t[0] <<
" " << t[1] <<
"\n";
291 os <<
defaultMean <<
" " << t[0] <<
" " << t[1] <<
"\n";
293 os << status[0] <<
" " << t[0] <<
" " << t[1] <<
"\n";
295 os << status[1] <<
" " << t[0] <<
" " << t[1] <<
"\n";
297 os << status[2] <<
" " << t[0] <<
" " << t[1] <<
"\n";
299 os << oldm <<
" " << t[0] <<
" " << t[1] <<
"\n";
307 if (inName !=
name()) {
308 is.clear(std::ios::badbit | is.rdstate());
309 std::cerr <<
"Mismatch when expecting to read state of a "
310 <<
name() <<
" distribution\n"
311 <<
"Name found was " << inName
312 <<
"\nistream is left in the badbit state\n";
316 std::vector<unsigned long> t(2);
326 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 void shootArray(const int size, long *vect, double mean=1.0)
static long shoot(double mean=1.0)
static double getOldMean()
static double getMaxMean()
static void setOldMean(double val)
static void setPStatus(double sq, double alxm, double g1)
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)
#define CLHEP_THREAD_LOCAL