Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IndexedGridFiller.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file IndexedGridFiller.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
19 #include "Acts/Utilities/IAxis.hpp"
21 
22 #include <algorithm>
23 #include <array>
24 #include <set>
25 #include <string>
26 #include <vector>
27 
28 std::vector<std::size_t> Acts::Experimental::detail::binSequence(
29  std::array<std::size_t, 2u> minMaxBins, std::size_t expand,
30  std::size_t nBins, Acts::detail::AxisBoundaryType type) {
31  // Return vector for iterations
32  std::vector<std::size_t> rBins;
37  auto fill_linear = [&](std::size_t lmin, std::size_t lmax) -> void {
38  for (std::size_t b = lmin; b <= lmax; ++b) {
39  rBins.push_back(b);
40  }
41  };
42  std::size_t bmin = minMaxBins[0u];
43  std::size_t bmax = minMaxBins[1u];
44 
45  // Open/Bound cases
46  if (type != Acts::detail::AxisBoundaryType::Closed) {
47  rBins.reserve(bmax - bmin + 1u + 2 * expand);
48  // handle bmin:/max expand it down (for bound, don't fill underflow)
49  if (type == Acts::detail::AxisBoundaryType::Bound) {
50  bmin = (int(bmin) - int(expand) > 0) ? bmin - expand : 1u;
51  bmax = (bmax + expand <= nBins) ? bmax + expand : nBins;
52  } else if (type == Acts::detail::AxisBoundaryType::Open) {
53  bmin = (int(bmin) - int(expand) >= 0) ? bmin - expand : 0u;
54  bmax = (bmax + expand <= nBins + 1u) ? bmax + expand : nBins + 1u;
55  }
56  fill_linear(bmin, bmax);
57  } else {
58  // Close case
59  std::size_t span = bmax - bmin + 1u + 2 * expand;
60  // Safe with respect to the closure point, treat as bound
61  if (2 * span < nBins and (bmax + expand <= nBins) and
62  (int(bmin) - int(expand) > 0)) {
63  return binSequence({bmin, bmax}, expand, nBins,
64  Acts::detail::AxisBoundaryType::Bound);
65  } else if (2 * span < nBins) {
66  bmin = int(bmin) - int(expand) > 0 ? bmin - expand : 1u;
67  bmax = bmax + expand <= nBins ? bmax + expand : nBins;
68  fill_linear(bmin, bmax);
69  // deal with expansions over the phi boundary
70  if (bmax + expand > nBins) {
71  std::size_t overstep = (bmax + expand - nBins);
72  fill_linear(1u, overstep);
73  }
74  if (int(bmin) - int(expand) < 1) {
75  std::size_t understep = abs(int(bmin) - int(expand));
76  fill_linear(nBins - understep, nBins);
77  }
78  std::sort(rBins.begin(), rBins.end());
79  } else {
80  // Jump over the phi boundary
81  fill_linear(bmax - expand, nBins);
82  fill_linear(1, bmin + expand);
83  std::sort(rBins.begin(), rBins.end());
84  }
85  }
86  return rBins;
87 }