Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:37

0001 // $Id: Hurd160Engine.h,v 1.5 2010/06/16 17:24:53 garren Exp $
0002 // -*- C++ -*-
0003 //
0004 // -----------------------------------------------------------------------
0005 //                           HEP Random
0006 //                      --- Hurd160Engine ---
0007 //                       class header file
0008 // -----------------------------------------------------------------------
0009 //
0010 // The starting point for the Hurd Random algorithm is the paper in 
0011 // IEEE Transactions on Computers c23, 2 Feb 1974. The algorithm is
0012 // essentially a series of 32 interconnected b-bit registers. The basic
0013 // property is that at each step, bit 1 becomes bit 0, bit 2 the new bit 1,
0014 // bit b the new bit b-1. This is modified so that the new bit b0 is the old
0015 // bit b1 XOR'd with some bit b-d from the previous bit register. The values
0016 // of d can be chosen so as to generate a primitive polynomial, a maximal
0017 // length sequence through all bit patterns except the zero pattern.
0018 //
0019 // This generator, Hurd160 use values based upon Table I of the afore 
0020 // mentioned paper, such that we have 160 total bits, representing 32
0021 // 5-bit registers (actually implemented as an array of 5 32-bit words)
0022 // =======================================================================
0023 //  07-23-98  KLS   Initial draft started
0024 // Ken Smith      - Added conversion operators:  6th Aug 1998
0025 // Mark Fischler  - Methods put, get for instance save/restore 12/8/04    
0026 // Mark Fischler  -  methods for anonymous save/restore 12/27/04    
0027 // =======================================================================
0028 
0029 #ifndef Hurd160Engine_h
0030 #define Hurd160Engine_h
0031 
0032 #include "CLHEP/Random/defs.h"
0033 #include "CLHEP/Random/RandomEngine.h"
0034 
0035 namespace CLHEP {
0036 
0037 /**
0038  * @author
0039  * @ingroup random
0040  */
0041 class Hurd160Engine: public HepRandomEngine {
0042  
0043 public:
0044 
0045   Hurd160Engine();
0046   Hurd160Engine( std::istream &is);
0047   Hurd160Engine( long seed );
0048   Hurd160Engine( int rowIndex, int colIndex );
0049   virtual ~Hurd160Engine();
0050   // Constructors and destructor.
0051 
0052   double flat();
0053   // Returns a pseudo random number between 0 and 1
0054 
0055   void flatArray( const int size, double* vect );
0056   // Fills the array "vect" of specified size with flat random values.
0057 
0058   void setSeed( long seed, int );
0059   // Sets the state of the algorithm according to seed.
0060 
0061   void setSeeds( const long* seeds, int );
0062   // Sets the state of the algorithm according to the zero-terminated
0063   // array of seeds. 
0064 
0065   void saveStatus( const char filename[] = "Hurd160Engine.conf" ) const;
0066   // Saves on named file the current engine status
0067 
0068   void restoreStatus( const char filename[] = "Hurd160Engine.conf" );
0069   // Reads from named file the last saved engine status
0070   // and restores it.
0071 
0072   void showStatus() const;
0073   // Dumps the engine status on the screen
0074 
0075   operator double();       // Returns same as flat()
0076   operator float();        // flat value, without worrying about filling bits
0077   operator unsigned int(); // 32-bit flat value, quickest of all
0078 
0079   virtual std::ostream & put (std::ostream & os) const;
0080   virtual std::istream & get (std::istream & is);
0081 
0082   std::string name() const;
0083   static std::string engineName() {return "Hurd160Engine";}
0084   static  std::string beginTag ( );
0085   virtual std::istream & getState ( std::istream & is );
0086 
0087   std::vector<unsigned long> put () const;
0088   bool get (const std::vector<unsigned long> & v);
0089   bool getState (const std::vector<unsigned long> & v);
0090   
0091   static const unsigned int VECTOR_STATE_SIZE = 7;
0092   
0093 private:
0094 
0095   void advance();
0096 
0097   long seeds_[2];
0098   int wordIndex;
0099   unsigned int words[5];
0100 
0101 }; // Hurd160Engine
0102 
0103 }  // namespace CLHEP
0104 
0105 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0106 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0107 using namespace CLHEP;
0108 #endif
0109 
0110 #endif // Hurd160Engine_h