Skip to content

Commit 56b9a7b

Browse files
sgorbunodavidrohr
authored andcommitted
TPC Splines: init inverse from the inverse voxel map; rebase
1 parent 7238e33 commit 56b9a7b

18 files changed

+1162
-1640
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,14 @@ class TPCFastSpaceChargeCorrectionHelper
8686

8787
/// Create SpaceCharge correction out of the voxel tree
8888
std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> createFromTrackResiduals(
89-
const o2::tpc::TrackResiduals& trackResiduals, TTree* voxResTree, bool useSmoothed = false, bool invertSigns = false);
89+
const o2::tpc::TrackResiduals& trackResiduals, TTree* voxResTree, TTree* voxResTreeInverse, bool useSmoothed, bool invertSigns);
90+
9091
/// _______________ Utilities ________________________
9192

9293
const TPCFastTransformGeo& getGeometry() { return mGeo; }
9394

9495
TPCFastSpaceChargeCorrectionMap& getCorrectionMap() { return mCorrectionMap; }
9596

96-
void fillSpaceChargeCorrectionFromMap(TPCFastSpaceChargeCorrection& correction);
97-
9897
void testGeometry(const TPCFastTransformGeo& geo) const;
9998

10099
/// initialise inverse transformation
@@ -103,15 +102,13 @@ class TPCFastSpaceChargeCorrectionHelper
103102
/// initialise inverse transformation from linear combination of several input corrections
104103
void initInverse(std::vector<o2::gpu::TPCFastSpaceChargeCorrection*>& corrections, const std::vector<float>& scaling, bool prn);
105104

105+
void MergeCorrections(std::vector<o2::gpu::TPCFastSpaceChargeCorrection*>& corrections, const std::vector<float>& scaling, bool prn);
106+
106107
private:
107108
/// geometry initialization
108109
void initGeometry();
109110

110-
/// get space charge correction in internal TPCFastTransform coordinates u,v->dx,du,dv
111-
void getSpaceChargeCorrection(const TPCFastSpaceChargeCorrection& correction, int slice, int row, o2::gpu::TPCFastSpaceChargeCorrectionMap::CorrectionPoint p, double& su, double& sv, double& dx, double& du, double& dv);
112-
113-
/// initialise max drift length
114-
void initMaxDriftLength(o2::gpu::TPCFastSpaceChargeCorrection& correction, bool prn);
111+
void fillSpaceChargeCorrectionFromMap(TPCFastSpaceChargeCorrection& correction, bool processingInverseCorrection);
115112

116113
static TPCFastSpaceChargeCorrectionHelper* sInstance; ///< singleton instance
117114
bool mIsInitialized = 0; ///< initialization flag

Detectors/TPC/calibration/src/TPCFastSpaceChargeCorrectionHelper.cxx

Lines changed: 461 additions & 460 deletions
Large diffs are not rendered by default.

Detectors/TPC/reconstruction/src/TPCFastTransformHelperO2.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ void TPCFastTransformHelperO2::testGeometry(const TPCFastTransformGeo& geo) cons
177177
{
178178
const Mapper& mapper = Mapper::instance();
179179

180-
if (geo.getNumberOfRocs() != Sector::MAXSECTOR) {
181-
LOG(fatal) << "Wrong number of sectors :" << geo.getNumberOfRocs() << " instead of " << Sector::MAXSECTOR << std::endl;
180+
if (geo.getNumberOfSectors() != Sector::MAXSECTOR) {
181+
LOG(fatal) << "Wrong number of sectors :" << geo.getNumberOfSectors() << " instead of " << Sector::MAXSECTOR << std::endl;
182182
}
183183

184184
if (geo.getNumberOfRows() != mapper.getNumberOfRows()) {

Detectors/TPC/reconstruction/test/testTPCFastTransform.cxx

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE(FastTransform_test1)
5353

5454
BOOST_CHECK_EQUAL(geo.test(), 0);
5555

56-
BOOST_CHECK_EQUAL(geo.getNumberOfRocs(), Sector::MAXSECTOR);
56+
BOOST_CHECK_EQUAL(geo.getNumberOfSectors(), Sector::MAXSECTOR);
5757
BOOST_CHECK_EQUAL(geo.getNumberOfRows(), mapper.getNumberOfRows());
5858

5959
double maxDx = 0, maxDy = 0;
@@ -71,15 +71,16 @@ BOOST_AUTO_TEST_CASE(FastTransform_test1)
7171
for (int pad = 0; pad < nPads; pad++) {
7272
const GlobalPadNumber p = mapper.globalPadNumber(PadPos(row, pad));
7373
const PadCentre& c = mapper.padCentre(p);
74-
float u = 0, v = 0;
75-
fastTransform.convPadTimeToUV(row, pad, 0, u, v, 0.);
76-
74+
float y = 0, z = 0;
75+
int sector = 0;
76+
float time = 0.;
77+
fastTransform.convPadTimeToLocal(sector, row, pad, time, y, z, 0.);
7778
double dx = x - c.X();
78-
double dy = u - (-c.Y()); // diferent sign convention for Y coordinate in the map
79+
double dy = y - (-c.Y()); // diferent sign convention for Y coordinate in the map
7980
BOOST_CHECK(fabs(dx) < 1.e-6);
8081
BOOST_CHECK(fabs(dy) < 1.e-5);
8182
if (fabs(dy) >= 1.e-5) {
82-
std::cout << "row " << row << " pad " << pad << " y calc " << u << " y in map " << -c.Y() << " dy " << dy << std::endl;
83+
std::cout << "row " << row << " pad " << pad << " y calc " << y << " y in map " << -c.Y() << " dy " << dy << std::endl;
8384
}
8485
if (fabs(maxDx) < fabs(dx)) {
8586
maxDx = dx;
@@ -104,46 +105,46 @@ BOOST_AUTO_TEST_CASE(FastTransform_test_setSpaceChargeCorrection)
104105
std::unique_ptr<TPCFastTransform> fastTransform0(TPCFastTransformHelperO2::instance()->create(0));
105106
const TPCFastTransformGeo& geo = fastTransform0->getGeometry();
106107

107-
auto correctionUV = [&](int roc, int /*row*/, const double u, const double v, double& dX, double& dU, double& dV) {
108+
auto correctionUV = [&](int sector, int /*row*/, const double u, const double v, double& dX, double& dU, double& dV) {
108109
// float lx = geo.getRowInfo(row).x;
109110
dX = 1. + 1 * u + 0.1 * u * u;
110111
dU = 2. + 0.2 * u + 0.002 * u * u; // + 0.001 * u * u * u;
111112
dV = 3. + 0.1 * v + 0.01 * v * v; //+ 0.0001 * v * v * v;
112113
};
113114

114-
auto correctionLocal = [&](int roc, int row, double ly, double lz,
115+
auto correctionLocal = [&](int sector, int row, double ly, double lz,
115116
double& dx, double& dly, double& dlz) {
116117
float u, v;
117-
geo.convLocalToUV(roc, ly, lz, u, v);
118+
geo.convLocalToUV(sector, ly, lz, u, v);
118119
double du, dv;
119-
correctionUV(roc, row, u, v, dx, du, dv);
120+
correctionUV(sector, row, u, v, dx, du, dv);
120121
float ly1, lz1;
121-
geo.convUVtoLocal(roc, u + du, v + dv, ly1, lz1);
122+
geo.convUVtoLocal(sector, u + du, v + dv, ly1, lz1);
122123
dly = ly1 - ly;
123124
dlz = lz1 - lz;
124125
};
125126

126-
int nRocs = geo.getNumberOfRocs();
127+
int nSectors = geo.getNumberOfSectors();
127128
int nRows = geo.getNumberOfRows();
128129
TPCFastSpaceChargeCorrectionMap& scData = TPCFastTransformHelperO2::instance()->getCorrectionMap();
129-
scData.init(nRocs, nRows);
130+
scData.init(nSectors, nRows);
130131

131-
for (int iRoc = 0; iRoc < nRocs; iRoc++) {
132+
for (int iSector = 0; iSector < nSectors; iSector++) {
132133
for (int iRow = 0; iRow < nRows; iRow++) {
133134
double dsu = 1. / (3 * 8 - 3);
134135
double dsv = 1. / (3 * 20 - 3);
135136
for (double su = 0.f; su < 1.f + .5 * dsu; su += dsv) {
136137
for (double sv = 0.f; sv < 1.f + .5 * dsv; sv += dsv) {
137138
float ly = 0.f, lz = 0.f;
138-
geo.convScaledUVtoLocal(iRoc, iRow, su, sv, ly, lz);
139+
geo.convScaledUVtoLocal(iSector, iRow, su, sv, ly, lz);
139140
double dx, dy, dz;
140-
correctionLocal(iRoc, iRow, ly, lz, dx, dy, dz);
141-
scData.addCorrectionPoint(iRoc, iRow,
141+
correctionLocal(iSector, iRow, ly, lz, dx, dy, dz);
142+
scData.addCorrectionPoint(iSector, iRow,
142143
ly, lz, dx, dy, dz);
143144
}
144145
}
145146
} // row
146-
} // roc
147+
} // sector
147148

148149
std::unique_ptr<TPCFastTransform> fastTransform(TPCFastTransformHelperO2::instance()->create(0));
149150

@@ -158,12 +159,12 @@ BOOST_AUTO_TEST_CASE(FastTransform_test_setSpaceChargeCorrection)
158159
double statDiff = 0., statN = 0.;
159160
double statDiffFile = 0., statNFile = 0.;
160161

161-
for (int roc = 0; roc < geo.getNumberOfRocs(); roc += 1) {
162-
// std::cout << "roc " << roc << " ... " << std::endl;
162+
for (int sector = 0; sector < geo.getNumberOfSectors(); sector += 1) {
163+
// std::cout << "sector " << sector << " ... " << std::endl;
163164

164-
const TPCFastTransformGeo::RocInfo& rocInfo = geo.getRocInfo(roc);
165+
const TPCFastTransformGeo::SectorInfo& sectorInfo = geo.getSectorInfo(sector);
165166

166-
float lastTimeBin = fastTransform->getMaxDriftTime(roc, 0.f);
167+
float lastTimeBin = fastTransform->getMaxDriftTime(sector, 0.f);
167168

168169
for (int row = 0; row < geo.getNumberOfRows(); row++) {
169170

@@ -172,31 +173,31 @@ BOOST_AUTO_TEST_CASE(FastTransform_test_setSpaceChargeCorrection)
172173
for (int pad = 0; pad < nPads; pad += 10) {
173174

174175
for (float time = 0; time < lastTimeBin; time += 30) {
175-
// std::cout<<"roc "<<roc<<" row "<<row<<" pad "<<pad<<" time "<<time<<std::endl;
176+
// std::cout<<"sector "<<sector<<" row "<<row<<" pad "<<pad<<" time "<<time<<std::endl;
176177

177178
fastTransform->setApplyCorrectionOff();
178179
float x0, y0, z0;
179-
fastTransform->Transform(roc, row, pad, time, x0, y0, z0);
180+
fastTransform->Transform(sector, row, pad, time, x0, y0, z0);
180181

181-
BOOST_CHECK_EQUAL(geo.test(roc, row, y0, z0), 0);
182+
BOOST_CHECK_EQUAL(geo.test(sector, row, y0, z0), 0);
182183

183184
fastTransform->setApplyCorrectionOn();
184185
float x1, y1, z1;
185-
fastTransform->Transform(roc, row, pad, time, x1, y1, z1);
186+
fastTransform->Transform(sector, row, pad, time, x1, y1, z1);
186187

187188
// local to UV
188189
float u0, v0, u1, v1;
189-
geo.convLocalToUV(roc, y0, z0, u0, v0);
190-
geo.convLocalToUV(roc, y1, z1, u1, v1);
190+
geo.convLocalToUV(sector, y0, z0, u0, v0);
191+
geo.convLocalToUV(sector, y1, z1, u1, v1);
191192
double dx, du, dv;
192-
correctionUV(roc, row, u0, v0, dx, du, dv);
193+
correctionUV(sector, row, u0, v0, dx, du, dv);
193194
statDiff += fabs((x1 - x0) - dx) + fabs((u1 - u0) - du) + fabs((v1 - v0) - dv);
194195
statN += 3;
195196
// std::cout << (x1 - x0) - dx << " " << (u1 - u0) - du << " " << (v1 - v0) - dv << std::endl; //": v0 " << v0 <<" z0 "<<z0<<" v1 "<< v1<<" z1 "<<z1 << std::endl;
196197
// BOOST_CHECK_MESSAGE(0, "SG");
197198

198199
float x1f, y1f, z1f;
199-
fromFile->Transform(roc, row, pad, time, x1f, y1f, z1f);
200+
fromFile->Transform(sector, row, pad, time, x1f, y1f, z1f);
200201
statDiffFile += fabs(x1f - x1) + fabs(y1f - y1) + fabs(z1f - z1);
201202
statNFile += 3;
202203
}

GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ GPUd() int32_t GPUTPCGMMerger::RefitSectorTrack(GPUTPCGMSectorTrack& sectorTrack
564564
trk.SinPhi() = inTrack->Param().GetSinPhi();
565565
trk.DzDs() = inTrack->Param().GetDzDs();
566566
trk.QPt() = inTrack->Param().GetQPt();
567-
trk.TOffset() = Param().par.continuousTracking ? GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convZOffsetToVertexTime(sector, inTrack->Param().GetZOffset(), Param().continuousMaxTimeBin) : 0;
567+
trk.TOffset() = Param().par.continuousTracking ? GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convZOffsetToVertexTime(inTrack->Param().GetZOffset(), Param().continuousMaxTimeBin) : 0;
568568
const auto tmp = sectorTrack.ClusterTN() > sectorTrack.ClusterT0() ? std::array<float, 2>{sectorTrack.ClusterTN(), sectorTrack.ClusterT0()} : std::array<float, 2>{sectorTrack.ClusterT0(), sectorTrack.ClusterTN()};
569569
trk.ShiftZ(this, sector, tmp[0], tmp[1], inTrack->Param().GetX()); // We do not store the inner / outer cluster X, so we just use the track X instead
570570
sectorTrack.SetX2(0.f);
@@ -1951,7 +1951,7 @@ GPUd() void GPUTPCGMMerger::MergeLoopersInit(int32_t nBlocks, int32_t nThreads,
19511951
const float qptabs = CAMath::Abs(p.GetQPt());
19521952
if (trk.OK() && trk.NClusters() && trk.Leg() == 0 && qptabs * Param().qptB5Scaler > 5.f && qptabs * Param().qptB5Scaler <= lowPtThresh) {
19531953
const int32_t sector = mClusters[trk.FirstClusterRef() + trk.NClusters() - 1].sector;
1954-
const float refz = p.GetZ() + (Param().par.continuousTracking ? GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(sector, p.GetTOffset(), Param().continuousMaxTimeBin) : 0) + (trk.CSide() ? -100 : 100);
1954+
const float refz = p.GetZ() + (Param().par.continuousTracking ? GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(p.GetTOffset(), Param().continuousMaxTimeBin) : 0) + (trk.CSide() ? -100 : 100);
19551955
float sinA, cosA;
19561956
CAMath::SinCos(trk.GetAlpha(), sinA, cosA);
19571957
float gx = cosA * p.GetX() - sinA * p.GetY();

GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ GPUd() float GPUTPCGMTrackParam::AttachClusters(const GPUTPCGMMerger* GPUrestric
502502
return -1e6f;
503503
}
504504

505-
const float zOffset = param.par.continuousTracking ? Merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(sector, mTOffset, param.continuousMaxTimeBin) : 0; // TODO: do some validatiomns for the transform conv functions...
505+
const float zOffset = param.par.continuousTracking ? Merger->GetConstantMem()->calibObjects.fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(mTOffset, param.continuousMaxTimeBin) : 0; // TODO: do some validatiomns for the transform conv functions...
506506
const float y0 = row.Grid().YMin();
507507
const float stepY = row.HstepY();
508508
const float z0 = row.Grid().ZMin() - zOffset; // We can use our own ZOffset, since this is only used temporarily anyway

GPU/GPUTracking/display/render/GPUDisplayDraw.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ 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.slice, cl.row, cln.getPad(), cln.getTime(), x, y, z);
558+
GPUTPCConvertImpl::convert(*mCalib->fastTransform, *mParam, cl.sector, cl.row, cln.getPad(), cln.getTime(), x, y, z);
559559
ZOffset = mCalib->fastTransformHelper->getCorrMap()->convVertexTimeToZOffset(track->GetParam().GetTOffset(), mParam->continuousMaxTimeBin);
560560
} else {
561561
uint8_t sector, row;

GPU/TPCFastTransformation/Spline1DSpec.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,41 @@ class Spline1DSpec<DataT, YdimT, 0> : public Spline1DContainer<DataT>
369369
dDr = v * a;
370370
// F(u) = dSl * Sl + dSr * Sr + dDl * Dl + dDr * Dr;
371371
}
372-
372+
/*
373+
template <typename T>
374+
GPUd() void getUsecondDerivatives(const Knot& knotL, DataT u,
375+
T& dSl, T& dDl, T& dSr, T& dDr,
376+
T& dSl2, T& dDl2, T& dSr2, T& dDr2) const
377+
{
378+
/// Get derivatives of the interpolated value {S(u): 1D -> nYdim} at the segment [knotL, next knotR]
379+
/// over the spline values Sl, Sr and the slopes Dl, Dr
380+
381+
if (u < (DataT)0) {
382+
u = (DataT)0;
383+
}
384+
if (u > (DataT)TBase::getUmax()) {
385+
u = (DataT)TBase::getUmax();
386+
}
387+
388+
u = u - knotL.u;
389+
T v = u * T(knotL.Li); // scaled u
390+
T vm1 = v - 1.;
391+
T a = u * vm1;
392+
T v2 = v * v;
393+
dSr = v2 * (3. - 2 * v);
394+
dSl = 1. - dSr;
395+
dDl = vm1 * a;
396+
dDr = v * a;
397+
T dv = T(knotL.Li);
398+
dSr2 = 6. * v * (1. - v) * dv;
399+
dSl2 = -dSr2;
400+
dDl2 = (v - 1) * (3 * v - 1);
401+
dDr = u * (v * v - v);
402+
dDr2 = 3.f * v * v - 2.f * v;
403+
// F(u) = dSl * Sl + dSr * Sr + dDl * Dl + dDr * Dr;
404+
// dF(u)/du = dSl2 * Sl + dSr2 * Sr + dDl2 * Dl + dDr2 * Dr;
405+
}
406+
*/
373407
using TBase::convXtoU;
374408
using TBase::getKnot;
375409
using TBase::getKnots;

0 commit comments

Comments
 (0)