Skip to content

Commit

Permalink
add SF configs, complete and harmonize custom_trigger_sf and tau scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
nprouvost committed Nov 27, 2024
1 parent 11c3444 commit 263ba62
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 12 deletions.
71 changes: 65 additions & 6 deletions hbt/config/configs_hbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ def if_era(
*if_era(run=3, year=2022, tag="preEE", values=[
f"data_{stream}_{period}" for stream in ["mu", "e", "tau", "met"] for period in "cd"
]),
# TODO: Add SingleMuon dataset for preEE -> which dataset name for it?
*if_era(run=3, year=2022, tag="postEE", values=[
f"data_{stream}_{period}" for stream in ["mu", "e", "tau", "met"] for period in "efg"
]),
Expand Down Expand Up @@ -661,6 +662,10 @@ def if_era(
"trigger_corr": "VVLoose",
})

# tau trigger correctors
cfg.x.tau_trigger_corrector = "tau_trigger"
cfg.x.cclub_tau_corrector = "tauTriggerSF"

################################################################################################
# electron settings
################################################################################################
Expand All @@ -682,11 +687,31 @@ def if_era(
"2022Re-recoBCD" if campaign.has_tag("preEE") else "2022Re-recoE+PromptFG",
"wp80iso",
)
cfg.x.electron_trigger_sf_names = ElectronSFConfig(
correction="Electron-HLT-SF",
# cfg.x.electron_trigger_sf_names = ElectronSFConfig(
# correction="Electron-HLT-SF",
# campaign="2022Re-recoBCD" if campaign.has_tag("preEE") else "2022Re-recoE+PromptFG",
# hlt_path="HLT_SF_Ele30_TightID",
# )
cfg.x.single_electron_trigger_data_effs_names = ElectronSFConfig(
correction="Electron-HLT-DataEff",
campaign="2022Re-recoBCD" if campaign.has_tag("preEE") else "2022Re-recoE+PromptFG",
hlt_path="HLT_SF_Ele30_TightID",
)
cfg.x.single_electron_trigger_mc_effs_names = ElectronSFConfig(
correction="Electron-HLT-McEff",
campaign="2022Re-recoBCD" if campaign.has_tag("preEE") else "2022Re-recoE+PromptFG",
hlt_path="HLT_SF_Ele30_TightID",
)
cfg.x.cross_electron_trigger_data_effs_names = ElectronSFConfig(
correction="Electron-HLT-DataEff",
campaign="2022Re-recoBCD" if campaign.has_tag("preEE") else "2022Re-recoE+PromptFG",
hlt_path="HLT_SF_Ele24_TightID",
)
cfg.x.cross_electron_trigger_mc_effs_names = ElectronSFConfig(
correction="Electron-HLT-McEff",
campaign="2022Re-recoBCD" if campaign.has_tag("preEE") else "2022Re-recoE+PromptFG",
hlt_path="HLT_SF_Ele24_TightID",
)
else:
assert False

Expand All @@ -709,10 +734,27 @@ def if_era(
"NUM_TightPFIso_DEN_TightID",
"2022_preEE" if campaign.has_tag("preEE") else "2022_postEE",
)
cfg.x.muon_trigger_sf_names = MuonSFConfig(
correction="NUM_IsoMu24_DEN_CutBasedIdTight_and_PFIsoTight",
# cfg.x.muon_trigger_sf_names = MuonSFConfig(
# correction="NUM_IsoMu24_DEN_CutBasedIdTight_and_PFIsoTight",
# campaign="2022_preEE" if campaign.has_tag("preEE") else "2022_postEE",
# )
cfg.x.single_muon_trigger_data_effs_names = MuonSFConfig(
correction="NUM_IsoMu24_DEN_CutBasedIdTight_and_PFIsoTight_DATAeff",
campaign="2022_preEE" if campaign.has_tag("preEE") else "2022_postEE",
)
cfg.x.single_muon_trigger_mc_effs_names = MuonSFConfig(
correction="NUM_IsoMu24_DEN_CutBasedIdTight_and_PFIsoTight_MCeff",
campaign="2022_preEE" if campaign.has_tag("preEE") else "2022_postEE",
)
cfg.x.cross_muon_trigger_data_effs_names = MuonSFConfig(
correction="NUM_IsoMu20_DEN_CutBasedIdTight_and_PFIsoTight_DATAeff",
campaign="2022_preEE" if campaign.has_tag("preEE") else "2022_postEE",
)
cfg.x.cross_muon_trigger_mc_effs_names = MuonSFConfig(
correction="NUM_IsoMu20_DEN_CutBasedIdTight_and_PFIsoTight_MCeff",
campaign="2022_preEE" if campaign.has_tag("preEE") else "2022_postEE",
)

else:
assert False

Expand Down Expand Up @@ -1019,6 +1061,17 @@ def add_external(name, value):
elif run == 3:
json_pog_era = f"{year}_Summer{year2}{campaign.x.postfix}"
json_mirror = "/afs/cern.ch/user/m/mrieger/public/mirrors/jsonpog-integration-6ce37404"
trigger_json_mirror = "/nfs/dust/cms/user/prouvost/cclub_gitlab/AnalysisCore/data/TriggerScaleFactors"
cfg.x.campaign_tag = ""
for tag in ("preEE", "postEE", "preBPix", "postBPix"):
if campaign.has_tag(tag, mode=any):
if cfg.x.campaign_tag:
raise ValueError(f"Multiple campaign tags found: {cfg.x.campaign_tag} and {tag}")
cfg.x.campaign_tag = tag
cclub_eras = (
f"{year}"
f"{cfg.x.campaign_tag}"
)
else:
assert False

Expand Down Expand Up @@ -1073,15 +1126,21 @@ def add_external(name, value):
if year == 2022 and campaign.has_tag("preEE"):
# muon scale factors
add_external("muon_sf", (f"{json_mirror}/POG/MUO/{json_pog_era}/muon_Z.json.gz", "v1"))
add_external("muon_trigger_sf", (f"{json_mirror}/POG/MUO/{json_pog_era}/muon_Z.json.gz", "v1"))
# muon trigger scale factors
add_external("muon_trigger_sf", (f"{trigger_json_mirror}/{cclub_eras}/temporary_MuHlt_abseta_pt.json", "v1")) # noqa
add_external("cross_muon_trigger_sf", (f"{trigger_json_mirror}/{cclub_eras}/CrossMuTauHlt.json", "v1"))
# electron scale factors
add_external("electron_sf", (f"{json_mirror}/POG/EGM/{json_pog_era}/electron.json.gz", "v1"))
add_external("electron_trigger_sf", (f"{json_mirror}/POG/EGM/{json_pog_era}/electronHlt.json.gz", "v1"))
# electron trigger scale factors
add_external("electron_trigger_sf", (f"{trigger_json_mirror}/{cclub_eras}/electronHlt.json", "v1"))
add_external("cross_electron_trigger_sf", (f"{trigger_json_mirror}/{cclub_eras}/CrossEleTauHlt.json", "v1"))
# tau energy correction and scale factors
# TODO: remove tag pog mirror once integrated centrally
json_mirror_tau_pog = "/afs/cern.ch/work/m/mrieger/public/mirrors/jsonpog-integration-taupog"
tau_pog_era = f"{year}_{'pre' if campaign.has_tag('preEE') else 'post'}EE"
add_external("tau_sf", (f"{json_mirror_tau_pog}/POG/TAU/{tau_pog_era}/tau_DeepTau2018v2p5_{tau_pog_era}.json.gz", "v1")) # noqa
# tau trigger scale factors
add_external("tau_trigger_sf", (f"{trigger_json_mirror}/{cclub_eras}/tau_trigger_DeepTau2018v2p5_2022preEE.json", "v1")) # noqa
else:
assert False

Expand Down
10 changes: 5 additions & 5 deletions hbt/production/custom_trigger_sf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from columnflow.production import Producer, producer
from columnflow.util import maybe_import
from columnflow.columnar_util import set_ak_column, EMPTY_FLOAT, Route
from colmnflow.production.cms.muon import muon_weights
from columnflow.production.cms.muon import muon_weights
from columnflow.production.cms.electron import electron_weights


Expand Down Expand Up @@ -65,7 +65,7 @@
"cross_etau_trigger_data_effs",
cls_dict={
"get_tau_file": (lambda self, external_files: external_files.tau_trigger_sf),
"get_tau_config": (lambda self: self.config_inst.x.cross_etau_trigger_data_effs_names),
"get_tau_corrector": (lambda self: self.config_inst.x.cclub_tau_corrector),
"weight_name": "cross_etau_trigger_data_effs",
},
)
Expand All @@ -74,7 +74,7 @@
"cross_etau_trigger_mc_effs",
cls_dict={
"get_tau_file": (lambda self, external_files: external_files.tau_trigger_sf),
"get_tau_config": (lambda self: self.config_inst.x.cross_etau_trigger_mc_effs_names),
"get_tau_corrector": (lambda self: self.config_inst.x.cclub_tau_corrector),
"weight_name": "cross_etau_trigger_mc_effs",
},
)
Expand Down Expand Up @@ -121,7 +121,7 @@
"cross_mutau_trigger_data_effs",
cls_dict={
"get_tau_file": (lambda self, external_files: external_files.tau_trigger_sf),
"get_tau_config": (lambda self: self.config_inst.x.cross_mutau_trigger_data_effs_names),
"get_tau_corrector": (lambda self: self.config_inst.x.cclub_tau_corrector),
"weight_name": "cross_mutau_trigger_data_effs",
},
)
Expand All @@ -130,7 +130,7 @@
"cross_mutau_trigger_mc_effs",
cls_dict={
"get_tau_file": (lambda self, external_files: external_files.tau_trigger_sf),
"get_tau_config": (lambda self: self.config_inst.x.cross_mutau_trigger_mc_effs_names),
"get_tau_corrector": (lambda self: self.config_inst.x.cclub_tau_corrector),
"weight_name": "cross_mutau_trigger_mc_effs",
},
)
Expand Down
5 changes: 4 additions & 1 deletion hbt/production/tau.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def tau_weights_setup(self: Producer, reqs: dict, inputs: dict, reader_targets:
mc_only=True,
# function to determine the correction file
get_tau_file=(lambda self, external_files: external_files.tau_sf),
get_tau_corrector=(lambda self: self.config_inst.x.tau_trigger_corrector),
)
def tau_trigger_weights(self: Producer, events: ak.Array, **kwargs) -> ak.Array:
"""
Expand Down Expand Up @@ -346,10 +347,12 @@ def tau_trigger_weights_setup(self: Producer, reqs: dict, inputs: dict, reader_t
correctionlib.highlevel.Correction.__call__ = correctionlib.highlevel.Correction.evaluate

# load the correction set
from IPython import embed; embed(header="tau_trigger_weights_setup")
correction_set = correctionlib.CorrectionSet.from_string(
self.get_tau_file(bundle.files).load(formatter="gzip").decode("utf-8"),
)
self.trigger_corrector = correction_set["tau_trigger"]
corrector_string = self.get_tau_corrector()
self.trigger_corrector = correction_set[corrector_string]

# check versions
assert self.trigger_corrector.version in [0, 1]

0 comments on commit 263ba62

Please sign in to comment.