diff --git a/analysis/topeft_run2/analysis_processor.py b/analysis/topeft_run2/analysis_processor.py index b5c6c3353..ba4bcd0ca 100644 --- a/analysis/topeft_run2/analysis_processor.py +++ b/analysis/topeft_run2/analysis_processor.py @@ -284,6 +284,10 @@ def process(self, events): xsec = self._samples[dataset]["xsec"] sow = self._samples[dataset]["nSumOfWeights"] + print("\n\n\n\n\n") + print("histAxisName:", histAxisName) + print("\n\n\n\n\n") + is_run3 = False if year.startswith("202"): is_run3 = True @@ -495,7 +499,9 @@ def _log_tau_flag_counts(label, flag_arrays): ################### Tau selection #################### if self.tau_h_analysis: - tau["pt"], tau["mass"] = ApplyTES(year, tau, isData) + tau_fo_tag = "VLoose" if is_run2 else "Loose" + tau_T_tag = "Loose" if is_run2 else "Medium" + if is_run2: vs_jet = tau.idDeepTau2017v2p1VSjet vs_e = tau.idDeepTau2017v2p1VSe @@ -505,8 +511,11 @@ def _log_tau_flag_counts(label, flag_arrays): vs_e = tau.idDeepTau2018v2p5VSe vs_mu = tau.idDeepTau2018v2p5VSmu + tau["pt"], tau["mass"] = ApplyTES(year, tau, isData, tau_T_tag) + tau["isVLoose"] = tauSelection.isVLooseTau(vs_jet) tau["isLoose"] = tauSelection.isLooseTau(vs_jet) + tau["isMedium"] = tauSelection.isMediumTau(vs_jet) tau["iseTight"] = tauSelection.iseTightTau(vs_e) tau["ismTight"] = ak.values_astype(tauSelection.ismTightTau(vs_mu), np.int8) tau["isPresVLoose"] = tauSelection.isPresTau( @@ -531,7 +540,19 @@ def _log_tau_flag_counts(label, flag_arrays): minpt=20, vsJetWP="Loose", ) - tau["isPres"] = tau["isPresVLoose"] + tau["isPresMedium"] = tauSelection.isPresTau( + tau.pt, + tau.eta, + tau.dxy, + tau.dz, + vs_jet, + vs_e, + vs_mu, + minpt=20, + vsJetWP="Medium", + ) + + tau["isPres"] = tau[f"isPres{tau_fo_tag}"] tau["isClean"] = te_os.isClean(tau, l_fo, drmin=0.3) tau["isGood"] = tau["isClean"] & tau["isPres"] @@ -559,28 +580,28 @@ def _log_tau_flag_counts(label, flag_arrays): ) tau = tau[tau['DMflag']] - tau_vloose = tau - tau_vloose_padded = ak.pad_none(tau_vloose, 1) - tau0_vloose = tau_vloose_padded[:,0] + tau_fo = tau + tau_fo_padded = ak.pad_none(tau_fo, 1) + tau0_fo = tau_fo_padded[:,0] - tau_loose = tau_vloose[tau_vloose["isLoose"]>0] - tau_loose_padded = ak.pad_none(tau_loose, 1) - tau0_loose = tau_loose_padded[:,0] + tau_T = tau_fo[tau_fo["isLoose"]>0] + tau_T_padded = ak.pad_none(tau_T, 1) + tau0_T = tau_T_padded[:,0] - cleaning_taus = tau_loose - nLtau = ak.num(tau_loose) + cleaning_taus = tau_T + nLtau = ak.num(tau_T) if self.tau_run_mode == "standard": - tau_F_mask = (ak.num(tau_vloose) == 1) + tau_F_mask = (ak.num(tau_fo) == 1) tau_L_mask = (nLtau == 1) elif self.tau_run_mode == "taufitter": - tau_F_mask = (ak.num(tau_vloose) >= 1) + tau_F_mask = (ak.num(tau_fo) >= 1) tau_L_mask = (nLtau >= 1) else: raise ValueError(f"Unknown tau_run_mode '{self.tau_run_mode}'") no_tau_mask = (nLtau == 0) - tau0 = ak.where(tau_L_mask, tau0_loose, tau0_vloose) + tau0 = tau0_T _log_tau_flag_counts( "tau_h_event_masks", @@ -592,20 +613,16 @@ def _log_tau_flag_counts(label, flag_arrays): ) if not isData: - AttachTauSF(events, tau_loose, year=year, vsJetWP="Loose") - - # if (not self._tau_wp_checked) and len(events) > 0: - # n_tau_vloose = int(ak.sum(tau_F_mask)) - # n_tau_loose = int(ak.sum(tau_L_mask)) - # n_tau_vloose_only = int(ak.sum(tau_F_mask & ~tau_L_mask)) - # print( - # f"\n\n\n\n\n\n\n\n\n[Tau WP check - {self.tau_run_mode}] Events with >=1 VLoose tau: {ak.to_list(n_tau_vloose)};\n>=1 Loose tau: {ak.to_list(n_tau_loose)};\nVLoose-only: {ak.to_list(n_tau_vloose_only)}\n\n\n\n\n\n\n\n\n" - # ) - # if self.tau_run_mode == "standard": - # masks_identical = bool(ak.all(tau_F_mask == tau_L_mask)) if len(events) > 0 else False - # if masks_identical and (n_tau_vloose > 0 or n_tau_loose > 0): - # raise AssertionError("Ftau and Ttau masks are identical; check tau WP separation") - # self._tau_wp_checked = True + AttachTauSF(events, tau_T, year=year, vsJetWP=tau_T_tag) + # print("\n\n\n\n\n\n") + # print("taus[pt]", ak.to_list(tau_T.pt)) + # print("taus[isLoose]", ak.to_list(tau_T.isLoose)) + # print("taus[isMedium]", ak.to_list(tau_T.isMedium)) + # print("taus[sf_tau_real]", ak.to_list(tau_T.sf_tau_real)) + # print("taus[sf_tau_fake]", ak.to_list(tau_T.sf_tau_fake)) + # print("events[sf_2l_taus_real]", ak.to_list(events["sf_2l_taus_real"])) + # print("events[sf_2l_taus_fake]", ak.to_list(events["sf_2l_taus_fake"])) + # print("\n\n\n\n\n\n") else: if is_run2: @@ -763,8 +780,8 @@ def _log_tau_flag_counts(label, flag_arrays): if not isData: cleanedJets["pt_gen"] = ak.values_astype(ak.fill_none(cleanedJets.matched_gen.pt, 0), np.float32) if self.tau_h_analysis: - tau["pt"], tau["mass"] = ApplyTESSystematic(year, tau, isData, syst_var) - tau["pt"], tau["mass"] = ApplyFESSystematic(year, tau, isData, syst_var) + tau["pt"], tau["mass"] = ApplyTESSystematic(year, tau, isData, syst_var, tau_T_tag) + tau["pt"], tau["mass"] = ApplyFESSystematic(year, tau, isData, syst_var, tau_T_tag) events_cache = events.caches[0] cleanedJets = ApplyJetCorrections(year, corr_type='jets', isData=isData, era=run_era).build(cleanedJets, lazy_cache=events_cache) #Run3 ready @@ -932,7 +949,7 @@ def _log_tau_flag_counts(label, flag_arrays): select_cat_dict = json.load(ch_json_test) if not self._skip_signal_regions: - # If we are not skipping the signal regions, we will import the SR categories + # If we are not skipping the signal regions, we will import the SR categories # This dictionary keeps track of which selections go with which SR categories if self.offZ_3l_split: import_sr_cat_dict = select_cat_dict["OFFZ_SPLIT_CH_LST_SR"] @@ -940,15 +957,19 @@ def _log_tau_flag_counts(label, flag_arrays): import_sr_cat_dict = select_cat_dict["TAU_CH_LST_SR"] elif self.fwd_analysis: import_sr_cat_dict = select_cat_dict["FWD_CH_LST_SR"] + elif self.all_analysis: + import_sr_cat_dict = select_cat_dict["ALL_CH_LST_SR"] else: import_sr_cat_dict = select_cat_dict["TOP22_006_CH_LST_SR"] if not self._skip_control_regions: - # If we are not skipping the control regions, we will import the CR categories + # If we are not skipping the control regions, we will import the CR categories # This dictionary keeps track of which selections go with which CR categories - import_cr_cat_dict = select_cat_dict["CH_LST_CR"] - if self.tau_h_analysis: - import_cr_cat_dict.update(select_cat_dict["TAU_CH_LST_CR"]) + if self.tau_h_analysis or self.all_analysis: + import_cr_cat_dict = select_cat_dict["TAU_CH_LST_CR"] + else: + import_cr_cat_dict = select_cat_dict["CH_LST_CR"] + #This list keeps track of the lepton categories lep_cats = [] @@ -1414,7 +1435,8 @@ def _log_tau_flag_counts(label, flag_arrays): if self.tau_h_analysis: varnames["ptz_wtau"] = ptz_wtau - varnames["tau0pt"] = tau0.pt + varnames["tau0Tpt"] = tau0_T.pt + varnames["tau0Fpt"] = tau0_fo.pt pass for varname, var in varnames.items(): diff --git a/analysis/topeft_run2/run_analysis.py b/analysis/topeft_run2/run_analysis.py index 5f259a9af..bd28f8cee 100644 --- a/analysis/topeft_run2/run_analysis.py +++ b/analysis/topeft_run2/run_analysis.py @@ -486,7 +486,8 @@ def _cleanup_work_queue_staging_directory(path, eligible_for_cleanup): hist_lst = ["njets", "lj0pt", "ptz"] if tau_h_analysis: hist_lst.append("ptz_wtau") - hist_lst.append("tau0pt") + hist_lst.append("tau0Tpt") + hist_lst.append("tau0Fpt") if fwd_analysis: hist_lst.append("lt") if "lepton_pt_vs_eta" not in hist_lst: @@ -560,7 +561,8 @@ def _cleanup_work_queue_staging_directory(path, eligible_for_cleanup): # "l1_eta_vs_phi", ] if tau_h_analysis: - hist_lst.append("tau0pt") + hist_lst.append("tau0Tpt") + hist_lst.append("tau0Fpt") else: # We want to specify a custom list # If we don't specify this argument, it will be None, and the processor will fill all hists @@ -606,7 +608,7 @@ def LoadJsonToSampleName(jsonFile, prefix): # Open cfg files else: with open(f) as fin: - print(" >> Reading json from cfg file...") + print(" >> Reading json from cfg file...", f) lines = fin.readlines() for l in lines: if "#" in l: @@ -679,7 +681,11 @@ def LoadJsonToSampleName(jsonFile, prefix): requested_years.update(year_synonyms.get(year_str, {year_str})) + print(">> Loaded a total of %i samples from json files." % len(samplesdict)) + print("requested_years:", requested_years) + if requested_years is not None: + print([sample.get("year") for sample in samplesdict.values()]) samplesdict = { name: sample for name, sample in samplesdict.items() diff --git a/topeft/channels/ch_lst.json b/topeft/channels/ch_lst.json index d0d36cd01..3f156e026 100644 --- a/topeft/channels/ch_lst.json +++ b/topeft/channels/ch_lst.json @@ -381,10 +381,10 @@ "jet_lst": [ "=2", "=3", - ">4" + "=4" ] }, - "1l_1tau_CR": { + "1l_1tau_CRtt": { "lep_chan_lst": [ [ "1l_1tau_CR", @@ -398,8 +398,7 @@ "m" ], "appl_lst": [ - "isSR_1l", - "isAR_1l" + "isSR_1l" ], "jet_lst": [ "=2", @@ -407,7 +406,7 @@ "=4" ] }, - "1l_dy_tautau_CR": { + "1l_1tau_CRDY": { "lep_chan_lst": [ [ "1l_dy_tautau_CR", @@ -430,38 +429,15 @@ "=3", "=4" ] - } - }, - "OFFZ_SPLIT_CH_LST_SR": { - "2l": { + }, + "2l_CR": { "lep_chan_lst": [ [ - "2lss_p", - "2lss", - "2l_p", - "bmask_atleast1m2l", - "bmask_atmost2m" - ], - [ - "2lss_m", - "2lss", - "2l_m", - "bmask_atleast1m2l", - "bmask_atmost2m" - ], - [ - "2lss_4t_p", - "2lss", - "2l_p", - "bmask_atleast1m2l", - "bmask_atleast3m" - ], - [ - "2lss_4t_m", + "2lss_CR", + "chargedl0", "2lss", - "2l_m", - "bmask_atleast1m2l", - "bmask_atleast3m" + "bmask_exactly1m", + "0tau" ] ], "lep_flav_lst": [ @@ -477,97 +453,203 @@ "isAR_2lSS_OS" ], "jet_lst": [ - "=4", - "=5", - "=6", - ">7" + "=1", + "=2", + "=3" ] }, - "3l": { + "2l_CRflip": { "lep_chan_lst": [ [ - "3l_onZ_1b", - "3l", - "3l_onZ", - "bmask_exactly1m" - ], + "2lss_CRflip", + "2l_nozeeveto", + "2lee", + "2l_onZ_as", + "0tau" + ] + ], + "lep_flav_lst": [ + "ee" + ], + "appl_lst": [ + "isSR_2lSS", + "isAR_2lSS" + ], + "appl_lst_data": [ + "isAR_2lSS_OS" + ], + "jet_lst": [ + "<3" + ] + }, + "2los_CRZ": { + "lep_chan_lst": [ [ - "3l_onZ_2b", + "2los_CRZ", + "2l_nozeeveto", + "2los", + "2l_onZ", + "bmask_exactly0m", + "0tau" + ] + ], + "lep_flav_lst": [ + "ee", + "mm" + ], + "appl_lst": [ + "isSR_2lOS", + "isAR_2lOS" + ], + "jet_lst": [ + ">0" + ] + }, + "2los_CRtt": { + "lep_chan_lst": [ + [ + "2los_CRtt", + "2l_nozeeveto", + "2los", + "2lem", + "bmask_exactly2m", + "0tau" + ] + ], + "lep_flav_lst": [ + "em" + ], + "appl_lst": [ + "isSR_2lOS", + "isAR_2lOS" + ], + "jet_lst": [ + "=2" + ] + }, + "3l_CR": { + "lep_chan_lst": [ + [ + "3l_CR", "3l", - "3l_onZ", - "bmask_atleast2m" - ], + "bmask_exactly0m", + "0tau" + ] + ], + "lep_flav_lst": [ + "eee", + "eem", + "emm", + "mmm" + ], + "appl_lst": [ + "isSR_3l", + "isAR_3l" + ], + "jet_lst": [ + "=0", + ">1" + ] + } + }, + "OFFZ_TAU_SPLIT_CH_LST_SR": { + "3l": { + "lep_chan_lst": [ [ "3l_m_offZ_low_1b", "3l_m", "3l_offZ_low", - "bmask_exactly1m" + "bmask_exactly1m", + "~fwdjet_mask", + "0tau" ], [ "3l_m_offZ_high_1b", "3l_m", "3l_offZ_high", - "bmask_exactly1m" + "bmask_exactly1m", + "~fwdjet_mask", + "0tau" ], [ "3l_m_offZ_none_1b", "3l_m", "3l_offZ_none", - "bmask_exactly1m" + "bmask_exactly1m", + "~fwdjet_mask", + "0tau" ], [ "3l_m_offZ_low_2b", "3l_m", "3l_offZ_low", - "bmask_atleast2m" + "bmask_atleast2m", + "~fwdjet_mask", + "0tau" ], [ "3l_m_offZ_high_2b", "3l_m", "3l_offZ_high", - "bmask_atleast2m" + "bmask_atleast2m", + "~fwdjet_mask", + "0tau" ], [ "3l_m_offZ_none_2b", "3l_m", "3l_offZ_none", - "bmask_atleast2m" + "bmask_atleast2m", + "~fwdjet_mask", + "0tau" ], [ "3l_p_offZ_low_1b", "3l_p", "3l_offZ_low", - "bmask_exactly1m" + "bmask_exactly1m", + "~fwdjet_mask", + "0tau" ], [ "3l_p_offZ_high_1b", "3l_p", "3l_offZ_high", - "bmask_exactly1m" + "bmask_exactly1m", + "~fwdjet_mask", + "0tau" ], [ "3l_p_offZ_none_1b", "3l_p", "3l_offZ_none", - "bmask_exactly1m" + "bmask_exactly1m", + "~fwdjet_mask", + "0tau" ], [ "3l_p_offZ_low_2b", "3l_p", "3l_offZ_low", - "bmask_atleast2m" + "bmask_atleast2m", + "~fwdjet_mask", + "0tau" ], [ "3l_p_offZ_high_2b", "3l_p", "3l_offZ_high", - "bmask_atleast2m" + "bmask_atleast2m", + "~fwdjet_mask", + "0tau" ], [ "3l_p_offZ_none_2b", "3l_p", "3l_offZ_none", - "bmask_atleast2m" + "bmask_atleast2m", + "~fwdjet_mask", + "0tau" ] ], "lep_flav_lst": [ @@ -586,26 +668,6 @@ "=4", ">5" ] - }, - "4l": { - "lep_chan_lst": [ - [ - "4l", - "4l", - "bmask_atleast1m2l" - ] - ], - "lep_flav_lst": [ - "llll" - ], - "appl_lst": [ - "isSR_4l" - ], - "jet_lst": [ - "=2", - "=3", - ">4" - ] } }, "CH_LST_CR": { @@ -725,8 +787,8 @@ ">1" ] } - }, - "FWD_CH_LST_SR": { + }, + "ALL_CH_LST_SR": { "2l": { "lep_chan_lst": [ [ @@ -735,7 +797,8 @@ "2l_p", "bmask_atleast1m2l", "bmask_atmost2m", - "~fwdjet_mask" + "~fwdjet_mask", + "0tau" ], [ "2lss_m", @@ -743,35 +806,42 @@ "2l_m", "bmask_atleast1m2l", "bmask_atmost2m", - "~fwdjet_mask" + "~fwdjet_mask", + "0tau" ], [ "2lss_4t_p", "2lss", "2l_p", "bmask_atleast1m2l", - "bmask_atleast3m" + "bmask_atleast3m", + "0tau" ], [ "2lss_4t_m", "2lss", "2l_m", "bmask_atleast1m2l", - "bmask_atleast3m" + "bmask_atleast3m", + "0tau" ], [ "2lss_fwd_p", - "2lss_fwd", - "2l_fwd_p", + "2lss", + "2l_p", "bmask_atleast1m2l", - "bmask_atmost2m" + "bmask_atmost2m", + "fwdjet_mask", + "0tau" ], [ "2lss_fwd_m", - "2lss_fwd", - "2l_fwd_m", + "2lss", + "2l_m", "bmask_atleast1m2l", - "bmask_atmost2m" + "bmask_atmost2m", + "fwdjet_mask", + "0tau" ] ], "lep_flav_lst": [ @@ -793,62 +863,315 @@ ">7" ] }, + "2lss_1tau": { + "lep_chan_lst": [ + [ + "2lss_m_1tau_onZ", + "2lss", + "2l_m", + "bmask_atleast1m2l", + "1tau", + "onZ_tau" + ], + [ + "2lss_p_1tau_offZ", + "2lss", + "2l_p", + "bmask_atleast1m2l", + "1tau", + "offZ_tau" + ], + [ + "2lss_m_1tau_offZ", + "2lss", + "2l_m", + "bmask_atleast1m2l", + "1tau", + "offZ_tau" + ], + [ + "2lss_p_1tau_onZ", + "2lss", + "2l_p", + "bmask_atleast1m2l", + "1tau", + "onZ_tau" + ] + ], + "lep_flav_lst": [ + "ee", + "em", + "mm" + ], + "appl_lst": [ + "isSR_2lSS", + "isAR_2lSS" + ], + "appl_lst_data": [ + "isAR_2lSS_OS" + ], + "jet_lst": [ + "=3", + "=4", + "=5", + ">6" + ] + }, + "2los_1tau": { + "lep_chan_lst": [ + [ + "2los_onZ_1tau", + "2los", + "bmask_atleast2m", + "1tau", + "2l_onZ" + ] + ], + "lep_flav_lst": [ + "ee", + "em", + "mm" + ], + "appl_lst": [ + "isSR_2lOS", + "isAR_2lOS" + ], + "jet_lst": [ + ">5" + ] + }, "3l": { "lep_chan_lst": [ [ "3l_onZ_1b", "3l", "3l_onZ", - "bmask_exactly1m" + "bmask_exactly1m", + "~fwdjet_mask", + "0tau" ], [ "3l_onZ_2b", "3l", "3l_onZ", - "bmask_atleast2m" + "bmask_atleast2m", + "~fwdjet_mask", + "0tau" ], [ - "3l_m_offZ_1b", + "3l_1tau_1b", + "bmask_exactly1m", + "1tau" + ], + [ + "3l_1tau_2b", + "bmask_atleast2m", + "1tau" + ], + [ + "3l_m_offZ_low_1b", "3l_m", - "3l_offZ", - "bmask_exactly1m" + "3l_offZ_low", + "bmask_exactly1m", + "~fwdjet_mask", + "0tau" ], [ - "3l_m_offZ_2b", + "3l_m_offZ_high_1b", "3l_m", - "3l_offZ", - "bmask_atleast2m" + "3l_offZ_high", + "bmask_exactly1m", + "~fwdjet_mask", + "0tau" ], [ - "3l_p_offZ_1b", + "3l_m_offZ_none_1b", + "3l_m", + "3l_offZ_none", + "bmask_exactly1m", + "~fwdjet_mask", + "0tau" + ], + [ + "3l_m_offZ_low_2b", + "3l_m", + "3l_offZ_low", + "bmask_atleast2m", + "~fwdjet_mask", + "0tau" + ], + [ + "3l_m_offZ_high_2b", + "3l_m", + "3l_offZ_high", + "bmask_atleast2m", + "~fwdjet_mask", + "0tau" + ], + [ + "3l_m_offZ_none_2b", + "3l_m", + "3l_offZ_none", + "bmask_atleast2m", + "~fwdjet_mask", + "0tau" + ], + [ + "3l_p_offZ_low_1b", "3l_p", - "3l_offZ", - "bmask_exactly1m" + "3l_offZ_low", + "bmask_exactly1m", + "~fwdjet_mask", + "0tau" ], [ - "3l_p_offZ_2b", + "3l_p_offZ_high_1b", "3l_p", - "3l_offZ", - "bmask_atleast2m" + "3l_offZ_high", + "bmask_exactly1m", + "~fwdjet_mask", + "0tau" + ], + [ + "3l_p_offZ_none_1b", + "3l_p", + "3l_offZ_none", + "bmask_exactly1m", + "~fwdjet_mask", + "0tau" + ], + [ + "3l_p_offZ_low_2b", + "3l_p", + "3l_offZ_low", + "bmask_atleast2m", + "~fwdjet_mask", + "0tau" + ], + [ + "3l_p_offZ_high_2b", + "3l_p", + "3l_offZ_high", + "bmask_atleast2m", + "~fwdjet_mask", + "0tau" + ], + [ + "3l_p_offZ_none_2b", + "3l_p", + "3l_offZ_none", + "bmask_atleast2m", + "~fwdjet_mask", + "0tau" ] ], "lep_flav_lst": [ "eee", "eem", "emm", - "mmm" + "mmm" ], "appl_lst": [ "isSR_3l", "isAR_3l" ], "jet_lst": [ + "=1", "=2", "=3", "=4", ">5" ] }, + "3l_fwd": { + "lep_chan_lst": [ + [ + "3l_onZ_1b_fwd", + "3l", + "3l_onZ", + "bmask_exactly1m", + "fwdjet_mask", + "0tau" + ], + [ + "3l_onZ_2b_fwd", + "3l", + "3l_onZ", + "bmask_atleast2m", + "fwdjet_mask", + "0tau" + ] + ], + "lep_flav_lst": [ + "eee", + "eem", + "emm", + "mmm" + ], + "appl_lst": [ + "isSR_3l", + "isAR_3l" + ], + "jet_lst": [ + "=1", + "=2", + "=3", + ">4" + ] + }, + "3l_offZ_fwd": { + "lep_chan_lst": [ + [ + "3l_m_offZ_1b_fwd", + "3l_m", + "3l_offZ", + "bmask_exactly1m", + "fwdjet_mask", + "0tau" + ], + [ + "3l_p_offZ_1b_fwd", + "3l_p", + "3l_offZ", + "bmask_exactly1m", + "fwdjet_mask", + "0tau" + ], + [ + "3l_m_offZ_2b_fwd", + "3l_m", + "3l_offZ", + "bmask_atleast2m", + "fwdjet_mask", + "0tau" + ], + + [ + "3l_p_offZ_2b_fwd", + "3l_p", + "3l_offZ", + "bmask_atleast2m", + "fwdjet_mask", + "0tau" + ] + ], + "lep_flav_lst": [ + "eee", + "eem", + "emm", + "mmm" + ], + "appl_lst": [ + "isSR_3l", + "isAR_3l" + ], + "jet_lst": [ + "=1", + "=2", + "=3", + ">4" + ] + }, "4l": { "lep_chan_lst": [ [ @@ -870,4 +1193,4 @@ ] } } -} \ No newline at end of file +} diff --git a/topeft/modules/axes.py b/topeft/modules/axes.py index c613d04fb..458af0084 100644 --- a/topeft/modules/axes.py +++ b/topeft/modules/axes.py @@ -111,10 +111,15 @@ "variable": [0, 150, 250, 500], "label": r"pt of lepton hadronic tau pair (GeV) ", }, - "tau0pt": { + "tau0Tpt": { "regular": (20, 0, 200), #"variable": [0, 150, 250, 500], - "label": r"pt of leading hadronic tau (GeV) ", + "label": r"pt of leading tight hadronic tau (GeV) ", + }, + "tau0Fpt": { + "regular": (20, 0, 200), + #"variable": [0, 150, 250, 500], + "label": r"pt of leading FO hadronic tau (GeV) ", }, "lt": { "regular": (12, 0, 600), diff --git a/topeft/modules/corrections.py b/topeft/modules/corrections.py index f1a190875..4b5c48a69 100644 --- a/topeft/modules/corrections.py +++ b/topeft/modules/corrections.py @@ -645,7 +645,7 @@ def ApplyTES(year, taus, isData, vsJetWP="Loose"): # Genuine taus (genmatch==5) receive the TES weights tes_kin = (flat_pt > 20) & (flat_pt < 205) - tes_dm = (flat_dm == 0) | (flat_dm == 1) | (flat_dm == 2) | (flat_dm == 10) | (flat_dm == 11) + tes_dm = (flat_dm == 0) | (flat_dm == 1) | (flat_dm == 10) | (flat_dm == 11) tes_where = tes_kin & tes_dm & (flat_gen == 5) full_tes = np.ones_like(flat_all_pt_np, dtype=np.float32) @@ -667,7 +667,7 @@ def ApplyTES(year, taus, isData, vsJetWP="Loose"): # Electron/muon fakes (genmatch 1-4) receive the FES weights fes_kin = (flat_pt > 20) & (flat_pt < 205) - fes_dm = (flat_dm == 0) | (flat_dm == 1) + fes_dm = (flat_dm == 0) | (flat_dm == 1) | (flat_dm == 10) | (flat_dm == 11) fes_where = fes_kin & fes_dm & (flat_gen >= 1) & (flat_gen <= 4) full_fes = np.ones_like(flat_all_pt_np, dtype=np.float32) @@ -897,7 +897,7 @@ def AttachTauSF(events, taus, year, vsJetWP="Loose"): wp = taus.idDeepTau2017v2p1VSjet ## legacy - whereFlag = ((pt>20) & (pt<205) & (gen==5) & (taus[f"is{vsJetWP}"]>0)) + whereFlag = ((pt>20) & (pt<205) & (gen==5) & (taus[f"is{vsJetWP}"]>0) ) real_sf_loose = np.where(whereFlag, SFevaluator[f'TauSF_{year}_{vsJetWP}'](dm,pt), 1) real_sf_loose_up = np.where(whereFlag, SFevaluator[f'TauSF_{year}_{vsJetWP}_up'](dm,pt), 1) real_sf_loose_down = np.where(whereFlag, SFevaluator[f'TauSF_{year}_{vsJetWP}_down'](dm,pt), 1) @@ -940,8 +940,8 @@ def AttachTauSF(events, taus, year, vsJetWP="Loose"): deep_tau_cuts = [ ( "DeepTau2018v2p5VSjet", - vsjet_flat_mask, - (flat_pt, flat_dm, flat_gen, vsJetWP, "Tight"), + (vsjet_flat_mask & vse_flat_mask), + (flat_pt, flat_dm, flat_gen, vsJetWP, "VVLoose"), (flat_gen == 5), ), ( @@ -960,9 +960,10 @@ def AttachTauSF(events, taus, year, vsJetWP="Loose"): tau_mask_flat = ak.fill_none(id_mask_flat & pt_mask_flat & gen_mask_flat, False) if "VSjet" in discr: - arg_sf = arg_list + ("nom", "pt") + arg_sf = arg_list + ("nom", "dm") else: arg_sf = arg_list + ("nom",) + DT_sf_list.append( ak.where( ~tau_mask_flat, @@ -971,8 +972,17 @@ def AttachTauSF(events, taus, year, vsJetWP="Loose"): ) ) + # print("\n\n\n\n\n") + # print("vsjet_flat_mask:", ak.to_list(vsjet_flat_mask)) + # print("vse_flat_mask:", ak.to_list(vse_flat_mask)) + # print("flat_pt:", ak.to_list(flat_pt)) + # print("flat_dm:", ak.to_list(flat_dm)) + # print("flat_gen:", ak.to_list(flat_gen)) + # print("ceval[discr].evaluate(*arg_sf):", ak.to_list(ceval[discr].evaluate(*arg_sf))) + # print("\n\n\n\n\n") + if "VSjet" in discr: - arg_up = arg_list + ("up", "pt") + arg_up = arg_list + ("up", "dm") else: arg_up = arg_list + ("up",) DT_up_list.append( @@ -983,7 +993,7 @@ def AttachTauSF(events, taus, year, vsJetWP="Loose"): ) ) if "VSjet" in discr: - arg_down = arg_list + ("down", "pt") + arg_down = arg_list + ("down", "dm") else: arg_down = arg_list + ("down",) DT_do_list.append( @@ -1012,10 +1022,13 @@ def AttachTauSF(events, taus, year, vsJetWP="Loose"): fake_elec_sf_up = ak.unflatten(DT_up_discr, ak.num(pt)) fake_elec_sf_down = ak.unflatten(DT_do_discr, ak.num(pt)) - whereFlag = ((pt>20) & (pt<205) & (gen!=5) & (gen!=4) & (gen!=3) & (gen!=2) & (gen!=1) & (taus[f"is{vsJetWP}"]>0)) - new_fake_sf = np.where(whereFlag, SFevaluator['TauFakeSF_Run3'](pt), 1) - new_fake_sf_up = np.where(whereFlag, SFevaluator['TauFakeSF_Run3_up'](pt), 1) - new_fake_sf_down = np.where(whereFlag, SFevaluator['TauFakeSF_Run3_down'](pt), 1) + # whereFlag = ((pt>20) & (pt<205) & (gen!=5) & (gen!=4) & (gen!=3) & (gen!=2) & (gen!=1) & (taus[f"is{vsJetWP}"]>0)) + # new_fake_sf = np.where(whereFlag, SFevaluator['TauFakeSF_Run3'](pt), 1) + # new_fake_sf_up = np.where(whereFlag, SFevaluator['TauFakeSF_Run3_up'](pt), 1) + # new_fake_sf_down = np.where(whereFlag, SFevaluator['TauFakeSF_Run3_down'](pt), 1) + new_fake_sf = ak.fill_none(np.ones_like(pt, dtype=np.float32), 1.0) + new_fake_sf_up = ak.fill_none(np.ones_like(pt, dtype=np.float32), 1.0) + new_fake_sf_down = ak.fill_none(np.ones_like(pt, dtype=np.float32), 1.0) # Run3 tau muon SF may be needed in the future fake_muon_sf = ak.fill_none(np.ones_like(pt, dtype=np.float32), 1.0) @@ -1493,7 +1506,6 @@ def AttachElectronSF(electrons, year, looseWP=None, useRun3MVA=True): if is_run3: if looseWP != "none": - #print("\n\n\n\n\nI'm applying EGM loose SFs\n\n\n\n\n") loose_sf_flat = None loose_up_flat = None loose_do_flat = None @@ -1520,7 +1532,6 @@ def AttachElectronSF(electrons, year, looseWP=None, useRun3MVA=True): loose_up = ak.unflatten(loose_up_flat, ak.num(pt)) loose_do = ak.unflatten(loose_do_flat, ak.num(pt)) else: - #print("\n\n\n\n\nI'm NOT applying EGM loose SFs\n\n\n\n\n") loose_sf = ak.ones_like(reco_sf) loose_up = ak.ones_like(reco_sf) loose_do = ak.ones_like(reco_sf) @@ -1600,14 +1611,6 @@ def AttachElectronSF(electrons, year, looseWP=None, useRun3MVA=True): iso_up = iso_sf + iso_err iso_do = iso_sf - iso_err - #print("\n\n\n\n\n\n\n") - #print('new_sf', new_sf) - #print('new_sf_2l', new_sf_2l) - #print('new_sf_3l', new_sf_3l) - #print('sf_nom_2l_elec', ak.to_list(reco_sf * new_sf_2l * loose_sf * iso_sf)) - #print('sf_nom_3l_elec', ak.to_list(reco_sf * new_sf_2l * loose_sf)) - #print("\n\n\n\n\n\n\n") - electrons['sf_nom_2l_elec'] = reco_sf * new_sf_2l * loose_sf * iso_sf electrons['sf_hi_2l_elec'] = (reco_up) * new_up_2l * loose_up * iso_up electrons['sf_lo_2l_elec'] = (reco_do) * new_do_2l * loose_do * iso_do diff --git a/topeft/modules/object_selection.py b/topeft/modules/object_selection.py index 1105add2c..669e37737 100644 --- a/topeft/modules/object_selection.py +++ b/topeft/modules/object_selection.py @@ -92,7 +92,7 @@ def isPresTau(self, pt, eta, dxy, dz, idDeepTauVSjet, idDeepTauVSe, idDeepTauVSm base_mask = ( (pt > minpt) - & (abs(eta) < get_te_param("eta_t_cut")) + & (abs(eta) < get_te_param("eta_t_cut_run3")) & (abs(dxy) < get_te_param("dxy_tau_cut")) & (abs(dz) < get_te_param("dz_tau_cut")) & (idDeepTauVSe >= 2) diff --git a/topeft/params/params.json b/topeft/params/params.json index e0dff6c58..d6664e4e4 100644 --- a/topeft/params/params.json +++ b/topeft/params/params.json @@ -2,6 +2,7 @@ "eta_e_cut" : 2.5, "eta_m_cut" : 2.4, "eta_t_cut" : 2.3, + "eta_t_cut_run3" : 2.5, "eta_j_cut" : 2.4, "fo_pt_cut" : 10.0,