5 from ROOT
import Belle2, TH2F, TH1F, TFile, gStyle, TColor, TCanvas
8 from interactive
import embed
14 color1501 = TColor(1501, 35 / 255., 55 / 255., 59 / 255.)
15 color1502 = TColor(1502, 99 / 255., 120 / 255., 173 / 255.)
16 color1503 = TColor(1503, 235 / 255., 129 / 255., 27 / 255.)
17 color1504 = TColor(1504, 99 / 255., 173 / 255., 132 / 255.)
18 color1505 = TColor(1505, 123 / 255., 111 / 255., 37 / 255.)
20 nWiresInLayer = [160, 192, 256, 320, 384]
23 def set_style(hist, color=1503, marker=20):
24 hist.SetLineColor(color)
27 hist.SetMarkerStyle(marker)
29 hist.SetMarkerColor(color)
32 hall = TH2F(
'all',
'all', 5, 0, 5, 384, 0, 384)
33 hhit = TH2F(
'hit',
'hit', 5, 0, 5, 384, 0, 384)
34 hno_ghost = TH2F(
'ng',
'hit', 5, 0, 5, 384, 0, 384)
35 hghost = TH2F(
'ghost',
'hit', 5, 0, 5, 384, 0, 384)
37 hlr = TH1F(
'lr',
'left right', 4, 0, 4)
38 hpri = TH1F(
'pri',
'priority position', 4, 0, 4)
39 hpritime = TH1F(
'pritime',
'priority time', 512, 0, 512)
40 hftime = TH1F(
'found time',
'found time', 48, -35, 13)
42 used = numpy.zeros(2336, numpy.int)
43 in_tsim = numpy.zeros(2336, numpy.int)
48 Module to make some monitor plots for TSF
74 if simhit.getISuperLayer() % 2 == 0:
75 iax, iw = simhit.getISuperLayer() // 2, simhit.getIWire()
76 if simhit.getPriorityPosition() == 1:
78 if iw == nWiresInLayer[iax]:
81 in_tsim[simhit.getSegmentID()] = 1
83 ind = hit.getSegmentID()
87 iax, iw = hit.getISuperLayer() // 2, hit.getIWire()
88 if hit.getPriorityPosition() == 1:
90 if iw == nWiresInLayer[iax]:
96 hno_ghost.Fill(iax, iw)
99 hlr.Fill(hit.getLeftRight())
100 hpri.Fill(hit.getPriorityPosition())
101 hpritime.Fill(hit.priorityTime())
102 hftime.Fill(hit.foundTime())
109 B2WARNING(
"The monitor module is never called.\n" +
110 "There seems to be no CDC Trigger data at all!")
112 elif hhit.GetEntries() == 0:
113 B2WARNING(
"No recorded TS hits at all!")
115 elif hall.GetEntries() == 0:
116 B2ERROR(
"No simulated TS hits at all!")
118 if not os.path.exists(
'monitor_plots'):
119 os.mkdir(
'monitor_plots')
120 can = TCanvas(
'can2',
'can2', 800, 700)
123 nts = [160, 192, 256, 320, 384]
137 p = hall.ProjectionY(
'all{}'.format(iax), ibin, ibin)
138 p.SetBins(nts[iax], 0, 2 * pi)
142 q = hhit.ProjectionY(
'hit{}'.format(iax), ibin, ibin)
143 q.SetBins(nts[iax], 0, 2 * pi)
147 g = hghost.ProjectionY(
'ghost{}'.format(iax), ibin, ibin)
148 g.SetBins(nts[iax], 0, 2 * pi)
152 s = hno_ghost.ProjectionY(
'ng{}'.format(iax), ibin, ibin)
153 s.SetBins(nts[iax], 0, 2 * pi)
157 r = g.Clone(
'ghost{}'.format(iax))
158 r2 = s.Clone(
'quong{}'.format(iax))
163 r.Divide(g, p, 1.0, 1.0,
'B')
165 r2.Divide(s, p, 1.0, 1.0,
'B')
168 for hits, name
in [(slhit,
'data TS'),
172 h.SetTitle(f
'SL{i * 2}')
173 set_style(h, 1501 + i, 20 + i)
174 if name
in [
'data TS',
'TSIM']:
176 h.Scale(1 / h.Integral(
'width'))
177 except ZeroDivisionError:
178 B2WARNING(f
'Not a single hit in SL{i * 2}!')
180 height = max([g.GetMaximum()
for g
in hits])
182 h.SetMaximum(1.1 * height)
185 if h.GetTitle() !=
'SL0':
188 can.BuildLegend(.85, .76, .95, .95)
189 hits[0].SetTitle(name +
' hit distribution in run {}; #phi (rad)'.format(
191 can.SaveAs(
'monitor_plots/' + name.split()[0] +
192 '_ts_hits_{:05d}.{}'.format(self.
first_run, file_type))
194 for ratio, name
in [(quos,
'ghost rate'), (quong,
'efficiency (w.r.t. fast TSIM)')]:
195 upp = max([g.GetMaximum()
for g
in ratio])
196 low = min([g.GetMinimum()
for g
in ratio])
199 h.SetTitle(
'SL{}'.format(2 * i))
200 h.SetMaximum(1.1 * upp)
201 h.SetMinimum(0.9 * low)
202 set_style(h, 1501 + i, 20 + i)
207 can.BuildLegend(.91, .76, .98, .95)
208 ratio[0].SetTitle(
'TSF ' + name +
' in run {};#phi (rad)'.format(
210 file_name = name.split()[0]
211 can.SaveAs(
'monitor_plots/ts_{}_{:05d}.{}'.format(file_name, self.
first_run, file_type))
214 for h
in [hlr, hpri, hpritime, hftime]:
217 name = h.GetTitle().replace(
' ',
'_')
218 can.SaveAs(
'monitor_plots/ghost_{}_{:05d}.{}'.format(name, self.
first_run, file_type))