Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-13 09:21:18

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