Skip to content

Commit

Permalink
Add back top pt weight.
Browse files Browse the repository at this point in the history
  • Loading branch information
riga committed Feb 12, 2025
1 parent 7ecdf80 commit 6a914e5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
25 changes: 21 additions & 4 deletions hbt/config/configs_hbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,25 @@ def if_not_era(*, values: list[str | None] | None = None, **kwargs) -> list[str]
discriminator="btagPNetB",
)

################################################################################################
# dataset / process specific methods
################################################################################################

# top pt reweighting
# https://twiki.cern.ch/twiki/bin/view/CMS/TopPtReweighting?rev=31
from columnflow.production.cms.top_pt_weight import TopPtWeightConfig
cfg.x.top_pt_weight = TopPtWeightConfig(
params={
"a": 0.0615,
"a_up": 0.0615 * 1.5,
"a_down": 0.0615 * 0.5,
"b": -0.0005,
"b_up": -0.0005 * 1.5,
"b_down": -0.0005 * 0.5,
},
pt_max=500.0,
)

################################################################################################
# shifts
################################################################################################
Expand Down Expand Up @@ -1322,10 +1341,8 @@ def add_external(name, value):

# define per-dataset event weights
for dataset in cfg.datasets:
# skipped for now
# if dataset.has_tag("ttbar"):
# dataset.x.event_weights = {"top_pt_weight": get_shifts("top_pt")}
pass
if dataset.has_tag("has_top"):
dataset.x.event_weights = {"top_pt_weight": get_shifts("top_pt")}

cfg.x.shift_groups = {
"jec": [
Expand Down
9 changes: 9 additions & 0 deletions hbt/production/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from columnflow.production.categories import category_ids
from columnflow.production.cms.electron import electron_weights
from columnflow.production.cms.muon import muon_weights
from columnflow.production.cms.top_pt_weight import top_pt_weight
from columnflow.util import maybe_import

from hbt.production.weights import (
Expand Down Expand Up @@ -78,13 +79,21 @@ def default(self: Producer, events: ak.Array, **kwargs) -> ak.Array:
if self.has_dep(trigger_weights):
events = self[trigger_weights](events, **kwargs)

# top pt weight
if self.has_dep(top_pt_weight):
events = self[top_pt_weight](events, **kwargs)

return events


@default.init
def default_init(self: Producer) -> None:
if self.produce_weights:
weight_producers = {tau_weights, electron_weights, muon_weights, trigger_weights}

if (dataset_inst := getattr(self, "dataset_inst", None)) and dataset_inst.has_tag("ttbar"):
weight_producers.add(top_pt_weight)

self.uses |= weight_producers
self.produces |= weight_producers

Expand Down
5 changes: 5 additions & 0 deletions hbt/selection/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from columnflow.production.cms.pileup import pu_weight
from columnflow.production.cms.pdf import pdf_weights
from columnflow.production.cms.scale import murmuf_weights
from columnflow.production.cms.top_pt_weight import gen_parton_top
from columnflow.production.util import attach_coffea_behavior
from columnflow.columnar_util import full_like
from columnflow.util import maybe_import
Expand Down Expand Up @@ -261,6 +262,10 @@ def default_init(self: Selector) -> None:
# save it as an attribute
setattr(self, prod_name, prod)

if self.dataset_inst.has_tag("ttbar"):
self.uses.add(gen_parton_top)
self.produces.add(gen_parton_top)


empty = default.derive("empty", cls_dict={})

Expand Down

0 comments on commit 6a914e5

Please sign in to comment.