Belle II Software light-2406-ragdoll
PIDLikelihood Class Reference

Class to collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes functions to return combined likelihood probability. More...

#include <PIDLikelihood.h>

Inheritance diagram for PIDLikelihood:
Collaboration diagram for PIDLikelihood:

Public Member Functions

 PIDLikelihood ()
 Default constructor: log likelihoods and flags set to 0.
 
void setLogLikelihood (Const::EDetector det, const Const::ChargedStable &part, float logl)
 Set log likelihood for a given detector and particle.
 
void subtractMaximum ()
 Subtract the maximum of log likelihoods of each detector component in order to reduce the range of values.
 
bool isAvailable (Const::PIDDetectorSet set=Const::PIDDetectorSet::set()) const
 Check whether PID information is available for at least one of the detectors in a given set.
 
bool areAllAvailable (Const::PIDDetectorSet set=Const::PIDDetectorSet::set()) const
 Check whether PID information is available for all detectors in a given set.
 
float getLogL (const Const::ChargedStable &part, Const::PIDDetectorSet set=Const::PIDDetectorSet::set()) const
 Return log likelihood for a given detector set and particle.
 
float getDeltaLogL (const Const::ChargedStable &p1, const Const::ChargedStable &p2, Const::PIDDetectorSet set=Const::PIDDetectorSet::set()) const
 Return log likelihood difference between two particles for a given detector set.
 
double getProbability (const Const::ChargedStable &p1, const Const::ChargedStable &p2, Const::PIDDetectorSet set=Const::PIDDetectorSet::set()) const
 Return combined likelihood probability for a particle being p1 and not p2, assuming equal prior probabilities.
 
double getProbability (const Const::ChargedStable &p1, const Const::ChargedStable &p2, double ratio, Const::PIDDetectorSet set=Const::PIDDetectorSet::set()) const
 Return combined likelihood probability for a particle being p1 and not p2.
 
double getProbability (const Const::ChargedStable &part, const double *fractions=nullptr, Const::PIDDetectorSet set=Const::PIDDetectorSet::set()) const
 Return combined likelihood probability for a particle according to chargedStableSet; if prior fractions not given equal prior probabilities assumed.
 
double getLogarithmicProbability (const Const::ChargedStable &part, const double *fractions=nullptr, Const::PIDDetectorSet set=Const::PIDDetectorSet::set()) const
 Return logarithmic equivalent of likelihood probability defined as log(p/(1-p)), where p is the combined likelihood probability of a particle according to chargedStableSet.
 
Const::ChargedStable getMostLikely (const double *fractions=nullptr, Const::PIDDetectorSet set=Const::PIDDetectorSet::set()) const
 Return most likely particle among chargedStableSet; if prior fractions not given equal prior probabilities assumed.
 
void printArray () const
 Prints the content of a private array of log likelihoods.
 
std::string getInfoHTML () const override
 Return HTML Info of PID Likelihoods.
 
void addPreOfficialLikelihood (const std::string &preOfficialIdentifier, const double preOfficialLikelihood)
 Add the pre-official likelihood.
 
double getPreOfficialLikelihood (const std::string &preOfficialIdentifier) const
 Get the pre-official likelihood.
 
void addRelationTo (const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
 Add a relation from this object to another object (with caching).
 
void addRelationTo (const TObject *object, float weight=1.0, const std::string &namedRelation="") const
 Add a relation from this object to another object (no caching, can be quite slow).
 
void copyRelations (const RelationsInterface< BASE > *sourceObj)
 Copies all relations of sourceObj (pointing from or to sourceObj) to this object (including weights).
 
template<class TO >
RelationVector< TO > getRelationsTo (const std::string &name="", const std::string &namedRelation="") const
 Get the relations that point from this object to another store array.
 
template<class FROM >
RelationVector< FROM > getRelationsFrom (const std::string &name="", const std::string &namedRelation="") const
 Get the relations that point from another store array to this object.
 
template<class T >
RelationVector< T > getRelationsWith (const std::string &name="", const std::string &namedRelation="") const
 Get the relations between this object and another store array.
 
template<class TO >
TO * getRelatedTo (const std::string &name="", const std::string &namedRelation="") const
 Get the object to which this object has a relation.
 
template<class FROM >
FROM * getRelatedFrom (const std::string &name="", const std::string &namedRelation="") const
 Get the object from which this object has a relation.
 
template<class T >
T * getRelated (const std::string &name="", const std::string &namedRelation="") const
 Get the object to or from which this object has a relation.
 
template<class TO >
std::pair< TO *, float > getRelatedToWithWeight (const std::string &name="", const std::string &namedRelation="") const
 Get first related object & weight of relation pointing to an array.
 
template<class FROM >
std::pair< FROM *, float > getRelatedFromWithWeight (const std::string &name="", const std::string &namedRelation="") const
 Get first related object & weight of relation pointing from an array.
 
template<class T >
std::pair< T *, float > getRelatedWithWeight (const std::string &name="", const std::string &namedRelation="") const
 Get first related object & weight of relation pointing from/to an array.
 
virtual std::string getName () const
 Return a short name that describes this object, e.g.
 
std::string getInfo () const
 Return a short summary of this object's contents in raw text format.
 
std::string getArrayName () const
 Get name of array this object is stored in, or "" if not found.
 
int getArrayIndex () const
 Returns this object's array index (in StoreArray), or -1 if not found.
 

Protected Member Functions

TClonesArray * getArrayPointer () const
 Returns the pointer to the raw DataStore array holding this object (protected since these arrays are easy to misuse).
 

Private Member Functions

void probability (double probabilities[], const double *fractions, Const::PIDDetectorSet detSet) const
 Calculate likelihood probabilities.
 
 ClassDefOverride (PIDLikelihood, 4)
 Collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM.
 
 ClassDef (RelationsInterface, 0)
 defines interface for accessing relations of objects in StoreArray.
 

Private Attributes

Const::DetectorSet m_detectors
 set of detectors with PID information
 
float m_logl [Const::PIDDetectors::c_size][Const::ChargedStable::c_SetSize]
 log likelihoods
 
std::map< std::string, double > m_preOfficialLikelihoods
 Internal storage of pre-official likelihood.
 
DataStore::StoreEntrym_cacheDataStoreEntry
 Cache of the data store entry to which this object belongs.
 
int m_cacheArrayIndex
 Cache of the index in the TClonesArray to which this object belongs.
 

Detailed Description

Class to collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes functions to return combined likelihood probability.

Definition at line 29 of file PIDLikelihood.h.

Constructor & Destructor Documentation

◆ PIDLikelihood()

Default constructor: log likelihoods and flags set to 0.

Definition at line 25 of file PIDLikelihood.cc.

26{
27 for (unsigned short i = 0; i < Const::PIDDetectors::c_size; i++) {
28 for (unsigned int k = 0; k < Const::ChargedStable::c_SetSize; k++) {
29 m_logl[i][k] = 0.0;
30 }
31 }
32}
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
Definition: Const.h:615
static const size_t c_size
Number of PID detectors, temporary workaround.
Definition: Const.h:376
float m_logl[Const::PIDDetectors::c_size][Const::ChargedStable::c_SetSize]
log likelihoods

Member Function Documentation

◆ addPreOfficialLikelihood()

void addPreOfficialLikelihood ( const std::string &  preOfficialIdentifier,
const double  preOfficialLikelihood 
)

Add the pre-official likelihood.

Parameters
preOfficialIdentifierName of the pre-official likelihood
preOfficialLikelihoodValue of the pre-official likelihood

Definition at line 329 of file PIDLikelihood.cc.

330{
331 m_preOfficialLikelihoods[preOfficialIdentifier] = preOfficialLikelihood;
332}
std::map< std::string, double > m_preOfficialLikelihoods
Internal storage of pre-official likelihood.

◆ addRelationTo() [1/2]

void addRelationTo ( const RelationsInterface< BASE > *  object,
float  weight = 1.0,
const std::string &  namedRelation = "" 
) const
inlineinherited

Add a relation from this object to another object (with caching).

Parameters
objectThe object to which the relation should point.
weightThe weight of the relation.
namedRelationAdditional name for the relation, or "" for the default naming

Definition at line 142 of file RelationsObject.h.

143 {
144 if (object)
146 object, object->m_cacheDataStoreEntry, object->m_cacheArrayIndex, weight, namedRelation);
147 }
void addRelation(const TObject *fromObject, StoreEntry *&fromEntry, int &fromIndex, const TObject *toObject, StoreEntry *&toEntry, int &toIndex, float weight, const std::string &namedRelation)
Add a relation from an object in a store array to another object in a store array.
Definition: DataStore.cc:492
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
DataStore::StoreEntry * m_cacheDataStoreEntry
Cache of the data store entry to which this object belongs.
int m_cacheArrayIndex
Cache of the index in the TClonesArray to which this object belongs.

◆ addRelationTo() [2/2]

void addRelationTo ( const TObject *  object,
float  weight = 1.0,
const std::string &  namedRelation = "" 
) const
inlineinherited

Add a relation from this object to another object (no caching, can be quite slow).

Parameters
objectThe object to which the relation should point.
weightThe weight of the relation.
namedRelationAdditional name for the relation, or "" for the default naming

Definition at line 155 of file RelationsObject.h.

156 {
157 StoreEntry* toEntry = nullptr;
158 int toIndex = -1;
159 DataStore::Instance().addRelation(this, m_cacheDataStoreEntry, m_cacheArrayIndex, object, toEntry, toIndex, weight, namedRelation);
160 }

◆ areAllAvailable()

bool areAllAvailable ( Const::PIDDetectorSet  set = Const::PIDDetectorSet::set()) const
inline

Check whether PID information is available for all detectors in a given set.

Was named isAvailable in release-8 or older.

Parameters
seta set of PID detectors
Returns
true if all detectors in the set provide likelihoods

Definition at line 68 of file PIDLikelihood.h.

69 {
70 return m_detectors.contains(set);
71 }
bool contains(const DetectorSet &set) const
Check whether this set contains another set.
Definition: Const.h:235
Const::DetectorSet m_detectors
set of detectors with PID information

◆ copyRelations()

void copyRelations ( const RelationsInterface< BASE > *  sourceObj)
inlineinherited

Copies all relations of sourceObj (pointing from or to sourceObj) to this object (including weights).

Useful if you want to make a complete copy of a StoreArray object to make modifications to it, but retain all information on linked objects.

Note: this only works if sourceObj inherits from the same base (e.g. RelationsObject), and only for related objects that also inherit from the same base.

Definition at line 170 of file RelationsObject.h.

171 {
172 if (!sourceObj)
173 return;
174 auto fromRels = sourceObj->getRelationsFrom<RelationsInterface<BASE>>("ALL");
175 for (unsigned int iRel = 0; iRel < fromRels.size(); iRel++) {
176 fromRels.object(iRel)->addRelationTo(this, fromRels.weight(iRel));
177 }
178
179 auto toRels = sourceObj->getRelationsTo<RelationsInterface<BASE>>("ALL");
180 for (unsigned int iRel = 0; iRel < toRels.size(); iRel++) {
181 this->addRelationTo(toRels.object(iRel), toRels.weight(iRel));
182 }
183 }
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).

◆ getArrayIndex()

int getArrayIndex ( ) const
inlineinherited

Returns this object's array index (in StoreArray), or -1 if not found.

Definition at line 385 of file RelationsObject.h.

386 {
388 return m_cacheArrayIndex;
389 }
bool findStoreEntry(const TObject *object, StoreEntry *&entry, int &index)
Find an object in an array in the data store.
Definition: DataStore.cc:398

◆ getArrayName()

std::string getArrayName ( ) const
inlineinherited

Get name of array this object is stored in, or "" if not found.

Definition at line 377 of file RelationsObject.h.

◆ getArrayPointer()

TClonesArray * getArrayPointer ( ) const
inlineprotectedinherited

Returns the pointer to the raw DataStore array holding this object (protected since these arrays are easy to misuse).

Definition at line 418 of file RelationsObject.h.

419 {
422 return nullptr;
424 }
TClonesArray * getPtrAsArray() const
Return ptr cast to TClonesArray.
Definition: StoreEntry.cc:83

◆ getDeltaLogL()

float getDeltaLogL ( const Const::ChargedStable p1,
const Const::ChargedStable p2,
Const::PIDDetectorSet  set = Const::PIDDetectorSet::set() 
) const
inline

Return log likelihood difference between two particles for a given detector set.

Parameters
p1charged stable particle
p2charged stable particle
seta set of PID detectors to use
Returns
log likelihood difference between p1 and p2: logL(p1) - logL(p2)

Definition at line 89 of file PIDLikelihood.h.

92 {
93 return getLogL(p1, set) - getLogL(p2, set);
94 }
float getLogL(const Const::ChargedStable &part, Const::PIDDetectorSet set=Const::PIDDetectorSet::set()) const
Return log likelihood for a given detector set and particle.

◆ getInfo()

std::string getInfo ( ) const
inlineinherited

Return a short summary of this object's contents in raw text format.

Returns the contents of getInfoHTML() while translating line-breaks etc.

Note
: You don't need to implement this function (it's not virtual), getInfoHTML() is enough.

Definition at line 370 of file RelationsObject.h.

371 {
373 }
virtual std::string getInfoHTML() const
Return a short summary of this object's contents in HTML format.
std::string htmlToPlainText(const std::string &html)
See RelationsObject::getInfo()

◆ getInfoHTML()

std::string getInfoHTML ( ) const
overridevirtual

Return HTML Info of PID Likelihoods.

Reimplemented from RelationsInterface< BASE >.

Definition at line 266 of file PIDLikelihood.cc.

267{
268 const string detectorName[Const::PIDDetectors::c_size] = {"SVD", "CDC", "TOP", "ARICH", "ECL", "KLM"};
269
270 std::stringstream stream;
271 stream << std::setprecision(4);
272
273 //colors from event display
274 std::string colour[Const::ChargedStable::c_SetSize];
275 colour[0] = gROOT->GetColor(kAzure)->AsHexString();
276 colour[1] = gROOT->GetColor(kCyan + 1)->AsHexString();
277 colour[2] = gROOT->GetColor(kGray + 1)->AsHexString();
278 colour[3] = gROOT->GetColor(kRed + 1)->AsHexString();
279 colour[4] = gROOT->GetColor(kOrange - 2)->AsHexString();
280 colour[5] = gROOT->GetColor(kMagenta)->AsHexString();
281
282 stream << "<b>Probabilities</b><br>";
283 stream << "<table border=0 width=100%>";
284 stream << "<tr><td>All</td><td>";
285 stream << "<table cellspacing=1 border=0 width=100%><tr>";
286 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++) {
287 double p = getProbability(Const::chargedStableSet.at(i));
288 stream << "<td bgcolor=\"" << colour[i] << "\" width=" << p * 100 << "%></td>";
289 }
290 stream << "</tr></table></td></tr>";
291
293 it != Const::PIDDetectorSet::set().end(); ++it) {
294 auto det = *it;
295 stream << "<tr><td>" << detectorName[it.getIndex()] << "</td><td>";
296 if (!isAvailable(det)) {
297 stream << "</td></tr>";
298 continue;
299 }
300 stream << "<table cellspacing=1 border=0 width=100%><tr>";
301 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++) {
302 double p = getProbability(Const::chargedStableSet.at(i), 0, det);
303 stream << "<td bgcolor=\"" << colour[i] << "\" width=" << p * 100 << "%></td>";
304 }
305 stream << "</tr></table></td></tr>";
306 }
307 stream << "</table>\n";
308
309 stream << "<b>Log-Likelihoods</b><br>";
310 stream << "<table>";
311 stream << "<tr><th>PID / Detector</th>";
312 for (unsigned k = 0; k < Const::PIDDetectors::c_size; k++)
313 stream << "<th>" << detectorName[k] << "</th>";
314 stream << "</tr>";
315 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++) {
316 stream << "<tr>";
317 stream << "<td bgcolor=\"" << colour[i] << "\">" << Const::chargedStableSet.at(i).getParticlePDG()->GetName() << "</td>";
318 for (unsigned k = 0; k < Const::PIDDetectors::c_size; k++) {
319 stream << "<td>" << m_logl[k][i] << "</td>";
320 }
321 stream << "</tr>";
322 }
323 stream << "</table>";
324 stream << "<br>";
325
326 return stream.str();
327}
Iterator end() const
Ending iterator.
Definition: UnitConst.cc:220
const ParticleType & at(unsigned int index) const
Return particle at given index, or end() if out of range.
Definition: Const.h:549
const TParticlePDG * getParticlePDG() const
Accessor for ROOT TParticlePDG object.
Definition: UnitConst.cc:351
static DetectorSet set()
Accessor for the set of valid detector IDs.
Definition: Const.h:333
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:618
bool isAvailable(Const::PIDDetectorSet set=Const::PIDDetectorSet::set()) const
Check whether PID information is available for at least one of the detectors in a given set.
double getProbability(const Const::ChargedStable &p1, const Const::ChargedStable &p2, Const::PIDDetectorSet set=Const::PIDDetectorSet::set()) const
Return combined likelihood probability for a particle being p1 and not p2, assuming equal prior proba...

◆ getLogarithmicProbability()

double getLogarithmicProbability ( const Const::ChargedStable part,
const double *  fractions = nullptr,
Const::PIDDetectorSet  set = Const::PIDDetectorSet::set() 
) const

Return logarithmic equivalent of likelihood probability defined as log(p/(1-p)), where p is the combined likelihood probability of a particle according to chargedStableSet.

This one gives a smooth peak-like distribution (opposite to probability distribution which has spikes at 0 and 1). If prior fractions are not given, equal prior probabilities are assumed.

Parameters
partcharged stable particle
fractionsarray of prior probabilities in the order defined in Const::ChargedStable
seta set of PID detectors to use
Returns
logarithmic equivalent of global likelihood probability

Definition at line 122 of file PIDLikelihood.cc.

125{
126 // Defined as log(p / (1 - p)) where p is global PID probability.
127 // In order to save the range of return values it must be implemented as below.
128
129 int k = part.getIndex();
130 if (k < 0) return -INFINITY; // p = 0
131
132 if (fractions and fractions[k] <= 0) return -INFINITY; // p = 0
133
134 double logL_part = getLogL(part, detSet);
135 std::vector<double> logLs; // all other log likelihoods with priors > 0
136 std::vector<double> priorRatios;
137 for (int i = 0; i < static_cast<int>(Const::ChargedStable::c_SetSize); i++) {
138 if (i == k) continue;
139 double ratio = fractions ? fractions[i] / fractions[k] : 1;
140 if (ratio <= 0) continue;
141 priorRatios.push_back(ratio);
142 logLs.push_back(getLogL(Const::chargedStableSet.at(i), detSet));
143 }
144 if (logLs.empty()) return +INFINITY; // p = 1
145
146 double logL_max = logLs[0]; // maximal log likelihood of the others
147 for (auto logl : logLs) logL_max = std::max(logl, logL_max);
148
149 double sum = 0;
150 for (size_t i = 0; i < logLs.size(); i++) sum += priorRatios[i] * exp(logLs[i] - logL_max);
151 if (sum == 0) return +INFINITY; // to suppress cppckeck warning although this can never happen (see prev. return)
152
153 return logL_part - logL_max - log(sum);
154}
int getIndex() const
This particle's index in the associated set.
Definition: Const.h:461

◆ getLogL()

float getLogL ( const Const::ChargedStable part,
Const::PIDDetectorSet  set = Const::PIDDetectorSet::set() 
) const

Return log likelihood for a given detector set and particle.

Parameters
partcharged stable particle
seta set of PID detectors to use
Returns
log likelihood

Definition at line 76 of file PIDLikelihood.cc.

78{
79 float result = 0;
81 it != Const::PIDDetectorSet::set().end(); ++it) {
82 if (set.contains(it))
83 result += m_logl[it.getIndex()][part.getIndex()];
84 }
85 return result;
86}

◆ getMostLikely()

Const::ChargedStable getMostLikely ( const double *  fractions = nullptr,
Const::PIDDetectorSet  set = Const::PIDDetectorSet::set() 
) const

Return most likely particle among chargedStableSet; if prior fractions not given equal prior probabilities assumed.

Parameters
fractionsarray of prior probabilities in the order defined in Const::ChargedStable
seta set of PID detectors to use
Returns
most likely particle

Definition at line 157 of file PIDLikelihood.cc.

159{
160 const unsigned int n = Const::ChargedStable::c_SetSize;
161 double prob[n];
162 probability(prob, fractions, detSet);
163
164 int k = 0;
165 double maxProb = prob[k];
166 for (unsigned i = 0; i < n; ++i) {
167 if (prob[i] > maxProb) {maxProb = prob[i]; k = i;}
168 }
169 return Const::chargedStableSet.at(k);
170
171}
void probability(double probabilities[], const double *fractions, Const::PIDDetectorSet detSet) const
Calculate likelihood probabilities.

◆ getName()

virtual std::string getName ( ) const
inlinevirtualinherited

Return a short name that describes this object, e.g.

pi+ for an MCParticle.

Reimplemented in Particle, and MCParticle.

Definition at line 344 of file RelationsObject.h.

344{ return ""; }

◆ getPreOfficialLikelihood()

double getPreOfficialLikelihood ( const std::string &  preOfficialIdentifier) const

Get the pre-official likelihood.

Parameters
preOfficialIdentifierName of the pre-official likelihood
Returns
Value of the pre-official likelihood

Definition at line 334 of file PIDLikelihood.cc.

335{
336 if (m_preOfficialLikelihoods.count(preOfficialIdentifier) == 0) {
337 B2WARNING("PIDLikelihood::getPreOfficialLikelihood: preOfficialIdentifier " << preOfficialIdentifier << " does not exist. ");
338 return -1.0;
339 }
340 return m_preOfficialLikelihoods.at(preOfficialIdentifier);
341}

◆ getProbability() [1/3]

double getProbability ( const Const::ChargedStable p1,
const Const::ChargedStable p2,
Const::PIDDetectorSet  set = Const::PIDDetectorSet::set() 
) const
inline

Return combined likelihood probability for a particle being p1 and not p2, assuming equal prior probabilities.

Parameters
p1charged stable particle
p2charged stable particle
seta set of PID detectors to use
Returns
binary likelihood probability

Definition at line 104 of file PIDLikelihood.h.

107 {
108 return getProbability(p1, p2, 1.0, set);
109 }

◆ getProbability() [2/3]

double getProbability ( const Const::ChargedStable p1,
const Const::ChargedStable p2,
double  ratio,
Const::PIDDetectorSet  set = Const::PIDDetectorSet::set() 
) const

Return combined likelihood probability for a particle being p1 and not p2.

Parameters
p1charged stable particle
p2charged stable particle
ratioratio of prior probabilities (p1/p2)
seta set of PID detectors to use
Returns
binary likelihood probability

Definition at line 89 of file PIDLikelihood.cc.

93{
94 if (ratio < 0) {
95 B2ERROR("PIDLikelihood::probability argument 'ratio' is given with negative value");
96 return 0;
97 }
98 if (ratio == 0) return 0;
99
100 double dlogl = getLogL(p2, set) - getLogL(p1, set);
101 double result = 0;
102 if (dlogl < 0) {
103 double elogl = exp(dlogl);
104 result = ratio / (ratio + elogl);
105 } else {
106 double elogl = exp(-dlogl) * ratio; // to prevent overflow for very large dlogl
107 result = elogl / (1.0 + elogl);
108 }
109
110 return result;
111}

◆ getProbability() [3/3]

double getProbability ( const Const::ChargedStable part,
const double *  fractions = nullptr,
Const::PIDDetectorSet  set = Const::PIDDetectorSet::set() 
) const

Return combined likelihood probability for a particle according to chargedStableSet; if prior fractions not given equal prior probabilities assumed.

Parameters
partcharged stable particle
fractionsarray of prior probabilities in the order defined in Const::ChargedStable
seta set of PID detectors to use
Returns
global likelihood probability

Definition at line 114 of file PIDLikelihood.cc.

117{
118 return 1 / (1 + exp(-getLogarithmicProbability(part, fractions, detSet)));
119}
double getLogarithmicProbability(const Const::ChargedStable &part, const double *fractions=nullptr, Const::PIDDetectorSet set=Const::PIDDetectorSet::set()) const
Return logarithmic equivalent of likelihood probability defined as log(p/(1-p)), where p is the combi...

◆ getRelated()

T * getRelated ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get the object to or from which this object has a relation.

Template Parameters
TThe class of objects to or from which the relation points.
Parameters
nameThe name of the store array to or from which the relation points. If empty the default store array name for class T will be used. If the special name "ALL" is given all store arrays containing objects of type T are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
The first related object or a null pointer.

Definition at line 278 of file RelationsObject.h.

279 {
281 T::Class(), name, namedRelation).object);
282 }
@ c_BothSides
Combination of c_FromSide and c_ToSide.
Definition: DataStore.h:79
Belle2::RelationEntry getRelationWith(ESearchSide searchSide, const TObject *object, StoreEntry *&entry, int &index, const TClass *withClass, const std::string &withName, const std::string &namedRelation)
Get the first relation between an object and another object in a store array.
Definition: DataStore.cc:597
TObject * object
Pointer to the object.
Definition: RelationEntry.h:32

◆ getRelatedFrom()

FROM * getRelatedFrom ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get the object from which this object has a relation.

Template Parameters
FROMThe class of objects from which the relation points.
Parameters
nameThe name of the store array from which the relation points. If empty the default store array name for class FROM will be used. If the special name "ALL" is given all store arrays containing objects of type FROM are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
The first related object or a null pointer.

Definition at line 263 of file RelationsObject.h.

264 {
266 m_cacheArrayIndex, FROM::Class(), name, namedRelation).object);
267 }
@ c_FromSide
Return relations/objects pointed from (to a given object).
Definition: DataStore.h:77

◆ getRelatedFromWithWeight()

std::pair< FROM *, float > getRelatedFromWithWeight ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get first related object & weight of relation pointing from an array.

Template Parameters
FROMThe class of objects from which the relation points.
Parameters
nameThe name of the store array from which the relation points. If empty the default store array name for class FROM will be used. If the special name "ALL" is given all store arrays containing objects of type FROM are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
Pair of first related object and the relation weight, or (NULL, 1.0) if none found.

Definition at line 314 of file RelationsObject.h.

316 {
318 FROM::Class(), name, namedRelation);
319 return std::make_pair(static_cast<FROM*>(entry.object), entry.weight);
320 }

◆ getRelatedTo()

TO * getRelatedTo ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get the object to which this object has a relation.

Template Parameters
TOThe class of objects to which the relation points.
Parameters
nameThe name of the store array to which the relation points. If empty the default store array name for class TO will be used. If the special name "ALL" is given all store arrays containing objects of type TO are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
The first related object or a null pointer.

Definition at line 248 of file RelationsObject.h.

249 {
251 TO::Class(), name, namedRelation).object);
252 }
@ c_ToSide
Return relations/objects pointed to (from a given object).
Definition: DataStore.h:78

◆ getRelatedToWithWeight()

std::pair< TO *, float > getRelatedToWithWeight ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get first related object & weight of relation pointing to an array.

Template Parameters
TOThe class of objects to which the relation points.
Parameters
nameThe name of the store array to which the relation points. If empty the default store array name for class TO will be used. If the special name "ALL" is given all store arrays containing objects of type TO are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
Pair of first related object and the relation weight, or (NULL, 1.0) if none found.

Definition at line 297 of file RelationsObject.h.

299 {
301 TO::Class(), name, namedRelation);
302 return std::make_pair(static_cast<TO*>(entry.object), entry.weight);
303 }

◆ getRelatedWithWeight()

std::pair< T *, float > getRelatedWithWeight ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get first related object & weight of relation pointing from/to an array.

Template Parameters
TThe class of objects to or from which the relation points.
Parameters
nameThe name of the store array to or from which the relation points. If empty the default store array name for class T will be used. If the special name "ALL" is given all store arrays containing objects of type T are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
Pair of first related object and the relation weight, or (NULL, 1.0) if none found.

Definition at line 331 of file RelationsObject.h.

333 {
335 T::Class(), name, namedRelation);
336 return std::make_pair(static_cast<T*>(entry.object), entry.weight);
337 }

◆ getRelationsFrom()

RelationVector< FROM > getRelationsFrom ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get the relations that point from another store array to this object.

Template Parameters
FROMThe class of objects from which the relations point.
Parameters
nameThe name of the store array from which the relations point. If empty the default store array name for class FROM will be used. If the special name "ALL" is given all store arrays containing objects of type FROM are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
A vector of relations.

Definition at line 212 of file RelationsObject.h.

214 {
216 m_cacheArrayIndex, FROM::Class(), name, namedRelation));
217 }
RelationVector< T > getRelationsWith(const std::string &name="", const std::string &namedRelation="") const
Get the relations between this object and another store array.

◆ getRelationsTo()

RelationVector< TO > getRelationsTo ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get the relations that point from this object to another store array.

Template Parameters
TOThe class of objects to which the relations point.
Parameters
nameThe name of the store array to which the relations point. If empty the default store array name for class TO will be used. If the special name "ALL" is given all store arrays containing objects of type TO are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
A vector of relations.

Definition at line 197 of file RelationsObject.h.

198 {
200 m_cacheArrayIndex, TO::Class(), name, namedRelation));
201 }

◆ getRelationsWith()

RelationVector< T > getRelationsWith ( const std::string &  name = "",
const std::string &  namedRelation = "" 
) const
inlineinherited

Get the relations between this object and another store array.

Relations in both directions are returned.

Template Parameters
TThe class of objects to or from which the relations point.
Parameters
nameThe name of the store array to or from which the relations point. If empty the default store array name for class T will be used. If the special name "ALL" is given all store arrays containing objects of type T are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
A vector of relations.

Definition at line 230 of file RelationsObject.h.

231 {
233 m_cacheArrayIndex, T::Class(), name, namedRelation));
234 }

◆ isAvailable()

bool isAvailable ( Const::PIDDetectorSet  set = Const::PIDDetectorSet::set()) const

Check whether PID information is available for at least one of the detectors in a given set.

Redefined after release-8.

Parameters
seta set of PID detectors
Returns
true if at least one of the detectors in the set provides likelihoods

Definition at line 67 of file PIDLikelihood.cc.

68{
69 for (const auto& detector : set) {
70 if (m_detectors.contains(detector)) return true;
71 }
72 return false;
73}

◆ printArray()

void printArray ( ) const

Prints the content of a private array of log likelihoods.

Definition at line 214 of file PIDLikelihood.cc.

215{
216
217 const string detectorName[Const::PIDDetectors::c_size] =
218 {"SVD", "CDC", "TOP", "ARICH", "ECL", "KLM"};
219 string hline("-------");
220 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++)
221 hline += "-----------";
222 string Hline("=======");
223 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++)
224 Hline += "===========";
225
226 cout << Hline << endl;
227
228 cout << "PDGcode";
229 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++)
230 cout << setw(10) << Const::chargedStableSet.at(i).getPDGCode() << " ";
231 cout << endl;
232
233 cout << Hline << endl;
234
235 float sum_logl[Const::ChargedStable::c_SetSize];
236 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++) sum_logl[i] = 0;
237
238 for (unsigned k = 0; k < Const::PIDDetectors::c_size; k++) {
239 cout << setw(7) << detectorName[k];
240 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++) {
241 cout << setw(10) << setprecision(4) << m_logl[k][i] << " ";
242 sum_logl[i] += m_logl[k][i];
243 }
244 cout << endl;
245 }
246
247 cout << hline << endl;
248
249 cout << setw(7) << "sum";
250 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++)
251 cout << setw(10) << setprecision(4) << sum_logl[i] << " ";
252 cout << endl;
253
254 if (isAvailable(Const::SVD) or isAvailable(Const::CDC) or isAvailable(Const::TOP) or
255 isAvailable(Const::ARICH) or isAvailable(Const::ECL) or isAvailable(Const::KLM)) {
256 unsigned k = 0;
257 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++)
258 if (sum_logl[i] > sum_logl[k]) k = i;
259 unsigned pos = 11 * (k + 1) + 3;
260 Hline.replace(pos, 1, "^");
261 }
262 cout << Hline << endl;
263
264}
int getPDGCode() const
PDG code.
Definition: Const.h:473

◆ probability()

void probability ( double  probabilities[],
const double *  fractions,
Const::PIDDetectorSet  detSet 
) const
private

Calculate likelihood probabilities.

Parameters
fractionsarray of prior fractions (not needed to be normalized)
probabilitiesarray of resulting probabilities
detSeta set of PID detectors to use

Definition at line 174 of file PIDLikelihood.cc.

177{
178 const unsigned int n = Const::ChargedStable::c_SetSize;
179 double frac[n];
180 if (!fractions) {
181 for (unsigned int i = 0; i < n; ++i) frac[i] = 1.0; // normalization not needed
182 fractions = frac;
183 }
184
185 double logL[n];
186 double logLmax = 0;
187 bool hasMax = false;
188 for (unsigned i = 0; i < n; ++i) {
189 logL[i] = 0;
190 if (fractions[i] > 0) {
191 logL[i] = getLogL(Const::chargedStableSet.at(i), detSet);
192 if (!hasMax || logL[i] > logLmax) {
193 logLmax = logL[i];
194 hasMax = true;
195 }
196 }
197 }
198
199 double norm = 0;
200 for (unsigned i = 0; i < n; ++i) {
201 probabilities[i] = 0;
202 if (fractions[i] > 0) probabilities[i] = exp(logL[i] - logLmax) * fractions[i];
203 norm += probabilities[i];
204 }
205 if (norm == 0) return;
206
207 for (unsigned i = 0; i < n; ++i) {
208 probabilities[i] /= norm;
209 }
210
211}

◆ setLogLikelihood()

void setLogLikelihood ( Const::EDetector  det,
const Const::ChargedStable part,
float  logl 
)

Set log likelihood for a given detector and particle.

Parameters
detdetector enumerator
partcharged stable particle
logllog likelihood

Definition at line 35 of file PIDLikelihood.cc.

38{
39 int index = Const::PIDDetectors::set().getIndex(det);
40 if (index < 0) {
41 B2ERROR("PIDLikelihood::setLogLikelihood: detector is not a PID device");
42 return;
43 }
44 if (logl != logl or logl == INFINITY) {
45 B2ERROR("PIDLikelihood::setLogLikelihood: log-likelihood for detector " << det << " is " << logl <<
46 " (i.e. +inf or NaN)! Ignoring this value. ("
47 << Const::SVD << "=SVD, " << Const::CDC << "=CDC, " << Const::TOP << "=TOP, "
48 << Const::ARICH << "=ARICH, " << Const::ECL << "=ECL, " << Const::KLM << "=KLM)");
49
50 return;
51 }
52 m_detectors += det;
53 m_logl[index][part.getIndex()] = logl;
54}
int getIndex(EDetector det) const
Getter for the index of a given detector in this set.
Definition: UnitConst.cc:278
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:374

◆ subtractMaximum()

void subtractMaximum ( )

Subtract the maximum of log likelihoods of each detector component in order to reduce the range of values.

Definition at line 57 of file PIDLikelihood.cc.

58{
59 for (auto& detectorLLs : m_logl) {
60 auto maxLL = detectorLLs[0];
61 for (auto LL : detectorLLs) maxLL = std::max(maxLL, LL);
62 for (auto& LL : detectorLLs) LL -= maxLL;
63 }
64}

Member Data Documentation

◆ m_cacheArrayIndex

int m_cacheArrayIndex
mutableprivateinherited

Cache of the index in the TClonesArray to which this object belongs.

Definition at line 432 of file RelationsObject.h.

◆ m_cacheDataStoreEntry

DataStore::StoreEntry* m_cacheDataStoreEntry
mutableprivateinherited

Cache of the data store entry to which this object belongs.

Definition at line 429 of file RelationsObject.h.

◆ m_detectors

Const::DetectorSet m_detectors
private

set of detectors with PID information

Definition at line 197 of file PIDLikelihood.h.

◆ m_logl

log likelihoods

Definition at line 198 of file PIDLikelihood.h.

◆ m_preOfficialLikelihoods

std::map<std::string, double> m_preOfficialLikelihoods
private

Internal storage of pre-official likelihood.

Definition at line 201 of file PIDLikelihood.h.


The documentation for this class was generated from the following files: