7 #include "KalmanUtilsMPlex.icc" 12 using namespace mkfit;
22 MultResidualsAdd_imp(
A,
B,
C,
D, 0,
NN);
35 const T*
a =
A.fArray;
37 const T*
b =
B.fArray;
39 const T*
c =
C.fArray;
47 d[0 *
N +
n] =
b[0 *
N +
n] +
a[0 *
N +
n] *
c[0 *
N +
n] +
a[1 *
N +
n] *
c[1 *
N +
n];
48 d[1 *
N +
n] =
b[1 *
N +
n] +
a[2 *
N +
n] *
c[0 *
N +
n] +
a[3 *
N +
n] *
c[1 *
N +
n];
49 d[2 *
N +
n] =
b[2 *
N +
n] +
a[4 *
N +
n] *
c[0 *
N +
n] +
a[5 *
N +
n] *
c[1 *
N +
n];
50 d[3 *
N +
n] =
b[3 *
N +
n] +
a[6 *
N +
n] *
c[0 *
N +
n] +
a[7 *
N +
n] *
c[1 *
N +
n];
51 d[4 *
N +
n] =
b[4 *
N +
n] +
a[8 *
N +
n] *
c[0 *
N +
n] +
a[9 *
N +
n] *
c[1 *
N +
n];
52 d[5 *
N +
n] =
b[5 *
N +
n] +
a[10 *
N +
n] *
c[0 *
N +
n] +
a[11 *
N +
n] *
c[1 *
N +
n];
58 inline void Chi2Similarity(
const MPlex2V&
A,
68 const T*
a =
A.fArray;
70 const T*
c =
C.fArray;
78 d[0 *
N +
n] =
c[0 *
N +
n] *
a[0 *
N +
n] *
a[0 *
N +
n] +
c[2 *
N +
n] *
a[1 *
N +
n] *
a[1 *
N +
n] +
79 2 * (
c[1 *
N +
n] *
a[1 *
N +
n] *
a[0 *
N +
n]);
91 const T*
a =
A.fArray;
93 const T*
b =
B.fArray;
100 c[0 *
N +
n] =
a[0 *
N +
n] +
b[0 *
N +
n];
101 c[1 *
N +
n] =
a[1 *
N +
n] +
b[1 *
N +
n];
102 c[2 *
N +
n] =
a[2 *
N +
n] +
b[2 *
N +
n];
103 c[3 *
N +
n] =
a[3 *
N +
n] +
b[3 *
N +
n];
104 c[4 *
N +
n] =
a[4 *
N +
n] +
b[4 *
N +
n];
105 c[5 *
N +
n] =
a[5 *
N +
n] +
b[5 *
N +
n];
115 const T*
a =
A.fArray;
117 const T*
b =
B.fArray;
124 c[0 *
N +
n] =
a[0 *
N +
n] +
b[0 *
N +
n];
125 c[1 *
N +
n] =
a[1 *
N +
n] +
b[1 *
N +
n];
126 c[2 *
N +
n] =
a[2 *
N +
n] +
b[2 *
N +
n];
138 const T*
a =
A.fArray;
140 const T*
b =
B.fArray;
147 c[0 *
N +
n] =
a[0 *
N +
n] -
b[0 *
N +
n];
148 c[1 *
N +
n] =
a[1 *
N +
n] -
b[1 *
N +
n];
149 c[2 *
N +
n] =
a[2 *
N +
n] -
b[2 *
N +
n];
159 const T*
a =
A.fArray;
161 const T*
b =
B.fArray;
168 c[0 *
N +
n] =
a[0 *
N +
n] -
b[0 *
N +
n];
169 c[1 *
N +
n] =
a[1 *
N +
n] -
b[1 *
N +
n];
183 const T* a00 = A00.fArray;
185 const T* a01 = A01.fArray;
187 const T*
b =
B.fArray;
193 for (
int n = 0;
n <
N; ++
n) {
194 c[0 *
N +
n] = a00[
n] *
b[0 *
N +
n] + a01[
n] *
b[1 *
N +
n];
195 c[1 *
N +
n] = a00[
n] *
b[1 *
N +
n] + a01[
n] *
b[2 *
N +
n];
196 c[2 *
N +
n] = a00[
n] *
b[3 *
N +
n] + a01[
n] *
b[4 *
N +
n];
197 c[3 *
N +
n] =
b[3 *
N +
n];
198 c[4 *
N +
n] =
b[4 *
N +
n];
199 c[5 *
N +
n] =
b[5 *
N +
n];
200 c[6 *
N +
n] = a01[
n] *
b[0 *
N +
n] - a00[
n] *
b[1 *
N +
n];
201 c[7 *
N +
n] = a01[
n] *
b[1 *
N +
n] - a00[
n] *
b[2 *
N +
n];
202 c[8 *
N +
n] = a01[
n] *
b[3 *
N +
n] - a00[
n] *
b[4 *
N +
n];
214 const T* a00 = A00.fArray;
216 const T* a01 = A01.fArray;
218 const T*
b =
B.fArray;
224 for (
int n = 0;
n <
N; ++
n) {
225 c[0 *
N +
n] =
b[0 *
N +
n] * a00[
n] +
b[1 *
N +
n] * a01[
n];
226 c[1 *
N +
n] =
b[3 *
N +
n] * a00[
n] +
b[4 *
N +
n] * a01[
n];
227 c[2 *
N +
n] =
b[5 *
N +
n];
231 inline void RotateResidualsOnTangentPlane(
const MPlexQF& R00,
236 RotateResidualsOnTangentPlane_impl(R00, R01,
A,
B, 0,
NN);
248 const T* a00 = A00.fArray;
250 const T* a01 = A01.fArray;
252 const T*
b =
B.fArray;
258 for (
int n = 0;
n <
N; ++
n) {
259 c[0 *
N +
n] = a00[
n] *
b[0 *
N +
n];
260 c[1 *
N +
n] = a00[
n] *
b[1 *
N +
n];
262 c[3 *
N +
n] = a01[
n] *
b[0 *
N +
n];
263 c[4 *
N +
n] = a01[
n] *
b[1 *
N +
n];
265 c[6 *
N +
n] =
b[1 *
N +
n];
266 c[7 *
N +
n] =
b[2 *
N +
n];
277 const T*
a =
A.fArray;
279 const T*
b =
B.fArray;
285 for (
int n = 0;
n <
N; ++
n) {
286 c[0 *
N +
n] =
a[0 *
N +
n] *
b[0 *
N +
n] +
a[1 *
N +
n] *
b[3 *
N +
n] +
a[3 *
N +
n] *
b[6 *
N +
n];
287 c[1 *
N +
n] =
a[0 *
N +
n] *
b[1 *
N +
n] +
a[1 *
N +
n] *
b[4 *
N +
n] +
a[3 *
N +
n] *
b[7 *
N +
n];
289 c[3 *
N +
n] =
a[1 *
N +
n] *
b[0 *
N +
n] +
a[2 *
N +
n] *
b[3 *
N +
n] +
a[4 *
N +
n] *
b[6 *
N +
n];
290 c[4 *
N +
n] =
a[1 *
N +
n] *
b[1 *
N +
n] +
a[2 *
N +
n] *
b[4 *
N +
n] +
a[4 *
N +
n] *
b[7 *
N +
n];
292 c[6 *
N +
n] =
a[3 *
N +
n] *
b[0 *
N +
n] +
a[4 *
N +
n] *
b[3 *
N +
n] +
a[5 *
N +
n] *
b[6 *
N +
n];
293 c[7 *
N +
n] =
a[3 *
N +
n] *
b[1 *
N +
n] +
a[4 *
N +
n] *
b[4 *
N +
n] +
a[5 *
N +
n] *
b[7 *
N +
n];
295 c[9 *
N +
n] =
a[6 *
N +
n] *
b[0 *
N +
n] +
a[7 *
N +
n] *
b[3 *
N +
n] +
a[8 *
N +
n] *
b[6 *
N +
n];
296 c[10 *
N +
n] =
a[6 *
N +
n] *
b[1 *
N +
n] +
a[7 *
N +
n] *
b[4 *
N +
n] +
a[8 *
N +
n] *
b[7 *
N +
n];
298 c[12 *
N +
n] =
a[10 *
N +
n] *
b[0 *
N +
n] +
a[11 *
N +
n] *
b[3 *
N +
n] +
a[12 *
N +
n] *
b[6 *
N +
n];
299 c[13 *
N +
n] =
a[10 *
N +
n] *
b[1 *
N +
n] +
a[11 *
N +
n] *
b[4 *
N +
n] +
a[12 *
N +
n] *
b[7 *
N +
n];
301 c[15 *
N +
n] =
a[15 *
N +
n] *
b[0 *
N +
n] +
a[16 *
N +
n] *
b[3 *
N +
n] +
a[17 *
N +
n] *
b[6 *
N +
n];
302 c[16 *
N +
n] =
a[15 *
N +
n] *
b[1 *
N +
n] +
a[16 *
N +
n] *
b[4 *
N +
n] +
a[17 *
N +
n] *
b[7 *
N +
n];
313 const T* r00 =
R00.fArray;
315 const T* r01 = R01.fArray;
317 const T* ci = Ci.fArray;
323 for (
int n = 0;
n <
N; ++
n) {
326 r00[
n] * r00[
n] * ci[0 *
N +
n] + 2 * r00[
n] * r01[
n] * ci[1 *
N +
n] + r01[
n] * r01[
n] * ci[2 *
N +
n];
327 co[1 *
N +
n] = r00[
n] * r01[
n] *
co[0 *
N +
n];
328 co[2 *
N +
n] = r01[
n] * r01[
n] *
co[0 *
N +
n];
329 co[0 *
N +
n] = r00[
n] * r00[
n] *
co[0 *
N +
n];
331 co[3 *
N +
n] = r00[
n] * ci[3 *
N +
n] + r01[
n] * ci[4 *
N +
n];
335 co[6 *
N +
n] = r00[
n] * ci[6 *
N +
n] + r01[
n] * ci[7 *
N +
n];
339 co[10 *
N +
n] = r00[
n] * ci[10 *
N +
n] + r01[
n] * ci[11 *
N +
n];
340 co[11 *
N +
n] = r01[
n] *
co[10 *
N +
n];
341 co[10 *
N +
n] = r00[
n] *
co[10 *
N +
n];
343 co[15 *
N +
n] = r00[
n] * ci[15 *
N +
n] + r01[
n] * ci[16 *
N +
n];
344 co[16 *
N +
n] = r01[
n] *
co[15 *
N +
n];
345 co[15 *
N +
n] = r00[
n] *
co[15 *
N +
n];
355 const T*
a =
A.fArray;
357 const T*
b =
B.fArray;
362 #include "KalmanGain62.ah" 367 KHMult_imp(
A, B00, B01,
C, 0,
NN);
376 const T*
a =
A.fArray;
378 const T*
b =
B.fArray;
392 const T*
a =
A.fArray;
394 const T*
b =
B.fArray;
403 template <
typename T1,
typename T2,
typename T3>
404 void MultFull(
const T1&
A,
int nia,
int nja,
const T2&
B,
int nib,
int njb, T3&
C,
int nic,
int njc) {
410 for (
int n = 0;
n <
NN; ++
n) {
411 for (
int i = 0;
i < nia; ++
i) {
412 for (
int j = 0;
j < njb; ++
j) {
414 for (
int k = 0;
k < nja; ++
k)
423 template <
typename T1,
typename T2,
typename T3>
424 void MultTranspFull(
const T1&
A,
int nia,
int nja,
const T2&
B,
int nib,
int njb, T3&
C,
int nic,
int njc) {
430 for (
int n = 0;
n <
NN; ++
n) {
431 for (
int i = 0;
i < nia; ++
i) {
432 for (
int j = 0;
j < nib; ++
j) {
434 for (
int k = 0;
k < nja; ++
k)
483 const bool propToHit) {
489 for (
int n = 0;
n <
NN; ++
n) {
490 msRad.At(
n, 0, 0) =
std::hypot(msPar.constAt(
n, 0, 0), msPar.constAt(
n, 1, 0));
501 for (
int n = 0;
n <
NN; ++
n) {
502 if (outPar.At(
n, 3, 0) < 0) {
503 Chg.At(
n, 0, 0) = -Chg.At(
n, 0, 0);
504 outPar.At(
n, 3, 0) = -outPar.At(
n, 3, 0);
531 const bool propToHit) {
537 for (
int n = 0;
n <
NN; ++
n) {
538 msRad.At(
n, 0, 0) =
std::hypot(msPar.constAt(
n, 0, 0), msPar.constAt(
n, 1, 0));
564 for (
int i = 0;
i < 6; ++
i) {
565 printf(
"%8f ", psPar.constAt(0, 0,
i));
570 for (
int i = 0;
i < 6; ++
i) {
571 for (
int j = 0;
j < 6; ++
j)
572 printf(
"%8f ", psErr.constAt(0,
i,
j));
577 for (
int i = 0;
i < 3; ++
i) {
578 printf(
"%8f ", msPar.constAt(0, 0,
i));
583 for (
int i = 0;
i < 3; ++
i) {
584 for (
int j = 0;
j < 3; ++
j)
585 printf(
"%8f ", msErr.constAt(0,
i,
j));
603 for (
int n = 0;
n <
NN; ++
n) {
604 const float r =
std::hypot(msPar.constAt(
n, 0, 0), msPar.constAt(
n, 1, 0));
605 rotT00.At(
n, 0, 0) = -(msPar.constAt(
n, 1, 0) + psPar.constAt(
n, 1, 0)) / (2 * r);
606 rotT01.At(
n, 0, 0) = (msPar.constAt(
n, 0, 0) + psPar.constAt(
n, 0, 0)) / (2 * r);
610 SubtractFirst3(msPar, psPar, res_glo);
613 AddIntoUpperLeft3x3(psErr, msErr, resErr_glo);
616 RotateResidualsOnTangentPlane(rotT00, rotT01, res_glo, res_loc);
619 ProjectResErr(rotT00, rotT01, resErr_glo, tempHH);
620 ProjectResErrTransp(rotT00, rotT01, tempHH, resErr_loc);
625 printf(
"resErr_loc:\n");
626 for (
int i = 0;
i < 2; ++
i) {
627 for (
int j = 0;
j < 2; ++
j)
628 printf(
"%8f ", resErr_loc.At(0,
i,
j));
639 Chi2Similarity(res_loc, resErr_loc, outChi2);
644 printf(
"resErr_loc (Inv):\n");
645 for (
int i = 0;
i < 2; ++
i) {
646 for (
int j = 0;
j < 2; ++
j)
647 printf(
"%8f ", resErr_loc.At(0,
i,
j));
651 printf(
"chi2: %8f\n", outChi2.At(0, 0, 0));
659 CovXYconstrain(rotT00, rotT01, psErr, psErrLoc);
662 KalmanHTG(rotT00, rotT01, resErr_loc, tempHH);
663 KalmanGain(psErrLoc, tempHH, K);
665 MultResidualsAdd(K, psPar, res_loc, outPar);
670 KHMult(K, rotT00, rotT01, tempLL);
671 KHC(tempLL, psErrLoc, outErr);
672 outErr.subtract(psErrLoc, outErr);
678 printf(
"psErrLoc:\n");
679 for (
int i = 0;
i < 6; ++
i) {
680 for (
int j = 0;
j < 6; ++
j)
681 printf(
"% 8e ", psErrLoc.At(0,
i,
j));
686 printf(
"res_glo:\n");
687 for (
int i = 0;
i < 3; ++
i) {
688 printf(
"%8f ", res_glo.At(0,
i, 0));
691 printf(
"res_loc:\n");
692 for (
int i = 0;
i < 2; ++
i) {
693 printf(
"%8f ", res_loc.At(0,
i, 0));
696 printf(
"resErr_loc (Inv):\n");
697 for (
int i = 0;
i < 2; ++
i) {
698 for (
int j = 0;
j < 2; ++
j)
699 printf(
"%8f ", resErr_loc.At(0,
i,
j));
704 for (
int i = 0;
i < 6; ++
i) {
705 for (
int j = 0;
j < 3; ++
j)
706 printf(
"%8f ", K.At(0,
i,
j));
711 for (
int i = 0;
i < 6; ++
i) {
712 printf(
"%8f ", outPar.At(0,
i, 0));
716 for (
int i = 0;
i < 6; ++
i) {
717 for (
int j = 0;
j < 6; ++
j)
718 printf(
"%8f ", outErr.At(0,
i,
j));
751 const bool propToHit) {
757 for (
int n = 0;
n <
NN; ++
n) {
758 msZ.At(
n, 0, 0) = msPar.constAt(
n, 2, 0);
767 for (
int n = 0;
n <
NN; ++
n) {
768 if (outPar.At(
n, 3, 0) < 0) {
769 Chg.At(
n, 0, 0) = -Chg.At(
n, 0, 0);
770 outPar.At(
n, 3, 0) = -outPar.At(
n, 3, 0);
797 const bool propToHit) {
803 for (
int n = 0;
n <
NN; ++
n) {
804 msZ.At(
n, 0, 0) = msPar.constAt(
n, 2, 0);
829 printf(
"updateParametersEndcapMPlex\n");
831 for (
int i = 0;
i < 6; ++
i) {
832 printf(
"%8f ", psPar.constAt(0, 0,
i));
837 for (
int i = 0;
i < 3; ++
i) {
838 printf(
"%8f ", msPar.constAt(0, 0,
i));
843 for (
int i = 0;
i < 6; ++
i) {
844 for (
int j = 0;
j < 6; ++
j)
845 printf(
"%8f ", psErr.constAt(0,
i,
j));
850 for (
int i = 0;
i < 3; ++
i) {
851 for (
int j = 0;
j < 3; ++
j)
852 printf(
"%8f ", msErr.constAt(0,
i,
j));
860 SubtractFirst2(msPar, psPar,
res);
863 AddIntoUpperLeft2x2(psErr, msErr, resErr);
869 for (
int i = 0;
i < 2; ++
i) {
870 for (
int j = 0;
j < 2; ++
j)
871 printf(
"%8f ", resErr.At(0,
i,
j));
882 Chi2Similarity(
res, resErr, outChi2);
887 printf(
"resErr_loc (Inv):\n");
888 for (
int i = 0;
i < 2; ++
i) {
889 for (
int j = 0;
j < 2; ++
j)
890 printf(
"%8f ", resErr.At(0,
i,
j));
894 printf(
"chi2: %8f\n", outChi2.At(0, 0, 0));
901 KalmanGain(psErr, resErr, K);
903 MultResidualsAdd(K, psPar,
res, outPar);
907 KHC(K, psErr, outErr);
912 printf(
"outErr before subtract:\n");
913 for (
int i = 0;
i < 6; ++
i) {
914 for (
int j = 0;
j < 6; ++
j)
915 printf(
"%8f ", outErr.At(0,
i,
j));
922 outErr.subtract(psErr, outErr);
928 for (
int i = 0;
i < 2; ++
i) {
929 printf(
"%8f ",
res.At(0,
i, 0));
932 printf(
"resErr (Inv):\n");
933 for (
int i = 0;
i < 2; ++
i) {
934 for (
int j = 0;
j < 2; ++
j)
935 printf(
"%8f ", resErr.At(0,
i,
j));
940 for (
int i = 0;
i < 6; ++
i) {
941 for (
int j = 0;
j < 2; ++
j)
942 printf(
"%8f ", K.At(0,
i,
j));
947 for (
int i = 0;
i < 6; ++
i) {
948 printf(
"%8f ", outPar.At(0,
i, 0));
952 for (
int i = 0;
i < 6; ++
i) {
953 for (
int j = 0;
j < 6; ++
j)
954 printf(
"%8f ", outErr.At(0,
i,
j));
Matriplex::Matriplex< float, HH, HH, NN > MPlexHH
Matriplex::Matriplex< float, LL, LL, NN > MPlexLL
MPlex< T, D1, D2, N > hypot(const MPlex< T, D1, D2, N > &a, const MPlex< T, D1, D2, N > &b)
void propagateHelixToRMPlex(const MPlexLS &inErr, const MPlexLV &inPar, const MPlexQI &inChg, const MPlexQF &msRad, MPlexLS &outErr, MPlexLV &outPar, MPlexQI &outFailFlag, const int N_proc, const PropagationFlags &pflags, const MPlexQI *noMatEffPtr)
void kalmanOperationEndcap(const int kfOp, const MPlexLS &psErr, const MPlexLV &psPar, const MPlexHS &msErr, const MPlexHV &msPar, MPlexLS &outErr, MPlexLV &outPar, MPlexQF &outChi2, const int N_proc)
Matriplex::Matriplex< float, HH, 1, NN > MPlexHV
void kalmanUpdate(const MPlexLS &psErr, const MPlexLV &psPar, const MPlexHS &msErr, const MPlexHV &msPar, MPlexLS &outErr, MPlexLV &outPar, const int N_proc)
Matriplex::Matriplex< float, LL, 2, NN > MPlexL2
Matriplex::Matriplex< float, LL, 1, NN > MPlexLV
void kalmanPropagateAndUpdate(const MPlexLS &psErr, const MPlexLV &psPar, MPlexQI &Chg, const MPlexHS &msErr, const MPlexHV &msPar, MPlexLS &outErr, MPlexLV &outPar, MPlexQI &outFailFlag, const int N_proc, const PropagationFlags &propFlags, const bool propToHit)
__host__ __device__ VT * co
void squashPhiMPlex(MPlexLV &par, const int N_proc)
void kalmanOperation(const int kfOp, const MPlexLS &psErr, const MPlexLV &psPar, const MPlexHS &msErr, const MPlexHV &msPar, MPlexLS &outErr, MPlexLV &outPar, MPlexQF &outChi2, const int N_proc)
void invertCramerSym(MPlexSym< T, D, N > &A, double *determ=nullptr)
void kalmanUpdateEndcap(const MPlexLS &psErr, const MPlexLV &psPar, const MPlexHS &msErr, const MPlexHV &msPar, MPlexLS &outErr, MPlexLV &outPar, const int N_proc)
void kalmanComputeChi2Endcap(const MPlexLS &psErr, const MPlexLV &psPar, const MPlexQI &inChg, const MPlexHS &msErr, const MPlexHV &msPar, MPlexQF &outChi2, const int N_proc)
constexpr Matriplex::idx_t NN
void kalmanPropagateAndUpdateEndcap(const MPlexLS &psErr, const MPlexLV &psPar, MPlexQI &Chg, const MPlexHS &msErr, const MPlexHV &msPar, MPlexLS &outErr, MPlexLV &outPar, MPlexQI &outFailFlag, const int N_proc, const PropagationFlags &propFlags, const bool propToHit)
void kalmanPropagateAndComputeChi2(const MPlexLS &psErr, const MPlexLV &psPar, const MPlexQI &inChg, const MPlexHS &msErr, const MPlexHV &msPar, MPlexQF &outChi2, MPlexLV &propPar, MPlexQI &outFailFlag, const int N_proc, const PropagationFlags &propFlags, const bool propToHit)
Matriplex::Matriplex< int, 1, 1, NN > MPlexQI
void kalmanPropagateAndComputeChi2Endcap(const MPlexLS &psErr, const MPlexLV &psPar, const MPlexQI &inChg, const MPlexHS &msErr, const MPlexHV &msPar, MPlexQF &outChi2, MPlexLV &propPar, MPlexQI &outFailFlag, const int N_proc, const PropagationFlags &propFlags, const bool propToHit)
Matriplex::Matriplex< float, 1, 1, NN > MPlexQF
DecomposeProduct< arg, typename Div::arg > D
Matriplex::MatriplexSym< float, 2, NN > MPlex2S
Matriplex::MatriplexSym< float, HH, NN > MPlexHS
Matriplex::Matriplex< float, LL, HH, NN > MPlexLH
Matriplex::Matriplex< float, 2, 1, NN > MPlex2V
void propagateHelixToZMPlex(const MPlexLS &inErr, const MPlexLV &inPar, const MPlexQI &inChg, const MPlexQF &msZ, MPlexLS &outErr, MPlexLV &outPar, MPlexQI &outFailFlag, const int N_proc, const PropagationFlags &pflags, const MPlexQI *noMatEffPtr)
Matriplex::MatriplexSym< float, LL, NN > MPlexLS
void kalmanComputeChi2(const MPlexLS &psErr, const MPlexLV &psPar, const MPlexQI &inChg, const MPlexHS &msErr, const MPlexHV &msPar, MPlexQF &outChi2, const int N_proc)
#define ASSUME_ALIGNED(a, b)