Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-07 07:59:08

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/Seeding2/CartesianSpacePointGrid.hpp"
0010 
0011 #include "Acts/Definitions/Common.hpp"
0012 
0013 namespace Acts {
0014 
0015 CartesianSpacePointGrid::CartesianSpacePointGrid(
0016     const Config& config, std::unique_ptr<const Logger> _logger)
0017     : m_cfg(config), m_logger(std::move(_logger)) {
0018   if (m_cfg.xMin > m_cfg.xMax) {
0019     throw std::invalid_argument(
0020         "CartesianSpacePointGrid: xMin is bigger then xMax");
0021   }
0022   if (m_cfg.yMin > m_cfg.yMax) {
0023     throw std::invalid_argument(
0024         "CartesianSpacePointGrid: yMin is bigger then yMax");
0025   }
0026   if (m_cfg.zMin > m_cfg.zMax) {
0027     throw std::invalid_argument(
0028         "CartesianSpacePointGrid: zMin is bigger than zMax");
0029   }
0030   if (m_cfg.sortingCoord == Acts::eTime) {
0031     throw std::invalid_argument(
0032         "CartesianSpacePointGrid: time is not supported as a spatial sorting "
0033         "dimension");
0034   }
0035 
0036   XAxisType xAxis(m_cfg.xMin, m_cfg.xMax, m_cfg.nXbins);
0037   YAxisType yAxis(m_cfg.yMin, m_cfg.yMax, m_cfg.nYbins);
0038   YAxisType zAxis(m_cfg.zMin, m_cfg.zMax, m_cfg.nZbins);
0039 
0040   ACTS_VERBOSE("Defining Grid:");
0041   ACTS_VERBOSE("- x Axis  : " << xAxis);
0042   ACTS_VERBOSE("- y Axis  : " << yAxis);
0043   ACTS_VERBOSE("- z Axis  : " << zAxis);
0044 
0045   GridType grid(
0046       std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis)));
0047   m_binnedGroup.emplace(std::move(grid), m_cfg.bottomBinFinder.value(),
0048                         m_cfg.topBinFinder.value(), m_cfg.navigation);
0049   m_grid = &m_binnedGroup->grid();
0050   m_sortCoordGetter = [c = m_cfg.sortingCoord, d = m_cfg.sortingDirection](
0051                           const ConstSpacePointProxy2& p) {
0052     return d * p.xyz()[c];
0053   };
0054 }
0055 
0056 void CartesianSpacePointGrid::clear() {
0057   for (std::size_t i = 0; i < grid().size(); ++i) {
0058     BinType& bin = grid().at(i);
0059     bin.clear();
0060   }
0061   m_counter = 0;
0062 }
0063 
0064 std::optional<std::size_t> CartesianSpacePointGrid::insert(
0065     SpacePointIndex index, float x, float y, float z) {
0066   const std::optional<std::size_t> gridIndex = binIndex(x, y, z);
0067   if (gridIndex.has_value()) {
0068     BinType& bin = grid().at(*gridIndex);
0069     bin.push_back(index);
0070     ++m_counter;
0071   }
0072   return gridIndex;
0073 }
0074 
0075 void CartesianSpacePointGrid::extend(
0076     const SpacePointContainer2::ConstRange& spacePoints) {
0077   ACTS_VERBOSE("Inserting " << spacePoints.size()
0078                             << " space points to the grid");
0079 
0080   for (const ConstSpacePointProxy2& sp : spacePoints) {
0081     insert(sp);
0082   }
0083 }
0084 
0085 void CartesianSpacePointGrid::sortBinsByCoord(
0086     const SpacePointContainer2& spacePoints) {
0087   ACTS_VERBOSE("Sorting the grid");
0088 
0089   for (std::size_t i = 0; i < grid().size(); ++i) {
0090     BinType& bin = grid().at(i);
0091     std::ranges::sort(bin, {}, [&](SpacePointIndex2 spIndex) {
0092       return m_sortCoordGetter(spacePoints[spIndex]);
0093     });
0094   }
0095 
0096   ACTS_VERBOSE(
0097       "Number of space points inserted (within grid range): " << m_counter);
0098 }
0099 
0100 Range1D<float> CartesianSpacePointGrid::computeCoordRange(
0101     const SpacePointContainer2& spacePoints) const {
0102   float minRange = std::numeric_limits<float>::max();
0103   float maxRange = std::numeric_limits<float>::lowest();
0104   for (const BinType& bin : grid()) {
0105     if (bin.empty()) {
0106       continue;
0107     }
0108     auto first = spacePoints[bin.front()];
0109     auto last = spacePoints[bin.back()];
0110     minRange = std::min(m_sortCoordGetter(first), minRange);
0111     maxRange = std::max(m_sortCoordGetter(last), maxRange);
0112   }
0113   return {minRange, maxRange};
0114 }
0115 
0116 }  // namespace Acts