Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
pois.cpp File Reference
#include <cmath>
#include "wcpplib/random/pois.h"
#include "wcpplib/random/rnorm.h"
#include "wcpplib/random/ranluxint.h"
#include "wcpplib/stream/prstream.h"

Go to the source code of this file.

Functions

long pois (double AMU, int &IERROR)
 

Function Documentation

◆ pois()

long pois ( double  AMU,
int &  IERROR 
)

Definition at line 17 of file pois.cpp.

26 {
27 double AMUOL = -1.;
28 double AMAX = 100.;
29 double EXPMA = 0.;
30 double PIR = 0;
31 double RAN;
32 //static double SECOND_RAN;
33 //static int s_inited_SECOND_RAN = 0;
34 long N = 0;
35 IERROR = 0;
36 if (AMU > AMAX) goto m500;
37 if (AMU == AMUOL) goto m200;
38 if (AMU > 0.0) goto m100;
39 //C MEAN SHOULD BE POSITIVE
40 IERROR = 1;
41 return 0;
42//C SAVE EXPONENTIAL FOR FURTHER IDENTICAL REQUESTS
43m100:
44 IERROR = 0;
45 AMUOL = AMU;
46 EXPMA = exp(-AMU);
47m200:
48 PIR = 1.;
49 N = -1;
50m300:
51 N = N + 1;
52 //{ // for debug
53 // double x = SRANLUX();
54 // mcout<<"pois: x = "<<x<<'\n';
55 // PIR=PIR * x;
56 //}
57 PIR = PIR * SRANLUX(); // working variant
58 if (PIR > EXPMA) goto m300;
59 return N;
60//C NORMAL APPROXIMATION FOR AMU.GT.AMAX
61m500:
62 /*
63 //Iprint2n(mcout,
64 // pois_state.s_inited_SECOND_RAN,
65 // pois_state.SECOND_RAN);
66 if(pois_state.s_inited_SECOND_RAN == 1)
67 {
68 pois_state.s_inited_SECOND_RAN = 0;
69 N = long(pois_state.SECOND_RAN*sqrt(AMU) + AMU + .5);
70 return N;
71 }
72 else
73 {
74 rnorm_double(SRANLUX(), SRANLUX(), RAN, pois_state.SECOND_RAN);
75 N = long(RAN*sqrt(AMU) + AMU + .5);
76 pois_state.s_inited_SECOND_RAN = 1;
77 return N;
78 }
79 */
80 RAN = rnorm_improved();
81 N = long(RAN * sqrt(AMU) + AMU + .5);
82 return N;
83
84}
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:313
DoubleAc exp(const DoubleAc &f)
Definition: DoubleAc.cpp:376
ffloat SRANLUX(void)
Definition: ranluxint.h:262
double rnorm_improved(void)
Definition: rnorm.cpp:15

Referenced by Heed::HeedParticle::physics(), Heed::HeedParticle_BGM::physics(), and Heed::HeedDeltaElectron::physics_after_new_speed().