80from tracking
import add_tracking_reconstruction
81from rawdata
import add_unpackers
82from caf.strategies
import SequentialRunByRun
83from caf.utils
import CentralDatabase
84from caf.utils
import LocalDatabase
85from caf.utils
import ExpRun, IoV
86from caf.backends
import LSF
87from caf.framework
import Calibration, CAF
89from ROOT.Belle2
import PXDDataMCGainCalibrationAlgorithm
92b2.set_log_level(b2.LogLevel.INFO)
95parser = argparse.ArgumentParser(
96 description=
"Compute gain correction maps for PXD from beam data")
101 help=
'Compute mask for specific IoV')
102parser.add_argument(
'--runHigh', default=-1, type=int,
103 help=
'Compute mask for specific IoV')
108 help=
'Compute mask for specific IoV')
109parser.add_argument(
'--maxSubRuns', default=-1, type=int,
110 help=
'Maximum number of subruns to use')
111parser.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)')
136args = parser.parse_args()
138ROOT.gROOT.SetBatch(
True)
145iov_to_calibrate = IoV(
149 run_high=args.runHigh)
152pxd_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)}')
209charge_collector = b2.register_module(
"PXDClusterChargeCollector")
210charge_collector.param(
"granularity",
"run")
211charge_collector.param(
"minClusterCharge", 8)
212charge_collector.param(
"minClusterSize", 2)
213charge_collector.param(
"maxClusterSize", 6)
214charge_collector.param(
"nBinsU", 4)
215charge_collector.param(
"nBinsV", 6)
217if not args.mcOnly
and not args.dataOnly:
218 charge_collector.param(
220 "PXDMCClusterChargeMapPar")
221charge_collector.param(
"fillChargeHistogram",
True)
222charge_collector.param(
"matchTrack", args.useTrackClusters)
226pre_charge_collector_path = b2.create_path()
227pre_charge_collector_path.add_module(
"Gearbox")
228pre_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")
244for 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)
256datamc_algo = PXDDataMCGainCalibrationAlgorithm()
260datamc_algo.minClusters = 5000
262datamc_algo.noiseSigma = 0.0
264datamc_algo.forceContinue =
False
265datamc_algo.strategy = 0
266if 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
279datamc_algo.useChargeHistogram =
True
281datamc_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"),
297charge_cal.files_to_iovs = files_to_iovs
300charge_cal.strategies = SequentialRunByRun
301charge_cal.max_files_per_collector_job = 1
303charge_cal.algorithms[0].params[
"iov_coverage"] = iov_to_calibrate
304charge_cal.ignored_runs = pxd_ignore_run_list
312cal_fw.add_calibration(charge_cal)
313cal_fw.backend = LSF()
315cal_fw.output_dir = f
'pxd_calibration_results_e{args.expNo}_range_{args.runLow}_{args.runHigh}'
316cal_fw.run(iov=iov_to_calibrate)