Skip to content

Commit b414331

Browse files
committed
GPU TPC: Faster implementation for search adjacent clusters in missing rows
1 parent d966c19 commit b414331

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

‎GPU/GPUTracking/Merger/GPUTPCGMMergerTypes.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ struct InterpolationErrorHit {
4040
GPUCA_PAR_MERGER_INTERPOLATION_ERROR_TYPE_A errorY, errorZ;
4141
GPUdi() bool isValid() const { return errorY >= (GPUCA_PAR_MERGER_INTERPOLATION_ERROR_TYPE_A)0; }
4242
GPUdi() void markInvalid() { errorY = (GPUCA_PAR_MERGER_INTERPOLATION_ERROR_TYPE_A)-1; }
43-
GPUdi() bool isAdjacentDone() const { return errorY == (GPUCA_PAR_MERGER_INTERPOLATION_ERROR_TYPE_A)-2; }
44-
GPUdi() void markAdjacentDone() { errorY = (GPUCA_PAR_MERGER_INTERPOLATION_ERROR_TYPE_A)-2; } // Adjacent clusters were searched at the interpolated position of this entry, the entry is invalid afterwards
43+
GPUdi() void markAdjacentSearch() { errorY = (GPUCA_PAR_MERGER_INTERPOLATION_ERROR_TYPE_A)-2; } // Invalidates an entry the interpolation rejection did not use, such that the last way searches adjacent clusters for the hit (distinct from the -1 of markInvalid)
4544
};
4645

4746
struct InterpolationErrors {

‎GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger& GPUrestrict() merger, int32_
8989
ConstrainZ(merger, clusters[0].sector, CAMath::Max(t0, tN), CAMath::Min(t0, tN));
9090
}
9191
int32_t ihitStart = 0;
92+
int32_t ihitStartInterpolateReject = 0; // First hit of the interpolation rejection way, the hits beyond are not covered by its search for adjacent clusters
9293
int32_t interpolatedStart = 0;
9394
float covYYUpd = 0.f;
9495
float deltaZ = 0.f;
@@ -127,6 +128,9 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger& GPUrestrict() merger, int32_
127128
const bool inFlyDirection = iWay & 1;
128129
const int32_t wayDirection = (iWay & 1) ? -1 : 1;
129130

131+
if (param.rec.tpc.mergerInterpolateErrors && iWay == nWays - 2) {
132+
ihitStartInterpolateReject = ihitStart;
133+
}
130134
for (int32_t ihit = ihitStart, interpolationIndex = interpolatedStart; ihit >= 0 && ihit < maxN; ihit += wayDirection) {
131135
if (lastIndexRow != 255) { // One index per pad row (2 if the track has clusters of 2 sectors in the row), counted also for hits skipped below, such that all ways use the same index for a hit
132136
interpolationIndex += (clusters[ihit].row == lastIndexRow ? (int32_t)(clusters[ihit].sector != lastIndexSector) : CAMath::Abs(clusters[ihit].row - lastIndexRow)) * wayDirection;
@@ -211,6 +215,7 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger& GPUrestrict() merger, int32_
211215
MarkClusters(clusters, ihitMergeFirst, ihit, wayDirection, GPUTPCGMMergedTrackHit::flagHighIncl);
212216
nMissedHard++;
213217
NTolerated++;
218+
MarkAdjacentSearch(param, iWay, inter);
214219
if (param.rec.tpc.rebuildTrackInFit && iWay == wayRebuildStart + 1 && param.rec.tpc.rebuildTrackMaxNonIntCov > 0 && !(param.rec.tpc.disableRebuildAttachment & 4)) {
215220
FindBestInterpolatedHit(merger, inter, cluster.sector, cluster.row, deltaZ, sumInvSqrtCharge, nAvgCharge, prop, iTrk, true, adjacentInRebuild && !(param.rec.tpc.disableMarkAdjacent & 1) ? adjacentLeg : 0);
216221
}
@@ -224,14 +229,15 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger& GPUrestrict() merger, int32_
224229
if (param.rec.tpc.rebuildTrackInFit && iWay == wayRebuildStart + 1 && param.rec.tpc.rebuildTrackMaxNonIntCov > 0 && !(param.rec.tpc.disableRebuildAttachment & 4)) {
225230
InterpolateMissingRows(merger, interpolation, clusters, ihit, interpolationIndex, cluster.row, deltaZ, sumInvSqrtCharge, nAvgCharge, prop, iTrk, adjacentInRebuild && !(param.rec.tpc.disableMarkAdjacent & 1) ? adjacentLeg : 0);
226231
}
232+
MarkAdjacentSearch(param, iWay, inter);
227233
fitBroken = true;
228234
break; // bad chi2 for the whole track, stop the fit
229235
}
230236

231237
float uncorrectedY = -1e6f;
232238
if (param.rec.tpc.rebuildTrackInFit && iWay == wayRebuildStart + 1 && !(param.rec.tpc.disableRebuildAttachment & 1)) {
233-
uncorrectedY = FindBestInterpolatedHit(merger, inter, cluster.sector, cluster.row, deltaZ, sumInvSqrtCharge, nAvgCharge, prop, iTrk, false, adjacentInRebuild && !(param.rec.tpc.disableMarkAdjacent & 1) ? adjacentLeg : 0); // TODO: Check whether we do not need to use track Y for some rejection steps
234-
} else if (adjacentInRebuild ? iWay == wayRebuildStart + 1 : (param.rec.tpc.mergerInterpolateErrors ? (finalFit && !inter.isAdjacentDone()) : allowChangeClusters)) {
239+
uncorrectedY = FindBestInterpolatedHit(merger, inter, cluster.sector, cluster.row, deltaZ, sumInvSqrtCharge, nAvgCharge, prop, iTrk, false, adjacentInRebuild && !(param.rec.tpc.disableMarkAdjacent & 1) ? adjacentLeg : 0); // TODO: Check whether we do not need to use track Y for some rejection steps
240+
} else if (adjacentInRebuild ? iWay == wayRebuildStart + 1 : (param.rec.tpc.mergerInterpolateErrors ? (finalFit && (retryAttempt || !inter.isValid() || (ihit - ihitStartInterpolateReject) * wayDirection > 0 || (param.rec.tpc.disableMarkAdjacent & 1))) : allowChangeClusters)) { // With interpolation rejection: in the last way all hits InterpolateReject did not search: in a retry, beyond its first hit, or without interpolated position (also invalidated where it skipped a hit)
235241
uncorrectedY = FindAdjacentClusters(merger, cluster.sector, cluster.row, iTrk, track.Leg() == 0, prop);
236242
}
237243
if (param.rec.tpc.rejectEdgeClustersInTrackFit && uncorrectedY <= -1e6f) {
@@ -249,6 +255,7 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger& GPUrestrict() merger, int32_
249255
if (currentClusterStatus) {
250256
nMissed++;
251257
nMissedHard++;
258+
MarkAdjacentSearch(param, iWay, inter);
252259
continue;
253260
}
254261

@@ -286,6 +293,7 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger& GPUrestrict() merger, int32_
286293
}
287294
// TODO: We can perhaps break here, if we pick up remaining rows
288295
}
296+
MarkAdjacentSearch(param, iWay, inter);
289297
continue;
290298
}
291299
}
@@ -526,6 +534,13 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger& GPUrestrict() merger, int32_
526534
return true;
527535
}
528536

537+
GPUdi() void GPUTPCGMTrackParam::MarkAdjacentSearch(const GPUParam& GPUrestrict() param, int32_t iWay, gputpcgmmergertypes::InterpolationErrorHit& GPUrestrict() inter)
538+
{
539+
if (param.rec.tpc.mergerInterpolateErrors && iWay == param.rec.tpc.nWays - 2) { // Hit not passed to InterpolateReject, search adjacent clusters in the last way
540+
inter.markAdjacentSearch();
541+
}
542+
}
543+
529544
GPUdii() void GPUTPCGMTrackParam::FitAddRow(const int32_t iRow, const uint8_t sector, const int32_t iTrk, const GPUTPCGMMergedTrack& GPUrestrict() track, GPUTPCGMPropagator& GPUrestrict() prop, const bool inFlyDirection, GPUTPCGMMerger& GPUrestrict() merger, uint8_t* GPUrestrict() dEdxSubThresholdRow, const bool dodEdx, const bool doAttach, const uint8_t doInterpolate, gputpcgmmergertypes::InterpolationErrorHit& GPUrestrict() inter, const float deltaZ, const float sumInvSqrtCharge, const int32_t nAvgCharge)
530545
{
531546
if (CAMath::Abs(mP[2]) > constants::MAX_SIN_PHI || CAMath::Abs(mP[0]) > CAMath::Abs(mX) * CAMath::Tan(GPUTPCGeometry::kSectAngle() / 2.f)) {
@@ -586,6 +601,7 @@ GPUdii() int32_t GPUTPCGMTrackParam::FitHit(GPUTPCGMMerger& GPUrestrict() merger
586601
float threshold = 3.f + (lastUpdateX >= 0 ? (CAMath::Abs(mX - lastUpdateX) / 2) : 0.f);
587602
if (mNDF > (int32_t)param.rec.tpc.mergerNonInterpolateRejectMinNDF && (CAMath::Abs(yy - mP[0]) > threshold || CAMath::Abs(zz - mP[1]) > threshold)) {
588603
retValUpd = GPUTPCGMPropagator::updateErrorClusterRejectedDistance;
604+
MarkAdjacentSearch(param, iWay, inter);
589605
if (param.rec.tpc.rebuildTrackInFit && (finalOutInFit || iWay < wayRebuildStart + 2)) {
590606
MarkClusters(clusters, ihitMergeFirst, ihit, wayDirection, GPUTPCGMMergedTrackHit::flagRejectDistance); // Will enable rejectChi2 in further rounds
591607
}
@@ -726,7 +742,6 @@ GPUd() int32_t GPUTPCGMTrackParam::InterpolateReject(const GPUTPCGMMerger& GPUre
726742
param.GetClusterErrors2(sector, row, ImP1, mP[2], mP[3], -1.f, 0.f, 0.f, clErr2Y, clErr2Z); // TODO: Use correct time/avgCharge
727743
FindAdjacentClustersUncorrectedPos(merger, sector, row, iTrk, doAttach == 2, uncorrectedY, uncorrectedZ, ImP1, clErr2Y + CAMath::Abs(ImC0), clErr2Z + CAMath::Abs(ImC2));
728744
}
729-
inter->markAdjacentDone();
730745
}
731746
if (GPUTPCGMPropagator::RejectCluster(chi2Y * param.rec.tpc.clusterRejectChi2TolleranceY, chi2Z * param.rec.tpc.clusterRejectChi2TolleranceZ, clusterState)) { // TODO: Relative Pt resolution decreases slightly, why?
732747
// printf("Reject Cluster chiy2 %f chiz2 %f (Pos Y: %f - %f %f ; Pos Z: %f - %f %f)\n", chi2Y, chi2Z, posY, mP[0], (float)inter->posY, posZ, mP[1], (float)inter->posZ + deltaZ);

‎GPU/GPUTracking/Merger/GPUTPCGMTrackParam.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class GPUTPCGMTrackParam
160160
GPUd() int32_t FitHit(GPUTPCGMMerger& merger, const int32_t iTrk, const GPUTPCGMMergedTrack& track, const float xx, const float yy, const float zz, const uint8_t clusterState, const float clAlpha, const int32_t iWay, const bool inFlyDirection, float& deltaZ, float& lastUpdateX, GPUTPCGMMergedTrackHit* clusters, GPUTPCGMPropagator& prop, gputpcgmmergertypes::InterpolationErrorHit& inter, GPUdEdx& dEdx, GPUdEdx& dEdxAlt, float& sumInvSqrtCharge, int32_t& nAvgCharge, const int32_t ihit, const int32_t ihitMergeFirst, const bool allowChangeClusters, const bool refit, const bool finalFit, int32_t& nMissed, int32_t& nMissedHard, float uncorrectedY, bool retryAttempt);
161161
GPUd() void FitAddRow(const int32_t iRow, const uint8_t sector, const int32_t iTrk, const GPUTPCGMMergedTrack& track, GPUTPCGMPropagator& prop, const bool inFlyDirection, GPUTPCGMMerger& merger, uint8_t* dEdxSubThresholdRow, const bool dodEdx, const bool doAttach, const uint8_t doInterpolate, gputpcgmmergertypes::InterpolationErrorHit& inter, const float deltaZ, const float sumInvSqrtCharge, const int32_t nAvgCharge);
162162
GPUd() void HandleCrossCE(const GPUParam& param, const uint8_t sector, const uint8_t& lastSector);
163+
GPUd() static void MarkAdjacentSearch(const GPUParam& param, int32_t iWay, gputpcgmmergertypes::InterpolationErrorHit& inter); // For hits the interpolation rejection way skips
163164
template <bool rebuiltKernel, bool retryAttempt>
164165
GPUd() static void RefitTrack(GPUTPCGMMergedTrack& track, int32_t iTrk, GPUTPCGMMerger& merger);
165166
GPUd() void MoveToReference(GPUTPCGMPropagator& prop, const GPUParam& param, float& alpha);

0 commit comments

Comments
 (0)