Belle II Software development
svdGroupingPerformance.py
1#!/usr/bin/env python3
2
3
10
11
18
19import basf2 as b2
20from basf2 import conditions as b2conditions
21from svd.executionTime_utils import SVDExtraEventStatisticsModule
22import rawdata as raw
23import tracking as trk
24import simulation as sim
25import argparse
26from background import get_background_files
27import generators as ge
28
29from ROOT import Belle2, TH1F, TH2F, TFile, TMath
30import math
31
32
33parser = argparse.ArgumentParser(description=__doc__)
34parser.add_argument("--seed", default="1",
35 help="seed")
36parser.add_argument("--fileDir", default="./",
37 help="Output File Dir")
38parser.add_argument("--fileTag", default="test",
39 help="Output File Tag")
40parser.add_argument("--moduleName", default="SVDGroupingPerformance",
41 help="Module Prefix")
42parser.add_argument("--isMC", action="store_true",
43 help="Use Simulation")
44parser.add_argument("--isRawTime", action="store_true",
45 help="Compute Raw SVD Time")
46parser.add_argument("--doSVDGrouping", action="store_true",
47 help="Perform grouping of SVD Clusters")
48parser.add_argument("--signalLifetime", type=float, default=30,
49 help="Lifetime of Signal when computing exponential-weigth for sorting signal groups")
50parser.add_argument("--numberOfSignalGroups", type=int, default=1,
51 help="Select only few signal groups")
52parser.add_argument("--formSingleSignalGroup", action="store_true",
53 help="Assign groupId 0 to every signal groups")
54parser.add_argument("--useSVDGroupInfo", action="store_true",
55 help="Use SVD Grouping info in SVDSpacePointCreator")
56parser.add_argument("--CoG3TimeCalibration_bucket36", action="store_true",
57 help="SVD Time calibration")
58parser.add_argument("--CoG3TimeCalibration_bucket32", action="store_true",
59 help="SVD Time calibration")
60parser.add_argument("--is3sample", action="store_true",
61 help="Emulate SVD 3 samples")
62parser.add_argument("--executionTime", action="store_true",
63 help="Store exection time tree")
64parser.add_argument("--test", action="store_true",
65 help="Test with small numbers of events")
66args = parser.parse_args()
67b2.B2INFO(f"Steering file args = {args}")
68
69if args.test:
70 b2.set_log_level(b2.LogLevel.DEBUG)
71 b2.set_debug_level(21)
72
73
74outputFileTag = ""
75if args.isMC:
76 outputFileTag += "_MC"
77if args.is3sample:
78 outputFileTag += "_emulated3sample"
79if args.isRawTime:
80 outputFileTag += "_RawTime"
81if args.doSVDGrouping:
82 outputFileTag += "_Grouping"
83 outputFileTag += "_sigLifeTime" + str(int(args.signalLifetime))
84 outputFileTag += "_Signal" + str(int(args.numberOfSignalGroups))
85 if args.formSingleSignalGroup:
86 outputFileTag += "_SuperGroup"
87 if args.useSVDGroupInfo:
88 outputFileTag += "_UsedInSPs"
89outputFileTag += "_" + str(args.fileTag)
90
91
92minTime = -160.
93maxTime = 160.
94sigLoc = 0
95sigMin = -50
96sigMax = 50
97if args.is3sample:
98 sigMin = -25
99 sigMax = 25
100if args.isRawTime:
101 minTime = -20.
102 maxTime = 200.
103 sigLoc = 100
104 sigMin = 70
105 sigMax = 130
106
107
108class SVDGroupingPerformance(b2.Module):
109 ''' check cluster grouping'''
110
111 def initialize(self):
112 '''define histograms'''
113
114 usedBin1 = 100
115 usedBin2 = 2000
116 eclMinVal = 19.5
117 eclMaxVal = 1100.5
118
119 timeBin = int(maxTime - minTime)
120
121
122 self.TH1F_Index = {}
123 self.TH1F_Store = []
124 TH1F_Store_Count = 0
125
126 self.TH2F_Index = {}
127 self.TH2F_Store = []
128 TH2F_Store_Count = 0
129
130 self.reso_TH2D_Histogram_Index = {}
131 self.reso_TH2D_Histograms = []
132 reso_TH2D_Histograms_Count = 0
133
134 self.outputFileName = str(args.fileDir) + str(args.moduleName) + outputFileTag
135 self.f = TFile(self.outputFileName + ".root", "RECREATE")
136
137
138 # EventT0s
139
140 self.TH1F_Store.append(TH1F("th1f_svdEventT0", "SVD EventT0", 500, -50., 50.))
141 self.TH1F_Store[-1].GetXaxis().SetTitle("SVD EventT0 (ns)")
142 self.TH1F_Index["th1f_svdEventT0"] = TH1F_Store_Count
143 TH1F_Store_Count += 1
144 self.TH1F_Store.append(TH1F("th1f_svdEventT0_State", "SVD EventT0 Availability", 2, -0.5, 1.5))
145 self.TH1F_Store[-1].GetXaxis().SetBinLabel(1, "Not Available")
146 self.TH1F_Store[-1].GetXaxis().SetBinLabel(2, "Available")
147 self.TH1F_Index["th1f_svdEventT0_State"] = TH1F_Store_Count
148 TH1F_Store_Count += 1
149
150 self.TH1F_Store.append(TH1F("th1f_cdcEventT0", "CDC EventT0", 500, -50., 50.))
151 self.TH1F_Store[-1].GetXaxis().SetTitle("CDC EventT0 (ns)")
152 self.TH1F_Index["th1f_cdcEventT0"] = TH1F_Store_Count
153 TH1F_Store_Count += 1
154 self.TH1F_Store.append(TH1F("th1f_cdcEventT0_State", "CDC EventT0 Availability", 2, -0.5, 1.5))
155 self.TH1F_Store[-1].GetXaxis().SetBinLabel(1, "Not Available")
156 self.TH1F_Store[-1].GetXaxis().SetBinLabel(2, "Available")
157 self.TH1F_Index["th1f_cdcEventT0_State"] = TH1F_Store_Count
158 TH1F_Store_Count += 1
159
160 # EventT0 - TOP Online EventT0
161
162 self.TH1F_Store.append(TH1F("th1f_svdEventT0topRef", "SVD EventT0 - TOP Online EventT0", 500, -20., 20.))
163 self.TH1F_Store[-1].GetXaxis().SetTitle("SVD EventT0 - TOP Online EventT0 (ns)")
164 self.TH1F_Index["th1f_svdEventT0topRef"] = TH1F_Store_Count
165 TH1F_Store_Count += 1
166
167 # Cluster Time
168
169 self.TH1F_Store.append(TH1F("th1f_clsTime_PreTracking", "(PreTracking) Cluster Time", timeBin, minTime, maxTime))
170 self.TH1F_Store[-1].GetXaxis().SetTitle("Cluster Time (ns)")
171 self.TH1F_Store[-1].SetLineColor(1)
172 self.TH1F_Index["th1f_clsTime_PreTracking"] = TH1F_Store_Count
173 TH1F_Store_Count += 1
174 self.TH1F_Store.append(TH1F("th1f_bkgClsTime_PreTracking", "(PreTracking) Bkg Cluster Time", timeBin, minTime, maxTime))
175 self.TH1F_Store[-1].GetXaxis().SetTitle("Cluster Time (ns)")
176 self.TH1F_Store[-1].SetLineColor(2)
177 self.TH1F_Index["th1f_bkgClsTime_PreTracking"] = TH1F_Store_Count
178 TH1F_Store_Count += 1
179 self.TH1F_Store.append(TH1F("th1f_sigClsTime_PreTracking", "(PreTracking) Sig Cluster Time", timeBin, minTime, maxTime))
180 self.TH1F_Store[-1].GetXaxis().SetTitle("Cluster Time (ns)")
181 self.TH1F_Store[-1].SetLineColor(3)
182 self.TH1F_Index["th1f_sigClsTime_PreTracking"] = TH1F_Store_Count
183 TH1F_Store_Count += 1
184
185 self.TH1F_Store.append(TH1F("th1f_clsTime_PostTracking", "(PostTracking) Cluster Time", timeBin, minTime, maxTime))
186 self.TH1F_Store[-1].GetXaxis().SetTitle("Cluster Time (ns)")
187 self.TH1F_Store[-1].SetLineColor(1)
188 self.TH1F_Index["th1f_clsTime_PostTracking"] = TH1F_Store_Count
189 TH1F_Store_Count += 1
190 self.TH1F_Store.append(TH1F("th1f_bkgClsTime_PostTracking", "(PostTracking) Bkg Cluster Time", timeBin, minTime, maxTime))
191 self.TH1F_Store[-1].GetXaxis().SetTitle("Cluster Time (ns)")
192 self.TH1F_Store[-1].SetLineColor(2)
193 self.TH1F_Index["th1f_bkgClsTime_PostTracking"] = TH1F_Store_Count
194 TH1F_Store_Count += 1
195 self.TH1F_Store.append(TH1F("th1f_sigClsTime_PostTracking", "(PostTracking) Sig Cluster Time", timeBin, minTime, maxTime))
196 self.TH1F_Store[-1].GetXaxis().SetTitle("Cluster Time (ns)")
197 self.TH1F_Store[-1].SetLineColor(3)
198 self.TH1F_Index["th1f_sigClsTime_PostTracking"] = TH1F_Store_Count
199 TH1F_Store_Count += 1
200
201 self.TH1F_Store.append(TH1F("th1f_trackTime", "Track Time", timeBin * 10, minTime, maxTime))
202 self.TH1F_Store[-1].GetXaxis().SetTitle("Track Time (ns)")
203 self.TH1F_Index["th1f_trackTime"] = TH1F_Store_Count
204 TH1F_Store_Count += 1
205 self.TH1F_Store.append(TH1F("th1f_trackTimeCDCRef", "Track Time - CDC EventT0", 10000, -50, 50))
206 self.TH1F_Store[-1].GetXaxis().SetTitle("Track Time - CDC EventT0 (ns)")
207 self.TH1F_Index["th1f_trackTimeCDCRef"] = TH1F_Store_Count
208 TH1F_Store_Count += 1
209
210 # Cluster Time - TOP Online EventT0
211
212 self.TH1F_Store.append(TH1F("th1f_clsTimeCdcRef_PreTracking", "(PreTracking) Cluster Time - CDC EventT0",
213 timeBin * 2, minTime, maxTime))
214 self.TH1F_Store[-1].GetXaxis().SetTitle("Cluster Time - CDC EventT0 (ns)")
215 self.TH1F_Store[-1].SetLineColor(1)
216 self.TH1F_Index["th1f_clsTimeCdcRef_PreTracking"] = TH1F_Store_Count
217 TH1F_Store_Count += 1
218
219 self.TH1F_Store.append(TH1F("th1f_clsTimeCdcRef_PostTracking", "(PostTracking) Cluster Time - CDC EventT0",
220 timeBin * 2, minTime, maxTime))
221 self.TH1F_Store[-1].GetXaxis().SetTitle("Cluster Time - CDC EventT0 (ns)")
222 self.TH1F_Store[-1].SetLineColor(1)
223 self.TH1F_Index["th1f_clsTimeCdcRef_PostTracking"] = TH1F_Store_Count
224 TH1F_Store_Count += 1
225
226 # ECL TC Emax
227
228 self.TH1F_Store.append(TH1F("th1f_eclTCEmax", "ECL E_{max}^{TC}", 1250, 0.5, 1250.5))
229 self.TH1F_Store[-1].GetXaxis().SetTitle("ECL E_{max}^{TC} (ADC)")
230 self.TH1F_Index["th1f_eclTCEmax"] = TH1F_Store_Count
231 TH1F_Store_Count += 1
232 self.TH1F_Store.append(TH1F("th1f_eclTCEmax_State", "ECL E_{max}^{TC} Availability", 2, -0.5, 1.5))
233 self.TH1F_Store[-1].GetXaxis().SetBinLabel(1, "Not Available")
234 self.TH1F_Store[-1].GetXaxis().SetBinLabel(2, "Available")
235 self.TH1F_Index["th1f_eclTCEmax_State"] = TH1F_Store_Count
236 TH1F_Store_Count += 1
237
238 self.TH2F_Store.append(TH2F("th2f_timeGr_vs_grAmp", "Time Group vs Group Amplitude", 60, 0., 300, 21, -1.5, 19.5))
239 self.TH2F_Store[-1].GetXaxis().SetTitle("Group Amplitude")
240 self.TH2F_Store[-1].GetYaxis().SetTitle("Time Group")
241 self.TH2F_Index["th2f_timeGr_vs_grAmp"] = TH2F_Store_Count
242 TH2F_Store_Count += 1
243 self.TH2F_Store.append(TH2F("th2f_timeGr_vs_grCenter", "Time Group vs Group Center", 80, minTime, maxTime, 21, -1.5, 19.5))
244 self.TH2F_Store[-1].GetXaxis().SetTitle("Group Center (ns)")
245 self.TH2F_Store[-1].GetYaxis().SetTitle("Time Group")
246 self.TH2F_Index["th2f_timeGr_vs_grCenter"] = TH2F_Store_Count
247 TH2F_Store_Count += 1
248 self.TH2F_Store.append(TH2F("th2f_timeGr_vs_grWidth", "Time Group vs Group Width", 50, 1, 11, 21, -1.5, 19.5))
249 self.TH2F_Store[-1].GetXaxis().SetTitle("Group Width (ns)")
250 self.TH2F_Store[-1].GetYaxis().SetTitle("Time Group")
251 self.TH2F_Index["th2f_timeGr_vs_grWidth"] = TH2F_Store_Count
252 TH2F_Store_Count += 1
253 self.TH2F_Store.append(TH2F("th2f_timeGr_vs_clsTime", "Time Group vs Cluster Time",
254 timeBin, minTime, maxTime, 21, -1.5, 19.5))
255 self.TH2F_Store[-1].GetXaxis().SetTitle("Cluster Time (ns)")
256 self.TH2F_Store[-1].GetYaxis().SetTitle("Time Group")
257 self.TH2F_Index["th2f_timeGr_vs_clsTime"] = TH2F_Store_Count
258 TH2F_Store_Count += 1
259 self.TH2F_Store.append(TH2F("th2f_timeGr_vs_clsTime_PostTracking", "(PostTracking) Time Group vs Cluster Time",
260 timeBin, minTime, maxTime, 21, -1.5, 19.5))
261 self.TH2F_Store[-1].GetXaxis().SetTitle("Cluster Time (ns)")
262 self.TH2F_Store[-1].GetYaxis().SetTitle("Time Group")
263 self.TH2F_Index["th2f_timeGr_vs_clsTime_PostTracking"] = TH2F_Store_Count
264 TH2F_Store_Count += 1
265
266 for i in range(4):
267 self.TH2F_Store.append(TH2F("th2f_sig" + str(i) + "GrMean_vs_cdcEventT0", "Center of 'Group " +
268 str(i) + "' vs CDC EventT0", 500, -50., 50., 500, -50., 50.))
269 self.TH2F_Store[-1].GetXaxis().SetTitle("Center of 'Group " + str(i) + "' (ns)")
270 self.TH2F_Store[-1].GetYaxis().SetTitle("CDC EventT0 (ns)")
271 self.TH2F_Index["th2f_sig" + str(i) + "GrMean_vs_cdcEventT0"] = TH2F_Store_Count
272 TH2F_Store_Count += 1
273 self.TH2F_Store.append(TH2F("th2f_sig" + str(i) + "GrMean_vs_cdcEventT0_rot45pos",
274 "Center of 'Group " + str(i) + "' vs CDC EventT0 (Rotated 45)",
275 500, -50., 50., 500, -50., 50.))
276 self.TH2F_Store[-1].GetXaxis().SetTitle("Center of 'Group " + str(i) + "' (ns)")
277 self.TH2F_Store[-1].GetYaxis().SetTitle("CDC EventT0 (ns)")
278 self.TH2F_Index["th2f_sig" + str(i) + "GrMean_vs_cdcEventT0_rot45pos"] = TH2F_Store_Count
279 TH2F_Store_Count += 1
280 self.TH2F_Store.append(TH2F("th2f_sig" + str(i) + "GrMean_vs_cdcEventT0_rot45neg",
281 "Center of 'Group " + str(i) + "' vs CDC EventT0 (Rotated -45)",
282 500, -50., 50., 500, -50., 50.))
283 self.TH2F_Store[-1].GetXaxis().SetTitle("Center of 'Group " + str(i) + "' (ns)")
284 self.TH2F_Store[-1].GetYaxis().SetTitle("CDC EventT0 (ns)")
285 self.TH2F_Index["th2f_sig" + str(i) + "GrMean_vs_cdcEventT0_rot45neg"] = TH2F_Store_Count
286 TH2F_Store_Count += 1
287
288 self.TH2F_Store.append(TH2F("th2f_aveClsTimeInTrk_vs_cdcEventT0",
289 "Track Time vs CDC EventT0", 500, -50., 50., 500, -50., 50.))
290 self.TH2F_Store[-1].GetXaxis().SetTitle("<Cluster Time> in Track (ns)")
291 self.TH2F_Store[-1].GetYaxis().SetTitle("CDC EventT0 (ns)")
292 self.TH2F_Index["th2f_aveClsTimeInTrk_vs_cdcEventT0"] = TH2F_Store_Count
293 TH2F_Store_Count += 1
294 self.TH2F_Store.append(TH2F("th2f_svdEventT0_vs_cdcEventT0", "SVD EventT0 vs CDC EventT0",
295 500, -50., 50., 500, -50., 50.))
296 self.TH2F_Store[-1].GetXaxis().SetTitle("SVD EventT0 (ns)")
297 self.TH2F_Store[-1].GetYaxis().SetTitle("CDC EventT0 (ns)")
298 self.TH2F_Index["th2f_svdEventT0_vs_cdcEventT0"] = TH2F_Store_Count
299 TH2F_Store_Count += 1
300 self.TH2F_Store.append(TH2F("th2f_svdEventT0_vs_cdcEventT0_rot45pos",
301 "SVD EventT0 vs CDC EventT0 (Rotated 45)", 500, -50., 50., 500, -50., 50.))
302 self.TH2F_Store[-1].GetXaxis().SetTitle("SVD EventT0 (ns)")
303 self.TH2F_Store[-1].GetYaxis().SetTitle("CDC EventT0 (ns)")
304 self.TH2F_Index["th2f_svdEventT0_vs_cdcEventT0_rot45pos"] = TH2F_Store_Count
305 TH2F_Store_Count += 1
306 self.TH2F_Store.append(TH2F("th2f_svdEventT0_vs_cdcEventT0_rot45neg",
307 "SVD EventT0 vs CDC EventT0 (Rotated -45)", 500, -50., 50., 500, -50., 50.))
308 self.TH2F_Store[-1].GetXaxis().SetTitle("SVD EventT0 (ns)")
309 self.TH2F_Store[-1].GetYaxis().SetTitle("CDC EventT0 (ns)")
310 self.TH2F_Index["th2f_svdEventT0_vs_cdcEventT0_rot45neg"] = TH2F_Store_Count
311 TH2F_Store_Count += 1
312
313 self.TH2F_Store.append(TH2F("th2f_trkTime_vs_clsTime_inCDCEventT0", "Track Time vs Cluster Time",
314 timeBin, minTime, maxTime, timeBin, minTime, maxTime))
315 self.TH2F_Store[-1].GetXaxis().SetTitle("Track Time - Cluster Time (ns)")
316 self.TH2F_Store[-1].GetYaxis().SetTitle("CDC EventT0 - Track Time (ns)")
317 self.TH2F_Index["th2f_trkTime_vs_clsTime_inCDCEventT0"] = TH2F_Store_Count
318 TH2F_Store_Count += 1
319 self.TH2F_Store.append(TH2F("th2f_trkTime_vs_clsTime_inSVDEventT0", "Track Time vs Cluster Time",
320 timeBin, minTime, maxTime, timeBin, minTime, maxTime))
321 self.TH2F_Store[-1].GetXaxis().SetTitle("Track Time - Cluster Time (ns)")
322 self.TH2F_Store[-1].GetYaxis().SetTitle("SVD EventT0 - Track Time (ns)")
323 self.TH2F_Index["th2f_trkTime_vs_clsTime_inSVDEventT0"] = TH2F_Store_Count
324 TH2F_Store_Count += 1
325
326 self.TH2F_Store.append(TH2F("th2f_aveClsTimeInTrk_vs_clsTime_inCDCEventT0", "<Cluster Time> in Track vs Cluster Time",
327 timeBin, minTime, maxTime, timeBin, minTime, maxTime))
328 self.TH2F_Store[-1].GetXaxis().SetTitle("<Cluster Time> in Track - Cluster Time (ns)")
329 self.TH2F_Store[-1].GetYaxis().SetTitle("CDC EventT0 - <Cluster Time> in Track (ns)")
330 self.TH2F_Index["th2f_aveClsTimeInTrk_vs_clsTime_inCDCEventT0"] = TH2F_Store_Count
331 TH2F_Store_Count += 1
332 self.TH2F_Store.append(TH2F("th2f_aveClsTimeInTrk_vs_clsTime_inSVDEventT0", "<Cluster Time> in Track vs Cluster Time",
333 timeBin, minTime, maxTime, timeBin, minTime, maxTime))
334 self.TH2F_Store[-1].GetXaxis().SetTitle("<Cluster Time> in Track - Cluster Time (ns)")
335 self.TH2F_Store[-1].GetYaxis().SetTitle("SVD EventT0 - <Cluster Time> in Track (ns)")
336 self.TH2F_Index["th2f_aveClsTimeInTrk_vs_clsTime_inSVDEventT0"] = TH2F_Store_Count
337 TH2F_Store_Count += 1
338
339 # Resolution w.r.t. ECL TC Emax
340
341 self.reso_TH2D_Histograms.append(TH2F("reso_eclTCEmax_vs_clsTimeTopRef_PreTracking",
342 "(PreTracking) ECL E_{max}^{TC} vs Cluster Time - TOP Online EventT0",
343 usedBin1, eclMinVal, eclMaxVal, usedBin2, -50, 50.))
344 self.reso_TH2D_Histograms[-1].GetXaxis().SetTitle("ECL E_{max}^{TC} (ADC)")
345 self.reso_TH2D_Histograms[-1].GetYaxis().SetTitle("Cluster Time - TOP Online EventT0 (ns)")
346 self.reso_TH2D_Histogram_Index["reso_eclTCEmax_vs_clsTimeTopRef_PreTracking"] = reso_TH2D_Histograms_Count
347 reso_TH2D_Histograms_Count += 1
348 self.reso_TH2D_Histograms.append(TH2F("reso_eclTCEmax_vs_clsTimeTopRef_PostTracking",
349 "(PostTracking) ECL E_{max}^{TC} vs Cluster Time - TOP Online EventT0",
350 usedBin1, eclMinVal, eclMaxVal, usedBin2, -50, 50.))
351 self.reso_TH2D_Histograms[-1].GetXaxis().SetTitle("ECL E_{max}^{TC} (ADC)")
352 self.reso_TH2D_Histograms[-1].GetYaxis().SetTitle("Cluster Time - TOP Online EventT0 (ns)")
353 self.reso_TH2D_Histogram_Index["reso_eclTCEmax_vs_clsTimeTopRef_PostTracking"] = reso_TH2D_Histograms_Count
354 reso_TH2D_Histograms_Count += 1
355
356 self.reso_TH2D_Histograms.append(TH2F("reso_eclTCEmax_vs_svdEventT0TopRef",
357 "ECL E_{max}^{TC} vs SVD EventT0 - TOP Online EventT0",
358 usedBin1, eclMinVal, eclMaxVal, usedBin2, -50, 50.))
359 self.reso_TH2D_Histograms[-1].GetXaxis().SetTitle("ECL E_{max}^{TC} (ADC)")
360 self.reso_TH2D_Histograms[-1].GetYaxis().SetTitle("SVD EventT0 - TOP Online EventT0 (ns)")
361 self.reso_TH2D_Histogram_Index["reso_eclTCEmax_vs_svdEventT0TopRef"] = reso_TH2D_Histograms_Count
362 reso_TH2D_Histograms_Count += 1
363
364 self.reso_TH2D_Histograms.append(TH2F("reso_eclTCEmax_vs_totalTracks",
365 "ECL E_{max}^{TC} vs Total SVD Tracks",
366 usedBin1, eclMinVal, eclMaxVal, 36, -0.5, 35.5))
367 self.reso_TH2D_Histograms[-1].GetXaxis().SetTitle("ECL E_{max}^{TC} (ADC)")
368 self.reso_TH2D_Histograms[-1].GetYaxis().SetTitle("Total SVD Tracks")
369 self.reso_TH2D_Histogram_Index["reso_eclTCEmax_vs_totalTracks"] = reso_TH2D_Histograms_Count
370 reso_TH2D_Histograms_Count += 1
371
372 self.reso_TH2D_Histograms.append(TH2F("reso_eclTCEmax_vs_totalClusters_PreTracking",
373 "(PreTracking) ECL E_{max}^{TC} vs Total SVD Clusters",
374 usedBin1, eclMinVal, eclMaxVal, 1000, 0.5, 1000.5))
375 self.reso_TH2D_Histograms[-1].GetXaxis().SetTitle("ECL E_{max}^{TC} (ADC)")
376 self.reso_TH2D_Histograms[-1].GetYaxis().SetTitle("Total SVD Clusters")
377 self.reso_TH2D_Histogram_Index["reso_eclTCEmax_vs_totalClusters_PreTracking"] = reso_TH2D_Histograms_Count
378 reso_TH2D_Histograms_Count += 1
379 self.reso_TH2D_Histograms.append(TH2F("reso_eclTCEmax_vs_totalClusters_PostTracking",
380 "(PostTracking) ECL E_{max}^{TC} vs Total SVD Clusters",
381 usedBin1, eclMinVal, eclMaxVal, 1000, 0.5, 1000.5))
382 self.reso_TH2D_Histograms[-1].GetXaxis().SetTitle("ECL E_{max}^{TC} (ADC)")
383 self.reso_TH2D_Histograms[-1].GetYaxis().SetTitle("Total SVD Clusters")
384 self.reso_TH2D_Histogram_Index["reso_eclTCEmax_vs_totalClusters_PostTracking"] = reso_TH2D_Histograms_Count
385 reso_TH2D_Histograms_Count += 1
386
387 def event(self):
388 ''' Event loop'''
389
390 EventT0 = Belle2.PyStoreObj('EventT0')
391 svdEventT0 = math.nan
392 cdcEventT0 = math.nan
393 svd = Belle2.Const.DetectorSet(Belle2.Const.SVD)
394 cdc = Belle2.Const.DetectorSet(Belle2.Const.CDC)
395 top = Belle2.Const.DetectorSet(Belle2.Const.TOP)
396 if EventT0.hasTemporaryEventT0(svd):
397 tmp = EventT0.getTemporaryEventT0s(Belle2.Const.SVD)
398 svdEventT0 = tmp.back().eventT0
399 if EventT0.hasTemporaryEventT0(cdc):
400 tmp = EventT0.getTemporaryEventT0s(Belle2.Const.CDC)
401 cdcEventT0 = tmp.back().eventT0
402
403 if not math.isnan(svdEventT0):
404 self.TH1F_Store[self.TH1F_Index["th1f_svdEventT0"]].Fill(svdEventT0)
405 self.TH1F_Store[self.TH1F_Index["th1f_svdEventT0_State"]].Fill(1)
406 else:
407 self.TH1F_Store[self.TH1F_Index["th1f_svdEventT0_State"]].Fill(0)
408 if not math.isnan(cdcEventT0):
409 self.TH1F_Store[self.TH1F_Index["th1f_cdcEventT0"]].Fill(cdcEventT0)
410 self.TH1F_Store[self.TH1F_Index["th1f_cdcEventT0_State"]].Fill(1)
411 else:
412 self.TH1F_Store[self.TH1F_Index["th1f_cdcEventT0_State"]].Fill(0)
413
414 if not math.isnan(svdEventT0) and not math.isnan(cdcEventT0):
415 self.TH2F_Store[self.TH2F_Index["th2f_svdEventT0_vs_cdcEventT0"]].Fill(svdEventT0, cdcEventT0)
416 self.TH2F_Store[self.TH2F_Index["th2f_svdEventT0_vs_cdcEventT0_rot45pos"]].Fill(
417 svdEventT0 * TMath.Cos(TMath.PiOver4()) + cdcEventT0 * TMath.Sin(TMath.PiOver4()),
418 - svdEventT0 * TMath.Sin(TMath.PiOver4()) + cdcEventT0 * TMath.Cos(TMath.PiOver4()))
419 self.TH2F_Store[self.TH2F_Index["th2f_svdEventT0_vs_cdcEventT0_rot45neg"]].Fill(
420 svdEventT0 * TMath.Cos(-TMath.PiOver4()) + cdcEventT0 * TMath.Sin(-TMath.PiOver4()),
421 - svdEventT0 * TMath.Sin(-TMath.PiOver4()) + cdcEventT0 * TMath.Cos(-TMath.PiOver4()))
422
423 OnlineEventT0 = []
424 if not args.isMC:
425 OnlineEventT0 = Belle2.PyStoreArray('OnlineEventT0s')
426 topOnlineEventT0 = math.nan
427 for evt in OnlineEventT0:
428 if evt.getOnlineEventT0Detector() == top:
429 topOnlineEventT0 = evt.getOnlineEventT0()
430
431 if not math.isnan(topOnlineEventT0) and not math.isnan(svdEventT0):
432 self.TH1F_Store[self.TH1F_Index["th1f_svdEventT0topRef"]].Fill(svdEventT0 - topOnlineEventT0)
433
434 TRGECLData = []
435 if not args.isMC:
436 TRGECLData = Belle2.PyStoreArray('TRGECLUnpackerStores')
437 eclTCEmax = 0
438 for trgHit in TRGECLData:
439 hitWin = trgHit.getHitWin()
440 if hitWin != 3 and hitWin != 4:
441 continue
442 if trgHit.getTCEnergy() > eclTCEmax:
443 eclTCEmax = trgHit.getTCEnergy()
444
445 if eclTCEmax:
446 self.TH1F_Store[self.TH1F_Index["th1f_eclTCEmax"]].Fill(eclTCEmax)
447 self.TH1F_Store[self.TH1F_Index["th1f_eclTCEmax_State"]].Fill(1)
448 if not math.isnan(topOnlineEventT0) and not math.isnan(svdEventT0):
449 self.reso_TH2D_Histograms[self.reso_TH2D_Histogram_Index["reso_eclTCEmax_vs_svdEventT0TopRef"]].Fill(
450 eclTCEmax, svdEventT0 - topOnlineEventT0)
451 else:
452 self.TH1F_Store[self.TH1F_Index["th1f_eclTCEmax_State"]].Fill(0)
453
454 # Pre Tracking
455
456 clusterList = Belle2.PyStoreArray("SVDClusters")
457 if eclTCEmax:
458 self.reso_TH2D_Histograms[self.reso_TH2D_Histogram_Index["reso_eclTCEmax_vs_totalClusters_PreTracking"]].Fill(
459 eclTCEmax, len(clusterList))
460 fillOnce = 0
461 for d in clusterList:
462 clsTime = d.getClsTime()
463
464 self.TH1F_Store[self.TH1F_Index["th1f_clsTime_PreTracking"]].Fill(clsTime)
465 if not math.isnan(cdcEventT0):
466 self.TH1F_Store[self.TH1F_Index["th1f_clsTimeCdcRef_PreTracking"]].Fill(clsTime - cdcEventT0)
467 if not math.isnan(topOnlineEventT0) and eclTCEmax:
468 self.reso_TH2D_Histograms[self.reso_TH2D_Histogram_Index["reso_eclTCEmax_vs_clsTimeTopRef_PreTracking"]].Fill(
469 eclTCEmax, clsTime - topOnlineEventT0)
470
471 groupIds = d.getTimeGroupId()
472 groupInfo = d.getTimeGroupInfo()
473
474 minId = 1000
475 par0 = -1000
476 par1 = -1000
477 par2 = -1000
478 for id in range(len(groupIds)):
479 gr = groupIds[id]
480 if gr < minId:
481 minId = gr
482 if len(groupInfo) > 0:
483 par0, par1, par2 = groupInfo[id]
484
485 if len(groupIds) == 0:
486 minId = -1
487
488 self.TH2F_Store[self.TH2F_Index["th2f_timeGr_vs_clsTime"]].Fill(clsTime, minId)
489 self.TH2F_Store[self.TH2F_Index["th2f_timeGr_vs_grAmp"]].Fill(par0, minId)
490 self.TH2F_Store[self.TH2F_Index["th2f_timeGr_vs_grCenter"]].Fill(par1, minId)
491 self.TH2F_Store[self.TH2F_Index["th2f_timeGr_vs_grWidth"]].Fill(par2, minId)
492
493 if fillOnce == minId and fillOnce < 4:
494 if not math.isnan(cdcEventT0):
495 hname = "th2f_sig" + str(fillOnce) + "GrMean_vs_cdcEventT0"
496 self.TH2F_Store[self.TH2F_Index[hname]].Fill(par1, cdcEventT0)
497 hname = "th2f_sig" + str(fillOnce) + "GrMean_vs_cdcEventT0_rot45neg"
498 self.TH2F_Store[self.TH2F_Index[hname]].Fill(
499 par1 * TMath.Cos(-TMath.PiOver4()) + cdcEventT0 * TMath.Sin(-TMath.PiOver4()),
500 - par1 * TMath.Sin(-TMath.PiOver4()) + cdcEventT0 * TMath.Cos(-TMath.PiOver4()))
501 hname = "th2f_sig" + str(fillOnce) + "GrMean_vs_cdcEventT0_rot45pos"
502 self.TH2F_Store[self.TH2F_Index[hname]].Fill(
503 par1 * TMath.Cos(TMath.PiOver4()) + cdcEventT0 * TMath.Sin(TMath.PiOver4()),
504 - par1 * TMath.Sin(TMath.PiOver4()) + cdcEventT0 * TMath.Cos(TMath.PiOver4()))
505 fillOnce += 1
506
507 if minId == 0:
508 self.TH1F_Store[self.TH1F_Index["th1f_sigClsTime_PreTracking"]].Fill(clsTime)
509 else:
510 self.TH1F_Store[self.TH1F_Index["th1f_bkgClsTime_PreTracking"]].Fill(clsTime)
511
512 # Post Tracking
513
514 recoTrackList = Belle2.PyStoreArray('RecoTracks')
515 nTracks = len(recoTrackList)
516 nClusters = 0
517 for recoTrk in recoTrackList:
518 if not recoTrk.wasFitSuccessful():
519 nTracks -= 1
520 continue
521
522 trackList = recoTrk.getRelationsFrom('Tracks')
523 if len(trackList) == 0:
524 nTracks -= 1
525 continue
526 trkTime0 = trackList[0].getTrackTime()
527
528 self.TH1F_Store[self.TH1F_Index["th1f_trackTime"]].Fill(trkTime0)
529 if not math.isnan(cdcEventT0):
530 self.TH1F_Store[self.TH1F_Index["th1f_trackTimeCDCRef"]].Fill(trkTime0 - cdcEventT0)
531
532 clusterList = recoTrk.getRelationsFrom("SVDClusters")
533 nClusters += len(clusterList)
534 if len(clusterList) == 0:
535 continue
536
537 trkTime = 0
538 for d in clusterList:
539 trkTime += d.getClsTime()
540 trkTime /= len(clusterList)
541
542 for d in clusterList:
543 clsTime = d.getClsTime()
544 groupIds = d.getTimeGroupId()
545 groupInfo = d.getTimeGroupInfo()
546
547 if not math.isnan(svdEventT0):
548 self.TH2F_Store[self.TH2F_Index["th2f_trkTime_vs_clsTime_inSVDEventT0"]].Fill(
549 trkTime0 - clsTime, svdEventT0 - trkTime0)
550 if not math.isnan(cdcEventT0):
551 self.TH2F_Store[self.TH2F_Index["th2f_trkTime_vs_clsTime_inCDCEventT0"]].Fill(
552 trkTime0 - clsTime, cdcEventT0 - trkTime0)
553 self.TH2F_Store[self.TH2F_Index["th2f_aveClsTimeInTrk_vs_cdcEventT0"]].Fill(trkTime, cdcEventT0)
554 if not math.isnan(svdEventT0):
555 self.TH2F_Store[self.TH2F_Index["th2f_aveClsTimeInTrk_vs_clsTime_inSVDEventT0"]].Fill(
556 trkTime - clsTime, svdEventT0 - trkTime)
557 if not math.isnan(cdcEventT0):
558 self.TH2F_Store[self.TH2F_Index["th2f_aveClsTimeInTrk_vs_clsTime_inCDCEventT0"]].Fill(
559 trkTime - clsTime, cdcEventT0 - trkTime)
560
561 self.TH1F_Store[self.TH1F_Index["th1f_clsTime_PostTracking"]].Fill(clsTime)
562 if not math.isnan(cdcEventT0):
563 self.TH1F_Store[self.TH1F_Index["th1f_clsTimeCdcRef_PostTracking"]].Fill(clsTime - cdcEventT0)
564 if not math.isnan(topOnlineEventT0) and eclTCEmax:
565 self.reso_TH2D_Histograms[self.reso_TH2D_Histogram_Index["reso_eclTCEmax_vs_clsTimeTopRef_PostTracking"]].Fill(
566 eclTCEmax, clsTime - topOnlineEventT0)
567
568 minId = 1000
569 par0 = -1000
570 par1 = -1000
571 par2 = -1000
572 if len(groupIds) == 0:
573 minId = -1
574 for id in range(len(groupIds)):
575 gr = groupIds[id]
576 if gr < minId:
577 minId = gr
578 if len(groupInfo) > 0:
579 par0, par1, par2 = groupInfo[id]
580
581 self.TH2F_Store[self.TH2F_Index["th2f_timeGr_vs_clsTime_PostTracking"]].Fill(clsTime, minId)
582
583 if par1 > sigMin and par1 < sigMax:
584 self.TH1F_Store[self.TH1F_Index["th1f_sigClsTime_PostTracking"]].Fill(clsTime)
585 else:
586 self.TH1F_Store[self.TH1F_Index["th1f_bkgClsTime_PostTracking"]].Fill(clsTime)
587
588 if eclTCEmax:
589 self.reso_TH2D_Histograms[self.reso_TH2D_Histogram_Index["reso_eclTCEmax_vs_totalTracks"]].Fill(eclTCEmax, nTracks)
590 self.reso_TH2D_Histograms[self.reso_TH2D_Histogram_Index["reso_eclTCEmax_vs_totalClusters_PostTracking"]].Fill(
591 eclTCEmax, nClusters)
592
593 def terminate(self):
594 '''write'''
595
596 self.f.mkdir("objects")
597 self.f.cd("objects")
598
599 for hist in self.TH1F_Store:
600 if "_State" in hist.GetName():
601 hist.Scale(1./hist.GetSumOfWeights())
602 hist.Write()
603
604 for hist in self.TH2F_Store:
605 hist.Write()
606
607 for hist in self.reso_TH2D_Histograms:
608 hist.Write()
609
610 self.f.Close()
611
612
613main = b2.create_path()
614
615b2.set_random_seed(args.seed)
616
617if args.isMC:
618 # options for simulation:
619 expList = [0]
620 numEvents = 10
621 bkgFiles = get_background_files() # Phase3 background
622 # bkgFiles = None # uncomment to remove background
623 simulateJitter = False
624 ROIfinding = False
625 MCTracking = False
626 eventinfosetter = b2.register_module('EventInfoSetter')
627 eventinfosetter.param('expList', expList)
628 eventinfosetter.param('runList', [0])
629 eventinfosetter.param('evtNumList', [numEvents])
630 main.add_module(eventinfosetter)
631 ge.add_evtgen_generator(path=main, finalstate='mixed')
632
633 sim.add_simulation(main, bkgfiles=bkgFiles)
634
635 if args.is3sample:
636 for m in main.modules():
637 if m.name() == "SVDEventInfoSetter":
638 m.param("daqMode", 1)
639 m.param("relativeShift", 7)
640 m.param("useDB", False)
641
642
643else:
644 # setup database
645 b2conditions.reset()
646 b2conditions.override_globaltags()
647 b2conditions.globaltags = ["online"]
648 b2conditions.prepend_globaltag("data_reprocessing_prompt")
649 b2conditions.prepend_globaltag("patch_main_release-07")
650 b2conditions.prepend_globaltag("patch_main_release-08")
651 if args.CoG3TimeCalibration_bucket36:
652 b2conditions.prepend_globaltag("svd_CoG3TimeCalibration_bucket36_withGrouping_pol3")
653 if args.CoG3TimeCalibration_bucket32:
654 b2conditions.prepend_globaltag("svd_CoG3TimeCalibration_bucket32_withGrouping_pol3")
655
656 MCTracking = False
657
658 if args.test:
659 main.add_module('RootInput', entrySequences=['0:100'])
660 else:
661 main.add_module('RootInput')
662
663 main.add_module("Gearbox")
664 main.add_module('Geometry', useDB=True)
665
666 raw.add_unpackers(main)
667
668 if args.is3sample:
669 # change ListName
670 for moda in main.modules():
671 if moda.name() == 'SVDUnpacker':
672 moda.param("svdShaperDigitListName", "SVDShaperDigits6Sample")
673 moda.param("SVDEventInfo", "SVDEventInfo6Sample")
674
675 # emulate 3-sample DAQ for events
676 zsemulator = b2.register_module("SVD3SamplesEmulator")
677 zsemulator.param("outputSVDShaperDigits", "SVDShaperDigits3SampleAll")
678 zsemulator.param("outputSVDEventInfo", "SVDEventInfo")
679 zsemulator.param("chooseStartingSample", False)
680 zsemulator.param("chooseRelativeShift", True)
681 zsemulator.param("relativeShift", 7)
682 zsemulator.param("SVDShaperDigits", "SVDShaperDigits6Sample")
683 zsemulator.param("SVDEventInfo", "SVDEventInfo6Sample")
684 main.add_module(zsemulator)
685
686 zsonline = b2.register_module("SVDZeroSuppressionEmulator")
687 zsonline.param("ShaperDigits", "SVDShaperDigits3SampleAll")
688 zsonline.param("ShaperDigitsIN", "SVDShaperDigits")
689 main.add_module(zsonline)
690
691
692# now do reconstruction:
693trk.add_tracking_reconstruction(
694 main,
695 mcTrackFinding=MCTracking,
696 append_full_grid_cdc_eventt0=True,
697 skip_full_grid_cdc_eventt0_if_svd_time_present=False)
698
699main.add_module(SVDGroupingPerformance())
700
701for moda in main.modules():
702 if moda.name() == 'SVDClusterizer':
703 moda.param("returnClusterRawTime", args.isRawTime)
704 if moda.name() == 'SVDTimeGrouping':
705 if args.doSVDGrouping:
706 moda.param("forceGroupingFromDB", False)
707 moda.param("isEnabledIn6Samples", True)
708 moda.param("isEnabledIn3Samples", True)
709 moda.param("useParamFromDB", False)
710 moda.param('tRangeLow', minTime)
711 moda.param('tRangeHigh', maxTime)
712 moda.param("expectedSignalTimeCenter", sigLoc)
713 moda.param('expectedSignalTimeMin', sigMin)
714 moda.param('expectedSignalTimeMax', sigMax)
715 moda.param("signalLifetime", args.signalLifetime)
716 if moda.name() == 'SVDSpacePointCreator':
717 if args.useSVDGroupInfo:
718 moda.param("forceGroupingFromDB", False)
719 moda.param("useSVDGroupInfoIn6Sample", True)
720 moda.param("useSVDGroupInfoIn3Sample", True)
721 moda.param("useParamFromDB", False)
722 moda.param("numberOfSignalGroups", args.numberOfSignalGroups)
723 moda.param("formSingleSignalGroup", args.formSingleSignalGroup)
724
725
726if args.executionTime:
727 executionFileName = str(args.fileDir) + "SVDExecutionTime" + outputFileTag + ".root"
728 main.add_module(SVDExtraEventStatisticsModule(executionFileName))
729
730main.add_module('Progress')
731
732b2.print_path(main)
733b2.process(main)
734print(b2.statistics)
The DetectorSet class for sets of detector IDs in the form of EDetector values.
Definition: Const.h:80
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67