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.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/clhep/include/CLHEP/Random/RandFlat.h (Version 11.3.0) and /externals/clhep/include/CLHEP/Random/RandFlat.h (Version 10.1.p2)


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