Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
RandPoissonQ.h
이 파일의 문서화 페이지로 가기
1 // $Id:$
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- RandPoissonQ ---
7 // class header file
8 // -----------------------------------------------------------------------
9 
10 // Class defining RandPoissonQ, which is derived from RandPoison.
11 // The user interface is identical; but RandGaussQ is much faster in all cases
12 // and a bit less accurate when mu > 100.
13 
14 // =======================================================================
15 // M. Fischler - Created: 4th Feb 2000
16 // M Fischler - put and get to/from streams 12/10/04
17 //
18 // =======================================================================
19 
20 #ifndef RandPoissonQ_h
21 #define RandPoissonQ_h 1
22 
23 #include "CLHEP/Random/Random.h"
25 
26 namespace CLHEP {
27 
32 class RandPoissonQ : public RandPoisson {
33 
34 public:
35 
36  inline RandPoissonQ ( HepRandomEngine& anEngine, double b1=1.0 );
37  inline RandPoissonQ ( HepRandomEngine* anEngine, double b1=1.0 );
38  // These constructors should be used to instantiate a RandPoissonQ
39  // distribution object defining a local engine for it.
40  // The static generator will be skipped using the non-static methods
41  // defined below.
42  // If the engine is passed by pointer the corresponding engine object
43  // will be deleted by the RandPoissonQ destructor.
44  // If the engine is passed by reference the corresponding engine object
45  // will not be deleted by the RandPoissonQ destructor.
46 
47  virtual ~RandPoissonQ();
48  // Destructor
49 
50  // Save and restore to/from streams
51 
52  std::ostream & put ( std::ostream & os ) const;
53  std::istream & get ( std::istream & is );
54 
55  // Methods to generate Poisson-distributed random deviates.
56 
57  // The method used for mu <= 100 is exact, and 3-7 times faster than
58  // that used by RandPoisson.
59  // For mu > 100 then we use a corrected version of a
60  // (quick) Gaussian approximation. Naively that would be:
61  //
62  // Poisson(mu) ~ floor( mu + .5 + Gaussian(sqrt(mu)) )
63  //
64  // but actually, that would give a slightly incorrect sigma and a
65  // very different skew than a true Poisson. Instead we return
66  //
67  // Poisson(mu) ~ floor( a0*mu + a1*g + a2*g*g ) )
68  // (with g a gaussian normal)
69  //
70  // where a0, a1, a2 are chosen to give the exctly correct mean, sigma,
71  // and skew for the Poisson distribution.
72 
73  // Static methods to shoot random values using the static generator
74 
75  static long shoot( double m=1.0 );
76 
77  static void shootArray ( const int size, long* vect, double m=1.0 );
78 
79  // Static methods to shoot random values using a given engine
80  // by-passing the static generator.
81 
82  static long shoot( HepRandomEngine* anEngine, double m=1.0 );
83 
84  static void shootArray ( HepRandomEngine* anEngine,
85  const int size, long* vect, double m=1.0 );
86 
87  // Methods using the localEngine to shoot random values, by-passing
88  // the static generator.
89 
90  long fire();
91  long fire( double m );
92 
93  void fireArray ( const int size, long* vect );
94  void fireArray ( const int size, long* vect, double m);
95 
96  double operator()();
97  double operator()( double m );
98 
99  std::string name() const;
101 
102  static std::string distributionName() {return "RandPoissonQ";}
103  // Provides the name of this distribution class
104 
105 
106  // static constants of possible interest to users:
107 
108  // RandPoisson will never return a deviate greater than this value:
109  static const double MAXIMUM_POISSON_DEVIATE; // Will be 2.0E9
110 
111  static inline int tableBoundary();
112 
113 private:
114 
115  // constructor helper
116  void setupForDefaultMu();
117 
118  // algorithm helper methods - all static since the shoot methods mayneed them
119  static long poissonDeviateSmall ( HepRandomEngine * e, double mean );
120  static long poissonDeviateQuick ( HepRandomEngine * e, double mean );
121  static long poissonDeviateQuick ( HepRandomEngine * e,
122  double A0, double A1, double A2, double sig );
123 
124  // All the engine info, and the default mean, are in the
125  // RandPoisson base class.
126 
127  // quantities for approximate Poisson by corrected Gaussian
128  double a0;
129  double a1;
130  double a2;
131  double sigma;
132 
133  // static data - constants only, so that saveEngineStatus works properly!
134 
135  // The following MUST MATCH the corresponding values used (in
136  // poissonTables.cc) when poissonTables.cdat was created.
137  // poissonTables.cc gets these values by including this header,
138  // but we must be careful not to change these values,
139  // and rebuild RandPoissonQ before re-generating poissonTables.cdat.
140 
141  // (These statics are given values near the start of the .cc file)
142 
143  static const double FIRST_MU; // lowest mu value in table
144  static const double LAST_MU; // highest mu value
145  static const double S; // Spacing between mu values
146  static const int BELOW; // Starting point for N is at mu - BELOW
147  static const int ENTRIES; // Number of entries in each mu row
148 
149 };
150 
151 } // namespace CLHEP
152 
153 #include "CLHEP/Random/RandPoissonQ.icc"
154 
155 #endif
static const double LAST_MU
Definition: RandPoissonQ.h:144
static long poissonDeviateSmall(HepRandomEngine *e, double mean)
std::string name() const
Definition: RandPoissonQ.cc:49
static std::string distributionName()
Definition: RandPoissonQ.h:102
static const double FIRST_MU
Definition: RandPoissonQ.h:143
static const int ENTRIES
Definition: RandPoissonQ.h:147
std::ostream & put(std::ostream &os) const
static const double S
Definition: RandPoissonQ.h:145
static constexpr double m
static long poissonDeviateQuick(HepRandomEngine *e, double mean)
static const double MAXIMUM_POISSON_DEVIATE
Definition: RandPoissonQ.h:109
static void shootArray(const int size, long *vect, double m=1.0)
void fireArray(const int size, long *vect)
RandPoissonQ(HepRandomEngine &anEngine, double b1=1.0)
static long shoot(double m=1.0)
static int tableBoundary()
HepRandomEngine & engine()
Definition: RandPoissonQ.cc:50
static const int BELOW
Definition: RandPoissonQ.h:146
virtual ~RandPoissonQ()
Definition: RandPoissonQ.cc:80