Skip to content

Commit e329718

Browse files
sgorbunocbmsw
authored andcommitted
TPC Splines: add limits for SP correction values per TPC row
1 parent 2d6b2fc commit e329718

File tree

3 files changed

+96
-33
lines changed

3 files changed

+96
-33
lines changed

Detectors/TPC/calibration/src/TPCFastSpaceChargeCorrectionHelper.cxx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ void TPCFastSpaceChargeCorrectionHelper::fillSpaceChargeCorrectionFromMap(TPCFas
144144
float* splineParameters = correction.getSplineData(slice, row);
145145
const std::vector<o2::gpu::TPCFastSpaceChargeCorrectionMap::CorrectionPoint>& data = mCorrectionMap.getPoints(slice, row);
146146
int nDataPoints = data.size();
147+
auto& info = correction.getSliceRowInfo(slice, row);
148+
info.resetMaxValues();
149+
info.resetMaxValuesInv();
147150
if (nDataPoints >= 4) {
148151
std::vector<double> pointSU(nDataPoints);
149152
std::vector<double> pointSV(nDataPoints);
@@ -156,6 +159,8 @@ void TPCFastSpaceChargeCorrectionHelper::fillSpaceChargeCorrectionFromMap(TPCFas
156159
pointCorr[3 * i + 0] = dx;
157160
pointCorr[3 * i + 1] = du;
158161
pointCorr[3 * i + 2] = dv;
162+
info.updateMaxValues(2. * dx, 2. * du, 2. * dv);
163+
info.updateMaxValuesInv(-2. * dx, -2. * du, -2. * dv);
159164
}
160165
helper.approximateDataPoints(spline, splineParameters, 0., spline.getGridX1().getUmax(), 0., spline.getGridX2().getUmax(), &pointSU[0],
161166
&pointSV[0], &pointCorr[0], nDataPoints);
@@ -767,9 +772,20 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
767772

768773
double yStep = (yLast - yFirst) / 2;
769774

775+
double zFirst = z - dz / 2.;
776+
double zLast = z + dz / 2.;
777+
double zStep = (zLast - zFirst) / 2.;
778+
779+
if (0) { // no smoothing
780+
yFirst = y;
781+
yLast = y;
782+
zFirst = z;
783+
zLast = z;
784+
}
785+
770786
for (double py = yFirst; py <= yLast + yStep / 2.; py += yStep) {
771787

772-
for (double pz = z - dz / 2.; pz <= z + dz / 2. + 1.e-4; pz += dz / 2.) {
788+
for (double pz = zFirst; pz <= zLast + zStep / 2.; pz += zStep) {
773789
map.addCorrectionPoint(iRoc, iRow, py, pz, correctionX, correctionY,
774790
correctionZ);
775791
}

GPU/TPCFastTransformation/TPCFastSpaceChargeCorrection.h

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,64 @@ class TPCFastSpaceChargeCorrection : public FlatObject
5858
};
5959

6060
struct SliceRowInfo {
61-
float gridU0{0.f}; //< U coordinate of the U-grid start
62-
float scaleUtoGrid{0.f}; //< scale U to U-grid coordinate
63-
float gridV0{0.f}; ///< V coordinate of the V-grid start
64-
float scaleVtoGrid{0.f}; //< scale V to V-grid coordinate
65-
float gridCorrU0{0.f}; ///< U coordinate of the U-grid start for corrected U
66-
float scaleCorrUtoGrid{0.f}; ///< scale corrected U to U-grid coordinate
67-
float gridCorrV0{0.f}; ///< V coordinate of the V-grid start for corrected V
68-
float scaleCorrVtoGrid{0.f}; ///< scale corrected V to V-grid coordinate
61+
float gridU0{0.f}; //< U coordinate of the U-grid start
62+
float scaleUtoGrid{0.f}; //< scale U to U-grid coordinate
63+
float gridV0{0.f}; ///< V coordinate of the V-grid start
64+
float scaleVtoGrid{0.f}; //< scale V to V-grid coordinate
65+
float gridCorrU0{0.f}; ///< U coordinate of the U-grid start for corrected U
66+
float scaleCorrUtoGrid{0.f}; ///< scale corrected U to U-grid coordinate
67+
float gridCorrV0{0.f}; ///< V coordinate of the V-grid start for corrected V
68+
float scaleCorrVtoGrid{0.f}; ///< scale corrected V to V-grid coordinate
69+
float maxCorr[3]{10.f, 10.f, 10.f}; ///< max correction for dX, dU, dV
70+
float minCorr[3]{-10.f, -10.f, -10.f}; ///< min correction for dX, dU, dV
71+
float maxInvCorr[3]{10.f, 10.f, 10.f}; ///< max inverse correction for dX, dU, dV
72+
float minInvCorr[3]{-10.f, -10.f, -10.f}; ///< min inverse correction for dX, dU, dV
6973
RowActiveArea activeArea;
74+
75+
void resetMaxValues()
76+
{
77+
maxCorr[0] = 1.f;
78+
minCorr[0] = -1.f;
79+
maxCorr[1] = 1.f;
80+
minCorr[1] = -1.f;
81+
maxCorr[2] = 1.f;
82+
minCorr[2] = -1.f;
83+
}
84+
85+
void updateMaxValues(float dx, float du, float dv)
86+
{
87+
maxCorr[0] = GPUCommonMath::Max(maxCorr[0], dx);
88+
minCorr[0] = GPUCommonMath::Min(minCorr[0], dx);
89+
90+
maxCorr[1] = GPUCommonMath::Max(maxCorr[1], du);
91+
minCorr[1] = GPUCommonMath::Min(minCorr[1], du);
92+
93+
maxCorr[2] = GPUCommonMath::Max(maxCorr[2], dv);
94+
minCorr[2] = GPUCommonMath::Min(minCorr[2], dv);
95+
}
96+
97+
void resetMaxValuesInv()
98+
{
99+
maxInvCorr[0] = 1.f;
100+
minInvCorr[0] = -1.f;
101+
maxInvCorr[1] = 1.f;
102+
minInvCorr[1] = -1.f;
103+
maxInvCorr[2] = 1.f;
104+
minInvCorr[2] = -1.f;
105+
}
106+
107+
void updateMaxValuesInv(float dx, float du, float dv)
108+
{
109+
maxInvCorr[0] = GPUCommonMath::Max(maxInvCorr[0], dx);
110+
minInvCorr[0] = GPUCommonMath::Min(minInvCorr[0], dx);
111+
112+
maxInvCorr[1] = GPUCommonMath::Max(maxInvCorr[1], du);
113+
minInvCorr[1] = GPUCommonMath::Min(minInvCorr[1], du);
114+
115+
maxInvCorr[2] = GPUCommonMath::Max(maxInvCorr[2], dv);
116+
minInvCorr[2] = GPUCommonMath::Min(minInvCorr[2], dv);
117+
}
118+
70119
ClassDefNV(SliceRowInfo, 2);
71120
};
72121

@@ -397,12 +446,10 @@ GPUdi() int32_t TPCFastSpaceChargeCorrection::getCorrection(int32_t slice, int32
397446
convUVtoGrid(slice, row, u, v, gridU, gridV);
398447
float dxuv[3];
399448
spline.interpolateU(splineData, gridU, gridV, dxuv);
400-
if (CAMath::Abs(dxuv[0]) > 100 || CAMath::Abs(dxuv[1]) > 100 || CAMath::Abs(dxuv[2]) > 100) {
401-
dxuv[0] = dxuv[1] = dxuv[2] = 0;
402-
}
403-
dx = dxuv[0];
404-
du = dxuv[1];
405-
dv = dxuv[2];
449+
const auto& info = getSliceRowInfo(slice, row);
450+
dx = GPUCommonMath::Max(info.minCorr[0], GPUCommonMath::Min(info.maxCorr[0], dxuv[0]));
451+
du = GPUCommonMath::Max(info.minCorr[1], GPUCommonMath::Min(info.maxCorr[1], dxuv[1]));
452+
dv = GPUCommonMath::Max(info.minCorr[2], GPUCommonMath::Min(info.maxCorr[2], dxuv[2]));
406453
return 0;
407454
}
408455

@@ -414,12 +461,10 @@ GPUdi() int32_t TPCFastSpaceChargeCorrection::getCorrectionOld(int32_t slice, in
414461
convUVtoGrid(slice, row, u, v, gridU, gridV);
415462
float dxuv[3];
416463
spline.interpolateUold(splineData, gridU, gridV, dxuv);
417-
if (CAMath::Abs(dxuv[0]) > 100 || CAMath::Abs(dxuv[1]) > 100 || CAMath::Abs(dxuv[2]) > 100) {
418-
dxuv[0] = dxuv[1] = dxuv[2] = 0;
419-
}
420-
dx = dxuv[0];
421-
du = dxuv[1];
422-
dv = dxuv[2];
464+
const auto& info = getSliceRowInfo(slice, row);
465+
dx = GPUCommonMath::Max(info.minCorr[0], GPUCommonMath::Min(info.maxCorr[0], dxuv[0]));
466+
du = GPUCommonMath::Max(info.minCorr[1], GPUCommonMath::Min(info.maxCorr[1], dxuv[1]));
467+
dv = GPUCommonMath::Max(info.minCorr[2], GPUCommonMath::Min(info.maxCorr[2], dxuv[2]));
423468
return 0;
424469
}
425470

@@ -433,9 +478,8 @@ GPUdi() void TPCFastSpaceChargeCorrection::getCorrectionInvCorrectedX(
433478
const float* splineData = getSplineData(slice, row, 1);
434479
float dx = 0;
435480
spline.interpolateU(splineData, gridU, gridV, &dx);
436-
if (CAMath::Abs(dx) > 100) {
437-
dx = 0;
438-
}
481+
const auto& info = getSliceRowInfo(slice, row);
482+
dx = GPUCommonMath::Max(info.minInvCorr[0], GPUCommonMath::Min(info.maxInvCorr[0], dx));
439483
x = mGeo.getRowInfo(row).x + dx;
440484
}
441485

@@ -450,9 +494,9 @@ GPUdi() void TPCFastSpaceChargeCorrection::getCorrectionInvUV(
450494

451495
float duv[2];
452496
spline.interpolateU(splineData, gridU, gridV, duv);
453-
if (CAMath::Abs(duv[0]) > 100 || CAMath::Abs(duv[1]) > 100) {
454-
duv[0] = duv[1] = 0;
455-
}
497+
const auto& info = getSliceRowInfo(slice, row);
498+
duv[0] = GPUCommonMath::Max(info.minInvCorr[1], GPUCommonMath::Min(info.maxInvCorr[1], duv[0]));
499+
duv[1] = GPUCommonMath::Max(info.minInvCorr[2], GPUCommonMath::Min(info.maxInvCorr[2], duv[1]));
456500
nomU = corrU - duv[0];
457501
nomV = corrV - duv[1];
458502
}

GPU/TPCFastTransformation/macro/TPCFastTransformInit.C

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
/// root -l TPCFastTransformInit.C'("debugVoxRes.root")'
2222
///
2323

24-
#include "Algorithm/RangeTokenizer.h"
25-
2624
#if !defined(__CLING__) || defined(__ROOTCLING__)
2725

2826
#include <filesystem>
@@ -41,6 +39,8 @@
4139
#include "TPCCalibration/TPCFastSpaceChargeCorrectionHelper.h"
4240
#endif
4341

42+
#include "Algorithm/RangeTokenizer.h"
43+
4444
using namespace o2::tpc;
4545
using namespace o2::gpu;
4646

@@ -99,8 +99,9 @@ void TPCFastTransformInit(const char* fileName = "debugVoxRes.root",
9999
trackResiduals.setZ2XBinning(z2xBins);
100100
trackResiduals.init();
101101

102-
{
103-
std::cout << "input track residuals: " << std::endl;
102+
{ // debug output
103+
104+
std::cout << " ===== input track residuals ==== " << std::endl;
104105
std::cout << "voxel tree y2xBins: " << y2xBins.size() << std::endl;
105106

106107
for (auto y2x : y2xBins) {
@@ -127,6 +128,7 @@ void TPCFastTransformInit(const char* fileName = "debugVoxRes.root",
127128
for (int i = 0; i < nZ2Xbins; i++) {
128129
std::cout << "getZ2X(bin) : " << trackResiduals.getZ2X(i) << std::endl;
129130
}
131+
std::cout << " ==================================== " << std::endl;
130132
}
131133

132134
std::cout << "create fast transformation ... " << std::endl;
@@ -310,15 +312,16 @@ void TPCFastTransformInit(const char* fileName = "debugVoxRes.root",
310312
geo.convUVtoLocal(iRoc, u + cu, v + cv, cy, cz);
311313
cy -= y;
312314
cz -= z;
315+
313316
double d[3] = {cx - correctionX, cy - correctionY, cz - correctionZ};
314317
if (voxEntries >= 1.) {
315318
for (int i = 0; i < 3; i++) {
316319
if (fabs(maxDiff[i]) < fabs(d[i])) {
317320
maxDiff[i] = d[i];
318321
maxDiffRoc[i] = iRoc;
319322
maxDiffRow[i] = iRow;
320-
std::cout << " roc " << iRoc << " row " << iRow << " xyz " << i
321-
<< " diff " << d[i] << " entries " << voxEntries << " y " << y2xBin << " z " << z2xBin << std::endl;
323+
// std::cout << " roc " << iRoc << " row " << iRow << " xyz " << i
324+
// << " diff " << d[i] << " entries " << voxEntries << " y " << y2xBin << " z " << z2xBin << std::endl;
322325
}
323326
sumDiff[i] += d[i] * d[i];
324327
}

0 commit comments

Comments
 (0)