17 from caf
import backends
18 from caf.framework
import Calibration, CAF
19 from caf.strategies
import SequentialRunByRun, SingleIOV, SimpleRunByRun
20 from ROOT
import Belle2
21 from ROOT.Belle2
import TOP
22 from basf2
import B2ERROR
23 from top_calibration
import BS13d_calibration_local
27 globalTags = [
'Reco_master_patch',
'data_reprocessing_proc10']
29 data_dir =
'/ghi/fs01/belle2/bdata/group/detector/TOP/2019-*/data_sroot_global/'
30 main_output_dir =
'top_calibration'
32 tts_file =
'/group/belle2/group/detector/TOP/calibration/MCreferences/TTSParametrizations.root'
33 laser_mc_fit =
'/group/belle2/group/detector/TOP/calibration/MCreferences/laserMCFit.root'
34 fit_mode =
'calibration'
41 print(
"usage: basf2", argvs[0],
"experiment run_1 run_2 ... run_n")
43 experiment = int(argvs[1])
44 run_numbers = sorted([int(r)
for r
in argvs[2:]])
45 run_first = run_numbers[0]
46 run_last = run_numbers[-1]
50 expNo =
'e' +
'{:0=4d}'.format(experiment)
51 for run
in run_numbers:
52 expRun =
'{:0=4d}'.format(experiment) +
'.' +
'{:0=5d}'.format(run)
53 filename = f
"{data_dir}/top.{expRun}.*.sroot"
54 inputFiles += glob.glob(filename)
55 if len(inputFiles) == 0:
56 runs =
"".join([str(r) +
"," for r
in run_numbers])[:-1]
57 B2ERROR(f
'No sroot files found in {data_dir} for exp={str(experiment)} runs={runs}')
61 if not os.path.isfile(tts_file):
62 B2ERROR(f
"File {tts_file} not found")
64 if not os.path.isfile(laser_mc_fit):
65 B2ERROR(f
"File {laser_mc_fit} not found")
69 run_range =
'r' +
'{:0=5d}'.format(run_first) +
'-' +
'{:0=5d}'.format(run_last)
70 output_dir = f
"{main_output_dir}/channelT0-local-{expNo}-{run_range}"
76 def channelT0_calibration():
77 ''' calibration of channel T0 with laser data '''
80 main = basf2.create_path()
83 main.add_module(
'SeqRootInput')
84 main.add_module(
'TOPGeometryParInitializer')
85 main.add_module(
'TOPUnpacker')
86 main.add_module(
'TOPRawDigitConverter',
87 useSampleTimeCalibration=
True,
88 useAsicShiftCalibration=
True,
89 useChannelT0Calibration=
False,
90 useModuleT0Calibration=
False,
91 useCommonT0Calibration=
False,
92 calpulseHeightMin=320,
93 calpulseHeightMax=680,
97 lookBackWindows=look_back)
100 collector = basf2.register_module(
'TOPLaserCalibratorCollector')
101 collector.param(
'useReferencePulse',
True)
102 collector.param(
'storeMCTruth',
False)
103 collector.param(
'refChannel', 0)
104 collector.param(
'refSlot', 4)
108 algorithm = TOP.TOPLocalCalFitter()
109 algorithm.setFitMode(fit_mode)
110 algorithm.setTTSFileName(tts_file)
111 algorithm.setFitConstraintsFileName(laser_mc_fit)
114 cal =
Calibration(name=
'TOP_channelT0', collector=collector,
115 algorithms=algorithm, input_files=inputFiles)
116 for globalTag
in reversed(globalTags):
117 cal.use_central_database(globalTag)
118 for localDB
in reversed(localDBs):
119 cal.use_local_database(localDB)
120 cal.pre_collector_path = main
121 cal.max_files_per_collector_job = 1
122 cal.strategies = SingleIOV
127 cal1 = BS13d_calibration_local(inputFiles, look_back, globalTags, localDBs)
128 cal2 = channelT0_calibration()
129 cal1.backend_args = {
"queue":
"l"}
130 cal2.backend_args = {
"queue":
"l"}
131 cal2.depends_on(cal1)
135 cal_fw.add_calibration(cal1)
136 cal_fw.add_calibration(cal2)
137 cal_fw.output_dir = output_dir