21 from ROOT
import Belle2, TFile, TTree, TH1F, TH2F, TH2D, TGraph, TFitResultPtr
22 from ROOT
import TROOT, gROOT, TF1, TMath, gStyle, gDirectory
27 from array
import array
30 from ROOT.Belle2
import SVDCoGCalibrationFunction
31 from ROOT.Belle2
import SVDCoGTimeCalibrations
33 import matplotlib.pyplot
as plt
35 svd_recoDigits =
"SVDRecoDigitsFromTracks"
37 svd_Clusters =
"SVDClustersFromTracks"
46 Python class used for evaluating the CoG corrections, create a localDB,
47 creating a localDB with the corrections and a root file to check the corrections
52 Function that allows to set if apply the CDC latency correction
56 - if True -> not apply correction
57 - if False -> apply correction
63 def fillLists(self, mode_byte_object, svdClusters_rel_RecoTracks_cl):
65 Function that fill the lists needed for the CoG corrections
68 mode_byte_object (modeByte): modeByte that contains the information about the TB
69 svdClusters_rel_RecoTracks_cl (SVDCluster): cluster related to tracks
72 timeCluster = svdClusters_rel_RecoTracks_cl.getClsTime()
73 snrCluster = svdClusters_rel_RecoTracks_cl.getSNR()
74 layerCluster = svdClusters_rel_RecoTracks_cl.getSensorID().getLayerNumber()
75 layerIndex = layerCluster - 3
76 sensorCluster = svdClusters_rel_RecoTracks_cl.getSensorID().getSensorNumber()
77 sensorIndex = sensorCluster - 1
78 ladderCluster = svdClusters_rel_RecoTracks_cl.getSensorID().getLadderNumber()
79 ladderIndex = ladderCluster - 1
80 sideCluster = svdClusters_rel_RecoTracks_cl.isUCluster()
89 TBClusters = mode_byte_object.getTriggerBin()
90 TBIndex = ord(TBClusters)
94 tZeroSync = tZero - 4000./509 * (3 - TBIndex)
99 resHist = self.
resList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
100 resHist.Fill(timeCluster - tZeroSync)
101 spHist = self.
spList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
103 spHist.Fill(timeCluster, tZeroSync)
104 cogHist = self.
cogList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
105 cogHist.Fill(timeCluster)
106 cdcHist = self.
cdcList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
107 cdcHist.Fill(tZeroSync)
108 snrHist = self.
snrList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
109 snrHist.Fill(snrCluster)
111 self.
nList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex] += 1
112 self.
sumCOGList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex] += timeCluster
119 Function that allows to set the localDB
122 localDB (str): Name of the localDB used
129 Initialize object (histograms, lists, ...) used by the class
154 for layer
in geoCache.getLayers(Belle2.VXD.SensorInfoBase.SVD):
164 self.
resList.append(layerList0)
165 self.
spList.append(layerList1)
166 self.
cogList.append(layerList2)
167 self.
cdcList.append(layerList3)
168 self.
snrList.append(layerList4)
169 self.
nList.append(layerList8)
172 for ladder
in geoCache.getLadders(layer):
182 layerList0.append(ladderList0)
183 layerList1.append(ladderList1)
184 layerList2.append(ladderList2)
185 layerList3.append(ladderList3)
186 layerList4.append(ladderList4)
187 layerList5.append(ladderList5)
188 layerList6.append(ladderList6)
189 layerList7.append(ladderList7)
190 layerList8.append(ladderList8)
192 for sensor
in geoCache.getSensors(ladder):
202 ladderList0.append(sensorList0)
203 ladderList1.append(sensorList1)
204 ladderList2.append(sensorList2)
205 ladderList3.append(sensorList3)
206 ladderList4.append(sensorList4)
207 ladderList5.append(sensorList5)
208 ladderList6.append(sensorList6)
209 ladderList7.append(sensorList7)
210 ladderList8.append(sensorList8)
212 for side
in range(2):
222 sensorList0.append(sideList0)
223 sensorList1.append(sideList1)
224 sensorList2.append(sideList2)
225 sensorList3.append(sideList3)
226 sensorList4.append(sideList4)
227 sensorList5.append(sideList5)
228 sensorList6.append(sideList6)
229 sensorList7.append(sideList7)
230 sensorList8.append(sideList8)
232 for i
in geoCache.getLayers(Belle2.VXD.SensorInfoBase.SVD):
233 layerN = i.getLayerNumber()
235 for j
in geoCache.getLadders(i):
236 ladderN = j.getLadderNumber()
238 for k
in geoCache.getSensors(j):
239 sensorN = k.getSensorNumber()
243 self.
resList[li][ldi][si][s].append(
244 TH1F(
"res" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 200, -100, 100))
245 self.
spList[li][ldi][si][s].append(
246 TH2D(
"sp" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 300, -150, 150, 300, -150, 150))
247 self.
cogList[li][ldi][si][s].append(
248 TH1F(
"cog" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 200, -100, 100))
249 self.
cdcList[li][ldi][si][s].append(
250 TH1F(
"cdc" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 200, -100, 100))
251 self.
snrList[li][ldi][si][s].append(
252 TH1F(
"snr" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 100, 0, 100))
253 self.
nList[li][ldi][si][s].append(0)
258 self.
AlphaUTB = TH2F(
"alphaVsTB_U",
" ", 400, 0.5, 2, 4, 0, 4)
259 self.
AlphaUTB.GetXaxis().SetTitle(
"alpha")
260 self.
AlphaUTB.GetYaxis().SetTitle(
"trigger bin")
262 self.
AlphaVTB = TH2F(
"alphaVsTB_V",
" ", 400, 0.5, 2, 4, 0, 4)
263 self.
AlphaVTB.GetXaxis().SetTitle(
"alpha")
264 self.
AlphaVTB.GetYaxis().SetTitle(
"trigger bin")
266 self.
BetaUTB = TH2F(
"betaVsTB_U",
" ", 200, -100, 100, 4, 0, 4)
267 self.
BetaUTB.GetXaxis().SetTitle(
"beta (ns)")
268 self.
BetaUTB.GetYaxis().SetTitle(
"trigger bin")
270 self.
BetaVTB = TH2F(
"betaVsTB_V",
" ", 200, -100, 100, 4, 0, 4)
271 self.
BetaVTB.GetXaxis().SetTitle(
"beta (ns)")
272 self.
BetaVTB.GetYaxis().SetTitle(
"trigger bin")
275 self.
MeanHistVTB = TH2F(
"meanHistVsTB_V",
" ", 100, -10, 10, 4, 0, 4)
276 self.
MeanHistVTB.GetXaxis().SetTitle(
"distribution mean (ns)")
277 self.
MeanHistVTB.GetYaxis().SetTitle(
"trigger bin")
279 self.
MeanHistUTB = TH2F(
"meanHistVsTB_U",
" ", 100, -10, 10, 4, 0, 4)
280 self.
MeanHistUTB.GetXaxis().SetTitle(
"distribution mean (ns)")
281 self.
MeanHistUTB.GetYaxis().SetTitle(
"trigger bin")
283 self.
RMSHistVTB = TH2F(
"rmsHistVsTB_V",
" ", 100, 0, 10, 4, 0, 4)
284 self.
RMSHistVTB.GetXaxis().SetTitle(
"distribution RMS (ns)")
285 self.
RMSHistVTB.GetYaxis().SetTitle(
"trigger bin")
287 self.
RMSHistUTB = TH2F(
"rmsHistVsTB_U",
" ", 100, 0, 10, 4, 0, 4)
288 self.
RMSHistUTB.GetXaxis().SetTitle(
"distribution RMS (ns)")
289 self.
RMSHistUTB.GetYaxis().SetTitle(
"trigger bin")
291 self.
MeanFitVTB = TH2F(
"meanFitVsTB_V",
" ", 100, -10, 10, 4, 0, 4)
292 self.
MeanFitVTB.GetXaxis().SetTitle(
"fit mean (ns)")
293 self.
MeanFitVTB.GetYaxis().SetTitle(
"trigger bin")
295 self.
MeanFitUTB = TH2F(
"meanFitVsTB_U",
" ", 100, -10, 10, 4, 0, 4)
296 self.
MeanFitUTB.GetXaxis().SetTitle(
"fit mean (ns)")
297 self.
MeanFitUTB.GetYaxis().SetTitle(
"trigger bin")
299 self.
RMSFitUTB = TH2F(
"rmsFitVsTB_U",
" ", 100, 0, 10, 4, 0, 4)
300 self.
RMSFitUTB.GetXaxis().SetTitle(
"fit sigma (ns)")
301 self.
RMSFitUTB.GetYaxis().SetTitle(
"trigger bin")
303 self.
RMSFitVTB = TH2F(
"rmsFitVsTB_V",
" ", 100, 0, 10, 4, 0, 4)
304 self.
RMSFitVTB.GetXaxis().SetTitle(
"fit sigma (ns)")
305 self.
RMSFitVTB.GetYaxis().SetTitle(
"trigger bin")
308 self.
gaus = TF1(
"gaus",
'gaus(0)', -150, 100)
314 Function that allows to cicle on the events
317 mode_byte = svd_evt_info.getModeByte()
331 for svdCluster
in svdCluster_list:
332 svdRecoDigit = svdCluster.getRelatedTo(svd_recoDigits)
337 Terminates te class and produces the output rootfile
345 timeCal = SVDCoGCalibrationFunction()
347 tbBias = [-50, -50, -50, -50]
348 tbScale = [1, 1, 1, 1]
349 tbBias_err = [1, 1, 1, 1]
350 tbScale_err = [1, 1, 1, 1]
351 tbCovScaleBias = [1, 1, 1, 1]
357 geoCache = Belle2.VXD.GeoCache.getInstance()
358 for layer in geoCache.getLayers(Belle2.VXD.SensorInfoBase.SVD):
359 layerNumber = layer.getLayerNumber()
361 for ladder in geoCache.getLadders(layer):
362 ladderNumber = ladder.getLadderNumber()
363 ldi = ladderNumber - 1
364 for sensor in geoCache.getSensors(ladder):
365 sensorNumber = sensor.getSensorNumber()
366 si = sensorNumber - 1
367 for side in range(2):
369 n = self.nList[li][ldi][si][side][tb]
373 gDirectory.mkdir(
"plots")
374 gDirectory.cd(
"plots")
375 for layer
in geoCache.getLayers(Belle2.VXD.SensorInfoBase.SVD):
376 layerNumber = layer.getLayerNumber()
378 gDirectory.mkdir(
"layer" + str(layer))
379 gDirectory.cd(
"layer" + str(layer))
380 for ladder
in geoCache.getLadders(layer):
381 ladderNumber = ladder.getLadderNumber()
382 ldi = ladderNumber - 1
383 for sensor
in geoCache.getSensors(ladder):
384 sensorNumber = sensor.getSensorNumber()
385 si = sensorNumber - 1
386 for side
in range(2):
389 res = self.
resList[li][ldi][si][side][tb]
390 fitResult = int(TFitResultPtr(res.Fit(self.
gaus,
"R")))
392 if res.GetEntries() > 5:
408 cog = self.
cogList[li][ldi][si][side][tb]
411 cdc = self.
cdcList[li][ldi][si][side][tb]
414 snr = self.
snrList[li][ldi][si][side][tb]
415 snrMean = snr.GetMean()
418 sp = self.
spList[li][ldi][si][side][tb]
419 covscalebias = sp.GetCovariance()
420 pfxsp = sp.ProfileX()
425 m = sp.GetCovariance() / pow(sp.GetRMS(1), 2)
427 m_err = 2 / pow(sp.GetRMS(), 3) * sp.GetRMSError() * sp.GetCovariance()
428 q = sp.GetMean(2) - m * sp.GetMean(1)
429 q_err = math.sqrt(pow(sp.GetMeanError(2), 2) +
430 pow(m * sp.GetMeanError(1), 2) + pow(m_err * sp.GetMean(1), 2))
444 n = self.
nList[li][ldi][si][side][tb]
448 tbBias_err[tb] = q_err
449 tbScale_err[tb] = m_err
450 TCOGMEAN += n * (m * self.
sumCOGList[li][ldi][si][side][tb] / n + q) / self.
NTOT
455 "Mean of the CoG corrected distribution: " +
457 " Mean of the T0 distribution: " +
461 tbBias[0] = tbBias[0] - T0MEAN
462 tbBias[1] = tbBias[1] - T0MEAN
463 tbBias[2] = tbBias[2] - T0MEAN
464 tbBias[3] = tbBias[3] - T0MEAN
466 timeCal.set_bias(tbBias[0], tbBias[1], tbBias[2], tbBias[3])
467 timeCal.set_scale(tbScale[0], tbScale[1], tbScale[2], tbScale[3])
468 print(
"setting CoG calibration for " + str(layerNumber) +
"." + str(ladderNumber) +
"." + str(sensorNumber))
469 payload.set(layerNumber, ladderNumber, sensorNumber, bool(side), 1, timeCal)