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