Skip to content

fix: use std::map for deterministic digi raw hit ordering - #2808

Open
wdconinc wants to merge 2 commits into
mainfrom
wdconinc-fix-digi-determinism-map
Open

fix: use std::map for deterministic digi raw hit ordering#2808
wdconinc wants to merge 2 commits into
mainfrom
wdconinc-fix-digi-determinism-map

Conversation

@wdconinc

Copy link
Copy Markdown
Contributor

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

Alternative to #2805: make raw-hit emission deterministic in SiliconTrackerDigi and MPGDTrackerDigi by replacing std::unordered_map with std::map. Because std::map iterates in ascending key order, the output ordering is deterministic with no extra code — only a one-word change at the declaration site.

Comparison with #2805 (explicit sort approach)

Aspect This PR (std::map) #2805 (unordered_map + sort)
Code change 1-word type change; removes #include <unordered_map> Extra vector, populate loop, std::ranges::sort
Accumulation cost O(log M) per insert/lookup O(1) average per insert/lookup
Sort cost None — order is intrinsic O(M log M) separate pass
Overall (N hits, M unique cells) O(N log M) O(N) + O(M log M)
Readability Intent expressed in type Intent expressed in separate algorithm
Correctness risk Lower — no extra loop, no index math Slightly higher surface area

In practice M ≤ N and for typical tracking events M ≈ N (few cells merge), so the complexities are equivalent. The std::map approach is favoured here because:

The only scenario where unordered_map + explicit sort would be strictly faster is when M ≪ N (heavy merging), because accumulation stays O(1) and you pay only O(M log M) at the very end. That is not the typical case for digitization, but if profiling ever shows it matters, the other approach is available.

Both PRs also fix the pre-existing bug where links/associations referenced the temporary map value instead of the persisted RawTrackerHit object in the output collection.

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 was used to inspect the two digi algorithms, implement the minimal std::map alternative fix, and draft this PR description including the comparative tradeoff table.

Replace unordered_map with map in SiliconTrackerDigi and MPGDTrackerDigi.
std::map iterates in ascending key order, making output ordering
deterministic without a separate sort step or intermediate vector.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 29, 2026 18:29

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 digitization stage by making RawTrackerHit emission order deterministic in SiliconTrackerDigi and MPGDTrackerDigi, and by ensuring links/associations reference the persisted RawTrackerHit objects in the output collections.

Changes:

  • Replace std::unordered_map with std::map for per-cell hit aggregation to guarantee deterministic iteration order by cellID.
  • Update emission loops to bind to the persisted raw_hit from the output collection when creating links/associations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/algorithms/digi/SiliconTrackerDigi.cc Switch hit aggregation to std::map and ensure links/associations reference the persisted RawTrackerHit objects.
src/algorithms/digi/MPGDTrackerDigi.cc Switch hit aggregation to std::map for deterministic emission order and ensure links/associations reference the persisted RawTrackerHit objects.

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

Comment thread src/algorithms/digi/SiliconTrackerDigi.cc
…#2811)

This PR applies the include-what-you-use fixes as suggested by
https://github.com/eic/EICrecon/actions/runs/30480148342.
Please merge this PR into the branch `wdconinc-fix-digi-determinism-map`
to resolve failures in PR #2808.

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 19:24

This comment was marked as duplicate.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants