Skip to content

Commit

Permalink
refactor: Add some requirements (acts-project#3720)
Browse files Browse the repository at this point in the history
Add some concept in order to request specific requirements on objects/functions used by the seeding
  • Loading branch information
CarloVarni authored Oct 15, 2024
1 parent e3b33cc commit fb3ddf4
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 23 deletions.
39 changes: 27 additions & 12 deletions Core/include/Acts/Seeding/SeedFinder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,32 @@
#include "Acts/Seeding/SeedFinderConfig.hpp"
#include "Acts/Seeding/SeedFinderUtils.hpp"
#include "Acts/Seeding/SpacePointGrid.hpp"
#include "Acts/Seeding/detail/UtilityFunctions.hpp"

#include <array>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <ranges>
#include <set>
#include <string>
#include <utility>
#include <vector>

namespace Acts {

template <typename Coll>
concept GridBinCollection =
std::ranges::random_access_range<Coll> &&
std::same_as<typename Coll::value_type, std::size_t>;

template <typename Coll, typename external_t, std::size_t N = 3ul>
concept CollectionStoresSeedsTo = requires(Coll coll, external_t sp) {
Acts::detail::pushBackOrInsertAtEnd(coll,
Acts::Seed<external_t, N>(sp, sp, sp));
};

enum class SpacePointCandidateType : short { eBottom, eTop };

enum class DetectorMeasurementInfo : short { eDefault, eDetailed };
Expand All @@ -44,32 +57,32 @@ class SeedFinder {
public:
struct SeedingState {
// bottom space point
std::vector<const external_spacepoint_t*> compatBottomSP;
std::vector<const external_spacepoint_t*> compatTopSP;
std::vector<const external_spacepoint_t*> compatBottomSP{};
std::vector<const external_spacepoint_t*> compatTopSP{};
// contains parameters required to calculate circle with linear equation
// ...for bottom-middle
std::vector<LinCircle> linCircleBottom;
std::vector<LinCircle> linCircleBottom{};
// ...for middle-top
std::vector<LinCircle> linCircleTop;
std::vector<LinCircle> linCircleTop{};

// create vectors here to avoid reallocation in each loop
std::vector<const external_spacepoint_t*> topSpVec;
std::vector<float> curvatures;
std::vector<float> impactParameters;
std::vector<const external_spacepoint_t*> topSpVec{};
std::vector<float> curvatures{};
std::vector<float> impactParameters{};

// managing seed candidates for SpM
CandidatesForMiddleSp<const external_spacepoint_t> candidates_collector;
CandidatesForMiddleSp<const external_spacepoint_t> candidates_collector{};

// managing doublet candidates
boost::container::small_vector<Acts::Neighbour<grid_t>,
Acts::detail::ipow(3, grid_t::DIM)>
bottomNeighbours;
bottomNeighbours{};
boost::container::small_vector<Acts::Neighbour<grid_t>,
Acts::detail::ipow(3, grid_t::DIM)>
topNeighbours;
topNeighbours{};

// Mutable variables for Space points used in the seeding
Acts::SpacePointMutableData spacePointMutableData;
Acts::SpacePointMutableData spacePointMutableData{};
};

/// The only constructor. Requires a config object.
Expand Down Expand Up @@ -97,7 +110,9 @@ class SeedFinder {
/// @param rMiddleSPRange range object containing the minimum and maximum r for middle SP for a certain z bin.
/// @note Ranges must return pointers.
/// @note Ranges must be separate objects for each parallel call.
template <typename container_t, typename sp_range_t>
template <typename container_t, Acts::GridBinCollection sp_range_t>
requires Acts::CollectionStoresSeedsTo<container_t, external_spacepoint_t,
3ul>
void createSeedsForGroup(const Acts::SeedFinderOptions& options,
SeedingState& state, const grid_t& grid,
container_t& outputCollection,
Expand Down
4 changes: 3 additions & 1 deletion Core/include/Acts/Seeding/SeedFinder.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ SeedFinder<external_spacepoint_t, grid_t, platform_t>::SeedFinder(
}

template <typename external_spacepoint_t, typename grid_t, typename platform_t>
template <typename container_t, typename sp_range_t>
template <typename container_t, Acts::GridBinCollection sp_range_t>
requires Acts::CollectionStoresSeedsTo<container_t, external_spacepoint_t,
3ul>
void SeedFinder<external_spacepoint_t, grid_t, platform_t>::createSeedsForGroup(
const Acts::SeedFinderOptions& options, SeedingState& state,
const grid_t& grid, container_t& outputCollection,
Expand Down
30 changes: 28 additions & 2 deletions Core/include/Acts/Seeding/detail/CylindricalSpacePointGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@

namespace Acts {

/// Concept to check the provided external space point type
/// can be used to fill the space point grid
template <typename external_spacepoint_t>
concept CylindricalGridElement = requires(external_spacepoint_t sp) {
{ sp.phi() } -> std::same_as<float>;
{ sp.z() } -> std::same_as<float>;
{ sp.radius() } -> std::same_as<float>;
};

/// Cylindrical Space Point bin is a 2D grid with (phi, z) bins
/// It stores a vector of internal space points to external space points
template <typename external_spacepoint_t>
template <Acts::CylindricalGridElement external_spacepoint_t>
using CylindricalSpacePointGrid = Acts::Grid<
std::vector<const external_spacepoint_t*>,
Acts::Axis<Acts::AxisType::Equidistant, Acts::AxisBoundaryType::Closed>,
Expand Down Expand Up @@ -90,6 +99,13 @@ struct CylindricalSpacePointGridConfig {
config.zMin /= 1_mm;
config.deltaRMax /= 1_mm;

for (float& val : config.zBinEdges) {
val /= 1_mm;
}
for (float& val : config.rBinEdges) {
val /= 1_mm;
}

if (config.phiMin < -std::numbers::pi_v<float> ||
config.phiMax > std::numbers::pi_v<float>) {
throw std::runtime_error(
Expand Down Expand Up @@ -119,7 +135,7 @@ struct CylindricalSpacePointGridConfig {

struct CylindricalSpacePointGridOptions {
// magnetic field
float bFieldInZ = 0.;
float bFieldInZ = 0. * Acts::UnitConstants::T;
bool isInInternalUnits = false;
CylindricalSpacePointGridOptions toInternalUnits() const {
if (isInInternalUnits) {
Expand Down Expand Up @@ -152,6 +168,16 @@ class CylindricalSpacePointGridCreator {
Acts::CylindricalSpacePointGrid<external_spacepoint_t>& grid,
external_spacepoint_iterator_t spBegin,
external_spacepoint_iterator_t spEnd);

template <typename external_spacepoint_t, typename external_collection_t>
requires std::ranges::range<external_collection_t> &&
std::same_as<typename external_collection_t::value_type,
external_spacepoint_t>
static void fillGrid(
const Acts::SeedFinderConfig<external_spacepoint_t>& config,
const Acts::SeedFinderOptions& options,
Acts::CylindricalSpacePointGrid<external_spacepoint_t>& grid,
const external_collection_t& collection);
};

} // namespace Acts
Expand Down
14 changes: 14 additions & 0 deletions Core/include/Acts/Seeding/detail/CylindricalSpacePointGrid.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,17 @@ void Acts::CylindricalSpacePointGridCreator::fillGrid(
std::ranges::sort(rbin, {}, [](const auto& rb) { return rb->radius(); });
}
}

template <typename external_spacepoint_t, typename external_collection_t>
requires std::ranges::range<external_collection_t> &&
std::same_as<typename external_collection_t::value_type,
external_spacepoint_t>
void Acts::CylindricalSpacePointGridCreator::fillGrid(
const Acts::SeedFinderConfig<external_spacepoint_t>& config,
const Acts::SeedFinderOptions& options,
Acts::CylindricalSpacePointGrid<external_spacepoint_t>& grid,
const external_collection_t& collection) {
Acts::CylindricalSpacePointGridCreator::fillGrid<external_spacepoint_t>(
config, options, grid, std::ranges::begin(collection),
std::ranges::end(collection));
}
17 changes: 12 additions & 5 deletions Core/include/Acts/Seeding/detail/UtilityFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,23 @@ concept isCollectionThatSupportsInsert =
};

// Define some functions
template <typename value_t>
void pushBackOrInsertAtEnd(
Acts::detail::isCollectionThatSupportsPushBack auto& storage,
value_t&& value) {
template <Acts::detail::isCollectionThatSupportsPushBack storage_t,
typename value_t>
requires requires(storage_t coll, value_t value) {
coll.push_back(value);
coll.push_back(std::move(value));
}
void pushBackOrInsertAtEnd(storage_t& storage, value_t&& value) {
storage.push_back(std::forward<value_t>(value));
}

template <std::ranges::range storage_t, typename value_t>
requires(!Acts::detail::isCollectionThatSupportsPushBack<storage_t> &&
Acts::detail::isCollectionThatSupportsInsert<storage_t>)
Acts::detail::isCollectionThatSupportsInsert<storage_t> &&
requires(storage_t coll, value_t value) {
coll.insert(std::ranges::end(coll), value);
coll.insert(std::ranges::end(coll), std::move(value));
})
void pushBackOrInsertAtEnd(storage_t& storage, value_t&& value) {
storage.insert(std::ranges::end(storage), std::forward<value_t>(value));
}
Expand Down
5 changes: 2 additions & 3 deletions Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,8 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute(
Acts::CylindricalSpacePointGridCreator::createGrid<value_type>(
m_cfg.gridConfig, m_cfg.gridOptions);

Acts::CylindricalSpacePointGridCreator::fillGrid(
m_cfg.seedFinderConfig, m_cfg.seedFinderOptions, grid,
spContainer.begin(), spContainer.end());
Acts::CylindricalSpacePointGridCreator::fillGrid<value_type>(
m_cfg.seedFinderConfig, m_cfg.seedFinderOptions, grid, spContainer);

// Compute radius Range
// we rely on the fact the grid is storing the proxies
Expand Down

0 comments on commit fb3ddf4

Please sign in to comment.