48 from caf.strategies
import SequentialRunByRun
49 from caf.utils
import ExpRun, IoV
50 from caf.backends
import LSF
51 from caf.framework
import Calibration, CAF
52 from ROOT.Belle2
import PXDHotPixelMaskCalibrationAlgorithm
53 from ROOT.Belle2
import PXDChargeCalibrationAlgorithm
54 from ROOT.Belle2
import PXDGainCalibrationAlgorithm
58 b2.set_log_level(b2.LogLevel.INFO)
60 ROOT.gROOT.SetBatch(
True)
63 parser = argparse.ArgumentParser(
64 description=
"Compute gain correction maps for PXD from beam data")
69 help=
'Compute mask for specific IoV')
70 parser.add_argument(
'--runHigh', default=-1, type=int,
71 help=
'Compute mask for specific IoV')
76 help=
'Compute mask for specific IoV')
77 parser.add_argument(
'--maxSubRuns', default=20, type=int,
78 help=
'Maximum number of subruns to use')
79 args = parser.parse_args()
83 pxd_ignore_run_list = [ExpRun(3, 484), ExpRun(3, 485), ExpRun(3, 486), ExpRun(3, 524)]
86 iov_to_calibrate = IoV(
90 run_high=args.runHigh)
94 with open(
"file_iov_map.pkl",
'br')
as map_file:
95 files_to_iovs = pickle.load(map_file)
100 input_file_iov_set = set(files_to_iovs.values())
101 for file_iov
in input_file_iov_set:
102 if iov_to_calibrate.contains(file_iov):
103 subruns = [k
for k, v
in files_to_iovs.items()
if v == file_iov]
104 input_files.extend(subruns[:args.maxSubRuns])
106 print(f
'Number selected input files: {len(input_files)}')
110 with open(
"mc_file_iov_map.pkl",
'br')
as map_file:
111 mc_files_to_iovs = pickle.load(map_file)
113 mc_input_files = list(mc_files_to_iovs.keys())
116 print(f
'Number selected mc input files: {len(mc_input_files)}')
122 hotpixel_collector = b2.register_module(
"PXDRawHotPixelMaskCollector")
123 hotpixel_collector.param(
"granularity",
"run")
126 pre_hotpixel_collector_path = b2.create_path()
127 pre_hotpixel_collector_path.add_module(
128 "Gearbox", fileName=
'geometry/Beast2_phase2.xml')
129 pre_hotpixel_collector_path.add_module(
"Geometry", useDB=
False)
130 pre_hotpixel_collector_path.add_module(
'PXDUnpacker')
131 pre_hotpixel_collector_path.add_module(
'PXDPostErrorChecker')
132 pre_hotpixel_collector_path.add_module(
'Progress')
134 hotpixel_algo = PXDHotPixelMaskCalibrationAlgorithm()
138 hotpixel_algo.forceContinueMasking =
False
140 hotpixel_algo.minEvents = 10000
143 hotpixel_algo.minHits = 15
145 hotpixel_algo.pixelMultiplier = 7
147 hotpixel_algo.maskDrains =
True
149 hotpixel_algo.drainMultiplier = 7
151 hotpixel_algo.maskRows =
True
153 hotpixel_algo.rowMultiplier = 7
156 hotpixel_algo.setPrefix(
"PXDRawHotPixelMaskCollector")
160 name=
"PXDHotPixelMaskCalibrationAlgorithm",
161 collector=hotpixel_collector,
162 algorithms=hotpixel_algo,
163 input_files=input_files)
164 hotpixel_cal.pre_collector_path = pre_hotpixel_collector_path
167 hotpixel_cal.files_to_iovs = files_to_iovs
170 hotpixel_cal.strategies = SequentialRunByRun
171 hotpixel_cal.max_files_per_collector_job = 1
172 hotpixel_cal.use_central_database(
"Calibration_Offline_Development")
174 hotpixel_cal.ignored_runs = pxd_ignore_run_list
175 hotpixel_cal.algorithms[0].params[
"iov_coverage"] = iov_to_calibrate
182 charge_collector = b2.register_module(
"PXDClusterChargeCollector")
183 charge_collector.param(
"granularity",
"run")
184 charge_collector.param(
"minClusterCharge", 8)
185 charge_collector.param(
"minClusterSize", 2)
186 charge_collector.param(
"maxClusterSize", 6)
187 charge_collector.param(
"nBinsU", 4)
188 charge_collector.param(
"nBinsV", 6)
192 pre_charge_collector_path = b2.create_path()
193 pre_charge_collector_path.add_module(
194 "Gearbox", fileName=
'geometry/Beast2_phase2.xml')
195 pre_charge_collector_path.add_module(
"Geometry", useDB=
False)
196 pre_charge_collector_path.add_module(
"ActivatePXDPixelMasker")
197 pre_charge_collector_path.add_module(
"PXDUnpacker")
198 pre_charge_collector_path.add_module(
'PXDPostErrorChecker')
199 pre_charge_collector_path.add_module(
"PXDRawHitSorter")
200 pre_charge_collector_path.add_module(
"PXDClusterizer")
203 landau_algo = PXDChargeCalibrationAlgorithm()
207 landau_algo.minClusters = 5000
209 landau_algo.noiseSigma = 0.6
211 landau_algo.forceContinue =
False
212 landau_algo.strategy = 1
214 landau_algo.setPrefix(
"PXDClusterChargeCollector")
218 name=
"PXDChargeCalibrationAlgorithm",
219 collector=charge_collector,
220 algorithms=landau_algo,
221 input_files=input_files)
223 charge_cal.pre_collector_path = pre_charge_collector_path
226 charge_cal.files_to_iovs = files_to_iovs
229 charge_cal.strategies = SequentialRunByRun
230 charge_cal.max_files_per_collector_job = 1
232 charge_cal.algorithms[0].params[
"iov_coverage"] = iov_to_calibrate
233 charge_cal.ignored_runs = pxd_ignore_run_list
235 charge_cal.use_central_database(
"Calibration_Offline_Development")
240 gain_collector = b2.register_module(
"PXDClusterChargeCollector")
241 gain_collector.param(
"granularity",
"run")
242 gain_collector.param(
"minClusterCharge", 8)
243 gain_collector.param(
"minClusterSize", 2)
244 gain_collector.param(
"maxClusterSize", 6)
245 gain_collector.param(
"nBinsU", 4)
246 gain_collector.param(
"nBinsV", 6)
249 pre_gain_collector_path = b2.create_path()
250 pre_gain_collector_path.add_module(
251 "Gearbox", fileName=
'geometry/Beast2_phase2.xml')
252 pre_gain_collector_path.add_module(
"Geometry", useDB=
False)
253 pre_gain_collector_path.add_module(
"PXDDigitizer")
254 pre_gain_collector_path.add_module(
"PXDClusterizer")
258 gain_algo = PXDGainCalibrationAlgorithm()
262 gain_algo.minClusters = 3000
264 gain_algo.noiseSigma = 0.6
266 gain_algo.forceContinue =
False
267 gain_algo.strategy = 1
269 gain_algo.setPrefix(
"PXDClusterChargeCollector")
273 name=
"PXDGainCalibrationAlgorithm",
274 collector=gain_collector,
275 algorithms=gain_algo,
276 input_files=mc_input_files)
278 gain_cal.pre_collector_path = pre_gain_collector_path
281 gain_cal.files_to_iovs = mc_files_to_iovs
284 gain_cal.strategies = SequentialRunByRun
285 gain_cal.max_files_per_collector_job = 1
287 gain_cal.algorithms[0].params[
"iov_coverage"] = iov_to_calibrate
288 gain_cal.ignored_runs = pxd_ignore_run_list
290 gain_cal.use_central_database(
"Calibration_Offline_Development")
296 charge_cal.depends_on(hotpixel_cal)
297 gain_cal.depends_on(charge_cal)
301 cal_fw.add_calibration(hotpixel_cal)
302 cal_fw.add_calibration(charge_cal)
303 cal_fw.add_calibration(gain_cal)
305 cal_fw.backend = LSF()
306 cal_fw.output_dir = f
'pxd_calibration_results_range_{args.runLow}_{args.runHigh}_{args.expNo}'
307 cal_fw.run(iov=iov_to_calibrate)