15#define GPUCA_CADEBUG 0
16#define DEBUG_SINGLE_TRACK -1
35#include "GPUParam.inc"
38#ifdef GPUCA_CADEBUG_ENABLED
43#ifndef GPUCA_GPUCODE_DEVICE
53 static constexpr float kDeg2Rad = M_PI / 180.f;
54 CADEBUG(
static constexpr float kSectAngle = 2 * M_PI / 18.f);
61 prop.SetMaterialTPC();
62 prop.SetPolynomialField(&
param.polynomialField);
63 prop.SetMaxSinPhi(maxSinPhi);
64 if (
param.rec.tpc.mergerInterpolateErrors) {
65 for (int32_t
i = 0;
i < N;
i++) {
70 const int32_t nWays =
param.rec.tpc.nWays;
71 const int32_t maxN = N;
72 int32_t ihitStart = 0;
74 float lastUpdateX = -1.f;
75 uint8_t lastRow = 255;
76 uint8_t lastSector = 255;
79 for (int32_t iWay = 0; iWay < nWays; iWay++) {
80 int32_t nMissed = 0, nMissed2 = 0;
81 float sumInvSqrtCharge = 0.f;
82 int32_t nAvgCharge = 0;
84 if (iWay && (iWay & 1) == 0) {
85 StoreOuter(&track.OuterParam(), prop.GetAlpha());
88 int32_t resetT0 = initResetT0();
89 const bool refit = (nWays == 1 || iWay >= 1);
90 const bool finalOutInFit = iWay + 2 >= nWays;
91 const bool finalFit = iWay == nWays - 1;
92 const float maxSinForUpdate = CAMath::Sin(70.f * kDeg2Rad);
95 prop.SetSeedingErrors(!(refit && attempt == 0));
96 prop.SetFitInProjections(
true);
97 prop.SetPropagateBzOnly(
param.rec.fitPropagateBzOnly == -1 ? !finalFit :
param.rec.fitPropagateBzOnly);
98 prop.SetMatLUT((
param.rec.useMatLUT && finalFit) ? merger->GetConstantMem()->calibObjects.matLUT :
nullptr);
99 prop.SetTrack(
this, iWay ? prop.GetAlpha() : Alpha);
101 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()));
105 const bool inFlyDirection = iWay & 1;
106 const int32_t wayDirection = (iWay & 1) ? -1 : 1;
108 int32_t goodRows = 0;
109 for (int32_t ihit = ihitStart; ihit >= 0 && ihit < maxN; ihit += wayDirection) {
110 const bool crossCE = lastSector != 255 && ((lastSector < 18) ^ (
clusters[ihit].sector < 18));
116 CADEBUG(printf(
"\tSkipping hit %d, %d hits rejected, flag %X\n", ihit, nMissed, (int32_t)
clusters[ihit].
state));
123 const bool allowChangeClusters = finalOutInFit && (nWays == 1 || ((iWay & 1) ? (ihit <= CAMath::Max(maxN / 2, maxN - 30)) : (ihit >= CAMath::Min(maxN / 2, 30))));
125 int32_t ihitMergeFirst = ihit;
126 uint8_t clusterState =
clusters[ihit].state;
131 merger->GetConstantMem()->calibObjects.fastTransformHelper->Transform(
clusters[ihit].sector,
clusters[ihit].
row, cl.getPad(), cl.getTime(), xx, yy, zz, mTOffset);
134 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));
138 if (MergeDoubleRowClusters(ihit, wayDirection,
clusters, merger, prop, xx, yy, zz, maxN, clAlpha, clusterState, allowChangeClusters) == -1) {
144 if (
param.rec.tpc.rejectIFCLowRadiusCluster) {
145 const float r2 = xx * xx + yy * yy;
146 const float rmax = (83.5f +
param.rec.tpc.sysClusErrorMinDist);
147 if (r2 < rmax * rmax) {
153 const auto& cluster =
clusters[ihit];
156 CADEBUG(printf(
"\tSector %2d %11sTrack 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.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]));
158 if (allowChangeClusters && lastRow != 255 && CAMath::Abs(cluster.row - lastRow) > 1) {
160 bool dodEdx =
param.dodEdxEnabled &&
param.rec.tpc.adddEdxSubThresholdClusters && finalFit && CAMath::Abs(cluster.row - lastRow) == 2;
161 dodEdx = AttachClustersPropagate(merger, cluster.sector, lastRow, cluster.row, iTrk, track.Leg() == 0, prop, inFlyDirection,
GPUCA_MAX_SIN_PHI, dodEdx);
163 dEdx.fillSubThreshold(lastRow - wayDirection);
165 dEdxAlt.fillSubThreshold(lastRow - wayDirection);
171 int32_t retValProp = prop.PropagateToXAlpha(xx, clAlpha, inFlyDirection);
173 CADEBUG(
if (!CheckCov()){printf(
"INVALID COV AFTER PROPAGATE!!!\n");});
175 if (retValProp == -2)
178 if (prop.PropagateToXAlpha(xx, prop.GetAlpha(), inFlyDirection) == 0) {
179 retValProp = prop.PropagateToXAlpha(xx, clAlpha, inFlyDirection);
182 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)) {
187 if (retValProp == 0) {
188 lastRow = cluster.row;
189 lastSector = cluster.
sector;
192 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 - PErr %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], retValProp));
196 if (
param.rec.tpc.addErrorsCECrossing) {
197 if (
param.rec.tpc.addErrorsCECrossing >= 2) {
198 AddCovDiagErrorsWithCorrelations(
param.rec.tpc.errorsCECrossing);
200 AddCovDiagErrors(
param.rec.tpc.errorsCECrossing);
202 }
else if (mC[2] < 0.5f) {
207 float uncorrectedY = -1e6f;
208 if (allowChangeClusters) {
209 uncorrectedY = AttachClusters(merger, cluster.sector, cluster.row, iTrk, track.Leg() == 0, prop);
212 const bool sinPhiErr = mNDF > 0 && CAMath::Abs(prop.GetSinPhi0()) >= maxSinForUpdate;
213 if (mNDF >= 0 && (mC[0] >
param.rec.tpc.trackFitCovLimit || mC[2] >
param.rec.tpc.trackFitCovLimit)) {
216 if (retValProp || sinPhiErr) {
220 CADEBUG(printf(
", %d --- break\n", (int32_t)sinPhiErr));
225 int32_t retValUpd = 0, retValInt = 0;
226 float threshold = 3.f + (lastUpdateX >= 0 ? (CAMath::Abs(mX - lastUpdateX) / 2) : 0.f);
227 if (mNDF > (int32_t)
param.rec.tpc.mergerNonInterpolateRejectMinNDF && (CAMath::Abs(yy - mP[0]) > threshold || CAMath::Abs(zz - mP[1]) > threshold)) {
230 int8_t rejectChi2 = 0;
232 if (
param.rec.tpc.mergerInterpolateErrors && CAMath::Abs(ihit - ihitMergeFirst) <= 1) {
233 if (iWay == nWays - 3) {
235 }
else if (iWay == nWays - 2) {
237 }
else if (iWay == nWays - 1) {
241 rejectChi2 = allowChangeClusters && goodRows > 5;
246 const float time = merger->GetConstantMem()->ioPtrs.clustersNative ? merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[cluster.num].getTime() : -1.f;
247 const float invSqrtCharge = merger->GetConstantMem()->ioPtrs.clustersNative ? CAMath::InvSqrt(merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[cluster.num].qMax) : 0.f;
248 const float invCharge = merger->GetConstantMem()->ioPtrs.clustersNative ? (1.f / merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[cluster.num].qMax) : 0.f;
249 float invAvgCharge = (sumInvSqrtCharge += invSqrtCharge) / ++nAvgCharge;
250 invAvgCharge *= invAvgCharge;
252 prop.GetErr2(err2Y, err2Z,
param, zz, cluster.row, clusterState, cluster.sector,
time, invAvgCharge, invCharge);
258 retValInt = prop.InterpolateReject(
param, yy, zz, clusterState, rejectChi2, &interpolation.
hit[ihit], err2Y, err2Z, deltaZ);
262 if (
param.rec.tpc.rejectEdgeClustersInTrackFit && uncorrectedY > -1e6f &&
param.rejectEdgeClusterByY(uncorrectedY, cluster.row, CAMath::Sqrt(mC[0]))) {
265 retValUpd = prop.Update(yy, zz, cluster.row,
param, clusterState, rejectChi2, refit, err2Y, err2Z);
268 merger->DebugStreamerUpdate(iTrk, ihit, xx, yy, zz, cluster, merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[cluster.num], *
this, prop, interpolation.
hit[ihit], rejectChi2, refit, retValUpd, sumInvSqrtCharge / nAvgCharge * sumInvSqrtCharge / nAvgCharge, yy, zz, clusterState, retValInt, err2Y, err2Z);
272 CADEBUG(
if (!CheckCov()) GPUError(
"INVALID COV AFTER UPDATE!!!"));
273 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 - FErr %d %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], retValUpd, retValInt));
277 if (!retValUpd && !retValInt)
281 nMissed = nMissed2 = 0;
285 float dy = mP[0] - prop.Model().
Y();
286 float dz = mP[1] - prop.Model().
Z();
287 if (CAMath::Abs(mP[4]) *
param.qptB5Scaler > 10 && --resetT0 <= 0 && CAMath::Abs(mP[2]) < 0.15f && dy * dy + dz * dz > 1) {
288 CADEBUG(printf(
"Reinit linearization\n"));
289 prop.SetTrack(
this, prop.GetAlpha());
292 if (
param.dodEdxEnabled && finalFit) {
293 bool acc = (clusterState &
param.rec.tpc.dEdxClusterRejectionFlagMask) == 0, accAlt = (clusterState &
param.rec.tpc.dEdxClusterRejectionFlagMaskAlt) == 0;
295 float qtot = 0, qmax = 0, pad = 0, relTime = 0;
296 const int32_t clusterCount = (ihit - ihitMergeFirst) * wayDirection + 1;
297 for (int32_t iTmp = ihitMergeFirst; iTmp != ihit + wayDirection; iTmp += wayDirection) {
298 const ClusterNative& cl = merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[cluster.num];
300 qmax = CAMath::Max<float>(qmax, cl.
qMax);
302 relTime += cl.getTime();
304 qtot /= clusterCount;
306 relTime /= clusterCount;
307 relTime = relTime - CAMath::Round(relTime);
309 dEdx.fillCluster(qtot, qmax, cluster.row, cluster.sector, mP[2], mP[3], merger->GetConstantMem()->calibObjects, zz, pad, relTime);
313 dEdxAlt.fillCluster(qtot, qmax, cluster.row, cluster.sector, mP[2], mP[3], merger->GetConstantMem()->calibObjects, zz, pad, relTime);
320 if (retValInt || allowChangeClusters) {
322 }
else if (finalFit) {
333 if (finalOutInFit && !(merger->Param().rec.tpc.disableRefitAttachment & 4) && lastRow != 255 && lastSector != 255) {
334 StoreLoopPropagation(merger, lastSector, lastRow, iTrk, lastRow >
clusters[(iWay & 1) ? (maxN - 1) : 0].row, prop.GetAlpha());
335 CADEBUG(printf(
"\t\tSTORING %d lastRow %d row %d out %d\n", iTrk, (
int)lastRow, (
int)
clusters[(iWay & 1) ? (maxN - 1) : 0].row, lastRow >
clusters[(iWay & 1) ? (maxN - 1) : 0].row));
337 if (!(iWay & 1) && !finalFit && !track.CCE() && !track.Looper()) {
338 deltaZ = ShiftZ(
clusters, merger, maxN);
346 o2::utils::DebugStreamer::instance()->getStreamer(
"debug_accept_track",
"UPDATE") << o2::utils::DebugStreamer::instance()->getUniqueTreeName(
"debug_accept_track").data() <<
"iTrk=" << iTrk <<
"outerParam=" << track.OuterParam() <<
"track=" <<
this <<
"ihitStart=" << ihitStart <<
"\n";
352 if (
param.rec.tpc.minNClustersFinalTrack != -1 && N + NTolerated <
param.rec.tpc.minNClustersFinalTrack) {
356 if (
param.par.dodEdx &&
param.dodEdxEnabled) {
357 dEdx.computedEdx(merger->MergedTracksdEdx()[iTrk],
param);
359 dEdxAlt.computedEdx(merger->MergedTracksdEdxAlt()[iTrk],
param);
362 Alpha = prop.GetAlpha();
363 MoveToReference(prop,
param, Alpha);
364 NormalizeAlpha(Alpha);
371 static constexpr float kDeg2Rad = M_PI / 180.f;
372 static constexpr float kSectAngle = 2 * M_PI / 18.f;
374 if (
param.rec.tpc.trackReferenceX <= 500) {
376 float saveAlpha = Alpha;
377 for (int32_t attempt = 0; attempt < 3; attempt++) {
378 float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / kDeg2Rad / 20.f) * kSectAngle;
380 if (prop.PropagateToXAlpha(
param.rec.tpc.trackReferenceX, Alpha, 0)) {
384 if (CAMath::Abs(mP[0]) <= mX * CAMath::Tan(kSectAngle / 2.f)) {
391 if (CAMath::Abs(mP[0]) > mX * CAMath::Tan(kSectAngle / 2.f)) {
392 float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / kDeg2Rad / 20.f) * kSectAngle;
401 if (mirrorParameters) {
402 prop.Mirror(inFlyDirection);
405 prop.GetErr2(err2Y, err2Z,
param, toZ,
row, clusterState, sector, -1.f, 0.f, 0.f);
406 prop.Model().
Y() = mP[0] = toY;
407 prop.Model().Z() = mP[1] = toZ;
414 if (CAMath::Abs(mC[5]) < 0.1f) {
415 mC[5] = mC[5] > 0 ? 0.1f : -0.1f;
420 mC[1] = mC[4] = mC[6] = mC[8] = mC[11] = mC[13] = 0;
421 prop.SetTrack(
this, prop.GetAlpha());
426GPUd() int32_t
GPUTPCGMTrackParam::MergeDoubleRowClusters(int32_t& ihit, int32_t wayDirection,
GPUTPCGMMergedTrackHit*
GPUrestrict()
clusters, 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)
429 float maxDistY, maxDistZ;
430 prop.GetErr2(maxDistY, maxDistZ, merger->Param(), zz,
clusters[ihit].row, 0,
clusters[ihit].sector, -1.f, 0.f, 0.f);
431 maxDistY = (maxDistY + mC[0]) * 20.f;
432 maxDistZ = (maxDistZ + mC[2]) * 20.f;
433 int32_t noReject = 0;
434 if (CAMath::Abs(clAlpha - prop.GetAlpha()) > 1.e-4f) {
435 noReject = prop.RotateToAlpha(clAlpha);
437 float projY = 0, projZ = 0;
439 noReject |= prop.GetPropagatedYZ(xx, projY, projZ);
446 float clamp = cl.qTot;
448 merger->GetConstantMem()->calibObjects.fastTransformHelper->Transform(
clusters[ihit].sector,
clusters[ihit].
row, cl.getPad(), cl.
getTime(), clx, cly, clz, mTOffset);
449 float dy = cly - projY;
450 float dz = clz - projZ;
451 if (noReject == 0 && (dy * dy > maxDistY || dz * dz > maxDistZ)) {
452 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));
457 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)));
461 clusterState |=
clusters[ihit].state;
464 if (!(ihit + wayDirection >= 0 && ihit + wayDirection < maxN &&
clusters[ihit].
row ==
clusters[ihit + wayDirection].
row &&
clusters[ihit].sector ==
clusters[ihit + wayDirection].sector)) {
467 ihit += wayDirection;
470 CADEBUG(printf(
"\t\tNo matching cluster in double-row, skipping\n"));
484 Merger->GetConstantMem()->calibObjects.fastTransformHelper->InverseTransformYZtoX(sector, iRow, mP[0], mP[1], X);
485 if (prop.GetPropagatedYZ(X, Y, Z)) {
489 return AttachClusters(Merger, sector, iRow, iTrack, goodLeg, Y, Z);
494 if (Merger->Param().rec.tpc.disableRefitAttachment & 1) {
501 if (
row.NHits() == 0) {
505 const float zOffset = Merger->Param().par.continuousTracking ? Merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(sector, mTOffset, Merger->Param().continuousMaxTimeBin) : 0;
506 const float y0 =
row.Grid().YMin();
507 const float stepY =
row.HstepY();
508 const float z0 =
row.Grid().ZMin() - zOffset;
509 const float stepZ =
row.HstepZ();
512 bool protect = CAMath::Abs(GetQPt() * Merger->Param().qptB5Scaler) <= Merger->Param().rec.tpc.rejectQPtB5 && goodLeg;
515 Merger->Param().GetClusterErrors2(sector, iRow, Z, mP[2], mP[3], -1.f, 0.f, 0.f, err2Y, err2Z);
516 const float tubeMaxSize2 = protect ? Merger->Param().rec.tpc.tubeProtectMaxSize2 : Merger->Param().rec.tpc.tubeRemoveMaxSize2;
517 const float tubeMinSize2 = protect ? Merger->Param().rec.tpc.tubeProtectMinSize2 : 0.f;
518 const float tubeSigma2 = protect ? Merger->Param().rec.tpc.tubeProtectSigma2 : Merger->Param().rec.tpc.tubeRemoveSigma2;
519 const float sy2 = CAMath::Max(tubeMinSize2, CAMath::Min(tubeMaxSize2, tubeSigma2 * (err2Y + CAMath::Abs(mC[0]))));
520 const float sz2 = CAMath::Max(tubeMinSize2, CAMath::Min(tubeMaxSize2, tubeSigma2 * (err2Z + CAMath::Abs(mC[2]))));
521 const float tubeY = CAMath::Sqrt(sy2);
522 const float tubeZ = CAMath::Sqrt(sz2);
523 const float sy21 = 1.f / sy2;
524 const float sz21 = 1.f / sz2;
525 float uncorrectedY, uncorrectedZ;
526 Merger->GetConstantMem()->calibObjects.fastTransformHelper->InverseTransformYZtoNominalYZ(sector, iRow, Y, Z, uncorrectedY, uncorrectedZ);
528 if (CAMath::Abs(uncorrectedY) >
row.getTPCMaxY()) {
531 row.Grid().GetBinArea(uncorrectedY, uncorrectedZ + zOffset, tubeY, tubeZ, bin, ny, nz);
533 const int32_t nBinsY =
row.Grid().Ny();
534 const int32_t idOffset = tracker.Data().ClusterIdOffset();
535 const int32_t*
ids = &(tracker.Data().ClusterDataIndex()[
row.HitNumberOffset()]);
545 for (int32_t k = 0; k <= nz; k++) {
546 const int32_t mybin = bin + k * nBinsY;
547 const uint32_t hitFst = firsthit[mybin];
548 const uint32_t hitLst = firsthit[mybin + ny + 1];
549 for (uint32_t ih = hitFst; ih < hitLst; ih++) {
550 int32_t
id = idOffset +
ids[ih];
553 if (myWeight <= *
weight) {
557 const cahit2 hh = hits[ih];
558 const float y =
y0 + hh.
x * stepY;
559 const float z = z0 + hh.
y * stepZ;
560 const float dy =
y - uncorrectedY;
561 const float dz =
z - uncorrectedZ;
562 if (dy * dy * sy21 + dz * dz * sz21 <= CAMath::Sqrt(2.f)) {
564 CAMath::AtomicMax(
weight, myWeight);
573 static constexpr float kSectAngle = 2 * M_PI / 18.f;
574 if (Merger->Param().rec.tpc.disableRefitAttachment & 2) {
577 if (CAMath::Abs(lastRow - toRow) < 2) {
580 int32_t
step = toRow > lastRow ? 1 : -1;
581 float xx = mX - GPUTPCGeometry::Row2X(lastRow);
582 for (int32_t iRow = lastRow + step; iRow != toRow; iRow +=
step) {
583 if (CAMath::Abs(mP[2]) > maxSinPhi) {
586 if (CAMath::Abs(mP[0]) > CAMath::Abs(mX) * CAMath::Tan(kSectAngle / 2.f)) {
589 int32_t err = prop.PropagateToXAlpha(xx + GPUTPCGeometry::Row2X(iRow), prop.GetAlpha(), inFlyDirection);
593 if (dodEdx && iRow + step == toRow) {
594 float yUncorrected, zUncorrected;
595 Merger->GetConstantMem()->calibObjects.fastTransformHelper->InverseTransformYZtoNominalYZ(sector, iRow, mP[0], mP[1], yUncorrected, zUncorrected);
596 uint32_t pad = CAMath::Float2UIntRn(GPUTPCGeometry::LinearY2Pad(sector, iRow, yUncorrected));
597 if (pad >= GPUTPCGeometry::NPads(iRow) || (Merger->GetConstantMem()->calibObjects.dEdxCalibContainer && Merger->GetConstantMem()->calibObjects.dEdxCalibContainer->isDead(sector, iRow, pad))) {
601 CADEBUG(printf(
"Attaching in row %d\n", iRow));
602 AttachClusters(Merger, sector, iRow, iTrack, goodLeg, prop);
609 CADEBUG(printf(
"\t%21sStorO Alpha %8.3f , X %8.3f - Y %8.3f, Z %8.3f - QPt %7.2f, SP %5.2f --- Cov sY %8.3f sZ %8.3f sSP %8.3f sPt %8.3f\n",
"",
alpha, mX, mP[0], mP[1], mP[4], mP[2], sqrtf(mC[0]), sqrtf(mC[2]), sqrtf(mC[5]), sqrtf(mC[14])));
610 for (int32_t
i = 0;
i < 5;
i++) {
611 outerParam->P[
i] = mP[
i];
613 for (int32_t
i = 0;
i < 15;
i++) {
614 outerParam->C[
i] = mC[
i];
617 outerParam->alpha =
alpha;
628 if (CAMath::Abs(mP[2]) < 0.75) {
631 if ((mP[2] * mP[4] < 0) ^ outwards) {
635 uint32_t nLoopData = CAMath::AtomicAdd(&Merger->Memory()->nLoopData, 1u);
636 if (nLoopData >= Merger->NMaxTracks()) {
637 Merger->raiseError(GPUErrors::ERROR_MERGER_LOOPER_OVERFLOW, nLoopData, Merger->NMaxTracks());
638 CAMath::AtomicExch(&Merger->Memory()->nLoopData, Merger->NMaxTracks());
647 data.outwards = outwards;
648 Merger->LoopData()[nLoopData] =
data;
654 prop.SetMaterialTPC();
655 prop.SetPolynomialField(&Merger->Param().polynomialField);
657 prop.SetMatLUT(Merger->Param().rec.useMatLUT ? Merger->GetConstantMem()->calibObjects.matLUT : nullptr);
658 prop.SetSeedingErrors(
false);
659 prop.SetFitInProjections(
true);
660 prop.SetPropagateBzOnly(
false);
663 prop.SetTrack(&
data.param,
data.alpha);
667 data.param.AttachClustersLooperFollow(Merger, prop,
data.sector,
data.row,
data.track,
data.outwards);
674 bool inFlyDirection = (Merger->MergedTracks()[iTrack].Leg() & 1) ^ up;
676 static constexpr float kSectAngle = 2 * M_PI / 18.f;
678 bool right = (mP[2] < 0) ^ up;
680 float lrFactor =
right ^ !up ? 1.f : -1.f;
682 CADEBUG(printf(
"\nCIRCLE Track %d: Sector %d Alpha %f X %f Y %f Z %f SinPhi %f DzDs %f QPt %f - Right %d Up %d lrFactor %f\n", iTrack, sector, prop.GetAlpha(), mX, mP[0], mP[1], mP[2], mP[3], mP[4], (int32_t)
right, (int32_t)up, lrFactor));
685 if (prop.RotateToAlpha(prop.GetAlpha() + (CAMath::Pi() / 2.f) * lrFactor)) {
688 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));
689 uint32_t maxTries = 100;
691 while (CAMath::Abs(mX) <= CAMath::Abs(mP[0]) * CAMath::Tan(kSectAngle / 2.f) + 0.1f) {
692 if (maxTries-- == 0) {
695 if (CAMath::Abs(mP[2]) > 0.7f) {
698 if (up ? (-mP[0] * lrFactor > GPUTPCGeometry::Row2X(
GPUCA_ROW_COUNT - 1)) : (-mP[0] * lrFactor < GPUTPCGeometry::Row2X(0))) {
701 if (!((up ? (-mP[0] * lrFactor >= toX) : (-mP[0] * lrFactor <= toX)) || (
right ^ (mP[2] > 0)))) {
704 int32_t err = prop.PropagateToXAlpha(mX + (up ? 1.f : -1.f), prop.GetAlpha(), inFlyDirection);
706 CADEBUG(printf(
"\t\tpropagation error (%d)\n", err));
709 CADEBUG(printf(
"\tPropagated to y = %f: X %f Z %f SinPhi %f\n", mX, mP[0], mP[1], mP[2]));
711 float rowX = GPUTPCGeometry::Row2X(
j);
712 if (CAMath::Abs(rowX - (-mP[0] * lrFactor)) < 1.5f) {
713 CADEBUG(printf(
"\t\tAttempt row %d (X %f Y %f Z %f)\n",
j, rowX, mX * lrFactor, mP[1]));
714 AttachClusters(Merger, sector,
j, iTrack,
false, mX * lrFactor, mP[1]);
718 if (maxTries-- == 0) {
722 if (++sector >= sectorSide + 18) {
726 if (--sector < sectorSide) {
730 CADEBUG(printf(
"\tRotating to sector %d: %f --> %f\n", sector, prop.GetAlpha(),
param.Alpha(sector) + (CAMath::Pi() / 2.f) * lrFactor));
731 int32_t err = prop.RotateToAlpha(
param.Alpha(sector) + (CAMath::Pi() / 2.f) * lrFactor);
733 CADEBUG(printf(
"Rotation Error %d\n", err));
736 CADEBUG(printf(
"\tAfter Rotating Alpha %f Position X %f Y %f Z %f SinPhi %f\n", prop.GetAlpha(), mP[0], mX, mP[1], mP[2]));
742 static constexpr float kSectAngle = 2 * M_PI / 18.f;
744 float X = mP[2] > 0 ? mP[0] : -mP[0];
745 float Y = mP[2] > 0 ? -mX : mX;
747 float SinPhi = CAMath::Sqrt(1 - mP[2] * mP[2]) * (mP[2] > 0 ? -1 : 1);
748 float b = prop.GetBz(prop.GetAlpha(), mX, mP[0], mP[1]);
750 float dx = outwards ? 1.f : -1.f;
751 const float myRowX = GPUTPCGeometry::Row2X(iRow);
755 uint32_t maxTries = 100;
757 float ex = CAMath::Sqrt(1 - SinPhi * SinPhi);
758 float exi = 1.f / ex;
759 float dxBzQ = dx * -
b * mP[4];
760 float newSinPhi = SinPhi + dxBzQ;
765 if (mP[2] > 0 ? (newSinPhi > 0.5) : (newSinPhi < -0.5)) {
770 float h2 = dS * exi * exi;
771 float h4 = .5f * h2 * dxBzQ;
774 Y += dS * SinPhi + h4;
777 if (CAMath::Abs(X) > CAMath::Abs(Y) * CAMath::Tan(kSectAngle / 2.f)) {
783 float paramX = mP[2] > 0 ? -Y : Y;
784 int32_t
step = outwards ? 1 : -1;
787 float rowX = mX + GPUTPCGeometry::Row2X(
j) - myRowX;
788 if (CAMath::Abs(rowX - paramX) < 1.5f) {
790 AttachClusters(Merger, sector,
j, iTrack,
false, mP[2] > 0 ? X : -X, Z);
801 const auto&
GPUrestrict() cls = merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear;
803 const auto tmp = zn > z0 ?
std::
array<
float, 3>{zn, z0, GPUTPCGeometry::Row2X(
clusters[N - 1].
row)} : std::array<float, 3>{z0, zn, GPUTPCGeometry::Row2X(
clusters[0].
row)};
804 return ShiftZ(merger,
clusters[0].sector, tmp[0], tmp[1], tmp[2]);
809 if (!merger->Param().par.continuousTracking) {
813 bool beamlineReached =
false;
814 const float r1 = CAMath::Max(0.0001f, CAMath::Abs(mP[4] * merger->Param().polynomialField.GetNominalBz()));
816 const float dist2 = mX * mX + mP[0] * mP[0];
817 const float dist1r2 = dist2 * r1 * r1;
819 const float alpha = CAMath::ACos(1 - 0.5f * dist1r2);
820 const float beta = CAMath::ATan2(mP[0], mX);
821 const int32_t comp = mP[2] > CAMath::Sin(beta);
822 const float sinab = CAMath::Sin((comp ? 0.5f : -0.5f) *
alpha + beta);
823 const float res = CAMath::Abs(sinab - mP[2]);
826 const float r = 1.f / r1;
827 const float dS =
alpha *
r;
828 float z0 = dS * mP[3];
829 if (CAMath::Abs(z0) > GPUTPCGeometry::TPCLength()) {
830 z0 = z0 > 0 ? GPUTPCGeometry::TPCLength() : -
GPUTPCGeometry::TPCLength();
833 beamlineReached =
true;
840 if (!beamlineReached) {
841 float refZ = ((sector <
GPUCA_NSECTORS / 2) ? merger->Param().rec.tpc.defaultZOffsetOverR : -merger->Param().rec.tpc.defaultZOffsetOverR) * clx;
843 merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->TransformIdealZ(sector, cltmax, basez, mTOffset);
844 deltaZ = basez - refZ;
847 float deltaT = merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convDeltaZtoDeltaTimeInTimeFrame(sector, deltaZ);
849 const float maxT = cltmin - merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->getT0();
850 const float minT = cltmax - merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->getMaxDriftTime(sector);
853 if (mTOffset < minT) {
854 deltaT = minT - mTOffset;
856 if (mTOffset + deltaT > maxT) {
857 deltaT =
maxT - mTOffset;
860 deltaZ += merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convDeltaTimeToDeltaZinTimeFrame(sector, deltaT);
873 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]) &&
874 (
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]);
881 bool ok = CAMath::Finite(mX) && CAMath::Finite(mChi2);
884 for (int32_t
i = 0;
i < 15;
i++) {
885 ok = ok && CAMath::Finite(
c[
i]);
887 for (int32_t
i = 0;
i < 5;
i++) {
888 ok = ok && CAMath::Finite(mP[
i]);
890 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) {
912 int32_t nTrackHits = track.NClusters();
913 int32_t NTolerated = 0;
915 float Alpha = track.
Alpha();
916 CADEBUG(int32_t nTrackHitsOld = nTrackHits;
float ptOld = t.QPt());
917 bool ok = t.Fit(merger, iTrk, merger->Clusters() + track.FirstClusterRef(), nTrackHits, NTolerated, Alpha, attempt,
GPUCA_MAX_SIN_PHI, track);
918 CADEBUG(printf(
"Finished Fit Track %d\n", iTrk));
919 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)));
921 if (!ok && attempt == 0 && merger->Param().rec.tpc.retryRefit) {
922 for (uint32_t
i = 0;
i < track.NClusters();
i++) {
925 CADEBUG(printf(
"Track rejected, marking for retry\n"));
926 if (merger->Param().rec.tpc.retryRefit == 2) {
927 nTrackHits = track.NClusters();
930 Alpha = track.
Alpha();
931 ok = t.Fit(merger, iTrk, merger->Clusters() + track.FirstClusterRef(), nTrackHits, NTolerated, Alpha, 1,
GPUCA_MAX_SIN_PHI, track);
933 uint32_t nRefit = CAMath::AtomicAdd(&merger->Memory()->nRetryRefit, 1u);
934 merger->RetryRefitIds()[nRefit] = iTrk;
938 if (CAMath::Abs(t.QPt()) < 1.e-4f) {
942 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()); });
945 track.SetNClustersFitted(nTrackHits);
947 track.
Alpha() = Alpha;
955 CAMath::SinCos(
alpha, sA, cA);
957 float sinPhi0 = mP[2], cosPhi0 = CAMath::Sqrt(1 - mP[2] * mP[2]);
958 float cosPhi = cosPhi0 * cA + sinPhi0 * sA;
959 float sinPhi = -cosPhi0 * sA + sinPhi0 * cA;
960 float j0 = cosPhi0 / cosPhi;
961 float j2 = cosPhi / cosPhi0;
962 mX =
x0 * cA + mP[0] * sA;
963 mP[0] = -
x0 * sA + mP[0] * cA;
977 SinPhi() = -SinPhi();
995 mC[14] += errors2[4];
1000 const int32_t diagMap[5] = {0, 2, 5, 9, 14};
1001 const float oldDiag[5] = {mC[0], mC[2], mC[5], mC[9], mC[14]};
1002 for (int32_t
i = 0;
i < 5;
i++) {
1003 mC[diagMap[
i]] += errors2[
i];
1004 for (int32_t
j = 0;
j <
i;
j++) {
1005 mC[diagMap[
i - 1] +
j + 1] *= gpu::CAMath::Sqrt(mC[diagMap[
i]] * mC[diagMap[
j]] / (oldDiag[
i] * oldDiag[
j]));
Helper class to access correction maps.
#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_INTERPOLATION_ERROR_TYPE_A
#define GPUCA_GET_CONSTEXPR(obj, val)
GPUdii() void GPUTPCGMTrackParam
GPUdni() void GPUTPCGMTrackParam
#define DEBUG_SINGLE_TRACK
float int32_t const GPUParam int16_t int8_t bool int8_t sector
float int32_t const GPUParam & param
@ updateErrorClusterRejectedDistance
@ updateErrorClusterRejected
@ updateErrorClusterRejectedEdge
int32_t GPUTPCGMMergedTrackHit int32_t int32_t float & Alpha
int32_t GPUTPCGMMergedTrackHit int32_t int32_t float int32_t float GPUTPCGMMergedTrack & track
int32_t int32_t int32_t bool float Y
GLfloat GLfloat GLfloat alpha
GLsizei const GLuint const GLfloat * weights
GLuint GLuint GLfloat weight
GLboolean GLboolean GLboolean b
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLfloat GLfloat y0
GLdouble GLdouble GLdouble z
Global TPC definitions and constants.
GPUdi() T BetheBlochAleph(T bg
@ streamUpdateTrack
stream update track informations
Defining DataPointCompositeObject explicitly as copiable.
std::string getTime(uint64_t ts)
@ clustererAndSharedFlags
GPUCA_PAR_MERGER_INTERPOLATION_ERROR_TYPE_A errorY
InterpolationErrorHit hit[GPUCA_MERGER_MAX_TRACK_CLUSTERS]
std::vector< Cluster > clusters