Skip to content

Commit

Permalink
implemented 50% of Marcel's & Philip's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
haddadanas committed Jun 3, 2024
1 parent 26595cf commit 5615ded
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 34 deletions.
2 changes: 0 additions & 2 deletions hbt/calibration/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def default(self: Calibrator, events: ak.Array, **kwargs) -> ak.Array:

if self.config_inst.has_tag("run2"):
events = self[met_phi](events, **kwargs)
else:
print("met_phi_setup will be skipped for now, since correction files for run 3 are not yet available!")

if self.dataset_inst.is_mc:
events = self[tec](events, **kwargs)
Expand Down
6 changes: 3 additions & 3 deletions hbt/config/analysis_hbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@
)


# #
# # Run 3 configs
# #
#
# Run 3 configs
#

# 2022
from hbt.config.configs_run3 import add_config as add_config_run3
Expand Down
24 changes: 6 additions & 18 deletions hbt/config/configs_run3.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def add_config(

# postfix for 2022 campaigns after ECAL Endcap water leak
year_postfix = "EE" if campaign.x.postfix == "post" else ""
postfixEE = f"{campaign.x.postfix}EE"
postfix_ee = f"{campaign.x.postfix}EE"

# get all root processes
procs = get_root_processes_from_campaign(campaign)
Expand Down Expand Up @@ -82,14 +82,6 @@ def add_config(
# add the process
cfg.add_process(procs.get(process_name))

# # add the process (and set xsec to 0.1 if not available)
# process_inst = procs.get(process_name)

# cfg.add_process(process_inst)
# for proc_inst in cfg.get_process(process_inst).get_leaf_processes():
# if campaign.ecm not in proc_inst.xsecs.keys():
# cfg.get_process(proc_inst.name).set_xsec(campaign.ecm, Number(0.1))

# configure colors, labels, etc
from hbt.config.styles import stylize_processes
stylize_processes(cfg)
Expand Down Expand Up @@ -401,11 +393,7 @@ def add_config(
# name of the deep tau tagger
# (used in the tec calibrator)
# https://twiki.cern.ch/twiki/bin/view/CMS/TauIDRecommendationForRun3
cfg.x.tau_tagger = "DeepTau2018v2p5" # "DeepTauv2p5"

# name of the MET phi correction set
# (used in the met_phi calibrator)
# cfg.x.met_phi_correction_set = "{variable}_metphicorr_pfmet_{data_source}"
cfg.x.tau_tagger = "DeepTau2018v2p5"

# names of electron correction sets and working points
# (used in the electron_sf producer)
Expand All @@ -417,7 +405,7 @@ def add_config(

# names of muon correction sets and working points
# (used in the muon producer)
cfg.x.muon_sf_names = ("NUM_TightPFIso_DEN_TightID", f"{year}_{postfixEE}")
cfg.x.muon_sf_names = ("NUM_TightPFIso_DEN_TightID", f"{year}_{postfix_ee}")

# load jec sources
with open(os.path.join(thisdir, "jec_sources.yaml"), "r") as f:
Expand Down Expand Up @@ -624,10 +612,10 @@ def add_config(
"electron_sf": (f"{json_mirror}/POG/EGM/{year}_Summer{year2}{year_postfix}/electron.json.gz", "v1"),

# tau energy correction and scale factors
"tau_sf": (f"{json_mirror_alt}/POG/TAU/{year}_{postfixEE}/tau_DeepTau2018v2p5_2022_{postfixEE}.json.gz", "v1"), # noqa
"tau_sf": (f"{json_mirror_alt}/POG/TAU/{year}_{postfix_ee}/tau_DeepTau2018v2p5_2022_{postfix_ee}.json.gz", "v1"), # noqa

# tau trigger
"tau_trigger_sf": (f"{json_mirror_alt}/POG/TAU/output/tau_trigger_DeepTau2018v2p5_{year}{postfixEE}.json", "v1"), # noqa
"tau_trigger_sf": (f"{json_mirror_alt}/POG/TAU/output/tau_trigger_DeepTau2018v2p5_{year}{postfix_ee}.json", "v1"), # noqa
}))

# external files with more complex year dependence # TODO: check this
Expand All @@ -651,7 +639,7 @@ def add_config(
},
},
}))
else: # year 2023
elif year == 2023: # year 2023
cfg.x.external_files.update(DotDict.wrap({
# lumi files
"lumi": {
Expand Down
2 changes: 2 additions & 0 deletions hbt/production/hhbtag.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from columnflow.util import maybe_import, dev_sandbox, InsertableDict
from columnflow.columnar_util import EMPTY_FLOAT, layout_ak_array

from hbt.util import IF_RUN_2

np = maybe_import("numpy")
ak = maybe_import("awkward")
Expand All @@ -25,6 +26,7 @@
# nano columns
"event",
"Jet.pt", "Jet.eta", "Jet.phi", "Jet.mass", "Jet.jetId",
IF_RUN_2("Jet.puId"),
"Jet.btagDeepFlavB",
"MET.pt", "MET.phi",
},
Expand Down
8 changes: 4 additions & 4 deletions hbt/production/tau.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def tau_weights(self: Producer, events: ak.Array, **kwargs) -> ak.Array:

# the correction tool only supports flat arrays, so convert inputs to flat np view first
pt = flat_np_view(events.Tau.pt, axis=1)
abseta = flat_np_view(abs(events.Tau.eta), axis=1) # TODO check if eta and not abseta
abseta = flat_np_view(abs(events.Tau.eta), axis=1)
dm = flat_np_view(events.Tau.decayMode, axis=1)
match = flat_np_view(events.Tau.genPartFlav, axis=1)

Expand Down Expand Up @@ -212,9 +212,9 @@ def tau_weights_setup(self: Producer, reqs: dict, inputs: dict, reader_targets:
self.id_vs_mu_corrector = correction_set[f"{tagger_name}VSmu"]

# check versions
# assert self.id_vs_jet_corrector.version in (0, 1, 2)
# assert self.id_vs_e_corrector.version in (0,)
# assert self.id_vs_mu_corrector.version in (0,)
assert self.id_vs_jet_corrector.version in (0, 1, 2, 3)
assert self.id_vs_e_corrector.version in (0, 1)
assert self.id_vs_mu_corrector.version in (0, 1)


@producer(
Expand Down
21 changes: 14 additions & 7 deletions hbt/selection/lepton.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ def muon_selection(
@selector(
uses={
# nano columns
"Tau.pt", "Tau.eta", "Tau.phi", "Tau.dz", "Tau.idDeepTau2017v2p1VSe",
"Tau.idDeepTau2017v2p1VSmu", "Tau.idDeepTau2017v2p1VSjet",
"Tau.pt", "Tau.eta", "Tau.phi", "Tau.dz",
"TrigObj.pt", "TrigObj.eta", "TrigObj.phi",
"Electron.pt", "Electron.eta", "Electron.phi",
"Muon.pt", "Muon.eta", "Muon.phi",
Expand Down Expand Up @@ -251,6 +250,8 @@ def tau_selection(
is_any_cross_tau = is_cross_tau or is_cross_tau_vbf or is_cross_tau_jet
is_2016 = self.config_inst.campaign.x.year == 2016
is_run3 = self.config_inst.has_tag("run3")
get_tau_tagger = lambda tag: f"id{self.config_inst.x.tau_tagger}VS{tag}"

# tau id v2.1 working points (binary to int transition after nano v10)
if self.config_inst.campaign.x.version < 10:
# https://cms-nanoaod-integration.web.cern.ch/integration/master/mc94X_doc.html
Expand Down Expand Up @@ -306,9 +307,9 @@ def tau_selection(
(abs(events.Tau.eta) < max_eta) &
(events.Tau.pt > min_pt) &
(abs(events.Tau.dz) < 0.2) &
(events.Tau.idDeepTau2017v2p1VSe >= (tau_vs_e.vvloose if is_any_cross_tau else tau_vs_e.vloose)) &
(events.Tau.idDeepTau2017v2p1VSmu >= (tau_vs_mu.vloose if is_any_cross_tau else tau_vs_mu.tight)) &
(events.Tau.idDeepTau2017v2p1VSjet >= tau_vs_jet.loose)
(events.Tau[get_tau_tagger("e")] >= (tau_vs_e.vvloose if is_any_cross_tau else tau_vs_e.vloose)) &
(events.Tau[get_tau_tagger("mu")] >= (tau_vs_mu.vloose if is_any_cross_tau else tau_vs_mu.tight)) &
(events.Tau[get_tau_tagger("jet")] >= tau_vs_jet.loose)
)

# remove taus with too close spatial separation to previously selected leptons
Expand All @@ -332,15 +333,15 @@ def tau_selection(
# indices for sorting first by isolation, then by pt
# for this, combine iso and pt values, e.g. iso 255 and pt 32.3 -> 2550032.3
f = 10 ** (np.ceil(np.log10(ak.max(events.Tau.pt))) + 1)
sort_key = events.Tau.idDeepTau2017v2p1VSjet * f + events.Tau.pt
sort_key = events.Tau[get_tau_tagger("jet")] * f + events.Tau.pt
sorted_indices = ak.argsort(sort_key, axis=-1, ascending=False)

# convert to sorted indices
base_indices = sorted_indices[base_mask[sorted_indices]]
base_indices = ak.values_astype(base_indices, np.int32)

# additional mask to select final, Medium isolated taus
iso_mask = events.Tau[base_indices].idDeepTau2017v2p1VSjet >= tau_vs_jet.medium
iso_mask = events.Tau[base_indices][get_tau_tagger("jet")] >= tau_vs_jet.medium

return base_indices, iso_mask

Expand All @@ -354,6 +355,12 @@ def tau_selection_init(self: Selector) -> None:
if shift_inst.has_tag("tec")
}

# Add columns for the right tau tagger
self.uses |= {
f"Tau.id{self.config_inst.x.tau_tagger}VS{tag}"
for tag in ("e", "mu", "jet")
}


@selector(
uses={
Expand Down

0 comments on commit 5615ded

Please sign in to comment.