137#include <b2bii/modules/B2BIIMdstInput/B2BIIFixMdstModule.h>
139#include "belle_legacy/panther/panther.h"
144#include "belle_legacy/ip/IpProfile.h"
146#include "belle_legacy/benergy/BeamEnergy.h"
148#include "belle_legacy/tables/mdst.h"
149#include "belle_legacy/tables/belletdf.h"
150#include "belle_legacy/tables/evtcls.h"
151#include "belle_legacy/kid/dEdxCalib.h"
152#include "belle_legacy/tables/level4.h"
162#define NOMINAL_ENERGY 5.290024915
169 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."
170 "There are a lot of magic numbers in this module, where do they come from? No one knows..."
171 "Return value is -1 if something went wrong, do not use these events!");
181 "1: add to Mdst_charged etc, -1: remove (move to Mdst_*_extra), 0:do nothing", 0);
209 addParam(
"ExpNo",
m_expno,
"Use data's exp # (0) or this value (>0) in muid", 0);
220 "Whether to save result as EventExtraInfo.",
false);
242 if ((BsCouTab(BELLE_EVENT) == 0) || (BsCouTab(MDST_EVENT_ADD) == 0)) {
243 B2INFO(
"Warning from B2BIIFixMdst: No Belle_event or Mdst_event_add table; no correction for event");
267 CLHEP::HepSymMatrix dpv(3, 0);
292 B2DEBUG(99,
"B2BIIFixMdst: Not a good event");
300 if (BsCouTab(L4_SUMMARY)) {
301 struct l4_summary* l =
302 (
struct l4_summary*) BsGetEnt(L4_SUMMARY, 1, BBS_No_Index);
303 if (l->m_type == 0) {
307 B2DEBUG(99,
"B2BIIFixMdst: L4 cut");
314 Belle::Evtcls_flag_Manager& EvtFlagMgr = Belle::Evtcls_flag_Manager::get_manager();
315 Belle::Evtcls_flag_Manager::iterator it1 = EvtFlagMgr.begin();
316 if (it1 != EvtFlagMgr.end() && *it1) {
317 if ((*it1).flag(0) < 10) {
321 B2DEBUG(99,
"B2BIIFixMdst: HadA cut");
328 Belle::Evtcls_hadronic_flag_Manager& HadMgr
329 = Belle::Evtcls_hadronic_flag_Manager::get_manager();
330 Belle::Evtcls_hadronic_flag_Manager::iterator ith = HadMgr.begin();
331 if (ith != HadMgr.end() && *ith) {
332 if ((*ith).hadronic_flag(2) <= 0) {
336 B2DEBUG(99,
"B2BIIFixMdst: HadB cut");
343 Belle::Belle_event_Manager& bevt = Belle::Belle_event_Manager::get_manager();
351 B2INFO(
"B2BIIFixMdst: " << Belle::Mdst_ecl_trk_Manager::get_manager().count() <<
" " <<
m_limit_mdst_ecl_trk);
354 if (Belle::Mdst_klm_cluster_hit_Manager::get_manager().count()
366 Belle::Belle_event_Manager& bevt = Belle::Belle_event_Manager::get_manager();
387 Belle::IpProfile::begin_run();
391 Belle::Belle_runhead_Manager& evtmgr = Belle::Belle_runhead_Manager::get_manager();
392 Belle::Belle_runhead_Manager::const_iterator belleevt = evtmgr.begin();
393 if (belleevt != evtmgr.end() && (*belleevt)) {
394 int expmc = belleevt->ExpMC();
395 int exp = belleevt->ExpNo();
396 int run = belleevt->RunNo();
400 char* env = std::getenv(
"USE_GRAND_REPROCESS_DATA");
403 B2ERROR(
"Env. variable USE_GRAND_REPROCESS_DATA and input mdst reprocess version=" <<
m_reprocess_version <<
404 " (=0:old; =1:new) are inconsistent -> kill the job. Set USE_GRAND_REPROCESS_DATA or input mdst file properly and retry.");
417 B2ERROR(
"[B2BIIFixMdst] Error: Cannot read \"Belle::Belle_RunHead\".");
426 Belle::Belle_version_Manager& bvmgr = Belle::Belle_version_Manager::get_manager();
431 B2INFO(
"reprocess version forcedly set to " << version);
435 Belle::Belle_processing_Manager& bpmgr = Belle::Belle_processing_Manager::get_manager();
436 Belle::Belle_runhead_Manager& evtmgr = Belle::Belle_runhead_Manager::get_manager();
437 Belle::Belle_runhead_Manager::const_iterator belleevt = evtmgr.begin();
439 int expmc(0), exp(0), run(0);
440 if (belleevt != evtmgr.end() && (*belleevt)) {
441 expmc = belleevt->ExpMC();
442 exp = belleevt->ExpNo();
443 run = belleevt->RunNo();
448 if (bpmgr.count() > 0) {
449 int i = bpmgr.count() - 1;
450 B_l_d = bpmgr[i].Belle_level_date();
454 if (bvmgr.count() > 0) {
458 int chk = std::abs(bvmgr[j].SVD())
459 + std::abs(bvmgr[j].CDC())
460 + std::abs(bvmgr[j].ECL());
468 if (expmc == 2 || (expmc == 1
469 && B_l_d > 20081107))
470 B2ERROR(
"No Belle::Belle_version table in run-header for MC or (Data processed with Belle_level > 20081107). Strange !");
472 if (B_l_d == 20081107) {
476 if (exp == 65 && run >= 1000) version = 0;
483 if (bvmgr.count() == 0) {
484 Belle::Belle_version& bv = bvmgr.add();
488 }
else if (bvmgr.count() > 0) {
489 if (bvmgr[0].SVD() != version) {
490 B2WARNING(
"Belle::Belle_version_SVD(=" << bvmgr[0].SVD() <<
") is inconsistent with version(=" << version <<
491 "); replace it anyway");
492 bvmgr[0].SVD(version);
494 if (bvmgr[0].CDC() != version) {
495 B2WARNING(
"Belle::Belle_version_CDC(=" << bvmgr[0].CDC() <<
") is inconsistent with version(=" << version <<
496 "); replace it anyway");
497 bvmgr[0].CDC(version);
499 if (bvmgr[0].ECL() != version) {
500 B2WARNING(
"Belle::Belle_version_ECL(=" << bvmgr[0].ECL() <<
") is inconsistent with version(=" << version <<
501 "); replace it anyway");
502 bvmgr[0].ECL(version);
514 Belle::Mdst_quality_Manager& qmgr = Belle::Mdst_quality_Manager::get_manager();
515 if (0 == qmgr.count())
return ret;
517 for (std::vector<Belle::Mdst_quality>::iterator it = qmgr.begin();
518 it != qmgr.end(); ++it) {
519 Belle::Mdst_quality& q = *it;
520 std::string c(q.name()());
523 if ((strcmp(c.c_str(),
"SVD ") == 0) && (q.quality() & 0x8002)) ret =
false;
544 double factor(0.001);
548 Belle::Belle_event_Manager& bevt_mgr = Belle::Belle_event_Manager::get_manager();
549 Belle::Belle_event_Manager::const_iterator bevt = bevt_mgr.begin();
550 if (bevt != bevt_mgr.end() && (*bevt)) {
551 if (bevt->ExpMC() == 1) energy = Belle::BeamEnergy::E_beam2();
552 if (bevt->ExpMC() == 2) {
554 else energy = Belle::BeamEnergy::E_beam2();
560 if ((expnum == 0 || runnum == 0) && BsCouTab(BELLE_EVENT) > 0) {
561 Belle::Belle_event& bevt = Belle::Belle_event_Manager::get_manager()[0];
562 if (bevt.ExpMC() == 1) {
563 expnum = bevt.ExpNo();
564 runnum = bevt.RunNo();
569 if (runnum >= 74 && runnum <= 472) energy += -0.540 * factor;
570 }
else if (expnum == 7) {
571 if (runnum >= 6 && runnum <= 475) energy += 0.305 * factor;
572 else if (runnum >= 538 && runnum <= 895) energy += -1.016 * factor;
573 else if (runnum >= 904 && runnum <= 1079) energy += -1.065 * factor;
574 else if (runnum >= 1101 && runnum <= 1248) energy += -0.608 * factor;
575 else if (runnum >= 1257 && runnum <= 1399) energy += -1.132 * factor;
576 else if (runnum >= 1400 && runnum <= 1599) energy += -1.446 * factor;
577 else if (runnum >= 1600 && runnum <= 1799) energy += -1.836 * factor;
578 else if (runnum >= 1800 && runnum <= 1999) energy += -1.829 * factor;
579 else if (runnum >= 2000 && runnum <= 2156) energy += -1.732 * factor;
580 else if (runnum >= 2294 && runnum <= 2599) energy += -2.318 * factor;
581 else if (runnum >= 2600 && runnum <= 2865) energy += -1.363 * factor;
582 }
else if (expnum == 9) {
583 if (runnum >= 17 && runnum <= 399) energy += -2.767 * factor;
584 else if (runnum >= 400 && runnum <= 499) energy += -2.826 * factor;
585 else if (runnum >= 500 && runnum <= 593) energy += -2.311 * factor;
586 else if (runnum >= 601 && runnum <= 699) energy += -2.138 * factor;
587 else if (runnum >= 700 && runnum <= 899) energy += -2.267 * factor;
588 else if (runnum >= 900 && runnum <= 999) energy += -2.412 * factor;
589 else if (runnum >= 1000 && runnum <= 1099) energy += -2.229 * factor;
590 else if (runnum >= 1100 && runnum <= 1220) energy += -1.842 * factor;
592 }
else if (expnum == 11) {
593 if (runnum >= 1 && runnum <= 161) energy += -2.173 * factor;
594 if (runnum >= 261 && runnum <= 399) energy += -1.392 * factor;
595 if (runnum >= 400 && runnum <= 499) energy += -1.321 * factor;
596 if (runnum >= 500 && runnum <= 599) energy += -1.394 * factor;
597 if (runnum >= 600 && runnum <= 699) energy += -1.827 * factor;
598 if (runnum >= 700 && runnum <= 799) energy += -1.912 * factor;
599 if (runnum >= 800 && runnum <= 899) energy += -1.603 * factor;
600 if (runnum >= 900 && runnum <= 998) energy += -1.759 * factor;
601 if (runnum >= 1001 && runnum <= 1099) energy += -1.915 * factor;
602 if (runnum >= 1100 && runnum <= 1199) energy += -1.513 * factor;
603 if (runnum >= 1200 && runnum <= 1287) energy += -0.639 * factor;
604 }
else if (expnum == 13) {
605 if (runnum >= 1 && runnum <= 99) energy += 0.279 * factor;
606 if (runnum >= 100 && runnum <= 198) energy += 0.140 * factor;
607 if (runnum >= 200 && runnum <= 297) energy += -0.095 * factor;
608 if (runnum >= 301 && runnum <= 440) energy += 0.232 * factor;
609 if (runnum >= 551 && runnum <= 699) energy += -0.385 * factor;
610 if (runnum >= 700 && runnum <= 799) energy += -0.654 * factor;
611 if (runnum >= 800 && runnum <= 899) energy += -0.972 * factor;
612 if (runnum >= 900 && runnum <= 999) energy += -0.770 * factor;
613 if (runnum >= 1000 && runnum <= 1099) energy += -0.353 * factor;
614 if (runnum >= 1100 && runnum <= 1199) energy += -0.490 * factor;
615 if (runnum >= 1200 && runnum <= 1299) energy += -0.687 * factor;
616 if (runnum >= 1300 && runnum <= 1399) energy += -0.545 * factor;
618 if (runnum >= 1400) energy += -0.783 * factor;
623 }
else if (expnum == 15) {
629 if (runnum < 764) energy = 5.288103;
630 if (runnum > 763 && runnum < 951) energy = 5.287005;
631 if (runnum > 950 && runnum < 1251) energy = 5.287804;
632 if (runnum > 1250) energy = 5.288603;
634 }
else if (expnum == 17) {
635 if (runnum <= 199) energy = 5.288702;
636 if (runnum >= 200 && runnum <= 399) energy = 5.289202;
637 if (runnum >= 400 && runnum <= 485) energy = 5.289401;
638 if (runnum >= 545 && runnum <= 799) energy = 5.289501;
639 if (runnum >= 800 && runnum <= 937) energy = 5.289401;
641 }
else if (expnum == 19) {
642 if (runnum >= 64 && runnum <= 199) energy = 5.2887023;
643 if (runnum >= 200 && runnum <= 299) energy = 5.2886025;
644 if (runnum >= 300 && runnum <= 399) energy = 5.28830299;
645 if (runnum >= 400 && runnum <= 459) energy = 5.28820313;
646 if (runnum >= 461 && runnum <= 599) energy = 5.28830299;
647 if (runnum >= 600 && runnum <= 666) energy = 5.28780366;
648 if (runnum >= 763 && runnum <= 999) energy = 5.28820313;
649 if (runnum >= 1000 && runnum <= 1099) energy = 5.28780366;
650 if (runnum >= 1100 && runnum <= 1199) energy = 5.28770378;
651 if (runnum >= 1200 && runnum <= 1399) energy = 5.28750402;
652 if (runnum >= 1400 && runnum <= 1499) energy = 5.28740413;
653 if (runnum >= 1500 && runnum <= 1599) energy = 5.28720434;
654 if (runnum >= 1600 && runnum <= 1643) energy = 5.28760390;
659 }
else if (expnum == 21) {
660 if (runnum >= 0 && runnum <= 180) energy = 5.28650496;
661 if (runnum >= 181 && runnum <= 324) energy = 5.2880034;
662 }
else if (expnum == 23) {
663 if (runnum >= 0 && runnum <= 238) energy = 5.28860254;
664 if (runnum >= 357 && runnum <= 607) energy = 5.28880222;
668 }
else if (expnum == 25) {
669 if (runnum >= 0 && runnum <= 99) energy = 5.28950099;
670 if (runnum >= 100 && runnum <= 199) energy = 5.28870238;
671 if (runnum >= 200 && runnum <= 299) energy = 5.28910171;
672 if (runnum >= 300 && runnum <= 399) energy = 5.28890205;
673 if (runnum >= 400 && runnum <= 799) energy = 5.28850269;
674 if (runnum >= 800 && runnum <= 899) energy = 5.28790353;
675 if (runnum >= 900 && runnum <= 999) energy = 5.28810326;
676 if (runnum >= 1000 && runnum <= 1099) energy = 5.28830298;
677 if (runnum >= 1100 && runnum <= 1199) energy = 5.28820313;
678 if (runnum >= 1200 && runnum <= 1299) energy = 5.28780366;
679 if (runnum >= 1300 && runnum <= 1462) energy = 5.28820313;
680 if (runnum >= 1600 && runnum <= 1699) energy = 5.28830299;
681 if (runnum >= 1700 && runnum <= 1799) energy = 5.28780366;
682 if (runnum >= 1800 && runnum <= 1899) energy = 5.28810327;
683 if (runnum >= 1900 && runnum <= 2122) energy = 5.28830299;
687 }
else if (expnum == 27) {
688 if (runnum >= 0 && runnum <= 180) energy = 5.28860254;
689 if (runnum >= 181 && runnum <= 288) energy = 5.28870238;
690 if (runnum >= 367 && runnum <= 499) energy = 5.28880222;
691 if (runnum >= 500 && runnum <= 590) energy = 5.28890206;
692 if (runnum >= 591 && runnum <= 699) energy = 5.28910172;
693 if (runnum >= 700 && runnum <= 1079) energy = 5.28900189;
694 if (runnum >= 1252 && runnum <= 1299) energy = 5.28850269;
695 if (runnum >= 1300 && runnum <= 1632) energy = 5.28870238;
699 }
else if (expnum == 31) {
700 if (runnum >= 0 && runnum <= 166) energy = 5.287404131;
701 if (runnum >= 231 && runnum <= 470) energy = 5.287903534;
702 if (runnum >= 471 && runnum <= 698) energy = 5.28810327;
703 if (runnum >= 699 && runnum <= 804) energy = 5.288602541;
704 if (runnum >= 805 && runnum <= 936) energy = 5.288702384;
705 if (runnum >= 1071 && runnum <= 1440) energy = 5.288902;
706 if (runnum >= 1441 && runnum <= 1715) energy = 5.289301;
708 }
else if (expnum >= 32) {
709 B2ERROR(
"Warning: Benergy is not ready for exp >=32.");
int m_expno
parameter ExpNo: Experiment number for muid (default=0) 0 ==> use experiment number stored in data fi...
std::string m_scale_error_dataset_name
Set scale_error_dataset name.
int m_benergy_db
Apply Benergy from DB or file.
void Muid_init(void)
Initialize the Muid module.
float m_scale_momenta_scale_mc
Set parameter scale_mc for scale_momenta.
bool m_saveResultExtraInfo
Whether to save result as EventExtraInfo.
int m_calib_dedx
Do dedx calibration.
int m_smear_trk
Do extra-smearing for MC tracks.
int m_scale_momenta
Apply scale_momenta.
void Muid_begin_run(const int, const int, const int)
Called for each new run.
int m_correct_ecl_option
Apply correct_ecl_option.
int m_use_ecl
parameter UseECL: Use (1) or don't use (0) ECL in muid (default=0)
int m_l4passed_only
Select level4-passed event only.
int m_correct_ecl
Apply correct_ecl.
double m_make_pi0_lower_limit
Set make_pi0 lower mass limit.
int m_make_pi0
Apply make_pi0 (after correct_ecl)
int m_shift_tof_mode
Do tof_correction.
int m_correct_ecl_primary_vertex
Apply correct_ecl_primary_vertex.
void Muid_event(void)
Called for each event.
int m_reprocess_version_specified
Specify reprocess version.
float m_scale_momenta_scale_data
Set parameter scale_data for scale_momenta.
int m_correct_ecl_version
Apply correct_ecl_version.
int m_scale_error
Apply scale_error.
int m_scale_momenta_mode
Set parameter mode for scale_momenta.
int m_check_version_consistency
Check consistency between environment variable and mdst version.
int m_table_size
Check table sizes.
void Muid_term(void)
Terminate the Muid module.
int m_limit_mdst_ecl_trk
Limit of mdst_ecl_trk table size.
int m_add_or_remove_extra_trk_vee2
(1) to add to Mdst_charged etc, (-1) to remove (move to Mdst_*_extra), (0) do nothing
int m_make_pi0_primary_vertex
Apply make_pi0_primary_vertex (after correct_ecl)
int m_correct_ecl_5s
For run indep.
int m_mapped_expno
Mapped value of m_old_exp_no.
int m_reprocess_version
Reprocess version (=0:old; =1:new)
int m_limit_mdst_klm_cluster_hit
Limit of mdst_klm_cluster_hit table size.
int m_hadron_b_only
Select Hadron B event only.
int m_benergy
Apply Benergy.
int m_good_event
Select good event only.
int m_hadron_a_only
Select Hadron A event only.
int m_benergy_mcdb
Apply Benergy from DB or default value in MC.
double m_make_pi0_upper_limit
Set make_pi0 upper mass limit.
StoreObjPtr< EventExtraInfo > m_eventExtraInfo
Event ExtraInfo.
int m_5Srun
5S,2S,1S run or not
int m_eklm_max_layer
parameter Endcap_MX_layer: Max layer # of KLM endcap (default=11) 0 ==> use same value as was used by...
int m_make_pi0_option
Set make_pi0 option.
void setDescription(const std::string &description)
Sets the description of the module.
void setReturnValue(int value)
Sets the return value for this module as integer.
void fix_pi0_brecon(void)
Fix relation gamma<->pi0 in brecon table.
void make_pi0(int, double, double)
Create Mdst_pi0 from Mdst_gamma and Mdst_ecl to let people get mass-constraint fitted momentum of pi0...
B2BIIFixMdstModule()
Constructor.
void shift_tof(const int mode)
Shift tof times to account for residuals.
virtual void initialize() override
Initialize the module.
void make_pi0_primary_vertex(int, double, double, const HepPoint3D &, const CLHEP::HepSymMatrix &)
Fill Mdst_pi0 based on the fit result.
virtual void event() override
Called for each event.
void smear_trk()
Apply track smearing (on MC)
double Benergy(int expnum=0, int runnum=0)
Return Beam energy.
virtual void terminate() override
Terminates the module.
int remove_extra_trk_vee2()
Remove extra tracks from Mdst_trk and Mdst_vee2.
void correct_ecl_primary_vertex(const HepPoint3D &, const CLHEP::HepSymMatrix &)
Correct ecl using primary vertex.
void correct_ecl(int, int)
Correct photon's momenta and error matrix.
virtual void beginRun() override
Called when a new run is started.
#define NOMINAL_ENERGY
Nomial beam energy.
int add_extra_trk_vee2()
Add Mdst_trk_extra and Mdst_vee_extra to Mdst_trk and Mdst_vee2, respectively.
int set_primary_vertex(HepPoint3D &v, CLHEP::HepSymMatrix &ve)
Set primary vertex assuming all tracks are pions.
static double s_benergy_value
Beam energy.
void scale_momenta(float scale_data=1.0, float scale_mc=1.0, int mode=0)
Scale momenta of Mdst_trk.
bool good_event()
Check if event corresponds to the period when Belle detector not in good condition.
void scale_error(const int message_level=0)
Apply scale error.
int get_reprocess_version()
Get reprocess version of input mdst.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.