ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinnedSPGroup.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BinnedSPGroup.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 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 
9 #pragma once
10 
13 #include "Acts/Seeding/Seed.hpp"
16 
17 #include <memory>
18 #include <vector>
19 
20 namespace Acts {
21 
25 template <typename external_spacepoint_t>
27  public:
28  using sp_it_t = typename std::vector<std::unique_ptr<
30 
31  NeighborhoodIterator() = delete;
32 
33  NeighborhoodIterator(std::vector<size_t> indices,
35  m_grid = spgrid;
36  m_indices = indices;
37  m_curInd = 0;
38  if (m_indices.size() > m_curInd) {
39  m_curIt = std::begin(spgrid->at(m_indices[m_curInd]));
40  m_binEnd = std::end(spgrid->at(m_indices[m_curInd]));
41  }
42  }
43 
44  NeighborhoodIterator(std::vector<size_t> indices,
46  size_t curInd, sp_it_t curIt) {
47  m_grid = spgrid;
48  m_indices = indices;
49  m_curInd = curInd;
50  m_curIt = curIt;
51  if (m_indices.size() > m_curInd) {
52  m_binEnd = std::end(spgrid->at(m_indices[m_curInd]));
53  }
54  }
56  std::vector<size_t> indices,
58  auto nIt = NeighborhoodIterator<external_spacepoint_t>(indices, spgrid);
59  // advance until first non-empty bin or last bin
60  if (nIt.m_curIt == nIt.m_binEnd) {
61  ++nIt;
62  }
63  return nIt;
64  }
65 
68  m_grid = other.m_grid;
69  m_indices = other.m_indices;
70  m_curInd = other.m_curInd;
71  m_curIt = other.m_curIt;
72  m_binEnd = other.m_binEnd;
73  }
74 
75  void operator++() {
76  // if iterator of current Bin not yet at end, increase
77  if (m_curIt != m_binEnd) {
78  m_curIt++;
79  // return only if end of current bin still not reached
80  if (m_curIt != m_binEnd) {
81  return;
82  }
83  }
84  // increase bin index m_curInd until you find non-empty bin
85  // or until m_curInd >= m_indices.size()-1
86  while (m_curIt == m_binEnd && m_indices.size() - 1 > m_curInd) {
87  m_curInd++;
88  m_curIt = std::begin(m_grid->at(m_indices[m_curInd]));
89  m_binEnd = std::end(m_grid->at(m_indices[m_curInd]));
90  }
91  }
92 
94  return (*m_curIt).get();
95  }
96 
98  return m_curIt != other.m_curIt || m_curInd != other.m_curInd;
99  }
100 
101  // iterators within current bin
104  // number of bins
105  std::vector<size_t> m_indices;
106  // current bin
107  size_t m_curInd;
109 };
110 
114 template <typename external_spacepoint_t>
116  public:
117  Neighborhood() = delete;
118  Neighborhood(std::vector<size_t> indices,
120  m_indices = indices;
121  m_spgrid = spgrid;
122  }
125  m_spgrid);
126  }
129  m_indices, m_spgrid, m_indices.size() - 1,
130  std::end(m_spgrid->at(m_indices.back())));
131  }
132 
133  private:
134  std::vector<size_t> m_indices;
136 };
137 
140 template <typename external_spacepoint_t>
142  public:
144  if (zIndex < phiZbins[1]) {
145  zIndex++;
146 
147  } else {
148  zIndex = 1;
149  phiIndex++;
150  }
151  // set current & neighbor bins only if bin indices valid
152  if (phiIndex <= phiZbins[0] && zIndex <= phiZbins[1]) {
153  currentBin =
154  std::vector<size_t>{grid->globalBinFromLocalBins({phiIndex, zIndex})};
157  outputIndex++;
158  return *this;
159  }
160  phiIndex = phiZbins[0];
161  zIndex = phiZbins[1] + 1;
162  return *this;
163  }
164 
165  bool operator==(const BinnedSPGroupIterator& otherState) {
166  return (zIndex == otherState.zIndex && phiIndex == otherState.phiIndex);
167  }
168 
171  }
172 
175  }
176 
179  }
180 
182  BinFinder<external_spacepoint_t>* botBinFinder,
184  : currentBin({spgrid->globalBinFromLocalBins({1, 1})}) {
185  grid = spgrid;
186  m_bottomBinFinder = botBinFinder;
187  m_topBinFinder = tBinFinder;
188  phiZbins = grid->numLocalBins();
189  phiIndex = 1;
190  zIndex = 1;
194  }
195 
197  BinFinder<external_spacepoint_t>* botBinFinder,
199  size_t phiInd, size_t zInd)
200  : currentBin({spgrid->globalBinFromLocalBins({phiInd, zInd})}) {
201  m_bottomBinFinder = botBinFinder;
202  m_topBinFinder = tBinFinder;
203  grid = spgrid;
204  phiIndex = phiInd;
205  zIndex = zInd;
206  phiZbins = grid->numLocalBins();
207  outputIndex = (phiInd - 1) * phiZbins[1] + zInd - 1;
208  if (phiIndex <= phiZbins[0] && zIndex <= phiZbins[1]) {
211  }
212  }
213 
214  private:
215  // middle spacepoint bin
216  std::vector<size_t> currentBin;
217  std::vector<size_t> bottomBinIndices;
218  std::vector<size_t> topBinIndices;
220  size_t phiIndex = 1;
221  size_t zIndex = 1;
222  size_t outputIndex = 0;
223  std::array<long unsigned int, 2ul> phiZbins;
226 };
227 
231 template <typename external_spacepoint_t>
233  public:
234  BinnedSPGroup() = delete;
235 
236  template <typename spacepoint_iterator_t>
238  spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd,
239  std::function<Acts::Vector2D(const external_spacepoint_t&, float, float,
240  float)>
241  covTool,
242  std::shared_ptr<Acts::BinFinder<external_spacepoint_t>> botBinFinder,
243  std::shared_ptr<Acts::BinFinder<external_spacepoint_t>> tBinFinder,
244  std::unique_ptr<SpacePointGrid<external_spacepoint_t>> grid,
246 
247  size_t size() { return m_binnedSP.size(); }
248 
251  m_binnedSP.get(), m_bottomBinFinder.get(), m_topBinFinder.get());
252  }
253 
255  auto phiZbins = m_binnedSP->numLocalBins();
257  m_binnedSP.get(), m_bottomBinFinder.get(), m_topBinFinder.get(),
258  phiZbins[0], phiZbins[1] + 1);
259  }
260 
261  private:
262  // grid with ownership of all InternalSpacePoint
263  std::unique_ptr<Acts::SpacePointGrid<external_spacepoint_t>> m_binnedSP;
264 
265  // BinFinder must return std::vector<Acts::Seeding::Bin> with content of
266  // each bin sorted in r (ascending)
267  std::shared_ptr<BinFinder<external_spacepoint_t>> m_topBinFinder;
268  std::shared_ptr<BinFinder<external_spacepoint_t>> m_bottomBinFinder;
269 };
270 
271 } // namespace Acts