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