Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // $Id: Random.h,v 1.5 2010/06/16 17:24:53 garren Exp $
0002 // -*- C++ -*-
0003 //
0004 // -----------------------------------------------------------------------
0005 //                             HEP Random
0006 //                          --- HepRandom ---
0007 //                          class header file
0008 // -----------------------------------------------------------------------
0009 // This file is part of Geant4 (simulation toolkit for HEP).
0010 //
0011 // It's a singleton instantiated by default within the HEP Random module.
0012 // It uses an instantiated HepJamesRandom engine as default algorithm
0013 // for pseudo-random number generation. HepRandom defines a static private
0014 // data member theGenerator and a set of static inlined methods to manipulate
0015 // it. By means of theGenerator the user can change the underlying engine
0016 // algorithm, get and set the seeds and use any kind of defined random
0017 // distribution.
0018 // Distribution classes inherit from HepRandom and define both static and
0019 // not-static interfaces.
0020 // A static table of uncorrelated seeds is available in this class.
0021 // A static method "getTheTableSeeds()" is defined to access a couple of
0022 // seeds at a given index in the table.
0023 
0024 // =======================================================================
0025 // Gabriele Cosmo - Created: 5th Sep 1995
0026 //                - Minor update: 17th May 1996
0027 //                - Poisson now operates on doubles : 31st Oct 1996
0028 //                - Added methods for engine status: 19th Nov 1996
0029 //                - Fixed default values to setTheSeed() and
0030 //                  setTheSeeds() static methods: 16th Oct 1997
0031 //                - Modified HepRandom to act as a singleton, constructors
0032 //                  are kept public for backward compatibility. Added table
0033 //                  of seeds from HepRandomEngine: 19th Mar 1998
0034 //                - Relocated Poisson and Gauss data and simplified
0035 //                  initialisation of static generator: 5th Jan 1999
0036 // =======================================================================
0037 
0038 #ifndef HepRandom_h
0039 #define HepRandom_h 1
0040 
0041 #include "CLHEP/Random/defs.h"
0042 #include "CLHEP/Random/RandomEngine.h"
0043 
0044 namespace CLHEP {
0045 
0046 /**
0047  * @author <Gabriele.Cosmo@cern.ch>
0048  * @ingroup random
0049  */
0050 class HepRandom {
0051 
0052 public:
0053 
0054   HepRandom();
0055   HepRandom(long seed);
0056   // Contructors with and without a seed using the default engine
0057   // (MixMax).
0058  
0059   HepRandom(HepRandomEngine & algorithm);
0060   HepRandom(HepRandomEngine * algorithm);
0061   // Constructor taking an alternative engine as argument. If a pointer is
0062   // given the corresponding object will be deleted by the HepRandom
0063   // destructor.
0064   
0065   virtual ~HepRandom();
0066   // Destructor
0067   
0068   // implicitly allow compiler-generated copy functions 
0069 
0070   double flat();
0071   // Returns the flat value ( interval ]0...1[ ).
0072 
0073   void flatArray(const int size, double* vect);
0074   // Fills "vect" array of flat random values, given the size.
0075 
0076   inline double flat (HepRandomEngine* theNewEngine);
0077   // Returns a flat value, given a defined Random Engine.
0078 
0079   inline void flatArray(HepRandomEngine* theNewEngine, 
0080                         const int size, double* vect);
0081   // Fills "vect" array of flat random values, given the size
0082   // and a defined Random Engine.
0083 
0084   virtual double operator()();
0085   // To get a flat random number using the operator ().
0086 
0087   virtual std::string name() const;
0088   virtual HepRandomEngine & engine();
0089     
0090   
0091   virtual std::ostream & put ( std::ostream & os ) const;
0092   virtual std::istream & get ( std::istream & is );
0093   // Save and restore to/from streams
0094 
0095   // --------------------------------------------------
0096   // Static member functions using the static generator
0097   // --------------------------------------------------
0098 
0099   static void setTheSeed(long seed, int lxr=3);
0100   // (Re)Initializes the generator with a seed.
0101 
0102   static long getTheSeed();
0103   // Gets the current seed of the current generator.
0104 
0105   static void setTheSeeds(const long* seeds, int aux=-1);
0106   // (Re)Initializes the generator with a zero terminated list of seeds.
0107 
0108   static const long* getTheSeeds();
0109   // Gets the current array of seeds of the current generator.
0110 
0111   static void getTheTableSeeds (long* seeds, int index);
0112   // Gets the array of seeds in the static seedTable at "index" position.
0113 
0114   static HepRandom * getTheGenerator();
0115   // Return the current static generator.
0116 
0117   static void setTheEngine (HepRandomEngine* theNewEngine);
0118   // To set the underlying algorithm object.
0119 
0120   static HepRandomEngine * getTheEngine();
0121   // Returns a pointer to the underlying algorithm object.
0122 
0123   static void saveEngineStatus( const char filename[] = "Config.conf" );
0124   // Saves to file the current status of the current engine.
0125 
0126   static void restoreEngineStatus( const char filename[] = "Config.conf" );
0127   // Restores a saved status (if any) for the current engine.
0128 
0129   static std::ostream& saveFullState ( std::ostream & os );
0130   // Saves to stream the state of the engine and cached data.
0131 
0132   static std::istream& restoreFullState ( std::istream & is );
0133   // Restores from stream the state of the engine and cached data.
0134 
0135   static std::ostream& saveDistState ( std::ostream & os ) {return os;}
0136   // Saves to stream the state of the cached data.
0137 
0138   static std::istream& restoreDistState ( std::istream & is ) {return is;}
0139   // Restores from stream the state of the cached data.
0140 
0141   static std::ostream& saveStaticRandomStates ( std::ostream & os );
0142   // Saves to stream the engine and cached data for all distributions.
0143 
0144   static std::istream& restoreStaticRandomStates ( std::istream & is );
0145   // Restores from stream the engine and cached data for all distributions.
0146 
0147   static void showEngineStatus();
0148   // Dumps the current engine status on screen.
0149 
0150   static int createInstance();
0151   // used to initialise the default engine
0152 
0153   static std::string distributionName() {return "HepRandomEngine";}  
0154   // Provides the name of this distribution class
0155        
0156 protected:     // -------- Data members ---------
0157 
0158   static const long seedTable[215][2];
0159   // Table of seeds
0160 
0161 };
0162 
0163 std::ostream & operator<< (std::ostream & os, const HepRandom & dist);
0164 std::istream & operator>> (std::istream & is, HepRandom & dist);
0165 
0166 }  // namespace CLHEP
0167 
0168 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0169 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0170 using namespace CLHEP;
0171 #endif
0172 
0173 #include "CLHEP/Random/Random.icc"
0174 
0175 #endif