Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions testbeam_analysis/examples/kalman_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ def straight_line(x, slope, offset):
for fit_dut_index, actual_fit_dut in enumerate(fit_duts):
track_estimates_chunk, chi2, x_errs, y_errs = track_analysis._fit_tracks_kalman_loop(
measurements, dut_fit_selection,
pixel_size, n_pixels, measurements_plot[0, :, -1],
pixel_size, n_pixels, measurements_plot[0, :, 2],
alignment=None,
beam_energy=2500.,
material_budget=[100. / 125390., 100. / 125390., 100. / 125390., 100. / 125390., 100. / 125390., 100. / 125390., 250. / 93700],
add_scattering_plane=False)
# interpolate hits with straight line
fit_x, _ = curve_fit(straight_line, measurements_plot[0, :, -1][fit_selection] / 1000., measurements[0, :, 0][fit_selection])
fit_y, _ = curve_fit(straight_line, measurements_plot[0, :, -1][fit_selection] / 1000., measurements[0, :, 1][fit_selection])
fit_x, _ = curve_fit(straight_line, measurements_plot[0, :, 2][fit_selection] / 1000., measurements[0, :, 0][fit_selection])
fit_y, _ = curve_fit(straight_line, measurements_plot[0, :, 2][fit_selection] / 1000., measurements[0, :, 1][fit_selection])

# store
track_estimates_chunk_all[fit_dut_index] = track_estimates_chunk
Expand All @@ -180,22 +180,22 @@ def straight_line(x, slope, offset):

# duts which are unused for fit
unused_duts = np.setdiff1d(range(measurements_plot.shape[1]), fit_selection)
x_fit = np.arange(measurements_plot[0, :, -1][0], measurements_plot[0, :, -1][-1], 1.) / 1000.
x_fit = np.arange(measurements_plot[0, :, 2][0], measurements_plot[0, :, 2][-1], 1.) / 1000.

# plot tracks in x-direction
plt.title('Tracks in x-direction for DUT_%d' % plot_dut)
plt.xlabel('z / mm')
plt.ylabel('x / $\mathrm{\mu}$m')
plt.grid()

plt.errorbar(measurements_plot[0, :, -1] / 1000.,
plt.errorbar(measurements_plot[0, :, 2] / 1000.,
track_estimates_chunk_all[np.where(fit_duts == plot_dut)[0], :, 0].reshape(measurements.shape[1],),
yerr=x_errs_all[np.where(fit_duts == plot_dut)[0]].reshape(measurements.shape[1],),
marker='o', linestyle='-', label='Smoothed estimates', zorder=2)
plt.plot(measurements[0, :, -1][unused_duts] / 1000.,
plt.plot(measurements_plot[0, :, 2][unused_duts] / 1000.,
track_estimates_chunk_all[np.where(fit_duts == plot_dut)[0], unused_duts, 0].reshape(len(unused_duts),),
'o', color='indianred', zorder=4)
plt.plot(measurements[0, :, -1] / 1000.,
plt.plot(measurements_plot[0, :, 2] / 1000.,
measurements_plot[0, :, 0],
marker='o', linestyle='-', label='Hit positions', color='green', zorder=3)
plt.plot(x_fit,
Expand All @@ -210,14 +210,14 @@ def straight_line(x, slope, offset):
plt.xlabel('z / mm')
plt.ylabel('y / $\mathrm{\mu}$m')
plt.grid()
plt.errorbar(measurements_plot[0, :, -1] / 1000.,
plt.errorbar(measurements_plot[0, :, 2] / 1000.,
track_estimates_chunk_all[np.where(fit_duts == plot_dut)[0], :, 1].reshape(measurements.shape[1],),
yerr=y_errs_all[np.where(fit_duts == plot_dut)[0]].reshape(measurements.shape[1],),
marker='o', linestyle='-', label='Smoothed estimates', zorder=2)
plt.plot(measurements_plot[0, :, -1][unused_duts] / 1000.,
plt.plot(measurements_plot[0, :, 2][unused_duts] / 1000.,
track_estimates_chunk_all[np.where(fit_duts == plot_dut)[0], unused_duts, 1].reshape(len(unused_duts), ),
'o', color='indianred', zorder=4)
plt.plot(measurements_plot[0, :, -1] / 1000.,
plt.plot(measurements_plot[0, :, 2] / 1000.,
measurements_plot[0, :, 1],
marker='o', linestyle='-', label='Hit positions', zorder=3)
plt.plot(x_fit,
Expand Down