CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

MTwistEngine.h

Go to the documentation of this file.
00001 // $Id: MTwistEngine.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $
00002 // -*- C++ -*-
00003 //
00004 // -----------------------------------------------------------------------
00005 //                             HEP Random
00006 //                        --- MTwistEngine ---
00007 //                          class header file
00008 // -----------------------------------------------------------------------
00009 // A "fast, compact, huge-period generator" based on M. Matsumoto and 
00010 // T. Nishimura, "Mersenne Twister: A 623-dimensionally equidistributed 
00011 // uniform pseudorandom number generator", to appear in ACM Trans. on
00012 // Modeling and Computer Simulation.  It is a twisted GFSR generator
00013 // with a Mersenne-prime period of 2^19937-1, uniform on open interval (0,1)
00014 // For further information, see http://www.math.keio.ac.jp/~matumoto/emt.html
00015 // =======================================================================
00016 // Ken Smith      - Started initial draft: 14th Jul 1998
00017 //                - Optimized to get pow() out of flat() method: 21st Jul
00018 //                - Added conversion operators:  6th Aug 1998
00019 // M Fischler     - Changes in way powers of two are kept: 16-Sep-1998
00020 // Mark Fischler  - Methods for distrib. instance save/restore 12/8/04    
00021 // Mark Fischler    methods for anonymous save/restore 12/27/04    
00022 // =======================================================================
00023 
00024 #ifndef MTwistEngine_h
00025 #define MTwistEngine_h
00026 
00027 #include "CLHEP/Random/defs.h"
00028 #include "CLHEP/Random/RandomEngine.h"
00029 
00030 namespace CLHEP {
00031 
00036 class MTwistEngine : public HepRandomEngine {
00037 
00038 public:
00039 
00040   MTwistEngine();
00041   MTwistEngine( long seed );
00042   MTwistEngine( int rowIndex, int colIndex );
00043   MTwistEngine( std::istream & is );
00044   virtual ~MTwistEngine();
00045   // Constructors and destructor.
00046 
00047   MTwistEngine( const MTwistEngine & p );
00048   MTwistEngine & operator=( const MTwistEngine & p );
00049   // Copy constructor and operator=.
00050 
00051   double flat();
00052   // Returns a pseudo random number between 0 and 1 (excluding the end points).
00053 
00054   void flatArray(const int size, double* vect);
00055   // Fills an array "vect" of specified size with flat random values.
00056 
00057   void setSeed(long seed, int);
00058   // Sets the state of the algorithm according to seed.
00059 
00060   void setSeeds(const long * seeds, int);
00061   // Sets the state of the algorithm according to the zero terminated
00062   // array of seeds. It is allowed to ignore one or many seeds in this array.
00063 
00064   void saveStatus( const char filename[] = "MTwist.conf") const;
00065   // Saves the current engine status in the named file
00066 
00067   void restoreStatus( const char filename[] = "MTwist.conf" );
00068   // Reads from named file the the last saved engine status and restores it.
00069 
00070   void showStatus() const;
00071   // Dumps the current engine status on the screen.
00072 
00073   operator float();     // returns flat, without worrying about filling bits
00074   operator unsigned int(); // 32-bit flat, quickest of all
00075 
00076   virtual std::ostream & put (std::ostream & os) const;
00077   virtual std::istream & get (std::istream & is);
00078   static  std::string beginTag ( );
00079   virtual std::istream & getState ( std::istream & is );
00080 
00081   std::string name() const;
00082   static std::string engineName() {return "MTwistEngine";}
00083 
00084   std::vector<unsigned long> put () const;
00085   bool get (const std::vector<unsigned long> & v);
00086   bool getState (const std::vector<unsigned long> & v);
00087 
00088   static const unsigned int VECTOR_STATE_SIZE = 626;
00089   
00090 private:
00091 
00092   unsigned int mt[624];
00093   int count624;
00094 
00095   static double twoToMinus_32;
00096   static double twoToMinus_53;
00097   static double nearlyTwoToMinus_54;
00098   void powersOfTwo();
00099 
00100   enum{ NminusM = 227, M = 397, N = 624};
00101   static int numEngines;
00102   static int maxIndex;
00103 
00104 }; // MTwistEngine
00105 
00106 }  // namespace CLHEP
00107 
00108 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
00109 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
00110 using namespace CLHEP;
00111 #endif
00112 
00113 #endif // MTwistEngine_h

Generated on Thu Jul 1 22:02:30 2010 for CLHEP by  doxygen 1.4.7