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

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

◆ ~EventAction()

~EventAction ( )
virtual

Destructor.

Definition at line 36 of file EventAction.cc.

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

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

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

65{
66 //Disable recording of Hits
68
69 //Create the final MCParticle list and update the indices of the MCParticle graph particles.
71
72 //Build a TrackID to MCParticle index list
73 vector<std::pair<unsigned int, bool> > indices;
74 indices.resize(m_mcParticleGraph.size() + 1);
75 for (unsigned int iParticle = 0; iParticle < m_mcParticleGraph.size(); ++iParticle) {
76 MCParticleGraph::GraphParticle& currParticle = m_mcParticleGraph[iParticle];
77 //assert(currParticle.getTrackID()<indices.size());
78 indices[currParticle.getTrackID()] = std::make_pair(currParticle.getIndex() - 1, currParticle.getIgnore());
79 }
80 RelationArray::ReplaceVec<> indexReplacement(indices);
81
82 //Update all registered MCParticle Relations and replace the TrackID by the final MCParticle id
83 const std::map<std::string, RelationArray::EConsolidationAction>& relations = SensitiveDetectorBase::getMCParticleRelations();
84 for (std::map<std::string, RelationArray::EConsolidationAction>::const_iterator it = relations.begin(); it != relations.end();
85 ++it) {
86 RelationArray mcPartRelation(it->first);
87 if (mcPartRelation) mcPartRelation.consolidate(indexReplacement, RelationArray::Identity(), it->second);
88 }
89
90 if (m_writeSimSteps) {
91 // Close the VR event-history file
92 if (m_VREventStream->is_open())
93 m_VREventStream->close();
94 }
95}
Class to represent Particle data in graph.
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.
size_t size() const
Return the number of particles in the graph.
void generateList(const std::string &name="", int options=c_setNothing)
Generates the MCParticle list and stores it in the StoreArray with the given name.
int getIndex() const
Get 1-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:230
Struct to replace indices based on a sequential container.
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:62
static const std::map< std::string, RelationArray::EConsolidationAction > & getMCParticleRelations()
Return a list of all registered Relations with MCParticles.
Struct for identity transformation on indices.
Definition: RelationArray.h:94

◆ getVREventStream()

std::ofstream * getVREventStream ( ) const
inline

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

Definition at line 68 of file EventAction.h.

68{ return m_VREventStream; }

Member Data Documentation

◆ m_evtMetaData

StoreObjPtr<EventMetaData> m_evtMetaData
private

Event metadata.

Definition at line 79 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 72 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 73 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 78 of file EventAction.h.

◆ m_writeSimSteps

bool m_writeSimSteps {false}
private

Flag for writing out the simulation steps.

Definition at line 77 of file EventAction.h.


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