Belle II Software  release-06-01-15
MdstPIDModule.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 /* Own header. */
10 #include <reconstruction/modules/MdstPID/MdstPIDModule.h>
11 
12 /* Belle2 headers. */
13 #include <framework/gearbox/Const.h>
14 #include <framework/logging/Logger.h>
15 #include <klm/muid/MuidElementNumbers.h>
16 
17 /* C++ headers. */
18 #include <string>
19 
20 using namespace std;
21 
22 namespace Belle2 {
28  REG_MODULE(MdstPID)
29 
31  m_pid(nullptr)
32  {
33  setDescription("Create MDST PID format (PIDLikelihood objects) from subdetector PID info.");
34  setPropertyFlags(c_ParallelProcessingCertified);
35  }
36 
37  MdstPIDModule::~MdstPIDModule()
38  {
39  }
40 
41  void MdstPIDModule::initialize()
42  {
43  // data store registration
44 
45  // required input
46  m_tracks.isRequired();
47  m_pidLikelihoods.registerInDataStore();
48  m_tracks.registerRelationTo(m_pidLikelihoods);
49 
50  // optional input
51  m_topLikelihoods.isOptional();
52  m_arichLikelihoods.isOptional();
53  m_cdcDedxLikelihoods.isOptional();
54  m_vxdDedxLikelihoods.isOptional();
55  m_eclLikelihoods.isOptional();
56  m_muid.isOptional();
57  }
58 
59 
60  void MdstPIDModule::beginRun()
61  {
62  }
63 
64  void MdstPIDModule::endRun()
65  {
66  }
67 
68  void MdstPIDModule::terminate()
69  {
70  }
71 
72  void MdstPIDModule::event()
73  {
74  // loop over reconstructed tracks and collect likelihoods
75  for (int itra = 0; itra < m_tracks.getEntries(); ++itra) {
76 
77  // reconstructed track
78  const Track* track = m_tracks[itra];
79 
80  // append new and set relation
81  m_pid = m_pidLikelihoods.appendNew();
82  track->addRelationTo(m_pid);
83 
84  // set top likelihoods
85  const TOPLikelihood* top = track->getRelated<TOPLikelihood>();
86  if (top) setLikelihoods(top);
87 
88  // set arich likelihoods
89  const ARICHLikelihood* arich = track->getRelated<ARICHLikelihood>();
90  if (arich) setLikelihoods(arich);
91 
92  // set CDC dE/dx likelihoods
93  const CDCDedxLikelihood* cdcdedx = track->getRelatedTo<CDCDedxLikelihood>();
94  if (cdcdedx) setLikelihoods(cdcdedx);
95 
96  // set VXD dE/dx likelihoods
97  const VXDDedxLikelihood* vxddedx = track->getRelatedTo<VXDDedxLikelihood>();
98  if (vxddedx) setLikelihoods(vxddedx);
99 
100  // set ecl likelihoods
101  const ECLPidLikelihood* ecl = track->getRelatedTo<ECLPidLikelihood>();
102  if (ecl) setLikelihoods(ecl);
103 
104  // set klm likelihoods
105  const KLMMuidLikelihood* muid = track->getRelatedTo<KLMMuidLikelihood>();
106  if (muid) setLikelihoods(muid);
107 
108  }
109 
110  }
111 
112 
113  void MdstPIDModule::setLikelihoods(const TOPLikelihood* logl)
114  {
115  if (logl->getFlag() != 1) return;
116 
117  for (const auto& chargedStable : Const::chargedStableSet) {
118  m_pid->setLogLikelihood(Const::TOP, chargedStable, logl->getLogL(chargedStable));
119  }
120 
121  }
122 
123 
124  void MdstPIDModule::setLikelihoods(const ARICHLikelihood* logl)
125  {
126  if (logl->getFlag() != 1) return;
127 
128  for (const auto& chargedStable : Const::chargedStableSet) {
129  m_pid->setLogLikelihood(Const::ARICH, chargedStable, logl->getLogL(chargedStable));
130  }
131 
132  }
133 
134 
135  void MdstPIDModule::setLikelihoods(const CDCDedxLikelihood* logl)
136  {
137 
138  for (const auto& chargedStable : Const::chargedStableSet) {
139  m_pid->setLogLikelihood(Const::CDC, chargedStable, logl->getLogL(chargedStable));
140  }
141 
142  }
143 
144 
145  void MdstPIDModule::setLikelihoods(const VXDDedxLikelihood* logl)
146  {
147 
148  for (const auto& chargedStable : Const::chargedStableSet) {
149  m_pid->setLogLikelihood(Const::SVD, chargedStable, logl->getLogL(chargedStable));
150  }
151 
152  }
153 
154 
155  void MdstPIDModule::setLikelihoods(const ECLPidLikelihood* logl)
156  {
157 
158  for (const auto& chargedStable : Const::chargedStableSet) {
159  m_pid->setLogLikelihood(Const::ECL, chargedStable, logl->getLogLikelihood(chargedStable));
160  }
161 
162  }
163 
164 
165  void MdstPIDModule::setLikelihoods(const KLMMuidLikelihood* muid)
166  {
167  if (abs(muid->getPDGCode()) != abs(Const::muon.getPDGCode())) {
168  B2WARNING("MdstPID, KLMMuidLikelihood: extrapolation with other than muon hypothesis ignored");
169  return;
170  }
171 
172  if (muid->getOutcome() == MuidElementNumbers::c_NotReached)
173  return; // track extrapolation didn't reach KLM
174 
175  if (muid->getJunkPDFValue())
176  return; // unclassifiable track (all likelihoods were zero), extremely rare
177 
178  for (const auto& chargedStable : Const::chargedStableSet) {
179  m_pid->setLogLikelihood(Const::KLM, chargedStable, muid->getLogL(chargedStable.getPDGCode()));
180  }
181  }
182 
183 
185 } // Belle2 namespace
186 
This is a class to store ARICH likelihoods in the datastore.
int getFlag() const
Get reconstruction flag.
float getLogL(const Const::ChargedStable &part) const
Return log likelihood for a given particle.
Container for likelihoods obtained by the CDC dE/dx PID (CDCDedxPIDModule).
double getLogL(const Const::ChargedStable &type) const
returns unnormalised log-likelihood value for a particle hypothesis using CDC information.
Container for likelihoods with ECL PID (ECLChargedPIDModule)
float getLogLikelihood(const Const::ChargedStable &type) const
returns log-likelihood value for a particle hypothesis.
Class to store the likelihoods from KLM with additional informations related to the extrapolation.
a module to fill PIDLikelihoods
Definition: MdstPIDModule.h:37
Base class for Modules.
Definition: Module.h:72
Class to store TOP log likelihoods (output of TOPReconstructor).
Definition: TOPLikelihood.h:26
int getFlag() const
Return reconstruction flag.
Definition: TOPLikelihood.h:63
float getLogL(const Const::ChargedStable &part) const
Return log likelihood for a given particle.
Definition: TOPLikelihood.h:76
Class that bundles various TrackFitResults.
Definition: Track.h:25
Container for likelihoods obtained by the VXD dE/dx PID (VXDDedxPIDModule).
double getLogL(const Const::ChargedStable &type) const
returns unnormalised log-likelihood value for a particle hypothesis using SVD (and/or PXD) informatio...
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.