StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RandPoisson.h
1 /***************************************************************************
2  *
3  * $Id: RandPoisson.h,v 1.1 1999/01/30 03:59:00 fisyak Exp $
4  *
5  * Author:
6  ***************************************************************************
7  *
8  * Description:
9  * RandPoisson.h,v 1.5 1998/02/05 00:29:04
10  * -----------------------------------------------------------------------
11  * HEP Random
12  * --- RandPoisson ---
13  * class header file
14  * -----------------------------------------------------------------------
15  * This file is part of Geant4 (simulation toolkit for HEP).
16  *
17  * Class defining methods for shooting numbers according to the Poisson
18  * distribution, given a mean (Algorithm taken from "W.H.Press et al.,
19  * Numerical Recipes in C, Second Edition".
20  * Default mean value is set to 1, value used for operator()().
21  *
22  **************************************************************************
23  *
24  * $Log: RandPoisson.h,v $
25  * Revision 1.1 1999/01/30 03:59:00 fisyak
26  * Root Version of StarClassLibrary
27  *
28  * Revision 1.1 1999/01/23 00:27:39 ullrich
29  * Initial Revision
30  *
31  **************************************************************************/
32 #ifndef RandPoisson_h
33 #define RandPoisson_h 1
34 
35 #include "Random.h"
36 
37 class RandPoisson : public HepRandom {
38 
39 public:
40 
41  inline RandPoisson ( HepRandomEngine& anEngine );
42  inline RandPoisson ( HepRandomEngine* anEngine );
43  // These constructors should be used to instantiate a RandPoisson
44  // distribution object defining a local engine for it.
45  // The static generator will be skeeped using the non-static methods
46  // defined below.
47  // If the engine is passed by pointer the corresponding engine object
48  // will be deleted by the RandPoisson destructor.
49  // If the engine is passed by reference the corresponding engine object
50  // will not be deleted by the RandPoisson destructor.
51 
52  virtual ~RandPoisson();
53  // Destructor
54 
55  // Static methods to shoot random values using the static generator
56 
57  static long shoot( HepDouble m=1.0 );
58 
59  static void shootArray ( const HepInt size, long* vect, HepDouble m=1.0 );
60 #ifndef ST_NO_TEMPLATE_DEF_ARGS
61  static void shootArray ( vector<long>&, HepDouble m=1.0 );
62 #else
63  static void shootArray ( vector<long, allocator<long> >&, HepDouble m=1.0 );
64 #endif
65  // Static methods to shoot random values using a given engine
66  // by-passing the static generator.
67 
68  static long shoot( HepRandomEngine* anEngine, HepDouble m=1.0 );
69 
70  static void shootArray ( HepRandomEngine* anEngine,
71  const HepInt size, long* vect, HepDouble m=1.0 );
72 #ifndef ST_NO_TEMPLATE_DEF_ARGS
73  static void shootArray ( HepRandomEngine*,
74  vector<long>&, HepDouble m=1.0 );
75 #else
76  static void shootArray ( HepRandomEngine*,
77  vector<long, allocator<long> >&, HepDouble m=1.0 );
78 #endif
79  // Methods using the localEngine to shoot random values, by-passing
80  // the static generator.
81 
82  long fire( HepDouble m=1.0 );
83 
84  void fireArray ( const HepInt size, long* vect, HepDouble m=1.0 );
85 #ifndef ST_NO_TEMPLATE_DEF_ARGS
86  void fireArray ( vector<long>&, HepDouble m=1.0 );
87 #else
88  void fireArray ( vector<long,allocator<long> >&, HepDouble m=1.0 );
89 #endif
90  HepDouble operator()();
91 
92 
93 protected:
94 
95  static HepDouble getOldMean() {return HepRandom::getTheGenerator()->getOldMean();}
96 
97  static HepDouble getMaxMean() {return HepRandom::getTheGenerator()->getMaxMean();}
98 
99  static void setOldMean( HepDouble val ){HepRandom::getTheGenerator()->setOldMean(val);}
100 
101  static HepDouble* getPStatus() {return HepRandom::getTheGenerator()->getPStatus();}
102 
103  static void setPStatus(HepDouble sq, HepDouble alxm, HepDouble g) {
104  HepRandom::getTheGenerator()->setPStatus(sq, alxm, g);
105  }
106 
107 private:
108 
109  HepRandomEngine* localEngine;
110  HepBoolean deleteEngine;
111  HepDouble status[3], oldm;
112  const HepDouble meanMax;
113 };
114 
115 // ------------------
116 // Inlined functions
117 // ------------------
118 
119 inline RandPoisson::RandPoisson(HepRandomEngine & anEngine)
120 : localEngine(&anEngine), deleteEngine(false),
121  oldm(-1.0), meanMax(2.0E9) {
122  status[0] = status[1] = status[2] = 0.;
123 }
124 
125 inline RandPoisson::RandPoisson(HepRandomEngine * anEngine)
126 : localEngine(anEngine), deleteEngine(true),
127  oldm(-1.0), meanMax(2.0E9) {
128  status[0] = status[1] = status[2] = 0.;
129 }
130 
131 #endif