Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
RandFlat.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// -----------------------------------------------------------------------
4// HEP Random
5// --- RandFlat ---
6// class header file
7// -----------------------------------------------------------------------
8// This file is part of Geant4 (simulation toolkit for HEP).
9
10// Class defining methods for shooting flat random numbers, double or
11// integers.
12// It provides methods to fill with double flat values arrays of
13// specified size, as well as methods for shooting sequences of 0,1 (bits).
14// Default boundaries ]0.1[ for operator()().
15
16// =======================================================================
17// Gabriele Cosmo - Created: 5th September 1995
18// Peter Urban - ShootBit() and related stuff added: 5th Sep 1996
19// Gabriele Cosmo - Added operator() and additional methods to fill
20// arrays specifying boundaries: 24th Jul 1997
21// J.Marraffino - Added default arguments as attributes and
22// operator() with arguments: 16th Feb 1998
23// M. Fischler - Moved copy constructor to protected so that
24// derived RandBit can get at it.
25// M Fischler - put and get to/from streams 12/10/04
26// =======================================================================
27
28#ifndef RandFlat_h
29#define RandFlat_h 1
30
31#include "CLHEP/Random/Random.h"
32#include "CLHEP/Utility/defs.h"
35
36namespace CLHEP {
37
38/**
39 * @author <Gabriele.Cosmo@cern.ch>
40 * @ingroup random
41 */
42class RandFlat : public HepRandom {
43
44public:
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 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 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;
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
163private:
164
165 // ShootBits generates an integer random number,
166 // which is used by fireBit().
167 // The number is stored in randomInt and firstUnusedBit
168
169 inline void fireBits();
170 static void shootBits();
171 static void shootBits(HepRandomEngine*);
172
173 // In MSB, the most significant bit of the integer random number
174 // generated by ShootBits() is set.
175 // Note:
176 // the number of significant bits must be chosen so that
177 // - an unsigned long can hold it
178 // - and it should be less than the number of bits returned
179 // by Shoot() which are not affected by precision problems
180 // on _each_ architecture.
181 // (Aim: the random generators should be machine-independent).
182
183 DLL_API static const unsigned long MSB;
184 DLL_API static const int MSBBits;
185 // These two are set up in RandFlat.cc and need not be saved/restored
186
187 unsigned long randomInt;
188 unsigned long firstUnusedBit;
189 static CLHEP_THREAD_LOCAL unsigned long staticRandomInt;
190 static CLHEP_THREAD_LOCAL unsigned long staticFirstUnusedBit;
191
192 std::shared_ptr<HepRandomEngine> localEngine;
193 double defaultWidth;
194 double defaultA;
195 double defaultB;
196
197};
198
199} // namespace CLHEP
200
201#include "CLHEP/Random/RandFlat.icc"
202
203#endif
double operator()()
Definition RandFlat.cc:49
double fire(double width)
static double shoot(double a, double b)
static std::ostream & saveFullState(std::ostream &os)
Definition RandFlat.cc:266
RandFlat(HepRandomEngine *anEngine)
std::ostream & put(std::ostream &os) const
Definition RandFlat.cc:185
static long shootInt(long a1, long n)
static long shootInt(HepRandomEngine *anEngine, long n)
double fire(double a, double b)
virtual ~RandFlat()
Definition RandFlat.cc:46
std::string name() const
Definition RandFlat.cc:43
static double shoot(HepRandomEngine *anEngine)
RandFlat(HepRandomEngine &anEngine)
RandFlat(HepRandomEngine *anEngine, double width)
RandFlat(HepRandomEngine &anEngine, double a, double b)
static double shoot(HepRandomEngine *anEngine, double width)
static long shootInt(long n)
static int shootBit()
Definition RandFlat.cc:111
static void restoreEngineStatus(const char filename[]="Config.conf")
Definition RandFlat.cc:148
void fireArray(const int size, double *vect)
Definition RandFlat.cc:88
long fireInt(long n)
static double shoot(double width)
long fireInt(long a1, long n)
static std::string distributionName()
Definition RandFlat.h:137
static void saveEngineStatus(const char filename[]="Config.conf")
Definition RandFlat.cc:133
static std::ostream & saveDistState(std::ostream &os)
Definition RandFlat.cc:232
RandFlat(HepRandomEngine &anEngine, double width)
RandFlat(HepRandomEngine *anEngine, double a, double b)
static std::istream & restoreDistState(std::istream &is)
Definition RandFlat.cc:241
static double shoot()
Definition RandFlat.cc:61
static void shootArray(const int size, double *vect)
Definition RandFlat.cc:65
static std::istream & restoreFullState(std::istream &is)
Definition RandFlat.cc:272
static double shoot(HepRandomEngine *anEngine, double a, double b)
static long shootInt(HepRandomEngine *anEngine, long a1, long n)
std::istream & get(std::istream &is)
Definition RandFlat.cc:201
static void shootArray(HepRandomEngine *anEngine, const int size, double *vect)
HepRandomEngine & engine()
Definition RandFlat.cc:44
#define DLL_API
Definition defs.h:19
#define CLHEP_THREAD_LOCAL