12 Script to perform the svd time calibration with the CoG6, CoG3 and ELS3 algorithms
19 from ROOT.Belle2
import SVDCoGTimeCalibrationAlgorithm
20 from ROOT.Belle2
import SVD3SampleCoGTimeCalibrationAlgorithm
21 from ROOT.Belle2
import SVD3SampleELSTimeCalibrationAlgorithm
22 from ROOT.Belle2
import SVDTimeValidationAlgorithm
28 from tracking
import add_tracking_reconstruction
30 from caf.framework
import Calibration
31 from caf
import strategies
32 from caf.utils
import IoV
33 from prompt
import CalibrationSettings, INPUT_DATA_FILTERS
36 b2.set_log_level(b2.LogLevel.INFO)
40 now = datetime.datetime.now()
42 settings = CalibrationSettings(name=
"caf_svd_time",
43 expert_username=
"gdujany",
45 input_data_formats=[
"raw"],
46 input_data_names=[
"hadron_calib"],
47 input_data_filters={
"hadron_calib": [INPUT_DATA_FILTERS[
"Data Tag"][
"hadron_calib"],
48 INPUT_DATA_FILTERS[
"Beam Energy"][
"4S"],
49 INPUT_DATA_FILTERS[
"Beam Energy"][
"Continuum"],
50 INPUT_DATA_FILTERS[
"Run Type"][
"physics"],
51 INPUT_DATA_FILTERS[
"Magnet"][
"On"]]},
54 "max_events_per_run": 10000,
62 def remove_module(path, name):
64 new_path = b2.create_path()
65 for m
in path.modules():
67 new_path.add_module(m)
72 NEW_RECO_DIGITS_NAME =
"SVDRecoDigitsFromTracks"
73 NEW_SHAPER_DIGITS_NAME =
"SVDShaperDigitsFromTracks"
76 def create_collector(name="SVDTimeCalibrationCollector",
77 clusters="SVDClustersFromTracks",
78 event_info="SVDEventInfo",
83 Simply creates a SVDTimeCalibrationCollector module with some options.
89 collector = b2.register_module(
"SVDTimeCalibrationCollector")
90 collector.set_name(name)
91 collector.param(
"SVDClustersFromTracksName", clusters)
92 collector.param(
"SVDEventInfoName", event_info)
93 collector.param(
"EventT0Name", event_t0)
94 collector.param(
"granularity", granularity)
95 collector.param(
"RawCoGBinWidth", rawBinWidth)
100 def create_validation_collector(name="SVDTimeValidationCollector",
101 clusters="SVDClusters",
102 clusters_onTracks="SVDClustersOnTracks",
103 event_info="SVDEventInfo",
107 Simply creates a SVDTimeCalibrationCollector module with some options.
113 collector = b2.register_module(
"SVDTimeValidationCollector")
114 collector.set_name(name)
115 collector.param(
"SVDClustersName", clusters)
116 collector.param(
"SVDClustersOnTracksName", clusters_onTracks)
117 collector.param(
"SVDEventInfoName", event_info)
118 collector.param(
"EventT0Name", event_t0)
119 collector.param(
"granularity", granularity)
124 def create_algorithm(unique_id, prefix="", min_entries=10000):
126 Simply creates a SVDCoGTimeCalibrationAlgorithm class with some options.
129 ROOT.Belle2.SVDCoGTimeCalibrationAlgorithm
132 algorithm = SVDCoGTimeCalibrationAlgorithm(unique_id)
134 algorithm = SVD3SampleCoGTimeCalibrationAlgorithm(unique_id)
136 algorithm = SVD3SampleELSTimeCalibrationAlgorithm(unique_id)
138 algorithm.setPrefix(prefix)
139 algorithm.setMinEntries(min_entries)
144 def create_validation_algorithm(prefix="", min_entries=10000):
146 Simply creates a SVDCoGTimeValidationAlgorithm class with some options.
149 ROOT.Belle2.SVDCoGTimeValidationAlgorithm
151 algorithm = SVDTimeValidationAlgorithm()
153 algorithm.setPrefix(prefix)
154 algorithm.setMinEntries(min_entries)
159 def create_svd_clusterizer(name="ClusterReconstruction",
160 clusters="SVDClustersFromTracks",
163 time_algorithm="CoG6",
164 get_3sample_raw_time=False):
166 Simply creates a SVDClusterizer module with some options.
172 cluster = b2.register_module(
"SVDClusterizer")
173 cluster.set_name(name)
174 cluster.param(
"Clusters", clusters)
175 if shaper_digits
is not None:
176 cluster.param(
"ShaperDigits", shaper_digits)
177 cluster.param(
"timeAlgorithm6Samples", time_algorithm)
178 cluster.param(
"useDB",
False)
179 if get_3sample_raw_time:
180 cluster.param(
"returnClusterRawTime",
True)
184 def create_pre_collector_path(clusterizers, isMC=False, is_validation=False):
186 Create a basf2 path that runs a common reconstruction path and also runs several SVDSimpleClusterizer
187 modules with different configurations. This way they re-use the same reconstructed objects.
190 clusterizers (list[pybasf2.Module]): All the differently configured SVDSimpleClusterizer modules.
191 They should output to different datastore objects.
197 path = b2.create_path()
201 path.add_module(
"RootInput", branchNames=HLT_INPUT_OBJECTS)
203 path.add_module(
"RootInput")
207 raw.add_unpackers(path, components=[
'PXD',
'SVD',
'CDC'])
209 path.add_module(
"Gearbox")
210 path.add_module(
"Geometry")
213 skim6SampleEvents = b2.register_module(
"SVD6SampleEventSkim")
214 path.add_module(skim6SampleEvents)
215 emptypath = b2.create_path()
216 skim6SampleEvents.if_false(emptypath)
220 add_tracking_reconstruction(path)
221 path = remove_module(path,
"V0Finder")
222 if not is_validation:
223 b2.set_module_parameters(path,
'SVDClusterizer', returnClusterRawTime=
True)
226 path.add_module(
"SVDShaperDigitsFromTracks")
228 for cluster
in clusterizers:
229 path.add_module(cluster)
231 path = remove_module(path,
"SVDMissingAPVsClusterCreator")
236 def get_calibrations(input_data, **kwargs):
238 file_to_iov_physics = input_data[
"hadron_calib"]
239 expert_config = kwargs.get(
"expert_config")
240 max_events_per_run = expert_config[
"max_events_per_run"]
241 isMC = expert_config[
"isMC"]
243 reduced_file_to_iov_physics = filter_by_max_events_per_run(file_to_iov_physics,
244 max_events_per_run, random_select=
True)
245 good_input_files = list(reduced_file_to_iov_physics.keys())
247 b2.B2INFO(f
"Total number of files used as input = {len(good_input_files)}")
249 exps = [i.exp_low
for i
in reduced_file_to_iov_physics.values()]
250 runs = sorted([i.run_low
for i
in reduced_file_to_iov_physics.values()])
256 if not len(good_input_files):
257 print(
"No good input files found! Check that the input files have entries != 0!")
260 cog6_suffix =
"_CoG6"
261 cog3_suffix =
"_CoG3"
262 els3_suffix =
"_ELS3"
267 unique_id_cog6 = f
"SVDCoGTimeCalibrations_{calType}_{now.isoformat()}_INFO:_3rdOrderPol_TBindep_" \
268 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
269 print(f
"\nUniqueID_CoG6:\n{unique_id_cog6}")
271 unique_id_cog3 = f
"SVD3SampleCoGTimeCalibrations_{calType}_{now.isoformat()}_INFO:_3rdOrderPol_TBindep_" \
272 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
273 print(f
"\nUniqueID_CoG3:\n{unique_id_cog3}")
275 unique_id_els3 = f
"SVD3SampleELSTimeCalibrations_{calType}_{now.isoformat()}_INFO:_TBindep_" \
276 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
277 print(f
"\nUniqueID_ELS3:\n{unique_id_els3}")
279 requested_iov = kwargs.get(
"requested_iov",
None)
280 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
286 cog6 = create_svd_clusterizer(
287 name=f
"ClusterReconstruction{cog6_suffix}",
288 clusters=f
"SVDClustersFromTracks{cog6_suffix}",
289 reco_digits=NEW_RECO_DIGITS_NAME,
290 shaper_digits=NEW_SHAPER_DIGITS_NAME,
291 time_algorithm=
"CoG6",
292 get_3sample_raw_time=
True)
294 cog3 = create_svd_clusterizer(
295 name=f
"ClusterReconstruction{cog3_suffix}",
296 clusters=f
"SVDClustersFromTracks{cog3_suffix}",
297 reco_digits=NEW_RECO_DIGITS_NAME,
298 shaper_digits=NEW_SHAPER_DIGITS_NAME,
299 time_algorithm=
"CoG3",
300 get_3sample_raw_time=
True)
302 els3 = create_svd_clusterizer(
303 name=f
"ClusterReconstruction{els3_suffix}",
304 clusters=f
"SVDClustersFromTracks{els3_suffix}",
305 reco_digits=NEW_RECO_DIGITS_NAME,
306 shaper_digits=NEW_SHAPER_DIGITS_NAME,
307 time_algorithm=
"ELS3",
308 get_3sample_raw_time=
True)
313 eventInfo =
"SVDEventInfo"
315 eventInfo =
"SVDEventInfoSim"
317 coll_cog6 = create_collector(
318 name=f
"SVDTimeCalibrationCollector{cog6_suffix}",
319 clusters=f
"SVDClustersFromTracks{cog6_suffix}",
320 event_info=eventInfo,
323 algo_cog6 = create_algorithm(
325 prefix=coll_cog6.name(),
328 coll_cog3 = create_collector(
329 name=f
"SVDTimeCalibrationCollector{cog3_suffix}",
330 clusters=f
"SVDClustersFromTracks{cog3_suffix}",
331 event_info=eventInfo,
335 algo_cog3 = create_algorithm(
337 prefix=coll_cog3.name(),
340 coll_els3 = create_collector(
341 name=f
"SVDTimeCalibrationCollector{els3_suffix}",
342 clusters=f
"SVDClustersFromTracks{els3_suffix}",
343 event_info=eventInfo,
346 algo_els3 = create_algorithm(
348 prefix=coll_els3.name(),
356 pre_collector_path = create_pre_collector_path(
357 clusterizers=[cog6, cog3, els3],
359 pre_collector_path.add_module(coll_cog6)
360 pre_collector_path.add_module(coll_cog3)
366 algorithms=[algo_cog3, algo_cog6, algo_els3],
367 input_files=good_input_files,
368 pre_collector_path=pre_collector_path)
372 for algorithm
in calibration.algorithms:
373 algorithm.params = {
"iov_coverage": output_iov}
379 val_cog6 = create_svd_clusterizer(
380 name=f
"ClusterReconstruction{cog6_suffix}",
381 clusters=f
"SVDClusters{cog6_suffix}",
382 time_algorithm=
"CoG6")
384 val_cog6_onTracks = create_svd_clusterizer(
385 name=f
"ClusterReconstruction{cog6_suffix}_onTracks",
386 clusters=f
"SVDClusters{cog6_suffix}_onTracks",
387 reco_digits=NEW_RECO_DIGITS_NAME,
388 shaper_digits=NEW_SHAPER_DIGITS_NAME,
389 time_algorithm=
"CoG6")
391 val_cog3 = create_svd_clusterizer(
392 name=f
"ClusterReconstruction{cog3_suffix}",
393 clusters=f
"SVDClusters{cog3_suffix}",
394 time_algorithm=
"CoG3")
396 val_cog3_onTracks = create_svd_clusterizer(
397 name=f
"ClusterReconstruction{cog3_suffix}_onTracks",
398 clusters=f
"SVDClusters{cog3_suffix}_onTracks",
399 reco_digits=NEW_RECO_DIGITS_NAME,
400 shaper_digits=NEW_SHAPER_DIGITS_NAME,
401 time_algorithm=
"CoG3")
403 val_els3 = create_svd_clusterizer(
404 name=f
"ClusterReconstruction{els3_suffix}",
405 clusters=f
"SVDClusters{els3_suffix}",
406 time_algorithm=
"ELS3")
408 val_els3_onTracks = create_svd_clusterizer(
409 name=f
"ClusterReconstruction{els3_suffix}_onTracks",
410 clusters=f
"SVDClusters{els3_suffix}_onTracks",
411 reco_digits=NEW_RECO_DIGITS_NAME,
412 shaper_digits=NEW_SHAPER_DIGITS_NAME,
413 time_algorithm=
"ELS3")
415 val_coll_cog6 = create_validation_collector(
416 name=f
"SVDTimeValidationCollector{cog6_suffix}",
417 clusters=f
"SVDClusters{cog6_suffix}",
418 clusters_onTracks=f
"SVDClusters{cog6_suffix}_onTracks",
419 event_info=eventInfo,
422 val_algo_cog6 = create_validation_algorithm(
423 prefix=val_coll_cog6.name(),
426 val_coll_cog3 = create_validation_collector(
427 name=f
"SVDTimeValidationCollector{cog3_suffix}",
428 clusters=f
"SVDClusters{cog3_suffix}",
429 clusters_onTracks=f
"SVDClusters{cog3_suffix}_onTracks",
430 event_info=eventInfo,
433 val_algo_cog3 = create_validation_algorithm(
434 prefix=val_coll_cog3.name(),
437 val_coll_els3 = create_validation_collector(
438 name=f
"SVDTimeValidationCollector{els3_suffix}",
439 clusters=f
"SVDClusters{els3_suffix}",
440 clusters_onTracks=f
"SVDClusters{els3_suffix}_onTracks",
441 event_info=eventInfo,
444 val_algo_els3 = create_validation_algorithm(
445 prefix=val_coll_els3.name(),
448 val_pre_collector_path = create_pre_collector_path(
449 clusterizers=[val_cog6, val_cog6_onTracks,
450 val_cog3, val_cog3_onTracks,
451 val_els3, val_els3_onTracks],
452 isMC=isMC, is_validation=
True)
453 val_pre_collector_path.add_module(val_coll_cog6)
454 val_pre_collector_path.add_module(val_coll_cog3)
457 collector=val_coll_els3,
458 algorithms=[val_algo_cog3, val_algo_cog6,
460 input_files=good_input_files,
461 pre_collector_path=val_pre_collector_path)
465 for algorithm
in val_calibration.algorithms:
466 algorithm.params = {
"iov_coverage": output_iov}
468 val_calibration.depends_on(calibration)
470 return [calibration, val_calibration]