|
| 1 | +#include "SimG4Core/Application/interface/Phase2EventAction.h" |
| 2 | +#include "SimG4Core/Application/interface/SimRunInterface.h" |
| 3 | +#include "SimG4Core/Notification/interface/TmpSimEvent.h" |
| 4 | +#include "SimG4Core/Notification/interface/TmpSimVertex.h" |
| 5 | +#include "SimG4Core/Notification/interface/BeginOfEvent.h" |
| 6 | +#include "SimG4Core/Notification/interface/EndOfEvent.h" |
| 7 | +#include "SimG4Core/Notification/interface/CMSSteppingVerbose.h" |
| 8 | + |
| 9 | +#include "FWCore/MessageLogger/interface/MessageLogger.h" |
| 10 | + |
| 11 | +#include "Randomize.hh" |
| 12 | + |
| 13 | +Phase2EventAction::Phase2EventAction(const edm::ParameterSet& p, |
| 14 | + SimRunInterface* rm, |
| 15 | + SimTrackManager* iManager, |
| 16 | + CMSSteppingVerbose* sv) |
| 17 | + : m_runInterface(rm), |
| 18 | + m_trackManager(iManager), |
| 19 | + m_SteppingVerbose(sv), |
| 20 | + m_stopFile(p.getParameter<std::string>("StopFile")), |
| 21 | + m_printRandom(p.getParameter<bool>("PrintRandomSeed")), |
| 22 | + m_debug(p.getUntrackedParameter<bool>("debug", false)) {} |
| 23 | + |
| 24 | +void Phase2EventAction::BeginOfEventAction(const G4Event* anEvent) { |
| 25 | + BeginOfEvent e(anEvent); |
| 26 | + m_beginOfEventSignal(&e); |
| 27 | + |
| 28 | + if (m_printRandom) { |
| 29 | + edm::LogVerbatim("SimG4CoreApplication") |
| 30 | + << "BeginOfEvent " << anEvent->GetEventID() << " Random number: " << G4UniformRand(); |
| 31 | + } |
| 32 | + |
| 33 | + if (nullptr != m_SteppingVerbose) { |
| 34 | + m_SteppingVerbose->beginOfEvent(anEvent); |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +void Phase2EventAction::EndOfEventAction(const G4Event* anEvent) { |
| 39 | + if (m_printRandom) { |
| 40 | + edm::LogVerbatim("SimG4CoreApplication") |
| 41 | + << "Phase2EventAction::EndOfEventAction: " << anEvent->GetEventID() << " Random number: " << G4UniformRand(); |
| 42 | + } |
| 43 | + if (!m_stopFile.empty() && std::ifstream(m_stopFile.c_str())) { |
| 44 | + edm::LogWarning("SimG4CoreApplication") |
| 45 | + << "Phase2EventAction::EndOfEventAction: termination signal received at event " << anEvent->GetEventID(); |
| 46 | + // soft abort run |
| 47 | + m_runInterface->abortRun(true); |
| 48 | + } |
| 49 | + if (anEvent->GetNumberOfPrimaryVertex() == 0) { |
| 50 | + edm::LogWarning("SimG4CoreApplication") << "Phase2EventACtion::EndOfEventAction: event " << anEvent->GetEventID() |
| 51 | + << " must have failed (no G4PrimaryVertices found) and will be skipped"; |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + m_trackManager->storeTracks(); |
| 56 | + |
| 57 | + // dispatch now end of event |
| 58 | + EndOfEvent e(anEvent); |
| 59 | + m_endOfEventSignal(&e); |
| 60 | + |
| 61 | + // delete transient objects |
| 62 | + m_trackManager->reset(); |
| 63 | +} |
| 64 | + |
| 65 | +void Phase2EventAction::abortEvent() { m_runInterface->abortEvent(); } |
0 commit comments