Skip to content

Commit

Permalink
refactor!: Grid specialization for Cylindrical geometry (#2858)
Browse files Browse the repository at this point in the history
Follow up from #2854 

In this PR I am defining a grid geometry for a cylindrical experiment with (phi, z) bins. This is done in a specific file that is included in the GridSpacePoint file. Other specializations can then be easily added in the same fashion (e.g. a pre-defined grid for telescope geometry).

Requires: 
- #2838
- #2854
- #2835
  • Loading branch information
CarloVarni authored Jan 19, 2024
1 parent 6f8e9b8 commit b6480f7
Show file tree
Hide file tree
Showing 23 changed files with 251 additions and 234 deletions.
7 changes: 0 additions & 7 deletions Core/include/Acts/Seeding/BinnedGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#pragma once

#include "Acts/Seeding/BinnedGroupIterator.hpp"
#include "Acts/Seeding/SpacePointGrid.hpp"
#include "Acts/Utilities/GridBinFinder.hpp"
#include "Acts/Utilities/GridIterator.hpp"
#include "Acts/Utilities/Holders.hpp"
Expand Down Expand Up @@ -94,9 +93,3 @@ class BinnedGroup {
} // namespace Acts

#include "Acts/Seeding/BinnedGroup.ipp"

namespace Acts {
template <typename external_spacepoint_t>
using BinnedSPGroup =
Acts::BinnedGroup<Acts::SpacePointGrid<external_spacepoint_t>>;
}
7 changes: 0 additions & 7 deletions Core/include/Acts/Seeding/BinnedGroupIterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#pragma once

#include "Acts/Seeding/SpacePointGrid.hpp"
#include "Acts/Utilities/GridIterator.hpp"
#include "Acts/Utilities/Holders.hpp"
#include "Acts/Utilities/detail/grid_helper.hpp"
Expand Down Expand Up @@ -120,9 +119,3 @@ class BinnedGroupIterator {
} // namespace Acts

#include "Acts/Seeding/BinnedGroupIterator.ipp"

namespace Acts {
template <typename external_spacepoint_t>
using BinnedSPGroupIterator =
BinnedGroupIterator<Acts::SpacePointGrid<external_spacepoint_t>>;
}
26 changes: 8 additions & 18 deletions Core/include/Acts/Seeding/Neighbour.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
// Copyright (C) 2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#pragma once

#include "Acts/Seeding/SpacePointGrid.hpp"
#include "Acts/Utilities/Grid.hpp"

namespace Acts {

Expand All @@ -27,37 +27,27 @@ namespace Acts {
/// have a higher radius. That means that there is no point in looking at
/// neighbour space point before itr, since we know they will be out of range.

template <typename external_spacepoint_t>
template <typename grid_t>
struct Neighbour {
/// @brief default constructor
Neighbour() = delete;

/// @brief Constructor with grid as rvalue
/// @param grid The grid containing the space points
/// @param idx The global index of the bin in the grid
/// @param lowerBound The lower bound of the allowed space points
Neighbour(Acts::SpacePointGrid<external_spacepoint_t>&& grid, std::size_t idx,
const float lowerBound) = delete;

/// @brief Constructor
/// @param grid The grid containing the space points
/// @param idx The global index of the bin in the grid
/// @param lowerBound The lower bound of the allowed space point
Neighbour(const Acts::SpacePointGrid<external_spacepoint_t>& grid,
std::size_t idx, const float lowerBound);
Neighbour(const grid_t& grid, std::size_t idx, const float lowerBound);

/// The global bin index on the grid
std::size_t index;
/// The iterator containing the position of the first space point in the valid
/// radius range
typename Acts::SpacePointGrid<
external_spacepoint_t>::value_type::const_iterator itr;
typename grid_t::value_type::const_iterator itr;
};

template <typename external_spacepoint_t>
Neighbour<external_spacepoint_t>::Neighbour(
const Acts::SpacePointGrid<external_spacepoint_t>& grid, std::size_t idx,
const float lowerBound)
template <typename grid_t>
Neighbour<grid_t>::Neighbour(const grid_t& grid, std::size_t idx,
const float lowerBound)
: index(idx) {
/// Get the space points in this specific global bin
const auto& collection = grid.at(idx);
Expand Down
21 changes: 12 additions & 9 deletions Core/include/Acts/Seeding/SeedFinder.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
// Copyright (C) 2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -19,6 +19,7 @@
#include "Acts/Seeding/SeedFinderConfig.hpp"
#include "Acts/Seeding/SeedFinderUtils.hpp"
#include "Acts/Seeding/SpacePointGrid.hpp"
#include "Acts/Utilities/detail/grid_helper.hpp"

#include <array>
#include <limits>
Expand All @@ -41,6 +42,7 @@ class SeedFinder {
///////////////////////////////////////////////////////////////////
// Public methods:
///////////////////////////////////////////////////////////////////
using grid_t = Acts::CylindricalSpacePointGrid<external_spacepoint_t>;

public:
struct SeedingState {
Expand All @@ -63,9 +65,11 @@ class SeedFinder {
candidates_collector;

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

// Adding space point info
Expand Down Expand Up @@ -99,7 +103,7 @@ class SeedFinder {
template <template <typename...> typename container_t, typename sp_range_t>
void createSeedsForGroup(
const Acts::SeedFinderOptions& options, SeedingState& state,
const Acts::SpacePointGrid<external_spacepoint_t>& grid,
const grid_t& grid,
std::back_insert_iterator<container_t<Seed<external_spacepoint_t>>> outIt,
const sp_range_t& bottomSPs, const std::size_t middleSPs,
const sp_range_t& topSPs,
Expand All @@ -126,8 +130,7 @@ class SeedFinder {
/// @returns a vector of seeds.
template <typename sp_range_t>
std::vector<Seed<external_spacepoint_t>> createSeedsForGroup(
const Acts::SeedFinderOptions& options,
const Acts::SpacePointGrid<external_spacepoint_t>& grid,
const Acts::SeedFinderOptions& options, const grid_t& grid,
const sp_range_t& bottomSPs, const std::size_t middleSPs,
const sp_range_t& topSPs) const;

Expand All @@ -150,9 +153,9 @@ class SeedFinder {
template <Acts::SpacePointCandidateType candidateType, typename out_range_t>
void getCompatibleDoublets(
Acts::SpacePointData& spacePointData,
const Acts::SeedFinderOptions& options,
const Acts::SpacePointGrid<external_spacepoint_t>& grid,
boost::container::small_vector<Neighbour<external_spacepoint_t>, 9>&
const Acts::SeedFinderOptions& options, const grid_t& grid,
boost::container::small_vector<Acts::Neighbour<grid_t>,
Acts::detail::ipow(3, grid_t::DIM)>&
otherSPsNeighbours,
const InternalSpacePoint<external_spacepoint_t>& mediumSP,
std::vector<LinCircle>& linCircleVec, out_range_t& outVec,
Expand Down
16 changes: 8 additions & 8 deletions Core/include/Acts/Seeding/SeedFinder.ipp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
// Copyright (C) 2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -39,7 +39,7 @@ template <typename external_spacepoint_t, typename platform_t>
template <template <typename...> typename container_t, typename sp_range_t>
void SeedFinder<external_spacepoint_t, platform_t>::createSeedsForGroup(
const Acts::SeedFinderOptions& options, SeedingState& state,
const Acts::SpacePointGrid<external_spacepoint_t>& grid,
const grid_t& grid,
std::back_insert_iterator<container_t<Seed<external_spacepoint_t>>> outIt,
const sp_range_t& bottomSPsIdx, const std::size_t middleSPsIdx,
const sp_range_t& topSPsIdx,
Expand Down Expand Up @@ -197,10 +197,11 @@ template <Acts::SpacePointCandidateType candidateType, typename out_range_t>
inline void
SeedFinder<external_spacepoint_t, platform_t>::getCompatibleDoublets(
Acts::SpacePointData& spacePointData,
const Acts::SeedFinderOptions& options,
const Acts::SpacePointGrid<external_spacepoint_t>& grid,
boost::container::small_vector<Neighbour<external_spacepoint_t>, 9>&
otherSPsNeighbours,
const Acts::SeedFinderOptions& options, const grid_t& grid,
boost::container::small_vector<
Acts::Neighbour<
typename SeedFinder<external_spacepoint_t, platform_t>::grid_t>,
Acts::detail::ipow(3, grid_t::DIM)>& otherSPsNeighbours,
const InternalSpacePoint<external_spacepoint_t>& mediumSP,
std::vector<LinCircle>& linCircleVec, out_range_t& outVec,
const float deltaRMinSP, const float deltaRMaxSP, const float uIP,
Expand Down Expand Up @@ -820,8 +821,7 @@ template <typename external_spacepoint_t, typename platform_t>
template <typename sp_range_t>
std::vector<Seed<external_spacepoint_t>>
SeedFinder<external_spacepoint_t, platform_t>::createSeedsForGroup(
const Acts::SeedFinderOptions& options,
const Acts::SpacePointGrid<external_spacepoint_t>& grid,
const Acts::SeedFinderOptions& options, const grid_t& grid,
const sp_range_t& bottomSPs, const std::size_t middleSPs,
const sp_range_t& topSPs) const {
SeedingState state;
Expand Down
112 changes: 3 additions & 109 deletions Core/include/Acts/Seeding/SpacePointGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,113 +8,7 @@

#pragma once

#include "Acts/Definitions/Units.hpp"
#include "Acts/Geometry/Extent.hpp"
#include "Acts/Seeding/InternalSpacePoint.hpp"
#include "Acts/Seeding/SeedFinderConfig.hpp"
#include "Acts/Utilities/Grid.hpp"
#include "Acts/Utilities/detail/Axis.hpp"
// Define specialization for Cylindrical detector geometry
#include "Acts/Seeding/detail/CylindricalSpacePointGrid.hpp"

#include <memory>

#include <boost/container/flat_set.hpp>

namespace Acts {

struct SpacePointGridConfig {
// minimum pT to be found by seedFinder
float minPt = 0;
// maximum extension of sensitive detector layer relevant for seeding as
// distance from x=y=0 (i.e. in r)
float rMax = 0;
// maximum extension of sensitive detector layer relevant for seeding in
// positive direction in z
float zMax = 0;
// maximum extension of sensitive detector layer relevant for seeding in
// negative direction in z
float zMin = 0;
// maximum distance in r from middle space point to bottom or top spacepoint
float deltaRMax = 0;
// maximum forward direction expressed as cot(theta)
float cotThetaMax = 0;
// maximum impact parameter in mm
float impactMax = 0;
// minimum phi value for phiAxis construction
float phiMin = -M_PI;
// maximum phi value for phiAxis construction
float phiMax = M_PI;
// Multiplicator for the number of phi-bins. The minimum number of phi-bins
// depends on min_pt, magnetic field: 2*M_PI/(minPT particle phi-deflection).
// phiBinDeflectionCoverage is a multiplier for this number. If
// numPhiNeighbors (in the configuration of the BinFinders) is configured to
// return 1 neighbor on either side of the current phi-bin (and you want to
// cover the full phi-range of minPT), leave this at 1.
int phiBinDeflectionCoverage = 1;
// maximum number of phi bins
int maxPhiBins = 10000;
// enable non equidistant binning in z
std::vector<float> zBinEdges;
bool isInInternalUnits = false;
SpacePointGridConfig toInternalUnits() const {
if (isInInternalUnits) {
throw std::runtime_error(
"Repeated conversion to internal units for SpacePointGridConfig");
}
using namespace Acts::UnitLiterals;
SpacePointGridConfig config = *this;
config.isInInternalUnits = true;
config.minPt /= 1_MeV;
config.rMax /= 1_mm;
config.zMax /= 1_mm;
config.zMin /= 1_mm;
config.deltaRMax /= 1_mm;

return config;
}
};

struct SpacePointGridOptions {
// magnetic field
float bFieldInZ = 0;
bool isInInternalUnits = false;
SpacePointGridOptions toInternalUnits() const {
if (isInInternalUnits) {
throw std::runtime_error(
"Repeated conversion to internal units for SpacePointGridOptions");
}
using namespace Acts::UnitLiterals;
SpacePointGridOptions options = *this;
options.isInInternalUnits = true;
options.bFieldInZ /= 1000_T;

return options;
}
};

template <typename external_spacepoint_t>
using SpacePointGrid = Grid<
std::vector<
std::unique_ptr<Acts::InternalSpacePoint<external_spacepoint_t>>>,
detail::Axis<detail::AxisType::Equidistant,
detail::AxisBoundaryType::Closed>,
detail::Axis<detail::AxisType::Variable, detail::AxisBoundaryType::Bound>>;

class SpacePointGridCreator {
public:
template <typename external_spacepoint_t>
static Acts::SpacePointGrid<external_spacepoint_t> createGrid(
const Acts::SpacePointGridConfig& _config,
const Acts::SpacePointGridOptions& _options);

template <typename external_spacepoint_t,
typename external_spacepoint_iterator_t, typename callable_t>
static void fillGrid(
const Acts::SeedFinderConfig<external_spacepoint_t>& config,
const Acts::SeedFinderOptions& options,
Acts::SpacePointGrid<external_spacepoint_t>& grid,
external_spacepoint_iterator_t spBegin,
external_spacepoint_iterator_t spEnd, callable_t&& toGlobal,
Acts::Extent& rRangeSPExtent);
};
} // namespace Acts
#include "Acts/Seeding/SpacePointGrid.ipp"
// Define specialization for other detector geometries
Loading

0 comments on commit b6480f7

Please sign in to comment.