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/>.
17
#include "src/common_cpp/Recon/Kalman/KalmanState.hh"
18
#include "gtest/gtest.h"
21
class KalmanStateTest : public ::testing::Test {
24
virtual ~KalmanStateTest() {}
25
virtual void SetUp() {}
26
virtual void TearDown() {}
29
TEST_F(KalmanStateTest, getters_and_setters_test) {
30
// Build a Kalman Site
31
MAUS::KalmanState a_site = MAUS::KalmanState();
36
// Define projected states...
37
TMatrixD projected_a(5, 1);
38
projected_a(0, 0) = 1.0;
39
projected_a(1, 0) = 2.0;
40
projected_a(2, 0) = 3.0;
41
projected_a(3, 0) = 4.0;
42
projected_a(4, 0) = 5.0;
43
// TMatrixD pull(2, 1);
48
// ... filtered states...
55
// TMatrixD residual(2, 1);
56
TMatrixD residual(1, 1);
58
// residual(1, 0) = 2.;
61
// ... and smoothed states.
62
TMatrixD smoothed_a(5, 1);
63
smoothed_a(0, 0) = 1.2;
64
smoothed_a(1, 0) = 2.2;
65
smoothed_a(2, 0) = 3.2;
66
smoothed_a(3, 0) = 4.2;
67
smoothed_a(4, 0) = 5.2;
69
TMatrixD smoothed_residual(1, 1);
70
smoothed_residual(0, 0) = 0.6;
72
TMatrixD covariance_residual(1, 1);
73
covariance_residual(0, 0) = 1.;
75
TMatrixD smoothed_residual(2, 1);
76
smoothed_residual(0, 0) = 0.6;
77
smoothed_residual(1, 0) = 3.;
79
TMatrixD covariance_residual(2, 2);
80
covariance_residual(0, 0) = 1.;
81
covariance_residual(0, 1) = 2.;
82
covariance_residual(1, 0) = 3.;
83
covariance_residual(1, 1) = 4.;
86
a_site.set_a(projected_a, MAUS::KalmanState::Projected);
87
a_site.set_residual(pull, MAUS::KalmanState::Projected);
89
a_site.set_a(a, MAUS::KalmanState::Filtered);
90
a_site.set_residual(residual, MAUS::KalmanState::Filtered);
91
a_site.set_chi2(chi2);
93
a_site.set_a(smoothed_a, MAUS::KalmanState::Smoothed);
94
a_site.set_residual(smoothed_residual, MAUS::KalmanState::Smoothed);
95
a_site.set_covariance_residual(covariance_residual, MAUS::KalmanState::Smoothed);
97
// Now, we can quickly check that these states were set as expected.
98
// Expectations can't handle TMatrices, so we'll be comparing first element of each.
99
EXPECT_EQ(a_site.id(), id);
100
EXPECT_EQ(a_site.residual(MAUS::KalmanState::Projected)(0, 0),
102
EXPECT_EQ(a_site.residual(MAUS::KalmanState::Filtered)(0, 0),
104
EXPECT_EQ(a_site.residual(MAUS::KalmanState::Smoothed)(0, 0),
105
smoothed_residual(0, 0));
106
EXPECT_EQ(a_site.a(MAUS::KalmanState::Projected)(0, 0),
108
EXPECT_EQ(a_site.a(MAUS::KalmanState::Filtered)(0, 0),
110
EXPECT_EQ(a_site.a(MAUS::KalmanState::Smoothed)(0, 0),
112
EXPECT_EQ(a_site.chi2(), chi2);
114
// Are the copy constructor and the assignment operator working? Check them.
116
MAUS::KalmanState copy = MAUS::KalmanState(a_site);
117
EXPECT_EQ(copy.id(), id);
118
EXPECT_EQ(copy.residual(MAUS::KalmanState::Projected)(0, 0),
120
EXPECT_EQ(copy.residual(MAUS::KalmanState::Filtered)(0, 0),
122
EXPECT_EQ(copy.residual(MAUS::KalmanState::Smoothed)(0, 0),
123
smoothed_residual(0, 0));
124
EXPECT_EQ(copy.a(MAUS::KalmanState::Projected)(0, 0),
126
EXPECT_EQ(copy.a(MAUS::KalmanState::Filtered)(0, 0),
128
EXPECT_EQ(copy.a(MAUS::KalmanState::Smoothed)(0, 0),
130
EXPECT_EQ(copy.chi2(), chi2);
131
EXPECT_EQ(copy.covariance_residual(MAUS::KalmanState::Smoothed)(0, 0),
132
covariance_residual(0, 0));
134
// Now, the assignment.
135
MAUS::KalmanState second_copy;
137
EXPECT_EQ(second_copy.id(), id);
138
EXPECT_EQ(second_copy.residual(MAUS::KalmanState::Projected)(0, 0),
140
EXPECT_EQ(second_copy.residual(MAUS::KalmanState::Filtered)(0, 0),
142
EXPECT_EQ(second_copy.residual(MAUS::KalmanState::Smoothed)(0, 0),
143
smoothed_residual(0, 0));
144
EXPECT_EQ(second_copy.a(MAUS::KalmanState::Projected)(0, 0),
146
EXPECT_EQ(second_copy.a(MAUS::KalmanState::Filtered)(0, 0),
148
EXPECT_EQ(second_copy.a(MAUS::KalmanState::Smoothed)(0, 0),
150
EXPECT_EQ(second_copy.chi2(), chi2);
151
EXPECT_EQ(second_copy.covariance_residual(MAUS::KalmanState::Smoothed)(0, 0),
152
covariance_residual(0, 0));
155
EXPECT_THROW(a_site.set_covariance_residual(covariance_residual, MAUS::KalmanState::Initialized),
157
EXPECT_THROW(a_site.set_residual(smoothed_residual, MAUS::KalmanState::Initialized),
159
EXPECT_THROW(a_site.set_covariance_matrix(covariance_residual, MAUS::KalmanState::Initialized),