StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RandGauss.h
1 /***************************************************************************
2  *
3  * $Id: RandGauss.h,v 1.1 1999/01/30 03:59:00 fisyak Exp $
4  *
5  * Author: Gabriele Cosmo - Created: 5th September 1995
6  * modified for SCL bl
7  ***************************************************************************
8  *
9  * Description:
10  * RandGauss.h,v 1.3 1997/08/12 00:38:44
11  * -----------------------------------------------------------------------
12  * HEP Random
13  * --- RandGauss ---
14  * class header file
15  * -----------------------------------------------------------------------
16  * This file is part of Geant4 (simulation toolkit for HEP).
17  *
18  * Class defining methods for shooting gaussian distributed random values,
19  * given a mean (deafult=0) or specifying also a deviation (default=1).
20  * Gaussian random numbers are generated two at the time, so every
21  * other time shoot is called the number returned is the one generated the
22  * time before.
23  * Default values are used for operator()().
24  *
25  ***************************************************************************
26  *
27  * $Log: RandGauss.h,v $
28  * Revision 1.1 1999/01/30 03:59:00 fisyak
29  * Root Version of StarClassLibrary
30  *
31  * Revision 1.1 1999/01/23 00:27:38 ullrich
32  * Initial Revision
33  *
34  **************************************************************************/
35 
36 #ifndef RandGauss_h
37 #define RandGauss_h 1
38 
39 #include "Random.h"
40 
41 class RandGauss : public HepRandom {
42 
43 public:
44 
45  inline RandGauss ( HepRandomEngine& anEngine );
46  inline RandGauss ( HepRandomEngine* anEngine );
47  // These constructors should be used to instantiate a RandGauss
48  // distribution object defining a local engine for it.
49  // The static generator will be skeeped using the non-static methods
50  // defined below.
51  // If the engine is passed by pointer the corresponding engine object
52  // will be deleted by the RandGauss destructor.
53  // If the engine is passed by reference the corresponding engine object
54  // will not be deleted by the RandGauss destructor.
55 
56  virtual ~RandGauss();
57  // Destructor
58 
59  // Static methods to shoot random values using the static generator
60 
61  static HepDouble shoot();
62 
63  static inline HepDouble shoot( HepDouble mean, HepDouble stdDev );
64 
65  static void shootArray ( const HepInt size, HepDouble* vect,
66  HepDouble mean=0.0, HepDouble stdDev=1.0 );
67 #ifndef ST_NO_TEMPLATE_DEF_ARGS
68  static void shootArray ( vector<HepDouble>&,
69  HepDouble mean=0.0, HepDouble stdDev=1.0 );
70 #else
71  static void shootArray ( vector<HepDouble, allocator<HepDouble> >&,
72  HepDouble mean=0.0, HepDouble stdDev=1.0 );
73 #endif
74  // Static methods to shoot random values using a given engine
75  // by-passing the static generator.
76 
77  static HepDouble shoot( HepRandomEngine* anEngine );
78 
79  static inline HepDouble shoot( HepRandomEngine* anEngine,
80  HepDouble mean, HepDouble stdDev );
81 
82  static void shootArray ( HepRandomEngine* anEngine, const HepInt size,
83  HepDouble* vect, HepDouble mean=0.0,
84  HepDouble stdDev=1.0 );
85 #ifndef ST_NO_TEMPLATE_DEF_ARGS
86  static void shootArray ( HepRandomEngine*,
87  vector<HepDouble>&,
88  HepDouble mean=0.0, HepDouble stdDev=1.0 );
89 #else
90  static void shootArray ( HepRandomEngine*,
91  vector<HepDouble, allocator<HepDouble> >&,
92  HepDouble mean=0.0, HepDouble stdDev=1.0 );
93 #endif
94  // Methods using the localEngine to shoot random values, by-passing
95  // the static generator.
96 
97  HepDouble fire();
98 
99  inline HepDouble fire( HepDouble mean, HepDouble stdDev );
100 
101  void fireArray ( const HepInt size, HepDouble* vect,
102  HepDouble mean=0.0, HepDouble stdDev=1.0 );
103 #ifndef ST_NO_TEMPLATE_DEF_ARGS
104  void fireArray ( vector<HepDouble>&,
105  HepDouble mean=0.0, HepDouble stdDev=1.0 );
106 #else
107  void fireArray ( vector<HepDouble, allocator<HepDouble> >&,
108  HepDouble mean=0.0, HepDouble stdDev=1.0 );
109 #endif
110  HepDouble operator()();
111 
112 protected:
113 
114  static HepBoolean getFlag() {return HepRandom::getTheGenerator()->getFlag();}
115 
116  static void setFlag( HepBoolean val ){HepRandom::getTheGenerator()->setFlag(val);}
117 
118  static HepDouble getVal() {return HepRandom::getTheGenerator()->getVal();}
119 
120  static void setVal( HepDouble nextVal ){HepRandom::getTheGenerator()->setVal(nextVal);}
121 
122 private:
123 
124  HepRandomEngine* localEngine;
125  HepBoolean deleteEngine, set;
126  HepDouble nextGauss;
127 
128 };
129 
130 // ------------------
131 // Inlined functions
132 // ------------------
133 
134 inline RandGauss::RandGauss(HepRandomEngine & anEngine)
135 : localEngine(&anEngine), deleteEngine(false), set(false),
136  nextGauss(0.0) {}
137 
138 inline RandGauss::RandGauss(HepRandomEngine * anEngine)
139 : localEngine(anEngine), deleteEngine(true), set(false),
140  nextGauss(0.0) {}
141 
142 inline HepDouble RandGauss::shoot(HepDouble mean, HepDouble stdDev) {
143  return shoot()*stdDev + mean;
144 }
145 
146 inline HepDouble RandGauss::shoot(HepRandomEngine* anEngine,
147  HepDouble mean, HepDouble stdDev) {
148  return shoot(anEngine)*stdDev + mean;
149 }
150 
151 inline HepDouble RandGauss::fire(HepDouble mean, HepDouble stdDev) {
152  return fire()*stdDev + mean;
153 }
154 
155 #endif