Belle II Software light-2405-quaxo
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.
 
bool isAvailable (Const::PIDDetectorSet set) const
 Check whether PID information from a given set of detectors is available.
 
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 for a given detector set and particles.
 
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=0, 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.
 
Const::ChargedStable getMostLikely (const double *fractions=0, 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 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, 3)
 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
 
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 26 of file PIDLikelihood.h.

Constructor & Destructor Documentation

◆ PIDLikelihood()

Default constructor: log likelihoods and flags set to 0.

Definition at line 23 of file PIDLikelihood.cc.

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

Member Function Documentation

◆ 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 }

◆ 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 for a given detector set and particles.

Parameters
p1charged stable particle
p2charged stable particle
seta set of PID detectors to use
Returns
log likelihood difference logL_p1 - logL_p2

Definition at line 68 of file PIDLikelihood.h.

71 {
72 return getLogL(p1, set) - getLogL(p2, set);
73 }
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 217 of file PIDLikelihood.cc.

218{
219 const string detectorName[Const::PIDDetectors::c_size] = {"SVD", "CDC", "TOP", "ARICH", "ECL", "KLM"};
220
221 std::stringstream stream;
222 stream << std::setprecision(4);
223
224 //colors from event display
225 std::string colour[Const::ChargedStable::c_SetSize];
226 colour[0] = gROOT->GetColor(kAzure)->AsHexString();
227 colour[1] = gROOT->GetColor(kCyan + 1)->AsHexString();
228 colour[2] = gROOT->GetColor(kGray + 1)->AsHexString();
229 colour[3] = gROOT->GetColor(kRed + 1)->AsHexString();
230 colour[4] = gROOT->GetColor(kOrange - 2)->AsHexString();
231 colour[5] = gROOT->GetColor(kMagenta)->AsHexString();
232
233 stream << "<b>Probabilities</b><br>";
234 stream << "<table border=0 width=100%>";
235 stream << "<tr><td>All</td><td>";
236 stream << "<table cellspacing=1 border=0 width=100%><tr>";
237 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++) {
238 double p = getProbability(Const::chargedStableSet.at(i));
239 stream << "<td bgcolor=\"" << colour[i] << "\" width=" << p * 100 << "%></td>";
240 }
241 stream << "</tr></table></td></tr>";
242
244 it != Const::PIDDetectorSet::set().end(); ++it) {
245 auto det = *it;
246 stream << "<tr><td>" << detectorName[it.getIndex()] << "</td><td>";
247 if (!isAvailable(det)) {
248 stream << "</td></tr>";
249 continue;
250 }
251 stream << "<table cellspacing=1 border=0 width=100%><tr>";
252 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++) {
253 double p = getProbability(Const::chargedStableSet.at(i), 0, det);
254 stream << "<td bgcolor=\"" << colour[i] << "\" width=" << p * 100 << "%></td>";
255 }
256 stream << "</tr></table></td></tr>";
257 }
258 stream << "</table>\n";
259
260 stream << "<b>Log-Likelihoods</b><br>";
261 stream << "<table>";
262 stream << "<tr><th>PID / Detector</th>";
263 for (unsigned k = 0; k < Const::PIDDetectors::c_size; k++)
264 stream << "<th>" << detectorName[k] << "</th>";
265 stream << "</tr>";
266 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++) {
267 stream << "<tr>";
268 stream << "<td bgcolor=\"" << colour[i] << "\">" << Const::chargedStableSet.at(i).getParticlePDG()->GetName() << "</td>";
269 for (unsigned k = 0; k < Const::PIDDetectors::c_size; k++) {
270 stream << "<td>" << m_logl[k][i] << "</td>";
271 }
272 stream << "</tr>";
273 }
274 stream << "</table>";
275 stream << "<br>";
276
277 return stream.str();
278}
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:540
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:324
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:609
bool isAvailable(Const::PIDDetectorSet set) const
Check whether PID information from a given set of detectors is available.
Definition: PIDLikelihood.h:50
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...
Definition: PIDLikelihood.h:83

◆ 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 55 of file PIDLikelihood.cc.

57{
58 float result = 0;
60 it != Const::PIDDetectorSet::set().end(); ++it) {
61 if (set.contains(it))
62 result += m_logl[it.getIndex()][part.getIndex()];
63 }
64 return result;
65}
bool contains(const DetectorSet &set) const
Check whether this set contains another set.
Definition: Const.h:226
int getIndex() const
This particle's index in the associated set.
Definition: Const.h:452

◆ getMostLikely()

Const::ChargedStable getMostLikely ( const double *  fractions = 0,
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
particle type

Definition at line 108 of file PIDLikelihood.cc.

110{
111 const unsigned int n = Const::ChargedStable::c_SetSize;
112 double prob[n];
113 probability(prob, fractions, detSet);
114
115 int k = 0;
116 double maxProb = prob[k];
117 for (unsigned i = 0; i < n; ++i) {
118 if (prob[i] > maxProb) {maxProb = prob[i]; k = i;}
119 }
120 return Const::chargedStableSet.at(k);
121
122}
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 ""; }

◆ 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
likelihood probability

Definition at line 83 of file PIDLikelihood.h.

86 {
87 return getProbability(p1, p2, 1.0, set);
88 }

◆ 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
likelihood probability

Definition at line 68 of file PIDLikelihood.cc.

72{
73 if (ratio < 0) {
74 B2ERROR("PIDLikelihood::probability argument 'ratio' is given with negative value");
75 return 0;
76 }
77 if (ratio == 0) return 0;
78
79 double dlogl = getLogL(p2, set) - getLogL(p1, set);
80 double res;
81 if (dlogl < 0) {
82 double elogl = exp(dlogl);
83 res = ratio / (ratio + elogl);
84 } else {
85 double elogl = exp(-dlogl) * ratio; // to prevent overflow for very large dlogl
86 res = elogl / (1.0 + elogl);
87 }
88 //TODO: only necessary if one wants to use mcprod1405 MC sample. Remove when there's a good replacement.
89 if (std::isfinite(res))
90 return res;
91 return 0;
92}

◆ getProbability() [3/3]

double getProbability ( const Const::ChargedStable part,
const double *  fractions = 0,
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
likelihood probability (a value btw. 0 and 1)

Definition at line 94 of file PIDLikelihood.cc.

97{
99 probability(prob, fractions, detSet);
100
101 int k = part.getIndex();
102 if (k < 0) return 0;
103
104 return prob[k];
105
106}

◆ 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
inline

Check whether PID information from a given set of detectors is available.

Parameters
seta set of PID detectors
Returns
true if the given set of detectors contributed to the PID information

Definition at line 50 of file PIDLikelihood.h.

50{return m_detectors.contains(set);}
Const::DetectorSet m_detectors
set of detectors with PID information

◆ printArray()

void printArray ( ) const

Prints the content of a private array of log likelihoods.

Definition at line 165 of file PIDLikelihood.cc.

166{
167
168 const string detectorName[Const::PIDDetectors::c_size] =
169 {"SVD", "CDC", "TOP", "ARICH", "ECL", "KLM"};
170 string hline("-------");
171 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++)
172 hline += "-----------";
173 string Hline("=======");
174 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++)
175 Hline += "===========";
176
177 cout << Hline << endl;
178
179 cout << "PDGcode";
180 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++)
181 cout << setw(10) << Const::chargedStableSet.at(i).getPDGCode() << " ";
182 cout << endl;
183
184 cout << Hline << endl;
185
186 float sum_logl[Const::ChargedStable::c_SetSize];
187 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++) sum_logl[i] = 0;
188
189 for (unsigned k = 0; k < Const::PIDDetectors::c_size; k++) {
190 cout << setw(7) << detectorName[k];
191 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++) {
192 cout << setw(10) << setprecision(4) << m_logl[k][i] << " ";
193 sum_logl[i] += m_logl[k][i];
194 }
195 cout << endl;
196 }
197
198 cout << hline << endl;
199
200 cout << setw(7) << "sum";
201 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++)
202 cout << setw(10) << setprecision(4) << sum_logl[i] << " ";
203 cout << endl;
204
205 if (isAvailable(Const::SVD) or isAvailable(Const::CDC) or isAvailable(Const::TOP) or
206 isAvailable(Const::ARICH) or isAvailable(Const::ECL) or isAvailable(Const::KLM)) {
207 unsigned k = 0;
208 for (unsigned i = 0; i < Const::ChargedStable::c_SetSize; i++)
209 if (sum_logl[i] > sum_logl[k]) k = i;
210 unsigned pos = 11 * (k + 1) + 3;
211 Hline.replace(pos, 1, "^");
212 }
213 cout << Hline << endl;
214
215}
int getPDGCode() const
PDG code.
Definition: Const.h:464

◆ 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 125 of file PIDLikelihood.cc.

128{
129 const unsigned int n = Const::ChargedStable::c_SetSize;
130 double frac[n];
131 if (!fractions) {
132 for (unsigned int i = 0; i < n; ++i) frac[i] = 1.0; // normalization not needed
133 fractions = frac;
134 }
135
136 double logL[n];
137 double logLmax = 0;
138 bool hasMax = false;
139 for (unsigned i = 0; i < n; ++i) {
140 logL[i] = 0;
141 if (fractions[i] > 0) {
142 logL[i] = getLogL(Const::chargedStableSet.at(i), detSet);
143 if (!hasMax || logL[i] > logLmax) {
144 logLmax = logL[i];
145 hasMax = true;
146 }
147 }
148 }
149
150 double norm = 0;
151 for (unsigned i = 0; i < n; ++i) {
152 probabilities[i] = 0;
153 if (fractions[i] > 0) probabilities[i] = exp(logL[i] - logLmax) * fractions[i];
154 norm += probabilities[i];
155 }
156 if (norm == 0) return;
157
158 for (unsigned i = 0; i < n; ++i) {
159 probabilities[i] /= norm;
160 }
161
162}

◆ 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 33 of file PIDLikelihood.cc.

36{
37 int index = Const::PIDDetectors::set().getIndex(det);
38 if (index < 0) {
39 B2ERROR("PIDLikelihood::setLogLikelihood: detector is not a PID device");
40 return;
41 }
42 if (logl != logl or logl == INFINITY) {
43 B2ERROR("PIDLikelihood::setLogLikelihood: log-likelihood for detector " << det << " is " << logl <<
44 " (i.e. +inf or NaN)! Ignoring this value. ("
45 << Const::SVD << "=SVD, " << Const::CDC << "=CDC, " << Const::TOP << "=TOP, "
46 << Const::ARICH << "=ARICH, " << Const::ECL << "=ECL, " << Const::KLM << "=KLM)");
47
48 return;
49 }
50 m_detectors += det;
51 m_logl[index][part.getIndex()] = logl;
52}
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:365

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 138 of file PIDLikelihood.h.

◆ m_logl

log likelihoods

Definition at line 139 of file PIDLikelihood.h.


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