Skip to content

Commit

Permalink
Merge pull request #66 from nprouvost/add_lowered_pt_non_triggered_ob…
Browse files Browse the repository at this point in the history
…jects

add lowered pt cut for non triggered objects in control channels
  • Loading branch information
riga authored Feb 10, 2025
2 parents e04374f + d1d8022 commit 403afde
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions hbt/selection/lepton.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@ def electron_selection(
mva_iso_wp90 = events.Electron.mvaFall17V2Iso_WP90

# default electron mask
default_mask = None
analysis_mask = None
control_mask = None
if is_single or is_cross:
min_pt = 26.0 if is_2016 else (31.0 if is_single else 25.0)
max_eta = 2.5 if is_single else 2.1
default_mask = (
(mva_iso_wp80 == 1) &
(abs(events.Electron.eta) < max_eta) &
(abs(events.Electron.dxy) < 0.045) &
(abs(events.Electron.dz) < 0.2) &
(events.Electron.pt > min_pt)
(abs(events.Electron.dz) < 0.2)
)

# additional cut in 2022 post-EE
Expand All @@ -144,6 +144,10 @@ def electron_selection(
(events.Electron.seediPhiOriY > 72)
)

# control mask for the electron selection
control_mask = default_mask & (events.Electron.pt > 24)
analysis_mask = default_mask & (events.Electron.pt > min_pt)

# veto electron mask (must be trigger independent!)
veto_mask = (
(mva_iso_wp90 == 1) &
Expand All @@ -153,7 +157,7 @@ def electron_selection(
(events.Electron.pt > 10.0)
)

return default_mask, veto_mask
return analysis_mask, control_mask, veto_mask


@electron_selection.init
Expand Down Expand Up @@ -218,7 +222,8 @@ def muon_selection(
is_cross = trigger.has_tag("cross_mu_tau")

# default muon mask
default_mask = None
analysis_mask = None
control_mask = None
if is_single or is_cross:
if is_2016:
min_pt = 23.0 if is_single else 20.0
Expand All @@ -229,9 +234,10 @@ def muon_selection(
(abs(events.Muon.eta) < 2.4) &
(abs(events.Muon.dxy) < 0.045) &
(abs(events.Muon.dz) < 0.2) &
(events.Muon.pfRelIso04_all < 0.15) &
(events.Muon.pt > min_pt)
(events.Muon.pfRelIso04_all < 0.15)
)
control_mask = default_mask & (events.Muon.pt > 20)
analysis_mask = default_mask & (events.Muon.pt > min_pt)

# veto muon mask (must be trigger independent!)
veto_mask = (
Expand All @@ -243,7 +249,7 @@ def muon_selection(
(events.Muon.pt > 10)
)

return default_mask, veto_mask
return analysis_mask, control_mask, veto_mask


@selector(
Expand Down Expand Up @@ -497,14 +503,14 @@ def lepton_selection(
is_cross = trigger.has_tag("cross_trigger")

# electron selection
electron_mask, electron_veto_mask = self[electron_selection](
electron_mask, electron_control_mask, electron_veto_mask = self[electron_selection](
events,
trigger,
**sel_kwargs,
)

# muon selection
muon_mask, muon_veto_mask = self[muon_selection](
muon_mask, muon_control_mask, muon_veto_mask = self[muon_selection](
events,
trigger,
**sel_kwargs,
Expand Down Expand Up @@ -708,15 +714,16 @@ def lepton_selection(
# expect 2 electrons, 2 veto electrons, 0 veto muons, and ignore the taus
is_ee = (
trigger_fired &
(ak.sum(electron_mask, axis=1) == 2) &
(ak.sum(electron_mask, axis=1) >= 1) &
(ak.sum(electron_control_mask, axis=1) == 2) &
leading_electron_matched &
(ak.sum(electron_veto_mask, axis=1) == 2) &
(ak.sum(muon_veto_mask, axis=1) == 0)
)

# get selected, sorted electrons to obtain quantities
# (this will be correct for events for which is_ee is actually True)
sorted_sel_electrons = events.Electron[electron_sorting_indices][electron_mask[electron_sorting_indices]]
sorted_sel_electrons = events.Electron[electron_sorting_indices][electron_control_mask[electron_sorting_indices]] # noqa
# determine the relative charge
e1_charge = ak.firsts(sorted_sel_electrons.charge, axis=1)
e2_charge = ak.firsts(sorted_sel_electrons.charge[:, 1:], axis=1)
Expand Down Expand Up @@ -749,15 +756,16 @@ def lepton_selection(
# expect 2 muons, 2 veto muons, 0 veto electrons, and ignore the taus
is_mumu = (
trigger_fired &
(ak.sum(muon_mask, axis=1) == 2) &
(ak.sum(muon_mask, axis=1) >= 1) &
(ak.sum(muon_control_mask, axis=1) == 2) &
leading_muon_matched &
(ak.sum(muon_veto_mask, axis=1) == 2) &
(ak.sum(electron_veto_mask, axis=1) == 0)
)

# get selected, sorted muons to obtain quantities
# (this will be correct for events for which is_mumu is actually True)
sorted_sel_muons = events.Muon[muon_sorting_indices][muon_mask[muon_sorting_indices]]
sorted_sel_muons = events.Muon[muon_sorting_indices][muon_control_mask[muon_sorting_indices]]
# determine the relative charge
mu1_charge = ak.firsts(sorted_sel_muons.charge, axis=1)
mu2_charge = ak.firsts(sorted_sel_muons.charge[:, 1:], axis=1)
Expand Down Expand Up @@ -795,7 +803,8 @@ def lepton_selection(
continue
# evaluate the muon selection once (it is the same for all single triggers)
if emu_muon_mask is False:
emu_muon_mask, _ = self[muon_selection](events, _trigger, **sel_kwargs)
# the correct muon mask is the control muon mask with min pt 20
_, emu_muon_mask, _ = self[muon_selection](events, _trigger, **sel_kwargs)
# store the trigger decision
mu_trig_fired = mu_trig_fired | _trigger_fired
# muons obey the trigger rules if no single trigger fired
Expand All @@ -818,14 +827,18 @@ def lepton_selection(
continue
# evaluate the electron selection once (it is the same for all single triggers)
if emu_electron_mask is False:
emu_electron_mask, _ = self[electron_selection](events, _trigger, **sel_kwargs)
emu_electron_mask_if_triggered, emu_electron_control_mask, _ = self[electron_selection](events, _trigger, **sel_kwargs) # noqa
# store the trigger decision
e_trig_fired = e_trig_fired | _trigger_fired
# evaluate the matching
e_match_mask = e_match_mask | (
self[electron_trigger_matching](events, _trigger, _trigger_fired, _leg_masks, **sel_kwargs) &
_trigger_fired
)

# the correct electron mask is the control electron mask where the trigger did not fire
# and the electron_mask_triggered where the trigger did fire
emu_electron_mask = ak.where(e_trig_fired, emu_electron_mask_if_triggered, emu_electron_control_mask)
# for events in which no single e trigger fired, consider the matching as successful
e_match_mask = e_match_mask | ~e_trig_fired
trig_electron_mask = emu_electron_mask & e_match_mask
Expand Down

0 comments on commit 403afde

Please sign in to comment.