Skip to content

Commit

Permalink
GPU TPC: Apply distortion correction during seeding
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrohr committed Feb 15, 2023
1 parent 27db2ba commit bd597e8
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions GPU/GPUTracking/SliceTracker/GPUTPCTrackletConstructor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "GPUTPCTrackletConstructor.h"
#if !defined(__OPENCL__) || defined(__OPENCLCPP__)
#include "GPUTPCGlobalTracking.h"
#include "CorrectionMapsHelper.h"
#endif
#include "GPUParam.inc"
#include "GPUCommonMath.h"
Expand Down Expand Up @@ -69,6 +70,7 @@ GPUd() void GPUTPCTrackletConstructor::StoreTracklet(int /*nBlocks*/, int /*nThr
const unsigned int nHits = r.mLastRow + 1 - r.mFirstRow;
unsigned int hitout = CAMath::AtomicAdd(tracker.NRowHits(), nHits);
if (hitout + nHits > tracker.NMaxRowHits()) {

tracker.raiseError(GPUErrors::ERROR_TRACKLET_HIT_OVERFLOW, tracker.ISlice(), hitout + nHits, tracker.NMaxRowHits());
CAMath::AtomicExch(tracker.NRowHits(), tracker.NMaxRowHits());
return;
Expand Down Expand Up @@ -134,7 +136,9 @@ GPUdic(2, 1) void GPUTPCTrackletConstructor::UpdateTracklet(int /*nBlocks*/, int
float x = row.X();
float y = y0 + hh.x * stepY;
float z = z0 + hh.y * stepZ;

#if !defined(__OPENCL__) || defined(__OPENCLCPP__)
tracker.GetConstantMem()->calibObjects.fastTransformHelper->TransformXYZ(tracker.ISlice(), iRow, x, y, z);
#endif
if (iRow == r.mStartRow) {
tParam.SetX(x);
tParam.SetY(y);
Expand Down Expand Up @@ -250,6 +254,18 @@ GPUdic(2, 1) void GPUTPCTrackletConstructor::UpdateTracklet(int /*nBlocks*/, int
r.mNMissed++;

float x = row.X();
#if !defined(__OPENCL__) || defined(__OPENCLCPP__)
{
float tmpY, tmpZ;
if (!tParam.GetPropagatedYZ(tracker.Param().constBz, x, tmpY, tmpZ)) {
r.mGo = 0;
rowHit = CALINK_INVAL;
break;
}
tracker.GetConstantMem()->calibObjects.fastTransformHelper->InverseTransformYZtoX(tracker.ISlice(), iRow, tmpY, tmpZ, x);
}
#endif

float err2Y, err2Z;
CADEBUG(printf("%14s: SEA TRACK ROW %3d X %8.3f -", "", iRow, tParam.X()); for (int i = 0; i < 5; i++) { printf(" %8.3f", tParam.Par()[i]); } printf(" -"); for (int i = 0; i < 15; i++) { printf(" %8.3f", tParam.Cov()[i]); } printf("\n"));
if (!tParam.TransportToX(x, tParam.SinPhi(), tParam.GetCosPhi(), tracker.Param().constBz, GPUCA_MAX_SIN_PHI_LOW)) {
Expand All @@ -267,8 +283,10 @@ GPUdic(2, 1) void GPUTPCTrackletConstructor::UpdateTracklet(int /*nBlocks*/, int
GPUglobalref() const cahit2* hits = tracker.HitData(row);
GPUglobalref() const calink* firsthit = tracker.FirstHitInBin(row);
#endif //! GPUCA_TEXTURE_FETCH_CONSTRUCTOR
float fY = tParam.GetY();
float fZ = tParam.GetZ();
float yUncorrected = tParam.GetY(), zUncorrected = tParam.GetZ();
#if !defined(__OPENCL__) || defined(__OPENCLCPP__)
tracker.GetConstantMem()->calibObjects.fastTransformHelper->InverseTransformYZtoNominalYZ(tracker.ISlice(), iRow, yUncorrected, zUncorrected, yUncorrected, zUncorrected);
#endif
calink best = CALINK_INVAL;

{ // search for the closest hit
Expand All @@ -279,7 +297,7 @@ GPUdic(2, 1) void GPUTPCTrackletConstructor::UpdateTracklet(int /*nBlocks*/, int
const float sz2 = CAMath::Min(maxWindow2, kFactor * (tParam.Err2Z() + err2Z));

int bin, ny, nz;
row.Grid().GetBinArea(fY, fZ + tParam.ZOffset(), CAMath::Sqrt(sy2), CAMath::Sqrt(sz2), bin, ny, nz);
row.Grid().GetBinArea(yUncorrected, zUncorrected + tParam.ZOffset(), CAMath::Sqrt(sy2), CAMath::Sqrt(sz2), bin, ny, nz);
float ds = 1e6f;

#ifdef __HIPCC__ // Todo: fixme!
Expand All @@ -299,8 +317,8 @@ GPUdic(2, 1) void GPUTPCTrackletConstructor::UpdateTracklet(int /*nBlocks*/, int
cahit2 hh = CA_TEXTURE_FETCH(cahit2, gAliTexRefu2, hits, ih);
float y = y0 + hh.x * stepY;
float z = z0 + hh.y * stepZ;
float dy = y - fY;
float dz = z - fZ;
float dy = y - yUncorrected;
float dz = z - zUncorrected;
if (dy * dy < sy2 && dz * dz < sz2) {
float dds = GPUCA_Y_FACTOR * CAMath::Abs(dy) + CAMath::Abs(dz);
if (dds < ds) {
Expand All @@ -322,8 +340,8 @@ GPUdic(2, 1) void GPUTPCTrackletConstructor::UpdateTracklet(int /*nBlocks*/, int
}

cahit2 hh = CA_TEXTURE_FETCH(cahit2, gAliTexRefu2, hits, best);
float y = y0 + hh.x * stepY;
float z = z0 + hh.y * stepZ;
float y = y0 + hh.x * stepY + tParam.GetY() - yUncorrected;
float z = z0 + hh.y * stepZ + tParam.GetZ() - zUncorrected;

CADEBUG(printf("%14s: SEA Hit %5d (%8.3f %8.3f), Res %f %f\n", "", best, y, z, tParam.Y() - y, tParam.Z() - z));

Expand Down Expand Up @@ -376,9 +394,9 @@ GPUdic(2, 1) void GPUTPCTrackletConstructor::DoTracklet(GPUconstantref() MEM_GLO
r.mNHits = 0;

#ifdef __HIPCC__ // Todo: fixme!
for (int k = -1; ++k < 2; /*k++*/) {
for (int iStage = -1; ++iStage < 2; /*iStage++*/) {
#else
for (int k = 0; k < 2; k++) {
for (int iStage = 0; iStage < 2; iStage++) {
#endif
for (; iRow != iRowEnd; iRow += r.mStage == 2 ? -1 : 1) {
if (!r.mGo) {
Expand All @@ -394,10 +412,23 @@ GPUdic(2, 1) void GPUTPCTrackletConstructor::DoTracklet(GPUconstantref() MEM_GLO
if (r.mStage == 2) {
StoreTracklet(0, 0, 0, 0, s, r, tracker, tParam, rowHits);
} else {
r.mStage = 2;
r.mNMissed = 0;
iRow = r.mEndRow;
iRowEnd = -1;
if ((r.mGo = (tParam.TransportToX(tracker.Row(r.mEndRow).X(), tracker.Param().constBz, GPUCA_MAX_SIN_PHI) && tParam.Filter(r.mLastY, r.mLastZ, tParam.Err2Y() * 0.5f, tParam.Err2Z() * 0.5f, GPUCA_MAX_SIN_PHI_LOW, true)))) {
float x = tracker.Row(r.mEndRow).X();
#if !defined(__OPENCL__) || defined(__OPENCLCPP__)
{
float tmpY, tmpZ;
if (tParam.GetPropagatedYZ(tracker.Param().constBz, x, tmpY, tmpZ)) {
tracker.GetConstantMem()->calibObjects.fastTransformHelper->InverseTransformYZtoX(tracker.ISlice(), iRow, tmpY, tmpZ, x);
} else {
r.mGo = 0;
continue;
}
}
#endif
if ((r.mGo = (tParam.TransportToX(x, tracker.Param().constBz, GPUCA_MAX_SIN_PHI) && tParam.Filter(r.mLastY, r.mLastZ, tParam.Err2Y() * 0.5f, tParam.Err2Z() * 0.5f, GPUCA_MAX_SIN_PHI_LOW, true)))) {
CADEBUG(printf("%14s: SEA BACK ROW %3d X %8.3f -", "", iRow, tParam.X()); for (int i = 0; i < 5; i++) { printf(" %8.3f", tParam.Par()[i]); } printf(" -"); for (int i = 0; i < 15; i++) { printf(" %8.3f", tParam.Cov()[i]); } printf("\n"));
float err2Y, err2Z;
tracker.GetErrors2Seeding(r.mEndRow, tParam, err2Y, err2Z);
Expand All @@ -408,9 +439,8 @@ GPUdic(2, 1) void GPUTPCTrackletConstructor::DoTracklet(GPUconstantref() MEM_GLO
tParam.SetCov(2, err2Z);
}
CADEBUG(printf("%14s: SEA ADJUS ROW %3d X %8.3f -", "", iRow, tParam.X()); for (int i = 0; i < 5; i++) { printf(" %8.3f", tParam.Par()[i]); } printf(" -"); for (int i = 0; i < 15; i++) { printf(" %8.3f", tParam.Cov()[i]); } printf("\n"));
r.mNHits -= r.mNHitsEndRow;
}
r.mNHits -= r.mNHitsEndRow;
r.mStage = 2;
}
}
}
Expand Down

0 comments on commit bd597e8

Please sign in to comment.