Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // $Id: MTwistEngine.h,v 1.5 2010/06/16 17:24:53 garren Exp $
0002 // -*- C++ -*-
0003 //
0004 // -----------------------------------------------------------------------
0005 //                             HEP Random
0006 //                        --- MTwistEngine ---
0007 //                          class header file
0008 // -----------------------------------------------------------------------
0009 // A "fast, compact, huge-period generator" based on M. Matsumoto and 
0010 // T. Nishimura, "Mersenne Twister: A 623-dimensionally equidistributed 
0011 // uniform pseudorandom number generator", to appear in ACM Trans. on
0012 // Modeling and Computer Simulation.  It is a twisted GFSR generator
0013 // with a Mersenne-prime period of 2^19937-1, uniform on open interval (0,1)
0014 // For further information, see http://www.math.keio.ac.jp/~matumoto/emt.html
0015 // =======================================================================
0016 // Ken Smith      - Started initial draft: 14th Jul 1998
0017 //                - Optimized to get pow() out of flat() method: 21st Jul
0018 //                - Added conversion operators:  6th Aug 1998
0019 // M Fischler     - Changes in way powers of two are kept: 16-Sep-1998
0020 // Mark Fischler  - Methods for distrib. instance save/restore 12/8/04    
0021 // Mark Fischler    methods for anonymous save/restore 12/27/04    
0022 // =======================================================================
0023 
0024 #ifndef MTwistEngine_h
0025 #define MTwistEngine_h
0026 
0027 #include "CLHEP/Random/defs.h"
0028 #include "CLHEP/Random/RandomEngine.h"
0029 
0030 namespace CLHEP {
0031 
0032 /**
0033  * @author
0034  * @ingroup random
0035  */
0036 class MTwistEngine : public HepRandomEngine {
0037 
0038 public:
0039 
0040   MTwistEngine();
0041   MTwistEngine( long seed );
0042   MTwistEngine( int rowIndex, int colIndex );
0043   MTwistEngine( std::istream & is );
0044   virtual ~MTwistEngine();
0045   // Constructors and destructor.
0046 
0047   double flat();
0048   // Returns a pseudo random number between 0 and 1 (excluding the end points).
0049 
0050   void flatArray(const int size, double* vect);
0051   // Fills an array "vect" of specified size with flat random values.
0052 
0053   void setSeed(long seed, int);
0054   // Sets the state of the algorithm according to seed.
0055 
0056   void setSeeds(const long * seeds, int);
0057   // Sets the state of the algorithm according to the zero terminated
0058   // array of seeds. It is allowed to ignore one or many seeds in this array.
0059 
0060   void saveStatus( const char filename[] = "MTwist.conf") const;
0061   // Saves the current engine status in the named file
0062 
0063   void restoreStatus( const char filename[] = "MTwist.conf" );
0064   // Reads from named file the the last saved engine status and restores it.
0065 
0066   void showStatus() const;
0067   // Dumps the current engine status on the screen.
0068 
0069   operator double();       // Returns same as flat()
0070   operator float();        // returns flat, without worrying about filling bits
0071   operator unsigned int(); // 32-bit flat, quickest of all
0072 
0073   virtual std::ostream & put (std::ostream & os) const;
0074   virtual std::istream & get (std::istream & is);
0075   static  std::string beginTag ( );
0076   virtual std::istream & getState ( std::istream & is );
0077 
0078   std::string name() const;
0079   static std::string engineName() {return "MTwistEngine";}
0080 
0081   std::vector<unsigned long> put () const;
0082   bool get (const std::vector<unsigned long> & v);
0083   bool getState (const std::vector<unsigned long> & v);
0084 
0085   static const unsigned int VECTOR_STATE_SIZE = 626;
0086   
0087 private:
0088 
0089   unsigned int mt[624];
0090   int count624;
0091 
0092   enum{ NminusM = 227, M = 397, N = 624};
0093 
0094 }; // MTwistEngine
0095 
0096 }  // namespace CLHEP
0097 
0098 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0099 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0100 using namespace CLHEP;
0101 #endif
0102 
0103 #endif // MTwistEngine_h