Belle II Software  release-05-01-25
EventAction.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Guofu Cao, Andreas Moll, Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <simulation/kernel/EventAction.h>
12 #include <framework/datastore/RelationArray.h>
13 #include <mdst/dataobjects/MCParticleGraph.h>
14 #include <simulation/kernel/SensitiveDetectorBase.h>
15 
16 #include <string>
17 
18 using namespace std;
19 using namespace Belle2;
20 using namespace Belle2::Simulation;
21 
22 
23 EventAction::EventAction(const std::string& mcCollectionName, MCParticleGraph& mcParticleGraph):
24  G4UserEventAction(), m_mcCollectionName(mcCollectionName), m_mcParticleGraph(mcParticleGraph)
25 {
26  if (false) {
27  G4Event* event;
28  BeginOfEventAction(event);
29  EndOfEventAction(event);
30  }
31 }
32 
34 {
35 
36 }
37 
38 void EventAction::BeginOfEventAction(const G4Event*)
39 {
40  //Enable recording of Hits
42 }
43 
44 
45 void EventAction::EndOfEventAction(const G4Event*)
46 {
47  //Disable recording of Hits
49 
50  //Create the final MCParticle list and update the indices of the MCParticle graph particles.
52 
53  //Build a TrackID to MCParticle index list
54  vector<std::pair<unsigned int, bool> > indices;
55  indices.resize(m_mcParticleGraph.size() + 1);
56  for (unsigned int iParticle = 0; iParticle < m_mcParticleGraph.size(); ++iParticle) {
57  MCParticleGraph::GraphParticle& currParticle = m_mcParticleGraph[iParticle];
58  //assert(currParticle.getTrackID()<indices.size());
59  indices[currParticle.getTrackID()] = std::make_pair(currParticle.getIndex() - 1, currParticle.getIgnore());
60  }
61  RelationArray::ReplaceVec<> indexReplacement(indices);
62 
63  //Update all registered MCParticle Relations and replace the TrackID by the final MCParticle id
64  const std::map<std::string, RelationArray::EConsolidationAction>& relations = SensitiveDetectorBase::getMCParticleRelations();
65  for (std::map<std::string, RelationArray::EConsolidationAction>::const_iterator it = relations.begin(); it != relations.end();
66  ++it) {
67  RelationArray mcPartRelation(it->first);
68  if (mcPartRelation) mcPartRelation.consolidate(indexReplacement, RelationArray::Identity(), it->second);
69  }
70 }
Belle2::MCParticle::getIndex
int getIndex() const
Get 1-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:241
Belle2::MCParticleGraph::generateList
void generateList(const std::string &name="", int options=c_setNothing)
Generates the MCParticle list and stores it in the StoreArray with the given name.
Definition: MCParticleGraph.cc:211
Belle2::RelationArray
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:72
Belle2::MCParticleGraph::size
size_t size() const
Return the number of particles in the graph.
Definition: MCParticleGraph.h:253
Belle2::RelationArray::consolidate
void consolidate()
Consolidate Relation Elements.
Definition: RelationArray.h:341
Belle2::MCParticleGraph
Class to build, validate and sort a particle decay chain.
Definition: MCParticleGraph.h:48
Belle2::RelationArray::Identity
Struct for identity transformation on indices.
Definition: RelationArray.h:104
Belle2::Simulation::EventAction::BeginOfEventAction
void BeginOfEventAction(const G4Event *event)
This method is invoked before converting the primary particles to G4Track objects.
Definition: EventAction.cc:38
Belle2::Simulation::EventAction::m_mcCollectionName
std::string m_mcCollectionName
The name of the MCParticle collection to which the MCParticles should be written.
Definition: EventAction.h:66
Belle2::Simulation::EventAction::m_mcParticleGraph
MCParticleGraph & m_mcParticleGraph
Reference to the MCParticle graph which is converted to a MCParticle list by this class.
Definition: EventAction.h:67
Belle2::MCParticleGraph::GraphParticle::getTrackID
int getTrackID() const
Returns the track ID assigned to this MCParticle.
Definition: MCParticleGraph.h:165
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Simulation::EventAction::EndOfEventAction
void EndOfEventAction(const G4Event *event)
This method is invoked at the very end of event processing.
Definition: EventAction.cc:45
Belle2::RelationArray::ReplaceVec
Struct to replace indices based on a sequential container.
Definition: RelationArray.h:142
Belle2::MCParticleGraph::c_clearParticles
@ c_clearParticles
Clear the particle list before adding the graph.
Definition: MCParticleGraph.h:76
Belle2::Simulation::SensitiveDetectorBase::setActive
static void setActive(bool activeStatus)
Enable/Disable all Sensitive Detectors.
Definition: SensitiveDetectorBase.h:54
Belle2::Simulation::EventAction::~EventAction
virtual ~EventAction()
Destructor.
Definition: EventAction.cc:33
Belle2::Simulation::SensitiveDetectorBase::getMCParticleRelations
static const std::map< std::string, RelationArray::EConsolidationAction > & getMCParticleRelations()
Return a list of all registered Relations with MCParticles.
Definition: SensitiveDetectorBase.h:46
Belle2::MCParticleGraph::GraphParticle::getIgnore
bool getIgnore() const
Get the ignore flag.
Definition: MCParticleGraph.h:150
Belle2::MCParticleGraph::GraphParticle
Class to represent Particle data in graph.
Definition: MCParticleGraph.h:86