Belle II Software prerelease-11-00-00a
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#include <reconstruction/modules/MdstPID/MdstPIDModule.h>
10#include <klm/muid/MuidElementNumbers.h>
11#include <mdst/dataobjects/Track.h>
12#include <mdst/dataobjects/PIDLikelihood.h>
13#include <top/dataobjects/TOPLikelihood.h>
14#include <arich/dataobjects/ARICHLikelihood.h>
15#include <cdc/dataobjects/CDCDedxLikelihood.h>
16#include <cdc/dataobjects/CDCDedxTrack.h>
17#include <reconstruction/dataobjects/VXDDedxLikelihood.h>
18
19using namespace std;
20using namespace Belle2;
21
22REG_MODULE(MdstPID);
23
25 m_pid(nullptr)
26{
27 setDescription("Create MDST PID format (PIDLikelihood objects) from subdetector PID info.");
29
30 m_chargedNames[Const::electron] = "electron";
34 m_chargedNames[Const::proton] = "proton";
35 m_chargedNames[Const::deuteron] = "deuteron";
36
37 addParam("subtractMaximum", m_subtractMaximum,
38 "if set to True, subtract the maximum of log likelihoods to reduce the range of values", false);
39}
40
41
43{
44 // data store registration
45
46 // required input
47 m_tracks.isRequired();
48 m_pidLikelihoods.registerInDataStore();
49 m_tracks.registerRelationTo(m_pidLikelihoods);
50
51 // optional input
52 m_topLikelihoods.isOptional();
53 m_arichLikelihoods.isOptional();
54 m_cdcDedxLikelihoods.isOptional();
55 m_vxdDedxLikelihoods.isOptional();
56 m_eclLikelihoods.isOptional();
57 m_muid.isOptional();
58}
59
60
62{
63 // loop over reconstructed tracks and collect likelihoods
64 for (int itra = 0; itra < m_tracks.getEntries(); ++itra) {
65
66 // reconstructed track
67 const Track* track = m_tracks[itra];
68
69 // append new and set relation
70 m_pid = m_pidLikelihoods.appendNew();
71 track->addRelationTo(m_pid);
72
73 // set top likelihoods
74 const TOPLikelihood* top = track->getRelated<TOPLikelihood>();
75 if (top) setLikelihoods(top);
76
77 // set arich likelihoods
78 const ARICHLikelihood* arich = track->getRelated<ARICHLikelihood>();
79 if (arich) setLikelihoods(arich);
80
81 // set CDC dE/dx likelihoods
82 const CDCDedxLikelihood* cdcdedx = track->getRelatedTo<CDCDedxLikelihood>();
83 if (cdcdedx) setLikelihoods(cdcdedx);
84 // and the number of layers with measurements used in the CDC likelihood
85 const CDCDedxTrack* cdcdedxtrack = track->getRelatedTo<CDCDedxTrack>();
86 if (cdcdedxtrack) m_CDCnLayerHitsUsed = cdcdedxtrack->getNLayerHitsUsed();
87
88 // set VXD dE/dx likelihoods
89 const VXDDedxLikelihood* vxddedx = track->getRelatedTo<VXDDedxLikelihood>();
90 if (vxddedx) setLikelihoods(vxddedx);
91
92 // set ecl likelihoods
93 const ECLPidLikelihood* ecl = track->getRelatedTo<ECLPidLikelihood>();
94 if (ecl) setLikelihoods(ecl);
95
96 // set klm likelihoods
97 const KLMMuidLikelihood* muid = track->getRelatedTo<KLMMuidLikelihood>();
98 if (muid) setLikelihoods(muid);
99
100 if (m_subtractMaximum) m_pid->subtractMaximum();
101 }
102
103}
104
105
107{
108 if (logl->getFlag() != 1) return;
109 if (not areLikelihoodsValid(logl)) return;
110
111 for (const auto& chargedStable : Const::chargedStableSet) {
112 m_pid->setLogLikelihood(Const::TOP, chargedStable, logl->getLogL(chargedStable));
113 }
114
115}
116
117
119{
120 if (logl->getFlag() != 1) return;
121 if (not areLikelihoodsValid(logl)) return;
122
123 for (const auto& chargedStable : Const::chargedStableSet) {
124 m_pid->setLogLikelihood(Const::ARICH, chargedStable, logl->getLogL(chargedStable));
125 }
126
127}
128
129
131{
132 if (not areLikelihoodsValid(logl)) return;
133
134 for (const auto& chargedStable : Const::chargedStableSet) {
135 m_pid->setLogLikelihood(Const::CDC, chargedStable, logl->getLogL(chargedStable));
136 m_pid->setCDCnLayerHitsUsed(m_CDCnLayerHitsUsed);
137 }
138
139}
140
141
143{
144 if (not areLikelihoodsValid(logl)) return;
145
146 for (const auto& chargedStable : Const::chargedStableSet) {
147 m_pid->setLogLikelihood(Const::SVD, chargedStable, logl->getLogL(chargedStable));
148 }
149
150}
151
152
154{
155 if (not areLikelihoodsValid(logl)) return;
156
157 for (const auto& chargedStable : Const::chargedStableSet) {
158 m_pid->setLogLikelihood(Const::ECL, chargedStable, logl->getLogLikelihood(chargedStable));
159 }
160
161}
162
163
165{
166 if (abs(muid->getPDGCode()) != abs(Const::muon.getPDGCode())) {
167 B2WARNING("MdstPID, KLMMuidLikelihood: extrapolation with other than muon hypothesis ignored");
168 return;
169 }
170
171 if (muid->getOutcome() == MuidElementNumbers::c_NotReached)
172 return; // track extrapolation didn't reach KLM
173
174 if (muid->getJunkPDFValue())
175 return; // unclassifiable track (all likelihoods were zero), extremely rare
176
177 if (not areLikelihoodsValid(muid)) return;
178
179 for (const auto& chargedStable : Const::chargedStableSet) {
180 m_pid->setLogLikelihood(Const::KLM, chargedStable, muid->getLogL(chargedStable.getPDGCode()));
181 }
182}
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.
Debug output for CDCDedxPID module.
double getNLayerHitsUsed() const
Return the number of hits used to determine the truncated mean.
static const ChargedStable muon
muon particle
Definition Const.h:660
static const ParticleSet chargedStableSet
set of charged stable particles
Definition Const.h:618
static const ChargedStable pion
charged pion particle
Definition Const.h:661
static const ChargedStable proton
proton particle
Definition Const.h:663
static const ChargedStable kaon
charged kaon particle
Definition Const.h:662
static const ChargedStable electron
electron particle
Definition Const.h:659
static const ChargedStable deuteron
deuteron particle
Definition Const.h:664
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 information related to the extrapolation.
StoreArray< KLMMuidLikelihood > m_muid
Optional collection of KLMMuidLikelihood.
int m_CDCnLayerHitsUsed
number of layers with measurements used in the CDC likelihood
bool areLikelihoodsValid(const T *logl)
Check for validity of log likelihood values (NaN and +Inf are not allowed).
StoreArray< VXDDedxLikelihood > m_vxdDedxLikelihoods
Optional collection of VXDDedxLikelihoods.
bool m_subtractMaximum
if true subtract the maximum of log likelihoods
virtual void initialize() override
Initialize the module.
virtual void event() override
Called for each event.
StoreArray< TOPLikelihood > m_topLikelihoods
Optional collection of TOPLikelihoods.
MdstPIDModule()
Constructor.
StoreArray< ECLPidLikelihood > m_eclLikelihoods
Optional collection of ECLPidLikelihoods.
PIDLikelihood * m_pid
pointer to the object to be filled
std::map< Const::ChargedStable, std::string > m_chargedNames
names of charged particles (used in error messages)
StoreArray< Track > m_tracks
Required collection of Tracks.
StoreArray< ARICHLikelihood > m_arichLikelihoods
Optional collection of ARICHLikelihoods.
void setLikelihoods(const TOPLikelihood *logl)
Set TOP log likelihoods and corresponding reconstruction flag.
StoreArray< CDCDedxLikelihood > m_cdcDedxLikelihoods
Optional collection of CDCDedxLikelihoods.
StoreArray< PIDLikelihood > m_pidLikelihoods
collection of PIDLikelihoods
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
Module()
Constructor.
Definition Module.cc:30
@ 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
Class to store TOP log likelihoods (output of TOPReconstructor).
int getFlag() const
Return reconstruction flag.
float getLogL(const Const::ChargedStable &part) const
Return log likelihood for a given particle.
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...
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
Abstract base class for different kinds of events.
STL namespace.