CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

RanecuEngine.h

Go to the documentation of this file.
00001 // $Id: RanecuEngine.h,v 1.6 2010/07/20 18:06:02 garren Exp $
00002 // -*- C++ -*-
00003 //
00004 // -----------------------------------------------------------------------
00005 //                             HEP Random
00006 //                         --- RanecuEngine ---
00007 //                          class header file
00008 // -----------------------------------------------------------------------
00009 // This file is part of Geant4 (simulation toolkit for HEP).
00010 //
00011 // RANECU Random Engine - algorithm originally written in FORTRAN77
00012 //                        as part of the MATHLIB HEP library.
00013 // The initialisation is carried out using a Multiplicative Congruential
00014 // generator using formula constants of L'Ecuyer as described in "F.James,
00015 // Comp. Phys. Comm. 60 (1990) 329-344".
00016 // Seeds are taken from a seed table given an index, the getSeed() method
00017 // returns the current index in the seed table, the getSeeds() method
00018 // returns a pointer to the couple of seeds stored in the local table of
00019 // seeds at the current index.
00020 
00021 // =======================================================================
00022 // Gabriele Cosmo - Created: 2nd February 1996
00023 //                - Minor corrections: 31st October 1996
00024 //                - Added methods for engine status: 19th November 1996
00025 //                - setSeed() now has default dummy argument
00026 //                  set to zero: 11th July 1997
00027 //                - Added default index to setSeeds(): 16th Oct 1997
00028 // J.Marraffino   - Added stream operators and related constructor.
00029 //                  Added automatic seed selection from seed table and
00030 //                  engine counter: 16th Feb 1998
00031 // Ken Smith      - Added conversion operators:  6th Aug 1998
00032 // Mark Fischler    Methods for distrib. instance save/restore 12/8/04    
00033 // Mark Fischler    methods for anonymous save/restore 12/27/04    
00034 // =======================================================================
00035 
00036 #ifndef RanecuEngine_h
00037 #define RanecuEngine_h 1
00038 
00039 #include "CLHEP/Random/defs.h"
00040 #include "CLHEP/Random/RandomEngine.h"
00041 
00042 namespace CLHEP {
00043 
00048 class RanecuEngine : public HepRandomEngine {
00049 
00050 public:
00051 
00052   RanecuEngine(std::istream& is);
00053   RanecuEngine();
00054   RanecuEngine(int index);
00055   virtual ~RanecuEngine();
00056   // Constructors and destructor.
00057 
00058   double flat();
00059   // Returns a pseudo random number between 0 and 1 
00060   // (excluding the end points)
00061 
00062   void flatArray (const int size, double* vect);
00063   // Fills an array "vect" of specified size with flat random values.
00064 
00065   void setIndex (long index);
00066   // Sets the state of the algorithm according to "index", the position
00067   // in the local table of seeds.
00068  
00069   void setSeed (long index, int dum=0);
00070   // Resets the state of the algorithm according to "index", the position
00071   // in the static table of seeds stored in HepRandom.
00072 
00073   void setSeeds (const long* seeds, int index=-1);
00074   // Sets the state of the algorithm according to the array of seeds
00075   // "seeds" containing two seed values to be stored in the local table at
00076   // "index" position.
00077 
00078   void saveStatus( const char filename[] = "Ranecu.conf" ) const;
00079   // Saves on file Ranecu.conf the current engine status.
00080 
00081   void restoreStatus( const char filename[] = "Ranecu.conf" );
00082   // Reads from file Ranecu.conf the last saved engine status
00083   // and restores it.
00084 
00085   void showStatus() const;
00086   // Dumps the engine status on the screen.
00087 
00088   operator unsigned int();
00089   // 32-bit int flat, faster in this case
00090 
00091   virtual std::ostream & put (std::ostream & os) const;
00092   virtual std::istream & get (std::istream & is);
00093   static  std::string beginTag ( );
00094   virtual std::istream & getState ( std::istream & is );
00095 
00096   std::string name() const;
00097   static std::string engineName() {return "RanecuEngine";}
00098 
00099   std::vector<unsigned long> put () const;
00100   bool get (const std::vector<unsigned long> & v);
00101   bool getState (const std::vector<unsigned long> & v);
00102   
00103 protected:
00104 
00105   // Suggested L'ecuyer coefficients for portable 32 bits generators.
00106   
00107   static const int ecuyer_a = 40014;
00108   static const int ecuyer_b = 53668;
00109   static const int ecuyer_c = 12211;
00110   static const int ecuyer_d = 40692;
00111   static const int ecuyer_e = 52774;
00112   static const int ecuyer_f = 3791;
00113   static const int shift1   = 2147483563;
00114   static const int shift2   = 2147483399;
00115 
00116   static const unsigned int VECTOR_STATE_SIZE = 4;
00117   
00118 private:
00119 
00120   // private method used to mitigate the effects of using a lookup table
00121   void further_randomize (int seq, int col, int index, int modulus);
00122 
00123   // Members defining the current state of the generator.
00124 
00125   static const int maxSeq = 215;
00126   long table[215][2];
00127   int seq;
00128   static int numEngines;
00129 
00130 };
00131 
00132 }  // namespace CLHEP
00133 
00134 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
00135 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
00136 using namespace CLHEP;
00137 #endif
00138 
00139 #endif

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7