Skip to content

Commit 5ec09f9

Browse files
authored
Merge pull request #1785 from Mu2e/copilot/review-issues-in-trkreco
Fix bugs in TrkReco: break→continue, division by zero, bounds checks, shadowing, dead code
2 parents 093f523 + 8fd3bcf commit 5ec09f9

7 files changed

Lines changed: 10 additions & 13 deletions

TrkReco/src/RobustHelixFinderData.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ namespace mu2e {
6363
_nXYSh = 0;
6464
_nZPhiSh = 0;
6565

66-
_nStrawHits = 0;
67-
_nComboHits = 0;
68-
69-
_nFiltComboHits = 0;
70-
_nFiltStrawHits = 0;
71-
7266
//clear the panel-based structure
7367
for (int f=0; f<StrawId::_ntotalfaces; ++f) {
7468
FaceZ_t* facez = &_oTracker[f];

TrkReco/src/RobustHelixFit.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ bool RobustHelixFit::initFZ_2(RobustHelixFinderData& HelixData) {
578578
for (int n=nmin; n<=nmax; n++) { //
579579
double x = dphidz + n*2*M_PI/dz;
580580
int bin = (x-minX)/stepX;
581-
hist[bin] += weight;
581+
if(bin >= 0 && bin < int(nbinsX)) hist[bin] += weight;
582582
}
583583
}
584584
}

TrkReco/src/SelectReflections_module.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ namespace mu2e {
9595
}
9696
}
9797
// if no intersections found, skip testing for a match with this track
98-
if(uptrkiinter == upks.intersections().end())break;
98+
if(uptrkiinter == upks.intersections().end())continue;
9999
// otherwise, search for a matching downstream track
100100
for(size_t idown = 0; idown <downksc.size(); ++idown){
101101
auto const& downks = downksc[idown];
@@ -130,7 +130,7 @@ namespace mu2e {
130130
ibest = 0;
131131
if(matches.size()>1){
132132
if(debug_ > 1) std::cout << "Selecting best reflection pair from " << matches.size() << " candidates " << std::endl;
133-
double value = std::numeric_limits<float>::max();
133+
double value = std::numeric_limits<double>::max();
134134
for (size_t imatch = 0; imatch < matches.size(); ++imatch) {
135135
auto const& match = matches[imatch];
136136
if(selbest_ == mom && -std::get<2>(match) < value){

TrkReco/src/SelectSameTrack_module.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ namespace mu2e {
113113
}
114114
}
115115
// if no intersections found, skip testing for a match with this track
116-
if(pritrkiinter == priks.intersections().end())break;
116+
if(pritrkiinter == priks.intersections().end())continue;
117117
// otherwise, search for a matching secondary track
118118
for(size_t isec = 0; isec <secksc.size(); ++isec){
119119
auto const& secks = secksc[isec];
@@ -140,6 +140,7 @@ namespace mu2e {
140140
for(auto const& hit: priks.hits()){
141141
if(hit._ambig > WireHitState::inactive)prihits.insert(hit._index);
142142
}
143+
if(prihits.empty()) continue;
143144
unsigned nover(0);
144145
for(auto const& hit: secks.hits()){
145146
if(hit._ambig > WireHitState::inactive && prihits.find(hit._index) != prihits.end())++nover;
@@ -162,7 +163,7 @@ namespace mu2e {
162163
ibest = 0;
163164
if(matches.size()>1){
164165
if(debug_ > 1) std::cout << "Selecting best reflection pair from " << matches.size() << " candidates " << std::endl;
165-
double value = std::numeric_limits<float>::max();
166+
double value = std::numeric_limits<double>::max();
166167
for (size_t imatch = 0; imatch < matches.size(); ++imatch) {
167168
auto const& match = matches[imatch];
168169
if(selbest_ == mom && -match.primom_ < value){

TrkReco/src/SimpleKalSeedSelector_tool.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace mu2e {
2929
if (hit.strawHitState() > WireHitState::inactive) ++ntest;
3030
}
3131

32+
if(ntest + ncurrent == 0) return test.fitConsistency() > current.fitConsistency();
3233
float nhitfrac = 2*float(ntest - ncurrent)/float(ntest + ncurrent);
3334
if(fabs(nhitfrac) > minsignhit_){
3435
// hit difference is significant;

TrkReco/src/TrackMatching_module.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ namespace mu2e
198198

199199
std::vector<KalSeedCluster> clusters;
200200
for(auto& handle : handles) {
201-
const size_t ntrks = handle->size();
202-
for(size_t itrk = 0; itrk < ntrks; ++itrk) {
201+
const size_t ntrks_handle = handle->size();
202+
for(size_t itrk = 0; itrk < ntrks_handle; ++itrk) {
203203
KalSeedPtr ptr(handle, itrk);
204204
clusters.push_back(KalSeedCluster({ptr}));
205205
}

TrkReco/src/TrkUtilities.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace mu2e {
4848
}
4949
// compute the overlap between 2 clusters
5050
double overlap(SHIV const& shiv1, SHIV const& shiv2) {
51+
if(shiv1.empty() || shiv2.empty()) return 0.0;
5152
double over(0.0);
5253
double norm = std::min(shiv1.size(),shiv2.size());
5354
// count the overlapping hits

0 commit comments

Comments
 (0)