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