Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinnedArrayXD.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BinnedArrayXD.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2018 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 // BinnedArrayXD.h, Acts project
12 
13 #pragma once
16 
17 #include <array>
18 #include <iostream>
19 #include <vector>
20 
21 class MsgStream;
22 
23 namespace Acts {
24 
33 template <class T>
34 class BinnedArrayXD : public BinnedArray<T> {
36  using TAP = std::pair<T, Vector3>;
37 
38  public:
42  BinnedArrayXD(T object)
43  : BinnedArray<T>(),
45  1, std::vector<std::vector<T>>(1, std::vector<T>(1, nullptr))),
46  m_arrayObjects({object}),
47  m_binUtility(nullptr) {
49  m_objectGrid[0][0][0] = object;
50  }
51 
57  BinnedArrayXD(const std::vector<TAP>& tapvector,
58  std::unique_ptr<const BinUtility> bu)
59  : BinnedArray<T>(),
60  m_objectGrid(bu->bins(2),
61  std::vector<std::vector<T>>(
62  bu->bins(1), std::vector<T>(bu->bins(0), nullptr))),
64  m_binUtility(std::move(bu)) {
66  m_arrayObjects.reserve(tapvector.size());
68  for (auto& tap : tapvector) {
70  if (m_binUtility->inside(tap.second)) {
71  // butil to the array store - if the bingen
72  // dimension is smaller 1,2 it will provide 0
73  auto bins = m_binUtility->binTriple(tap.second);
75  m_objectGrid[bins[2]][bins[1]][bins[0]] = tap.first;
77  if (std::find(m_arrayObjects.begin(), m_arrayObjects.end(),
78  tap.first) == m_arrayObjects.end()) {
79  m_arrayObjects.push_back(tap.first);
80  }
81  }
82  }
83  }
84 
89  BinnedArrayXD(const std::vector<std::vector<std::vector<T>>>& grid,
90  std::unique_ptr<const BinUtility> bu)
91  : BinnedArray<T>(),
94  m_binUtility(std::move(bu)) {
95  // get the total dimension
96  size_t objects =
97  m_binUtility->bins(0) * m_binUtility->bins(1) * m_binUtility->bins(2);
99  m_arrayObjects.reserve(objects);
101  for (auto& o2 : m_objectGrid) {
102  for (auto& o1 : o2) {
103  for (auto& o0 : o1) {
104  if (o0) {
106  if (std::find(m_arrayObjects.begin(), m_arrayObjects.end(), o0) ==
107  m_arrayObjects.end()) {
108  m_arrayObjects.push_back(o0);
109  }
110  }
111  }
112  }
113  }
114  }
115 
118  BinnedArrayXD(const BinnedArrayXD<T>& barr) = delete;
119 
122  BinnedArrayXD& operator=(const BinnedArrayXD<T>& barr) = delete;
123 
125  ~BinnedArrayXD() override = default;
134  T object(const Vector2& lposition, std::array<size_t, 3>& bins) const final {
135  if (m_binUtility) {
136  size_t bdim = m_binUtility->dimensions();
137  bins[2] = bdim > 2 ? m_binUtility->bin(lposition, 2) : 0;
138  bins[1] = bdim > 1 ? m_binUtility->bin(lposition, 1) : 0;
139  bins[0] = m_binUtility->bin(lposition, 0);
140  return m_objectGrid[bins[2]][bins[1]][bins[0]];
141  }
142  return m_objectGrid[0][0][0];
143  }
144 
145  // satisfy overload / override
146  T object(const Vector2& lposition) const override {
147  std::array<size_t, 3> bins{};
148  return object(lposition, bins);
149  }
150 
157  T object(const Vector3& position, std::array<size_t, 3>& bins) const final {
158  if (m_binUtility) {
159  size_t bdim = m_binUtility->dimensions();
160  bins[2] = bdim > 2 ? m_binUtility->bin(position, 2) : 0;
161  bins[1] = bdim > 1 ? m_binUtility->bin(position, 1) : 0;
162  bins[0] = m_binUtility->bin(position, 0);
163  return m_objectGrid[bins[2]][bins[1]][bins[0]];
164  }
165  return m_objectGrid[0][0][0];
166  }
167 
168  // satisfy overload / override
169  T object(const Vector3& position) const override {
170  std::array<size_t, 3> bins{};
171  return object(position, bins);
172  }
173 
176  const std::vector<T>& arrayObjects() const final { return m_arrayObjects; }
177 
181  const std::vector<std::vector<std::vector<T>>>& objectGrid() const final {
182  return m_objectGrid;
183  }
184 
187  const BinUtility* binUtility() const final { return (m_binUtility.get()); }
188 
189  private:
191  std::vector<std::vector<std::vector<T>>> m_objectGrid;
193  std::vector<T> m_arrayObjects;
195  std::unique_ptr<const BinUtility> m_binUtility;
196 };
197 } // end of namespace Acts