Project
Loading...
Searching...
No Matches
GPUTPCGMTrackParam.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 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
14
15#define GPUCA_CADEBUG 0
16#define DEBUG_SINGLE_TRACK -1
17#define EXTRACT_RESIDUALS 0
18
19#if EXTRACT_RESIDUALS == 1
20#include "GPUROOTDump.h"
21#endif
22
23#include "GPUTPCDef.h"
24#include "GPUTPCGMTrackParam.h"
26#include "GPUTPCGMPropagator.h"
27#include "GPUTPCGMBorderTrack.h"
28#include "GPUTPCGMMergedTrack.h"
30#include "GPUTPCGMMerger.h"
31#include "GPUTPCTracker.h"
32#include "GPUTPCClusterData.h"
33#include "GPUdEdx.h"
34#include "GPUParam.h"
35#include "GPUO2DataTypes.h"
36#include "GPUConstantMem.h"
37#include "TPCFastTransform.h"
39#include "GPUTPCConvertImpl.h"
40#include "GPUTPCGMMergerTypes.h"
41#include "GPUParam.inc"
42#include "GPUGetConstexpr.h"
43
44#ifdef GPUCA_CADEBUG_ENABLED
45#include "../utils/qconfig.h"
47#endif
48
49#ifndef GPUCA_GPUCODE_DEVICE
50#include <cmath>
51#include <cstdlib>
52#endif
53
54using namespace o2::gpu;
55using namespace o2::tpc;
56
57GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger* GPUrestrict() merger, int32_t iTrk, GPUTPCGMMergedTrackHit* GPUrestrict() clusters, GPUTPCGMMergedTrackHitXYZ* GPUrestrict() clustersXYZ, int32_t& GPUrestrict() N, int32_t& GPUrestrict() NTolerated, float& GPUrestrict() Alpha, int32_t attempt, float maxSinPhi, gputpcgmmergertypes::GPUTPCOuterParam* GPUrestrict() outerParam)
58{
59 static constexpr float kDeg2Rad = M_PI / 180.f;
60 CADEBUG(static constexpr float kSectAngle = 2 * M_PI / 18.f);
61
62 const GPUParam& GPUrestrict() param = merger->Param();
63
64 GPUdEdx dEdx, dEdxAlt;
67 prop.SetMaterialTPC();
68 prop.SetPolynomialField(&param.polynomialField);
69 prop.SetMaxSinPhi(maxSinPhi);
70 prop.SetToyMCEventsFlag(param.par.toyMCEventsFlag);
71 if ((clusters[0].sector < 18) == (clusters[N - 1].sector < 18)) {
72 ShiftZ2(clusters, clustersXYZ, merger, N);
73 }
74 if (param.rec.tpc.mergerInterpolateErrors) {
75 for (int32_t i = 0; i < N; i++) {
76 interpolation.hit[i].errorY = -1;
77 }
78 }
79
80 const int32_t nWays = param.rec.tpc.nWays;
81 const int32_t maxN = N;
82 int32_t ihitStart = 0;
83 float covYYUpd = 0.f;
84 float lastUpdateX = -1.f;
85 uint8_t lastRow = 255;
86 uint8_t lastSector = 255;
87 uint8_t storeOuter = 0;
88
89 for (int32_t iWay = 0; iWay < nWays; iWay++) {
90 int32_t nMissed = 0, nMissed2 = 0;
91 float sumInvSqrtCharge = 0.f;
92 int32_t nAvgCharge = 0;
93
94 if (iWay && storeOuter != 255 && param.rec.tpc.nWaysOuter && outerParam) {
95 storeOuter = 0;
96 if (iWay == nWays - 1) {
97 StoreOuter(outerParam, prop, 0);
98 if (merger->MergedTracks()[iTrk].Looper()) {
99 storeOuter = 1;
100 }
101 } else if (iWay == nWays - 2 && merger->MergedTracks()[iTrk].Looper()) {
102 storeOuter = 2;
103 }
104 }
105
106 int32_t resetT0 = initResetT0();
107 const bool refit = (nWays == 1 || iWay >= 1);
108 const float maxSinForUpdate = CAMath::Sin(70.f * kDeg2Rad);
109
110 ResetCovariance();
111 prop.SetSeedingErrors(!(refit && attempt == 0));
112 prop.SetFitInProjections(param.rec.fitInProjections == -1 ? (iWay != 0) : param.rec.fitInProjections);
113 prop.SetPropagateBzOnly(param.rec.fitPropagateBzOnly > iWay);
114 prop.SetMatLUT((param.rec.useMatLUT && iWay == nWays - 1) ? merger->GetConstantMem()->calibObjects.matLUT : nullptr);
115 prop.SetTrack(this, iWay ? prop.GetAlpha() : Alpha);
116 ConstrainSinPhi(prop.GetFitInProjections() ? 0.95f : GPUCA_MAX_SIN_PHI_LOW);
117 CADEBUG(printf("Fitting track %d way %d (sector %d, alpha %f)\n", iTrk, iWay, CAMath::Float2IntRn(prop.GetAlpha() / kSectAngle) + (mP[1] < 0 ? 18 : 0), prop.GetAlpha()));
118
119 N = 0;
120 lastUpdateX = -1;
121 const bool inFlyDirection = iWay & 1;
122 uint8_t lastLeg = clusters[ihitStart].leg;
123 const int32_t wayDirection = (iWay & 1) ? -1 : 1;
124
125 bool noFollowCircle = false, noFollowCircle2 = false;
126 int32_t goodRows = 0;
127 for (int32_t ihit = ihitStart; ihit >= 0 && ihit < maxN; ihit += wayDirection) {
128 const bool crossCE = lastSector != 255 && ((lastSector < 18) ^ (clusters[ihit].sector < 18));
129 if (crossCE) {
130 lastSector = clusters[ihit].sector;
131 noFollowCircle2 = true;
132 }
133
134 if (storeOuter == 2 && clusters[ihit].leg == clusters[maxN - 1].leg - 1) {
135 if (lastLeg == clusters[maxN - 1].leg) {
136 StoreOuter(outerParam, prop, 1);
137 storeOuter = 255;
138 } else {
139 storeOuter = 0;
140 }
141 }
142
143 if ((param.rec.tpc.trackFitRejectMode > 0 && nMissed >= param.rec.tpc.trackFitRejectMode) || nMissed2 >= param.rec.tpc.trackFitMaxRowMissedHard || clusters[ihit].state & GPUTPCGMMergedTrackHit::flagReject) {
144 CADEBUG(printf("\tSkipping hit, %d hits rejected, flag %X\n", nMissed, (int32_t)clusters[ihit].state));
145 if (iWay + 2 >= nWays && !(clusters[ihit].state & GPUTPCGMMergedTrackHit::flagReject)) {
147 }
148 continue;
149 }
150
151 const bool allowModification = refit && (iWay == 0 || (((nWays - iWay) & 1) ? (ihit >= CAMath::Min(maxN / 2, 30)) : (ihit <= CAMath::Max(maxN / 2, maxN - 30))));
152
153 int32_t ihitMergeFirst = ihit;
154 uint8_t clusterState = clusters[ihit].state;
155 const float clAlpha = param.Alpha(clusters[ihit].sector);
156 float xx, yy, zz;
157 if (param.par.earlyTpcTransform) {
158 const float zOffset = (clusters[ihit].sector < 18) == (clusters[0].sector < 18) ? mTZOffset : -mTZOffset;
159 xx = clustersXYZ[ihit].x;
160 yy = clustersXYZ[ihit].y;
161 zz = clustersXYZ[ihit].z - zOffset;
162 } else {
163 const ClusterNative& GPUrestrict() cl = merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[clusters[ihit].num];
164 merger->GetConstantMem()->calibObjects.fastTransformHelper->Transform(clusters[ihit].sector, clusters[ihit].row, cl.getPad(), cl.getTime(), xx, yy, zz, mTZOffset);
165 }
166 // clang-format off
167 CADEBUG(printf("\tHit %3d/%3d Row %3d: Cluster Alpha %8.3f %3d, X %8.3f - Y %8.3f, Z %8.3f (Missed %d)\n", ihit, maxN, (int32_t)clusters[ihit].row, clAlpha, (int32_t)clusters[ihit].sector, xx, yy, zz, nMissed));
168 // CADEBUG(if ((uint32_t)merger->GetTrackingChain()->mIOPtrs.nMCLabelsTPC > clusters[ihit].num))
169 // CADEBUG({printf(" MC:"); for (int32_t i = 0; i < 3; i++) {int32_t mcId = merger->GetTrackingChain()->mIOPtrs.mcLabelsTPC[clusters[ihit].num].fClusterID[i].fMCID; if (mcId >= 0) printf(" %d", mcId); } } printf("\n"));
170 // clang-format on
171 if (MergeDoubleRowClusters(ihit, wayDirection, clusters, clustersXYZ, merger, prop, xx, yy, zz, maxN, clAlpha, clusterState, allowModification) == -1) {
172 nMissed++;
173 nMissed2++;
174 continue;
175 }
176
177 if (param.rec.tpc.rejectIFCLowRadiusCluster) {
178 const float r2 = xx * xx + yy * yy;
179 const float rmax = (83.5f + param.rec.tpc.sysClusErrorMinDist);
180 if (r2 < rmax * rmax) {
181 MarkClusters(clusters, ihitMergeFirst, ihit, wayDirection, GPUTPCGMMergedTrackHit::flagRejectErr);
182 }
183 }
184
185 const auto& cluster = clusters[ihit];
186
187 bool changeDirection = (cluster.leg - lastLeg) & 1;
188 // clang-format off
189 CADEBUG(if (changeDirection) printf("\t\tChange direction\n"));
190 CADEBUG(printf("\tLeg %3d Sector %2d %4sTrack Alpha %8.3f %s, X %8.3f - Y %8.3f, Z %8.3f - QPt %7.2f (%7.2f), SP %5.2f (%5.2f) %28s --- Cov sY %8.3f sZ %8.3f sSP %8.3f sPt %8.3f - YPt %8.3f\n", (int32_t)cluster.leg, (int32_t)cluster.sector, "", prop.GetAlpha(), (CAMath::Abs(prop.GetAlpha() - clAlpha) < 0.01 ? " " : " R!"), mX, mP[0], mP[1], mP[4], prop.GetQPt0(), mP[2], prop.GetSinPhi0(), "", sqrtf(mC[0]), sqrtf(mC[2]), sqrtf(mC[5]), sqrtf(mC[14]), mC[10]));
191 // clang-format on
192 if (allowModification && changeDirection && !noFollowCircle && !noFollowCircle2) {
193 bool tryFollow = lastRow != 255;
194 if (tryFollow) {
195 const GPUTPCGMTrackParam backup = *this;
196 const float backupAlpha = prop.GetAlpha();
197 if (FollowCircle<0>(merger, prop, lastSector, lastRow, iTrk, clAlpha, xx, yy, cluster.sector, cluster.row, inFlyDirection)) {
198 CADEBUG(printf("Error during follow circle, resetting track!\n"));
199 *this = backup;
200 prop.SetTrack(this, backupAlpha);
201 noFollowCircle = true;
202 tryFollow = false;
203 }
204 }
205 if (tryFollow) {
206 MirrorTo(prop, yy, zz, inFlyDirection, param, cluster.row, clusterState, false, cluster.sector);
207 lastUpdateX = mX;
208 lastLeg = cluster.leg;
209 lastSector = cluster.sector;
210 lastRow = 255;
211 N++;
212 resetT0 = initResetT0();
213 // clang-format off
214 CADEBUG(printf("\n"));
215 CADEBUG(printf("\t%21sMirror Alpha %8.3f , X %8.3f - Y %8.3f, Z %8.3f - QPt %7.2f (%7.2f), SP %5.2f (%5.2f) %28s --- Cov sY %8.3f sZ %8.3f sSP %8.3f sPt %8.3f - YPt %8.3f\n", "", prop.GetAlpha(), mX, mP[0], mP[1], mP[4], prop.GetQPt0(), mP[2], prop.GetSinPhi0(), "", sqrtf(mC[0]), sqrtf(mC[2]), sqrtf(mC[5]), sqrtf(mC[14]), mC[10]));
216 // clang-format on
217 continue;
218 }
219 } else if (allowModification && lastRow != 255 && CAMath::Abs(cluster.row - lastRow) > 1) {
221 bool dodEdx = param.dodEdxEnabled && param.rec.tpc.adddEdxSubThresholdClusters && iWay == nWays - 1 && CAMath::Abs(cluster.row - lastRow) == 2 && cluster.leg == clusters[maxN - 1].leg;
222 dodEdx = AttachClustersPropagate(merger, cluster.sector, lastRow, cluster.row, iTrk, cluster.leg == clusters[maxN - 1].leg, prop, inFlyDirection, GPUCA_MAX_SIN_PHI, dodEdx);
223 if (dodEdx) {
224 dEdx.fillSubThreshold(lastRow - wayDirection);
225 if GPUCA_RTC_CONSTEXPR (GPUCA_GET_CONSTEXPR(param.rec.tpc, dEdxClusterRejectionFlagMask) != GPUCA_GET_CONSTEXPR(param.rec.tpc, dEdxClusterRejectionFlagMaskAlt)) {
226 dEdxAlt.fillSubThreshold(lastRow - wayDirection);
227 }
228 }
229 }
230 }
231
232 int32_t err = prop.PropagateToXAlpha(xx, clAlpha, inFlyDirection);
233 // clang-format off
234 CADEBUG(if (!CheckCov()){printf("INVALID COV AFTER PROPAGATE!!!\n");});
235 // clang-format on
236 if (err == -2) // Rotation failed, try to bring to new x with old alpha first, rotate, and then propagate to x, alpha
237 {
238 CADEBUG(printf("REROTATE\n"));
239 if (prop.PropagateToXAlpha(xx, prop.GetAlpha(), inFlyDirection) == 0) {
240 err = prop.PropagateToXAlpha(xx, clAlpha, inFlyDirection);
241 }
242 }
243 if (lastRow == 255 || CAMath::Abs((int32_t)lastRow - (int32_t)cluster.row) > 5 || lastSector != cluster.sector || (param.rec.tpc.trackFitRejectMode < 0 && -nMissed <= param.rec.tpc.trackFitRejectMode)) {
244 goodRows = 0;
245 } else {
246 goodRows++;
247 }
248 if (err == 0) {
249 lastRow = cluster.row;
250 lastSector = cluster.sector;
251 }
252 // clang-format off
253 CADEBUG(printf("\t%21sPropaga Alpha %8.3f , X %8.3f - Y %8.3f, Z %8.3f - QPt %7.2f (%7.2f), SP %5.2f (%5.2f) --- Res %8.3f %8.3f --- Cov sY %8.3f sZ %8.3f sSP %8.3f sPt %8.3f - YPt %8.3f - Err %d", "", prop.GetAlpha(), mX, mP[0], mP[1], mP[4], prop.GetQPt0(), mP[2], prop.GetSinPhi0(), mP[0] - yy, mP[1] - zz, sqrtf(mC[0]), sqrtf(mC[2]), sqrtf(mC[5]), sqrtf(mC[14]), mC[10], err));
254 // clang-format on
255
256 if (crossCE) {
257 if (param.rec.tpc.addErrorsCECrossing) {
258 if (param.rec.tpc.addErrorsCECrossing >= 2) {
259 AddCovDiagErrorsWithCorrelations(param.rec.tpc.errorsCECrossing);
260 } else {
261 AddCovDiagErrors(param.rec.tpc.errorsCECrossing);
262 }
263 } else if (mC[2] < 0.5f) {
264 mC[2] = 0.5f;
265 }
266 }
267
268 if (err == 0 && changeDirection) {
269 const float mirrordY = prop.GetMirroredYTrack();
270 CADEBUG(printf(" -- MirroredY: %f --> %f", mP[0], mirrordY));
271 if (CAMath::Abs(yy - mP[0]) > CAMath::Abs(yy - mirrordY)) {
272 CADEBUG(printf(" - Mirroring!!!"));
273 if (allowModification) {
274 AttachClustersMirror<0>(merger, cluster.sector, cluster.row, iTrk, yy, prop); // TODO: Never true, will always call FollowCircle above, really???
275 }
276 MirrorTo(prop, yy, zz, inFlyDirection, param, cluster.row, clusterState, true, cluster.sector);
277 noFollowCircle = false;
278
279 lastUpdateX = mX;
280 lastLeg = cluster.leg;
281 lastRow = 255;
282 N++;
283 resetT0 = initResetT0();
284 // clang-format off
285 CADEBUG(printf("\n"));
286 CADEBUG(printf("\t%21sMirror Alpha %8.3f , X %8.3f - Y %8.3f, Z %8.3f - QPt %7.2f (%7.2f), SP %5.2f (%5.2f) %28s --- Cov sY %8.3f sZ %8.3f sSP %8.3f sPt %8.3f - YPt %8.3f\n", "", prop.GetAlpha(), mX, mP[0], mP[1], mP[4], prop.GetQPt0(), mP[2], prop.GetSinPhi0(), "", sqrtf(mC[0]), sqrtf(mC[2]), sqrtf(mC[5]), sqrtf(mC[14]), mC[10]));
287 // clang-format on
288 continue;
289 }
290 }
291
292 float uncorrectedY = -1e6f;
293 if (allowModification) {
294 uncorrectedY = AttachClusters(merger, cluster.sector, cluster.row, iTrk, cluster.leg == clusters[maxN - 1].leg, prop);
295 }
296
297 const int32_t err2 = mNDF > 0 && CAMath::Abs(prop.GetSinPhi0()) >= maxSinForUpdate;
298 if (err || err2) {
299 if (mC[0] > param.rec.tpc.trackFitCovLimit || mC[2] > param.rec.tpc.trackFitCovLimit) {
300 break;
301 }
302 MarkClusters(clusters, ihitMergeFirst, ihit, wayDirection, GPUTPCGMMergedTrackHit::flagHighIncl);
303 nMissed2++;
304 NTolerated++;
305 CADEBUG(printf(" --- break (%d, %d)\n", err, err2));
306 continue;
307 }
308 CADEBUG(printf("\n"));
309
310 int32_t retVal;
311 float threshold = 3.f + (lastUpdateX >= 0 ? (CAMath::Abs(mX - lastUpdateX) / 2) : 0.f);
312 if (mNDF > 5 && (CAMath::Abs(yy - mP[0]) > threshold || CAMath::Abs(zz - mP[1]) > threshold)) {
314 } else {
315 int8_t rejectChi2 = attempt ? 0 : ((param.rec.tpc.mergerInterpolateErrors && CAMath::Abs(ihit - ihitMergeFirst) <= 1) ? (refit ? (GPUTPCGMPropagator::rejectInterFill + ((nWays - iWay) & 1)) : 0) : (allowModification && goodRows > 5));
316#if EXTRACT_RESIDUALS == 1
317 if (iWay == nWays - 1 && interpolation.hit[ihit].errorY > (GPUCA_PAR_MERGER_INTERPOLATION_ERROR_TYPE_A)0) {
318 const float Iz0 = interpolation.hit[ihit].posY - mP[0];
319 const float Iz1 = interpolation.hit[ihit].posZ - mP[1];
320 float Iw0 = mC[2] + (float)interpolation.hit[ihit].errorZ;
321 float Iw2 = mC[0] + (float)interpolation.hit[ihit].errorY;
322 float Idet1 = 1.f / CAMath::Max(1e-10f, Iw0 * Iw2 - mC[1] * mC[1]);
323 const float Ik00 = (mC[0] * Iw0 + mC[1] * mC[1]) * Idet1;
324 const float Ik01 = (mC[0] * mC[1] + mC[1] * Iw2) * Idet1;
325 const float Ik10 = (mC[1] * Iw0 + mC[2] * mC[1]) * Idet1;
326 const float Ik11 = (mC[1] * mC[1] + mC[2] * Iw2) * Idet1;
327 const float ImP0 = mP[0] + Ik00 * Iz0 + Ik01 * Iz1;
328 const float ImP1 = mP[1] + Ik10 * Iz0 + Ik11 * Iz1;
329 const float ImC0 = mC[0] - Ik00 * mC[0] + Ik01 * mC[1];
330 const float ImC2 = mC[2] - Ik10 * mC[1] + Ik11 * mC[2];
331 auto& tup = GPUROOTDump<TNtuple>::get("clusterres", "row:clX:clY:clZ:angle:trkX:trkY:trkZ:trkSinPhi:trkDzDs:trkQPt:trkSigmaY2:trkSigmaZ2trkSigmaQPt2");
332 tup.Fill((float)cluster.row, xx, yy, zz, clAlpha, mX, ImP0, ImP1, mP[2], mP[3], mP[4], ImC0, ImC2, mC[14]);
333 }
334#endif
336 if (param.rec.tpc.rejectEdgeClustersInTrackFit && uncorrectedY > -1e6f && param.rejectEdgeClusterByY(uncorrectedY, cluster.row, CAMath::Sqrt(mC[0]))) { // uncorrectedY > -1e6f implies allowModification
338 } else {
339 const float time = merger->GetConstantMem()->ioPtrs.clustersNative ? merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[cluster.num].getTime() : -1.f;
340 const float invSqrtCharge = merger->GetConstantMem()->ioPtrs.clustersNative ? CAMath::InvSqrt(merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[cluster.num].qMax) : 0.f;
341 const float invCharge = merger->GetConstantMem()->ioPtrs.clustersNative ? (1.f / merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[cluster.num].qMax) : 0.f;
342 float invAvgCharge = (sumInvSqrtCharge += invSqrtCharge) / ++nAvgCharge;
343 invAvgCharge *= invAvgCharge;
344 retVal = prop.Update(yy, zz, cluster.row, param, clusterState, rejectChi2, &interpolation.hit[ihit], refit, cluster.sector, time, invAvgCharge, invCharge GPUCA_DEBUG_STREAMER_CHECK(, &debugVals));
345 }
346 GPUCA_DEBUG_STREAMER_CHECK(if (o2::utils::DebugStreamer::checkStream(o2::utils::StreamFlags::streamUpdateTrack, iTrk)) {
347 merger->DebugStreamerUpdate(iTrk, ihit, xx, yy, zz, cluster, merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[cluster.num], *this, prop, interpolation.hit[ihit], rejectChi2, refit, retVal, sumInvSqrtCharge / nAvgCharge * sumInvSqrtCharge / nAvgCharge, yy, zz, clusterState, debugVals.retVal, debugVals.err2Y, debugVals.err2Z);
348 });
349 }
350 // clang-format off
351 CADEBUG(if (!CheckCov()) GPUError("INVALID COV AFTER UPDATE!!!"));
352 CADEBUG(printf("\t%21sFit Alpha %8.3f , X %8.3f - Y %8.3f, Z %8.3f - QPt %7.2f (%7.2f), SP %5.2f (%5.2f), DzDs %5.2f %16s --- Cov sY %8.3f sZ %8.3f sSP %8.3f sPt %8.3f - YPt %8.3f - Err %d\n", "", prop.GetAlpha(), mX, mP[0], mP[1], mP[4], prop.GetQPt0(), mP[2], prop.GetSinPhi0(), mP[3], "", sqrtf(mC[0]), sqrtf(mC[2]), sqrtf(mC[5]), sqrtf(mC[14]), mC[10], retVal));
353 // clang-format on
354
355 ConstrainSinPhi();
356 if (retVal == 0) // track is updated
357 {
358 if (storeOuter == 1 && cluster.leg == clusters[maxN - 1].leg) {
359 StoreOuter(outerParam, prop, 2);
360 storeOuter = 255;
361 }
362 noFollowCircle2 = false;
363 lastUpdateX = mX;
364 covYYUpd = mC[0];
365 nMissed = nMissed2 = 0;
366 UnmarkClusters(clusters, ihitMergeFirst, ihit, wayDirection, GPUTPCGMMergedTrackHit::flagHighIncl);
367 N++;
368 ihitStart = ihit;
369 float dy = mP[0] - prop.Model().Y();
370 float dz = mP[1] - prop.Model().Z();
371 if (CAMath::Abs(mP[4]) * param.qptB5Scaler > 10 && --resetT0 <= 0 && CAMath::Abs(mP[2]) < 0.15f && dy * dy + dz * dz > 1) {
372 CADEBUG(printf("Reinit linearization\n"));
373 prop.SetTrack(this, prop.GetAlpha());
374 }
376 if (param.dodEdxEnabled && iWay == nWays - 1 && cluster.leg == clusters[maxN - 1].leg) { // TODO: Costimize flag to remove, and option to remove double-clusters
377 bool acc = (clusterState & param.rec.tpc.dEdxClusterRejectionFlagMask) == 0, accAlt = (clusterState & param.rec.tpc.dEdxClusterRejectionFlagMaskAlt) == 0;
378 if (acc || accAlt) {
379 float qtot = 0, qmax = 0, pad = 0, relTime = 0;
380 const int32_t clusterCount = (ihit - ihitMergeFirst) * wayDirection + 1;
381 for (int32_t iTmp = ihitMergeFirst; iTmp != ihit + wayDirection; iTmp += wayDirection) {
382 if (merger->GetConstantMem()->ioPtrs.clustersNative == nullptr) {
383 qtot += clustersXYZ[ihit].amp;
384 } else {
385 const ClusterNative& cl = merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[cluster.num];
386 qtot += cl.qTot;
387 qmax = CAMath::Max<float>(qmax, cl.qMax);
388 pad += cl.getPad();
389 relTime += cl.getTime();
390 }
391 }
392 qtot /= clusterCount; // TODO: Weighted Average
393 pad /= clusterCount;
394 relTime /= clusterCount;
395 relTime = relTime - CAMath::Round(relTime);
396 if (acc) {
397 dEdx.fillCluster(qtot, qmax, cluster.row, cluster.sector, mP[2], mP[3], merger->GetConstantMem()->calibObjects, zz, pad, relTime);
398 }
399 if GPUCA_RTC_CONSTEXPR (GPUCA_GET_CONSTEXPR(param.rec.tpc, dEdxClusterRejectionFlagMask) != GPUCA_GET_CONSTEXPR(param.rec.tpc, dEdxClusterRejectionFlagMaskAlt)) {
400 if (accAlt) {
401 dEdxAlt.fillCluster(qtot, qmax, cluster.row, cluster.sector, mP[2], mP[3], merger->GetConstantMem()->calibObjects, zz, pad, relTime);
402 }
403 }
404 }
405 }
406 }
407 } else if (retVal >= GPUTPCGMPropagator::updateErrorClusterRejected) { // cluster far away form the track
408 if (allowModification) {
409 MarkClusters(clusters, ihitMergeFirst, ihit, wayDirection, GPUTPCGMMergedTrackHit::flagRejectDistance);
410 } else if (iWay == nWays - 1) {
411 MarkClusters(clusters, ihitMergeFirst, ihit, wayDirection, GPUTPCGMMergedTrackHit::flagRejectErr);
412 }
413 nMissed++;
414 nMissed2++;
415 } else {
416 break; // bad chi2 for the whole track, stop the fit
417 }
418 }
419 if (((nWays - iWay) & 1) && (iWay != nWays - 1) && (clusters[0].sector < 18) == (clusters[maxN - 1].sector < 18)) {
420 ShiftZ2(clusters, clustersXYZ, merger, maxN);
421 }
422 }
423 ConstrainSinPhi();
424
425 GPUCA_DEBUG_STREAMER_CHECK(if (o2::utils::DebugStreamer::checkStream(o2::utils::StreamFlags::streamUpdateTrack, iTrk)) {
426 o2::utils::DebugStreamer::instance()->getStreamer("debug_accept_track", "UPDATE") << o2::utils::DebugStreamer::instance()->getUniqueTreeName("debug_accept_track").data() << "iTrk=" << iTrk << "outerParam=" << *outerParam << "track=" << this << "ihitStart=" << ihitStart << "\n";
427 })
428
429 if (!(N + NTolerated >= GPUCA_TRACKLET_SELECTOR_MIN_HITS_B5(mP[4] * param.qptB5Scaler) && 2 * NTolerated <= CAMath::Max(10, N) && CheckNumericalQuality(covYYUpd))) {
430 return false; // TODO: NTolerated should never become that large, check what is going wrong!
431 }
432 if (param.rec.tpc.minNClustersFinalTrack != -1 && N + NTolerated < param.rec.tpc.minNClustersFinalTrack) {
433 return false;
434 }
435
436 // TODO: we have looping tracks here with 0 accepted clusters in the primary leg. In that case we should refit the track using only the primary leg.
437
438 if (param.par.dodEdx && param.dodEdxEnabled) {
439 dEdx.computedEdx(merger->MergedTracksdEdx()[iTrk], param);
440 if GPUCA_RTC_CONSTEXPR (GPUCA_GET_CONSTEXPR(param.rec.tpc, dEdxClusterRejectionFlagMask) != GPUCA_GET_CONSTEXPR(param.rec.tpc, dEdxClusterRejectionFlagMaskAlt)) {
441 dEdxAlt.computedEdx(merger->MergedTracksdEdxAlt()[iTrk], param);
442 }
443 }
444 Alpha = prop.GetAlpha();
445 MoveToReference(prop, param, Alpha);
446 NormalizeAlpha(Alpha);
447
448 return true;
449}
450
451GPUdni() void GPUTPCGMTrackParam::MoveToReference(GPUTPCGMPropagator& prop, const GPUParam& param, float& Alpha)
452{
453 static constexpr float kDeg2Rad = M_PI / 180.f;
454 static constexpr float kSectAngle = 2 * M_PI / 18.f;
455
456 if (param.rec.tpc.trackReferenceX <= 500) {
457 GPUTPCGMTrackParam save = *this;
458 float saveAlpha = Alpha;
459 for (int32_t attempt = 0; attempt < 3; attempt++) {
460 float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / kDeg2Rad / 20.f) * kSectAngle;
461 Alpha += dAngle;
462 if (prop.PropagateToXAlpha(param.rec.tpc.trackReferenceX, Alpha, 0)) {
463 break;
464 }
465 ConstrainSinPhi();
466 if (CAMath::Abs(mP[0]) <= mX * CAMath::Tan(kSectAngle / 2.f)) {
467 return;
468 }
469 }
470 *this = save;
471 Alpha = saveAlpha;
472 }
473 if (CAMath::Abs(mP[0]) > mX * CAMath::Tan(kSectAngle / 2.f)) {
474 float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / kDeg2Rad / 20.f) * kSectAngle;
475 Rotate(dAngle);
476 ConstrainSinPhi();
477 Alpha += dAngle;
478 }
479}
480
481GPUd() void GPUTPCGMTrackParam::MirrorTo(GPUTPCGMPropagator& GPUrestrict() prop, float toY, float toZ, bool inFlyDirection, const GPUParam& param, uint8_t row, uint8_t clusterState, bool mirrorParameters, int8_t sector)
482{
483 if (mirrorParameters) {
484 prop.Mirror(inFlyDirection);
485 }
486 float err2Y, err2Z;
487 prop.GetErr2(err2Y, err2Z, param, toZ, row, clusterState, sector, -1.f, 0.f, 0.f); // Use correct time / avgCharge
488 prop.Model().Y() = mP[0] = toY;
489 prop.Model().Z() = mP[1] = toZ;
490 if (mC[0] < err2Y) {
491 mC[0] = err2Y;
492 }
493 if (mC[2] < err2Z) {
494 mC[2] = err2Z;
495 }
496 if (CAMath::Abs(mC[5]) < 0.1f) {
497 mC[5] = mC[5] > 0 ? 0.1f : -0.1f;
498 }
499 if (mC[9] < 1.f) {
500 mC[9] = 1.f;
501 }
502 mC[1] = mC[4] = mC[6] = mC[8] = mC[11] = mC[13] = 0;
503 prop.SetTrack(this, prop.GetAlpha());
504 mNDF = -3;
505 mChi2 = 0;
506}
507
508GPUd() int32_t GPUTPCGMTrackParam::MergeDoubleRowClusters(int32_t& ihit, int32_t wayDirection, GPUTPCGMMergedTrackHit* GPUrestrict() clusters, GPUTPCGMMergedTrackHitXYZ* clustersXYZ, const GPUTPCGMMerger* GPUrestrict() merger, GPUTPCGMPropagator& GPUrestrict() prop, float& GPUrestrict() xx, float& GPUrestrict() yy, float& GPUrestrict() zz, int32_t maxN, float clAlpha, uint8_t& GPUrestrict() clusterState, bool rejectChi2)
509{
510 if (ihit + wayDirection >= 0 && ihit + wayDirection < maxN && clusters[ihit].row == clusters[ihit + wayDirection].row && clusters[ihit].sector == clusters[ihit + wayDirection].sector && clusters[ihit].leg == clusters[ihit + wayDirection].leg) {
511 float maxDistY, maxDistZ;
512 prop.GetErr2(maxDistY, maxDistZ, merger->Param(), zz, clusters[ihit].row, 0, clusters[ihit].sector, -1.f, 0.f, 0.f); // TODO: Use correct time, avgCharge
513 maxDistY = (maxDistY + mC[0]) * 20.f;
514 maxDistZ = (maxDistZ + mC[2]) * 20.f;
515 int32_t noReject = 0; // Cannot reject if simple estimation of y/z fails (extremely unlike case)
516 if (CAMath::Abs(clAlpha - prop.GetAlpha()) > 1.e-4f) {
517 noReject = prop.RotateToAlpha(clAlpha);
518 }
519 float projY = 0, projZ = 0;
520 if (noReject == 0) {
521 noReject |= prop.GetPropagatedYZ(xx, projY, projZ);
522 }
523 float count = 0.f;
524 xx = yy = zz = 0.f;
525 clusterState = 0;
526 while (true) {
527 float clx, cly, clz, clamp;
528 if (merger->Param().par.earlyTpcTransform) {
529 const float zOffset = (clusters[ihit].sector < 18) == (clusters[0].sector < 18) ? mTZOffset : -mTZOffset;
530 clx = clustersXYZ[ihit].x;
531 cly = clustersXYZ[ihit].y;
532 clz = clustersXYZ[ihit].z - zOffset;
533 clamp = clustersXYZ[ihit].amp;
534 } else {
535 const ClusterNative& GPUrestrict() cl = merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[clusters[ihit].num];
536 clamp = cl.qTot;
537 merger->GetConstantMem()->calibObjects.fastTransformHelper->Transform(clusters[ihit].sector, clusters[ihit].row, cl.getPad(), cl.getTime(), clx, cly, clz, mTZOffset);
538 }
539 float dy = cly - projY;
540 float dz = clz - projZ;
541 if (noReject == 0 && (dy * dy > maxDistY || dz * dz > maxDistZ)) {
542 CADEBUG(printf("\t\tRejecting double-row cluster: dy %f, dz %f, chiY %f, chiZ %f (Y: trk %f prj %f cl %f - Z: trk %f prj %f cl %f)\n", dy, dz, sqrtf(maxDistY), sqrtf(maxDistZ), mP[0], projY, cly, mP[1], projZ, clz));
543 if (rejectChi2) {
545 }
546 } else {
547 CADEBUG(printf("\t\tMerging hit row %d X %f Y %f Z %f (dy %f, dz %f, chiY %f, chiZ %f)\n", clusters[ihit].row, clx, cly, clz, dy, dz, sqrtf(maxDistY), sqrtf(maxDistZ)));
548 xx += clx * clamp; // TODO: Weight in pad/time instead of XYZ
549 yy += cly * clamp;
550 zz += clz * clamp;
551 clusterState |= clusters[ihit].state;
552 count += clamp;
553 }
554 if (!(ihit + wayDirection >= 0 && ihit + wayDirection < maxN && clusters[ihit].row == clusters[ihit + wayDirection].row && clusters[ihit].sector == clusters[ihit + wayDirection].sector && clusters[ihit].leg == clusters[ihit + wayDirection].leg)) {
555 break;
556 }
557 ihit += wayDirection;
558 }
559 if (count < 0.1f) {
560 CADEBUG(printf("\t\tNo matching cluster in double-row, skipping\n"));
561 return -1;
562 }
563 xx /= count;
564 yy /= count;
565 zz /= count;
566 }
567 return 0;
568}
569
570GPUd() float GPUTPCGMTrackParam::AttachClusters(const GPUTPCGMMerger* GPUrestrict() Merger, int32_t sector, int32_t iRow, int32_t iTrack, bool goodLeg, GPUTPCGMPropagator& prop)
571{
572 float Y, Z;
573 if (Merger->Param().par.earlyTpcTransform) {
574 Y = mP[0];
575 Z = mP[1];
576 } else {
577 float X = 0;
578 Merger->GetConstantMem()->calibObjects.fastTransformHelper->InverseTransformYZtoX(sector, iRow, mP[0], mP[1], X);
579 if (prop.GetPropagatedYZ(X, Y, Z)) {
580 Y = mP[0];
581 Z = mP[1];
582 }
583 }
584 return AttachClusters(Merger, sector, iRow, iTrack, goodLeg, Y, Z);
585}
586
587GPUd() float GPUTPCGMTrackParam::AttachClusters(const GPUTPCGMMerger* GPUrestrict() Merger, int32_t sector, int32_t iRow, int32_t iTrack, bool goodLeg, float Y, float Z)
588{
589 if (Merger->Param().rec.tpc.disableRefitAttachment & 1) {
590 return -1e6f;
591 }
592 const GPUTPCTracker& GPUrestrict() tracker = *(Merger -> GetConstantMem()->tpcTrackers + sector);
593 const GPUTPCRow& GPUrestrict() row = tracker.Row(iRow);
594 GPUglobalref() const cahit2* hits = tracker.HitData(row);
595 GPUglobalref() const calink* firsthit = tracker.FirstHitInBin(row);
596 if (row.NHits() == 0) {
597 return -1e6f;
598 }
599
600 const float zOffset = Merger->Param().par.earlyTpcTransform ? ((Merger->MergedTracks()[iTrack].CSide() ^ (sector >= 18)) ? -mTZOffset : mTZOffset) : Merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(sector, mTZOffset, Merger->Param().continuousMaxTimeBin);
601 const float y0 = row.Grid().YMin();
602 const float stepY = row.HstepY();
603 const float z0 = row.Grid().ZMin() - zOffset; // We can use our own ZOffset, since this is only used temporarily anyway
604 const float stepZ = row.HstepZ();
605 int32_t bin, ny, nz;
606
607 float err2Y, err2Z;
608 Merger->Param().GetClusterErrors2(sector, iRow, Z, mP[2], mP[3], -1.f, 0.f, 0.f, err2Y, err2Z); // TODO: Use correct time/avgCharge
609 const float sy2 = CAMath::Min(Merger->Param().rec.tpc.tubeMaxSize2, Merger->Param().rec.tpc.tubeChi2 * (err2Y + CAMath::Abs(mC[0]))); // Cov can be bogus when following circle
610 const float sz2 = CAMath::Min(Merger->Param().rec.tpc.tubeMaxSize2, Merger->Param().rec.tpc.tubeChi2 * (err2Z + CAMath::Abs(mC[2]))); // In that case we should provide the track error externally
611 const float tubeY = CAMath::Sqrt(sy2);
612 const float tubeZ = CAMath::Sqrt(sz2);
613 const float sy21 = 1.f / sy2;
614 const float sz21 = 1.f / sz2;
615 float uncorrectedY, uncorrectedZ;
616 if (Merger->Param().par.earlyTpcTransform) {
617 uncorrectedY = Y;
618 uncorrectedZ = Z;
619 } else {
620 Merger->GetConstantMem()->calibObjects.fastTransformHelper->InverseTransformYZtoNominalYZ(sector, iRow, Y, Z, uncorrectedY, uncorrectedZ);
621 }
622
623 if (CAMath::Abs(uncorrectedY) > row.getTPCMaxY()) {
624 return uncorrectedY;
625 }
626 row.Grid().GetBinArea(uncorrectedY, uncorrectedZ + zOffset, tubeY, tubeZ, bin, ny, nz);
627
628 const int32_t nBinsY = row.Grid().Ny();
629 const int32_t idOffset = tracker.Data().ClusterIdOffset();
630 const int32_t* ids = &(tracker.Data().ClusterDataIndex()[row.HitNumberOffset()]);
631 uint32_t myWeight = Merger->TrackOrderAttach()[iTrack] | gputpcgmmergertypes::attachAttached | gputpcgmmergertypes::attachTube;
632 GPUAtomic(uint32_t)* const weights = Merger->ClusterAttachment();
633 if (goodLeg) {
635 }
636 for (int32_t k = 0; k <= nz; k++) {
637 const int32_t mybin = bin + k * nBinsY;
638 const uint32_t hitFst = firsthit[mybin];
639 const uint32_t hitLst = firsthit[mybin + ny + 1];
640 for (uint32_t ih = hitFst; ih < hitLst; ih++) {
641 int32_t id = idOffset + ids[ih];
642 GPUAtomic(uint32_t)* const weight = weights + id;
643 if constexpr (GPUCA_PAR_NO_ATOMIC_PRECHECK == 0) {
644 if (myWeight <= *weight) {
645 continue;
646 }
647 }
648 const cahit2 hh = hits[ih];
649 const float y = y0 + hh.x * stepY;
650 const float z = z0 + hh.y * stepZ;
651 const float dy = y - uncorrectedY;
652 const float dz = z - uncorrectedZ;
653 if (dy * dy * sy21 + dz * dz * sz21 <= CAMath::Sqrt(2.f)) {
654 // CADEBUG(printf("Found Y %f Z %f\n", y, z));
655 CAMath::AtomicMax(weight, myWeight);
656 }
657 }
658 }
659 return uncorrectedY;
660}
661
662GPUd() bool GPUTPCGMTrackParam::AttachClustersPropagate(const GPUTPCGMMerger* GPUrestrict() Merger, int32_t sector, int32_t lastRow, int32_t toRow, int32_t iTrack, bool goodLeg, GPUTPCGMPropagator& GPUrestrict() prop, bool inFlyDirection, float maxSinPhi, bool dodEdx)
663{
664 static constexpr float kSectAngle = 2 * M_PI / 18.f;
665 if (Merger->Param().rec.tpc.disableRefitAttachment & 2) {
666 return dodEdx;
667 }
668 if (CAMath::Abs(lastRow - toRow) < 2) {
669 return dodEdx;
670 }
671 int32_t step = toRow > lastRow ? 1 : -1;
672 float xx = mX - GPUTPCGeometry::Row2X(lastRow);
673 for (int32_t iRow = lastRow + step; iRow != toRow; iRow += step) {
674 if (CAMath::Abs(mP[2]) > maxSinPhi) {
675 return dodEdx;
676 }
677 if (CAMath::Abs(mP[0]) > CAMath::Abs(mX) * CAMath::Tan(kSectAngle / 2.f)) {
678 return dodEdx;
679 }
680 int32_t err = prop.PropagateToXAlpha(xx + GPUTPCGeometry::Row2X(iRow), prop.GetAlpha(), inFlyDirection);
681 if (err) {
682 return dodEdx;
683 }
684 if (dodEdx && iRow + step == toRow) {
685 float yUncorrected, zUncorrected;
686 Merger->GetConstantMem()->calibObjects.fastTransformHelper->InverseTransformYZtoNominalYZ(sector, iRow, mP[0], mP[1], yUncorrected, zUncorrected);
687 uint32_t pad = CAMath::Float2UIntRn(GPUTPCGeometry::LinearY2Pad(sector, iRow, yUncorrected));
688 if (pad >= GPUTPCGeometry::NPads(iRow) || (Merger->GetConstantMem()->calibObjects.dEdxCalibContainer && Merger->GetConstantMem()->calibObjects.dEdxCalibContainer->isDead(sector, iRow, pad))) {
689 dodEdx = false;
690 }
691 }
692 CADEBUG(printf("Attaching in row %d\n", iRow));
693 AttachClusters(Merger, sector, iRow, iTrack, goodLeg, prop);
694 }
695 return dodEdx;
696}
697
698GPUd() bool GPUTPCGMTrackParam::FollowCircleChk(float lrFactor, float toY, float toX, bool up, bool right)
699{
700 return CAMath::Abs(mX * lrFactor - toY) > 1.f && // transport further in Y
701 CAMath::Abs(mP[2]) < 0.7f && // rotate back
702 (up ? (-mP[0] * lrFactor > toX || (right ^ (mP[2] > 0))) : (-mP[0] * lrFactor < toX || (right ^ (mP[2] < 0)))); // don't overshoot in X
703}
704
705GPUdii() void GPUTPCGMTrackParam::StoreOuter(gputpcgmmergertypes::GPUTPCOuterParam* outerParam, const GPUTPCGMPropagator& prop, int32_t phase)
706{
707 CADEBUG(printf("\t%21sStorO%d Alpha %8.3f , X %8.3f - Y %8.3f, Z %8.3f - QPt %7.2f (%7.2f), SP %5.2f (%5.2f) --- Cov sY %8.3f sZ %8.3f sSP %8.3f sPt %8.3f\n", "", phase, prop.GetAlpha(), mX, mP[0], mP[1], mP[4], prop.GetQPt0(), mP[2], prop.GetSinPhi0(), sqrtf(mC[0]), sqrtf(mC[2]), sqrtf(mC[5]), sqrtf(mC[14])));
708 for (int32_t i = 0; i < 5; i++) {
709 outerParam->P[i] = mP[i];
710 }
711 for (int32_t i = 0; i < 15; i++) {
712 outerParam->C[i] = mC[i];
713 }
714 outerParam->X = mX;
715 outerParam->alpha = prop.GetAlpha();
716}
717
718GPUdic(0, 1) void GPUTPCGMTrackParam::StoreAttachMirror(const GPUTPCGMMerger* GPUrestrict() Merger, int32_t sector, int32_t iRow, int32_t iTrack, float toAlpha, float toY, float toX, int32_t toSector, int32_t toRow, bool inFlyDirection, float alpha)
719{
720 uint32_t nLoopData = CAMath::AtomicAdd(&Merger->Memory()->nLoopData, 1u);
721 if (nLoopData >= Merger->NMaxTracks()) {
722 Merger->raiseError(GPUErrors::ERROR_MERGER_LOOPER_OVERFLOW, nLoopData, Merger->NMaxTracks());
723 CAMath::AtomicExch(&Merger->Memory()->nLoopData, Merger->NMaxTracks());
724 return;
725 }
727 data.param = *this;
728 data.alpha = alpha;
729 data.track = iTrack;
730 data.toAlpha = toAlpha;
731 data.toY = toY;
732 data.toX = toX;
733 data.sector = sector;
734 data.row = iRow;
735 data.toSector = toSector;
736 data.toRow = toRow;
737 data.inFlyDirection = inFlyDirection;
738 Merger->LoopData()[nLoopData] = data;
739}
740
741GPUdii() void GPUTPCGMTrackParam::RefitLoop(const GPUTPCGMMerger* GPUrestrict() Merger, int32_t loopIdx)
742{
744 prop.SetMaterialTPC();
745 prop.SetPolynomialField(&Merger->Param().polynomialField);
746 prop.SetMaxSinPhi(GPUCA_MAX_SIN_PHI);
747 prop.SetToyMCEventsFlag(Merger->Param().par.toyMCEventsFlag);
748 prop.SetMatLUT(Merger->Param().rec.useMatLUT ? Merger->GetConstantMem()->calibObjects.matLUT : nullptr);
749 prop.SetSeedingErrors(false);
750 prop.SetFitInProjections(true);
751 prop.SetPropagateBzOnly(false);
752
753 GPUTPCGMLoopData& data = Merger->LoopData()[loopIdx];
754 prop.SetTrack(&data.param, data.alpha);
755 if (data.toSector == -1) {
756 data.param.AttachClustersMirror<1>(Merger, data.sector, data.row, data.track, data.toY, prop, true);
757 } else {
758 data.param.FollowCircle<1>(Merger, prop, data.sector, data.row, data.track, data.toAlpha, data.toX, data.toY, data.toSector, data.toRow, data.inFlyDirection, true);
759 }
760}
761
762template <int32_t I>
763GPUdic(0, 1) int32_t GPUTPCGMTrackParam::FollowCircle(const GPUTPCGMMerger* GPUrestrict() Merger, GPUTPCGMPropagator& GPUrestrict() prop, int32_t sector, int32_t iRow, int32_t iTrack, float toAlpha, float toX, float toY, int32_t toSector, int32_t toRow, bool inFlyDirection, bool phase2)
764{
765 static constexpr float kSectAngle = 2 * M_PI / 18.f;
766 if (Merger->Param().rec.tpc.disableRefitAttachment & 4) {
767 return 1;
768 }
769 const bool inExtraPass = Merger->Param().rec.tpc.looperInterpolationInExtraPass == -1 ? GPUCA_PAR_MERGER_SPLIT_LOOP_INTERPOLATION : Merger->Param().rec.tpc.looperInterpolationInExtraPass;
770 if (inExtraPass && phase2 == false) {
771 StoreAttachMirror(Merger, sector, iRow, iTrack, toAlpha, toY, toX, toSector, toRow, inFlyDirection, prop.GetAlpha());
772 return 1;
773 }
774 const GPUParam& GPUrestrict() param = Merger->Param();
775 bool right;
776 float dAlpha = toAlpha - prop.GetAlpha();
777 int32_t sectorSide = sector >= (GPUCA_NSECTORS / 2) ? (GPUCA_NSECTORS / 2) : 0;
778 if (CAMath::Abs(dAlpha) > 0.001f) {
779 right = CAMath::Abs(dAlpha) < CAMath::Pi() ? (dAlpha > 0) : (dAlpha < 0);
780 } else {
781 right = toY > mP[0];
782 }
783 bool up = (mP[2] < 0) ^ right;
784 int32_t targetRow = up ? (GPUCA_ROW_COUNT - 1) : 0;
785 float lrFactor = mP[2] < 0 ? -1.f : 1.f; // !(right ^ down) // TODO: shouldn't it be "right ? 1.f : -1.f", but that gives worse results...
786 // clang-format off
787 CADEBUG(printf("CIRCLE Track %d: Sector %d Alpha %f X %f Y %f Z %f SinPhi %f DzDs %f - Next hit: Sector %d Alpha %f X %f Y %f - Right %d Up %d dAlpha %f lrFactor %f\n", iTrack, sector, prop.GetAlpha(), mX, mP[0], mP[1], mP[2], mP[3], toSector, toAlpha, toX, toY, (int32_t)right, (int32_t)up, dAlpha, lrFactor));
788 // clang-format on
789
790 AttachClustersPropagate(Merger, sector, iRow, targetRow, iTrack, false, prop, inFlyDirection, 0.7f);
791 if (prop.RotateToAlpha(prop.GetAlpha() + (CAMath::Pi() / 2.f) * lrFactor)) {
792 return 1;
793 }
794 CADEBUG(printf("\tRotated: X %f Y %f Z %f SinPhi %f (Alpha %f / %f)\n", mP[0], mX, mP[1], mP[2], prop.GetAlpha(), prop.GetAlpha() + CAMath::Pi() / 2.f));
795 while (sector != toSector || FollowCircleChk(lrFactor, toY, toX, up, right)) {
796 while ((sector != toSector) ? (CAMath::Abs(mX) <= CAMath::Abs(mP[0]) * CAMath::Tan(kSectAngle / 2.f)) : FollowCircleChk(lrFactor, toY, toX, up, right)) {
797 int32_t err = prop.PropagateToXAlpha(mX + 1.f, prop.GetAlpha(), inFlyDirection);
798 if (err) {
799 CADEBUG(printf("\t\tpropagation error (%d)\n", err));
800 prop.RotateToAlpha(prop.GetAlpha() - (CAMath::Pi() / 2.f) * lrFactor);
801 return 1;
802 }
803 CADEBUG(printf("\tPropagated to y = %f: X %f Z %f SinPhi %f\n", mX, mP[0], mP[1], mP[2]));
804 for (int32_t j = 0; j < GPUCA_ROW_COUNT; j++) {
805 float rowX = GPUTPCGeometry::Row2X(j);
806 if (CAMath::Abs(rowX - (-mP[0] * lrFactor)) < 1.5f) {
807 CADEBUG(printf("\t\tAttempt row %d (Y %f Z %f)\n", j, mX * lrFactor, mP[1]));
808 AttachClusters(Merger, sector, j, iTrack, false, mX * lrFactor, mP[1]);
809 }
810 }
811 }
812 if (sector != toSector) {
813 if (right) {
814 if (++sector >= sectorSide + 18) {
815 sector -= 18;
816 }
817 } else {
818 if (--sector < sectorSide) {
819 sector += 18;
820 }
821 }
822 CADEBUG(printf("\tRotating to sector %d\n", sector));
823 if (prop.RotateToAlpha(param.Alpha(sector) + (CAMath::Pi() / 2.f) * lrFactor)) {
824 CADEBUG(printf("\t\trotation error\n"));
825 prop.RotateToAlpha(prop.GetAlpha() - (CAMath::Pi() / 2.f) * lrFactor);
826 return 1;
827 }
828 CADEBUG(printf("\tAfter Rotatin Alpha %f Position X %f Y %f Z %f SinPhi %f\n", prop.GetAlpha(), mP[0], mX, mP[1], mP[2]));
829 }
830 }
831 CADEBUG(printf("\tRotating back\n"));
832 for (int32_t i = 0; i < 2; i++) {
833 if (prop.RotateToAlpha(prop.GetAlpha() + (CAMath::Pi() / 2.f) * lrFactor) == 0) {
834 break;
835 }
836 if (i) {
837 CADEBUG(printf("Final rotation failed\n"));
838 return 1;
839 }
840 CADEBUG(printf("\tresetting physical model\n"));
841 prop.SetTrack(this, prop.GetAlpha());
842 }
843 prop.Rotate180();
844 CADEBUG(printf("\tMirrored position: Alpha %f X %f Y %f Z %f SinPhi %f DzDs %f\n", prop.GetAlpha(), mX, mP[0], mP[1], mP[2], mP[3]));
845 iRow = toRow;
846 float dx = toX - GPUTPCGeometry::Row2X(toRow);
847 if (up ^ (toX > mX)) {
848 if (up) {
849 while (iRow < GPUCA_ROW_COUNT - 2 && GPUTPCGeometry::Row2X(iRow + 1) + dx <= mX) {
850 iRow++;
851 }
852 } else {
853 while (iRow > 1 && GPUTPCGeometry::Row2X(iRow - 1) + dx >= mX) {
854 iRow--;
855 }
856 }
857 prop.PropagateToXAlpha(GPUTPCGeometry::Row2X(iRow) + dx, prop.GetAlpha(), inFlyDirection);
858 AttachClustersPropagate(Merger, sector, iRow, toRow, iTrack, false, prop, inFlyDirection);
859 }
860 if (prop.PropagateToXAlpha(toX, prop.GetAlpha(), inFlyDirection)) {
861 mX = toX;
862 }
863 CADEBUG(printf("Final position: Alpha %f X %f Y %f Z %f SinPhi %f DzDs %f\n", prop.GetAlpha(), mX, mP[0], mP[1], mP[2], mP[3]));
864 return (0);
865}
866
867template <int32_t I>
868GPUdni() void GPUTPCGMTrackParam::AttachClustersMirror(const GPUTPCGMMerger* GPUrestrict() Merger, int32_t sector, int32_t iRow, int32_t iTrack, float toY, GPUTPCGMPropagator& GPUrestrict() prop, bool phase2)
869{
870 static constexpr float kSectAngle = 2 * M_PI / 18.f;
871
872 if (Merger->Param().rec.tpc.disableRefitAttachment & 8) {
873 return;
874 }
875 const bool inExtraPass = Merger->Param().rec.tpc.looperInterpolationInExtraPass == -1 ? GPUCA_PAR_MERGER_SPLIT_LOOP_INTERPOLATION : Merger->Param().rec.tpc.looperInterpolationInExtraPass;
876 if (inExtraPass && phase2 == false) {
877 StoreAttachMirror(Merger, sector, iRow, iTrack, 0, toY, 0, -1, 0, 0, prop.GetAlpha());
878 return;
879 }
880 // Note that the coordinate system is rotated by 90 degree swapping X and Y!
881 float X = mP[2] > 0 ? mP[0] : -mP[0];
882 float toX = mP[2] > 0 ? toY : -toY;
883 float Y = mP[2] > 0 ? -mX : mX;
884 float Z = mP[1];
885 if (CAMath::Abs(mP[2]) >= GPUCA_MAX_SIN_PHI_LOW) {
886 return;
887 }
888 float SinPhi = CAMath::Sqrt(1 - mP[2] * mP[2]) * (mP[2] > 0 ? -1 : 1);
889 if (CAMath::Abs(SinPhi) >= GPUCA_MAX_SIN_PHI_LOW) {
890 return;
891 }
892 float b = prop.GetBz(prop.GetAlpha(), mX, mP[0], mP[1]);
893
894 int32_t count = CAMath::Float2IntRn(CAMath::Abs((toX - X) * 2.f));
895 if (count == 0) {
896 return;
897 }
898 float dx = (toX - X) / count;
899 const float myRowX = GPUTPCGeometry::Row2X(iRow);
900 // printf("AttachMirror\n");
901 // printf("X %f Y %f Z %f SinPhi %f toY %f -->\n", mX, mP[0], mP[1], mP[2], toY);
902 // printf("X %f Y %f Z %f SinPhi %f, count %d dx %f (to: %f)\n", X, Y, Z, SinPhi, count, dx, X + count * dx);
903 while (count--) {
904 float ex = CAMath::Sqrt(1 - SinPhi * SinPhi);
905 float exi = 1.f / ex;
906 float dxBzQ = dx * -b * mP[4];
907 float newSinPhi = SinPhi + dxBzQ;
908 if (CAMath::Abs(newSinPhi) > GPUCA_MAX_SIN_PHI_LOW) {
909 return;
910 }
911 float dS = dx * exi;
912 float h2 = dS * exi * exi;
913 float h4 = .5f * h2 * dxBzQ;
914
915 X += dx;
916 Y += dS * SinPhi + h4;
917 Z += dS * mP[3];
918 SinPhi = newSinPhi;
919 if (CAMath::Abs(X) > CAMath::Abs(Y) * CAMath::Tan(kSectAngle / 2.f)) {
920 continue;
921 }
922
923 // printf("count %d: At X %f Y %f Z %f SinPhi %f\n", count, mP[2] > 0 ? -Y : Y, mP[2] > 0 ? X : -X, Z, SinPhi);
924
925 float paramX = mP[2] > 0 ? -Y : Y;
926 int32_t step = paramX >= mX ? 1 : -1;
927 int32_t found = 0;
928 for (int32_t j = iRow; j >= 0 && j < GPUCA_ROW_COUNT && found < 3; j += step) {
929 float rowX = mX + GPUTPCGeometry::Row2X(j) - myRowX;
930 if (CAMath::Abs(rowX - paramX) < 1.5f) {
931 // printf("Attempt row %d\n", j);
932 AttachClusters(Merger, sector, j, iTrack, false, mP[2] > 0 ? X : -X, Z);
933 }
934 }
935 }
936}
937
938GPUd() void GPUTPCGMTrackParam::ShiftZ2(const GPUTPCGMMergedTrackHit* clusters, GPUTPCGMMergedTrackHitXYZ* clustersXYZ, const GPUTPCGMMerger* merger, int32_t N)
939{
940 float tzInner, tzOuter;
941 float xInner, xOuter;
942 if (N == 0) {
943 N = 1;
944 }
945 if (merger->Param().par.earlyTpcTransform) {
946 tzInner = clustersXYZ[N - 1].z;
947 tzOuter = clustersXYZ[0].z;
948 xInner = clustersXYZ[N - 1].x;
949 xOuter = clustersXYZ[0].x;
950 } else {
951 const auto& GPUrestrict() cls = merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear;
952 tzInner = cls[clusters[N - 1].num].getTime();
953 tzOuter = cls[clusters[0].num].getTime();
954 xInner = GPUTPCGeometry::Row2X(clusters[N - 1].row);
955 xOuter = GPUTPCGeometry::Row2X(clusters[0].row);
956 }
957 ShiftZ(merger, clusters[0].sector, tzInner, tzOuter, xInner, xOuter);
958}
959
960GPUd() void GPUTPCGMTrackParam::ShiftZ(const GPUTPCGMMerger* GPUrestrict() merger, int32_t sector, float tz1, float tz2, float x1, float x2)
961{
962 if (!merger->Param().par.continuousTracking) {
963 return;
964 }
965 const float r1 = CAMath::Max(0.0001f, CAMath::Abs(mP[4] * merger->Param().polynomialField.GetNominalBz()));
966
967 const float dist2 = mX * mX + mP[0] * mP[0];
968 const float dist1r2 = dist2 * r1 * r1;
969 float deltaZ = 0.f;
970 bool beamlineReached = false;
971 if (dist1r2 < 4) {
972 const float alpha = CAMath::ACos(1 - 0.5f * dist1r2); // Angle of a circle, such that |(cosa, sina) - (1,0)| == dist
973 const float beta = CAMath::ATan2(mP[0], mX);
974 const int32_t comp = mP[2] > CAMath::Sin(beta);
975 const float sinab = CAMath::Sin((comp ? 0.5f : -0.5f) * alpha + beta); // Angle of circle through origin and track position, to be compared to Snp
976 const float res = CAMath::Abs(sinab - mP[2]);
977
978 if (res < 0.2) {
979 const float r = 1.f / r1;
980 const float dS = alpha * r;
981 float z0 = dS * mP[3];
982 if (CAMath::Abs(z0) > GPUTPCGeometry::TPCLength()) {
983 z0 = z0 > 0 ? GPUTPCGeometry::TPCLength() : -GPUTPCGeometry::TPCLength();
984 }
985 deltaZ = mP[1] - z0;
986 beamlineReached = true;
987
988 // printf("X %9.3f Y %9.3f QPt %9.3f R %9.3f --> Alpha %9.3f Snp %9.3f Snab %9.3f Res %9.3f dS %9.3f z0 %9.3f\n", mX, mP[0], mP[4], r, alpha / 3.1415 * 180, mP[2], sinab, res, dS, z0);
989 }
990 }
991
992 if (!beamlineReached) {
993 if (merger->Param().par.earlyTpcTransform) {
994 float basez, basex;
995 if (CAMath::Abs(tz1) < CAMath::Abs(tz2)) {
996 basez = tz1;
997 basex = x1;
998 } else {
999 basez = tz2;
1000 basex = x2;
1001 }
1002 float refZ = ((basez > 0) ? merger->Param().rec.tpc.defaultZOffsetOverR : -merger->Param().rec.tpc.defaultZOffsetOverR) * basex;
1003 deltaZ = basez - refZ - mTZOffset;
1004 } else {
1005 float baset, basex;
1006 if (CAMath::Abs(tz1) > CAMath::Abs(tz2)) {
1007 baset = tz1;
1008 basex = x1;
1009 } else {
1010 baset = tz2;
1011 basex = x2;
1012 }
1013 float refZ = ((sector < GPUCA_NSECTORS / 2) ? merger->Param().rec.tpc.defaultZOffsetOverR : -merger->Param().rec.tpc.defaultZOffsetOverR) * basex;
1014 float basez;
1015 merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->TransformIdealZ(sector, baset, basez, mTZOffset);
1016 deltaZ = basez - refZ;
1017 }
1018 }
1019 if (merger->Param().par.earlyTpcTransform) {
1020 mTZOffset += deltaZ;
1021 mP[1] -= deltaZ;
1022 deltaZ = 0;
1023 float zMax = CAMath::Max(tz1, tz2);
1024 float zMin = CAMath::Min(tz1, tz2);
1025 // printf("Z Check: Clusters %f %f, min %f max %f vtx %f\n", tz1, tz2, zMin, zMax, mTZOffset);
1026 if (zMin < 0 && zMin - mTZOffset < -GPUTPCGeometry::TPCLength()) {
1027 deltaZ = zMin - mTZOffset + GPUTPCGeometry::TPCLength();
1028 } else if (zMax > 0 && zMax - mTZOffset > GPUTPCGeometry::TPCLength()) {
1029 deltaZ = zMax - mTZOffset - GPUTPCGeometry::TPCLength();
1030 }
1031 if (zMin < 0 && zMax - (mTZOffset + deltaZ) > 0) {
1032 deltaZ = zMax - mTZOffset;
1033 } else if (zMax > 0 && zMin - (mTZOffset + deltaZ) < 0) {
1034 deltaZ = zMin - mTZOffset;
1035 }
1036 // if (deltaZ != 0) printf("Moving clusters to TPC Range: Shift %f in Z: %f to %f --> %f to %f in Z\n", deltaZ, tz2 - mTZOffset, tz1 - mTZOffset, tz2 - mTZOffset - deltaZ, tz1 - mTZOffset - deltaZ);
1037 mTZOffset += deltaZ;
1038 mP[1] -= deltaZ;
1039 } else {
1040 float deltaT = merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convDeltaZtoDeltaTimeInTimeFrame(sector, deltaZ);
1041 mTZOffset += deltaT;
1042 mP[1] -= deltaZ;
1043 const float maxT = CAMath::Min(tz1, tz2) - merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->getT0();
1044 const float minT = CAMath::Max(tz1, tz2) - merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->getMaxDriftTime(sector);
1045 // printf("T Check: Clusters %f %f, min %f max %f vtx %f\n", tz1, tz2, minT, maxT, mTZOffset);
1046 deltaT = 0.f;
1047 if (mTZOffset < minT) {
1048 deltaT = minT - mTZOffset;
1049 }
1050 if (mTZOffset + deltaT > maxT) {
1051 deltaT = maxT - mTZOffset;
1052 }
1053 if (deltaT != 0.f) {
1054 deltaZ = merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convDeltaTimeToDeltaZinTimeFrame(sector, deltaT);
1055 // printf("Moving clusters to TPC Range: QPt %f, New mTZOffset %f, t1 %f, t2 %f, Shift %f in Z: %f to %f --> %f to %f in T\n", mP[4], mTZOffset + deltaT, tz1, tz2, deltaZ, tz2 - mTZOffset, tz1 - mTZOffset, tz2 - mTZOffset - deltaT, tz1 - mTZOffset - deltaT);
1056 mTZOffset += deltaT;
1057 mP[1] -= deltaZ;
1058 }
1059 }
1060 // printf("\n");
1061}
1062
1063GPUd() bool GPUTPCGMTrackParam::CheckCov() const
1064{
1065 const float* c = mC;
1066 bool ok = c[0] >= 0 && c[2] >= 0 && c[5] >= 0 && c[9] >= 0 && c[14] >= 0 && (c[1] * c[1] <= c[2] * c[0]) && (c[3] * c[3] <= c[5] * c[0]) && (c[4] * c[4] <= c[5] * c[2]) && (c[6] * c[6] <= c[9] * c[0]) && (c[7] * c[7] <= c[9] * c[2]) && (c[8] * c[8] <= c[9] * c[5]) &&
1067 (c[10] * c[10] <= c[14] * c[0]) && (c[11] * c[11] <= c[14] * c[2]) && (c[12] * c[12] <= c[14] * c[5]) && (c[13] * c[13] <= c[14] * c[9]);
1068 return ok;
1069}
1070
1071GPUd() bool GPUTPCGMTrackParam::CheckNumericalQuality(float overrideCovYY) const
1072{
1073 //* Check that the track parameters and covariance matrix are reasonable
1074 bool ok = CAMath::Finite(mX) && CAMath::Finite(mChi2);
1075 CADEBUG(printf("OK %d - %f - ", (int32_t)ok, mX); for (int32_t i = 0; i < 5; i++) { printf("%f ", mP[i]); } printf(" - "); for (int32_t i = 0; i < 15; i++) { printf("%f ", mC[i]); } printf("\n"));
1076 const float* c = mC;
1077 for (int32_t i = 0; i < 15; i++) {
1078 ok = ok && CAMath::Finite(c[i]);
1079 }
1080 CADEBUG(printf("OK1 %d\n", (int32_t)ok));
1081 for (int32_t i = 0; i < 5; i++) {
1082 ok = ok && CAMath::Finite(mP[i]);
1083 }
1084 CADEBUG(printf("OK2 %d\n", (int32_t)ok));
1085 if ((overrideCovYY > 0 ? overrideCovYY : c[0]) > 4.f * 4.f || c[2] > 4.f * 4.f || c[5] > 2.f * 2.f || c[9] > 2.f * 2.f) {
1086 ok = 0;
1087 }
1088 CADEBUG(printf("OK3 %d\n", (int32_t)ok));
1089 if (CAMath::Abs(mP[2]) > GPUCA_MAX_SIN_PHI) {
1090 ok = 0;
1091 }
1092 CADEBUG(printf("OK4 %d\n", (int32_t)ok));
1093 if (!CheckCov()) {
1094 ok = false;
1095 }
1096 CADEBUG(printf("OK5 %d\n", (int32_t)ok));
1097 return ok;
1098}
1099
1100GPUd() void GPUTPCGMTrackParam::RefitTrack(GPUTPCGMMergedTrack& GPUrestrict() track, int32_t iTrk, GPUTPCGMMerger* GPUrestrict() merger, int32_t attempt) // TODO: Inline me, once __forceinline__ is fixed by HIP
1101{
1102 if (!track.OK()) {
1103 return;
1104 }
1105
1106 // clang-format off
1107 CADEBUG(if (DEBUG_SINGLE_TRACK >= 0 && iTrk != DEBUG_SINGLE_TRACK) { track.SetNClusters(0); track.SetOK(0); return; } );
1108 // clang-format on
1109
1110 int32_t nTrackHits = track.NClusters();
1111 int32_t NTolerated = 0; // Clusters not fit but tollerated for track length cut
1112 GPUTPCGMTrackParam t = track.Param();
1113 float Alpha = track.Alpha();
1114 CADEBUG(int32_t nTrackHitsOld = nTrackHits; float ptOld = t.QPt());
1115 bool ok = t.Fit(merger, iTrk, merger->Clusters() + track.FirstClusterRef(), merger->Param().par.earlyTpcTransform ? merger->ClustersXYZ() + track.FirstClusterRef() : nullptr, nTrackHits, NTolerated, Alpha, attempt, GPUCA_MAX_SIN_PHI, &track.OuterParam());
1116 CADEBUG(printf("Finished Fit Track %d\n", iTrk));
1117 CADEBUG(printf("OUTPUT hits %d -> %d+%d = %d, QPt %f -> %f, SP %f, ok %d chi2 %f chi2ndf %f\n", nTrackHitsOld, nTrackHits, NTolerated, nTrackHits + NTolerated, ptOld, t.QPt(), t.SinPhi(), (int32_t)ok, t.Chi2(), t.Chi2() / CAMath::Max(1, nTrackHits)));
1118
1119 if (!ok && attempt == 0 && merger->Param().rec.tpc.retryRefit) {
1120 for (uint32_t i = 0; i < track.NClusters(); i++) {
1121 merger->Clusters()[track.FirstClusterRef() + i].state &= GPUTPCGMMergedTrackHit::clustererAndSharedFlags;
1122 }
1123 CADEBUG(printf("Track rejected, marking for retry\n"));
1124 if (merger->Param().rec.tpc.retryRefit == 2) {
1125 nTrackHits = track.NClusters();
1126 NTolerated = 0; // Clusters not fit but tollerated for track length cut
1127 t = track.Param();
1128 Alpha = track.Alpha();
1129 ok = t.Fit(merger, iTrk, merger->Clusters() + track.FirstClusterRef(), merger->ClustersXYZ() + track.FirstClusterRef(), nTrackHits, NTolerated, Alpha, 1, GPUCA_MAX_SIN_PHI, &track.OuterParam());
1130 } else {
1131 uint32_t nRefit = CAMath::AtomicAdd(&merger->Memory()->nRetryRefit, 1u);
1132 merger->RetryRefitIds()[nRefit] = iTrk;
1133 return;
1134 }
1135 }
1136 if (CAMath::Abs(t.QPt()) < 1.e-4f) {
1137 t.QPt() = 1.e-4f;
1138 }
1139
1140 CADEBUG(if (t.GetX() > 250) { printf("ERROR, Track %d at impossible X %f, Pt %f, Looper %d\n", iTrk, t.GetX(), CAMath::Abs(1.f / t.QPt()), (int32_t)merger->MergedTracks()[iTrk].Looper()); });
1141
1142 track.SetOK(ok);
1143 track.SetNClustersFitted(nTrackHits);
1144 track.Param() = t;
1145 track.Alpha() = Alpha;
1146
1147 // if (track.OK()) merger->DebugRefitMergedTrack(track);
1148}
1149
1150GPUd() void GPUTPCGMTrackParam::Rotate(float alpha)
1151{
1152 float cA, sA;
1153 CAMath::SinCos(alpha, sA, cA);
1154 float x0 = mX;
1155 float sinPhi0 = mP[2], cosPhi0 = CAMath::Sqrt(1 - mP[2] * mP[2]);
1156 float cosPhi = cosPhi0 * cA + sinPhi0 * sA;
1157 float sinPhi = -cosPhi0 * sA + sinPhi0 * cA;
1158 float j0 = cosPhi0 / cosPhi;
1159 float j2 = cosPhi / cosPhi0;
1160 mX = x0 * cA + mP[0] * sA;
1161 mP[0] = -x0 * sA + mP[0] * cA;
1162 mP[2] = sinPhi;
1163 mC[0] *= j0 * j0;
1164 mC[1] *= j0;
1165 mC[3] *= j0;
1166 mC[6] *= j0;
1167 mC[10] *= j0;
1168
1169 mC[3] *= j2;
1170 mC[4] *= j2;
1171 mC[5] *= j2 * j2;
1172 mC[8] *= j2;
1173 mC[12] *= j2;
1174 if (cosPhi < 0) { // change direction ( t0 direction is already changed in t0.UpdateValues(); )
1175 SinPhi() = -SinPhi();
1176 DzDs() = -DzDs();
1177 QPt() = -QPt();
1178 mC[3] = -mC[3];
1179 mC[4] = -mC[4];
1180 mC[6] = -mC[6];
1181 mC[7] = -mC[7];
1182 mC[10] = -mC[10];
1183 mC[11] = -mC[11];
1184 }
1185}
1186
1187GPUd() void GPUTPCGMTrackParam::AddCovDiagErrors(const float* GPUrestrict() errors2)
1188{
1189 mC[0] += errors2[0];
1190 mC[2] += errors2[1];
1191 mC[5] += errors2[2];
1192 mC[9] += errors2[3];
1193 mC[14] += errors2[4];
1194}
1195
1196GPUd() void GPUTPCGMTrackParam::AddCovDiagErrorsWithCorrelations(const float* GPUrestrict() errors2)
1197{
1198 const int32_t diagMap[5] = {0, 2, 5, 9, 14};
1199 const float oldDiag[5] = {mC[0], mC[2], mC[5], mC[9], mC[14]};
1200 for (int32_t i = 0; i < 5; i++) {
1201 mC[diagMap[i]] += errors2[i];
1202 for (int32_t j = 0; j < i; j++) {
1203 mC[diagMap[i - 1] + j + 1] *= gpu::CAMath::Sqrt(mC[diagMap[i]] * mC[diagMap[j]] / (oldDiag[i] * oldDiag[j]));
1204 }
1205 }
1206}
benchmark::State & state
Helper class to access correction maps.
uint64_t phase
Definition RawEventData.h:7
int16_t time
Definition RawEventData.h:4
int32_t i
#define GPUdic(...)
#define GPUAtomic(type)
#define GPUrestrict()
#define GPUglobalref()
#define GPUCA_DEBUG_STREAMER_CHECK(...)
#define GPUCA_RTC_CONSTEXPR
#define GPUCA_MAX_SIN_PHI_LOW
#define GPUCA_TRACKLET_SELECTOR_MIN_HITS_B5(QPTB5)
#define GPUCA_MAX_SIN_PHI
#define GPUCA_PAR_NO_ATOMIC_PRECHECK
#define GPUCA_PAR_MERGER_SPLIT_LOOP_INTERPOLATION
#define GPUCA_PAR_MERGER_INTERPOLATION_ERROR_TYPE_A
#define CADEBUG(...)
Definition GPUDef.h:79
#define GPUCA_GET_CONSTEXPR(obj, val)
int32_t retVal
uint8_t leg
GPUdii() void GPUTPCGMTrackParam
GPUdni() void GPUTPCGMTrackParam
#define DEBUG_SINGLE_TRACK
#define GPUCA_NSECTORS
#define GPUCA_ROW_COUNT
float float float & zMax
float float & zMin
uint32_t j
Definition RawData.h:0
uint32_t res
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
Definition of TPCFastTransform class.
double num
static GPUROOTDump< T, Args... > & get(const char *name1, Names... names)
Definition GPUROOTDump.h:58
float const GPUParam float int32_t int16_t int8_t sector
float int32_t const GPUParam & param
int32_t GPUTPCGMMergedTrackHit GPUTPCGMMergedTrackHitXYZ int32_t int32_t float & Alpha
int32_t int32_t int32_t bool float Y
const GPUParam float & alpha
GLfloat GLfloat GLfloat alpha
Definition glcorearb.h:279
GLsizei const GLuint const GLfloat * weights
Definition glcorearb.h:5475
GLint GLsizei count
Definition glcorearb.h:399
GLuint * ids
Definition glcorearb.h:647
GLuint GLfloat GLfloat GLfloat x1
Definition glcorearb.h:5034
GLdouble GLdouble right
Definition glcorearb.h:4077
GLuint GLuint GLfloat weight
Definition glcorearb.h:5477
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean * data
Definition glcorearb.h:298
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLfloat x0
Definition glcorearb.h:5034
GLenum clamp
Definition glcorearb.h:1245
GLboolean r
Definition glcorearb.h:1233
GLenum GLfloat param
Definition glcorearb.h:271
GLuint id
Definition glcorearb.h:650
GLuint GLfloat GLfloat y0
Definition glcorearb.h:5034
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
uint32_t calink
Definition GPUTPCDef.h:30
const float3 float float x2
Definition MathUtils.h:42
Global TPC definitions and constants.
Definition SimTraits.h:167
GPUd() void PIDResponse
Definition PIDResponse.h:71
value_T step
Definition TrackUtils.h:42
value_T maxT
Definition TrackUtils.h:132
@ streamUpdateTrack
stream update track informations
std::string getTime(uint64_t ts)
GPUCA_PAR_MERGER_INTERPOLATION_ERROR_TYPE_A errorZ
GPUCA_PAR_MERGER_INTERPOLATION_ERROR_TYPE_A errorY
InterpolationErrorHit hit[GPUCA_MERGER_MAX_TRACK_CLUSTERS]
std::vector< Cluster > clusters
std::vector< int > row