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*
a =
A.fArray;
315 const T*
b =
B.fArray;
320 #include "KalmanGain62.ah" 325 KHMult_imp(
A, B00, B01,
C, 0,
NN);
334 const T*
a =
A.fArray;
336 const T*
b =
B.fArray;
350 const T*
a =
A.fArray;
352 const T*
b =
B.fArray;
361 template <
typename T1,
typename T2,
typename T3>
362 void MultFull(
const T1&
A,
int nia,
int nja,
const T2&
B,
int nib,
int njb, T3&
C,
int nic,
int njc) {
368 for (
int n = 0;
n <
NN; ++
n) {
369 for (
int i = 0;
i < nia; ++
i) {
370 for (
int j = 0;
j < njb; ++
j) {
372 for (
int k = 0;
k < nja; ++
k)
381 template <
typename T1,
typename T2,
typename T3>
382 void MultTranspFull(
const T1&
A,
int nia,
int nja,
const T2&
B,
int nib,
int njb, T3&
C,
int nic,
int njc) {
388 for (
int n = 0;
n <
NN; ++
n) {
389 for (
int i = 0;
i < nia; ++
i) {
390 for (
int j = 0;
j < nib; ++
j) {
392 for (
int k = 0;
k < nja; ++
k)
440 const bool propToHit) {
446 for (
int n = 0;
n <
NN; ++
n) {
456 for (
int n = 0;
n <
NN; ++
n) {
457 if (outPar.
At(
n, 3, 0) < 0) {
458 Chg.
At(
n, 0, 0) = -Chg.
At(
n, 0, 0);
459 outPar.
At(
n, 3, 0) = -outPar.
At(
n, 3, 0);
485 const bool propToHit) {
491 for (
int n = 0;
n <
NN; ++
n) {
518 for (
int i = 0;
i < 6; ++
i) {
519 printf(
"%8f ", psPar.
constAt(0, 0,
i));
524 for (
int i = 0;
i < 6; ++
i) {
525 for (
int j = 0;
j < 6; ++
j)
531 for (
int i = 0;
i < 3; ++
i) {
532 printf(
"%8f ", msPar.
constAt(0, 0,
i));
537 for (
int i = 0;
i < 3; ++
i) {
538 for (
int j = 0;
j < 3; ++
j)
557 for (
int n = 0;
n <
NN; ++
n) {
564 SubtractFirst3(msPar, psPar, res_glo);
567 AddIntoUpperLeft3x3(psErr, msErr, resErr_glo);
570 RotateResidualsOnTangentPlane(rotT00, rotT01, res_glo, res_loc);
573 ProjectResErr(rotT00, rotT01, resErr_glo, tempHH);
574 ProjectResErrTransp(rotT00, rotT01, tempHH, resErr_loc);
579 printf(
"resErr_loc:\n");
580 for (
int i = 0;
i < 2; ++
i) {
581 for (
int j = 0;
j < 2; ++
j)
582 printf(
"%8f ", resErr_loc.
At(0,
i,
j));
593 Chi2Similarity(res_loc, resErr_loc, outChi2);
598 printf(
"resErr_loc (Inv):\n");
599 for (
int i = 0;
i < 2; ++
i) {
600 for (
int j = 0;
j < 2; ++
j)
601 printf(
"%8f ", resErr_loc.
At(0,
i,
j));
605 printf(
"chi2: %8f\n", outChi2.
At(0, 0, 0));
612 KalmanHTG(rotT00, rotT01, resErr_loc, tempHH);
613 KalmanGain(psErr, tempHH, K);
615 MultResidualsAdd(K, psPar, res_loc, outPar);
620 KHMult(K, rotT00, rotT01, tempLL);
621 KHC(tempLL, psErr, outErr);
627 printf(
"res_glo:\n");
628 for (
int i = 0;
i < 3; ++
i) {
629 printf(
"%8f ", res_glo.
At(0,
i, 0));
632 printf(
"res_loc:\n");
633 for (
int i = 0;
i < 2; ++
i) {
634 printf(
"%8f ", res_loc.
At(0,
i, 0));
637 printf(
"resErr_loc (Inv):\n");
638 for (
int i = 0;
i < 2; ++
i) {
639 for (
int j = 0;
j < 2; ++
j)
640 printf(
"%8f ", resErr_loc.
At(0,
i,
j));
645 for (
int i = 0;
i < 6; ++
i) {
646 for (
int j = 0;
j < 3; ++
j)
647 printf(
"%8f ", K.
At(0,
i,
j));
652 for (
int i = 0;
i < 6; ++
i) {
653 printf(
"%8f ", outPar.
At(0,
i, 0));
657 for (
int i = 0;
i < 6; ++
i) {
658 for (
int j = 0;
j < 6; ++
j)
659 printf(
"%8f ", outErr.
At(0,
i,
j));
691 const bool propToHit) {
697 for (
int n = 0;
n <
NN; ++
n) {
707 for (
int n = 0;
n <
NN; ++
n) {
708 if (outPar.
At(
n, 3, 0) < 0) {
709 Chg.
At(
n, 0, 0) = -Chg.
At(
n, 0, 0);
710 outPar.
At(
n, 3, 0) = -outPar.
At(
n, 3, 0);
736 const bool propToHit) {
742 for (
int n = 0;
n <
NN; ++
n) {
768 printf(
"updateParametersEndcapMPlex\n");
770 for (
int i = 0;
i < 6; ++
i) {
771 printf(
"%8f ", psPar.
constAt(0, 0,
i));
776 for (
int i = 0;
i < 3; ++
i) {
777 printf(
"%8f ", msPar.
constAt(0, 0,
i));
782 for (
int i = 0;
i < 6; ++
i) {
783 for (
int j = 0;
j < 6; ++
j)
789 for (
int i = 0;
i < 3; ++
i) {
790 for (
int j = 0;
j < 3; ++
j)
799 SubtractFirst2(msPar, psPar,
res);
802 AddIntoUpperLeft2x2(psErr, msErr, resErr);
808 for (
int i = 0;
i < 2; ++
i) {
809 for (
int j = 0;
j < 2; ++
j)
810 printf(
"%8f ", resErr.
At(0,
i,
j));
821 Chi2Similarity(
res, resErr, outChi2);
826 printf(
"resErr_loc (Inv):\n");
827 for (
int i = 0;
i < 2; ++
i) {
828 for (
int j = 0;
j < 2; ++
j)
829 printf(
"%8f ", resErr.
At(0,
i,
j));
833 printf(
"chi2: %8f\n", outChi2.
At(0, 0, 0));
840 KalmanGain(psErr, resErr, K);
842 MultResidualsAdd(K, psPar,
res, outPar);
846 KHC(K, psErr, outErr);
851 printf(
"outErr before subtract:\n");
852 for (
int i = 0;
i < 6; ++
i) {
853 for (
int j = 0;
j < 6; ++
j)
854 printf(
"%8f ", outErr.
At(0,
i,
j));
867 for (
int i = 0;
i < 2; ++
i) {
868 printf(
"%8f ",
res.At(0,
i, 0));
871 printf(
"resErr (Inv):\n");
872 for (
int i = 0;
i < 2; ++
i) {
873 for (
int j = 0;
j < 2; ++
j)
874 printf(
"%8f ", resErr.
At(0,
i,
j));
879 for (
int i = 0;
i < 6; ++
i) {
880 for (
int j = 0;
j < 2; ++
j)
881 printf(
"%8f ", K.
At(0,
i,
j));
886 for (
int i = 0;
i < 6; ++
i) {
887 printf(
"%8f ", outPar.
At(0,
i, 0));
891 for (
int i = 0;
i < 6; ++
i) {
892 for (
int j = 0;
j < 6; ++
j)
893 printf(
"%8f ", outErr.
At(0,
i,
j));
void kalmanPropagateAndUpdate(const MPlexLS &psErr, const MPlexLV &psPar, MPlexQI &Chg, const MPlexHS &msErr, const MPlexHV &msPar, MPlexLS &outErr, MPlexLV &outPar, const int N_proc, const PropagationFlags propFlags, const bool propToHit)
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)
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 kalmanPropagateAndComputeChi2Endcap(const MPlexLS &psErr, const MPlexLV &psPar, const MPlexQI &inChg, const MPlexHS &msErr, const MPlexHV &msPar, MPlexQF &outChi2, MPlexLV &propPar, const int N_proc, const PropagationFlags propFlags, const bool propToHit)
void propagateHelixToRMPlex(const MPlexLS &inErr, const MPlexLV &inPar, const MPlexQI &inChg, const MPlexQF &msRad, MPlexLS &outErr, MPlexLV &outPar, const int N_proc, const PropagationFlags pflags, const MPlexQI *noMatEffPtr)
void squashPhiMPlex(MPlexLV &par, 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, const int N_proc, const PropagationFlags propFlags, const bool propToHit)
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)
const T & constAt(idx_t n, idx_t i, idx_t j) const
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, const int N_proc, const PropagationFlags propFlags, const bool propToHit)
void propagateHelixToZMPlex(const MPlexLS &inErr, const MPlexLV &inPar, const MPlexQI &inChg, const MPlexQF &msZ, MPlexLS &outErr, MPlexLV &outPar, const int N_proc, const PropagationFlags pflags, const MPlexQI *noMatEffPtr)
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)