ATLAS Offline Software
Loading...
Searching...
No Matches
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"
6namespace Trk {
7
8inline bool
9Surface::operator!=(const Surface& sf) const
10{
11 return !((*this) == sf);
12}
13
14inline const Amg::Transform3D*
15Surface::cachedTransform() const
16{
17 return ((m_transforms) ? &(m_transforms->transform) : nullptr);
18}
19
20inline const Amg::Transform3D&
21Surface::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
35inline const Amg::Vector3D&
36Surface::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
50inline const Amg::Vector3D&
51Surface::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
67inline Amg::Vector2D
68Surface::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
83inline double
84Surface::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 */
93template<class T>
94bool
95Surface::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
106inline Amg::Vector3D
107Surface::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
115inline Amg::Vector3D
116Surface::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
125inline Amg::Vector3D
126Surface::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
135inline Amg::Vector3D
136Surface::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
144inline std::unique_ptr<Surface>
145Surface::uniqueClone() const
146{
147 return std::unique_ptr<Surface>(clone());
148}
149
150// common to all surfaces, uses memory optized method
151inline std::optional<Amg::Vector2D>
152Surface::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
161inline std::optional<Amg::Vector2D>
162Surface::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
173inline Amg::Vector3D
174Surface::normal(const Amg::Vector2D&) const
175{
176 return Amg::Vector3D(normal());
177}
178
179inline const Amg::Vector3D&
180Surface::globalReferencePoint() const
181{
182 return center();
183}
184
185inline const TrkDetElementBase*
186Surface::associatedDetectorElement() const
187{
188 return m_associatedDetElement;
189}
190
191inline Identifier
192Surface::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
201inline const Trk::Layer*
202Surface::associatedLayer() const
203{
204 return (m_associatedLayer);
205}
206
207inline const Trk::MaterialLayer*
208Surface::materialLayer() const
209{
210 return m_materialLayer.get();
211}
212
213inline Trk::MaterialLayer*
214Surface::materialLayer()
215{
216 return m_materialLayer.get();
217}
218
219inline const Surface*
220Surface::baseSurface() const
221{
222 return (this);
223}
224
225inline bool
226Surface::isActive() const
227{
228 return (m_associatedDetElement != nullptr);
229}
230
231inline bool
232Surface::isFree() const
233{
234 return (m_owner == Trk::noOwn);
235}
236
237inline void
238Surface::setTransform(const Amg::Transform3D& trans)
239{
240 m_transforms = std::make_unique<Transforms>(trans);
241}
242
243inline void
244Surface::setOwner(SurfaceOwner x)
245{
246 m_owner = x;
247}
248
249inline SurfaceOwner
250Surface::owner() const
251{
252 return m_owner;
253}
254
255inline void
256Surface::setMaterialLayer(std::shared_ptr<MaterialLayer> mlay)
257{
258 m_materialLayer = std::move(mlay);
259}
260
261inline void
262Surface::associateLayer(const Layer& lay)
263{
264 m_associatedLayer = (&lay);
265}
266
267// Avoid out-of-line-eigen calls
268ATH_FLATTEN
269inline Amg::Transform3D
270Surface::inverseTransformHelper() const
271{
272 return transform().inverse();
273}
274
275// Avoid out-of-line-eigen calls
276ATH_FLATTEN
277inline Amg::Vector3D
278Surface::inverseTransformMultHelper(const Amg::Vector3D& pos) const
279{
280 return inverseTransformHelper() * pos;
281}
282
283} // end of namespace Trk
284