From df773a9fba63e4026d64411da96e70817873b316 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Apr 2026 13:48:25 +0000 Subject: [PATCH 1/2] Fix bugs in TrkReco: break->continue, division by zero, bounds checks, shadowing, dead code Agent-Logs-Url: https://github.com/Mu2e/Offline/sessions/f9f302df-5ed3-439e-8046-3c5c0c6a940e Co-authored-by: oksuzian <48927306+oksuzian@users.noreply.github.com> --- TrkReco/src/RobustHelixFinderData.cc | 6 ------ TrkReco/src/RobustHelixFit.cc | 2 +- TrkReco/src/SelectReflections_module.cc | 4 ++-- TrkReco/src/SelectSameTrack_module.cc | 5 +++-- TrkReco/src/SimpleKalSeedSelector_tool.cc | 1 + TrkReco/src/TrackMatching_module.cc | 4 ++-- TrkReco/src/TrkUtilities.cc | 1 + 7 files changed, 10 insertions(+), 13 deletions(-) diff --git a/TrkReco/src/RobustHelixFinderData.cc b/TrkReco/src/RobustHelixFinderData.cc index 9fedaa10b8..520d0fede9 100644 --- a/TrkReco/src/RobustHelixFinderData.cc +++ b/TrkReco/src/RobustHelixFinderData.cc @@ -63,12 +63,6 @@ namespace mu2e { _nXYSh = 0; _nZPhiSh = 0; - _nStrawHits = 0; - _nComboHits = 0; - - _nFiltComboHits = 0; - _nFiltStrawHits = 0; - //clear the panel-based structure for (int f=0; f= 0 && bin < int(nbinsX)) hist[bin] += weight; } } } diff --git a/TrkReco/src/SelectReflections_module.cc b/TrkReco/src/SelectReflections_module.cc index 33ac868f4b..acdcd13058 100644 --- a/TrkReco/src/SelectReflections_module.cc +++ b/TrkReco/src/SelectReflections_module.cc @@ -95,7 +95,7 @@ namespace mu2e { } } // if no intersections found, skip testing for a match with this track - if(uptrkiinter == upks.intersections().end())break; + if(uptrkiinter == upks.intersections().end())continue; // otherwise, search for a matching downstream track for(size_t idown = 0; idown 1){ if(debug_ > 1) std::cout << "Selecting best reflection pair from " << matches.size() << " candidates " << std::endl; - double value = std::numeric_limits::max(); + double value = std::numeric_limits::max(); for (size_t imatch = 0; imatch < matches.size(); ++imatch) { auto const& match = matches[imatch]; if(selbest_ == mom && -std::get<2>(match) < value){ diff --git a/TrkReco/src/SelectSameTrack_module.cc b/TrkReco/src/SelectSameTrack_module.cc index a6cb8d584d..1039bfb3fa 100644 --- a/TrkReco/src/SelectSameTrack_module.cc +++ b/TrkReco/src/SelectSameTrack_module.cc @@ -113,7 +113,7 @@ namespace mu2e { } } // if no intersections found, skip testing for a match with this track - if(pritrkiinter == priks.intersections().end())break; + if(pritrkiinter == priks.intersections().end())continue; // otherwise, search for a matching secondary track for(size_t isec = 0; isec WireHitState::inactive && prihits.find(hit._index) != prihits.end())++nover; } + if(prihits.empty()) continue; double hfrac = float(nover)/float(prihits.size()); if(debug_ > 2) std::cout << "Hit overlap " << hfrac << std::endl; if(hfrac > minhf_){ @@ -162,7 +163,7 @@ namespace mu2e { ibest = 0; if(matches.size()>1){ if(debug_ > 1) std::cout << "Selecting best reflection pair from " << matches.size() << " candidates " << std::endl; - double value = std::numeric_limits::max(); + double value = std::numeric_limits::max(); for (size_t imatch = 0; imatch < matches.size(); ++imatch) { auto const& match = matches[imatch]; if(selbest_ == mom && -match.primom_ < value){ diff --git a/TrkReco/src/SimpleKalSeedSelector_tool.cc b/TrkReco/src/SimpleKalSeedSelector_tool.cc index 1ccfba7c57..c77cceb909 100644 --- a/TrkReco/src/SimpleKalSeedSelector_tool.cc +++ b/TrkReco/src/SimpleKalSeedSelector_tool.cc @@ -29,6 +29,7 @@ namespace mu2e { if (hit.strawHitState() > WireHitState::inactive) ++ntest; } + if(ntest + ncurrent == 0) return test.fitConsistency() > current.fitConsistency(); float nhitfrac = 2*float(ntest - ncurrent)/float(ntest + ncurrent); if(fabs(nhitfrac) > minsignhit_){ // hit difference is significant; diff --git a/TrkReco/src/TrackMatching_module.cc b/TrkReco/src/TrackMatching_module.cc index 8cd47ee53e..6d9ed1a038 100644 --- a/TrkReco/src/TrackMatching_module.cc +++ b/TrkReco/src/TrackMatching_module.cc @@ -198,8 +198,8 @@ namespace mu2e std::vector clusters; for(auto& handle : handles) { - const size_t ntrks = handle->size(); - for(size_t itrk = 0; itrk < ntrks; ++itrk) { + const size_t ntrks_handle = handle->size(); + for(size_t itrk = 0; itrk < ntrks_handle; ++itrk) { KalSeedPtr ptr(handle, itrk); clusters.push_back(KalSeedCluster({ptr})); } diff --git a/TrkReco/src/TrkUtilities.cc b/TrkReco/src/TrkUtilities.cc index 6c93eeeff5..27c4b025b2 100644 --- a/TrkReco/src/TrkUtilities.cc +++ b/TrkReco/src/TrkUtilities.cc @@ -48,6 +48,7 @@ namespace mu2e { } // compute the overlap between 2 clusters double overlap(SHIV const& shiv1, SHIV const& shiv2) { + if(shiv1.empty() || shiv2.empty()) return 0.0; double over(0.0); double norm = std::min(shiv1.size(),shiv2.size()); // count the overlapping hits From 8fd3bcf5ca418cf23a5c627fe76c429a6971e380 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Apr 2026 13:49:48 +0000 Subject: [PATCH 2/2] Move prihits.empty() guard before nover computation in SelectSameTrack Agent-Logs-Url: https://github.com/Mu2e/Offline/sessions/f9f302df-5ed3-439e-8046-3c5c0c6a940e Co-authored-by: oksuzian <48927306+oksuzian@users.noreply.github.com> --- TrkReco/src/SelectSameTrack_module.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TrkReco/src/SelectSameTrack_module.cc b/TrkReco/src/SelectSameTrack_module.cc index 1039bfb3fa..5d7e16e690 100644 --- a/TrkReco/src/SelectSameTrack_module.cc +++ b/TrkReco/src/SelectSameTrack_module.cc @@ -140,11 +140,11 @@ namespace mu2e { for(auto const& hit: priks.hits()){ if(hit._ambig > WireHitState::inactive)prihits.insert(hit._index); } + if(prihits.empty()) continue; unsigned nover(0); for(auto const& hit: secks.hits()){ if(hit._ambig > WireHitState::inactive && prihits.find(hit._index) != prihits.end())++nover; } - if(prihits.empty()) continue; double hfrac = float(nover)/float(prihits.size()); if(debug_ > 2) std::cout << "Hit overlap " << hfrac << std::endl; if(hfrac > minhf_){