Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-31 22:26:10

0001 #include "SimG4Core/Application/interface/EventAction.h"
0002 #include "SimG4Core/Application/interface/SimRunInterface.h"
0003 #include "SimG4Core/Notification/interface/G4SimVertex.h"
0004 #include "SimG4Core/Notification/interface/G4SimTrack.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   m_trackManager->setCollapsePrimaryVertices(p.getParameter<bool>("CollapsePrimaryVertices"));
0024 }
0025 
0026 EventAction::~EventAction() {}
0027 
0028 void EventAction::BeginOfEventAction(const G4Event* anEvent) {
0029   m_trackManager->reset();
0030 
0031   BeginOfEvent e(anEvent);
0032   m_beginOfEventSignal(&e);
0033 
0034   if (m_printRandom) {
0035     edm::LogVerbatim("SimG4CoreApplication")
0036         << "BeginOfEvent " << anEvent->GetEventID() << " Random number: " << G4UniformRand();
0037   }
0038 
0039   if (nullptr != m_SteppingVerbose) {
0040     m_SteppingVerbose->BeginOfEvent(anEvent);
0041   }
0042 }
0043 
0044 void EventAction::EndOfEventAction(const G4Event* anEvent) {
0045   if (m_printRandom) {
0046     edm::LogVerbatim("SimG4CoreApplication")
0047         << " EndOfEvent " << anEvent->GetEventID() << " Random number: " << G4UniformRand();
0048   }
0049   if (!m_stopFile.empty() && std::ifstream(m_stopFile.c_str())) {
0050     edm::LogWarning("SimG4CoreApplication")
0051         << "EndOfEventAction: termination signal received at event " << anEvent->GetEventID();
0052     // soft abort run
0053     m_runInterface->abortRun(true);
0054   }
0055   if (anEvent->GetNumberOfPrimaryVertex() == 0) {
0056     edm::LogWarning("SimG4CoreApplication") << "EndOfEventAction: event " << anEvent->GetEventID()
0057                                             << " must have failed (no G4PrimaryVertices found) and will be skipped ";
0058     return;
0059   }
0060 
0061   m_trackManager->storeTracks(m_runInterface->simEvent());
0062 
0063   // dispatch now end of event, and only then delete tracks...
0064   EndOfEvent e(anEvent);
0065   m_endOfEventSignal(&e);
0066 
0067   m_trackManager->deleteTracks();
0068   m_trackManager->cleanTkCaloStateInfoMap();
0069 }
0070 
0071 void EventAction::addTkCaloStateInfo(uint32_t t, const std::pair<math::XYZVectorD, math::XYZTLorentzVectorD>& p) {
0072   m_trackManager->addTkCaloStateInfo(t, p);
0073 }
0074 
0075 void EventAction::abortEvent() { m_runInterface->abortEvent(); }