11Script to perform the svd time calibration with the CoG6, CoG3 and ELS3 algorithms
22from tracking
import add_tracking_reconstruction
24from caf.framework
import Calibration
25from caf
import strategies
26from caf.utils
import IoV
27from prompt
import CalibrationSettings, INPUT_DATA_FILTERS
30from prompt.calibrations.caf_cdc
import settings
as cdc_tracking_calibration
32b2.set_log_level(b2.LogLevel.INFO)
36now = datetime.datetime.now()
38settings = CalibrationSettings(name=
"caf_svd_time",
39 expert_username=
"gdujany",
41 input_data_formats=[
"raw"],
42 input_data_names=[
"hadron_calib"],
43 input_data_filters={
"hadron_calib": [INPUT_DATA_FILTERS[
"Data Tag"][
"hadron_calib"],
44 INPUT_DATA_FILTERS[
"Beam Energy"][
"4S"],
45 INPUT_DATA_FILTERS[
"Beam Energy"][
"Continuum"],
46 INPUT_DATA_FILTERS[
"Run Type"][
"physics"],
47 INPUT_DATA_FILTERS[
"Magnet"][
"On"]]},
48 depends_on=[cdc_tracking_calibration],
50 "timeAlgorithms": [
"CoG3",
"ELS3",
"CoG6"],
51 "listOfMutedCalibrations": [],
52 "max_events_per_run": 10000,
53 "max_events_per_file": 5000,
55 "linearCutsOnCoG3":
False,
56 "upperLineParameters": [-94.0, 1.264],
57 "lowerLineParameters": [-134.0, 1.264],
58 "rangeRawTimeForIoVCoG6": [20., 80.],
59 "rangeRawTimeForIoVCoG3": [70., 140.],
60 "rangeRawTimeForIoVELS3": [20., 80.],
61 "useRawtimeForTracking":
False,
62 "useSVDGrouping":
True
69def remove_module(path, name):
71 new_path = b2.create_path()
72 for m
in path.modules():
74 new_path.add_module(m)
79NEW_RECO_DIGITS_NAME =
"SVDRecoDigitsFromTracks"
80NEW_SHAPER_DIGITS_NAME =
"SVDShaperDigitsFromTracks"
83def create_collector(name="SVDTimeCalibrationCollector",
84 clusters="SVDClustersFromTracks",
85 event_info="SVDEventInfo",
90 maxRawTimeForIoV=150.):
92 Simply creates a SVDTimeCalibrationCollector module with some options.
98 collector = b2.register_module("SVDTimeCalibrationCollector")
99 collector.set_name(name)
100 collector.param(
"SVDClustersFromTracksName", clusters)
101 collector.param(
"SVDEventInfoName", event_info)
102 collector.param(
"EventT0Name", event_t0)
103 collector.param(
"granularity", granularity)
104 collector.param(
"RawCoGBinWidth", rawBinWidth)
105 collector.param(
"RawTimeIoVMin", minRawTimeForIoV)
106 collector.param(
"RawTimeIoVMax", maxRawTimeForIoV)
111def create_validation_collector(name="SVDTimeValidationCollector",
112 clusters="SVDClusters",
113 clusters_onTracks="SVDClustersOnTracks",
117 Simply creates a SVDTimeCalibrationCollector module with some options.
123 collector = b2.register_module("SVDTimeValidationCollector")
124 collector.set_name(name)
125 collector.param(
"SVDClustersName", clusters)
126 collector.param(
"SVDClustersOnTracksName", clusters_onTracks)
127 collector.param(
"EventT0Name", event_t0)
128 collector.param(
"granularity", granularity)
137 linearCutsOnCoG3=False,
138 interceptUpperLine=-94.0,
139 angularCoefficientUpperLine=1.264,
140 interceptLowerLine=-134.0,
141 angularCoefficientLowerLine=1.264):
143 Simply creates a SVDCoGTimeCalibrationAlgorithm class with some options.
146 ROOT.Belle2.SVDCoGTimeCalibrationAlgorithm
148 from ROOT
import Belle2
149 from ROOT.Belle2
import SVDCoGTimeCalibrationAlgorithm
150 from ROOT.Belle2
import SVD3SampleCoGTimeCalibrationAlgorithm
151 from ROOT.Belle2
import SVD3SampleELSTimeCalibrationAlgorithm
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)
171def create_validation_algorithm(prefix="", min_entries=10000):
173 Simply creates a SVDCoGTimeValidationAlgorithm class with some options.
176 ROOT.Belle2.SVDCoGTimeValidationAlgorithm
178 from ROOT
import Belle2
179 from ROOT.Belle2
import SVDTimeValidationAlgorithm
180 algorithm = SVDTimeValidationAlgorithm()
182 algorithm.setPrefix(prefix)
183 algorithm.setMinEntries(min_entries)
188def 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)
216def 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 reuse 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, skip_full_grid_cdc_eventt0_if_svd_time_present=
False)
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")
307def get_calibrations(input_data, **kwargs):
309 from ROOT
import Belle2
310 from ROOT.Belle2
import SVDClusterTimeShifterAlgorithm
312 file_to_iov_physics = input_data[
"hadron_calib"]
313 expert_config = kwargs.get(
"expert_config")
314 timeAlgorithms = expert_config[
"timeAlgorithms"]
315 listOfMutedCalibrations = expert_config[
"listOfMutedCalibrations"]
316 max_events_per_run = expert_config[
"max_events_per_run"]
317 max_events_per_file = expert_config[
"max_events_per_file"]
318 isMC = expert_config[
"isMC"]
319 linearCutsOnCoG3 = expert_config[
"linearCutsOnCoG3"]
320 upperLineParameters = expert_config[
"upperLineParameters"]
321 lowerLineParameters = expert_config[
"lowerLineParameters"]
322 rangeRawTimeForIoVCoG6 = expert_config[
"rangeRawTimeForIoVCoG6"]
323 rangeRawTimeForIoVCoG3 = expert_config[
"rangeRawTimeForIoVCoG3"]
324 rangeRawTimeForIoVELS3 = expert_config[
"rangeRawTimeForIoVELS3"]
325 useSVDGrouping = expert_config[
"useSVDGrouping"]
326 useRawtimeForTracking = expert_config[
"useRawtimeForTracking"]
328 reduced_file_to_iov_physics = filter_by_max_events_per_run(file_to_iov_physics,
329 max_events_per_run, random_select=
True,
330 max_events_per_file=max_events_per_file)
331 good_input_files = list(reduced_file_to_iov_physics.keys())
333 b2.B2INFO(f
"Total number of files used as input = {len(good_input_files)}")
335 exps = [i.exp_low
for i
in reduced_file_to_iov_physics.values()]
336 runs = sorted([i.run_low
for i
in reduced_file_to_iov_physics.values()])
342 if not len(good_input_files):
343 print(
"No good input files found! Check that the input files have entries != 0!")
346 cog6_suffix =
"_CoG6"
347 cog3_suffix =
"_CoG3"
348 els3_suffix =
"_ELS3"
353 unique_id_cog6 = f
"SVDCoGTimeCalibrations_{calType}_{now.isoformat()}_INFO:_3rdOrderPol_TBindep_" \
354 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
355 print(f
"\nUniqueID_CoG6:\n{unique_id_cog6}")
357 unique_id_cog3 = f
"SVD3SampleCoGTimeCalibrations_{calType}_{now.isoformat()}_INFO:_3rdOrderPol_TBindep_" \
358 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
359 print(f
"\nUniqueID_CoG3:\n{unique_id_cog3}")
361 unique_id_els3 = f
"SVD3SampleELSTimeCalibrations_{calType}_{now.isoformat()}_INFO:_TBindep_" \
362 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
363 print(f
"\nUniqueID_ELS3:\n{unique_id_els3}")
365 requested_iov = kwargs.get(
"requested_iov",
None)
366 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
372 list_of_calibrations = []
378 cog6 = create_svd_clusterizer(
379 name=f
"ClusterReconstruction{cog6_suffix}",
380 clusters=f
"SVDClustersFromTracks{cog6_suffix}",
381 reco_digits=NEW_RECO_DIGITS_NAME,
382 shaper_digits=NEW_SHAPER_DIGITS_NAME,
383 time_algorithm=
"CoG6",
384 get_3sample_raw_time=
True)
386 cog3 = create_svd_clusterizer(
387 name=f
"ClusterReconstruction{cog3_suffix}",
388 clusters=f
"SVDClustersFromTracks{cog3_suffix}",
389 reco_digits=NEW_RECO_DIGITS_NAME,
390 shaper_digits=NEW_SHAPER_DIGITS_NAME,
391 time_algorithm=
"CoG3",
392 get_3sample_raw_time=
True)
394 els3 = create_svd_clusterizer(
395 name=f
"ClusterReconstruction{els3_suffix}",
396 clusters=f
"SVDClustersFromTracks{els3_suffix}",
397 reco_digits=NEW_RECO_DIGITS_NAME,
398 shaper_digits=NEW_SHAPER_DIGITS_NAME,
399 time_algorithm=
"ELS3",
400 get_3sample_raw_time=
True)
405 eventInfo =
"SVDEventInfo"
407 eventInfo =
"SVDEventInfoSim"
409 coll_cog6 = create_collector(
410 name=f
"SVDTimeCalibrationCollector{cog6_suffix}",
411 clusters=f
"SVDClustersFromTracks{cog6_suffix}",
412 event_info=eventInfo,
414 minRawTimeForIoV=rangeRawTimeForIoVCoG6[0],
415 maxRawTimeForIoV=rangeRawTimeForIoVCoG6[1])
417 algo_cog6 = create_algorithm(
419 prefix=coll_cog6.name(),
422 coll_cog3 = create_collector(
423 name=f
"SVDTimeCalibrationCollector{cog3_suffix}",
424 clusters=f
"SVDClustersFromTracks{cog3_suffix}",
425 event_info=eventInfo,
428 minRawTimeForIoV=rangeRawTimeForIoVCoG3[0],
429 maxRawTimeForIoV=rangeRawTimeForIoVCoG3[1])
431 algo_cog3 = create_algorithm(
433 prefix=coll_cog3.name(),
435 linearCutsOnCoG3=linearCutsOnCoG3,
436 interceptUpperLine=upperLineParameters[0],
437 angularCoefficientUpperLine=upperLineParameters[1],
438 interceptLowerLine=lowerLineParameters[0],
439 angularCoefficientLowerLine=lowerLineParameters[1])
441 coll_els3 = create_collector(
442 name=f
"SVDTimeCalibrationCollector{els3_suffix}",
443 clusters=f
"SVDClustersFromTracks{els3_suffix}",
444 event_info=eventInfo,
446 minRawTimeForIoV=rangeRawTimeForIoVELS3[0],
447 maxRawTimeForIoV=rangeRawTimeForIoVELS3[1])
449 algo_els3 = create_algorithm(
451 prefix=coll_els3.name(),
460 list_of_clusterizers = []
461 list_of_algorithms = []
462 for a
in timeAlgorithms:
464 list_of_clusterizers.append(cog3)
465 list_of_algorithms.append(algo_cog3)
467 list_of_clusterizers.append(cog6)
468 list_of_algorithms.append(algo_cog6)
470 list_of_clusterizers.append(els3)
471 list_of_algorithms.append(algo_els3)
473 pre_collector_path = create_pre_collector_path(
474 clusterizers=list_of_clusterizers,
475 isMC=isMC, max_events_per_run=max_events_per_run,
476 max_events_per_file=max_events_per_file,
477 useSVDGrouping=useSVDGrouping, useRawtimeForTracking=useRawtimeForTracking)
480 collector_managed_by_CAF = coll_els3
481 if "ELS3" in timeAlgorithms:
482 collector_managed_by_CAF = coll_els3
483 if "CoG6" in timeAlgorithms:
484 pre_collector_path.add_module(coll_cog6)
485 if "CoG3" in timeAlgorithms:
486 pre_collector_path.add_module(coll_cog3)
489 elif "CoG3" in timeAlgorithms:
490 collector_managed_by_CAF = coll_cog3
491 if "CoG6" in timeAlgorithms:
492 pre_collector_path.add_module(coll_cog6)
494 collector_managed_by_CAF = coll_cog6
498 collector=collector_managed_by_CAF,
499 algorithms=list_of_algorithms,
500 input_files=good_input_files,
501 pre_collector_path=pre_collector_path)
503 calibration.strategies = strategies.SequentialBoundaries
505 for algorithm
in calibration.algorithms:
506 algorithm.params = {
"iov_coverage": output_iov}
508 if "rawTimeCalibration" not in listOfMutedCalibrations:
509 list_of_calibrations.append(calibration)
515 SVDClustersOnTrackPrefix =
"SVDClustersOnTrack"
517 shift_clusterizers_onTracks = []
518 for alg
in timeAlgorithms:
519 cluster = create_svd_clusterizer(
520 name=f
"ClusterReconstruction_{alg}",
521 clusters=f
"{SVDClustersOnTrackPrefix}_{alg}",
522 shaper_digits=NEW_SHAPER_DIGITS_NAME,
524 shiftSVDClusterTime=
False)
525 shift_clusterizers_onTracks.append(cluster)
527 shift_pre_collector_path = create_pre_collector_path(
528 clusterizers=shift_clusterizers_onTracks,
529 isMC=isMC, max_events_per_run=max_events_per_run,
530 max_events_per_file=max_events_per_file,
531 useSVDGrouping=useSVDGrouping)
533 shift_collector = b2.register_module(
"SVDClusterTimeShifterCollector")
534 shift_collector.set_name(
"SVDClusterTimeShifterCollector")
535 shift_collector.param(
"MaxClusterSize", 6)
536 shift_collector.param(
"EventT0Name",
"EventT0")
537 shift_collector.param(
"SVDClustersOnTrackPrefix", f
"{SVDClustersOnTrackPrefix}")
538 shift_collector.param(
"TimeAlgorithms", timeAlgorithms)
540 shift_algo = SVDClusterTimeShifterAlgorithm(f
"{calType}_{now.isoformat()}_INFO:_"
541 f
"Exp{expNum}_runsFrom{firstRun}to{lastRun}")
542 shift_algo.setMinEntries(100)
543 shift_algo.setMaximumAllowedShift(15.)
544 shift_algo.setTimeAlgorithm(timeAlgorithms)
546 shift_calibration =
Calibration(
"SVDClusterTimeShifter",
547 collector=shift_collector,
548 algorithms=shift_algo,
549 input_files=good_input_files,
550 pre_collector_path=shift_pre_collector_path)
552 shift_calibration.strategies = strategies.SingleIOV
554 for algorithm
in shift_calibration.algorithms:
555 algorithm.params = {
"apply_iov": output_iov}
557 if "timeShiftCalibration" not in listOfMutedCalibrations:
558 list_of_calibrations.append(shift_calibration)
564 val_cog6 = create_svd_clusterizer(
565 name=f
"ClusterReconstruction{cog6_suffix}",
566 clusters=f
"SVDClusters{cog6_suffix}",
567 time_algorithm=
"CoG6")
569 val_cog6_onTracks = create_svd_clusterizer(
570 name=f
"ClusterReconstruction{cog6_suffix}_onTracks",
571 clusters=f
"SVDClusters{cog6_suffix}_onTracks",
572 reco_digits=NEW_RECO_DIGITS_NAME,
573 shaper_digits=NEW_SHAPER_DIGITS_NAME,
574 time_algorithm=
"CoG6")
576 val_cog3 = create_svd_clusterizer(
577 name=f
"ClusterReconstruction{cog3_suffix}",
578 clusters=f
"SVDClusters{cog3_suffix}",
579 time_algorithm=
"CoG3")
581 val_cog3_onTracks = create_svd_clusterizer(
582 name=f
"ClusterReconstruction{cog3_suffix}_onTracks",
583 clusters=f
"SVDClusters{cog3_suffix}_onTracks",
584 reco_digits=NEW_RECO_DIGITS_NAME,
585 shaper_digits=NEW_SHAPER_DIGITS_NAME,
586 time_algorithm=
"CoG3")
588 val_els3 = create_svd_clusterizer(
589 name=f
"ClusterReconstruction{els3_suffix}",
590 clusters=f
"SVDClusters{els3_suffix}",
591 time_algorithm=
"ELS3")
593 val_els3_onTracks = create_svd_clusterizer(
594 name=f
"ClusterReconstruction{els3_suffix}_onTracks",
595 clusters=f
"SVDClusters{els3_suffix}_onTracks",
596 reco_digits=NEW_RECO_DIGITS_NAME,
597 shaper_digits=NEW_SHAPER_DIGITS_NAME,
598 time_algorithm=
"ELS3")
600 val_coll_cog6 = create_validation_collector(
601 name=f
"SVDTimeValidationCollector{cog6_suffix}",
602 clusters=f
"SVDClusters{cog6_suffix}",
603 clusters_onTracks=f
"SVDClusters{cog6_suffix}_onTracks",
606 val_algo_cog6 = create_validation_algorithm(
607 prefix=val_coll_cog6.name(),
610 val_coll_cog3 = create_validation_collector(
611 name=f
"SVDTimeValidationCollector{cog3_suffix}",
612 clusters=f
"SVDClusters{cog3_suffix}",
613 clusters_onTracks=f
"SVDClusters{cog3_suffix}_onTracks",
616 val_algo_cog3 = create_validation_algorithm(
617 prefix=val_coll_cog3.name(),
620 val_coll_els3 = create_validation_collector(
621 name=f
"SVDTimeValidationCollector{els3_suffix}",
622 clusters=f
"SVDClusters{els3_suffix}",
623 clusters_onTracks=f
"SVDClusters{els3_suffix}_onTracks",
626 val_algo_els3 = create_validation_algorithm(
627 prefix=val_coll_els3.name(),
630 list_of_val_clusterizers = []
631 list_of_val_algorithms = []
632 for a
in timeAlgorithms:
634 list_of_val_clusterizers.append(val_cog3)
635 list_of_val_clusterizers.append(val_cog3_onTracks)
636 list_of_val_algorithms.append(val_algo_cog3)
638 list_of_val_clusterizers.append(val_cog6)
639 list_of_val_clusterizers.append(val_cog6_onTracks)
640 list_of_val_algorithms.append(val_algo_cog6)
642 list_of_val_clusterizers.append(val_els3)
643 list_of_val_clusterizers.append(val_els3_onTracks)
644 list_of_val_algorithms.append(val_algo_els3)
646 val_pre_collector_path = create_pre_collector_path(
647 clusterizers=list_of_val_clusterizers,
648 isMC=isMC, max_events_per_run=max_events_per_run,
649 max_events_per_file=max_events_per_file,
650 useSVDGrouping=useSVDGrouping, useRawtimeForTracking=useRawtimeForTracking,
653 val_collector_managed_by_CAF = val_coll_els3
654 if "ELS3" in timeAlgorithms:
655 val_collector_managed_by_CAF = val_coll_els3
656 if "CoG6" in timeAlgorithms:
657 val_pre_collector_path.add_module(val_coll_cog6)
658 if "CoG3" in timeAlgorithms:
659 val_pre_collector_path.add_module(val_coll_cog3)
660 elif "CoG3" in timeAlgorithms:
661 val_collector_managed_by_CAF = val_coll_cog3
662 if "CoG6" in timeAlgorithms:
663 val_pre_collector_path.add_module(val_coll_cog6)
665 val_collector_managed_by_CAF = val_coll_cog6
668 collector=val_collector_managed_by_CAF,
669 algorithms=list_of_val_algorithms,
670 input_files=good_input_files,
671 pre_collector_path=val_pre_collector_path)
673 val_calibration.strategies = strategies.SequentialRunByRun
675 for algorithm
in val_calibration.algorithms:
676 algorithm.params = {
"iov_coverage": output_iov}
678 if "timeValidation" not in listOfMutedCalibrations:
679 list_of_calibrations.append(val_calibration)
681 for item
in range(len(list_of_calibrations) - 1):
682 list_of_calibrations[item + 1].depends_on(list_of_calibrations[item])
684 return list_of_calibrations