1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
3
* MAUS is free software: you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation, either version 3 of the License, or
6
* (at your option) any later version.
8
* MAUS is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with MAUS. If not, see <http://www.gnu.org/licenses/>.
20
#include "src/common_cpp/Recon/Kalman/KalmanFilter.hh"
21
#include "src/common_cpp/Recon/Kalman/KalmanHelicalPropagator.hh"
22
#include "src/common_cpp/Recon/Kalman/KalmanState.hh"
24
#include "gtest/gtest.h"
28
class KalmanFilterTest : public ::testing::Test {
31
virtual ~KalmanFilterTest() {}
32
virtual void SetUp() {
35
old_site.Initialise(5);
36
new_site.Initialise(5);
39
old_site.set_z(-451.132);
40
old_site.set_measurement(-15.5);
43
new_site.set_z(-749.828);
44
new_site.set_measurement(-28.5);
55
old_site.set_a(a, MAUS::KalmanState::Filtered);
56
old_site.set_a(a, MAUS::KalmanState::Projected);
60
for ( int i = 0; i < 5; ++i ) {
61
C(i, i) = 1.; // dummy values
63
old_site.set_covariance_matrix(C, MAUS::KalmanState::Projected);
65
kalman_sites.push_back(old_site);
66
kalman_sites.push_back(new_site);
68
virtual void TearDown() {}
69
MAUS::KalmanState old_site;
70
MAUS::KalmanState new_site;
72
static const int dim = 5;
73
std::vector<MAUS::KalmanState> kalman_sites;
76
TEST_F(KalmanFilterTest, test_constructor) {
77
MAUS::KalmanFilter *filter = new MAUS::KalmanFilter(dim);
78
// EXPECT_EQ(track->ndf(), 0.);
79
// EXPECT_EQ(track->tracker(), -1);
84
TEST_F(KalmanFilterTest, test_update_H_for_misalignments) {
85
MAUS::KalmanFilter *filter = new MAUS::KalmanFilter(dim);
86
ThreeVector direction_plane0(0., 1., 0.);
87
ThreeVector direction_plane1(0.866, -0.5, 0.0);
88
ThreeVector direction_plane2(-0.866, -0.5, 0.0);
90
MAUS::KalmanState *a_site= new MAUS::KalmanState();
91
a_site->Initialise(dim);
92
a_site->set_direction(direction_plane0);
94
// Say we have a measurement...
95
TMatrixD measurement(2, 1);
96
measurement(0, 0) = 10.;
97
measurement(1, 0) = 0.;
99
// and there's a x,y position corresponding to that measurement...
102
a(0, 0) = -measurement(0, 0)*1.4945;
104
a(2, 0) = 5.; // random number, y doesnt matter.
107
a_site->set_a(a, MAUS::KalmanState::Projected);
112
filter->UpdateH(a_site);
114
TMatrixD HA = filter->SolveMeasurementEquation(a, s);
115
EXPECT_NEAR(measurement(0, 0), HA(0, 0), 1e-6);
117
// now, we introduce a shift in x.
118
// The state vector is the same, the measurement is slightly different
119
double shift_x = 2.; // mm
120
s(0, 0) = shift_x; // mm
121
// the new measurement includes the misalignment shift
122
double new_alpha = measurement(0, 0) + shift_x/1.4945;
124
TMatrixD HA_new = filter->SolveMeasurementEquation(a, s);
126
EXPECT_NEAR(new_alpha, HA_new(0, 0), 1e-1);
127
// Now, we introduce a shift in both x & y.
128
double shift_y = 2.; // mm
129
s(1, 0) = shift_y; // mm
130
// So we need a plane that's not 0 (because this one is vertical, only measures x)
131
a_site->set_direction(direction_plane1);
132
ThreeVector perp = direction_plane1.Orthogonal();
138
TEST_F(KalmanFilterTest, test_filtering_methods) {
139
MAUS::KalmanFilter *filter = new MAUS::KalmanFilter(dim);
141
ThreeVector direction_plane0(0., 1., 0.);
142
ThreeVector direction_plane1(0.866, -0.5, 0.0);
143
ThreeVector direction_plane2(-0.866, -0.5, 0.0);
145
MAUS::KalmanState *a_site= new MAUS::KalmanState();
146
a_site->Initialise(5);
148
// Plane 0. 1st case.
149
a_site->set_direction(direction_plane2);
158
a_site->set_a(a, MAUS::KalmanState::Projected);
161
filter->UpdateH(a_site);
162
TMatrixD HA = filter->H()*a; // SolveMeasurementEquation(a, s);
164
EXPECT_TRUE(HA(0, 0) > 0);
168
a_site->set_a(a, MAUS::KalmanState::Projected);
171
EXPECT_TRUE(HA(0, 0) < 0);
175
a_site->set_a(a, MAUS::KalmanState::Projected);
178
EXPECT_TRUE(HA(0, 0) < 0);
182
a_site->set_a(a, MAUS::KalmanState::Projected);
185
EXPECT_TRUE(HA(0, 0) < 0);
189
a_site->set_a(a, MAUS::KalmanState::Projected);
191
EXPECT_TRUE(HA(0, 0) > 0);
195
a_site->set_a(a, MAUS::KalmanState::Projected);
198
EXPECT_TRUE(HA(0, 0) > 0);
200
a_site->set_measurement(HA(0, 0));
202
// So we have H ready. Let's test the built of W.
203
// For that, we will need V.
204
filter->UpdateV(a_site);
207
a_site->set_covariance_matrix(C, KalmanState::Projected);
208
a_site->set_input_shift_covariance(C_S);
211
// EXPECT_THROW(track->UpdateW(a_site), Squeal);