~vpec/maus/tof_calib_read

« back to all changes in this revision

Viewing changes to tests/cpp_unit/Recon/Kalman/KalmanStateTest.cc

  • Committer: Adam Dobbs
  • Date: 2015-06-26 14:33:50 UTC
  • mfrom: (659.1.113 release-candidate)
  • Revision ID: phuccj@gmail.com-20150626143350-m56pbthi31ahqvxj
Tags: MAUS-v0.9.6
MAUS-v0.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
2
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 */
17
 
#include "src/common_cpp/Recon/Kalman/KalmanState.hh"
18
 
#include "gtest/gtest.h"
19
 
 
20
 
namespace {
21
 
class KalmanStateTest : public ::testing::Test {
22
 
 protected:
23
 
  KalmanStateTest()  {}
24
 
  virtual ~KalmanStateTest() {}
25
 
  virtual void SetUp()    {}
26
 
  virtual void TearDown() {}
27
 
};
28
 
 
29
 
TEST_F(KalmanStateTest, getters_and_setters_test) {
30
 
  // Build a Kalman Site
31
 
  MAUS::KalmanState a_site = MAUS::KalmanState();
32
 
  a_site.Initialise(5);
33
 
  int id = 13;
34
 
  a_site.set_id(id);
35
 
 
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);
44
 
  TMatrixD pull(1, 1);
45
 
  pull(0, 0) = 1.2;
46
 
  // pull(1, 0) = 1.;
47
 
 
48
 
  // ... filtered states...
49
 
  TMatrixD a(5, 1);
50
 
  a(0, 0) = 1.1;
51
 
  a(1, 0) = 2.1;
52
 
  a(2, 0) = 3.1;
53
 
  a(3, 0) = 4.1;
54
 
  a(4, 0) = 5.1;
55
 
  // TMatrixD residual(2, 1);
56
 
  TMatrixD residual(1, 1);
57
 
  residual(0, 0) = 0.8;
58
 
  // residual(1, 0) = 2.;
59
 
  double chi2 = 2.;
60
 
 
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;
68
 
 
69
 
  TMatrixD smoothed_residual(1, 1);
70
 
  smoothed_residual(0, 0) = 0.6;
71
 
 
72
 
  TMatrixD covariance_residual(1, 1);
73
 
  covariance_residual(0, 0) = 1.;
74
 
  /*
75
 
  TMatrixD smoothed_residual(2, 1);
76
 
  smoothed_residual(0, 0) = 0.6;
77
 
  smoothed_residual(1, 0) = 3.;
78
 
 
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.;
84
 
  */
85
 
  // Set them all.
86
 
  a_site.set_a(projected_a, MAUS::KalmanState::Projected);
87
 
  a_site.set_residual(pull, MAUS::KalmanState::Projected);
88
 
 
89
 
  a_site.set_a(a, MAUS::KalmanState::Filtered);
90
 
  a_site.set_residual(residual, MAUS::KalmanState::Filtered);
91
 
  a_site.set_chi2(chi2);
92
 
 
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);
96
 
 
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),
101
 
            pull(0, 0));
102
 
  EXPECT_EQ(a_site.residual(MAUS::KalmanState::Filtered)(0, 0),
103
 
            residual(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),
107
 
            projected_a(0, 0));
108
 
  EXPECT_EQ(a_site.a(MAUS::KalmanState::Filtered)(0, 0),
109
 
            a(0, 0));
110
 
  EXPECT_EQ(a_site.a(MAUS::KalmanState::Smoothed)(0, 0),
111
 
            smoothed_a(0, 0));
112
 
  EXPECT_EQ(a_site.chi2(), chi2);
113
 
 
114
 
  // Are the copy constructor and the assignment operator working? Check them.
115
 
  // First, copy...
116
 
  MAUS::KalmanState copy = MAUS::KalmanState(a_site);
117
 
  EXPECT_EQ(copy.id(), id);
118
 
  EXPECT_EQ(copy.residual(MAUS::KalmanState::Projected)(0, 0),
119
 
            pull(0, 0));
120
 
  EXPECT_EQ(copy.residual(MAUS::KalmanState::Filtered)(0, 0),
121
 
            residual(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),
125
 
            projected_a(0, 0));
126
 
  EXPECT_EQ(copy.a(MAUS::KalmanState::Filtered)(0, 0),
127
 
            a(0, 0));
128
 
  EXPECT_EQ(copy.a(MAUS::KalmanState::Smoothed)(0, 0),
129
 
            smoothed_a(0, 0));
130
 
  EXPECT_EQ(copy.chi2(), chi2);
131
 
  EXPECT_EQ(copy.covariance_residual(MAUS::KalmanState::Smoothed)(0, 0),
132
 
            covariance_residual(0, 0));
133
 
 
134
 
  // Now, the assignment.
135
 
  MAUS::KalmanState second_copy;
136
 
  second_copy = copy;
137
 
  EXPECT_EQ(second_copy.id(), id);
138
 
  EXPECT_EQ(second_copy.residual(MAUS::KalmanState::Projected)(0, 0),
139
 
            pull(0, 0));
140
 
  EXPECT_EQ(second_copy.residual(MAUS::KalmanState::Filtered)(0, 0),
141
 
            residual(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),
145
 
            projected_a(0, 0));
146
 
  EXPECT_EQ(second_copy.a(MAUS::KalmanState::Filtered)(0, 0),
147
 
            a(0, 0));
148
 
  EXPECT_EQ(second_copy.a(MAUS::KalmanState::Smoothed)(0, 0),
149
 
            smoothed_a(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));
153
 
 
154
 
  // Bad requests
155
 
  EXPECT_THROW(a_site.set_covariance_residual(covariance_residual, MAUS::KalmanState::Initialized),
156
 
               MAUS::Exception);
157
 
  EXPECT_THROW(a_site.set_residual(smoothed_residual, MAUS::KalmanState::Initialized),
158
 
               MAUS::Exception);
159
 
  EXPECT_THROW(a_site.set_covariance_matrix(covariance_residual, MAUS::KalmanState::Initialized),
160
 
               MAUS::Exception);
161
 
}
162
 
}