Geant4 11.1.1
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 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 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  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 45 of file RandPoisson.cc.

45 {
46}

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 38 of file RandPoisson.cc.

38{return *localEngine;}

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

◆ fire() [1/2]

long CLHEP::RandPoisson::fire ( )

Definition at line 215 of file RandPoisson.cc.

215 {
216 return long(fire( defaultMean ));
217}

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

◆ fire() [2/2]

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

Definition at line 219 of file RandPoisson.cc.

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

◆ fireArray() [1/2]

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

Definition at line 271 of file RandPoisson.cc.

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

◆ fireArray() [2/2]

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

Definition at line 277 of file RandPoisson.cc.

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

◆ get()

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

Reimplemented from CLHEP::HepRandom.

Reimplemented in CLHEP::RandPoissonQ.

Definition at line 304 of file RandPoisson.cc.

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

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 37 of file RandPoisson.cc.

37{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 48 of file RandPoisson.cc.

48 {
49 return double(fire( defaultMean ));
50}

◆ operator()() [2/2]

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

Definition at line 52 of file RandPoisson.cc.

52 {
53 return double(fire( mean ));
54}

◆ put()

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

Reimplemented from CLHEP::HepRandom.

Reimplemented in CLHEP::RandPoissonQ.

Definition at line 283 of file RandPoisson.cc.

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

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  mean = 1.0)
static

Definition at line 93 of file RandPoisson.cc.

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

Definition at line 154 of file RandPoisson.cc.

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

◆ shootArray() [1/2]

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

Definition at line 148 of file RandPoisson.cc.

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

◆ shootArray() [2/2]

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

Definition at line 208 of file RandPoisson.cc.

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

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: