3 """CDC tracking calibration. Performs the T0 determination using HLT skimmed raw data."""
5 from prompt
import CalibrationSettings, input_data_filters
8 from random
import choice
9 from caf.framework
import Calibration
10 from caf
import strategies
14 settings = CalibrationSettings(name=
"CDC Tracking",
15 expert_username=
"eberthol",
17 input_data_formats=[
"raw"],
18 input_data_names=[
"mumutight_calib",
"hadron_calib",
"cosmic_calib"],
19 input_data_filters={
"mumutight_calib": [input_data_filters[
"Data Tag"][
"mumutight_calib"],
20 input_data_filters[
"Data Quality Tag"][
"Good"],
21 input_data_filters[
"Magnet"][
"On"]],
22 "hadron_calib": [input_data_filters[
"Data Tag"][
"hadron_calib"],
23 input_data_filters[
"Data Quality Tag"][
"Good"],
24 input_data_filters[
"Magnet"][
"On"]],
25 "cosmic_calib": [input_data_filters[
"Data Tag"][
"cosmic_calib"],
26 input_data_filters[
"Data Quality Tag"][
"Good"],
27 input_data_filters[
"Magnet"][
"On"]]},
30 "max_files_per_run": 100000,
31 "min_events_per_file": 1,
32 "max_events_per_calibration": 200000,
33 "max_events_per_calibration_for_xt_sr": 1000000,
34 "max_events_per_file": 5000,
35 "max_events_per_file_hadron": 2500,
36 "payload_boundaries": [],
41 def select_files(all_input_files, min_events, max_processed_events_per_file):
42 basf2.B2INFO(
"Attempting to choose a good subset of files")
46 while total_events < min_events:
49 if not all_input_files:
52 new_file_choice = choice(all_input_files)
54 all_input_files.remove(new_file_choice)
56 total_events_in_file = events_in_basf2_file(new_file_choice)
57 if not total_events_in_file:
60 events_contributed = 0
61 if total_events_in_file < max_processed_events_per_file:
63 events_contributed = total_events_in_file
65 events_contributed = max_processed_events_per_file
66 chosen_files.append(new_file_choice)
67 total_events += events_contributed
69 basf2.B2INFO(f
"Total chosen files = {len(chosen_files)}")
70 basf2.B2INFO(f
"Total events in chosen files = {total_events}")
71 if total_events < min_events:
73 f
"There weren't enough files events selected when max_processed_events_per_file={max_processed_events_per_file}")
82 def get_calibrations(input_data, **kwargs):
86 file_to_iov_mumu = input_data[
"mumutight_calib"]
87 file_to_iov_hadron = input_data[
"hadron_calib"]
88 file_to_iov_Bcosmics = input_data[
"cosmic_calib"]
91 expert_config = kwargs.get(
"expert_config")
92 max_files_per_run = expert_config[
"max_files_per_run"]
93 min_events_per_file = expert_config[
"min_events_per_file"]
94 max_events_per_calibration = expert_config[
"max_events_per_calibration"]
95 max_events_per_calibration_for_xt_sr = expert_config[
"max_events_per_calibration_for_xt_sr"]
96 max_events_per_file = expert_config[
"max_events_per_file"]
97 max_events_per_file_hadron = expert_config[
"max_events_per_file_hadron"]
98 payload_boundaries = []
99 payload_boundaries.extend([ExpRun(*boundary)
for boundary
in expert_config[
"payload_boundaries"]])
100 basf2.B2INFO(f
"Payload boundaries from expert_config: {payload_boundaries}")
102 reduced_file_to_iov_mumu = filter_by_max_files_per_run(file_to_iov_mumu, max_files_per_run, min_events_per_file)
103 input_files_mumu = list(reduced_file_to_iov_mumu.keys())
104 basf2.B2INFO(f
"Total number of mumutight_calib files actually used as input = {len(input_files_mumu)}")
105 chosen_files_mumu = select_files(input_files_mumu[:], max_events_per_calibration, max_events_per_file)
106 chosen_files_mumu_for_xt_sr = select_files(input_files_mumu[:], max_events_per_calibration_for_xt_sr, max_events_per_file)
108 reduced_file_to_iov_hadron = filter_by_max_files_per_run(file_to_iov_hadron, max_files_per_run, min_events_per_file)
109 input_files_hadron = list(reduced_file_to_iov_hadron.keys())
110 basf2.B2INFO(f
"Total number of hadron_calib files actually used as input = {len(input_files_hadron)}")
111 chosen_files_hadron = select_files(input_files_hadron[:], max_events_per_calibration, max_events_per_file_hadron)
112 chosen_files_hadron_for_xt_sr = select_files(input_files_hadron[:],
113 max_events_per_calibration_for_xt_sr, max_events_per_file_hadron)
115 reduced_file_to_iov_Bcosmics = filter_by_max_files_per_run(file_to_iov_Bcosmics, max_files_per_run, min_events_per_file)
116 input_files_Bcosmics = list(reduced_file_to_iov_Bcosmics.keys())
117 basf2.B2INFO(f
"Total number of cosmic_calib files actually used as input = {len(input_files_Bcosmics)}")
118 chosen_files_Bcosmics = select_files(input_files_Bcosmics[:], max_events_per_calibration, max_events_per_file)
119 chosen_files_Bcosmics_for_xt_sr = select_files(
120 input_files_Bcosmics[:],
121 max_events_per_calibration_for_xt_sr,
125 "mumutight_calib": chosen_files_mumu_for_xt_sr,
126 "hadron_calib": chosen_files_hadron_for_xt_sr,
127 "cosmic_calib": chosen_files_Bcosmics_for_xt_sr
131 "mumutight_calib": chosen_files_mumu,
132 "hadron_calib": chosen_files_hadron,
133 "cosmic_calib": chosen_files_Bcosmics
137 requested_iov = kwargs.get(
"requested_iov",
None)
139 from caf.utils
import IoV
141 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
144 collector_granularity =
'all'
145 if payload_boundaries:
146 basf2.B2INFO(
'Found payload_boundaries: set collector granularity to run')
147 collector_granularity =
'run'
150 cal0 = CDCCalibration(name=
'tz0',
151 algorithms=[tz_algo()],
152 input_file_dict=chosen_file_dict,
154 max_events=max_events_per_file,
155 collector_granularity=collector_granularity
159 cal1 = CDCCalibration(name=
'tw0',
160 algorithms=[tw_algo()],
161 input_file_dict=chosen_file_dict,
163 max_events=max_events_per_file,
164 collector_granularity=collector_granularity,
168 cal2 = CDCCalibration(name=
'tz1',
169 algorithms=[tz_algo()],
170 input_file_dict=chosen_file_dict,
172 max_events=max_events_per_file,
173 collector_granularity=collector_granularity,
178 cal3 = CDCCalibration(name=
'xt0',
179 algorithms=[xt_algo()],
180 input_file_dict=input_file_dict,
182 collector_granularity=collector_granularity,
187 cal4 = CDCCalibration(name=
'sr0',
188 algorithms=[sr_algo()],
189 input_file_dict=input_file_dict,
191 collector_granularity=collector_granularity,
195 cal5 = CDCCalibration(name=
'tz2',
196 algorithms=[tz_algo()],
197 input_file_dict=chosen_file_dict,
199 max_events=max_events_per_file,
200 collector_granularity=collector_granularity,
204 if payload_boundaries:
205 basf2.B2INFO(
"Found payload_boundaries: calibration strategies set to SequentialBoundaries.")
207 for algorithm
in cal0.algorithms:
208 algorithm.params = {
"iov_coverage": output_iov,
"payload_boundaries": payload_boundaries}
209 for algorithm
in cal1.algorithms:
210 algorithm.params = {
"iov_coverage": output_iov,
"payload_boundaries": payload_boundaries}
211 for algorithm
in cal2.algorithms:
212 algorithm.params = {
"iov_coverage": output_iov,
"payload_boundaries": payload_boundaries}
213 for algorithm
in cal3.algorithms:
214 algorithm.params = {
"iov_coverage": output_iov,
"payload_boundaries": payload_boundaries}
215 for algorithm
in cal4.algorithms:
216 algorithm.params = {
"iov_coverage": output_iov,
"payload_boundaries": payload_boundaries}
217 for algorithm
in cal5.algorithms:
218 algorithm.params = {
"iov_coverage": output_iov,
"payload_boundaries": payload_boundaries}
222 for algorithm
in cal0.algorithms:
223 algorithm.params = {
"apply_iov": output_iov}
224 for algorithm
in cal1.algorithms:
225 algorithm.params = {
"apply_iov": output_iov}
226 for algorithm
in cal2.algorithms:
227 algorithm.params = {
"apply_iov": output_iov}
228 for algorithm
in cal3.algorithms:
229 algorithm.params = {
"apply_iov": output_iov}
230 for algorithm
in cal4.algorithms:
231 algorithm.params = {
"apply_iov": output_iov}
232 for algorithm
in cal5.algorithms:
233 algorithm.params = {
"apply_iov": output_iov}
235 return [cal0, cal1, cal2, cal3, cal4, cal5]
240 def pre_collector(max_events=None):
242 Define pre collection (reconstruction in our purpose).
243 Probably, we need only CDC and ECL data.
245 max_events [int] : number of events to be processed.
246 All events by Default.
248 path : path for pre collection
250 from basf2
import create_path, register_module
252 reco_path = create_path()
253 if max_events
is None:
254 root_input = register_module(
256 branchNames=HLT_INPUT_OBJECTS
259 root_input = register_module(
261 branchNames=HLT_INPUT_OBJECTS,
263 '0:{}'.format(max_events)])
264 reco_path.add_module(root_input)
266 gearbox = register_module(
'Gearbox')
267 reco_path.add_module(gearbox)
268 reco_path.add_module(
'Geometry', useDB=
True)
270 from rawdata
import add_unpackers
272 add_unpackers(reco_path)
274 from reconstruction
import add_reconstruction
275 add_reconstruction(reco_path,
276 add_trigger_calculation=
False,
277 trackFitHypotheses=[211, 13],
283 def pre_collector_cr(max_events=None):
285 Define pre collection (reconstruction in our purpose).
286 Probably, we need only CDC and ECL data.
288 max_events [int] : number of events to be processed.
289 All events by Default.
291 path : path for pre collection
293 from basf2
import create_path, register_module
295 reco_path = create_path()
296 if max_events
is None:
297 root_input = register_module(
299 branchNames=HLT_INPUT_OBJECTS
302 root_input = register_module(
304 branchNames=HLT_INPUT_OBJECTS,
306 '0:{}'.format(max_events)])
307 reco_path.add_module(root_input)
309 gearbox = register_module(
'Gearbox')
310 reco_path.add_module(gearbox)
311 reco_path.add_module(
'Geometry', useDB=
True)
313 from rawdata
import add_unpackers
315 add_unpackers(reco_path)
317 from reconstruction
import add_cosmics_reconstruction
318 add_cosmics_reconstruction(reco_path,
319 components=[
'CDC',
'ECL'],
322 data_taking_period=
'normal'
327 def collector(bField=True, is_cosmic=False, granularity='all'):
329 Create a cdc calibration collector
331 bField [bool] : True if B field is on, else False
332 isCosmic [bool] : True if cosmic events,
333 else (collision) False.
335 collector : collector module
337 from basf2
import register_module
338 col = register_module(
'CDCCalibrationCollector',
339 granularity=granularity,
340 calExpectedDriftTime=
True,
341 eventT0Extraction=
True,
350 Create a T0 calibration algorithm.
354 from ROOT
import Belle2
356 algo.storeHisto(
True)
357 algo.setMaxMeanDt(0.5)
358 algo.setMaxRMSDt(0.1)
359 algo.setMinimumNDF(20)
365 Create a time walk calibration algorithm.
369 from ROOT
import Belle2
371 algo.setStoreHisto(
True)
378 Create a XT calibration algorithm.
380 prefix : prefixed name for algorithm,
381 which should be consistent with one of collector..
385 from ROOT
import Belle2
387 algo.setStoreHisto(
True)
388 algo.setLRSeparate(
True)
389 algo.setThreshold(0.55)
395 Create a Spacial resolution calibration algorithm.
397 prefix : prefixed name for algorithm,
398 which should be consistent with one of collector..
400 algo : Spacial algorithm
402 from ROOT
import Belle2
404 algo.setStoreHisto(
True)
405 algo.setThreshold(0.4)
411 CDCCalibration is a specialized calibration class for cdc.
412 Since collector is same in all elements, no need to specify it.
422 collector_granularity='All'):
423 for algo
in algorithms:
424 algo.setHistFileName(name)
426 super().__init__(name=name,
427 algorithms=algorithms
430 from caf.framework
import Collection
432 for skim_type, file_list
in input_file_dict.items():
433 if skim_type ==
"Bcosmics":
435 input_files=file_list,
436 pre_collector_path=pre_collector_cr(max_events=max_events),
440 input_files=file_list,
441 pre_collector_path=pre_collector(max_events=max_events),
443 self.add_collection(name=skim_type, collection=collection)
447 if dependencies
is not None:
448 for dep
in dependencies: