diff --git a/nbd/builder/objs_dicts.py b/nbd/builder/objs_dicts.py index 66c7b76..ec62c1e 100644 --- a/nbd/builder/objs_dicts.py +++ b/nbd/builder/objs_dicts.py @@ -61,6 +61,15 @@ "postprocessing/fatjets/saturate_ranges_fatjets.json", ) +# taus imports +from nbd.extraction.taus import taus +from nbd.postprocessing.taus.columns_taus import ( + tau_cond, + reco_columns as reco_columns_taus, +) +from nbd.models.jets.jets_muons import load_mixture_model as load_model_taus +from nbd.postprocessing.taus.post_actions_taus import target_dictionary_taus + objs_dicts = { "Electron": { "derived_vars_func": electrons.extractGenElectronFeatures, @@ -149,12 +158,30 @@ "preprocess_dict": None, "gen_postprocessing_dict": None, }, + "Tau": { + "derived_vars_func": taus.extractGenTauFeatures, + "eff_model": None, + "eff_model_path": None, + "flow_loader": load_model_taus, + "flow_path": "/mnt/c/Users/user/Desktop/FlashSim-Tau/others/FlashSim-Models/tau_model@epoch500.pt", + "eff_columns": None, + "gen_columns": tau_cond, + "reco_columns": reco_columns_taus, + "vars_dictionary": target_dictionary_taus, + "scale_file_path": "/mnt/c/Users/user/Desktop/FlashSim-Tau/trainer/training/taus_v9/scale_factors_taus.json", + "batch_size": 10000, + "saturate_ranges_path": "/mnt/c/Users/user/Desktop/FlashSim-Tau/trainer/training/taus_v9/ranges_taus.json", + "eff": False, + "preprocess_dict": None, + "gen_postprocessing_dict": None, + }, } reco_objects = [ "Electron", "Muon", "Jet", + "Tau", # "FatJet", ] # list of FullSim branches to be copied and saved in the dedicated tree diff --git a/nbd/extraction/taus/init.py b/nbd/extraction/taus/init.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/nbd/extraction/taus/init.py @@ -0,0 +1 @@ + diff --git a/nbd/extraction/taus/taus.h b/nbd/extraction/taus/taus.h new file mode 100644 index 0000000..cf18463 --- /dev/null +++ b/nbd/extraction/taus/taus.h @@ -0,0 +1,256 @@ +// utilities for TAU +#ifndef UTILS_TAU_H +#define UTILS_TAU_H + +auto TDeltaPhi(ROOT::VecOps::RVec& Phi1, + ROOT::VecOps::RVec& Phi2) { + auto size = Phi1.size(); + ROOT::VecOps::RVec dphis; + dphis.reserve(size); + for (size_t i = 0; i < size; i++) { + Double_t dphi = TVector2::Phi_mpi_pi(Phi1[i] - Phi2[i]); + dphis.emplace_back(dphi); + } + return dphis; +} +auto Tclosest_jet_dr(ROOT::VecOps::RVec& etaj, + ROOT::VecOps::RVec& phij, + ROOT::VecOps::RVec& etat, + ROOT::VecOps::RVec& phit) { + + auto size_outer = etat.size(); + auto size_inner = etaj.size(); + ROOT::VecOps::RVec distances; + distances.reserve(size_outer); + for (size_t i = 0; i < size_outer; i++) { + distances.emplace_back(10); + float closest = 1; + for (size_t j = 0; j < size_inner; j++) { + Double_t deta = etat[i] - etaj[j]; + Double_t dphi = TVector2::Phi_mpi_pi(phit[i] - phij[j]); + float dr = TMath::Sqrt(deta * deta + dphi * dphi); + if (dr < closest) { + closest = dr; + } + } + if (closest < 1) { + distances[i] = closest; + } + } + return distances; +} +auto Tclosest_jet_mass(ROOT::VecOps::RVec& etaj, + ROOT::VecOps::RVec& phij, + ROOT::VecOps::RVec& etat, + ROOT::VecOps::RVec& phit, + ROOT::VecOps::RVec& massj) { + + auto size_outer = etat.size(); + auto size_inner = etaj.size(); + ROOT::VecOps::RVec masses; + masses.reserve(size_outer); + for (size_t i = 0; i < size_outer; i++) { + masses.emplace_back(-1); + float closest = 1; + for (size_t j = 0; j < size_inner; j++) { + Double_t deta = etat[i] - etaj[j]; + Double_t dphi = TVector2::Phi_mpi_pi(phit[i] - phij[j]); + float dr = TMath::Sqrt(deta * deta + dphi * dphi); + if (dr < closest) { + closest = dr; + masses[i] = massj[j]; + } + } + } + return masses; +} +auto Tclosest_jet_pt(ROOT::VecOps::RVec& etaj, + ROOT::VecOps::RVec& phij, + ROOT::VecOps::RVec& etat, + ROOT::VecOps::RVec& phit, + ROOT::VecOps::RVec& ptj) { + + auto size_outer = etat.size(); + auto size_inner = etaj.size(); + ROOT::VecOps::RVec pts; + pts.reserve(size_outer); + for (size_t i = 0; i < size_outer; i++) { + pts.emplace_back(-1); + float closest = 1; + for (size_t j = 0; j < size_inner; j++) { + Double_t deta = etat[i] - etaj[j]; + Double_t dphi = TVector2::Phi_mpi_pi(phit[i] - phij[j]); + float dr = TMath::Sqrt(deta * deta + dphi * dphi); + if (dr < closest) { + closest = dr; + pts[i] = ptj[j]; + } + } + } + return pts; +} +auto Tclosest_jet_deta(ROOT::VecOps::RVec& etaj, + ROOT::VecOps::RVec& phij, + ROOT::VecOps::RVec& etat, + ROOT::VecOps::RVec& phit) { + + auto size_outer = etat.size(); + auto size_inner = etaj.size(); + ROOT::VecOps::RVec detas; + detas.reserve(size_outer); + for (size_t i = 0; i < size_outer; i++) { + detas.emplace_back(10); + float closest = 1; + for (size_t j = 0; j < size_inner; j++) { + Double_t deta = etat[i] - etaj[j]; + Double_t dphi = TVector2::Phi_mpi_pi(phit[i] - phij[j]); + float dr = TMath::Sqrt(deta * deta + dphi * dphi); + if (dr < closest) { + closest = dr; + detas[i] = deta; + } + } + } + return detas; +} +auto Tclosest_jet_dphi(ROOT::VecOps::RVec& etaj, + ROOT::VecOps::RVec& phij, + ROOT::VecOps::RVec& etat, + ROOT::VecOps::RVec& phit) { + + auto size_outer = etat.size(); + auto size_inner = etaj.size(); + ROOT::VecOps::RVec dphis; + dphis.reserve(size_outer); + for (size_t i = 0; i < size_outer; i++) { + dphis.emplace_back(10); + float closest = 1; + for (size_t j = 0; j < size_inner; j++) { + Double_t deta = etat[i] - etaj[j]; + Double_t dphi = TVector2::Phi_mpi_pi(phit[i] - phij[j]); + float dr = TMath::Sqrt(deta * deta + dphi * dphi); + if (dr < closest) { + closest = dr; + dphis[i] = dphi; + } + } + } + return dphis; +} +auto TBitwiseDecoder(ROOT::VecOps::RVec& ints, int bit) { + auto size = ints.size(); + ROOT::VecOps::RVec bits; + bits.reserve(size); + int num = pow(2, (bit)); + for (size_t i = 0; i < size; i++) { + Double_t bAND = ints[i] & num; + if (bAND == num) { + bits.emplace_back(1); + } + else { + bits.emplace_back(0); + } + } + return bits; +} + +auto taus_per_event(ROOT::VecOps::RVec& MGM) { + int size = MGM.size(); + return size; +} + +auto Tcharge(ROOT::VecOps::RVec& pdgId) { + auto size = pdgId.size(); + ROOT::VecOps::RVec charge; + charge.reserve(size); + for (size_t i = 0; i < size; i++) { + if (pdgId[i] == -15) + charge.emplace_back(+1); + else + charge.emplace_back(-1); + } + return charge; +} + +auto Tmatch_reco_to_gen( + ROOT::VecOps::RVec& Tau_genPartIdx, // Tau_genPartIdx + ROOT::VecOps::RVec& GenPart_statusFlags) { // GenPart_statusFlags + + auto size = Tau_genPartIdx.size(); + ROOT::VecOps::RVec indexes(size); + for (size_t i = 0; i < size; i++) { + indexes[i] = -1; + auto curr_index = Tau_genPartIdx[i]; + if ((curr_index >= 0) && ((GenPart_statusFlags[curr_index] & 8192) > 0)) { + indexes[i] = curr_index; + } + } + return indexes; +} + +auto Tclean_genjet_mask(ROOT::VecOps::RVec& jet_pt, + ROOT::VecOps::RVec& jet_eta, + ROOT::VecOps::RVec& jet_phi, + ROOT::VecOps::RVec& lep_pt, + ROOT::VecOps::RVec& lep_eta, + ROOT::VecOps::RVec& lep_phi) { + /* Mask to remove GenElectrons and GenMuons from the GenJet collection.*/ + auto lep_size = lep_pt.size(); + auto jet_size = jet_pt.size(); + + ROOT::VecOps::RVec clean_jet_mask; + clean_jet_mask.reserve(jet_size); + + for (size_t i = 0; i < jet_size; i++) { + clean_jet_mask.push_back(1); + for (size_t j = 0; j < lep_size; j++) { + auto dpt = jet_pt[i] - lep_pt[j]; + auto deta = jet_eta[i] - lep_eta[j]; + auto dphi = TVector2::Phi_mpi_pi(jet_phi[i] - lep_phi[j]); + auto dr = TMath::Sqrt(deta * deta + dphi * dphi); + + if ((dr <= 0.01) && ((dpt / lep_pt[j]) <= 0.001)) { + clean_jet_mask[i] = 0; + } + } + } + return clean_jet_mask; +} + +auto Tclosest_jet_flavour_encoder(ROOT::VecOps::RVec& etaj, + ROOT::VecOps::RVec& phij, + ROOT::VecOps::RVec& etae, + ROOT::VecOps::RVec& phie, + ROOT::VecOps::RVec& fj, + ROOT::VecOps::RVec flavours) { + + /* General function to encode the hadron and parton flavour of the closest + Jet object. To be used for flavour one-hot encoding for training. + */ + + auto size_outer = etae.size(); + auto size_inner = etaj.size(); + auto n_flavours = flavours.size(); + ROOT::VecOps::RVec fenc; + fenc.reserve(size_outer); + for (size_t i = 0; i < size_outer; i++) { + fenc.emplace_back(0); + float closest = 1; + for (size_t j = 0; j < size_inner; j++) { + Double_t deta = etae[i] - etaj[j]; + Double_t dphi = TVector2::Phi_mpi_pi(phie[i] - phij[j]); + float dr = TMath::Sqrt(deta * deta + dphi * dphi); + if (dr < closest) { + closest = dr; + for (size_t k = 0; k < n_flavours; k++) { + if (abs(fj[j]) == flavours[k]) { + fenc[i] = 1; + } + } + } + } + } + return fenc; +} + +#endif \ No newline at end of file diff --git a/nbd/extraction/taus/taus.py b/nbd/extraction/taus/taus.py new file mode 100644 index 0000000..6702055 --- /dev/null +++ b/nbd/extraction/taus/taus.py @@ -0,0 +1,143 @@ +import os +import ROOT + +module_path = os.path.join(os.path.dirname(__file__), "taus.h") + +ROOT.gInterpreter.ProcessLine(f'#include "{module_path}"') + + +def jet_cleaning(d): + cleaned = ( + d.Define("TMPGenElectronMask", "abs(GenPart_pdgId) == 11") + .Define("TMPGenElectron_pt", "GenPart_pt[TMPGenElectronMask]") + .Define("TMPGenElectron_eta", "GenPart_eta[TMPGenElectronMask]") + .Define("TMPGenElectron_phi", "GenPart_phi[TMPGenElectronMask]") + .Define("TMPGenMuonMask", "abs(GenPart_pdgId) == 13") + .Define("TMPGenMuon_pt", "GenPart_pt[TMPGenMuonMask]") + .Define("TMPGenMuon_eta", "GenPart_eta[TMPGenMuonMask]") + .Define("TMPGenMuon_phi", "GenPart_phi[TMPGenMuonMask]") + .Define("TMPGenTauMask", "abs(GenPart_pdgId) == 15") + .Define("TMPGenTau_pt", "GenPart_pt[TMPGenTauMask]") + .Define("TMPGenTau_eta", "GenPart_eta[TMPGenTauMask]") + .Define("TMPGenTau_phi", "GenPart_phi[TMPGenTauMask]") + .Define( + "CleanGenJet_mask_ele", + "Tclean_genjet_mask(GenJet_pt, GenJet_eta, GenJet_phi, TMPGenElectron_pt, TMPGenElectron_eta, TMPGenElectron_phi)", + ) + .Define( + "CleanGenJet_mask_muon", + "Tclean_genjet_mask(GenJet_pt, GenJet_eta, GenJet_phi, TMPGenMuon_pt, TMPGenMuon_eta, TMPGenMuon_phi)", + ) + .Define( + "CleanGenJet_mask_tau", + "Tclean_genjet_mask(GenJet_pt, GenJet_eta, GenJet_phi, TMPGenTau_pt, TMPGenTau_eta, TMPGenTau_phi)", + ) + .Define("CleanGenJetMask", "CleanGenJet_mask_ele && CleanGenJet_mask_muon") + .Define("CleanGenJet_pt", "GenJet_pt[CleanGenJetMask]") + .Define("CleanGenJet_eta", "GenJet_eta[CleanGenJetMask]") + .Define("CleanGenJet_phi", "GenJet_phi[CleanGenJetMask]") + .Define("CleanGenJet_mass", "GenJet_mass[CleanGenJetMask]") + .Define( + "CleanGenJet_hadronFlavour_uchar", "GenJet_hadronFlavour[CleanGenJetMask]" + ) + .Define( + "CleanGenJet_hadronFlavour", + "static_cast>(CleanGenJet_hadronFlavour_uchar)", + ) + .Define("CleanGenJet_partonFlavour", "GenJet_partonFlavour[CleanGenJetMask]") + ) + + return cleaned + + +def extractGenTauFeatures(df): + """for getting gentau, recotau and cleaned genjet features + + Args: + df (rdataframe): original rdataframe (should be cleaned by jet copies) + + Returns: + rdataframe: rdataframe with new features + """ + df1 = jet_cleaning(df) + extracted = ( + df1.Define( + "TauMaskJ", + "(GenPart_pdgId == 15 | GenPart_pdgId == -15)&&((GenPart_statusFlags & 8192) > 0)", + ) + .Define("MGenTau_eta", "GenPart_eta[TauMaskJ]") + .Define("MGenTau_pdgId", "GenPart_pdgId[TauMaskJ]") + .Define("MGenTau_charge", "Tcharge(MGenTau_pdgId)") + .Define("MGenTau_phi", "GenPart_phi[TauMaskJ]") + .Define("MGenTau_pt", "GenPart_pt[TauMaskJ]") + .Define("MGenPart_statusFlags", "GenPart_statusFlags[TauMaskJ]") + .Define("MGenPart_statusFlags0", "TBitwiseDecoder(MGenPart_statusFlags, 0)") + .Define("MGenPart_statusFlags1", "TBitwiseDecoder(MGenPart_statusFlags, 1)") + .Define("MGenPart_statusFlags2", "TBitwiseDecoder(MGenPart_statusFlags, 2)") + .Define("MGenPart_statusFlags3", "TBitwiseDecoder(MGenPart_statusFlags, 3)") + .Define("MGenPart_statusFlags4", "TBitwiseDecoder(MGenPart_statusFlags, 4)") + .Define("MGenPart_statusFlags5", "TBitwiseDecoder(MGenPart_statusFlags, 5)") + .Define("MGenPart_statusFlags6", "TBitwiseDecoder(MGenPart_statusFlags, 6)") + .Define("MGenPart_statusFlags7", "TBitwiseDecoder(MGenPart_statusFlags, 7)") + .Define("MGenPart_statusFlags8", "TBitwiseDecoder(MGenPart_statusFlags, 8)") + .Define("MGenPart_statusFlags9", "TBitwiseDecoder(MGenPart_statusFlags, 9)") + .Define("MGenPart_statusFlags10", "TBitwiseDecoder(MGenPart_statusFlags, 10)") + .Define("MGenPart_statusFlags11", "TBitwiseDecoder(MGenPart_statusFlags, 11)") + .Define("MGenPart_statusFlags12", "TBitwiseDecoder(MGenPart_statusFlags, 12)") + .Define("MGenPart_statusFlags13", "TBitwiseDecoder(MGenPart_statusFlags, 13)") + .Define("MGenPart_statusFlags14", "TBitwiseDecoder(MGenPart_statusFlags, 14)") + .Define( + "ClosestJet_dr", + "Tclosest_jet_dr(CleanGenJet_eta, CleanGenJet_phi, MGenTau_eta, MGenTau_phi)", + ) + .Define( + "ClosestJet_deta", + "Tclosest_jet_deta(CleanGenJet_eta, CleanGenJet_phi, MGenTau_eta, MGenTau_phi)", + ) + .Define( + "ClosestJet_dphi", + "Tclosest_jet_dphi(CleanGenJet_eta, CleanGenJet_phi, MGenTau_eta, MGenTau_phi)", + ) + .Define( + "ClosestJet_pt", + "Tclosest_jet_pt(CleanGenJet_eta, CleanGenJet_phi, MGenTau_eta, MGenTau_phi, CleanGenJet_pt)", + ) + .Define( + "ClosestJet_mass", + "Tclosest_jet_mass(CleanGenJet_eta, CleanGenJet_phi, MGenTau_eta, MGenTau_phi, CleanGenJet_mass)", + ) + .Define( + "ClosestJet_EncodedPartonFlavour_light", + "Tclosest_jet_flavour_encoder(CleanGenJet_eta, CleanGenJet_phi, MGenTau_eta, MGenTau_phi, CleanGenJet_partonFlavour, ROOT::VecOps::RVec{1,2,3})", + ) + .Define( + "ClosestJet_EncodedPartonFlavour_gluon", + "Tclosest_jet_flavour_encoder(CleanGenJet_eta, CleanGenJet_phi, MGenTau_eta, MGenTau_phi, CleanGenJet_partonFlavour, ROOT::VecOps::RVec{21})", + ) + .Define( + "ClosestJet_EncodedPartonFlavour_c", + "Tclosest_jet_flavour_encoder(CleanGenJet_eta, CleanGenJet_phi, MGenTau_eta, MGenTau_phi, CleanGenJet_partonFlavour, ROOT::VecOps::RVec{4})", + ) + .Define( + "ClosestJet_EncodedPartonFlavour_b", + "Tclosest_jet_flavour_encoder(CleanGenJet_eta, CleanGenJet_phi, MGenTau_eta, MGenTau_phi, CleanGenJet_partonFlavour, ROOT::VecOps::RVec{5})", + ) + .Define( + "ClosestJet_EncodedPartonFlavour_undefined", + "Tclosest_jet_flavour_encoder(CleanGenJet_eta, CleanGenJet_phi, MGenTau_eta, MGenTau_phi, CleanGenJet_partonFlavour, ROOT::VecOps::RVec{0})", + ) + .Define( + "ClosestJet_EncodedHadronFlavour_b", + "Tclosest_jet_flavour_encoder(CleanGenJet_eta, CleanGenJet_phi, MGenTau_eta, MGenTau_phi, CleanGenJet_hadronFlavour, ROOT::VecOps::RVec{5})", + ) + .Define( + "ClosestJet_EncodedHadronFlavour_c", + "Tclosest_jet_flavour_encoder(CleanGenJet_eta, CleanGenJet_phi, MGenTau_eta, MGenTau_phi, CleanGenJet_hadronFlavour, ROOT::VecOps::RVec{4})", + ) + .Define( + "ClosestJet_EncodedHadronFlavour_light", + "Tclosest_jet_flavour_encoder(CleanGenJet_eta, CleanGenJet_phi, MGenTau_eta, MGenTau_phi, CleanGenJet_hadronFlavour, ROOT::VecOps::RVec{0})", + ) + ) + + return extracted \ No newline at end of file diff --git a/nbd/postprocessing/postprocessing.py b/nbd/postprocessing/postprocessing.py index 841cfb7..dccdd2a 100644 --- a/nbd/postprocessing/postprocessing.py +++ b/nbd/postprocessing/postprocessing.py @@ -72,8 +72,8 @@ def restore_range(column_name, scale_dict, df): return df[column_name] -def inverse_transform(df, column_name, function, p): - df[column_name] = df[column_name].apply(lambda x: (function(x) - p[1]) / p[0]) +def inverse_transform(df, column_name, function, p, *args): + df[column_name] = df[column_name].apply(lambda x: (function(*args, x) - p[1]) / p[0]) return df[column_name] @@ -144,6 +144,20 @@ def unsmear_jetId(df, column_name): return df[column_name] +def unsmear_decayMode(df, column_name): + """Unsmear the decayMode setting values to 0, 1, 2, 5, 6, 7, 10, 11""" + val = df[column_name].values + val = np.rint(val) + val = np.where(val <= 0, 0, val) + val = np.where(val == 3, 5, val) + val = np.where(val == 4, 5, val) + val = np.where(val == 8, 10, val) + val = np.where(val == 9, 10, val) + val = np.where(val >= 11, 11, val) + df[column_name] = val + return df[column_name] + + def cut_unsmearing(df, column_name, cut, x1, x2): val = df[column_name].values df[column_name] = np.where(val < cut, x1, x2) @@ -174,7 +188,10 @@ def process_column_var(column_name, operations, df, gen_df, saturate_ranges_path elif op[0] == "uj": df[column_name] = unsmear_jetId(df, column_name) - + + elif op[0] == "udm": + df[column_name] = unsmear_decayMode(df, column_name) + elif op[0] == "c": cut = op[1] vals = op[2] @@ -183,7 +200,11 @@ def process_column_var(column_name, operations, df, gen_df, saturate_ranges_path elif op[0] == "i": function = op[1] p = op[2] - df[column_name] = inverse_transform(df, column_name, function, p) + if len(op) == 3: + df[column_name] = inverse_transform(df, column_name, function, p) + else: + args = op[3] + df[column_name] = inverse_transform(df, column_name, function, p, args) elif op[0] == "m": gen_column_name = op[1] diff --git a/nbd/postprocessing/taus/columns_taus.py b/nbd/postprocessing/taus/columns_taus.py new file mode 100644 index 0000000..9fc8e9e --- /dev/null +++ b/nbd/postprocessing/taus/columns_taus.py @@ -0,0 +1,71 @@ +# Description: Columns for muons +tau_cond = [ + "MGenTau_eta", + "MGenTau_phi", + "MGenTau_pt", + "MGenTau_charge", + "MGenPart_statusFlags0", + "MGenPart_statusFlags1", + "MGenPart_statusFlags2", + "MGenPart_statusFlags3", + "MGenPart_statusFlags4", + "MGenPart_statusFlags5", + "MGenPart_statusFlags6", + "MGenPart_statusFlags7", + "MGenPart_statusFlags8", + "MGenPart_statusFlags9", + "MGenPart_statusFlags10", + "MGenPart_statusFlags11", + "MGenPart_statusFlags12", + "MGenPart_statusFlags13", + "MGenPart_statusFlags14", + "ClosestJet_dr", + "ClosestJet_deta", + "ClosestJet_dphi", + "ClosestJet_pt", + "ClosestJet_mass", + "ClosestJet_EncodedPartonFlavour_light", + "ClosestJet_EncodedPartonFlavour_gluon", + "ClosestJet_EncodedPartonFlavour_c", + "ClosestJet_EncodedPartonFlavour_b", + "ClosestJet_EncodedPartonFlavour_undefined", + "ClosestJet_EncodedHadronFlavour_b", + "ClosestJet_EncodedHadronFlavour_c", + "ClosestJet_EncodedHadronFlavour_light", + "Pileup_gpudensity", + "Pileup_nPU", + "Pileup_nTrueInt", + "Pileup_pudensity", + "Pileup_sumEOOT", + "Pileup_sumLOOT", +] + +tau_names = [ + "dz", + "dxy", + "rawDeepTau2017v2p1VSmu", + "puCorr", + "leadTkDeltaPhi", + "leadTkDeltaEta", + "rawIso", + "chargedIso", + "rawDeepTau2017v2p1VSe", + "rawIsodR03", + "rawDeepTau2017v2p1VSjet", + "leadTkPtOverTauPt", + "idDeepTau2017v2p1VSe", + "idDeepTau2017v2p1VSjet", + "decayMode", + "charge", + "idDeepTau2017v2p1VSmu", + "idAntiMu", + "idDecayModeOldDMs", + "idAntiEleDeadECal", + "etaMinusGen", + "filteredphi", + "phiMinusGen", + "ptRatio", + "cleanmask" + ] + +reco_columns = [f"Tau_{name}" for name in tau_names] \ No newline at end of file diff --git a/nbd/postprocessing/taus/init.py b/nbd/postprocessing/taus/init.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/nbd/postprocessing/taus/init.py @@ -0,0 +1 @@ + diff --git a/nbd/postprocessing/taus/post_actions_taus.py b/nbd/postprocessing/taus/post_actions_taus.py new file mode 100644 index 0000000..2f89ee4 --- /dev/null +++ b/nbd/postprocessing/taus/post_actions_taus.py @@ -0,0 +1,77 @@ +import numpy as np + +""" +Dictionary of postprocessing operations for conditioning and target variables. +It is generated make_dataset function. Values of dictionary are list objects in which +sepcify preprocessing operation. Every operation has the following template + + ["string", *pars] + +where "string" tells which operation to perform and *pars its parameters. Such operations are + +unsmearing: ["d", [inf, sup]] +transformation: ["i", func, [a, b], *args] # (func(*args, x) - b) / a + +In the case of multiple operations, order follows the operation list indexing. +""" + +target_dictionary = { + 'dz': [["i", np.tan, [50, 0]]], + 'dxy': [["i", np.tan, [150, 0]]], + 'leadTkDeltaPhi': [ + ["i", np.tan, [80, 0]], + ], + 'leadTkDeltaEta': [ + ["i", np.tan, [100, 0]], + ], + 'rawIsodR03': [ + ["d", [-np.inf, -7.5], np.log(0.00001)], + ["i", np.exp, [1, 0.00001]], + ], + 'leadTkPtOverTauPt': [ + ["i", np.tan, [10, -10]], + ], + 'idDeepTau2017v2p1VSe': [ + ["d", None, None], + ["i", np.power, [1, 1], 2] + ], + 'idDeepTau2017v2p1VSjet': [ + ["d", None, None], + ["i", np.power, [1, 1], 2] + ], + 'decayMode': [["udm"]], + 'charge': [["c", 0.0, [-1, 1]]], + 'idDeepTau2017v2p1VSmu': [ + ["d", None, None], + ["i", np.power, [1, 1], 2] + ], + 'idAntiMu': [["d", None, None]], + 'idDecayModeOldDMs': [["d", None, None]], + 'idAntiEleDeadECal': [["d", None, None]], + "etaMinusGen": [ + ["i", np.tan, [100, 0]], + ["s"], + ["a", "MGenTau_eta"], + ["rename", "Tau_eta"], + ], + "phiMinusGen": [ + ["i", np.tan, [80, 0]], + ["s"], + ["a", "MGenTau_phi"], + ["pmp"], + ["rename", "Tau_phi"], + ], + 'ptRatio': [ + ["i", np.tan, [10, -10]], + ["s"], + ["m", "MGenTau_pt"], + ["rename", "Tau_pt"], + ], + 'cleanmask': [["c", 0.5, [0, 1]]], + 'mass': [["create", 1.7768610]], +} + + +target_dictionary_taus = {} +for key, value in target_dictionary.items(): + target_dictionary_taus["Tau_" + key] = value