ATLAS Offline Software
Loading...
Searching...
No Matches
CompactBinnedArray2D.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
18class MsgStream;
19
20namespace Trk {
21
29
30template<class T>
32{
33
34public:
35
36 //Rule of 0 for default ctors
37
39 CompactBinnedArray2D(const std::vector<T*>& tclassvector,
40 const std::vector<std::vector<size_t>>& indexarray,
41 const BinUtility& bingen,
42 const std::vector<Trk::BinUtility>& bVec)
43 : CompactBinnedArray<T>(),
44 m_array(indexarray),
45 m_arrayObjects(tclassvector),
46 m_binUtility(bingen),
47 m_buVec(bVec) {}
48
49 CompactBinnedArray2D(const std::vector<T*>& tclassvector,
50 std::vector<std::vector<size_t>>&& indexarray,
51 BinUtility&& bingen, std::vector<Trk::BinUtility>&& bVec)
52 : CompactBinnedArray<T>(),
53 m_array(std::move(indexarray)),
54 m_arrayObjects(tclassvector),
55 m_binUtility(std::move(bingen)),
56 m_buVec(std::move(bVec)) {}
57
58
64
65 CompactBinnedArray2D* clone(const std::vector<T*>& ptrs) const
66 {
67 assert(ptrs.size() == m_arrayObjects.size());
69 }
70
74 T* object(const Amg::Vector2D& lp) const
75 {
76 if (m_binUtility.inside(lp)) {
77 size_t bin = m_binUtility.bin(lp, 0);
78 if (m_buVec[bin].inside(lp))
79 return m_arrayObjects[m_array[bin][m_buVec[bin].bin(lp, 0)]];
80 }
81 return nullptr;
82 }
83
87 T* object(const Amg::Vector3D& gp) const
88 {
89 size_t bin = m_binUtility.bin(gp);
90 size_t index = m_array[bin][m_buVec[bin].bin(gp, 0)];
91 return m_arrayObjects[index];
92 }
93
96 T* entryObject(const Amg::Vector3D& gp) const
97 {
98 size_t bin = m_binUtility.bin(gp);
99 size_t biNext = m_binUtility.entry(gp, 0);
100 return (m_arrayObjects[m_array[biNext][m_buVec[bin].entry(gp, 0)]]);
101 }
102
106 const Amg::Vector3D& mom,
107 bool associatedResult = true) const
108 {
109 // search in layer utility only
110 size_t bin = m_binUtility.bin(gp, 0);
111 size_t binSub = m_buVec[bin].next(gp, mom, 0);
112 if (associatedResult) {
113 return m_arrayObjects[m_array[bin][binSub]];
114 }
115 // evaluate distance
116 std::pair<int, float> ds = m_binUtility.distanceToNext(gp, mom, 0);
117 std::pair<int, float> dl = m_buVec[bin].distanceToNext(gp, mom, 0);
118 // the bins
119 if (dl.second < ds.second){
120 return m_arrayObjects[m_array[bin][binSub]];
121 }
122 bin = m_binUtility.next(gp, mom, 0);
123 Amg::Vector3D probe = gp + (ds.second) * mom.normalized();
124 binSub = m_buVec[bin].bin(probe, 0);
125 return m_arrayObjects[m_array[bin][binSub]];
126 }
127
129 std::span<T* const> arrayObjects()
130 {
131 return std::span<T* const>(m_arrayObjects.begin(), m_arrayObjects.end());
132 }
133
134
136 std::span<T const * const> arrayObjects() const
137 {
138 return std::span<const T* const>(m_arrayObjects.begin(), m_arrayObjects.end());
139 }
140
142 unsigned int arrayObjectsNumber() const { return m_arrayObjects.size(); }
143
145 const BinUtility* binUtility() const { return &m_binUtility; }
146
148 const BinUtility* layerBinUtility(const Amg::Vector3D& pos) const
149 {
150 return &(m_buVec[m_binUtility.bin(pos)]);
151 }
152
154 size_t layerBin(const Amg::Vector3D& pos) const
155 {
156 return (layerBinUtility(pos)->bin(pos));
157 }
158
159private:
160 std::vector<std::vector<size_t>> m_array{};
161 std::vector<T*> m_arrayObjects{};
163 std::vector<BinUtility> m_buVec{};
164};
165
166} // end of namespace Trk
167
168#endif // TRKDETDESCRUTILS_COMPACTBINNEDARRAY2D_H
A generic symmetric BinUtility, for fully symmetric binning in terms of binning grid and binning type...
Definition BinUtility.h:39
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 arguments.
CompactBinnedArray2D * clone(const std::vector< T * > &ptrs) const
size_t layerBin(const Amg::Vector3D &pos) const
Return the layer bin.
std::vector< BinUtility > m_buVec
vector of bin utilities for 2nd dim
const BinUtility * layerBinUtility(const Amg::Vector3D &pos) const
Return the BinUtility.
const BinUtility * binUtility() const
Return the BinUtility.
T * object(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray it returns nullptr if not defi...
T * entryObject(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray - entry point.
unsigned int arrayObjectsNumber() const
Number of Entries in the Array.
std::span< T const *const > arrayObjects() const
Return all objects of the Array const T.
CompactBinnedArray2D * clone() const
Implicit Constructor.
std::vector< std::vector< size_t > > m_array
vector of indices to objects
T * object(const Amg::Vector2D &lp) const
Returns the pointer to the templated class object from the BinnedArray, it returns nullptr if not def...
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.
std::vector< T * > m_arrayObjects
objects
CompactBinnedArray2D(const std::vector< T * > &tclassvector, std::vector< std::vector< size_t > > &&indexarray, BinUtility &&bingen, std::vector< Trk::BinUtility > &&bVec)
std::span< T *const > arrayObjects()
Return all objects of the Array.
BinUtility m_binUtility
binUtility
defines common utilities needed for implementation of binned material
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
Definition index.py:1
STL namespace.