5 Created on Wed Jan 31 20:54:00 2018
6 Plot PXD position estimator payload
11 import matplotlib.pyplot
as plt
16 from ROOT
import Belle2
21 """Plot the PXDClusterPositionEstimator playload """
34 """Plot position payload in case it has changed"""
38 B2INFO(
"PXDClusterPositionEstimator payload has changed. Plot the new payload.")
43 """Compute the average covariance for a shape classifier"""
47 offsetMap = shape_classifier.getOffsetMap()
48 likelyhoodMap = shape_classifier.getLikelyhoodMap()
50 for item
in offsetMap:
51 shape_index = item.first
54 for eta_index, offset
in enumerate(offsets):
55 likelyhood = likelyhoodMap[shape_index][eta_index]
56 flat_covs.append([offset.getUSigma2(), offset.getVSigma2(), offset.getUVCovariance()])
57 weights.append(likelyhood)
59 weights = np.array(weights)
60 flat_covs = np.array(flat_covs)
61 flat_average = np.average(flat_covs, axis=0, weights=weights)
62 return np.array([[flat_average[0], flat_average[2]], [flat_average[2], flat_average[1]]])
65 """Plot position estimator payload"""
67 pixelkind = pair.first
71 summary_dict = {
'shapes': [],
83 for uBin
in range(1, grid.GetXaxis().GetNbins() + 1):
84 for vBin
in range(1, grid.GetYaxis().GetNbins() + 1):
90 thetaU = grid.GetXaxis().GetBinCenter(uBin)
91 thetaV = grid.GetYaxis().GetBinCenter(vBin)
97 summary_dict[
'thetaU'].append(thetaU)
98 summary_dict[
'thetaV'].append(thetaV)
99 summary_dict[
'pixelkind'].append(pixelkind)
100 summary_dict[
'shapes'].append(stats[
'shapes'])
101 summary_dict[
'corrections'].append(stats[
'corrections'])
102 summary_dict[
'coverage'].append(stats[
'coverage'])
103 summary_dict[
'sigma_u'].append(stats[
'sigma_u'] * 10000)
104 summary_dict[
'sigma_v'].append(stats[
'sigma_v'] * 10000)
105 summary_dict[
'corr_uv'].append(stats[
'corr_uv'])
108 df = pd.DataFrame(summary_dict)
110 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'corrections')
111 fig = plt.figure(figsize=(12, 12))
112 ax = fig.add_subplot(111)
113 ax.set_xlabel(
'thetaU / degree', size=20)
114 ax.set_ylabel(
'thetaV / degree', size=20)
115 ax.set_title(
'Number of corrections kind={:d}'.format(pixelkind), size=20)
118 mask=pivot_table.isnull(),
125 'label':
'#corrections'})
127 fig.savefig(self.
resultdir +
'/Corrections_Heatmap_kind_{:d}.png'.format(pixelkind), dpi=100)
131 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'shapes')
132 fig = plt.figure(figsize=(12, 12))
133 ax = fig.add_subplot(111)
134 ax.set_xlabel(
'thetaU / degree', size=20)
135 ax.set_ylabel(
'thetaV / degree', size=20)
136 ax.set_title(
'Number of shapes kind={:d}'.format(pixelkind), size=20)
139 mask=pivot_table.isnull(),
148 fig.savefig(self.
resultdir +
'/Shapes_Heatmap_kind_{:d}.png'.format(pixelkind), dpi=100)
152 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'coverage')
153 fig = plt.figure(figsize=(12, 12))
154 ax = fig.add_subplot(111)
155 ax.set_xlabel(
'thetaU / degree', size=20)
156 ax.set_ylabel(
'thetaV / degree', size=20)
157 ax.set_title(
'Coverage kind={:d}'.format(pixelkind), size=20)
160 mask=pivot_table.isnull(),
167 'label':
'coverage / %'})
169 fig.savefig(self.
resultdir +
'/Coverage_Heatmap_kind_{:d}.png'.format(pixelkind), dpi=100)
173 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'sigma_u')
174 fig = plt.figure(figsize=(12, 12))
175 ax = fig.add_subplot(111)
176 ax.set_xlabel(
'thetaU / degree', size=20)
177 ax.set_ylabel(
'thetaV / degree', size=20)
178 ax.set_title(
'Average cluster sigma u kind={:d}'.format(pixelkind), size=20)
181 mask=pivot_table.isnull(),
188 'label':
'sigma u / um'})
190 fig.savefig(self.
resultdir +
'/SigmaU_Heatmap_kind_{:d}.png'.format(pixelkind), dpi=100)
194 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'sigma_v')
195 fig = plt.figure(figsize=(12, 12))
196 ax = fig.add_subplot(111)
197 ax.set_xlabel(
'thetaU / degree', size=20)
198 ax.set_ylabel(
'thetaV / degree', size=20)
199 ax.set_title(
'Average cluster sigma v kind={:d}'.format(pixelkind), size=20)
202 mask=pivot_table.isnull(),
209 'label':
'sigma v / um'})
211 fig.savefig(self.
resultdir +
'/SigmaV_Heatmap_kind_{:d}.png'.format(pixelkind), dpi=100)
215 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'corr_uv')
216 fig = plt.figure(figsize=(12, 12))
217 ax = fig.add_subplot(111)
218 ax.set_xlabel(
'thetaU / degree', size=20)
219 ax.set_ylabel(
'thetaV / degree', size=20)
220 ax.set_title(
'Average uv correlation kind={:d}'.format(pixelkind), size=20)
223 mask=pivot_table.isnull(),
230 'label':
'correlation'})
232 fig.savefig(self.
resultdir +
'/CorrelationUV_Heatmap_kind_{:d}.png'.format(pixelkind), dpi=100)
237 """Compute some statistics for a shape classifier"""
239 offsetMap = shape_classifier.getOffsetMap()
240 likelyhoodMap = shape_classifier.getLikelyhoodMap()
241 shapeLikelyhoodMap = shape_classifier.getShapeLikelyhoodMap()
248 for item
in offsetMap:
249 shape_index = item.first
250 offsets_array = item.second
251 shape_likelyhood = shapeLikelyhoodMap[shape_index]
255 for eta_index, offset
in enumerate(offsets_array):
256 coverage += likelyhoodMap[shape_index][eta_index]
262 sigma_u = np.sqrt(cov[0, 0])
263 sigma_v = np.sqrt(cov[1, 1])
264 corr_uv = cov[0, 1] / (np.sqrt(cov[0, 0]) * np.sqrt(cov[1, 1]))
272 stats[
'shapes'] = nShapes
273 stats[
'corrections'] = nCorrections
274 stats[
'coverage'] = 100 * coverage
275 stats[
'sigma_u'] = sigma_u
276 stats[
'sigma_v'] = sigma_v
277 stats[
'corr_uv'] = corr_uv
283 if __name__ ==
"__main__":
288 parser = argparse.ArgumentParser(description=
"Plot summary of hit estimator")
289 parser.add_argument(
'--resultdir', default=
"results", type=str, help=
'Put all plots in this directory')
290 args = parser.parse_args()
293 if os.path.isdir(os.getcwd() +
'/' + args.resultdir):
294 shutil.rmtree(os.getcwd() +
'/' + args.resultdir)
297 os.mkdir(os.getcwd() +
'/' + args.resultdir)
301 main.add_module(
"EventInfoSetter", evtNumList=[1])
303 main.add_module(
"Progress")