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