2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 #include "CxxUtils/inline_hints.h"
9 Surface::operator!=(const Surface& sf) const
11 return !((*this) == sf);
14 inline const Amg::Transform3D*
15 Surface::cachedTransform() const
17 return ((m_transforms) ? &(m_transforms->transform) : nullptr);
20 inline const Amg::Transform3D&
21 Surface::transform() const
24 return m_transforms->transform;
26 if (m_associatedDetElement && m_associatedDetElementId.is_valid()) {
27 return m_associatedDetElement->transform(m_associatedDetElementId);
29 if (m_associatedDetElement) {
30 return m_associatedDetElement->transform();
35 inline const Amg::Vector3D&
36 Surface::center() const
39 return m_transforms->center;
41 if (m_associatedDetElement && m_associatedDetElementId.is_valid()) {
42 return m_associatedDetElement->center(m_associatedDetElementId);
44 if (m_associatedDetElement) {
45 return m_associatedDetElement->center();
50 inline const Amg::Vector3D&
51 Surface::normal() const
54 return m_transforms->normal;
56 if (m_associatedDetElement && m_associatedDetElementId.is_valid()) {
57 return m_associatedDetElement->normal(m_associatedDetElementId);
59 if (m_associatedDetElement) {
60 return m_associatedDetElement->normal();
65 // standard is to set non-defined parameters to 0, but can be changed for
68 Surface::localParametersToPosition(const LocalParameters& locpars) const
70 if (locpars.contains(Trk::loc1) && locpars.contains(Trk::loc2)) {
71 return Amg::Vector2D(locpars[Trk::loc1], locpars[loc2]);
73 if (locpars.contains(Trk::loc1)) {
74 return Amg::Vector2D(locpars[Trk::loc1], 0.);
76 if (locpars.contains(Trk::loc2)) {
77 return Amg::Vector2D(0., locpars[loc2]);
79 return Amg::Vector2D(0., 0.);
82 // common to planar surfaces
84 Surface::pathCorrection(const Amg::Vector3D&, const Amg::Vector3D& mom) const
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
92 //* the templated parameters on Surface method */
95 Surface::onSurface(const T& pars, const Trk::BoundaryCheck& bcheck) const
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);
101 return isOnSurface(pars.position(), bcheck);
104 /// Local to Global implementations
105 // From Local position
107 Surface::localToGlobal(const Amg::Vector2D& locpos) const
109 Amg::Vector3D gPosition;
110 localToGlobal(locpos, Amg::Vector3D(1., 1., 1.), gPosition);
114 // From local position and momentum
116 Surface::localToGlobal(const Amg::Vector2D& locpos,
117 const Amg::Vector3D& glomom) const
119 Amg::Vector3D gPosition(0., 0., 0.);
120 localToGlobal(locpos, glomom, gPosition);
124 // From Local parameters
126 Surface::localToGlobal(const LocalParameters& locpars) const
128 Amg::Vector3D gPosition(0., 0., 0.);
130 localParametersToPosition(locpars), Amg::Vector3D(1., 1., 1.), gPosition);
134 // From Local parameters and momementum
136 Surface::localToGlobal(const LocalParameters& locpars,
137 const Amg::Vector3D& glomom) const
139 Amg::Vector3D gPosition(0., 0., 0.);
140 localToGlobal(localParametersToPosition(locpars), glomom, gPosition);
144 inline std::unique_ptr<Surface>
145 Surface::uniqueClone() const
147 return std::unique_ptr<Surface>(clone());
150 // common to all surfaces, uses memory optized method
151 inline std::optional<Amg::Vector2D>
152 Surface::globalToLocal(const Amg::Vector3D& glopos, double) const
154 Amg::Vector2D lPosition(0., 0.);
155 if (globalToLocal(glopos, Amg::Vector3D(1., 1., 1.), lPosition)) {
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
165 Amg::Vector2D lPosition(0., 0.);
166 if (globalToLocal(glopos, glomom, lPosition)) {
172 // take local position and return global direction
174 Surface::normal(const Amg::Vector2D&) const
176 return Amg::Vector3D(normal());
179 inline const Amg::Vector3D&
180 Surface::globalReferencePoint() const
185 inline const TrkDetElementBase*
186 Surface::associatedDetectorElement() const
188 return m_associatedDetElement;
192 Surface::associatedDetectorElementIdentifier() const
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();
202 Surface::associatedLayer() const
204 return (m_associatedLayer);
208 Surface::materialLayer() const
210 return m_materialLayer.get();
214 Surface::materialLayer()
216 return m_materialLayer.get();
219 inline const Surface*
220 Surface::baseSurface() const
226 Surface::isActive() const
228 return (m_associatedDetElement != nullptr);
232 Surface::isFree() const
234 return (m_owner == Trk::noOwn);
238 Surface::setTransform(const Amg::Transform3D& trans)
240 m_transforms = std::make_unique<Transforms>(trans);
244 Surface::setOwner(SurfaceOwner x)
250 Surface::owner() const
256 Surface::setMaterialLayer(std::shared_ptr<Layer> mlay)
258 m_materialLayer = mlay;
262 Surface::associateLayer(const Layer& lay)
264 m_associatedLayer = (&lay);
267 // Avoid out-of-line-eigen calls
269 inline Amg::Transform3D
270 Surface::inverseTransformHelper() const
272 return transform().inverse();
275 // Avoid out-of-line-eigen calls
278 Surface::inverseTransformMultHelper(const Amg::Vector3D& pos) const
280 return inverseTransformHelper() * pos;
283 } // end of namespace Trk