Skip to content

fix: sort space points before Acts seeding to ensure MT reproducibility - #2804

Open
wdconinc wants to merge 3 commits into
mainfrom
wdconinc-fix-trackseeding-sp-sort-for-mt-reproduc
Open

fix: sort space points before Acts seeding to ensure MT reproducibility#2804
wdconinc wants to merge 3 commits into
mainfrom
wdconinc-fix-trackseeding-sp-sort-for-mt-reproduc

Conversation

@wdconinc

Copy link
Copy Markdown
Contributor

Briefly, what does this PR introduce? Please link to any relevant presentations or discussions.

This introduces a deterministic pre-sort of spacePoints in TrackSeeding::process before constructing the Acts space-point container and calling Acts::SeedFinderOrthogonal.

The sort is std::stable_sort with lexicographic key (r, phi, z, x, y) and a final ObjectID(collectionID, index) tie-breaker for exact coordinate ties. This canonicalizes seeding input order across runs.

Motivation/background:

  • compare-single-multi-threaded investigations showed ~1 ULP ST/MT differences in CentralCKFTracksUnfiltered / CentralCKFTrackParametersUnfiltered due to ordering sensitivity in the seed/track chain.
  • Acts::SeedFinderOrthogonal uses KDTree internals whose split behavior (std::partition) can be input-order sensitive for near-equal coordinates.
  • This is a defense-in-depth layer on top of the SiliconTrackerDigi/MPGDTrackerDigi deterministic ordering fix (wdconinc-fix-digi-determinism, commit cc20d099e).
  • A principled upstream ACTS/KDTree fix is being tracked separately.

What is the urgency of this PR?

  • High (please describe reason below)
  • Medium
  • Low

What kind of change does this PR introduce?

  • Bug fix (issue #__)
  • New feature (issue #__)
  • Optimization (issue #__)
  • Updated parameters, constants (issue #__)
  • Updated documentation
  • other: __

Please check if any of the following apply

  • This PR requires changes to geometry (epic PR: __)
  • This PR requires changes to EDM4eic (EDM PR: __)
  • This PR introduces breaking changes. Please describe changes users need to make below.
  • This PR changes default behavior. Please describe changes below.
  • AI was used in preparing this PR. Please describe usage below.

AI usage: assisted with implementing the deterministic stable sort, preparing commit/PR text, and running targeted local build/configuration checks.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 29, 2026 17:46
@github-actions github-actions Bot added the topic: tracking Relates to tracking reconstruction label Jul 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves multi-thread reproducibility in the tracking seeding chain by deterministically ordering SpacePoint inputs before building the Acts space-point container and running Acts::SeedFinderOrthogonal, reducing sensitivity to input-order-dependent KDTree behavior.

Changes:

  • Added a deterministic std::stable_sort of spacePoints in TrackSeeding::process using a lexicographic coordinate key and an ObjectID tie-breaker.
  • Added the necessary <algorithm> include to support the new sort.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +104 to +114
std::stable_sort(spacePoints.begin(), spacePoints.end(), [](const auto* lhs, const auto* rhs) {
const auto lhsPositionKey = std::tuple{lhs->r(), lhs->phi(), lhs->z(), lhs->x(), lhs->y()};
const auto rhsPositionKey = std::tuple{rhs->r(), rhs->phi(), rhs->z(), rhs->x(), rhs->y()};
if (lhsPositionKey != rhsPositionKey) {
return lhsPositionKey < rhsPositionKey;
}

const auto lhsId = lhs->getObjectID();
const auto rhsId = rhs->getObjectID();
return std::tie(lhsId.collectionID, lhsId.index) < std::tie(rhsId.collectionID, rhsId.index);
});
Comment thread src/algorithms/tracking/TrackSeeding.cc
SpacePoint only exposes x(), y(), z(), r(). Use (r, z, x, y) as the sort key; phi = atan2(y, x) is fully encoded by (x, y) so no sorting information is lost.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 29, 2026 20:01
@wdconinc
wdconinc removed the request for review from Copilot July 29, 2026 20:04

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Clang-Tidy found issue(s) with the introduced code (1/1)

auto [trk_seeds, trk_params] = output;

std::vector<const eicrecon::SpacePoint*> spacePoints = getSpacePoints(*trk_hits);
std::stable_sort(spacePoints.begin(), spacePoints.end(), [](const auto* lhs, const auto* rhs) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ modernize-use-ranges ⚠️
use a ranges version of this algorithm

Suggested change
std::stable_sort(spacePoints.begin(), spacePoints.end(), [](const auto* lhs, const auto* rhs) {
std::ranges::stable_sort(spacePoints,, [](const auto* lhs, const auto* rhs) {

…ty (fix: iwyu) (#2812)

This PR applies the include-what-you-use fixes as suggested by
https://github.com/eic/EICrecon/actions/runs/30486835399.
Please merge this PR into the branch
`wdconinc-fix-trackseeding-sp-sort-for-mt-reproduc`
to resolve failures in PR #2804.

Auto-generated by [create-pull-request][1]

[1]: https://github.com/peter-evans/create-pull-request

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 29, 2026 22:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Labels

topic: tracking Relates to tracking reconstruction

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants