Skip to content

Commit 678d8ba

Browse files
committed
fixes in object definitions
1 parent 234ceff commit 678d8ba

File tree

1 file changed

+75
-21
lines changed

1 file changed

+75
-21
lines changed

hbw/selection/common.py

+75-21
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from hbw.production.weights import event_weights_to_normalize, large_weights_killer
3030
from hbw.selection.stats import hbw_selection_step_stats, hbw_increment_stats
3131
from hbw.selection.cutflow_features import cutflow_features
32-
from hbw.util import four_vec
32+
from hbw.util import four_vec, call_once_on_config
3333

3434
np = maybe_import("numpy")
3535
ak = maybe_import("awkward")
@@ -84,6 +84,11 @@ def jet_selection(
8484
events = set_ak_column(events, "local_index", ak.local_index(events.Jet))
8585

8686
# default jet definition
87+
jet_mask_loose = (
88+
(events.Jet.pt >= 25) &
89+
(abs(events.Jet.eta) <= 2.4) &
90+
(events.Jet.jetId >= 2) # 1: loose, 2: tight, 4: isolated, 6: tight+isolated
91+
)
8792
jet_mask = (
8893
(events.Jet.pt >= 25) &
8994
(abs(events.Jet.eta) <= 2.4) &
@@ -99,6 +104,9 @@ def jet_selection(
99104
# get the jet indices for pt-sorting of jets
100105
jet_indices = masked_sorted_indices(jet_mask, events.Jet.pt)
101106

107+
steps["nJetReco1"] = ak.num(events.Jet) >= 1
108+
steps["nJetLoose1"] = ak.sum(jet_mask_loose, axis=1) >= 1
109+
102110
# add jet steps
103111
events = set_ak_column(events, "cutflow.n_jet", ak.sum(jet_mask, axis=1))
104112
steps["nJet1"] = events.cutflow.n_jet >= 1
@@ -142,6 +150,13 @@ def jet_selection(
142150

143151
@jet_selection.init
144152
def jet_selection_init(self: Selector) -> None:
153+
# Add shift dependencies
154+
self.shifts |= {
155+
shift_inst.name
156+
for shift_inst in self.config_inst.shifts
157+
if shift_inst.has_tag(("jec", "jer"))
158+
}
159+
145160
# set the main b_tagger + working point as defined from the selector
146161
self.config_inst.x.b_tagger = self.b_tagger
147162
self.config_inst.x.btag_wp = self.btag_wp
@@ -169,22 +184,24 @@ def jet_selection_init(self: Selector) -> None:
169184
self.produces.add("cutflow.n_jet")
170185
self.produces.add("cutflow.n_btag")
171186

172-
# create variable instances
173-
self.config_inst.add_variable(
174-
name="cf_n_jet",
175-
expression="cutflow.n_jet",
176-
binning=(7, -0.5, 6.5),
177-
x_title="Number of jets",
178-
discrete_x=True,
179-
)
180-
self.config_inst.add_variable(
181-
name="cf_n_btag",
182-
expression="cutflow.n_btag",
183-
binning=(7, -0.5, 6.5),
184-
x_title=f"Number of b-tagged jets ({self.b_tagger}, {self.btag_wp} WP)",
185-
discrete_x=True,
186-
)
187-
187+
@call_once_on_config
188+
def add_jet_cutflow_variables(config: od.Config):
189+
config.add_variable(
190+
name="cf_n_jet",
191+
expression="cutflow.n_jet",
192+
binning=(7, -0.5, 6.5),
193+
x_title="Number of jets",
194+
discrete_x=True,
195+
)
196+
config.add_variable(
197+
name="cf_n_btag",
198+
expression="cutflow.n_btag",
199+
binning=(7, -0.5, 6.5),
200+
x_title=f"Number of b-tagged jets ({self.b_tagger}, {self.btag_wp} WP)",
201+
discrete_x=True,
202+
)
203+
204+
add_jet_cutflow_variables(self.config_inst)
188205

189206
@selector(
190207
uses=(
@@ -295,21 +312,25 @@ def lepton_definition(
295312
(electron.convVeto) &
296313
(electron.lostHits == 0) &
297314
((electron.mvaTTH >= 0.30) | (electron.mvaIso_WP90)) &
298-
(ak.all(electron.matched_jet[btag_column] <= btag_wp_score, axis=1)) &
315+
(
316+
((electron.mvaTTH < 0.30) & (electron.matched_jet[btag_column] <= btag_tight_score)) |
317+
((electron.mvaTTH >= 0.30) & (electron.matched_jet[btag_column] <= btag_wp_score))
318+
) &
319+
(electron.matched_jet[btag_column] <= btag_wp_score) &
299320
((electron.mvaTTH >= 0.30) | (electron.jetRelIso < 0.70))
300321
)
301322

302323
mu_mask_fakeable = (
303324
mu_mask_loose &
304325
(muon.cone_pt >= 10) &
305326
(
306-
((muon.mvaTTH < 0.30) & (ak.all(muon.matched_jet[btag_column] <= btag_tight_score, axis=1))) |
307-
((muon.mvaTTH >= 0.30) & (ak.all(muon.matched_jet[btag_column] <= btag_wp_score, axis=1)))
327+
((muon.mvaTTH < 0.50) & (muon.matched_jet[btag_column] <= btag_tight_score)) |
328+
((muon.mvaTTH >= 0.50) & (muon.matched_jet[btag_column] <= btag_wp_score))
308329
) &
309330
# missing: DeepJet of nearby jet
310331
((muon.mvaTTH >= 0.50) | (muon.jetRelIso < 0.80))
311332
)
312-
from hbw.util import debugger; debugger()
333+
313334
# tight masks
314335
e_mask_tight = (
315336
e_mask_fakeable &
@@ -451,6 +472,22 @@ def vbf_jet_selection(
451472
)
452473

453474

475+
@vbf_jet_selection.init
476+
def vbf_jet_selection_init(self: Selector) -> None:
477+
# Add shift dependencies
478+
self.shifts |= {
479+
shift_inst.name
480+
for shift_inst in self.config_inst.shifts
481+
if shift_inst.has_tag(("jec", "jer"))
482+
}
483+
484+
# update selector step labels
485+
self.config_inst.x.selector_step_labels = self.config_inst.x("selector_step_labels", {})
486+
self.config_inst.x.selector_step_labels.update({
487+
"VBFJetPair": r"$N_{VBFJetPair}^{AK4} \geq 1$",
488+
})
489+
490+
454491
@selector(
455492
uses=(
456493
four_vec(
@@ -461,6 +498,7 @@ def vbf_jet_selection(
461498
)
462499
),
463500
produces=(
501+
# NOTE: we should only produce them when cutflow is required
464502
{"cutflow.n_fatjet", "cutflow.n_hbbjet"} |
465503
four_vec(
466504
{"FatJet", "HbbJet"},
@@ -581,6 +619,22 @@ def sl_boosted_jet_selection(
581619
)
582620

583621

622+
@sl_boosted_jet_selection.init
623+
def sl_boosted_jet_selection_init(self: Selector) -> None:
624+
# Add shift dependencies
625+
self.shifts |= {
626+
shift_inst.name
627+
for shift_inst in self.config_inst.shifts
628+
if shift_inst.has_tag(("jec", "jer"))
629+
}
630+
631+
# update selector step labels
632+
self.config_inst.x.selector_step_labels = self.config_inst.x("selector_step_labels", {})
633+
self.config_inst.x.selector_step_labels.update({
634+
"HbbJet": r"$N_{H \rightarrow bb}^{AK8} \geq 1$",
635+
})
636+
637+
584638
# boosted selection for the DL channel (only one parameter needs to be changed)
585639
dl_boosted_jet_selection = sl_boosted_jet_selection.derive(
586640
"dl_boosted_jet_selection",

0 commit comments

Comments
 (0)