Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:08

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2024 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 http://mozilla.org/MPL/2.0/.
0008 
0009 namespace Acts {
0010 
0011 template <typename grid_t>
0012 BinnedGroup<grid_t>::BinnedGroup(
0013     grid_t&& grid,
0014     const Acts::GridBinFinder<Acts::BinnedGroup<grid_t>::DIM>& bottomFinder,
0015     const Acts::GridBinFinder<Acts::BinnedGroup<grid_t>::DIM>& topFinder,
0016     std::array<std::vector<std::size_t>, Acts::BinnedGroup<grid_t>::DIM>
0017         navigation)
0018     : m_grid(std::move(grid)),
0019       m_mask(m_grid.size(true), true),
0020       m_bottomBinFinder(&bottomFinder),
0021       m_topBinFinder(&topFinder),
0022       m_bins(std::move(navigation)) {
0023   /// If navigation is not defined for all axes, then we default that to a
0024   /// std::iota from 1ul
0025   std::array<std::size_t, DIM> numLocBins = m_grid.numLocalBins();
0026   for (std::size_t i(0ul); i < DIM; ++i) {
0027     if (!m_bins[i].empty()) {
0028       continue;
0029     }
0030     m_bins[i].resize(numLocBins[i]);
0031     std::iota(m_bins[i].begin(), m_bins[i].end(), 1ul);
0032   }
0033 }
0034 
0035 template <typename grid_t>
0036 BinnedGroup<grid_t>::BinnedGroup(
0037     grid_t&& grid, std::vector<bool> mask,
0038     const Acts::GridBinFinder<Acts::BinnedGroup<grid_t>::DIM>& bottomFinder,
0039     const Acts::GridBinFinder<Acts::BinnedGroup<grid_t>::DIM>& topFinder,
0040     std::array<std::vector<std::size_t>, Acts::BinnedGroup<grid_t>::DIM>
0041         navigation)
0042     : m_grid(std::move(grid)),
0043       m_mask(std::move(mask)),
0044       m_bottomBinFinder(&bottomFinder),
0045       m_topBinFinder(&topFinder),
0046       m_bins(std::move(navigation)) {
0047   // Check the elements in the mask corresponds to all the global bins in the
0048   // grid so that we can check if a global bin is masked
0049   if (m_mask.size() != m_grid.size(true)) {
0050     throw std::invalid_argument(
0051         "Provided mask does not match the grid. The number of entries must "
0052         "correspond to the number of global bins in the grid.");
0053   }
0054 
0055   /// If navigation is not defined for all axes, then we default that to a
0056   /// std::iota from 1ul
0057   std::array<std::size_t, DIM> numLocBins = m_grid.numLocalBins();
0058   for (std::size_t i(0ul); i < DIM; ++i) {
0059     if (!m_bins[i].empty()) {
0060       continue;
0061     }
0062     m_bins[i].resize(numLocBins[i]);
0063     std::iota(m_bins[i].begin(), m_bins[i].end(), 1ul);
0064   }
0065 }
0066 
0067 template <typename grid_t>
0068 const grid_t& BinnedGroup<grid_t>::grid() const {
0069   return m_grid;
0070 }
0071 
0072 template <typename grid_t>
0073 grid_t& BinnedGroup<grid_t>::grid() {
0074   return m_grid;
0075 }
0076 
0077 template <typename grid_t>
0078 const std::vector<bool>& BinnedGroup<grid_t>::mask() const {
0079   return m_mask;
0080 }
0081 
0082 template <typename grid_t>
0083 Acts::BinnedGroupIterator<grid_t> BinnedGroup<grid_t>::begin() const {
0084   return Acts::BinnedGroupIterator<grid_t>(
0085       *this, std::array<std::size_t, Acts::BinnedGroup<grid_t>::DIM>(), m_bins);
0086 }
0087 
0088 template <typename grid_t>
0089 Acts::BinnedGroupIterator<grid_t> BinnedGroup<grid_t>::end() const {
0090   std::array<std::size_t, Acts::BinnedGroup<grid_t>::DIM> endline{};
0091   for (std::size_t i(0ul); i < Acts::BinnedGroup<grid_t>::DIM; ++i) {
0092     endline[i] = m_bins[i].size();
0093   }
0094   return Acts::BinnedGroupIterator<grid_t>(*this, endline, m_bins);
0095 }
0096 
0097 }  // namespace Acts