Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:03:30

0001 // $Id: Ranlux64Engine.h,v 1.5 2010/06/16 17:24:53 garren Exp $
0002 // -*- C++ -*-
0003 //
0004 // -----------------------------------------------------------------------
0005 //                             HEP Random
0006 //                        --- Ranlux64Engine ---
0007 //                          class header file
0008 // -----------------------------------------------------------------------
0009 // The algorithm for this random engine has been taken from the notes of 
0010 // a double-precision ranlux implementation by Martin Luscher, dated 
0011 // November 1997.
0012 //
0013 // Like the previous ranlux generator, this one also has "luxury" levels,
0014 // determining how many pseudo-random numbers are discarded for every 
0015 // twelve values used. Three levels are given, with the note that Luscher
0016 // himself advocates only the highest two levels for this engine.
0017 //  level 0  (p=109):              Throw away 109 values for every 12 used
0018 //  level 1  (p=202):   (default)  Throw away 202 values for every 12 used
0019 //  level 2  (p=397):              Throw away 397 values for every 12 used
0020 //
0021 // The initialization is carried out using a Multiplicative Congruential
0022 // generator using formula constants of L'Ecuyer as described in "F.James,
0023 // Comp. Phys. Comm. 60 (1990) 329-344".
0024 // =======================================================================
0025 // Ken Smith      - Created Initial draft: 14th Jul 1998
0026 //                - Added conversion operators:  6th Aug 1998
0027 // Mark Fischler
0028 // 9/9/98     - Added update() routine to allow computation of many at once
0029 //        - Replaced algorithm with jone exactly matching Luscher:
0030 //          48-bits generated
0031 //          skip n-12 instead of n numbers
0032 //        - Corrected protection agains overflow
0033 // 12/8/04        - Methods for instance save/restore     
0034 // 12/27/04       - methods for anonymous save/restore 12/27/04    
0035 //
0036 // =======================================================================
0037 
0038 #ifndef Ranlux64Engine_h
0039 #define Ranlux64Engine_h
0040 
0041 #include "CLHEP/Random/defs.h"
0042 #include "CLHEP/Random/RandomEngine.h"
0043 
0044 namespace CLHEP {
0045 
0046 /**
0047  * @author
0048  * @ingroup random
0049  */
0050 class Ranlux64Engine : public HepRandomEngine {
0051 
0052 public:
0053 
0054   Ranlux64Engine( std::istream& is );
0055   Ranlux64Engine();
0056   Ranlux64Engine( long seed, int lxr = 1 );
0057   Ranlux64Engine( int rowIndex, int colIndex, int lxr );
0058   virtual ~Ranlux64Engine();
0059   // Constructors and destructor
0060 
0061   double flat();
0062   // It returns a pseudo random number between 0 and 1,
0063   // excluding the end points.
0064 
0065   void flatArray (const int size, double* vect);
0066   // Fills the array "vect" of specified size with flat random values.
0067 
0068   void setSeed(long seed, int lxr=1);
0069   // Sets the state of the algorithm according to seed.
0070 
0071   void setSeeds(const long * seeds, int lxr=1);
0072   // Sets the state of the algorithm according to the zero terminated
0073   // array of seeds.  Only the first seed is used.
0074 
0075   void saveStatus( const char filename[] = "Ranlux64.conf" ) const;
0076   // Saves in named file the current engine status.
0077 
0078   void restoreStatus( const char filename[] = "Ranlux64.conf" );
0079   // Reads from named file the last saved engine status and restores it.
0080 
0081   void showStatus() const;
0082   // Dumps the engine status on the screen.
0083 
0084   int getLuxury() const { return luxury; }
0085   // Gets the luxury level.
0086 
0087   virtual std::ostream & put (std::ostream & os) const;
0088   virtual std::istream & get (std::istream & is);
0089   static  std::string beginTag ( );
0090   virtual std::istream & getState ( std::istream & is );
0091 
0092   std::string name() const;
0093   static std::string engineName() {return "Ranlux64Engine";}
0094 
0095   std::vector<unsigned long> put () const;
0096   bool get (const std::vector<unsigned long> & v);
0097   bool getState (const std::vector<unsigned long> & v);
0098   
0099   static const unsigned int VECTOR_STATE_SIZE = 30;
0100   
0101 private:
0102 
0103   void update();
0104   void advance(int dozens);
0105 
0106   int pDiscard;     // separate sequence by p-r = p-12 discarded elements
0107   int pDozens;      // pDiscard / 12;
0108   int endIters;     // pDiscard % 12;
0109   int luxury;
0110 
0111   int index;
0112   double randoms[12]; // randoms [i] is the x[n-i] of Luscher's note
0113   double carry;
0114 
0115 }; // Ranlux64Engine
0116 
0117 }  // namespace CLHEP
0118 
0119 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0120 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0121 using namespace CLHEP;
0122 #endif
0123 
0124 #endif // Ranlux64Engine_h