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;
53 for (
unsigned int index = 0; index < Const::ClusterDetectorSet::set().size(); ++index) {
54 if (set.
contains(Const::ClusterDetectorSet::set()[index]))
55 result += m_logl[index][cluster.getIndex()];
67 B2ERROR(
"Cluster::probability argument 'ratio' is given with negative value");
70 if (ratio == 0)
return 0;
72 double dlogl = getLogL(c2, set) - getLogL(c1, set);
75 double elogl = exp(dlogl);
76 res = ratio / (ratio + elogl);
78 double elogl = exp(-dlogl) * ratio;
79 res = elogl / (1.0 + elogl);
82 if (std::isfinite(res))
88 const double* fractions,
91 double prob[Const::Cluster::c_SetSize];
92 probability(prob, fractions, detSet);
94 int k = cluster.getIndex();
104 const unsigned int n = Const::Cluster::c_SetSize;
106 probability(prob, fractions, detSet);
109 double maxProb = prob[k];
110 for (
unsigned i = 0; i < n; ++i) {
111 if (prob[i] > maxProb) {maxProb = prob[i]; k = i;}
113 return Const::clusterSet.at(k);
118 void Cluster::probability(
double probabilities[],
119 const double* fractions,
122 const unsigned int n = Const::Cluster::c_SetSize;
125 for (
unsigned int i = 0; i < n; ++i) frac[i] = 1.0;
132 for (
unsigned i = 0; i < n; ++i) {
134 if (fractions[i] > 0) {
135 logL[i] = getLogL(Const::clusterSet.at(i), detSet);
136 if (!hasMax || logL[i] > logLmax) {
144 for (
unsigned i = 0; i < n; ++i) {
145 probabilities[i] = 0;
146 if (fractions[i] > 0) probabilities[i] = exp(logL[i] - logLmax) * fractions[i];
147 norm += probabilities[i];
149 if (norm == 0)
return;
151 for (
unsigned i = 0; i < n; ++i) {
152 probabilities[i] /= norm;
158 void Cluster::printArray()
const
161 string detectorName[Const::ClusterDetectors::c_size] = {
"ECL",
"KLM"};
162 string hline(
"-------");
163 for (
unsigned i = 0; i < Const::Cluster::c_SetSize; i++)
164 hline +=
"-----------";
165 string Hline(
"=======");
166 for (
unsigned i = 0; i < Const::Cluster::c_SetSize; i++)
167 Hline +=
"===========";
169 cout << Hline << endl;
172 for (
unsigned i = 0; i < Const::Cluster::c_SetSize; i++)
173 cout << setw(10) << Const::clusterSet.at(i).getPDGCode() <<
" ";
176 cout << Hline << endl;
178 float sum_logl[Const::Cluster::c_SetSize];
179 for (
unsigned i = 0; i < Const::Cluster::c_SetSize; i++) sum_logl[i] = 0;
181 for (
unsigned k = 0; k < Const::ClusterDetectors::c_size; k++) {
182 cout << setw(7) << detectorName[k];
183 for (
unsigned i = 0; i < Const::Cluster::c_SetSize; i++) {
184 cout << setw(10) << setprecision(4) << m_logl[k][i] <<
" ";
185 sum_logl[i] += m_logl[k][i];
190 cout << hline << endl;
192 cout << setw(7) <<
"sum";
193 for (
unsigned i = 0; i < Const::Cluster::c_SetSize; i++)
194 cout << setw(10) << setprecision(4) << sum_logl[i] <<
" ";
197 if (isAvailable(Const::ECL) or isAvailable(Const::KLM)) {
199 for (
unsigned i = 0; i < Const::Cluster::c_SetSize; i++)
200 if (sum_logl[i] > sum_logl[k]) k = i;
201 unsigned pos = 11 * (k + 1) + 3;
202 Hline.replace(pos, 1,
"^");
204 cout << Hline << endl;
208 std::string Cluster::getInfoHTML()
const
210 string detectorName[Const::ClusterDetectors::c_size] = {
"ECL",
"KLM"};
212 std::stringstream stream;
213 stream << std::setprecision(4);
214 stream <<
"<b>Likelihoods</b><br>";
216 stream <<
"<tr><th>Cluster / Detector</th>";
217 for (
unsigned k = 0; k < Const::ClusterDetectors::c_size; k++)
218 stream <<
"<th>" << detectorName[k] <<
"</th>";
220 for (
unsigned i = 0; i < Const::Cluster::c_SetSize; i++) {
222 stream <<
"<td>" << Const::clusterSet.at(i).getPDGCode() <<
"</td>";
223 for (
unsigned k = 0; k < Const::ClusterDetectors::c_size; k++) {
224 stream <<
"<td>" << m_logl[k][i] <<
"</td>";
228 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.