9#include <mdst/dataobjects/Cluster.h>
10#include <framework/logging/Logger.h>
35 B2ERROR(
"ClusterLikelihood::setLogLikelihood: detector is not a cluster device");
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");
56 result +=
m_logl[it.getIndex()][cluster.getIndex()];
68 B2ERROR(
"Cluster::probability argument 'ratio' is given with negative value");
71 if (ratio == 0)
return 0;
76 double elogl = exp(dlogl);
77 res = ratio / (ratio + elogl);
79 double elogl = exp(-dlogl) * ratio;
80 res = elogl / (1.0 + elogl);
83 if (std::isfinite(res))
89 const double* fractions,
95 int k = cluster.getIndex();
110 double maxProb = prob[k];
111 for (
unsigned i = 0; i < n; ++i) {
112 if (prob[i] > maxProb) {maxProb = prob[i]; k = i;}
120 const double* fractions,
126 for (
unsigned int i = 0; i < n; ++i) frac[i] = 1.0;
133 for (
unsigned i = 0; i < n; ++i) {
135 if (fractions[i] > 0) {
137 if (!hasMax || logL[i] > logLmax) {
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];
150 if (norm == 0)
return;
152 for (
unsigned i = 0; i < n; ++i) {
153 probabilities[i] /= norm;
163 string hline(
"-------");
165 hline +=
"-----------";
166 string Hline(
"=======");
168 Hline +=
"===========";
170 cout << Hline << endl;
177 cout << Hline << endl;
183 cout << setw(7) << detectorName[k];
185 cout << setw(10) << setprecision(4) <<
m_logl[k][i] <<
" ";
186 sum_logl[i] +=
m_logl[k][i];
191 cout << hline << endl;
193 cout << setw(7) <<
"sum";
195 cout << setw(10) << setprecision(4) << sum_logl[i] <<
" ";
201 if (sum_logl[i] > sum_logl[k]) k = i;
202 unsigned pos = 11 * (k + 1) + 3;
203 Hline.replace(pos, 1,
"^");
205 cout << Hline << endl;
213 std::stringstream stream;
214 stream << std::setprecision(4);
215 stream <<
"<b>Likelihoods</b><br>";
217 stream <<
"<tr><th>Cluster / Detector</th>";
219 stream <<
"<th>" << detectorName[k] <<
"</th>";
225 stream <<
"<td>" <<
m_logl[k][i] <<
"</td>";
229 stream <<
"</table>";
Cluster()
Default constructor: log likelihoods and flags set to 0.
bool isAvailable(Const::ClusterDetectorSet set) const
Check whether cluster information from a given set of detectors is available.
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 ...
float getLogL(const Const::Cluster &cluster, Const::ClusterDetectorSet set=Const::ClusterDetectorSet::set()) const
Return log likelihood for a given detector set and particle.
void probability(double probabilities[], const double *fractions, Const::ClusterDetectorSet detSet) const
Calculate likelihood probabilities.
std::string getInfoHTML() const override
Return HTML Info of cluster Likelihoods.
float m_logl[Const::ClusterDetectors::c_size][Const::Cluster::c_SetSize]
log likelihoods
void printArray() const
Prints the content of a private array of log likelihoods.
void setLogLikelihood(Const::EDetector det, const Const::Cluster &cluster, float logl)
Set log likelihood for a given detector and particle.
Const::DetectorSet m_detectors
set of detectors with cluster information
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...
static DetectorSet set()
Accessor function for the set of valid detectors.
static const size_t c_size
Number of PID detectors, temporary workaround.
Provides a type-safe way to pass members of the clusterSet set.
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
int getIndex(EDetector det) const
Getter for the index of a given detector in this set.
Iterator end() const
Ending iterator.
bool contains(const DetectorSet &set) const
Check whether this set contains another set.
const ParticleType & at(unsigned int index) const
Return particle at given index, or end() if out of range.
int getPDGCode() const
PDG code.
int getIndex() const
This particle's index in the associated set.
A class for sets of detector IDs whose content is limited to restricted set of valid detector IDs.
static DetectorSet set()
Accessor for the set of valid detector IDs.
static const ParticleSet clusterSet
set of cluster particles
EDetector
Enum for identifying the detector components (detector and subdetector).
Abstract base class for different kinds of events.