9def load_voltage_steps(run_number, voltage_values, voltage_strings, file_path="/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/ZdcConditions/INJpulser_combined_2024.json"):
10 """Reads a JSON file, determines the correct voltage step configuration for a given run number,
11 and fills two lists:
12 - voltage_values: List of raw float values after applying ScaleFactor.
13 - voltage_strings: List of string representations rounded to 5 decimal places in "X.XXXXX" format.
14
15 Args:
16 run_number (int): The run number to find the voltage steps for.
17 voltage_values (list): A list that will be filled with the raw scaled voltage steps as floats.
18 voltage_strings (list): A list that will be filled with the formatted voltage steps as strings.
19 file_path (str): The path to the JSON file. Defaults to the provided path.
20 """
21
22 if not os.path.exists(file_path):
23 print(f
"Error: File not found at {file_path}")
24 return
25
26
27 with open(file_path, "r") as file:
28 data = json.load(file)
29
30
31 steps_config_name = None
32 scale_factor = None
33
34 for run_range in data["RunRanges"]:
35 if run_range["First"] <= run_number < run_range["Last"]:
36 steps_config_name = run_range["StepsConfig"]
37 scale_factor = run_range["ScaleFactor"]
38 break
39
40 if not steps_config_name or scale_factor is None:
41 print(f
"Warning: No voltage step configuration found for run number {run_number}.")
42 return
43
44
45 step_config = data[
"StepConfigurations"].
get(steps_config_name)
46 if not step_config:
47 print(f
"Error: Step configuration '{steps_config_name}' not found in the JSON file.")
48 return
49
50
51 voltage_values.clear()
52 voltage_strings.clear()
53
54
55 for step in step_config:
56 if "nStep" in step and "vStart" in step and "vStep" in step:
57 n_steps = step["nStep"]
58 v_start = step["vStart"]
59 v_step = step["vStep"]
60
61 for i in range(n_steps):
62 voltage = (v_start + i * v_step) * scale_factor
63 voltage_values.append(voltage)
64
65 voltage_strings.append(f"{int(voltage*1000000):d}muV")
66
void print(char *figname, TCanvas *c1)
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)