Skip to content

Commit bab47b7

Browse files
matthias-kleinerclaude
authored andcommitted
TPC: fix the weight and grid scaling of the spline derivatives in addCorrections (#15994)
* TPC: fix the weight scaling of the mixed spline derivative in addCorrections TPCFastSpaceChargeCorrectionHelper::addCorrections scaled the 4th parameter of each spline knot (the mixed derivative d2S/dudv) with the square of the weight: secMainScale * secMainScale for the main correction, ls * ls * ... for the added ones (ls is the weight times the z fade-out factor, 1 at the knots). A spline is linear in its parameters, so scaling the correction by w scales all of them by w. The correction was therefore right at the knots but wrong between them whenever a weight != 1 was used, e.g. the derivative map added with weight lumiScale in TPCScalerSpec::buildMap. The error is proportional to w - w^2. Measured with a production map and the derivative map of run 568041 (random points, vs the weighted point-by-point sum of getCorrectionLocal and of the inverse getters), for map + 0.13 x derivative: rms ~20 um in dx and dz, ~10 um without the first 10 pad rows; deviations above 100 um are rare (0.4 % of the points) and lie mostly in the first pad rows. At a weight of -0.5 the rms is ~150 um (~60 um without the first 10 pad rows). With the fix the sum is exact to float precision (< 0.1 um) for weights from -1 to 1.5, inverse corrections included; w = 1 is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * TPC: fix the chain-rule grid factors in addCorrections A correction added on a different spline grid is sampled at the main grid's knots, and its derivatives must be converted with the chain rule: with u = (y - y0) * yScale, d/du_main = (yScale_corr / yScale_main) d/du_corr, the same for v. addCorrections used the inverse ratios, and applied the u factor to the dS/dv parameter and the v factor to dS/du (knot parameters {S, dS/dv, dS/du, d2S/dudv}). For identical grids (e.g. the derivative map) the factors are 1 and nothing changes. The M-shape map is created on a 4 x 4 grid in TPCScalerSpec, with factors of 35-98 with respect to a production map: adding the M-shape map of run 544797 (up to 6 mm) to a map of run 568041 gave errors of up to 89 cm in dx and up to the kMaxCorrection limit of 100 cm in dy (rms 4 cm and 7 cm), vs the point-by-point sum. With the fix: rms 1-2 um, max 60 um (resampling of non-nested grids) inside the main map's grid. Outside of it (|z| > ~1.37 x for production voxel maps) the merged map follows the edge and z fade-out of the main grid, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit a36f08c) (cherry picked from commit f4d548e)
1 parent 91453af commit bab47b7

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

‎Detectors/TPC/calibration/src/TPCFastSpaceChargeCorrectionHelper.cxx‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,8 +1040,8 @@ void TPCFastSpaceChargeCorrectionHelper::mergeCorrections(
10401040
constexpr int nKnotPar3d = nKnotPar1d * 3;
10411041

10421042
{ // scale the main correction
1043-
1044-
double parscale[4] = {mainScale, mainScale, mainScale, mainScale * mainScale};
1043+
// a spline is linear in its parameters: scaling the function scales all of them, the mixed derivative included
1044+
double parscale[4] = {mainScale, mainScale, mainScale, mainScale};
10451045
for (int iknot = 0, ind = 0; iknot < spline.getNumberOfKnots(); iknot++) {
10461046
for (int ipar = 0; ipar < nKnotPar1d; ++ipar) {
10471047
for (int idim = 0; idim < 3; idim++, ind++) {
@@ -1075,10 +1075,11 @@ void TPCFastSpaceChargeCorrectionHelper::mergeCorrections(
10751075
double scale = additionalCorrections[icorr].second;
10761076
auto& linfo = corr.getRowInfo(row);
10771077

1078-
double scaleU = rowInfo.gridMeasured.getYscale() / linfo.gridMeasured.getYscale();
1079-
double scaleV = rowInfo.gridMeasured.getZscale() / linfo.gridMeasured.getZscale();
1080-
double scaleRealU = rowInfo.gridReal.getYscale() / linfo.gridReal.getYscale();
1081-
double scaleRealV = rowInfo.gridReal.getZscale() / linfo.gridReal.getZscale();
1078+
// chain rule for the derivatives: u = (y - y0) * yScale, v = (z - z0) * zScale => d/du_main = (du_corr / du_main) d/du_corr
1079+
double scaleU = linfo.gridMeasured.getYscale() / rowInfo.gridMeasured.getYscale();
1080+
double scaleV = linfo.gridMeasured.getZscale() / rowInfo.gridMeasured.getZscale();
1081+
double scaleRealU = linfo.gridReal.getYscale() / rowInfo.gridReal.getYscale();
1082+
double scaleRealV = linfo.gridReal.getZscale() / rowInfo.gridReal.getZscale();
10821083

10831084
for (int iu = 0; iu < gridU.getNumberOfKnots(); iu++) {
10841085
double u = gridU.getKnot(iu).u;
@@ -1094,7 +1095,8 @@ void TPCFastSpaceChargeCorrectionHelper::mergeCorrections(
10941095
float lu, lv, ls;
10951096
corr.convLocalToGrid(sector, row, y, z, lu, lv, ls);
10961097
ls *= scale;
1097-
double parscale[4] = {ls, ls * scaleU, ls * scaleV, ls * ls * scaleU * scaleV};
1098+
// knot parameters: {S, dS/dv, dS/du, d2S/dudv}
1099+
double parscale[4] = {ls, ls * scaleV, ls * scaleU, ls * scaleU * scaleV};
10981100
const auto& spl = corr.getSplineForRow(row);
10991101
spl.interpolateParametersAtU(corr.getCorrectionData(sector, row), lu, lv, P);
11001102
for (int ipar = 0, ind = 0; ipar < nKnotPar1d; ++ipar) {
@@ -1110,7 +1112,7 @@ void TPCFastSpaceChargeCorrectionHelper::mergeCorrections(
11101112
float lu, lv, ls;
11111113
corr.convRealLocalToGrid(sector, row, y, z, lu, lv, ls);
11121114
ls *= scale;
1113-
double parscale[4] = {ls, ls * scaleRealU, ls * scaleRealV, ls * ls * scaleRealU * scaleRealV};
1115+
double parscale[4] = {ls, ls * scaleRealV, ls * scaleRealU, ls * scaleRealU * scaleRealV};
11141116

11151117
{ // inverse X correction
11161118
corr.getSplineInvXforRow(row).interpolateParametersAtU(corr.getCorrectionDataInvX(sector, row), lu, lv, P);

0 commit comments

Comments
 (0)