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) {
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) {
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)
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)
603 for (
int n = 0;
n <
NN; ++
n) {
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);
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) {
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) {
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)
850 for (
int i = 0;
i < 3; ++
i) {
851 for (
int j = 0;
j < 3; ++
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));
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));
MatriplexSym & subtract(const MatriplexSym &a, const MatriplexSym &b)
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)
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)
const T & constAt(idx_t n, idx_t i, idx_t j) const
void kalmanUpdate(const MPlexLS &psErr, const MPlexLV &psPar, const MPlexHS &msErr, const MPlexHV &msPar, MPlexLS &outErr, MPlexLV &outPar, const int N_proc)
T & At(idx_t n, idx_t i, idx_t j)
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)
__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 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)
void kalmanComputeChi2Endcap(const MPlexLS &psErr, const MPlexLV &psPar, const MPlexQI &inChg, const MPlexHS &msErr, const MPlexHV &msPar, MPlexQF &outChi2, const int N_proc)
const T & constAt(idx_t n, idx_t i, idx_t j) const
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)
constexpr Matriplex::idx_t NN
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)
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)
DecomposeProduct< arg, typename Div::arg > D
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)
T & At(idx_t n, idx_t i, idx_t j)