Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023 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 #include "Acts/Detector/detail/IndexedGridFiller.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Common.hpp"
0013 #include "Acts/Detector/detail/ReferenceGenerators.hpp"
0014 #include "Acts/Geometry/GeometryContext.hpp"
0015 #include "Acts/Geometry/Polyhedron.hpp"
0016 #include "Acts/Navigation/SurfaceCandidatesUpdaters.hpp"
0017 #include "Acts/Utilities/Delegate.hpp"
0018 #include "Acts/Utilities/Enumerate.hpp"
0019 #include "Acts/Utilities/IAxis.hpp"
0020 #include "Acts/Utilities/Logger.hpp"
0021 
0022 #include <algorithm>
0023 #include <array>
0024 #include <set>
0025 #include <string>
0026 #include <vector>
0027 
0028 std::vector<std::size_t> Acts::Experimental::detail::binSequence(
0029     std::array<std::size_t, 2u> minMaxBins, std::size_t expand,
0030     std::size_t nBins, Acts::detail::AxisBoundaryType type) {
0031   // Return vector for iterations
0032   std::vector<std::size_t> rBins;
0033   /// Helper method to fill a range
0034   ///
0035   /// @param lmin the minimum bin
0036   /// @param lmax the maximum bin
0037   auto fill_linear = [&](std::size_t lmin, std::size_t lmax) -> void {
0038     for (std::size_t b = lmin; b <= lmax; ++b) {
0039       rBins.push_back(b);
0040     }
0041   };
0042   std::size_t bmin = minMaxBins[0u];
0043   std::size_t bmax = minMaxBins[1u];
0044 
0045   // Open/Bound cases
0046   if (type != Acts::detail::AxisBoundaryType::Closed) {
0047     rBins.reserve(bmax - bmin + 1u + 2 * expand);
0048     // handle bmin:/max expand it down (for bound, don't fill underflow)
0049     if (type == Acts::detail::AxisBoundaryType::Bound) {
0050       bmin = (int(bmin) - int(expand) > 0) ? bmin - expand : 1u;
0051       bmax = (bmax + expand <= nBins) ? bmax + expand : nBins;
0052     } else if (type == Acts::detail::AxisBoundaryType::Open) {
0053       bmin = (int(bmin) - int(expand) >= 0) ? bmin - expand : 0u;
0054       bmax = (bmax + expand <= nBins + 1u) ? bmax + expand : nBins + 1u;
0055     }
0056     fill_linear(bmin, bmax);
0057   } else {
0058     // Close case
0059     std::size_t span = bmax - bmin + 1u + 2 * expand;
0060     // Safe with respect to the closure point, treat as bound
0061     if (2 * span < nBins && (bmax + expand <= nBins) &&
0062         (int(bmin) - int(expand) > 0)) {
0063       return binSequence({bmin, bmax}, expand, nBins,
0064                          Acts::detail::AxisBoundaryType::Bound);
0065     } else if (2 * span < nBins) {
0066       bmin = int(bmin) - int(expand) > 0 ? bmin - expand : 1u;
0067       bmax = bmax + expand <= nBins ? bmax + expand : nBins;
0068       fill_linear(bmin, bmax);
0069       // deal with expansions over the phi boundary
0070       if (bmax + expand > nBins) {
0071         std::size_t overstep = (bmax + expand - nBins);
0072         fill_linear(1u, overstep);
0073       }
0074       if (int(bmin) - int(expand) < 1) {
0075         std::size_t understep = abs(int(bmin) - int(expand));
0076         fill_linear(nBins - understep, nBins);
0077       }
0078       std::sort(rBins.begin(), rBins.end());
0079     } else {
0080       // Jump over the phi boundary
0081       fill_linear(bmax - expand, nBins);
0082       fill_linear(1, bmin + expand);
0083       std::sort(rBins.begin(), rBins.end());
0084     }
0085   }
0086   return rBins;
0087 }