Belle II Software  release-08-01-10
SVD3SampleCoGTimeCalibrationPromptCAF.py
1 
8 
9 import basf2 as b2
10 
11 import sys
12 import datetime
13 
14 from ROOT.Belle2 import SVD3SampleCoGTimeCalibrationAlgorithm
15 
16 from caf.framework import Calibration
17 from prompt import CalibrationSettings
18 from caf import strategies
19 from caf.utils import IoV
20 
21 import svd as svd
22 
23 b2.set_log_level(b2.LogLevel.INFO)
24 
25 now = datetime.datetime.now()
26 
27 settings = CalibrationSettings(name="SVD3SampleCoGTimeCalibrationPrompt",
28  expert_username="gdujany",
29  description=__doc__,
30  input_data_formats=["cdst"],
31  input_data_names=["hlt_hadron"],
32  depends_on=[])
33 
34 
35 # Definition of the class
36 
37 
38 def get_calibrations(input_data, **kwargs):
39 
40  # Set-up re-processing path
41  path = b2.create_path()
42 
43  path.add_module("Gearbox")
44  path.add_module("Geometry", useDB=True)
45 
46  # unpack raw svd data and produce: SVDEventInfo and SVDShaperDigits
48 
49  # run SVD reconstruction, changing names of StoreArray
51 
52  for moda in path.modules():
53  if moda.name() == 'SVDCoGTimeEstimator':
54  moda.param("ShaperDigits", 'SVDShaperDigitsFromTracks')
55  moda.param("RecoDigits", 'SVDRecoDigitsFromTracks')
56  moda.param("CalibrationWithEventT0", False)
57  if moda.name() == 'SVDSimpleClusterizer':
58  moda.param("Clusters", 'SVDClustersFromTracks')
59  moda.param("RecoDigits", 'SVDRecoDigitsFromTracks')
60  moda.param("ShaperDigits", 'SVDShaperDigitsFromTracks') # for 3TA
61  moda.param("timeAlgorithm", 1) # 1:CoG3, 2:ELS3
62  if moda.name() == 'SVDSpacePointCreator':
63  moda.param("SVDClusters", 'SVDClustersFromTracks')
64 
65  path = b2.remove_module(path, 'SVDMissingAPVsClusterCreator')
66 
67  file_to_iov_physics = input_data["hlt_hadron"]
68 
69  max_files_per_run = 1
70 
71  from prompt.utils import filter_by_max_files_per_run
72 
73  # reduced_file_to_iov_physics = filter_by_max_files_per_run(file_to_iov_physics, max_files_per_run)
74  reduced_file_to_iov_physics = filter_by_max_files_per_run(file_to_iov_physics, max_files_per_run, min_events_per_file=1)
75  # input_files_physics = list(reduced_file_to_iov_physics.keys())
76  good_input_files = list(reduced_file_to_iov_physics.keys())
77  b2.B2INFO(f"Total number of files actually used as input = {len(good_input_files)}")
78 
79  exps = [i.exp_low for i in reduced_file_to_iov_physics.values()]
80  runs = sorted([i.run_low for i in reduced_file_to_iov_physics.values()])
81 
82  firstRun = runs[0]
83  lastRun = runs[-1]
84  expNum = exps[0]
85 
86  if not len(good_input_files):
87  print("No good input files found! Check that the input files have entries != 0!")
88  sys.exit(1)
89 
90  uniqueID = "SVD3SampleCoGTimeCalibrations_Test_" + str(now.isoformat()) + "_INFO:_3rdOrderPol_TBindep_Exp" + \
91  str(expNum) + "_runsFrom" + str(firstRun) + "to" + str(lastRun)
92  print("")
93  print("UniqueID")
94  print("")
95  print(str(uniqueID))
96  print("")
97 
98  requested_iov = kwargs.get("requested_iov", None)
99  output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
100 
101  # collector setup
102  collector = b2.register_module('SVDTimeCalibrationCollector')
103  collector.param("SVDClustersFromTracksName", "SVDClustersFromTracks")
104  collector.param("SVDEventInfoName", "SVDEventInfo")
105  collector.param("EventT0Name", "EventT0")
106  collector.param("granularity", "run")
107 
108  # algorithm setup
109  algorithm = SVD3SampleCoGTimeCalibrationAlgorithm(uniqueID)
110  algorithm.setMinEntries(10000)
111 
112  # calibration setup
113  calibration = Calibration('SVD3SampleCoGTime',
114  collector=collector,
115  algorithms=algorithm,
116  input_files=good_input_files,
117  pre_collector_path=path,
118  )
119 
120  # calibration.pre_algorithms = pre_alg
121  # calibration.strategies = strategies.SequentialRunByRun
122  # calibration.strategies = strategies.SingleIOV
123  calibration.strategies = strategies.SequentialBoundaries
124 
125  for algorithm in calibration.algorithms:
126  algorithm.params = {"iov_coverage": output_iov}
127 
128  return [calibration]
def add_svd_unpacker(path)
Definition: __init__.py:276
def add_svd_reconstruction(path, isROIsimulation=False, createRecoDigits=False, applyMasking=False)
Definition: __init__.py:15