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

Ranlux64Engine.h

Go to the documentation of this file.
00001 // $Id: Ranlux64Engine.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $
00002 // -*- C++ -*-
00003 //
00004 // -----------------------------------------------------------------------
00005 //                             HEP Random
00006 //                        --- Ranlux64Engine ---
00007 //                          class header file
00008 // -----------------------------------------------------------------------
00009 // The algorithm for this random engine has been taken from the notes of 
00010 // a double-precision ranlux implementation by Martin Luscher, dated 
00011 // November 1997.
00012 //
00013 // Like the previous ranlux generator, this one also has "luxury" levels,
00014 // determining how many pseudo-random numbers are discarded for every 
00015 // twelve values used. Three levels are given, with the note that Luscher
00016 // himself advocates only the highest two levels for this engine.
00017 //  level 0  (p=109):              Throw away 109 values for every 12 used
00018 //  level 1  (p=202):   (default)  Throw away 202 values for every 12 used
00019 //  level 2  (p=397):              Throw away 397 values for every 12 used
00020 //
00021 // The initialization is carried out using a Multiplicative Congruential
00022 // generator using formula constants of L'Ecuyer as described in "F.James,
00023 // Comp. Phys. Comm. 60 (1990) 329-344".
00024 // =======================================================================
00025 // Ken Smith      - Created Initial draft: 14th Jul 1998
00026 //                - Added conversion operators:  6th Aug 1998
00027 // Mark Fischler
00028 // 9/9/98         - Added update() routine to allow computation of many at once
00029 //                - Replaced algorithm with jone exactly matching Luscher:
00030 //                      48-bits generated
00031 //                      skip n-12 instead of n numbers
00032 //                - Corrected protection agains overflow
00033 // 12/8/04        - Methods for instance save/restore     
00034 // 12/27/04       - methods for anonymous save/restore 12/27/04    
00035 //
00036 // =======================================================================
00037 
00038 #ifndef Ranlux64Engine_h
00039 #define Ranlux64Engine_h
00040 
00041 #include "CLHEP/Random/defs.h"
00042 #include "CLHEP/Random/RandomEngine.h"
00043 
00044 namespace CLHEP {
00045 
00050 class Ranlux64Engine : public HepRandomEngine {
00051 
00052 public:
00053 
00054   Ranlux64Engine( std::istream& is );
00055   Ranlux64Engine();
00056   Ranlux64Engine( long seed, int lux = 1 );
00057   Ranlux64Engine( int rowIndex, int colIndex, int lux );
00058   virtual ~Ranlux64Engine();
00059   // Constructors and destructor
00060 
00061   Ranlux64Engine(const Ranlux64Engine &p);
00062   // Copy constructor
00063 
00064   Ranlux64Engine & operator = (const Ranlux64Engine &p);
00065   // Overloaded assignment operator, to retrieve the engine status.
00066 
00067   double flat();
00068   // It returns a pseudo random number between 0 and 1,
00069   // excluding the end points.
00070 
00071   void flatArray (const int size, double* vect);
00072   // Fills the array "vect" of specified size with flat random values.
00073 
00074   void setSeed(long seed, int lux=1);
00075   // Sets the state of the algorithm according to seed.
00076 
00077   void setSeeds(const long * seeds, int lux=1);
00078   // Sets the state of the algorithm according to the zero terminated
00079   // array of seeds.  Only the first seed is used.
00080 
00081   void saveStatus( const char filename[] = "Ranlux64.conf" ) const;
00082   // Saves in named file the current engine status.
00083 
00084   void restoreStatus( const char filename[] = "Ranlux64.conf" );
00085   // Reads from named file the last saved engine status and restores it.
00086 
00087   void showStatus() const;
00088   // Dumps the engine status on the screen.
00089 
00090   int getLuxury() const { return luxury; }
00091   // Gets the luxury level.
00092 
00093   virtual std::ostream & put (std::ostream & os) const;
00094   virtual std::istream & get (std::istream & is);
00095   static  std::string beginTag ( );
00096   virtual std::istream & getState ( std::istream & is );
00097 
00098   std::string name() const;
00099   static std::string engineName() {return "Ranlux64Engine";}
00100 
00101   std::vector<unsigned long> put () const;
00102   bool get (const std::vector<unsigned long> & v);
00103   bool getState (const std::vector<unsigned long> & v);
00104   
00105   static const unsigned int VECTOR_STATE_SIZE = 30;
00106   
00107 private:
00108 
00109   void update();
00110   void advance(int dozens);
00111 
00112   int pDiscard;     // separate sequence by p-r = p-12 discarded elements
00113   int pDozens;      // pDiscard / 12;
00114   int endIters;     // pDiscard % 12;
00115   int luxury;
00116 
00117   int index;
00118   double randoms[12]; // randoms [i] is the x[n-i] of Luscher's note
00119   double carry;
00120 
00121   static int numEngines;        
00122   static int maxIndex;
00123 
00124   static double twoToMinus_32;
00125   static double twoToMinus_48;
00126   static double twoToMinus_49;
00127 
00128 }; // Ranlux64Engine
00129 
00130 }  // namespace CLHEP
00131 
00132 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
00133 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
00134 using namespace CLHEP;
00135 #endif
00136 
00137 #endif // Ranlux64Engine_h

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