File indexing completed on 2025-01-30 09:17:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/InstanceCount.h>
0017 #include <DDG4/Geant4Kernel.h>
0018 #include <DDG4/Geant4RunAction.h>
0019 #include <DDG4/Geant4GeneratorActionInit.h>
0020 #include <DDG4/Geant4InputHandling.h>
0021
0022 #include <G4Run.hh>
0023
0024 using namespace dd4hep::sim;
0025
0026
0027 Geant4GeneratorActionInit::Geant4GeneratorActionInit(Geant4Context* ctxt, const std::string& nam)
0028 : Geant4GeneratorAction(ctxt,nam)
0029 {
0030 InstanceCount::increment(this);
0031 context()->kernel().runAction().callAtEnd(this,&Geant4GeneratorActionInit::end);
0032 context()->kernel().runAction().callAtBegin(this,&Geant4GeneratorActionInit::begin);
0033 declareProperty("numberOfEvents", m_evtTotal);
0034 declareProperty("numberOfRuns", m_evtRun);
0035 }
0036
0037
0038 Geant4GeneratorActionInit::~Geant4GeneratorActionInit() {
0039 InstanceCount::decrement(this);
0040 }
0041
0042
0043 void Geant4GeneratorActionInit::begin(const G4Run* run) {
0044 m_evtRun = 0;
0045 m_run = run->GetRunID();
0046 }
0047
0048
0049 void Geant4GeneratorActionInit::end(const G4Run* ) {
0050 printP1("+++ Finished run %d after %d events (%d events in total)",m_run,m_evtRun,m_evtTotal);
0051 m_evtRun = 0;
0052 m_run = 0;
0053 }
0054
0055
0056 void Geant4GeneratorActionInit::operator()(G4Event* ) {
0057
0058 ++m_evtTotal;
0059 ++m_evtRun;
0060
0061 print("+++ Initializing event %d. Within run:%d event %d.",m_evtTotal,m_run,m_evtRun);
0062 generationInitialization(this,context());
0063 }