ATLAS Offline Software
Loading...
Searching...
No Matches
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
18class MsgStream;
19
20namespace Trk {
21
33
34template<class T>
35class NavBinnedArray1D final : public BinnedArray<T>
36{
37
38public:
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))
65 , m_transf(Amg::Transform3D(shift * (barr.m_transf)))
66 {}
67
70 : BinnedArray<T>()
71 , m_array{barr.m_array}
72 , m_arrayObjects(nullptr)
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 }
104
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
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
148 std::span<T* const> arrayObjects()
149 {
151 return std::span<T* const>(m_arrayObjects->begin(),m_arrayObjects->end());
152 }
153
155 std::span<T const * const> arrayObjects() const
156 {
158 return std::span<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
175
176private:
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
std::vector< size_t > vec
Eigen::Affine3d Transform3D
A generic symmetric BinUtility, for fully symmetric binning in terms of binning grid and binning type...
Definition BinUtility.h:39
BinnedArray()=default
NavBinnedArray1D & operator=(const NavBinnedArray1D &barr)
Assignment operator.
unsigned int arrayObjectsNumber() const
Number of Entries in the Array.
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 * object(const Amg::Vector2D &lp) const
Returns the pointer to the templated class object from the BinnedArray, it returns nullptr if not def...
std::span< T const *const > arrayObjects() const
Return all objects of the Array const T.
NavBinnedArray1D(NavBinnedArray1D &&)=default
NavBinnedArray1D & operator=(NavBinnedArray1D &&)=default
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,...
void createArrayCache() const
vector of pointers to the class T
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::span< T *const > arrayObjects()
Return all objects of the Array non-const T.
void updateTransform(Amg::Transform3D &transform)
Reposition.
Amg::Transform3D m_transf
NavBinnedArray1D * clone() const
Implicit Constructor.
~NavBinnedArray1D()=default
std::vector< std::shared_ptr< T > > m_array
1D vector of cached not owning pointers to class T
NavBinnedArray1D(const NavBinnedArray1D &barr, std::vector< std::shared_ptr< T > > &&vec, const Amg::Transform3D &shift)
Copy Constructor with shift.
const Amg::Transform3D * transform() const
Return the transform.
NavBinnedArray1D()=default
T * entryObject(const Amg::Vector3D &) const
Returns the pointer to the templated class object from the BinnedArray - entry point.
CxxUtils::CachedUniquePtr< std::vector< T * > > m_arrayObjects
binUtility for retrieving and filling the Array
NavBinnedArray1D(const NavBinnedArray1D &barr)
Copy Constructor.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130
Definition of ATLAS Math & Geometry primitives (Amg)
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
CachedUniquePtrT< const T > CachedUniquePtr
Ensure that the ATLAS eigen extensions are properly loaded.
STL namespace.