CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Matrix/CLHEP/Random/RandPoissonQ.h
Go to the documentation of this file.
1 // $Id: RandPoissonQ.h,v 1.5 2010/06/16 17:24:53 garren Exp $
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/defs.h"
24 #include "CLHEP/Random/Random.h"
25 #include "CLHEP/Random/RandPoisson.h"
26 
27 namespace CLHEP {
28 
33 class RandPoissonQ : public RandPoisson {
34 
35 public:
36 
37  inline RandPoissonQ ( HepRandomEngine& anEngine, double b1=1.0 );
38  inline RandPoissonQ ( HepRandomEngine* anEngine, double b1=1.0 );
39  // These constructors should be used to instantiate a RandPoissonQ
40  // distribution object defining a local engine for it.
41  // The static generator will be skipped using the non-static methods
42  // defined below.
43  // If the engine is passed by pointer the corresponding engine object
44  // will be deleted by the RandPoissonQ destructor.
45  // If the engine is passed by reference the corresponding engine object
46  // will not be deleted by the RandPoissonQ destructor.
47 
48  virtual ~RandPoissonQ();
49  // Destructor
50 
51  // Save and restore to/from streams
52 
53  std::ostream & put ( std::ostream & os ) const;
54  std::istream & get ( std::istream & is );
55 
56  // Methods to generate Poisson-distributed random deviates.
57 
58  // The method used for mu <= 100 is exact, and 3-7 times faster than
59  // that used by RandPoisson.
60  // For mu > 100 then we use a corrected version of a
61  // (quick) Gaussian approximation. Naively that would be:
62  //
63  // Poisson(mu) ~ floor( mu + .5 + Gaussian(sqrt(mu)) )
64  //
65  // but actually, that would give a slightly incorrect sigma and a
66  // very different skew than a true Poisson. Instead we return
67  //
68  // Poisson(mu) ~ floor( a0*mu + a1*g + a2*g*g ) )
69  // (with g a gaussian normal)
70  //
71  // where a0, a1, a2 are chosen to give the exctly correct mean, sigma,
72  // and skew for the Poisson distribution.
73 
74  // Static methods to shoot random values using the static generator
75 
76  static long shoot( double m=1.0 );
77 
78  static void shootArray ( const int size, long* vect, double m=1.0 );
79 
80  // Static methods to shoot random values using a given engine
81  // by-passing the static generator.
82 
83  static long shoot( HepRandomEngine* anEngine, double m=1.0 );
84 
85  static void shootArray ( HepRandomEngine* anEngine,
86  const int size, long* vect, double m=1.0 );
87 
88  // Methods using the localEngine to shoot random values, by-passing
89  // the static generator.
90 
91  long fire();
92  long fire( double m );
93 
94  void fireArray ( const int size, long* vect );
95  void fireArray ( const int size, long* vect, double m);
96 
97  double operator()();
98  double operator()( double m );
99 
100  std::string name() const;
102 
103  static std::string distributionName() {return "RandPoissonQ";}
104  // Provides the name of this distribution class
105 
106 
107  // static constants of possible interest to users:
108 
109  // RandPoisson will never return a deviate greater than this value:
110  static const double MAXIMUM_POISSON_DEVIATE; // Will be 2.0E9
111 
112  static inline int tableBoundary();
113 
114 private:
115 
116  // constructor helper
117  void setupForDefaultMu();
118 
119  // algorithm helper methods - all static since the shoot methods mayneed them
120  static long poissonDeviateSmall ( HepRandomEngine * e, double mean );
121  static long poissonDeviateQuick ( HepRandomEngine * e, double mean );
122  static long poissonDeviateQuick ( HepRandomEngine * e,
123  double A0, double A1, double A2, double sig );
124 
125  // All the engine info, and the default mean, are in the
126  // RandPoisson base class.
127 
128  // quantities for approximate Poisson by corrected Gaussian
129  double a0;
130  double a1;
131  double a2;
132  double sigma;
133 
134  // static data - constants only, so that saveEngineStatus works properly!
135 
136  // The following MUST MATCH the corresponding values used (in
137  // poissonTables.cc) when poissonTables.cdat was created.
138  // poissonTables.cc gets these values by including this header,
139  // but we must be careful not to change these values,
140  // and rebuild RandPoissonQ before re-generating poissonTables.cdat.
141 
142  // (These statics are given values near the start of the .cc file)
143 
144  static const double FIRST_MU; // lowest mu value in table
145  static const double LAST_MU; // highest mu value
146  static const double S; // Spacing between mu values
147  static const int BELOW; // Starting point for N is at mu - BELOW
148  static const int ENTRIES; // Number of entries in each mu row
149 
150 };
151 
152 } // namespace CLHEP
153 
154 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
155 // backwards compatibility will be enabled ONLY in CLHEP 1.9
156 using namespace CLHEP;
157 #endif
158 
159 #include "CLHEP/Random/RandPoissonQ.icc"
160 
161 #endif
static const double MAXIMUM_POISSON_DEVIATE
std::string name() const
Definition: RandPoissonQ.cc:49
std::ostream & put(std::ostream &os) const
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
virtual ~RandPoissonQ()
Definition: RandPoissonQ.cc:81