Geant4 Cross Reference |
1 // -*- C++ -*- 1 2 // 3 // ------------------------------------------- 4 // HEP Random 5 // --- RandFlat --- 6 // class header file 7 // ------------------------------------------- 8 // This file is part of Geant4 (simulation too 9 10 // Class defining methods for shooting flat ra 11 // integers. 12 // It provides methods to fill with double fla 13 // specified size, as well as methods for shoo 14 // Default boundaries ]0.1[ for operator()(). 15 16 // =========================================== 17 // Gabriele Cosmo - Created: 5th September 199 18 // Peter Urban - ShootBit() and related stu 19 // Gabriele Cosmo - Added operator() and addit 20 // arrays specifying boundari 21 // J.Marraffino - Added default arguments as 22 // operator() with arguments: 23 // M. Fischler - Moved copy constructor to 24 // derived RandBit can get at it. 25 // M Fischler - put and get to/from strea 26 // =========================================== 27 28 #ifndef RandFlat_h 29 #define RandFlat_h 1 30 31 #include "CLHEP/Random/Random.h" 32 #include "CLHEP/Utility/memory.h" 33 #include "CLHEP/Utility/thread_local.h" 34 35 namespace CLHEP { 36 37 /** 38 * @author <Gabriele.Cosmo@cern.ch> 39 * @ingroup random 40 */ 41 class RandFlat : public HepRandom { 42 43 public: 44 45 inline RandFlat ( HepRandomEngine& anEngine 46 inline RandFlat ( HepRandomEngine& anEngine, 47 inline RandFlat ( HepRandomEngine& anEngine, 48 inline RandFlat ( HepRandomEngine* anEngine 49 inline RandFlat ( HepRandomEngine* anEngine, 50 inline RandFlat ( HepRandomEngine* anEngine, 51 // These constructors should be used to inst 52 // distribution object defining a local engi 53 // The static generator will be skipped usin 54 // defined below. 55 // If the engine is passed by pointer the co 56 // will be deleted by the RandFlat destructo 57 // If the engine is passed by reference the 58 // will not be deleted by the RandFlat destr 59 60 virtual ~RandFlat(); 61 // Destructor 62 63 // Static methods to shoot random values usi 64 65 static double shoot(); 66 67 static inline double shoot( double width ); 68 69 static inline double shoot( double a, doubl 70 71 static inline long shootInt( long n ); 72 73 static inline long shootInt( long a1, long 74 75 static inline int shootBit(); 76 77 static void shootArray ( const int size, do 78 79 static void shootArray ( const int size, do 80 double lx, double 81 82 // Static methods to shoot random values us 83 // by-passing the static generator. 84 85 static inline double shoot ( HepRandomEngin 86 87 static inline double shoot( HepRandomEngine 88 89 static inline double shoot( HepRandomEngine 90 double a, do 91 static inline long shootInt( HepRandomEngin 92 93 static inline long shootInt( HepRandomEngin 94 95 static inline int shootBit( HepRandomEngine 96 97 static inline void shootArray ( HepRandomEn 98 const int s 99 100 static void shootArray ( HepRandomEngine* a 101 const int size, do 102 double lx, double 103 104 // Methods using the localEngine to shoot r 105 // the static generator. 106 107 inline double fire(); 108 109 inline double fire( double width ); 110 111 inline double fire( double a, double b ); 112 113 inline long fireInt( long n ); 114 115 inline long fireInt( long a1, long n ); 116 117 inline int fireBit(); 118 119 void fireArray (const int size, double* vect 120 121 void fireArray (const int size, double* vect 122 double lx, double dx); 123 124 double operator()(); 125 double operator()( double width ); 126 double operator()( double a, double b ); 127 128 // Save and restore to/from streams 129 130 std::ostream & put ( std::ostream & os ) con 131 std::istream & get ( std::istream & is ); 132 133 std::string name() const; 134 HepRandomEngine & engine(); 135 136 static std::string distributionName() {retur 137 // Provides the name of this distribution cl 138 139 // Methods overriding the base class static 140 // by adding extra data so that save in one 141 // will produce the identical sequence to re 142 // generating shootBit() randoms there 143 144 static void saveEngineStatus( const char fil 145 // Saves to file the current status of the c 146 147 static void restoreEngineStatus( const char 148 // Restores a saved status (if any) for the 149 150 static std::ostream& saveFullState ( std::os 151 // Saves to stream the state of the engine a 152 153 static std::istream& restoreFullState ( std: 154 // Restores from stream the state of the eng 155 156 static std::ostream& saveDistState ( std::os 157 // Saves to stream the state of the cached d 158 159 static std::istream& restoreDistState ( std: 160 // Restores from stream the state of the cac 161 162 163 protected: 164 165 #if 0 166 // Protected copy constructor. Defining it h 167 RandFlat(const RandFlat& d); 168 #endif // 0 169 170 private: 171 172 // ShootBits generates an integer random num 173 // which is used by fireBit(). 174 // The number is stored in randomInt and fir 175 176 inline void fireBits(); 177 static inline void shootBits(); 178 static inline void shootBits(HepRandomEngine 179 180 // In MSB, the most significant bit of the i 181 // generated by ShootBits() is set. 182 // Note: 183 // the number of significant bits must be 184 // - an unsigned long can hold it 185 // - and it should be less than the number 186 // by Shoot() which are not affected by 187 // on _each_ architecture. 188 // (Aim: the random generators should be m 189 190 static const unsigned long MSB; 191 static const int MSBBits; 192 // These two are set up in RandFlat.cc and n 193 194 unsigned long randomInt; 195 unsigned long firstUnusedBit; 196 static CLHEP_THREAD_LOCAL unsigned long stat 197 static CLHEP_THREAD_LOCAL unsigned long stat 198 199 std::shared_ptr<HepRandomEngine> localEngine 200 double defaultWidth; 201 double defaultA; 202 double defaultB; 203 204 }; 205 206 } // namespace CLHEP 207 208 #include "CLHEP/Random/RandFlat.icc" 209 210 #endif 211