Skip to content

Commit

Permalink
separate trigger and main analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
BalduinLetzer committed Aug 6, 2024
1 parent 7c92741 commit 605903c
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 186 deletions.
35 changes: 0 additions & 35 deletions hbw/config/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,41 +177,6 @@ def add_jet_categories(config: od.Config) -> None:
label="2b",
)

@call_once_on_config()
def add_trigger_categories(config: od.Config) -> None:
# mc truth categories
cat_trig_mu = config.add_category( # noqa
name="trig_mu",
id=1000,
selection="catid_trigger_mu",
label="Muon\n(MC truth)",
)
cat_trig_ele = config.add_category( # noqa
name="trig_ele",
id=2000,
selection="catid_trigger_ele",
label="Electron\n(MC truth)",
)
# orthogonal categories
cat_trig_mu_orth = config.add_category( # noqa
name="trig_mu_orth",
id=3000,
selection="catid_trigger_orth_mu",
label="Muon\northogonal\nmeasurement",
)
cat_trig_ele_orth = config.add_category( # noqa
name="trig_ele_orth",
id=4000,
selection="catid_trigger_orth_ele",
label="Electron\northogonal\nmeasurement",
)
cat_trig_ele_orth_nomatch = config.add_category( # noqa
name="trig_ele_orth_nomatch",
id=5000,
selection="catid_trigger_orth_e_no_match",
label="Electron\northogonal\nmeasurement\nno match",
)

@call_once_on_config()
def add_categories_selection(config: od.Config) -> None:
"""
Expand Down
49 changes: 2 additions & 47 deletions hbw/config/config_run2.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from hbw.config.processes import configure_hbw_processes
from hbw.config.defaults_and_groups import set_config_defaults_and_groups
from hbw.util import four_vec
from hbw.trigger.trigger_config import add_trigger_config

thisdir = os.path.dirname(os.path.abspath(__file__))

Expand Down Expand Up @@ -616,8 +617,6 @@ def make_jme_filename(jme_aux, sample_type, name, era=None):
"btag_weight*",
# columns for btag reweighting crosschecks
"n_jets", "ht",
# HLT columns for trigger studies
"HLT.*",
} | four_vec( # Jets
{"Jet", "Bjet", "Lightjet", "VBFJet"},
{"btagDeepFlavB", "btagPNetB", "hadronFlavour", "qgl"},
Expand Down Expand Up @@ -706,50 +705,6 @@ def produce_version(cls, inst, params):
from hbw.config.sl_res import configure_sl_res
configure_sl_res(cfg)

# set triggers for trigger studies
if year == 2017:
cfg.x.trigger = {
"e": ["Ele35_WPTight_Gsf"],
"mu": ["IsoMu27"],
}
cfg.x.ref_trigger = {
"e": "IsoMu27",
"mu": "Ele35_WPTight_Gsf",
}
elif year == 2018:
cfg.x.trigger = {
"e": "Ele32_WPTight_Gsf",
"mu": "IsoMu24",
}
cfg.x.ref_trigger = {
"e": "IsoMu24",
"mu": "Ele32_WPTight_Gsf",
}
elif year == 2022:
cfg.x.trigger = {
"e": [
"Ele30_WPTight_Gsf", "Ele28_eta2p1_WPTight_Gsf_HT150", "Ele15_IsoVVVL_PFHT450", "QuadPFJet70_50_40_35_PFBTagParticleNet_2BTagSum0p65",
],
"mu": [
"IsoMu24", "Mu50", "Mu15_IsoVVVL_PFHT450", "QuadPFJet70_50_40_35_PFBTagParticleNet_2BTagSum0p65",
],
}
cfg.x.ref_trigger = {
"e": "IsoMu24",
"mu": "Ele30_WPTight_Gsf",
}
else:
raise NotImplementedError(f"Trigger for year {year} is not defined.")

# short labels for triggers with long names
cfg.x.trigger_short = {
"Ele30_WPTight_Gsf": "Ele30Tight",
"Ele28_eta2p1_WPTight_Gsf_HT150": "Ele28eta2p1TightHT150",
"Ele15_IsoVVVL_PFHT450": "Ele15IsoVVVLHT450",
"QuadPFJet70_50_40_35_PFBTagParticleNet_2BTagSum0p65": "QuadPFJet2Btag",
"IsoMu24": "IsoMu24",
"Mu50": "Mu50",
"Mu15_IsoVVVL_PFHT450": "Mu15IsoVVVLHT450",
}
add_trigger_config(cfg, year=year)

return cfg
30 changes: 0 additions & 30 deletions hbw/config/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,33 +635,3 @@ def add_variables(config: od.Config) -> None:
binning=(40, -3.2, 3.2),
x_title=r"MET $\phi$",
)

# trigger bits to build histograms
config.add_variable(
name="trig_bits_mu",
aux={
"axis_type": "strcat",
},
x_title="Trigger names",
)
config.add_variable(
name="trig_bits_orth_mu",
aux={
"axis_type": "strcat",
},
x_title="Trigger names (orthogonal)",
)
config.add_variable(
name="trig_bits_e",
aux={
"axis_type": "strcat",
},
x_title="Trigger names",
)
config.add_variable(
name="trig_bits_orth_e",
aux={
"axis_type": "strcat",
},
x_title="Trigger names (orthogonal)",
)
69 changes: 0 additions & 69 deletions hbw/selection/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,72 +298,3 @@ def dnn_mask(self: Categorizer, events: ak.Array, **kwargs) -> tuple[ak.Array, a
outp_mask = outp_mask & mask

return events, outp_mask

#
# Trigger categorizers
#

# categorizer muon channel
@categorizer()
def catid_trigger_mu(
self: Categorizer,
events: ak.Array,
results: SelectionResult | None = None,
**kwargs,
) -> tuple[ak.Array, ak.Array]:
if results:
return events, results.steps.SR_mu
else:
raise NotImplementedError(f"Category didn't receive a SelectionResult")

# categorizer electron channel
@categorizer()
def catid_trigger_ele(
self: Categorizer,
events: ak.Array,
results: SelectionResult | None = None,
**kwargs,
) -> tuple[ak.Array, ak.Array]:
if results:
return events, results.steps.SR_ele
else:
raise NotImplementedError(f"Category didn't receive a SelectionResult")

# categorizer for orthogonal measurement (muon channel)
@categorizer()
def catid_trigger_orth_mu(
self: Categorizer,
events: ak.Array,
results: SelectionResult | None = None,
**kwargs,
) -> tuple[ak.Array, ak.Array]:
if results:
return events, ( results.steps.TrigEleMatch & results.steps.SR_mu & results.steps.ref_trigger_mu)
else:
raise NotImplementedError(f"Category didn't receive a SelectionResult")

# categorizer for orthogonal measurement (electron channel)
@categorizer()
def catid_trigger_orth_ele(
self: Categorizer,
events: ak.Array,
results: SelectionResult | None = None,
**kwargs,
) -> tuple[ak.Array, ak.Array]:
if results:
return events, ( results.steps.TrigMuMatch & results.steps.SR_ele & results.steps.ref_trigger_e)
else:
raise NotImplementedError(f"Category didn't receive a SelectionResult")

# test categorizer without matching of trigger and offline object
@categorizer()
def catid_trigger_orth_e_no_match(
self: Categorizer,
events: ak.Array,
results: SelectionResult | None = None,
**kwargs,
) -> tuple[ak.Array, ak.Array]:
if results:
return events, ( results.steps.SR_ele & results.steps.ref_trigger_e)
else:
raise NotImplementedError(f"Category didn't receive a SelectionResult")
67 changes: 67 additions & 0 deletions hbw/trigger/categories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# coding: utf-8
"""
defines categories based on the selection used for the trigger studies
"""

from __future__ import annotations

import law

from columnflow.util import maybe_import
from columnflow.categorization import Categorizer, categorizer
from columnflow.selection import SelectionResult

np = maybe_import("numpy")
ak = maybe_import("awkward")

# categorizer muon channel
@categorizer()
def catid_trigger_mu(
self: Categorizer,
events: ak.Array,
results: SelectionResult | None = None,
**kwargs,
) -> tuple[ak.Array, ak.Array]:
if results:
return events, results.steps.SR_mu
else:
raise NotImplementedError(f"Category didn't receive a SelectionResult")

# categorizer electron channel
@categorizer()
def catid_trigger_ele(
self: Categorizer,
events: ak.Array,
results: SelectionResult | None = None,
**kwargs,
) -> tuple[ak.Array, ak.Array]:
if results:
return events, results.steps.SR_ele
else:
raise NotImplementedError(f"Category didn't receive a SelectionResult")

# categorizer for orthogonal measurement (muon channel)
@categorizer()
def catid_trigger_orth_mu(
self: Categorizer,
events: ak.Array,
results: SelectionResult | None = None,
**kwargs,
) -> tuple[ak.Array, ak.Array]:
if results:
return events, ( results.steps.TrigEleMatch & results.steps.SR_mu & results.steps.ref_trigger_mu)
else:
raise NotImplementedError(f"Category didn't receive a SelectionResult")

# categorizer for orthogonal measurement (electron channel)
@categorizer()
def catid_trigger_orth_ele(
self: Categorizer,
events: ak.Array,
results: SelectionResult | None = None,
**kwargs,
) -> tuple[ak.Array, ak.Array]:
if results:
return events, ( results.steps.TrigMuMatch & results.steps.SR_ele & results.steps.ref_trigger_e)
else:
raise NotImplementedError(f"Category didn't receive a SelectionResult")
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
--datasets tt_dl_powheg --categories trig_mu \
--selector trigger_studies --producers event_weights,trigger_prod \
--calibrators "" \
--plot-function hbw.plotting.plot_efficiencies.plot_efficiencies
--plot-function hbw.trigger.plot_efficiencies.plot_efficiencies
'''

def plot_efficiencies(
Expand Down
Loading

0 comments on commit 605903c

Please sign in to comment.