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