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/>.
19
#include "src/common_cpp/Recon/Kalman/MAUSSciFiIntegratedPropagator.hh"
21
#include "src/common_cpp/Utils/Exception.hh"
27
FieldIntegratedPropagator::FieldIntegratedPropagator(SciFiGeometryHelper* helper) :
28
Kalman::Propagator_base(5),
30
_perfectErrorTracking() {
31
_errorTracking.SetTrackingModel(Kalman::Global::ErrorTracking::em_forwards_dynamic);
32
_errorTracking.SetGeometryModel(Kalman::Global::ErrorTracking::axial_lookup);
33
_errorTracking.SetEnergyLossModel(Kalman::Global::ErrorTracking::bethe_bloch_forwards);
35
_perfectErrorTracking.SetTrackingModel(Kalman::Global::ErrorTracking::em_forwards_dynamic);
36
_perfectErrorTracking.SetGeometryModel(Kalman::Global::ErrorTracking::axial_lookup);
37
_perfectErrorTracking.SetEnergyLossModel(Kalman::Global::ErrorTracking::no_eloss);
40
void FieldIntegratedPropagator::Propagate(const Kalman::TrackPoint& start_tp, Kalman::TrackPoint& end_tp) {
42
Kalman::State old_filtered = start_tp.GetFiltered();
43
TMatrixD old_covariance = old_filtered.GetCovariance();
45
std::cerr << "Start State:\n";
46
TMatrixD test = old_filtered.GetVector();
47
std::cerr << " " << test(0, 0) << " " << test(2, 0) << " " << test(4, 0) << " " << test(1, 0) << " " << test(3, 0) << "\n";
49
double* V = _V_convert_to_array(old_filtered, start_tp.GetPosition());
50
double* M = _M_convert_to_array(old_filtered, start_tp.GetPosition());
52
_errorTracking.Propagate(V, end_tp.GetPosition());
53
_perfectErrorTracking.PropagateTransferMatrix(M, end_tp.GetPosition());
55
std::cerr << "MATRIX V\n";
56
for (int i = 0; i < 8; ++i) {
57
std::cerr << V[i] << " ";
60
std::cerr << "MATRIX M\n";
61
for (int i = 0; i < 8; ++i) {
62
std::cerr << M[i] << " ";
66
Kalman::State predicted = _V_convert_to_state(V);
69
PropagatorMatrix() = _M_convert_to_matrix(M);
70
NoiseMatrix() = predicted.GetCovariance() - old_covariance;
72
std::cerr << "Propagator Test:\n";
73
test = PropagatorMatrix()*old_filtered.GetVector();
74
std::cerr << " " << test(0, 0) << " " << test(2, 0) << " " << test(4, 0) << " " << test(1, 0) << " " << test(3, 0) << "\n";
79
PropagatorMatrix().Print();
82
for (int i = 0; i < 6; ++i) {
83
for (int j = 0; j < 6; ++j) {
84
std::cerr << M[8+(i*6)+j] << '\t';
92
end_tp.SetPredicted(predicted);
96
TMatrixD FieldIntegratedPropagator::CalculatePropagator(const Kalman::TrackPoint& start,
97
const Kalman::TrackPoint& end) {
98
Kalman::State old_filtered = start.GetFiltered();
99
TMatrixD old_covariance = old_filtered.GetCovariance();
101
double* M = _M_convert_to_array(old_filtered, start.GetPosition());
103
_errorTracking.PropagateTransferMatrix(M, end.GetPosition());
105
TMatrix propagator = _M_convert_to_matrix(M);
111
TMatrixD FieldIntegratedPropagator::CalculateProcessNoise(const Kalman::TrackPoint& start,
112
const Kalman::TrackPoint& end) {
113
Kalman::State old_filtered = start.GetFiltered();
114
TMatrixD old_covariance = old_filtered.GetCovariance();
116
double* V = _V_convert_to_array(old_filtered, start.GetPosition());
118
_errorTracking.Propagate(V, end.GetPosition());
120
Kalman::State predicted = _V_convert_to_state(V);
122
TMatrixD new_noise = predicted.GetCovariance() - old_covariance;
128
double* FieldIntegratedPropagator::_V_convert_to_array(Kalman::State state, double position) {
129
TMatrixD vector = state.GetVector();
130
TMatrixD covariance = state.GetCovariance();
132
double* V = new double[29];
134
double pz = std::sqrt(vector(4, 0)*vector(4, 0) - Recon::Constants::MuonMass*Recon::Constants::MuonMass - vector(1, 0)*vector(1, 0) - vector(3, 0)*vector(3, 0));
145
V[8] = 0.0; // Variance T
152
V[14] = covariance(0, 0); // Variance X
153
V[15] = covariance(0, 2);
154
V[16] = covariance(0, 4);
155
V[17] = covariance(0, 1);
156
V[18] = covariance(0, 3);
158
V[19] = covariance(2, 2); // Variance Y
159
V[20] = covariance(2, 4);
160
V[21] = covariance(2, 1);
161
V[22] = covariance(2, 3);
163
V[23] = covariance(4, 4); // Variance E
164
V[24] = covariance(4, 1);
165
V[25] = covariance(4, 3);
167
V[26] = covariance(1, 1); // Variance px
168
V[27] = covariance(1, 3);
170
V[28] = covariance(3, 3); // Variance py
175
Kalman::State FieldIntegratedPropagator::_V_convert_to_state(double* array) {
176
TMatrixD vector(5, 1);
177
TMatrixD covariance(5, 5);
179
vector(0, 0) = array[1]; // x
180
vector(1, 0) = array[5]; // px
181
vector(2, 0) = array[2]; // y
182
vector(3, 0) = array[6]; // py
183
vector(4, 0) = array[4]; // E
185
covariance(0, 0) = array[14]; // x x
186
covariance(0, 2) = array[15]; // x y
187
covariance(0, 4) = array[16]; // x E
188
covariance(0, 1) = array[17]; // x px
189
covariance(0, 3) = array[18]; // x py
191
covariance(2, 2) = array[19]; // y y
192
covariance(2, 4) = array[20]; // y E
193
covariance(2, 1) = array[21]; // y px
194
covariance(2, 3) = array[22]; // y py
196
covariance(4, 4) = array[23]; // E E
197
covariance(4, 1) = array[24]; // E px
198
covariance(4, 3) = array[25]; // E py
200
covariance(1, 1) = array[26]; // px px
201
covariance(1, 3) = array[27]; // px py
203
covariance(3, 3) = array[28]; // py py
205
// Fill in the others...
206
covariance(1, 0) = covariance(0, 1);
207
covariance(2, 0) = covariance(0, 2);
208
covariance(3, 0) = covariance(0, 3);
209
covariance(4, 0) = covariance(0, 4);
211
covariance(4, 2) = covariance(2, 4);
212
covariance(1, 2) = covariance(2, 1);
213
covariance(3, 2) = covariance(2, 3);
215
covariance(1, 4) = covariance(4, 1);
216
covariance(3, 4) = covariance(4, 3);
218
covariance(3, 1) = covariance(1, 3);
220
Kalman::State state(vector, covariance);
226
double* FieldIntegratedPropagator::_M_convert_to_array(Kalman::State state, double position) {
227
TMatrixD vector = state.GetVector();
229
double* M = new double[44];
231
double pz = std::sqrt(vector(4, 0)*vector(4, 0) - Recon::Constants::MuonMass*Recon::Constants::MuonMass - vector(1, 0)*vector(1, 0) - vector(3, 0)*vector(3, 0));
242
for ( int i = 8; i < 44; ++i ) {
245
M[8] = 1.0; // Make it the identity
255
TMatrixD FieldIntegratedPropagator::_M_convert_to_matrix(double* array) {
257
TMatrixD matrix(5, 5);
259
matrix(4, 4) = array[15]; // E E
260
matrix(4, 0) = array[16]; // E x
261
matrix(4, 1) = array[17]; // E px
262
matrix(4, 2) = array[18]; // E y
263
matrix(4, 3) = array[19]; // E py
265
matrix(0, 4) = array[21]; // x E
266
matrix(0, 0) = array[22]; // x x
267
matrix(0, 1) = array[23]; // x px
268
matrix(0, 2) = array[24]; // x y
269
matrix(0, 3) = array[25]; // x py
271
matrix(1, 4) = array[27]; // px E
272
matrix(1, 0) = array[28]; // px x
273
matrix(1, 1) = array[29]; // px px
274
matrix(1, 2) = array[30]; // px y
275
matrix(1, 3) = array[31]; // px py
277
matrix(2, 4) = array[33]; // y E
278
matrix(2, 0) = array[34]; // y x
279
matrix(2, 1) = array[35]; // y px
280
matrix(2, 2) = array[36]; // y y
281
matrix(2, 3) = array[37]; // y py
283
matrix(3, 4) = array[39]; // py E
284
matrix(3, 0) = array[40]; // py x
285
matrix(3, 1) = array[41]; // py px
286
matrix(3, 2) = array[42]; // py y
287
matrix(3, 3) = array[43]; // py py