Skip to content

Commit

Permalink
implemented Marcel's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
haddadanas committed Nov 6, 2024
1 parent bf150eb commit 05e9227
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions columnflow/production/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ def normalization_weights(self: Producer, events: ak.Array, **kwargs) -> ak.Arra
attribute. When py:attr`allow_stitching` is set to True, the sum of event weights is computed
for all datasets with a leaf process contained in the leaf processes of the
py:attr:`dataset_inst`. For stitching, the process_id needs to be reconstructed for each leaf
process on a per event basis.
process on a per event basis. Moreover, when stitching is enabled, the an additional normalization
weight is computed for the inclusive dataset only and stored in a column named
py:attr:`weight_name`_inclusive_only. This weight resembles the normalization weight for the
inclusive dataset, as if it were unstitched and should therefore only be applied, when using the
inclusive dataset as a standalone dataset.
"""
# read the process id column
process_id = np.asarray(events.process_id)
Expand All @@ -198,9 +203,9 @@ def normalization_weights(self: Producer, events: ak.Array, **kwargs) -> ak.Arra
events = set_ak_column(events, self.weight_name, norm_weight, value_type=np.float32)

# If we are stitching, we also compute the inclusive weight for debugging purposes
if self.allow_stitching:
if self.allow_stitching and self.dataset_inst == self.get_inclusive_dataset():
incl_norm_weight = events.mc_weight * self.inclusive_weight
events = set_ak_column(events, f"{self.weight_name}_incl", incl_norm_weight, value_type=np.float32)
events = set_ak_column(events, f"{self.weight_name}_inclusive_only", incl_norm_weight, value_type=np.float32)
return events


Expand All @@ -210,11 +215,6 @@ def normalization_weights_requires(self: Producer, reqs: dict) -> None:
Adds the requirements needed by the underlying py:attr:`task` to access selection stats into
*reqs*.
"""
if self.allow_stitching:
self.stitching_datasets = self.get_stitching_datasets()
else:
self.stitching_datasets = [self.dataset_inst]

# check that all datasets are known
for dataset in self.stitching_datasets:
if not self.config_inst.has_dataset(dataset):
Expand Down Expand Up @@ -341,7 +341,12 @@ def normalization_weights_init(self: Producer) -> None:
"""
self.produces.add(self.weight_name)
if self.allow_stitching:
self.produces.add(f"{self.weight_name}_incl")
self.stitching_datasets = self.get_stitching_datasets()
else:
self.stitching_datasets = [self.dataset_inst]

if self.allow_stitching and self.dataset_inst == self.get_inclusive_dataset():
self.produces.add(f"{self.weight_name}_inclusive_only")


stitched_normalization_weights = normalization_weights.derive(
Expand Down

0 comments on commit 05e9227

Please sign in to comment.