13 Plot PXD position estimator payload
17 import matplotlib.pyplot
as plt
22 from ROOT
import Belle2
26 """Plot the PXDClusterPositionEstimator playload """
39 """Plot position payload in case it has changed"""
43 b2.B2INFO(
"PXDClusterPositionEstimator payload has changed. Plot the new payload.")
48 """Compute the average covariance for a shape classifier"""
52 offsetMap = shape_classifier.getOffsetMap()
53 likelyhoodMap = shape_classifier.getLikelyhoodMap()
55 for item
in offsetMap:
56 shape_index = item.first
59 for eta_index, offset
in enumerate(offsets):
60 likelyhood = likelyhoodMap[shape_index][eta_index]
61 flat_covs.append([offset.getUSigma2(), offset.getVSigma2(), offset.getUVCovariance()])
62 weights.append(likelyhood)
64 weights = np.array(weights)
65 flat_covs = np.array(flat_covs)
66 flat_average = np.average(flat_covs, axis=0, weights=weights)
67 return np.array([[flat_average[0], flat_average[2]], [flat_average[2], flat_average[1]]])
70 """Plot position estimator payload"""
72 pixelkind = pair.first
76 summary_dict = {
'shapes': [],
88 for uBin
in range(1, grid.GetXaxis().GetNbins() + 1):
89 for vBin
in range(1, grid.GetYaxis().GetNbins() + 1):
92 shape_classifier = self.
position_estimatorposition_estimator.getShapeClassifier(uBin, vBin, pixelkind)
95 thetaU = grid.GetXaxis().GetBinCenter(uBin)
96 thetaV = grid.GetYaxis().GetBinCenter(vBin)
102 summary_dict[
'thetaU'].append(thetaU)
103 summary_dict[
'thetaV'].append(thetaV)
104 summary_dict[
'pixelkind'].append(pixelkind)
105 summary_dict[
'shapes'].append(stats[
'shapes'])
106 summary_dict[
'corrections'].append(stats[
'corrections'])
107 summary_dict[
'coverage'].append(stats[
'coverage'])
108 summary_dict[
'sigma_u'].append(stats[
'sigma_u'] * 10000)
109 summary_dict[
'sigma_v'].append(stats[
'sigma_v'] * 10000)
110 summary_dict[
'corr_uv'].append(stats[
'corr_uv'])
113 df = pd.DataFrame(summary_dict)
115 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'corrections')
116 fig = plt.figure(figsize=(12, 12))
117 ax = fig.add_subplot(111)
118 ax.set_xlabel(
'thetaU / degree', size=20)
119 ax.set_ylabel(
'thetaV / degree', size=20)
120 ax.set_title(
'Number of corrections kind={:d}'.format(pixelkind), size=20)
123 mask=pivot_table.isnull(),
130 'label':
'#corrections'})
132 fig.savefig(self.
resultdirresultdir +
'/Corrections_Heatmap_kind_{:d}.png'.format(pixelkind), dpi=100)
136 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'shapes')
137 fig = plt.figure(figsize=(12, 12))
138 ax = fig.add_subplot(111)
139 ax.set_xlabel(
'thetaU / degree', size=20)
140 ax.set_ylabel(
'thetaV / degree', size=20)
141 ax.set_title(
'Number of shapes kind={:d}'.format(pixelkind), size=20)
144 mask=pivot_table.isnull(),
153 fig.savefig(self.
resultdirresultdir +
'/Shapes_Heatmap_kind_{:d}.png'.format(pixelkind), dpi=100)
157 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'coverage')
158 fig = plt.figure(figsize=(12, 12))
159 ax = fig.add_subplot(111)
160 ax.set_xlabel(
'thetaU / degree', size=20)
161 ax.set_ylabel(
'thetaV / degree', size=20)
162 ax.set_title(
'Coverage kind={:d}'.format(pixelkind), size=20)
165 mask=pivot_table.isnull(),
172 'label':
'coverage / %'})
174 fig.savefig(self.
resultdirresultdir +
'/Coverage_Heatmap_kind_{:d}.png'.format(pixelkind), dpi=100)
178 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'sigma_u')
179 fig = plt.figure(figsize=(12, 12))
180 ax = fig.add_subplot(111)
181 ax.set_xlabel(
'thetaU / degree', size=20)
182 ax.set_ylabel(
'thetaV / degree', size=20)
183 ax.set_title(
'Average cluster sigma u kind={:d}'.format(pixelkind), size=20)
186 mask=pivot_table.isnull(),
193 'label':
'sigma u / um'})
195 fig.savefig(self.
resultdirresultdir +
'/SigmaU_Heatmap_kind_{:d}.png'.format(pixelkind), dpi=100)
199 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'sigma_v')
200 fig = plt.figure(figsize=(12, 12))
201 ax = fig.add_subplot(111)
202 ax.set_xlabel(
'thetaU / degree', size=20)
203 ax.set_ylabel(
'thetaV / degree', size=20)
204 ax.set_title(
'Average cluster sigma v kind={:d}'.format(pixelkind), size=20)
207 mask=pivot_table.isnull(),
214 'label':
'sigma v / um'})
216 fig.savefig(self.
resultdirresultdir +
'/SigmaV_Heatmap_kind_{:d}.png'.format(pixelkind), dpi=100)
220 pivot_table = df.pivot(index=
'thetaU', columns=
'thetaV', values=
'corr_uv')
221 fig = plt.figure(figsize=(12, 12))
222 ax = fig.add_subplot(111)
223 ax.set_xlabel(
'thetaU / degree', size=20)
224 ax.set_ylabel(
'thetaV / degree', size=20)
225 ax.set_title(
'Average uv correlation kind={:d}'.format(pixelkind), size=20)
228 mask=pivot_table.isnull(),
235 'label':
'correlation'})
237 fig.savefig(self.
resultdirresultdir +
'/CorrelationUV_Heatmap_kind_{:d}.png'.format(pixelkind), dpi=100)
242 """Compute some statistics for a shape classifier"""
244 offsetMap = shape_classifier.getOffsetMap()
245 likelyhoodMap = shape_classifier.getLikelyhoodMap()
252 for item
in offsetMap:
253 shape_index = item.first
254 offsets_array = item.second
258 for eta_index, offset
in enumerate(offsets_array):
259 coverage += likelyhoodMap[shape_index][eta_index]
265 sigma_u = np.sqrt(cov[0, 0])
266 sigma_v = np.sqrt(cov[1, 1])
267 corr_uv = cov[0, 1] / (np.sqrt(cov[0, 0]) * np.sqrt(cov[1, 1]))
275 stats[
'shapes'] = nShapes
276 stats[
'corrections'] = nCorrections
277 stats[
'coverage'] = 100 * coverage
278 stats[
'sigma_u'] = sigma_u
279 stats[
'sigma_v'] = sigma_v
280 stats[
'corr_uv'] = corr_uv
286 if __name__ ==
"__main__":
291 parser = argparse.ArgumentParser(description=
"Plot summary of hit estimator")
292 parser.add_argument(
'--resultdir', default=
"results", type=str, help=
'Put all plots in this directory')
293 args = parser.parse_args()
296 if os.path.isdir(os.getcwd() +
'/' + args.resultdir):
297 shutil.rmtree(os.getcwd() +
'/' + args.resultdir)
300 os.mkdir(os.getcwd() +
'/' + args.resultdir)
303 main = b2.create_path()
304 main.add_module(
"EventInfoSetter", evtNumList=[1])
306 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)