Skip to content

Commit

Permalink
feat!: Add a radius bin to the grid (#3662)
Browse files Browse the repository at this point in the history
This adds a radius bin to the grid. The binning can be provided by the user with a vector of values. If none is provided, the range `rMin -> rMax` will be used.  
That means that now the grids is 3D : `(phi, z, radius)`

By default `rMin = 0_mm`, while `rMax = 320_mm`
  • Loading branch information
CarloVarni authored Oct 4, 2024
1 parent 68d0709 commit 74244eb
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 58 deletions.
20 changes: 13 additions & 7 deletions Core/include/Acts/Seeding/detail/CylindricalSpacePointGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ template <typename external_spacepoint_t>
using CylindricalSpacePointGrid = Acts::Grid<
std::vector<const external_spacepoint_t*>,
Acts::Axis<Acts::AxisType::Equidistant, Acts::AxisBoundaryType::Closed>,
Acts::Axis<Acts::AxisType::Variable, Acts::AxisBoundaryType::Bound>,
Acts::Axis<Acts::AxisType::Variable, Acts::AxisBoundaryType::Bound>>;

/// Cylindrical Binned Group
Expand All @@ -35,22 +36,25 @@ using CylindricalBinnedGroupIterator = Acts::BinnedGroupIterator<

struct CylindricalSpacePointGridConfig {
// minimum pT to be found by seedFinder
float minPt = 0;
float minPt = 0 * Acts::UnitConstants::MeV;
// maximum extension of sensitive detector layer relevant for seeding as
// distance from x=y=0 (i.e. in r)
float rMax = 0;
float rMax = 320 * Acts::UnitConstants::mm;
// maximum extension of sensitive detector layer relevant for seeding as
// distance from x=y=0 (i.e. in r)
float rMin = 0 * Acts::UnitConstants::mm;
// maximum extension of sensitive detector layer relevant for seeding in
// positive direction in z
float zMax = 0;
float zMax = 0 * Acts::UnitConstants::mm;
// maximum extension of sensitive detector layer relevant for seeding in
// negative direction in z
float zMin = 0;
float zMin = 0 * Acts::UnitConstants::mm;
// maximum distance in r from middle space point to bottom or top spacepoint
float deltaRMax = 0;
float deltaRMax = 0 * Acts::UnitConstants::mm;
// maximum forward direction expressed as cot(theta)
float cotThetaMax = 0;
// maximum impact parameter in mm
float impactMax = 0;
float impactMax = 0 * Acts::UnitConstants::mm;
// minimum phi value for phiAxis construction
float phiMin = -M_PI;
// maximum phi value for phiAxis construction
Expand All @@ -65,7 +69,8 @@ struct CylindricalSpacePointGridConfig {
// maximum number of phi bins
int maxPhiBins = 10000;
// enable non equidistant binning in z
std::vector<float> zBinEdges;
std::vector<float> zBinEdges{};
std::vector<float> rBinEdges{};
bool isInInternalUnits = false;
CylindricalSpacePointGridConfig toInternalUnits() const {
if (isInInternalUnits) {
Expand All @@ -77,6 +82,7 @@ struct CylindricalSpacePointGridConfig {
CylindricalSpacePointGridConfig config = *this;
config.isInInternalUnits = true;
config.minPt /= 1_MeV;
config.rMin /= 1_mm;
config.rMax /= 1_mm;
config.zMax /= 1_mm;
config.zMin /= 1_mm;
Expand Down
54 changes: 21 additions & 33 deletions Core/include/Acts/Seeding/detail/CylindricalSpacePointGrid.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Acts::CylindricalSpacePointGridCreator::createGrid(
config.phiMin, config.phiMax, phiBins);

// vector that will store the edges of the bins of z
std::vector<AxisScalar> zValues;
std::vector<AxisScalar> zValues{};

// If zBinEdges is not defined, calculate the edges as zMin + bin * zBinSize
if (config.zBinEdges.empty()) {
Expand All @@ -130,9 +130,19 @@ Acts::CylindricalSpacePointGridCreator::createGrid(
}
}

std::vector<AxisScalar> rValues{};
rValues.reserve(std::max(2ul, config.rBinEdges.size()));
if (config.rBinEdges.empty()) {
rValues = {config.rMin, config.rMax};
} else {
rValues.insert(rValues.end(), config.rBinEdges.begin(),
config.rBinEdges.end());
}

Axis<AxisType::Variable, AxisBoundaryType::Bound> zAxis(std::move(zValues));
Axis<AxisType::Variable, AxisBoundaryType::Bound> rAxis(std::move(rValues));
return Acts::CylindricalSpacePointGrid<external_spacepoint_t>(
std::make_tuple(std::move(phiAxis), std::move(zAxis)));
std::make_tuple(std::move(phiAxis), std::move(zAxis), std::move(rAxis)));
}

template <typename external_spacepoint_t,
Expand All @@ -155,13 +165,13 @@ void Acts::CylindricalSpacePointGridCreator::fillGrid(
"SeedFinderOptions not in ACTS internal units in BinnedSPGroup");
}

// sort by radius
// add magnitude of beamPos to rMax to avoid excluding measurements
// create number of bins equal to number of millimeters rMax
// (worst case minR: configured minR + 1mm)
// binSizeR allows to increase or reduce numRBins if needed
std::size_t numRBins = static_cast<std::size_t>(
(config.rMax + options.beamPos.norm()) / config.binSizeR);
// Space points are assumed to be ALREADY CORRECTED for beamspot position
// phi, z and r space point selection comes naturally from the
// grid axis definition. No need to explicitly cut on those values.
// If a space point is outside the validity range of these quantities
// it goes in an over- or under-flow bin.
// Additional cuts can be applied by customizing the space point selector
// in the config object.

// keep track of changed bins while sorting
std::vector<bool> usedBinIndex(grid.size(), false);
Expand All @@ -172,37 +182,15 @@ void Acts::CylindricalSpacePointGridCreator::fillGrid(
for (external_spacepoint_iterator_t it = spBegin; it != spEnd;
it++, ++counter) {
const external_spacepoint_t& sp = *it;
float spX = sp.x();
float spY = sp.y();
float spZ = sp.z();

// remove SPs according to experiment specific cuts
if (!config.spacePointSelector(sp)) {
continue;
}

// remove SPs outside z and phi region
if (spZ > config.zMax || spZ < config.zMin) {
continue;
}

float spPhi = std::atan2(spY, spX);
if (spPhi > config.phiMax || spPhi < config.phiMin) {
continue;
}

// calculate r-Bin index and protect against overflow (underflow not
// possible)
std::size_t rIndex =
static_cast<std::size_t>(sp.radius() / config.binSizeR);
// if index out of bounds, the SP is outside the region of interest
if (rIndex >= numRBins) {
continue;
}

// fill rbins into grid
std::size_t globIndex =
grid.globalBinFromPosition(Acts::Vector2{sp.phi(), sp.z()});
std::size_t globIndex = grid.globalBinFromPosition(
Acts::Vector3{sp.phi(), sp.z(), sp.radius()});
auto& rbin = grid.at(globIndex);
rbin.push_back(&sp);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class SeedingAlgorithm final : public IAlgorithm {
Acts::SeedFinder<SpacePointProxy_t,
Acts::CylindricalSpacePointGrid<SpacePointProxy_t>>
m_seedFinder;
std::unique_ptr<const Acts::GridBinFinder<2ul>> m_bottomBinFinder;
std::unique_ptr<const Acts::GridBinFinder<2ul>> m_topBinFinder;
std::unique_ptr<const Acts::GridBinFinder<3ul>> m_bottomBinFinder{nullptr};
std::unique_ptr<const Acts::GridBinFinder<3ul>> m_topBinFinder{nullptr};

Config m_cfg;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class SeedingAlgorithmHashing final : public IAlgorithm {
Acts::SeedFinder<SpacePointProxy_t,
Acts::CylindricalSpacePointGrid<SpacePointProxy_t>>
m_seedFinder;
std::unique_ptr<const Acts::GridBinFinder<2ul>> m_bottomBinFinder;
std::unique_ptr<const Acts::GridBinFinder<2ul>> m_topBinFinder;
std::unique_ptr<const Acts::GridBinFinder<3ul>> m_bottomBinFinder{nullptr};
std::unique_ptr<const Acts::GridBinFinder<3ul>> m_topBinFinder{nullptr};

Config m_cfg;

Expand Down
10 changes: 5 additions & 5 deletions Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ ActsExamples::SeedingAlgorithm::SeedingAlgorithm(
ActsExamples::SpacePointContainer<std::vector<const SimSpacePoint*>>,
Acts::detail::RefHolder>::SpacePointProxyType;

m_bottomBinFinder = std::make_unique<const Acts::GridBinFinder<2ul>>(
m_cfg.numPhiNeighbors, cfg.zBinNeighborsBottom);
m_topBinFinder = std::make_unique<const Acts::GridBinFinder<2ul>>(
m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsTop);
m_bottomBinFinder = std::make_unique<const Acts::GridBinFinder<3ul>>(
m_cfg.numPhiNeighbors, cfg.zBinNeighborsBottom, 0);
m_topBinFinder = std::make_unique<const Acts::GridBinFinder<3ul>>(
m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsTop, 0);

m_cfg.seedFinderConfig.seedFilter =
std::make_unique<Acts::SeedFilter<SpacePointProxy_type>>(
Expand Down Expand Up @@ -265,7 +265,7 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute(
maxRange = std::max(lastEl->radius(), maxRange);
}

std::array<std::vector<std::size_t>, 2ul> navigation;
std::array<std::vector<std::size_t>, 3ul> navigation;
navigation[1ul] = m_cfg.seedFinderConfig.zBinsCustomLooping;

auto spacePointsGrouping = Acts::CylindricalBinnedGroup<value_type>(
Expand Down
10 changes: 5 additions & 5 deletions Examples/Algorithms/TrackFinding/src/SeedingAlgorithmHashing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ ActsExamples::SeedingAlgorithmHashing::SeedingAlgorithmHashing(
m_cfg.seedFinderConfig.experimentCuts.connect<itkFastTrackingCuts>();
}

m_bottomBinFinder = std::make_unique<const Acts::GridBinFinder<2ul>>(
m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsBottom);
m_topBinFinder = std::make_unique<const Acts::GridBinFinder<2ul>>(
m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsTop);
m_bottomBinFinder = std::make_unique<const Acts::GridBinFinder<3ul>>(
m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsBottom, 0);
m_topBinFinder = std::make_unique<const Acts::GridBinFinder<3ul>>(
m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsTop, 0);

m_cfg.seedFinderConfig.seedFilter =
std::make_unique<Acts::SeedFilter<SpacePointProxy_type>>(
Expand Down Expand Up @@ -291,7 +291,7 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithmHashing::execute(
maxRange = std::max(lastEl->radius(), maxRange);
}

std::array<std::vector<std::size_t>, 2ul> navigation;
std::array<std::vector<std::size_t>, 3ul> navigation;
navigation[1ul] = m_cfg.seedFinderConfig.zBinsCustomLooping;

// groups spacepoints
Expand Down
9 changes: 5 additions & 4 deletions Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ int main(int argc, char** argv) {
Acts::SeedFinderConfig<value_type> config;
// silicon detector max
config.rMax = 160._mm;
config.rMin = 0._mm;
config.deltaRMin = 5._mm;
config.deltaRMax = 160._mm;
config.deltaRMinTopSP = config.deltaRMin;
Expand Down Expand Up @@ -178,10 +179,10 @@ int main(int argc, char** argv) {
std::vector<std::pair<int, int>> zBinNeighborsTop;
std::vector<std::pair<int, int>> zBinNeighborsBottom;

auto bottomBinFinder = std::make_unique<Acts::GridBinFinder<2ul>>(
Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsBottom));
auto topBinFinder = std::make_unique<Acts::GridBinFinder<2ul>>(
Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsTop));
auto bottomBinFinder = std::make_unique<Acts::GridBinFinder<3ul>>(
numPhiNeighbors, zBinNeighborsBottom, 0);
auto topBinFinder = std::make_unique<Acts::GridBinFinder<3ul>>(
numPhiNeighbors, zBinNeighborsTop, 0);
Acts::SeedFilterConfig sfconf;

Acts::ATLASCuts<value_type> atlasCuts = Acts::ATLASCuts<value_type>();
Expand Down

0 comments on commit 74244eb

Please sign in to comment.