Belle II Software  release-05-01-25
MCV0MatcherModule.cc
1 #include <tracking/modules/mcMatcher/MCV0MatcherModule.h>
2 
3 #include <framework/datastore/StoreArray.h>
4 #include <framework/gearbox/Const.h>
5 #include <framework/gearbox/Unit.h>
6 #include <framework/logging/Logger.h>
7 #include <mdst/dataobjects/TrackFitResult.h>
8 #include <mdst/dataobjects/MCParticle.h>
9 #include <mdst/dataobjects/V0.h>
10 
11 using namespace Belle2;
12 
13 REG_MODULE(MCV0Matcher);
14 
16 {
17  setDescription("A module matching the V0s found by the V0Finder with MCParticles");
19 
20  //input
21  addParam("TrackColName", m_TrackColName,
22  "Belle2::Track collection name (input). Note that the V0s use "
23  "pointers indices into these arrays, so all hell may break loose "
24  "if you change this.", std::string(""));
25  addParam("TFRColName", m_TFRColName,
26  "Belle2::TrackFitResult collection name (input). Note that the V0s "
27  "use pointers indices into these arrays, so all hell may break loose "
28  "if you change this.", std::string(""));
29  addParam("V0ColName", m_V0ColName, "V0 collection name (input)", std::string(""));
30  addParam("MCParticleColName", m_MCParticleColName, "MCParticle collection name (input)", std::string(""));
31 }
32 
33 
35 {
36 }
37 
38 
40 {
42  tracks.isRequired();
43 
45  trackFitResults.isRequired();
46 
48  v0s.isRequired();
49 
51  mcParticles.isRequired();
52  v0s.registerRelationTo(mcParticles);
53  B2WARNING("This module is supposed to be used only for the debugging\n \
54  of the V0Finder module, not as MC matching during analysis.");
55 }
56 
57 
59 {
60 }
61 
63 {
65  B2DEBUG(200, (v0s.getEntries() != 0 ? "V0s has entries." : " No V0s."));
66 
67  for (const auto& v0 : v0s) {
68  // Try to match the tracks of each V0 with the MC V0.
69  const Const::ParticleType v0hypothesis = v0.getV0Hypothesis();
70  const std::pair<Track*, Track*> trackPtrs = v0.getTracks();
71 
72  const MCParticle* mcV0PartPlus = trackPtrs.first->getRelatedTo<MCParticle>(m_MCParticleColName);
73  const MCParticle* mcV0PartMinus = trackPtrs.second->getRelatedTo<MCParticle>(m_MCParticleColName);
74 
75  if (mcV0PartPlus == nullptr or mcV0PartMinus == nullptr) {
76  B2DEBUG(200, "At least one track of the V0 does not have a MC related particle. It will be skipped for matching.");
77  continue;
78  }
79 
80  const MCParticle* mcV0PartPlusMother = mcV0PartPlus->getMother();
81  const MCParticle* mcV0PartMinusMother = mcV0PartMinus->getMother();
82 
83  if (!mcV0PartPlus->getMother() or !mcV0PartMinusMother) {
84  B2DEBUG(200, "At least one track of the V0 does not have a mother MCParticle, skipping.");
85  continue;
86  }
87 
88  if (mcV0PartPlusMother != mcV0PartMinusMother) {
89  B2DEBUG(200, "The V0 is most likely built up from combinatoric background, thus no MC relation can be set.");
90  continue;
91  }
92 
93  if (Const::ParticleType(mcV0PartPlusMother->getPDG()) == v0hypothesis) {
94  B2DEBUG(200, "V0 successfully matched.");
95  v0.addRelationTo(mcV0PartPlusMother);
96  } else {
97  B2DEBUG(200, "V0 did not match anything.");
98  }
99  }
100 
101  B2DEBUG(200, "MC matching finished.");
102 }
103 
105 {
106 }
107 
109 {
110 }
Belle2::MCV0MatcherModule::beginRun
void beginRun() override
Called once before a new run begins.
Definition: MCV0MatcherModule.cc:58
Belle2::StoreArray::registerRelationTo
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition: StoreArray.h:150
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module::c_ParallelProcessingCertified
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:82
Belle2::MCV0MatcherModule::MCV0MatcherModule
MCV0MatcherModule()
Constructor, for setting module description and parameters.
Definition: MCV0MatcherModule.cc:15
Belle2::MCV0MatcherModule::m_TFRColName
std::string m_TFRColName
Belle2::TrackFitResult collection name (input).
Definition: MCV0MatcherModule.h:56
Belle2::MCV0MatcherModule::initialize
void initialize() override
Use this to initialize resources or memory your module needs.
Definition: MCV0MatcherModule.cc:39
Belle2::RelationsInterface::getRelatedTo
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
Definition: RelationsObject.h:250
Belle2::MCV0MatcherModule::m_V0ColName
std::string m_V0ColName
V0 collection name (input).
Definition: MCV0MatcherModule.h:57
Belle2::MCV0MatcherModule::terminate
void terminate() override
Clean up anything you created in initialize().
Definition: MCV0MatcherModule.cc:108
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::Module::setPropertyFlags
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:210
Belle2::MCV0MatcherModule::endRun
void endRun() override
Called once when a run ends.
Definition: MCV0MatcherModule.cc:104
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MCParticle::getPDG
int getPDG() const
Return PDG code of particle.
Definition: MCParticle.h:123
Belle2::MCParticle::getMother
MCParticle * getMother() const
Returns a pointer to the mother particle.
Definition: MCParticle.h:593
Belle2::Module::addParam
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:562
Belle2::Const::ParticleType
The ParticleType class for identifying different particle types.
Definition: Const.h:284
Belle2::MCV0MatcherModule::event
void event() override
Called once for each event.
Definition: MCV0MatcherModule.cc:62
Belle2::MCV0MatcherModule::m_TrackColName
std::string m_TrackColName
Belle2::Track collection name (input).
Definition: MCV0MatcherModule.h:55
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::MCV0MatcherModule::~MCV0MatcherModule
~MCV0MatcherModule()
Destructor (empty).
Definition: MCV0MatcherModule.cc:34
Belle2::MCV0MatcherModule::m_MCParticleColName
std::string m_MCParticleColName
MCParticle collection name (input).
Definition: MCV0MatcherModule.h:58
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226