Skip to content

Commit

Permalink
further triggerstudies and adjusted variable binning
Browse files Browse the repository at this point in the history
  • Loading branch information
BalduinLetzer committed Jul 24, 2024
1 parent d493030 commit ebeeaf6
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 30 deletions.
4 changes: 2 additions & 2 deletions hbw/config/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ def add_trigger_categories(config: od.Config) -> None:
name="trig_mu_orth",
id=3000,
selection="catid_trigger_orth_mu",
label="Muon\n(orthogonal measurement)",
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\n(orthogonal measurement)",
label="Electron\northogonal\nmeasurement",
)

@call_once_on_config()
Expand Down
11 changes: 11 additions & 0 deletions hbw/config/config_run2.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,5 +740,16 @@ def produce_version(cls, inst, params):
}
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",
}

return cfg
32 changes: 23 additions & 9 deletions hbw/config/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def add_variables(config: od.Config) -> None:
name="ht",
expression=lambda events: ak.sum(events.Jet.pt, axis=1),
aux={"inputs": {"Jet.pt"}},
binning=(40, 0, 1200),
binning=(600, 0, 1200),
unit="GeV",
x_title="HT",
)
Expand All @@ -412,14 +412,14 @@ def add_variables(config: od.Config) -> None:
config.add_variable(
name="jets_pt",
expression="Jet.pt",
binning=(40, 0, 400),
binning=(600, 0, 400),
unit="GeV",
x_title="$p_{T}$ of all jets",
)
config.add_variable(
name="muons_pt",
expression="Muon.pt",
binning=(40, 0, 400),
binning=(600, 0, 400),
unit="GeV",
x_title="$p_{T}$ of all muons",
)
Expand Down Expand Up @@ -595,29 +595,29 @@ def add_variables(config: od.Config) -> None:
name=f"{obj.lower()}_pt",
expression=f"{obj}.pt[:,0]",
null_value=EMPTY_FLOAT,
binning=(40, 0., 350.),
binning=(600, 0., 350.),
unit="GeV",
x_title=obj + r" $p_{T}$",
)
config.add_variable(
name=f"{obj.lower()}_phi",
expression=f"{obj}.phi[:,0]",
null_value=EMPTY_FLOAT,
binning=(40, -3.2, 3.2),
binning=(600, -3.2, 3.2),
x_title=obj + r" $\phi$",
)
config.add_variable(
name=f"{obj.lower()}_eta",
expression=f"{obj}.eta[:,0]",
null_value=EMPTY_FLOAT,
binning=(50, -2.5, 2.5),
binning=(600, -2.5, 2.5),
x_title=obj + r" $\eta$",
)
config.add_variable(
name=f"{obj.lower()}_mass",
expression=f"{obj}.mass[:,0]",
null_value=EMPTY_FLOAT,
binning=(40, 0, 200),
binning=(600, 0, 200),
x_title=obj + " mass",
)

Expand All @@ -638,14 +638,28 @@ def add_variables(config: od.Config) -> None:

# trigger bits to build histograms
config.add_variable(
name="trig_bits",
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",
name="trig_bits_orth_e",
aux={
"axis_type": "strcat",
},
Expand Down
23 changes: 16 additions & 7 deletions hbw/plotting/plot_efficiencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def plot_efficiencies(
default_style_config = prepare_style_config(
config_inst, category_inst, variable_inst, density, shape_norm, yscale,
)

from hbw.util import debugger; debugger()
# loop over processes
for proc_inst, myhist in hists.items():

Expand All @@ -89,21 +89,27 @@ def plot_efficiencies(
}

# plot config for the individual triggers
for i in myhist.axes[1]:
if "bin_sel" in kwargs:
mask_bins = tuple(bin for bin in kwargs["bin_sel"] if bin)
else :
mask_bins = myhist.axes[1]
for i in mask_bins:
if i == "allEvents": continue

plot_config[f"hist_{i}"] = {
plot_config[f"hist_{proc_inst.label}_{i}"] = {
"method": "draw_efficiency",
"hist": myhist[:, i],
"kwargs": {
"norm": norm_hist,
"label": f"{i}",
"label": f"{proc_inst.label}: {config_inst.x.trigger_short[i]}",
},
}

# set legend title to process name
default_style_config["legend_cfg"]["title"] = proc_inst.label

if "title" in default_style_config["legend_cfg"]:
default_style_config["legend_cfg"]["title"] += " & " + proc_inst.label
else:
default_style_config["legend_cfg"]["title"] = proc_inst.label

# plot-function specific changes
default_style_config["ax_cfg"]["ylabel"] = "Efficiency"
Expand All @@ -114,7 +120,10 @@ def plot_efficiencies(

# set correct CMS label TODO: this should be implemented correctly in columnflow by default at one point
style_config["cms_label_cfg"]["exp"] = ""
style_config["cms_label_cfg"]["llabel"] = "Private Work (CMS Simulation)"
if "data" in proc_inst.name:
style_config["cms_label_cfg"]["llabel"] = "Private Work (CMS Data)"
else:
style_config["cms_label_cfg"]["llabel"] = "Private Work (CMS Simulation)"
if "xlim" in kwargs:
style_config["ax_cfg"]["xlim"] = kwargs["xlim"]

Expand Down
17 changes: 9 additions & 8 deletions hbw/production/trigger_prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@


@producer(
produces={"trig_bits", "trig_bits_orth"},
produces={"trig_bits_mu", "trig_bits_orth_mu", "trig_bits_e", "trig_bits_orth_e"},
channel=["mu", "e"],
)
def trigger_prod(self: Producer, events: ak.Array, **kwargs) -> ak.Array:
"""
Produces column where each bin corresponds to a certain trigger
"""

trig_bits = ak.Array([["allEvents"]] * len(events))
trig_bits_orth = ak.Array([["allEvents"]] * len(events))

for channel in self.channel:

trig_bits = ak.Array([["allEvents"]] * len(events))
trig_bits_orth = ak.Array([["allEvents"]] * len(events))

ref_trig = self.config_inst.x.ref_trigger[channel]

for trigger in self.config_inst.x.trigger[channel]:

trig_passed = ak.where(events.HLT[trigger], [[trigger]], [[]])
Expand All @@ -35,9 +37,8 @@ def trigger_prod(self: Producer, events: ak.Array, **kwargs) -> ak.Array:
trig_passed_orth = ak.where((events.HLT[ref_trig] & events.HLT[trigger]), [[trigger]], [[]])
trig_bits_orth = ak.concatenate([trig_bits_orth, trig_passed_orth], axis=1)


events = set_ak_column(events, "trig_bits", trig_bits)
events = set_ak_column(events, "trig_bits_orth", trig_bits_orth)
events = set_ak_column(events, f"trig_bits_{channel}", trig_bits)
events = set_ak_column(events, f"trig_bits_orth_{channel}", trig_bits_orth)

return events

Expand All @@ -50,5 +51,5 @@ def trigger_prod_init(self: Producer) -> None:
self.uses.add(f"HLT.{self.config_inst.x.ref_trigger[channel]}")

# producers for single channels
mu_trigger_prod = trigger_prod.derive("mu_trigger_prod", cls_dict={"channel": ["mu"], "produces": {"trig_bits", "trig_bits_orth"}})
mu_trigger_prod = trigger_prod.derive("mu_trigger_prod", cls_dict={"channel": ["mu"]})
ele_trigger_prod = trigger_prod.derive("ele_trigger_prod", cls_dict={"channel": ["e"]})
4 changes: 2 additions & 2 deletions hbw/selection/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def catid_trigger_orth_mu(
**kwargs,
) -> tuple[ak.Array, ak.Array]:
if results:
return events, ( results.steps.TrigEleMatch & results.steps.SR_mu )
return events, ( results.steps.TrigEleMatch & results.steps.SR_mu & results.steps.ref_trigger_mu)
else:
raise NotImplementedError(f"Category didn't receive a SelectionResult")

Expand All @@ -351,6 +351,6 @@ def catid_trigger_orth_ele(
**kwargs,
) -> tuple[ak.Array, ak.Array]:
if results:
return events, ( results.steps.TrigMuMatch & results.steps.SR_ele )
return events, ( results.steps.TrigMuMatch & results.steps.SR_ele & results.steps.ref_trigger_e)
else:
raise NotImplementedError(f"Category didn't receive a SelectionResult")
2 changes: 1 addition & 1 deletion hbw/selection/hists.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def hbw_selection_hists(
Main selector to create and fill histograms for weight normalization.
"""
# collect important information from the results
no_weights = ak.ones_like(events.mc_weight)
no_weights = ak.Array(np.ones(len(events)))
event_mask = results.event
event_mask_no_bjet = results.steps.all_but_bjet
n_jets = results.x.n_central_jets
Expand Down
6 changes: 6 additions & 0 deletions hbw/selection/trigger_sel.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def trigger_sel(

# TODO: check if trigger were fired by unprescaled L1 seed

# add reference trigger to selection steps for use orthogonal categories
for channel, ref_trigger in self.config_inst.x.ref_trigger.items():
results.steps[f"ref_trigger_{channel}"] = events.HLT[ref_trigger]

# save selection results for different channels
results.steps["SR_mu"] = (
results.steps.cleanup &
Expand Down Expand Up @@ -139,3 +143,5 @@ def trigger_sel_init(self: Selector) -> None:
jet_selection,
}

for ref_trigger in self.config_inst.x.ref_trigger.values():
self.uses.add(f"HLT.{ref_trigger}")

0 comments on commit ebeeaf6

Please sign in to comment.