111 def terminate(self):
112 """
113 termination
114 """
115 if self.nevents == 0:
116 b2.B2WARNING("The monitor module is never called.\n" +
117 "There seems to be no CDC Trigger data at all!")
118 return
119 elif hhit.GetEntries() == 0:
120 b2.B2WARNING("No recorded TS hits at all!")
121 return
122 elif hall.GetEntries() == 0:
123 b2.B2ERROR("No simulated TS hits at all!")
124 return
125 if not os.path.exists('monitor_plots'):
126 os.mkdir('monitor_plots')
127 can = TCanvas('can2', 'can2', 800, 700)
128 gStyle.SetOptStat(0)
129
130 nts = [160, 192, 256, 320, 384]
131
132 slall = [[]] * 5
133 slhit = [[]] * 5
134 slghost = [[]] * 5
135 quos = [[]] * 5
136 slng = [[]] * 5
137 quong = [[]] * 5
138
139
140 width = 8
141 for iax in range(5):
142 ibin = iax + 1
143 p = hall.ProjectionY(f'all{iax}', ibin, ibin)
144 p.SetBins(nts[iax], 0, 2 * pi)
145 p.Rebin(width)
146 slall[iax] = p
147
148 q = hhit.ProjectionY(f'hit{iax}', ibin, ibin)
149 q.SetBins(nts[iax], 0, 2 * pi)
150 q.Rebin(width)
151 slhit[iax] = q
152
153 g = hghost.ProjectionY(f'ghost{iax}', ibin, ibin)
154 g.SetBins(nts[iax], 0, 2 * pi)
155 g.Rebin(width)
156 slghost[iax] = g
157
158 s = hno_ghost.ProjectionY(f'ng{iax}', ibin, ibin)
159 s.SetBins(nts[iax], 0, 2 * pi)
160 s.Rebin(width)
161 slng[iax] = s
162
163 r = g.Clone(f'ghost{iax}')
164 r2 = s.Clone(f'quong{iax}')
165 g.Sumw2()
166 p.Sumw2()
167 s.Sumw2()
168
169 r.Divide(g, p, 1.0, 1.0, 'B')
170 quos[iax] = r
171 r2.Divide(s, p, 1.0, 1.0, 'B')
172 quong[iax] = r2
173
174 for hits, name in [(slhit, 'data TS'),
175 (slall, 'TSIM')]:
176 for i in range(5):
177 h = hits[i]
178 h.SetTitle(f'SL{i * 2}')
179 set_style(h, 1501 + i, 20 + i)
180 if name in ['data TS', 'TSIM']:
181 try:
182 h.Scale(1 / h.Integral('width'))
183 except ZeroDivisionError:
184 b2.B2WARNING(f'Not a single hit in SL{i * 2}!')
185 continue
186 height = max([g.GetMaximum() for g in hits])
187 for h in hits:
188 h.SetMaximum(1.1 * height)
189 h.SetMinimum(0)
190 options = 'L M E0'
191 if h.GetTitle() != 'SL0':
192 options += ' same'
193 h.Draw(options)
194 can.BuildLegend(.85, .76, .95, .95)
195 hits[0].SetTitle(name + f' hit distribution in run {self.first_run}; #phi (rad)')
196 can.SaveAs('monitor_plots/' + name.split()[0] + f'_ts_hits_{self.first_run:05d}.{file_type}')
197
198 for ratio, name in [(quos, 'ghost rate'), (quong, 'efficiency (w.r.t. fast TSIM)')]:
199 upp = max([g.GetMaximum() for g in ratio])
200 low = min([g.GetMinimum() for g in ratio])
201 for i in range(5):
202 h = ratio[i]
203 h.SetTitle(f'SL{2 * i}')
204 h.SetMaximum(1.1 * upp)
205 h.SetMinimum(0.9 * low)
206 set_style(h, 1501 + i, 20 + i)
207 options = 'e0'
208 if i != 0:
209 options += ' same'
210 h.Draw(options)
211 can.BuildLegend(.91, .76, .98, .95)
212 ratio[0].SetTitle('TSF ' + name + f' in run {self.first_run};#phi (rad)')
213 file_name = name.split()[0]
214 can.SaveAs(f'monitor_plots/ts_{file_name}_{self.first_run:05d}.{file_type}')
215
216
217 for h in [hlr, hpri, hpritime, hftime]:
218 set_style(h, 1503)
219 h.Draw()
220 name = h.GetTitle().replace(' ', '_')
221 can.SaveAs(f'monitor_plots/ghost_{name}_{self.first_run:05d}.{file_type}')