Skip to content

Commit 7238e33

Browse files
sgorbunodavidrohr
authored andcommitted
TPC Splines: minimise the amount of transformations
1 parent 156ee04 commit 7238e33

File tree

13 files changed

+268
-488
lines changed

13 files changed

+268
-488
lines changed

Detectors/TPC/calibration/src/TPCFastSpaceChargeCorrectionHelper.cxx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,8 @@ void TPCFastSpaceChargeCorrectionHelper::initGeometry()
6363
mGeo.startConstruction(nRows);
6464

6565
auto& detParam = ParameterDetector::Instance();
66-
float tpcZlengthSideA = detParam.TPClength;
67-
float tpcZlengthSideC = detParam.TPClength;
6866

69-
mGeo.setTPCzLength(tpcZlengthSideA, tpcZlengthSideC);
70-
71-
mGeo.setTPCalignmentZ(0.);
67+
mGeo.setTPCzLength(detParam.TPClength);
7268

7369
for (int iRow = 0; iRow < mGeo.getNumberOfRows(); iRow++) {
7470
Sector sector = 0;
@@ -295,7 +291,7 @@ std::unique_ptr<TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrectionHelper
295291
auto myThread = [&](int iThread) {
296292
for (int iRow = iThread; iRow < nRows; iRow += mNthreads) {
297293
const auto& info = mGeo.getRowInfo(iRow);
298-
double vMax = mGeo.getTPCzLength(iRoc);
294+
double vMax = mGeo.getTPCzLength();
299295
double dv = vMax / (6. * (nKnotsZ - 1));
300296

301297
double dpad = info.maxPad / (6. * (nKnotsY - 1));
@@ -512,8 +508,8 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
512508
double zMax = rowInfo.x * trackResiduals.getZ2X(trackResiduals.getNZ2XBins() - 1);
513509
double uMin = yMin;
514510
double uMax = yMax;
515-
double vMin = geo.getTPCzLength(iRoc) - zMax;
516-
double vMax = geo.getTPCzLength(iRoc) - zMin;
511+
double vMin = geo.getTPCzLength() - zMax;
512+
double vMax = geo.getTPCzLength() - zMin;
517513
info.gridU0 = uMin;
518514
info.scaleUtoGrid = spline.getGridX1().getUmax() / (uMax - uMin);
519515
info.gridV0 = vMin;
@@ -822,7 +818,7 @@ void TPCFastSpaceChargeCorrectionHelper::initMaxDriftLength(o2::gpu::TPCFastSpac
822818
if (prn) {
823819
LOG(info) << "init MaxDriftLength for roc " << roc;
824820
}
825-
double vLength = (roc < mGeo.getNumberOfRocsA()) ? mGeo.getTPCzLengthA() : mGeo.getTPCzLengthC();
821+
double vLength = mGeo.getTPCzLength();
826822
TPCFastSpaceChargeCorrection::RocInfo& rocInfo = correction.getRocInfo(roc);
827823
rocInfo.vMax = 0.f;
828824

@@ -843,7 +839,7 @@ void TPCFastSpaceChargeCorrectionHelper::initMaxDriftLength(o2::gpu::TPCFastSpac
843839
while (v1 - v0 > 0.1) {
844840
float v = 0.5 * (v0 + v1);
845841
float dx, du, dv;
846-
correction.getCorrection(roc, row, u, v, dx, du, dv);
842+
correction.getCorrectionInternal(roc, row, u, v, dx, du, dv);
847843
double cx = x + dx;
848844
double cu = u + du;
849845
double cv = v + dv;
@@ -962,14 +958,14 @@ void TPCFastSpaceChargeCorrectionHelper::initInverse(std::vector<o2::gpu::TPCFas
962958
correction.convGridToUV(roc, row, gridU[iu], gridV[iv], u, v);
963959

964960
float dx, du, dv;
965-
correction.getCorrection(roc, row, u, v, dx, du, dv);
961+
correction.getCorrectionInternal(roc, row, u, v, dx, du, dv);
966962
dx *= scaling[0];
967963
du *= scaling[0];
968964
dv *= scaling[0];
969965
// add remaining corrections
970966
for (int i = 1; i < corrections.size(); ++i) {
971967
float dxTmp, duTmp, dvTmp;
972-
corrections[i]->getCorrection(roc, row, u, v, dxTmp, duTmp, dvTmp);
968+
corrections[i]->getCorrectionInternal(roc, row, u, v, dxTmp, duTmp, dvTmp);
973969
dx += dxTmp * scaling[i];
974970
du += duTmp * scaling[i];
975971
dv += dvTmp * scaling[i];

Detectors/TPC/reconstruction/src/TPCFastTransformHelperO2.cxx

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,7 @@ void TPCFastTransformHelperO2::init()
5656
mGeo.startConstruction(nRows);
5757

5858
auto& detParam = ParameterDetector::Instance();
59-
float tpcZlengthSideA = detParam.TPClength;
60-
float tpcZlengthSideC = detParam.TPClength;
61-
62-
mGeo.setTPCzLength(tpcZlengthSideA, tpcZlengthSideC);
63-
64-
mGeo.setTPCalignmentZ(0.);
59+
mGeo.setTPCzLength(detParam.TPClength);
6560

6661
for (int iRow = 0; iRow < mGeo.getNumberOfRows(); iRow++) {
6762
Sector sector = 0;
@@ -114,12 +109,8 @@ std::unique_ptr<TPCFastTransform> TPCFastTransformHelperO2::create(Long_t TimeSt
114109
// set some initial calibration values, will be reinitialised later int updateCalibration()
115110
const float t0 = 0.;
116111
const float vDrift = 0.f;
117-
const float vdCorrY = 0.;
118-
const float ldCorr = 0.;
119-
const float tofCorr = 0.;
120-
const float primVtxZ = 0.;
121112
const long int initTimeStamp = -1;
122-
fastTransform.setCalibration(initTimeStamp, t0, vDrift, vdCorrY, ldCorr, tofCorr, primVtxZ);
113+
fastTransform.setCalibration1(initTimeStamp, t0, vDrift);
123114

124115
fastTransform.finishConstruction();
125116
}
@@ -171,19 +162,13 @@ int TPCFastTransformHelperO2::updateCalibration(TPCFastTransform& fastTransform,
171162
const double vDrift = elParam.ZbinWidth * vDriftRef * vDriftFactor; // cm/timebin
172163

173164
// fast transform formula:
174-
// L = (t-t0)*(mVdrift + mVdriftCorrY*yLab ) + mLdriftCorr
175-
// Z = Z(L) + tpcAlignmentZ
165+
// L = (t-t0)*mVdrift
166+
// Z = Z(L)
176167
// spline corrections for xyz
177-
// Time-of-flight correction: ldrift += dist-to-vtx*tofCorr
178168

179169
const double t0 = (driftTimeOffset + elParam.getAverageShapingTime()) / elParam.ZbinWidth;
180170

181-
const double vdCorrY = 0.;
182-
const double ldCorr = 0.;
183-
const double tofCorr = 0.;
184-
const double primVtxZ = 0.;
185-
186-
fastTransform.setCalibration(TimeStamp, t0, vDrift, vdCorrY, ldCorr, tofCorr, primVtxZ);
171+
fastTransform.setCalibration1(TimeStamp, t0, vDrift);
187172

188173
return 0;
189174
}

Detectors/TPC/reconstruction/test/testTPCFastTransform.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE(FastTransform_test1)
7272
const GlobalPadNumber p = mapper.globalPadNumber(PadPos(row, pad));
7373
const PadCentre& c = mapper.padCentre(p);
7474
float u = 0, v = 0;
75-
fastTransform.convPadTimeToUV(0, row, pad, 0, u, v, 0.);
75+
fastTransform.convPadTimeToUV(row, pad, 0, u, v, 0.);
7676

7777
double dx = x - c.X();
7878
double dy = u - (-c.Y()); // diferent sign convention for Y coordinate in the map
@@ -192,8 +192,8 @@ BOOST_AUTO_TEST_CASE(FastTransform_test_setSpaceChargeCorrection)
192192
correctionUV(roc, row, u0, v0, dx, du, dv);
193193
statDiff += fabs((x1 - x0) - dx) + fabs((u1 - u0) - du) + fabs((v1 - v0) - dv);
194194
statN += 3;
195-
//std::cout << (x1 - x0) - dx << " " << (u1 - u0) - du << " " << (v1 - v0) - dv << std::endl; //": v0 " << v0 <<" z0 "<<z0<<" v1 "<< v1<<" z1 "<<z1 << std::endl;
196-
//BOOST_CHECK_MESSAGE(0, "SG");
195+
// std::cout << (x1 - x0) - dx << " " << (u1 - u0) - du << " " << (v1 - v0) - dv << std::endl; //": v0 " << v0 <<" z0 "<<z0<<" v1 "<< v1<<" z1 "<<z1 << std::endl;
196+
// BOOST_CHECK_MESSAGE(0, "SG");
197197

198198
float x1f, y1f, z1f;
199199
fromFile->Transform(roc, row, pad, time, x1f, y1f, z1f);

GPU/GPUTracking/Merger/GPUTPCGMSectorTrack.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ GPUd() void GPUTPCGMSectorTrack::Set(const GPUTPCGMMerger* merger, const GPUTPCT
3737
mParam.mSecPhi = 1.f / mParam.mCosPhi;
3838
mAlpha = alpha;
3939
mSector = sector;
40-
mTOffset = merger->Param().par.continuousTracking ? merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convZOffsetToVertexTime(sector, t.GetZOffset(), merger->Param().continuousMaxTimeBin) : 0;
40+
mTOffset = merger->Param().par.continuousTracking ? merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convZOffsetToVertexTime(t.GetZOffset(), merger->Param().continuousMaxTimeBin) : 0;
4141
mNClusters = sectorTr->NHits();
4242
}
4343

@@ -323,7 +323,7 @@ GPUd() bool GPUTPCGMSectorTrack::TransportToX(GPUTPCGMMerger* merger, float x, f
323323
b.SetPar(2, ey1);
324324
b.SetPar(3, param.mDzDs);
325325
b.SetPar(4, param.mQPt);
326-
b.SetZOffsetLinear(merger->Param().par.continuousTracking ? merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(mSector, mTOffset, merger->Param().continuousMaxTimeBin) : 0);
326+
b.SetZOffsetLinear(merger->Param().par.continuousTracking ? merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(mTOffset, merger->Param().continuousMaxTimeBin) : 0);
327327

328328
if (!doCov) {
329329
return (1);
@@ -478,7 +478,7 @@ GPUd() bool GPUTPCGMSectorTrack::TransportToXAlpha(GPUTPCGMMerger* merger, float
478478
b.SetPar(2, ey1);
479479
b.SetPar(3, dzds);
480480
b.SetPar(4, qpt);
481-
b.SetZOffsetLinear(merger->Param().par.continuousTracking ? merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(mSector, mTOffset, merger->Param().continuousMaxTimeBin) : 0);
481+
b.SetZOffsetLinear(merger->Param().par.continuousTracking ? merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(mTOffset, merger->Param().continuousMaxTimeBin) : 0);
482482

483483
b.SetCov(0, c00 + h2 * h2c22 + h4 * h4c44 + 2.f * (h2 * c20ph4c42 + h4 * c40));
484484
b.SetCov(1, c11 + dS * (c31 + n7));

GPU/GPUTracking/display/render/GPUDisplayDraw.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,13 +555,13 @@ void GPUDisplay::DrawFinal(int32_t iSector, int32_t /*iCol*/, const GPUTPCGMProp
555555
if constexpr (std::is_same_v<T, GPUTPCGMMergedTrack>) {
556556
auto cl = mIOPtrs->mergedTrackHits[track->FirstClusterRef() + lastCluster];
557557
const auto& cln = mIOPtrs->clustersNative->clustersLinear[cl.num];
558-
GPUTPCConvertImpl::convert(*mCalib->fastTransform, *mParam, cl.sector, cl.row, cln.getPad(), cln.getTime(), x, y, z);
559-
ZOffset = mCalib->fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(iSector, track->GetParam().GetTOffset(), mParam->continuousMaxTimeBin);
558+
GPUTPCConvertImpl::convert(*mCalib->fastTransform, *mParam, cl.slice, cl.row, cln.getPad(), cln.getTime(), x, y, z);
559+
ZOffset = mCalib->fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(track->GetParam().GetTOffset(), mParam->continuousMaxTimeBin);
560560
} else {
561561
uint8_t sector, row;
562562
auto cln = track->getCluster(mIOPtrs->outputClusRefsTPCO2, lastCluster, *mIOPtrs->clustersNative, sector, row);
563563
GPUTPCConvertImpl::convert(*mCalib->fastTransform, *mParam, sector, row, cln.getPad(), cln.getTime(), x, y, z);
564-
ZOffset = mCalib->fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(sector, track->getTime0(), mParam->continuousMaxTimeBin);
564+
ZOffset = mCalib->fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(track->getTime0(), mParam->continuousMaxTimeBin);
565565
}
566566
} else {
567567
const GPUTPCMCInfo& mc = mIOPtrs->mcInfosTPC[i];
@@ -593,7 +593,7 @@ void GPUDisplay::DrawFinal(int32_t iSector, int32_t /*iCol*/, const GPUTPCGMProp
593593
#ifdef GPUCA_TPC_GEOMETRY_O2
594594
trkParam.Set(mclocal[0], mclocal[1], mc.z, mclocal[2], mclocal[3], mc.pZ, -charge); // TODO: DR: unclear to me why we need -charge here
595595
if (mParam->par.continuousTracking) {
596-
ZOffset = fabsf(mCalib->fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(0, mc.t0, mParam->continuousMaxTimeBin)) * (mc.z < 0 ? -1 : 1);
596+
ZOffset = fabsf(mCalib->fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(mc.t0, mParam->continuousMaxTimeBin)) * (mc.z < 0 ? -1 : 1);
597597
}
598598
#else
599599
if (fabsf(mc.z) > GPUTPCGeometry::TPCLength()) {

GPU/GPUTracking/display/render/GPUDisplayImportEvent.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void GPUDisplay::DrawGLScene_updateEventData()
180180
while (mParam->par.continuousTracking && trdTriggerRecord < (int32_t)mIOPtrs->nTRDTriggerRecords - 1 && mIOPtrs->trdTrackletIdxFirst[trdTriggerRecord + 1] <= i) {
181181
trdTriggerRecord++; // This requires to go through the data in order I believe
182182
float trdTime = mIOPtrs->trdTriggerTimes[trdTriggerRecord] * 1e3 / o2::constants::lhc::LHCBunchSpacingNS / o2::tpc::constants::LHCBCPERTIMEBIN;
183-
trdZoffset = fabsf(mCalib->fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(0, trdTime, mParam->continuousMaxTimeBin));
183+
trdZoffset = fabsf(mCalib->fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(trdTime, mParam->continuousMaxTimeBin));
184184
}
185185
const auto& sp = mIOPtrs->trdSpacePoints[i];
186186
int32_t iSec = trdGeometry()->GetSector(mIOPtrs->trdTracklets[i].GetDetector());
@@ -218,7 +218,7 @@ void GPUDisplay::DrawGLScene_updateEventData()
218218
float ZOffset = 0;
219219
if (mParam->par.continuousTracking) {
220220
float tofTime = mIOPtrs->tofClusters[i].getTime() * 1e-3 / o2::constants::lhc::LHCBunchSpacingNS / o2::tpc::constants::LHCBCPERTIMEBIN;
221-
ZOffset = fabsf(mCalib->fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(0, tofTime, mParam->continuousMaxTimeBin));
221+
ZOffset = fabsf(mCalib->fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(tofTime, mParam->continuousMaxTimeBin));
222222
ptr->z += ptr->z > 0 ? ZOffset : -ZOffset;
223223
}
224224
if (fabsf(ptr->z) > maxClusterZ) {
@@ -249,7 +249,7 @@ void GPUDisplay::DrawGLScene_updateEventData()
249249
if (mParam->par.continuousTracking) {
250250
o2::InteractionRecord startIR = o2::InteractionRecord(0, mIOPtrs->settingsTF && mIOPtrs->settingsTF->hasTfStartOrbit ? mIOPtrs->settingsTF->tfStartOrbit : 0);
251251
float itsROFtime = mIOPtrs->itsClusterROF[j].getBCData().differenceInBC(startIR) / (float)o2::tpc::constants::LHCBCPERTIMEBIN;
252-
ZOffset = fabsf(mCalib->fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(0, itsROFtime + itsROFhalfLen, mParam->continuousMaxTimeBin));
252+
ZOffset = fabsf(mCalib->fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(itsROFtime + itsROFhalfLen, mParam->continuousMaxTimeBin));
253253
}
254254
if (i != mIOPtrs->itsClusterROF[j].getFirstEntry()) {
255255
throw std::runtime_error("Inconsistent ITS data, number of clusters does not match ROF content");

GPU/TPCFastTransformation/TPCFastSpaceChargeCorrection.cxx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ void TPCFastSpaceChargeCorrection::setActualBufferAddress(char* actualFlatBuffer
225225
info.scaleUtoGrid = spline.getGridX1().getUmax() / mGeo.getRowInfo(row).getUwidth();
226226

227227
info.gridV0 = infoOld.gridV0;
228-
info.scaleVtoGrid = spline.getGridX2().getUmax() / (mGeo.getTPCzLength(roc) + 3. - info.gridV0);
228+
info.scaleVtoGrid = spline.getGridX2().getUmax() / (mGeo.getTPCzLength() + 3. - info.gridV0);
229229

230230
info.gridCorrU0 = infoOld.gridCorrU0;
231231
info.scaleCorrUtoGrid = infoOld.scaleCorrUtoGrid;
@@ -440,7 +440,7 @@ GPUd() void TPCFastSpaceChargeCorrection::setNoCorrection()
440440
{
441441
// initialise all corrections to 0.
442442
for (int32_t roc = 0; roc < mGeo.getNumberOfRocs(); roc++) {
443-
double vLength = (roc < mGeo.getNumberOfRocsA()) ? mGeo.getTPCzLengthA() : mGeo.getTPCzLengthC();
443+
double vLength = mGeo.getTPCzLength();
444444
RocInfo& rocInfo = getRocInfo(roc);
445445
rocInfo.vMax = vLength;
446446
for (int32_t row = 0; row < mGeo.getNumberOfRows(); row++) {
@@ -548,12 +548,14 @@ double TPCFastSpaceChargeCorrection::testInverse(bool prn)
548548
if (prn) {
549549
LOG(info) << "check inverse transform for roc " << roc;
550550
}
551-
double vLength = mGeo.getTPCzLength(roc);
551+
double vLength = mGeo.getTPCzLength();
552552
MaxValue maxDroc[3];
553553
for (int32_t row = 0; row < mGeo.getNumberOfRows(); row++) {
554-
float u0, u1, v0, v1;
555-
mGeo.convScaledUVtoUV(roc, row, 0., 0., u0, v0);
556-
mGeo.convScaledUVtoUV(roc, row, 1., 1., u1, v1);
554+
float u0 = mGeo.getRowInfo(row).getUmin();
555+
float u1 = mGeo.getRowInfo(row).getUmax();
556+
float v0 = 0.;
557+
float v1 = vLength;
558+
557559
double x = mGeo.getRowInfo(row).x;
558560
double stepU = (u1 - u0) / 100.;
559561
double stepV = (v1 - v0) / 100.;
@@ -564,7 +566,7 @@ double TPCFastSpaceChargeCorrection::testInverse(bool prn)
564566
continue;
565567
}
566568
float dx, du, dv;
567-
getCorrection(roc, row, u, v, dx, du, dv);
569+
getCorrectionInternal(roc, row, u, v, dx, du, dv);
568570
double cx = x + dx;
569571
double cu = u + du;
570572
double cv = v + dv;

GPU/TPCFastTransformation/TPCFastSpaceChargeCorrection.h

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ class TPCFastSpaceChargeCorrection : public FlatObject
180180

181181
/// _______________ The main method: cluster correction _______________________
182182
///
183-
GPUd() int32_t getCorrection(int32_t roc, int32_t row, float u, float v, float& dx, float& du, float& dv) const;
183+
GPUd() int32_t getCorrectionInternal(int32_t roc, int32_t row, float u, float v, float& dx, float& du, float& dv) const;
184+
185+
GPUdi() std::tuple<float, float, float> getCorrectionLocal(int32_t roc, int32_t row, float y, float z) const;
184186

185187
/// inverse correction: Corrected U and V -> coorrected X
186188
GPUd() void getCorrectionInvCorrectedX(int32_t roc, int32_t row, float corrU, float corrV, float& corrX) const;
@@ -199,6 +201,10 @@ class TPCFastSpaceChargeCorrection : public FlatObject
199201

200202
/// _______________ Utilities _______________________________________________
201203

204+
/// convert local y, z to internal grid coordinates u,v
205+
/// return values: u, v, scaling factor
206+
GPUd() std::tuple<float, float, float> convLocalToGrid(int32_t roc, int32_t row, float y, float z) const;
207+
202208
/// convert u,v to internal grid coordinates
203209
GPUd() void convUVtoGrid(int32_t roc, int32_t row, float u, float v, float& gridU, float& gridV) const;
204210

@@ -259,9 +265,6 @@ class TPCFastSpaceChargeCorrection : public FlatObject
259265
/// release temporary memory used during construction
260266
void releaseConstructionMemory();
261267

262-
/// temporary method with the an way of calculating 2D spline
263-
GPUd() int32_t getCorrectionOld(int32_t roc, int32_t row, float u, float v, float& dx, float& du, float& dv) const;
264-
265268
/// _______________ Data members _______________________________________________
266269

267270
/// _______________ Construction control _______________________________________________
@@ -354,7 +357,7 @@ GPUdi() void TPCFastSpaceChargeCorrection::convCorrectedUVtoGrid(int32_t roc, in
354357
gridV = (corrV - info.gridCorrV0) * info.scaleCorrVtoGrid;
355358
}
356359

357-
GPUdi() int32_t TPCFastSpaceChargeCorrection::getCorrection(int32_t roc, int32_t row, float u, float v, float& dx, float& du, float& dv) const
360+
GPUdi() int32_t TPCFastSpaceChargeCorrection::getCorrectionInternal(int32_t roc, int32_t row, float u, float v, float& dx, float& du, float& dv) const
358361
{
359362
const auto& info = getRocRowInfo(roc, row);
360363
const SplineType& spline = getSpline(roc, row);
@@ -382,26 +385,41 @@ GPUdi() int32_t TPCFastSpaceChargeCorrection::getCorrection(int32_t roc, int32_t
382385
return 0;
383386
}
384387

385-
GPUdi() int32_t TPCFastSpaceChargeCorrection::getCorrectionOld(int32_t roc, int32_t row, float u, float v, float& dx, float& du, float& dv) const
388+
GPUdi() std::tuple<float, float, float> TPCFastSpaceChargeCorrection::getCorrectionLocal(int32_t roc, int32_t row, float y, float z) const
386389
{
390+
const auto& info = getRocRowInfo(roc, row);
387391
const SplineType& spline = getSpline(roc, row);
388392
const float* splineData = getSplineData(roc, row);
393+
394+
float u, v;
395+
396+
mGeo.convLocalToUV(roc, y, z, u, v);
397+
389398
float gridU = 0, gridV = 0;
390399
convUVtoGrid(roc, row, u, v, gridU, gridV);
400+
// shrink to the grid area
401+
gridU = GPUCommonMath::Clamp(gridU, 0.f, (float)spline.getGridX1().getUmax());
402+
gridV = GPUCommonMath::Clamp(gridV, 0.f, (float)spline.getGridX2().getUmax());
403+
391404
float dxuv[3];
392-
spline.interpolateUold(splineData, gridU, gridV, dxuv);
393-
const auto& info = getRocRowInfo(roc, row);
405+
spline.interpolateU(splineData, gridU, gridV, dxuv);
406+
394407
float s = v / info.gridV0;
395-
if (s < 0.) {
396-
s = 0.;
397-
}
398-
if (s > 1.) {
399-
s = 1.;
408+
409+
if (v >= info.gridV0) {
410+
s = 1.f;
411+
} else if (v <= 0.f) {
412+
s = 0.f;
400413
}
401-
dx = GPUCommonMath::Max(info.minCorr[0], GPUCommonMath::Min(info.maxCorr[0], s * dxuv[0]));
402-
du = GPUCommonMath::Max(info.minCorr[1], GPUCommonMath::Min(info.maxCorr[1], s * dxuv[1]));
403-
dv = GPUCommonMath::Max(info.minCorr[2], GPUCommonMath::Min(info.maxCorr[2], s * dxuv[2]));
404-
return 0;
414+
415+
float dx = GPUCommonMath::Clamp(s * dxuv[0], info.minCorr[0], info.maxCorr[0]);
416+
float du = GPUCommonMath::Clamp(s * dxuv[1], info.minCorr[1], info.maxCorr[1]);
417+
float dv = GPUCommonMath::Clamp(s * dxuv[2], info.minCorr[2], info.maxCorr[2]);
418+
419+
float dy, dz;
420+
mGeo.convUVtoLocal(roc, du, dv, dy, dz);
421+
422+
return {dx, dy, dz};
405423
}
406424

407425
GPUdi() void TPCFastSpaceChargeCorrection::getCorrectionInvCorrectedX(

0 commit comments

Comments
 (0)