ATLAS Offline Software
Surface.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "CxxUtils/inline_hints.h"
6 namespace Trk {
7 
8 inline bool
9 Surface::operator!=(const Surface& sf) const
10 {
11  return !((*this) == sf);
12 }
13 
14 inline const Amg::Transform3D*
15 Surface::cachedTransform() const
16 {
17  return ((m_transforms) ? &(m_transforms->transform) : nullptr);
18 }
19 
20 inline const Amg::Transform3D&
21 Surface::transform() const
22 {
23  if (m_transforms) {
24  return m_transforms->transform;
25  }
26  if (m_associatedDetElement && m_associatedDetElementId.is_valid()) {
27  return m_associatedDetElement->transform(m_associatedDetElementId);
28  }
29  if (m_associatedDetElement) {
30  return m_associatedDetElement->transform();
31  }
32  return s_idTransform;
33 }
34 
35 inline const Amg::Vector3D&
36 Surface::center() const
37 {
38  if (m_transforms) {
39  return m_transforms->center;
40  }
41  if (m_associatedDetElement && m_associatedDetElementId.is_valid()) {
42  return m_associatedDetElement->center(m_associatedDetElementId);
43  }
44  if (m_associatedDetElement) {
45  return m_associatedDetElement->center();
46  }
47  return s_origin;
48 }
49 
50 inline const Amg::Vector3D&
51 Surface::normal() const
52 {
53  if (m_transforms) {
54  return m_transforms->normal;
55  }
56  if (m_associatedDetElement && m_associatedDetElementId.is_valid()) {
57  return m_associatedDetElement->normal(m_associatedDetElementId);
58  }
59  if (m_associatedDetElement) {
60  return m_associatedDetElement->normal();
61  }
62  return s_zAxis;
63 }
64 
65 // standard is to set non-defined parameters to 0, but can be changed for
66 // surface type
67 inline Amg::Vector2D
68 Surface::localParametersToPosition(const LocalParameters& locpars) const
69 {
70  if (locpars.contains(Trk::loc1) && locpars.contains(Trk::loc2)) {
71  return Amg::Vector2D(locpars[Trk::loc1], locpars[loc2]);
72  }
73  if (locpars.contains(Trk::loc1)) {
74  return Amg::Vector2D(locpars[Trk::loc1], 0.);
75  }
76  if (locpars.contains(Trk::loc2)) {
77  return Amg::Vector2D(0., locpars[loc2]);
78  }
79  return Amg::Vector2D(0., 0.);
80 }
81 
82 // common to planar surfaces
83 inline double
84 Surface::pathCorrection(const Amg::Vector3D&, const Amg::Vector3D& mom) const
85 {
86  Amg::Vector3D dir(mom.unit());
87  double cosAlpha = dir.dot(normal());
88  return (cosAlpha != 0 ? std::abs(1. / cosAlpha)
89  : 1.); // ST undefined for cosAlpha=0
90 }
91 
92 //* the templated parameters on Surface method */
93 template<class T>
94 bool
95 Surface::onSurface(const T& pars, const Trk::BoundaryCheck& bcheck) const
96 {
97  // surface pointer comparison as a first fast check (w/o transform)
98  if ((&pars.associatedSurface() == this)) {
99  return (bcheck ? insideBoundsCheck(pars.localPosition(), bcheck) : true);
100  }
101  return isOnSurface(pars.position(), bcheck);
102 }
103 
104 /// Local to Global implementations
105 // From Local position
106 inline Amg::Vector3D
107 Surface::localToGlobal(const Amg::Vector2D& locpos) const
108 {
109  Amg::Vector3D gPosition;
110  localToGlobal(locpos, Amg::Vector3D(1., 1., 1.), gPosition);
111  return gPosition;
112 }
113 
114 // From local position and momentum
115 inline Amg::Vector3D
116 Surface::localToGlobal(const Amg::Vector2D& locpos,
117  const Amg::Vector3D& glomom) const
118 {
119  Amg::Vector3D gPosition(0., 0., 0.);
120  localToGlobal(locpos, glomom, gPosition);
121  return gPosition;
122 }
123 
124 // From Local parameters
125 inline Amg::Vector3D
126 Surface::localToGlobal(const LocalParameters& locpars) const
127 {
128  Amg::Vector3D gPosition(0., 0., 0.);
129  localToGlobal(
130  localParametersToPosition(locpars), Amg::Vector3D(1., 1., 1.), gPosition);
131  return gPosition;
132 }
133 
134 // From Local parameters and momementum
135 inline Amg::Vector3D
136 Surface::localToGlobal(const LocalParameters& locpars,
137  const Amg::Vector3D& glomom) const
138 {
139  Amg::Vector3D gPosition(0., 0., 0.);
140  localToGlobal(localParametersToPosition(locpars), glomom, gPosition);
141  return gPosition;
142 }
143 
144 inline std::unique_ptr<Surface>
145 Surface::uniqueClone() const
146 {
147  return std::unique_ptr<Surface>(clone());
148 }
149 
150 // common to all surfaces, uses memory optized method
151 inline std::optional<Amg::Vector2D>
152 Surface::globalToLocal(const Amg::Vector3D& glopos, double) const
153 {
154  Amg::Vector2D lPosition(0., 0.);
155  if (globalToLocal(glopos, Amg::Vector3D(1., 1., 1.), lPosition)) {
156  return lPosition;
157  }
158  return std::nullopt;
159 }
160 // common to all surfaces, uses memory optized method
161 inline std::optional<Amg::Vector2D>
162 Surface::globalToLocal(const Amg::Vector3D& glopos,
163  const Amg::Vector3D& glomom) const
164 {
165  Amg::Vector2D lPosition(0., 0.);
166  if (globalToLocal(glopos, glomom, lPosition)) {
167  return lPosition;
168  }
169  return std::nullopt;
170 }
171 
172 // take local position and return global direction
173 inline Amg::Vector3D
174 Surface::normal(const Amg::Vector2D&) const
175 {
176  return Amg::Vector3D(normal());
177 }
178 
179 inline const Amg::Vector3D&
180 Surface::globalReferencePoint() const
181 {
182  return center();
183 }
184 
185 inline const TrkDetElementBase*
186 Surface::associatedDetectorElement() const
187 {
188  return m_associatedDetElement;
189 }
190 
191 inline Identifier
192 Surface::associatedDetectorElementIdentifier() const
193 {
194  if (!m_associatedDetElement)
195  return Identifier(); // in invalid state
196  if (m_associatedDetElementId.is_valid())
197  return m_associatedDetElementId;
198  return m_associatedDetElement->identify();
199 }
200 
201 inline const Layer*
202 Surface::associatedLayer() const
203 {
204  return (m_associatedLayer);
205 }
206 
207 inline const Layer*
208 Surface::materialLayer() const
209 {
210  return m_materialLayer.get();
211 }
212 
213 inline Layer*
214 Surface::materialLayer()
215 {
216  return m_materialLayer.get();
217 }
218 
219 inline const Surface*
220 Surface::baseSurface() const
221 {
222  return (this);
223 }
224 
225 inline bool
226 Surface::isActive() const
227 {
228  return (m_associatedDetElement != nullptr);
229 }
230 
231 inline bool
232 Surface::isFree() const
233 {
234  return (m_owner == Trk::noOwn);
235 }
236 
237 inline void
238 Surface::setTransform(const Amg::Transform3D& trans)
239 {
240  m_transforms = std::make_unique<Transforms>(trans);
241 }
242 
243 inline void
244 Surface::setOwner(SurfaceOwner x)
245 {
246  m_owner = x;
247 }
248 
249 inline SurfaceOwner
250 Surface::owner() const
251 {
252  return m_owner;
253 }
254 
255 inline void
256 Surface::setMaterialLayer(std::shared_ptr<Layer> mlay)
257 {
258  m_materialLayer = mlay;
259 }
260 
261 inline void
262 Surface::associateLayer(const Layer& lay)
263 {
264  m_associatedLayer = (&lay);
265 }
266 
267 // Avoid out-of-line-eigen calls
268 ATH_FLATTEN
269 inline Amg::Transform3D
270 Surface::inverseTransformHelper() const
271 {
272  return transform().inverse();
273 }
274 
275 // Avoid out-of-line-eigen calls
276 ATH_FLATTEN
277 inline Amg::Vector3D
278 Surface::inverseTransformMultHelper(const Amg::Vector3D& pos) const
279 {
280  return inverseTransformHelper() * pos;
281 }
282 
283 } // end of namespace Trk
284