Skip to content

Commit

Permalink
Updated code to add more MC information. Particularly MC Btypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dchao committed Aug 12, 2014
1 parent dc9d7d2 commit d1d95b2
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 145 deletions.
10 changes: 6 additions & 4 deletions build_generic_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ int main() {
event_builder.set_run(run);
event_builder.set_sp_mode(sp_modes[sp]);
event_builder.set_event_weight(event_weights[pair<int, int>(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_mctype(rootreader.get_b1_mctype());
event_builder.set_b2_mctype(rootreader.get_b2_mctype());
event_builder.set_b1_tau_mctype(rootreader.get_b1_tau_mctype());
event_builder.set_b2_tau_mctype(rootreader.get_b2_tau_mctype());
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());
Expand Down Expand Up @@ -158,6 +158,8 @@ int main() {
candidate_builder.set_sig_vtxh(curr_cand.get_sig_vtxh());
candidate_builder.set_sig_Dtype(curr_cand.get_sig_d_mode());
candidate_builder.set_sig_Dstartype(curr_cand.get_sig_dstar_mode());
candidate_builder.set_tag_l_ePid(curr_cand.get_l_ePidMap());
candidate_builder.set_tag_l_muPid(curr_cand.get_l_muPidMap());
candidate_builder.set_svm_score(svm_scorer.get_score());

candidate_builder.InsertTable();
Expand Down
100 changes: 52 additions & 48 deletions create_database/BDtaunuMcReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ void BDtaunuMcReader::ClearColumnValues() {

McB1.bflavor = kUndefinedBFlavor;
McB1.mc_idx = -1;
McB1.bmctype = kUndefinedBMcType;
McB1.b_mctype = kUndefinedBMcType;
McB1.tau_mctype = kUndefinedTauMcType;
McB1.dtau_max_photon_energy = -1;
McB1.taumctype = ktau_undefined_mc;

McB2.bflavor = kUndefinedBFlavor;
McB2.mc_idx = -1;
McB2.bmctype = kUndefinedBMcType;
McB2.b_mctype = kUndefinedBMcType;
McB2.tau_mctype = kUndefinedTauMcType;
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
Expand Down Expand Up @@ -207,19 +207,23 @@ void BDtaunuMcReader::DetermineBMcType(McBMeson &mcB) {

// Return if no MC B mesons are in the event.
if (mcB.mc_idx == -1) {
mcB.bmctype = kCont;
mcB.b_mctype = 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 n_ell, n_nu;
n_ell = n_nu = 0;

int n_d, n_dstar, n_dstarstar, n_dstrange, n_pi, n_other;
n_d = n_dstar = n_dstarstar = n_dstrange = n_pi = n_other = 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_pi, n_other;
n_ell = n_nu = n_d = n_dstar = n_dstarstar = n_dstrange = n_pi = n_other = 0;

int ell_idx = -1;
int ell_mcidx = -1;

// Scan through the entire first generation daughter.
int begin_dauIdx = dauIdx[mcB.mc_idx];
Expand All @@ -239,7 +243,7 @@ void BDtaunuMcReader::DetermineBMcType(McBMeson &mcB) {
if (std::binary_search(ell.begin(), ell.end(), abs(mcLund[i]))) {
n_ell += 1;
ell_lund = abs(mcLund[i]);
ell_idx = i;
ell_mcidx = i;
} else if (std::binary_search(nu.begin(), nu.end(), abs(mcLund[i]))) {
n_nu += 1;
nu_lund = abs(mcLund[i]);
Expand All @@ -261,67 +265,67 @@ void BDtaunuMcReader::DetermineBMcType(McBMeson &mcB) {
// Determine the B MC Type. See bdtaunu_definitions.h for the
// definitions.
if (n_ell == 1 && n_nu == 1) {
if (n_d == 1) {
if (n_daughters == 3) {
if (ell_lund == abs(lundIdMap["tau-"])) {
mcB.bmctype = kDtau;
} else {
mcB.bmctype = kDl;
}
} else if (n_pi > 0) {
mcB.bmctype = kDstarstar_nonres;
} else {
mcB.bmctype = kD_SL;
}
} else if (n_dstar == 1) {
if (n_d + n_dstar + n_dstarstar == 0) {
mcB.b_mctype = kCharmless_SL;
} else if (n_dstarstar > 0) {
mcB.b_mctype = kDstarstar_res;
} else {
assert(n_d + n_dstar == 1);
if (n_daughters == 3) {
if (ell_lund == abs(lundIdMap["tau-"])) {
mcB.bmctype = kDstartau;
if (n_d == 1) {
mcB.b_mctype = kDtau;
} else {
mcB.b_mctype = kDstartau;
}
} else {
mcB.bmctype = kDstarl;
if (n_d == 1) {
mcB.b_mctype = kDl;
} else {
mcB.b_mctype = kDstarl;
}
}
} else if (n_pi > 0) {
mcB.bmctype = kDstarstar_nonres;
} else {
mcB.bmctype = kD_SL;
mcB.b_mctype = kDstarstar_nonres;
}
} else if (n_dstarstar == 1) {
mcB.bmctype = kDstarstar_res;
} else if (n_d + n_dstar + n_dstarstar == 0) {
mcB.bmctype = k0D_SL;
} else {
mcB.bmctype = kUndefinedBMcType;
}
} else if (n_ell == 0 && n_nu == 0) {
int nD = n_dstarstar + n_dstrange + n_d;
int nD = n_d + n_dstar + n_dstarstar + n_dstrange;
if (nD == 0) {
mcB.bmctype = k0Charm_Had;
mcB.b_mctype = k0Charm_Had;
} else if (nD == 1) {
mcB.bmctype = k1Charm_Had;
mcB.b_mctype = k1Charm_Had;
} else if (nD == 2) {
mcB.bmctype = k2Charm_Had;
mcB.b_mctype = k2Charm_Had;
} else {
mcB.bmctype = kUndefinedBMcType;
mcB.b_mctype = kUndefinedBMcType;
}
} else {
mcB.bmctype = kUndefinedBMcType;
mcB.b_mctype = kUndefinedBMcType;
}

// Determine tau mc type
if (mcB.bmctype == kDtau || mcB.bmctype == kDstartau) {
mcB.taumctype = ktau_had_mc;
if (mcB.b_mctype == kDtau || mcB.b_mctype == kDstartau) {
mcB.tau_mctype = ktau_h_mc;

int begin_dauIdx = dauIdx[ell_idx];
int end_dauIdx = begin_dauIdx + dauLen[ell_idx];
int begin_dauIdx = dauIdx[ell_mcidx];
int end_dauIdx = begin_dauIdx + dauLen[ell_mcidx];
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;
if (abs(mcLund[i]) == abs(lundIdMap["e-"])) {
mcB.tau_mctype = ktau_e_mc;
break;
} else if (abs(mcLund[i]) == abs(lundIdMap["mu-"])) {
mcB.tau_mctype = ktau_mu_mc;
break;
} else if (abs(mcLund[i]) == abs(lundIdMap["K-"])) {
mcB.tau_mctype = ktau_k_mc;
break;
} else {
continue;
}
}
} else {
mcB.tau_mctype = kUndefinedTauMcType;
}
}

Expand Down
29 changes: 21 additions & 8 deletions create_database/BDtaunuMcReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ class BDtaunuMcReader : public BDtaunuReader {
struct McBMeson {
int bflavor;
int mc_idx;
int bmctype;
int b_mctype;
int tau_mctype;
double dtau_max_photon_energy;
int taumctype;
McBMeson() :
bflavor(kUndefinedBFlavor),
mc_idx(-1), bmctype(kUndefinedBMcType),
dtau_max_photon_energy(-1), taumctype(ktau_undefined_mc) {};
mc_idx(-1),
b_mctype(kUndefinedBMcType),
tau_mctype(kUndefinedTauMcType),
dtau_max_photon_energy(-1) {};
} McB1, McB2;

private:
Expand Down Expand Up @@ -84,15 +86,26 @@ class BDtaunuMcReader : public BDtaunuReader {

//! B MC type of first truth B.
/*! Returns an int that corresponds to the #BMcType enum in */
int get_b1mctype() const { return McB1.bmctype; }
int get_b1_mctype() const { return McB1.b_mctype; }

//! 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_b2_mctype() const { return McB2.b_mctype; }

int get_b1_taumctype() const { return McB1.taumctype; }
int get_b2_taumctype() const { return McB2.taumctype; }
//! tau MC type of first truth B
/*! Returns an int corresponding to #TauMcType enum. */
int get_b1_tau_mctype() const { return McB1.tau_mctype; }

//! tau MC type of second truth B
/*! Returns an int corresponding to #TauMcType enum. */
int get_b2_tau_mctype() const { return McB2.tau_mctype; }

//! Energy of the highest energy photon of first truth B.
/*! Returns -1 if no photons exist. */
double get_b1_dtau_max_photon_energy() const { return McB1.dtau_max_photon_energy; }

//! Energy of the highest energy photon of second truth B.
/*! Returns -1 if no photons exist. */
double get_b2_dtau_max_photon_energy() const { return McB2.dtau_max_photon_energy; }
};

Expand Down
44 changes: 43 additions & 1 deletion create_database/BDtaunuReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ void BDtaunuReader::Initialize() {
YSigBhMass = new float[maximum_Y_candidates];
YSigBVtxProbh = new float[maximum_Y_candidates];

lTrkIdx = new int[maximum_l_candidates];
hTrkIdx = new int[maximum_h_candidates];
eSelectorsMap = new int[maximum_h_candidates + maximum_l_candidates];
muSelectorsMap = new int[maximum_h_candidates + maximum_l_candidates];
KSelectorsMap = new int[maximum_h_candidates + maximum_l_candidates];
piSelectorsMap = new int[maximum_h_candidates + maximum_l_candidates];

Yd1Idx = new int[maximum_Y_candidates];
Yd2Idx = new int[maximum_Y_candidates];
Bd1Idx = new int[maximum_B_candidates];
Expand Down Expand Up @@ -160,6 +167,12 @@ void BDtaunuReader::SetBranchAddress() {
tr->SetBranchAddress("YSigBsoftP3MagCM", YSigBsoftP3MagCM);
tr->SetBranchAddress("YSigBhMass", YSigBhMass);
tr->SetBranchAddress("YSigBVtxProbh", YSigBVtxProbh);
tr->SetBranchAddress("lTrkIdx", lTrkIdx);
tr->SetBranchAddress("hTrkIdx", hTrkIdx);
tr->SetBranchAddress("eSelectorsMap", eSelectorsMap);
tr->SetBranchAddress("muSelectorsMap", muSelectorsMap);
tr->SetBranchAddress("KSelectorsMap", KSelectorsMap);
tr->SetBranchAddress("piSelectorsMap", piSelectorsMap);
tr->SetBranchAddress("Yd1Idx", Yd1Idx);
tr->SetBranchAddress("Yd2Idx", Yd2Idx);
tr->SetBranchAddress("Bd1Idx", Bd1Idx);
Expand Down Expand Up @@ -218,6 +231,10 @@ void BDtaunuReader::FillUpsilonList() {
bflavor, tag_dstar_mode, tag_d_mode,
sig_dstar_mode, sig_d_mode, sig_tau_mode);

// Get PID info of the candidate.
int l_ePidMap, l_muPidMap;
ComputeCandidatePid(cand_idx, l_ePidMap, l_muPidMap);

// Construct an UpsilonCandidate object and fill in its features.
UpsilonCandidate cand(eventId, cand_idx,
YBPairEextra50[cand_idx], YBPairMmissPrime2[cand_idx],
Expand All @@ -234,7 +251,8 @@ void BDtaunuReader::FillUpsilonList() {
bflavor,
tag_dstar_mode, tag_d_mode,
sig_dstar_mode, sig_d_mode,
sig_tau_mode);
sig_tau_mode,
l_ePidMap, l_muPidMap);

// Add it to the UpsilonList.
upsilon_candidates.add_candidate(cand);
Expand Down Expand Up @@ -319,6 +337,24 @@ void BDtaunuReader::ComputeCandidateDecay(

}

void BDtaunuReader::ComputeCandidatePid(
int cand_idx,
int &l_ePidMap, int &l_muPidMap) {

int tagBIdx = Yd1Idx[cand_idx];
int lIdx = Bd2Idx[tagBIdx];
int ltrkIdx = lTrkIdx[lIdx];

assert(
abs(Bd2Lund[tagBIdx]) == abs(lundIdMap["e+"]) ||
abs(Bd2Lund[tagBIdx]) == abs(lundIdMap["mu+"])
);

l_ePidMap = eSelectorsMap[ltrkIdx];
l_muPidMap = muSelectorsMap[ltrkIdx];

}


BDtaunuReader::~BDtaunuReader() {
delete[] YBPairMmissPrime2;
Expand All @@ -341,6 +377,12 @@ BDtaunuReader::~BDtaunuReader() {
delete[] YSigBsoftP3MagCM;
delete[] YSigBhMass;
delete[] YSigBVtxProbh;
delete[] lTrkIdx;
delete[] hTrkIdx;
delete[] eSelectorsMap;
delete[] muSelectorsMap;
delete[] KSelectorsMap;
delete[] piSelectorsMap;
delete[] Yd1Idx;
delete[] Yd2Idx;
delete[] Bd1Idx;
Expand Down
7 changes: 7 additions & 0 deletions create_database/BDtaunuReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class BDtaunuReader : public RootReader {
float *YSigBCosThetaDSoftCM, *YSigBsoftP3MagCM;
float *YSigBhMass, *YSigBVtxProbh;

int *lTrkIdx, *hTrkIdx;
int *eSelectorsMap, *muSelectorsMap, *KSelectorsMap, *piSelectorsMap;

protected:
int nY, nB, nD;
int ntau, nh, nl, ngamma;
Expand Down Expand Up @@ -85,6 +88,10 @@ class BDtaunuReader : public RootReader {
int Dd3_lundId, int Dd4_lundId, int Dd5_lundId);
int DetermineTauMode(int taud1_lundId);

void ComputeCandidatePid(
int cand_idx,
int &l_ePidMap, int &l_muPidMap);

protected:

virtual void Initialize();
Expand Down
6 changes: 6 additions & 0 deletions create_database/CandidateSQLiteTableBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ CandidateSQLiteTableBuilder::CandidateSQLiteTableBuilder(sqlite3* database) :
cand_level_feature_colnames.push_back(std::pair<std::string, std::string>("sig_vtxh", "REAL"));
cand_level_feature_colnames.push_back(std::pair<std::string, std::string>("sig_Dtype", "INTEGER"));
cand_level_feature_colnames.push_back(std::pair<std::string, std::string>("sig_Dstartype", "INTEGER"));
cand_level_feature_colnames.push_back(std::pair<std::string, std::string>("tag_l_ePid", "INTEGER"));
cand_level_feature_colnames.push_back(std::pair<std::string, std::string>("tag_l_muPid", "INTEGER"));

bestcand_colnames.push_back(std::pair<std::string, std::string>("svm_score", "REAL"));
}
Expand Down Expand Up @@ -209,6 +211,10 @@ void CandidateSQLiteTableBuilder::BindColumns() {
assert(db_status == SQLITE_OK);
db_status = sqlite3_bind_int(insert_stmt, sqlite3_bind_parameter_index(insert_stmt, "@sig_Dstartype"), sig_Dstartype);
assert(db_status == SQLITE_OK);
db_status = sqlite3_bind_int(insert_stmt, sqlite3_bind_parameter_index(insert_stmt, "@tag_l_ePid"), tag_l_ePid);
assert(db_status == SQLITE_OK);
db_status = sqlite3_bind_int(insert_stmt, sqlite3_bind_parameter_index(insert_stmt, "@tag_l_muPid"), tag_l_muPid);
assert(db_status == SQLITE_OK);
db_status = sqlite3_bind_double(insert_stmt, sqlite3_bind_parameter_index(insert_stmt, "@svm_score"), svm_score);
assert(db_status == SQLITE_OK);
}
4 changes: 4 additions & 0 deletions create_database/CandidateSQLiteTableBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class CandidateSQLiteTableBuilder : public SQLiteTableBuilder {
double sig_vtxh;
int sig_Dtype;
int sig_Dstartype;
int tag_l_ePid;
int tag_l_muPid;

double svm_score;

Expand Down Expand Up @@ -94,6 +96,8 @@ class CandidateSQLiteTableBuilder : public SQLiteTableBuilder {
void set_sig_vtxh(double value) { sig_vtxh = value; }
void set_sig_Dtype(int value) { sig_Dtype = value; }
void set_sig_Dstartype(int value) { sig_Dstartype = value; }
void set_tag_l_ePid(int value) { tag_l_ePid = value; }
void set_tag_l_muPid(int value) { tag_l_muPid = value; }

void set_svm_score(double value) { svm_score = value; }
};
Expand Down
Loading

0 comments on commit d1d95b2

Please sign in to comment.