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