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 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 "timeAlgorithms": [
"CoG3",
"ELS3",
"CoG6"],
55 "listOfMutedCalibrations": [],
56 "max_events_per_run": 10000,
57 "max_events_per_file": 5000,
59 "linearCutsOnCoG3":
False,
60 "upperLineParameters": [-94.0, 1.264],
61 "lowerLineParameters": [-134.0, 1.264],
62 "rangeRawTimeForIoVCoG6": [20., 80.],
63 "rangeRawTimeForIoVCoG3": [70., 140.],
64 "rangeRawTimeForIoVELS3": [20., 80.],
65 "useRawtimeForTracking":
False,
66 "useSVDGrouping":
True
73 def remove_module(path, name):
75 new_path = b2.create_path()
76 for m
in path.modules():
78 new_path.add_module(m)
83 NEW_RECO_DIGITS_NAME =
"SVDRecoDigitsFromTracks"
84 NEW_SHAPER_DIGITS_NAME =
"SVDShaperDigitsFromTracks"
87 def create_collector(name="SVDTimeCalibrationCollector",
88 clusters="SVDClustersFromTracks",
89 event_info="SVDEventInfo",
94 maxRawTimeForIoV=150.):
96 Simply creates a SVDTimeCalibrationCollector module with some options.
102 collector = b2.register_module(
"SVDTimeCalibrationCollector")
103 collector.set_name(name)
104 collector.param(
"SVDClustersFromTracksName", clusters)
105 collector.param(
"SVDEventInfoName", event_info)
106 collector.param(
"EventT0Name", event_t0)
107 collector.param(
"granularity", granularity)
108 collector.param(
"RawCoGBinWidth", rawBinWidth)
109 collector.param(
"RawTimeIoVMin", minRawTimeForIoV)
110 collector.param(
"RawTimeIoVMax", maxRawTimeForIoV)
115 def create_validation_collector(name="SVDTimeValidationCollector",
116 clusters="SVDClusters",
117 clusters_onTracks="SVDClustersOnTracks",
121 Simply creates a SVDTimeCalibrationCollector module with some options.
127 collector = b2.register_module(
"SVDTimeValidationCollector")
128 collector.set_name(name)
129 collector.param(
"SVDClustersName", clusters)
130 collector.param(
"SVDClustersOnTracksName", clusters_onTracks)
131 collector.param(
"EventT0Name", event_t0)
132 collector.param(
"granularity", granularity)
137 def create_algorithm(
141 linearCutsOnCoG3=False,
142 interceptUpperLine=-94.0,
143 angularCoefficientUpperLine=1.264,
144 interceptLowerLine=-134.0,
145 angularCoefficientLowerLine=1.264):
147 Simply creates a SVDCoGTimeCalibrationAlgorithm class with some options.
150 ROOT.Belle2.SVDCoGTimeCalibrationAlgorithm
153 algorithm = SVDCoGTimeCalibrationAlgorithm(unique_id)
155 algorithm = SVD3SampleCoGTimeCalibrationAlgorithm(unique_id)
156 algorithm.setTwoLineSelectionParameters(
159 angularCoefficientUpperLine,
161 angularCoefficientLowerLine)
163 algorithm = SVD3SampleELSTimeCalibrationAlgorithm(unique_id)
165 algorithm.setPrefix(prefix)
166 algorithm.setMinEntries(min_entries)
171 def create_validation_algorithm(prefix="", min_entries=10000):
173 Simply creates a SVDCoGTimeValidationAlgorithm class with some options.
176 ROOT.Belle2.SVDCoGTimeValidationAlgorithm
178 algorithm = SVDTimeValidationAlgorithm()
180 algorithm.setPrefix(prefix)
181 algorithm.setMinEntries(min_entries)
186 def create_svd_clusterizer(name="ClusterReconstruction",
187 clusters="SVDClustersFromTracks",
190 time_algorithm="CoG6",
191 get_3sample_raw_time=False,
192 shiftSVDClusterTime=None):
194 Simply creates a SVDClusterizer module with some options.
200 cluster = b2.register_module(
"SVDClusterizer")
201 cluster.set_name(name)
202 cluster.param(
"Clusters", clusters)
203 if shaper_digits
is not None:
204 cluster.param(
"ShaperDigits", shaper_digits)
205 cluster.param(
"timeAlgorithm6Samples", time_algorithm)
206 if shiftSVDClusterTime
is not None:
207 cluster.param(
"shiftSVDClusterTime", shiftSVDClusterTime)
208 cluster.param(
"useDB",
False)
209 if get_3sample_raw_time:
210 cluster.param(
"returnClusterRawTime",
True)
214 def create_pre_collector_path(
217 max_events_per_run=10000,
218 max_events_per_file=10000,
220 useRawtimeForTracking=False,
221 is_validation=False):
223 Create a basf2 path that runs a common reconstruction path and also runs several SVDSimpleClusterizer
224 modules with different configurations. This way they re-use the same reconstructed objects.
227 clusterizers (list[pybasf2.Module]): All the differently configured
228 SVDSimpleClusterizer modules. They should output to different datastore objects.
229 max_events_per_run (int, optional): Max events read per run. Defaults to 10000.
230 is_validation (bool, optional): Is used to produce the validation plots. Defaults to False.
236 path = b2.create_path()
240 path.add_module(
"RootInput", branchNames=HLT_INPUT_OBJECTS, entrySequences=[f
'0:{max_events_per_file - 1}'])
242 path.add_module(
"RootInput")
246 raw.add_unpackers(path, components=[
'PXD',
'SVD',
'CDC'])
248 path.add_module(
"Gearbox")
249 path.add_module(
"Geometry")
252 skim6SampleEvents = b2.register_module(
"SVD6SampleEventSkim")
253 path.add_module(skim6SampleEvents)
254 emptypath = b2.create_path()
255 skim6SampleEvents.if_false(emptypath)
259 add_tracking_reconstruction(path, append_full_grid_cdc_eventt0=
True)
260 path = remove_module(path,
"V0Finder")
261 if not is_validation:
265 b2.set_module_parameters(path,
'SVDClusterizer', returnClusterRawTime=useRawtimeForTracking)
267 if useRawtimeForTracking:
268 b2.set_module_parameters(path,
'SVDTimeGrouping',
269 forceGroupingFromDB=
False,
270 useParamFromDB=
False,
271 isEnabledIn6Samples=
True,
273 expectedSignalTimeCenter=100,
274 expectedSignalTimeMin=70, expectedSignalTimeMax=130,
275 tRangeLow=-20, tRangeHigh=220)
276 b2.set_module_parameters(path,
'SVDSpacePointCreator',
277 forceGroupingFromDB=
False,
278 useParamFromDB=
False,
279 useSVDGroupInfoIn6Sample=
True,
280 numberOfSignalGroups=2, formSingleSignalGroup=
True)
282 b2.set_module_parameters(path,
'SVDTimeGrouping',
283 forceGroupingFromDB=
False,
284 useParamFromDB=
False,
285 isEnabledIn6Samples=
True, acceptSigmaN=3,
286 expectedSignalTimeMin=-30, expectedSignalTimeMax=30)
287 b2.set_module_parameters(path,
'SVDSpacePointCreator',
288 forceGroupingFromDB=
False,
289 useSVDGroupInfoIn6Sample=
True)
291 b2.set_module_parameters(path,
'SVDTimeGrouping', forceGroupingFromDB=
False, isEnabledIn6Samples=
False)
292 b2.set_module_parameters(path,
'SVDSpacePointCreator', forceGroupingFromDB=
False, useSVDGroupInfoIn6Sample=
False)
295 path.add_module(
"SVDShaperDigitsFromTracks")
297 for cluster
in clusterizers:
298 path.add_module(cluster)
300 path = remove_module(path,
"SVDMissingAPVsClusterCreator")
305 def get_calibrations(input_data, **kwargs):
307 file_to_iov_physics = input_data[
"hadron_calib"]
308 expert_config = kwargs.get(
"expert_config")
309 timeAlgorithms = expert_config[
"timeAlgorithms"]
310 listOfMutedCalibrations = expert_config[
"listOfMutedCalibrations"]
311 max_events_per_run = expert_config[
"max_events_per_run"]
312 max_events_per_file = expert_config[
"max_events_per_file"]
313 isMC = expert_config[
"isMC"]
314 linearCutsOnCoG3 = expert_config[
"linearCutsOnCoG3"]
315 upperLineParameters = expert_config[
"upperLineParameters"]
316 lowerLineParameters = expert_config[
"lowerLineParameters"]
317 rangeRawTimeForIoVCoG6 = expert_config[
"rangeRawTimeForIoVCoG6"]
318 rangeRawTimeForIoVCoG3 = expert_config[
"rangeRawTimeForIoVCoG3"]
319 rangeRawTimeForIoVELS3 = expert_config[
"rangeRawTimeForIoVELS3"]
320 useSVDGrouping = expert_config[
"useSVDGrouping"]
321 useRawtimeForTracking = expert_config[
"useRawtimeForTracking"]
323 reduced_file_to_iov_physics = filter_by_max_events_per_run(file_to_iov_physics,
324 max_events_per_run, random_select=
True,
325 max_events_per_file=max_events_per_file)
326 good_input_files = list(reduced_file_to_iov_physics.keys())
328 b2.B2INFO(f
"Total number of files used as input = {len(good_input_files)}")
330 exps = [i.exp_low
for i
in reduced_file_to_iov_physics.values()]
331 runs = sorted([i.run_low
for i
in reduced_file_to_iov_physics.values()])
337 if not len(good_input_files):
338 print(
"No good input files found! Check that the input files have entries != 0!")
341 cog6_suffix =
"_CoG6"
342 cog3_suffix =
"_CoG3"
343 els3_suffix =
"_ELS3"
348 unique_id_cog6 = f
"SVDCoGTimeCalibrations_{calType}_{now.isoformat()}_INFO:_3rdOrderPol_TBindep_" \
349 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
350 print(f
"\nUniqueID_CoG6:\n{unique_id_cog6}")
352 unique_id_cog3 = f
"SVD3SampleCoGTimeCalibrations_{calType}_{now.isoformat()}_INFO:_3rdOrderPol_TBindep_" \
353 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
354 print(f
"\nUniqueID_CoG3:\n{unique_id_cog3}")
356 unique_id_els3 = f
"SVD3SampleELSTimeCalibrations_{calType}_{now.isoformat()}_INFO:_TBindep_" \
357 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
358 print(f
"\nUniqueID_ELS3:\n{unique_id_els3}")
360 requested_iov = kwargs.get(
"requested_iov",
None)
361 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
367 list_of_calibrations = []
373 cog6 = create_svd_clusterizer(
374 name=f
"ClusterReconstruction{cog6_suffix}",
375 clusters=f
"SVDClustersFromTracks{cog6_suffix}",
376 reco_digits=NEW_RECO_DIGITS_NAME,
377 shaper_digits=NEW_SHAPER_DIGITS_NAME,
378 time_algorithm=
"CoG6",
379 get_3sample_raw_time=
True)
381 cog3 = create_svd_clusterizer(
382 name=f
"ClusterReconstruction{cog3_suffix}",
383 clusters=f
"SVDClustersFromTracks{cog3_suffix}",
384 reco_digits=NEW_RECO_DIGITS_NAME,
385 shaper_digits=NEW_SHAPER_DIGITS_NAME,
386 time_algorithm=
"CoG3",
387 get_3sample_raw_time=
True)
389 els3 = create_svd_clusterizer(
390 name=f
"ClusterReconstruction{els3_suffix}",
391 clusters=f
"SVDClustersFromTracks{els3_suffix}",
392 reco_digits=NEW_RECO_DIGITS_NAME,
393 shaper_digits=NEW_SHAPER_DIGITS_NAME,
394 time_algorithm=
"ELS3",
395 get_3sample_raw_time=
True)
400 eventInfo =
"SVDEventInfo"
402 eventInfo =
"SVDEventInfoSim"
404 coll_cog6 = create_collector(
405 name=f
"SVDTimeCalibrationCollector{cog6_suffix}",
406 clusters=f
"SVDClustersFromTracks{cog6_suffix}",
407 event_info=eventInfo,
409 minRawTimeForIoV=rangeRawTimeForIoVCoG6[0],
410 maxRawTimeForIoV=rangeRawTimeForIoVCoG6[1])
412 algo_cog6 = create_algorithm(
414 prefix=coll_cog6.name(),
417 coll_cog3 = create_collector(
418 name=f
"SVDTimeCalibrationCollector{cog3_suffix}",
419 clusters=f
"SVDClustersFromTracks{cog3_suffix}",
420 event_info=eventInfo,
423 minRawTimeForIoV=rangeRawTimeForIoVCoG3[0],
424 maxRawTimeForIoV=rangeRawTimeForIoVCoG3[1])
426 algo_cog3 = create_algorithm(
428 prefix=coll_cog3.name(),
430 linearCutsOnCoG3=linearCutsOnCoG3,
431 interceptUpperLine=upperLineParameters[0],
432 angularCoefficientUpperLine=upperLineParameters[1],
433 interceptLowerLine=lowerLineParameters[0],
434 angularCoefficientLowerLine=lowerLineParameters[1])
436 coll_els3 = create_collector(
437 name=f
"SVDTimeCalibrationCollector{els3_suffix}",
438 clusters=f
"SVDClustersFromTracks{els3_suffix}",
439 event_info=eventInfo,
441 minRawTimeForIoV=rangeRawTimeForIoVELS3[0],
442 maxRawTimeForIoV=rangeRawTimeForIoVELS3[1])
444 algo_els3 = create_algorithm(
446 prefix=coll_els3.name(),
455 list_of_clusterizers = []
456 list_of_algorithms = []
457 for a
in timeAlgorithms:
459 list_of_clusterizers.append(cog3)
460 list_of_algorithms.append(algo_cog3)
462 list_of_clusterizers.append(cog6)
463 list_of_algorithms.append(algo_cog6)
465 list_of_clusterizers.append(els3)
466 list_of_algorithms.append(algo_els3)
468 pre_collector_path = create_pre_collector_path(
469 clusterizers=list_of_clusterizers,
470 isMC=isMC, max_events_per_run=max_events_per_run,
471 max_events_per_file=max_events_per_file,
472 useSVDGrouping=useSVDGrouping, useRawtimeForTracking=useRawtimeForTracking)
475 collector_managed_by_CAF = coll_els3
476 if "ELS3" in timeAlgorithms:
477 collector_managed_by_CAF = coll_els3
478 if "CoG6" in timeAlgorithms:
479 pre_collector_path.add_module(coll_cog6)
480 if "CoG3" in timeAlgorithms:
481 pre_collector_path.add_module(coll_cog3)
484 elif "CoG3" in timeAlgorithms:
485 collector_managed_by_CAF = coll_cog3
486 if "CoG6" in timeAlgorithms:
487 pre_collector_path.add_module(coll_cog6)
489 collector_managed_by_CAF = coll_cog6
493 collector=collector_managed_by_CAF,
494 algorithms=list_of_algorithms,
495 input_files=good_input_files,
496 pre_collector_path=pre_collector_path)
498 calibration.strategies = strategies.SequentialBoundaries
500 for algorithm
in calibration.algorithms:
501 algorithm.params = {
"iov_coverage": output_iov}
503 if "rawTimeCalibration" not in listOfMutedCalibrations:
504 list_of_calibrations.append(calibration)
510 SVDClustersOnTrackPrefix =
"SVDClustersOnTrack"
512 shift_clusterizers_onTracks = []
513 for alg
in timeAlgorithms:
514 cluster = create_svd_clusterizer(
515 name=f
"ClusterReconstruction_{alg}",
516 clusters=f
"{SVDClustersOnTrackPrefix}_{alg}",
517 shaper_digits=NEW_SHAPER_DIGITS_NAME,
519 shiftSVDClusterTime=
False)
520 shift_clusterizers_onTracks.append(cluster)
522 shift_pre_collector_path = create_pre_collector_path(
523 clusterizers=shift_clusterizers_onTracks,
524 isMC=isMC, max_events_per_run=max_events_per_run,
525 max_events_per_file=max_events_per_file,
526 useSVDGrouping=useSVDGrouping)
528 shift_collector = b2.register_module(
"SVDClusterTimeShifterCollector")
529 shift_collector.set_name(
"SVDClusterTimeShifterCollector")
530 shift_collector.param(
"MaxClusterSize", 6)
531 shift_collector.param(
"EventT0Name",
"EventT0")
532 shift_collector.param(
"SVDClustersOnTrackPrefix", f
"{SVDClustersOnTrackPrefix}")
533 shift_collector.param(
"TimeAlgorithms", timeAlgorithms)
535 shift_algo = SVDClusterTimeShifterAlgorithm(f
"{calType}_{now.isoformat()}_INFO:_"
536 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}")
537 shift_algo.setMinEntries(100)
538 shift_algo.setMaximumAllowedShift(15.)
539 shift_algo.setTimeAlgorithm(timeAlgorithms)
541 shift_calibration =
Calibration(
"SVDClusterTimeShifter",
542 collector=shift_collector,
543 algorithms=shift_algo,
544 input_files=good_input_files,
545 pre_collector_path=shift_pre_collector_path)
547 shift_calibration.strategies = strategies.SingleIOV
549 for algorithm
in shift_calibration.algorithms:
550 algorithm.params = {
"apply_iov": output_iov}
552 if "timeShiftCalibration" not in listOfMutedCalibrations:
553 list_of_calibrations.append(shift_calibration)
559 val_cog6 = create_svd_clusterizer(
560 name=f
"ClusterReconstruction{cog6_suffix}",
561 clusters=f
"SVDClusters{cog6_suffix}",
562 time_algorithm=
"CoG6")
564 val_cog6_onTracks = create_svd_clusterizer(
565 name=f
"ClusterReconstruction{cog6_suffix}_onTracks",
566 clusters=f
"SVDClusters{cog6_suffix}_onTracks",
567 reco_digits=NEW_RECO_DIGITS_NAME,
568 shaper_digits=NEW_SHAPER_DIGITS_NAME,
569 time_algorithm=
"CoG6")
571 val_cog3 = create_svd_clusterizer(
572 name=f
"ClusterReconstruction{cog3_suffix}",
573 clusters=f
"SVDClusters{cog3_suffix}",
574 time_algorithm=
"CoG3")
576 val_cog3_onTracks = create_svd_clusterizer(
577 name=f
"ClusterReconstruction{cog3_suffix}_onTracks",
578 clusters=f
"SVDClusters{cog3_suffix}_onTracks",
579 reco_digits=NEW_RECO_DIGITS_NAME,
580 shaper_digits=NEW_SHAPER_DIGITS_NAME,
581 time_algorithm=
"CoG3")
583 val_els3 = create_svd_clusterizer(
584 name=f
"ClusterReconstruction{els3_suffix}",
585 clusters=f
"SVDClusters{els3_suffix}",
586 time_algorithm=
"ELS3")
588 val_els3_onTracks = create_svd_clusterizer(
589 name=f
"ClusterReconstruction{els3_suffix}_onTracks",
590 clusters=f
"SVDClusters{els3_suffix}_onTracks",
591 reco_digits=NEW_RECO_DIGITS_NAME,
592 shaper_digits=NEW_SHAPER_DIGITS_NAME,
593 time_algorithm=
"ELS3")
595 val_coll_cog6 = create_validation_collector(
596 name=f
"SVDTimeValidationCollector{cog6_suffix}",
597 clusters=f
"SVDClusters{cog6_suffix}",
598 clusters_onTracks=f
"SVDClusters{cog6_suffix}_onTracks",
601 val_algo_cog6 = create_validation_algorithm(
602 prefix=val_coll_cog6.name(),
605 val_coll_cog3 = create_validation_collector(
606 name=f
"SVDTimeValidationCollector{cog3_suffix}",
607 clusters=f
"SVDClusters{cog3_suffix}",
608 clusters_onTracks=f
"SVDClusters{cog3_suffix}_onTracks",
611 val_algo_cog3 = create_validation_algorithm(
612 prefix=val_coll_cog3.name(),
615 val_coll_els3 = create_validation_collector(
616 name=f
"SVDTimeValidationCollector{els3_suffix}",
617 clusters=f
"SVDClusters{els3_suffix}",
618 clusters_onTracks=f
"SVDClusters{els3_suffix}_onTracks",
621 val_algo_els3 = create_validation_algorithm(
622 prefix=val_coll_els3.name(),
625 list_of_val_clusterizers = []
626 list_of_val_algorithms = []
627 for a
in timeAlgorithms:
629 list_of_val_clusterizers.append(val_cog3)
630 list_of_val_clusterizers.append(val_cog3_onTracks)
631 list_of_val_algorithms.append(val_algo_cog3)
633 list_of_val_clusterizers.append(val_cog6)
634 list_of_val_clusterizers.append(val_cog6_onTracks)
635 list_of_val_algorithms.append(val_algo_cog6)
637 list_of_val_clusterizers.append(val_els3)
638 list_of_val_clusterizers.append(val_els3_onTracks)
639 list_of_val_algorithms.append(val_algo_els3)
641 val_pre_collector_path = create_pre_collector_path(
642 clusterizers=list_of_val_clusterizers,
643 isMC=isMC, max_events_per_run=max_events_per_run,
644 max_events_per_file=max_events_per_file,
645 useSVDGrouping=useSVDGrouping, useRawtimeForTracking=useRawtimeForTracking,
648 val_collector_managed_by_CAF = val_coll_els3
649 if "ELS3" in timeAlgorithms:
650 val_collector_managed_by_CAF = val_coll_els3
651 if "CoG6" in timeAlgorithms:
652 val_pre_collector_path.add_module(val_coll_cog6)
653 if "CoG3" in timeAlgorithms:
654 val_pre_collector_path.add_module(val_coll_cog3)
655 elif "CoG3" in timeAlgorithms:
656 val_collector_managed_by_CAF = val_coll_cog3
657 if "CoG6" in timeAlgorithms:
658 val_pre_collector_path.add_module(val_coll_cog6)
660 val_collector_managed_by_CAF = val_coll_cog6
663 collector=val_collector_managed_by_CAF,
664 algorithms=list_of_val_algorithms,
665 input_files=good_input_files,
666 pre_collector_path=val_pre_collector_path)
668 val_calibration.strategies = strategies.SequentialRunByRun
670 for algorithm
in val_calibration.algorithms:
671 algorithm.params = {
"iov_coverage": output_iov}
673 if "timeValidation" not in listOfMutedCalibrations:
674 list_of_calibrations.append(val_calibration)
676 for item
in range(len(list_of_calibrations) - 1):
677 list_of_calibrations[item + 1].depends_on(list_of_calibrations[item])
679 return list_of_calibrations