00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef RandFlat_h
00038 #define RandFlat_h 1
00039
00040 #include "Random.h"
00041
00042 class RandFlat : public HepRandom {
00043
00044 public:
00045
00046 inline RandFlat ( HepRandomEngine& anEngine );
00047 inline RandFlat ( HepRandomEngine* anEngine );
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 virtual ~RandFlat();
00058
00059
00060
00061
00062 static inline HepDouble shoot();
00063 static inline HepDouble shoot( HepDouble width );
00064 static inline HepDouble shoot( HepDouble a, HepDouble b );
00065
00066 static inline long shootInt( long n );
00067 static inline long shootInt( long m, long n );
00068
00069 static inline HepInt shootBit();
00070
00071 static inline void shootArray ( const HepInt size, HepDouble* vect );
00072 #ifndef ST_NO_TEMPLATE_DEF_ARGS
00073 static inline void shootArray (vector<HepDouble>&);
00074 #else
00075 static inline void shootArray (vector<HepDouble, allocator<HepDouble> >&);
00076 #endif
00077 static void shootArray ( const HepInt size, HepDouble* vect,
00078 HepDouble lx, HepDouble dx );
00079 #ifndef ST_NO_TEMPLATE_DEF_ARGS
00080 static void shootArray ( vector<HepDouble>&, HepDouble, HepDouble );
00081 #else
00082 static void shootArray ( vector<HepDouble, allocator<HepDouble> >&,
00083 HepDouble, HepDouble );
00084 #endif
00085
00086
00087
00088 static inline HepDouble shoot ( HepRandomEngine* anEngine );
00089
00090 static inline HepDouble shoot( HepRandomEngine* anEngine, HepDouble width );
00091
00092 static inline HepDouble shoot( HepRandomEngine* anEngine,
00093 HepDouble a, HepDouble b );
00094 static inline long shootInt( HepRandomEngine* anEngine, long n );
00095
00096 static inline long shootInt( HepRandomEngine* anEngine, long m, long n );
00097
00098 static inline HepInt shootBit( HepRandomEngine* );
00099
00100 static inline void shootArray ( HepRandomEngine* anEngine,
00101 const HepInt size, HepDouble* vect );
00102 #ifndef ST_NO_TEMPLATE_DEF_ARGS
00103 static inline void shootArray ( HepRandomEngine*, vector<HepDouble>& );
00104 #else
00105 static inline void shootArray ( HepRandomEngine*, vector<HepDouble,allocator<HepDouble> >& );
00106 #endif
00107
00108 static void shootArray ( HepRandomEngine* anEngine,
00109 const HepInt size, HepDouble* vect,
00110 HepDouble lx, HepDouble dx );
00111 #ifndef ST_NO_TEMPLATE_DEF_ARGS
00112 static void shootArray ( HepRandomEngine*,
00113 vector<HepDouble>&,
00114 HepDouble, HepDouble );
00115 #else
00116 static void shootArray ( HepRandomEngine*,
00117 vector<HepDouble,allocator<HepDouble> >&,
00118 HepDouble, HepDouble );
00119 #endif
00120
00121
00122
00123 inline HepDouble fire();
00124
00125 inline HepDouble fire( HepDouble width );
00126
00127 inline HepDouble fire( HepDouble a, HepDouble b );
00128
00129 inline long fireInt( long n );
00130
00131 inline long fireInt( long m, long n );
00132
00133 inline HepInt fireBit();
00134
00135 inline void fireArray (const HepInt size, HepDouble* vect);
00136 #ifndef ST_NO_TEMPLATE_DEF_ARGS
00137 inline void fireArray (vector<HepDouble>&);
00138 #else
00139 inline void fireArray (vector<HepDouble,allocator<HepDouble> >&);
00140 #endif
00141
00142 void fireArray (const HepInt size, HepDouble* vect,
00143 HepDouble lx, HepDouble dx);
00144 #ifndef ST_NO_TEMPLATE_DEF_ARGS
00145 void fireArray (vector<HepDouble>&, HepDouble, HepDouble);
00146 #else
00147 void fireArray (vector<HepDouble,allocator<HepDouble> >&, HepDouble, HepDouble);
00148 #endif
00149 HepDouble operator()();
00150
00151 private:
00152
00153
00154
00155
00156
00157 inline void fireBits();
00158 static inline void shootBits();
00159 static inline void shootBits(HepRandomEngine*);
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 HepRandomEngine* localEngine;
00172 HepBoolean deleteEngine;
00173
00174 unsigned long randomInt;
00175 unsigned long firstUnusedBit;
00176
00177 static const HepInt MSBBits;
00178 static const unsigned long MSB;
00179
00180 static unsigned long staticRandomInt;
00181 static unsigned long staticFirstUnusedBit;
00182 };
00183
00184 inline RandFlat::RandFlat(HepRandomEngine & anEngine)
00185 : localEngine(&anEngine), deleteEngine(false), firstUnusedBit(0) {}
00186
00187 inline RandFlat::RandFlat(HepRandomEngine * anEngine)
00188 : localEngine(anEngine), deleteEngine(true), firstUnusedBit(0) {}
00189
00190 inline HepDouble RandFlat::shoot() {
00191 return HepRandom::getTheGenerator()->flat();
00192 }
00193
00194 inline HepDouble RandFlat::shoot(HepDouble a, HepDouble b) {
00195 return (b-a)* shoot() + a;
00196 }
00197
00198 inline HepDouble RandFlat::shoot(HepDouble width) {
00199 return width * shoot();
00200 }
00201
00202 inline long RandFlat::shootInt(long n) {
00203 return long(shoot()*HepDouble(n));
00204 }
00205
00206 inline long RandFlat::shootInt(long m, long n) {
00207 return long(shoot()*HepDouble(n-m)) + m;
00208 }
00209
00210 inline void RandFlat::shootArray(const HepInt size, HepDouble* vect) {
00211 HepRandom::getTheGenerator()->flatArray(size,vect);
00212 }
00213
00214 #ifndef ST_NO_TEMPLATE_DEF_ARGS
00215 inline void RandFlat::shootArray(vector<HepDouble>& vec)
00216 #else
00217 inline void RandFlat::shootArray(vector<HepDouble,allocator<HepDouble> >& vec)
00218 #endif
00219 {
00220 HepRandom::getTheGenerator()->flatArray(vec);
00221 }
00222
00223 inline void RandFlat::shootBits() {
00224 const HepDouble factor= 2.0*MSB;
00225 staticFirstUnusedBit= MSB;
00226 staticRandomInt= (unsigned long)(factor*shoot());
00227 }
00228
00229 inline HepInt RandFlat::shootBit() {
00230 if (staticFirstUnusedBit==0)
00231 shootBits();
00232 unsigned long temp= staticFirstUnusedBit&staticRandomInt;
00233 staticFirstUnusedBit>>= 1;
00234 return temp!=0;
00235 }
00236
00237
00238
00239 inline HepDouble RandFlat::shoot(HepRandomEngine* anEngine) {
00240 return anEngine->flat();
00241 }
00242
00243
00244 inline HepDouble RandFlat::shoot(HepRandomEngine* anEngine,
00245 HepDouble a, HepDouble b) {
00246 return (b-a)* anEngine->flat() + a;
00247 }
00248
00249 inline HepDouble RandFlat::shoot(HepRandomEngine* anEngine,
00250 HepDouble width) {
00251 return width * anEngine->flat();
00252 }
00253
00254 inline long RandFlat::shootInt(HepRandomEngine* anEngine,
00255 long n) {
00256 return long(anEngine->flat()*HepDouble(n));
00257 }
00258
00259 inline long RandFlat::shootInt(HepRandomEngine* anEngine,
00260 long m, long n) {
00261 return long(HepDouble(n-m)*anEngine->flat()) + m;
00262 }
00263
00264 inline void RandFlat::shootArray(HepRandomEngine* anEngine,
00265 const HepInt size, HepDouble* vect) {
00266 anEngine->flatArray(size,vect);
00267 }
00268
00269 #ifndef ST_NO_TEMPLATE_DEF_ARGS
00270 inline void RandFlat::shootArray(HepRandomEngine* anEngine,
00271 vector<HepDouble>& vec)
00272 #else
00273 inline void RandFlat::shootArray(HepRandomEngine* anEngine,
00274 vector<HepDouble,allocator<HepDouble> >& vec)
00275 #endif
00276 {
00277 anEngine->flatArray(vec);
00278 }
00279
00280 inline void RandFlat::shootBits(HepRandomEngine* engine) {
00281 const HepDouble factor= 2.0*MSB;
00282 staticFirstUnusedBit= MSB;
00283 staticRandomInt= (unsigned long)(factor*shoot(engine));
00284 }
00285
00286 inline HepInt RandFlat::shootBit(HepRandomEngine* engine) {
00287 if (staticFirstUnusedBit==0)
00288 shootBits(engine);
00289 unsigned long temp= staticFirstUnusedBit&staticRandomInt;
00290 staticFirstUnusedBit>>= 1;
00291 return temp!=0;
00292 }
00293
00294
00295
00296 inline HepDouble RandFlat::fire() {
00297 return localEngine->flat();
00298 }
00299
00300 inline HepDouble RandFlat::fire(HepDouble a, HepDouble b) {
00301 return (b-a)* fire() + a;
00302 }
00303
00304 inline HepDouble RandFlat::fire(HepDouble width) {
00305 return width * fire();
00306 }
00307
00308 inline long RandFlat::fireInt(long n) {
00309 return long(fire()*HepDouble(n));
00310 }
00311
00312 inline long RandFlat::fireInt(long m, long n) {
00313 return long(fire()*HepDouble(n-m)) + m;
00314 }
00315
00316 inline void RandFlat::fireArray(const HepInt size, HepDouble* vect) {
00317 flatArray(localEngine,size,vect);
00318 }
00319
00320 #ifndef ST_NO_TEMPLATE_DEF_ARGS
00321 inline void RandFlat::fireArray(vector<HepDouble>&vec)
00322 #else
00323 inline void RandFlat::fireArray(vector<HepDouble,allocator<HepDouble> >&vec)
00324 #endif
00325 {
00326 flatArray(localEngine,vec);
00327 }
00328
00329 inline void RandFlat::fireBits() {
00330 const HepDouble factor= 2.0*MSB;
00331 firstUnusedBit= MSB;
00332 randomInt= (unsigned long)(factor*fire());
00333 }
00334
00335 inline HepInt RandFlat::fireBit() {
00336 if (firstUnusedBit==0)
00337 fireBits();
00338 unsigned long temp= firstUnusedBit&randomInt;
00339 firstUnusedBit>>= 1;
00340 return temp!=0;
00341 }
00342 #endif