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 Mat55 wA = cA.inverse();
80 Mat55 wB = cB.inverse();
81 Mat55 wTot = wA + wB;
82 Mat55 cTot = wTot.inverse();
83 Mat51 pA, pB;
84 for (int i = 0; i < 5; ++i) {
85 pA(i) = tA.getParam(i);
86 pB(i) = tB.getParam(i);
87 }
88 Mat51 pTot = cTot * (wA * pA + wB * pB);
89 // build result - same alpha/x as inputs
90 for (int i = 0; i < 5; ++i) {
91 res.setParam(pTot(i), i);
92 }
93 for (int i = 0, k = 0; i < 5; ++i) {
94 for (int j = 0; j <= i; ++j, ++k) {
95 res.setCov(static_cast<T>(cTot(i, j)), k);
96 }
97 }
98 return res;
99}
100
101// Performs an outward (0->7) and inward (7->0) Kalman refit storing the
102// extrapolation *before* the cluster update at each layer.
103// cluster array clArr[0] = PV (optional), clArr[1..7] = layers 0-6.
104// chi2 is accumulated only for the outward direction
105template <typename T>
107 const o2::its::TrackITS& iTrack,
108 std::array<const TrackingCluster<T>*, 8>& clArr,
109 std::array<o2::track::TrackParametrizationWithError<T>, 8>& extrapOut,
110 std::array<o2::track::TrackParametrizationWithError<T>, 8>& extrapInw,
111 T& chi2,
112 bool useStableRef,
114{
115 const auto prop = o2::base::PropagatorImpl<T>::Instance();
116 const auto geom = o2::its::GeometryTGeo::Instance();
117 const auto bz = prop->getNominalBz();
118
120 return refLin ? tr.rotate(alpha, *refLin, bz) : tr.rotate(alpha);
121 };
122 auto accountCluster = [&](int i, std::array<o2::track::TrackParametrizationWithError<T>, 8>& extrapDest, o2::track::TrackParametrizationWithError<T>& tr, o2::track::TrackParametrization<T>* refLin) -> int {
123 if (clArr[i]) {
124 bool outward = tr.getX() < clArr[i]->getX();
125 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)) {
126 return 0;
127 }
128 if (outward) {
129 chi2 += tr.getPredictedChi2Quiet(*clArr[i]);
130 }
131 extrapDest[i] = tr; // before update
132 if (!tr.update(*clArr[i])) {
133 return 0;
134 }
135 } else {
136 extrapDest[i].invalidate();
137 return -1;
138 }
139 return 1;
140 };
141 auto trFitInw = convertTrack<T>(iTrack.getParamOut());
142 auto trFitOut = convertTrack<T>(iTrack.getParamIn());
143 if (clArr[0]) { // propagate outward seed to PV cluster's tracking frame
144 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)) {
145 return false;
146 }
147 }
148 // linearization references
149 o2::track::TrackParametrization<T> refLinInw0, refLinOut0, *refLinOut = nullptr, *refLinInw = nullptr;
150 if (useStableRef) {
151 refLinOut = &(refLinOut0 = trFitOut);
152 refLinInw = &(refLinInw0 = trFitInw);
153 }
154
155 auto resetTrackCov = [bz](auto& trk) {
156 trk.resetCovariance();
157 float qptB5Scale = std::abs(bz) > 0.1f ? std::abs(bz) / 5.006680f : 1.f;
158 float q2pt2 = trk.getQ2Pt() * trk.getQ2Pt(), q2pt2Wgh = q2pt2 * qptB5Scale * qptB5Scale;
159 float err2 = (100.f + q2pt2Wgh) / (1.f + q2pt2Wgh) * q2pt2; // -> 100 for high pTs, -> 1 for low pTs.
160 trk.setCov(err2, 14); // 100% error
161 };
162 resetTrackCov(trFitOut);
163 resetTrackCov(trFitInw);
164
165 for (int i = 0; i <= 7; i++) {
166 if (!accountCluster(i, extrapOut, trFitOut, refLinOut) || !accountCluster(7 - i, extrapInw, trFitInw, refLinInw)) {
167 return false;
168 }
169 }
170 return true;
171}
172
173} // namespace o2::its3::align
174
175#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:106
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