Skip to content

Commit

Permalink
MAINT: fix KF prediction
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickDieter authored and DavidLP committed Jul 25, 2017
1 parent 4c99c85 commit 545147e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions testbeam_analysis/testing/test_kalman.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ def test_kalman(self):
'add_scattering_plane': False}

# expected result array: (state estimates, chi, x error, y errors)
result = np.array([[[-1.23045812e+03, 2.82684464e+03, 9.54189393e-04, 5.78723069e-05],
[-1.25900270e+03, 2.82511339e+03, 9.54667995e-04, 5.79013344e-05],
[-1.28705254e+03, 2.82443254e+03, 9.22692240e-04, 2.23966275e-05],
[-1.30575083e+03, 2.82550588e+03, 8.57719412e-04, -4.92360235e-05],
[-1.33339390e+03, 2.83014572e+03, 7.55275169e-04, -1.26771525e-04],
[-1.36192826e+03, 2.83782855e+03, 6.79389545e-04, -1.82924543e-04],
[-1.38713361e+03, 2.84461505e+03, 6.79389545e-04, -1.82924543e-04]],
[74],
[3.62429044, 3.2884327, 3.21655702, 3.1539946, 3.23671172, 4.66501707, 8.62909928],
[3.62429044, 3.2884327, 3.21655702, 3.1539946, 3.23671172, 4.66501707, 8.62909928]])
result = np.array([[[-1.23001328e+03, 2.82727830e+03, -9.15880110e-04, -2.09034100e-05],
[-1.25862573e+03, 2.82521051e+03, -8.74822163e-04, 2.73502359e-05],
[-1.28712065e+03, 2.82381689e+03, -8.12311281e-04, 1.00543040e-04],
[-1.30702210e+03, 2.82479582e+03, -7.11712303e-04, 1.56181457e-04],
[-1.33425505e+03, 2.82962871e+03, -6.79354825e-04, 1.80316681e-04],
[-1.36061740e+03, 2.83880395e+03, -7.31034579e-04, 1.42175167e-04],
[-1.38773879e+03, 2.84407865e+03, -7.31034579e-04, 1.42175167e-04]],
[37],
[3.67202783, 4.76060863, 3.73543952, 3.67302492, 3.99327848, 4.88787552, 10.82919706],
[3.67202783, 4.76060863, 3.73543952, 3.67302492, 3.99327848, 4.88787552, 10.82919706]])

for i in range(4): # test each return (state estimates, chi, x error, y errors) seperatly
test = test_tools._call_function_with_args(function=track_analysis._fit_tracks_kalman_loop,
Expand Down
4 changes: 2 additions & 2 deletions testbeam_analysis/tools/kalman.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ def _filter(alignment, transition_matrices, observation_matrices, transition_cov
z_diff = offsets_rotated[1][:, 2] - offsets_rotated[0][:, 2]

# update transition matrix, only need to change these value in case for rotated planes
transition_matrices[:, t - 1, 0, 2] = - z_diff
transition_matrices[:, t - 1, 1, 3] = - z_diff
transition_matrices[:, t - 1, 0, 2] = z_diff
transition_matrices[:, t - 1, 1, 3] = z_diff

# store updated transition matrix for smoothing function
transition_matrices_update[:, t - 1] = transition_matrices[:, t - 1]
Expand Down
8 changes: 4 additions & 4 deletions testbeam_analysis/track_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,8 +1243,8 @@ def _fit_tracks_kalman_loop(track_hits, dut_fit_selection, pixel_size, n_pixels,
# If first dut is used in track building, take first dut hit as initial value and
# its corresponding cluster position error as the error on the measurement.
initial_state_mean[index] = np.array([actual_hits[0, 0], actual_hits[0, 1], 0., 0.])
initial_state_covariance[index, 0, 0] = np.square(x_err[0]) # np.square(pixel_resolution[0, 0]) # np.square(x_err[0])
initial_state_covariance[index, 1, 1] = np.square(y_err[0]) # np.square(pixel_resolution[0, 1]) # np.square(y_err[0])
initial_state_covariance[index, 0, 0] = np.square(x_err[0])
initial_state_covariance[index, 1, 1] = np.square(y_err[0])
else: # first dut is not in fit selction
# Take hit from first dut which is in fit selection. Cannot take hit from first dut,
# since do not want to pass measurement to kalman filter (unbiased).
Expand All @@ -1260,9 +1260,9 @@ def _fit_tracks_kalman_loop(track_hits, dut_fit_selection, pixel_size, n_pixels,
# rotations of planes into account.
transition_matrix[index, sel, :, 0] = np.array([1., 0., 0., 0.])
transition_matrix[index, sel, :, 1] = np.array([0., 1., 0., 0.])
transition_matrix[index, sel, :, 2] = np.array([-(z_diff), np.zeros((len(sel),)),
transition_matrix[index, sel, :, 2] = np.array([(z_diff), np.zeros((len(sel),)),
np.ones((len(sel),)), np.zeros((len(sel),))]).T
transition_matrix[index, sel, :, 3] = np.array([np.zeros((len(sel),)), -(z_diff),
transition_matrix[index, sel, :, 3] = np.array([np.zeros((len(sel),)), (z_diff),
np.zeros((len(sel),)), np.ones((len(sel),))]).T

# express transition covariance matrices, according to http://web-docs.gsi.de/~ikisel/reco/Methods/CovarianceMatrices-NIMA329-1993.pdf
Expand Down

0 comments on commit 545147e

Please sign in to comment.