Skip to content

Commit 860bd49

Browse files
committed
Feat: update cutculator
1 parent 86b3abe commit 860bd49

File tree

1 file changed

+46
-23
lines changed

1 file changed

+46
-23
lines changed

PWGCF/Femto/Macros/cutculator.py

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env python3
22

3-
#!/usr/bin/env python3
4-
53
# Copyright 2019-2025 CERN and copyright holders of ALICE O2.
64
# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
75
# All rights not expressly granted are reserved.
@@ -38,34 +36,47 @@ def parse_bin_label(label):
3836

3937

4038
def ask_user_selection(group):
41-
"""Prompt user to select bin(s) for this selection group."""
39+
"""
40+
Prompt user to select bin(s) for this selection group.
41+
- If minimal selections contain exactly 1 entry → auto-select it.
42+
- Optional selections remain user-selectable.
43+
"""
44+
selection_name = group[0].get("SelectionName", "unknown")
45+
4246
# Separate minimal and optional bins
4347
minimal_bins = [b for b in group if b.get("MinimalCut", "0") == "1" and b.get("OptionalCut", "0") == "0"]
4448
optional_bins = [b for b in group if b.get("OptionalCut", "0") == "1"]
4549

4650
selected_bins = []
4751

48-
# Minimal selection (cannot skip, 0 = loosest minimal)
52+
# Minimal selection
4953
if minimal_bins:
50-
print(f"\nSelection: {group[0].get('SelectionName', 'unknown')}")
51-
for idx, b in enumerate(minimal_bins):
52-
print(f" [{idx}] {b.get('Value', '')}")
53-
while True:
54-
sel_input = input("Enter index for minimal cut (0 = loosest minimal): ")
55-
if sel_input.strip() == "":
56-
sel_input = "0"
57-
try:
58-
sel_idx = int(sel_input)
59-
if 0 <= sel_idx < len(minimal_bins):
60-
selected_bins.append(minimal_bins[sel_idx])
61-
break
62-
except ValueError:
63-
pass
64-
print("Invalid input. Please enter a valid index.")
54+
if len(minimal_bins) == 1:
55+
# autoselect minimal OPTION
56+
only = minimal_bins[0]
57+
print(f"\nSelection: {selection_name} — only one minimal option → auto-selecting: {only.get('Value','')}")
58+
selected_bins.append(only)
59+
else:
60+
# Multiple → ask user
61+
print(f"\nSelection: {selection_name}")
62+
for idx, b in enumerate(minimal_bins):
63+
print(f" [{idx}] {b.get('Value', '')}")
64+
while True:
65+
sel_input = input("Enter index for minimal cut (0 = loosest minimal): ")
66+
if sel_input.strip() == "":
67+
sel_input = "0"
68+
try:
69+
sel_idx = int(sel_input)
70+
if 0 <= sel_idx < len(minimal_bins):
71+
selected_bins.append(minimal_bins[sel_idx])
72+
break
73+
except ValueError:
74+
pass
75+
print("Invalid input. Please enter a valid index.")
6576

6677
# Optional selection (can skip with 0)
6778
if optional_bins:
68-
print(f"Selection: {group[0].get('SelectionName', 'unknown')} (optional selection, 0 to skip)")
79+
print(f"Selection: {selection_name} (optional selection, 0 to skip)")
6980
for idx, b in enumerate(optional_bins, start=1):
7081
print(f" [{idx}] {b.get('Value', '')}")
7182
while True:
@@ -145,10 +156,22 @@ def main(rootfile_path, tdir_path="femto-producer"):
145156
continue
146157
bitmask |= 1 << int(pos)
147158

159+
print("\n=======================================")
160+
print("Summary of your selections:")
161+
print("=======================================\n")
162+
163+
summary = {}
164+
for b in selected_bins:
165+
sel = b.get("SelectionName", "unknown")
166+
summary.setdefault(sel, []).append(b.get("Value", ""))
167+
168+
for sel, values in summary.items():
169+
print(f" {sel}: {', '.join(values)}")
170+
148171
print("\nFinal selected bitmask:")
149-
print(f"Decimal: {bitmask}")
150-
print(f"Binary: {bin(bitmask)}")
151-
print(f"Hex: {hex(bitmask)}")
172+
print(f" Decimal: {bitmask}")
173+
print(f" Binary: {bin(bitmask)}")
174+
print(f" Hex: {hex(bitmask)}")
152175

153176

154177
if __name__ == "__main__":

0 commit comments

Comments
 (0)