Skip to content

Commit 22c28cd

Browse files
sgorbunodavidrohr
authored andcommitted
TPC Splines: completely switch to local TPC coordinates in the grid
1 parent 7a7a09e commit 22c28cd

File tree

9 files changed

+328
-272
lines changed

9 files changed

+328
-272
lines changed

Detectors/TPC/calibration/include/TPCCalibration/TPCFastSpaceChargeCorrectionHelper.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,16 @@ class TPCFastSpaceChargeCorrectionHelper
8585
const int nKnotsY = 10, const int nKnotsZ = 20);
8686

8787
/// Create SpaceCharge correction out of the voxel tree
88+
/// \param trackResiduals TrackResiduals object
89+
/// \param voxResTree TTree with voxel residuals
90+
/// \param voxResTreeInverse TTree with inverse voxel residuals
91+
/// \param useSmoothed if true, use smoothed residuals
92+
/// \param invertSigns if true, invert the signs of the residuals
93+
/// \return pointer to the created TPCFastSpaceChargeCorrection object
94+
/// \note voxel trees wont be changed. They are read as non-const because of the ROOT::TTreeProcessorMT interface
8895
std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> createFromTrackResiduals(
89-
const o2::tpc::TrackResiduals& trackResiduals, TTree* voxResTree, TTree* voxResTreeInverse, bool useSmoothed, bool invertSigns);
96+
const o2::tpc::TrackResiduals& trackResiduals, TTree* voxResTree, TTree* voxResTreeInverse, //
97+
bool useSmoothed, bool invertSigns);
9098

9199
/// _______________ Utilities ________________________
92100

Detectors/TPC/calibration/src/TPCFastSpaceChargeCorrectionHelper.cxx

Lines changed: 134 additions & 136 deletions
Large diffs are not rendered by default.

GPU/TPCFastTransformation/TPCFastSpaceChargeCorrection.cxx

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ TPCFastSpaceChargeCorrection::TPCFastSpaceChargeCorrection()
3535
mScenarioPtr(nullptr),
3636
mTimeStamp(-1),
3737
mSplineData{nullptr, nullptr, nullptr},
38-
mSectorDataSizeBytes{0, 0, 0}
38+
mDataSizeBytes{0, 0, 0}
3939
{
4040
// Default Constructor: creates an empty uninitialized object
4141
}
@@ -64,7 +64,7 @@ void TPCFastSpaceChargeCorrection::destroy()
6464
mTimeStamp = -1;
6565
for (int32_t is = 0; is < 3; is++) {
6666
mSplineData[is] = nullptr;
67-
mSectorDataSizeBytes[is] = 0;
67+
mDataSizeBytes[is] = 0;
6868
}
6969
FlatObject::destroy();
7070
}
@@ -105,9 +105,9 @@ void TPCFastSpaceChargeCorrection::cloneFromObject(const TPCFastSpaceChargeCorre
105105
mSectorInfo[i] = obj.mSectorInfo[i];
106106
}
107107

108-
mSectorDataSizeBytes[0] = obj.mSectorDataSizeBytes[0];
109-
mSectorDataSizeBytes[1] = obj.mSectorDataSizeBytes[1];
110-
mSectorDataSizeBytes[2] = obj.mSectorDataSizeBytes[2];
108+
mDataSizeBytes[0] = obj.mDataSizeBytes[0];
109+
mDataSizeBytes[1] = obj.mDataSizeBytes[1];
110+
mDataSizeBytes[2] = obj.mDataSizeBytes[2];
111111

112112
// variable-size data
113113
mScenarioPtr = obj.mScenarioPtr;
@@ -162,9 +162,9 @@ void TPCFastSpaceChargeCorrection::setActualBufferAddress(char* actualFlatBuffer
162162
}
163163
size_t bufferSize = scBufferOffset + scBufferSize;
164164
for (int32_t is = 0; is < 3; is++) {
165-
size_t sectorDataOffset = alignSize(bufferSize, SplineType::getParameterAlignmentBytes());
166-
mSplineData[is] = reinterpret_cast<char*>(mFlatBufferPtr + sectorDataOffset);
167-
bufferSize = sectorDataOffset + mSectorDataSizeBytes[is] * mGeo.getNumberOfSectors();
165+
size_t splineDataOffset = alignSize(bufferSize, SplineType::getParameterAlignmentBytes());
166+
mSplineData[is] = reinterpret_cast<char*>(mFlatBufferPtr + splineDataOffset);
167+
bufferSize = splineDataOffset + mDataSizeBytes[is];
168168
}
169169
}
170170

@@ -199,14 +199,8 @@ void TPCFastSpaceChargeCorrection::print() const
199199
mGeo.print();
200200
LOG(info) << " mNumberOfScenarios = " << mNumberOfScenarios;
201201
LOG(info) << " mTimeStamp = " << mTimeStamp;
202-
LOG(info) << " mSectorDataSizeBytes = " << mSectorDataSizeBytes[0] << " " << mSectorDataSizeBytes[1] << " " << mSectorDataSizeBytes[2];
203-
{
204-
LOG(info) << " TPC rows: ";
205-
for (int32_t i = 0; i < mGeo.getNumberOfRows(); i++) {
206-
const RowInfo& r = mRowInfos[i];
207-
LOG(info) << " tpc row " << i << ": splineScenarioID = " << r.splineScenarioID << " dataOffsetBytes = " << r.dataOffsetBytes;
208-
}
209-
}
202+
LOG(info) << " mDataSizeBytes = " << mDataSizeBytes[0] << " " << mDataSizeBytes[1] << " " << mDataSizeBytes[2];
203+
210204
if (mScenarioPtr) {
211205
for (int32_t i = 0; i < mNumberOfScenarios; i++) {
212206
LOG(info) << " SplineScenario " << i << ": ";
@@ -255,8 +249,23 @@ void TPCFastSpaceChargeCorrection::startConstruction(const TPCFastTransformGeo&
255249

256250
assert(mConstructionScenarios != nullptr);
257251

258-
for (int32_t i = 0; i < mGeo.getNumberOfRows(); i++) {
259-
mRowInfos[i].splineScenarioID = -1;
252+
for (int32_t i = 0; i < mGeo.getNumberOfSectors(); i++) {
253+
mSectorInfo[i].vMax1 = 0.;
254+
for (int32_t j = 0; j < mGeo.getNumberOfRows(); j++) {
255+
auto& row = mSectorRowInfos[mGeo.getMaxNumberOfRows() * i + j];
256+
row.splineScenarioID = -1;
257+
row.gridReal = {};
258+
row.gridMeasured = {};
259+
row.dataOffsetBytes[0] = 0;
260+
row.dataOffsetBytes[1] = 0;
261+
row.dataOffsetBytes[2] = 0;
262+
row.minCorr[0] = 0;
263+
row.minCorr[1] = 0;
264+
row.minCorr[2] = 0;
265+
row.maxCorr[0] = 0;
266+
row.maxCorr[1] = 0;
267+
row.maxCorr[2] = 0;
268+
}
260269
}
261270

262271
for (int32_t i = 0; i < mNumberOfScenarios; i++) {
@@ -268,18 +277,18 @@ void TPCFastSpaceChargeCorrection::startConstruction(const TPCFastTransformGeo&
268277
mScenarioPtr = nullptr;
269278
for (int32_t s = 0; s < 3; s++) {
270279
mSplineData[s] = nullptr;
271-
mSectorDataSizeBytes[s] = 0;
280+
mDataSizeBytes[s] = 0;
272281
}
273282
mClassVersion = 4;
274283
}
275284

276-
void TPCFastSpaceChargeCorrection::setRowScenarioID(int32_t iRow, int32_t iScenario)
285+
void TPCFastSpaceChargeCorrection::setRowScenarioID(int32_t iSector, int32_t iRow, int32_t iScenario)
277286
{
278287
/// Initializes a TPC row
279288
assert(mConstructionMask & ConstructionState::InProgress);
289+
assert(iSector >= 0 && iSector < mGeo.getNumberOfSectors());
280290
assert(iRow >= 0 && iRow < mGeo.getNumberOfRows() && iScenario >= 0 && iScenario < mNumberOfScenarios);
281-
282-
RowInfo& row = mRowInfos[iRow];
291+
auto& row = getSectorRowInfo(iSector, iRow);
283292
row.splineScenarioID = iScenario;
284293
for (int32_t s = 0; s < 3; s++) {
285294
row.dataOffsetBytes[s] = 0;
@@ -302,9 +311,14 @@ void TPCFastSpaceChargeCorrection::finishConstruction()
302311

303312
assert(mConstructionMask & ConstructionState::InProgress);
304313

305-
for (int32_t i = 0; i < mGeo.getNumberOfRows(); i++) {
306-
assert(mRowInfos[i].splineScenarioID >= 0);
314+
for (int32_t i = 0; i < mGeo.getNumberOfSectors(); i++) {
315+
for (int32_t j = 0; j < mGeo.getNumberOfRows(); j++) {
316+
SectorRowInfo& row = getSectorRowInfo(i, j);
317+
assert(row.splineScenarioID >= 0);
318+
assert(row.splineScenarioID < mNumberOfScenarios);
319+
}
307320
}
321+
308322
for (int32_t i = 0; i < mNumberOfScenarios; i++) {
309323
assert(mConstructionScenarios[i].isConstructed());
310324
}
@@ -324,18 +338,20 @@ void TPCFastSpaceChargeCorrection::finishConstruction()
324338
scBufferSize = alignSize(scBufferSize + sp.getFlatBufferSize(), sp.getBufferAlignmentBytes());
325339
}
326340
size_t bufferSize = scBufferOffsets[0] + scBufferSize;
327-
size_t sectorDataOffset[3];
341+
size_t splineDataOffset[3];
328342
for (int32_t is = 0; is < 3; is++) {
329-
sectorDataOffset[is] = alignSize(bufferSize, SplineType::getParameterAlignmentBytes());
330-
mSectorDataSizeBytes[is] = 0;
331-
for (int32_t i = 0; i < mGeo.getNumberOfRows(); i++) {
332-
RowInfo& row = mRowInfos[i];
333-
SplineType& spline = mConstructionScenarios[row.splineScenarioID];
334-
row.dataOffsetBytes[is] = alignSize(mSectorDataSizeBytes[is], SplineType::getParameterAlignmentBytes());
335-
mSectorDataSizeBytes[is] = row.dataOffsetBytes[is] + spline.getSizeOfParameters();
343+
splineDataOffset[is] = alignSize(bufferSize, SplineType::getParameterAlignmentBytes());
344+
mDataSizeBytes[is] = 0;
345+
for (int32_t i = 0; i < mGeo.getNumberOfSectors(); i++) {
346+
for (int32_t j = 0; j < mGeo.getNumberOfRows(); j++) {
347+
SectorRowInfo& row = getSectorRowInfo(i, j);
348+
SplineType& spline = mConstructionScenarios[row.splineScenarioID];
349+
row.dataOffsetBytes[is] = alignSize(mDataSizeBytes[is], SplineType::getParameterAlignmentBytes());
350+
mDataSizeBytes[is] = row.dataOffsetBytes[is] + spline.getSizeOfParameters();
351+
}
336352
}
337-
mSectorDataSizeBytes[is] = alignSize(mSectorDataSizeBytes[is], SplineType::getParameterAlignmentBytes());
338-
bufferSize = sectorDataOffset[is] + mSectorDataSizeBytes[is] * mGeo.getNumberOfSectors();
353+
mDataSizeBytes[is] = alignSize(mDataSizeBytes[is], SplineType::getParameterAlignmentBytes());
354+
bufferSize = splineDataOffset[is] + mDataSizeBytes[is];
339355
}
340356

341357
FlatObject::finishConstruction(bufferSize);
@@ -350,7 +366,7 @@ void TPCFastSpaceChargeCorrection::finishConstruction()
350366
}
351367

352368
for (int32_t is = 0; is < 3; is++) {
353-
mSplineData[is] = reinterpret_cast<char*>(mFlatBufferPtr + sectorDataOffset[is]);
369+
mSplineData[is] = reinterpret_cast<char*>(mFlatBufferPtr + splineDataOffset[is]);
354370
}
355371
releaseConstructionMemory();
356372

@@ -363,9 +379,9 @@ GPUd() void TPCFastSpaceChargeCorrection::setNoCorrection()
363379
{
364380
// initialise all corrections to 0.
365381
for (int32_t sector = 0; sector < mGeo.getNumberOfSectors(); sector++) {
366-
double vLength = mGeo.getTPCzLength();
367-
SectorInfo& sectorInfo = getSectorInfo(sector);
368-
sectorInfo.vMax = vLength;
382+
383+
getSectorInfo(sector).vMax1 = mGeo.getTPCzLength();
384+
369385
for (int32_t row = 0; row < mGeo.getNumberOfRows(); row++) {
370386
const SplineType& spline = getSpline(sector, row);
371387

@@ -385,10 +401,12 @@ GPUd() void TPCFastSpaceChargeCorrection::setNoCorrection()
385401

386402
SectorRowInfo& info = getSectorRowInfo(sector, row);
387403

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;
404+
float y0 = mGeo.getRowInfo(row).getYmin();
405+
float yScale = spline.getGridX1().getUmax() / mGeo.getRowInfo(row).getYwidth();
406+
float z0 = mGeo.getZmin(sector);
407+
float zScale = spline.getGridX2().getUmax() / mGeo.getTPCzLength();
408+
float zReadout = mGeo.getZreadout(sector);
409+
info.gridMeasured.set(y0, yScale, z0, zScale, zReadout, zReadout);
392410

393411
info.gridReal = info.gridMeasured;
394412
} // row
@@ -399,8 +417,10 @@ void TPCFastSpaceChargeCorrection::constructWithNoCorrection(const TPCFastTransf
399417
{
400418
const int32_t nCorrectionScenarios = 1;
401419
startConstruction(geo, nCorrectionScenarios);
402-
for (int32_t row = 0; row < geo.getNumberOfRows(); row++) {
403-
setRowScenarioID(row, 0);
420+
for (int32_t sector = 0; sector < geo.getNumberOfSectors(); sector++) {
421+
for (int32_t row = 0; row < geo.getNumberOfRows(); row++) {
422+
setRowScenarioID(sector, row, 0);
423+
}
404424
}
405425
{
406426
TPCFastSpaceChargeCorrection::SplineType spline;
@@ -456,20 +476,13 @@ double TPCFastSpaceChargeCorrection::testInverse(bool prn)
456476
if (prn) {
457477
LOG(info) << "check inverse transform for sector " << sector;
458478
}
459-
double vLength = mGeo.getTPCzLength();
479+
460480
MaxValue maxDsector[3];
461481
for (int32_t row = 0; row < mGeo.getNumberOfRows(); row++) {
462482
double x = mGeo.getRowInfo(row).x;
463483
auto [y0, y1] = mGeo.getRowInfo(row).getYrange();
464484
auto [z0, z1] = mGeo.getZrange(sector);
465485

466-
// grid borders
467-
if (sector < mGeo.getNumberOfSectorsA()) {
468-
z1 = vLength - getSectorRowInfo(sector, row).gridMeasured.l0;
469-
} else {
470-
z0 = getSectorRowInfo(sector, row).gridMeasured.l0 - vLength;
471-
}
472-
473486
double stepY = (y1 - y0) / 100.;
474487
double stepZ = (z1 - z0) / 100.;
475488
MaxValue maxDrow[3];
@@ -479,7 +492,7 @@ double TPCFastSpaceChargeCorrection::testInverse(bool prn)
479492
double realX = x + dx;
480493
double realY = y + dy;
481494
double realZ = z + dz;
482-
if (!isLocalInsideGrid(sector, row, y, z) || !isLocalInsideGrid(sector, row, realY, realZ)) {
495+
if (!isLocalInsideGrid(sector, row, y, z) || !isRealLocalInsideGrid(sector, row, realY, realZ)) {
483496
continue;
484497
}
485498
double r2 = realX * realX + realY * realY;

0 commit comments

Comments
 (0)