ATLAS Offline Software
CompactBinnedArray2D.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // CompactBinnedArray2D.h, (c) ATLAS Detector software
8 
9 #ifndef TRKDETDESCRUTILS_COMPACTBINNEDARRAY2D_H
10 #define TRKDETDESCRUTILS_COMPACTBINNEDARRAY2D_H
11 
14 
15 // STL
16 #include <vector>
17 
18 class MsgStream;
19 
20 namespace Trk {
21 
30 template<class T>
32 {
33 
34 public:
37  : CompactBinnedArray<T>()
38  , m_binUtility(nullptr)
39  {}
40 
42  CompactBinnedArray2D(const std::vector<T*>& tclassvector,
43  const std::vector<std::vector<size_t>>& indexarray,
44  const BinUtility* bingen,
45  const std::vector<Trk::BinUtility*>& bVec)
46  : CompactBinnedArray<T>()
47  , m_array(indexarray)
48  , m_arrayObjects(tclassvector)
49  , m_binUtility(bingen)
50  , m_buVec(bVec)
51  {
52  // check compatibility
53  // size of the index array must correspond to the number of bins in the
54  // BinUtility
55  if (indexarray.size() != bingen->bins())
56  std::cout << " problem in construction of CompactBinnedArray2D: index "
57  "array not compatible with BinUtility:"
58  << indexarray.size() << "!=" << bingen->bins() << std::endl;
59  // maximal index must stay within the range of available objects
60  size_t iMax = 0;
61  for (size_t i = 0; i < indexarray.size(); i++) {
62  for (size_t j = 0; j < indexarray[i].size(); j++) {
63  if (indexarray[i][j] > iMax)
64  iMax = indexarray[i][j];
65  }
66  }
67  if (iMax > tclassvector.size() - 1)
68  std::cout
69  << " problem in construction of CompactBinnedArray2D:runaway index:"
70  << iMax << "," << tclassvector.size() << std::endl;
71  }
72 
75  : CompactBinnedArray<T>()
76  , m_array()
77  , m_arrayObjects()
78  , m_binUtility(nullptr)
79  , m_buVec()
80  {
81  m_binUtility = (barr.m_binUtility) ? barr.m_binUtility->clone() : 0;
82 
83  m_array = barr.m_array;
85  m_buVec = barr.m_buVec;
86  }
89  {
90  if (this != &barr) {
91 
92  delete m_binUtility;
93  // now refill
94  m_binUtility = (barr.m_binUtility) ? barr.m_binUtility->clone() : 0;
95  // --------------------------------------------------------------------------
96  if (m_binUtility) {
97  m_array = std::vector<std::vector<size_t>>((barr.m_array));
98  m_arrayObjects = std::vector<T*>((barr.m_arrayObjects));
99  m_buVec = std::vector<Trk::BinUtility*>((barr.m_buVec));
100  }
101  }
102  return *this;
103  }
106  {
107  return new CompactBinnedArray2D(
109  }
110 
111  CompactBinnedArray2D* clone(const std::vector<T*>& ptrs) const
112  {
113  assert(ptrs.size() == m_arrayObjects.size());
114  return new CompactBinnedArray2D(
115  ptrs, m_array, m_binUtility->clone(), m_buVec);
116  }
117 
120  {
121  delete m_binUtility;
122  for (unsigned int i = 0; i < m_buVec.size(); i++)
123  delete m_buVec[i];
124  }
125 
129  T* object(const Amg::Vector2D& lp) const
130  {
131  if (m_binUtility->inside(lp)) {
132  size_t bin = m_binUtility->bin(lp, 0);
133  if (m_buVec[bin]->inside(lp))
134  return m_arrayObjects[m_array[bin][m_buVec[bin]->bin(lp, 0)]];
135  }
136  return nullptr;
137  }
138 
142  T* object(const Amg::Vector3D& gp) const
143  {
144  if (m_binUtility) {
145  size_t bin = m_binUtility->bin(gp);
146  size_t index = m_array[bin][m_buVec[bin]->bin(gp, 0)];
147  return m_arrayObjects[index];
148  }
149  return nullptr;
150  }
151 
154  T* entryObject(const Amg::Vector3D& gp) const
155  {
156  if (m_binUtility) {
157  size_t bin = m_binUtility->bin(gp);
158  size_t biNext = m_binUtility->entry(gp, 0);
159  return (m_arrayObjects[m_array[biNext][m_buVec[bin]->entry(gp, 0)]]);
160  }
161  return nullptr;
162  }
163 
166  T* nextObject(const Amg::Vector3D& gp,
167  const Amg::Vector3D& mom,
168  bool associatedResult = true) const
169  {
170  if (!m_binUtility)
171  return nullptr;
172  // search in layer utility only
173  size_t bin = m_binUtility->bin(gp, 0);
174  size_t binSub = m_buVec[bin]->next(gp, mom, 0);
175  if (associatedResult) {
176  return m_arrayObjects[m_array[bin][binSub]];
177  }
178  // evaluate distance
179  std::pair<int, float> ds = m_binUtility->distanceToNext(gp, mom, 0);
180  std::pair<int, float> dl = m_buVec[bin]->distanceToNext(gp, mom, 0);
181  // the bins
182  if (dl.second < ds.second)
183  return m_arrayObjects[m_array[bin][binSub]];
184 
185  bin = m_binUtility->next(gp, mom, 0);
186  Amg::Vector3D probe = gp + (ds.second) * mom.normalized();
187  binSub = m_buVec[bin]->bin(probe, 0);
188  return m_arrayObjects[m_array[bin][binSub]];
189  }
190 
193  {
195  m_arrayObjects.data() + m_arrayObjects.size());
196  }
197 
198 
201  {
203  m_arrayObjects.data() + m_arrayObjects.size());
204  }
205 
207  unsigned int arrayObjectsNumber() const { return m_arrayObjects.size(); }
208 
210  const BinUtility* binUtility() const { return (m_binUtility); }
211 
214  {
215  return (m_buVec[m_binUtility->bin(pos)]);
216  }
217 
219  size_t layerBin(const Amg::Vector3D& pos) const
220  {
221  return (layerBinUtility(pos)->bin(pos));
222  }
223 
224 private:
225  std::vector<std::vector<size_t>> m_array;
226  std::vector<T*> m_arrayObjects;
228  std::vector<BinUtility*> m_buVec;
229 };
230 
231 } // end of namespace Trk
232 
233 #endif // TRKDETDESCRUTILS_COMPACTBINNEDARRAY2D_H
Trk::CompactBinnedArray2D::object
T * object(const Amg::Vector2D &lp) const
Returns the pointer to the templated class object from the BinnedArray, it returns 0 if not defined;.
Definition: CompactBinnedArray2D.h:129
Trk::CompactBinnedArray2D::binUtility
const BinUtility * binUtility() const
Return the BinUtility.
Definition: CompactBinnedArray2D.h:210
Trk::BinUtility::entry
size_t entry(const Amg::Vector3D &position, size_t ba=0) const
Bin from a 3D vector (already in binning frame)
Definition: BinUtility.h:145
checkxAOD.ds
ds
Definition: Tools/PyUtils/bin/checkxAOD.py:260
TestSUSYToolsAlg.dl
dl
Definition: TestSUSYToolsAlg.py:81
Trk::CompactBinnedArray2D::m_binUtility
const BinUtility * m_binUtility
binUtility
Definition: CompactBinnedArray2D.h:227
Trk::CompactBinnedArray2D::object
T * object(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray it returns 0 if not defined;.
Definition: CompactBinnedArray2D.h:142
Trk::CompactBinnedArray2D::nextObject
T * nextObject(const Amg::Vector3D &gp, const Amg::Vector3D &mom, bool associatedResult=true) const
Returns the pointer to the templated class object from the BinnedArray.
Definition: CompactBinnedArray2D.h:166
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
index
Definition: index.py:1
Trk::CompactBinnedArray2D::arrayObjects
BinnedArraySpan< T const *const > arrayObjects() const
Return all objects of the Array const T.
Definition: CompactBinnedArray2D.h:200
Trk::CompactBinnedArray2D::m_buVec
std::vector< BinUtility * > m_buVec
vector of bin utilities for 2nd dim
Definition: CompactBinnedArray2D.h:228
BinnedArray.h
BinUtility.h
Trk::BinUtility::distanceToNext
std::pair< size_t, float > distanceToNext(const Amg::Vector3D &position, const Amg::Vector3D &direction, size_t ba=0) const
Distance estimate to next bin
Definition: BinUtility.h:161
bin
Definition: BinsDiffFromStripMedian.h:43
Trk::CompactBinnedArray2D::clone
CompactBinnedArray2D * clone(const std::vector< T * > &ptrs) const
Definition: CompactBinnedArray2D.h:111
Trk::CompactBinnedArray2D::clone
CompactBinnedArray2D * clone() const
Implicit Constructor.
Definition: CompactBinnedArray2D.h:105
Trk::CompactBinnedArray
Definition: CompactBinnedArray.h:31
Trk::BinUtility::bins
size_t bins(size_t ba=0) const
Number of bins.
Definition: BinUtility.h:223
Trk::CompactBinnedArray2D
Definition: CompactBinnedArray2D.h:32
Trk::CompactBinnedArray2D::entryObject
T * entryObject(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray - entry point.
Definition: CompactBinnedArray2D.h:154
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
Trk::CompactBinnedArray2D::layerBinUtility
const BinUtility * layerBinUtility(const Amg::Vector3D &pos) const
Return the BinUtility.
Definition: CompactBinnedArray2D.h:213
lumiFormat.i
int i
Definition: lumiFormat.py:85
Trk::CompactBinnedArray2D::m_arrayObjects
std::vector< T * > m_arrayObjects
objects
Definition: CompactBinnedArray2D.h:226
Trk::CompactBinnedArray2D::operator=
CompactBinnedArray2D & operator=(const CompactBinnedArray2D &barr)
Assignment operator.
Definition: CompactBinnedArray2D.h:88
Trk::CompactBinnedArray2D::arrayObjectsNumber
unsigned int arrayObjectsNumber() const
Number of Entries in the Array.
Definition: CompactBinnedArray2D.h:207
Trk::CompactBinnedArray2D::~CompactBinnedArray2D
~CompactBinnedArray2D()
Virtual Destructor.
Definition: CompactBinnedArray2D.h:119
Trk::BinUtility
Definition: BinUtility.h:39
Trk::CompactBinnedArray2D::CompactBinnedArray2D
CompactBinnedArray2D()
Default Constructor - needed for inherited classes.
Definition: CompactBinnedArray2D.h:36
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::BinUtility::inside
bool inside(const Amg::Vector3D &position) const
Check if bin is inside from Vector3D.
Definition: BinUtility.h:190
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::CompactBinnedArray2D::CompactBinnedArray2D
CompactBinnedArray2D(const CompactBinnedArray2D &barr)
Copy Constructor - copies only pointers !
Definition: CompactBinnedArray2D.h:74
Trk::inside
@ inside
Definition: PropDirection.h:29
Trk::CompactBinnedArray2D::layerBin
size_t layerBin(const Amg::Vector3D &pos) const
Return the layer bin.
Definition: CompactBinnedArray2D.h:219
DeMoScan.index
string index
Definition: DeMoScan.py:364
Trk::CompactBinnedArray2D::CompactBinnedArray2D
CompactBinnedArray2D(const std::vector< T * > &tclassvector, const std::vector< std::vector< size_t >> &indexarray, const BinUtility *bingen, const std::vector< Trk::BinUtility * > &bVec)
Constructor with std::vector and a BinUtility.
Definition: CompactBinnedArray2D.h:42
Trk::BinUtility::clone
BinUtility * clone() const
Implizit Constructor.
Definition: BinUtility.h:130
Trk::CompactBinnedArray2D::m_array
std::vector< std::vector< size_t > > m_array
vector of indices to objects
Definition: CompactBinnedArray2D.h:225
Trk::BinUtility::bin
size_t bin(const Amg::Vector3D &position, size_t ba=0) const
Bin from a 3D vector (already in binning frame)
Definition: BinUtility.h:136
Trk::BinnedArraySpan
std::span< T > BinnedArraySpan
Definition: BinnedArray.h:34
Trk::BinUtility::next
size_t next(const Amg::Vector3D &position, const Amg::Vector3D &direction, size_t ba=0) const
Bin from a 3D vector (already in binning frame)
Definition: BinUtility.h:153
Trk::CompactBinnedArray2D::arrayObjects
BinnedArraySpan< T *const > arrayObjects()
Return all objects of the Array.
Definition: CompactBinnedArray2D.h:192