Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
NavBinnedArray1D.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 // NavBinnedArray1D.h, (c) ATLAS Detector software
8 
9 #ifndef TRKDETDESCRUTILS_NAVBINNEDARRAY1D_H
10 #define TRKDETDESCRUTILS_NAVBINNEDARRAY1D_H
11 
13 
14 // STL
15 #include <vector>
16 #include <memory>
17 
18 class MsgStream;
19 
20 namespace Trk {
21 
34 template<class T>
36 {
37 
38 public:
39  // defaults, copy assignment can not be defaulted (CachedPtr)
40  NavBinnedArray1D() = default;
43  ~NavBinnedArray1D() = default;
44 
49  NavBinnedArray1D(const std::vector<std::shared_ptr<T>>& tclassvector,
50  const BinUtility& bingen, const Amg::Transform3D& transform)
51  : BinnedArray<T>(),
52  m_array{tclassvector},
53  m_arrayObjects(nullptr),
54  m_binUtility(bingen),
56 
59  std::vector<std::shared_ptr<T>>&& vec,
60  const Amg::Transform3D& shift)
61  : BinnedArray<T>()
62  , m_array(std::move(vec))
63  , m_arrayObjects{}
64  , m_binUtility(barr.m_binUtility)
65  , m_transf(Amg::Transform3D(shift * (barr.m_transf)))
66  {}
67 
70  : BinnedArray<T>()
71  , m_array{barr.m_array}
72  , m_arrayObjects(nullptr)
73  , m_binUtility(barr.m_binUtility)
74  , m_transf(barr.m_transf)
75  {
76  }
77 
80  {
81  if (this != &barr) {
82  m_arrayObjects.release();
84  // --------------------------------------------------------------------------
85  m_array = (barr.m_array);
86  m_transf = barr.m_transf;
87  }
88  return *this;
89  }
90 
92  NavBinnedArray1D* clone() const { return new NavBinnedArray1D(*this); }
93 
97  T* object(const Amg::Vector2D& lp) const
98  {
99  if (m_binUtility.inside(lp)) {
100  return (m_array[m_binUtility.bin(lp)]).get();
101  }
102  return nullptr;
103  }
107  T* object(const Amg::Vector3D& gp) const
108  {
109  // transform into navig.coordinates
110  const Amg::Vector3D navGP((m_transf.inverse()) * gp);
111  if (m_binUtility.inside(navGP)) {
112  return (m_array[m_binUtility.bin(navGP)]).get();
113  }
114  return nullptr;
115  }
116 
119  T* entryObject(const Amg::Vector3D&) const { return (m_array[0]).get(); }
120 
123  T* nextObject(const Amg::Vector3D& gp,
124  const Amg::Vector3D& mom,
125  bool associatedResult = true) const
126  {
127  // transform into navig.coordinates
128  const Amg::Vector3D navGP((m_transf.inverse()) * gp);
129  const Amg::Vector3D navMom((m_transf.inverse()).linear() * mom);
130  // the bins
131  size_t firstBin = m_binUtility.next(navGP, navMom, 0);
132  // use the information of the associated result
133  if (associatedResult) {
134  if (firstBin <= m_binUtility.max(0)) {
135  return (m_array[firstBin]).get();
136  } else {
137  return nullptr;
138  }
139  }
140  // the associated result was 0 -> set to boundary
141  firstBin = (firstBin < m_binUtility.bins(0))
142  ? firstBin
143  : m_binUtility.max(0);
144  return (m_array[m_binUtility.bin(navGP)]).get();
145  }
146 
149  {
151  return BinnedArraySpan<T* const>(&*(m_arrayObjects->begin()), &*(m_arrayObjects->end()));
152  }
153 
156  {
158  return BinnedArraySpan<T const * const>(&*(m_arrayObjects->begin()), &*(m_arrayObjects->end()));
159  }
160 
162  unsigned int arrayObjectsNumber() const { return arrayObjects().size(); }
163 
165  const BinUtility* binUtility() const { return &m_binUtility; }
166 
168  const Amg::Transform3D* transform() const { return &m_transf; }
169 
172  {
174  }
175 
176 private:
177  void createArrayCache() const
178  {
179  if (!m_arrayObjects) {
180  auto arrayObjects = std::make_unique<std::vector<T*>>();
181  for (unsigned int ill = 0; ill < m_array.size(); ++ill) {
182  arrayObjects->push_back((m_array[ill]).get());
183  }
184  m_arrayObjects.set(std::move(arrayObjects));
185  }
186  }
187 
189  std::vector<std::shared_ptr<T>> m_array;
194  // !< transform into local navigation coordinates
196 };
197 
198 } // end of namespace Trk
199 
200 #endif // TRKDETDESCRUTILS_NAVBINNEDARRAY1D_H
Trk::NavBinnedArray1D::operator=
NavBinnedArray1D & operator=(NavBinnedArray1D &&)=default
Trk::NavBinnedArray1D::m_binUtility
BinUtility m_binUtility
Definition: NavBinnedArray1D.h:193
Trk::NavBinnedArray1D::arrayObjectsNumber
unsigned int arrayObjectsNumber() const
Number of Entries in the Array.
Definition: NavBinnedArray1D.h:162
Trk::BinUtility::max
size_t max(size_t ba=0) const
First bin maximal value.
Definition: BinUtility.h:212
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
Trk::NavBinnedArray1D::m_array
std::vector< std::shared_ptr< T > > m_array
1D vector of cached not owning pointers to class T
Definition: NavBinnedArray1D.h:189
CxxUtils::CachedUniquePtrT
Cached pointer with atomic update.
Definition: CachedUniquePtr.h:54
BinUtility.h
Trk::NavBinnedArray1D::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: NavBinnedArray1D.h:123
Trk::NavBinnedArray1D::object
T * object(const Amg::Vector2D &lp) const
Returns the pointer to the templated class object from the BinnedArray, it returns nullptr if not def...
Definition: NavBinnedArray1D.h:97
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:9
Trk::NavBinnedArray1D::transform
const Amg::Transform3D * transform() const
Return the transform.
Definition: NavBinnedArray1D.h:168
Trk::NavBinnedArray1D::binUtility
const BinUtility * binUtility() const
Return the BinUtility.
Definition: NavBinnedArray1D.h:165
Trk::NavBinnedArray1D::NavBinnedArray1D
NavBinnedArray1D(const NavBinnedArray1D &barr)
Copy Constructor.
Definition: NavBinnedArray1D.h:69
Trk::BinUtility::bins
size_t bins(size_t ba=0) const
Number of bins.
Definition: BinUtility.h:221
Trk::NavBinnedArray1D::NavBinnedArray1D
NavBinnedArray1D(const std::vector< std::shared_ptr< T >> &tclassvector, const BinUtility &bingen, const Amg::Transform3D &transform)
Constructor with std::vector and a BinUtility - reference counted, will delete objects at the end,...
Definition: NavBinnedArray1D.h:49
Trk::NavBinnedArray1D::m_transf
Amg::Transform3D m_transf
Definition: NavBinnedArray1D.h:195
Trk::NavBinnedArray1D::m_arrayObjects
CxxUtils::CachedUniquePtr< std::vector< T * > > m_arrayObjects
binUtility for retrieving and filling the Array
Definition: NavBinnedArray1D.h:191
Trk::NavBinnedArray1D::arrayObjects
BinnedArraySpan< T const *const > arrayObjects() const
Return all objects of the Array const T.
Definition: NavBinnedArray1D.h:155
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Trk::NavBinnedArray1D::object
T * object(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray it returns nullptr if not defi...
Definition: NavBinnedArray1D.h:107
columnar::final
CM final
Definition: ColumnAccessor.h:106
Trk::BinUtility
Definition: BinUtility.h:39
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:186
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::NavBinnedArray1D::arrayObjects
BinnedArraySpan< T *const > arrayObjects()
Return all objects of the Array non-const T.
Definition: NavBinnedArray1D.h:148
Trk::NavBinnedArray1D::NavBinnedArray1D
NavBinnedArray1D(NavBinnedArray1D &&)=default
Trk::NavBinnedArray1D::NavBinnedArray1D
NavBinnedArray1D(const NavBinnedArray1D &barr, std::vector< std::shared_ptr< T >> &&vec, const Amg::Transform3D &shift)
Copy Constructor with shift.
Definition: NavBinnedArray1D.h:58
Trk::NavBinnedArray1D::operator=
NavBinnedArray1D & operator=(const NavBinnedArray1D &barr)
Assignment operator.
Definition: NavBinnedArray1D.h:79
Trk::NavBinnedArray1D
Definition: NavBinnedArray1D.h:36
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
Trk::NavBinnedArray1D::updateTransform
void updateTransform(Amg::Transform3D &transform)
Reposition.
Definition: NavBinnedArray1D.h:171
Trk::NavBinnedArray1D::NavBinnedArray1D
NavBinnedArray1D()=default
Trk::NavBinnedArray1D::entryObject
T * entryObject(const Amg::Vector3D &) const
Returns the pointer to the templated class object from the BinnedArray - entry point.
Definition: NavBinnedArray1D.h:119
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:126
Trk::BinnedArray
Definition: BinnedArray.h:38
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:145
Trk::NavBinnedArray1D::clone
NavBinnedArray1D * clone() const
Implicit Constructor.
Definition: NavBinnedArray1D.h:92
Trk::NavBinnedArray1D::~NavBinnedArray1D
~NavBinnedArray1D()=default
Trk::NavBinnedArray1D::createArrayCache
void createArrayCache() const
vector of pointers to the class T
Definition: NavBinnedArray1D.h:177