File indexing completed on 2024-04-06 12:30:14
0001 #include "SimG4Core/Application/interface/EventAction.h"
0002 #include "SimG4Core/Application/interface/SimRunInterface.h"
0003 #include "SimG4Core/Notification/interface/TmpSimEvent.h"
0004 #include "SimG4Core/Notification/interface/TmpSimVertex.h"
0005 #include "SimG4Core/Notification/interface/BeginOfEvent.h"
0006 #include "SimG4Core/Notification/interface/EndOfEvent.h"
0007 #include "SimG4Core/Notification/interface/CMSSteppingVerbose.h"
0008
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010
0011 #include "Randomize.hh"
0012
0013 EventAction::EventAction(const edm::ParameterSet& p,
0014 SimRunInterface* rm,
0015 SimTrackManager* iManager,
0016 CMSSteppingVerbose* sv)
0017 : m_runInterface(rm),
0018 m_trackManager(iManager),
0019 m_SteppingVerbose(sv),
0020 m_stopFile(p.getParameter<std::string>("StopFile")),
0021 m_printRandom(p.getParameter<bool>("PrintRandomSeed")),
0022 m_debug(p.getUntrackedParameter<bool>("debug", false)) {}
0023
0024 void EventAction::BeginOfEventAction(const G4Event* anEvent) {
0025 BeginOfEvent e(anEvent);
0026 m_beginOfEventSignal(&e);
0027
0028 if (m_printRandom) {
0029 edm::LogVerbatim("SimG4CoreApplication")
0030 << "BeginOfEvent " << anEvent->GetEventID() << " Random number: " << G4UniformRand();
0031 }
0032
0033 if (nullptr != m_SteppingVerbose) {
0034 m_SteppingVerbose->beginOfEvent(anEvent);
0035 }
0036 }
0037
0038 void EventAction::EndOfEventAction(const G4Event* anEvent) {
0039 if (m_printRandom) {
0040 edm::LogVerbatim("SimG4CoreApplication")
0041 << "EventACtion::EndOfEventAction: " << anEvent->GetEventID() << " Random number: " << G4UniformRand();
0042 }
0043 if (!m_stopFile.empty() && std::ifstream(m_stopFile.c_str())) {
0044 edm::LogWarning("SimG4CoreApplication")
0045 << "EventACtion::EndOfEventAction: termination signal received at event " << anEvent->GetEventID();
0046
0047 m_runInterface->abortRun(true);
0048 }
0049 if (anEvent->GetNumberOfPrimaryVertex() == 0) {
0050 edm::LogWarning("SimG4CoreApplication") << "EventACtion::EndOfEventAction: event " << anEvent->GetEventID()
0051 << " must have failed (no G4PrimaryVertices found) and will be skipped";
0052 return;
0053 }
0054
0055 m_trackManager->storeTracks();
0056
0057
0058 EndOfEvent e(anEvent);
0059 m_endOfEventSignal(&e);
0060
0061
0062 m_trackManager->reset();
0063 }
0064
0065 void EventAction::abortEvent() { m_runInterface->abortEvent(); }