15#define GPUCA_CADEBUG 0
16#define DEBUG_SINGLE_TRACK -1
17#define EXTRACT_RESIDUALS 0
19#if EXTRACT_RESIDUALS == 1
40#include "GPUParam.inc"
43#ifdef GPUCA_CADEBUG_ENABLED
48#ifndef GPUCA_GPUCODE_DEVICE
58 static constexpr float kDeg2Rad = M_PI / 180.f;
59 CADEBUG(
static constexpr float kSectAngle = 2 * M_PI / 18.f);
66 prop.SetMaterialTPC();
67 prop.SetPolynomialField(&
param.polynomialField);
68 prop.SetMaxSinPhi(maxSinPhi);
69 if (
param.rec.tpc.mergerInterpolateErrors) {
70 for (int32_t
i = 0;
i < N;
i++) {
75 const int32_t nWays =
param.rec.tpc.nWays;
76 const int32_t maxN = N;
77 int32_t ihitStart = 0;
79 float lastUpdateX = -1.f;
80 uint8_t lastRow = 255;
81 uint8_t lastSector = 255;
84 for (int32_t iWay = 0; iWay < nWays; iWay++) {
85 int32_t nMissed = 0, nMissed2 = 0;
86 float sumInvSqrtCharge = 0.f;
87 int32_t nAvgCharge = 0;
89 if (iWay && (iWay & 1) == 0) {
90 StoreOuter(&track.OuterParam(), prop.GetAlpha());
93 int32_t resetT0 = initResetT0();
94 const bool refit = (nWays == 1 || iWay >= 1);
95 const bool finalOutInFit = iWay + 2 >= nWays;
96 const bool finalFit = iWay == nWays - 1;
97 const float maxSinForUpdate = CAMath::Sin(70.f * kDeg2Rad);
100 prop.SetSeedingErrors(!(refit && attempt == 0));
101 prop.SetFitInProjections(
true);
102 prop.SetPropagateBzOnly(
param.rec.fitPropagateBzOnly == -1 ? !finalFit :
param.rec.fitPropagateBzOnly);
103 prop.SetMatLUT((
param.rec.useMatLUT && finalFit) ? merger->GetConstantMem()->calibObjects.matLUT :
nullptr);
104 prop.SetTrack(
this, iWay ? prop.GetAlpha() : Alpha);
106 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()));
110 const bool inFlyDirection = iWay & 1;
111 const int32_t wayDirection = (iWay & 1) ? -1 : 1;
113 int32_t goodRows = 0;
114 for (int32_t ihit = ihitStart; ihit >= 0 && ihit < maxN; ihit += wayDirection) {
115 const bool crossCE = lastSector != 255 && ((lastSector < 18) ^ (
clusters[ihit].sector < 18));
121 CADEBUG(printf(
"\tSkipping hit %d, %d hits rejected, flag %X\n", ihit, nMissed, (int32_t)
clusters[ihit].
state));
128 const bool allowChangeClusters = finalOutInFit && (nWays == 1 || ((iWay & 1) ? (ihit <= CAMath::Max(maxN / 2, maxN - 30)) : (ihit >= CAMath::Min(maxN / 2, 30))));
130 int32_t ihitMergeFirst = ihit;
131 uint8_t clusterState =
clusters[ihit].state;
136 merger->GetConstantMem()->calibObjects.fastTransformHelper->Transform(
clusters[ihit].sector,
clusters[ihit].
row, cl.getPad(), cl.getTime(), xx, yy, zz, mTOffset);
139 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));
143 if (MergeDoubleRowClusters(ihit, wayDirection,
clusters, merger, prop, xx, yy, zz, maxN, clAlpha, clusterState, allowChangeClusters) == -1) {
149 if (
param.rec.tpc.rejectIFCLowRadiusCluster) {
150 const float r2 = xx * xx + yy * yy;
151 const float rmax = (83.5f +
param.rec.tpc.sysClusErrorMinDist);
152 if (r2 < rmax * rmax) {
157 const auto& cluster =
clusters[ihit];
160 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]));
162 if (allowChangeClusters && lastRow != 255 && CAMath::Abs(cluster.row - lastRow) > 1) {
164 bool dodEdx =
param.dodEdxEnabled &&
param.rec.tpc.adddEdxSubThresholdClusters && finalFit && CAMath::Abs(cluster.row - lastRow) == 2;
165 dodEdx = AttachClustersPropagate(merger, cluster.sector, lastRow, cluster.row, iTrk, track.Leg() == 0, prop, inFlyDirection,
GPUCA_MAX_SIN_PHI, dodEdx);
167 dEdx.fillSubThreshold(lastRow - wayDirection);
169 dEdxAlt.fillSubThreshold(lastRow - wayDirection);
175 int32_t retValProp = prop.PropagateToXAlpha(xx, clAlpha, inFlyDirection);
177 CADEBUG(
if (!CheckCov()){printf(
"INVALID COV AFTER PROPAGATE!!!\n");});
179 if (retValProp == -2)
182 if (prop.PropagateToXAlpha(xx, prop.GetAlpha(), inFlyDirection) == 0) {
183 retValProp = prop.PropagateToXAlpha(xx, clAlpha, inFlyDirection);
186 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)) {
191 if (retValProp == 0) {
192 lastRow = cluster.row;
193 lastSector = cluster.
sector;
196 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));
200 if (
param.rec.tpc.addErrorsCECrossing) {
201 if (
param.rec.tpc.addErrorsCECrossing >= 2) {
202 AddCovDiagErrorsWithCorrelations(
param.rec.tpc.errorsCECrossing);
204 AddCovDiagErrors(
param.rec.tpc.errorsCECrossing);
206 }
else if (mC[2] < 0.5f) {
211 float uncorrectedY = -1e6f;
212 if (allowChangeClusters) {
213 uncorrectedY = AttachClusters(merger, cluster.sector, cluster.row, iTrk, track.Leg() == 0, prop);
216 const bool sinPhiErr = mNDF > 0 && CAMath::Abs(prop.GetSinPhi0()) >= maxSinForUpdate;
217 if (mNDF >= 0 && (mC[0] >
param.rec.tpc.trackFitCovLimit || mC[2] >
param.rec.tpc.trackFitCovLimit)) {
220 if (retValProp || sinPhiErr) {
224 CADEBUG(printf(
", %d --- break\n", (int32_t)sinPhiErr));
229 int32_t retValUpd = 0, retValInt = 0;
230 float threshold = 3.f + (lastUpdateX >= 0 ? (CAMath::Abs(mX - lastUpdateX) / 2) : 0.f);
231 if (mNDF > (int32_t)
param.rec.tpc.mergerNonInterpolateRejectMinNDF && (CAMath::Abs(yy - mP[0]) > threshold || CAMath::Abs(zz - mP[1]) > threshold)) {
234 int8_t rejectChi2 = 0;
236 if (
param.rec.tpc.mergerInterpolateErrors && CAMath::Abs(ihit - ihitMergeFirst) <= 1) {
237 if (iWay == nWays - 3) {
239 }
else if (iWay == nWays - 2) {
241 }
else if (iWay == nWays - 1) {
245 rejectChi2 = allowChangeClusters && goodRows > 5;
250 const float time = merger->GetConstantMem()->ioPtrs.clustersNative ? merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[cluster.num].getTime() : -1.f;
251 const float invSqrtCharge = merger->GetConstantMem()->ioPtrs.clustersNative ? CAMath::InvSqrt(merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[cluster.num].qMax) : 0.f;
252 const float invCharge = merger->GetConstantMem()->ioPtrs.clustersNative ? (1.f / merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[cluster.num].qMax) : 0.f;
253 float invAvgCharge = (sumInvSqrtCharge += invSqrtCharge) / ++nAvgCharge;
254 invAvgCharge *= invAvgCharge;
256 prop.GetErr2(err2Y, err2Z,
param, zz, cluster.row, clusterState, cluster.sector,
time, invAvgCharge, invCharge);
262 retValInt = prop.InterpolateReject(
param, yy, zz, clusterState, rejectChi2, &interpolation.
hit[ihit], err2Y, err2Z, deltaZ);
266 if (
param.rec.tpc.rejectEdgeClustersInTrackFit && uncorrectedY > -1e6f &&
param.rejectEdgeClusterByY(uncorrectedY, cluster.row, CAMath::Sqrt(mC[0]))) {
269 retValUpd = prop.Update(yy, zz, cluster.row,
param, clusterState, rejectChi2, refit, err2Y, err2Z);
272 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);
276 CADEBUG(
if (!CheckCov()) GPUError(
"INVALID COV AFTER UPDATE!!!"));
277 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));
281 if (!retValUpd && !retValInt)
285 nMissed = nMissed2 = 0;
289 float dy = mP[0] - prop.Model().
Y();
290 float dz = mP[1] - prop.Model().
Z();
291 if (CAMath::Abs(mP[4]) *
param.qptB5Scaler > 10 && --resetT0 <= 0 && CAMath::Abs(mP[2]) < 0.15f && dy * dy + dz * dz > 1) {
292 CADEBUG(printf(
"Reinit linearization\n"));
293 prop.SetTrack(
this, prop.GetAlpha());
296 if (
param.dodEdxEnabled && finalFit) {
297 bool acc = (clusterState &
param.rec.tpc.dEdxClusterRejectionFlagMask) == 0, accAlt = (clusterState &
param.rec.tpc.dEdxClusterRejectionFlagMaskAlt) == 0;
299 float qtot = 0, qmax = 0, pad = 0, relTime = 0;
300 const int32_t clusterCount = (ihit - ihitMergeFirst) * wayDirection + 1;
301 for (int32_t iTmp = ihitMergeFirst; iTmp != ihit + wayDirection; iTmp += wayDirection) {
302 const ClusterNative& cl = merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear[cluster.num];
304 qmax = CAMath::Max<float>(qmax, cl.
qMax);
306 relTime += cl.getTime();
308 qtot /= clusterCount;
310 relTime /= clusterCount;
311 relTime = relTime - CAMath::Round(relTime);
313 dEdx.fillCluster(qtot, qmax, cluster.row, cluster.sector, mP[2], mP[3], merger->GetConstantMem()->calibObjects, zz, pad, relTime);
317 dEdxAlt.fillCluster(qtot, qmax, cluster.row, cluster.sector, mP[2], mP[3], merger->GetConstantMem()->calibObjects, zz, pad, relTime);
324 if (retValInt || allowChangeClusters) {
326 }
else if (finalFit) {
337 if (finalOutInFit && !(merger->Param().rec.tpc.disableRefitAttachment & 4) && lastRow != 255 && lastSector != 255) {
338 StoreLoopPropagation(merger, lastSector, lastRow, iTrk, lastRow >
clusters[(iWay & 1) ? (maxN - 1) : 0].row, prop.GetAlpha());
339 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));
341 if (!(iWay & 1) && !finalFit && !track.CCE() && !track.Looper()) {
342 deltaZ = ShiftZ(
clusters, merger, maxN);
350 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";
356 if (
param.rec.tpc.minNClustersFinalTrack != -1 && N + NTolerated <
param.rec.tpc.minNClustersFinalTrack) {
360 if (
param.par.dodEdx &&
param.dodEdxEnabled) {
361 dEdx.computedEdx(merger->MergedTracksdEdx()[iTrk],
param);
363 dEdxAlt.computedEdx(merger->MergedTracksdEdxAlt()[iTrk],
param);
366 Alpha = prop.GetAlpha();
367 MoveToReference(prop,
param, Alpha);
368 NormalizeAlpha(Alpha);
375 static constexpr float kDeg2Rad = M_PI / 180.f;
376 static constexpr float kSectAngle = 2 * M_PI / 18.f;
378 if (
param.rec.tpc.trackReferenceX <= 500) {
380 float saveAlpha = Alpha;
381 for (int32_t attempt = 0; attempt < 3; attempt++) {
382 float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / kDeg2Rad / 20.f) * kSectAngle;
384 if (prop.PropagateToXAlpha(
param.rec.tpc.trackReferenceX, Alpha, 0)) {
388 if (CAMath::Abs(mP[0]) <= mX * CAMath::Tan(kSectAngle / 2.f)) {
395 if (CAMath::Abs(mP[0]) > mX * CAMath::Tan(kSectAngle / 2.f)) {
396 float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / kDeg2Rad / 20.f) * kSectAngle;
405 if (mirrorParameters) {
406 prop.Mirror(inFlyDirection);
409 prop.GetErr2(err2Y, err2Z,
param, toZ,
row, clusterState, sector, -1.f, 0.f, 0.f);
410 prop.Model().
Y() = mP[0] = toY;
411 prop.Model().Z() = mP[1] = toZ;
418 if (CAMath::Abs(mC[5]) < 0.1f) {
419 mC[5] = mC[5] > 0 ? 0.1f : -0.1f;
424 mC[1] = mC[4] = mC[6] = mC[8] = mC[11] = mC[13] = 0;
425 prop.SetTrack(
this, prop.GetAlpha());
430GPUd() 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)
433 float maxDistY, maxDistZ;
434 prop.GetErr2(maxDistY, maxDistZ, merger->Param(), zz,
clusters[ihit].row, 0,
clusters[ihit].sector, -1.f, 0.f, 0.f);
435 maxDistY = (maxDistY + mC[0]) * 20.f;
436 maxDistZ = (maxDistZ + mC[2]) * 20.f;
437 int32_t noReject = 0;
438 if (CAMath::Abs(clAlpha - prop.GetAlpha()) > 1.e-4f) {
439 noReject = prop.RotateToAlpha(clAlpha);
441 float projY = 0, projZ = 0;
443 noReject |= prop.GetPropagatedYZ(xx, projY, projZ);
450 float clamp = cl.qTot;
452 merger->GetConstantMem()->calibObjects.fastTransformHelper->Transform(
clusters[ihit].sector,
clusters[ihit].
row, cl.getPad(), cl.
getTime(), clx, cly, clz, mTOffset);
453 float dy = cly - projY;
454 float dz = clz - projZ;
455 if (noReject == 0 && (dy * dy > maxDistY || dz * dz > maxDistZ)) {
456 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));
461 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)));
465 clusterState |=
clusters[ihit].state;
468 if (!(ihit + wayDirection >= 0 && ihit + wayDirection < maxN &&
clusters[ihit].
row ==
clusters[ihit + wayDirection].
row &&
clusters[ihit].sector ==
clusters[ihit + wayDirection].sector)) {
471 ihit += wayDirection;
474 CADEBUG(printf(
"\t\tNo matching cluster in double-row, skipping\n"));
488 Merger->GetConstantMem()->calibObjects.fastTransformHelper->InverseTransformYZtoX(sector, iRow, mP[0], mP[1], X);
489 if (prop.GetPropagatedYZ(X, Y, Z)) {
493 return AttachClusters(Merger, sector, iRow, iTrack, goodLeg, Y, Z);
498 if (Merger->Param().rec.tpc.disableRefitAttachment & 1) {
505 if (
row.NHits() == 0) {
509 const float zOffset = Merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(sector, mTOffset, Merger->Param().continuousMaxTimeBin);
510 const float y0 =
row.Grid().YMin();
511 const float stepY =
row.HstepY();
512 const float z0 =
row.Grid().ZMin() - zOffset;
513 const float stepZ =
row.HstepZ();
517 Merger->Param().GetClusterErrors2(sector, iRow, Z, mP[2], mP[3], -1.f, 0.f, 0.f, err2Y, err2Z);
518 const float sy2 = CAMath::Min(Merger->Param().rec.tpc.tubeMaxSize2, Merger->Param().rec.tpc.tubeChi2 * (err2Y + CAMath::Abs(mC[0])));
519 const float sz2 = CAMath::Min(Merger->Param().rec.tpc.tubeMaxSize2, Merger->Param().rec.tpc.tubeChi2 * (err2Z + CAMath::Abs(mC[2])));
520 const float tubeY = CAMath::Sqrt(sy2);
521 const float tubeZ = CAMath::Sqrt(sz2);
522 const float sy21 = 1.f / sy2;
523 const float sz21 = 1.f / sz2;
524 float uncorrectedY, uncorrectedZ;
525 Merger->GetConstantMem()->calibObjects.fastTransformHelper->InverseTransformYZtoNominalYZ(sector, iRow, Y, Z, uncorrectedY, uncorrectedZ);
527 if (CAMath::Abs(uncorrectedY) >
row.getTPCMaxY()) {
530 row.Grid().GetBinArea(uncorrectedY, uncorrectedZ + zOffset, tubeY, tubeZ, bin, ny, nz);
532 const int32_t nBinsY =
row.Grid().Ny();
533 const int32_t idOffset = tracker.Data().ClusterIdOffset();
534 const int32_t*
ids = &(tracker.Data().ClusterDataIndex()[
row.HitNumberOffset()]);
540 for (int32_t k = 0; k <= nz; k++) {
541 const int32_t mybin = bin + k * nBinsY;
542 const uint32_t hitFst = firsthit[mybin];
543 const uint32_t hitLst = firsthit[mybin + ny + 1];
544 for (uint32_t ih = hitFst; ih < hitLst; ih++) {
545 int32_t
id = idOffset +
ids[ih];
548 if (myWeight <= *
weight) {
552 const cahit2 hh = hits[ih];
553 const float y =
y0 + hh.
x * stepY;
554 const float z = z0 + hh.
y * stepZ;
555 const float dy =
y - uncorrectedY;
556 const float dz =
z - uncorrectedZ;
557 if (dy * dy * sy21 + dz * dz * sz21 <= CAMath::Sqrt(2.f)) {
559 CAMath::AtomicMax(
weight, myWeight);
568 static constexpr float kSectAngle = 2 * M_PI / 18.f;
569 if (Merger->Param().rec.tpc.disableRefitAttachment & 2) {
572 if (CAMath::Abs(lastRow - toRow) < 2) {
575 int32_t
step = toRow > lastRow ? 1 : -1;
576 float xx = mX - GPUTPCGeometry::Row2X(lastRow);
577 for (int32_t iRow = lastRow + step; iRow != toRow; iRow +=
step) {
578 if (CAMath::Abs(mP[2]) > maxSinPhi) {
581 if (CAMath::Abs(mP[0]) > CAMath::Abs(mX) * CAMath::Tan(kSectAngle / 2.f)) {
584 int32_t err = prop.PropagateToXAlpha(xx + GPUTPCGeometry::Row2X(iRow), prop.GetAlpha(), inFlyDirection);
588 if (dodEdx && iRow + step == toRow) {
589 float yUncorrected, zUncorrected;
590 Merger->GetConstantMem()->calibObjects.fastTransformHelper->InverseTransformYZtoNominalYZ(sector, iRow, mP[0], mP[1], yUncorrected, zUncorrected);
591 uint32_t pad = CAMath::Float2UIntRn(GPUTPCGeometry::LinearY2Pad(sector, iRow, yUncorrected));
592 if (pad >= GPUTPCGeometry::NPads(iRow) || (Merger->GetConstantMem()->calibObjects.dEdxCalibContainer && Merger->GetConstantMem()->calibObjects.dEdxCalibContainer->isDead(sector, iRow, pad))) {
596 CADEBUG(printf(
"Attaching in row %d\n", iRow));
597 AttachClusters(Merger, sector, iRow, iTrack, goodLeg, prop);
604 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])));
605 for (int32_t
i = 0;
i < 5;
i++) {
606 outerParam->P[
i] = mP[
i];
608 for (int32_t
i = 0;
i < 15;
i++) {
609 outerParam->C[
i] = mC[
i];
612 outerParam->alpha =
alpha;
623 if (CAMath::Abs(mP[2]) < 0.75) {
626 if ((mP[2] * mP[4] < 0) ^ outwards) {
630 uint32_t nLoopData = CAMath::AtomicAdd(&Merger->Memory()->nLoopData, 1u);
631 if (nLoopData >= Merger->NMaxTracks()) {
632 Merger->raiseError(GPUErrors::ERROR_MERGER_LOOPER_OVERFLOW, nLoopData, Merger->NMaxTracks());
633 CAMath::AtomicExch(&Merger->Memory()->nLoopData, Merger->NMaxTracks());
642 data.outwards = outwards;
643 Merger->LoopData()[nLoopData] =
data;
649 prop.SetMaterialTPC();
650 prop.SetPolynomialField(&Merger->Param().polynomialField);
652 prop.SetMatLUT(Merger->Param().rec.useMatLUT ? Merger->GetConstantMem()->calibObjects.matLUT : nullptr);
653 prop.SetSeedingErrors(
false);
654 prop.SetFitInProjections(
true);
655 prop.SetPropagateBzOnly(
false);
658 prop.SetTrack(&
data.param,
data.alpha);
662 data.param.AttachClustersLooperFollow(Merger, prop,
data.sector,
data.row,
data.track,
data.outwards);
669 bool inFlyDirection = (Merger->MergedTracks()[iTrack].Leg() & 1) ^ up;
671 static constexpr float kSectAngle = 2 * M_PI / 18.f;
673 bool right = (mP[2] < 0) ^ up;
675 float lrFactor =
right ^ !up ? 1.f : -1.f;
677 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));
680 if (prop.RotateToAlpha(prop.GetAlpha() + (CAMath::Pi() / 2.f) * lrFactor)) {
683 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));
684 uint32_t maxTries = 100;
686 while (CAMath::Abs(mX) <= CAMath::Abs(mP[0]) * CAMath::Tan(kSectAngle / 2.f) + 0.1f) {
687 if (maxTries-- == 0) {
690 if (CAMath::Abs(mP[2]) > 0.7f) {
693 if (up ? (-mP[0] * lrFactor > GPUTPCGeometry::Row2X(
GPUCA_ROW_COUNT - 1)) : (-mP[0] * lrFactor < GPUTPCGeometry::Row2X(0))) {
696 if (!((up ? (-mP[0] * lrFactor >= toX) : (-mP[0] * lrFactor <= toX)) || (
right ^ (mP[2] > 0)))) {
699 int32_t err = prop.PropagateToXAlpha(mX + (up ? 1.f : -1.f), prop.GetAlpha(), inFlyDirection);
701 CADEBUG(printf(
"\t\tpropagation error (%d)\n", err));
704 CADEBUG(printf(
"\tPropagated to y = %f: X %f Z %f SinPhi %f\n", mX, mP[0], mP[1], mP[2]));
706 float rowX = GPUTPCGeometry::Row2X(
j);
707 if (CAMath::Abs(rowX - (-mP[0] * lrFactor)) < 1.5f) {
708 CADEBUG(printf(
"\t\tAttempt row %d (X %f Y %f Z %f)\n",
j, rowX, mX * lrFactor, mP[1]));
709 AttachClusters(Merger, sector,
j, iTrack,
false, mX * lrFactor, mP[1]);
713 if (maxTries-- == 0) {
717 if (++sector >= sectorSide + 18) {
721 if (--sector < sectorSide) {
725 CADEBUG(printf(
"\tRotating to sector %d: %f --> %f\n", sector, prop.GetAlpha(),
param.Alpha(sector) + (CAMath::Pi() / 2.f) * lrFactor));
726 int32_t err = prop.RotateToAlpha(
param.Alpha(sector) + (CAMath::Pi() / 2.f) * lrFactor);
728 CADEBUG(printf(
"Rotation Error %d\n", err));
731 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]));
737 static constexpr float kSectAngle = 2 * M_PI / 18.f;
739 float X = mP[2] > 0 ? mP[0] : -mP[0];
740 float Y = mP[2] > 0 ? -mX : mX;
742 float SinPhi = CAMath::Sqrt(1 - mP[2] * mP[2]) * (mP[2] > 0 ? -1 : 1);
743 float b = prop.GetBz(prop.GetAlpha(), mX, mP[0], mP[1]);
745 float dx = outwards ? 1.f : -1.f;
746 const float myRowX = GPUTPCGeometry::Row2X(iRow);
750 uint32_t maxTries = 100;
752 float ex = CAMath::Sqrt(1 - SinPhi * SinPhi);
753 float exi = 1.f / ex;
754 float dxBzQ = dx * -
b * mP[4];
755 float newSinPhi = SinPhi + dxBzQ;
760 if (mP[2] > 0 ? (newSinPhi > 0.5) : (newSinPhi < -0.5)) {
765 float h2 = dS * exi * exi;
766 float h4 = .5f * h2 * dxBzQ;
769 Y += dS * SinPhi + h4;
772 if (CAMath::Abs(X) > CAMath::Abs(Y) * CAMath::Tan(kSectAngle / 2.f)) {
778 float paramX = mP[2] > 0 ? -Y : Y;
779 int32_t
step = outwards ? 1 : -1;
782 float rowX = mX + GPUTPCGeometry::Row2X(
j) - myRowX;
783 if (CAMath::Abs(rowX - paramX) < 1.5f) {
785 AttachClusters(Merger, sector,
j, iTrack,
false, mP[2] > 0 ? X : -X, Z);
796 const auto&
GPUrestrict() cls = merger->GetConstantMem()->ioPtrs.clustersNative->clustersLinear;
798 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)};
799 return ShiftZ(merger,
clusters[0].sector, tmp[0], tmp[1], tmp[2]);
804 if (!merger->Param().par.continuousTracking) {
808 bool beamlineReached =
false;
809 const float r1 = CAMath::Max(0.0001f, CAMath::Abs(mP[4] * merger->Param().polynomialField.GetNominalBz()));
811 const float dist2 = mX * mX + mP[0] * mP[0];
812 const float dist1r2 = dist2 * r1 * r1;
814 const float alpha = CAMath::ACos(1 - 0.5f * dist1r2);
815 const float beta = CAMath::ATan2(mP[0], mX);
816 const int32_t comp = mP[2] > CAMath::Sin(beta);
817 const float sinab = CAMath::Sin((comp ? 0.5f : -0.5f) *
alpha + beta);
818 const float res = CAMath::Abs(sinab - mP[2]);
821 const float r = 1.f / r1;
822 const float dS =
alpha *
r;
823 float z0 = dS * mP[3];
824 if (CAMath::Abs(z0) > GPUTPCGeometry::TPCLength()) {
825 z0 = z0 > 0 ? GPUTPCGeometry::TPCLength() : -
GPUTPCGeometry::TPCLength();
828 beamlineReached =
true;
835 if (!beamlineReached) {
836 float refZ = ((sector <
GPUCA_NSECTORS / 2) ? merger->Param().rec.tpc.defaultZOffsetOverR : -merger->Param().rec.tpc.defaultZOffsetOverR) * clx;
838 merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->TransformIdealZ(sector, cltmax, basez, mTOffset);
839 deltaZ = basez - refZ;
842 float deltaT = merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convDeltaZtoDeltaTimeInTimeFrame(sector, deltaZ);
844 const float maxT = cltmin - merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->getT0();
845 const float minT = cltmax - merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->getMaxDriftTime(sector);
848 if (mTOffset < minT) {
849 deltaT = minT - mTOffset;
851 if (mTOffset + deltaT > maxT) {
852 deltaT =
maxT - mTOffset;
855 deltaZ += merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convDeltaTimeToDeltaZinTimeFrame(sector, deltaT);
868 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]) &&
869 (
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]);
876 bool ok = CAMath::Finite(mX) && CAMath::Finite(mChi2);
879 for (int32_t
i = 0;
i < 15;
i++) {
880 ok = ok && CAMath::Finite(
c[
i]);
882 for (int32_t
i = 0;
i < 5;
i++) {
883 ok = ok && CAMath::Finite(mP[
i]);
885 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) {
907 int32_t nTrackHits = track.NClusters();
908 int32_t NTolerated = 0;
910 float Alpha = track.
Alpha();
911 CADEBUG(int32_t nTrackHitsOld = nTrackHits;
float ptOld = t.QPt());
912 bool ok = t.Fit(merger, iTrk, merger->Clusters() + track.FirstClusterRef(), nTrackHits, NTolerated, Alpha, attempt,
GPUCA_MAX_SIN_PHI, track);
913 CADEBUG(printf(
"Finished Fit Track %d\n", iTrk));
914 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)));
916 if (!ok && attempt == 0 && merger->Param().rec.tpc.retryRefit) {
917 for (uint32_t
i = 0;
i < track.NClusters();
i++) {
920 CADEBUG(printf(
"Track rejected, marking for retry\n"));
921 if (merger->Param().rec.tpc.retryRefit == 2) {
922 nTrackHits = track.NClusters();
925 Alpha = track.
Alpha();
926 ok = t.Fit(merger, iTrk, merger->Clusters() + track.FirstClusterRef(), nTrackHits, NTolerated, Alpha, 1,
GPUCA_MAX_SIN_PHI, track);
928 uint32_t nRefit = CAMath::AtomicAdd(&merger->Memory()->nRetryRefit, 1u);
929 merger->RetryRefitIds()[nRefit] = iTrk;
933 if (CAMath::Abs(t.QPt()) < 1.e-4f) {
937 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()); });
940 track.SetNClustersFitted(nTrackHits);
942 track.
Alpha() = Alpha;
950 CAMath::SinCos(
alpha, sA, cA);
952 float sinPhi0 = mP[2], cosPhi0 = CAMath::Sqrt(1 - mP[2] * mP[2]);
953 float cosPhi = cosPhi0 * cA + sinPhi0 * sA;
954 float sinPhi = -cosPhi0 * sA + sinPhi0 * cA;
955 float j0 = cosPhi0 / cosPhi;
956 float j2 = cosPhi / cosPhi0;
957 mX =
x0 * cA + mP[0] * sA;
958 mP[0] = -
x0 * sA + mP[0] * cA;
972 SinPhi() = -SinPhi();
990 mC[14] += errors2[4];
995 const int32_t diagMap[5] = {0, 2, 5, 9, 14};
996 const float oldDiag[5] = {mC[0], mC[2], mC[5], mC[9], mC[14]};
997 for (int32_t
i = 0;
i < 5;
i++) {
998 mC[diagMap[
i]] += errors2[
i];
999 for (int32_t
j = 0;
j <
i;
j++) {
1000 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