Skip to content

Core correctness: CovMatrix stride, eigenvector guard, std::abs - #307

Draft
gavinsdavies wants to merge 1 commit into
mainfrom
feature/gsdavies/core-correctness
Draft

Core correctness: CovMatrix stride, eigenvector guard, std::abs#307
gavinsdavies wants to merge 1 commit into
mainfrom
feature/gsdavies/core-correctness

Conversation

@gavinsdavies

Copy link
Copy Markdown
Contributor

Part of #303.

Fixes

RecoBase/DwnstrTrack.h — covariance stride mismatch. CovMatrix(i,j) always read fCovXY[5*i+j], but for no-magnet 4-parameter tracks Reset(true) resizes fCovXY to 16 and the producer (SSDRecDwnstrTracksAutre) fills it with stride 4 (SetCovarianceMatrix(i*nPars + j)). So every off-diagonal read on 4-param tracks returned the wrong element, and (3,3) read index 18 of a 16-element vector (out of bounds). The getter now uses NumParams()*i + j, matching the setter. A full call-site audit (all two-argument CovMatrix( uses are in SSDDVertexFitFCNAutre.cxx) confirmed all callers pass logical indices and none compensates for the old stride; the 5-parameter/magnet path is byte-for-byte unchanged. No other RecoBase class has this pattern (VertexAutre uses a true 2-D array).

RecoUtils/RecoUtils.cxx — degenerate eigenvector guard. findLine divides by the principal eigenvector's z-component without a guard; an xy-collinear point set gives n[2] ≈ 0 and infinite endpoints. Added an early return (epsilon 1e-12 on a unit-normalized vector — far below any physical slope, above eigen-decomposition round-off) in the same style and output contract as the existing el == -1 check: lfirst/llast stay zero-initialized, which the callers in SingleTrackAlgo already tolerate.

Geometry/Geometry.cxx — portable std::abs. Detector::View() used unqualified abs(sin(...)) on doubles (×4). It currently resolves to a floating overload under GCC/libstdc++, but if it ever resolves to C int abs(int) (other toolchain/include order), every comparison < 0.2 collapses and all sensors classify as X_VIEW. Now std::abs, with an explicit <cmath> include.

Verification

The CovMatrix change is a deliberate correctness change for 4-param tracks only (audit in the description above); everything else is behavior-preserving. No local build environment and no repo CI — a collaborator build before undrafting would be appreciated.

🤖 Assisted by Claude Code (claude-fable-5)

@FNALbuild

Copy link
Copy Markdown
Collaborator

✔️ CI build for EMPHATIC Succeeded on slf7 for maxopt -- details available through the CI dashboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants