Belle II Software development
EventAction Class Reference

The Event Action class. More...

#include <EventAction.h>

Inheritance diagram for EventAction:

Public Member Functions

 EventAction (const std::string &mcCollectionName, MCParticleGraph &mcParticleGraph)
 Constructor.
 
virtual ~EventAction ()
 Destructor.
 
void BeginOfEventAction (const G4Event *event)
 This method is invoked before converting the primary particles to G4Track objects.
 
void EndOfEventAction (const G4Event *event)
 This method is invoked at the very end of event processing.
 
std::ofstream * getVREventStream () const
 This method gets the output stream for the event-history steps.
 

Protected Attributes

std::string m_mcCollectionName
 The name of the MCParticle collection to which the MCParticles should be written.
 
MCParticleGraphm_mcParticleGraph
 Reference to the MCParticle graph which is converted to a MCParticle list by this class.
 

Private Attributes

bool m_writeSimSteps {false}
 Flag for writing out the simulation steps.
 
std::ofstream * m_VREventStream {nullptr}
 Output stream for writing each step of event's history for the Virtual Reality.
 
StoreObjPtr< EventMetaDatam_evtMetaData
 Event metadata.
 

Detailed Description

The Event Action class.

This class is invoked by G4EventManager for each event.

Definition at line 34 of file EventAction.h.

Constructor & Destructor Documentation

◆ EventAction()

EventAction ( const std::string & mcCollectionName,
MCParticleGraph & mcParticleGraph )

Constructor.

Parameters
mcCollectionNameThe name of the MCParticle collection.
mcParticleGraphReference to the MCParticle graph.

Definition at line 24 of file EventAction.cc.

24 :
25 G4UserEventAction(), m_mcCollectionName(mcCollectionName), m_mcParticleGraph(mcParticleGraph)
26{
27 if (false) {
28 G4Event* event;
29 BeginOfEventAction(event);
30 EndOfEventAction(event);
31 }
34 m_VREventStream = new std::ofstream;
35}
bool getWriteSimSteps() const
Get the flag for writing the simulation steps into an output csv file.
static Environment & Instance()
Static method to get a reference to the Environment instance.
std::string m_mcCollectionName
The name of the MCParticle collection to which the MCParticles should be written.
Definition EventAction.h:70
std::ofstream * m_VREventStream
Output stream for writing each step of event's history for the Virtual Reality.
Definition EventAction.h:76
MCParticleGraph & m_mcParticleGraph
Reference to the MCParticle graph which is converted to a MCParticle list by this class.
Definition EventAction.h:71
bool m_writeSimSteps
Flag for writing out the simulation steps.
Definition EventAction.h:75
void EndOfEventAction(const G4Event *event)
This method is invoked at the very end of event processing.
void BeginOfEventAction(const G4Event *event)
This method is invoked before converting the primary particles to G4Track objects.

◆ ~EventAction()

~EventAction ( )
virtual

Destructor.

Definition at line 37 of file EventAction.cc.

38{
39 if (m_writeSimSteps) {
40 // Just in case the file is still opened...
41 if (m_VREventStream->is_open())
42 m_VREventStream->close();
43 delete m_VREventStream;
44 }
45}

Member Function Documentation

◆ BeginOfEventAction()

void BeginOfEventAction ( const G4Event * event)

This method is invoked before converting the primary particles to G4Track objects.

Parameters
eventPointer to the current G4Event object.

Definition at line 47 of file EventAction.cc.

48{
49 //Enable recording of Hits
51 if (m_writeSimSteps) {
52 // Open a new output file for the VR event-history steps
53 if (m_VREventStream->is_open())
54 m_VREventStream->close();
55 if (not m_evtMetaData.isValid())
56 B2FATAL("EventMetaData is not valid.");
57 int eventNumber = m_evtMetaData->getEvent();
58 std::string filename = boost::str(boost::format("event%1%.csv") % eventNumber);
59 m_VREventStream->open(filename);
60 B2INFO("Opened VR event-history file " << filename);
61 }
62}
StoreObjPtr< EventMetaData > m_evtMetaData
Event metadata.
Definition EventAction.h:77
static void setActive(bool activeStatus)
Enable/Disable all Sensitive Detectors.

◆ EndOfEventAction()

void EndOfEventAction ( const G4Event * event)

This method is invoked at the very end of event processing.

Parameters
eventThe pointer to the G4Event object which allows to access trajectories, hits collections and/or digits collections.

Definition at line 65 of file EventAction.cc.

66{
67 //Disable recording of Hits
69
70 //Create the final MCParticle list and update the indices of the MCParticle graph particles.
72
73 //Build a TrackID to MCParticle index list
74 vector<std::pair<unsigned int, bool> > indices;
75 indices.resize(m_mcParticleGraph.size() + 1);
76 for (unsigned int iParticle = 0; iParticle < m_mcParticleGraph.size(); ++iParticle) {
77 MCParticleGraph::GraphParticle& currParticle = m_mcParticleGraph[iParticle];
78 //assert(currParticle.getTrackID()<indices.size());
79 indices[currParticle.getTrackID()] = std::make_pair(currParticle.getIndex() - 1, currParticle.getIgnore());
80 }
81 RelationArray::ReplaceVec<> indexReplacement(indices);
82
83 //Update all registered MCParticle Relations and replace the TrackID by the final MCParticle id
84 const std::map<std::string, RelationArray::EConsolidationAction>& relations = SensitiveDetectorBase::getMCParticleRelations();
85 for (std::map<std::string, RelationArray::EConsolidationAction>::const_iterator it = relations.begin(); it != relations.end();
86 ++it) {
87 RelationArray mcPartRelation(it->first);
88 if (mcPartRelation) mcPartRelation.consolidate(indexReplacement, RelationArray::Identity(), it->second);
89 }
90
91 if (m_writeSimSteps) {
92 // Close the VR event-history file
93 if (m_VREventStream->is_open())
94 m_VREventStream->close();
95 }
96}
int getTrackID() const
Returns the track ID assigned to this MCParticle.
bool getIgnore() const
Get the ignore flag.
@ c_clearParticles
Clear the particle list before adding the graph.
int getIndex() const
Get 1-based index of the particle in the corresponding MCParticle list.
Definition MCParticle.h:219
static const std::map< std::string, RelationArray::EConsolidationAction > & getMCParticleRelations()
Return a list of all registered Relations with MCParticles.

◆ getVREventStream()

std::ofstream * getVREventStream ( ) const
inline

This method gets the output stream for the event-history steps.

Definition at line 66 of file EventAction.h.

66{ return m_VREventStream; }

Member Data Documentation

◆ m_evtMetaData

StoreObjPtr<EventMetaData> m_evtMetaData
private

Event metadata.

Definition at line 77 of file EventAction.h.

◆ m_mcCollectionName

std::string m_mcCollectionName
protected

The name of the MCParticle collection to which the MCParticles should be written.

Definition at line 70 of file EventAction.h.

◆ m_mcParticleGraph

MCParticleGraph& m_mcParticleGraph
protected

Reference to the MCParticle graph which is converted to a MCParticle list by this class.

Definition at line 71 of file EventAction.h.

◆ m_VREventStream

std::ofstream* m_VREventStream {nullptr}
private

Output stream for writing each step of event's history for the Virtual Reality.

Definition at line 76 of file EventAction.h.

76{nullptr};

◆ m_writeSimSteps

bool m_writeSimSteps {false}
private

Flag for writing out the simulation steps.

Definition at line 75 of file EventAction.h.

75{false};

The documentation for this class was generated from the following files: