Skip to content

Commit 0c78a63

Browse files
committed
Feat: update cutculator
1 parent da2c876 commit 0c78a63

2 files changed

Lines changed: 359 additions & 115 deletions

File tree

PWGCF/Femto/Macros/cutculator.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ def parse_bin_label(label):
3535
return result
3636

3737

38+
def is_filter_histogram(bins):
39+
"""
40+
Determine whether the parsed bins belong to a filter histogram (fixed,
41+
non-selectable pre-filter values) rather than a selection/bitmask histogram.
42+
Filter bins carry a "FilterName" key; selection bins carry "SelectionName".
43+
"""
44+
for b in bins:
45+
if "FilterName" in b:
46+
return True
47+
if "SelectionName" in b:
48+
return False
49+
# no parseable bins at all; treat as selection histogram (existing behavior)
50+
return False
51+
52+
3853
def format_value_with_comment(b):
3954
"""Return Value plus optional (comment=...) suffix."""
4055
val = b.get("Value", "")
@@ -44,6 +59,20 @@ def format_value_with_comment(b):
4459
return val
4560

4661

62+
def print_filter_values(bins):
63+
"""
64+
Filters are fixed values already applied when the producer ran — there is
65+
nothing to select. Just print each filter's name and value.
66+
"""
67+
print("\n=======================================")
68+
print("Filter values used in this histogram:")
69+
print("=======================================\n")
70+
for b in bins:
71+
name = b.get("FilterName", "unknown")
72+
value = b.get("FilterValue", "")
73+
print(f" {name}: {value}")
74+
75+
4776
def ask_user_selection(group):
4877
"""
4978
Prompt user to select bin(s) for this selection group.
@@ -188,7 +217,8 @@ def main(rootfile_path, tdir_path="femto-producer"):
188217
print(f"\nUsing histogram: {hname}")
189218
print(f"Histogram contains {nbins} bins.\n")
190219

191-
# parse all bins, ignoring the last 2 special bins
220+
# parse all bins, ignoring the last 2 special bins ("All analyzed"/"All passed",
221+
# present on both selection and filter histograms)
192222
bins = []
193223
for i in range(1, nbins - 2 + 1):
194224
label = hist.GetXaxis().GetBinLabel(i)
@@ -198,6 +228,16 @@ def main(rootfile_path, tdir_path="femto-producer"):
198228
bdict["_bin_index"] = i
199229
bins.append(bdict)
200230

231+
if not bins:
232+
print("No parseable bins found in this histogram.")
233+
return
234+
235+
# filter histograms carry fixed, already-applied values — nothing to select,
236+
# so just print them and skip the interactive/bitmask machinery entirely
237+
if is_filter_histogram(bins):
238+
print_filter_values(bins)
239+
return
240+
201241
# group by SelectionName
202242
groups = {}
203243
for b in bins:

0 commit comments

Comments
 (0)