Skip to content

Commit

Permalink
Redefined B MC types. Some changes initial changes towards computing …
Browse files Browse the repository at this point in the history
…those types in the event
  • Loading branch information
dchao committed Aug 1, 2014
1 parent 75f100e commit ffb55a4
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 125 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions build_generic_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ int main() {
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_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());
Expand Down
103 changes: 74 additions & 29 deletions create_database/BDtaunuMcReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ std::vector<int> BDtaunuMcReader::build_dstrange() {
}
const std::vector<int> BDtaunuMcReader::dstrange = build_dstrange();

// pion.
std::vector<int> BDtaunuMcReader::build_pion() {
std::vector<int> 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<int> BDtaunuMcReader::pion = build_pion();


BDtaunuMcReader::BDtaunuMcReader() : BDtaunuReader() {
Initialize();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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]);
Expand All @@ -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;
}
Expand All @@ -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;
}
}
}
}

Expand All @@ -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);

}

Expand Down
14 changes: 12 additions & 2 deletions create_database/BDtaunuMcReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ class BDtaunuMcReader : public BDtaunuReader {
const static std::vector<int> dstar;
const static std::vector<int> dstarstar;
const static std::vector<int> dstrange;
const static std::vector<int> pion;

static std::vector<int> build_ell();
static std::vector<int> build_nu();
static std::vector<int> build_dmeson();
static std::vector<int> build_dstar();
static std::vector<int> build_dstarstar();
static std::vector<int> build_dstrange();
static std::vector<int> build_pion();

protected:
int mcLen;
Expand All @@ -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();
Expand Down Expand Up @@ -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
68 changes: 22 additions & 46 deletions create_database/McEventSQLiteTableBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ McEventSQLiteTableBuilder::McEventSQLiteTableBuilder(sqlite3* database, const ch
meta_colnames.push_back(std::pair<std::string, std::string>("ml_sample", "TEXT"));
meta_colnames.push_back(std::pair<std::string, std::string>("division", "TEXT"));
meta_colnames.push_back(std::pair<std::string, std::string>("mc_evttypeA", "INTEGER"));
meta_colnames.push_back(std::pair<std::string, std::string>("mc_evttypeB", "INTEGER"));
meta_colnames.push_back(std::pair<std::string, std::string>("b1mctype", "INTEGER"));
meta_colnames.push_back(std::pair<std::string, std::string>("b2mctype", "INTEGER"));
meta_colnames.push_back(std::pair<std::string, std::string>("b1_taumctype", "INTEGER"));
meta_colnames.push_back(std::pair<std::string, std::string>("b2_taumctype", "INTEGER"));
meta_colnames.push_back(std::pair<std::string, std::string>("b1_dtau_max_photon_energy", "REAL"));
meta_colnames.push_back(std::pair<std::string, std::string>("b2_dtau_max_photon_energy", "REAL"));

BuildCachedDataMap(assignment_fname);
}
Expand All @@ -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);
}

Expand All @@ -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)) {
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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;
}
}
7 changes: 6 additions & 1 deletion create_database/McEventSQLiteTableBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -23,7 +25,6 @@ class McEventSQLiteTableBuilder : public EventSQLiteTableBuilder {
void BindColumns();

int DetermineMcEventTypeDefA() const;
int DetermineMcEventTypeDefB() const;

public:
McEventSQLiteTableBuilder() {};
Expand All @@ -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; }
};
Expand Down
Loading

0 comments on commit ffb55a4

Please sign in to comment.