Belle II Software development
caf_ecl_WaveformTemplates.py
1
2
3
10
11"""ECL waveform template calibration"""
12
13from prompt import CalibrationSettings, INPUT_DATA_FILTERS
14
15# --------------------------------------------------------------
16# ..Tell the automated script some required details
17settings = CalibrationSettings(
18 name="ecl_WaveformTemplateShapeCalibration",
19 expert_username="savino.longo",
20 subsystem="ecl",
21 description=__doc__,
22 input_data_formats=["cdst"],
23 input_data_names=["gamma_gamma_calib"],
24 input_data_filters={
25 "gamma_gamma_calib": [
26 INPUT_DATA_FILTERS["Data Tag"]["gamma_gamma_calib"],
27 INPUT_DATA_FILTERS["Data Quality Tag"]["Good Or Recoverable"],
28 INPUT_DATA_FILTERS["Run Type"]["physics"],
29 INPUT_DATA_FILTERS["Magnet"]["On"]]},
30 depends_on=[],
31 expert_config={
32 "C2_MinEnergyThreshold": 2.0,
33 "nFilesCollector": 50,
34 "nParallelAlgos": 1
35 },
36 produced_payloads=["ECLWaveformTemplate"])
37
38
39# --------------------------------------------------------------
40# ..The calibration functions
41
42def get_calibrations(input_data, **kwargs):
43 import basf2
44 from ROOT import Belle2
45 from caf.utils import IoV
46 from caf.framework import Calibration
47
48 # --------------------------------------------------------------
49 # ..gamma gamma
50
51 # ..Input data
52 file_to_iov_gamma_gamma = input_data["gamma_gamma_calib"]
53 input_files = list(file_to_iov_gamma_gamma.keys())
54
55 # ..Algorithm
57
58 expert_config = kwargs.get("expert_config")
59 C2_MinEnergyThreshold = expert_config["C2_MinEnergyThreshold"]
60 nFilesCollector = expert_config["nFilesCollector"]
61
62 # ..The calibration
63 collector_C1 = basf2.register_module("eclWaveformTemplateCalibrationC1Collector")
64 collector_C1.param('MinEnergyThreshold', C2_MinEnergyThreshold)
65
66 cal_ecl_Wave_C1 = Calibration(
67 "ecl_Wave_C1",
68 collector=collector_C1,
69 algorithms=[algo_C1],
70 input_files=input_files,
71 max_files_per_collector_job=nFilesCollector)
72
73 # ..Add prepare_cdst_analysis to pre_collector_path
74 gamma_gamma_pre_path = basf2.create_path()
75 gamma_gamma_pre_path.add_module("RootInput", inputFileNames="", branchNames=["EventMetaData", "RawECLs"])
76 eclunpacker = basf2.register_module('ECLUnpacker')
77 gamma_gamma_pre_path.add_module(eclunpacker)
78
79 cal_ecl_Wave_C1.pre_collector_path = gamma_gamma_pre_path
80
81 calibrations_C2 = []
82 algos_C2 = []
83 algos_C3 = []
84 collectors_C2 = []
85
86 batches = expert_config["nParallelAlgos"]
87 nCrystals = 8736
88 batchsize = int(nCrystals / batches)
89 if (batches * batchsize < nCrystals):
90 batchsize = batchsize + 1
91
92 # keep option to run in parallel
93 for i in range(0, batches):
94
95 lowLimit = (batchsize*i)+1
96
97 highLimit = (batchsize*(i+1))
98
99 if (highLimit > nCrystals):
100 highLimit = nCrystals
101
102 print("lowLimit,highLimit", lowLimit, highLimit)
103
104 # ..Algorithm
106 algos_C2[-1].setFirstCellID(lowLimit)
107 algos_C2[-1].setLastCellID(highLimit)
108
110 algos_C3[-1].setFirstCellID(lowLimit)
111 algos_C3[-1].setLastCellID(highLimit)
112
113 collectors_C2.append(basf2.register_module("eclWaveformTemplateCalibrationC2Collector"))
114 collectors_C2[-1].pre_collector_path = gamma_gamma_pre_path
115 collectors_C2[-1].param('MinCellID', lowLimit)
116 collectors_C2[-1].param('MaxCellID', highLimit)
117 collectors_C2[-1].param('MinEnergyThreshold', C2_MinEnergyThreshold)
118
119 # ..The calibration
120 calibrations_C2.append(Calibration("ecl_Wave_C2_"+str(lowLimit)+"_"+str(highLimit),
121 collector=collectors_C2[-1],
122 algorithms=[algos_C2[-1],
123 algos_C3[-1]],
124 input_files=input_files,
125 max_files_per_collector_job=nFilesCollector))
126 calibrations_C2[-1].pre_collector_path = gamma_gamma_pre_path
127 calibrations_C2[-1].depends_on(cal_ecl_Wave_C1)
128
129 # ..Algorithm
131 algo_C4.setFirstCellID(1)
132 algo_C4.setLastCellID(8736)
133
134 # ..The calibration
135 cal_ecl_Wave_C4 = Calibration("ecl_Wave_C4",
136 collector="DummyCollector",
137 algorithms=[algo_C4],
138 input_files=input_files[:1],
139 )
140
141 cal_ecl_Wave_C4.depends_on(cal_ecl_Wave_C1)
142 for cal in calibrations_C2:
143 cal_ecl_Wave_C4.depends_on(cal)
144
145 # --------------------------------------------------------------
146 # ..Force the output iovs to be open
147 requested_iov = kwargs.get("requested_iov", None)
148 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
149 for algorithm in cal_ecl_Wave_C1.algorithms:
150 algorithm.params = {"apply_iov": output_iov}
151 for C2 in calibrations_C2:
152 for algorithm in C2.algorithms:
153 algorithm.params = {"apply_iov": output_iov}
154 for algorithm in cal_ecl_Wave_C4.algorithms:
155 algorithm.params = {"apply_iov": output_iov}
156
157 # --------------------------------------------------------------
158 # ..Return the calibrations
159 calList = [cal_ecl_Wave_C1] + calibrations_C2 + [cal_ecl_Wave_C4]
160 return calList