26from ROOT
import Belle2, TFile, TFitResultPtr, TH1F, TH2D, TH2F
27from ROOT
import TF1, gDirectory, gROOT
29from ROOT.Belle2
import SVDCoGCalibrationFunction
32svd_recoDigits =
"SVDRecoDigitsFromTracks"
34svd_Clusters =
"SVDClustersFromTracks"
43 Python class used for evaluating the CoG corrections, create a localDB,
44 creating a localDB
with the corrections
and a root file to check the corrections
49 Function that allows to set if apply the CDC latency correction
53 -
if True ->
not apply correction
54 -
if False -> apply correction
60 def fillLists(self, mode_byte_object, svdClusters_rel_RecoTracks_cl):
62 Function that fill the lists needed for the CoG corrections
65 mode_byte_object (modeByte): modeByte that contains the information about the TB
66 svdClusters_rel_RecoTracks_cl (SVDCluster): cluster related to tracks
69 timeCluster = svdClusters_rel_RecoTracks_cl.getClsTime()
70 snrCluster = svdClusters_rel_RecoTracks_cl.getSNR()
71 layerCluster = svdClusters_rel_RecoTracks_cl.getSensorID().getLayerNumber()
72 layerIndex = layerCluster - 3
73 sensorCluster = svdClusters_rel_RecoTracks_cl.getSensorID().getSensorNumber()
74 sensorIndex = sensorCluster - 1
75 ladderCluster = svdClusters_rel_RecoTracks_cl.getSensorID().getLadderNumber()
76 ladderIndex = ladderCluster - 1
77 sideCluster = svdClusters_rel_RecoTracks_cl.isUCluster()
86 TBClusters = mode_byte_object.getTriggerBin()
87 TBIndex = ord(TBClusters)
91 tZeroSync = tZero - 4000./509 * (3 - TBIndex)
96 resHist = self.
resList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
97 resHist.Fill(timeCluster - tZeroSync)
98 spHist = self.
spList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
100 spHist.Fill(timeCluster, tZeroSync)
101 cogHist = self.
cogList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
102 cogHist.Fill(timeCluster)
103 cdcHist = self.
cdcList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
104 cdcHist.Fill(tZeroSync)
105 snrHist = self.
snrList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
106 snrHist.Fill(snrCluster)
108 self.
nList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex] += 1
109 self.
sumCOGList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex] += timeCluster
116 Function that allows to set the localDB
119 localDB (str): Name of the localDB used
126 Initialize object (histograms, lists, ...) used by the class
151 for layer
in geoCache.getLayers(Belle2.VXD.SensorInfoBase.SVD):
161 self.
resList.append(layerList0)
162 self.
spList.append(layerList1)
163 self.
cogList.append(layerList2)
164 self.
cdcList.append(layerList3)
165 self.
snrList.append(layerList4)
166 self.
nList.append(layerList8)
169 for ladder
in geoCache.getLadders(layer):
179 layerList0.append(ladderList0)
180 layerList1.append(ladderList1)
181 layerList2.append(ladderList2)
182 layerList3.append(ladderList3)
183 layerList4.append(ladderList4)
184 layerList5.append(ladderList5)
185 layerList6.append(ladderList6)
186 layerList7.append(ladderList7)
187 layerList8.append(ladderList8)
189 for sensor
in geoCache.getSensors(ladder):
199 ladderList0.append(sensorList0)
200 ladderList1.append(sensorList1)
201 ladderList2.append(sensorList2)
202 ladderList3.append(sensorList3)
203 ladderList4.append(sensorList4)
204 ladderList5.append(sensorList5)
205 ladderList6.append(sensorList6)
206 ladderList7.append(sensorList7)
207 ladderList8.append(sensorList8)
209 for side
in range(2):
219 sensorList0.append(sideList0)
220 sensorList1.append(sideList1)
221 sensorList2.append(sideList2)
222 sensorList3.append(sideList3)
223 sensorList4.append(sideList4)
224 sensorList5.append(sideList5)
225 sensorList6.append(sideList6)
226 sensorList7.append(sideList7)
227 sensorList8.append(sideList8)
229 for i
in geoCache.getLayers(Belle2.VXD.SensorInfoBase.SVD):
230 layerN = i.getLayerNumber()
232 for j
in geoCache.getLadders(i):
233 ladderN = j.getLadderNumber()
235 for k
in geoCache.getSensors(j):
236 sensorN = k.getSensorNumber()
240 self.
resList[li][ldi][si][s].append(
241 TH1F(
"res" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 200, -100, 100))
242 self.
spList[li][ldi][si][s].append(
243 TH2D(
"sp" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 300, -150, 150, 300, -150, 150))
244 self.
cogList[li][ldi][si][s].append(
245 TH1F(
"cog" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 200, -100, 100))
246 self.
cdcList[li][ldi][si][s].append(
247 TH1F(
"cdc" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 200, -100, 100))
248 self.
snrList[li][ldi][si][s].append(
249 TH1F(
"snr" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 100, 0, 100))
250 self.
nList[li][ldi][si][s].append(0)
255 self.
AlphaUTB = TH2F(
"alphaVsTB_U",
" ", 400, 0.5, 2, 4, 0, 4)
256 self.
AlphaUTB.GetXaxis().SetTitle(
"alpha")
257 self.
AlphaUTB.GetYaxis().SetTitle(
"trigger bin")
259 self.
AlphaVTB = TH2F(
"alphaVsTB_V",
" ", 400, 0.5, 2, 4, 0, 4)
260 self.
AlphaVTB.GetXaxis().SetTitle(
"alpha")
261 self.
AlphaVTB.GetYaxis().SetTitle(
"trigger bin")
263 self.
BetaUTB = TH2F(
"betaVsTB_U",
" ", 200, -100, 100, 4, 0, 4)
264 self.
BetaUTB.GetXaxis().SetTitle(
"beta (ns)")
265 self.
BetaUTB.GetYaxis().SetTitle(
"trigger bin")
267 self.
BetaVTB = TH2F(
"betaVsTB_V",
" ", 200, -100, 100, 4, 0, 4)
268 self.
BetaVTB.GetXaxis().SetTitle(
"beta (ns)")
269 self.
BetaVTB.GetYaxis().SetTitle(
"trigger bin")
272 self.
MeanHistVTB = TH2F(
"meanHistVsTB_V",
" ", 100, -10, 10, 4, 0, 4)
273 self.
MeanHistVTB.GetXaxis().SetTitle(
"distribution mean (ns)")
274 self.
MeanHistVTB.GetYaxis().SetTitle(
"trigger bin")
276 self.
MeanHistUTB = TH2F(
"meanHistVsTB_U",
" ", 100, -10, 10, 4, 0, 4)
277 self.
MeanHistUTB.GetXaxis().SetTitle(
"distribution mean (ns)")
278 self.
MeanHistUTB.GetYaxis().SetTitle(
"trigger bin")
280 self.
RMSHistVTB = TH2F(
"rmsHistVsTB_V",
" ", 100, 0, 10, 4, 0, 4)
281 self.
RMSHistVTB.GetXaxis().SetTitle(
"distribution RMS (ns)")
282 self.
RMSHistVTB.GetYaxis().SetTitle(
"trigger bin")
284 self.
RMSHistUTB = TH2F(
"rmsHistVsTB_U",
" ", 100, 0, 10, 4, 0, 4)
285 self.
RMSHistUTB.GetXaxis().SetTitle(
"distribution RMS (ns)")
286 self.
RMSHistUTB.GetYaxis().SetTitle(
"trigger bin")
288 self.
MeanFitVTB = TH2F(
"meanFitVsTB_V",
" ", 100, -10, 10, 4, 0, 4)
289 self.
MeanFitVTB.GetXaxis().SetTitle(
"fit mean (ns)")
290 self.
MeanFitVTB.GetYaxis().SetTitle(
"trigger bin")
292 self.
MeanFitUTB = TH2F(
"meanFitVsTB_U",
" ", 100, -10, 10, 4, 0, 4)
293 self.
MeanFitUTB.GetXaxis().SetTitle(
"fit mean (ns)")
294 self.
MeanFitUTB.GetYaxis().SetTitle(
"trigger bin")
296 self.
RMSFitUTB = TH2F(
"rmsFitVsTB_U",
" ", 100, 0, 10, 4, 0, 4)
297 self.
RMSFitUTB.GetXaxis().SetTitle(
"fit sigma (ns)")
298 self.
RMSFitUTB.GetYaxis().SetTitle(
"trigger bin")
300 self.
RMSFitVTB = TH2F(
"rmsFitVsTB_V",
" ", 100, 0, 10, 4, 0, 4)
301 self.
RMSFitVTB.GetXaxis().SetTitle(
"fit sigma (ns)")
302 self.
RMSFitVTB.GetYaxis().SetTitle(
"trigger bin")
305 self.
gaus = TF1(
"gaus",
'gaus(0)', -150, 100)
311 Function that allows to cicle on the events
314 mode_byte = svd_evt_info.getModeByte()
328 for svdCluster
in svdCluster_list:
334 Terminates te class and produces the output rootfile
342 timeCal = SVDCoGCalibrationFunction()
344 tbBias = [-50, -50, -50, -50]
345 tbScale = [1, 1, 1, 1]
346 tbBias_err = [1, 1, 1, 1]
347 tbScale_err = [1, 1, 1, 1]
355 for layer
in geoCache.getLayers(Belle2.VXD.SensorInfoBase.SVD):
356 layerNumber = layer.getLayerNumber()
358 for ladder
in geoCache.getLadders(layer):
359 ladderNumber = ladder.getLadderNumber()
360 ldi = ladderNumber - 1
361 for sensor
in geoCache.getSensors(ladder):
362 sensorNumber = sensor.getSensorNumber()
363 si = sensorNumber - 1
364 for side
in range(2):
366 n = self.
nList[li][ldi][si][side][tb]
370 gDirectory.mkdir("plots")
371 gDirectory.cd(
"plots")
372 for layer
in geoCache.getLayers(Belle2.VXD.SensorInfoBase.SVD):
373 layerNumber = layer.getLayerNumber()
375 gDirectory.mkdir(
"layer" + str(layer))
376 gDirectory.cd(
"layer" + str(layer))
377 for ladder
in geoCache.getLadders(layer):
378 ladderNumber = ladder.getLadderNumber()
379 ldi = ladderNumber - 1
380 for sensor
in geoCache.getSensors(ladder):
381 sensorNumber = sensor.getSensorNumber()
382 si = sensorNumber - 1
383 for side
in range(2):
386 res = self.
resList[li][ldi][si][side][tb]
387 fitResult = int(TFitResultPtr(res.Fit(self.
gaus,
"R")))
389 if res.GetEntries() > 5:
405 cog = self.
cogList[li][ldi][si][side][tb]
408 cdc = self.
cdcList[li][ldi][si][side][tb]
411 snr = self.
snrList[li][ldi][si][side][tb]
415 sp = self.
spList[li][ldi][si][side][tb]
417 pfxsp = sp.ProfileX()
422 m = sp.GetCovariance() / pow(sp.GetRMS(1), 2)
424 m_err = 2 / pow(sp.GetRMS(), 3) * sp.GetRMSError() * sp.GetCovariance()
425 q = sp.GetMean(2) - m * sp.GetMean(1)
426 q_err = math.sqrt(pow(sp.GetMeanError(2), 2) +
427 pow(m * sp.GetMeanError(1), 2) + pow(m_err * sp.GetMean(1), 2))
441 n = self.
nList[li][ldi][si][side][tb]
445 tbBias_err[tb] = q_err
446 tbScale_err[tb] = m_err
447 TCOGMEAN += n * (m * self.
sumCOGList[li][ldi][si][side][tb] / n + q) / self.
NTOT
452 "Mean of the CoG corrected distribution: " +
454 " Mean of the T0 distribution: " +
458 tbBias[0] = tbBias[0] - T0MEAN
459 tbBias[1] = tbBias[1] - T0MEAN
460 tbBias[2] = tbBias[2] - T0MEAN
461 tbBias[3] = tbBias[3] - T0MEAN
463 timeCal.set_bias(tbBias[0], tbBias[1], tbBias[2], tbBias[3])
464 timeCal.set_scale(tbScale[0], tbScale[1], tbScale[2], tbScale[3])
465 print(
"setting CoG calibration for " + str(layerNumber) +
"." + str(ladderNumber) +
"." + str(sensorNumber))
466 payload.set(layerNumber, ladderNumber, sensorNumber, bool(side), 1, timeCal)
static IntervalOfValidity always()
Function that returns an interval of validity that is always valid, c.f.
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
base class for calibrations classes
static GeoCache & getInstance()
Return a reference to the singleton instance.
gaus
gaus function used for fitting distributions
MeanHistVTB
mean of the residuals distribution vs TB, for V side
Evt
counts the number of events
notApplyCDCLatencyCorrection
parameter that allows to apply or not the CDC latency correction
RMSFitUTB
RMS of the residuals distribution vs TB, for U side (from gaussian fit)
EventT0Hist
distribution of EventT0
resList
lists used to create the histograms for each TB : residuals
RMSFitVTB
RMS of the residuals distribution vs TB, for V side (from gaussian fit)
BetaUTB
beta parameter vs TB, for U side
def set_localdb(self, localDB)
NTOT
counts the number of clusters
MeanFitUTB
mean of the residuals distribution vs TB, for U side (from gaussian fit)
localdb
set the name of the localDB used
cdcEventT0
registers PyStoreObj EventT0
AlphaUTB
alpha parameter vs TB, for U side
AlphaVTB
alpha parameter vs TB, for V side
def fillLists(self, mode_byte_object, svdClusters_rel_RecoTracks_cl)
MeanFitVTB
mean of the residuals distribution vs TB, for V side (from gaussian fit)
outputFileName
name of the output file
BetaVTB
beta parameter vs TB, for V side
spList
scatterplot t0 vs cog
MeanHistUTB
mean of the residuals distribution vs TB, for U side
def notApplyCorrectForCDCLatency(self, mode)
sumCOGList
sum of CoG times
RMSHistVTB
RMS of the residuals distribution vs TB, for V side.
RMSHistUTB
RMS of the residuals distribution vs TB, for U side.
static Database & Instance()
Instance of a singleton Database.