Garfield++ v2r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
pois.cpp
Go to the documentation of this file.
1#include <cmath>
2
6
7namespace Heed {
8
9long pois(const double amu, int &ierror) {
10 // C
11 // C POISSON GENERATOR
12 // C CODED FROM LOS ALAMOS REPORT LA-5061-MS
13 // C PROB(N)=EXP(-AMU)*AMU**N/FACT(N)
14 // C WHERE FACT(N) STANDS FOR FACTORIAL OF N
15 // C ON RETURN IERROR.EQ.0 NORMALLY
16 // C IERROR.EQ.1 IF AMU.LE.0.
17 // C
18 double AMUOL = -1.;
19 double AMAX = 100.;
20 double EXPMA = 0.;
21 double PIR = 0;
22 long N = 0;
23 ierror = 0;
24 if (amu > AMAX) goto m500;
25 if (amu == AMUOL) goto m200;
26 if (amu > 0.0) goto m100;
27 // C MEAN SHOULD BE POSITIVE
28 ierror = 1;
29 return 0;
30// C SAVE EXPONENTIAL FOR FURTHER IDENTICAL REQUESTS
31m100:
32 ierror = 0;
33 AMUOL = amu;
34 EXPMA = exp(-amu);
35m200:
36 PIR = 1.;
37 N = -1;
38m300:
39 N = N + 1;
40 PIR = PIR * SRANLUX();
41 if (PIR > EXPMA) goto m300;
42 return N;
43// C NORMAL APPROXIMATION FOR AMU.GT.AMAX
44m500:
45 const double RAN = rnorm_improved();
46 N = long(RAN * sqrt(amu) + amu + .5);
47 return N;
48}
49}
Definition: BGMesh.cpp:5
double rnorm_improved()
Definition: rnorm.h:11
long pois(const double amu, int &ierror)
Definition: pois.cpp:9
DoubleAc exp(const DoubleAc &f)
Definition: DoubleAc.cpp:377
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:314