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 
169  bool operator!=(const BinnedSPGroupIterator& otherState) {
170  return !(this->operator==(otherState));
171  }
172 
175  }
176 
179  }
180 
183  }
184 
186  BinFinder<external_spacepoint_t>* botBinFinder,
188  : currentBin({spgrid->globalBinFromLocalBins({1, 1})}) {
189  grid = spgrid;
190  m_bottomBinFinder = botBinFinder;
191  m_topBinFinder = tBinFinder;
192  phiZbins = grid->numLocalBins();
193  phiIndex = 1;
194  zIndex = 1;
198  }
199 
201  BinFinder<external_spacepoint_t>* botBinFinder,
203  size_t phiInd, size_t zInd)
204  : currentBin({spgrid->globalBinFromLocalBins({phiInd, zInd})}) {
205  m_bottomBinFinder = botBinFinder;
206  m_topBinFinder = tBinFinder;
207  grid = spgrid;
208  phiIndex = phiInd;
209  zIndex = zInd;
210  phiZbins = grid->numLocalBins();
211  outputIndex = (phiInd - 1) * phiZbins[1] + zInd - 1;
212  if (phiIndex <= phiZbins[0] && zIndex <= phiZbins[1]) {
215  }
216  }
217 
218  private:
219  // middle spacepoint bin
220  std::vector<size_t> currentBin;
221  std::vector<size_t> bottomBinIndices;
222  std::vector<size_t> topBinIndices;
224  size_t phiIndex = 1;
225  size_t zIndex = 1;
226  size_t outputIndex = 0;
227  std::array<long unsigned int, 2ul> phiZbins;
230 };
231 
235 template <typename external_spacepoint_t>
237  public:
238  BinnedSPGroup() = delete;
239 
240  template <typename spacepoint_iterator_t>
242  spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd,
243  std::function<Acts::Vector2D(const external_spacepoint_t&, float, float,
244  float)>
245  covTool,
246  std::shared_ptr<Acts::BinFinder<external_spacepoint_t>> botBinFinder,
247  std::shared_ptr<Acts::BinFinder<external_spacepoint_t>> tBinFinder,
248  std::unique_ptr<SpacePointGrid<external_spacepoint_t>> grid,
250 
251  size_t size() { return m_binnedSP.size(); }
252 
255  m_binnedSP.get(), m_bottomBinFinder.get(), m_topBinFinder.get());
256  }
257 
259  auto phiZbins = m_binnedSP->numLocalBins();
261  m_binnedSP.get(), m_bottomBinFinder.get(), m_topBinFinder.get(),
262  phiZbins[0], phiZbins[1] + 1);
263  }
264 
265  private:
266  // grid with ownership of all InternalSpacePoint
267  std::unique_ptr<Acts::SpacePointGrid<external_spacepoint_t>> m_binnedSP;
268 
269  // BinFinder must return std::vector<Acts::Seeding::Bin> with content of
270  // each bin sorted in r (ascending)
271  std::shared_ptr<BinFinder<external_spacepoint_t>> m_topBinFinder;
272  std::shared_ptr<BinFinder<external_spacepoint_t>> m_bottomBinFinder;
273 };
274 
275 } // namespace Acts