11 Script to perform the svd time calibration with the CoG6, CoG3 and ELS3 algorithms
18 from ROOT.Belle2
import SVDCoGTimeCalibrationAlgorithm
19 from ROOT.Belle2
import SVD3SampleCoGTimeCalibrationAlgorithm
20 from ROOT.Belle2
import SVD3SampleELSTimeCalibrationAlgorithm
21 from ROOT.Belle2
import SVDClusterTimeShifterAlgorithm
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 from prompt.calibrations.caf_cdc
import settings
as cdc_tracking_calibration
38 b2.set_log_level(b2.LogLevel.INFO)
42 now = datetime.datetime.now()
44 settings = CalibrationSettings(name=
"caf_svd_time",
45 expert_username=
"gdujany",
47 input_data_formats=[
"raw"],
48 input_data_names=[
"hadron_calib"],
49 input_data_filters={
"hadron_calib": [INPUT_DATA_FILTERS[
"Data Tag"][
"hadron_calib"],
50 INPUT_DATA_FILTERS[
"Beam Energy"][
"4S"],
51 INPUT_DATA_FILTERS[
"Beam Energy"][
"Continuum"],
52 INPUT_DATA_FILTERS[
"Run Type"][
"physics"],
53 INPUT_DATA_FILTERS[
"Magnet"][
"On"]]},
54 depends_on=[cdc_tracking_calibration],
56 "timeAlgorithms": [
"CoG3",
"ELS3",
"CoG6"],
57 "listOfMutedCalibrations": [],
58 "max_events_per_run": 10000,
59 "max_events_per_file": 5000,
61 "linearCutsOnCoG3":
False,
62 "upperLineParameters": [-94.0, 1.264],
63 "lowerLineParameters": [-134.0, 1.264],
64 "rangeRawTimeForIoVCoG6": [20., 80.],
65 "rangeRawTimeForIoVCoG3": [70., 140.],
66 "rangeRawTimeForIoVELS3": [20., 80.],
67 "useRawtimeForTracking":
False,
68 "useSVDGrouping":
True
75 def remove_module(path, name):
77 new_path = b2.create_path()
78 for m
in path.modules():
80 new_path.add_module(m)
85 NEW_RECO_DIGITS_NAME =
"SVDRecoDigitsFromTracks"
86 NEW_SHAPER_DIGITS_NAME =
"SVDShaperDigitsFromTracks"
89 def create_collector(name="SVDTimeCalibrationCollector",
90 clusters="SVDClustersFromTracks",
91 event_info="SVDEventInfo",
96 maxRawTimeForIoV=150.):
98 Simply creates a SVDTimeCalibrationCollector module with some options.
104 collector = b2.register_module(
"SVDTimeCalibrationCollector")
105 collector.set_name(name)
106 collector.param(
"SVDClustersFromTracksName", clusters)
107 collector.param(
"SVDEventInfoName", event_info)
108 collector.param(
"EventT0Name", event_t0)
109 collector.param(
"granularity", granularity)
110 collector.param(
"RawCoGBinWidth", rawBinWidth)
111 collector.param(
"RawTimeIoVMin", minRawTimeForIoV)
112 collector.param(
"RawTimeIoVMax", maxRawTimeForIoV)
117 def create_validation_collector(name="SVDTimeValidationCollector",
118 clusters="SVDClusters",
119 clusters_onTracks="SVDClustersOnTracks",
123 Simply creates a SVDTimeCalibrationCollector module with some options.
129 collector = b2.register_module(
"SVDTimeValidationCollector")
130 collector.set_name(name)
131 collector.param(
"SVDClustersName", clusters)
132 collector.param(
"SVDClustersOnTracksName", clusters_onTracks)
133 collector.param(
"EventT0Name", event_t0)
134 collector.param(
"granularity", granularity)
139 def create_algorithm(
143 linearCutsOnCoG3=False,
144 interceptUpperLine=-94.0,
145 angularCoefficientUpperLine=1.264,
146 interceptLowerLine=-134.0,
147 angularCoefficientLowerLine=1.264):
149 Simply creates a SVDCoGTimeCalibrationAlgorithm class with some options.
152 ROOT.Belle2.SVDCoGTimeCalibrationAlgorithm
155 algorithm = SVDCoGTimeCalibrationAlgorithm(unique_id)
157 algorithm = SVD3SampleCoGTimeCalibrationAlgorithm(unique_id)
158 algorithm.setTwoLineSelectionParameters(
161 angularCoefficientUpperLine,
163 angularCoefficientLowerLine)
165 algorithm = SVD3SampleELSTimeCalibrationAlgorithm(unique_id)
167 algorithm.setPrefix(prefix)
168 algorithm.setMinEntries(min_entries)
173 def create_validation_algorithm(prefix="", min_entries=10000):
175 Simply creates a SVDCoGTimeValidationAlgorithm class with some options.
178 ROOT.Belle2.SVDCoGTimeValidationAlgorithm
180 algorithm = SVDTimeValidationAlgorithm()
182 algorithm.setPrefix(prefix)
183 algorithm.setMinEntries(min_entries)
188 def create_svd_clusterizer(name="ClusterReconstruction",
189 clusters="SVDClustersFromTracks",
192 time_algorithm="CoG6",
193 get_3sample_raw_time=False,
194 shiftSVDClusterTime=None):
196 Simply creates a SVDClusterizer module with some options.
202 cluster = b2.register_module(
"SVDClusterizer")
203 cluster.set_name(name)
204 cluster.param(
"Clusters", clusters)
205 if shaper_digits
is not None:
206 cluster.param(
"ShaperDigits", shaper_digits)
207 cluster.param(
"timeAlgorithm6Samples", time_algorithm)
208 if shiftSVDClusterTime
is not None:
209 cluster.param(
"shiftSVDClusterTime", shiftSVDClusterTime)
210 cluster.param(
"useDB",
False)
211 if get_3sample_raw_time:
212 cluster.param(
"returnClusterRawTime",
True)
216 def create_pre_collector_path(
219 max_events_per_run=10000,
220 max_events_per_file=10000,
222 useRawtimeForTracking=False,
223 is_validation=False):
225 Create a basf2 path that runs a common reconstruction path and also runs several SVDSimpleClusterizer
226 modules with different configurations. This way they re-use the same reconstructed objects.
229 clusterizers (list[pybasf2.Module]): All the differently configured
230 SVDSimpleClusterizer modules. They should output to different datastore objects.
231 max_events_per_run (int, optional): Max events read per run. Defaults to 10000.
232 is_validation (bool, optional): Is used to produce the validation plots. Defaults to False.
238 path = b2.create_path()
242 path.add_module(
"RootInput", branchNames=HLT_INPUT_OBJECTS, entrySequences=[f
'0:{max_events_per_file - 1}'])
244 path.add_module(
"RootInput")
248 raw.add_unpackers(path, components=[
'PXD',
'SVD',
'CDC'])
250 path.add_module(
"Gearbox")
251 path.add_module(
"Geometry")
254 skim6SampleEvents = b2.register_module(
"SVD6SampleEventSkim")
255 path.add_module(skim6SampleEvents)
256 emptypath = b2.create_path()
257 skim6SampleEvents.if_false(emptypath)
261 add_tracking_reconstruction(path, append_full_grid_cdc_eventt0=
True)
262 path = remove_module(path,
"V0Finder")
263 if not is_validation:
267 b2.set_module_parameters(path,
'SVDClusterizer', returnClusterRawTime=useRawtimeForTracking)
269 if useRawtimeForTracking:
270 b2.set_module_parameters(path,
'SVDTimeGrouping',
271 forceGroupingFromDB=
False,
272 useParamFromDB=
False,
273 isEnabledIn6Samples=
True,
275 expectedSignalTimeCenter=100,
276 expectedSignalTimeMin=70, expectedSignalTimeMax=130,
277 tRangeLow=-20, tRangeHigh=220)
278 b2.set_module_parameters(path,
'SVDSpacePointCreator',
279 forceGroupingFromDB=
False,
280 useParamFromDB=
False,
281 useSVDGroupInfoIn6Sample=
True,
282 numberOfSignalGroups=2, formSingleSignalGroup=
True)
284 b2.set_module_parameters(path,
'SVDTimeGrouping',
285 forceGroupingFromDB=
False,
286 useParamFromDB=
False,
287 isEnabledIn6Samples=
True, acceptSigmaN=3,
288 expectedSignalTimeMin=-30, expectedSignalTimeMax=30)
289 b2.set_module_parameters(path,
'SVDSpacePointCreator',
290 forceGroupingFromDB=
False,
291 useSVDGroupInfoIn6Sample=
True)
293 b2.set_module_parameters(path,
'SVDTimeGrouping', forceGroupingFromDB=
False, isEnabledIn6Samples=
False)
294 b2.set_module_parameters(path,
'SVDSpacePointCreator', forceGroupingFromDB=
False, useSVDGroupInfoIn6Sample=
False)
297 path.add_module(
"SVDShaperDigitsFromTracks")
299 for cluster
in clusterizers:
300 path.add_module(cluster)
302 path = remove_module(path,
"SVDMissingAPVsClusterCreator")
307 def get_calibrations(input_data, **kwargs):
309 file_to_iov_physics = input_data[
"hadron_calib"]
310 expert_config = kwargs.get(
"expert_config")
311 timeAlgorithms = expert_config[
"timeAlgorithms"]
312 listOfMutedCalibrations = expert_config[
"listOfMutedCalibrations"]
313 max_events_per_run = expert_config[
"max_events_per_run"]
314 max_events_per_file = expert_config[
"max_events_per_file"]
315 isMC = expert_config[
"isMC"]
316 linearCutsOnCoG3 = expert_config[
"linearCutsOnCoG3"]
317 upperLineParameters = expert_config[
"upperLineParameters"]
318 lowerLineParameters = expert_config[
"lowerLineParameters"]
319 rangeRawTimeForIoVCoG6 = expert_config[
"rangeRawTimeForIoVCoG6"]
320 rangeRawTimeForIoVCoG3 = expert_config[
"rangeRawTimeForIoVCoG3"]
321 rangeRawTimeForIoVELS3 = expert_config[
"rangeRawTimeForIoVELS3"]
322 useSVDGrouping = expert_config[
"useSVDGrouping"]
323 useRawtimeForTracking = expert_config[
"useRawtimeForTracking"]
325 reduced_file_to_iov_physics = filter_by_max_events_per_run(file_to_iov_physics,
326 max_events_per_run, random_select=
True,
327 max_events_per_file=max_events_per_file)
328 good_input_files = list(reduced_file_to_iov_physics.keys())
330 b2.B2INFO(f
"Total number of files used as input = {len(good_input_files)}")
332 exps = [i.exp_low
for i
in reduced_file_to_iov_physics.values()]
333 runs = sorted([i.run_low
for i
in reduced_file_to_iov_physics.values()])
339 if not len(good_input_files):
340 print(
"No good input files found! Check that the input files have entries != 0!")
343 cog6_suffix =
"_CoG6"
344 cog3_suffix =
"_CoG3"
345 els3_suffix =
"_ELS3"
350 unique_id_cog6 = f
"SVDCoGTimeCalibrations_{calType}_{now.isoformat()}_INFO:_3rdOrderPol_TBindep_" \
351 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
352 print(f
"\nUniqueID_CoG6:\n{unique_id_cog6}")
354 unique_id_cog3 = f
"SVD3SampleCoGTimeCalibrations_{calType}_{now.isoformat()}_INFO:_3rdOrderPol_TBindep_" \
355 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
356 print(f
"\nUniqueID_CoG3:\n{unique_id_cog3}")
358 unique_id_els3 = f
"SVD3SampleELSTimeCalibrations_{calType}_{now.isoformat()}_INFO:_TBindep_" \
359 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
360 print(f
"\nUniqueID_ELS3:\n{unique_id_els3}")
362 requested_iov = kwargs.get(
"requested_iov",
None)
363 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
369 list_of_calibrations = []
375 cog6 = create_svd_clusterizer(
376 name=f
"ClusterReconstruction{cog6_suffix}",
377 clusters=f
"SVDClustersFromTracks{cog6_suffix}",
378 reco_digits=NEW_RECO_DIGITS_NAME,
379 shaper_digits=NEW_SHAPER_DIGITS_NAME,
380 time_algorithm=
"CoG6",
381 get_3sample_raw_time=
True)
383 cog3 = create_svd_clusterizer(
384 name=f
"ClusterReconstruction{cog3_suffix}",
385 clusters=f
"SVDClustersFromTracks{cog3_suffix}",
386 reco_digits=NEW_RECO_DIGITS_NAME,
387 shaper_digits=NEW_SHAPER_DIGITS_NAME,
388 time_algorithm=
"CoG3",
389 get_3sample_raw_time=
True)
391 els3 = create_svd_clusterizer(
392 name=f
"ClusterReconstruction{els3_suffix}",
393 clusters=f
"SVDClustersFromTracks{els3_suffix}",
394 reco_digits=NEW_RECO_DIGITS_NAME,
395 shaper_digits=NEW_SHAPER_DIGITS_NAME,
396 time_algorithm=
"ELS3",
397 get_3sample_raw_time=
True)
402 eventInfo =
"SVDEventInfo"
404 eventInfo =
"SVDEventInfoSim"
406 coll_cog6 = create_collector(
407 name=f
"SVDTimeCalibrationCollector{cog6_suffix}",
408 clusters=f
"SVDClustersFromTracks{cog6_suffix}",
409 event_info=eventInfo,
411 minRawTimeForIoV=rangeRawTimeForIoVCoG6[0],
412 maxRawTimeForIoV=rangeRawTimeForIoVCoG6[1])
414 algo_cog6 = create_algorithm(
416 prefix=coll_cog6.name(),
419 coll_cog3 = create_collector(
420 name=f
"SVDTimeCalibrationCollector{cog3_suffix}",
421 clusters=f
"SVDClustersFromTracks{cog3_suffix}",
422 event_info=eventInfo,
425 minRawTimeForIoV=rangeRawTimeForIoVCoG3[0],
426 maxRawTimeForIoV=rangeRawTimeForIoVCoG3[1])
428 algo_cog3 = create_algorithm(
430 prefix=coll_cog3.name(),
432 linearCutsOnCoG3=linearCutsOnCoG3,
433 interceptUpperLine=upperLineParameters[0],
434 angularCoefficientUpperLine=upperLineParameters[1],
435 interceptLowerLine=lowerLineParameters[0],
436 angularCoefficientLowerLine=lowerLineParameters[1])
438 coll_els3 = create_collector(
439 name=f
"SVDTimeCalibrationCollector{els3_suffix}",
440 clusters=f
"SVDClustersFromTracks{els3_suffix}",
441 event_info=eventInfo,
443 minRawTimeForIoV=rangeRawTimeForIoVELS3[0],
444 maxRawTimeForIoV=rangeRawTimeForIoVELS3[1])
446 algo_els3 = create_algorithm(
448 prefix=coll_els3.name(),
457 list_of_clusterizers = []
458 list_of_algorithms = []
459 for a
in timeAlgorithms:
461 list_of_clusterizers.append(cog3)
462 list_of_algorithms.append(algo_cog3)
464 list_of_clusterizers.append(cog6)
465 list_of_algorithms.append(algo_cog6)
467 list_of_clusterizers.append(els3)
468 list_of_algorithms.append(algo_els3)
470 pre_collector_path = create_pre_collector_path(
471 clusterizers=list_of_clusterizers,
472 isMC=isMC, max_events_per_run=max_events_per_run,
473 max_events_per_file=max_events_per_file,
474 useSVDGrouping=useSVDGrouping, useRawtimeForTracking=useRawtimeForTracking)
477 collector_managed_by_CAF = coll_els3
478 if "ELS3" in timeAlgorithms:
479 collector_managed_by_CAF = coll_els3
480 if "CoG6" in timeAlgorithms:
481 pre_collector_path.add_module(coll_cog6)
482 if "CoG3" in timeAlgorithms:
483 pre_collector_path.add_module(coll_cog3)
486 elif "CoG3" in timeAlgorithms:
487 collector_managed_by_CAF = coll_cog3
488 if "CoG6" in timeAlgorithms:
489 pre_collector_path.add_module(coll_cog6)
491 collector_managed_by_CAF = coll_cog6
495 collector=collector_managed_by_CAF,
496 algorithms=list_of_algorithms,
497 input_files=good_input_files,
498 pre_collector_path=pre_collector_path)
500 calibration.strategies = strategies.SequentialBoundaries
502 for algorithm
in calibration.algorithms:
503 algorithm.params = {
"iov_coverage": output_iov}
505 if "rawTimeCalibration" not in listOfMutedCalibrations:
506 list_of_calibrations.append(calibration)
512 SVDClustersOnTrackPrefix =
"SVDClustersOnTrack"
514 shift_clusterizers_onTracks = []
515 for alg
in timeAlgorithms:
516 cluster = create_svd_clusterizer(
517 name=f
"ClusterReconstruction_{alg}",
518 clusters=f
"{SVDClustersOnTrackPrefix}_{alg}",
519 shaper_digits=NEW_SHAPER_DIGITS_NAME,
521 shiftSVDClusterTime=
False)
522 shift_clusterizers_onTracks.append(cluster)
524 shift_pre_collector_path = create_pre_collector_path(
525 clusterizers=shift_clusterizers_onTracks,
526 isMC=isMC, max_events_per_run=max_events_per_run,
527 max_events_per_file=max_events_per_file,
528 useSVDGrouping=useSVDGrouping)
530 shift_collector = b2.register_module(
"SVDClusterTimeShifterCollector")
531 shift_collector.set_name(
"SVDClusterTimeShifterCollector")
532 shift_collector.param(
"MaxClusterSize", 6)
533 shift_collector.param(
"EventT0Name",
"EventT0")
534 shift_collector.param(
"SVDClustersOnTrackPrefix", f
"{SVDClustersOnTrackPrefix}")
535 shift_collector.param(
"TimeAlgorithms", timeAlgorithms)
537 shift_algo = SVDClusterTimeShifterAlgorithm(f
"{calType}_{now.isoformat()}_INFO:_"
538 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}")
539 shift_algo.setMinEntries(100)
540 shift_algo.setMaximumAllowedShift(15.)
541 shift_algo.setTimeAlgorithm(timeAlgorithms)
543 shift_calibration =
Calibration(
"SVDClusterTimeShifter",
544 collector=shift_collector,
545 algorithms=shift_algo,
546 input_files=good_input_files,
547 pre_collector_path=shift_pre_collector_path)
549 shift_calibration.strategies = strategies.SingleIOV
551 for algorithm
in shift_calibration.algorithms:
552 algorithm.params = {
"apply_iov": output_iov}
554 if "timeShiftCalibration" not in listOfMutedCalibrations:
555 list_of_calibrations.append(shift_calibration)
561 val_cog6 = create_svd_clusterizer(
562 name=f
"ClusterReconstruction{cog6_suffix}",
563 clusters=f
"SVDClusters{cog6_suffix}",
564 time_algorithm=
"CoG6")
566 val_cog6_onTracks = create_svd_clusterizer(
567 name=f
"ClusterReconstruction{cog6_suffix}_onTracks",
568 clusters=f
"SVDClusters{cog6_suffix}_onTracks",
569 reco_digits=NEW_RECO_DIGITS_NAME,
570 shaper_digits=NEW_SHAPER_DIGITS_NAME,
571 time_algorithm=
"CoG6")
573 val_cog3 = create_svd_clusterizer(
574 name=f
"ClusterReconstruction{cog3_suffix}",
575 clusters=f
"SVDClusters{cog3_suffix}",
576 time_algorithm=
"CoG3")
578 val_cog3_onTracks = create_svd_clusterizer(
579 name=f
"ClusterReconstruction{cog3_suffix}_onTracks",
580 clusters=f
"SVDClusters{cog3_suffix}_onTracks",
581 reco_digits=NEW_RECO_DIGITS_NAME,
582 shaper_digits=NEW_SHAPER_DIGITS_NAME,
583 time_algorithm=
"CoG3")
585 val_els3 = create_svd_clusterizer(
586 name=f
"ClusterReconstruction{els3_suffix}",
587 clusters=f
"SVDClusters{els3_suffix}",
588 time_algorithm=
"ELS3")
590 val_els3_onTracks = create_svd_clusterizer(
591 name=f
"ClusterReconstruction{els3_suffix}_onTracks",
592 clusters=f
"SVDClusters{els3_suffix}_onTracks",
593 reco_digits=NEW_RECO_DIGITS_NAME,
594 shaper_digits=NEW_SHAPER_DIGITS_NAME,
595 time_algorithm=
"ELS3")
597 val_coll_cog6 = create_validation_collector(
598 name=f
"SVDTimeValidationCollector{cog6_suffix}",
599 clusters=f
"SVDClusters{cog6_suffix}",
600 clusters_onTracks=f
"SVDClusters{cog6_suffix}_onTracks",
603 val_algo_cog6 = create_validation_algorithm(
604 prefix=val_coll_cog6.name(),
607 val_coll_cog3 = create_validation_collector(
608 name=f
"SVDTimeValidationCollector{cog3_suffix}",
609 clusters=f
"SVDClusters{cog3_suffix}",
610 clusters_onTracks=f
"SVDClusters{cog3_suffix}_onTracks",
613 val_algo_cog3 = create_validation_algorithm(
614 prefix=val_coll_cog3.name(),
617 val_coll_els3 = create_validation_collector(
618 name=f
"SVDTimeValidationCollector{els3_suffix}",
619 clusters=f
"SVDClusters{els3_suffix}",
620 clusters_onTracks=f
"SVDClusters{els3_suffix}_onTracks",
623 val_algo_els3 = create_validation_algorithm(
624 prefix=val_coll_els3.name(),
627 list_of_val_clusterizers = []
628 list_of_val_algorithms = []
629 for a
in timeAlgorithms:
631 list_of_val_clusterizers.append(val_cog3)
632 list_of_val_clusterizers.append(val_cog3_onTracks)
633 list_of_val_algorithms.append(val_algo_cog3)
635 list_of_val_clusterizers.append(val_cog6)
636 list_of_val_clusterizers.append(val_cog6_onTracks)
637 list_of_val_algorithms.append(val_algo_cog6)
639 list_of_val_clusterizers.append(val_els3)
640 list_of_val_clusterizers.append(val_els3_onTracks)
641 list_of_val_algorithms.append(val_algo_els3)
643 val_pre_collector_path = create_pre_collector_path(
644 clusterizers=list_of_val_clusterizers,
645 isMC=isMC, max_events_per_run=max_events_per_run,
646 max_events_per_file=max_events_per_file,
647 useSVDGrouping=useSVDGrouping, useRawtimeForTracking=useRawtimeForTracking,
650 val_collector_managed_by_CAF = val_coll_els3
651 if "ELS3" in timeAlgorithms:
652 val_collector_managed_by_CAF = val_coll_els3
653 if "CoG6" in timeAlgorithms:
654 val_pre_collector_path.add_module(val_coll_cog6)
655 if "CoG3" in timeAlgorithms:
656 val_pre_collector_path.add_module(val_coll_cog3)
657 elif "CoG3" in timeAlgorithms:
658 val_collector_managed_by_CAF = val_coll_cog3
659 if "CoG6" in timeAlgorithms:
660 val_pre_collector_path.add_module(val_coll_cog6)
662 val_collector_managed_by_CAF = val_coll_cog6
665 collector=val_collector_managed_by_CAF,
666 algorithms=list_of_val_algorithms,
667 input_files=good_input_files,
668 pre_collector_path=val_pre_collector_path)
670 val_calibration.strategies = strategies.SequentialRunByRun
672 for algorithm
in val_calibration.algorithms:
673 algorithm.params = {
"iov_coverage": output_iov}
675 if "timeValidation" not in listOfMutedCalibrations:
676 list_of_calibrations.append(val_calibration)
678 for item
in range(len(list_of_calibrations) - 1):
679 list_of_calibrations[item + 1].depends_on(list_of_calibrations[item])
681 return list_of_calibrations