Repository navigation
Truncate trajectory for ranged-out particles. - #234
Merged
Merged
Conversation
This was referenced Nov 6, 2026
oksuzian
approved these changes
Nov 6, 2026
oksuzian
left a comment
There was a problem hiding this comment.
PR Review Summary — #234
Reviewed at head 61bd31663ab6746c32bcf615badc9661a085cf54. First pass.
Decision
- 🟢 approve.
Track::truncatedoes what the description says, and it changes nothing when it refuses. I read it line by line againstTrack,Domain,DomainWallandPiecewiseTrajectory, and ran it through Mu2e/Offline#2111 on 9,314 off-spill cosmics in two settings and 16,508 nightlyreco_03events: 455 of 465 cuts were made, and every output change is the intended one. One finding: the guard also refuses a cut for material sites that the fit never processed. In Mu2e this blocks 10 of the 465 cuts, including one of the tracks the cut is meant for (finding 1). It does not block.
Scope understood
- A public
bool Track::truncate(TimeDir tdir, double time)(Fit/Track.hh:1084-1122). It ends the fit trajectory attime, removes the domains beyond it with theDomainWalls into them, and trims the domain that containstimewith the newDomain::setEdge(Fit/Domain.hh:27). It returns false, changing nothing, unless the fit is usable,timeis finite and strictly inside the trajectory, no active non-wall effect lies at or beyondtime, and at least one domain remains. - A new
Tests/Truncate_unit.cc. The change is header-only, with no class layout change.
Findings
- 🟡 [S2] The guard counts active material sites that the fit never processed, so it refuses cuts that would remove nothing the fit used.
- Evidence:
Track.hh:1094refuses whenever any active effect other than aDomainWalllies at or beyond the cut. WithConfig::ends_false,iterateprocesses only the effects between the first and last active measurement (setBounds,Track.hh:735-760).processEndsruns only whenends_is set (:554). So an active material site after the last active measurement creates no trajectory piece.- In Mu2e (Offline#2111, off-spill cosmics,
KKCHmuwithProcessEnds: false), 10 of 229 range-out cuts were refused. - A temporary print showed that every refusal came from 1 to 8 active straw-material crossings (
KKStrawXing) after the cut, and from nothing else. In each case the last active hit was 2.1 to 3.9 ns before the cut. - In 9 of the 10, the latest of these crossings lies after the end of the trajectory, by 0.2 to 39 ns.
- The nightly
reco_03sample had 236 cuts and no refusal.
- In Mu2e (Offline#2111, off-spill cosmics,
- Impact: the protection the PR gives inactive hits ("each holds its own reference piece") applies equally to these sites, but they still block the cut. On one Mu2e track (1430:0:24052), 56 ns of trajectory and 12 sampled tracker crossings stay past the stop. The caller gets only
false, so it cannot tell this case apart from a cut that would really remove a piece the fit used. - Suggested fix: skip active sites that the fit did not process. A simple test on the last active measurement is not enough, because material added by
extrapolate(exing,tdir)also lies after it and does own pieces. If that distinction is too much for this PR, record why a cut was refused (ahistory_entry, or a reason the caller can read), so the caller can count it.
- Evidence:
Checked, no action needed
- 🟢 A refusal changes nothing. Every condition is tested before the first change (
:1085-1098). After that point, nothing in the function can fail. - 🟢 Domains and walls.
- Forwards, a wall is removed when its next domain is removed; backwards, when its previous domain is (
:1099-1101). domains_is ordered bybegin()(Track.hh:68). Moving the first domain's begin later keeps it below its own end, and that end is at or below the next domain's begin. So the order the set relies on still holds.
- Forwards, a wall is removed when its next domain is removed; backwards, when its previous domain is (
- 🟢 A cut exactly on a domain boundary. The unit test does not hit this case; I traced it by reading.
- Forwards: the domain that begins at
timeis removed, andouter->end() > timeis false, sosetEdgeis not called. setRange(...,true)(:1107) erases the piece that begins attime, becauseTimeRange::overlapsuses half-open ranges.- Backwards, the
end() <= timeloop (:1113) does the same.
- Forwards: the domain that begins at
- 🟢 Extrapolating again continues from the cut. The outermost domain edge is the cut, so
coverEndDomaindoes nothing. The unit test extrapolates again after each cut. - 🟢 Calling it from inside an
extrapolatepredicate is safe. Each loop inTrack::extrapolateends right after a false predicate, without usingendpieceornearestPieceagain. Mu2e calls it outside the predicate anyway: in the sweep, afterextrapolatereturns. - 🟢 The unit test covers both directions, both fields, refusals and repeated cuts.
- Both directions,
LoopHelixandCentralHelix, with field correction on and off. - Refusals at the last active effect, outside the trajectory and for a NaN cut.
- Two cuts per direction, the second removing several domains, each followed by a re-extrapolation.
- Inactive hits beyond a cut.
- GitHub Actions ran
Truncateat this head in all four configurations (Debug and Release, Ubuntu and macOS): 28 of 28 tests pass. These three files produce no compiler warnings.
- Both directions,
Validation check
- Build/tests run: KinKal standalone build and
ctestnot run; my session blocked running the PR's build. The GitHub Actions logs above stand in. - Mu2e build: Offline#2111 head
18a24eee, with this PR'sFit/Track.hhandFit/Domain.hhplaced over the p110 release headers. Those release headers are byte-identical to gitv3.9.1, this PR's base.muse buildexited with status 0 and no warnings, and all 1168 compile lines used the overlay.ExtrapolateSweepTestpasses.- Off-spill cosmics (9,314 events, two settings) and nightly
reco_03(16,508 events): all jobs exited with status 0. Results are in my Offline#2111 review.
- Config contract check: not applicable.
- Cross-repo consistency: Offline#2111 needs a tag with this PR and an envset carrying it.
Residual risk
- Mu2e only cuts forwards, and only inside the end piece and the last domain:
KKExtrapadds crossings only on the end piece. So the backwards path and the removal of whole domains run only in the unit test. - Not checked:
KinematicLinetrajectories.
Author follow-ups
- Optional: finding 1.
brownd1978
approved these changes
Nov 7, 2026
brownd1978
left a comment
Collaborator
There was a problem hiding this comment.
This looks good. My only qualm is that the domain time trim is unprotected, and could be used in error. But, since that's a non-const function and no non-const accessor exists outside Track itself the space for an error in negligible.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Companion to Mu2e/Offline#2084 (follow-up Offline PR: Mu2e/Offline#2111)
Problem
Track::extrapolateextends the end piece of the fit trajectory in field-domain steps (field correction on) or inmaxDtStepsteps (off), and the predicate is only asked after each step. When the predicate stops at a time inside thelast step (in Mu2e, where the particle ranges out in a material it is about to cross), the trajectory and the
outermost domain already run past it, by up to one domain or step.
Trackhas no way to shorten them again, soeverything downstream of the extrapolation (saved segments, sampled surface crossings, the saved domain bounds) also
continues past the stop.
Change
A public
bool Track::truncate(TimeDir tdir, double time): the fit trajectory ends attimein directiontdir. Thedomains beyond
timeare removed together with theDomainWalls into them, and the domain containingtimeendsthere (new
Domain::setEdge, which moves a domain's end or begin). Nothing changes, and the return value is false,unless the fit is usable,
timeis inside the trajectory, and no active hit or material effect is at or beyondtime,so no piece the fit uses is removed or shortened past it. Inactive hits and crossings beyond
timeare kept: theychange nothing in the fit, and each holds its own reference piece. Forwards, the trajectory is cut with
PiecewiseTrajectory::setRange(range, true); backwards it is rebuilt from the first piece reaching beyondtime, sincesetRangekeeps the last piece before the range at the front. The state at and beforetimeis unchanged, and a laterextrapolatein the same direction continues fromtime(the outermost domain edge istime, socoverEndDomaindoes nothing). It can be called from inside an extrapolation
predicate: each walk in
extrapolateends as soon as the predicate returns false, without using the end piece again.Header-only (
Fit/Track.hh,Fit/Domain.hh); no class layout changes.Test
New
Tests/Truncate_unit.cc(registered with the other unit tests): ToyMC tracks in the uniform 1 T field of theother fit unit tests, LoopHelix and CentralHelix, field correction on and off, 3 fits each. Each fit is extrapolated
20 ns past each end and cut twice in each direction: inside the outermost domain beyond the last active hit or
material, then, after extrapolating again, halfway between that effect and the end, which with field correction
removes several domains. It checks that:
DomainWalls into them are removed, and no wall into a removed domain remains;A second case makes the last 4 hits of a track inactive (with no material after the last active hit): after one long
extrapolation step past them, a cut between the last active effect and the first inactive hit is accepted, every
effect is kept, and each inactive hit beyond the cut keeps a usable reference piece.
cteston v3.9.1 + this change (AL9, e29, Release): 28/28 pass,Truncatewith 3 usable fits in each of its 8 cases.The test uses a uniform field because the ToyMC fits do not converge in a field gradient at v3.9.1, independent of
this change:
LoopHelixFit --nevents 20converges 19/20 fits in the uniform field (both schedule files), 1-5/20 with--Bgrad -0.036and 0/20 with--Bgrad -0.1(GapDiverged/ParamsDiverged), with field correction on or off.Validation in Mu2e
With the follow-up Offline call (
truncate(TimeDir::forwards, stop time)whereKKExtrapfinds the particle rangesout), every range-out stop is truncated: 149 of 149 and 111 of 111 on Mu2e nightly off-spill cosmics (10,000 events,
field correction on and off), 39 of 39 on 3,334 production off-spill events. Every track without a stop is unchanged,
and the ranged-out ones lose only what lay beyond the stop: 9 sampled tracker crossings on one nightly track (none in
truth) and 4 on 10,352 Run 2 cosmics, all with field correction; with it off the ntuples are bit-identical.
🤖 Generated with Claude Code