Skip to content

Fix the KalTrack isolation shared hits sort (and downstream effects on MC hit matching etc) - #1179

Merged
bloodyyugo merged 2 commits into
masterfrom
fix/kaltrack-isolation-shared-hits-sort
Aug 14, 2026
Merged

Fix the KalTrack isolation shared hits sort (and downstream effects on MC hit matching etc)#1179
bloodyyugo merged 2 commits into
masterfrom
fix/kaltrack-isolation-shared-hits-sort

Conversation

@bloodyyugo

Copy link
Copy Markdown
Contributor

This PR fixes the issue of misidentifying reco tracks from made up of SimTrackerHit-matched hits as unmatched to an MCParticle.

The issue in the code was from this snippet in KalTrack (hat-tip to Lauren for finding this):

// KalTrack.java:533-546
List allHits = sensor.hits; // NOT a copy
if (allHits.size() > 1 && ms.hitID > -1) {
Measurement hitOnTrack = allHits.get(ms.hitID); // read pre-sort: OK
...
Collections.sort(allHits, Measurement.MeasurementComparatorUp); // :546 mutates SiModule.hits
int isoID = ms.hitID + awayFromBeam*nSteps; // :550 stale index into the new order

... in words, the measurement list in the first line just points to the list on the SiModule and the sort then changes the order of these hits. After this, the ms.hitID is basically meaningless.

This bug effected a few collections after this snippet gets first run in KalmanPatRecDriver.java:
KFTrackData isolations
KFGBLStripClusterData (potentially used for using KF in alignment)
KFUnbiasRes

sensor.hits is shared by every track with a hit on that SiModule, and
ms.hitID indexes into it as populated at pattern recognition time.
Sorting it in place corrupted that ordering for every other track
sharing the sensor and made the subsequent ms.hitID lookup stale.
Sort a private copy instead and locate the hit on track by identity
in the sorted copy.

Also add Preselection2021.java, an LCSim driver for truth-based
electron/positron track and V0 preselection with per-layer isolation
diagnostics (including an exact iso==0 counter used to confirm the
residual zero-isolation entries in the innermost SiStriplet layers
are genuine, not an artifact of the sorting bug above).
@bloodyyugo
bloodyyugo requested review from EBerzin and mgignac August 14, 2026 21:35
@bloodyyugo

Copy link
Copy Markdown
Contributor Author

I also added Preselection2021 (a mockup of the hpstr preselection in hps-java) which I was using to debug the truth.

@bloodyyugo

Copy link
Copy Markdown
Contributor Author

Here are some plots proving this works...

The track purity for the electron in the V0 (can be from recoil):
image

...and for positron:
image

The V0 reco electron p vs. truth p from A' electron before bug-fix:
Screenshot 2026-08-14 at 3 48 35 PM

...and after:
Screenshot 2026-08-14 at 3 47 53 PM

Layer 0 isolation values (pre-bugfix peak at 0 is from code picking same hit as hit on track):
image

@bloodyyugo
bloodyyugo merged commit d8673a3 into master Aug 14, 2026
2 checks passed
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.

3 participants