Belle II Software prerelease-11-00-00a
caf_svd_time.py
1#!/usr/bin/env python3
2
3
10'''
11Script to perform the svd time calibration with the CoG6, CoG3 and ELS3 algorithms
12'''
13
14import sys
15import datetime
16import random
17
18import basf2 as b2
19
20import rawdata as raw
21from softwaretrigger.constants import HLT_INPUT_OBJECTS
22from tracking import add_tracking_reconstruction
23
24from caf.framework import Calibration
25from caf import strategies
26from caf.utils import IoV
27from prompt import CalibrationSettings, INPUT_DATA_FILTERS
28from prompt.utils import filter_by_max_events_per_run
29
30from prompt.calibrations.caf_cdc import settings as cdc_tracking_calibration
31
32b2.set_log_level(b2.LogLevel.INFO)
33
34random.seed(42)
35
36now = datetime.datetime.now()
37
38settings = CalibrationSettings(name="caf_svd_time",
39 expert_username="giulio.dujany",
40 subsystem="svd",
41 description=__doc__,
42 input_data_formats=["raw"],
43 input_data_names=["hadron_calib"],
44 input_data_filters={"hadron_calib": [INPUT_DATA_FILTERS["Data Tag"]["hadron_calib"],
45 INPUT_DATA_FILTERS["Beam Energy"]["4S"],
46 INPUT_DATA_FILTERS["Beam Energy"]["Continuum"],
47 INPUT_DATA_FILTERS["Run Type"]["physics"],
48 INPUT_DATA_FILTERS["Magnet"]["On"]]},
49 depends_on=[cdc_tracking_calibration], # SVD time depends on CDC tracking calibration
50 expert_config={
51 "timeAlgorithms": ["CoG3", "ELS3", "CoG6"],
52 "listOfMutedCalibrations": [],
53 # "rawTimeCalibration", "timeShiftCalibration", "AbsoluteTimeShiftCalibration", "timeValidation"
54 "max_events_per_run": 10000,
55 "max_events_per_file": 5000,
56 "isMC": False,
57 "linearCutsOnCoG3": False,
58 "upperLineParameters": [-94.0, 1.264],
59 "lowerLineParameters": [-134.0, 1.264],
60 "rangeRawTimeForIoVCoG6": [20., 80.],
61 "rangeRawTimeForIoVCoG3": [70., 140.],
62 "rangeRawTimeForIoVELS3": [20., 80.],
63 "useRawtimeForTracking": False,
64 "useSVDGrouping": True
65 },
66 produced_payloads=["SVD3SampleCoGTimeCalibrations",
67 "SVD3SampleELSTimeCalibrations",
68 "SVDCoGTimeCalibrations",
69 "SVDClusterTimeShifter"])
70
71
73
74
75def remove_module(path, name):
76
77 new_path = b2.create_path()
78 for m in path.modules():
79 if name != m.name():
80 new_path.add_module(m)
81 return new_path
82
83
84
85NEW_RECO_DIGITS_NAME = "SVDRecoDigitsFromTracks"
86NEW_SHAPER_DIGITS_NAME = "SVDShaperDigitsFromTracks"
87
88
89def create_collector(name="SVDTimeCalibrationCollector",
90 clusters="SVDClustersFromTracks",
91 event_info="SVDEventInfo",
92 event_t0="EventT0",
93 rawBinWidth=2,
94 granularity="run",
95 minRawTimeForIoV=0.,
96 maxRawTimeForIoV=150.):
97 """
98 Simply creates a SVDTimeCalibrationCollector module with some options.
99
100 Returns:
101 pybasf2.Module
102 """
103
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)
113
114 return collector
115
116
117def create_validation_collector(name="SVDTimeValidationCollector",
118 clusters="SVDClusters",
119 clusters_onTracks="SVDClustersOnTracks",
120 event_t0="EventT0",
121 collector_module="SVDTimeValidationCollector",
122 time_algorithm="CoG6",
123 granularity="run"):
124 """
125 Simply creates a SVDTimeCalibrationCollector module with some options.
126
127 Returns:
128 pybasf2.Module
129 """
130
131 collector = b2.register_module(collector_module)
132 collector.set_name(name)
133 collector.param("SVDClustersName", clusters)
134 collector.param("SVDClustersOnTracksName", clusters_onTracks)
135 collector.param("EventT0Name", event_t0)
136 collector.param("granularity", granularity)
137 collector.param("TimeAlgorithm", time_algorithm)
138 return collector
139
140
141def create_algorithm(
142 unique_id,
143 prefix="",
144 min_entries=10000,
145 linearCutsOnCoG3=False,
146 interceptUpperLine=-94.0,
147 angularCoefficientUpperLine=1.264,
148 interceptLowerLine=-134.0,
149 angularCoefficientLowerLine=1.264):
150 """
151 Simply creates a SVDCoGTimeCalibrationAlgorithm class with some options.
152
153 Returns:
154 ROOT.Belle2.SVDCoGTimeCalibrationAlgorithm
155 """
156 from ROOT import Belle2 # noqa: make the Belle2 namespace available
157 from ROOT.Belle2 import SVDCoGTimeCalibrationAlgorithm
158 from ROOT.Belle2 import SVD3SampleCoGTimeCalibrationAlgorithm
159 from ROOT.Belle2 import SVD3SampleELSTimeCalibrationAlgorithm
160 if "CoG6" in prefix:
161 algorithm = SVDCoGTimeCalibrationAlgorithm(unique_id)
162 if "CoG3" in prefix:
163 algorithm = SVD3SampleCoGTimeCalibrationAlgorithm(unique_id)
164 algorithm.setTwoLineSelectionParameters(
165 linearCutsOnCoG3,
166 interceptUpperLine,
167 angularCoefficientUpperLine,
168 interceptLowerLine,
169 angularCoefficientLowerLine)
170 if "ELS3" in prefix:
171 algorithm = SVD3SampleELSTimeCalibrationAlgorithm(unique_id)
172 if prefix:
173 algorithm.setPrefix(prefix)
174 algorithm.setMinEntries(min_entries)
175
176 return algorithm
177
178
179def create_validation_algorithm(prefix="", min_entries=10000):
180 """
181 Simply creates a SVDCoGTimeValidationAlgorithm class with some options.
182
183 Returns:
184 ROOT.Belle2.SVDCoGTimeValidationAlgorithm
185 """
186 from ROOT import Belle2 # noqa: make the Belle2 namespace available
187 from ROOT.Belle2 import SVDTimeValidationAlgorithm
188
189 algorithm = SVDTimeValidationAlgorithm()
190
191 if prefix:
192 algorithm.setPrefix(prefix)
193 algorithm.setMinEntries(min_entries)
194
195 return algorithm
196
197
198def create_svd_clusterizer(name="ClusterReconstruction",
199 clusters="SVDClustersFromTracks",
200 reco_digits=None,
201 shaper_digits=None,
202 time_algorithm="CoG6",
203 get_3sample_raw_time=False,
204 shiftSVDClusterTime=None,
205 absoluteShiftSVDClusterTime=None,
206 ):
207 """
208 Simply creates a SVDClusterizer module with some options.
209
210 Returns:
211 pybasf2.Module
212 """
213
214 cluster = b2.register_module("SVDClusterizer")
215 cluster.set_name(name)
216 cluster.param("Clusters", clusters)
217 if shaper_digits is not None:
218 cluster.param("ShaperDigits", shaper_digits)
219 cluster.param("timeAlgorithm6Samples", time_algorithm)
220 if shiftSVDClusterTime is not None:
221 cluster.param("shiftSVDClusterTime", shiftSVDClusterTime)
222 cluster.param("useDB", False)
223 if get_3sample_raw_time:
224 cluster.param("returnClusterRawTime", True)
225 if absoluteShiftSVDClusterTime is not None:
226 cluster.param("absoluteShiftSVDClusterTime", absoluteShiftSVDClusterTime)
227 return cluster
228
229
230def create_pre_collector_path(
231 clusterizers,
232 isMC=False,
233 max_events_per_run=10000,
234 max_events_per_file=10000,
235 useSVDGrouping=True,
236 useRawtimeForTracking=False,
237 is_validation=False):
238 """
239 Create a basf2 path that runs a common reconstruction path and also runs several SVDSimpleClusterizer
240 modules with different configurations. This way they reuse the same reconstructed objects.
241
242 Parameters:
243 clusterizers (list[pybasf2.Module]): All the differently configured
244 SVDSimpleClusterizer modules. They should output to different datastore objects.
245 max_events_per_run (int, optional): Max events read per run. Defaults to 10000.
246 is_validation (bool, optional): Is used to produce the validation plots. Defaults to False.
247
248 returns:
249 pybasf2.Path
250 """
251 # Set-up re-processing path
252 path = b2.create_path()
253
254 # Read from file only what is needed
255 if not isMC:
256 path.add_module("RootInput", branchNames=HLT_INPUT_OBJECTS, entrySequences=[f'0:{max_events_per_file - 1}'])
257 else:
258 path.add_module("RootInput")
259
260 # unpack raw data to do the tracking
261 if not isMC:
262 raw.add_unpackers(path, components=['PXD', 'SVD', 'CDC'])
263 else:
264 path.add_module("Gearbox")
265 path.add_module("Geometry")
266
267 # proceed only if we acquired 6-sample strips
268 skim6SampleEvents = b2.register_module("SVD6SampleEventSkim")
269 path.add_module(skim6SampleEvents)
270 emptypath = b2.create_path()
271 skim6SampleEvents.if_false(emptypath)
272
273 if not isMC:
274 # run tracking reconstruction
275 add_tracking_reconstruction(path, append_full_grid_cdc_eventt0=True, skip_full_grid_cdc_eventt0_if_svd_time_present=False)
276 path = remove_module(path, "V0Finder")
277 if not is_validation:
278 # if we would like using the grouping (True by default), we should use the calibrated cluster time
279 # if we would like to use the raw time, than the cluster grouping parameters are OK only for CoG3
280 # in the reconstruction (default in reconstruction)
281 b2.set_module_parameters(path, 'SVDClusterizer', returnClusterRawTime=useRawtimeForTracking)
282 if useSVDGrouping:
283 if useRawtimeForTracking:
284 b2.set_module_parameters(path, 'SVDTimeGrouping',
285 forceGroupingFromDB=False,
286 useParamFromDB=False,
287 isEnabledIn6Samples=True,
288 acceptSigmaN=5,
289 expectedSignalTimeCenter=100,
290 expectedSignalTimeMin=70, expectedSignalTimeMax=130,
291 tRangeLow=-20, tRangeHigh=220)
292 b2.set_module_parameters(path, 'SVDSpacePointCreator',
293 forceGroupingFromDB=False,
294 useParamFromDB=False,
295 useSVDGroupInfoIn6Sample=True,
296 numberOfSignalGroups=2, formSingleSignalGroup=True)
297 else:
298 b2.set_module_parameters(path, 'SVDTimeGrouping',
299 forceGroupingFromDB=False,
300 useParamFromDB=False,
301 isEnabledIn6Samples=True, acceptSigmaN=3,
302 expectedSignalTimeMin=-30, expectedSignalTimeMax=30)
303 b2.set_module_parameters(path, 'SVDSpacePointCreator',
304 forceGroupingFromDB=False,
305 useSVDGroupInfoIn6Sample=True)
306 else:
307 b2.set_module_parameters(path, 'SVDTimeGrouping', forceGroupingFromDB=False, isEnabledIn6Samples=False)
308 b2.set_module_parameters(path, 'SVDSpacePointCreator', forceGroupingFromDB=False, useSVDGroupInfoIn6Sample=False)
309
310 # repeat svd reconstruction using only SVDShaperDigitsFromTracks
311 path.add_module("SVDShaperDigitsFromTracks")
312
313 for cluster in clusterizers:
314 path.add_module(cluster)
315
316 path = remove_module(path, "SVDMissingAPVsClusterCreator")
317
318 return path
319
320
321def get_calibrations(input_data, **kwargs):
322
323 from ROOT import Belle2 # noqa: make the Belle2 namespace available
324 from ROOT.Belle2 import SVDClusterTimeShifterAlgorithm, SVDClusterAbsoluteTimeShifterAlgorithm
325
326 file_to_iov_physics = input_data["hadron_calib"]
327 expert_config = kwargs.get("expert_config")
328 timeAlgorithms = expert_config["timeAlgorithms"]
329 listOfMutedCalibrations = expert_config["listOfMutedCalibrations"]
330 max_events_per_run = expert_config["max_events_per_run"] # Maximum number of events selected per each run
331 max_events_per_file = expert_config["max_events_per_file"] # Maximum number of events selected per each file
332 isMC = expert_config["isMC"]
333 linearCutsOnCoG3 = expert_config["linearCutsOnCoG3"]
334 upperLineParameters = expert_config["upperLineParameters"]
335 lowerLineParameters = expert_config["lowerLineParameters"]
336 rangeRawTimeForIoVCoG6 = expert_config["rangeRawTimeForIoVCoG6"]
337 rangeRawTimeForIoVCoG3 = expert_config["rangeRawTimeForIoVCoG3"]
338 rangeRawTimeForIoVELS3 = expert_config["rangeRawTimeForIoVELS3"]
339 useSVDGrouping = expert_config["useSVDGrouping"]
340 useRawtimeForTracking = expert_config["useRawtimeForTracking"]
341
342 reduced_file_to_iov_physics = filter_by_max_events_per_run(file_to_iov_physics,
343 max_events_per_run, random_select=True,
344 max_events_per_file=max_events_per_file)
345 good_input_files = list(reduced_file_to_iov_physics.keys())
346
347 b2.B2INFO(f"Total number of files used as input = {len(good_input_files)}")
348
349 exps = [i.exp_low for i in reduced_file_to_iov_physics.values()]
350 runs = sorted([i.run_low for i in reduced_file_to_iov_physics.values()])
351
352 firstRun = runs[0]
353 lastRun = runs[-1]
354 expNum = exps[0]
355
356 if not len(good_input_files):
357 print("No good input files found! Check that the input files have entries != 0!")
358 sys.exit(1)
359
360 cog6_suffix = "_CoG6"
361 cog3_suffix = "_CoG3"
362 els3_suffix = "_ELS3"
363
364 calType = "Prompt"
365 if isMC:
366 calType = "MC"
367 unique_id_cog6 = f"SVDCoGTimeCalibrations_{calType}_{now.isoformat()}_INFO:_3rdOrderPol_TBindep_" \
368 f"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
369 print(f"\nUniqueID_CoG6:\n{unique_id_cog6}")
370
371 unique_id_cog3 = f"SVD3SampleCoGTimeCalibrations_{calType}_{now.isoformat()}_INFO:_3rdOrderPol_TBindep_" \
372 f"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
373 print(f"\nUniqueID_CoG3:\n{unique_id_cog3}")
374
375 unique_id_els3 = f"SVD3SampleELSTimeCalibrations_{calType}_{now.isoformat()}_INFO:_TBindep_" \
376 f"Exp{expNum}_runsFrom{firstRun}to{lastRun}"
377 print(f"\nUniqueID_ELS3:\n{unique_id_els3}")
378
379 requested_iov = kwargs.get("requested_iov", None)
380 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
381
382
386 list_of_calibrations = []
387
388
391
392 cog6 = create_svd_clusterizer(
393 name=f"ClusterReconstruction{cog6_suffix}",
394 clusters=f"SVDClustersFromTracks{cog6_suffix}",
395 reco_digits=NEW_RECO_DIGITS_NAME,
396 shaper_digits=NEW_SHAPER_DIGITS_NAME,
397 time_algorithm="CoG6",
398 get_3sample_raw_time=True)
399
400 cog3 = create_svd_clusterizer(
401 name=f"ClusterReconstruction{cog3_suffix}",
402 clusters=f"SVDClustersFromTracks{cog3_suffix}",
403 reco_digits=NEW_RECO_DIGITS_NAME,
404 shaper_digits=NEW_SHAPER_DIGITS_NAME,
405 time_algorithm="CoG3",
406 get_3sample_raw_time=True)
407
408 els3 = create_svd_clusterizer(
409 name=f"ClusterReconstruction{els3_suffix}",
410 clusters=f"SVDClustersFromTracks{els3_suffix}",
411 reco_digits=NEW_RECO_DIGITS_NAME,
412 shaper_digits=NEW_SHAPER_DIGITS_NAME,
413 time_algorithm="ELS3",
414 get_3sample_raw_time=True)
415
416
419 eventInfo = "SVDEventInfo"
420 if isMC:
421 eventInfo = "SVDEventInfoSim"
422
423 coll_cog6 = create_collector(
424 name=f"SVDTimeCalibrationCollector{cog6_suffix}",
425 clusters=f"SVDClustersFromTracks{cog6_suffix}",
426 event_info=eventInfo,
427 event_t0="EventT0",
428 minRawTimeForIoV=rangeRawTimeForIoVCoG6[0],
429 maxRawTimeForIoV=rangeRawTimeForIoVCoG6[1])
430
431 algo_cog6 = create_algorithm(
432 unique_id_cog6,
433 prefix=coll_cog6.name(),
434 min_entries=10000)
435
436 coll_cog3 = create_collector(
437 name=f"SVDTimeCalibrationCollector{cog3_suffix}",
438 clusters=f"SVDClustersFromTracks{cog3_suffix}",
439 event_info=eventInfo,
440 rawBinWidth=1,
441 event_t0="EventT0",
442 minRawTimeForIoV=rangeRawTimeForIoVCoG3[0],
443 maxRawTimeForIoV=rangeRawTimeForIoVCoG3[1])
444
445 algo_cog3 = create_algorithm(
446 unique_id_cog3,
447 prefix=coll_cog3.name(),
448 min_entries=10000,
449 linearCutsOnCoG3=linearCutsOnCoG3,
450 interceptUpperLine=upperLineParameters[0],
451 angularCoefficientUpperLine=upperLineParameters[1],
452 interceptLowerLine=lowerLineParameters[0],
453 angularCoefficientLowerLine=lowerLineParameters[1])
454
455 coll_els3 = create_collector(
456 name=f"SVDTimeCalibrationCollector{els3_suffix}",
457 clusters=f"SVDClustersFromTracks{els3_suffix}",
458 event_info=eventInfo,
459 event_t0="EventT0",
460 minRawTimeForIoV=rangeRawTimeForIoVELS3[0],
461 maxRawTimeForIoV=rangeRawTimeForIoVELS3[1])
462
463 algo_els3 = create_algorithm(
464 unique_id_els3,
465 prefix=coll_els3.name(),
466 min_entries=10000)
467
468
472
473 # Check what time algorithms (CoG6, CoG3, ELS3) will be calibrated according to expert input
474 list_of_clusterizers = []
475 list_of_algorithms = []
476 for a in timeAlgorithms:
477 if a == "CoG3":
478 list_of_clusterizers.append(cog3)
479 list_of_algorithms.append(algo_cog3)
480 if a == "CoG6":
481 list_of_clusterizers.append(cog6)
482 list_of_algorithms.append(algo_cog6)
483 if a == "ELS3":
484 list_of_clusterizers.append(els3)
485 list_of_algorithms.append(algo_els3)
486
487 pre_collector_path = create_pre_collector_path(
488 clusterizers=list_of_clusterizers,
489 isMC=isMC, max_events_per_run=max_events_per_run,
490 max_events_per_file=max_events_per_file,
491 useSVDGrouping=useSVDGrouping, useRawtimeForTracking=useRawtimeForTracking)
492
493 # Decide what collector will be "managed" by the CAF
494 collector_managed_by_CAF = coll_els3
495 if "ELS3" in timeAlgorithms:
496 collector_managed_by_CAF = coll_els3
497 if "CoG6" in timeAlgorithms:
498 pre_collector_path.add_module(coll_cog6)
499 if "CoG3" in timeAlgorithms:
500 pre_collector_path.add_module(coll_cog3)
501 # We leave the coll_els3 to be the one "managed" by the CAF
502
503 elif "CoG3" in timeAlgorithms:
504 collector_managed_by_CAF = coll_cog3
505 if "CoG6" in timeAlgorithms:
506 pre_collector_path.add_module(coll_cog6)
507 else:
508 collector_managed_by_CAF = coll_cog6
509
510 # calibration setup
511 calibration = Calibration("SVDTime",
512 collector=collector_managed_by_CAF, # The other collectors are in the pre_collector_path itself
513 algorithms=list_of_algorithms,
514 input_files=good_input_files,
515 pre_collector_path=pre_collector_path)
516
517 calibration.strategies = strategies.SequentialBoundaries
518
519 for algorithm in calibration.algorithms:
520 algorithm.params = {"iov_coverage": output_iov}
521
522 if "rawTimeCalibration" not in listOfMutedCalibrations:
523 list_of_calibrations.append(calibration)
524
525
528
529 SVDClustersOnTrackPrefix = "SVDClustersOnTrack"
530
531 shift_clusterizers_onTracks = []
532 for alg in timeAlgorithms:
533 cluster = create_svd_clusterizer(
534 name=f"ClusterReconstruction_{alg}",
535 clusters=f"{SVDClustersOnTrackPrefix}_{alg}",
536 shaper_digits=NEW_SHAPER_DIGITS_NAME,
537 time_algorithm=alg,
538 shiftSVDClusterTime=False)
539 shift_clusterizers_onTracks.append(cluster)
540
541 shift_pre_collector_path = create_pre_collector_path(
542 clusterizers=shift_clusterizers_onTracks,
543 isMC=isMC, max_events_per_run=max_events_per_run,
544 max_events_per_file=max_events_per_file,
545 useSVDGrouping=useSVDGrouping)
546
547 shift_collector = b2.register_module("SVDClusterTimeShifterCollector")
548 shift_collector.set_name("SVDClusterTimeShifterCollector")
549 shift_collector.param("MaxClusterSize", 6)
550 shift_collector.param("EventT0Name", "EventT0")
551 shift_collector.param("SVDClustersOnTrackPrefix", f"{SVDClustersOnTrackPrefix}")
552 shift_collector.param("TimeAlgorithms", timeAlgorithms)
553
554 shift_algo = SVDClusterTimeShifterAlgorithm(f"{calType}_{now.isoformat()}_INFO:_"
555 f"Exp{expNum}_runsFrom{firstRun}to{lastRun}")
556 shift_algo.setMinEntries(100)
557 shift_algo.setMaximumAllowedShift(15.)
558 shift_algo.setTimeAlgorithm(timeAlgorithms)
559
560 shift_calibration = Calibration("SVDClusterTimeShifter",
561 collector=shift_collector,
562 algorithms=shift_algo,
563 input_files=good_input_files,
564 pre_collector_path=shift_pre_collector_path)
565
566 shift_calibration.strategies = strategies.SingleIOV
567
568 for algorithm in shift_calibration.algorithms:
569 algorithm.params = {"apply_iov": output_iov}
570
571 if "timeShiftCalibration" not in listOfMutedCalibrations:
572 list_of_calibrations.append(shift_calibration)
573
574
577
578 SVDClustersOnTrackPrefix = "SVDClustersOnTrack"
579
580 absolute_shift_clusterizers_onTracks = []
581
582 for alg in timeAlgorithms:
583 cluster = create_svd_clusterizer(
584 name=f"ClusterReconstruction_{alg}",
585 clusters=f"{SVDClustersOnTrackPrefix}_{alg}",
586 shaper_digits=NEW_SHAPER_DIGITS_NAME,
587 time_algorithm=alg,
588 absoluteShiftSVDClusterTime=False,
589 )
590 absolute_shift_clusterizers_onTracks.append(cluster)
591
592 absolute_shift_pre_collector_path = create_pre_collector_path(
593 clusterizers=absolute_shift_clusterizers_onTracks,
594 isMC=isMC, max_events_per_run=max_events_per_run,
595 max_events_per_file=max_events_per_file,
596 useSVDGrouping=useSVDGrouping)
597
598 absolute_shift_collector = b2.register_module("SVDClusterAbsoluteTimeShifterCollector")
599 absolute_shift_collector.set_name("SVDClusterAbsoluteTimeShifterCollector")
600 absolute_shift_collector.param("EventT0Name", "EventT0")
601 absolute_shift_collector.param("SVDClustersOnTrackPrefix", f"{SVDClustersOnTrackPrefix}")
602 absolute_shift_collector.param("TimeAlgorithms", timeAlgorithms)
603
604 absolute_shift_algo = SVDClusterAbsoluteTimeShifterAlgorithm(f"{calType}_{now.isoformat()}_INFO:_"
605 f"Exp{expNum}_runsFrom{firstRun}to{lastRun}")
606 absolute_shift_algo.setMinEntries(100)
607 absolute_shift_algo.setMaximumAllowedShift(15.)
608 absolute_shift_algo.setTimeAlgorithm(timeAlgorithms)
609 print(f'Time algorithms for absolute shift: {timeAlgorithms}')
610 absolute_shift_calibration = Calibration("SVDClusterAbsoluteTimeShift",
611 collector=absolute_shift_collector,
612 algorithms=absolute_shift_algo,
613 input_files=good_input_files,
614 pre_collector_path=absolute_shift_pre_collector_path)
615
616 absolute_shift_calibration.strategies = strategies.SequentialBoundaries
617
618 for algorithm in absolute_shift_calibration.algorithms:
619 algorithm.params = {"apply_iov": output_iov}
620 if "AbsoluteTimeShiftCalibration" not in listOfMutedCalibrations:
621 list_of_calibrations.append(absolute_shift_calibration)
622
623
626
627 val_cog6 = create_svd_clusterizer(
628 name=f"ClusterReconstruction{cog6_suffix}",
629 clusters=f"SVDClusters{cog6_suffix}",
630 time_algorithm="CoG6")
631
632 val_cog6_onTracks = create_svd_clusterizer(
633 name=f"ClusterReconstruction{cog6_suffix}_onTracks",
634 clusters=f"SVDClusters{cog6_suffix}_onTracks",
635 reco_digits=NEW_RECO_DIGITS_NAME,
636 shaper_digits=NEW_SHAPER_DIGITS_NAME,
637 time_algorithm="CoG6")
638
639 val_cog3 = create_svd_clusterizer(
640 name=f"ClusterReconstruction{cog3_suffix}",
641 clusters=f"SVDClusters{cog3_suffix}",
642 time_algorithm="CoG3")
643
644 val_cog3_onTracks = create_svd_clusterizer(
645 name=f"ClusterReconstruction{cog3_suffix}_onTracks",
646 clusters=f"SVDClusters{cog3_suffix}_onTracks",
647 reco_digits=NEW_RECO_DIGITS_NAME,
648 shaper_digits=NEW_SHAPER_DIGITS_NAME,
649 time_algorithm="CoG3")
650
651 val_els3 = create_svd_clusterizer(
652 name=f"ClusterReconstruction{els3_suffix}",
653 clusters=f"SVDClusters{els3_suffix}",
654 time_algorithm="ELS3")
655
656 val_els3_onTracks = create_svd_clusterizer(
657 name=f"ClusterReconstruction{els3_suffix}_onTracks",
658 clusters=f"SVDClusters{els3_suffix}_onTracks",
659 reco_digits=NEW_RECO_DIGITS_NAME,
660 shaper_digits=NEW_SHAPER_DIGITS_NAME,
661 time_algorithm="ELS3")
662
663 val_coll_cog6 = create_validation_collector(
664 name=f"SVDTimeValidationCollector{cog6_suffix}",
665 clusters=f"SVDClusters{cog6_suffix}",
666 clusters_onTracks=f"SVDClusters{cog6_suffix}_onTracks",
667 event_t0="EventT0",
668 time_algorithm="CoG6")
669
670 val_algo_cog6 = create_validation_algorithm(
671 prefix=val_coll_cog6.name(),
672 min_entries=10000)
673
674 val_coll_cog3 = create_validation_collector(
675 name=f"SVDTimeValidationCollector{cog3_suffix}",
676 clusters=f"SVDClusters{cog3_suffix}",
677 clusters_onTracks=f"SVDClusters{cog3_suffix}_onTracks",
678 event_t0="EventT0",
679 time_algorithm="CoG3")
680
681 val_algo_cog3 = create_validation_algorithm(
682 prefix=val_coll_cog3.name(),
683 min_entries=10000)
684
685 val_coll_els3 = create_validation_collector(
686 name=f"SVDTimeValidationCollector{els3_suffix}",
687 clusters=f"SVDClusters{els3_suffix}",
688 clusters_onTracks=f"SVDClusters{els3_suffix}_onTracks",
689 event_t0="EventT0",
690 time_algorithm="ELS3")
691
692 val_algo_els3 = create_validation_algorithm(
693 prefix=val_coll_els3.name(),
694 min_entries=10000)
695
696 list_of_val_clusterizers = []
697 list_of_val_algorithms = []
698 for a in timeAlgorithms:
699 if a == "CoG3":
700 list_of_val_clusterizers.append(val_cog3)
701 list_of_val_clusterizers.append(val_cog3_onTracks)
702 list_of_val_algorithms.append(val_algo_cog3)
703 if a == "CoG6":
704 list_of_val_clusterizers.append(val_cog6)
705 list_of_val_clusterizers.append(val_cog6_onTracks)
706 list_of_val_algorithms.append(val_algo_cog6)
707 if a == "ELS3":
708 list_of_val_clusterizers.append(val_els3)
709 list_of_val_clusterizers.append(val_els3_onTracks)
710 list_of_val_algorithms.append(val_algo_els3)
711
712 val_pre_collector_path = create_pre_collector_path(
713 clusterizers=list_of_val_clusterizers,
714 isMC=isMC, max_events_per_run=max_events_per_run,
715 max_events_per_file=max_events_per_file,
716 useSVDGrouping=useSVDGrouping, useRawtimeForTracking=useRawtimeForTracking,
717 is_validation=True)
718
719 val_collector_managed_by_CAF = val_coll_els3
720 if "ELS3" in timeAlgorithms:
721 val_collector_managed_by_CAF = val_coll_els3
722 if "CoG6" in timeAlgorithms:
723 val_pre_collector_path.add_module(val_coll_cog6)
724 if "CoG3" in timeAlgorithms:
725 val_pre_collector_path.add_module(val_coll_cog3)
726 elif "CoG3" in timeAlgorithms:
727 val_collector_managed_by_CAF = val_coll_cog3
728 if "CoG6" in timeAlgorithms:
729 val_pre_collector_path.add_module(val_coll_cog6)
730 else:
731 val_collector_managed_by_CAF = val_coll_cog6
732
733 val_calibration = Calibration("SVDTimeValidation",
734 collector=val_collector_managed_by_CAF,
735 algorithms=list_of_val_algorithms,
736 input_files=good_input_files,
737 pre_collector_path=val_pre_collector_path)
738
739 for algorithm in val_calibration.algorithms:
740 algorithm.params = {"iov_coverage": output_iov}
741
742 if "timeValidation" not in listOfMutedCalibrations:
743 list_of_calibrations.append(val_calibration)
744
745 print(f'List of calib: {list_of_calibrations}')
746 for item in range(len(list_of_calibrations) - 1):
747 # Absolute time shift calibration does not depend on any other calibration
748 print(f'Item: {item}')
749 print(f'calib item: {list_of_calibrations[item]}')
750 print(f'name of calib item: {list_of_calibrations[item].name}')
751
752 print(f'calibration name: {list_of_calibrations[item].name}')
753 if "AbsoluteTimeShiftCalibration" in list_of_calibrations[item].name:
754 if len(list_of_calibrations) > 1:
755 print(" WARNING : AbsoluteTimeShiftCalibration should not depend on any other calibration.")
756 print("Not setting dependencies to or from other calibrations.")
757 continue
758 #  and make sure no other calibration depends on it
759 elif "AbsoluteTimeShiftCalibration" in list_of_calibrations[item + 1].name:
760 # if item + 1 is not the last calibration in the list
761 if item + 1 < len(list_of_calibrations) - 1:
762 #  set the dependency to the next one
763 list_of_calibrations[item + 2].depends_on(list_of_calibrations[item])
764 #  no else because in this case it's the last calibration in the list
765 else:
766 list_of_calibrations[item + 1].depends_on(list_of_calibrations[item])
767
768 return list_of_calibrations