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{
29 m_VREventStream = new std::ofstream;
30}
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

◆ ~EventAction()

~EventAction ( )
virtual

Destructor.

Definition at line 32 of file EventAction.cc.

33{
34 if (m_writeSimSteps) {
35 // Just in case the file is still opened...
36 if (m_VREventStream->is_open())
37 m_VREventStream->close();
38 delete m_VREventStream;
39 }
40}

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 42 of file EventAction.cc.

43{
44 //Enable recording of Hits
46 if (m_writeSimSteps) {
47 // Open a new output file for the VR event-history steps
48 if (m_VREventStream->is_open())
49 m_VREventStream->close();
50 if (not m_evtMetaData.isValid())
51 B2FATAL("EventMetaData is not valid.");
52 int eventNumber = m_evtMetaData->getEvent();
53 std::string filename = boost::str(boost::format("event%1%.csv") % eventNumber);
54 m_VREventStream->open(filename);
55 B2INFO("Opened VR event-history file " << filename);
56 }
57}
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 60 of file EventAction.cc.

61{
62 //Disable recording of Hits
64
65 //Create the final MCParticle list and update the indices of the MCParticle graph particles.
67
68 //Build a TrackID to MCParticle index list
69 vector<std::pair<unsigned int, bool> > indices;
70 indices.resize(m_mcParticleGraph.size() + 1);
71 for (unsigned int iParticle = 0; iParticle < m_mcParticleGraph.size(); ++iParticle) {
72 const MCParticleGraph::GraphParticle& currParticle = m_mcParticleGraph[iParticle];
73 //assert(currParticle.getTrackID()<indices.size());
74 indices[currParticle.getTrackID()] = std::make_pair(currParticle.getIndex() - 1, currParticle.getIgnore());
75 }
76 RelationArray::ReplaceVec<> indexReplacement(indices);
77
78 //Update all registered MCParticle Relations and replace the TrackID by the final MCParticle id
79 const std::map<std::string, RelationArray::EConsolidationAction>& relations = SensitiveDetectorBase::getMCParticleRelations();
80 for (std::map<std::string, RelationArray::EConsolidationAction>::const_iterator it = relations.begin(); it != relations.end();
81 ++it) {
82 RelationArray mcPartRelation(it->first);
83 if (mcPartRelation) mcPartRelation.consolidate(indexReplacement, RelationArray::Identity(), it->second);
84 }
85
86 if (m_writeSimSteps) {
87 // Close the VR event-history file
88 if (m_VREventStream->is_open())
89 m_VREventStream->close();
90 }
91}
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: