Skip to content

Commit d75e375

Browse files
sgorbunodavidrohr
authored andcommitted
TPC Splines: minimise the amount of transformations
1 parent dbf53a0 commit d75e375

File tree

10 files changed

+262
-474
lines changed

10 files changed

+262
-474
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/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(

GPU/TPCFastTransformation/TPCFastTransform.cxx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
using namespace o2::gpu;
3838

3939
TPCFastTransform::TPCFastTransform()
40-
: FlatObject(), mTimeStamp(0), mCorrection(), mApplyCorrection(1), mT0(0.f), mVdrift(0.f), mVdriftCorrY(0.f), mLdriftCorr(0.f), mTOFcorr(0.f), mPrimVtxZ(0.f), mLumi(TPCFastTransform::DEFLUMI), mLumiError(0.f), mLumiScaleFactor(1.0f), mIDC(TPCFastTransform::DEFIDC), mIDCError(0.f), mCTP2IDCFallBackThreshold(30.f)
40+
: FlatObject(), mTimeStamp(0), mCorrection(), mApplyCorrection(1), mT0(0.f), mVdrift(0.f), mLumi(TPCFastTransform::DEFLUMI), mLumiError(0.f), mLumiScaleFactor(1.0f), mIDC(TPCFastTransform::DEFIDC), mIDCError(0.f), mCTP2IDCFallBackThreshold(30.f)
4141
{
4242
// Default Constructor: creates an empty uninitialized object
4343
}
@@ -54,10 +54,6 @@ void TPCFastTransform::cloneFromObject(const TPCFastTransform& obj, char* newFla
5454
mApplyCorrection = obj.mApplyCorrection;
5555
mT0 = obj.mT0;
5656
mVdrift = obj.mVdrift;
57-
mVdriftCorrY = obj.mVdriftCorrY;
58-
mLdriftCorr = obj.mLdriftCorr;
59-
mTOFcorr = obj.mTOFcorr;
60-
mPrimVtxZ = obj.mPrimVtxZ;
6157
mLumi = obj.mLumi;
6258
mLumiError = obj.mLumiError;
6359
mIDC = obj.mIDC;
@@ -123,7 +119,7 @@ void TPCFastTransform::startConstruction(const TPCFastSpaceChargeCorrection& cor
123119
mCorrection.cloneFromObject(correction, nullptr);
124120
}
125121

126-
void TPCFastTransform::setCalibration(int64_t timeStamp, float t0, float vDrift, float vDriftCorrY, float lDriftCorr, float tofCorr, float primVtxZ)
122+
void TPCFastTransform::setCalibration1(int64_t timeStamp, float t0, float vDrift)
127123
{
128124
/// Sets all drift calibration parameters and the time stamp
129125
///
@@ -133,10 +129,6 @@ void TPCFastTransform::setCalibration(int64_t timeStamp, float t0, float vDrift,
133129
mTimeStamp = timeStamp;
134130
mT0 = t0;
135131
mVdrift = vDrift;
136-
mVdriftCorrY = vDriftCorrY;
137-
mLdriftCorr = lDriftCorr;
138-
mTOFcorr = tofCorr;
139-
mPrimVtxZ = primVtxZ;
140132
mConstructionMask |= ConstructionExtraState::CalibrationIsSet;
141133
}
142134

@@ -160,10 +152,6 @@ void TPCFastTransform::print() const
160152
LOG(info) << "mApplyCorrection = " << mApplyCorrection;
161153
LOG(info) << "mT0 = " << mT0;
162154
LOG(info) << "mVdrift = " << mVdrift;
163-
LOG(info) << "mVdriftCorrY = " << mVdriftCorrY;
164-
LOG(info) << "mLdriftCorr = " << mLdriftCorr;
165-
LOG(info) << "mTOFcorr = " << mTOFcorr;
166-
LOG(info) << "mPrimVtxZ = " << mPrimVtxZ;
167155
LOG(info) << "mLumi = " << mLumi;
168156
LOG(info) << "mLumiError = " << mLumiError;
169157
LOG(info) << "mIDC = " << mIDC;

0 commit comments

Comments
 (0)