From ffb55a4e6203479bf495d140c92ecae9efef3940 Mon Sep 17 00:00:00 2001 From: dchao Date: Thu, 31 Jul 2014 17:13:57 -0700 Subject: [PATCH] Redefined B MC types. Some changes initial changes towards computing those types in the event --- Makefile | 2 +- build_generic_db.cc | 4 + create_database/BDtaunuMcReader.cc | 103 +++++++++++++------ create_database/BDtaunuMcReader.h | 14 ++- create_database/McEventSQLiteTableBuilder.cc | 68 ++++-------- create_database/McEventSQLiteTableBuilder.h | 7 +- include/bdtaunu_definitions.h | 85 +++++++-------- 7 files changed, 158 insertions(+), 125 deletions(-) diff --git a/Makefile b/Makefile index 93feb6c..1a396ee 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ LDFLAGS = $(LDPATH) LDFLAGS += $(addprefix -l, $(SHARED_LIBARIES)) -lsqlite3 LDFLAGS += $(shell root-config --libs) -TARGETS = main build_sigmc_db build_generic_db +TARGETS = build_generic_db #update_event_svm_scores build_sigmc_db all : CXXFLAGS += -O3 all : $(TARGETS) diff --git a/build_generic_db.cc b/build_generic_db.cc index 7b0ce49..3fd21fc 100644 --- a/build_generic_db.cc +++ b/build_generic_db.cc @@ -110,6 +110,10 @@ int main() { event_builder.set_event_weight(event_weights[pair(sp_modes[sp], run)]); event_builder.set_b1mctype(rootreader.get_b1mctype()); event_builder.set_b2mctype(rootreader.get_b2mctype()); + event_builder.set_b1_taumctype(rootreader.get_b1_taumctype()); + event_builder.set_b2_taumctype(rootreader.get_b2_taumctype()); + event_builder.set_b1_dtau_max_photon_energy(rootreader.get_b1_dtau_max_photon_energy()); + event_builder.set_b2_dtau_max_photon_energy(rootreader.get_b2_dtau_max_photon_energy()); event_builder.set_nTrk(rootreader.get_nTrk()); event_builder.set_R2(rootreader.get_R2All()); event_builder.set_nY(rootreader.get_nY()); diff --git a/create_database/BDtaunuMcReader.cc b/create_database/BDtaunuMcReader.cc index 0a0f2c6..7aa54ed 100644 --- a/create_database/BDtaunuMcReader.cc +++ b/create_database/BDtaunuMcReader.cc @@ -87,6 +87,16 @@ std::vector BDtaunuMcReader::build_dstrange() { } const std::vector BDtaunuMcReader::dstrange = build_dstrange(); +// pion. +std::vector BDtaunuMcReader::build_pion() { + std::vector pion_temp; + pion_temp.push_back(abs(lundIdMap["pi+"])); + pion_temp.push_back(abs(lundIdMap["pi0"])); + std::sort(pion_temp.begin(), pion_temp.end()); + return pion_temp; +} +const std::vector BDtaunuMcReader::pion = build_pion(); + BDtaunuMcReader::BDtaunuMcReader() : BDtaunuReader() { Initialize(); @@ -136,12 +146,18 @@ void BDtaunuMcReader::SetBranchAddress() { void BDtaunuMcReader::ClearColumnValues() { BDtaunuReader::ClearColumnValues(); mcLen = 0; + McB1.bflavor = kUndefinedBFlavor; - McB1.bmctype = kUndefinedBMcType; McB1.mc_idx = -1; + McB1.bmctype = kUndefinedBMcType; + McB1.dtau_max_photon_energy = -1; + McB1.taumctype = ktau_undefined_mc; + McB2.bflavor = kUndefinedBFlavor; - McB2.bmctype = kUndefinedBMcType; McB2.mc_idx = -1; + McB2.bmctype = kUndefinedBMcType; + McB2.dtau_max_photon_energy = -1; + McB2.taumctype = ktau_undefined_mc; } // Find the MC B meson's from the mcLund array of the event. Determine @@ -187,29 +203,34 @@ void BDtaunuMcReader::FindBMesons() { } // Determine the B MC types. -int BDtaunuMcReader::DetermineBMcType(int bmc_idx) { +void BDtaunuMcReader::DetermineBMcType(McBMeson &mcB) { // Return if no MC B mesons are in the event. - if (bmc_idx == -1) - return kCont; + if (mcB.mc_idx == -1) { + mcB.bmctype = kCont; + return; + } // Count the number of daughters of the first generation B daughters // and record the lundId of relevant daughters. int n_daughters = 0; int ell_lund, nu_lund; ell_lund = nu_lund = 0; - int n_ell, n_nu, n_d, n_dstar, n_dstarstar, n_dstrange, n_other; - n_ell = n_nu = n_d = n_dstar = n_dstarstar = n_dstrange = n_other = 0; + int n_ell, n_nu, n_d, n_dstar, n_dstarstar, n_dstrange, n_pi, n_other; + n_ell = n_nu = n_d = n_dstar = n_dstarstar = n_dstrange = n_pi = n_other = 0; + + int ell_idx = -1; // Scan through the entire first generation daughter. - int begin_dauIdx = dauIdx[bmc_idx]; - int end_dauIdx = begin_dauIdx + dauLen[bmc_idx]; + int begin_dauIdx = dauIdx[mcB.mc_idx]; + int end_dauIdx = begin_dauIdx + dauLen[mcB.mc_idx]; for (int i = begin_dauIdx; i < end_dauIdx; i++) { - // Ignore daughters that have less than min_photon_energy (20 - // MeV). They are probably spurious particles generated in MC. - if (mcLund[i] == lundIdMap["gamma"] && - mcenergy[i] < min_photon_energy) { + // Note down max photon energy, but don't use it to classify B type. + if (mcLund[i] == lundIdMap["gamma"]) { + if (mcenergy[i] > mcB.dtau_max_photon_energy) { + mcB.dtau_max_photon_energy = mcenergy[i]; + } continue; } n_daughters += 1; @@ -218,6 +239,7 @@ int BDtaunuMcReader::DetermineBMcType(int bmc_idx) { if (std::binary_search(ell.begin(), ell.end(), abs(mcLund[i]))) { n_ell += 1; ell_lund = abs(mcLund[i]); + ell_idx = i; } else if (std::binary_search(nu.begin(), nu.end(), abs(mcLund[i]))) { n_nu += 1; nu_lund = abs(mcLund[i]); @@ -229,6 +251,8 @@ int BDtaunuMcReader::DetermineBMcType(int bmc_idx) { n_dstarstar += 1; } else if (std::binary_search(dstrange.begin(), dstrange.end(), abs(mcLund[i]))) { n_dstrange += 1; + } else if (std::binary_search(pion.begin(), pion.end(), abs(mcLund[i]))) { + n_pi += 1; } else { n_other += 1; } @@ -240,43 +264,64 @@ int BDtaunuMcReader::DetermineBMcType(int bmc_idx) { if (n_d == 1) { if (n_daughters == 3) { if (ell_lund == abs(lundIdMap["tau-"])) { - return kDtau; + mcB.bmctype = kDtau; } else { - return kDl; + mcB.bmctype = kDl; } + } else if (n_pi > 0) { + mcB.bmctype = kDstarstar_nonres; } else { - return kD_SL; + mcB.bmctype = kD_SL; } } else if (n_dstar == 1) { if (n_daughters == 3) { if (ell_lund == abs(lundIdMap["tau-"])) { - return kDstartau; + mcB.bmctype = kDstartau; } else { - return kDstarl; + mcB.bmctype = kDstarl; } + } else if (n_pi > 0) { + mcB.bmctype = kDstarstar_nonres; } else { - return kD_SL; + mcB.bmctype = kD_SL; } } else if (n_dstarstar == 1) { - return kDstarstar_SL; + mcB.bmctype = kDstarstar_res; } else if (n_d + n_dstar + n_dstarstar == 0) { - return k0Charm_SL; + mcB.bmctype = k0D_SL; } else { - return kUndefinedBMcType; + mcB.bmctype = kUndefinedBMcType; } } else if (n_ell == 0 && n_nu == 0) { int nD = n_dstarstar + n_dstrange + n_d; if (nD == 0) { - return k0Charm_Had; + mcB.bmctype = k0Charm_Had; } else if (nD == 1) { - return k1Charm_Had; + mcB.bmctype = k1Charm_Had; } else if (nD == 2) { - return k2Charm_Had; + mcB.bmctype = k2Charm_Had; } else { - return kUndefinedBMcType; + mcB.bmctype = kUndefinedBMcType; } } else { - return kUndefinedBMcType; + mcB.bmctype = kUndefinedBMcType; + } + + // Determine tau mc type + if (mcB.bmctype == kDtau || mcB.bmctype == kDstartau) { + mcB.taumctype = ktau_had_mc; + + int begin_dauIdx = dauIdx[ell_idx]; + int end_dauIdx = begin_dauIdx + dauLen[ell_idx]; + for (int i = begin_dauIdx; i < end_dauIdx; i++) { + if (abs(mcLund[i]) == lundIdMap["e-"]) { + mcB.taumctype = ktau_e_mc; + } else if (abs(mcLund[i]) == lundIdMap["mu-"]) { + mcB.taumctype = ktau_mu_mc; + } else { + continue; + } + } } } @@ -287,8 +332,8 @@ void BDtaunuMcReader::FillMCInformation() { FindBMesons(); // Determine B MC types. - McB1.bmctype = DetermineBMcType(McB1.mc_idx); - McB2.bmctype = DetermineBMcType(McB2.mc_idx); + DetermineBMcType(McB1); + DetermineBMcType(McB2); } diff --git a/create_database/BDtaunuMcReader.h b/create_database/BDtaunuMcReader.h index 60e099f..0b8998e 100644 --- a/create_database/BDtaunuMcReader.h +++ b/create_database/BDtaunuMcReader.h @@ -23,6 +23,7 @@ class BDtaunuMcReader : public BDtaunuReader { const static std::vector dstar; const static std::vector dstarstar; const static std::vector dstrange; + const static std::vector pion; static std::vector build_ell(); static std::vector build_nu(); @@ -30,6 +31,7 @@ class BDtaunuMcReader : public BDtaunuReader { static std::vector build_dstar(); static std::vector build_dstarstar(); static std::vector build_dstrange(); + static std::vector build_pion(); protected: int mcLen; @@ -42,15 +44,18 @@ class BDtaunuMcReader : public BDtaunuReader { int bflavor; int mc_idx; int bmctype; + double dtau_max_photon_energy; + int taumctype; McBMeson() : bflavor(kUndefinedBFlavor), - mc_idx(-1), bmctype(kUndefinedBMcType) {}; + mc_idx(-1), bmctype(kUndefinedBMcType), + dtau_max_photon_energy(-1), taumctype(ktau_undefined_mc) {}; } McB1, McB2; private: void FillMCInformation(); void FindBMesons(); - int DetermineBMcType(int bmc_idx); + void DetermineBMcType(McBMeson &mcB); protected: virtual void Initialize(); @@ -84,6 +89,11 @@ class BDtaunuMcReader : public BDtaunuReader { //! B MC type of second truth B. /*! Returns an int that corresponds to the #BMcType enum in */ int get_b2mctype() const { return McB2.bmctype; } + + int get_b1_taumctype() const { return McB1.taumctype; } + int get_b2_taumctype() const { return McB2.taumctype; } + double get_b1_dtau_max_photon_energy() const { return McB1.dtau_max_photon_energy; } + double get_b2_dtau_max_photon_energy() const { return McB2.dtau_max_photon_energy; } }; #endif diff --git a/create_database/McEventSQLiteTableBuilder.cc b/create_database/McEventSQLiteTableBuilder.cc index ed77ca7..f1ebb44 100644 --- a/create_database/McEventSQLiteTableBuilder.cc +++ b/create_database/McEventSQLiteTableBuilder.cc @@ -34,7 +34,12 @@ McEventSQLiteTableBuilder::McEventSQLiteTableBuilder(sqlite3* database, const ch meta_colnames.push_back(std::pair("ml_sample", "TEXT")); meta_colnames.push_back(std::pair("division", "TEXT")); meta_colnames.push_back(std::pair("mc_evttypeA", "INTEGER")); - meta_colnames.push_back(std::pair("mc_evttypeB", "INTEGER")); + meta_colnames.push_back(std::pair("b1mctype", "INTEGER")); + meta_colnames.push_back(std::pair("b2mctype", "INTEGER")); + meta_colnames.push_back(std::pair("b1_taumctype", "INTEGER")); + meta_colnames.push_back(std::pair("b2_taumctype", "INTEGER")); + meta_colnames.push_back(std::pair("b1_dtau_max_photon_energy", "REAL")); + meta_colnames.push_back(std::pair("b2_dtau_max_photon_energy", "REAL")); BuildCachedDataMap(assignment_fname); } @@ -55,7 +60,18 @@ void McEventSQLiteTableBuilder::BindColumns() { db_status = sqlite3_bind_text(insert_stmt, sqlite3_bind_parameter_index(insert_stmt, "@division"), sample_assignment_map[babar_event_id].second.c_str(), -1, SQLITE_STATIC); assert(db_status == SQLITE_OK); db_status = sqlite3_bind_int(insert_stmt, sqlite3_bind_parameter_index(insert_stmt, "@mc_evttypeA"), DetermineMcEventTypeDefA()); - db_status = sqlite3_bind_int(insert_stmt, sqlite3_bind_parameter_index(insert_stmt, "@mc_evttypeB"), DetermineMcEventTypeDefB()); + assert(db_status == SQLITE_OK); + db_status = sqlite3_bind_int(insert_stmt, sqlite3_bind_parameter_index(insert_stmt, "@b1mctype"), b1mctype); + assert(db_status == SQLITE_OK); + db_status = sqlite3_bind_int(insert_stmt, sqlite3_bind_parameter_index(insert_stmt, "@b2mctype"), b2mctype); + assert(db_status == SQLITE_OK); + db_status = sqlite3_bind_int(insert_stmt, sqlite3_bind_parameter_index(insert_stmt, "@b1_taumctype"), b1_taumctype); + assert(db_status == SQLITE_OK); + db_status = sqlite3_bind_int(insert_stmt, sqlite3_bind_parameter_index(insert_stmt, "@b2_taumctype"), b2_taumctype); + assert(db_status == SQLITE_OK); + db_status = sqlite3_bind_double(insert_stmt, sqlite3_bind_parameter_index(insert_stmt, "@b1_dtau_max_photon_energy"), b1_dtau_max_photon_energy); + assert(db_status == SQLITE_OK); + db_status = sqlite3_bind_double(insert_stmt, sqlite3_bind_parameter_index(insert_stmt, "@b2_dtau_max_photon_energy"), b2_dtau_max_photon_energy); assert(db_status == SQLITE_OK); } @@ -74,7 +90,8 @@ int McEventSQLiteTableBuilder::DetermineMcEventTypeDefA() const { return kDtau_SigA; } else if (b1mctype == kDstartau || b2mctype == kDstartau) { return kDstartau_SigA; - } else if (b1mctype == kDstarstar_SL || b2mctype == kDstarstar_SL) { + } else if (b1mctype == kDstarstar_res || b2mctype == kDstarstar_res || + b1mctype == kDstarstar_nonres || b2mctype == kDstarstar_nonres ) { return kDstarstar_BkgA; } else if ((b1mctype == kDl && b2mctype == kDstarl) || (b1mctype == kDstarl && b2mctype == kDl)) { @@ -93,7 +110,7 @@ int McEventSQLiteTableBuilder::DetermineMcEventTypeDefA() const { switch (b1mctype) { case kD_SL: - case k0Charm_SL: + case k0D_SL: b1_dectype = 0; break; case k0Charm_Had: @@ -105,7 +122,7 @@ int McEventSQLiteTableBuilder::DetermineMcEventTypeDefA() const { switch (b2mctype) { case kD_SL: - case k0Charm_SL: + case k0D_SL: b2_dectype = 0; break; case k0Charm_Had: @@ -128,44 +145,3 @@ int McEventSQLiteTableBuilder::DetermineMcEventTypeDefA() const { } } -int McEventSQLiteTableBuilder::DetermineMcEventTypeDefB() const { - - int bmctype; - if ((truthB_idx_map.find(babar_event_id))->second == 0) { - bmctype = b1mctype; - } else { - bmctype = b2mctype; - } - - switch (bmctype) { - case kDtau: - return kDtau_SigB; - break; - case kDstartau: - return kDstartau_SigB; - break; - case kDl: - return kDl_NormB; - break; - case kDstarl: - return kDstarl_NormB; - break; - case kDstarstar_SL: - return kDstarstar_BkgB; - break; - case kD_SL: - case k0Charm_SL: - return kSL_BkgB; - break; - case k0Charm_Had: - case k1Charm_Had: - case k2Charm_Had: - return kHad_BkgB; - break; - case kCont: - return kCont_BkgB; - break; - default: - return kUndefinedMcEventTypeB; - } -} diff --git a/create_database/McEventSQLiteTableBuilder.h b/create_database/McEventSQLiteTableBuilder.h index c30f283..35b01cd 100644 --- a/create_database/McEventSQLiteTableBuilder.h +++ b/create_database/McEventSQLiteTableBuilder.h @@ -13,6 +13,8 @@ class McEventSQLiteTableBuilder : public EventSQLiteTableBuilder { private: int b1mctype, b2mctype; + int b1_taumctype, b2_taumctype; + double b1_dtau_max_photon_energy, b2_dtau_max_photon_energy; int sp_mode; double event_weight; @@ -23,7 +25,6 @@ class McEventSQLiteTableBuilder : public EventSQLiteTableBuilder { void BindColumns(); int DetermineMcEventTypeDefA() const; - int DetermineMcEventTypeDefB() const; public: McEventSQLiteTableBuilder() {}; @@ -32,6 +33,10 @@ class McEventSQLiteTableBuilder : public EventSQLiteTableBuilder { void set_b1mctype(int value) { b1mctype = value; } void set_b2mctype(int value) { b2mctype = value; } + void set_b1_taumctype(int value) { b1_taumctype = value; } + void set_b2_taumctype(int value) { b2_taumctype = value; } + void set_b1_dtau_max_photon_energy(double value) { b1_dtau_max_photon_energy = value; } + void set_b2_dtau_max_photon_energy(double value) { b2_dtau_max_photon_energy = value; } void set_sp_mode(int spmode) { sp_mode = spmode; } void set_event_weight(double evt_wgt) { event_weight = evt_wgt; } }; diff --git a/include/bdtaunu_definitions.h b/include/bdtaunu_definitions.h index 9bf62e3..e08678e 100644 --- a/include/bdtaunu_definitions.h +++ b/include/bdtaunu_definitions.h @@ -86,14 +86,19 @@ enum SampleType { kUndefinedSampleType = -1, /*!< Undefined */ }; -//! Truth B MC Types. +//! Truth B MC Types. /*! This labels truth \f$B\f$ mesons into various decay categories * that will be helpful in characterizing whether the event is signal * or background. * - * The label is done by examining the \f$B\f$ meson's decay daughters. - * Note that we are currently ignoring \f$\gamma\f$ daughters that - * have energy below 20 MeV. */ + * The label is done by examining the \f$B\f$ meson's decay daughters. + * + * \f$B\f$ \f$\gamma\f$ daughters are currently ignored in determining + * the MC type. However, the energy of the photon with the highest energy + * is saved; one can use this to determine whether the event has radiative + * photons involved. Therefore, the following descriptions omit the + * \f$+n\gamma\f$, \f$n\geq0\f$, though this is needed to be technically + * correct. */ enum BMcType { //! No truth \f$B\f$ mesons. @@ -115,15 +120,15 @@ enum BMcType { //! Truth \f$B\f$ decays as \f$B\rightarrow D^{**}\ell\nu_\ell X\f$ /*! \f$X\f$ is any sequence of particles. */ - kDstarstar_SL = 5, + kDstarstar_res = 5, - //! Truth \f$B\f$ decays as \f$B\rightarrow D^{(*)}\ell\nu_\ell X\f$ + //! Truth \f$B\f$ decays as \f$B\rightarrow D^{(*)}n\pi^{\pm,0}\ell\nu_\ell X\f$ /*! \f$X\f$ is any sequence of particles. */ - kD_SL = 6, + kDstarstar_nonres = 6, //! Truth \f$B\f$ decays as \f$B\rightarrow X\ell\nu_\ell\f$ /*! \f$X\f$ is any sequence of particles not involving a charm meson. */ - k0Charm_SL = 7, + kCharmless_SL = 7, //! Truth \f$B\f$ decays hadronically. Daughters contain no charm mesons. k0Charm_Had = 8, @@ -138,7 +143,32 @@ enum BMcType { kUndefinedBMcType = -1, }; -//! MC Event Types, Definition A. + +//! Truth \f$\tau\f$ MC Types. See Details. +/*! Truth \f$\tau\f$ MC Types for truth \f$B\f$'s decaying as + * \f$B\rightarrow D^{(*)}\tau\nu_\tau\f$. Any other \f$B\f$ decay types + * will have this value undefined. */ +enum TauMcType { + + //! Truth \f$\tau\f$ decays as \f$\tau\rightarrow e+\nu_e+X\f$. + ktau_e_mc = 0, + + //! Truth \f$\tau\f$ decays as \f$\tau\rightarrow \mu+\nu_\mu+X\f$. + ktau_mu_mc = 1, + + //! Truth \f$\tau\f$ decays as \f$\tau\rightarrow K+X\f$. + ktau_k_mc = 2, + + //! Truth \f$\tau\f$ decays as \f$\tau\rightarrow X\f$. + /*! \f$X\f$ is any sequence of particles not involving \f$e, \mu, K\f$. */ + ktau_h_mc = 3, + + //! Undefined \f$\tau\f$ MC type. + ktau_undefined_mc = -1, +}; + + +//! MC Event Types, Definition A. This will soon be obsolete. /*! This labels Monte Carlo events into various signal and background * truth categories. * @@ -205,41 +235,4 @@ enum McEventTypeA { kUndefinedMcEventTypeA = -1, }; -//! MC Event Types, Definition B. -/*! This labels Monte Carlo events into various signal and background - * truth categories. It is based on the #BMcType of a randomly chosen - * truth B meson. */ -enum McEventTypeB { - - //! \f$B\rightarrow D\tau\nu_\tau\f$ signal event. - kDtau_SigB = 0, - - //! \f$B\rightarrow D^*\tau\nu_\tau\f$ signal event. - kDstartau_SigB = 1, - - //! \f$B\rightarrow D\ell\nu_\ell\f$ normalization event. - /*! \f$\ell=e,\,\mu\f$. */ - kDl_NormB = 2, - - //! \f$B\rightarrow D^*\ell\nu_\ell\f$ normalization event. - /*! \f$\ell=e,\,\mu\f$. */ - kDstarl_NormB = 3, - - //! \f$B\rightarrow D^{**}\ell\nu_\ell X\f$ background event. - /*! \f$X\f$ is any sequence of particles. */ - kDstarstar_BkgB = 4, - - //! Other semileptonic background event. - kSL_BkgB = 5, - - //! Hadronic background event. - kHad_BkgB = 6, - - //! Continuum background event. - kCont_BkgB = 7, - - //! Undefined MC event type. Indicates error. - kUndefinedMcEventTypeB = -1, -}; - #endif