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)
482 const bool propToHit) {
488 for (
int n = 0;
n <
NN; ++
n) {
500 for (
int n = 0;
n <
NN; ++
n) {
501 if (outPar.
At(
n, 3, 0) < 0) {
502 Chg.
At(
n, 0, 0) = -Chg.
At(
n, 0, 0);
503 outPar.
At(
n, 3, 0) = -outPar.
At(
n, 3, 0);
529 const bool propToHit) {
535 for (
int n = 0;
n <
NN; ++
n) {
562 for (
int i = 0;
i < 6; ++
i) {
563 printf(
"%8f ", psPar.
constAt(0, 0,
i));
568 for (
int i = 0;
i < 6; ++
i) {
569 for (
int j = 0;
j < 6; ++
j)
575 for (
int i = 0;
i < 3; ++
i) {
576 printf(
"%8f ", msPar.
constAt(0, 0,
i));
581 for (
int i = 0;
i < 3; ++
i) {
582 for (
int j = 0;
j < 3; ++
j)
601 for (
int n = 0;
n <
NN; ++
n) {
608 SubtractFirst3(msPar, psPar, res_glo);
611 AddIntoUpperLeft3x3(psErr, msErr, resErr_glo);
614 RotateResidualsOnTangentPlane(rotT00, rotT01, res_glo, res_loc);
617 ProjectResErr(rotT00, rotT01, resErr_glo, tempHH);
618 ProjectResErrTransp(rotT00, rotT01, tempHH, resErr_loc);
623 printf(
"resErr_loc:\n");
624 for (
int i = 0;
i < 2; ++
i) {
625 for (
int j = 0;
j < 2; ++
j)
626 printf(
"%8f ", resErr_loc.
At(0,
i,
j));
637 Chi2Similarity(res_loc, resErr_loc, outChi2);
642 printf(
"resErr_loc (Inv):\n");
643 for (
int i = 0;
i < 2; ++
i) {
644 for (
int j = 0;
j < 2; ++
j)
645 printf(
"%8f ", resErr_loc.
At(0,
i,
j));
649 printf(
"chi2: %8f\n", outChi2.
At(0, 0, 0));
657 CovXYconstrain(rotT00, rotT01, psErr, psErrLoc);
660 KalmanHTG(rotT00, rotT01, resErr_loc, tempHH);
661 KalmanGain(psErrLoc, tempHH, K);
663 MultResidualsAdd(K, psPar, res_loc, outPar);
668 KHMult(K, rotT00, rotT01, tempLL);
669 KHC(tempLL, psErrLoc, outErr);
676 printf(
"psErrLoc:\n");
677 for (
int i = 0;
i < 6; ++
i) {
678 for (
int j = 0;
j < 6; ++
j)
679 printf(
"% 8e ", psErrLoc.
At(0,
i,
j));
684 printf(
"res_glo:\n");
685 for (
int i = 0;
i < 3; ++
i) {
686 printf(
"%8f ", res_glo.
At(0,
i, 0));
689 printf(
"res_loc:\n");
690 for (
int i = 0;
i < 2; ++
i) {
691 printf(
"%8f ", res_loc.
At(0,
i, 0));
694 printf(
"resErr_loc (Inv):\n");
695 for (
int i = 0;
i < 2; ++
i) {
696 for (
int j = 0;
j < 2; ++
j)
697 printf(
"%8f ", resErr_loc.
At(0,
i,
j));
702 for (
int i = 0;
i < 6; ++
i) {
703 for (
int j = 0;
j < 3; ++
j)
704 printf(
"%8f ", K.
At(0,
i,
j));
709 for (
int i = 0;
i < 6; ++
i) {
710 printf(
"%8f ", outPar.
At(0,
i, 0));
714 for (
int i = 0;
i < 6; ++
i) {
715 for (
int j = 0;
j < 6; ++
j)
716 printf(
"%8f ", outErr.
At(0,
i,
j));
748 const bool propToHit) {
754 for (
int n = 0;
n <
NN; ++
n) {
764 for (
int n = 0;
n <
NN; ++
n) {
765 if (outPar.
At(
n, 3, 0) < 0) {
766 Chg.
At(
n, 0, 0) = -Chg.
At(
n, 0, 0);
767 outPar.
At(
n, 3, 0) = -outPar.
At(
n, 3, 0);
793 const bool propToHit) {
799 for (
int n = 0;
n <
NN; ++
n) {
825 printf(
"updateParametersEndcapMPlex\n");
827 for (
int i = 0;
i < 6; ++
i) {
828 printf(
"%8f ", psPar.
constAt(0, 0,
i));
833 for (
int i = 0;
i < 3; ++
i) {
834 printf(
"%8f ", msPar.
constAt(0, 0,
i));
839 for (
int i = 0;
i < 6; ++
i) {
840 for (
int j = 0;
j < 6; ++
j)
846 for (
int i = 0;
i < 3; ++
i) {
847 for (
int j = 0;
j < 3; ++
j)
856 SubtractFirst2(msPar, psPar,
res);
859 AddIntoUpperLeft2x2(psErr, msErr, resErr);
865 for (
int i = 0;
i < 2; ++
i) {
866 for (
int j = 0;
j < 2; ++
j)
867 printf(
"%8f ", resErr.
At(0,
i,
j));
878 Chi2Similarity(
res, resErr, outChi2);
883 printf(
"resErr_loc (Inv):\n");
884 for (
int i = 0;
i < 2; ++
i) {
885 for (
int j = 0;
j < 2; ++
j)
886 printf(
"%8f ", resErr.
At(0,
i,
j));
890 printf(
"chi2: %8f\n", outChi2.
At(0, 0, 0));
897 KalmanGain(psErr, resErr, K);
899 MultResidualsAdd(K, psPar,
res, outPar);
903 KHC(K, psErr, outErr);
908 printf(
"outErr before subtract:\n");
909 for (
int i = 0;
i < 6; ++
i) {
910 for (
int j = 0;
j < 6; ++
j)
911 printf(
"%8f ", outErr.
At(0,
i,
j));
924 for (
int i = 0;
i < 2; ++
i) {
925 printf(
"%8f ",
res.At(0,
i, 0));
928 printf(
"resErr (Inv):\n");
929 for (
int i = 0;
i < 2; ++
i) {
930 for (
int j = 0;
j < 2; ++
j)
931 printf(
"%8f ", resErr.
At(0,
i,
j));
936 for (
int i = 0;
i < 6; ++
i) {
937 for (
int j = 0;
j < 2; ++
j)
938 printf(
"%8f ", K.
At(0,
i,
j));
943 for (
int i = 0;
i < 6; ++
i) {
944 printf(
"%8f ", outPar.
At(0,
i, 0));
948 for (
int i = 0;
i < 6; ++
i) {
949 for (
int j = 0;
j < 6; ++
j)
950 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)
__host__ __device__ VT * co
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)