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