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

JamesRandom.h

Go to the documentation of this file.
00001 // $Id: JamesRandom.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $
00002 // -*- C++ -*-
00003 //
00004 // -----------------------------------------------------------------------
00005 //                             HEP Random
00006 //                        --- HepJamesRandom ---
00007 //                          class header file
00008 // -----------------------------------------------------------------------
00009 // This file is part of Geant4 (simulation toolkit for HEP).
00010 //
00011 // HepJamesRandom implements the algorithm by Marsaglia-Zaman RANMAR
00012 // described in "F.James, Comp. Phys. Comm. 60 (1990) 329" and implemented
00013 // in FORTRAN77 as part of the MATHLIB HEP library for pseudo-random
00014 // numbers generation.
00015 // This is the default random engine invoked by each distribution unless
00016 // the user sets a different one.
00017 
00018 // =======================================================================
00019 // Gabriele Cosmo - Created: 5th September 1995
00020 //                - Minor corrections: 31st October 1996
00021 //                - Added methods for engine status: 19th November 1996
00022 //                - setSeed(), setSeeds() now have default dummy argument
00023 //                  set to zero: 11th July 1997
00024 // J.Marraffino   - Added stream operators and related constructor.
00025 //                  Added automatic seed selection from seed table and
00026 //                  engine counter: 16th Feb 1998
00027 // Ken Smith      - Added conversion operators:  6th Aug 1998
00028 // V. Innocente   - changed pointers to indices     3 may 2000
00029 // Mark Fischler  - Methods for distrib. instance save/restore 12/8/04    
00030 //  Mark Fischler    methods for anonymous save/restore 12/27/04    
00031 // =======================================================================
00032 
00033 #ifndef HepJamesRandom_h
00034 #define HepJamesRandom_h 1
00035 
00036 #include "CLHEP/Random/defs.h"
00037 #include "CLHEP/Random/RandomEngine.h"
00038 
00039 namespace CLHEP {
00040 
00045 class HepJamesRandom: public HepRandomEngine {
00046 
00047 public:
00048 
00049   HepJamesRandom(std::istream& is);
00050   HepJamesRandom();
00051   HepJamesRandom(long seed);
00052   HepJamesRandom(int rowIndex, int colIndex);
00053   virtual ~HepJamesRandom();
00054   // Constructor and destructor.
00055 
00056   HepJamesRandom(const HepJamesRandom &p);
00057   // Copy constructor
00058 
00059   HepJamesRandom & operator = (const HepJamesRandom &p);
00060   // Overloaded assignment operator, to retrieve the engine status.
00061 
00062   double flat();
00063   // Returns a pseudo random number between 0 and 1 
00064   // (excluding the end points)
00065 
00066   void flatArray (const int size, double* vect);
00067   // Fills the array "vect" of specified size with flat random values.
00068 
00069   void setSeed(long seed, int dum=0);
00070   // Sets the state of the algorithm according to seed.
00071 
00072   void setSeeds(const long * seeds, int dum=0);
00073   // Sets the state of the algorithm according to the zero terminated
00074   // array of seeds. Only the first seed is used.
00075 
00076   void saveStatus( const char filename[] = "JamesRand.conf" ) const;
00077   // Saves on file JamesRand.conf the current engine status.
00078 
00079   void restoreStatus( const char filename[] = "JamesRand.conf" );
00080   // Reads from file JamesRand.conf the last saved engine status
00081   // and restores it.
00082 
00083   void showStatus() const;
00084   // Dumps the engine status on the screen.
00085 
00086   operator unsigned int();
00087   // 32-bit flat, but slower than double or float.
00088 
00089   virtual std::ostream & put (std::ostream & os) const;
00090   virtual std::istream & get (std::istream & is);
00091   static  std::string beginTag ( );
00092   virtual std::istream & getState ( std::istream & is );
00093 
00094   std::string name() const;
00095   static std::string engineName() {return "HepJamesRandom";}
00096 
00097   std::vector<unsigned long> put () const;
00098   bool get (const std::vector<unsigned long> & v);
00099   bool getState (const std::vector<unsigned long> & v);
00100   
00101   static const unsigned int VECTOR_STATE_SIZE = 202;
00102   
00103 private:
00104 
00105   // Members defining the current status of the generator.
00106   double u[97];
00107   double c, cd, cm;
00108   int i97, j97;
00109   static int numEngines;
00110   static int maxIndex;
00111 };
00112 
00113 }  // namespace CLHEP
00114 
00115 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
00116 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
00117 using namespace CLHEP;
00118 #endif
00119 
00120 #endif

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