Project
Loading...
Searching...
No Matches
TrackFit.h
Go to the documentation of this file.
1// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_ITS3_ALIGN_TRACKFIT
13#define O2_ITS3_ALIGN_TRACKFIT
14
15#include <Eigen/Dense>
16
22
23namespace o2::its3::align
24{
25using Mat51 = Eigen::Matrix<double, 5, 1>;
26using Mat55 = Eigen::Matrix<double, 5, 5>;
28
29template <typename T>
30struct TrackingCluster : public o2::BaseCluster<T> {
32 T alpha{};
33};
34
35template <typename T, typename F>
37{
38 if constexpr (std::is_same_v<T, F>) {
39 return trk;
40 }
42 dst.setX(trk.getX());
43 dst.setAlpha(trk.getAlpha());
44 for (int iPar{0}; iPar < track::kNParams; ++iPar) {
45 dst.setParam(trk.getParam(iPar), iPar);
46 }
47 dst.setAbsCharge(trk.getAbsCharge());
48 dst.setPID(trk.getPID());
49 dst.setUserField(trk.getUserField());
50 for (int iCov{0}; iCov < track::kCovMatSize; ++iCov) {
51 dst.setCov(trk.getCov()[iCov], iCov);
52 }
53 return dst;
54}
55
56// Both tracks must be at the same (alpha, x).
57// Returns the interpolated track.
58template <typename T>
62{
63 auto res = tA;
64 if (!tA.isValid() || !tB.isValid() || tA.getAlpha() != tB.getAlpha() || tA.getX() != tB.getX()) {
65 res.invalidate();
66 return res;
67 }
68 auto unpack = [](const std::array<T, track::kCovMatSize>& c) {
69 Mat55 m;
70 for (int i = 0, k = 0; i < 5; ++i) {
71 for (int j = 0; j <= i; ++j, ++k) {
72 m(i, j) = m(j, i) = (double)c[k];
73 }
74 }
75 return m;
76 };
77 Mat55 cA = unpack(tA.getCov());
78 Mat55 cB = unpack(tB.getCov());
79 Eigen::LLT<Mat55> lltA(cA), lltB(cB);
80 Mat55 wA = lltA.solve(Mat55::Identity());
81 Mat55 wB = lltB.solve(Mat55::Identity());
82 Mat55 wTot = wA + wB;
83 Eigen::LLT<Mat55> lltTot(wTot);
84 Mat55 cTot = lltTot.solve(Mat55::Identity());
85 Mat51 pA, pB;
86 for (int i = 0; i < 5; ++i) {
87 pA(i) = tA.getParam(i);
88 pB(i) = tB.getParam(i);
89 }
90 Mat51 pTot = cTot * (wA * pA + wB * pB);
91 // build result - same alpha/x as inputs
92 for (int i = 0; i < 5; ++i) {
93 res.setParam(pTot(i), i);
94 }
95 for (int i = 0, k = 0; i < 5; ++i) {
96 for (int j = 0; j <= i; ++j, ++k) {
97 res.setCov(static_cast<T>(cTot(i, j)), k);
98 }
99 }
100 return res;
101}
102
103// Performs an outward (0->7) and inward (7->0) Kalman refit storing the
104// extrapolation *before* the cluster update at each layer.
105// cluster array clArr[0] = PV (optional), clArr[1..7] = layers 0-6.
106// chi2 is accumulated only for the outward direction
107template <typename T>
109 const o2::its::TrackITS& iTrack,
110 std::array<const TrackingCluster<T>*, 8>& clArr,
111 std::array<o2::track::TrackParametrizationWithError<T>, 8>& extrapOut,
112 std::array<o2::track::TrackParametrizationWithError<T>, 8>& extrapInw,
113 T& chi2,
114 bool useStableRef,
116{
117 const auto prop = o2::base::PropagatorImpl<T>::Instance();
118 const auto geom = o2::its::GeometryTGeo::Instance();
119 const auto bz = prop->getNominalBz();
120
122 return refLin ? tr.rotate(alpha, *refLin, bz) : tr.rotate(alpha);
123 };
124 auto accountCluster = [&](int i, std::array<o2::track::TrackParametrizationWithError<T>, 8>& extrapDest, o2::track::TrackParametrizationWithError<T>& tr, o2::track::TrackParametrization<T>* refLin) -> int {
125 if (clArr[i]) {
126 bool outward = tr.getX() < clArr[i]->getX();
127 if (!rotateTrack(tr, clArr[i]->alpha, refLin) || !prop->propagateTo(tr, refLin, clArr[i]->getX(), false, base::PropagatorImpl<T>::MAX_SIN_PHI, base::PropagatorImpl<T>::MAX_STEP, corrType)) {
128 return 0;
129 }
130 if (outward) {
131 chi2 += tr.getPredictedChi2Quiet(*clArr[i]);
132 }
133 extrapDest[i] = tr; // before update
134 if (!tr.update(*clArr[i])) {
135 return 0;
136 }
137 } else {
138 extrapDest[i].invalidate();
139 return -1;
140 }
141 return 1;
142 };
143 auto trFitInw = convertTrack<T>(iTrack.getParamOut());
144 auto trFitOut = convertTrack<T>(iTrack.getParamIn());
145 if (clArr[0]) { // propagate outward seed to PV cluster's tracking frame
146 if (!trFitOut.rotate(clArr[0]->alpha) || !prop->propagateToX(trFitOut, clArr[0]->getX(), bz, base::PropagatorImpl<T>::MAX_SIN_PHI, base::PropagatorImpl<T>::MAX_STEP, corrType)) {
147 return false;
148 }
149 }
150 // linearization references
151 o2::track::TrackParametrization<T> refLinInw0, refLinOut0, *refLinOut = nullptr, *refLinInw = nullptr;
152 if (useStableRef) {
153 refLinOut = &(refLinOut0 = trFitOut);
154 refLinInw = &(refLinInw0 = trFitInw);
155 }
156
157 auto resetTrackCov = [bz](auto& trk) {
158 trk.resetCovariance();
159 float qptB5Scale = std::abs(bz) > 0.1f ? std::abs(bz) / 5.006680f : 1.f;
160 float q2pt2 = trk.getQ2Pt() * trk.getQ2Pt(), q2pt2Wgh = q2pt2 * qptB5Scale * qptB5Scale;
161 float err2 = (100.f + q2pt2Wgh) / (1.f + q2pt2Wgh) * q2pt2; // -> 100 for high pTs, -> 1 for low pTs.
162 trk.setCov(err2, 14); // 100% error
163 };
164 resetTrackCov(trFitOut);
165 resetTrackCov(trFitInw);
166
167 for (int i = 0; i <= 7; i++) {
168 if (!accountCluster(i, extrapOut, trFitOut, refLinOut) || !accountCluster(7 - i, extrapInw, trFitInw, refLinInw)) {
169 return false;
170 }
171 }
172 return true;
173}
174
175} // namespace o2::its3::align
176
177#endif
Wrapper container for different reconstructed object types.
Base track model for the Barrel, params only, w/o covariance.
int32_t i
Definition of the GeometryTGeo class.
uint32_t j
Definition RawData.h:0
uint32_t res
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
Definition of the ITS track.
BaseCluster()=default
GPUd() value_type estimateLTFast(o2 static GPUd() float estimateLTIncrement(const o2 PropagatorImpl * Instance(bool uninitialized=false)
Definition Propagator.h:178
static GeometryTGeo * Instance()
GLfloat GLfloat GLfloat alpha
Definition glcorearb.h:279
const GLfloat * m
Definition glcorearb.h:4066
GLenum GLenum dst
Definition glcorearb.h:1767
o2::track::TrackParCovD TrackD
Definition TrackFit.h:27
bool doBidirRefit(const o2::its::TrackITS &iTrack, std::array< const TrackingCluster< T > *, 8 > &clArr, std::array< o2::track::TrackParametrizationWithError< T >, 8 > &extrapOut, std::array< o2::track::TrackParametrizationWithError< T >, 8 > &extrapInw, T &chi2, bool useStableRef, typename o2::base::PropagatorImpl< T >::MatCorrType corrType)
Definition TrackFit.h:108
Eigen::Matrix< double, 5, 5 > Mat55
Definition TrackFit.h:26
o2::track::TrackParametrizationWithError< T > interpolateTrackParCov(const o2::track::TrackParametrizationWithError< T > &tA, const o2::track::TrackParametrizationWithError< T > &tB)
Definition TrackFit.h:59
Eigen::Matrix< double, 5, 1 > Mat51
Definition TrackFit.h:25
track::TrackParametrizationWithError< T > convertTrack(const track::TrackParametrizationWithError< F > &trk)
Definition TrackFit.h:36
constexpr int kCovMatSize
constexpr int kNParams
TrackParametrizationWithError< double > TrackParCovD
Definition Track.h:32