Belle II Software light-2406-ragdoll
Cluster Class Reference

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

#include <Cluster.h>

Inheritance diagram for Cluster:
Collaboration diagram for Cluster:

Public Member Functions

 Cluster ()
 Default constructor: log likelihoods and flags set to 0.
 
void setLogLikelihood (Const::EDetector det, const Const::Cluster &cluster, float logl)
 Set log likelihood for a given detector and particle.
 
bool isAvailable (Const::ClusterDetectorSet set) const
 Check whether cluster information from a given set of detectors is available.
 
float getLogL (const Const::Cluster &cluster, Const::ClusterDetectorSet set=Const::ClusterDetectorSet::set()) const
 Return log likelihood for a given detector set and particle.
 
float getDeltaLogL (const Const::Cluster &c1, const Const::Cluster &c2, Const::ClusterDetectorSet set=Const::ClusterDetectorSet::set()) const
 Return log likelihood difference for a given detector set and clusters.
 
double getProbability (const Const::Cluster &c1, const Const::Cluster &c2, Const::ClusterDetectorSet set=Const::ClusterDetectorSet::set()) const
 Return combined likelihood probability for a cluster being c1 and not c2, assuming equal prior probabilities.
 
double getProbability (const Const::Cluster &c1, const Const::Cluster &c2, double ratio, Const::ClusterDetectorSet set=Const::ClusterDetectorSet::set()) const
 Return combined likelihood probability for a cluster being c1 and not c2.
 
double getProbability (const Const::Cluster &cluster, const double *fractions=0, Const::ClusterDetectorSet set=Const::ClusterDetectorSet::set()) const
 Return combined likelihood probability for a cluster according to clusterSet; if prior fractions not given equal prior probabilities assumed.
 
Const::Cluster getMostLikely (const double *fractions=0, Const::ClusterDetectorSet set=Const::ClusterDetectorSet::set()) const
 Return most likely particle among clusterSet; 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 cluster 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::ClusterDetectorSet detSet) const
 Calculate likelihood probabilities.
 
 ClassDefOverride (Cluster, 1)
 Initial version.
 
 ClassDef (RelationsInterface, 0)
 defines interface for accessing relations of objects in StoreArray.
 

Private Attributes

Const::DetectorSet m_detectors
 set of detectors with cluster information
 
float m_logl [Const::ClusterDetectors::c_size][Const::Cluster::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 Clusters from ECL and KLM aimed for output to mdst includes functions to return combined likelihood probability.

Definition at line 26 of file Cluster.h.

Constructor & Destructor Documentation

◆ Cluster()

Cluster ( )

Default constructor: log likelihoods and flags set to 0.

Definition at line 19 of file Cluster.cc.

20{
21 for (unsigned short i = 0; i < Const::ClusterDetectors::c_size; i++) {
22 for (unsigned int k = 0; k < Const::Cluster::c_SetSize; k++) {
23 m_logl[i][k] = 0.0;
24 }
25 }
26}
float m_logl[Const::ClusterDetectors::c_size][Const::Cluster::c_SetSize]
log likelihoods
Definition: Cluster.h:139
static const size_t c_size
Number of PID detectors, temporary workaround.
Definition: Const.h:389
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
Definition: Const.h:652

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::Cluster c1,
const Const::Cluster c2,
Const::ClusterDetectorSet  set = Const::ClusterDetectorSet::set() 
) const
inline

Return log likelihood difference for a given detector set and clusters.

Parameters
c1cluster
c2cluster
seta set of cluster detectors to use
Returns
log likelihood difference logL_c1 - logL_c2

Definition at line 68 of file Cluster.h.

71 {
72 return getLogL(c1, set) - getLogL(c2, set);
73 }
float getLogL(const Const::Cluster &cluster, Const::ClusterDetectorSet set=Const::ClusterDetectorSet::set()) const
Return log likelihood for a given detector set and particle.
Definition: Cluster.cc:49

◆ 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 cluster Likelihoods.

Reimplemented from RelationsInterface< BASE >.

Definition at line 209 of file Cluster.cc.

210{
211 const string detectorName[Const::ClusterDetectors::c_size] = {"ECL", "KLM"};
212
213 std::stringstream stream;
214 stream << std::setprecision(4);
215 stream << "<b>Likelihoods</b><br>";
216 stream << "<table>";
217 stream << "<tr><th>Cluster / Detector</th>";
218 for (unsigned k = 0; k < Const::ClusterDetectors::c_size; k++)
219 stream << "<th>" << detectorName[k] << "</th>";
220 stream << "</tr>";
221 for (unsigned i = 0; i < Const::Cluster::c_SetSize; i++) {
222 stream << "<tr>";
223 stream << "<td>" << Const::clusterSet.at(i).getPDGCode() << "</td>";
224 for (unsigned k = 0; k < Const::ClusterDetectors::c_size; k++) {
225 stream << "<td>" << m_logl[k][i] << "</td>";
226 }
227 stream << "</tr>";
228 }
229 stream << "</table>";
230 stream << "<br>";
231
232 return stream.str();
233}
const ParticleType & at(unsigned int index) const
Return particle at given index, or end() if out of range.
Definition: Const.h:549
int getPDGCode() const
PDG code.
Definition: Const.h:473
static const ParticleSet clusterSet
set of cluster particles
Definition: Const.h:655

◆ getLogL()

float getLogL ( const Const::Cluster cluster,
Const::ClusterDetectorSet  set = Const::ClusterDetectorSet::set() 
) const

Return log likelihood for a given detector set and particle.

Parameters
clustercluster
seta set of cluster detectors to use
Returns
log likelihood

Definition at line 49 of file Cluster.cc.

51{
52 float result = 0;
54 it != Const::ClusterDetectorSet::set().end(); ++it) {
55 if (set.contains(it))
56 result += m_logl[it.getIndex()][cluster.getIndex()];
57 }
58 return result;
59}
Iterator end() const
Ending iterator.
Definition: UnitConst.cc:220
bool contains(const DetectorSet &set) const
Check whether this set contains another set.
Definition: Const.h:235
static DetectorSet set()
Accessor for the set of valid detector IDs.
Definition: Const.h:333

◆ getMostLikely()

Const::Cluster getMostLikely ( const double *  fractions = 0,
Const::ClusterDetectorSet  set = Const::ClusterDetectorSet::set() 
) const

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

Parameters
fractionsarray of prior probabilities in the order defined in Const::Cluster
seta set of PID detectors to use
Returns
particle type

Definition at line 102 of file Cluster.cc.

104{
105 const unsigned int n = Const::Cluster::c_SetSize;
106 double prob[n];
107 probability(prob, fractions, detSet);
108
109 int k = 0;
110 double maxProb = prob[k];
111 for (unsigned i = 0; i < n; ++i) {
112 if (prob[i] > maxProb) {maxProb = prob[i]; k = i;}
113 }
114 return Const::clusterSet.at(k);
115
116}
void probability(double probabilities[], const double *fractions, Const::ClusterDetectorSet detSet) const
Calculate likelihood probabilities.
Definition: Cluster.cc:119

◆ 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::Cluster c1,
const Const::Cluster c2,
Const::ClusterDetectorSet  set = Const::ClusterDetectorSet::set() 
) const
inline

Return combined likelihood probability for a cluster being c1 and not c2, assuming equal prior probabilities.

Parameters
c1cluster
c2cluster
seta set of cluster detectors to use
Returns
likelihood probability

Definition at line 83 of file Cluster.h.

86 {
87 return getProbability(c1, c2, 1.0, set);
88 }
double getProbability(const Const::Cluster &c1, const Const::Cluster &c2, Const::ClusterDetectorSet set=Const::ClusterDetectorSet::set()) const
Return combined likelihood probability for a cluster being c1 and not c2, assuming equal prior probab...
Definition: Cluster.h:83

◆ getProbability() [2/3]

Double32_t getProbability ( const Const::Cluster c1,
const Const::Cluster c2,
double  ratio,
Const::ClusterDetectorSet  set = Const::ClusterDetectorSet::set() 
) const

Return combined likelihood probability for a cluster being c1 and not c2.

Parameters
c1cluster
c2cluster
ratioratio of prior probabilities (c1/c2)
seta set of cluster detectors to use
Returns
likelihood probability

Definition at line 62 of file Cluster.cc.

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

◆ getProbability() [3/3]

double getProbability ( const Const::Cluster cluster,
const double *  fractions = 0,
Const::ClusterDetectorSet  set = Const::ClusterDetectorSet::set() 
) const

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

Parameters
clustercluster
fractionsarray of prior probabilities in the order defined in Const::Cluster
seta set of cluster detectors to use
Returns
likelihood probability (a value btw. 0 and 1)

Definition at line 88 of file Cluster.cc.

91{
92 double prob[Const::Cluster::c_SetSize];
93 probability(prob, fractions, detSet);
94
95 int k = cluster.getIndex();
96 if (k < 0) return 0;
97
98 return prob[k];
99
100}

◆ 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::ClusterDetectorSet  set) const
inline

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

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

Definition at line 50 of file Cluster.h.

50{return m_detectors.contains(set);}
Const::DetectorSet m_detectors
set of detectors with cluster information
Definition: Cluster.h:138

◆ printArray()

void printArray ( ) const

Prints the content of a private array of log likelihoods.

Definition at line 159 of file Cluster.cc.

160{
161
162 const string detectorName[Const::ClusterDetectors::c_size] = {"ECL", "KLM"};
163 string hline("-------");
164 for (unsigned i = 0; i < Const::Cluster::c_SetSize; i++)
165 hline += "-----------";
166 string Hline("=======");
167 for (unsigned i = 0; i < Const::Cluster::c_SetSize; i++)
168 Hline += "===========";
169
170 cout << Hline << endl;
171
172 cout << "PDGcode";
173 for (unsigned i = 0; i < Const::Cluster::c_SetSize; i++)
174 cout << setw(10) << Const::clusterSet.at(i).getPDGCode() << " ";
175 cout << endl;
176
177 cout << Hline << endl;
178
179 float sum_logl[Const::Cluster::c_SetSize];
180 for (unsigned i = 0; i < Const::Cluster::c_SetSize; i++) sum_logl[i] = 0;
181
182 for (unsigned k = 0; k < Const::ClusterDetectors::c_size; k++) {
183 cout << setw(7) << detectorName[k];
184 for (unsigned i = 0; i < Const::Cluster::c_SetSize; i++) {
185 cout << setw(10) << setprecision(4) << m_logl[k][i] << " ";
186 sum_logl[i] += m_logl[k][i];
187 }
188 cout << endl;
189 }
190
191 cout << hline << endl;
192
193 cout << setw(7) << "sum";
194 for (unsigned i = 0; i < Const::Cluster::c_SetSize; i++)
195 cout << setw(10) << setprecision(4) << sum_logl[i] << " ";
196 cout << endl;
197
198 if (isAvailable(Const::ECL) or isAvailable(Const::KLM)) {
199 unsigned k = 0;
200 for (unsigned i = 0; i < Const::Cluster::c_SetSize; i++)
201 if (sum_logl[i] > sum_logl[k]) k = i;
202 unsigned pos = 11 * (k + 1) + 3;
203 Hline.replace(pos, 1, "^");
204 }
205 cout << Hline << endl;
206
207}
bool isAvailable(Const::ClusterDetectorSet set) const
Check whether cluster information from a given set of detectors is available.
Definition: Cluster.h:50

◆ probability()

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

Calculate likelihood probabilities.

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

Definition at line 119 of file Cluster.cc.

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

◆ setLogLikelihood()

void setLogLikelihood ( Const::EDetector  det,
const Const::Cluster cluster,
float  logl 
)

Set log likelihood for a given detector and particle.

Parameters
detdetector enumerator
clustercluster
logllog likelihood

Definition at line 29 of file Cluster.cc.

32{
33 int index = Const::ClusterDetectors::set().getIndex(det);
34 if (index < 0) {
35 B2ERROR("ClusterLikelihood::setLogLikelihood: detector is not a cluster device");
36 return;
37 }
38 if (logl != logl or logl == INFINITY) {
39 B2ERROR("ClusterLikelihood::setLogLikelihood: log-likelihood for detector " << det << " is " << logl <<
40 " (i.e. +inf or NaN)! Ignoring this value. (" << Const::ECL << "=ECL, " << Const::KLM << "=KLM");
41
42 return;
43 }
44 m_detectors += det;
45 m_logl[index][part.getIndex()] = logl;
46}
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:387
int getIndex(EDetector det) const
Getter for the index of a given detector in this set.
Definition: UnitConst.cc:278

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 cluster information

Definition at line 138 of file Cluster.h.

◆ m_logl

log likelihoods

Definition at line 139 of file Cluster.h.


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