Belle II Software  release-08-01-10
EventAction.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <simulation/kernel/EventAction.h>
10 #include <framework/datastore/RelationArray.h>
11 #include <mdst/dataobjects/MCParticleGraph.h>
12 #include <simulation/kernel/SensitiveDetectorBase.h>
13 
14 #include <string>
15 
16 using namespace std;
17 using namespace Belle2;
18 using namespace Belle2::Simulation;
19 
20 
21 EventAction::EventAction(const std::string& mcCollectionName, MCParticleGraph& mcParticleGraph):
22  G4UserEventAction(), m_mcCollectionName(mcCollectionName), m_mcParticleGraph(mcParticleGraph)
23 {
24  if (false) {
25  G4Event* event;
26  BeginOfEventAction(event);
27  EndOfEventAction(event);
28  }
29 }
30 
32 {
33 
34 }
35 
36 void EventAction::BeginOfEventAction(const G4Event*)
37 {
38  //Enable recording of Hits
40 }
41 
42 
43 void EventAction::EndOfEventAction(const G4Event*)
44 {
45  //Disable recording of Hits
47 
48  //Create the final MCParticle list and update the indices of the MCParticle graph particles.
50 
51  //Build a TrackID to MCParticle index list
52  vector<std::pair<unsigned int, bool> > indices;
53  indices.resize(m_mcParticleGraph.size() + 1);
54  for (unsigned int iParticle = 0; iParticle < m_mcParticleGraph.size(); ++iParticle) {
55  MCParticleGraph::GraphParticle& currParticle = m_mcParticleGraph[iParticle];
56  //assert(currParticle.getTrackID()<indices.size());
57  indices[currParticle.getTrackID()] = std::make_pair(currParticle.getIndex() - 1, currParticle.getIgnore());
58  }
59  RelationArray::ReplaceVec<> indexReplacement(indices);
60 
61  //Update all registered MCParticle Relations and replace the TrackID by the final MCParticle id
62  const std::map<std::string, RelationArray::EConsolidationAction>& relations = SensitiveDetectorBase::getMCParticleRelations();
63  for (std::map<std::string, RelationArray::EConsolidationAction>::const_iterator it = relations.begin(); it != relations.end();
64  ++it) {
65  RelationArray mcPartRelation(it->first);
66  if (mcPartRelation) mcPartRelation.consolidate(indexReplacement, RelationArray::Identity(), it->second);
67  }
68 }
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.
Class to build, validate and sort a particle decay chain.
@ 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
void consolidate()
Consolidate Relation Elements.
std::string m_mcCollectionName
The name of the MCParticle collection to which the MCParticles should be written.
Definition: EventAction.h:64
MCParticleGraph & m_mcParticleGraph
Reference to the MCParticle graph which is converted to a MCParticle list by this class.
Definition: EventAction.h:65
virtual ~EventAction()
Destructor.
Definition: EventAction.cc:31
void EndOfEventAction(const G4Event *event)
This method is invoked at the very end of event processing.
Definition: EventAction.cc:43
void BeginOfEventAction(const G4Event *event)
This method is invoked before converting the primary particles to G4Track objects.
Definition: EventAction.cc:36
static void setActive(bool activeStatus)
Enable/Disable all Sensitive Detectors.
static const std::map< std::string, RelationArray::EConsolidationAction > & getMCParticleRelations()
Return a list of all registered Relations with MCParticles.
Abstract base class for different kinds of events.
Struct for identity transformation on indices.
Definition: RelationArray.h:94