Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:29

0001 #pragma once
0002 /**
0003 S4Random.h
0004 ============
0005 
0006 For all the bells and whistles use U4Random.hh
0007 
0008 S4Random.h aims to be a minimal headeronly alternative 
0009 intended for use from standalone tests.
0010 
0011 **/
0012 
0013 #include "CLHEP/Random/RandomEngine.h"
0014 #include "Randomize.hh"
0015 #include "s_seq.h"
0016 
0017 struct S4Random : public CLHEP::HepRandomEngine
0018 {
0019     static constexpr const char* NAME = "S4Random" ; 
0020 
0021     // assert-ing methods : but mandatory for CLHEP::HepRandomEngine
0022     void flatArray(const int size, double* vect){ assert(0); }
0023     void setSeed(long seed, int){ assert(0); }
0024     void setSeeds(const long * seeds, int){ assert(0); }
0025     void saveStatus( const char filename[]) const{ assert(0); }
0026     void restoreStatus( const char filename[]){ assert(0); }
0027     void showStatus() const { assert(0); }
0028     std::string name() const { return NAME ; }
0029 
0030     S4Random(); 
0031 
0032     std::string desc() const ; 
0033     double      flat();
0034     std::string demo(int n) ; 
0035     void        setSequenceIndex(int index_);   // -ve to disable, must be less than ni  
0036 
0037 private:
0038     void enable();
0039     void disable();
0040 
0041     s_seq*                   m_seq ; 
0042     CLHEP::HepRandomEngine*  m_default ;
0043 
0044 };
0045 
0046 inline S4Random::S4Random()
0047     :
0048     m_seq(new s_seq),
0049     m_default(CLHEP::HepRandom::getTheEngine())
0050 {
0051 }
0052 
0053 inline std::string S4Random::desc() const { return m_seq->desc() ; }
0054 inline double      S4Random::flat(){        return m_seq->flat() ; }
0055 inline std::string S4Random::demo(int n) {  return m_seq->demo(n) ; }
0056 
0057 
0058 /**
0059 S4Random::setSequenceIndex
0060 --------------------------------
0061 
0062 Switches random stream when index is not negative.
0063 This is used for example to switch between the separate streams 
0064 used for each photon.
0065 
0066 A negative index disables the control of the Geant4 random engine.  
0067 
0068 **/
0069 
0070 inline void S4Random::setSequenceIndex(int index_)
0071 {
0072     m_seq->setSequenceIndex(index_); 
0073 
0074     if(index_ < 0 ) 
0075     {
0076         disable() ; 
0077     }
0078     else 
0079     {
0080         enable() ; 
0081     }
0082 }
0083 
0084 /**
0085 S4Random::enable 
0086 -----------------
0087 
0088 Invokes CLHEP::HepRandom::setTheEngine to *this* U4Random instance 
0089 which means that all subsequent calls to G4UniformRand will provide pre-cooked 
0090 randoms from the stream controlled by *U4Random::setSequenceIndex*
0091 
0092 **/
0093 inline void S4Random::enable(){  CLHEP::HepRandom::setTheEngine(this); }
0094 
0095 /**
0096 S4Random::disable
0097 ------------------
0098 
0099 Returns to the engine active at instanciation, typically the default engine.
0100 
0101 **/
0102 
0103 inline void S4Random::disable(){ CLHEP::HepRandom::setTheEngine(m_default); }
0104 
0105 
0106