← Back to Pull requests

Fix precision of eta at negative z in GenVector #24233

Closed
unknown closed this pull request without merging on Nov 19, 2026 22:04 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 16:02 UTC
Author

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) computes log(zs + sqrt(zs zs + 1)) with zs = z / rho. For zs < 0 the sum subtracts two nearly equal numbers. The error of eta is then about zs zs times the rounding error of the scalar type. For large negative zs (|zs| above epsilon^-0.25, which is 54 for float and 8192 for double) the function returns -log(-2 zs): it drops the 0.5 / zs term that it keeps for positive zs.

Cartesian3D, Cylindrical3D, PxPyPzE4D and PxPyPzM4D call this function. The problem is thus in Eta() of XYZVector, XYZPoint, RhoZPhiVector, PxPyPzEVector, PxPyPzMVector and their float variants.

Example: ROOT::Math::XYZVectorF with 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 XYZVector and 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 of zs to 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.

  • Eta is an odd function of z, bit for bit.

  • The results at z > 0 do not change, bit for bit (0 of 24e6 tested points differ).

  • The error at z < 0 is equal to the error at z > 0.
  • 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

  • For double and |z|/rho < 1, 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 by Polar3D) has no such subtraction and does not change.

  • MathX/GenVectorX/MathHeaders.h has two more copies of Eta_FromRhoZ, outside the Impl namespace. No code calls them. They do not change.
  • Tests

    The new test math/genvector/test/testEta.cxx (testGenVectorEta, Google Test) checks Cartesian3D, Cylindrical3D, PxPyPzE4D and PxPyPzM4D, for z/rho from 3e-5 to 7e8:

  • eta(-z) is equal to -eta(z) bit for bit, for float and double;

  • eta of a float vector is within 2 ULP of 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. coordinates3D and coordinates4D pass on master and with this PR.

    Checklist:

  • tested changes locally (standalone build of the GenVector headers, of the new test and of coordinates3D and coordinates4D, with GCC 8.5 and GCC 14.3; no full ROOT build)

  • updated the docs (if necessary): no change of the documentation is necessary
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: guitargeek Review duration: 1802m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%