CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
CLHEP::RandPoisson Class Reference

#include <RandPoisson.h>

+ Inheritance diagram for CLHEP::RandPoisson:

Public Member Functions

 RandPoisson (HepRandomEngine &anEngine, double a1=1.0)
 
 RandPoisson (HepRandomEngine *anEngine, double a1=1.0)
 
virtual ~RandPoisson ()
 
std::ostream & put (std::ostream &os) const
 
std::istream & get (std::istream &is)
 
long fire ()
 
long fire (double mean)
 
void fireArray (const int size, long *vect)
 
void fireArray (const int size, long *vect, double mean)
 
double operator() ()
 
double operator() (double mean)
 
std::string name () const
 
HepRandomEngineengine ()
 
- Public Member Functions inherited from CLHEP::HepRandom
 HepRandom ()
 
 HepRandom (long seed)
 
 HepRandom (HepRandomEngine &algorithm)
 
 HepRandom (HepRandomEngine *algorithm)
 
virtual ~HepRandom ()
 
double flat ()
 
void flatArray (const int size, double *vect)
 
double flat (HepRandomEngine *theNewEngine)
 
void flatArray (HepRandomEngine *theNewEngine, const int size, double *vect)
 
virtual double operator() ()
 
virtual std::string name () const
 
virtual HepRandomEngineengine ()
 
virtual std::ostream & put (std::ostream &os) const
 
virtual std::istream & get (std::istream &is)
 

Static Public Member Functions

static long shoot (double mean=1.0)
 
static void shootArray (const int size, long *vect, double mean=1.0)
 
static long shoot (HepRandomEngine *anEngine, double mean=1.0)
 
static void shootArray (HepRandomEngine *anEngine, const int size, long *vect, double mean=1.0)
 
static std::string distributionName ()
 
- Static Public Member Functions inherited from CLHEP::HepRandom
static void setTheSeed (long seed, int lxr=3)
 
static long getTheSeed ()
 
static void setTheSeeds (const long *seeds, int aux=-1)
 
static const long * getTheSeeds ()
 
static void getTheTableSeeds (long *seeds, int index)
 
static HepRandomgetTheGenerator ()
 
static void setTheEngine (HepRandomEngine *theNewEngine)
 
static HepRandomEnginegetTheEngine ()
 
static void saveEngineStatus (const char filename[]="Config.conf")
 
static void restoreEngineStatus (const char filename[]="Config.conf")
 
static std::ostream & saveFullState (std::ostream &os)
 
static std::istream & restoreFullState (std::istream &is)
 
static std::ostream & saveDistState (std::ostream &os)
 
static std::istream & restoreDistState (std::istream &is)
 
static std::ostream & saveStaticRandomStates (std::ostream &os)
 
static std::istream & restoreStaticRandomStates (std::istream &is)
 
static void showEngineStatus ()
 
static int createInstance ()
 
static std::string distributionName ()
 

Protected Member Functions

HepRandomEnginegetLocalEngine ()
 

Static Protected Member Functions

static double getOldMean ()
 
static double getMaxMean ()
 
static void setOldMean (double val)
 
static doublegetPStatus ()
 
static void setPStatus (double sq, double alxm, double g1)
 

Protected Attributes

double meanMax
 
double defaultMean
 

Additional Inherited Members

- Static Protected Attributes inherited from CLHEP::HepRandom
static const long seedTable [215][2]
 

Detailed Description

Author

Definition at line 43 of file RandPoisson.h.

Constructor & Destructor Documentation

◆ RandPoisson() [1/2]

CLHEP::RandPoisson::RandPoisson ( HepRandomEngine anEngine,
double  a1 = 1.0 
)
inline

◆ RandPoisson() [2/2]

CLHEP::RandPoisson::RandPoisson ( HepRandomEngine anEngine,
double  a1 = 1.0 
)
inline

◆ ~RandPoisson()

CLHEP::RandPoisson::~RandPoisson ( )
virtual

Definition at line 47 of file RandPoisson.cc.

47 {
48}

Member Function Documentation

◆ distributionName()

static std::string CLHEP::RandPoisson::distributionName ( )
inlinestatic

Definition at line 95 of file RandPoisson.h.

95{return "RandPoisson";}

◆ engine()

HepRandomEngine & CLHEP::RandPoisson::engine ( )
virtual

Reimplemented from CLHEP::HepRandom.

Reimplemented in CLHEP::RandPoissonQ, and CLHEP::RandPoissonT.

Definition at line 40 of file RandPoisson.cc.

40{return *localEngine;}

Referenced by CLHEP::RandPoissonQ::engine(), and CLHEP::RandPoissonT::engine().

◆ fire() [1/2]

long CLHEP::RandPoisson::fire ( )

Definition at line 217 of file RandPoisson.cc.

217 {
218 return long(fire( defaultMean ));
219}

Referenced by dist_layout(), fire(), fireArray(), main(), operator()(), poissonTest(), and testRandPoisson().

◆ fire() [2/2]

long CLHEP::RandPoisson::fire ( double  mean)

Definition at line 221 of file RandPoisson.cc.

221 {
222
223// Returns as a floating-point number an integer value that is a random
224// deviation drawn from a Poisson distribution of mean xm, using flat()
225// as a source of uniform random numbers.
226// (Adapted from Numerical Recipes in C)
227
228 double em, t, y;
229 double sq, alxm, g1;
230
231 sq = status[0];
232 alxm = status[1];
233 g1 = status[2];
234
235 if( xm == -1 ) return 0;
236 if( xm < 12.0 ) {
237 if( xm != oldm ) {
238 oldm = xm;
239 g1 = std::exp(-xm);
240 }
241 em = -1;
242 t = 1.0;
243 do {
244 em += 1.0;
245 t *= localEngine->flat();
246 } while( t > g1 );
247 }
248 else if ( xm < meanMax ) {
249 if ( xm != oldm ) {
250 oldm = xm;
251 sq = std::sqrt(2.0*xm);
252 alxm = std::log(xm);
253 g1 = xm*alxm - gammln(xm + 1.0);
254 }
255 do {
256 do {
257 y = std::tan(CLHEP::pi*localEngine->flat());
258 em = sq*y + xm;
259 } while( em < 0.0 );
260 em = std::floor(em);
261 t = 0.9*(1.0 + y*y)* std::exp(em*alxm - gammln(em + 1.0) - g1);
262 } while( localEngine->flat() > t );
263 }
264 else {
265 em = xm + std::sqrt(xm) * normal (localEngine.get()); // mf 1/13/06
266 if ( static_cast<long>(em) < 0 )
267 em = static_cast<long>(xm) >= 0 ? xm : getMaxMean();
268 }
269 status[0] = sq; status[1] = alxm; status[2] = g1;
270 return long(em);
271}
static double getMaxMean()
Definition: RandPoisson.h:105
double gammln(double xx)
Definition: RandPoisson.cc:58

◆ fireArray() [1/2]

void CLHEP::RandPoisson::fireArray ( const int  size,
long *  vect 
)

Definition at line 273 of file RandPoisson.cc.

274{
275 for( long* v = vect; v != vect + size; ++v )
276 *v = fire( defaultMean );
277}

◆ fireArray() [2/2]

void CLHEP::RandPoisson::fireArray ( const int  size,
long *  vect,
double  mean 
)

Definition at line 279 of file RandPoisson.cc.

280{
281 for( long* v = vect; v != vect + size; ++v )
282 *v = fire( m1 );
283}

◆ get()

std::istream & CLHEP::RandPoisson::get ( std::istream &  is)
virtual

Reimplemented from CLHEP::HepRandom.

Reimplemented in CLHEP::RandPoissonQ, and CLHEP::RandPoissonT.

Definition at line 314 of file RandPoisson.cc.

314 {
315 std::string inName;
316 is >> inName;
317 if (inName != name()) {
318 is.clear(std::ios::badbit | is.rdstate());
319 std::cerr << "Mismatch when expecting to read state of a "
320 << name() << " distribution\n"
321 << "Name found was " << inName
322 << "\nistream is left in the badbit state\n";
323 return is;
324 }
325 if (possibleKeywordInput(is, "Uvec", meanMax)) {
326 std::vector<unsigned long> t(2);
327 is >> meanMax >> t[0] >> t[1]; meanMax = DoubConv::longs2double(t);
328 is >> defaultMean >> t[0] >> t[1]; defaultMean = DoubConv::longs2double(t);
329 is >> status[0] >> t[0] >> t[1]; status[0] = DoubConv::longs2double(t);
330 is >> status[1] >> t[0] >> t[1]; status[1] = DoubConv::longs2double(t);
331 is >> status[2] >> t[0] >> t[1]; status[2] = DoubConv::longs2double(t);
332 is >> oldm >> t[0] >> t[1]; oldm = DoubConv::longs2double(t);
333 return is;
334 }
335 // is >> meanMax encompassed by possibleKeywordInput
336 is >> defaultMean >> status[0] >> status[1] >> status[2];
337 return is;
338}
static double longs2double(const std::vector< unsigned long > &v)
Definition: DoubConv.cc:110
std::string name() const
Definition: RandPoisson.cc:39
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:168

Referenced by CLHEP::RandPoissonQ::get(), and CLHEP::RandPoissonT::get().

◆ getLocalEngine()

HepRandomEngine * CLHEP::RandPoisson::getLocalEngine ( )
inlineprotected

◆ getMaxMean()

static double CLHEP::RandPoisson::getMaxMean ( )
inlinestaticprotected

Definition at line 105 of file RandPoisson.h.

105{return meanMax_st;}

Referenced by fire(), and shoot().

◆ getOldMean()

static double CLHEP::RandPoisson::getOldMean ( )
inlinestaticprotected

Definition at line 103 of file RandPoisson.h.

103{return oldm_st;}

Referenced by shoot().

◆ getPStatus()

static double * CLHEP::RandPoisson::getPStatus ( )
inlinestaticprotected

Definition at line 109 of file RandPoisson.h.

109{return status_st;}

Referenced by shoot().

◆ name()

std::string CLHEP::RandPoisson::name ( ) const
virtual

Reimplemented from CLHEP::HepRandom.

Reimplemented in CLHEP::RandPoissonQ, and CLHEP::RandPoissonT.

Definition at line 39 of file RandPoisson.cc.

39{return "RandPoisson";}

Referenced by get(), and put().

◆ operator()() [1/2]

double CLHEP::RandPoisson::operator() ( )
virtual

Reimplemented from CLHEP::HepRandom.

Reimplemented in CLHEP::RandPoissonQ, and CLHEP::RandPoissonT.

Definition at line 50 of file RandPoisson.cc.

50 {
51 return double(fire( defaultMean ));
52}
#define double(obj)
Definition: excDblThrow.cc:32

◆ operator()() [2/2]

double CLHEP::RandPoisson::operator() ( double  mean)

Definition at line 54 of file RandPoisson.cc.

54 {
55 return double(fire( mean ));
56}

◆ put()

std::ostream & CLHEP::RandPoisson::put ( std::ostream &  os) const
virtual

Reimplemented from CLHEP::HepRandom.

Reimplemented in CLHEP::RandPoissonQ, and CLHEP::RandPoissonT.

Definition at line 285 of file RandPoisson.cc.

285 {
286 long pr=os.precision(20);
287 std::vector<unsigned long> t(2);
288 os << " " << name() << "\n";
289 os << "Uvec" << "\n";
291 os << meanMax << " " << t[0] << " " << t[1] << "\n";
293 os << defaultMean << " " << t[0] << " " << t[1] << "\n";
294 t = DoubConv::dto2longs(status[0]);
295 os << status[0] << " " << t[0] << " " << t[1] << "\n";
296 t = DoubConv::dto2longs(status[1]);
297 os << status[1] << " " << t[0] << " " << t[1] << "\n";
298 t = DoubConv::dto2longs(status[2]);
299 os << status[2] << " " << t[0] << " " << t[1] << "\n";
300 t = DoubConv::dto2longs(oldm);
301 os << oldm << " " << t[0] << " " << t[1] << "\n";
302 os.precision(pr);
303 return os;
304#ifdef REMOVED
305 long pr=os.precision(20);
306 os << " " << name() << "\n";
307 os << meanMax << " " << defaultMean << "\n";
308 os << status[0] << " " << status[1] << " " << status[2] << "\n";
309 os.precision(pr);
310 return os;
311#endif
312}
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:94

Referenced by CLHEP::RandPoissonQ::put(), and CLHEP::RandPoissonT::put().

◆ setOldMean()

static void CLHEP::RandPoisson::setOldMean ( double  val)
inlinestaticprotected

Definition at line 107 of file RandPoisson.h.

107{oldm_st = val;}

Referenced by shoot().

◆ setPStatus()

static void CLHEP::RandPoisson::setPStatus ( double  sq,
double  alxm,
double  g1 
)
inlinestaticprotected

Definition at line 111 of file RandPoisson.h.

111 {
112 status_st[0] = sq; status_st[1] = alxm; status_st[2] = g1;
113 }

Referenced by shoot().

◆ shoot() [1/2]

long CLHEP::RandPoisson::shoot ( double  mean = 1.0)
static

Definition at line 95 of file RandPoisson.cc.

95 {
96
97// Returns as a floating-point number an integer value that is a random
98// deviation drawn from a Poisson distribution of mean xm, using flat()
99// as a source of uniform random numbers.
100// (Adapted from Numerical Recipes in C)
101
102 double em, t, y;
103 double sq, alxm, g1;
104 double om = getOldMean();
105 HepRandomEngine* anEngine = HepRandom::getTheEngine();
106
107 double* pstatus = getPStatus();
108 sq = pstatus[0];
109 alxm = pstatus[1];
110 g1 = pstatus[2];
111
112 if( xm == -1 ) return 0;
113 if( xm < 12.0 ) {
114 if( xm != om ) {
115 setOldMean(xm);
116 g1 = std::exp(-xm);
117 }
118 em = -1;
119 t = 1.0;
120 do {
121 em += 1.0;
122 t *= anEngine->flat();
123 } while( t > g1 );
124 }
125 else if ( xm < getMaxMean() ) {
126 if ( xm != om ) {
127 setOldMean(xm);
128 sq = std::sqrt(2.0*xm);
129 alxm = std::log(xm);
130 g1 = xm*alxm - gammln(xm + 1.0);
131 }
132 do {
133 do {
134 y = std::tan(CLHEP::pi*anEngine->flat());
135 em = sq*y + xm;
136 } while( em < 0.0 );
137 em = std::floor(em);
138 t = 0.9*(1.0 + y*y)* std::exp(em*alxm - gammln(em + 1.0) - g1);
139 } while( anEngine->flat() > t );
140 }
141 else {
142 em = xm + std::sqrt(xm) * normal (anEngine); // mf 1/13/06
143 if ( static_cast<long>(em) < 0 )
144 em = static_cast<long>(xm) >= 0 ? xm : getMaxMean();
145 }
146 setPStatus(sq,alxm,g1);
147 return long(em);
148}
static HepRandomEngine * getTheEngine()
Definition: Random.cc:270
static double getOldMean()
Definition: RandPoisson.h:103
static void setOldMean(double val)
Definition: RandPoisson.h:107
static void setPStatus(double sq, double alxm, double g1)
Definition: RandPoisson.h:111
static double * getPStatus()
Definition: RandPoisson.h:109

Referenced by captureStatics(), CLHEP::RandPoissonT::fire(), layout(), randomizeStatics(), CLHEP::RandPoissonT::shoot(), shootArray(), and user_layout().

◆ shoot() [2/2]

long CLHEP::RandPoisson::shoot ( HepRandomEngine anEngine,
double  mean = 1.0 
)
static

Definition at line 156 of file RandPoisson.cc.

156 {
157
158// Returns as a floating-point number an integer value that is a random
159// deviation drawn from a Poisson distribution of mean xm, using flat()
160// of a given Random Engine as a source of uniform random numbers.
161// (Adapted from Numerical Recipes in C)
162
163 double em, t, y;
164 double sq, alxm, g1;
165 double om = getOldMean();
166
167 double* pstatus = getPStatus();
168 sq = pstatus[0];
169 alxm = pstatus[1];
170 g1 = pstatus[2];
171
172 if( xm == -1 ) return 0;
173 if( xm < 12.0 ) {
174 if( xm != om ) {
175 setOldMean(xm);
176 g1 = std::exp(-xm);
177 }
178 em = -1;
179 t = 1.0;
180 do {
181 em += 1.0;
182 t *= anEngine->flat();
183 } while( t > g1 );
184 }
185 else if ( xm < getMaxMean() ) {
186 if ( xm != om ) {
187 setOldMean(xm);
188 sq = std::sqrt(2.0*xm);
189 alxm = std::log(xm);
190 g1 = xm*alxm - gammln(xm + 1.0);
191 }
192 do {
193 do {
194 y = std::tan(CLHEP::pi*anEngine->flat());
195 em = sq*y + xm;
196 } while( em < 0.0 );
197 em = std::floor(em);
198 t = 0.9*(1.0 + y*y)* std::exp(em*alxm - gammln(em + 1.0) - g1);
199 } while( anEngine->flat() > t );
200 }
201 else {
202 em = xm + std::sqrt(xm) * normal (anEngine); // mf 1/13/06
203 if ( static_cast<long>(em) < 0 )
204 em = static_cast<long>(xm) >= 0 ? xm : getMaxMean();
205 }
206 setPStatus(sq,alxm,g1);
207 return long(em);
208}

◆ shootArray() [1/2]

void CLHEP::RandPoisson::shootArray ( const int  size,
long *  vect,
double  mean = 1.0 
)
static

Definition at line 150 of file RandPoisson.cc.

151{
152 for( long* v = vect; v != vect + size; ++v )
153 *v = shoot(m1);
154}
static long shoot(double mean=1.0)
Definition: RandPoisson.cc:95

◆ shootArray() [2/2]

void CLHEP::RandPoisson::shootArray ( HepRandomEngine anEngine,
const int  size,
long *  vect,
double  mean = 1.0 
)
static

Definition at line 210 of file RandPoisson.cc.

212{
213 for( long* v = vect; v != vect + size; ++v )
214 *v = shoot(anEngine,m1);
215}

Member Data Documentation

◆ defaultMean

◆ meanMax

double CLHEP::RandPoisson::meanMax
protected

Definition at line 100 of file RandPoisson.h.

Referenced by fire(), get(), and put().


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