80 from tracking
import add_tracking_reconstruction
81 from rawdata
import add_unpackers
82 from caf.strategies
import SequentialRunByRun
83 from caf.utils
import CentralDatabase
84 from caf.utils
import LocalDatabase
85 from caf.utils
import ExpRun, IoV
86 from caf.backends
import LSF
87 from caf.framework
import Calibration, CAF
88 from ROOT.Belle2
import PXDDataMCGainCalibrationAlgorithm
92 b2.set_log_level(b2.LogLevel.INFO)
95 parser = argparse.ArgumentParser(
96 description=
"Compute gain correction maps for PXD from beam data")
101 help=
'Compute mask for specific IoV')
102 parser.add_argument(
'--runHigh', default=-1, type=int,
103 help=
'Compute mask for specific IoV')
108 help=
'Compute mask for specific IoV')
109 parser.add_argument(
'--maxSubRuns', default=-1, type=int,
110 help=
'Maximum number of subruns to use')
111 parser.add_argument(
'--localDB', default=
"", type=str,
112 help=
'path to local DB database.txt')
115 default=
"DefaultFromKEKCC",
117 help=
'Full paths to list of runs to ignore, separate multiple by a comma , ')
122 help=
'Run charge calibration for MC only, otherwise specify --dataOnly \
123 or run the full gain calibration on data using MC charge from DB')
128 help=
'Run charge calibration for Data only, otherwise specify --mcOnly \
129 or run the full gain calibration on data using MC charge from DB')
131 '--useTrackClusters',
134 help=
'Flag to use track matched clusters (=1) and apply theta angle projection to cluster charge (=2)')
136 args = parser.parse_args()
138 ROOT.gROOT.SetBatch(
True)
145 iov_to_calibrate = IoV(
149 run_high=args.runHigh)
152 pxd_ignore_run_list = []
156 with open(
"mc_file_iov_map.pkl",
'br')
as map_file:
157 files_to_iovs = pickle.load(map_file)
158 input_files = list(files_to_iovs.keys())
159 print(f
'Number selected mc input files: {len(input_files)}')
164 pxd_ignore_run_list = [ExpRun(3, 484), ExpRun(3, 485), ExpRun(3, 486), ExpRun(3, 524),
173 ignoreRuns = args.ignoreRuns
174 if "DefaultFromKEKCC" in ignoreRuns:
175 dirkekcc = f
"/hsm/belle2/bdata/Data/Raw/e000{args.expNo}/"
176 ignoreRuns = dirkekcc +
"RunListBeam," + dirkekcc +
"RunListCosmic"
178 for flist
in ignoreRuns.split(
","):
179 fignore = open(flist)
180 line = fignore.readline()
182 run = line[0:line.find(
',')]
183 pxd_ignore_run_list.append(ExpRun(args.expNo, int(run)))
184 line = fignore.readline()
187 print(
'List of ignored runs')
188 print(pxd_ignore_run_list)
191 with open(
"file_iov_map.pkl",
'br')
as map_file:
192 files_to_iovs = pickle.load(map_file)
194 input_file_iov_set = set(files_to_iovs.values())
195 for file_iov
in input_file_iov_set:
196 if iov_to_calibrate.contains(file_iov):
197 subruns = [k
for k, v
in files_to_iovs.items()
if v == file_iov]
198 input_files.extend(subruns[:args.maxSubRuns])
200 print(f
'Number selected data input files: {len(input_files)}')
209 charge_collector = b2.register_module(
"PXDClusterChargeCollector")
210 charge_collector.param(
"granularity",
"run")
211 charge_collector.param(
"minClusterCharge", 8)
212 charge_collector.param(
"minClusterSize", 2)
213 charge_collector.param(
"maxClusterSize", 6)
214 charge_collector.param(
"nBinsU", 4)
215 charge_collector.param(
"nBinsV", 6)
217 if not args.mcOnly
and not args.dataOnly:
218 charge_collector.param(
220 "PXDMCClusterChargeMapPar")
221 charge_collector.param(
"fillChargeHistogram",
True)
222 charge_collector.param(
"matchTrack", args.useTrackClusters)
226 pre_charge_collector_path = b2.create_path()
227 pre_charge_collector_path.add_module(
"Gearbox")
228 pre_charge_collector_path.add_module(
"Geometry")
231 pre_charge_collector_path.add_module(
"PXDDigitizer")
232 if args.useTrackClusters:
233 add_tracking_reconstruction(pre_charge_collector_path)
235 pre_charge_collector_path.add_module(
"PXDClusterizer")
237 if args.useTrackClusters:
238 add_unpackers(pre_charge_collector_path, [
'PXD',
'SVD',
'CDC'])
239 add_tracking_reconstruction(pre_charge_collector_path)
241 add_unpackers(pre_charge_collector_path, [
'PXD'])
242 pre_charge_collector_path.add_module(
"PXDClusterizer")
244 for module
in pre_charge_collector_path.modules():
245 if module.name() ==
'Geeometry':
246 module.param(
'excludedComponents', [
'ECL',
'KLM',
'TOP'])
247 if module.name() ==
'PXDUnpacker':
248 module.param(
'SuppressErrorMask', 0xffffffff)
249 if module.name() ==
'PXDPostErrorChecker':
250 module.param(
'CriticalErrorMask', 0)
256 datamc_algo = PXDDataMCGainCalibrationAlgorithm()
260 datamc_algo.minClusters = 5000
262 datamc_algo.noiseSigma = 0.0
264 datamc_algo.forceContinue =
False
265 datamc_algo.strategy = 0
266 if args.mcOnly
or args.dataOnly:
268 datamc_algo.doCalibration =
False
271 datamc_algo.chargePayloadName =
"PXDMCClusterChargeMapPar"
274 datamc_algo.chargePayloadName =
"PXDClusterChargeMapPar"
277 datamc_algo.doCalibration =
True
279 datamc_algo.useChargeHistogram =
True
281 datamc_algo.setPrefix(
"PXDClusterChargeCollector")
285 name=
"PXDDataMCGainCalibrationAlgorithm",
286 collector=charge_collector,
287 algorithms=datamc_algo,
288 input_files=input_files,
289 pre_collector_path=pre_charge_collector_path,
291 CentralDatabase(
"data_reprocessing_prompt"),
292 CentralDatabase(
"pxd_calibration"),
297 charge_cal.files_to_iovs = files_to_iovs
300 charge_cal.strategies = SequentialRunByRun
301 charge_cal.max_files_per_collector_job = 1
303 charge_cal.algorithms[0].params[
"iov_coverage"] = iov_to_calibrate
304 charge_cal.ignored_runs = pxd_ignore_run_list
312 cal_fw.add_calibration(charge_cal)
313 cal_fw.backend = LSF()
315 cal_fw.output_dir = f
'pxd_calibration_results_e{args.expNo}_range_{args.runLow}_{args.runHigh}'
316 cal_fw.run(iov=iov_to_calibrate)