27 from ROOT
import Belle2, TFile, TFitResultPtr, TH1F, TH2D, TH2F
28 from ROOT
import TF1, gDirectory, gROOT
30 from ROOT.Belle2
import SVDCoGCalibrationFunction
33 svd_recoDigits =
"SVDRecoDigitsFromTracks"
35 svd_Clusters =
"SVDClustersFromTracks"
44 Python class used for evaluating the CoG corrections, create a localDB,
45 creating a localDB with the corrections and a root file to check the corrections
50 Function that allows to set if apply the CDC latency correction
54 - if True -> not apply correction
55 - if False -> apply correction
61 def fillLists(self, mode_byte_object, svdClusters_rel_RecoTracks_cl):
63 Function that fill the lists needed for the CoG corrections
66 mode_byte_object (modeByte): modeByte that contains the information about the TB
67 svdClusters_rel_RecoTracks_cl (SVDCluster): cluster related to tracks
70 timeCluster = svdClusters_rel_RecoTracks_cl.getClsTime()
71 snrCluster = svdClusters_rel_RecoTracks_cl.getSNR()
72 layerCluster = svdClusters_rel_RecoTracks_cl.getSensorID().getLayerNumber()
73 layerIndex = layerCluster - 3
74 sensorCluster = svdClusters_rel_RecoTracks_cl.getSensorID().getSensorNumber()
75 sensorIndex = sensorCluster - 1
76 ladderCluster = svdClusters_rel_RecoTracks_cl.getSensorID().getLadderNumber()
77 ladderIndex = ladderCluster - 1
78 sideCluster = svdClusters_rel_RecoTracks_cl.isUCluster()
84 hasTimezero = self.
cdcEventT0cdcEventT0.hasEventT0()
87 TBClusters = mode_byte_object.getTriggerBin()
88 TBIndex = ord(TBClusters)
92 tZeroSync = tZero - 4000./509 * (3 - TBIndex)
97 resHist = self.
resListresList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
98 resHist.Fill(timeCluster - tZeroSync)
99 spHist = self.
spListspList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
101 spHist.Fill(timeCluster, tZeroSync)
102 cogHist = self.
cogListcogList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
103 cogHist.Fill(timeCluster)
104 cdcHist = self.
cdcListcdcList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
105 cdcHist.Fill(tZeroSync)
106 snrHist = self.
snrListsnrList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex]
107 snrHist.Fill(snrCluster)
109 self.
nListnList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex] += 1
110 self.
sumCOGListsumCOGList[layerIndex][ladderIndex][sensorIndex][sideIndex][TBIndex] += timeCluster
117 Function that allows to set the localDB
120 localDB (str): Name of the localDB used
127 Initialize object (histograms, lists, ...) used by the class
152 for layer
in geoCache.getLayers(Belle2.VXD.SensorInfoBase.SVD):
162 self.
resListresList.append(layerList0)
163 self.
spListspList.append(layerList1)
164 self.
cogListcogList.append(layerList2)
165 self.
cdcListcdcList.append(layerList3)
166 self.
snrListsnrList.append(layerList4)
167 self.
nListnList.append(layerList8)
170 for ladder
in geoCache.getLadders(layer):
180 layerList0.append(ladderList0)
181 layerList1.append(ladderList1)
182 layerList2.append(ladderList2)
183 layerList3.append(ladderList3)
184 layerList4.append(ladderList4)
185 layerList5.append(ladderList5)
186 layerList6.append(ladderList6)
187 layerList7.append(ladderList7)
188 layerList8.append(ladderList8)
190 for sensor
in geoCache.getSensors(ladder):
200 ladderList0.append(sensorList0)
201 ladderList1.append(sensorList1)
202 ladderList2.append(sensorList2)
203 ladderList3.append(sensorList3)
204 ladderList4.append(sensorList4)
205 ladderList5.append(sensorList5)
206 ladderList6.append(sensorList6)
207 ladderList7.append(sensorList7)
208 ladderList8.append(sensorList8)
210 for side
in range(2):
220 sensorList0.append(sideList0)
221 sensorList1.append(sideList1)
222 sensorList2.append(sideList2)
223 sensorList3.append(sideList3)
224 sensorList4.append(sideList4)
225 sensorList5.append(sideList5)
226 sensorList6.append(sideList6)
227 sensorList7.append(sideList7)
228 sensorList8.append(sideList8)
230 for i
in geoCache.getLayers(Belle2.VXD.SensorInfoBase.SVD):
231 layerN = i.getLayerNumber()
233 for j
in geoCache.getLadders(i):
234 ladderN = j.getLadderNumber()
236 for k
in geoCache.getSensors(j):
237 sensorN = k.getSensorNumber()
241 self.
resListresList[li][ldi][si][s].append(
242 TH1F(
"res" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 200, -100, 100))
243 self.
spListspList[li][ldi][si][s].append(
244 TH2D(
"sp" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 300, -150, 150, 300, -150, 150))
245 self.
cogListcogList[li][ldi][si][s].append(
246 TH1F(
"cog" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 200, -100, 100))
247 self.
cdcListcdcList[li][ldi][si][s].append(
248 TH1F(
"cdc" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 200, -100, 100))
249 self.
snrListsnrList[li][ldi][si][s].append(
250 TH1F(
"snr" +
"_" + str(k) +
"." + str(s) +
"." + str(t),
" ", 100, 0, 100))
251 self.
nListnList[li][ldi][si][s].append(0)
252 self.
sumCOGListsumCOGList[li][ldi][si][s].append(0)
254 self.
EventT0HistEventT0Hist = TH1F(
"EventT0",
" ", 200, -100, 100)
256 self.
AlphaUTBAlphaUTB = TH2F(
"alphaVsTB_U",
" ", 400, 0.5, 2, 4, 0, 4)
257 self.
AlphaUTBAlphaUTB.GetXaxis().SetTitle(
"alpha")
258 self.
AlphaUTBAlphaUTB.GetYaxis().SetTitle(
"trigger bin")
260 self.
AlphaVTBAlphaVTB = TH2F(
"alphaVsTB_V",
" ", 400, 0.5, 2, 4, 0, 4)
261 self.
AlphaVTBAlphaVTB.GetXaxis().SetTitle(
"alpha")
262 self.
AlphaVTBAlphaVTB.GetYaxis().SetTitle(
"trigger bin")
264 self.
BetaUTBBetaUTB = TH2F(
"betaVsTB_U",
" ", 200, -100, 100, 4, 0, 4)
265 self.
BetaUTBBetaUTB.GetXaxis().SetTitle(
"beta (ns)")
266 self.
BetaUTBBetaUTB.GetYaxis().SetTitle(
"trigger bin")
268 self.
BetaVTBBetaVTB = TH2F(
"betaVsTB_V",
" ", 200, -100, 100, 4, 0, 4)
269 self.
BetaVTBBetaVTB.GetXaxis().SetTitle(
"beta (ns)")
270 self.
BetaVTBBetaVTB.GetYaxis().SetTitle(
"trigger bin")
273 self.
MeanHistVTBMeanHistVTB = TH2F(
"meanHistVsTB_V",
" ", 100, -10, 10, 4, 0, 4)
274 self.
MeanHistVTBMeanHistVTB.GetXaxis().SetTitle(
"distribution mean (ns)")
275 self.
MeanHistVTBMeanHistVTB.GetYaxis().SetTitle(
"trigger bin")
277 self.
MeanHistUTBMeanHistUTB = TH2F(
"meanHistVsTB_U",
" ", 100, -10, 10, 4, 0, 4)
278 self.
MeanHistUTBMeanHistUTB.GetXaxis().SetTitle(
"distribution mean (ns)")
279 self.
MeanHistUTBMeanHistUTB.GetYaxis().SetTitle(
"trigger bin")
281 self.
RMSHistVTBRMSHistVTB = TH2F(
"rmsHistVsTB_V",
" ", 100, 0, 10, 4, 0, 4)
282 self.
RMSHistVTBRMSHistVTB.GetXaxis().SetTitle(
"distribution RMS (ns)")
283 self.
RMSHistVTBRMSHistVTB.GetYaxis().SetTitle(
"trigger bin")
285 self.
RMSHistUTBRMSHistUTB = TH2F(
"rmsHistVsTB_U",
" ", 100, 0, 10, 4, 0, 4)
286 self.
RMSHistUTBRMSHistUTB.GetXaxis().SetTitle(
"distribution RMS (ns)")
287 self.
RMSHistUTBRMSHistUTB.GetYaxis().SetTitle(
"trigger bin")
289 self.
MeanFitVTBMeanFitVTB = TH2F(
"meanFitVsTB_V",
" ", 100, -10, 10, 4, 0, 4)
290 self.
MeanFitVTBMeanFitVTB.GetXaxis().SetTitle(
"fit mean (ns)")
291 self.
MeanFitVTBMeanFitVTB.GetYaxis().SetTitle(
"trigger bin")
293 self.
MeanFitUTBMeanFitUTB = TH2F(
"meanFitVsTB_U",
" ", 100, -10, 10, 4, 0, 4)
294 self.
MeanFitUTBMeanFitUTB.GetXaxis().SetTitle(
"fit mean (ns)")
295 self.
MeanFitUTBMeanFitUTB.GetYaxis().SetTitle(
"trigger bin")
297 self.
RMSFitUTBRMSFitUTB = TH2F(
"rmsFitVsTB_U",
" ", 100, 0, 10, 4, 0, 4)
298 self.
RMSFitUTBRMSFitUTB.GetXaxis().SetTitle(
"fit sigma (ns)")
299 self.
RMSFitUTBRMSFitUTB.GetYaxis().SetTitle(
"trigger bin")
301 self.
RMSFitVTBRMSFitVTB = TH2F(
"rmsFitVsTB_V",
" ", 100, 0, 10, 4, 0, 4)
302 self.
RMSFitVTBRMSFitVTB.GetXaxis().SetTitle(
"fit sigma (ns)")
303 self.
RMSFitVTBRMSFitVTB.GetYaxis().SetTitle(
"trigger bin")
306 self.
gausgaus = TF1(
"gaus",
'gaus(0)', -150, 100)
312 Function that allows to cicle on the events
315 mode_byte = svd_evt_info.getModeByte()
322 self.
EvtEvt = self.
EvtEvt + 1
329 for svdCluster
in svdCluster_list:
331 self.
fillListsfillLists(mode_byte, svdCluster)
335 Terminates te class and produces the output rootfile
343 timeCal = SVDCoGCalibrationFunction()
345 tbBias = [-50, -50, -50, -50]
346 tbScale = [1, 1, 1, 1]
347 tbBias_err = [1, 1, 1, 1]
348 tbScale_err = [1, 1, 1, 1]
355 geoCache = Belle2.VXD.GeoCache.getInstance()
356 for layer in geoCache.getLayers(Belle2.VXD.SensorInfoBase.SVD):
357 layerNumber = layer.getLayerNumber()
359 for ladder in geoCache.getLadders(layer):
360 ladderNumber = ladder.getLadderNumber()
361 ldi = ladderNumber - 1
362 for sensor in geoCache.getSensors(ladder):
363 sensorNumber = sensor.getSensorNumber()
364 si = sensorNumber - 1
365 for side in range(2):
367 n = self.nList[li][ldi][si][side][tb]
371 gDirectory.mkdir(
"plots")
372 gDirectory.cd(
"plots")
373 for layer
in geoCache.getLayers(Belle2.VXD.SensorInfoBase.SVD):
374 layerNumber = layer.getLayerNumber()
376 gDirectory.mkdir(
"layer" + str(layer))
377 gDirectory.cd(
"layer" + str(layer))
378 for ladder
in geoCache.getLadders(layer):
379 ladderNumber = ladder.getLadderNumber()
380 ldi = ladderNumber - 1
381 for sensor
in geoCache.getSensors(ladder):
382 sensorNumber = sensor.getSensorNumber()
383 si = sensorNumber - 1
384 for side
in range(2):
387 res = self.
resListresList[li][ldi][si][side][tb]
388 fitResult = int(TFitResultPtr(res.Fit(self.
gausgaus,
"R")))
390 if res.GetEntries() > 5:
392 self.
MeanHistUTBMeanHistUTB.Fill(res.GetMean(), tb)
393 self.
RMSHistUTBRMSHistUTB.Fill(res.GetRMS(), tb)
396 self.
RMSFitUTBRMSFitUTB.Fill(self.
gausgaus.GetParameter(2), tb)
398 self.
MeanHistVTBMeanHistVTB.Fill(res.GetMean(), tb)
399 self.
RMSHistVTBRMSHistVTB.Fill(res.GetRMS(), tb)
402 self.
RMSFitVTBRMSFitVTB.Fill(self.
gausgaus.GetParameter(2), tb)
406 cog = self.
cogListcogList[li][ldi][si][side][tb]
409 cdc = self.
cdcListcdcList[li][ldi][si][side][tb]
412 snr = self.
snrListsnrList[li][ldi][si][side][tb]
416 sp = self.
spListspList[li][ldi][si][side][tb]
418 pfxsp = sp.ProfileX()
423 m = sp.GetCovariance() / pow(sp.GetRMS(1), 2)
425 m_err = 2 / pow(sp.GetRMS(), 3) * sp.GetRMSError() * sp.GetCovariance()
426 q = sp.GetMean(2) - m * sp.GetMean(1)
427 q_err = math.sqrt(pow(sp.GetMeanError(2), 2) +
428 pow(m * sp.GetMeanError(1), 2) + pow(m_err * sp.GetMean(1), 2))
437 self.
BetaUTBBetaUTB.Fill(q, tb)
440 self.
BetaVTBBetaVTB.Fill(q, tb)
442 n = self.
nListnList[li][ldi][si][side][tb]
446 tbBias_err[tb] = q_err
447 tbScale_err[tb] = m_err
448 TCOGMEAN += n * (m * self.
sumCOGListsumCOGList[li][ldi][si][side][tb] / n + q) / self.
NTOTNTOT
453 "Mean of the CoG corrected distribution: " +
455 " Mean of the T0 distribution: " +
459 tbBias[0] = tbBias[0] - T0MEAN
460 tbBias[1] = tbBias[1] - T0MEAN
461 tbBias[2] = tbBias[2] - T0MEAN
462 tbBias[3] = tbBias[3] - T0MEAN
464 timeCal.set_bias(tbBias[0], tbBias[1], tbBias[2], tbBias[3])
465 timeCal.set_scale(tbScale[0], tbScale[1], tbScale[2], tbScale[3])
466 print(
"setting CoG calibration for " + str(layerNumber) +
"." + str(ladderNumber) +
"." + str(sensorNumber))
467 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.