Skip to content

Commit 8533ede

Browse files
authored
PWGHF: fix off-by-one bug in findBin() (#5885)
* fix off-by-one bug in findBin() * Use c++ algorithms directly * remove redundant check
1 parent cc905dd commit 8533ede

File tree

1 file changed

+1
-18
lines changed

1 file changed

+1
-18
lines changed

Analysis/Core/include/AnalysisCore/HFSelectorCuts.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,7 @@ int findBin(o2::framework::Configurable<std::vector<T1>> const& bins, T2 value)
3737
if (value >= bins->back()) {
3838
return -1;
3939
}
40-
int step;
41-
int bin = 0;
42-
int count = bins->size();
43-
44-
while (count > 0) {
45-
step = count / 2;
46-
bin += step;
47-
if (bins->operator[](bin) <= value) {
48-
count -= step + 1;
49-
} else {
50-
bin -= step;
51-
count = step;
52-
}
53-
}
54-
if (bin == bins->size()) {
55-
bin = 0;
56-
}
57-
return bin - 1;
40+
return std::distance(bins->begin(), std::upper_bound(bins->begin(), bins->end(), value)) - 1;
5841
}
5942

6043
// namespace per channel

0 commit comments

Comments
 (0)