130 #include <b2bii/modules/B2BIIMdstInput/B2BIIFixMdstModule.h>
132 #include "belle_legacy/panther/panther.h"
137 #include "belle_legacy/ip/IpProfile.h"
139 #include "belle_legacy/benergy/BeamEnergy.h"
141 #include "belle_legacy/tables/mdst.h"
142 #include "belle_legacy/tables/belletdf.h"
143 #include "belle_legacy/tables/evtcls.h"
144 #include "belle_legacy/kid/dEdxCalib.h"
145 #include "belle_legacy/tables/level4.h"
155 #define NOMINAL_ENERGY 5.290024915
162 setDescription(
"Used to fix the old Belle I mdst files before processing. This module was taken from the old Belle I code and converted into a basf2 module."
163 "There are a lot of magic numbers in this module, where do they come from? Noone knows..."
164 "Return value is -1 if something went wrong, do not use these events!");
174 "1: add to Mdst_charged etc, -1: remove (move to Mdst_*_extra), 0:do nothing", 0);
202 addParam(
"ExpNo",
m_expno,
"Use data's exp # (0) or this value (>0) in muid", 0);
227 if ((BsCouTab(BELLE_EVENT) == 0) || (BsCouTab(MDST_EVENT_ADD) == 0)) {
228 B2INFO(
"Warning from B2BIIFixMdst: No Belle_event or Mdst_event_add table; no correction for event");
250 CLHEP::HepSymMatrix dpv(3, 0);
273 B2DEBUG(99,
"B2BIIFixMdst: Not a good event");
281 if (BsCouTab(L4_SUMMARY)) {
282 struct l4_summary* l =
283 (
struct l4_summary*) BsGetEnt(L4_SUMMARY, 1, BBS_No_Index);
284 if (l->m_type == 0) {
286 B2DEBUG(99,
"B2BIIFixMdst: L4 cut");
293 Belle::Evtcls_flag_Manager& EvtFlagMgr = Belle::Evtcls_flag_Manager::get_manager();
294 Belle::Evtcls_flag_Manager::iterator it1 = EvtFlagMgr.begin();
295 if (it1 != EvtFlagMgr.end() && *it1) {
296 if ((*it1).flag(0) < 10) {
298 B2DEBUG(99,
"B2BIIFixMdst: HadA cut");
305 Belle::Evtcls_hadronic_flag_Manager& HadMgr
306 = Belle::Evtcls_hadronic_flag_Manager::get_manager();
307 Belle::Evtcls_hadronic_flag_Manager::iterator ith = HadMgr.begin();
308 if (ith != HadMgr.end() && *ith) {
309 if ((*ith).hadronic_flag(2) <= 0) {
311 B2DEBUG(99,
"B2BIIFixMdst: HadB cut");
318 Belle::Belle_event_Manager& bevt = Belle::Belle_event_Manager::get_manager();
324 B2INFO(
"B2BIIFixMdst: " << Belle::Mdst_ecl_trk_Manager::get_manager().count() <<
" " <<
m_limit_mdst_ecl_trk);
327 if (Belle::Mdst_klm_cluster_hit_Manager::get_manager().count()
337 Belle::Belle_event_Manager& bevt = Belle::Belle_event_Manager::get_manager();
356 Belle::IpProfile::begin_run();
360 Belle::Belle_runhead_Manager& evtmgr = Belle::Belle_runhead_Manager::get_manager();
361 Belle::Belle_runhead_Manager::const_iterator belleevt = evtmgr.begin();
362 if (belleevt != evtmgr.end() && (*belleevt)) {
363 int expmc = belleevt->ExpMC();
364 int exp = belleevt->ExpNo();
365 int run = belleevt->RunNo();
369 char* env = std::getenv(
"USE_GRAND_REPROCESS_DATA");
372 B2ERROR(
"Env. variable USE_GRAND_REPROCESS_DATA and input mdst reprocess version=" <<
m_reprocess_version <<
373 " (=0:old; =1:new) are inconsistent -> kill the job. Set USE_GRAND_REPROCESS_DATA or input mdst file properly and retry.");
386 B2ERROR(
"[B2BIIFixMdst] Error: Cannot read \"Belle::Belle_RunHead\".");
395 Belle::Belle_version_Manager& bvmgr = Belle::Belle_version_Manager::get_manager();
400 B2INFO(
"reprocess version forcedly set to " << version);
404 Belle::Belle_processing_Manager& bpmgr = Belle::Belle_processing_Manager::get_manager();
405 Belle::Belle_runhead_Manager& evtmgr = Belle::Belle_runhead_Manager::get_manager();
406 Belle::Belle_runhead_Manager::const_iterator belleevt = evtmgr.begin();
408 int expmc(0), exp(0), run(0);
409 if (belleevt != evtmgr.end() && (*belleevt)) {
410 expmc = belleevt->ExpMC();
411 exp = belleevt->ExpNo();
412 run = belleevt->RunNo();
417 if (bpmgr.count() > 0) {
418 int i = bpmgr.count() - 1;
419 B_l_d = bpmgr[i].Belle_level_date();
423 if (bvmgr.count() > 0) {
427 int chk = std::abs(bvmgr[j].SVD())
428 + std::abs(bvmgr[j].CDC())
429 + std::abs(bvmgr[j].ECL());
437 if (expmc == 2 || (expmc == 1
438 && B_l_d > 20081107))
439 B2ERROR(
"No Belle::Belle_version table in run-header for MC or (Data processed with Belle_level > 20081107). Strange !");
441 if (B_l_d == 20081107) {
445 if (exp == 65 && run >= 1000) version = 0;
452 if (bvmgr.count() == 0) {
453 Belle::Belle_version& bv = bvmgr.add();
457 }
else if (bvmgr.count() > 0) {
458 if (bvmgr[0].SVD() != version) {
459 B2WARNING(
"Belle::Belle_version_SVD(=" << bvmgr[0].SVD() <<
") is inconsistent with version(=" << version <<
460 "); replace it anyway");
461 bvmgr[0].SVD(version);
463 if (bvmgr[0].CDC() != version) {
464 B2WARNING(
"Belle::Belle_version_CDC(=" << bvmgr[0].CDC() <<
") is inconsistent with version(=" << version <<
465 "); replace it anyway");
466 bvmgr[0].CDC(version);
468 if (bvmgr[0].ECL() != version) {
469 B2WARNING(
"Belle::Belle_version_ECL(=" << bvmgr[0].ECL() <<
") is inconsistent with version(=" << version <<
470 "); replace it anyway");
471 bvmgr[0].ECL(version);
483 Belle::Mdst_quality_Manager& qmgr = Belle::Mdst_quality_Manager::get_manager();
484 if (0 == qmgr.count())
return ret;
486 for (std::vector<Belle::Mdst_quality>::iterator it = qmgr.begin();
487 it != qmgr.end(); ++it) {
488 Belle::Mdst_quality& q = *it;
489 std::string c(q.name()());
492 if ((strcmp(c.c_str(),
"SVD ") == 0) && (q.quality() & 0x8002)) ret =
false;
513 double factor(0.001);
517 Belle::Belle_event_Manager& bevt_mgr = Belle::Belle_event_Manager::get_manager();
518 Belle::Belle_event_Manager::const_iterator bevt = bevt_mgr.begin();
519 if (bevt != bevt_mgr.end() && (*bevt)) {
520 if (bevt->ExpMC() == 1) energy = Belle::BeamEnergy::E_beam2();
521 if (bevt->ExpMC() == 2) {
529 if ((expnum == 0 || runnum == 0) && BsCouTab(BELLE_EVENT) > 0) {
530 Belle::Belle_event& bevt = Belle::Belle_event_Manager::get_manager()[0];
531 if (bevt.ExpMC() == 1) {
532 expnum = bevt.ExpNo();
533 runnum = bevt.RunNo();
538 if (runnum >= 74 && runnum <= 472) energy += -0.540 * factor;
539 }
else if (expnum == 7) {
540 if (runnum >= 6 && runnum <= 475) energy += 0.305 * factor;
541 else if (runnum >= 538 && runnum <= 895) energy += -1.016 * factor;
542 else if (runnum >= 904 && runnum <= 1079) energy += -1.065 * factor;
543 else if (runnum >= 1101 && runnum <= 1248) energy += -0.608 * factor;
544 else if (runnum >= 1257 && runnum <= 1399) energy += -1.132 * factor;
545 else if (runnum >= 1400 && runnum <= 1599) energy += -1.446 * factor;
546 else if (runnum >= 1600 && runnum <= 1799) energy += -1.836 * factor;
547 else if (runnum >= 1800 && runnum <= 1999) energy += -1.829 * factor;
548 else if (runnum >= 2000 && runnum <= 2156) energy += -1.732 * factor;
549 else if (runnum >= 2294 && runnum <= 2599) energy += -2.318 * factor;
550 else if (runnum >= 2600 && runnum <= 2865) energy += -1.363 * factor;
551 }
else if (expnum == 9) {
552 if (runnum >= 17 && runnum <= 399) energy += -2.767 * factor;
553 else if (runnum >= 400 && runnum <= 499) energy += -2.826 * factor;
554 else if (runnum >= 500 && runnum <= 593) energy += -2.311 * factor;
555 else if (runnum >= 601 && runnum <= 699) energy += -2.138 * factor;
556 else if (runnum >= 700 && runnum <= 899) energy += -2.267 * factor;
557 else if (runnum >= 900 && runnum <= 999) energy += -2.412 * factor;
558 else if (runnum >= 1000 && runnum <= 1099) energy += -2.229 * factor;
559 else if (runnum >= 1100 && runnum <= 1220) energy += -1.842 * factor;
561 }
else if (expnum == 11) {
562 if (runnum >= 1 && runnum <= 161) energy += -2.173 * factor;
563 if (runnum >= 261 && runnum <= 399) energy += -1.392 * factor;
564 if (runnum >= 400 && runnum <= 499) energy += -1.321 * factor;
565 if (runnum >= 500 && runnum <= 599) energy += -1.394 * factor;
566 if (runnum >= 600 && runnum <= 699) energy += -1.827 * factor;
567 if (runnum >= 700 && runnum <= 799) energy += -1.912 * factor;
568 if (runnum >= 800 && runnum <= 899) energy += -1.603 * factor;
569 if (runnum >= 900 && runnum <= 998) energy += -1.759 * factor;
570 if (runnum >= 1001 && runnum <= 1099) energy += -1.915 * factor;
571 if (runnum >= 1100 && runnum <= 1199) energy += -1.513 * factor;
572 if (runnum >= 1200 && runnum <= 1287) energy += -0.639 * factor;
573 }
else if (expnum == 13) {
574 if (runnum >= 1 && runnum <= 99) energy += 0.279 * factor;
575 if (runnum >= 100 && runnum <= 198) energy += 0.140 * factor;
576 if (runnum >= 200 && runnum <= 297) energy += -0.095 * factor;
577 if (runnum >= 301 && runnum <= 440) energy += 0.232 * factor;
578 if (runnum >= 551 && runnum <= 699) energy += -0.385 * factor;
579 if (runnum >= 700 && runnum <= 799) energy += -0.654 * factor;
580 if (runnum >= 800 && runnum <= 899) energy += -0.972 * factor;
581 if (runnum >= 900 && runnum <= 999) energy += -0.770 * factor;
582 if (runnum >= 1000 && runnum <= 1099) energy += -0.353 * factor;
583 if (runnum >= 1100 && runnum <= 1199) energy += -0.490 * factor;
584 if (runnum >= 1200 && runnum <= 1299) energy += -0.687 * factor;
585 if (runnum >= 1300 && runnum <= 1399) energy += -0.545 * factor;
587 if (runnum >= 1400) energy += -0.783 * factor;
592 }
else if (expnum == 15) {
598 if (runnum < 764) energy = 5.288103;
599 if (runnum > 763 && runnum < 951) energy = 5.287005;
600 if (runnum > 950 && runnum < 1251) energy = 5.287804;
601 if (runnum > 1250) energy = 5.288603;
603 }
else if (expnum == 17) {
604 if (runnum <= 199) energy = 5.288702;
605 if (runnum >= 200 && runnum <= 399) energy = 5.289202;
606 if (runnum >= 400 && runnum <= 485) energy = 5.289401;
607 if (runnum >= 545 && runnum <= 799) energy = 5.289501;
608 if (runnum >= 800 && runnum <= 937) energy = 5.289401;
610 }
else if (expnum == 19) {
611 if (runnum >= 64 && runnum <= 199) energy = 5.2887023;
612 if (runnum >= 200 && runnum <= 299) energy = 5.2886025;
613 if (runnum >= 300 && runnum <= 399) energy = 5.28830299;
614 if (runnum >= 400 && runnum <= 459) energy = 5.28820313;
615 if (runnum >= 461 && runnum <= 599) energy = 5.28830299;
616 if (runnum >= 600 && runnum <= 666) energy = 5.28780366;
617 if (runnum >= 763 && runnum <= 999) energy = 5.28820313;
618 if (runnum >= 1000 && runnum <= 1099) energy = 5.28780366;
619 if (runnum >= 1100 && runnum <= 1199) energy = 5.28770378;
620 if (runnum >= 1200 && runnum <= 1399) energy = 5.28750402;
621 if (runnum >= 1400 && runnum <= 1499) energy = 5.28740413;
622 if (runnum >= 1500 && runnum <= 1599) energy = 5.28720434;
623 if (runnum >= 1600 && runnum <= 1643) energy = 5.28760390;
628 }
else if (expnum == 21) {
629 if (runnum >= 0 && runnum <= 180) energy = 5.28650496;
630 if (runnum >= 181 && runnum <= 324) energy = 5.2880034;
631 }
else if (expnum == 23) {
632 if (runnum >= 0 && runnum <= 238) energy = 5.28860254;
633 if (runnum >= 357 && runnum <= 607) energy = 5.28880222;
637 }
else if (expnum == 25) {
638 if (runnum >= 0 && runnum <= 99) energy = 5.28950099;
639 if (runnum >= 100 && runnum <= 199) energy = 5.28870238;
640 if (runnum >= 200 && runnum <= 299) energy = 5.28910171;
641 if (runnum >= 300 && runnum <= 399) energy = 5.28890205;
642 if (runnum >= 400 && runnum <= 799) energy = 5.28850269;
643 if (runnum >= 800 && runnum <= 899) energy = 5.28790353;
644 if (runnum >= 900 && runnum <= 999) energy = 5.28810326;
645 if (runnum >= 1000 && runnum <= 1099) energy = 5.28830298;
646 if (runnum >= 1100 && runnum <= 1199) energy = 5.28820313;
647 if (runnum >= 1200 && runnum <= 1299) energy = 5.28780366;
648 if (runnum >= 1300 && runnum <= 1462) energy = 5.28820313;
649 if (runnum >= 1600 && runnum <= 1699) energy = 5.28830299;
650 if (runnum >= 1700 && runnum <= 1799) energy = 5.28780366;
651 if (runnum >= 1800 && runnum <= 1899) energy = 5.28810327;
652 if (runnum >= 1900 && runnum <= 2122) energy = 5.28830299;
656 }
else if (expnum == 27) {
657 if (runnum >= 0 && runnum <= 180) energy = 5.28860254;
658 if (runnum >= 181 && runnum <= 288) energy = 5.28870238;
659 if (runnum >= 367 && runnum <= 499) energy = 5.28880222;
660 if (runnum >= 500 && runnum <= 590) energy = 5.28890206;
661 if (runnum >= 591 && runnum <= 699) energy = 5.28910172;
662 if (runnum >= 700 && runnum <= 1079) energy = 5.28900189;
663 if (runnum >= 1252 && runnum <= 1299) energy = 5.28850269;
664 if (runnum >= 1300 && runnum <= 1632) energy = 5.28870238;
668 }
else if (expnum == 31) {
669 if (runnum >= 0 && runnum <= 166) energy = 5.287404131;
670 if (runnum >= 231 && runnum <= 470) energy = 5.287903534;
671 if (runnum >= 471 && runnum <= 698) energy = 5.28810327;
672 if (runnum >= 699 && runnum <= 804) energy = 5.288602541;
673 if (runnum >= 805 && runnum <= 936) energy = 5.288702384;
674 if (runnum >= 1071 && runnum <= 1440) energy = 5.288902;
675 if (runnum >= 1441 && runnum <= 1715) energy = 5.289301;
677 }
else if (expnum >= 32) {
678 B2ERROR(
"Warning: Benergy is not ready for exp >=32.");