Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:19

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : A.Sailer
0011 //
0012 //=========================================================================
0013 
0014 // Class include file
0015 #include "Geant4EventSeed.h"
0016 
0017 // Framework include files
0018 #include <DD4hep/InstanceCount.h>
0019 #include <DD4hep/Printout.h>
0020 
0021 #include <DDG4/Geant4EventAction.h>
0022 #include <DDG4/Geant4Random.h>
0023 #include <DDG4/Factories.h>
0024 
0025 #include <CLHEP/Random/EngineFactory.h>
0026 
0027 //Geant includes
0028 #include <G4Run.hh>
0029 #include <G4Event.hh>
0030 
0031 using namespace dd4hep::sim;
0032 
0033 /// Standard constructor
0034 Geant4EventSeed::Geant4EventSeed(Geant4Context* c, const std::string& typ) : Geant4RunAction(c, typ),
0035                                          m_initialSeed(0),
0036                                          m_runID(0),
0037                                          m_type(typ),
0038                                          m_initialised(false)
0039 {
0040   Geant4Action::runAction().callAtBegin(this,&Geant4EventSeed::begin);
0041   Geant4Action::eventAction().callAtBegin(this,&Geant4EventSeed::beginEvent);
0042   InstanceCount::increment(this);
0043 }
0044 
0045 /// Default destructor
0046 Geant4EventSeed::~Geant4EventSeed() {
0047   InstanceCount::decrement(this);
0048 }
0049 
0050 /// begin-of-run callback
0051 void Geant4EventSeed::begin(const G4Run* run) {
0052 
0053   if(not m_initialised){
0054     m_initialised = true;
0055     m_initialSeed = Geant4Random::instance()->engine()->getSeed();
0056   }
0057 
0058   m_runID = run->GetRunID();
0059 
0060   dd4hep::printout( dd4hep::INFO, m_type, "Get RunID: runID=%u", m_runID );
0061 
0062 }
0063 
0064 /// begin-of-event callback
0065 void Geant4EventSeed::beginEvent(const G4Event* evt) {
0066 
0067   Geant4Random *rndm = Geant4Random::instance();
0068 
0069   unsigned int eventID = evt->GetEventID();
0070   unsigned int newSeed = hash( m_initialSeed, eventID, m_runID );
0071 
0072   dd4hep::printout( dd4hep::INFO, m_type,
0073             "At beginEvent: eventID=%u, runID=%u initialSeed=%u, newSeed=%u" ,
0074             evt->GetEventID(),  m_runID, m_initialSeed, newSeed );
0075 
0076   rndm->setSeed( newSeed );
0077 
0078   if ( dd4hep::printLevel() <= dd4hep::DEBUG ) {
0079     rndm->showStatus();
0080   }
0081 
0082 }
0083 
0084 DECLARE_GEANT4ACTION(Geant4EventSeed)