Belle II Software  release-08-01-10
analyze_TOPFE_ntuple.py
1 
8 
9 # Script to analyze the output of TOPFE_qualityPlots.py
10 
11 import sys
12 import ROOT
13 ROOT.gStyle.SetOptStat(0)
14 ROOT.gROOT.SetBatch()
15 
16 if len(sys.argv) < 2:
17  print("Usage: %s <name of root ntuple>" % sys.argv[0])
18  sys.exit(-1)
19 
20 f = ROOT.TFile.Open(sys.argv[1])
21 
22 t = f.Get("feProps")
23 t.SetLineWidth(2)
24 t.SetLineColor(6)
25 calChannel = "ch % 8 == 0"
26 signalChannel = "ch % 8 != 0"
27 c = ROOT.TCanvas()
28 
29 nTRDHist = ROOT.TH1D("nTRDHist", "all channels;number of TOPRawDigits;waveforms", 1000, 0, 30)
30 t.Draw("nTOPRawDigits>>nTRDHist")
31 c.SaveAs("nTOPRawDigits_All.pdf")
32 c.SetLogy()
33 c.SaveAs("nTOPRawDigits_All_logy.pdf")
34 c.SetLogy(False)
35 c.Clear()
36 nTRDHist.Reset()
37 
38 t.Draw("nTOPRawDigits>>nTRDHist", calChannel)
39 c.SaveAs("nTOPRawDigits_cal.pdf")
40 c.SetLogy()
41 c.SaveAs("nTOPRawDigits_cal_logy.pdf")
42 c.SetLogy(False)
43 c.Clear()
44 nTRDHist.Reset()
45 
46 t.Draw("nTOPRawDigits>>nTRDHist", signalChannel)
47 c.SaveAs("nTOPRawDigits_sig.pdf")
48 c.SetLogy()
49 c.SaveAs("nTOPRawDigits_sig_logy.pdf")
50 c.SetLogy(False)
51 c.Clear()
52 
53 t.Draw("fePeakHt:fePeak1Ht", calChannel, "hist")
54 c.SaveAs("fePeakHt_vs_fePeak1Ht_cal.pdf")
55 c.Clear()
56 
57 wd_adcHist = ROOT.TH2D("wd_adcHist", "Width vs Pulse height;width;height", 130, 0, 130, 1100, 50, 1150)
58 t.Draw("fePeakHt:fePeakWd>>wd_adcHist", "", "colz")
59 c.SaveAs("fePeakWd_vs_fePeakHt.pdf")
60 c.Clear()
61 wd_adcHist.Reset()
62 
63 wd_adcHist.SetTitle("Width vs Pulse height in the calibration channel;width;height")
64 t.Draw("fePeakHt:fePeakWd>>wd_adcHist", calChannel, "colz")
65 c.SaveAs("fePeakWd_vs_fePeakHt_cal.pdf")
66 c.Clear()
67 wd_adcHist.Reset()
68 
69 wd_adcHist.SetTitle("Width vs Pulse height in the signal channel;width;height")
70 t.Draw("fePeakHt:fePeakWd>>wd_adcHist", signalChannel, "colz")
71 c.SaveAs("fePeakWd_vs_fePeakHt_sig.pdf")
72 c.Clear()
73 wd_adcHist.Reset()
74 
75 wd_tdcHist = ROOT.TH2D("wd_tdcHist", "Width vs TDC;TDC;width", 256, 1, 257, 130, 0, 130)
76 t.Draw("fePeakWd:fePeakTDC>>wd_tdcHist", "", "colz")
77 c.SaveAs("fePeakWd_vs_TDC.pdf")
78 c.Clear()
79 
80 ht_tdcHist = ROOT.TH2D("ht_tdcHist", "Height vs TDC;TDC;height", 256, 1, 257, 1100, 50, 1150)
81 t.Draw("fePeakHt:fePeakTDC>>ht_tdcHist", "", "colz")
82 c.SaveAs("fePeakHt_vs_TDC.pdf")
83 c.SetLogz()
84 c.Clear()
85 
86 ch_tdcHist = ROOT.TH2D("ch_tdcHist", "Channel vs TDC;TDC;channel number", 256, 1, 257, 512, 0, 512)
87 t.Draw("ch:fePeakTDC>>ch_tdcHist", "", "colz")
88 c.SetLogz()
89 c.SaveAs("fePeakTDC_vs_ch.pdf")
90 c.Clear()
91 #
92 adcHist = ROOT.TH1D("adcHist", "ADC counts;ADC", 1000, 0, 1000)
93 adcHist.SetLineWidth(2)
94 adcHist.SetLineColor(4)
95 t.Draw("fePeakHt>>adcHist", calChannel)
96 adcHist.SetTitle("ADC counts in the calibration channel")
97 c.SaveAs("ADC_distribution_peak0_cal.pdf")
98 c.Clear()
99 adcHist.Reset()
100 
101 adcHist.SetLineWidth(2)
102 adcHist.SetLineColor(4)
103 t.Draw("fePeakHt>>adcHist", signalChannel)
104 adcHist.SetTitle("ADC counts in the signal channels")
105 c.SaveAs("ADC_distribution_peak0_sig.pdf")
106 c.Clear()
107 
108 tdcHist = ROOT.TH1D("tdcHist", "tdcHist;TDC;waveforms", 256, 1, 257)
109 tdcHist.SetLineWidth(2)
110 tdcHist.SetLineColor(4)
111 t.Draw("fePeakTDC>>tdcHist", calChannel)
112 tdcHist.SetTitle("TDC distribution calibration channel")
113 c.SaveAs("TDC_distribution_peak0_cal.pdf")
114 c.Clear()
115 tdcHist.Reset()
116 
117 tdcHist.SetLineWidth(2)
118 tdcHist.SetLineColor(4)
119 t.Draw("fePeakTDC>>tdcHist", signalChannel)
120 tdcHist.SetTitle("TDC distribution signal channels")
121 c.SaveAs("TDC_distribution_peak0_signal.pdf")
122 c.Clear()
123 tdcHist.Reset()
124 
125 tdcHist.SetLineWidth(2)
126 tdcHist.SetLineColor(4)
127 t.Draw("fePeak1TDC>>tdcHist", calChannel + "&& nTOPRawDigits > 2")
128 tdcHist.SetTitle("TDC distribution 2nd peak calibration channel")
129 c.Update()
130 c.SaveAs("fePeak1TDC_calChannel.pdf")
131 c.BuildLegend()
132 c.Clear()
133 tdcHist.Reset()
134 
135 tdcHist.SetLineWidth(2)
136 tdcHist.SetLineColor(4)
137 t.Draw("fePeak1TDC>>tdcHist", signalChannel + "&& nTOPRawDigits > 1")
138 tdcHist.SetTitle("TDC distribution 2nd peak signal channel")
139 c.Update()
140 c.SaveAs("fePeak1TDC_signalChannel.pdf")
141 c.BuildLegend()
142 c.Clear()
143 tdcHist.Reset()
144 
145 hists = []
146 c.Clear()
147 c.Divide(3, 3)
148 c.cd(9)
149 h0 = ROOT.TH1D("feh0", "all Channels", 1000, 50, 1050)
150 t.Draw("fePeakHt>>feh0")
151 for iCanv in range(1, 9):
152  c.cd(iCanv)
153  h = ROOT.TH1D("feh%d" % iCanv, "channel %d;ADC;waveforms" % iCanv, 1000, 50, 1050)
154  t.Draw("fePeakHt>>feh%d" % iCanv, "ch %% 8 == %d" % (iCanv - 1))
155  hists.append(h)
156 c.SaveAs("fePeakHt_byChannel.pdf")
157 
158 hists = []
159 c.Clear()
160 c.Divide(3, 3)
161 c.cd(5)
162 h0 = ROOT.TH1D("fe_asic0", "all ASICs", 1000, 50, 1050)
163 t.Draw("fePeakHt>>fe_asic0")
164 for iASIC, iCanv in enumerate([1, 3, 7, 9]):
165  c.cd(iCanv)
166  h = ROOT.TH1D("fe_asic%d" % iCanv, "ASIC %d;ADC;waveforms" % iASIC, 1000, 50, 1050)
167  t.Draw("fePeakHt>>fe_asic%d" % iCanv, "(ch/8) %% 4 == %d" % (iASIC))
168  hists.append(h)
169 c.SaveAs("fePeakHt_byASIC.pdf")
170 
171 hists = []
172 c.Clear()
173 c.Divide(3, 3)
174 c.cd(5)
175 h0 = ROOT.TH1D("fe_carrier0", "all Carriers", 1000, 50, 1050)
176 t.Draw("fePeakHt>>fe_carrier0")
177 for iCarrier, iCanv in enumerate([1, 3, 7, 9]):
178  c.cd(iCanv)
179  h = ROOT.TH1D("fe_carrier%d" % iCanv, "Carrier %d;ADC;waveforms" % iCarrier, 1000, 50, 1050)
180  t.Draw("fePeakHt>>fe_carrier%d" % iCanv, "(ch/8/4) %% 4 == %d" % (iCarrier))
181  hists.append(h)
182 c.SaveAs("fePeakHt_byCarrier.pdf")
183 
184 hists = []
185 c.Clear()
186 c.Divide(3, 3)
187 c.cd(5)
188 h0 = ROOT.TH1D("fe_boardstack0", "all board stacks", 1000, 50, 1050)
189 t.Draw("fePeakHt>>fe_boardstack0")
190 for iBS, iCanv in enumerate([1, 3, 7, 9]):
191  c.cd(iCanv)
192  h = ROOT.TH1D("fe_boardstack%d" % iCanv, "board stack %d;ADC;waveforms" % iBS, 1000, 50, 1050)
193  t.Draw("fePeakHt>>fe_boardstack%d" % iCanv, "(ch/8/4/4) %% 4 == %d" % (iBS))
194  hists.append(h)
195 c.SaveAs("fePeakHt_byBoardStack.pdf")
196 
197 # Count the number of failure modes
198 total = t.GetEntries()
199 
200 print("Fraction with width > 30: %.3f" % (1.0 * t.Draw("fePeakWd", "fePeakWd>30", "goff") / total))
201 print("Fraction with peaks at window borders: (average occupancy / bin = %.3f)" % (1. / 256))
202 print("\ttdc < 2 : %.3f" % (1.0 * t.Draw("fePeakWd", "fePeakTDC<2", "goff") / total))
203 print("\t63 < tdc < 66 : %.3f" % (1.0 * t.Draw("fePeakWd", "fePeakTDC>63 && fePeakTDC<66", "goff") / total))
204 print("\t127 < tdc < 130: %.3f" % (1.0 * t.Draw("fePeakWd", "fePeakTDC>127 && fePeakTDC<130", "goff") / total))
205 print("\t191 < tdc < 194: %.3f" % (1.0 * t.Draw("fePeakWd", "fePeakTDC>191 && fePeakTDC<194", "goff") / total))
206 print("\ttdc > 255 : %.3f" % (1.0 * t.Draw("fePeakWd", "fePeakTDC>255", "goff") / total))