Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:37

0001 // $Id: JamesRandom.h,v 1.5 2010/06/16 17:24:53 garren Exp $
0002 // -*- C++ -*-
0003 //
0004 // -----------------------------------------------------------------------
0005 //                             HEP Random
0006 //                        --- HepJamesRandom ---
0007 //                          class header file
0008 // -----------------------------------------------------------------------
0009 // This file is part of Geant4 (simulation toolkit for HEP).
0010 //
0011 // HepJamesRandom implements the algorithm by Marsaglia-Zaman RANMAR
0012 // described in "F.James, Comp. Phys. Comm. 60 (1990) 329" and implemented
0013 // in FORTRAN77 as part of the MATHLIB HEP library for pseudo-random
0014 // numbers generation.
0015 // This is the default random engine invoked by each distribution unless
0016 // the user sets a different one.
0017 
0018 // =======================================================================
0019 // Gabriele Cosmo - Created: 5th September 1995
0020 //                - Minor corrections: 31st October 1996
0021 //                - Added methods for engine status: 19th November 1996
0022 //                - setSeed(), setSeeds() now have default dummy argument
0023 //                  set to zero: 11th July 1997
0024 // J.Marraffino   - Added stream operators and related constructor.
0025 //                  Added automatic seed selection from seed table and
0026 //                  engine counter: 16th Feb 1998
0027 // Ken Smith      - Added conversion operators:  6th Aug 1998
0028 // V. Innocente   - changed pointers to indices     3 may 2000
0029 // Mark Fischler  - Methods for distrib. instance save/restore 12/8/04    
0030 //  Mark Fischler    methods for anonymous save/restore 12/27/04    
0031 // =======================================================================
0032 
0033 #ifndef HepJamesRandom_h
0034 #define HepJamesRandom_h 1
0035 
0036 #include "CLHEP/Random/defs.h"
0037 #include "CLHEP/Random/RandomEngine.h"
0038 
0039 namespace CLHEP {
0040 
0041 /**
0042  * @author
0043  * @ingroup random
0044  */
0045 class HepJamesRandom: public HepRandomEngine {
0046 
0047 public:
0048 
0049   HepJamesRandom(std::istream& is);
0050   HepJamesRandom();
0051   HepJamesRandom(long seed);
0052   HepJamesRandom(int rowIndex, int colIndex);
0053   virtual ~HepJamesRandom();
0054   // Constructor and destructor.
0055 
0056   double flat();
0057   // Returns a pseudo random number between 0 and 1 
0058   // (excluding the end points)
0059 
0060   void flatArray (const int size, double* vect);
0061   // Fills the array "vect" of specified size with flat random values.
0062 
0063   void setSeed(long seed, int dum=0);
0064   // Sets the state of the algorithm according to seed.
0065 
0066   void setSeeds(const long * seeds, int dum=0);
0067   // Sets the state of the algorithm according to the zero terminated
0068   // array of seeds. Only the first seed is used.
0069 
0070   void saveStatus( const char filename[] = "JamesRand.conf" ) const;
0071   // Saves on file JamesRand.conf the current engine status.
0072 
0073   void restoreStatus( const char filename[] = "JamesRand.conf" );
0074   // Reads from file JamesRand.conf the last saved engine status
0075   // and restores it.
0076 
0077   void showStatus() const;
0078   // Dumps the engine status on the screen.
0079 
0080   operator double();
0081   // Returns same as flat()
0082   operator float();
0083   // less precise flat, faster if possible
0084   operator unsigned int();
0085   // 32-bit flat, but slower than double or float.
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 "HepJamesRandom";}
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 = 202;
0100   
0101 private:
0102 
0103   // Members defining the current status of the generator.
0104   double u[97];
0105   double c, cd, cm;
0106   int i97, j97;
0107 };
0108 
0109 }  // namespace CLHEP
0110 
0111 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0112 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0113 using namespace CLHEP;
0114 #endif
0115 
0116 #endif