38#include <b2bii/modules/B2BIIMdstInput/B2BIIFixMdstModule.h>
39#include "belle_legacy/panther/panther.h"
40#include "belle_legacy/tables/mdst.h"
41#include "belle_legacy/tables/belletdf.h"
42#include "belle_legacy/belleutil/belutil.h"
43#include <framework/utilities/Spline.h>
72 B2INFO(
"%B2BIIFixMdst muid is initialized by basf with"
75 " ==> use value in data file" :
"")
77 << std::endl <<
" UseECL = "
79 << std::endl <<
" ExpNo = " <<
m_expno
81 " ==> use value in data file" :
""));
83 B2INFO(
"%B2BIIFixMdst muid is disabled by user (ExpNo = "
110 B2INFO(
"Reading DB constants for "
111 << ((expmc == 1) ?
"data" :
"MC") <<
", Exp #" << expno
112 <<
", Run #" << run);
135 Belle::Mdst_klm_mu_ex_Manager& muexMgr = Belle::Mdst_klm_mu_ex_Manager::get_manager();
141 if ((
void*)&muexMgr == NULL) {
142 B2ERROR(
"%B2BIIFixMdst muid did not find Belle::Mdst_klm_mu_ex table "
143 <<
"in this event, which implies" << std::endl
144 <<
" that muid_set and muid_dec were not run yet. "
145 <<
"Required order of modules is " << std::endl
146 <<
" ... muid_set muid_dec ... rec2mdst ... B2BIIFixMdst ..."
147 << std::endl <<
" This program is terminated.");
150 Belle::Mdst_ecl_trk_Manager& eclTrkMgr = Belle::Mdst_ecl_trk_Manager::get_manager();
151 Belle::Mdst_ecl_trk_Index eclTrkIdx = eclTrkMgr.index(
"trk");
161 for (std::vector<Belle::Mdst_klm_mu_ex>::iterator iMuex = muexMgr.begin();
162 iMuex < muexMgr.end(); ++iMuex) {
163 Belle::Mdst_charged& chg = iMuex->pMDST_Charged();
164 Belle::Mdst_muid& muid = chg.muid();
165 int ECMaxLyr = (muid.quality() & 0x400000) ? 1 : 0;
173 double px = chg.px();
174 double py = chg.py();
175 double pz = chg.pz();
176 double p =
sqrt(px * px + py * py + pz * pz);
177 double muon = iMuex->Muon_likelihood();
178 double pion = iMuex->Pion_likelihood();
179 double kaon = iMuex->Kaon_likelihood();
180 double miss = iMuex->Miss_likelihood();
181 double junk = iMuex->Junk_likelihood();
182 int outcome = iMuex->Outcome();
183 int lyrPasMax = iMuex->Layer_trk_brl() +
184 iMuex->Layer_trk_end() + 1;
185 int lyrPicMax = iMuex->Layer_hit_brl();
186 if (iMuex->Layer_hit_end() != -1) {
187 lyrPicMax = iMuex->Layer_trk_brl() +
188 iMuex->Layer_hit_end() + 1;
190 int lyrDiff = lyrPasMax - lyrPicMax;
191 int lyrExt = iMuex->Layer_trk_brl();
192 if ((outcome == 2) || (outcome == 4)) {
193 lyrExt = iMuex->Layer_trk_end();
194 if ((ECMaxLyr == 1) && (lyrExt > 11)) {
197 int lyrEnd = std::min(iMuex->Layer_hit_end(), 11);
198 lyrPasMax = iMuex->Layer_trk_brl() + lyrExt + 1;
199 lyrPicMax = iMuex->Layer_trk_brl() + lyrEnd + 1;
200 lyrDiff = lyrPasMax - lyrPicMax;
203 int nPoints = iMuex->N_hits() * 2;
204 double rChi2 = 1.0E10;
206 rChi2 = iMuex->Chi_2() / nPoints;
210 muon =
m_muonprob->
prob(ECMaxLyr, outcome, lyrExt, lyrDiff, rChi2);
211 pion =
m_pionprob->
prob(ECMaxLyr, outcome, lyrExt, lyrDiff, rChi2);
212 kaon =
m_kaonprob->
prob(ECMaxLyr, outcome, lyrExt, lyrDiff, rChi2);
213 double denom = muon + pion + kaon;
214 if (denom < 1.0E-10) {
216 muon = pion = kaon = 0.0;
224 Belle::Mdst_trk& trk = chg.trk();
225 std::vector<Belle::Mdst_ecl_trk> eclTrk = point_from(trk.get_ID(), eclTrkIdx);
226 std::vector<Belle::Mdst_ecl_trk>::iterator iEclTrk = eclTrk.begin();
227 if (iEclTrk != eclTrk.end()) {
228 Belle::Mdst_ecl& ecl = iEclTrk->ecl();
230 if (ecl.match() >= 1) {
231 double eEcl = ecl.energy();
232 if ((eEcl > 0.0) && (p > 0.25)) {
236 double denom = muonE + pionE + kaonE;
237 if (denom > 1.0E-10) {
238 if (miss + junk > 0.0) {
253 denom = muon + pion + kaon;
254 if (denom < 1.0E-10) {
256 muon = pion = kaon = 0.0;
268 iMuex->Muon_likelihood(muon);
269 iMuex->Pion_likelihood(pion);
270 iMuex->Kaon_likelihood(kaon);
271 iMuex->Miss_likelihood(miss);
272 iMuex->Junk_likelihood(junk);
273 iMuex->Outcome(outcome);
290 readDB(dbtemplate, expNo);
299 if (expNo == 0)
return;
301 if ((expNo < 5) || ((expNo & 1) == 0)) {
305 char dbname[] =
"muid_xxxx_e000000.dat";
306 std::string pathname =
"";
307 bool tmp = Belle::set_belfnm_verbose(
false);
308 while ((pathname ==
"") && (expNo >= 5)) {
309 std::sprintf(dbname,
"%s%s%s%06d%s",
"muid_", dbtemplate,
310 "_e", expNo,
".dat");
311 pathname = Belle::belfnm(dbname, 0,
"share/belle_legacy/data-files/muid");
314 (void)Belle::set_belfnm_verbose(tmp);
316 if (pathname ==
"") {
317 B2ERROR(
"%MuidProb: Failed to open database file."
318 <<
"Module B2BIIFixMdst muid will do nothing.");
323 std::ifstream probDB;
325 probDB.open(pathname.c_str());
326 probDB.get(ident, 80,
'\n');
327 B2INFO(
"%MuidProb: Reading file " << pathname
328 << std::endl <<
"%MuidProb: " << ident
329 << std::endl <<
"%MuidProb: ");
331 for (
int l = 0; l < 2; l++) {
333 for (
int k = 0; k < 4; k++) {
334 for (
int j = 0; j < 15; j++) {
335 for (
int i = 0; i <
kRange; i++) {
336 probDB >>
fRange[l][k][j][i];
342 for (
int k = 0; k < 4; k++) {
343 for (
int i = 0; i <
kRchisq; i++) {
349 for (
int k = 0; k < 4; k++) {
350 for (
int j = 0; j < 15; j++) {
357 for (
int k = 0; k <
kPTrk; k++) {
358 double probSum = 0.0;
359 for (
int i = 0; i <
kEEcl; i++) {
360 probDB >>
fEEcl[k][i];
361 probSum +=
fEEcl[k][i];
377 int lyr_ext,
int lyr_dif,
double chi2_red)
const
387 return probRange(ECMaxLyr, outcome, lyr_ext, lyr_dif) *
388 probRchisq(ECMaxLyr, outcome, lyr_ext, chi2_red);
404 if (outcome <= 0) {
return 0.0; }
405 if (outcome > 4) {
return 0.0; }
406 if (lyr_ext < 0) {
return 0.0; }
407 if (lyr_ext > 14) {
return 0.0; }
408 if (lyr_dif < 0) {
return 0.0; }
411 return fRange[ECMaxLyr][outcome - 1][lyr_ext][lyr_dif];
418 double chi2_red)
const
432 if (outcome <= 0) {
return 0.0; }
433 if (outcome > 4) {
return 0.0; }
434 if (lyr_ext < 0) {
return 0.0; }
435 if (lyr_ext > 14) {
return 0.0; }
436 if (chi2_red < 0.0) {
return 0.0; }
439 double area =
fRchisqN[ECMaxLyr][outcome - 1][lyr_ext];
441 prob = area *
fRchisq[ECMaxLyr][outcome - 1][
kRchisq - 1] + (1.0 - area);
445 prob =
fRchisq[ECMaxLyr][outcome - 1][i] +
446 dx * (
fRchisqD1[ECMaxLyr][outcome - 1][i] +
447 dx * (
fRchisqD2[ECMaxLyr][outcome - 1][i] +
448 dx *
fRchisqD3[ECMaxLyr][outcome - 1][i]));
449 prob = (prob < 0.0) ? 0.0 : area * prob;
469 prob =
fEEcl[jTrk][i] +
473 if (prob < 0.0) { prob = 0.0; }
void Muid_end_run(void)
Called when the current run ends.
int m_expno
parameter ExpNo: Experiment number for muid (default=0) 0 ==> use experiment number stored in data fi...
void Muid_init(void)
Initialize the Muid module.
void Muid_begin_run(const int, const int, const int)
Called for each new run.
MuidProb * m_kaonprob
Pointer to kaons' prob-density object.
int m_use_ecl
parameter UseECL: Use (1) or don't use (0) ECL in muid (default=0)
void Muid_event(void)
Called for each event.
MuidProb * m_pionprob
Pointer to pions' prob-density object.
void Muid_term(void)
Terminate the Muid module.
int m_mapped_expno
Mapped value of m_old_exp_no.
MuidProb * m_muonprob
Pointer to muons' prob-density object.
int m_old_expno
Most recently used experiment # in muid.
int m_eklm_max_layer
parameter Endcap_MX_layer: Max layer # of KLM endcap (default=11) 0 ==> use same value as was used by...
Class computes probability density for Muid calculation.
double fRchisq[2][4][kRchisq+1]
Reduced chi-squared pdf.
double fRchisqD2[2][4][kRchisq+1]
Second derivatives of Reduced chi-squared pdf.
static const int kRange
Array size of range.
double fRange[2][4][15][kRange]
Range pdf.
double probRange(int, int, int, int) const
Compute probability density for range.
double probECL(double, double) const
Compute probability density for ECL energy deposit.
double fRchisqD1[2][4][kRchisq+1]
First derivatives of Reduced chi-squared pdf.
double prob(int, int, int, int, double) const
Compute probability density.
double probRchisq(int, int, int, double) const
Compute probability density for reduced chi-squared.
MuidProb(const char *, int &)
Constructor.
static const int kRchisq
Array size of reduced chi-squared.
static const double kEEclMax
Overflow value of ECL energy.
double fEEclD1[kPTrk][kEEcl+1]
First derivatives of ECL energy pdf.
double fEEclD2[kPTrk][kEEcl+1]
Second derivatives of ECL energy pdf.
static const double kPTrkMax
Overflow value of CDC momentum.
double fEEclD3[kPTrk][kEEcl+1]
Third derivatives of ECL energy pdf.
double fRchisqN[2][4][15]
Non-overflow normalization.
static const int kEEcl
Array size of ECL energy.
double fRchisqD3[2][4][kRchisq+1]
Third derivatives of Reduced chi-squared pdf.
static const int kPTrk
Array size of CDC momentum.
static const double kRchisqMax
Overflow value of reduced chi-squared.
void readDB(const char *, int &)
Read in probability density functions from database.
double fEEcl[kPTrk][kEEcl+1]
ECL energy pdf.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.