SLIC  6.1.1
Simulation for the Linear Collider (SLIC) - Geant4 simulation application
EventAction.cc
Go to the documentation of this file.
1 #include "EventAction.hh"
2 
3 // LCDD
4 #include "lcdd/detectors/CurrentTrackState.hh"
5 #include "lcdd/util/StringUtil.hh"
6 
7 // SLIC
8 #include "EventMessenger.hh"
9 #include "EventSourceManager.hh"
10 #include "LcioManager.hh"
11 #include "MCParticleManager.hh"
12 #include "RunManager.hh"
13 #include "TrackManager.hh"
14 
15 // Geant4
16 #include "G4Event.hh"
17 #include "G4RunManager.hh"
18 #include "G4SDManager.hh"
19 
20 namespace slic {
21 
23  G4UserEventAction(), Module("EventAction", false), m_enableEventTimer(false) {
25 }
26 
28 }
29 
30 void EventAction::BeginOfEventAction(const G4Event* anEvent) {
31  // Reset current track state.
32  CurrentTrackState::setCurrentTrackID(-1);
33 
34  m_pluginManager->beginEvent(anEvent);
35 }
36 
37 void EventAction::EndOfEventAction(const G4Event *anEvent) {
38 
39  // If either the run or event have been aborted, don't write an LCEvent.
40  if (!RunManager::instance()->isRunAborted() &&
41  !G4RunManager::GetRunManager()->GetCurrentEvent()->IsAborted()) {
42 
43  /* Create an empty LCEvent. */
44  LcioManager::instance()->createLCEvent();
45 
46  /* Save track information to MCParticle collection in LCIO output event. */
47  TrackManager::instance()->saveTrackSummaries(anEvent, LcioManager::instance()->getCurrentLCEvent());
48 
49  /* End of event processing for the current event generator. */
50  EventSourceManager::instance()->endEvent(anEvent);
51 
52  /* Execute LcioManager's end of event action. */
53  LcioManager::instance()->endEvent(anEvent);
54  }
55 
56  m_pluginManager->endEvent(anEvent);
57 
58  /* Stop the event timer. */
60 
61  /* Print the end event message. */
62  //printEndEventMessage(anEvent);
63 }
64 
65 /*
66 void EventAction::printEndEventMessage(const G4Event *anEvent) {
67  //log() << LOG::okay << ">>>> EndEvent <" + StringUtil::toString(anEvent->GetEventID()) + ">" << LOG::endl << LOG::done;
68 }*/
69 
71  const EventAction* ea = static_cast<const EventAction*>(G4RunManager::GetRunManager()->GetUserEventAction());
72  return const_cast<EventAction*>(ea);
73 }
74 
76  if (m_enableEventTimer) {
77  m_eventTimer.Stop();
78 #ifdef SLIC_LOG
79  log() << LOG::okay << "Event Timer: " << m_eventTimer << LOG::done;
80 #endif
81  }
82 }
83 
85  if (m_enableEventTimer) {
86  m_eventTimer.Start();
87 #ifdef SLIC_LOG
88  log() << LOG::verbose << "Started Event Timer." << LOG::done;
89 #endif
90  }
91 }
92 
94 } // namespace slic
static LcioManager * instance()
Implementation of G4UserEventAction.
Definition: EventAction.hh:25
void startEventTimer()
Definition: EventAction.cc:84
G4Timer m_eventTimer
Definition: EventAction.hh:86
void BeginOfEventAction(const G4Event *anEvent)
Definition: EventAction.cc:30
static EventAction * getEventAction()
Definition: EventAction.cc:70
void enableEventTimer(bool et=true)
Definition: EventAction.cc:93
virtual void EndOfEventAction(const G4Event *anEvent)
Definition: EventAction.cc:37
virtual ~EventAction()
Definition: EventAction.cc:27
G4UImessenger * m_messenger
Definition: EventAction.hh:88
Messenger for event-related commands.
Base class for slic code modules that provides common functionality, such as logging to an output str...
Definition: Module.hh:25
LogStream & log()
Definition: Module.hh:99
void beginEvent(const G4Event *anEvent)
void endEvent(const G4Event *anEvent)
static RunManager * instance()
Definition: RunManager.hh:38
@ okay
Definition: LogStream.hh:33
@ verbose
Definition: LogStream.hh:33
@ done
Definition: LogStream.hh:26