Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8e78169
Resolved the conflicts: mostly left local version of the code
hephysicist Feb 3, 2025
d4f96f7
Plotting script with CAT colors
jmalvaso Nov 26, 2024
0ece10d
Normalization, pileup, job submission and other small updates
jmalvaso Nov 26, 2024
c833752
Modification to the legend position and columns
jmalvaso Dec 3, 2024
394805c
Fake factor estimation code: initial commit
hephysicist Dec 10, 2024
2a8894a
Fake factor method, work in progress
hephysicist Jan 20, 2025
c4b6249
Some plotting aestetics
hephysicist Jan 20, 2025
21ab46b
Developed a task to calculate fake factors for WJ and QCD
hephysicist Jan 28, 2025
b9d4b3f
Fake factor method: work in progress
hephysicist Jan 28, 2025
c76efd3
FF method work in progress. Trying to slove problems of framework fre…
hephysicist Feb 3, 2025
9bf8095
Fake Factor method: minimal working version
hephysicist Feb 12, 2025
e2e2ef4
Minor code updates
hephysicist Feb 12, 2025
b3cc09f
Fake_factor method update
hephysicist Feb 14, 2025
766350c
Update on the fake factor method and plotting, jets.py form columnflo…
hephysicist Feb 27, 2025
46c51ee
Updated fake factor method: fixed bugs with chunked io
hephysicist Mar 24, 2025
02429bd
Fixed the long-standing issue with flattening of the arrays at the st…
hephysicist Mar 24, 2025
fdb30eb
Updated framework tasks according to a new approach of storing differ…
hephysicist Mar 24, 2025
000ee8b
Updated code for the Fake Factor calculation
hephysicist Apr 7, 2025
cc6e541
Merge branch 'production' into ff_method_minimal_stable
hephysicist Apr 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,219 changes: 1,104 additions & 1,115 deletions columnflow/calibration/cms/jets.py

Large diffs are not rendered by default.

21 changes: 10 additions & 11 deletions columnflow/calibration/cms/met.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@


@calibrator(
uses={"run", "PV.npvs"},
# name of the MET collection to calibrate
met_name="MET",
uses={"run", "PV.npvs", "PuppiMET.pt", "PuppiMET.phi"},
produces={"PuppiMET.pt", "PuppiMET.phi"},

# function to determine the correction file
get_met_file=(lambda self, external_files: external_files.met_phi_corr),
Expand Down Expand Up @@ -55,17 +54,17 @@ def met_phi(self: Calibrator, events: ak.Array, **kwargs) -> ak.Array:
met = events[self.met_name]

# copy the intial pt and phi values
corr_pt = np.array(events.PuppiMET.pt, dtype=np.float32)
corr_phi = np.array(events.PuppiMET.phi, dtype=np.float32)

corr_pt = np.array(met.pt, dtype=np.float32)
corr_phi = np.array(met.phi, dtype=np.float32)

# select only events where MET pt is below the expected beam energy
mask = met.pt < (0.5 * self.config_inst.campaign.ecm)
# select only events where PuppiMET pt is below the expected beam energy
mask = events.PuppiMET.pt < (0.5 * self.config_inst.campaign.ecm)

# arguments for evaluation
args = (
met.pt[mask],
met.phi[mask],
events.PuppiMET.pt[mask],
events.PuppiMET.phi[mask],
ak.values_astype(events.PV.npvs[mask], np.float32),
ak.values_astype(events.run[mask], np.float32),
)
Expand All @@ -75,8 +74,8 @@ def met_phi(self: Calibrator, events: ak.Array, **kwargs) -> ak.Array:
corr_phi[mask] = self.met_phi_corrector.evaluate(*args)

# save the corrected values
events = set_ak_column(events, f"{self.met_name}.pt", corr_pt, value_type=np.float32)
events = set_ak_column(events, f"{self.met_name}.phi", corr_phi, value_type=np.float32)
events = set_ak_column(events, "PuppiMET.pt", corr_pt, value_type=np.float32)
events = set_ak_column(events, "PuppiMET.phi", corr_phi, value_type=np.float32)


return events
Expand Down
23 changes: 11 additions & 12 deletions columnflow/columnar_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import math
import time
import enum

import inspect
import threading
import multiprocessing
Expand All @@ -40,6 +41,7 @@
maybe_import("coffea.nanoevents.methods.base")
maybe_import("coffea.nanoevents.methods.nanoaod")
pq = maybe_import("pyarrow.parquet")
hist = maybe_import("hist")


# loggers
Expand Down Expand Up @@ -1405,18 +1407,15 @@ def allows_shift(ax) -> bool:
data[ax.name] = ak.copy(data[ax.name])
flat_np_view(data[ax.name])[right_egde_mask] -= ax.widths[-1] * 1e-5

print("CreateHistograms /afs/cern.ch/user/j/jmalvaso/CPinHToTauTau/modules/columnflow/columnflow/columnar_util.py needs to be fixed")
print("Comment until else to run plotvariables")
#fill
# if 'event' in data.keys():
# arrays = {}
# for ax_name in axis_names:
# if ax_name in data.keys():
# arrays[ax_name] = data[ax_name]
# h.fill(**fill_kwargs, **arrays)
# else:
arrays = ak.flatten(ak.cartesian(data))
h.fill(**fill_kwargs, **{field: arrays[field] for field in arrays.fields})
if 'event' in data.keys():
arrays = {}
for ax_name in axis_names:
if ax_name in data.keys():
arrays[ax_name] = data[ax_name]
h.fill(**fill_kwargs, **arrays)
else:
arrays = ak.flatten(ak.cartesian(data))
h.fill(**fill_kwargs, **{field: arrays[field] for field in arrays.fields})



Expand Down
8 changes: 6 additions & 2 deletions columnflow/hist_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ def allows_shift(ax) -> bool:
flat_np_view(data[ax.name])[right_egde_mask] -= ax.widths[-1] * 1e-5

# fill
arrays = ak.flatten(ak.cartesian(data))
h.fill(**fill_kwargs, **{field: arrays[field] for field in arrays.fields})
flat_data = {}
for key, arr in data.items():
if arr.ndim != 1: flat_data[key] = ak.flatten(arr)
else: flat_data[key] = arr
h.fill(**fill_kwargs, **flat_data)



def add_hist_axis(histogram: hist.Hist, variable_inst: od.Variable) -> hist.Hist:
Expand Down
3 changes: 2 additions & 1 deletion columnflow/plotting/plot_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ def plot_all(
legend_kwargs = {
"ncol": 2,
"loc": "center left",
"bbox_to_anchor": (0.25, 0.8), # Position the legend outside the plot

"bbox_to_anchor": (0.35, 0.8), # Position the legend outside the plot
# Moves the legend to the right side of the plot.
# The first value (1) controls the horizontal position,
# and the second value (0.95) controls the vertical position.
Expand Down
4 changes: 2 additions & 2 deletions columnflow/plotting/plot_functions_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def plot_variable_per_process(
and the process with the second highest number of events last.
Handles cases with only one or two processes.
"""

remove_residual_axis(hists, "shift")
# Define the color maps
color_maps = {
Expand Down Expand Up @@ -94,7 +95,6 @@ def plot_variable_per_process(
custom_order = sorted_keys
# Reorder histograms based on custom order
sorted_hists = OrderedDict((key, sorted_hists_desc[key]) for key in custom_order)

variable_inst = variable_insts[0]
sorted_hists = apply_variable_settings(sorted_hists, variable_insts, variable_settings)
sorted_hists = apply_process_settings(sorted_hists, process_settings)
Expand Down Expand Up @@ -276,7 +276,7 @@ def plot_shifted_variable(
default_style_config = prepare_style_config(
config_inst, category_inst, variable_inst, density, shape_norm, yscale,
)
default_style_config["rax_cfg"]["ylim"] = (0.25, 1.75)
default_style_config["rax_cfg"]["ylim"] = (0.75, 1.25)
default_style_config["rax_cfg"]["ylabel"] = "Ratio"
default_style_config["legend_cfg"]["title"] = legend_title

Expand Down
11 changes: 6 additions & 5 deletions columnflow/production/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,21 +339,20 @@ def normalization_weights_setup(
)

for process_id, br in branching_ratios.items():

#sum_weights = merged_selection_stats["sum_mc_weight_per_process"][str(process_id)]
sum_weights = self.dataset_inst.n_events
process_weight_table[0, process_id] = lumi * inclusive_xsec * br / sum_weights

else:
# fill the process weight table with per-process cross sections
for process_inst in process_insts:
if self.config_inst.campaign.ecm not in process_inst.xsecs.keys():

continue
raise KeyError(
f"no cross section registered for process {process_inst} for center-of-mass "
f"energy of {self.config_inst.campaign.ecm}",
)
#sum_weights = merged_selection_stats["sum_mc_weight_per_process"][str(process_inst.id)]
#quick fix that need to be fixed
################################
#n_evt_per_file = /self.dataset_inst.n_files
sum_weights = self.dataset_inst.n_events
################################
xsec = process_inst.get_xsec(self.config_inst.campaign.ecm).nominal
Expand Down Expand Up @@ -402,3 +401,5 @@ def normalization_weights_init(self: Producer) -> None:
"get_xsecs_from_inclusive_dataset": False,
},
)


2 changes: 1 addition & 1 deletion columnflow/selection/cms/jets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@selector(
uses={
"Jet.{pt,eta,phi,mass,jetId,chEmEF}", optional("Jet.puId"),
"Jet.{pt,eta,phi,mass,jetId,chEmEF}",
"Muon.{pt,eta,phi,mass,isPFcand}",
},
produces={"Jet.veto_map_mask"},
Expand Down
Loading