9#include <mdst/dataobjects/PIDLikelihood.h>
10#include <framework/logging/Logger.h>
14#include <TParticlePDG.h>
39 B2ERROR(
"PIDLikelihood::setLogLikelihood: detector is not a PID device");
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)");
74 B2ERROR(
"PIDLikelihood::probability argument 'ratio' is given with negative value");
77 if (ratio == 0)
return 0;
82 double elogl = exp(dlogl);
83 res = ratio / (ratio + elogl);
85 double elogl = exp(-dlogl) * ratio;
86 res = elogl / (1.0 + elogl);
89 if (std::isfinite(res))
95 const double* fractions,
116 double maxProb = prob[k];
117 for (
unsigned i = 0; i < n; ++i) {
118 if (prob[i] > maxProb) {maxProb = prob[i]; k = i;}
126 const double* fractions,
132 for (
unsigned int i = 0; i < n; ++i) frac[i] = 1.0;
139 for (
unsigned i = 0; i < n; ++i) {
141 if (fractions[i] > 0) {
143 if (!hasMax || logL[i] > logLmax) {
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];
156 if (norm == 0)
return;
158 for (
unsigned i = 0; i < n; ++i) {
159 probabilities[i] /= norm;
169 {
"SVD",
"CDC",
"TOP",
"ARICH",
"ECL",
"KLM"};
170 string hline(
"-------");
172 hline +=
"-----------";
173 string Hline(
"=======");
175 Hline +=
"===========";
177 cout << Hline << endl;
184 cout << Hline << endl;
190 cout << setw(7) << detectorName[k];
192 cout << setw(10) << setprecision(4) <<
m_logl[k][i] <<
" ";
193 sum_logl[i] +=
m_logl[k][i];
198 cout << hline << endl;
200 cout << setw(7) <<
"sum";
202 cout << setw(10) << setprecision(4) << sum_logl[i] <<
" ";
209 if (sum_logl[i] > sum_logl[k]) k = i;
210 unsigned pos = 11 * (k + 1) + 3;
211 Hline.replace(pos, 1,
"^");
213 cout << Hline << endl;
221 std::stringstream stream;
222 stream << std::setprecision(4);
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();
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>";
239 stream <<
"<td bgcolor=\"" << colour[i] <<
"\" width=" << p * 100 <<
"%></td>";
241 stream <<
"</tr></table></td></tr>";
246 stream <<
"<tr><td>" << detectorName[it.getIndex()] <<
"</td><td>";
248 stream <<
"</td></tr>";
251 stream <<
"<table cellspacing=1 border=0 width=100%><tr>";
254 stream <<
"<td bgcolor=\"" << colour[i] <<
"\" width=" << p * 100 <<
"%></td>";
256 stream <<
"</tr></table></td></tr>";
258 stream <<
"</table>\n";
260 stream <<
"<b>Log-Likelihoods</b><br>";
262 stream <<
"<tr><th>PID / Detector</th>";
264 stream <<
"<th>" << detectorName[k] <<
"</th>";
270 stream <<
"<td>" <<
m_logl[k][i] <<
"</td>";
274 stream <<
"</table>";
Provides a type-safe way to pass members of the chargedStableSet 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.
static DetectorSet set()
Accessor function for the set of valid detectors.
static const size_t c_size
Number of PID detectors, temporary workaround.
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.
const TParticlePDG * getParticlePDG() const
Accessor for ROOT TParticlePDG object.
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 chargedStableSet
set of charged stable particles
EDetector
Enum for identifying the detector components (detector and subdetector).
PIDLikelihood()
Default constructor: log likelihoods and flags set to 0.
bool isAvailable(Const::PIDDetectorSet set) const
Check whether PID information from a given set of detectors is available.
std::string getInfoHTML() const override
Return HTML Info of PID Likelihoods.
float m_logl[Const::PIDDetectors::c_size][Const::ChargedStable::c_SetSize]
log likelihoods
void printArray() const
Prints the content of a private array of log likelihoods.
float getLogL(const Const::ChargedStable &part, Const::PIDDetectorSet set=Const::PIDDetectorSet::set()) const
Return log likelihood for a given detector set and particle.
void setLogLikelihood(Const::EDetector det, const Const::ChargedStable &part, float logl)
Set log likelihood for a given detector and particle.
void probability(double probabilities[], const double *fractions, Const::PIDDetectorSet detSet) const
Calculate likelihood probabilities.
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 probabil...
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...
Const::DetectorSet m_detectors
set of detectors with PID information
Abstract base class for different kinds of events.