Belle II Software development
MdstPIDModule.h
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#pragma once
10
11#include <framework/core/Module.h>
12#include <framework/datastore/StoreArray.h>
13#include <framework/logging/Logger.h>
14#include <framework/gearbox/Const.h>
15
16#include <mdst/dataobjects/Track.h>
17#include <mdst/dataobjects/PIDLikelihood.h>
18
19#include <top/dataobjects/TOPLikelihood.h>
20#include <arich/dataobjects/ARICHLikelihood.h>
21#include <reconstruction/dataobjects/CDCDedxLikelihood.h>
22#include <reconstruction/dataobjects/VXDDedxLikelihood.h>
23#include <ecl/dataobjects/ECLPidLikelihood.h>
24#include <klm/dataobjects/KLMMuidLikelihood.h>
25
26#include <string>
27#include <cmath>
28#include <map>
29
30namespace Belle2 {
40 class MdstPIDModule : public Module {
41 public:
42
43
48
53 virtual void initialize() override;
54
59 virtual void event() override;
60
61 private:
62
67 void setLikelihoods(const TOPLikelihood* logl);
68
73 void setLikelihoods(const ARICHLikelihood* logl);
74
79 void setLikelihoods(const CDCDedxLikelihood* logl);
80
85 void setLikelihoods(const VXDDedxLikelihood* logl);
86
91 void setLikelihoods(const ECLPidLikelihood* logl);
92
97 void setLikelihoods(const KLMMuidLikelihood* muid);
98
105 template<class T>
106 float getLogL(const T* logl, const Const::ChargedStable& chargedStable) const
107 {
108 return logl->getLogL(chargedStable);
109 }
110
117 float getLogL(const ECLPidLikelihood* logl, const Const::ChargedStable& chargedStable) const
118 {
119 return logl->getLogLikelihood(chargedStable);
120 }
121
128 float getLogL(const KLMMuidLikelihood* logl, const Const::ChargedStable& chargedStable) const
129 {
130 return logl->getLogL(chargedStable.getPDGCode());
131 }
132
138 template<class T>
139 bool areLikelihoodsValid(const T* logl)
140 {
141 std::vector<float> values;
142 for (const auto& chargedStable : Const::chargedStableSet) {
143 auto value = getLogL(logl, chargedStable);
144 values.push_back(value);
145 if (std::isnan(value) or value == INFINITY) {
146 B2ERROR("MdstPID::setLikelihoods: invalid " << logl->ClassName() << " for " << m_chargedNames[chargedStable]
147 << ", is " << value
148 << ". Likelihoods ignored.");
149 return false;
150 }
151 }
152 // check if log likelihoods differ
153 for (auto value : values) {
154 if (value != values.back()) return true; // values differ
155 }
156 return false; // values are all the same - ignore Likelihoods
157 }
158
159 // module parameters
162 // input collections
171 // output collection
174 // other
176 std::map<Const::ChargedStable, std::string> m_chargedNames;
178 };
179
181} // Belle2 namespace
182
183
184
185
This is a class to store ARICH likelihoods in the datastore.
Container for likelihoods obtained by the CDC dE/dx PID (CDCDedxPIDModule).
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:589
int getPDGCode() const
PDG code.
Definition: Const.h:473
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:618
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.
double getLogL(int pdg) const
Get the log-likelihood.
a module to fill PIDLikelihoods
Definition: MdstPIDModule.h:40
StoreArray< KLMMuidLikelihood > m_muid
Optional collection of KLMMuidLikelihood.
bool areLikelihoodsValid(const T *logl)
Check for validity of log likelihood values (NaN and +Inf are not allowed).
float getLogL(const ECLPidLikelihood *logl, const Const::ChargedStable &chargedStable) const
Get log likelihood for a given particle (ECL specialization)
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.
float getLogL(const T *logl, const Const::ChargedStable &chargedStable) const
Get log likelihood for a given particle.
StoreArray< PIDLikelihood > m_pidLikelihoods
collection of PIDLikelihoods
float getLogL(const KLMMuidLikelihood *logl, const Const::ChargedStable &chargedStable) const
Get log likelihood for a given particle (KLM specialization)
Base class for Modules.
Definition: Module.h:72
Class to collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes...
Definition: PIDLikelihood.h:29
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Class to store TOP log likelihoods (output of TOPReconstructor).
Definition: TOPLikelihood.h:26
Container for likelihoods obtained by the VXD dE/dx PID (VXDDedxPIDModule).
Abstract base class for different kinds of events.