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

Random/CLHEP/Random/RandFlat.h
Go to the documentation of this file.
1 // $Id: RandFlat.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- RandFlat ---
7 // class header file
8 // -----------------------------------------------------------------------
9 // This file is part of Geant4 (simulation toolkit for HEP).
10 
11 // Class defining methods for shooting flat random numbers, double or
12 // integers.
13 // It provides methods to fill with double flat values arrays of
14 // specified size, as well as methods for shooting sequences of 0,1 (bits).
15 // Default boundaries ]0.1[ for operator()().
16 
17 // =======================================================================
18 // Gabriele Cosmo - Created: 5th September 1995
19 // Peter Urban - ShootBit() and related stuff added: 5th Sep 1996
20 // Gabriele Cosmo - Added operator() and additional methods to fill
21 // arrays specifying boundaries: 24th Jul 1997
22 // J.Marraffino - Added default arguments as attributes and
23 // operator() with arguments: 16th Feb 1998
24 // M. Fischler - Moved copy constructor to protected so that
25 // derived RandBit can get at it.
26 // M Fischler - put and get to/from streams 12/10/04
27 // =======================================================================
28 
29 #ifndef RandFlat_h
30 #define RandFlat_h 1
31 
32 #include "CLHEP/Random/defs.h"
33 #include "CLHEP/Random/Random.h"
34 #include "CLHEP/Utility/memory.h"
35 
36 namespace CLHEP {
37 
42 class RandFlat : public HepRandom {
43 
44 public:
45 
46  inline RandFlat ( HepRandomEngine& anEngine );
47  inline RandFlat ( HepRandomEngine& anEngine, double width );
48  inline RandFlat ( HepRandomEngine& anEngine, double a, double b );
49  inline RandFlat ( HepRandomEngine* anEngine );
50  inline RandFlat ( HepRandomEngine* anEngine, double width );
51  inline RandFlat ( HepRandomEngine* anEngine, double a, double b );
52  // These constructors should be used to instantiate a RandFlat
53  // distribution object defining a local engine for it.
54  // The static generator will be skipped using the non-static methods
55  // defined below.
56  // If the engine is passed by pointer the corresponding engine object
57  // will be deleted by the RandFlat destructor.
58  // If the engine is passed by reference the corresponding engine object
59  // will not be deleted by the RandFlat destructor.
60 
61  virtual ~RandFlat();
62  // Destructor
63 
64  // Static methods to shoot random values using the static generator
65 
66  static double shoot();
67 
68  static inline double shoot( double width );
69 
70  static inline double shoot( double a, double b );
71 
72  static inline long shootInt( long n );
73 
74  static inline long shootInt( long a1, long n );
75 
76  static inline int shootBit();
77 
78  static void shootArray ( const int size, double* vect );
79 
80  static void shootArray ( const int size, double* vect,
81  double lx, double dx );
82 
83  // Static methods to shoot random values using a given engine
84  // by-passing the static generator.
85 
86  static inline double shoot ( HepRandomEngine* anEngine );
87 
88  static inline double shoot( HepRandomEngine* anEngine, double width );
89 
90  static inline double shoot( HepRandomEngine* anEngine,
91  double a, double b );
92  static inline long shootInt( HepRandomEngine* anEngine, long n );
93 
94  static inline long shootInt( HepRandomEngine* anEngine, long a1, long n );
95 
96  static inline int shootBit( HepRandomEngine* );
97 
98  static inline void shootArray ( HepRandomEngine* anEngine,
99  const int size, double* vect );
100 
101  static void shootArray ( HepRandomEngine* anEngine,
102  const int size, double* vect,
103  double lx, double dx );
104 
105  // Methods using the localEngine to shoot random values, by-passing
106  // the static generator.
107 
108  inline double fire();
109 
110  inline double fire( double width );
111 
112  inline double fire( double a, double b );
113 
114  inline long fireInt( long n );
115 
116  inline long fireInt( long a1, long n );
117 
118  inline int fireBit();
119 
120  void fireArray (const int size, double* vect);
121 
122  void fireArray (const int size, double* vect,
123  double lx, double dx);
124 
125  double operator()();
126  double operator()( double width );
127  double operator()( double a, double b );
128 
129  // Save and restore to/from streams
130 
131  std::ostream & put ( std::ostream & os ) const;
132  std::istream & get ( std::istream & is );
133 
134  std::string name() const;
135  HepRandomEngine & engine();
136 
137  static std::string distributionName() {return "RandFlat";}
138  // Provides the name of this distribution class
139 
140  // Methods overriding the base class static saveEngineStatus ones,
141  // by adding extra data so that save in one program, then further shootBit()s
142  // will produce the identical sequence to restore in another program, then
143  // generating shootBit() randoms there
144 
145  static void saveEngineStatus( const char filename[] = "Config.conf" );
146  // Saves to file the current status of the current engine.
147 
148  static void restoreEngineStatus( const char filename[] = "Config.conf" );
149  // Restores a saved status (if any) for the current engine.
150 
151  static std::ostream& saveFullState ( std::ostream & os );
152  // Saves to stream the state of the engine and cached data.
153 
154  static std::istream& restoreFullState ( std::istream & is );
155  // Restores from stream the state of the engine and cached data.
156 
157  static std::ostream& saveDistState ( std::ostream & os );
158  // Saves to stream the state of the cached data.
159 
160  static std::istream& restoreDistState ( std::istream & is );
161  // Restores from stream the state of the cached data.
162 
163 
164 protected:
165 
166 #if 0
167  // Protected copy constructor. Defining it here disallows use by users.
168  RandFlat(const RandFlat& d);
169 #endif // 0
170 
171 private:
172 
173  // ShootBits generates an integer random number,
174  // which is used by fireBit().
175  // The number is stored in randomInt and firstUnusedBit
176 
177  inline void fireBits();
178  static inline void shootBits();
179  static inline void shootBits(HepRandomEngine*);
180 
181  // In MSB, the most significant bit of the integer random number
182  // generated by ShootBits() is set.
183  // Note:
184  // the number of significant bits must be chosen so that
185  // - an unsigned long can hold it
186  // - and it should be less than the number of bits returned
187  // by Shoot() which are not affected by precision problems
188  // on _each_ architecture.
189  // (Aim: the random generators should be machine-independent).
190 
191  static const unsigned long MSB;
192  static const int MSBBits;
193  // These two are set up in RandFlat.cc and need not be saved/restored
194 
195  unsigned long randomInt;
196  unsigned long firstUnusedBit;
197  static unsigned long staticRandomInt;
198  static unsigned long staticFirstUnusedBit;
199 
200  shared_ptr<HepRandomEngine> localEngine;
201  double defaultWidth;
202  double defaultA;
203  double defaultB;
204 
205 };
206 
207 } // namespace CLHEP
208 
209 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
210 // backwards compatibility will be enabled ONLY in CLHEP 1.9
211 using namespace CLHEP;
212 #endif
213 
214 #include "CLHEP/Random/RandFlat.icc"
215 
216 #endif
CLHEP::shared_ptr
Definition: Matrix/CLHEP/Utility/memory.h:66
CLHEP::RandFlat::fireInt
long fireInt(long n)
a
@ a
Definition: testCategories.cc:125
CLHEP::HepRandomEngine
Definition: Matrix/CLHEP/Random/RandomEngine.h:55
CLHEP::RandFlat::saveFullState
static std::ostream & saveFullState(std::ostream &os)
Definition: RandFlat.cc:259
CLHEP::RandFlat::name
std::string name() const
Definition: RandFlat.cc:42
CLHEP::RandFlat::fire
double fire()
b
@ b
Definition: testCategories.cc:125
CLHEP::RandFlat::restoreDistState
static std::istream & restoreDistState(std::istream &is)
Definition: RandFlat.cc:234
CLHEP::RandFlat::engine
HepRandomEngine & engine()
Definition: RandFlat.cc:43
CLHEP::RandFlat::get
std::istream & get(std::istream &is)
Definition: RandFlat.cc:187
is
HepRotation and so forth isNear() norm2() rectify() static Rotation row1 row4(To avoid bloat in the code pulled in for programs which don 't use all these features, we split the implementation .cc files. Only isNear() goes into the original Rotation.cc) --------------------------------------- HepAxisAngle and HepEulerAngles classes --------------------------------------- These classes are very useful and simple structures for holding the result of a nice intuituve decomposition of a rotation there is no longer much content in the distinct ZOOM PhysicsVectors library The only content left in the library is the object files representing the various Exception objects When we build the CLHEP classes for the ZOOM we will set up so as to use ZOOM SpaceVector is(but we can disable namespace usage and most of our users do so at this point). What I do is leave Hep3Vector in the global namespace
CLHEP::RandFlat::distributionName
static std::string distributionName()
Definition: Random/CLHEP/Random/RandFlat.h:137
CLHEP::RandFlat::put
std::ostream & put(std::ostream &os) const
Definition: RandFlat.cc:156
CLHEP::RandFlat::restoreFullState
static std::istream & restoreFullState(std::istream &is)
Definition: RandFlat.cc:265
CLHEP::detail::n
n
Definition: Ranlux64Engine.cc:85
size
user code seldom needs to call this function directly ZMerrno whether or not they are still recorded ZMerrno size() Return the(integer) number of ZMthrow 'n exceptions currently recorded. 5) ZMerrno.clear() Set an internal counter to zero. This counter is available(see next function) to user code to track ZMthrow 'n exceptions that have occurred during any arbitrary time interval. 6) ZMerrno.countSinceCleared() Return the(integer) number of ZMthrow 'n exceptions that have been recorded via ZMerrno.write()
CLHEP::RandFlat::operator()
double operator()()
Definition: RandFlat.cc:48
CLHEP::RandFlat::fireArray
void fireArray(const int size, double *vect)
Definition: RandFlat.cc:87
CLHEP
Definition: ClhepVersion.h:13
CLHEP::RandFlat::restoreEngineStatus
static void restoreEngineStatus(const char filename[]="Config.conf")
Definition: RandFlat.cc:119
CLHEP::RandFlat::shootInt
static long shootInt(long n)
CLHEP::RandFlat::RandFlat
RandFlat(HepRandomEngine &anEngine)
CLHEP::RandFlat::shootArray
static void shootArray(const int size, double *vect)
Definition: RandFlat.cc:64
CLHEP::RandFlat::saveDistState
static std::ostream & saveDistState(std::ostream &os)
Definition: RandFlat.cc:225
CLHEP::RandFlat::fireBit
int fireBit()
CLHEP::RandFlat::~RandFlat
virtual ~RandFlat()
Definition: RandFlat.cc:45
CLHEP::RandFlat::saveEngineStatus
static void saveEngineStatus(const char filename[]="Config.conf")
Definition: RandFlat.cc:104
CLHEP::RandFlat::shoot
static double shoot()
Definition: RandFlat.cc:60
CLHEP::RandFlat
Definition: Matrix/CLHEP/Random/RandFlat.h:42
CLHEP::RandFlat::shootBit
static int shootBit()