CbmRoot
Loading...
Searching...
No Matches
LitFiltration.h
Go to the documentation of this file.
1/* Copyright (C) 2009-2013 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer] */
4
14#ifndef LITFILTRATION_H_
15#define LITFILTRATION_H_
16
17#include "LitPixelHit.h"
18#include "LitScalPixelHit.h"
19#include "LitStripHit.h"
20#include "LitTrackParam.h"
21
22namespace lit
23{
24 namespace parallel
25 {
26
38 template<class T>
39 inline void LitFiltration(LitTrackParam<T>& par, const LitPixelHit<T>& hit, T& chiSq)
40 {
41 static const T ONE = 1., TWO = 2.;
42
43 T dxx = hit.Dx * hit.Dx;
44 T dxy = hit.Dxy;
45 T dyy = hit.Dy * hit.Dy;
46
47 // calculate residuals
48 T dx = hit.X - par.X;
49 T dy = hit.Y - par.Y;
50
51 // Calculate and inverse residual covariance matrix
52 T t = ONE
53 / (dxx * dyy + dxx * par.C5 + dyy * par.C0 + par.C0 * par.C5 - dxy * dxy - TWO * dxy * par.C1
54 - par.C1 * par.C1);
55 T R00 = (dyy + par.C5) * t;
56 T R01 = -(dxy + par.C1) * t;
57 T R11 = (dxx + par.C0) * t;
58
59 // Calculate Kalman gain matrix
60 T K00 = par.C0 * R00 + par.C1 * R01;
61 T K01 = par.C0 * R01 + par.C1 * R11;
62 T K10 = par.C1 * R00 + par.C5 * R01;
63 T K11 = par.C1 * R01 + par.C5 * R11;
64 T K20 = par.C2 * R00 + par.C6 * R01;
65 T K21 = par.C2 * R01 + par.C6 * R11;
66 T K30 = par.C3 * R00 + par.C7 * R01;
67 T K31 = par.C3 * R01 + par.C7 * R11;
68 T K40 = par.C4 * R00 + par.C8 * R01;
69 T K41 = par.C4 * R01 + par.C8 * R11;
70
71 // Calculate filtered state vector
72 par.X += K00 * dx + K01 * dy;
73 par.Y += K10 * dx + K11 * dy;
74 par.Tx += K20 * dx + K21 * dy;
75 par.Ty += K30 * dx + K31 * dy;
76 par.Qp += K40 * dx + K41 * dy;
77
78 // Calculate filtered covariance matrix
79 T cIn[15] = {par.C0, par.C1, par.C2, par.C3, par.C4, par.C5, par.C6, par.C7,
80 par.C8, par.C9, par.C10, par.C11, par.C12, par.C13, par.C14};
81
82 par.C0 += -K00 * cIn[0] - K01 * cIn[1];
83 par.C1 += -K00 * cIn[1] - K01 * cIn[5];
84 par.C2 += -K00 * cIn[2] - K01 * cIn[6];
85 par.C3 += -K00 * cIn[3] - K01 * cIn[7];
86 par.C4 += -K00 * cIn[4] - K01 * cIn[8];
87
88 par.C5 += -K11 * cIn[5] - K10 * cIn[1];
89 par.C6 += -K11 * cIn[6] - K10 * cIn[2];
90 par.C7 += -K11 * cIn[7] - K10 * cIn[3];
91 par.C8 += -K11 * cIn[8] - K10 * cIn[4];
92
93 par.C9 += -K20 * cIn[2] - K21 * cIn[6];
94 par.C10 += -K20 * cIn[3] - K21 * cIn[7];
95 par.C11 += -K20 * cIn[4] - K21 * cIn[8];
96
97 par.C12 += -K30 * cIn[3] - K31 * cIn[7];
98 par.C13 += -K30 * cIn[4] - K31 * cIn[8];
99
100 par.C14 += -K40 * cIn[4] - K41 * cIn[8];
101
102 // Calculate chi-square
103 T xmx = hit.X - par.X;
104 T ymy = hit.Y - par.Y;
105 T norm =
106 dxx * dyy - dxx * par.C5 - dyy * par.C0 + par.C0 * par.C5 - dxy * dxy + TWO * dxy * par.C1 - par.C1 * par.C1;
107 chiSq =
108 ((xmx * (dyy - par.C5) - ymy * (dxy - par.C1)) * xmx + (-xmx * (dxy - par.C1) + ymy * (dxx - par.C0)) * ymy)
109 / norm;
110 }
111
123 template<class T>
124 inline void LitFiltration(LitTrackParam<T>& par, const LitStripHit<T>& hit, T& chiSq)
125 {
126 static const T ONE = 1., TWO = 2.;
127
128 T duu = hit.Du * hit.Du;
129 T phiCosSq = hit.phiCos * hit.phiCos;
130 T phiSinSq = hit.phiSin * hit.phiSin;
131 T phi2SinCos = TWO * hit.phiCos * hit.phiSin;
132
133 // residual
134 T r = hit.U - par.C0 * hit.phiCos - par.C1 * hit.phiSin;
135 T norm = duu + par.C0 * phiCosSq + phi2SinCos * par.C1 + par.C5 * phiSinSq;
136 // myf norm = duu + cIn[0] * phiCos + cIn[5] * phiSin;
137 T R = rcp(norm);
138
139 // Calculate Kalman gain matrix
140 T K0 = par.C0 * hit.phiCos + par.C1 * hit.phiSin;
141 T K1 = par.C1 * hit.phiCos + par.C5 * hit.phiSin;
142 T K2 = par.C2 * hit.phiCos + par.C6 * hit.phiSin;
143 T K3 = par.C3 * hit.phiCos + par.C7 * hit.phiSin;
144 T K4 = par.C4 * hit.phiCos + par.C8 * hit.phiSin;
145
146 T KR0 = K0 * R;
147 T KR1 = K1 * R;
148 T KR2 = K2 * R;
149 T KR3 = K3 * R;
150 T KR4 = K4 * R;
151
152 // Calculate filtered state vector
153 par.X += KR0 * r;
154 par.Y += KR1 * r;
155 par.Tx += KR2 * r;
156 par.Ty += KR3 * r;
157 par.Qp += KR4 * r;
158
159 // Calculate filtered covariance matrix
160 par.C0 -= KR0 * K0;
161 par.C1 -= KR0 * K1;
162 par.C2 -= KR0 * K2;
163 par.C3 -= KR0 * K3;
164 par.C4 -= KR0 * K4;
165
166 par.C5 -= KR1 * K1;
167 par.C6 -= KR1 * K2;
168 par.C7 -= KR1 * K3;
169 par.C8 -= KR1 * K4;
170
171 par.C9 -= KR2 * K2;
172 par.C10 -= KR2 * K3;
173 par.C11 -= KR2 * K4;
174
175 par.C12 -= KR3 * K3;
176 par.C13 -= KR3 * K4;
177
178 par.C14 -= KR4 * K4;
179
180 // Calculate chi-square
181 T ru = hit.U - par.X * hit.phiCos - par.Y * hit.phiSin;
182 chiSq = (ru * ru) / (duu - phiCosSq * par.C0 - phi2SinCos * par.C1 - phiSinSq * par.C5);
183 }
184
192 inline void LitFiltration(LitTrackParamScal& par, const LitScalPixelHit& hit, fscal& chiSq)
193 {
194 LitPixelHitScal pixelHit;
195 pixelHit.X = hit.X;
196 pixelHit.Y = hit.Y;
197 pixelHit.Z = hit.Z;
198 pixelHit.Dx = hit.Dx;
199 pixelHit.Dy = hit.Dy;
200 pixelHit.Dxy = hit.Dxy;
201 LitFiltration<fscal>(par, pixelHit, chiSq);
202 }
203
204 } // namespace parallel
205} // namespace lit
206#endif /* LITFILTRATION_H_ */
Base class for pixel hits.
Base class for scalar pixel hits.
Base class for strip hits.
Track parameters data class.
Base class for strip hits.
Definition LitStripHit.h:32
Base class for pixel hits.
Definition LitPixelHit.h:35
Base class for scalar pixel hits.
Track parameters data class.
fscal rcp(const fscal &a)
Returns reciprocal.
Definition LitMath.h:32
void LitFiltration(LitTrackParam< T > &par, const LitPixelHit< T > &hit, T &chiSq)
Function implements Kalman filter update step for pixel hit.