Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:18:57

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Seeding/CylindricalSpacePointGrid.hpp"
0010 
0011 #include "Acts/Seeding/detail/SpacePointGridPhiBinning.hpp"
0012 
0013 namespace Acts {
0014 
0015 CylindricalSpacePointGrid::CylindricalSpacePointGrid(
0016     const Config& config, std::unique_ptr<const Logger> _logger)
0017     : m_cfg(config), m_logger(std::move(_logger)) {
0018   if (m_cfg.phiMin < -std::numbers::pi_v<float> ||
0019       m_cfg.phiMax > std::numbers::pi_v<float>) {
0020     throw std::runtime_error(
0021         "CylindricalSpacePointGrid: phiMin (" + std::to_string(m_cfg.phiMin) +
0022         ") and/or phiMax (" + std::to_string(m_cfg.phiMax) +
0023         ") are outside the allowed phi range, defined as "
0024         "[-std::numbers::pi_v<float>, std::numbers::pi_v<float>]");
0025   }
0026   if (m_cfg.phiMin > m_cfg.phiMax) {
0027     throw std::runtime_error(
0028         "CylindricalSpacePointGrid: phiMin is bigger then phiMax");
0029   }
0030   if (m_cfg.rMin > m_cfg.rMax) {
0031     throw std::runtime_error(
0032         "CylindricalSpacePointGrid: rMin is bigger then rMax");
0033   }
0034   if (m_cfg.zMin > m_cfg.zMax) {
0035     throw std::runtime_error(
0036         "CylindricalSpacePointGrid: zMin is bigger than zMax");
0037   }
0038 
0039   const int phiBins = detail::computeSpacePointGridPhiBins(
0040       {.minPt = m_cfg.minPt,
0041        .bFieldInZ = m_cfg.bFieldInZ,
0042        .rMax = m_cfg.rMax,
0043        .deltaRMax = m_cfg.deltaRMax,
0044        .impactMax = m_cfg.impactMax,
0045        .phiBinDeflectionCoverage = m_cfg.phiBinDeflectionCoverage,
0046        .maxPhiBins = m_cfg.maxPhiBins},
0047       logger());
0048 
0049   PhiAxisType phiAxis(AxisClosed, m_cfg.phiMin, m_cfg.phiMax, phiBins);
0050 
0051   // vector that will store the edges of the bins of z
0052   std::vector<double> zValues;
0053 
0054   // If zBinEdges is not defined, calculate the edges as zMin + bin * zBinSize
0055   if (m_cfg.zBinEdges.empty()) {
0056     // TODO: can probably be optimized using smaller z bins
0057     // and returning (multiple) neighbors only in one z-direction for forward
0058     // seeds
0059     // FIXME: zBinSize must include scattering
0060     const float zBinSize = m_cfg.cotThetaMax * m_cfg.deltaRMax;
0061     const float zBins =
0062         std::max(1.f, std::floor((m_cfg.zMax - m_cfg.zMin) / zBinSize));
0063 
0064     zValues.reserve(static_cast<int>(zBins));
0065     for (int bin = 0; bin <= static_cast<int>(zBins); bin++) {
0066       const double edge =
0067           m_cfg.zMin + bin * ((m_cfg.zMax - m_cfg.zMin) / zBins);
0068       zValues.push_back(edge);
0069     }
0070   } else {
0071     // Use the zBinEdges defined in the m_cfg
0072     zValues.reserve(m_cfg.zBinEdges.size());
0073     for (float bin : m_cfg.zBinEdges) {
0074       zValues.push_back(bin);
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   ZAxisType zAxis(AxisOpen, std::move(zValues));
0088   RAxisType rAxis(AxisOpen, std::move(rValues));
0089 
0090   ACTS_VERBOSE("Defining Grid:");
0091   ACTS_VERBOSE("- Phi Axis: " << phiAxis);
0092   ACTS_VERBOSE("- Z axis  : " << zAxis);
0093   ACTS_VERBOSE("- R axis  : " << rAxis);
0094 
0095   GridType grid(
0096       std::make_tuple(std::move(phiAxis), std::move(zAxis), 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 CylindricalSpacePointGrid::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> CylindricalSpacePointGrid::insert(
0111     SpacePointIndex index, float phi, float z, float r) {
0112   const std::optional<std::size_t> gridIndex = binIndex(phi, z, 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 CylindricalSpacePointGrid::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 CylindricalSpacePointGrid::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> CylindricalSpacePointGrid::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 }  // namespace Acts