Skip to content

Commit

Permalink
weights, effi errors, versions
Browse files Browse the repository at this point in the history
  • Loading branch information
BalduinLetzer committed Aug 15, 2024
1 parent 31debc6 commit 22d588c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
4 changes: 2 additions & 2 deletions hbw/trigger/plot_efficiencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def plot_efficiencies(
for proc_inst, myhist in hists.items():

# get normalisation from first histogram (all events)
norm_hist = np.array(myhist[:, 0].values())
norm_hist = myhist[:, 0]

# plot config for the background distribution
plot_config["hist_0"] = {
Expand Down Expand Up @@ -101,7 +101,7 @@ def plot_efficiencies(
"method": "draw_efficiency",
"hist": myhist[:, i],
"kwargs": {
"norm": norm_hist,
"h_norm": norm_hist,
"label": f"{proc_inst.label}: {config_inst.x.trigger_short[i]}",
},
}
Expand Down
5 changes: 5 additions & 0 deletions hbw/trigger/trigger_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ def add_trigger_columns(config: od.Config) -> None:
},
x_title="Trigger names (orthogonal)",
)
config.add_variable(
name="trig_weights",
binning=(100, -5, 5),
x_title="event weights",
)


@call_once_on_config()
Expand Down
27 changes: 27 additions & 0 deletions hbw/trigger/trigger_prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from columnflow.production.categories import category_ids

from hbw.trigger.trigger_config import add_trigger_categories
from hbw.weight.default import default_weight_producer
from hbw.production.weights import event_weights

np = maybe_import("numpy")
ak = maybe_import("awkward")
Expand All @@ -19,6 +21,7 @@
@producer(
produces={"trig_bits_mu", "trig_bits_orth_mu", "trig_bits_e", "trig_bits_orth_e"},
channel=["mu", "e"],
version=1,
)
def trigger_prod(self: Producer, events: ak.Array, **kwargs) -> ak.Array:
"""
Expand Down Expand Up @@ -63,6 +66,7 @@ def trigger_prod_init(self: Producer) -> None:
@producer(
uses=category_ids,
produces=category_ids,
version=1,
)
def trig_cats(self: Producer, events: ak.Array, **kwargs) -> ak.Array:
"""
Expand All @@ -78,3 +82,26 @@ def trig_cats(self: Producer, events: ak.Array, **kwargs) -> ak.Array:
def trig_cats_init(self: Producer) -> None:

add_trigger_categories(self.config_inst)


@producer(
uses={
default_weight_producer,
event_weights,
},
produces={
"trig_weights",
},
version=1,
)
def trig_weights(self: Producer, events: ak.Array, **kwargs) -> ak.Array:
"""
Produces a weight column to check the event weights
"""

events = self[event_weights](events, **kwargs)
events, weights = self[default_weight_producer](events, **kwargs)
trig_weights = weights
events = set_ak_column(events, "trig_weights", trig_weights)

return events
7 changes: 4 additions & 3 deletions hbw/trigger/trigger_sel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@selector(
uses=(four_vec({"Muon", "Electron"})) | {"TrigObj.*"},
exposed=True,
version=1,
)
def trigger_sel(
self: Selector,
Expand Down Expand Up @@ -90,19 +91,19 @@ def trigger_sel(
# save selection results for different channels
results.steps["SR_mu"] = (
results.steps.cleanup &
results.steps.nJet1 &
results.steps.nJet3 &
results.steps.nBjet1 &
results.steps.TrigMuMask
)
results.steps["SR_ele"] = (
results.steps.cleanup &
results.steps.nJet1 &
results.steps.nJet3 &
results.steps.nBjet1 &
results.steps.TrigEleMask
)
results.steps["all_but_bjet"] = (
results.steps.cleanup &
results.steps.nJet1 &
results.steps.nJet3 &
(results.steps.TrigMuMask | results.steps.TrigEleMask)
)

Expand Down
2 changes: 1 addition & 1 deletion hbw/weight/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def base_init(self: WeightProducer) -> None:
"stitched_normalization_weight": [],
**default_correction_weights,
}
base.derive("default", cls_dict={"weight_columns": default_weight_columns})
default_weight_producer = base.derive("default", cls_dict={"weight_columns": default_weight_columns})
base.derive("unstitched", cls_dict={"weight_columns": {**default_correction_weights, "normalization_weight": []}})

weight_columns_execpt_btag = default_weight_columns.copy()
Expand Down
2 changes: 1 addition & 1 deletion modules/columnflow

0 comments on commit 22d588c

Please sign in to comment.