Fix precision of eta at negative z in GenVector #24233
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #24233"
general
weight: 0.35
guitargeek
This Pull request:
Makes
Eta()of the GenVector coordinate systems that compute eta from rho and z precise for negative z, and an odd function of z bit for bit.Changes or fixes:
The problem
ROOT::Math::Impl::Eta_FromRhoZ(rho, z)computeslog(zs + sqrt(zs zs + 1))withzs = z / rho. Forzs < 0the sum subtracts two nearly equal numbers. The error of eta is then aboutzs zstimes the rounding error of the scalar type. For large negativezs(|zs|aboveepsilon^-0.25, which is 54 for float and 8192 for double) the function returns-log(-2 zs): it drops the0.5 / zsterm that it keeps for positivezs.Cartesian3D,Cylindrical3D,PxPyPzE4DandPxPyPzM4Dcall this function. The problem is thus inEta()ofXYZVector,XYZPoint,RhoZPhiVector,PxPyPzEVector,PxPyPzMVectorand their float variants.Example:
ROOT::Math::XYZVectorFwith x = 30, y = 40 (rho = 50) and |z| = 340. The exact |eta| is 2.61543304, and the nearest float is 2.61543298.| | master | this PR |
|---|---|---|
|
Eta()at z = +340 | 2.61543298 | 2.61543298 ||
Eta()at z = -340 | -2.61543393 | -2.61543298 || error at z = +340 | 0.26 ULP | 0.26 ULP |
| error at z = -340 | 3.74 ULP | 0.26 ULP |
| change of eta for one float step of z at z = +340 | 2.4e-7 | 2.4e-7 |
| change of eta for one float step of z at z = -340 | 9.5e-7 | 2.4e-7 |
Context
The problem shows in the reconstruction of the CMS HGCAL endcap calorimeters, which are at z > 0 and at z < 0. CMS runs the same reconstruction in two implementations: one written for GPUs (run on the CPU here) and one written for the CPU. On the same input, the cluster positions of the two implementations differ only by float rounding: 1.7e-7 relative (99% quantile), the same at z > 0 and at z < 0. A later step reads the cluster position as a float
XYZVectorand selects track-cluster pairs with windows in eta. The eta difference between the two implementations is not the same on the two sides: its 99% quantile is 2.4e-7 at z > 0 and 4.5e-6 at z < 0. A window cut on eta then changes its decision about 20 times more often in the negative endcap.With the reconstruction built against this fix, on the same 1037 simulated events with 200 pileup interactions (the 21 files of a CMS validation sample of 60,710 events that contain an event in which the two implementations disagree):
| Events where the two implementations take a different decision | master | this PR |
|---|---|---|
| in the endcap at z < 0 | 22 | 2 |
| in the endcap at z > 0 | 1 | 1 |
| total | 23 | 3 |
The 3 events that remain come from the float rounding of the cluster positions, which is the same on both sides.
The fix
The function computes the formula for
|zs|, where the sum has no cancellation, and applies the sign ofzsto the result. The branch for large|zs|uses the same expression for both signs. The branch for rho = 0 does not change. The scalar type does not change.The first commit changes GenVector and adds the test. The second commit makes the same change in the copy of the function in GenVectorX (
MathX/GenVectorX/eta.h).Measurements
A standalone program compares the function of master and the function of this PR with
asinhl(z / rho)in long double. Each line has 4e6 random points, each evaluated at +z and at -z. The error is in units of the last place (ULP) of the scalar type: largest value / 99% quantile. x86-64, GCC 8.5,-O2.| Scalar | Points | z > 0, master and this PR | z < 0, master | z < 0, this PR |
|---|---|---|---|---|
| float | rho in [1, 300], \|z\| in (0, 600], \|z\|/rho >= 1 | 1.32 / 0.80 | 256 / 115 | 1.32 / 0.80 |
| float | rho in [1, 300], \|z\| in (0, 600], \|z\|/rho < 1 | 1.49 / 0.89 | 1.72 / 0.97 | 1.49 / 0.89 |
| float | rho in [0.001, 1], \|z\| in (0, 600], \|z\|/rho >= 1 | 1.10 / 0.53 | 256 / 78 | 1.10 / 0.53 |
| float | rho in [1, 300], \|z\|/rho in [10, 1e10] | 0.79 / 0.52 | 256 / 139 | 0.79 / 0.52 |
| double | rho in [1, 300], \|z\| in (0, 600], \|z\|/rho >= 1 | 2.65 / 1.21 | 9.0e4 / 800 | 2.65 / 1.21 |
| double | rho in [0.001, 1], \|z\| in (0, 600], \|z\|/rho >= 1 | 1.98 / 0.56 | 6.2e6 / 3.3e6 | 1.98 / 0.56 |
| double | rho in [1, 300], \|z\|/rho in [10, 1e10] | 1.11 / 0.56 | 6.1e6 / 2.2e6 | 1.11 / 0.56 |
Number of points with
eta(-z) != -eta(z)on master, for rho in [1, 300] and |z| in (0, 600]: 2301690 of 4e6 (float) and 3530696 of 4e6 (double). With this PR: 0 in all samples.A second test moves each of x, y and z of a float position by -1, 0 or +1 float step (rho in [30, 270], |z| in [320, 520], 2e6 positions) and reads the change of eta. At z > 0 the 99% quantile is 2.4e-7 and the largest value is 4.8e-7, on master and with this PR. At z < 0 the 99% quantile goes from 6.7e-6 to 2.4e-7 and the largest value goes from 3.0e-5 to 4.8e-7.
Not in this PR
log(zs + sqrt(zs zs + 1))loses relative precision when |zs| is small, because the argument of the log is near 1. The error is the same for both signs of z (99% quantile 50 ULP, largest value 8.7e5 ULP for rho in [1, 300] and |z| in (0, 600]), on master and with this PR. A fix for that changes the results at z > 0, so it is not part of this change.Eta_FromTheta(used byPolar3D) has no such subtraction and does not change.MathX/GenVectorX/MathHeaders.hhas two more copies ofEta_FromRhoZ, outside theImplnamespace. No code calls them. They do not change.Tests
The new test
math/genvector/test/testEta.cxx(testGenVectorEta, Google Test) checksCartesian3D,Cylindrical3D,PxPyPzE4DandPxPyPzM4D, for z/rho from 3e-5 to 7e8:asinh(z / rho)in long double, for both signs of z (the largest error on the grid of the test is 1.14 ULP).The test fails on master (21742 failed checks) and passes with this PR.
coordinates3Dandcoordinates4Dpass on master and with this PR.Checklist:
coordinates3Dandcoordinates4D, with GCC 8.5 and GCC 14.3; no full ROOT build)