Fix to stabilize fast calo hit sorting#1750
Conversation
|
Hi @bechenard,
which require these tests: build. @Mu2e/fnalbuild-users, @Mu2e/write have access to CI actions on main. ⌛ The following tests have been triggered for 4756208: build (Build queue - API unavailable) |
|
☀️ The build tests passed at 4756208.
N.B. These results were obtained from a build of this Pull Request at 4756208 after being merged into the base branch at aa12407. For more information, please check the job page here. |
|
I'll review this pull request by first loading the relevant ability and then examining the PR details and code changes.Let me also look at the full file for more context around the changed code:## Review of PR #1750: Fix to stabilize fast calo hit sorting Author: @bechenard | Branch: Change SummaryThis PR modifies a single file — The Diff// BEFORE:
auto functorTime = [&caloHits,&hits](auto a, auto b) {return caloHits[a].time() < caloHits[b].time();};
// AFTER:
auto functorTime = [&caloHits,&hits](auto a, auto b) {return caloHits[a].time() < caloHits[b].time() ||
(fabs(caloHits[a].time() - caloHits[b].time())<1e-3 &&
caloHits[a].crystalID() <caloHits[b].crystalID());};PurposeThe original comparator sorted hits by Issues Found🔴 1. Comparator violates strict weak ordering — critical correctness bugThis is the most important issue. The comparator used with Consider two hits
The comparator evaluates:
So it's possible that both Root cause: The first condition ( Suggested fix: The comparator should use a consistent "equivalence bucket" approach. For example: auto functorTime = [&caloHits](auto a, auto b) {
double dt = caloHits[a].time() - caloHits[b].time();
if (fabs(dt) < 1e-3) {
return caloHits[a].crystalID() < caloHits[b].crystalID();
}
return dt < 0; // i.e., caloHits[a].time() < caloHits[b].time()
};
🟡 2.
|
| Severity | Issue | Description |
|---|---|---|
| 🔴 Critical | Strict weak ordering violation | Comparator can return true for both (a,b) and (b,a) — undefined behavior with std::stable_sort |
| 🟡 Minor | Unused capture &hits |
Lambda captures hits but doesn't use it |
| 🟡 Minor | fabs without explicit include |
Relies on transitive <cmath> inclusion |
| ⚪ Nit | Missing space | crystalID() <caloHits formatting |
The critical issue (#1) should be resolved before merging. The fuzzy time tolerance combined with the strict less-than on time creates contradictory orderings that violate std::stable_sort's contract.
|
📝 The HEAD of |
|
@FNALbuild run build test |
|
⌛ The following tests have been triggered for 863a01d: build (Build queue - API unavailable) |
|
☀️ The build tests passed at 863a01d.
N.B. These results were obtained from a build of this Pull Request at 863a01d after being merged into the base branch at 9ffc000. For more information, please check the job page here. |
Addresses issue 1086