ATLAS Offline Software
CompactBinnedArray1D.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // CompactBinnedArray1D.h, (c) ATLAS Detector software
8 
9 #ifndef TRKDETDESCRUTILS_COMPACTBINNEDARRAY1D_H
10 #define TRKDETDESCRUTILS_COMPACTBINNEDARRAY1D_H
11 
14 
15 // STL
16 #include <vector>
17 
18 class MsgStream;
19 
20 namespace Trk {
21 
31 template<class T>
33 {
34 
35 public:
38  : CompactBinnedArray<T>()
39  , m_binUtility(nullptr)
40  {}
41 
43  CompactBinnedArray1D(const std::vector<T*>& tclassvector,
44  const std::vector<size_t>& indexvector,
45  BinUtility* bingen)
46  : CompactBinnedArray<T>()
47  , m_array(indexvector)
48  , m_arrayObjects(tclassvector)
49  , m_binUtility(bingen)
50  {
51  // check compatibility
52  // size of the index vector must correspond to the number of bins in the
53  // BinUtility
54  if (indexvector.size() != bingen->bins())
55  std::cout << " problem in construction of CompactBinnedArray1D: number "
56  "of indexes not compatible with BinUtility:"
57  << indexvector.size() << "!=" << bingen->bins() << std::endl;
58  // maximal index must stay within the range of available objects
59  unsigned int iMax = 0;
60  for (unsigned int i = 0; i < indexvector.size(); i++)
61  if (indexvector[i] > iMax)
62  iMax = indexvector[i];
63  if (iMax > tclassvector.size() - 1)
64  std::cout
65  << " problem in construction of CompactBinnedArray1D:runaway index:"
66  << iMax << "," << tclassvector.size() << std::endl;
67  }
68 
71  : CompactBinnedArray<T>()
72  , m_binUtility(nullptr)
73  {
74  m_binUtility = (barr.m_binUtility) ? barr.m_binUtility->clone() : 0;
75 
76  m_array = barr.m_array;
78  }
81  {
82  if (this != &barr) {
83 
84  delete m_binUtility;
85  // now refill
86  m_binUtility = (barr.m_binUtility) ? barr.m_binUtility->clone() : 0;
87  // --------------------------------------------------------------------------
88  if (m_binUtility) {
89  m_array = barr.m_array;
91  }
92  }
93  return *this;
94  }
97  {
98  return new CompactBinnedArray1D(
100  }
101 
102  CompactBinnedArray1D* clone(const std::vector<T*>& ptrs) const
103  {
104  assert(ptrs.size() == m_arrayObjects.size());
105  return new CompactBinnedArray1D(ptrs, m_array, m_binUtility->clone());
106  }
107 
110 
114  T* object(const Amg::Vector2D& lp) const
115  {
116  if (m_binUtility->inside(lp))
117  return m_arrayObjects[m_array[m_binUtility->bin(lp, 0)]];
118  return nullptr;
119  }
120 
124  T* object(const Amg::Vector3D& gp) const
125  {
126  if (m_binUtility)
127  return m_arrayObjects[m_array[m_binUtility->bin(gp, 0)]];
128  return nullptr;
129  }
130 
133  T* entryObject(const Amg::Vector3D& gp) const
134  {
135  if (m_binUtility)
136  return (m_arrayObjects[m_array[m_binUtility->entry(gp, 0)]]);
137  return nullptr;
138  }
139 
142  T* nextObject(const Amg::Vector3D& gp,
143  const Amg::Vector3D& mom,
144  bool associatedResult = true) const
145  {
146  if (!m_binUtility)
147  return nullptr;
148  // the bins
149  size_t bin = associatedResult ? m_binUtility->bin(gp, 0)
150  : m_binUtility->next(gp, mom, 0);
151  return m_arrayObjects[m_array[bin]];
152  }
153 
156  {
158  m_arrayObjects.data() + m_arrayObjects.size());
159  }
160 
163  {
165  m_arrayObjects.data() + m_arrayObjects.size());
166  }
167 
169  unsigned int arrayObjectsNumber() const { return m_arrayObjects.size(); }
170 
172  const BinUtility* binUtility() const { return (m_binUtility); }
173 
176  {
177  return (m_binUtility);
178  }
179 
181  size_t layerBin(const Amg::Vector3D& pos) const
182  {
183  return (m_binUtility->bin(pos));
184  }
185 
186 private:
187  std::vector<size_t> m_array;
188  std::vector<T*> m_arrayObjects;
190 };
191 
192 } // end of namespace Trk
193 
194 #endif // TRKDETDESCRUTILS_COMPACTBINNEDARRAY1D_H
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
CompactBinnedArray.h
Trk::CompactBinnedArray1D::binUtility
const BinUtility * binUtility() const
Return the BinUtility.
Definition: CompactBinnedArray1D.h:172
Trk::CompactBinnedArray1D::m_binUtility
BinUtility * m_binUtility
binUtility
Definition: CompactBinnedArray1D.h:189
Trk::CompactBinnedArray1D::arrayObjects
BinnedArraySpan< T const *const > arrayObjects() const
Return all objects of the Array const T.
Definition: CompactBinnedArray1D.h:162
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
BinUtility.h
bin
Definition: BinsDiffFromStripMedian.h:43
Trk::CompactBinnedArray1D::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: CompactBinnedArray1D.h:114
Trk::CompactBinnedArray1D::arrayObjectsNumber
unsigned int arrayObjectsNumber() const
Number of Entries in the Array.
Definition: CompactBinnedArray1D.h:169
Trk::CompactBinnedArray
Definition: CompactBinnedArray.h:31
Trk::CompactBinnedArray1D::layerBin
size_t layerBin(const Amg::Vector3D &pos) const
Return the layer bin.
Definition: CompactBinnedArray1D.h:181
Trk::BinUtility::bins
size_t bins(size_t ba=0) const
Number of bins.
Definition: BinUtility.h:223
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
lumiFormat.i
int i
Definition: lumiFormat.py:85
Trk::CompactBinnedArray1D::m_arrayObjects
std::vector< T * > m_arrayObjects
objects
Definition: CompactBinnedArray1D.h:188
Trk::CompactBinnedArray1D::arrayObjects
BinnedArraySpan< T *const > arrayObjects()
Return all objects of the Array non const T.
Definition: CompactBinnedArray1D.h:155
Trk::CompactBinnedArray1D::~CompactBinnedArray1D
~CompactBinnedArray1D()
Virtual Destructor.
Definition: CompactBinnedArray1D.h:109
Trk::CompactBinnedArray1D::CompactBinnedArray1D
CompactBinnedArray1D(const CompactBinnedArray1D &barr)
Copy Constructor - copies only pointers !
Definition: CompactBinnedArray1D.h:70
Trk::CompactBinnedArray1D::CompactBinnedArray1D
CompactBinnedArray1D()
Default Constructor - needed for inherited classes.
Definition: CompactBinnedArray1D.h:37
Trk::CompactBinnedArray1D::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: CompactBinnedArray1D.h:142
Trk::BinUtility
Definition: BinUtility.h:39
Trk::CompactBinnedArray1D::CompactBinnedArray1D
CompactBinnedArray1D(const std::vector< T * > &tclassvector, const std::vector< size_t > &indexvector, BinUtility *bingen)
Constructor with std::vector and a BinUtility.
Definition: CompactBinnedArray1D.h:43
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
Trk::CompactBinnedArray1D::m_array
std::vector< size_t > m_array
vector of indices to objects
Definition: CompactBinnedArray1D.h:187
Trk::CompactBinnedArray1D::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: CompactBinnedArray1D.h:124
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::CompactBinnedArray1D::clone
CompactBinnedArray1D * clone(const std::vector< T * > &ptrs) const
Definition: CompactBinnedArray1D.h:102
Trk::CompactBinnedArray1D::clone
CompactBinnedArray1D * clone() const
Implicit Constructor.
Definition: CompactBinnedArray1D.h:96
Trk::BinUtility::clone
BinUtility * clone() const
Implizit Constructor.
Definition: BinUtility.h:130
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::CompactBinnedArray1D::layerBinUtility
const BinUtility * layerBinUtility(const Amg::Vector3D &) const
Return the BinUtility.
Definition: CompactBinnedArray1D.h:175
Trk::CompactBinnedArray1D
Definition: CompactBinnedArray1D.h:33
Trk::CompactBinnedArray1D::operator=
CompactBinnedArray1D & operator=(const CompactBinnedArray1D &barr)
Assignment operator.
Definition: CompactBinnedArray1D.h:80
Trk::BinnedArraySpan
std::span< T > BinnedArraySpan
Definition: BinnedArray.h:34
Trk::CompactBinnedArray1D::entryObject
T * entryObject(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray - entry point.
Definition: CompactBinnedArray1D.h:133
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