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