File indexing completed on 2026-07-26 08:18:59
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Seeding/SphericalSpacePointGrid.hpp"
0010
0011 #include "Acts/Seeding/detail/SpacePointGridPhiBinning.hpp"
0012
0013 #include <cmath>
0014
0015 namespace Acts::Experimental {
0016
0017 SphericalSpacePointGrid::SphericalSpacePointGrid(
0018 const Config& config, std::unique_ptr<const Logger> _logger)
0019 : m_cfg(config), m_logger(std::move(_logger)) {
0020 if (m_cfg.phiMin < -std::numbers::pi_v<float> ||
0021 m_cfg.phiMax > std::numbers::pi_v<float>) {
0022 throw std::runtime_error(
0023 "SphericalSpacePointGrid: phiMin (" + std::to_string(m_cfg.phiMin) +
0024 ") and/or phiMax (" + std::to_string(m_cfg.phiMax) +
0025 ") are outside the allowed phi range, defined as "
0026 "[-std::numbers::pi_v<float>, std::numbers::pi_v<float>]");
0027 }
0028 if (m_cfg.phiMin > m_cfg.phiMax) {
0029 throw std::runtime_error(
0030 "SphericalSpacePointGrid: phiMin is bigger then phiMax");
0031 }
0032 if (m_cfg.rMin > m_cfg.rMax) {
0033 throw std::runtime_error(
0034 "SphericalSpacePointGrid: rMin is bigger then rMax");
0035 }
0036 if (m_cfg.etaMin > m_cfg.etaMax) {
0037 throw std::runtime_error(
0038 "SphericalSpacePointGrid: etaMin is bigger than etaMax");
0039 }
0040
0041 const int phiBins = Acts::detail::computeSpacePointGridPhiBins(
0042 {.minPt = m_cfg.minPt,
0043 .bFieldInZ = m_cfg.bFieldInZ,
0044 .rMax = m_cfg.rMax,
0045 .deltaRMax = m_cfg.deltaRMax,
0046 .impactMax = m_cfg.impactMax,
0047 .phiBinDeflectionCoverage = m_cfg.phiBinDeflectionCoverage,
0048 .maxPhiBins = m_cfg.maxPhiBins},
0049 logger());
0050
0051 PhiAxisType phiAxis(AxisClosed, m_cfg.phiMin, m_cfg.phiMax, phiBins);
0052
0053
0054
0055
0056 std::vector<double> etaValues;
0057
0058
0059 if (m_cfg.etaBinEdges.empty()) {
0060 const float etaBinSize = m_cfg.deltaEtaMax;
0061 const float etaBins =
0062 std::max(1.f, std::floor((m_cfg.etaMax - m_cfg.etaMin) / etaBinSize));
0063
0064 etaValues.reserve(static_cast<int>(etaBins) + 1);
0065 for (int bin = 0; bin <= static_cast<int>(etaBins); bin++) {
0066 const double eta =
0067 m_cfg.etaMin + bin * ((m_cfg.etaMax - m_cfg.etaMin) / etaBins);
0068 etaValues.push_back(std::sinh(eta));
0069 }
0070 } else {
0071
0072 etaValues.reserve(m_cfg.etaBinEdges.size());
0073 for (float eta : m_cfg.etaBinEdges) {
0074 etaValues.push_back(std::sinh(eta));
0075 }
0076 }
0077
0078 std::vector<double> rValues;
0079 rValues.reserve(std::max(2ul, m_cfg.rBinEdges.size()));
0080 if (m_cfg.rBinEdges.empty()) {
0081 rValues = {m_cfg.rMin, m_cfg.rMax};
0082 } else {
0083 rValues.insert(rValues.end(), m_cfg.rBinEdges.begin(),
0084 m_cfg.rBinEdges.end());
0085 }
0086
0087 CotThetaAxisType cotThetaAxis(AxisOpen, std::move(etaValues));
0088 RAxisType rAxis(AxisOpen, std::move(rValues));
0089
0090 ACTS_VERBOSE("Defining Grid:");
0091 ACTS_VERBOSE("- Phi Axis: " << phiAxis);
0092 ACTS_VERBOSE("- cot(theta) axis (sinh(eta) edges): " << cotThetaAxis);
0093 ACTS_VERBOSE("- R axis : " << rAxis);
0094
0095 GridType grid(std::make_tuple(std::move(phiAxis), std::move(cotThetaAxis),
0096 std::move(rAxis)));
0097 m_binnedGroup.emplace(std::move(grid), m_cfg.bottomBinFinder.value(),
0098 m_cfg.topBinFinder.value(), m_cfg.navigation);
0099 m_grid = &m_binnedGroup->grid();
0100 }
0101
0102 void SphericalSpacePointGrid::clear() {
0103 for (std::size_t i = 0; i < grid().size(); ++i) {
0104 BinType& bin = grid().at(i);
0105 bin.clear();
0106 }
0107 m_counter = 0;
0108 }
0109
0110 std::optional<std::size_t> SphericalSpacePointGrid::insert(
0111 SpacePointIndex index, float phi, float cotTheta, float r) {
0112 const std::optional<std::size_t> gridIndex = binIndex(phi, cotTheta, r);
0113 if (gridIndex.has_value()) {
0114 BinType& bin = grid().at(*gridIndex);
0115 bin.push_back(index);
0116 ++m_counter;
0117 }
0118 return gridIndex;
0119 }
0120
0121 void SphericalSpacePointGrid::extend(
0122 const SpacePointContainer::ConstRange& spacePoints) {
0123 ACTS_VERBOSE("Inserting " << spacePoints.size()
0124 << " space points to the grid");
0125
0126 for (const ConstSpacePointProxy& sp : spacePoints) {
0127 insert(sp);
0128 }
0129 }
0130
0131 void SphericalSpacePointGrid::sortBinsByR(
0132 const SpacePointContainer& spacePoints) {
0133 ACTS_VERBOSE("Sorting the grid");
0134
0135 for (std::size_t i = 0; i < grid().size(); ++i) {
0136 BinType& bin = grid().at(i);
0137 std::ranges::sort(bin, {}, [&](SpacePointIndex spIndex) {
0138 return spacePoints[spIndex].zr()[1];
0139 });
0140 }
0141
0142 ACTS_VERBOSE(
0143 "Number of space points inserted (within grid range): " << m_counter);
0144 }
0145
0146 Range1D<float> SphericalSpacePointGrid::computeRadiusRange(
0147 const SpacePointContainer& spacePoints) const {
0148 float minRange = std::numeric_limits<float>::max();
0149 float maxRange = std::numeric_limits<float>::lowest();
0150 for (const BinType& bin : grid()) {
0151 if (bin.empty()) {
0152 continue;
0153 }
0154 auto first = spacePoints[bin.front()];
0155 auto last = spacePoints[bin.back()];
0156 minRange = std::min(first.zr()[1], minRange);
0157 maxRange = std::max(last.zr()[1], maxRange);
0158 }
0159 return {minRange, maxRange};
0160 }
0161
0162 }