CbmRoot
Loading...
Searching...
No Matches
CbmLitRK4TrackExtrapolator.cxx
Go to the documentation of this file.
1/* Copyright (C) 2007-2019 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer], Timur Ablyazimov */
4
11
13
14#include <cmath>
15#include <complex>
16
17CbmLitRK4TrackExtrapolator::CbmLitRK4TrackExtrapolator(std::shared_ptr<CbmLitField> field) : fField(field) {}
18
20
22 litfloat zOut, std::vector<litfloat>* F)
23{
24 *parOut = *parIn;
25 return Extrapolate(parOut, zOut, F);
26}
27
29{
30 litfloat zIn = par->GetZ();
31
32 std::vector<litfloat> xIn = par->GetStateVector();
33 std::vector<litfloat> xOut(6, 0.);
34 std::vector<litfloat> F1(36, 0.);
35
36 RK4Order(xIn, zIn, xOut, zOut, F1);
37
38 std::vector<litfloat> cIn = par->GetCovMatrix();
39 std::vector<litfloat> cOut(21);
40 TransportC(cIn, F1, cOut);
41
42 par->SetStateVector(xOut);
43 par->SetCovMatrix(cOut);
44 par->SetZ(zOut);
45
46 if (F != NULL) {
47 F->assign(F1.begin(), F1.end());
48 }
49
50 return kLITSUCCESS;
51}
52
53void CbmLitRK4TrackExtrapolator::RK4Order(const std::vector<litfloat>& xIn, litfloat zIn, std::vector<litfloat>& xOut,
54 litfloat zOut, std::vector<litfloat>& derivs) const
55{
56 const litfloat fC = 0.000299792458;
57
58 litfloat coef[4] = {0.0, 0.5, 0.5, 1.0};
59
60 litfloat Ax[4], Ay[4];
61 litfloat dAx_dtx[4], dAy_dtx[4], dAx_dty[4], dAy_dty[4];
62 litfloat k[5][4];
63 litfloat fTx[4];
64 litfloat fTy[4];
65
66 litfloat h = zOut - zIn;
67 litfloat hC = h * fC;
68 litfloat hCqp = h * fC * xIn[4];
69 litfloat x0[5];
70
71 litfloat x[5] = {xIn[0], xIn[1], xIn[2], xIn[3], xIn[5]};
72
73 for (unsigned int iStep = 0; iStep < 4; iStep++) { // 1
74 if (iStep > 0) {
75 for (unsigned int i = 0; i < 5; i++) {
76 x[i] = xIn[4 == i ? 5 : i] + coef[iStep] * k[i][iStep - 1];
77 }
78 }
79
80 litfloat Bx, By, Bz;
81 fField->GetFieldValue(x[0], x[1], zIn + coef[iStep] * h, Bx, By, Bz);
82
83 litfloat tx = x[2];
84 fTx[iStep] = tx;
85 litfloat ty = x[3];
86 fTy[iStep] = ty;
87 litfloat txtx = tx * tx;
88 litfloat tyty = ty * ty;
89 litfloat txty = tx * ty;
90 litfloat txtxtyty1 = 1.0 + txtx + tyty;
91 litfloat t1 = std::sqrt(txtxtyty1);
92 litfloat t2 = 1.0 / txtxtyty1;
93
94 Ax[iStep] = (txty * Bx + ty * Bz - (1.0 + txtx) * By) * t1;
95 Ay[iStep] = (-txty * By - tx * Bz + (1.0 + tyty) * Bx) * t1;
96
97 dAx_dtx[iStep] = Ax[iStep] * tx * t2 + (ty * Bx - 2.0 * tx * By) * t1;
98 dAx_dty[iStep] = Ax[iStep] * ty * t2 + (tx * Bx + Bz) * t1;
99 dAy_dtx[iStep] = Ay[iStep] * tx * t2 + (-ty * By - Bz) * t1;
100 dAy_dty[iStep] = Ay[iStep] * ty * t2 + (-tx * By + 2.0 * ty * Bx) * t1;
101
102 k[0][iStep] = tx * h;
103 k[1][iStep] = ty * h;
104 k[2][iStep] = Ax[iStep] * hCqp;
105 k[3][iStep] = Ay[iStep] * hCqp;
106 k[4][iStep] = t1 * h / CbmLitTrackParam::fSpeedOfLight;
107 } // 1
108
109 for (unsigned int i = 0; i < 4; i++) {
110 xOut[i] = CalcOut(xIn[i], k[i]);
111 }
112 xOut[4] = xIn[4];
113 xOut[5] = CalcOut(xIn[5], k[4]);
114
115 // Calculation of the derivatives
116
117 // derivatives dx/dx, dx/dy and dx/dt
118 // dx/dx
119 derivs[0] = 1.;
120 derivs[6] = 0.;
121 derivs[12] = 0.;
122 derivs[18] = 0.;
123 derivs[24] = 0.;
124 derivs[30] = 0.;
125 // dx/dy
126 derivs[1] = 0.;
127 derivs[7] = 1.;
128 derivs[13] = 0.;
129 derivs[19] = 0.;
130 derivs[25] = 0.;
131 derivs[31] = 0.;
132 // dx/dt
133 derivs[5] = 0.;
134 derivs[11] = 0.;
135 derivs[17] = 0.;
136 derivs[23] = 0.;
137 derivs[29] = 0.;
138 derivs[35] = 1.;
139 // end of derivatives dx/dx, dx/dy and dx/dt
140
141 litfloat fT1 = std::sqrt(1 + xIn[2] * xIn[2] + xIn[3] * xIn[3]);
142
143 // Derivatives dx/tx
144 x[0] = x0[0] = 0.0;
145 x[1] = x0[1] = 0.0;
146 x[2] = x0[2] = 1.0;
147 x[3] = x0[3] = 0.0;
148 x[4] = x0[4] = 0.0;
149 for (unsigned int iStep = 0; iStep < 4; iStep++) { // 2
150 if (iStep > 0) {
151 for (unsigned int i = 0; i < 5; i++) {
152 if (i != 2) {
153 x[i] = x0[i] + coef[iStep] * k[i][iStep - 1];
154 }
155 }
156 }
157
158 k[0][iStep] = x[2] * h;
159 k[1][iStep] = x[3] * h;
160 //k[2][iStep] = (dAx_dtx[iStep] * x[2] + dAx_dty[iStep] * x[3]) * hCqp;
161 k[3][iStep] = (dAy_dtx[iStep] * x[2] + dAy_dty[iStep] * x[3]) * hCqp;
162 k[4][iStep] = (fTx[iStep] * x[2] + fTy[iStep] * x[3]) * h / CbmLitTrackParam::fSpeedOfLight / fT1;
163 } // 2
164
165 derivs[2] = CalcOut(x0[0], k[0]);
166 derivs[8] = CalcOut(x0[1], k[1]);
167 derivs[14] = 1.0;
168 derivs[20] = CalcOut(x0[3], k[3]);
169 derivs[26] = 0.0;
170 derivs[32] = CalcOut(x0[4], k[4]);
171 // end of derivatives dx/dtx
172
173 // Derivatives dx/ty
174 x[0] = x0[0] = 0.0;
175 x[1] = x0[1] = 0.0;
176 x[2] = x0[2] = 0.0;
177 x[3] = x0[3] = 1.0;
178 x[4] = x0[4] = 0.0;
179 for (unsigned int iStep = 0; iStep < 4; iStep++) { // 4
180 if (iStep > 0) {
181 for (unsigned int i = 0; i < 5; i++) {
182 if (i != 3) {
183 x[i] = x0[i] + coef[iStep] * k[i][iStep - 1];
184 }
185 }
186 }
187
188 k[0][iStep] = x[2] * h;
189 k[1][iStep] = x[3] * h;
190 k[2][iStep] = (dAx_dtx[iStep] * x[2] + dAx_dty[iStep] * x[3]) * hCqp;
191 //k[3][iStep] = (dAy_dtx[iStep] * x[2] + dAy_dty[iStep] * x[3]) * hCqp;
192 k[4][iStep] = (fTx[iStep] * x[2] + fTy[iStep] * x[3]) * h / CbmLitTrackParam::fSpeedOfLight / fT1;
193 } // 4
194
195 derivs[3] = CalcOut(x0[0], k[0]);
196 derivs[9] = CalcOut(x0[1], k[1]);
197 derivs[15] = CalcOut(x0[2], k[2]);
198 derivs[21] = 1.;
199 derivs[27] = 0.;
200 derivs[33] = CalcOut(x0[4], k[4]);
201 // end of derivatives dx/dty
202
203 // Derivatives dx/dqp
204 x[0] = x0[0] = 0.0;
205 x[1] = x0[1] = 0.0;
206 x[2] = x0[2] = 0.0;
207 x[3] = x0[3] = 0.0;
208 x[4] = x0[4] = 0.0;
209 for (unsigned int iStep = 0; iStep < 4; iStep++) { // 4
210 if (iStep > 0) {
211 for (unsigned int i = 0; i < 5; i++) {
212 x[i] = x0[i] + coef[iStep] * k[i][iStep - 1];
213 }
214 }
215
216 k[0][iStep] = x[2] * h;
217 k[1][iStep] = x[3] * h;
218 k[2][iStep] = Ax[iStep] * hC + hCqp * (dAx_dtx[iStep] * x[2] + dAx_dty[iStep] * x[3]);
219 k[3][iStep] = Ay[iStep] * hC + hCqp * (dAy_dtx[iStep] * x[2] + dAy_dty[iStep] * x[3]);
220 k[4][iStep] = (fTx[iStep] * x[2] + fTy[iStep] * x[3]) * h / CbmLitTrackParam::fSpeedOfLight / fT1;
221 } // 4
222
223 derivs[4] = CalcOut(x0[0], k[0]);
224 derivs[10] = CalcOut(x0[1], k[1]);
225 derivs[16] = CalcOut(x0[2], k[2]);
226 derivs[22] = CalcOut(x0[3], k[3]);
227 derivs[28] = 1.;
228 derivs[34] = CalcOut(x0[4], k[4]);
229 // end of derivatives dx/dqp
230
231 // end calculation of the derivatives
232}
233
235{
236 return in + k[0] / 6. + k[1] / 3. + k[2] / 3. + k[3] / 6.;
237}
238
239static void MultiplyMatrices(const std::vector<litfloat>& lm, const std::vector<litfloat>& rm,
240 std::vector<litfloat>& res)
241{
242 for (int i = 0; i < 6; ++i) {
243 for (int j = 0; j < 6; ++j) {
244 litfloat& r = res[6 * i + j];
245 r = 0;
246
247 for (int k = 0; k < 6; ++k)
248 r += lm[6 * i + k] * rm[j + 6 * k];
249 }
250 }
251}
252
253static void TransposeMatrix(const std::vector<litfloat>& m, std::vector<litfloat>& res)
254{
255 for (int i = 0; i < 6; ++i) {
256 for (int j = 0; j < 6; ++j)
257 res[i + 6 * j] = m[6 * i + j];
258 }
259}
260
261void CbmLitRK4TrackExtrapolator::TransportC(const std::vector<litfloat>& cIn, const std::vector<litfloat>& F,
262 std::vector<litfloat>& cOut) const
263{
264 // F*C*Ft
265 /*litfloat A = cIn[2] + F[2] * cIn[9] + F[3] * cIn[10] + F[4] * cIn[11];
266 litfloat B = cIn[3] + F[2] * cIn[10] + F[3] * cIn[12] + F[4] * cIn[13];
267 litfloat C = cIn[4] + F[2] * cIn[11] + F[3] * cIn[13] + F[4] * cIn[14];
268
269 litfloat D = cIn[6] + F[7] * cIn[9] + F[8] * cIn[10] + F[9] * cIn[11];
270 litfloat E = cIn[7] + F[7] * cIn[10] + F[8] * cIn[12] + F[9] * cIn[13];
271 litfloat G = cIn[8] + F[7] * cIn[11] + F[8] * cIn[13] + F[9] * cIn[14];
272
273 litfloat H = cIn[9] + F[13] * cIn[10] + F[14] * cIn[11];
274 litfloat I = cIn[10] + F[13] * cIn[12] + F[14] * cIn[13];
275 litfloat J = cIn[11] + F[13] * cIn[13] + F[14] * cIn[14];
276
277 litfloat K = cIn[13] + F[17] * cIn[11] + F[19] * cIn[14];
278
279 cOut[0] = cIn[0] + F[2] * cIn[2] + F[3] * cIn[3] + F[4] * cIn[4] + A * F[2] + B * F[3] + C * F[4];
280 cOut[1] = cIn[1] + F[2] * cIn[6] + F[3] * cIn[7] + F[4] * cIn[8] + A * F[7] + B * F[8] + C * F[9];
281 cOut[2] = A + B * F[13] + C * F[14];
282 cOut[3] = B + A * F[17] + C * F[19];
283 cOut[4] = C;
284
285 cOut[5] = cIn[5] + F[7] * cIn[6] + F[8] * cIn[7] + F[9] * cIn[8] + D * F[7] + E * F[8] + G * F[9];
286 cOut[6] = D + E * F[13] + G * F[14];
287 cOut[7] = E + D * F[17] + G * F[19];
288 cOut[8] = G;
289
290 cOut[9] = H + I * F[13] + J * F[14];
291 cOut[10] = I + H * F[17] + J * F[19];
292 cOut[11] = J;
293
294 cOut[12] = cIn[12] + F[17] * cIn[10] + F[19] * cIn[13] + (F[17] * cIn[9] + cIn[10] + F[19] * cIn[11]) * F[17] + K * F[19];
295 cOut[13] = K;
296
297 cOut[14] = cIn[14];*/
298 std::vector<litfloat> C(36);
299 int k = 0;
300
301 for (int i = 0; i < 6; ++i) {
302 for (int j = i; j < 6; ++j) {
303 C[6 * i + j] = cIn[k++];
304
305 if (i < j) C[i + 6 * j] = C[6 * i + j];
306 }
307 }
308
309 std::vector<litfloat> tmp(36);
310 MultiplyMatrices(F, C, tmp);
311 std::vector<litfloat> FT(36);
312 TransposeMatrix(F, FT);
313 std::vector<litfloat> tmp2(36);
314 MultiplyMatrices(tmp, FT, tmp2);
315 k = 0;
316
317 for (int i = 0; i < 6; ++i) {
318 for (int j = i; j < 6; ++j)
319 cOut[k++] = tmp2[6 * i + j];
320 }
321}
LitStatus
Definition CbmLitEnums.h:29
@ kLITSUCCESS
Definition CbmLitEnums.h:30
Interface for accessing the magnetic field.
double litfloat
Definition CbmLitFloat.h:19
static void TransposeMatrix(const std::vector< litfloat > &m, std::vector< litfloat > &res)
static void MultiplyMatrices(const std::vector< litfloat > &lm, const std::vector< litfloat > &rm, std::vector< litfloat > &res)
std::shared_ptr< CbmLitField > fField
virtual LitStatus Extrapolate(const CbmLitTrackParam *parIn, CbmLitTrackParam *parOut, litfloat zOut, std::vector< litfloat > *F)
Track parameters extrapolation with calculation of transport matrix.
void RK4Order(const std::vector< litfloat > &xIn, litfloat zIn, std::vector< litfloat > &xOut, litfloat zOut, std::vector< litfloat > &derivs) const
CbmLitRK4TrackExtrapolator(std::shared_ptr< CbmLitField > field)
litfloat CalcOut(litfloat in, const litfloat k[4]) const
void TransportC(const std::vector< litfloat > &cIn, const std::vector< litfloat > &F, std::vector< litfloat > &cOut) const
Data class for track parameters.
litfloat GetZ() const
void SetStateVector(const vector< litfloat > &x)
Set parameters from vector.
static litfloat fSpeedOfLight
vector< litfloat > GetStateVector() const
Return state vector as vector.
void SetZ(litfloat z)
const vector< litfloat > & GetCovMatrix() const
void SetCovMatrix(const vector< litfloat > &C)
Data class with information on a STS local track.