Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
CLHEP::RandPoisson Class Reference

#include <RandPoisson.h>

+ Inheritance diagram for CLHEP::RandPoisson:

Public Member Functions

 RandPoisson (HepRandomEngine &anEngine, double m=1.0)
 
 RandPoisson (HepRandomEngine *anEngine, double m=1.0)
 
virtual ~RandPoisson ()
 
std::ostream & put (std::ostream &os) const
 
std::istream & get (std::istream &is)
 
long fire ()
 
long fire (double m)
 
void fireArray (const int size, long *vect)
 
void fireArray (const int size, long *vect, double m)
 
double operator() ()
 
double operator() (double m)
 
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 m=1.0)
 
static void shootArray (const int size, long *vect, double m=1.0)
 
static long shoot (HepRandomEngine *anEngine, double m=1.0)
 
static void shootArray (HepRandomEngine *anEngine, const int size, long *vect, double m=1.0)
 
static std::string distributionName ()
 
- Static Public Member Functions inherited from CLHEP::HepRandom
static void setTheSeed (long seed, int lux=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 double * getPStatus ()
 
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 41 of file RandPoisson.h.

Constructor & Destructor Documentation

◆ RandPoisson() [1/2]

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

◆ RandPoisson() [2/2]

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

◆ ~RandPoisson()

CLHEP::RandPoisson::~RandPoisson ( )
virtual

Definition at line 43 of file RandPoisson.cc.

43 {
44}

Member Function Documentation

◆ distributionName()

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

Definition at line 93 of file RandPoisson.h.

93{return "RandPoisson";}

◆ engine()

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

Reimplemented from CLHEP::HepRandom.

Reimplemented in CLHEP::RandPoissonQ.

Definition at line 36 of file RandPoisson.cc.

36{return *localEngine;}

Referenced by CLHEP::RandPoissonQ::engine().

◆ fire() [1/2]

long CLHEP::RandPoisson::fire ( )

Definition at line 213 of file RandPoisson.cc.

213 {
214 return long(fire( defaultMean ));
215}

Referenced by fire(), fireArray(), and operator()().

◆ fire() [2/2]

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

Definition at line 217 of file RandPoisson.cc.

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

◆ fireArray() [1/2]

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

Definition at line 269 of file RandPoisson.cc.

270{
271 for( long* v = vect; v != vect + size; ++v )
272 *v = fire( defaultMean );
273}

◆ fireArray() [2/2]

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

Definition at line 275 of file RandPoisson.cc.

276{
277 for( long* v = vect; v != vect + size; ++v )
278 *v = fire( m1 );
279}

◆ get()

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

Reimplemented from CLHEP::HepRandom.

Reimplemented in CLHEP::RandPoissonQ.

Definition at line 302 of file RandPoisson.cc.

302 {
303 std::string inName;
304 is >> inName;
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";
311 return is;
312 }
313 if (possibleKeywordInput(is, "Uvec", meanMax)) {
314 std::vector<unsigned long> t(2);
315 is >> meanMax >> t[0] >> t[1]; meanMax = DoubConv::longs2double(t);
316 is >> defaultMean >> t[0] >> t[1]; defaultMean = DoubConv::longs2double(t);
317 is >> status[0] >> t[0] >> t[1]; status[0] = DoubConv::longs2double(t);
318 is >> status[1] >> t[0] >> t[1]; status[1] = DoubConv::longs2double(t);
319 is >> status[2] >> t[0] >> t[1]; status[2] = DoubConv::longs2double(t);
320 is >> oldm >> t[0] >> t[1]; oldm = DoubConv::longs2double(t);
321 return is;
322 }
323 // is >> meanMax encompassed by possibleKeywordInput
324 is >> defaultMean >> status[0] >> status[1] >> status[2];
325 return is;
326}
static double longs2double(const std::vector< unsigned long > &v)
Definition: DoubConv.cc:114
std::string name() const
Definition: RandPoisson.cc:35
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167

Referenced by CLHEP::RandPoissonQ::get().

◆ getLocalEngine()

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

◆ getMaxMean()

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

Definition at line 103 of file RandPoisson.h.

103{return meanMax_st;}

Referenced by fire(), and shoot().

◆ getOldMean()

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

Definition at line 101 of file RandPoisson.h.

101{return oldm_st;}

Referenced by shoot().

◆ getPStatus()

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

Definition at line 107 of file RandPoisson.h.

107{return status_st;}

Referenced by shoot().

◆ name()

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

Reimplemented from CLHEP::HepRandom.

Reimplemented in CLHEP::RandPoissonQ.

Definition at line 35 of file RandPoisson.cc.

35{return "RandPoisson";}

Referenced by get(), and put().

◆ operator()() [1/2]

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

Reimplemented from CLHEP::HepRandom.

Reimplemented in CLHEP::RandPoissonQ.

Definition at line 46 of file RandPoisson.cc.

46 {
47 return double(fire( defaultMean ));
48}

◆ operator()() [2/2]

double CLHEP::RandPoisson::operator() ( double  m)

Definition at line 50 of file RandPoisson.cc.

50 {
51 return double(fire( mean ));
52}

◆ put()

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

Reimplemented from CLHEP::HepRandom.

Reimplemented in CLHEP::RandPoissonQ.

Definition at line 281 of file RandPoisson.cc.

281 {
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";
290 t = DoubConv::dto2longs(status[0]);
291 os << status[0] << " " << t[0] << " " << t[1] << "\n";
292 t = DoubConv::dto2longs(status[1]);
293 os << status[1] << " " << t[0] << " " << t[1] << "\n";
294 t = DoubConv::dto2longs(status[2]);
295 os << status[2] << " " << t[0] << " " << t[1] << "\n";
296 t = DoubConv::dto2longs(oldm);
297 os << oldm << " " << t[0] << " " << t[1] << "\n";
298 os.precision(pr);
299 return os;
300}
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:98

Referenced by CLHEP::RandPoissonQ::put().

◆ setOldMean()

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

Definition at line 105 of file RandPoisson.h.

105{oldm_st = val;}

Referenced by shoot().

◆ setPStatus()

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

Definition at line 109 of file RandPoisson.h.

109 {
110 status_st[0] = sq; status_st[1] = alxm; status_st[2] = g1;
111 }

Referenced by shoot().

◆ shoot() [1/2]

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

Definition at line 91 of file RandPoisson.cc.

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

Referenced by shootArray().

◆ shoot() [2/2]

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

Definition at line 152 of file RandPoisson.cc.

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

◆ shootArray() [1/2]

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

Definition at line 146 of file RandPoisson.cc.

147{
148 for( long* v = vect; v != vect + size; ++v )
149 *v = shoot(m1);
150}
static long shoot(double m=1.0)
Definition: RandPoisson.cc:91

◆ shootArray() [2/2]

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

Definition at line 206 of file RandPoisson.cc.

208{
209 for( long* v = vect; v != vect + size; ++v )
210 *v = shoot(anEngine,m1);
211}

Member Data Documentation

◆ defaultMean

double CLHEP::RandPoisson::defaultMean
protected

◆ meanMax

double CLHEP::RandPoisson::meanMax
protected

Definition at line 98 of file RandPoisson.h.

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


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