Belle II Software  release-05-01-25
plotInterimFEDataNtuple.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # ---------------------------------------------------------------------------------------
5 # draw summary plots from output of makeInterimFEDataNtuple module (run******_slot**_ana.root)
6 # Contibutors: Maeda Yosuke and Umberto Tamponi
7 #
8 # Usage: basf2 plotInterimFEDataNtuple <output root file of makeInterimFEDataNtuple.py> (to be called in this steering file)
9 # ---------------------------------------------------------------------------------------
10 
11 import sys
12 import time
13 from basf2 import *
14 from ROOT import gROOT
15 gROOT.SetBatch(True)
16 from ROOT import gStyle, gPad, TFile, TTree, TStyle, TCanvas, TH1F, TH2F, TF1, TLegend, TAxis, TPaveStats, TLatex, TLine, TArrow
17 
18 
19 def plotInterimFEDataNtupleSummary(root_output, FitWidth=2, IsOfflineFEDisabled=False):
20 
21  DelayTimeRefl = 30 # [ns]
22  ReflHalfTimwRange = 5 # [ns]
23 
24  pdf_output = root_output[0:root_output.rfind(".root")] + "_Summary.pdf"
25 
26  print(root_output + " --> " + pdf_output)
27 
28  gStyle.SetFrameFillStyle(0)
29  gStyle.SetFillStyle(0)
30  gStyle.SetStatX(0.9)
31  gStyle.SetStatY(0.9)
32  gStyle.SetStatStyle(0)
33  gStyle.SetOptStat(112210)
34  gStyle.SetOptFit(1110)
35  canvas = TCanvas("cv1", "cv1", 800, 800)
36  canvas.SetFillStyle(0)
37  canvas.Print((pdf_output + "["))
38 
39  f = TFile(root_output)
40  tr = f.Get("tree")
41  nEntries = tr.GetEntries()
42 
43  latex = TLatex()
44  latex.SetNDC()
45  latex.SetTextSize(0.03)
46  latex.SetTextAlign(33)
47 
48  print("making summary plot for all the slots...")
49  canvas.Clear()
50  canvas.Divide(2, 2)
51  canvas.cd(1)
52  gPad.SetFrameFillStyle(0)
53  gPad.SetFillStyle(0)
54  tr.Draw("eventNum[0]>>hNHit", "(nHit>0)*(Sum$(offlineFlag<=0))")
55  tr.Draw("eventNum[0]>>hHeader", "(nHit>0)*(nFEHeader)")
56  tr.Draw("eventNum[0]>>hEmptyHeader", "(nHit>0)*(nEmptyFEHeader)")
57  tr.Draw("eventNum[0]>>hWfm", "(nHit>0)*(nWaveform)")
58  tr.Draw("eventNum[0]>>hError", "(nHit>0)*(errorFlag>0)")
59  hNHit = gROOT.FindObject("hNHit")
60  if hNHit.Integral() < 1:
61  print("ERROR : no hits were found.")
62  return
63  hHeader = gROOT.FindObject("hHeader")
64  hEmptyHeader = gROOT.FindObject("hEmptyHeader")
65  hWfm = gROOT.FindObject("hWfm")
66  hError = gROOT.FindObject("hError")
67  BinWidth = hNHit.GetXaxis().GetBinUpEdge(1) - hNHit.GetXaxis().GetBinLowEdge(1)
68  hNHit.Scale(1. / BinWidth)
69  hHeader.Scale(1. / BinWidth)
70  hEmptyHeader.Scale(1. / BinWidth)
71  hWfm.Scale(1. / BinWidth)
72  hError.Scale(1. / BinWidth)
73  hNHit.SetStats(False)
74  hNHit.SetTitle(root_output + " - # hits/headers/waveforms")
75  hNHit.SetLineColor(1)
76  hHeader.SetLineColor(2)
77  hEmptyHeader.SetLineColor(3)
78  hWfm.SetLineColor(4)
79  hError.SetLineColor(6)
80  legend = TLegend(0.6, 0.175, 0.875, 0.4)
81  legend.SetFillStyle(0)
82  legend.SetBorderSize(0)
83  legend.AddEntry(hNHit, "nHit (no offline FE)")
84  legend.AddEntry(hHeader, "# of FE headers")
85  legend.AddEntry(hEmptyHeader, "# of empty FE headers")
86  legend.AddEntry(hWfm, "# of waveforms")
87  hNHit.GetXaxis().SetTitle("event number")
88  ytitle = "average # every " + str(BinWidth) + " events"
89  hNHit.GetYaxis().SetTitle(ytitle)
90  hNHit.GetYaxis().SetRangeUser(0, 1.05 * hHeader.GetBinContent(hHeader.GetMaximumBin()))
91  gPad.Clear()
92  hNHit.Draw("hist")
93  hHeader.Draw("samehist")
94  hEmptyHeader.Draw("samehist")
95  hWfm.Draw("samehist")
96  legend.Draw()
97  if hWfm.Integral() > 0:
98  evtFracNoWfm = 1 - hWfm.Integral() / hNHit.Integral()
99  print("fraction of events without waveform : " + str(int(1000 * evtFracNoWfm) / 10) + "%")
100  latex.DrawLatex(0.875, 0.175, "fraction of no-waveform events : " + str(int(1000 * evtFracNoWfm) / 10) + "%")
101  print(".", end="")
102 
103  canvas.cd(2)
104  gPad.SetFrameFillStyle(0)
105  gPad.SetFillStyle(0)
106  if hError.GetEntries() > 0:
107  hError.SetStats(False)
108  hError.SetTitle(root_output + " - error rate")
109  hError.GetXaxis().SetTitle("event number")
110  ytitle = "fraction of events with any errors for every" + str(BinWidth) + " events"
111  hError.GetYaxis().SetTitle(ytitle)
112  hError.Draw("hist")
113  else:
114  latex.SetTextSize(0.1)
115  latex.SetTextAlign(22)
116  latex.DrawLatex(0.5, 0.5, "NO ERROR DETECTED")
117  print(".", end="")
118 
119  canvas.cd(3)
120  gPad.SetFrameFillStyle(0)
121  gPad.SetFillStyle(0)
122  hSlotNumAll = TH1F("hSlotNumAll", "", 17, -0.5, 16.5)
123  hSlotNumNoCalCh = TH1F("hSlotNumNoCalCh", "", 17, -0.5, 16.5)
124  basicHitSelection = "hitQuality>0" # && hitQuality<50 && hitQuality%10!=4"
125  basicHitSelectionSingle = basicHitSelection + "&& offlineFlag<=0"
126  tr.Draw("Sum$(" + basicHitSelectionSingle + ")>>hNHitAllSlots(100,-0.5,499.5)")
127  tr.Draw("Sum$(" + basicHitSelectionSingle + "&&!isCalCh)>>hNHitAllSlotsNoCalCh(100,-0.5,499.5)")
128  tr.Draw("rawTime>>hRawTimeAll(128,-128,640)", "hitQuality%10<4 && hitQuality>0")
129  hNHitAll = [gROOT.FindObject("hNHitAllSlots")]
130  hNHitNoCalCh = [gROOT.FindObject("hNHitAllSlotsNoCalCh")]
131  hRawTimeList = [gROOT.FindObject("hRawTimeAll")]
132  nSlotEntriesAll = []
133  nSlotEntriesNoCalCh = []
134  nSlotEntriesCalCh = []
135  nSlotEntriesCalChWfm = []
136  nHitMeanAll = []
137  nHitMeanNoCalCh = []
138  nHitMeanLaser = []
139  strMultiplicity = "0"
140  for slot in range(1, 17):
141  slotCut = " && slotNum==" + str(slot)
142  tr.Draw("Sum$(" + basicHitSelectionSingle + slotCut + ")>>hNHitAll" + str(slot) + "(90,2.5,92.5)")
143  tr.Draw("Sum$(" + basicHitSelectionSingle + " && !isCalCh" + slotCut + ")>>hNHitNoCalCh" + str(slot) + "(90,2.5,92.5)")
144  tr.Draw("rawTime>>hRawTime" + str(slot) + "(128,-128,1152)",
145  "hitQuality>0 " + slotCut)
146  hNHitAllTmp = gROOT.FindObject("hNHitAll" + str(slot))
147  hNHitNoCalChTmp = gROOT.FindObject("hNHitNoCalCh" + str(slot))
148  hRawTimeTmp = gROOT.FindObject("hRawTime" + str(slot))
149  hNHitAll.append(hNHitAllTmp)
150  hNHitNoCalCh.append(hNHitNoCalChTmp)
151  hRawTimeList.append(hRawTimeTmp)
152  nSlotEntriesAllTmp = hNHitAllTmp.Integral(hNHitAllTmp.GetXaxis().FindBin(3), hNHitAllTmp.GetXaxis().GetNbins() + 1)
153  nSlotEntriesNoCalChTmp = hNHitNoCalChTmp.Integral(
154  hNHitNoCalChTmp.GetXaxis().FindBin(3),
155  hNHitNoCalChTmp.GetXaxis().GetNbins() + 1)
156  hSlotNumAll.SetBinContent(slot + 1, nSlotEntriesAllTmp)
157  hSlotNumNoCalCh.SetBinContent(slot + 1, nSlotEntriesNoCalChTmp)
158  nSlotEntriesAll.append(nSlotEntriesAllTmp)
159  nSlotEntriesCalCh.append(-1)
160  nSlotEntriesCalChWfm.append(-1)
161  nSlotEntriesNoCalCh.append(nSlotEntriesNoCalChTmp)
162  nHitMeanAll.append(hNHitAllTmp.GetMean())
163  nHitMeanNoCalCh.append(hNHitNoCalChTmp.GetMean())
164  nHitMeanLaser.append(-1) # defined later
165  strMultiplicity += (" + (Sum$(" + basicHitSelectionSingle + slotCut + ")>=3)")
166  print(".", end="")
167 
168  hSlotNumAll.SetLineColor(1)
169  hSlotNumNoCalCh.SetLineColor(2)
170  hSlotNumAll.SetFillStyle(0)
171  hSlotNumNoCalCh.SetFillStyle(0)
172  hSlotNumAll.SetStats(False)
173  hSlotNumAll.Draw()
174  hSlotNumAll.GetYaxis().SetRangeUser(0, nEntries * 1.2)
175  hSlotNumAll.SetTitle("hit event number (nHit>=3) for each slot and multiplicity")
176  hSlotNumAll.GetXaxis().SetTitle("slot number")
177  line = TLine()
178  line.SetLineColor(4)
179  line.SetLineStyle(2)
180  line.DrawLine(-0.5, nEntries, 16.5, nEntries)
181  hSlotNumNoCalCh.Draw("same")
182  tr.Draw(strMultiplicity + ">>hMultiplicity", "", "same")
183  hMultiplicity = gROOT.FindObject("hMultiplicity")
184  hMultiplicity.SetFillStyle(0)
185  hMultiplicity.SetLineColor(3)
186  legendSlot = TLegend(0.5, 0.65, 0.875, 0.875)
187  legendSlot.SetFillStyle(0)
188  legendSlot.SetBorderSize(0)
189  legendSlot.AddEntry(hSlotNumAll, "all channels, single hit")
190  legendSlot.AddEntry(hSlotNumNoCalCh, "w/o cal. channels, single hit")
191  legendSlot2 = TLegend(legendSlot)
192  legendSlot2.AddEntry(hMultiplicity, "# of hit modules")
193  legendSlot2.Draw()
194  print(".", end="")
195 
196  canvas.cd(4)
197  gPad.SetFrameFillStyle(0)
198  gPad.SetFillStyle(0)
199  hNHitAll[0].SetLineColor(1)
200  hNHitNoCalCh[0].SetLineColor(2)
201  hNHitAll[0].SetStats(False)
202  hNHitAll[0].SetTitle("# of total FE hits for all available slots")
203  hNHitAll[0].GetXaxis().SetTitle("# of hits")
204  hNHitAll[0].Draw()
205  hNHitNoCalCh[0].Draw("same")
206  legendSlot.Draw()
207  LaserAdded = False
208  print(".")
209 
210  canvas.Print(pdf_output)
211  canvas.Clear()
212 
213  canvas.Divide(4, 4)
214  for slot in range(1, 17):
215  canvas.cd(slot)
216  hRawTime = hRawTimeList[slot]
217  hRawTime.SetStats(False)
218  hRawTime.SetTitle("rawTime distribution")
219  hRawTime.GetXaxis().SetTitle("rawTime")
220  ytitle = "Entries [/(" + str(hRawTime.GetXaxis().GetBinUpEdge(1) - hRawTime.GetXaxis().GetBinLowEdge(1)) + " samples)]"
221  hRawTime.GetYaxis().SetTitle(ytitle)
222  slotstr = "slot" + "{0:02d}".format(slot)
223  hRawTime.SetTitle("rawTime distribution : " + slotstr)
224  hRawTime.Draw()
225  canvas.Print(pdf_output)
226  canvas.Clear()
227 
228  for slot in range(1, 17):
229 
230  slotCut = "slotNum==" + str(slot)
231  if tr.GetEntries(slotCut) < 1:
232  print("slot : " + str(slot) + " : no events")
233  continue
234  else:
235  print("slot : " + str(slot) + " : processing...")
236 
237  slotstr = "slot" + "{0:02d}".format(slot)
238 
239  gStyle.SetStatX(0.875)
240  gStyle.SetStatY(0.875)
241  canvas.Clear()
242  canvas.Divide(2, 4)
243 
244  # hit map for calibration channels (without offline FE)
245  canvas.cd(1)
246  gPad.SetFrameFillStyle(0)
247  gPad.SetFillStyle(0)
248  tr.Draw("TMath::FloorNint((pixelId-1)/64+1):TMath::FloorNint((pixelId-1)%64+1)>>hCalMap" +
249  str(slot) + "(64,0.5,64.5,8,0.5,8.5)", ("isCalCh && offlineFlag<=0 && " + slotCut), "colz")
250  hCalMap = gROOT.FindObject("hCalMap" + str(slot))
251  hCalMap.SetStats(False)
252  hCalMap.Scale(1. / nEntries)
253  hCalMap.SetTitle(root_output + " - occupancy map only in cal. ch. (hits/evt) : " + slotstr)
254 
255  # number of hits for calibration channels (both without and with offline FE)
256  canvas.cd(2)
257  gPad.SetFrameFillStyle(0)
258  gPad.SetFillStyle(0)
259  tr.Draw("Sum$((isCalCh)*(offlineFlag<=0)*(" + slotCut + "))>>hCalEff" + str(slot) + "(65,-0.5,64.5)")
260  hCalEff = gROOT.FindObject("hCalEff" + str(slot))
261  hCalEff.GetXaxis().SetTitle("# of hits identified in cal. ch.")
262  hCalEff.SetTitle("# of hits in cal. ch. for each event : " + slotstr)
263  IsCosmicRayData = True if (hCalEff.GetMean() < 1.) else False
264  tr.Draw("Sum$((hitQuality>=200)*(" + slotCut + "))>>hCalEffOfflineFE" + str(slot) + "(65,-0.5,64.5)", "", "same")
265  hCalEffOfflineFE = gROOT.FindObject("hCalEffOfflineFE" + str(slot))
266  hCalEffOfflineFE.SetLineColor(2)
267  hCalEff.GetYaxis().SetRangeUser(0, max(hCalEff.GetBinContent(hCalEff.GetMaximumBin()),
268  hCalEffOfflineFE.GetBinContent(hCalEffOfflineFE.GetMaximumBin())) * 1.3)
269  legendEff = TLegend(0.15, 0.875, 0.5, 0.7)
270  legendEff.SetFillStyle(0)
271  legendEff.AddEntry(hCalEff, "w/o offline FE (" + str(int(hCalEff.GetMean() * 10 + 0.5) / 10.) + ")")
272  if IsOfflineFEDisabled:
273  legendEff.AddEntry(hCalEffOfflineFE, "w/ offline FE (disabled)")
274  else:
275  legendEff.AddEntry(hCalEffOfflineFE, "w/ offline FE (" + str(int(hCalEffOfflineFE.GetMean() * 10 + 0.5) / 10.) + ")")
276  legendEff.Draw()
277  gPad.Update()
278  nSlotEntriesCalCh[slot - 1] = hCalEff.GetMean()
279  nSlotEntriesCalChWfm[slot - 1] = hCalEffOfflineFE.GetMean()
280 
281  # laser timing distribution with offline FE (if available)
282  canvas.cd(5)
283  gPad.SetFrameFillStyle(0)
284  gPad.SetFillStyle(0)
285  gPad.SetLogy()
286  cut = "refTime>0 && hitQuality>0 && hitQuality<50 && " + slotCut
287  if IsOfflineFEDisabled:
288  ytitle_hLaser = "Laser timing distribution (w/o offline FE) : " + slotstr
289  else:
290  cut += " && hitQuality>=10"
291  ytitle_hLaser = "Laser timing distribution (w/ offline FE) : " + slotstr
292  tr.Draw("time-refTime>>hLaserTime" + str(slot) + "(180,-125,55)", cut + " && !isCalCh")
293  tr.Draw("time-refTime>>hLaserTimeCal" + str(slot) + "(180,-125,55)", cut + " && isCalCh", "same")
294  hLaserTime = gROOT.FindObject("hLaserTime" + str(slot))
295  hLaserTimeCal = gROOT.FindObject("hLaserTimeCal" + str(slot))
296  hLaserTime.GetXaxis().SetTitle("hit time - ref. time [ns]")
297  BinWidth = hLaserTime.GetXaxis().GetBinUpEdge(1) - hLaserTime.GetXaxis().GetBinLowEdge(1)
298  ytitle = "Entries[/(" + str(BinWidth) + " ns)]"
299  hLaserTime.GetYaxis().SetTitle(ytitle)
300  hLaserTime.SetTitle(ytitle_hLaser)
301  hLaserTimeCal.SetLineColor(2)
302  cutDirectHit = cut
303  cutReflHit = cut
304  PeakTime = 1000000
305  legX1 = 0.3
306  legX2 = 0.475
307  if hLaserTime.Integral(1, int(hLaserTime.GetXaxis().GetNbins() / 2)) < 0.5 * hLaserTime.Integral():
308  gStyle.SetStatX(0.475)
309  gStyle.SetStatY(0.875)
310  legX1 = 0.7
311  legX2 = 0.875
312  legendTime = TLegend(legX1, 0.875, legX2, 0.7)
313  legendTime.SetFillStyle(0)
314  legendTime.SetBorderSize(0)
315  legendTime.AddEntry(hLaserTime, "non-cal. channel")
316  legendTime.AddEntry(hLaserTimeCal, "cal. channel")
317  legendTime.Draw()
318  if hLaserTime.Integral() > 10:
319  MaxHeight = -1
320  iBin = 1
321  BinTime = hLaserTime.GetXaxis().GetBinLowEdge(1)
322  PeakTime = BinTime
323  while BinTime < hLaserTime.GetXaxis().GetBinUpEdge(hLaserTime.GetXaxis().GetNbins()):
324  tmpHeight = hLaserTime.GetBinContent(iBin)
325  BinTime = hLaserTime.GetXaxis().GetBinCenter(iBin)
326  if tmpHeight > MaxHeight:
327  MaxHeight = tmpHeight
328  PeakTime = BinTime
329  iBin += 1
330  hLaserTime.Fit("gaus", "+", "", PeakTime - FitWidth, PeakTime + FitWidth)
331  if hLaserTime.GetFunction("gaus"):
332  func = hLaserTime.GetFunction("gaus")
333  PeakTime = func.GetParameter(1)
334  PeakHeight = func.GetParameter(0)
335  else:
336  PeakHeight = hLaserTime.GetBinContent(hLaserTime.GetXaxis().FindBin(PeakTime))
337  cutDirectHit += " && TMath::Abs(time-refTime-(" + str(PeakTime) + "))<" + str(FitWidth)
338  cutReflHit += " && TMath::Abs(time-refTime-(" + str(PeakTime + DelayTimeRefl) + "))<" + str(ReflHalfTimwRange)
339  line = TLine()
340  line.SetLineColor(3)
341  arrow = TArrow()
342  arrow.SetLineColor(3)
343  line.DrawLine(PeakTime - FitWidth, 0.5, PeakTime - FitWidth, PeakHeight / 10.)
344  line.DrawLine(PeakTime + FitWidth, 0.5, PeakTime + FitWidth, PeakHeight / 10.)
345  line.DrawLine(
346  PeakTime +
347  DelayTimeRefl -
348  ReflHalfTimwRange,
349  0.5,
350  PeakTime +
351  DelayTimeRefl -
352  ReflHalfTimwRange,
353  PeakHeight /
354  100.)
355  line.DrawLine(
356  PeakTime +
357  DelayTimeRefl +
358  ReflHalfTimwRange,
359  0.5,
360  PeakTime +
361  DelayTimeRefl +
362  ReflHalfTimwRange,
363  PeakHeight /
364  100.)
365  arrow.DrawArrow(PeakTime - FitWidth, 5, PeakTime + FitWidth, 5, 0.01, "<>")
366  arrow.DrawArrow(
367  PeakTime +
368  DelayTimeRefl -
369  ReflHalfTimwRange,
370  5,
371  PeakTime +
372  DelayTimeRefl +
373  ReflHalfTimwRange,
374  5,
375  0.01,
376  "<>")
377 
378  # laser hit map for direct hit peak with offline feature extraction (if available)
379  canvas.cd(3)
380  gPad.SetFrameFillStyle(0)
381  gPad.SetFillStyle(0)
382  tr.Draw("TMath::FloorNint((pixelId-1)/64+1):TMath::FloorNint((pixelId-1)%64+1)>>hLaserMap" +
383  str(slot) + "(64,0.5,64.5,8,0.5,8.5)", cutDirectHit, "colz")
384  hLaserMap = gROOT.FindObject("hLaserMap" + str(slot))
385  hLaserMap.Scale(1. / tr.GetEntries())
386  hLaserMap.SetStats(False)
387  hLaserMap.SetTitle(root_output + " - laser direct hit occupancy (hits/event)")
388 
389  # laser hit map for reflected photon peak with offline feature extraction (if available)
390  canvas.cd(4)
391  gPad.SetFrameFillStyle(0)
392  gPad.SetFillStyle(0)
393  tr.Draw("TMath::FloorNint((pixelId-1)/64+1):TMath::FloorNint((pixelId-1)%64+1)>>hLaserReflMap" +
394  str(slot) + "(64,0.5,64.5,8,0.5,8.5)",
395  ("hitQuality>0 && hitQuality%10!=4 && " + slotCut if IsCosmicRayData else cutReflHit), "colz")
396  hLaserReflMap = gROOT.FindObject("hLaserReflMap" + str(slot))
397  hLaserReflMap.Scale(1. / tr.GetEntries())
398  hLaserReflMap.SetStats(False)
399  hLaserReflMap.SetTitle(root_output + (" - hit map for the whole timing region (hits/event)"
400  if IsCosmicRayData else " - laser reflected hit occupancy (hits/event)"))
401 
402  # number of hits
403  canvas.cd(6)
404  gPad.SetFrameFillStyle(0)
405  gPad.SetFillStyle(0)
406  hNHitAll[slot].SetStats(False)
407  hNHitAll[slot].SetTitle("number of hits for " + slotstr)
408  hNHitAll[slot].SetLineColor(1)
409  hNHitNoCalCh[slot].SetLineColor(2)
410  hNHitAll[slot].Draw()
411  hNHitNoCalCh[slot].Draw("same")
412  latex.SetTextSize(0.05)
413  latex.SetTextAlign(33)
414  latex.DrawLatex(0.875, 0.785, "underflow : " + str(int(hNHitAll[slot].GetBinContent(0) * 1000 / nEntries) / 10) + "%")
415  latex.DrawLatex(0.875, 0.685, "underflow : " + str(int(hNHitNoCalCh[slot].GetBinContent(0) * 1000 / nEntries) / 10) + "%")
416  if PeakTime < 0:
417  tr.Draw("Sum$(" + basicHitSelection + "&& " + slotCut + "&&TMath::Abs(time-refTime-(" +
418  str(PeakTime) + "))<" + str(FitWidth) + ")>>hNHitLaser" + str(slot), "", "same")
419  hNHitLaser = gROOT.FindObject("hNHitLaser" + str(slot))
420  hNHitLaser.SetFillStyle(0)
421  hNHitLaser.SetLineColor(3)
422  nHitMeanLaser[slot - 1] = hNHitLaser.GetMean()
423  hMax = max(hNHitLaser.GetBinContent(hNHitLaser.GetMaximumBin()),
424  hNHitAll[slot].GetBinContent(hNHitAll[slot].GetMaximumBin()),
425  hNHitNoCalCh[slot].GetBinContent(hNHitNoCalCh[slot].GetMaximumBin()))
426  hNHitAll[slot].GetYaxis().SetRangeUser(0, 1.1 * hMax)
427  if not LaserAdded:
428  legstr = "Laser direct hit (" + ("single hit" if IsOfflineFEDisabled else "multi hit") + ")"
429  legendSlot.AddEntry(hNHitLaser, legstr)
430  legendSlot.SetY1(0.55)
431  LaserAdded = True
432  else:
433  hMax = max(hNHitAll[slot].GetBinContent(hNHitAll[slot].GetMaximumBin()),
434  hNHitNoCalCh[slot].GetBinContent(hNHitNoCalCh[slot].GetMaximumBin()))
435  hNHitAll[slot].GetYaxis().SetRangeUser(0, 1.1 * hMax)
436  legendSlot.Draw()
437 
438  # time indterval of the double calibration pulses (when offline FE is available)
439  canvas.cd(7)
440  gPad.SetFrameFillStyle(0)
441  gPad.SetFillStyle(0)
442  if IsOfflineFEDisabled or IsCosmicRayData:
443  hRawTime = hRawTimeList[slot]
444  hRawTime.SetStats(False)
445  hRawTime.SetTitle("rawTime distribution")
446  hRawTime.GetXaxis().SetTitle("rawTime")
447  ytitle = "Entries [/(" + str(hRawTime.GetXaxis().GetBinUpEdge(1) - hRawTime.GetXaxis().GetBinLowEdge(1)) + " samples)]"
448  hRawTime.GetYaxis().SetTitle(ytitle)
449  hRawTime.SetTitle("rawTime distribution : " + slotstr)
450  hRawTime.Draw()
451  else:
452  tr.Draw("time-refTime:TMath::FloorNint((pixelId-1)/8)>>hCalPulseInterval" + str(slot) + "(64,-0.5,63.5,100,19,24)",
453  # tr.Draw("time-refTime:TMath::FloorNint((pixelId-1)/8)>>hCalPulseInterval"
454  # + str(slot) + "(64,-0.5,63.5,100,7.5,32.5)",
455  "hitQuality>=200 && " + slotCut, "colz")
456  hCalPulseInterval = gROOT.FindObject("hCalPulseInterval" + str(slot))
457  hCalPulseInterval.GetXaxis().SetTitle("asic number = (pixelId-1)/8")
458  hCalPulseInterval.GetYaxis().SetTitle("time interval of double cal. pulses [ns]")
459  hCalPulseInterval.SetTitle("time interval of double calibration pulses : " + slotstr)
460  hCalPulseInterval.SetStats(False)
461 
462  canvas.cd(8)
463  gPad.SetFrameFillStyle(0)
464  gPad.SetFillStyle(0)
465  gPad.SetLogy()
466  tr.Draw("sample>>hSample" + str(slot) + "(256,-0.5,255.5)",
467  "slotNum==" + str(slot) + ("&&hitQuality>0&&hitQuality%10!=4" if IsCosmicRayData
468  else "&&hitQuality>=100&&hitQuality<200"))
469  hSample = gROOT.FindObject("hSample" + str(slot))
470  hSample.SetFillStyle(0)
471  hSample.SetLineColor(1)
472  hSample.SetStats(False)
473  hSample.SetTitle("entries of each sample# for TBC : " + slotstr)
474  hSample.GetXaxis().SetTitle("Sample# for each hit" if IsCosmicRayData
475  else "Sample# of the first calibration pulse")
476  line.DrawLine(
477  hSample.GetXaxis().GetBinLowEdge(1),
478  nEntries / 4,
479  hSample.GetXaxis().GetBinUpEdge(
480  hSample.GetXaxis().GetNbins()),
481  nEntries / 4)
482 
483  canvas.Print(pdf_output)
484 
485  canvas.Print((pdf_output + "]"))
486 
487  print(" (nEvt >=3hits) (mean nhit) (no cal.ch) (nCalHit) (nCalHit wfm) (nHitLaser)")
488  for iSlot in range(0, 16):
489  print("slot" + "{0:02d}".format(iSlot + 1) +
490  " " + "{0:7d}".format(int(nSlotEntriesAll[iSlot])) + " \t " + str('%03.2f' % nHitMeanAll[iSlot]) +
491  " \t " + str('%03.2f' % nHitMeanNoCalCh[iSlot]) + " \t" + str('%03.2f' % nSlotEntriesCalCh[iSlot]) +
492  " \t " + str('%03.2f' % nSlotEntriesCalChWfm[iSlot]) + " \t " + str('%03.2f' % nHitMeanLaser[iSlot]))
493 
494  print("nEntries = " + str(nEntries))
495 # time.sleep(15)
496 
497 
498 def plotInterimFEDataNtupleAdvanced(root_output, FitWidth=5):
499 
500  pdf_output = root_output[0:root_output.rfind(".root")] + "_Advanced.png"
501  root_out = root_output[0:root_output.rfind(".root")] + "_Advanced.root"
502 
503  print(root_output + " --> " + pdf_output)
504 
505  gStyle.SetFrameFillStyle(0)
506  gStyle.SetFillStyle(0)
507  gStyle.SetStatX(0.9)
508  gStyle.SetStatY(0.9)
509  gStyle.SetStatStyle(0)
510  gStyle.SetOptStat(112210)
511  gStyle.SetOptFit(1110)
512  canvas = TCanvas("cv2", "cv2", 1600, 1600)
513  canvas.SetFillStyle(0)
514 
515  f = TFile(root_output)
516  tr = f.Get("tree")
517 
518  canvas.Divide(2, 3)
519  canvas.cd(1)
520  gPad.SetFrameFillStyle(0)
521  gPad.SetFillStyle(0)
522  tr.Draw("rawTdc-refTdc:winNum>>hTimeVSWin(512, 0, 512, 60, -160, -130)", "refTdc>0 && !isCalCh", "colz")
523  hTimeVSWin = gROOT.FindObject("hTimeVSWin")
524  hTimeVSWin.GetXaxis().SetTitle("hit first window")
525  hTimeVSWin.GetYaxis().SetTitle("hit time - ref. time [ns]")
526  hTimeVSWin.SetStats(False)
527  hTimeVSWin.SetTitle(root_output + " hit time - ref time VS window number.")
528 
529  canvas.cd(2)
530  gPad.SetFrameFillStyle(0)
531  gPad.SetFillStyle(0)
532  tr.Draw("rawTdc-refTdc:sample>>hTimeVSSample(2560, 0, 256, 60, -160, -130)", "refTdc>0 && !isCalCh", "colz")
533  hTimeVSSample = gROOT.FindObject("hTimeVSSample")
534  hTimeVSSample.SetStats(False)
535  hTimeVSSample.GetXaxis().SetTitle("hit sample [sample]")
536  hTimeVSSample.GetYaxis().SetTitle("hit time - ref. time [ns]")
537  hTimeVSSample.SetTitle("hit time - ref time VS hit time.")
538  gPad.Update()
539 
540  canvas.cd(3)
541  gPad.SetFrameFillStyle(0)
542  gPad.SetFillStyle(0)
543  tr.Draw("rawTdc-refTdc:pixelId>>hTimeVSPixel(512, 0, 512, 60, -160, -130 )", "refTdc>0 && !isCalCh", "colz")
544  hTimeVSPixel = gROOT.FindObject("hTimeVSPixel")
545  hTimeVSPixel.SetStats(False)
546  hTimeVSPixel.GetXaxis().SetTitle("pixel ID")
547  hTimeVSPixel.GetYaxis().SetTitle("hit time - ref. time [ns]")
548  hTimeVSPixel.SetTitle("hit time - ref time VS pixel ID.")
549  gPad.Update()
550 
551  canvas.cd(4)
552  gPad.SetFrameFillStyle(0)
553  gPad.SetFillStyle(0)
554  tr.Draw("height:sample>>hHeightVSSample(256, 0, 256, 200, 0, 1000)", "", "colz")
555  hHeightVSSample = gROOT.FindObject("hHeightVSSample")
556  hHeightVSSample.SetStats(False)
557  hHeightVSSample.GetXaxis().SetTitle("hit sample [sample]")
558  hHeightVSSample.GetYaxis().SetTitle("hit amplitude [ADC] ")
559  hHeightVSSample.SetTitle("amplitude VS hit time (incl calpulse).")
560  gPad.SetLogz()
561  gPad.Update()
562 
563  canvas.cd(5)
564  gPad.SetFrameFillStyle(0)
565  gPad.SetFillStyle(0)
566  tr.Draw("sample>>hHitTime(400, -50, 350)")
567  hHitTime = gROOT.FindObject("hHitTime")
568  hHitTime.SetStats(False)
569  hHitTime.GetXaxis().SetTitle("hit sample [sample]")
570  hHitTime.GetYaxis().SetTitle("entries / 1 sample ")
571  hHitTime.SetTitle("hit sample (incl calpulse).")
572  gPad.Update()
573 
574  canvas.cd(6)
575  gPad.SetFrameFillStyle(0)
576  gPad.SetFillStyle(0)
577  tr.Draw("Sum$(!isCalCh)>>hHitEff(200, 0, 200)", "rawTdc-refTdc > -160 && rawTdc-refTdc < -130")
578  hHitEff = gROOT.FindObject("hHitEff")
579  hHitEff.GetXaxis().SetTitle("# of hits candidates per event")
580  hHitEff.SetTitle("# of laser hit candidates for each event in -160 < time < -130")
581  print("mean nHit value : " + str(hHitEff.GetMean()))
582  gPad.Update()
583  pave = hHitEff.FindObject("stats")
584  pave.SetX1NDC(0.65)
585  pave.SetX2NDC(0.95)
586  pave.SetY1NDC(0.875)
587  pave.SetY2NDC(0.625)
588 
589  canvas.Print(pdf_output)
590 
591  root_plot_out = TFile(root_out, "recreate")
592  hTimeVSSample.Write()
593  hTimeVSPixel.Write()
594  hHeightVSSample.Write()
595  hTimeVSWin.Write()
596  hHitTime.Write()
597  hHitEff.Write()
598 
599  root_plot_out.Close()
600 # time.sleep(15)
601 
602 
603 if __name__ == '__main__':
604 
605  args = sys.argv
606  if len(args) > 1:
607  plotInterimFEDataNtupleSummary(args[1])
608  # plotInterimFEDataNtupleAdvanced(args[1])
609  else:
610  print("usage:")
611  print(args[0] + " (output of plotInterimFEData)")