12Plot PXD position estimator payload
16import matplotlib.pyplot
as plt
21from ROOT
import Belle2
25 """Plot the PXDClusterPositionEstimator playload """
38 """Plot position payload in case it has changed"""
42 b2.B2INFO(
"PXDClusterPositionEstimator payload has changed. Plot the new payload.")
47 """Compute the average covariance for a shape classifier"""
51 offsetMap = shape_classifier.getOffsetMap()
52 likelyhoodMap = shape_classifier.getLikelyhoodMap()
54 for item
in offsetMap:
55 shape_index = item.first
58 for eta_index, offset
in enumerate(offsets):
59 likelyhood = likelyhoodMap[shape_index][eta_index]
60 flat_covs.append([offset.getUSigma2(), offset.getVSigma2(), offset.getUVCovariance()])
61 weights.append(likelyhood)
63 weights = np.array(weights)
64 flat_covs = np.array(flat_covs)
65 flat_average = np.average(flat_covs, axis=0, weights=weights)
66 return np.array([[flat_average[0], flat_average[2]], [flat_average[2], flat_average[1]]])
69 """Plot position estimator payload"""
71 pixelkind = pair.first
75 summary_dict = {
'shapes': [],
87 for uBin
in range(1, grid.GetXaxis().GetNbins() + 1):
88 for vBin
in range(1, grid.GetYaxis().GetNbins() + 1):
94 thetaU = grid.GetXaxis().GetBinCenter(uBin)
95 thetaV = grid.GetYaxis().GetBinCenter(vBin)
101 summary_dict[
'thetaU'].append(thetaU)
102 summary_dict[
'thetaV'].append(thetaV)
103 summary_dict[
'pixelkind'].append(pixelkind)
104 summary_dict[
'shapes'].append(stats[
'shapes'])
105 summary_dict[
'corrections'].append(stats[
'corrections'])
106 summary_dict[
'coverage'].append(stats[
'coverage'])
107 summary_dict[
'sigma_u'].append(stats[
'sigma_u'] * 10000)
108 summary_dict[
'sigma_v'].append(stats[
'sigma_v'] * 10000)
109 summary_dict[
'corr_uv'].append(stats[
'corr_uv'])
112 df = pd.DataFrame(summary_dict)
114 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'corrections')
115 fig = plt.figure(figsize=(12, 12))
116 ax = fig.add_subplot(111)
117 ax.set_xlabel(
'thetaU / degree', size=20)
118 ax.set_ylabel(
'thetaV / degree', size=20)
119 ax.set_title(f
'Number of corrections kind={pixelkind:d}', size=20)
122 mask=pivot_table.isnull(),
129 'label':
'#corrections'})
131 fig.savefig(self.
resultdir + f
'/Corrections_Heatmap_kind_{pixelkind:d}.png', dpi=100)
135 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'shapes')
136 fig = plt.figure(figsize=(12, 12))
137 ax = fig.add_subplot(111)
138 ax.set_xlabel(
'thetaU / degree', size=20)
139 ax.set_ylabel(
'thetaV / degree', size=20)
140 ax.set_title(f
'Number of shapes kind={pixelkind:d}', size=20)
143 mask=pivot_table.isnull(),
152 fig.savefig(self.
resultdir + f
'/Shapes_Heatmap_kind_{pixelkind:d}.png', dpi=100)
156 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'coverage')
157 fig = plt.figure(figsize=(12, 12))
158 ax = fig.add_subplot(111)
159 ax.set_xlabel(
'thetaU / degree', size=20)
160 ax.set_ylabel(
'thetaV / degree', size=20)
161 ax.set_title(f
'Coverage kind={pixelkind:d}', size=20)
164 mask=pivot_table.isnull(),
171 'label':
'coverage / %'})
173 fig.savefig(self.
resultdir + f
'/Coverage_Heatmap_kind_{pixelkind:d}.png', dpi=100)
177 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'sigma_u')
178 fig = plt.figure(figsize=(12, 12))
179 ax = fig.add_subplot(111)
180 ax.set_xlabel(
'thetaU / degree', size=20)
181 ax.set_ylabel(
'thetaV / degree', size=20)
182 ax.set_title(f
'Average cluster sigma u kind={pixelkind:d}', size=20)
185 mask=pivot_table.isnull(),
192 'label':
'sigma u / um'})
194 fig.savefig(self.
resultdir + f
'/SigmaU_Heatmap_kind_{pixelkind:d}.png', dpi=100)
198 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'sigma_v')
199 fig = plt.figure(figsize=(12, 12))
200 ax = fig.add_subplot(111)
201 ax.set_xlabel(
'thetaU / degree', size=20)
202 ax.set_ylabel(
'thetaV / degree', size=20)
203 ax.set_title(f
'Average cluster sigma v kind={pixelkind:d}', size=20)
206 mask=pivot_table.isnull(),
213 'label':
'sigma v / um'})
215 fig.savefig(self.
resultdir + f
'/SigmaV_Heatmap_kind_{pixelkind:d}.png', dpi=100)
219 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'corr_uv')
220 fig = plt.figure(figsize=(12, 12))
221 ax = fig.add_subplot(111)
222 ax.set_xlabel(
'thetaU / degree', size=20)
223 ax.set_ylabel(
'thetaV / degree', size=20)
224 ax.set_title(f
'Average uv correlation kind={pixelkind:d}', size=20)
227 mask=pivot_table.isnull(),
234 'label':
'correlation'})
236 fig.savefig(self.
resultdir + f
'/CorrelationUV_Heatmap_kind_{pixelkind:d}.png', dpi=100)
241 """Compute some statistics for a shape classifier"""
243 offsetMap = shape_classifier.getOffsetMap()
244 likelyhoodMap = shape_classifier.getLikelyhoodMap()
251 for item
in offsetMap:
252 shape_index = item.first
253 offsets_array = item.second
257 for eta_index, offset
in enumerate(offsets_array):
258 coverage += likelyhoodMap[shape_index][eta_index]
264 sigma_u = np.sqrt(cov[0, 0])
265 sigma_v = np.sqrt(cov[1, 1])
266 corr_uv = cov[0, 1] / (np.sqrt(cov[0, 0]) * np.sqrt(cov[1, 1]))
274 stats[
'shapes'] = nShapes
275 stats[
'corrections'] = nCorrections
276 stats[
'coverage'] = 100 * coverage
277 stats[
'sigma_u'] = sigma_u
278 stats[
'sigma_v'] = sigma_v
279 stats[
'corr_uv'] = corr_uv
285if __name__ ==
"__main__":
290 parser = argparse.ArgumentParser(description=
"Plot summary of hit estimator")
291 parser.add_argument(
'--resultdir', default=
"results", type=str, help=
'Put all plots in this directory')
292 args = parser.parse_args()
295 if os.path.isdir(os.getcwd() +
'/' + args.resultdir):
296 shutil.rmtree(os.getcwd() +
'/' + args.resultdir)
299 os.mkdir(os.getcwd() +
'/' + args.resultdir)
302 main = b2.create_path()
303 main.add_module(
"EventInfoSetter", evtNumList=[1])
305 main.add_module(
"Progress")
Class to access a DBObjPtr from Python.
def average_covariance(self, shape_classifier)
counter
Counter for number of different payloads.
position_estimator
Position estimator payload.
resultdir
Directory to put all plots.
def __init__(self, resultdir)
def get_classifier_stats(self, shape_classifier, pixelkind)