Skip to content

Commit

Permalink
only single mu trigger + more plotting variables + turn off subjet ma…
Browse files Browse the repository at this point in the history
…tching + inclusive_weight_producer
  • Loading branch information
haddadanas committed Nov 7, 2024
1 parent 1dc03e1 commit 4126b9c
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 38 deletions.
11 changes: 6 additions & 5 deletions hbt/config/configs_hbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ def if_era(
"dy_m50toinf_2j_pt400to600_amcatnlo",
"dy_m50toinf_2j_pt600toinf_amcatnlo",
"w_lnu_amcatnlo",
"z_qq_pt100to200_1j_amcatnlo",
"z_qq_pt100to200_2j_amcatnlo",
"z_qq_pt200to400_1j_amcatnlo",
"z_qq_pt200to400_2j_amcatnlo", # literally no events selected above 400 GeV
"z_qq_1j_pt100to200_amcatnlo",
"z_qq_2j_pt100to200_amcatnlo",
"z_qq_1j_pt200to400_amcatnlo",
"z_qq_2j_pt200to400_amcatnlo", # literally no events selected above 400 GeV
"zz_pythia",
"wz_pythia",
"ww_pythia",
Expand Down Expand Up @@ -1084,11 +1084,12 @@ def add_external(name, value):
# (this info is used by weight producers)
get_shifts = functools.partial(get_shifts_from_sources, cfg)
cfg.x.event_weights = DotDict({
# "normalization_weight_incl": [],
"normalization_weight": [],
"pdf_weight": get_shifts("pdf"),
"murmuf_weight": get_shifts("murmuf"),
"normalized_pu_weight": get_shifts("minbias_xs"),
"normalized_njet_btag_weight": get_shifts(*(f"btag_{unc}" for unc in cfg.x.btag_unc_names)),
"normalized_btag_weight": get_shifts(*(f"btag_{unc}" for unc in cfg.x.btag_unc_names)),
"electron_weight": get_shifts("e"),
"muon_weight": get_shifts("mu"),
"tau_weight": get_shifts(*(f"tau_{unc}" for unc in cfg.x.tau_unc_names)),
Expand Down
64 changes: 60 additions & 4 deletions hbt/config/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ def add_variables(config: od.Config) -> None:
binning=(200, -10, 10),
x_title="MC weight",
)
config.add_variable(
name="normalization",
expression="normalization_weight",
binning=(200, -2, 2),
x_title="MC weight",
)
config.add_variable(
name="normalization_incl",
expression="normalization_weight_incl",
binning=(200, -2, 2),
x_title="MC weight",
)
config.add_variable(
name="pu_weight",
expression="pu_weight",
Expand Down Expand Up @@ -195,6 +207,25 @@ def add_variables(config: od.Config) -> None:
unit="GeV",
x_title=r"Muon 1 $p_{T}$",
)
from functools import reduce
from operator import mul
weight_names = [
"pdf_weight",
"murmuf_weight",
"normalized_pu_weight",
"normalized_njet_btag_weight",
"electron_weight",
"muon_weight",
"tau_weight",
"tau_trigger_weight",
]
config.add_variable(
name="mul_weights",
expression=(lambda events: reduce(mul, [events[name] for name in weight_names])),
binning=(100, -1, 3),
x_title="mul_weights",
)

config.add_variable(
name="mu2_pt",
expression="Muon.pt[:,1]",
Expand Down Expand Up @@ -272,16 +303,41 @@ def add_variables(config: od.Config) -> None:
config.add_variable(
name="pt2mu",
expression="pt2mu",
binning=[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140, 160, 180,
200, 225, 250, 275, 300, 325, 350, 375, 400, 450, 500],
binning=(50, 0, 500.0),
unit="GeV",
x_title=r"$p_T (\mu\mu)$",
)
config.add_variable(
name="pt2mu_40",
expression="pt2mu",
selection="Muon.pt[:, 0] > 40",
null_value=EMPTY_FLOAT,
binning=(50, 0, 500.0),
unit="GeV",
x_title=r"$p_T (\mu\mu)$",
)
config.add_variable(
name="pt2mu_50",
expression="pt2mu",
selection="Muon.pt[:, 0] > 50",
null_value=EMPTY_FLOAT,
binning=(50, 0, 500.0),
unit="GeV",
x_title=r"$p_T (\mu\mu)$",
)
config.add_variable(
name="pt2mu_80",
expression="pt2mu",
selection="Muon.pt[:, 0] > 80",
null_value=EMPTY_FLOAT,
binning=(50, 0, 500.0),
unit="GeV",
x_title=r"$p_T (\mu\mu)$",
)

config.add_variable(
name="m2mu",
expression="m2mu",
binning=(20, 50, 200.0),
binning=(40, 0, 200.0),
unit="GeV",
x_title=r"$m_{\mu\mu}$",
)
Expand Down
2 changes: 1 addition & 1 deletion hbt/selection/jet.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def jet_selection(
# final event selection
jet_sel = (
(ak.sum(default_mask, axis=1) >= 2) &
ak.fill_none(subjets_btagged, True) # was none for events with no matched fatjet
True # ak.fill_none(subjets_btagged, True) # was none for events with no matched fatjet
)

# some final type conversions
Expand Down
46 changes: 23 additions & 23 deletions hbt/selection/lepton.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def muon_selection(
(abs(events.Muon.dxy) < 0.045) &
(abs(events.Muon.dz) < 0.2) &
(events.Muon.pfRelIso04_all < 0.15) &
(events.Muon.pt > 20) &
(events.Muon.pt > 30) &
matches_leg0
)
new_mask = (
Expand Down Expand Up @@ -470,29 +470,29 @@ def lepton_selection(
sel_electron_indices = ak.where(where, electron_indices, sel_electron_indices)
sel_tau_indices = ak.where(where, tau_indices, sel_tau_indices)

elif trigger.has_tag({"single_mu", "cross_mu_tau"}):
elif trigger.has_tag({"single_mu"}):
# expect 1 muon, 1 veto muon (the same one), 0 veto electrons, and at least one tau
is_mutau = (
trigger_fired &
(ak.num(muon_indices, axis=1) == 1) &
(ak.num(muon_veto_indices, axis=1) == 1) &
(ak.num(electron_veto_indices, axis=1) == 0) &
(ak.num(tau_indices, axis=1) >= 1)
)
is_iso = ak.sum(tau_iso_mask, axis=1) >= 1
# determine the os/ss charge sign relation
mu_charge = ak.firsts(events.Muon[muon_indices].charge, axis=1)
tau_charge = ak.firsts(events.Tau[tau_indices].charge, axis=1)
is_os = mu_charge == -tau_charge
# store global variables
where = (channel_id == 0) & is_mutau
channel_id = ak.where(where, ch_mutau.id, channel_id)
tau2_isolated = ak.where(where, is_iso, tau2_isolated)
leptons_os = ak.where(where, is_os, leptons_os)
single_triggered = ak.where(where & is_single, True, single_triggered)
cross_triggered = ak.where(where & is_cross, True, cross_triggered)
sel_muon_indices = ak.where(where, muon_indices, sel_muon_indices)
sel_tau_indices = ak.where(where, tau_indices, sel_tau_indices)
# is_mutau = (
# trigger_fired &
# (ak.num(muon_indices, axis=1) == 1) &
# (ak.num(muon_veto_indices, axis=1) == 1) &
# (ak.num(electron_veto_indices, axis=1) == 0) &
# (ak.num(tau_indices, axis=1) >= 1)
# )
# is_iso = ak.sum(tau_iso_mask, axis=1) >= 1
# # determine the os/ss charge sign relation
# mu_charge = ak.firsts(events.Muon[muon_indices].charge, axis=1)
# tau_charge = ak.firsts(events.Tau[tau_indices].charge, axis=1)
# is_os = mu_charge == -tau_charge
# # store global variables
# where = (channel_id == 0) & is_mutau
# channel_id = ak.where(where, ch_mutau.id, channel_id)
# tau2_isolated = ak.where(where, is_iso, tau2_isolated)
# leptons_os = ak.where(where, is_os, leptons_os)
# single_triggered = ak.where(where & is_single, True, single_triggered)
# cross_triggered = ak.where(where & is_cross, True, cross_triggered)
# sel_muon_indices = ak.where(where, muon_indices, sel_muon_indices)
# sel_tau_indices = ak.where(where, tau_indices, sel_tau_indices)

# expect 2 muon, 2 veto muon (the same one), 0 veto electrons
is_mumu = (
Expand Down
27 changes: 27 additions & 0 deletions hbt/weight/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
Default event weight definitions.
"""
import law

from columnflow.weight import WeightProducer, weight_producer
from columnflow.columnar_util import Route
Expand All @@ -11,6 +12,16 @@
ak = maybe_import("awkward")
np = maybe_import("numpy")

logger = law.logger.get_logger(__name__)


def ensure_list(obj):
if obj is None:
return []
if isinstance(obj, list):
return obj
return [obj]


@weight_producer(
# both produced columns and dependent shifts are defined in init below
Expand All @@ -35,10 +46,20 @@ def default_init(self: WeightProducer) -> None:
# weight producer instance, store weight_columns, used columns, and shifts
self.weight_columns = []

# cast keep_weights and drop_weights to lists
self.keep_weights = ensure_list(self.keep_weights)
self.drop_weights = ensure_list(self.drop_weights)

# helpers to match to kept or dropped weights
do_keep = pattern_matcher(self.keep_weights) if self.keep_weights else (lambda _: True)
do_drop = pattern_matcher(self.drop_weights) if self.drop_weights else (lambda _: False)

for weight_name in list(self.keep_weights):
if weight_name not in self.config_inst.x.event_weights:
# raise ValueError(f"Unknown weight name: {weight_name}")
self.config_inst.x.event_weights.update({weight_name: []})
logger.info(f"Did not find weight {weight_name} in config, adding it!")

for weight_name in self.config_inst.x.event_weights:
if not do_keep(weight_name) or do_drop(weight_name):
continue
Expand Down Expand Up @@ -70,3 +91,9 @@ def default_init(self: WeightProducer) -> None:
"inclusive_only",
cls_dict={"keep_weights": "normalization_weight_incl"},
)


no_weight = default.derive(
"no_weight",
cls_dict={"skip_func": (lambda self: True), "mc_only": None},
)
11 changes: 6 additions & 5 deletions law.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ run3_2022_preEE*__cf.MergeReductionStats: wlcg_mirrored, local_fs_desy_anhaddad,
run3_2022_preEE*__cf.MergeSelectionStats: wlcg_mirrored, local_fs_desy_anhaddad, wlcg_fs_desy_anhaddad
run3_2022_preEE*__cf.ProduceColumns: wlcg_mirrored, local_fs_desy_anhaddad, wlcg_fs_desy_anhaddad
run3_2022_preEE*__cf.UniteColumns: wlcg_mirrored, local_fs_desy_anhaddad, wlcg_fs_desy_anhaddad
run3_2022_preEE*__cf.CreateHistograms: wlcg_mirrored, local_fs_desy_anhaddad, wlcg_fs_desy_anhaddad
run3_2022_preEE*__cf.MergeHistograms: wlcg_mirrored, local_fs_desy_anhaddad, wlcg_fs_desy_anhaddad
run3_2022_preEE*__cf.CreateHistograms: wlcg, wlcg_fs_desy_anhaddad
run3_2022_preEE*__cf.MergeHistograms: wlcg, wlcg_fs_desy_anhaddad
run3_2022_preEE*__cf.MergeShiftedHistograms: wlcg_mirrored, local_fs_desy_anhaddad, wlcg_fs_desy_anhaddad
run3_2022_preEE*__cf.CreateDatacards: wlcg_mirrored, local_fs_desy_anhaddad, wlcg_fs_desy_anhaddad
# fallbacks
Expand Down Expand Up @@ -138,9 +138,10 @@ cf.CreateSyncFile: wlcg
[versions]

run3_2022_preEE*__cf.CalibrateEvents: prod1
run3_2022_preEE*__cf.MergeSelectionStats: dysf
run3_2022_preEE*__cf.MergeReductionStats: dysf
run3_2022_preEE*__cf.ProvideReducedEvents: dysf
run3_2022_preEE*__cf.MergeSelectionStats: dysf_cat
run3_2022_preEE*__cf.MergeReductionStats: dysf_cat
run3_2022_preEE*__cf.ProvideReducedEvents: dysf_cat
run3_2022_preEE*__cf.ProduceColumns: dysf_cat


#
Expand Down

0 comments on commit 4126b9c

Please sign in to comment.