Skip to content

Commit 7a7a09e

Browse files
sgorbunodavidrohr
authored andcommitted
TPC Splines: get rid of internal UV coordinates
1 parent df01596 commit 7a7a09e

File tree

8 files changed

+124
-253
lines changed

8 files changed

+124
-253
lines changed

Detectors/TPC/calibration/src/TPCFastSpaceChargeCorrectionHelper.cxx

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -354,15 +354,14 @@ void TPCFastSpaceChargeCorrectionHelper::testGeometry(const TPCFastTransformGeo&
354354
for (int pad = 0; pad < nPads; pad++) {
355355
const GlobalPadNumber p = mapper.globalPadNumber(PadPos(row, pad));
356356
const PadCentre& c = mapper.padCentre(p);
357-
double u = geo.convPadToU(row, pad);
358-
357+
auto [y, z] = geo.convPadDriftLengthToLocal(0, row, pad, 0.);
359358
const double dx = x - c.X();
360-
const double dy = u - (-c.Y()); // diferent sign convention for Y coordinate in the map
359+
const double dy = y - (-c.Y()); // diferent sign convention for Y coordinate in the map
361360

362361
if (fabs(dx) >= 1.e-6 || fabs(dy) >= 1.e-5) {
363362
LOG(warning) << "wrong calculated pad position:"
364363
<< " row " << row << " pad " << pad << " x calc " << x << " x in map " << c.X() << " dx " << (x - c.X())
365-
<< " y calc " << u << " y in map " << -c.Y() << " dy " << dy << std::endl;
364+
<< " y calc " << y << " y in map " << -c.Y() << " dy " << dy << std::endl;
366365
}
367366
if (fabs(maxDx) < fabs(dx)) {
368367
maxDx = dx;
@@ -499,18 +498,14 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
499498
double yMax = rowInfo.x * trackResiduals.getY2X(iRow, trackResiduals.getNY2XBins() - 1);
500499
double zMin = rowInfo.x * trackResiduals.getZ2X(0);
501500
double zMax = rowInfo.x * trackResiduals.getZ2X(trackResiduals.getNZ2XBins() - 1);
502-
double uMin = yMin;
503-
double uMax = yMax;
504-
double vMin = geo.getTPCzLength() - zMax;
505-
double vMax = geo.getTPCzLength() - zMin;
506-
info.gridU0 = uMin;
507-
info.scaleUtoGrid = spline.getGridX1().getUmax() / (uMax - uMin);
508-
info.gridV0 = vMin;
509-
info.scaleVtoGrid = spline.getGridX2().getUmax() / (vMax - vMin);
510-
info.gridCorrU0 = info.gridU0;
511-
info.gridCorrV0 = info.gridV0;
512-
info.scaleCorrUtoGrid = info.scaleUtoGrid;
513-
info.scaleCorrVtoGrid = info.scaleVtoGrid;
501+
double lMin = geo.getTPCzLength() - zMax;
502+
double lMax = geo.getTPCzLength() - zMin;
503+
info.gridMeasured.y0 = yMin;
504+
info.gridMeasured.yScale = spline.getGridX1().getUmax() / (yMax - yMin);
505+
info.gridMeasured.l0 = lMin;
506+
info.gridMeasured.lScale = spline.getGridX2().getUmax() / (lMax - lMin);
507+
508+
info.gridReal = info.gridMeasured;
514509

515510
// std::cout << " iSector " << iSector << " iRow " << iRow << " uMin: " << uMin << " uMax: " << uMax << " vMin: " << vMin << " vMax: " << vMax
516511
//<< " grid scale u "<< info.scaleUtoGrid << " grid scale v "<< info.scaleVtoGrid<< std::endl;
@@ -593,8 +588,8 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
593588

594589
auto myThread = [&](int iThread, int nTreads) {
595590
struct Voxel {
596-
float mY, mZ; // not-distorted local coordinates
597-
float mDy, mDz; // bin size
591+
float mY, mZ; // non-distorted local coordinates
592+
float mDy, mDz; // voxel size
598593
int mSmoothingStep{100}; // is the voxel data original or smoothed at this step
599594
};
600595

@@ -905,11 +900,10 @@ void TPCFastSpaceChargeCorrectionHelper::initInverse(std::vector<o2::gpu::TPCFas
905900

906901
double realY = y + dy;
907902
double realZ = z + dz;
908-
float realU, realV;
909-
mGeo.convLocalToUV1(sector, realY, realZ, realU, realV);
903+
double realL = mGeo.convZtoDriftLength(sector, realZ);
910904

911-
dataPointGridU.push_back(realU);
912-
dataPointGridV.push_back(realV);
905+
dataPointGridU.push_back(realY);
906+
dataPointGridV.push_back(realL);
913907
dataPointF.push_back(dx);
914908
dataPointF.push_back(dy);
915909
dataPointF.push_back(dz);
@@ -920,17 +914,14 @@ void TPCFastSpaceChargeCorrectionHelper::initInverse(std::vector<o2::gpu::TPCFas
920914

921915
auto& sectorRowInfo = correction.getSectorRowInfo(sector, row);
922916

923-
sectorRowInfo.gridCorrU0 = sectorRowInfo.gridU0;
924-
sectorRowInfo.gridCorrV0 = sectorRowInfo.gridV0;
925-
sectorRowInfo.scaleCorrUtoGrid = sectorRowInfo.scaleUtoGrid;
926-
sectorRowInfo.scaleCorrVtoGrid = sectorRowInfo.scaleVtoGrid;
917+
sectorRowInfo.gridReal = sectorRowInfo.gridMeasured;
927918

928919
int nDataPoints = dataPointGridU.size();
929920

930921
// convert real Y,Z to grid U,V
931922
for (int i = 0; i < nDataPoints; i++) {
932-
dataPointGridU[i] = (dataPointGridU[i] - sectorRowInfo.gridCorrU0) * sectorRowInfo.scaleCorrUtoGrid;
933-
dataPointGridV[i] = (dataPointGridV[i] - sectorRowInfo.gridCorrV0) * sectorRowInfo.scaleCorrVtoGrid;
923+
dataPointGridU[i] = (dataPointGridU[i] - sectorRowInfo.gridReal.y0) * sectorRowInfo.gridReal.yScale;
924+
dataPointGridV[i] = (dataPointGridV[i] - sectorRowInfo.gridReal.l0) * sectorRowInfo.gridReal.lScale;
934925
}
935926

936927
splineParameters.resize(spline.getNumberOfParameters());
@@ -1035,8 +1026,10 @@ void TPCFastSpaceChargeCorrectionHelper::MergeCorrections(
10351026
secRowInfo.updateMaxValues(linfo.getMaxValues(), scale);
10361027
secRowInfo.updateMaxValues(linfo.getMinValues(), scale);
10371028

1038-
double scaleU = secRowInfo.scaleUtoGrid / linfo.scaleUtoGrid;
1039-
double scaleV = secRowInfo.scaleVtoGrid / linfo.scaleVtoGrid;
1029+
double scaleU = secRowInfo.gridMeasured.yScale / linfo.gridMeasured.yScale;
1030+
double scaleV = secRowInfo.gridMeasured.lScale / linfo.gridMeasured.lScale;
1031+
double scaleRealU = secRowInfo.gridReal.yScale / linfo.gridReal.yScale;
1032+
double scaleRealV = secRowInfo.gridReal.lScale / linfo.gridReal.lScale;
10401033

10411034
for (int iu = 0; iu < gridU.getNumberOfKnots(); iu++) {
10421035
double u = gridU.getKnot(iu).u;
@@ -1060,11 +1053,11 @@ void TPCFastSpaceChargeCorrectionHelper::MergeCorrections(
10601053
}
10611054
}
10621055

1063-
auto [y, z] = mainCorrection.convGridToCorrectedLocal(sector, row, u, v);
1056+
auto [y, z] = mainCorrection.convGridToRealLocal(sector, row, u, v);
10641057
// return values: u, v, scaling factor
1065-
auto [lu, lv, ls] = corr.convCorrectedLocalToGrid(sector, row, y, z);
1058+
auto [lu, lv, ls] = corr.convRealLocalToGrid(sector, row, y, z);
10661059
ls *= scale;
1067-
double parscale[4] = {ls, ls * scaleU, ls * scaleV, ls * ls * scaleU * scaleV};
1060+
double parscale[4] = {ls, ls * scaleRealU, ls * scaleRealV, ls * ls * scaleRealU * scaleRealV};
10681061

10691062
{ // inverse X correction
10701063
corr.getSplineInvX(sector, row).interpolateParametersAtU(corr.getSplineDataInvX(sector, row), lu, lv, P);

Detectors/TPC/reconstruction/src/TPCFastTransformHelperO2.cxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,16 @@ void TPCFastTransformHelperO2::testGeometry(const TPCFastTransformGeo& geo) cons
202202
for (int pad = 0; pad < nPads; pad++) {
203203
const GlobalPadNumber p = mapper.globalPadNumber(PadPos(row, pad));
204204
const PadCentre& c = mapper.padCentre(p);
205-
double u = geo.convPadToU(row, pad);
205+
206+
auto [y, z] = geo.convPadDriftLengthToLocal(0, row, pad, 0.);
206207

207208
const double dx = x - c.X();
208-
const double dy = u - (-c.Y()); // diferent sign convention for Y coordinate in the map
209+
const double dy = y - (-c.Y()); // diferent sign convention for Y coordinate in the map
209210

210211
if (fabs(dx) >= 1.e-6 || fabs(dy) >= 1.e-5) {
211212
LOG(warning) << "wrong calculated pad position:"
212213
<< " row " << row << " pad " << pad << " x calc " << x << " x in map " << c.X() << " dx " << (x - c.X())
213-
<< " y calc " << u << " y in map " << -c.Y() << " dy " << dy << std::endl;
214+
<< " y calc " << y << " y in map " << -c.Y() << " dy " << dy << std::endl;
214215
}
215216
if (fabs(maxDx) < fabs(dx)) {
216217
maxDx = dx;

GPU/TPCFastTransformation/TPCFastSpaceChargeCorrection.cxx

Lines changed: 13 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -141,48 +141,18 @@ void TPCFastSpaceChargeCorrection::setActualBufferAddress(char* actualFlatBuffer
141141
{
142142
/// Sets the actual location of the external flat buffer after it has been moved (e.g. to another maschine)
143143

144-
struct RowInfoVersion3 {
145-
int32_t splineScenarioID{0}; ///< scenario index (which of Spline2D splines to use)
146-
size_t dataOffsetBytes[3]{0}; ///< offset for the spline data withing a TPC sector
147-
};
148-
149-
struct RowActiveAreaVersion3 {
150-
float maxDriftLengthCheb[5]{0.f};
151-
float vMax{0.f};
152-
float cuMin{0.f};
153-
float cuMax{0.f};
154-
float cvMax{0.f};
155-
};
156-
157-
struct SectorRowInfoVersion3 {
158-
float gridV0{0.f}; ///< V coordinate of the V-grid start
159-
float gridCorrU0{0.f}; ///< U coordinate of the U-grid start for corrected U
160-
float gridCorrV0{0.f}; ///< V coordinate of the V-grid start for corrected V
161-
float scaleCorrUtoGrid{0.f}; ///< scale corrected U to U-grid coordinate
162-
float scaleCorrVtoGrid{0.f}; ///< scale corrected V to V-grid coordinate
163-
RowActiveAreaVersion3 activeArea;
164-
};
165-
166-
FlatObject::setActualBufferAddress(actualFlatBufferPtr);
167-
168-
size_t rowsOffset = 0;
169-
size_t rowsSize = 0;
170-
if (mClassVersion == 3) {
171-
rowsSize = sizeof(RowInfoVersion3) * mGeo.getNumberOfRows();
144+
if (mClassVersion != 4) {
145+
LOG(error) << "TPCFastSpaceChargeCorrection::setActualBufferAddress() called with class version " << mClassVersion << ". This is not supported.";
146+
return;
172147
}
173148

174-
size_t sectorRowsOffset = rowsOffset + rowsSize;
175-
size_t sectorRowsSize = 0;
176-
if (mClassVersion == 3) { // copy old-format sectorrow data from the buffer to the arrays
177-
sectorRowsSize = sizeof(SectorRowInfoVersion3) * mGeo.getNumberOfRows() * mGeo.getNumberOfSectors();
178-
}
149+
FlatObject::setActualBufferAddress(actualFlatBufferPtr);
179150

180-
size_t scOffset = alignSize(sectorRowsOffset + sectorRowsSize, SplineType::getClassAlignmentBytes());
181151
size_t scSize = sizeof(SplineType) * mNumberOfScenarios;
182152

183-
mScenarioPtr = reinterpret_cast<SplineType*>(mFlatBufferPtr + scOffset);
153+
mScenarioPtr = reinterpret_cast<SplineType*>(mFlatBufferPtr);
184154

185-
size_t scBufferOffset = alignSize(scOffset + scSize, SplineType::getBufferAlignmentBytes());
155+
size_t scBufferOffset = alignSize(scSize, SplineType::getBufferAlignmentBytes());
186156
size_t scBufferSize = 0;
187157

188158
for (int32_t i = 0; i < mNumberOfScenarios; i++) {
@@ -196,45 +166,6 @@ void TPCFastSpaceChargeCorrection::setActualBufferAddress(char* actualFlatBuffer
196166
mSplineData[is] = reinterpret_cast<char*>(mFlatBufferPtr + sectorDataOffset);
197167
bufferSize = sectorDataOffset + mSectorDataSizeBytes[is] * mGeo.getNumberOfSectors();
198168
}
199-
200-
if (mClassVersion == 3) { // copy old-format sectorrow data from the buffer to the arrays
201-
202-
auto* rowInfosOld = reinterpret_cast<RowInfoVersion3*>(mFlatBufferPtr + rowsOffset);
203-
for (int32_t i = 0; i < mGeo.getNumberOfRows(); i++) {
204-
RowInfoVersion3& infoOld = rowInfosOld[i];
205-
RowInfo& info = mRowInfos[i];
206-
info.splineScenarioID = infoOld.splineScenarioID;
207-
for (int32_t is = 0; is < 3; is++) {
208-
info.dataOffsetBytes[is] = infoOld.dataOffsetBytes[is];
209-
}
210-
}
211-
212-
for (int32_t is = 0; is < mNumberOfScenarios; is++) {
213-
auto& spline = mScenarioPtr[is];
214-
spline.setXrange(0., spline.getGridX1().getUmax(), 0., spline.getGridX2().getUmax());
215-
}
216-
217-
auto* sectorRowInfosOld = reinterpret_cast<SectorRowInfoVersion3*>(mFlatBufferPtr + sectorRowsOffset);
218-
219-
for (int32_t sector = 0; sector < mGeo.getNumberOfSectors(); sector++) {
220-
for (int32_t row = 0; row < mGeo.getNumberOfRows(); row++) {
221-
SectorRowInfoVersion3& infoOld = sectorRowInfosOld[mGeo.getNumberOfRows() * sector + row];
222-
SectorRowInfo& info = getSectorRowInfo(sector, row);
223-
const auto& spline = getSpline(sector, row);
224-
info.gridU0 = mGeo.getRowInfo(row).u0;
225-
info.scaleUtoGrid = spline.getGridX1().getUmax() / mGeo.getRowInfo(row).getUwidth();
226-
227-
info.gridV0 = infoOld.gridV0;
228-
info.scaleVtoGrid = spline.getGridX2().getUmax() / (mGeo.getTPCzLength() + 3. - info.gridV0);
229-
230-
info.gridCorrU0 = infoOld.gridCorrU0;
231-
info.scaleCorrUtoGrid = infoOld.scaleCorrUtoGrid;
232-
233-
info.gridCorrV0 = infoOld.gridCorrV0;
234-
info.scaleCorrVtoGrid = infoOld.scaleCorrVtoGrid;
235-
}
236-
}
237-
}
238169
}
239170

240171
void TPCFastSpaceChargeCorrection::setFutureBufferAddress(char* futureFlatBufferPtr)
@@ -454,17 +385,12 @@ GPUd() void TPCFastSpaceChargeCorrection::setNoCorrection()
454385

455386
SectorRowInfo& info = getSectorRowInfo(sector, row);
456387

457-
info.gridU0 = mGeo.getRowInfo(row).u0;
458-
info.scaleUtoGrid = spline.getGridX1().getUmax() / mGeo.getRowInfo(row).getUwidth();
459-
460-
info.gridV0 = 0.f;
461-
info.scaleVtoGrid = spline.getGridX2().getUmax() / vLength;
462-
463-
info.gridCorrU0 = info.gridU0;
464-
info.gridCorrV0 = info.gridV0;
465-
info.scaleCorrUtoGrid = info.scaleUtoGrid;
466-
info.scaleCorrVtoGrid = info.scaleVtoGrid;
388+
info.gridMeasured.y0 = mGeo.getRowInfo(row).getYmin();
389+
info.gridMeasured.yScale = spline.getGridX1().getUmax() / mGeo.getRowInfo(row).getYwidth();
390+
info.gridMeasured.l0 = 0.f;
391+
info.gridMeasured.lScale = spline.getGridX2().getUmax() / vLength;
467392

393+
info.gridReal = info.gridMeasured;
468394
} // row
469395
} // sector
470396
}
@@ -539,9 +465,9 @@ double TPCFastSpaceChargeCorrection::testInverse(bool prn)
539465

540466
// grid borders
541467
if (sector < mGeo.getNumberOfSectorsA()) {
542-
z1 = vLength - getSectorRowInfo(sector, row).gridV0;
468+
z1 = vLength - getSectorRowInfo(sector, row).gridMeasured.l0;
543469
} else {
544-
z0 = getSectorRowInfo(sector, row).gridV0 - vLength;
470+
z0 = getSectorRowInfo(sector, row).gridMeasured.l0 - vLength;
545471
}
546472

547473
double stepY = (y1 - y0) / 100.;

0 commit comments

Comments
 (0)