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 10.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/RanshiEngine.h (Version 11.3.0) and /externals/clhep/include/CLHEP/Random/RanshiEngine.h (Version 11.1)


  1 // -*- C++ -*-                                      1 // -*- C++ -*-
  2 //                                                  2 //
  3 // -------------------------------------------      3 // -----------------------------------------------------------------------
  4 //                           HEP Random             4 //                           HEP Random
  5 //                      --- RanshiEngine ---        5 //                      --- RanshiEngine ---
  6 //                       class header file          6 //                       class header file
  7 // -------------------------------------------      7 // -----------------------------------------------------------------------
  8 //                                                  8 //
  9 //                                                  9 //
 10 // The algorithm for this random engine was ta     10 // The algorithm for this random engine was taken from "F.Gutbrod, Comp.
 11 // Phys. Comm. 87 (1995) 291-306".                 11 // Phys. Comm. 87 (1995) 291-306".
 12 //                                                 12 //
 13 // The algorithm can be imagined as a physical     13 // The algorithm can be imagined as a physical system as follows: Imagine
 14 // 512 "black balls" each with their own uniqu     14 // 512 "black balls" each with their own unique spin, and positions char- 
 15 // acterized by disrete angles, where the spin     15 // acterized by disrete angles, where the spin is a 32-bit unsigned integer.
 16 // A "red ball" collides based upon the angle      16 // A "red ball" collides based upon the angle determined by the last 8 bits
 17 // of its spin, and the spin of the colliding      17 // of its spin, and the spin of the colliding ball is taken as the output
 18 // random number. The spin of the colliding ba     18 // random number. The spin of the colliding ball is replaced then with the
 19 // left circular shift of the black ball's spi     19 // left circular shift of the black ball's spin XOR'd with the red ball's
 20 // spin. The black ball's old spin becomes the     20 // spin. The black ball's old spin becomes the red ball's.
 21 //                                                 21 //
 22 // To avoid the traps presented, two measures      22 // To avoid the traps presented, two measures are taken: first, the red 
 23 // ball will oscillate between hitting the low     23 // ball will oscillate between hitting the lower half of the buffer on one
 24 // turn and the upper half on another; second,     24 // turn and the upper half on another; second, the red ball's spin is 
 25 // incremented by a counter of the number of r     25 // incremented by a counter of the number of random numbers produced.
 26 //                                                 26 //
 27 // The result is scaled to a double precision      27 // The result is scaled to a double precision floating point number to which
 28 // is added another random double further scal     28 // is added another random double further scaled 2^(53-32) places to the
 29 // right in order to ensure that the remaining     29 // right in order to ensure that the remaining bits of the result are not 
 30 // left empty due to the mere 32 bits represen     30 // left empty due to the mere 32 bits representation used internally.
 31                                                    31 
 32 // ===========================================     32 // =======================================================================
 33 // Ken Smith      - Created: 9th June 1998         33 // Ken Smith      - Created: 9th June 1998
 34 //                - Removed pow() from flat me     34 //                - Removed pow() from flat method: 21st Jul 1998
 35 //                - Added conversion operators     35 //                - Added conversion operators:  6th Aug 1998
 36 // Mark Fischler    Methods put, get for insta     36 // Mark Fischler    Methods put, get for instance save/restore 12/8/04    
 37 // Mark Fischler    methods for anonymous save     37 // Mark Fischler    methods for anonymous save/restore 12/27/04    
 38 // ===========================================     38 // =======================================================================
 39                                                    39 
 40 #ifndef HepRanshiEngine_h                          40 #ifndef HepRanshiEngine_h
 41 #define HepRanshiEngine_h                          41 #define HepRanshiEngine_h
 42                                                    42 
 43 #include "CLHEP/Random/RandomEngine.h"             43 #include "CLHEP/Random/RandomEngine.h"
 44                                                    44 
 45 namespace CLHEP {                                  45 namespace CLHEP {
 46                                                    46 
 47 /**                                                47 /**
 48  * @author                                         48  * @author
 49  * @ingroup random                                 49  * @ingroup random
 50  */                                                50  */
 51 class RanshiEngine: public HepRandomEngine {       51 class RanshiEngine: public HepRandomEngine {
 52                                                    52  
 53 public:                                            53 public:
 54                                                    54 
 55     RanshiEngine();                                55     RanshiEngine();
 56     RanshiEngine(std::istream &is);                56     RanshiEngine(std::istream &is);
 57     RanshiEngine(long seed);                       57     RanshiEngine(long seed);
 58     RanshiEngine(int rowIndex, int colIndex);      58     RanshiEngine(int rowIndex, int colIndex);
 59     virtual ~RanshiEngine();                       59     virtual ~RanshiEngine();
 60     // Constructors and destructor                 60     // Constructors and destructor
 61                                                    61 
 62     double flat();                                 62     double flat();
 63     // Returns a pseudo random number between      63     // Returns a pseudo random number between 0 and 1
 64                                                    64 
 65     void flatArray(const int size, double* vec     65     void flatArray(const int size, double* vect);
 66     // Fills the array "vect" of specified siz     66     // Fills the array "vect" of specified size with flat random values
 67                                                    67 
 68     void setSeed(long seed, int);                  68     void setSeed(long seed, int);
 69     // Sets the state of the algorithm accordi     69     // Sets the state of the algorithm according to seed.
 70                                                    70 
 71     void setSeeds(const long* seeds, int);         71     void setSeeds(const long* seeds, int);
 72     // Sets the state of the algorithm accordi     72     // Sets the state of the algorithm according to the zero-terminated
 73     // array of seeds.                             73     // array of seeds. 
 74                                                    74 
 75     void saveStatus(const char filename[] = "R     75     void saveStatus(const char filename[] = "RanshiEngine.conf") const;
 76     // Saves on named file the current engine      76     // Saves on named file the current engine status
 77                                                    77 
 78     void restoreStatus(const char filename[] =     78     void restoreStatus(const char filename[] = "RanshiEngine.conf");
 79     // Reads from named file the last saved en     79     // Reads from named file the last saved engine status
 80     // and restores it.                            80     // and restores it.
 81                                                    81 
 82     void showStatus() const;                       82     void showStatus() const;
 83     // Dumps the engine status on the screen       83     // Dumps the engine status on the screen
 84                                                    84 
 85     operator double();       // Returns same a     85     operator double();       // Returns same as flat()
 86     operator float();        // flat value, wi     86     operator float();        // flat value, without worrying about filling bits
 87     operator unsigned int(); // 32-bit flat va     87     operator unsigned int(); // 32-bit flat value, quickest of all
 88                                                    88 
 89     virtual std::ostream & put (std::ostream &     89     virtual std::ostream & put (std::ostream & os) const;
 90     virtual std::istream & get (std::istream &     90     virtual std::istream & get (std::istream & is);
 91     static  std::string beginTag ( );              91     static  std::string beginTag ( );
 92     virtual std::istream & getState ( std::ist     92     virtual std::istream & getState ( std::istream & is );
 93                                                    93 
 94     std::string name() const;                      94     std::string name() const;
 95     static std::string engineName() {return "R     95     static std::string engineName() {return "RanshiEngine";}
 96                                                    96 
 97     std::vector<unsigned long> put () const;       97     std::vector<unsigned long> put () const;
 98     bool get (const std::vector<unsigned long>     98     bool get (const std::vector<unsigned long> & v);
 99     bool getState (const std::vector<unsigned      99     bool getState (const std::vector<unsigned long> & v);
100                                                   100   
101 private:                                          101 private:
102     enum {numBuff = 512};                         102     enum {numBuff = 512};
103                                                   103 
104     unsigned int halfBuff, numFlats;              104     unsigned int halfBuff, numFlats;
105     unsigned int buffer[numBuff];                 105     unsigned int buffer[numBuff];
106     unsigned int redSpin;                         106     unsigned int redSpin;
107                                                   107 
108     static const unsigned int VECTOR_STATE_SIZ    108     static const unsigned int VECTOR_STATE_SIZE = numBuff + 4;
109                                                   109   
110 }; // RanshiEngine                                110 }; // RanshiEngine
111                                                   111 
112 }  // namespace CLHEP                             112 }  // namespace CLHEP
113                                                   113 
114 #endif // HepRanshiEngine_h                       114 #endif // HepRanshiEngine_h
115                                                   115