9 #include <mdst/dataobjects/Cluster.h>
10 #include <framework/logging/Logger.h>
21 for (
unsigned short i = 0; i < Const::ClusterDetectors::c_size; i++) {
22 for (
unsigned int k = 0; k < Const::Cluster::c_SetSize; k++) {
33 int index = Const::ClusterDetectors::set().getIndex(det);
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");
45 m_logl[index][part.getIndex()] = logl;
54 it != Const::ClusterDetectorSet::set().end(); ++it) {
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;
73 double dlogl = getLogL(c2, set) - getLogL(c1, set);
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,
92 double prob[Const::Cluster::c_SetSize];
93 probability(prob, fractions, detSet);
95 int k = cluster.getIndex();
105 const unsigned int n = Const::Cluster::c_SetSize;
107 probability(prob, fractions, detSet);
110 double maxProb = prob[k];
111 for (
unsigned i = 0; i < n; ++i) {
112 if (prob[i] > maxProb) {maxProb = prob[i]; k = i;}
114 return Const::clusterSet.at(k);
119 void Cluster::probability(
double probabilities[],
120 const double* fractions,
123 const unsigned int n = Const::Cluster::c_SetSize;
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) {
136 logL[i] = getLogL(Const::clusterSet.at(i), detSet);
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;
159 void Cluster::printArray()
const
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 +=
"===========";
170 cout << Hline << endl;
173 for (
unsigned i = 0; i < Const::Cluster::c_SetSize; i++)
174 cout << setw(10) << Const::clusterSet.at(i).getPDGCode() <<
" ";
177 cout << Hline << endl;
179 float sum_logl[Const::Cluster::c_SetSize];
180 for (
unsigned i = 0; i < Const::Cluster::c_SetSize; i++) sum_logl[i] = 0;
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];
191 cout << hline << endl;
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] <<
" ";
198 if (isAvailable(Const::ECL) or isAvailable(Const::KLM)) {
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,
"^");
205 cout << Hline << endl;
209 std::string Cluster::getInfoHTML()
const
211 const string detectorName[Const::ClusterDetectors::c_size] = {
"ECL",
"KLM"};
213 std::stringstream stream;
214 stream << std::setprecision(4);
215 stream <<
"<b>Likelihoods</b><br>";
217 stream <<
"<tr><th>Cluster / Detector</th>";
218 for (
unsigned k = 0; k < Const::ClusterDetectors::c_size; k++)
219 stream <<
"<th>" << detectorName[k] <<
"</th>";
221 for (
unsigned i = 0; i < Const::Cluster::c_SetSize; i++) {
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>";
229 stream <<
"</table>";
Provides a type-safe way to pass members of the clusterSet set.
bool contains(const DetectorSet &set) const
Check whether this set contains another set.
A class for sets of detector IDs whose content is limited to restricted set of valid detector IDs.
EDetector
Enum for identifying the detector components (detector and subdetector).
Abstract base class for different kinds of events.