Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #pragma once
0002 /**
0003 S4RandomMonitor
0004 =================
0005 
0006 Instanciation holds onto the current engine in m_engine and 
0007 replaces it with itself.  Flat calls to the engine are 
0008 then passed thru to the original engine and monitoring logging 
0009 is provided.  See S4RandomArray for saving all the randoms. 
0010 
0011 NB test which requires Geant4 is in u4/tests/S4RandomMonitorTest.cc
0012 
0013 **/
0014 
0015 #include <vector>
0016 #include <string>
0017 #include <iostream>
0018 #include <iomanip>
0019 #include <sstream>
0020 #include <cstdlib>
0021 #include <csignal>
0022 #include <cassert>
0023 
0024 #include "Randomize.hh"
0025 #include "G4Types.hh"
0026 #include "CLHEP/Random/RandomEngine.h"
0027 
0028 struct S4RandomMonitor : public CLHEP::HepRandomEngine
0029 {
0030     static constexpr const char* NAME = "S4RandomMonitor" ; 
0031     CLHEP::HepRandomEngine*  m_engine ;
0032 
0033     S4RandomMonitor(); 
0034 
0035     // mandatory CLHEP::HepRandomEngine methods
0036     double flat();
0037     void flatArray(const int size, double* vect);
0038     void setSeed(long seed, int);
0039     void setSeeds(const long * seeds, int); 
0040     void saveStatus( const char filename[] = "Config.conf") const ;
0041     void restoreStatus( const char filename[] = "Config.conf" ) ;
0042     void showStatus() const ;
0043     std::string name() const ;
0044 }; 
0045 
0046 inline S4RandomMonitor::S4RandomMonitor()
0047     :
0048     m_engine(CLHEP::HepRandom::getTheEngine())
0049 {
0050     CLHEP::HepRandom::setTheEngine(this); 
0051 }
0052 
0053 
0054 /**
0055 S4RandomMonitor::flat
0056 ------------------------
0057 
0058 This is the engine method that gets invoked by G4UniformRand calls 
0059 
0060 **/
0061 
0062 inline double S4RandomMonitor::flat()
0063 {
0064     double d = m_engine->flat(); 
0065     std::cerr << "S4RandomMonitor::flat " << d << std::endl ;
0066     return d ; 
0067 }
0068 
0069 
0070 /**
0071 S4RandomMonitor::flatArray
0072 ------------------------------
0073 
0074 This method and several others are required as S4RandomMonitor ISA CLHEP::HepRandomEngine
0075 
0076 **/
0077 
0078 inline void S4RandomMonitor::flatArray(const int size, double* vect)
0079 {
0080      assert(0); 
0081 }
0082 inline void S4RandomMonitor::setSeed(long seed, int)
0083 {
0084     assert(0); 
0085 }
0086 inline void S4RandomMonitor::setSeeds(const long * seeds, int)
0087 {
0088     assert(0); 
0089 }
0090 inline void S4RandomMonitor::saveStatus( const char filename[]) const 
0091 {
0092     assert(0); 
0093 }
0094 inline void S4RandomMonitor::restoreStatus( const char filename[]) 
0095 {
0096     assert(0); 
0097 }
0098 inline void S4RandomMonitor::showStatus() const 
0099 {
0100     assert(0); 
0101 }
0102 inline std::string S4RandomMonitor::name() const 
0103 {
0104     return NAME ; 
0105 }
0106