Belle II Software development
SVD3SampleCoGTimeCalibrationCAF.py
1
8
9import basf2 as b2
10
11import os
12import sys
13import datetime
14import glob
15
16from ROOT import Belle2, TFile
17from ROOT.Belle2 import SVD3SampleCoGTimeCalibrationAlgorithm # changed
18
19from caf.framework import CAF, Calibration, CentralDatabase
20from caf import backends
21from caf import strategies
22
23import reconstruction as reco
24import svd as svd
25
26b2.set_log_level(b2.LogLevel.INFO)
27input_branches = [
28 'SVDShaperDigitsFromTracks',
29 'EventT0',
30 'RawSVDs'
31 # 'SVDShaperDigits',
32 # 'SVDEventInfo'
33]
34
35now = datetime.datetime.now()
36
37
38# pre_collector
39
40
41def 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 if moda.name() == 'SVDSimpleClusterizer':
61 moda.param("Clusters", 'SVDClustersFromTracks')
62 moda.param("RecoDigits", 'SVDRecoDigitsFromTracks')
63 moda.param("ShaperDigits", 'SVDShaperDigitsFromTracks')
64 moda.param("timeAlgorithm", 1) # changed
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
75def 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 collector.param("RawCoGBinWidth", 0.5)
89
90 # algorithm setup
91 algorithm = SVD3SampleCoGTimeCalibrationAlgorithm(uniqueID) # changed
92 algorithm.setMinEntries(100)
93 algorithm.setAllowedTimeShift(2.)
94
95 # calibration setup
96 calibration = Calibration('SVD3SampleCoGTime', # changed
97 collector=collector,
98 algorithms=algorithm,
99 input_files=files,
100 pre_collector_path=pre_collector(),
101 database_chain=[CentralDatabase(tag) for tag in tags],
102 output_patterns=None,
103 max_files_per_collector_job=1,
104 backend_args=None
105 )
106
107 calibration.strategies = strategies.SequentialBoundaries
108
109 return calibration
110
111
112if __name__ == "__main__":
113
114 input_files = [os.path.abspath(file) for file in Belle2.Environment.Instance().getInputFilesOverride()]
115
116 print(" ")
117 print("INPUT FILES")
118 print(" ")
119 print(input_files)
120 print(" ")
121
122 good_input_files = []
123 runs = []
124 expNum = int()
125 for i in input_files:
126 file_list = glob.glob(i)
127 for f in file_list:
128 tf = TFile.Open(f)
129 tree = tf.Get("tree")
130 if tree.GetEntries() != 0:
131 good_input_files.append(f)
132 print(str(f))
133 inputStringSplit = f.split("/")
134 for string in inputStringSplit:
135 if string.startswith('r0'):
136 s_run = str(string)
137 runNum = runs.append(int(s_run[1:6]))
138 if string.startswith('e0'):
139 s_exp = str(string)
140 expNum = int(s_exp[1:5])
141
142 runs.sort()
143
144 firstRun = runs[0]
145 lastRun = runs[-1]
146
147 if not len(good_input_files):
148 print("You have to specify some input file(s)\n"
149 "using the standard basf2 command line option - i")
150 print("See: basf2 -h")
151 sys.exit(1)
152
153 # print(good_input_files)
154
155 uniqueID = "SVD3SampleCoGTimeCalibrations_" + str(now.isoformat()) + "_INFO:_3rdOrderPol_TBindep_Exp" + \
156 str(expNum) + "_runsFrom" + str(firstRun) + "to" + str(lastRun) # changed
157 print("")
158 print("UniqueID")
159 print("")
160 print(str(uniqueID))
161 print("")
162 b2.conditions.override_globaltags()
163 svdCoGCAF = SVDCoGTimeCalibration(good_input_files,
164 [ # "online_proc11",
165 "online", "Reco_master_patch_rel5"],
166 # "data_reprocessing_proc11_baseline",
167 # "staging_data_reprocessing_proc11",
168 # "data_reprocessing_proc10",
169 # "svd_NOCoGCorrections"],
170 uniqueID)
171
172 cal_fw = CAF()
173 cal_fw.add_calibration(svdCoGCAF)
174 cal_fw.backend = backends.LSF()
175 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:275