EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KalmanVertexTrackUpdater.ipp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KalmanVertexTrackUpdater.ipp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
13 
14 template <typename input_track_t>
16  const Vertex<input_track_t>& vtx) {
17  const Vector3D vtxPos = vtx.fullPosition().template head<3>();
18 
19  // Get the linearized track
20  const LinearizedTrack& linTrack = track.linearizedState;
21 
22  // Check if linearized state exists
23  if (linTrack.covarianceAtPCA.determinant() == 0.) {
24  // Track has no linearized state, returning w/o update
25  return;
26  }
27 
28  // Retrieve linTrack information
29  const ActsMatrixD<5, 3> posJac = linTrack.positionJacobian.block<5, 3>(0, 0);
30  const ActsMatrixD<5, 3> momJac = linTrack.momentumJacobian.block<5, 3>(0, 0);
31  const ActsVectorD<5> trkParams = linTrack.parametersAtPCA.head<5>();
32  const ActsSymMatrixD<5> trkParamWeight =
33  linTrack.weightAtPCA.block<5, 5>(0, 0);
34 
35  // Calculate S matrix
36  ActsSymMatrixD<3> sMat =
37  (momJac.transpose() * (trkParamWeight * momJac)).inverse();
38 
39  const ActsVectorD<5> residual = linTrack.constantTerm.head<5>();
40 
41  // Refit track momentum
42  Vector3D newTrkMomentum = sMat * momJac.transpose() * trkParamWeight *
43  (trkParams - residual - posJac * vtxPos);
44 
45  // Refit track parameters
46  BoundVector newTrkParams(BoundVector::Zero());
47 
48  // Get phi and theta and correct for possible periodicity changes
49  auto correctedPhiTheta =
50  Acts::detail::ensureThetaBounds(newTrkMomentum(0), newTrkMomentum(1));
51 
52  newTrkParams(BoundIndices::eBoundPhi) = correctedPhiTheta.first; // phi
53  newTrkParams(BoundIndices::eBoundTheta) = correctedPhiTheta.second; // theta
54  newTrkParams(BoundIndices::eBoundQOverP) = newTrkMomentum(2); // qOverP
55 
56  // Vertex covariance and weight matrices
57  const ActsSymMatrixD<3> vtxCov =
58  vtx.fullCovariance().template block<3, 3>(0, 0);
59  const ActsSymMatrixD<3> vtxWeight = vtxCov.inverse();
60 
61  // New track covariance matrix
62  ActsSymMatrixD<3> newTrkCov =
63  -vtxCov * posJac.transpose() * trkParamWeight * momJac * sMat;
64 
66 
67  // Now determine the smoothed chi2 of the track in the following
68  KalmanVertexUpdater::updatePosition<input_track_t>(
69  vtx, linTrack, track.trackWeight, -1, matrixCache);
70 
71  // Corresponding weight matrix
72  const ActsSymMatrixD<3>& reducedVtxWeight = matrixCache.newVertexWeight;
73 
74  // Difference in positions
75  Vector3D posDiff = vtx.position() - matrixCache.newVertexPos;
76 
77  // Get smoothed params
78  ActsVectorD<5> smParams =
79  trkParams - (residual + posJac * vtx.fullPosition().template head<3>() +
80  momJac * newTrkMomentum);
81 
82  // New chi2 to be set later
83  double chi2 = posDiff.dot(reducedVtxWeight * posDiff) +
84  smParams.dot(trkParamWeight * smParams);
85 
86  // Not yet 4d ready. This can be removed together will all head<> statements,
87  // once time is consistently introduced to vertexing
89  newFullTrkCov.block<3, 3>(0, 0) = newTrkCov;
90 
91  SymMatrix4D vtxFullWeight(SymMatrix4D::Zero());
92  vtxFullWeight.block<3, 3>(0, 0) = vtxWeight;
93 
94  SymMatrix4D vtxFullCov(SymMatrix4D::Zero());
95  vtxFullCov.block<3, 3>(0, 0) = vtxCov;
96 
98  sMat, newFullTrkCov, vtxFullWeight, vtxFullCov, newTrkParams);
99 
100  // Create new refitted parameters
101  std::shared_ptr<PerigeeSurface> perigeeSurface =
102  Surface::makeShared<PerigeeSurface>(vtx.position());
103 
104  BoundTrackParameters refittedPerigee = BoundTrackParameters(
105  perigeeSurface, newTrkParams, std::move(fullPerTrackCov));
106 
107  // Set new properties
108  track.fittedParams = refittedPerigee;
109  track.chi2Track = chi2;
110  track.ndf = 2 * track.trackWeight;
111 
112  return;
113 }
114 
115 inline Acts::BoundMatrix
117  const SymMatrix3D& sMat, const ActsMatrixD<4, 3>& newTrkCov,
118  const SymMatrix4D& vtxWeight, const SymMatrix4D& vtxCov,
119  const BoundVector& newTrkParams) {
120  // Now new momentum covariance
121  ActsSymMatrixD<3> momCov =
122  sMat + (newTrkCov.block<3, 3>(0, 0)).transpose() *
123  (vtxWeight.block<3, 3>(0, 0) * newTrkCov.block<3, 3>(0, 0));
124 
125  // Full (x,y,z,phi, theta, q/p) covariance matrix
126  // To be made 7d again after switching to (x,y,z,phi, theta, q/p, t)
128 
129  fullTrkCov.block<3, 3>(0, 0) = vtxCov.block<3, 3>(0, 0);
130  fullTrkCov.block<3, 3>(0, 3) = newTrkCov.block<3, 3>(0, 0);
131  fullTrkCov.block<3, 3>(3, 0) = (newTrkCov.block<3, 3>(0, 0)).transpose();
132  fullTrkCov.block<3, 3>(3, 3) = momCov;
133 
134  // Combined track jacobian
136 
137  // First row
138  trkJac(0, 0) = -std::sin(newTrkParams[2]);
139  trkJac(0, 1) = std::cos(newTrkParams[2]);
140 
141  double tanTheta = std::tan(newTrkParams[3]);
142 
143  // Second row
144  trkJac(1, 0) = -trkJac(0, 1) / tanTheta;
145  trkJac(1, 1) = trkJac(0, 0) / tanTheta;
146 
147  trkJac.block<4, 4>(1, 2) = ActsSymMatrixD<4>::Identity();
148 
149  // Full perigee track covariance
150  BoundMatrix fullPerTrackCov(BoundMatrix::Identity());
151  fullPerTrackCov.block<5, 5>(0, 0) =
152  (trkJac * (fullTrkCov * trkJac.transpose()));
153 
154  return fullPerTrackCov;
155 }