CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Random/CLHEP/Random/RanshiEngine.h
Go to the documentation of this file.
1 // $Id: RanshiEngine.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- RanshiEngine ---
7 // class header file
8 // -----------------------------------------------------------------------
9 //
10 //
11 // The algorithm for this random engine was taken from "F.Gutbrod, Comp.
12 // Phys. Comm. 87 (1995) 291-306".
13 //
14 // The algorithm can be imagined as a physical system as follows: Imagine
15 // 512 "black balls" each with their own unique spin, and positions char-
16 // acterized by disrete angles, where the spin is a 32-bit unsigned integer.
17 // A "red ball" collides based upon the angle determined by the last 8 bits
18 // of its spin, and the spin of the colliding ball is taken as the output
19 // random number. The spin of the colliding ball is replaced then with the
20 // left circular shift of the black ball's spin XOR'd with the red ball's
21 // spin. The black ball's old spin becomes the red ball's.
22 //
23 // To avoid the traps presented, two measures are taken: first, the red
24 // ball will oscillate between hitting the lower half of the buffer on one
25 // turn and the upper half on another; second, the red ball's spin is
26 // incremented by a counter of the number of random numbers produced.
27 //
28 // The result is scaled to a double precision floating point number to which
29 // is added another random double further scaled 2^(53-32) places to the
30 // right in order to ensure that the remaining bits of the result are not
31 // left empty due to the mere 32 bits representation used internally.
32 
33 // =======================================================================
34 // Ken Smith - Created: 9th June 1998
35 // - Removed pow() from flat method: 21st Jul 1998
36 // - Added conversion operators: 6th Aug 1998
37 // Mark Fischler Methods put, get for instance save/restore 12/8/04
38 // Mark Fischler methods for anonymous save/restore 12/27/04
39 // =======================================================================
40 
41 #ifndef HepRanshiEngine_h
42 #define HepRanshiEngine_h
43 
44 #include "CLHEP/Random/defs.h"
45 #include "CLHEP/Random/RandomEngine.h"
46 
47 namespace CLHEP {
48 
53 class RanshiEngine: public HepRandomEngine {
54 
55 public:
56 
57  RanshiEngine();
58  RanshiEngine(std::istream &is);
59  RanshiEngine(long seed);
60  RanshiEngine(int rowIndex, int colIndex);
61  virtual ~RanshiEngine();
62  // Constructors and destructor
63 
64  double flat();
65  // Returns a pseudo random number between 0 and 1
66 
67  void flatArray(const int size, double* vect);
68  // Fills the array "vect" of specified size with flat random values
69 
70  void setSeed(long seed, int);
71  // Sets the state of the algorithm according to seed.
72 
73  void setSeeds(const long* seeds, int);
74  // Sets the state of the algorithm according to the zero-terminated
75  // array of seeds.
76 
77  void saveStatus(const char filename[] = "RanshiEngine.conf") const;
78  // Saves on named file the current engine status
79 
80  void restoreStatus(const char filename[] = "RanshiEngine.conf");
81  // Reads from named file the last saved engine status
82  // and restores it.
83 
84  void showStatus() const;
85  // Dumps the engine status on the screen
86 
87  operator float(); // flat value, without worrying about filling bits
88  operator unsigned int(); // 32-bit flat value, quickest of all
89 
90  virtual std::ostream & put (std::ostream & os) const;
91  virtual std::istream & get (std::istream & is);
92  static std::string beginTag ( );
93  virtual std::istream & getState ( std::istream & is );
94 
95  std::string name() const;
96  static std::string engineName() {return "RanshiEngine";}
97 
98  std::vector<unsigned long> put () const;
99  bool get (const std::vector<unsigned long> & v);
100  bool getState (const std::vector<unsigned long> & v);
101 
102 private:
103  static int numEngines;
104  enum {numBuff = 512};
105 
106  unsigned int halfBuff, numFlats;
107  unsigned int buffer[numBuff];
108  unsigned int redSpin;
109 
110  static const unsigned int VECTOR_STATE_SIZE = numBuff + 4;
111 
112 }; // RanshiEngine
113 
114 } // namespace CLHEP
115 
116 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
117 // backwards compatibility will be enabled ONLY in CLHEP 1.9
118 using namespace CLHEP;
119 #endif
120 
121 #endif // HepRanshiEngine_h
CLHEP::RanshiEngine::RanshiEngine
RanshiEngine()
Definition: RanshiEngine.cc:49
CLHEP::RanshiEngine::restoreStatus
void restoreStatus(const char filename[]="RanshiEngine.conf")
Definition: RanshiEngine.cc:174
CLHEP::RanshiEngine::beginTag
static std::string beginTag()
Definition: RanshiEngine.cc:306
CLHEP::RanshiEngine::setSeed
void setSeed(long seed, int)
Definition: RanshiEngine.cc:123
is
HepRotation and so forth isNear() norm2() rectify() static Rotation row1 row4(To avoid bloat in the code pulled in for programs which don 't use all these features, we split the implementation .cc files. Only isNear() goes into the original Rotation.cc) --------------------------------------- HepAxisAngle and HepEulerAngles classes --------------------------------------- These classes are very useful and simple structures for holding the result of a nice intuituve decomposition of a rotation there is no longer much content in the distinct ZOOM PhysicsVectors library The only content left in the library is the object files representing the various Exception objects When we build the CLHEP classes for the ZOOM we will set up so as to use ZOOM SpaceVector is(but we can disable namespace usage and most of our users do so at this point). What I do is leave Hep3Vector in the global namespace
size
user code seldom needs to call this function directly ZMerrno whether or not they are still recorded ZMerrno size() Return the(integer) number of ZMthrow 'n exceptions currently recorded. 5) ZMerrno.clear() Set an internal counter to zero. This counter is available(see next function) to user code to track ZMthrow 'n exceptions that have occurred during any arbitrary time interval. 6) ZMerrno.countSinceCleared() Return the(integer) number of ZMthrow 'n exceptions that have been recorded via ZMerrno.write()
CLHEP::RanshiEngine::flatArray
void flatArray(const int size, double *vect)
Definition: RanshiEngine.cc:117
CLHEP::RanshiEngine::engineName
static std::string engineName()
Definition: Random/CLHEP/Random/RanshiEngine.h:96
CLHEP
Definition: ClhepVersion.h:13
CLHEP::RanshiEngine::showStatus
void showStatus() const
Definition: RanshiEngine.cc:211
v
they are gone ZOOM Features Discontinued The following features of the ZOOM package were felt to be extreme overkill These have been after checking that no existing user code was utilizing as in SpaceVector v
Definition: keyMergeIssues.doc:324
CLHEP::RanshiEngine::flat
double flat()
Definition: RanshiEngine.cc:102
CLHEP::RanshiEngine::setSeeds
void setSeeds(const long *seeds, int)
Definition: RanshiEngine.cc:127
CLHEP::RanshiEngine::~RanshiEngine
virtual ~RanshiEngine()
Definition: RanshiEngine.cc:100
seeds
Technical Maintenance Note for CLHEP Random Consequences of seeding JamesRandom with positive seed values greater than In the source code JamesRandom The usual way of seeding a generator is via the default which makes use of the table of seeds(with some trickery to ensure that the values won 't repeat after the table rows are exhausted). The trickery preserves the fact that sees are never negative(because the table values are never negative
CLHEP::RanshiEngine::saveStatus
void saveStatus(const char filename[]="RanshiEngine.conf") const
Definition: RanshiEngine.cc:144
CLHEP::RanshiEngine::put
std::vector< unsigned long > put() const
Definition: RanshiEngine.cc:277
CLHEP::RanshiEngine::get
virtual std::istream & get(std::istream &is)
Definition: RanshiEngine.cc:289
CLHEP::RanshiEngine::getState
virtual std::istream & getState(std::istream &is)
Definition: RanshiEngine.cc:310
CLHEP::RanshiEngine::name
std::string name() const
Definition: RanshiEngine.cc:44