23 from caf
import backends
24 from caf.framework
import Calibration, CAF
25 from caf.strategies
import SingleIOV
26 from ROOT.Belle2
import TOP
27 from basf2
import B2ERROR
28 from top_calibration
import BS13d_calibration_local
32 globalTags = [
'data_reprocessing_proc11']
34 data_dir =
'/ghi/fs01/belle2/bdata/group/detector/TOP/2019-*/data_sroot_global/'
35 main_output_dir =
'top_calibration'
37 tts_file =
'/group/belle2/group/detector/TOP/calibration/MCreferences/TTSParametrizations.root'
38 laser_mc_fit =
'/group/belle2/group/detector/TOP/calibration/MCreferences/laserMCFit.root'
39 fit_mode =
'calibration'
46 print(
"usage: basf2", argvs[0],
"experiment run_1 run_2 ... run_n")
48 experiment = int(argvs[1])
49 run_numbers = sorted([int(r)
for r
in argvs[2:]])
50 run_first = run_numbers[0]
51 run_last = run_numbers[-1]
55 expNo =
'e' +
'{:0=4d}'.format(experiment)
56 for run
in run_numbers:
57 expRun =
'{:0=4d}'.format(experiment) +
'.' +
'{:0=5d}'.format(run)
58 filename = f
"{data_dir}/top.{expRun}.*.sroot"
59 inputFiles += glob.glob(filename)
60 if len(inputFiles) == 0:
61 runs =
"".join([str(r) +
"," for r
in run_numbers])[:-1]
62 B2ERROR(f
'No sroot files found in {data_dir} for exp={str(experiment)} runs={runs}')
66 if not os.path.isfile(tts_file):
67 B2ERROR(f
"File {tts_file} not found")
69 if not os.path.isfile(laser_mc_fit):
70 B2ERROR(f
"File {laser_mc_fit} not found")
74 run_range =
'r' +
'{:0=5d}'.format(run_first) +
'-' +
'{:0=5d}'.format(run_last)
75 output_dir = f
"{main_output_dir}/channelT0-local-{expNo}-{run_range}"
81 def channelT0_calibration():
82 ''' calibration of channel T0 with laser data '''
85 main = basf2.create_path()
88 main.add_module(
'SeqRootInput')
89 main.add_module(
'TOPGeometryParInitializer')
90 main.add_module(
'TOPUnpacker')
91 main.add_module(
'TOPRawDigitConverter',
92 useSampleTimeCalibration=
True,
93 useAsicShiftCalibration=
True,
94 useChannelT0Calibration=
False,
95 useModuleT0Calibration=
False,
96 useCommonT0Calibration=
False,
97 calpulseHeightMin=320,
98 calpulseHeightMax=680,
100 calpulseWidthMax=2.2,
101 calibrationChannel=0,
102 lookBackWindows=look_back)
105 collector = basf2.register_module(
'TOPLaserCalibratorCollector')
106 collector.param(
'useReferencePulse',
True)
107 collector.param(
'storeMCTruth',
False)
108 collector.param(
'refChannel', 0)
109 collector.param(
'refSlot', 4)
113 algorithm = TOP.TOPLocalCalFitter()
114 algorithm.setFitMode(fit_mode)
115 algorithm.setTTSFileName(tts_file)
116 algorithm.setFitConstraintsFileName(laser_mc_fit)
119 cal =
Calibration(name=
'TOP_channelT0', collector=collector,
120 algorithms=algorithm, input_files=inputFiles)
121 for globalTag
in reversed(globalTags):
122 cal.use_central_database(globalTag)
123 for localDB
in reversed(localDBs):
124 cal.use_local_database(localDB)
125 cal.pre_collector_path = main
126 cal.max_files_per_collector_job = 1
127 cal.strategies = SingleIOV
132 cal1 = BS13d_calibration_local(inputFiles, look_back, globalTags, localDBs)
133 cal2 = channelT0_calibration()
134 cal1.backend_args = {
"queue":
"l"}
135 cal2.backend_args = {
"queue":
"l"}
136 cal2.depends_on(cal1)
140 cal_fw.add_calibration(cal1)
141 cal_fw.add_calibration(cal2)
142 cal_fw.output_dir = output_dir
143 cal_fw.backend = backends.LSF()