Skip to content

Commit

Permalink
fix: Prevent unphysical number of phi bins (#1161) (#1167)
Browse files Browse the repository at this point in the history
The bug described in issue #1161 is caused by the creation of negative or (near) infinite number of phi bins, which cause the internal mechanisms of `std::vector` to crash. This effect is caused by the fact that the number of phi neighbours is not properly initialized, causing it to take on uninitialized values.

This commit does two things to prevent this issue. First of all, it adds a sensible default value for the number of phi neighbours, ensuring that it never takes on uninitialized values. Secondly, a sanity check is added to the space point grid to ensure that the phi delta value has a physically meaningful value; if this is not the case, an exception is thrown.

Resolves #1161.
  • Loading branch information
stephenswat committed Feb 22, 2022
1 parent b7d2de0 commit c0aea9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Core/include/Acts/Seeding/SpacePointGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct SpacePointGridConfig {
// maximum impact parameter in mm
float impactMax;
// sets of consecutive phi bins in the seed making step
int numPhiNeighbors;
int numPhiNeighbors = 0;
// enable non equidistant binning in z
std::vector<float> zBinEdges;

Expand Down
8 changes: 8 additions & 0 deletions Core/include/Acts/Seeding/SpacePointGrid.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ Acts::SpacePointGridCreator::createGrid(
float deltaPhi = (outerAngle - innerAngle + deltaAngleWithMaxD0) /
(2 * config.numPhiNeighbors + 1);

// sanity check: if the delta phi is equal to or less than zero, we'll be
// creating an infinite or a negative number of bins, which would be bad!
if (deltaPhi <= 0.f) {
throw std::domain_error(
"Delta phi value is equal to or less than zero, leading to an "
"impossible number of bins (negative or infinite)");
}

// divide 2pi by angle delta to get number of phi-bins
// size is always 2pi even for regions of interest
phiBins = std::ceil(2 * M_PI / deltaPhi);
Expand Down

0 comments on commit c0aea9f

Please sign in to comment.