Belle II Software  release-08-01-10
SVDCoGTimeCalibrationCAF.py
1 
8 
9 import basf2 as b2
10 
11 import os
12 import sys
13 import datetime
14 import glob
15 
16 from ROOT import Belle2, TFile
17 from ROOT.Belle2 import SVDCoGTimeCalibrationAlgorithm
18 
19 from caf.framework import CAF, Calibration, CentralDatabase
20 from caf import backends
21 from caf import strategies
22 
23 import reconstruction as reco
24 import svd as svd
25 
26 b2.set_log_level(b2.LogLevel.INFO)
27 input_branches = [
28  'SVDShaperDigitsFromTracks',
29  'EventT0',
30  'RawSVDs'
31  # 'SVDShaperDigits',
32  # 'SVDEventInfo'
33 ]
34 
35 now = datetime.datetime.now()
36 
37 
38 # pre_collector
39 
40 
41 def pre_collector():
42 
43  b2.B2INFO("Pre-collector")
44  pre_path = b2.create_path()
45  pre_path.add_module('RootInput', branchNames=input_branches)
46 
47  pre_path.add_module("Gearbox")
48  pre_path.add_module("Geometry", useDB=True)
49 
50  # run SVD unpacker
51  svd.add_svd_unpacker(pre_path)
52 
53  # run SVD reconstruction, changing names of StoreArray
54  reco.add_svd_reconstruction(pre_path)
55 
56  for moda in pre_path.modules():
57  if moda.name() == 'SVDCoGTimeEstimator':
58  moda.param("ShaperDigits", 'SVDShaperDigitsFromTracks')
59  moda.param("RecoDigits", 'SVDRecoDigitsFromTracks')
60  moda.param("CalibrationWithEventT0", False)
61  if moda.name() == 'SVDSimpleClusterizer':
62  moda.param("Clusters", 'SVDClustersFromTracks')
63  moda.param("RecoDigits", 'SVDRecoDigitsFromTracks')
64  moda.param("timeAlgorithm", 0)
65  if moda.name() == 'SVDSpacePointCreator':
66  moda.param("SVDClusters", 'SVDClustersFromTracks')
67 
68  pre_path = b2.remove_module(pre_path, 'SVDMissingAPVsClusterCreator')
69 
70  b2.print_path(pre_path)
71 
72  return pre_path
73 
74 
75 def SVDCoGTimeCalibration(files, tags, uniqueID):
76 
77  # Set-up re-processing path
78  path = b2.create_path()
79 
80  path.add_module('Progress')
81 
82  # collector setup
83  collector = b2.register_module('SVDTimeCalibrationCollector')
84  collector.param("SVDClustersFromTracksName", "SVDClustersFromTracks")
85  collector.param("SVDEventInfoName", "SVDEventInfo")
86  collector.param("EventT0Name", "EventT0")
87  collector.param("granularity", "run")
88 
89  # algorithm setup
90  algorithm = SVDCoGTimeCalibrationAlgorithm(uniqueID)
91  algorithm.setMinEntries(100)
92  algorithm.setAllowedTimeShift(2.)
93 
94  # calibration setup
95  calibration = Calibration('SVDCoGTime',
96  collector=collector,
97  algorithms=algorithm,
98  input_files=files,
99  pre_collector_path=pre_collector(),
100  database_chain=[CentralDatabase(tag) for tag in tags],
101  output_patterns=None,
102  max_files_per_collector_job=1,
103  backend_args=None
104  )
105 
106  calibration.strategies = strategies.SequentialBoundaries
107 
108  return calibration
109 
110 
111 if __name__ == "__main__":
112 
113  input_files = [os.path.abspath(file) for file in Belle2.Environment.Instance().getInputFilesOverride()]
114 
115  print(" ")
116  print("INPUT FILES")
117  print(" ")
118  print(input_files)
119  print(" ")
120 
121  good_input_files = []
122  runs = []
123  expNum = int()
124  for i in input_files:
125  file_list = glob.glob(i)
126  for f in file_list:
127  tf = TFile.Open(f)
128  tree = tf.Get("tree")
129  if tree.GetEntries() != 0:
130  good_input_files.append(f)
131  print(str(f))
132  inputStringSplit = f.split("/")
133  for string in inputStringSplit:
134  if string.startswith('r0'):
135  s_run = str(string)
136  runNum = runs.append(int(s_run[1:6]))
137  if string.startswith('e0'):
138  s_exp = str(string)
139  expNum = int(s_exp[1:5])
140 
141  runs.sort()
142 
143  firstRun = runs[0]
144  lastRun = runs[-1]
145 
146  if not len(good_input_files):
147  print("You have to specify some input file(s)\n"
148  "using the standard basf2 command line option - i")
149  print("See: basf2 -h")
150  sys.exit(1)
151 
152  # print(good_input_files)
153 
154  uniqueID = "SVDCoGTimeCalibrations_" + str(now.isoformat()) + "_INFO:_3rdOrderPol_TBindep_Exp" + \
155  str(expNum) + "_runsFrom" + str(firstRun) + "to" + str(lastRun)
156  print("")
157  print("UniqueID")
158  print("")
159  print(str(uniqueID))
160  print("")
161  b2.conditions.override_globaltags()
162  svdCoGCAF = SVDCoGTimeCalibration(good_input_files,
163  ["online_proc11",
164  "data_reprocessing_proc11_baseline",
165  "staging_data_reprocessing_proc11",
166  "svd_NOCoGCorrections"],
167  uniqueID)
168 
169  cal_fw = CAF()
170  cal_fw.add_calibration(svdCoGCAF)
171  cal_fw.backend = backends.LSF()
172  cal_fw.run()
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
def add_svd_unpacker(path)
Definition: __init__.py:276