Skip to content

Add a projection of the spatial covariance to Intersection. - #239

Open
brownd1978 wants to merge 7 commits into
KFTrack:mainfrom
brownd1978:iproj
Open

brownd1978 wants to merge 7 commits into
KFTrack:mainfrom
brownd1978:iproj

Conversation

@brownd1978

@brownd1978 brownd1978 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

This PR also addresses #237 and #238

Summary of changes in #239

This PR adds an optional projection of the trajectory's spatial covariance onto the local plane at an Intersection. It also adds the fraction of that covariance that lies inside the surface boundaries. Along the way it fixes several intersection and unit-test problems: #237, #238, the macOS Truncate CI failure and the gradient-field fit tests. The commits are 9cce2ac, bae8ab3, 085d199, 33f4bbd, 862cc6f, d426035 and cb8107d (the last one is local and not pushed yet).

1. Projected covariance in the Intersection payload

  • New fields:
    • Intersection gains the local tangent-plane frame (udir_, vdir_; W = norm_).
    • It also gains pcov_, the 2x2 spatial covariance of the trajectory projected onto that plane in UV coordinates.
    • IntersectFlag gains hascov_, which records whether pcov_ was filled. It is independent of good() and is included in == and !=.
  • When it is computed: the projection is optional, because it is relatively costly.
    • All intersect(...) overloads, including the ParticleTrajectory version, take a trailing bool pcov = false. Existing callers are unchanged.
    • When it is requested, the projection is computed only for the final intersection, and for on-surface intersections whether they are in bounds or not.
  • fillPlaneCovariance(ktraj, surf, inter, tol, dirtol=1e-10) can be called on its own:
    • It takes the frame from the surface's tangent plane at the intersection position. That means intersections built by hand (position, time and flags only) get the same frame, pcov_ and inbfrac_ as intersect(..., pcov=true).
    • If the trajectory is (nearly) parallel to the plane, the covariance is left at 0 and hascov_ false. The test is |cos(direction, normal)| < dirtol.
  • Projection fix: planeCovariance(time, plane, dirtol) in LoopHelix, CentralHelix and KinematicLine now projects along the particle direction. The result is the covariance of the point where the trajectory crosses the plane. Before, the 3D position covariance was projected orthogonally onto U and V. Errors along the particle direction, such as t0, drop out of this linear projection.
    • The cut on a direction lying in the plane is now the dirtol argument rather than repeated 1e-10 literals.

2. Covariance fraction inside the surface bounds

  • New field: Intersection::inbfrac_ (meaningful when hascov_ is set) is the approximate (~1%) fraction of the 2D Gaussian described by pcov_ that lies inside the surface boundaries.
  • Method (boundsFraction):
    • The fraction is integrated in whitened coordinates, as an angular integral over rays from the intersection point.
    • Along each ray, boundary crossings are found by stepping out to 5 sigma and refining by bisection.
    • Angular sectors that contain a corner or a nearby edge are subdivided adaptively.
    • This handles any number of edges, corners and holes in the same way.
    • On curved surfaces the boundaries are projected onto the tangent plane along the surface normal.
    • A degenerate covariance returns 1 if the intersection is in bounds and 0 if not.

3. Intersection behaviour changes and fixes

  • Out-of-bounds crossings on cylinders and frustrums: these intersections now return an on-surface crossing flagged out of bounds, instead of no intersection. If no in-bounds crossing exists in the range, the first crossing in the full range is returned. Callers that need in-bounds crossings must check inbounds_ or good().
  • hpIntersect: build the CentralHelix plane window from the true helix axis #237: hpIntersect now narrows its search window for CentralHelix with the true helix axis (new CentralHelix::axis()) rather than the tangent line, so every plane crossing lies inside the window.
  • canIntersect: miss cylinder crossings when the field is tilted from the cylinder axis #238: canIntersect for cylinders and frustrums now finds glancing intersections when the field is tilted from the surface axis.
    • It uses the fact that the helix-centre distance from the axis is convex in time.
    • It allows for the cos(tilt) foreshortening of the projected helix circle, and for the cone-radius change across the tilt.
  • Failed end-disk searches: the cylinder and frustrum code now ignores end-disk crossings that are not on the surface. A failed search leaves time_ at 0, which could otherwise fall inside query ranges that span t = 0.
  • Material::extrapolate: it returns early for an inactive element crossing (for example an out-of-bounds one), so the trajectory is not split. As with process and append, the effect is kept, and it contributes again if it becomes active on a refit.

4. Unit tests

  • IntersectionCovariance (new): compares pcov_ with a toy MC of trajectory crossings, for LoopHelix, CentralHelix and KinematicLine on plane, rectangle and cylinder surfaces. It also checks consistency with planeCovariance, that pcov_ is filled only on request, and the out-of-bounds and parallel cases.
  • IntersectionBounds (new): compares inbfrac_ with a toy MC, and with analytic values where they exist, for edges, corners and curved surfaces. It checks that hand-built intersections reproduce intersect(..., pcov=true). The intersection tolerance is 1e-3 mm, which is small next to the ~1 mm projected errors. The test runs in about 2 s optimized and about 30 s in an -O0 build, well inside the CI limit.
  • IntersectTilt (new): covers the glancing tilted-axis cylinder and frustrum crossings from canIntersect: miss cylinder crossings when the field is tilted from the cylinder axis #238.
  • ParticleTrajectoryTest: gains a check of the covariance on piecewise-trajectory intersections.
  • Truncate: the macOS CI failure (LoopHelix bfcorr inactive hits ... effects kept) is fixed.
    • The test now counts the domains and DomainWalls that are removed beyond the cut, rather than requiring the total number of effects to stay the same. How many domains a step leaves beyond the cut depends on floating-point details.
    • A short-step extrapolation and a second cut make sure the domain-removal path is always exercised.
  • ToyMC fix: in a non-uniform field, hits were generated only over the initial piece's range in field tolerance, rather than over the full simulation range. This broke the gradient-field fit tests. Hits now span the full range, and straw-material pieces stay valid at the end of the trajectory. The LoopHelixFit and CentralHelixFit gradient tests are re-enabled at the Mu2e tracker gradient.

5. Downstream (Offline)

  • Existing intersect callers compile and behave as before, because the covariance is off by default.
  • The out-of-bounds cylinder and frustrum returns can reach KKShellXing::updateReference. That is intentional (review finding S2). In the companion Offline work, KKShellXing treats such crossings as inactive material.
  • The Offline near-miss extension to ExtrapolateSweep uses pcov_ and inbfrac_ from this PR. It will be submitted as a separate Offline PR.

— Claude (Opus 5.5, Anthropic), via Claude Code

@brownd1978
brownd1978 requested a review from RobMina November 20, 2026 23:57
…ar helix and cylinder and frustrum axes. Add a unit test of this situation. Coded by Claude
@brownd1978

brownd1978 commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

Claude also addressed #238 and the CI failure in the Truncate test on MacOS.

@oksuzian oksuzian left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary — #239

Reviewed at head 085d1998f9c09f50ecd8641c07b5a7379ff13f82. First pass. I reviewed the library change at bae8ab3; 085d1998 only changes a test.

Decision

  • 🟢 approve. The new crossing-point covariance is right. It agrees to 5e-11 with Offline's independently written stand-in on 26,638 random cases, and the new toy test fails if the old projection is put back. Both issues are fixed. On the random cases from my #235 review, CentralHelix plane queries that return nothing drop from 1,944 to 18 of 19,770 (#237), and long-cylinder misses drop from 1,126 to 88 of 28,083 (#238). Every miss that is left is a stepping limit, not the new window or the new gate. The four findings are S2 and S3 and do not block.
  • 085d1998 only rewrites Tests/Truncate_unit.cc, so the library code is the same as at bae8ab3 and everything below applies to it. I built it and all 31 tests pass. GitHub Actions passed all four jobs at 085d1998, macOS included.

Scope understood

  • Intersection gains udir_ and vdir_, the U and V directions of the surface's tangent plane, and pcov_, the covariance (mm²) in U,V of where the trajectory crosses that plane. fillPlaneCovariance fills them for every on-surface result of stepIntersect and of the KinematicLine intersection.
  • planeCovariance(time,plane) in all three trajectories now projects along the particle direction, u - n (u·d)/(n·d). That gives the covariance of the crossing point instead of the plain projection at a fixed time.
  • CentralHelix::axis is new. hpIntersect now builds its search window from the helix axis for both helices (#237). For cylinders and frustums, canIntersect now tests the larger end separation and allows for the field tilt (#238).
  • Two new tests: IntersectionCovariance (toy MC) and IntersectTilt (random queries compared with stepping over the whole range).

Findings

  1. 🟡 [S2] The covariance is also computed for internal searches that only need a time, which makes cylinder intersections about 25% slower.
    • Evidence: fillPlaneCovariance runs at the end of every converged stepIntersect (Geometry/Intersect.hh:113). That includes the end-disk searches in hcIntersect (:192-193) and hfIntersect (:286-287), which use only time_. I timed intersect on my #235 cases (median ns per call, three alternating rounds, -O3). Cylinders: 2,885–3,135 on main, 3,729–3,886 here, and 3,087–3,120 here with only fillPlaneCovariance emptied. Planes: 1,706–1,789 on main, 1,756–1,839 here, and 1,372–1,483 without the fill.
    • Suggested fix: fill the covariance once, in the public intersect functions, on the result returned to the caller. I did not measure the effect on Mu2e reconstruction time.
  2. 🟡 [S2] In Offline, intersections that Offline builds itself will be stored with pcov_ = 0.
    • Evidence: the comment at Intersection.hh:25 says pcov_ is filled for all on-surface intersections. Offline's ExtrapolateSweep fills KinKal::Intersection field by field at Mu2eKinKal/inc/ExtrapolateSweep.hh:273, :365 and :406. The first of those handles every plane target: the ST foils, passive planes, calorimeter layers and calorimeter support front. KKFit.hh:1018 then writes these into the KalSeed. Cylinder crossings come from KinKal::intersect and will be filled. A zero matrix is then the only sign that the covariance is missing, and zero also means "parallel to the plane" or "no fit covariance".
    • Suggested fix: say in the Intersection.hh comment that pcov_ is zero when it is not computed. When Offline takes this tag, call KinKal::fillPlaneCovariance at those three places.
  3. ⚪ [S3] Two test details in Tests/IntersectionCovariance_unit.cc.
    • Line 163 gives KinematicLine the errors {0.1,0.1,0.0005,0.0005,0.005,0.05}, but its parameter order is d0, phi0, z0, theta, t0, mom (KinematicLine.hh:23-31). So phi0 gets 0.1 rad and z0 gets 0.0005 mm, which looks like positions and angles swapped. The 0.1 rad error dominates, and the two KinematicLine plane cases pass with the old projection too. The cylinder case still catches it.
    • The check against planeCovariance (:72-82) repeats the same call fillPlaneCovariance makes, so it cannot fail.
  4. ⚪ [S3] The new planeCovariance comment (LoopHelix.cc:139, CentralHelix.cc:170, KinematicLine.cc:138) says the result "includes the effect of the t0 (and other) errors on the position along the trajectory".
    • With this projection, a t0 error only moves the point along the trajectory, so it drops out exactly (LoopHelix.cc:356: dX_dt0 = -omval*mdir, along the motion). "Errors that only move the point along the trajectory, such as t0, drop out" would say it.
    • The 1.0e-10 parallel cut is written four times (Intersect.hh:31 and the three planeCovariance functions). fillPlaneCovariance avoids the throw only while they agree, so one named constant would keep them together.

Checked, no action needed

  • 🟢 The projection is right. A change dx in position moves the crossing by dx − d (n·dx)/(n·d), which is what uproj and vproj compute. I checked it three ways.
    • Offline's stand-in trkCrvPlaneCovariance (CRVReco/inc/TrkCrvPlaneError.hh:31) was written independently and uses the same projector, applied to the Cartesian state covariance. I compared it with pcov_ on 26,638 random cases: full correlated parameter covariances, fields tilted up to 0.3 rad, random planes for all three trajectories, and cylinder tangent planes for LoopHelix. The largest difference is 4.6e-11 of sqrt(uu·vv).
    • With the old planeCovariance restored in the three .cc files, IntersectionCovariance fails 6 of its 8 cases. For example, LoopHelix on the plane gives 98.7 mm² where the toy gives 1.00 mm². At this head it also passes with 20 other seeds.
    • No caller depends on the old meaning. The only KinKal caller, Tests/Trajectory.hh:332, uses a plane normal to the momentum, where the two projections agree. GitHub code search finds no caller in any Mu2e repository.
  • 🟢 #237 is fixed.
    • CentralHelix::center(t) has the same coordinate along the field as position3(t) (CentralHelix.cc:487 and :205). So the new axis is the true helix axis, and the R·tanθ window holds every crossing. LoopHelix is unchanged, because its linearize already returned axis.
    • On my #235 cases, CentralHelix planes return nothing for 1,944 of 19,770 queries on main and for 18 here. The 1,930 of 19,887 quoted in #237 came from my earlier count; 19,887 is the LoopHelix total. All 18 that remain go less than tol past the plane.
    • The tests cover it: with only this change undone, IntersectTilt and IntersectionCovariance both fail.
  • 🟢 #238 is fixed, and the new canIntersect never rejects a range the old one passed.
    • The old cylinder test needed both ends unnested; the new one needs either end. Its cut, rbend*cos(tilt) − R, is never larger than the old |R − rbend|. The same holds for the frustum.
    • The bounds are right. The helix centre moves linearly along the field, so its distance from the axis is convex in time and largest at an end. The tilted circle projects to an ellipse whose minor axis is rbend*cos(tilt), and it spans ±rbend*sin(tilt) along the axis.
    • Brute force on 166,910 random queries (both helices, cylinders and frustums along z, field tilted up to 0.45 rad, 0.5 to 2 T): there are 91,423 ranges where the helix goes more than tol past the surface on both sides. The old test rejects 22,516 of them and the new one rejects none.
    • On my #235 cases, long-cylinder queries that return nothing drop from 1,126 to 88 of 28,083. The old test caused 1,049 of the 1,126, all with a tilted field (median 163 mrad, minimum 1.2 mrad). All 88 that remain pass the new test, and stepping over the whole query misses them too. 78 go less than tol past the surface. The other 10 go 1.1 to 9.6 tol deep, and six of those are cylinders of 7 to 26 mm radius. In all of them both crossings fall inside one step.
  • 🟢 The frustum change also fixes cones with no field tilt, where the nesting changes along the axis. IntersectTilt run against main misses 99 of 265 and 17 of 40 crossings at zero tilt. On my #235 frustum cases, misses drop from 1,283 to 39 of 14,383. Mu2e's OPA is a frustum (GeometryService/src/KinKalGeomMaker.cc:375).
  • 🟢 What changes for the worse is limited to crossings the stepping is not meant to catch.
    • Of the 94,383 cases, 5 that main gets right are wrong here. All are CentralHelix planes whose crossing goes only 0.24 to 0.58 tol past the plane, and the new window steps over it.
    • Four queries that returned nothing now return a later root. Three are crossings shallower than tol. The fourth is a 1 mm cut through a cylinder at tol = 0.1 mm, with both crossings inside one 11 mm step.
    • The 10 new results on finite surfaces with no in-bounds crossing are out-of-bounds crossings, correctly flagged with inbounds_ false.
  • 🟢 The other tests are unchanged. Every other test binary prints the same output in both builds, apart from paths and fit times. The one exception is a CentralHelix time in IntersectReturn, which moves by 7e-13 ns and now equals the expected value.
  • 🟢 Offline can read old files, and old code can read new ones.
    • RecoDataProducts/src/classes_def.xml:225 declares KinKal::Intersection with no ClassVersion. ROOT therefore versions it by checksum, and no version bump is needed.
    • I built genreflex dictionaries with that selection from the base headers and from the head headers. A file written with either layout reads correctly with the other, split and unsplit, with no warnings. The new members read as zero from old files.
    • ROOT's libSmatrix.rootmap provides the dictionary for the 2x2 symmetric matrix.
    • Offline has no aggregate initialisation or structured bindings of Intersection.
  • 🟢 The macOS CI failure at bae8ab3 was not from this PR. It is Truncate failing with "FAILED: LoopHelix bfcorr inactive hits event 1 effects kept", the same failure as on main since #236 merged (906c4ce, 17 November) and at 3a6860b. 085d1998 replaces that count with checkCut, which is stricter: it requires that exactly the domains beyond the cut and their DomainWalls are removed.

Validation check

  • Build/tests run: yes. KinKal standalone, CMake Release, Mu2e envset p111 (GCC 13.3, ROOT 6.38). I built the merge base 3a6860b, this head and 085d1998, with no warnings under -Wall -Werror. ctest passes 29 of 29 at the base, 31 of 31 here and 31 of 31 at 085d1998. I also ran each test binary on its own in the base and head builds and compared the outputs. The harness, scripts, cases and logs are under /exp/mu2e/data/users/oksuzian/claude-scratch/kinkal239_review/.
  • CI: GitHub Actions at bae8ab3 passed Ubuntu Debug and Release and failed macOS Debug and Release, with the Truncate failure above. At 085d1998 all four jobs passed.
  • Sourced numbers: none in the diff.
  • Cross-repo consistency: needs a follow-up in Offline when it takes this tag (finding 2). Nothing breaks at compile or read time.

Residual risk

  • Not checked: an Offline build against this KinKal and a Mu2e reconstruction job. So I have neither the Mu2e CPU cost of finding 1 nor the number of Mu2e intersections that move. I also did not run a Debug build or a macOS build myself; CI covers both.
  • Each persisted KalIntersection grows by 9 doubles (72 bytes before compression). It already stores the full state covariance in pstate_, and the same projection follows from that, which is what the CRV stand-in does. Whether Offline needs pcov_ on file is worth deciding when it takes the tag.
  • Thin cylinders cut by much larger helix circles can still be missed by the stepping. That is independent of this PR.

Author follow-ups

  1. Optional: fill pcov_ only on the result returned to the caller (finding 1).
  2. Note in Intersection.hh that pcov_ is zero when it is not computed. When Offline takes this tag, fill it in Offline's ExtrapolateSweep (finding 2).
  3. Optional: fix the KinematicLine errors in IntersectionCovariance and the comments in finding 4.
  4. The body says the PR "addresses" #237, which GitHub does not treat as a closing keyword, and it does not name #238 or the Truncate fix. "Fixes #237, fixes #238" in the body would close both issues on merge.

…t. Re-enable that test at Mu2e tracker gradient. Fixed by Claude.

@oksuzian oksuzian left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary — #239

Reviewed at head 33f4bbdef7b6e819b57180b386ac4f2506557039. Re-review of 085d1998.

Decision

  • 🟢 approve. The new commit only changes tests. It fixes the toy MC so the gradient-field fit tests can run again, and turns those tests back on. All four GitHub Actions jobs pass at this head, Ubuntu and macOS, Debug and Release. My four findings from the review at 085d1998 (6001853059) are unchanged and still do not block.

Scope understood

  • 33f4bbde changes Tests/ToyMC.hh, Tests/LoopHelixFit_unit.cc and Tests/CentralHelixFit_unit.cc. No library code changes.
  • createTraj now returns the end of the full simulation time, and simulateParticle spreads the hits over that whole range. In a gradient field the first piece covers only the time the field stays within tolerance. Before, all the hits were packed into that short first piece.
  • createStrawMaterial covers one step past the crossing when the crossing is at or past the end simulated so far. It now uses append(newend,true) to drop pieces past the crossing, which were simulated with the old momentum.
  • The two *Fit_unit tests again run with --Bgrad -0.036, the seedfit.txt schedule and --extend driftextend.txt. They were turned off in b6e53d91 (2024-03-14, "the MC is broken").

Findings

  • No new findings. Status of the four from the review at 085d1998:
    1. 🟡 [S2] The covariance is filled during internal searches too, so cylinder intersections are about 25% slower: open.
    2. 🟡 [S2] Offline builds some intersections itself, and those will be stored with pcov_ = 0: open, as an Offline follow-up when it takes the tag.
    3. ⚪ [S3] The KinematicLine errors in IntersectionCovariance_unit.cc:163 look swapped, and the check at :72-82 cannot fail: open.
    4. ⚪ [S3] The t0 comment, and the 1.0e-10 cut written four times: open.

Checked, no action needed

  • 🟢 Uniform-field tests simulate the same events as before.
    • In a uniform field, rangeInTolerance returns the trajectory's own range (General/BFieldMap.hh:93-94). So the first piece still spans the full tmax, and the hit times are unchanged.
    • Each straw crossing there is appended at the last piece, so append(...,true) removes nothing (Trajectory/PiecewiseTrajectory.hh:158-164). The old append(...,false) would have thrown otherwise, and it never did.
  • 🟢 In a gradient field the new code is consistent.
    • extendTraj stops exactly at the hit time (Tests/ToyMC.hh:261), so a straw crossing is at most a little past the simulated end, and the new branch covers that case.
    • append(newend,true) keeps the old end time when it is later (PiecewiseTrajectory.hh:169).
  • 🟢 The re-enabled tests can fail. FitTest exits non-zero when more than 10% of fits fail or diverge (Tests/FitTest.hh:1027-1028), or when the fitted momentum bias or resolution is out of tolerance (:1043-1046). It ends with exit(retval) (:1166), which ctest reads.

Validation check

  • Build/tests run: no local build for this commit. GitHub Actions passed all four Tests jobs at 33f4bbde, finishing 02:26:48Z to 02:29:36Z (read 2026-11-21T05:40Z). My earlier local build at 085d1998 (31 of 31 tests passing) covers the library code, which is unchanged.
  • Sourced numbers: none in the diff. -0.036 is the existing Mu2e-like gradient the tests used before 2024.
  • Cross-repo consistency: test-only change. Offline is not affected.

Residual risk

  • I did not run the re-enabled gradient tests locally or check how stable they are across seeds. CI runs one seed.

Author follow-ups

  1. The follow-ups from my review at 085d1998 still apply. The two marked optional remain optional.

@oksuzian oksuzian left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary — #239

Reviewed at head 862cc6f76abbb27063eaf7746357555bb060269d. Re-review of 33f4bbde.

Decision

  • 🟢 approve. 862cc6f7 makes the covariance projection optional and off by default. That fixes both of my S2 findings: internal searches no longer pay for it, and the new hascov_ flag says whether pcov_ was filled. One new S2: fillPlaneCovariance now relies on the U direction already being set, which matters only for code outside KinKal that builds its own intersections. All four GitHub Actions jobs pass at this head. Nothing here blocks.

Scope understood

  • fillPlaneFrame(surf,inter) sets udir_ and vdir_ for every on-surface result of stepIntersect and of the KinematicLine intersection. fillPlaneCovariance(ktraj,inter) fills pcov_ and sets hascov_ only when asked.
  • Every public intersect gains bool pcov=false after tdir. When it is true, the covariance is filled once, on the returned result. ParticleTrajectory fills it from the piece holding the final intersection.
  • IntersectFlag gains hascov_, which ==, != and the printouts include.
  • Both tests check that a default call returns the same intersection with no covariance.

Findings

  1. 🟡 [S2] (new) fillPlaneCovariance now takes the plane's U direction from inter.udir_ instead of from the surface. An intersection whose frame was never set therefore gets a zero covariance marked as valid.
    • Evidence: Geometry/Intersect.hh:40 builds Plane(inter.norm_,inter.udir_,inter.pos_) and sets hascov_ = true at :42. Inside KinKal every on-surface result passes fillPlaneFrame first (:124, :371), so this is safe there.
    • An Intersection filled by hand, as Offline's ExtrapolateSweep does (Mu2eKinKal/inc/ExtrapolateSweep.hh:273-283, :406-412 at 0f6b4ad0), has udir_ = 0. ROOT's Unit() returns a zero vector unchanged (Math/GenVector/DisplacementVector3D.h:337-338, ROOT 6.38), so Plane.cc:6 does not throw and vdir_ is zero too. planeCovariance then projects onto zero vectors (LoopHelix.cc:145-146), and the result is pcov_ = 0 with hascov_ true.
    • Impact: none inside KinKal. It affects the Offline follow-up I suggested in my first review. Calling fillPlaneCovariance at those places would need fillPlaneFrame(surf,inter) first. Without it, the result is silently zero.
    • Suggested fix: return with hascov_ false when udir_ is zero. Or keep the surface argument and call fillPlaneFrame inside, as the 085d1998 version did.

Findings from my earlier reviews

  1. 🟡 [S2] The covariance was computed for internal searches too: fixed. Only the public intersect functions fill it, on request and on the final result (Intersect.hh:324-351, :372; ParticleTrajectoryIntersect.hh:20, :50). Internal searches set only the frame, from one tangentPlane call. I did not re-time it.
  2. 🟡 [S2] Offline's hand-built intersections would be stored with pcov_ = 0: fixed on the KinKal side. The Intersection.hh:25-26 comment now says the covariance is filled only on request, and hascov_ records whether it was. With the default off, Offline's own intersections and those from KinKal::intersect now agree: none carries a covariance unless Offline asks. If Offline wants it, see new finding 1.
  3. ⚪ [S3] Test details in IntersectionCovariance_unit.cc: half fixed.
    • The KinematicLine errors still look swapped (:174).
    • The check against planeCovariance (:83-93) can now fail. It compares the plane built from inter.norm_/udir_ with surf.tangentPlane, two separate constructions.
  4. ⚪ [S3] The t0 comment (LoopHelix.cc:139, CentralHelix.cc:170, KinematicLine.cc:138) and the 1.0e-10 cut written four times (Intersect.hh:39 and the three planeCovariance functions): open.

Checked, no action needed

  • 🟢 The default path is unchanged apart from the covariance.
    • The new check in IntersectionCovariance_unit.cc:61-66 requires pcov=false to give the same flags, time and U and V directions as pcov=true, with hascov_ false and pcov_ zero. It runs for all eight surface and trajectory cases.
    • ParticleTrajectoryTest.hh:274-287 checks that the piecewise version fills nothing unless asked. When asked, it must match planeCovariance on the piece at the crossing.
  • 🟢 Source compatible for Offline. The new argument is last and has a default. fillPlaneCovariance is new in this PR, so no Offline code calls it yet; Offline main 0f6b4ad0 has no use of it or of hascov_.
  • 🟢 Persistence. Offline writes KinKal::IntersectFlag with no ClassVersion (RecoDataProducts/src/classes_def.xml:224). The new hascov_ member is versioned by checksum, the same way as the members my first review tested by reading files back. I did not repeat that read-back test for this layout.

Validation check

  • Build/tests run: no local build for this commit. GitHub Actions passed all four Tests jobs at 862cc6f7, finishing 07:08:02Z to 07:13:31Z (read 2026-11-21T08:56Z). I read the diff and the head files through the GitHub API.
  • Sourced numbers: none in the diff.
  • Cross-repo consistency: no Offline change needed to build. Offline wants a change only if it chooses to fill the covariance (new finding 1).

Residual risk

  • Not measured at this head: intersection timing, and reading old and new IntersectFlag layouts back.

Author follow-ups

  1. Guard fillPlaneCovariance against an unset frame, or restore its surface argument (new finding 1).
  2. Optional: the test errors and comments in earlier findings 3 and 4.
  3. As before, "Fixes #237, fixes #238" in the body would close both issues on merge.

…surface bounds to the Intersection payload. Allow out-of-bounds cylinder and frustrum intersections. Ensure hand-built intersections produce the same plane intersections. Code by Claude.

@oksuzian oksuzian left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary — #239

Reviewed at head d426035c5380ed16e9f7e5202c1e9862e4fe92b5. Re-review of 862cc6f7.

Decision

  • 🔴 request changes. Both Debug jobs in GitHub Actions fail at this head. The new IntersectionBounds test runs past ctest's 250 s limit on macOS and on Ubuntu. The test is correct and passes when it has time: 622 s in my Debug build. A looser toy tolerance fixes it. At 1e-4 mm it passes in 7.7 s in Release.
  • The second S1 does not block merging KinKal. intersect now returns out-of-bounds crossings for finite cylinder and frustum searches that find no in-bounds crossing. Offline's KKShellXing takes any on-surface, in-range crossing as the new material crossing. In a reproduction with Mu2e-like tracks, this switches the material off where 862cc6f7 returned nothing and Offline went on to search the next piece. I could not measure how often this happens in Mu2e reconstruction. Offline needs a small change before it takes this tag.
  • The rest checks out. The hand-built intersection problem from my last review is fixed and tested. The in-bounds fraction is computed correctly, and its test fails when the integral is broken. Old and new files read back.

Scope understood

  • fillPlaneCovariance(ktraj,surf,inter,tol) now rebuilds the normal and the U and V directions from surf.tangentPlane(inter.pos_) (Geometry/Intersect.hh:126-129). It then fills inbfrac_, the fraction of the projected Gaussian that falls inside the surface bounds (:135).
  • The cylinder and frustum searches now share hbIntersect (:275-306). If the search restricted to the surface's length finds no in-bounds crossing, it returns the first crossing over the whole range (:305), usually out of bounds. Before, it returned nothing.
  • gap_ moves from Intersection to IntersectFlag, and Intersection gains inbfrac_.
  • A new test, IntersectionBounds, compares inbfrac_ with a toy MC and with exact results for 60 surface and trajectory cases.

Findings

  1. 🟠 [S1] (new) Both Debug CI jobs fail. The new IntersectionBounds test runs past the 250 s ctest limit.
    • Evidence: run 44937146321. macOS Debug: 29/32 Test #29: IntersectionBounds ...............***Timeout 250.02 sec. Ubuntu Debug: the same line at 250.10 sec. All 31 other tests pass in both jobs. The limit is Tests/CMakeLists.txt:59. In Release the test takes 50.50 s (macOS) and 67.33 s (Ubuntu). The next slowest intersection test takes 5.93 to 8.06 s.
    • Not flaky, and caused by this commit. The test is new, and all four jobs passed at 862cc6f7 (run 44878594310). Locally the Debug ctest times out the same way at 250.10 s. Run alone with no limit, the Debug test takes 622 s and passes. Release passes with the default seed and with seeds 1 to 5.
    • Cause: the toy loop. With --ntoy 0 the test runs in 0.12 s. The default is 20,000 toys for each of 60 cases (:204), so 1.2 million intersect calls at tol = 1.0e-6 mm (:45). That tolerance limits the helix step to about 0.04 mm, so each toy call takes about 56 µs.
    • Suggested fix: use a looser tolerance for the toy intersections. I tried only changing :45. At 1e-4 mm the test passes in 7.7 s in Release, and at 1e-3 mm in 3.4 s. The projected errors in the test are 0.38 to 1.16 mm, so this does not change what the test measures. Raising the timeout would also work, but every Debug run would then spend about 10 minutes on this test.
  2. 🟠 [S1] (new) Out-of-bounds cylinder crossings now reach an Offline caller that adopts them: KKShellXing::updateReference.
    • Evidence (Offline main 0f6b4ad0): when a crossing's piece changes, Mu2eKinKal/inc/KKShellXing.hh:88 searches the whole piece. :91 and :97 accept the result on onsurface_ && inrange_ with no inbounds_ check. Only when nothing is found does :93 search ±1 ns over the full trajectory, which returns only good() crossings when the window spans more than one piece (ParticleTrajectoryIntersect.hh:48). updateState then needs good() (KKShellXing.hh:107). So an adopted out-of-bounds crossing switches the material off, and later searches start from that crossing's time.

    • When it is reached: the drift fit sets AddCaloMaterial : true (Mu2eKinKal/fcl/prolog.fcl:505). That puts the calorimeter inner-support cylinder crossings into the fit (KKFit.hh:457-477), and every refit re-references them (KinKal Fit/Track.hh:402, :637). An active material crossing starts a new piece at its own time (KinKal Fit/Material.hh:75-90). So it sits on a piece boundary, which is the case the comment at KKShellXing.hh:89-90 describes. IPA crossings come from the drift-fit extrapolation with MaxDtStep : 1.0 ns (prolog.fcl:385). Pieces that short are not affected (below).

    • Reproduction: I ran the :88 search on the piece just after or just before an in-bounds crossing, with the crossing 0.02 ns outside the piece. The tracks are conversion-electron-like (95 to 105 MeV, cos θ 0.45 to 0.70, starting in the target region, 1 T along z, t0 = 500 ns).

      surface (searches) piece adopted at 862cc6f7 adopted here
      IPA, r 300 mm, z −3270 to −2270 (13,780) 1 or 2 ns 0 0
      5 ns 37 (0.27%) 5,273 (38.3%)
      10 ns 38 (0.28%) 5,382 (39.1%)
      ring-like, r 350 mm, 200 mm long (2,084) 1 or 2 ns 0 0
      5 or 10 ns 0 1,462 (70.2%)

      In those cases 862cc6f7 returns nothing, so KKShellXing goes on to search the neighbouring piece. The IPA geometry is from GeometryService/src/KinKalGeomMaker.cc:372. The ring stands in for the calorimeter inner support; I did not take its exact size from the geometry.

    • Impact: for an affected track, the energy loss in the calorimeter inner-support ring is dropped from the fit. I did not measure how long the fit pieces are near the calorimeter, so I do not know how often this happens. Merging KinKal does not change Offline until Offline takes the new tag.

    • Suggested fix: either keep the old empty result unless the caller asks for out-of-bounds crossings, or ask that Offline check inbounds_ at KKShellXing.hh:91, :94 and :97 before it takes this tag. A short-range search could already return out-of-bounds crossings before this commit, so the Offline check is worth adding either way.

  3. ⚪ [S3] (new; the code is older) Intersect.hh:291-292 uses an end-disk crossing time without checking onsurface_. A failed search leaves time_ at 0, which passes trange.inRange whenever the query spans t = 0. For one helix, 862cc6f7 returns an out-of-bounds crossing (t 1.190 ns, z −3878 mm) for the query [−0.05, 4.95] ns, but nothing once the same helix is shifted to t0 = 500 ns. Mu2e times are far from 0, but KinKal's unit tests use ranges around 0. Checking frontinter.onsurface_ and backinter.onsurface_ there fixes it.

Findings from my earlier reviews

  1. 🟢 [was S2] A hand-built Intersection (U direction zero, as in Offline's ExtrapolateSweep.hh:273-283 and :406-412) got pcov_ = 0 with hascov_ true: fixed in d426035c, verified. fillPlaneCovariance now takes the frame from the surface (Intersect.hh:126-129). IntersectionBounds_unit.cc:61-77 builds an intersection from position, time and flags only. It requires the same normal, U and V directions, pcov_ and inbfrac_ as intersect(...,pcov=true) to 1e-9, in all 60 cases. The signature now takes the surface and tolerance. Nothing in Offline calls it yet.
  2. ⚪ [S3] KinematicLine errors in IntersectionCovariance_unit.cc: still open, carried over. :174 still gives {0.1,0.1,0.0005,0.0005,0.005,0.05}. The new test has the right order for d0, phi0, z0, theta, t0, mom (IntersectionBounds_unit.cc:230).
  3. ⚪ [S3] The t0 comment and the 1.0e-10 cut: still open, carried over. The comment is at LoopHelix.cc:139, CentralHelix.cc:170 and KinematicLine.cc:138. The cut is at Intersect.hh:131, LoopHelix.cc:143, CentralHelix.cc:174 and KinematicLine.cc:142.
  • My first two findings stay fixed. The covariance is filled only on request (Intersect.hh:386-411, :433; ParticleTrajectoryIntersect.hh:50).

Checked, no action needed

  • 🟢 What changes in intersect. I ran my #235 cases with brute-force truth at 862cc6f7 and at this head. 862cc6f7 gives the same results as bae8ab3 on all 94,383. Here 792 change, all on bounded cylinders and frustums (26,643 cases). Planes (39,657) and long cylinders (28,083) do not change.
    • 695 return an out-of-bounds crossing where 862cc6f7 returned nothing. In 692 of them it is the first crossing that brute-force stepping finds. In 8 of the 695 the truth also has an in-bounds crossing, which both versions miss.
    • 74 return a different out-of-bounds crossing. In 44 it is an earlier crossing, 130 to 3,316 mm earlier along the path. In 30 it is the same crossing, moved by less than the tolerance.
    • 11 now find an in-bounds crossing that 862cc6f7 missed, each matching the truth. 5 find one just past the end of the query, flagged inrange_ false.
    • 7 frustum results move by 1.5e-9 to 6.6e-7 mm. The frustum end-disk searches now use tdir.
    • No in-bounds result that 862cc6f7 returned is lost or replaced.
  • 🟢 The other Offline callers are safe. CaloMaterialLayers.hh:60, :66, :75, KKFit.hh:449 and KKExtrap.hh:107 require good(). ExtrapolateSweep.hh:430 checks inbounds_ itself and steps past out-of-bounds roots (at most 256 per target, piece and window, :148). Sampling with KKFit.hh:1056 requires inbounds_ by default (prolog.fcl:38). The cosmic fits set SampleInBounds : false (prolog.fcl:454, :471) and accept out-of-bounds samples by design. KinematicLine searches do not change. EventNtuple main a8e216fb has no intersect calls.
  • 🟢 The inbfrac_ integral is right. The Cholesky factor, the whitened rays and the radial mass exp(−r1²/2) − exp(−r2²/2) integrated over angle and divided by 2π give the probability inside the bounds.
    • I compared boundsFraction with a direct 2D Monte Carlo of 2 million points in the tangent plane. Corners with correlation 0.9 and −0.95, a four-edge rectangle, an annulus hole and a cylinder end agree within 0.0015. A strip 0.1σ wide gives 0.0274 against 0.0351, which is the limit the comment at Intersect.hh:47-48 states.
    • It is computed only when the covariance is requested. One call costs 18 to 141 µs, against about 3 µs for a cylinder intersect.
  • 🟢 The new test catches a wrong integral. It fails if the toy (:100) or the exact result (:104) disagrees. I broke the integral twice. Dropping the U-V correlation fails 8 of the 60 cases, the corner cases among them. Using the wrong Gaussian width fails 45.
  • 🟢 The default path costs a little more on bounded surfaces. Median ns per call without the covariance, three alternating rounds on one pinned core, -O3: planes 1,331 to 1,417 at 862cc6f7 and 1,332 to 1,440 here. Finite cylinders 2,920 to 2,938 and 3,350 to 3,367 (+15%). Frustums 3,046 to 3,061 and 3,246 to 3,268 (+7%). All cylinders together +4%. The extra time is the second, full-range search when no in-bounds crossing is found.
  • 🟢 Old and new files read back. Offline writes KinKal::IntersectFlag and KinKal::Intersection with no ClassVersion (RecoDataProducts/src/classes_def.xml:224-225). I built genreflex dictionaries with that selection from the 3a6860b headers and from this head. Files written with either layout read with the other, split and unsplit, with no warnings. New code reads gap_ correctly from old files. Old code reading new files gets gap_ false. Nothing in KinKal or Offline sets gap_ today, but EventNtuple copies it into the ntuple (InfoStructHelper.cc:138). IntersectFlag::operator== does not compare gap_.

Validation check

  • Build/tests run: yes. KinKal standalone, CMake, Mu2e envset p111 (GCC 13.3, ROOT 6.38), built with no warnings.
    • Release at this head: ctest 32 of 32 pass, IntersectionBounds 67.33 s.
    • Release at 862cc6f7: 31 of 31 pass.
    • Debug at this head: 31 of 32 pass, and IntersectionBounds times out at 250.10 s. Run alone it passes in 622 s.
  • CI: GitHub Actions run 44937146321 at this head, read at 19:22Z. Release passes on macOS and Ubuntu. Debug fails on both (finding 1), finishing at 18:53:20Z and 18:55:19Z.
  • Sourced numbers: none in the diff.
  • Cross-repo consistency: Offline builds unchanged. Offline needs a follow-up before it takes this tag (finding 2).

Residual risk

  • Not run: an Offline build and a Mu2e reconstruction job against this KinKal. Intersection and IntersectFlag change layout, so that needs a full Offline rebuild. Without it I do not know how often finding 2 happens, or how many Mu2e intersections change.
  • The reproduction for finding 2 uses Mu2e-like tracks and surfaces, not Mu2e fit trajectories.

Author follow-ups

  1. Make IntersectionBounds fit the Debug time limit, for example with a looser toy tolerance (finding 1).
  2. Decide whether out-of-bounds results should need an opt-in, or ask Offline to check inbounds_ in KKShellXing::updateReference before it takes this tag (finding 2).
  3. Optional: check onsurface_ on the end-disk searches (finding 3), and the test and comment items carried over.
  4. As before, "Fixes #237, fixes #238" in the body would close both issues on merge.

@oksuzian oksuzian left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary — #239

Reviewed at head cb8107dc3571abe8edc2cf06d142c87a0dff2f45. Re-review of d426035c.

Decision

  • 🟡 comment. Dave, thanks for "Small fixes". The Debug CI timeout is fixed, and so are the three small items. All four CI jobs pass at this head.
  • One item from my last review is still open, and I can now measure it. Out-of-bounds cylinder crossings still reach Offline's KKShellXing. In 2,000 Mu2e reconstruction events, this PR drops the calorimeter disk-1 inner-ring material from 5 tracks. Two simple Offline patches did not fix it. Merging KinKal alone changes nothing in Offline, so I would not hold the merge. But Offline should not take a tag with this PR until this is fixed, here or in Offline (finding 1). Offline#2204 does not change it.
  • The new early return in Material::extrapolate is safe. It changes nothing in Offline main: d426035c and this head give identical reconstruction output. Offline#2204 depends on it.
  • Merge order: KinKal#239, then a KinKal tag and an envset that carries it, then Offline#2204. Finding 1 needs a fix before that tag reaches Offline.

Scope understood

  • The increment since d426035c is one commit, "Small fixes", 9 files.
  • Material::extrapolate returns early for an inactive crossing (Fit/Material.hh:106-108). It no longer splits the trajectory for a crossing that has no material effect.
  • The toy tolerance in IntersectionBounds goes from 1e-6 mm to 1e-3 mm (Tests/IntersectionBounds_unit.cc:45).
  • The end-disk searches now check onsurface_ (Geometry/Intersect.hh:293-294).
  • The 1.0e-10 cut becomes a dirtol argument. fillPlaneCovariance keeps 1e-10 as its default (Intersect.hh:122). planeCovariance(time,plane,dirtol) has no default in all three trajectories (LoopHelix.hh:84, CentralHelix.hh:78, KinematicLine.hh:78).
  • The KinematicLine errors in IntersectionCovariance_unit.cc:174 now follow the parameter order, and the t0 comments are fixed.

Findings

  1. 🟠 [S1] (carried over, now measured) Out-of-bounds cylinder crossings reach KKShellXing::updateReference, and Mu2e reconstruction loses calorimeter material. Still open.
    • Code, Offline main 0f6b4ad0: when a material crossing's piece changes, Mu2eKinKal/inc/KKShellXing.hh:88 searches the new piece. :91 and :97 accept the result on onsurface_ && inrange_, with no inbounds_ check. updateState then needs good() (:107), so the material is switched off. Offline#2204 keeps this logic (KKShellXing.hh:93, :96, :99 at 49929928).

    • Toy reproduction, rerun at this head: the same numbers as at d426035c. With 5 ns pieces, 26,252 of 68,884 IPA searches (38.1%) adopt an out-of-bounds crossing. With 1 ns pieces, none do. Output: res/shellrepro3_cb8107dc.txt.

    • In Mu2e reconstruction: I built Offline main 0f6b4ad0 against KinKal 3a6860b (this PR's base) and against this head, and ran the production recoMC/OnSpill.fcl on 2,000 CeMLeadingLogMix1BB events with SaveMaterialXings : true. All 7,822 fitted tracks have the same status, active hits, chi2, t0 and momentum at the first segment. 6 calorimeter crossings in 5 tracks change from in bounds to out of bounds, and their energy loss goes to zero:

      event fit crossing dP at base momentum at EMC_Disk_1_Back, base to this head
      348 KKDe EMC_Disk_1_InnerRing 4 −9.31 MeV/c 79.06 to 88.32 MeV/c
      2475 KKDe EMC_Disk_1_InnerRing 2 −1.53 MeV/c 85.16 to 86.68 MeV/c
      3979 KKDe EMC_Disk_1_InnerRing 1 and 2 −9.30 and −1.23 MeV/c 86.93 to 97.42 MeV/c
      3998 KKDmu EMC_Disk_1_InnerRing 2 −4.25 MeV/c 81.87 to 86.08 MeV/c
      4742 KKDe EMC_Disk_1_InnerRing 1 −3.98 MeV/c 94.37 to 98.33 MeV/c

      That is 4 of 1,991 KKDe tracks and 1 of 1,955 KKDmu tracks. No KKUe or KKUmu track changes. Run 1430, subrun 1612. Outputs: jobs/out/onspill.{base,cb8}_mx.0/ks_dump.txt.

    • Impact: the fit is unchanged, because the ring sits after the last tracker hit. What changes is the track beyond the ring: the momentum at the calorimeter disk-1 surfaces, by 1.5 to 10.5 MeV/c in these 5 tracks. Anything that uses the extrapolated state at disk 1 sees this.

    • Where it happens: these crossings are made only when good() (CaloMaterialLayers.hh:60, :66, :75), and KKShellXing::updateReference is the only place that moves them. So the change comes from what intersect returns there during a refit.

    • I tried two local Offline patches to updateReference, and neither is a fix:

      • Never replace an in-bounds crossing with an out-of-bounds one. This keeps stale crossings. Compared with the base, all 108 calorimeter material crossings that are out of bounds in the base stay in bounds, and 30 fits change (chi2 up to 39 different).
      • When the piece search returns an out-of-bounds crossing for an in-bounds one, also search ±1 ns over the full trajectory and prefer an in-bounds result. All fits match the base. But the same 5 tracks still lose the ring, and 4 other tracks gain a ring crossing the base had out of bounds.
        So the in-bounds crossing is not found within ±1 ns either. I did not trace these 5 events further. Patches: w_main_cb8/kkshell_test_patch1.diff and kkshell_test_patch.diff; outputs jobs/out/onspill.fix1_mx.0 and onspill.fix_mx.0.
    • Options: make the out-of-bounds fallback in hbIntersect opt-in, as I suggested last time. Or find, with these 5 events, what Offline should do instead. I would not hold this PR, because merging KinKal alone changes nothing in Offline. But please do not let Offline take a tag with it until this is understood.

Findings from my earlier reviews

  1. 🟢 [was S1] Debug CI timeout in IntersectionBounds: fixed in cb8107dc, verified. The toy tolerance is now 1e-3 mm (IntersectionBounds_unit.cc:45). CI run 44956448456 at this head: the test passes in 24.58 s (macOS Debug), 24.85 s (Ubuntu Debug), 2.70 s (macOS Release) and 3.48 s (Ubuntu Release). 32 of 32 tests pass in all four jobs. Locally, Debug takes 46.30 s and Release 3.48 s, 32 of 32 pass, and both builds have no warnings. The test still catches a broken integral at the new tolerance. Dropping the U-V correlation fails 8 of 60 cases, and using the wrong Gaussian width fails 45, as before.
  2. 🟠 [was S1] Out-of-bounds crossings adopted by KKShellXing: still open. See finding 1.
    • With KinKal#239 and Offline#2204 together: Offline#2204 changes only the search arguments in updateReference, so the adoption is the same. The near-miss crossings Offline#2204 adds are inactive by design, so for them adopting an out-of-bounds crossing is fine. The problem is the in-bounds crossings.
    • With KinKal#239 and without Offline#2204: Offline main builds and runs against this head (no warnings). The only reconstruction change I found is finding 1. The early return in Material.hh has no effect there (below).
  3. 🟢 [was S3] End-disk crossing times without onsurface_: fixed in cb8107dc. Intersect.hh:293-294 now require frontinter.onsurface_ and backinter.onsurface_. My t=0 test helix gives the same result at both heads, because the full-range fallback returns the same crossing. So this is checked by reading the code, not by a failing case.
  4. 🟢 [was S3] KinematicLine errors in IntersectionCovariance_unit.cc: fixed in cb8107dc. :174 now reads {0.1,0.002,0.1,0.002,0.005,0.05}, in the order d0, phi0, z0, theta, t0, mom of KinematicLine.hh:23-30.
  5. 🟢 [was S3] The t0 comment and the 1.0e-10 cut: fixed in cb8107dc. The comments at LoopHelix.cc:139, CentralHelix.cc:170 and KinematicLine.cc:138 now say that errors along the direction drop out. The literal is the dirtol argument.

Checked, no action needed

  • 🟢 The Material::extrapolate early return (Fit/Material.hh:106-108).
    • Which Mu2e crossings can be inactive: in Offline main, none that reach extrapolate. KKExtrap::addCrossing builds a KKShellXing only for crossings the sweep accepted in bounds, and the constructor makes the material when inter.good() (KKShellXing.hh:75). Calorimeter crossings added by AddCaloMaterial go through the fit, not extrapolate. process and append already skipped inactive crossings (Material.hh:57, :76). With Offline#2204, the near misses are inactive on purpose, and this return stops them splitting the trajectory.
    • Measured: Offline main against d426035c and against this head, same 2,000 OnSpill events. All 9 KalSeed collections are identical, every track and every intersection. The same holds for 10,000 CosmicCRYExtracted events (6,730 KKLine tracks) and their TrkCrvMatch output. Base 3a6860b against this head is also identical there.
    • Offline#2204's ExtrapolateSweepTest checks that a near-miss material does not split the trajectory (ExtrapolateSweepTest_main.cc, "inactive material split the trajectory"). That check needs this commit, so Offline#2204 needs a tag at cb8107dc or later, not d426035c. I read this from the code; I did not build Offline#2204 against d426035c.
  • 🟢 planeCovariance has no default dirtol. Nothing outside KinKal is broken. Offline main 0f6b4ad0 has no call to planeCovariance or fillPlaneCovariance, and EventNtuple a8e216fb has none. Offline#2204 passes dirtol at every call (CRVReco/inc/TrkCrvGeom.hh:44, Mu2eKinKal/inc/ExtrapolateSweep.hh:353, :358) and uses the default only through fillPlaneCovariance (:507).

Validation check

  • Build/tests run: yes. KinKal standalone with CMake on the Mu2e p111 environment, Release and Debug, no warnings, ctest 32 of 32 (above).
  • Offline main 0f6b4ad0 with muse, against KinKal 3a6860b, d426035c and this head: all three build with no warnings.
  • Jobs: production recoMC/OnSpill.fcl on 2,000 events of dig.mu2e.CeMLeadingLogMix1BB.MDC2025au_best_v1_3.001430_00001612.art, and recoMC/Extracted.fcl plus TrkCrvMatcher on 10,000 events of dig.mu2e.CosmicCRYExtracted.MDC2025bb_best_v1_5.001400_00017143.art. Both read in place from dCache. All jobs exit 0 with no exceptions. CPU per event is the same within 0.2% across the three KinKal versions (0.1758 to 0.1761 s, TimeTracker).
  • CI: GitHub Actions at this head, read at 2026-11-21 23:24Z. All four jobs pass: Release Ubuntu 22:26:28Z, Release macOS 22:26:41Z, Debug Ubuntu 22:29:56Z, Debug macOS 22:31:21Z.
  • Sourced numbers: none in the diff.
  • Cross-repo consistency: finding 1 needs a fix before Offline takes the tag. Offline#2204 needs this head or later.
  • Paths in this review are under /exp/mu2e/data/users/oksuzian/claude-scratch/kinkal239_offline2204_review/.

Residual risk

  • I ran one OnSpill file (2,000 events) and one extracted cosmic file (10,000 events). Finding 1 shows up at about 0.2% of downstream electron tracks in that sample. Other samples (other momenta, upstream tracks, cosmics through the calorimeter) may differ.
  • I did not run Offline's validation suite or valCompare.

Author follow-ups

  1. Before Offline takes a tag with this PR, fix finding 1: either make the out-of-bounds fallback opt-in, or find the right Offline change with the 5 events listed. Run 1430, subrun 1612 of the file named under Validation check.
  2. As before, "Fixes #237, fixes #238" in the PR body would close both issues on merge.

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