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