ATLAS Offline Software
Loading...
Searching...
No Matches
Surface.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6// Surface.cxx, (c) ATLAS Detector Software
8
9// Trk
10#include "TrkSurfaces/Surface.h"
12
13// Gaudi
14#include "GaudiKernel/MsgStream.h"
15
16//CxxUtils
18// STD
19#include <iomanip>
20#include <iostream>
21#include <utility>
22
23Trk::Surface::Surface() = default;
24
28 , m_transforms(std::make_unique<Transforms>(tform))
29{
30}
31
38
47
48// We compile this function with optimization, even in debug builds; otherwise,
49// the heavy use of Eigen makes it too slow. However, from here we may call
50// to out-of-line Eigen code that is linked from other DSOs; in that case,
51// it would not be optimized. Avoid this by forcing all Eigen code
52// to be inlined here if possible.
54// copy constructor - Attention! sets the associatedDetElement to 0 and the
55// identifier to invalid
64
65// We compile this function with optimization, even in debug builds; otherwise,
66// the heavy use of Eigen makes it too slow. However, from here we may call
67// to out-of-line Eigen code that is linked from other DSOs; in that case,
68// it would not be optimized. Avoid this by forcing all Eigen code
69// to be inlined here if possible.
71// copy constructor with shift - Attention! sets the associatedDetElement to 0
72// and the identifier to invalid also invalidates the material layer
75 , m_owner(Trk::noOwn)
76{
77 if (sf.m_transforms) {
78 m_transforms = std::make_unique<Transforms>(
79 shift * sf.m_transforms->transform, shift * sf.m_transforms->center);
80 } else {
81 m_transforms = std::make_unique<Transforms>(Amg::Transform3D(shift));
82 }
83}
84
85// destructor
86Trk::Surface::~Surface() = default;
87
88// assignment operator
89// the assigned surfaces loses its link to the detector element
92{
93 if (this != &sf) {
94 m_transforms = std::make_unique<Transforms>(sf.transform());
95 m_associatedDetElement = nullptr;
97 m_associatedLayer = sf.m_associatedLayer;
98 m_materialLayer = sf.m_materialLayer;
100 }
101 return *this;
102}
103
104// returns the LocalPosition on a surface of a GlobalPosition
105std::optional<Amg::Vector2D>
107 const BoundaryCheck& bchk,
108 double tol1,
109 double tol2) const
110{
111 std::optional<Amg::Vector2D> posOnSurface = globalToLocal(glopo, tol1);
112 if (!bchk){
113 return posOnSurface;
114 }
115 if (posOnSurface && insideBounds(*posOnSurface, tol1, tol2)){
116 return posOnSurface;
117 }
118 return std::nullopt;
119}
120
121// checks if GlobalPosition is on Surface and inside bounds
122bool
124 const BoundaryCheck& bchk,
125 double tol1,
126 double tol2) const
127{
128 std::optional<Amg::Vector2D> posOnSurface =
129 positionOnSurface(glopo, bchk, tol1, tol2);
130 return static_cast<bool>(posOnSurface);
131}
132
133// return the measurement frame
136{
137 return transform().linear();
138}
139
140namespace {
141 bool checkTransform(const Trk::Surface &surface) {
142 Amg::RotationMatrix3D rot = surface.transform().rotation();
143 Amg::RotationMatrix3D lin = surface.transform().linear();
144 if (rot.cols() != lin.cols() || rot.rows() != lin.rows()) return false;
145 bool ret=true;
146 for (unsigned int col_i=0; col_i<rot.cols(); ++col_i){
147 for (unsigned int row_i=0; row_i<rot.rows(); ++row_i){
148 ret &= (std::abs( rot(row_i,col_i) - lin(row_i,col_i))<1e-5);
149 }
150 }
151 return ret;
152 }
153}
154
155// overload dump for MsgStream operator
156MsgStream&
157Trk::Surface::dump(MsgStream& sl) const
158{
159 sl << std::setiosflags(std::ios::fixed);
160 sl << std::setprecision(4);
161 sl << name() << std::endl;
162 if (associatedDetectorElement()!=nullptr){
163 sl<<" Detector Type = "<<associatedDetectorElement()->detectorTypeString()<<std::endl;
164 }
165 sl << " Center position (x, y, z) = (" << center().x() << ", " << center().y() << ", " << center().z() << ")"
166 << std::endl;
167 Amg::RotationMatrix3D rot(transform().linear());
168 Amg::Vector3D rotX(rot.col(0));
169 Amg::Vector3D rotY(rot.col(1));
170 Amg::Vector3D rotZ(rot.col(2));
171 sl << std::setprecision(6);
172 sl << " Rotation: colX = (" << rotX(0) << ", " << rotX(1) << ", " << rotX(2) << ")" << std::endl;
173 sl << " colY = (" << rotY(0) << ", " << rotY(1) << ", " << rotY(2) << ")" << std::endl;
174 sl << " colZ = (" << rotZ(0) << ", " << rotZ(1) << ", " << rotZ(2) << ")" << std::endl;
175 sl << " Bounds : " << bounds();
176 if (!checkTransform(*this)) {
177 sl << std::endl << " NOT a strict rotation matrix." << std::endl;
178 }
179 sl << std::setprecision(-1);
180 return sl;
181}
182
183// overload dump for MsgStream operator
184std::ostream&
185Trk::Surface::dump(std::ostream& sl) const
186{
187 sl << std::setiosflags(std::ios::fixed);
188 sl << std::setprecision(4);
189 sl << name() << std::endl;
190 if (associatedDetectorElement()!=nullptr){
191 sl<<" Detector Type = "<<associatedDetectorElement()->detectorTypeString()<<std::endl;
192 }
193 sl << " Center position (x, y, z) = (" << center().x() << ", " << center().y() << ", " << center().z() << ")"
194 << std::endl;
195 Amg::RotationMatrix3D rot(transform().linear());
196 Amg::Vector3D rotX(rot.col(0));
197 Amg::Vector3D rotY(rot.col(1));
198 Amg::Vector3D rotZ(rot.col(2));
199 sl << std::setprecision(6);
200 sl << " Rotation: colX = (" << rotX(0) << ", " << rotX(1) << ", " << rotX(2) << ")" << std::endl;
201 sl << " colY = (" << rotY(0) << ", " << rotY(1) << ", " << rotY(2) << ")" << std::endl;
202 sl << " colZ = (" << rotZ(0) << ", " << rotZ(1) << ", " << rotZ(2) << ")" << std::endl;
203 sl << " Bounds : " << bounds();
204 if (!checkTransform(*this)) {
205 sl << std::endl << " NOT a strict rotation matrix." << std::endl;
206 }
207 sl << std::setprecision(-1);
208 return sl;
209}
210
212MsgStream&
213Trk::operator<<(MsgStream& sl, const Trk::Surface& sf)
214{
215 return sf.dump(sl);
216}
217
218std::ostream&
219Trk::operator<<(std::ostream& sl, const Trk::Surface& sf)
220{
221 return sf.dump(sl);
222}
The BoundaryCheck class allows to steer the way surface boundaries are used for inside/outside checks...
Abstract Base Class for tracking surfaces.
Surface & operator=(const Surface &sf)
Definition Surface.cxx:91
virtual bool globalToLocal(const Amg::Vector3D &glob, const Amg::Vector3D &mom, Amg::Vector2D &loc) const =0
Specified by each surface type: GlobalToLocal method without dynamic memory allocation - boolean chec...
virtual bool insideBounds(const Amg::Vector2D &locpos, double tol1=0., double tol2=0.) const =0
virtual methods to be overwritten by the inherited surfaces
const TrkDetElementBase * associatedDetectorElement() const
return associated Detector Element
SurfaceOwner m_owner
enum for surface owner : default free surface
std::shared_ptr< MaterialLayer > m_materialLayer
Possibility to attach a material description to the surface.
virtual Amg::RotationMatrix3D measurementFrame(const Amg::Vector3D &glopos, const Amg::Vector3D &glomom) const
Return the measurement frame - this is needed for alignment, in particular for StraightLine and Perig...
Definition Surface.cxx:135
const TrkDetElementBase * m_associatedDetElement
Not owning Pointer to the Detector Element.
const Layer * m_associatedLayer
The associated layer Trk::Layer This is the layer in which the Surface is embedded.
virtual MsgStream & dump(MsgStream &sl) const
Output Method for MsgStream, to be overloaded by child classes.
Definition Surface.cxx:157
virtual ~Surface()
Virtual Destructor.
Surface()
Default Constructor for inheriting classes.
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
Identifier m_associatedDetElementId
Identifier to the Detector Element.
std::unique_ptr< Transforms > m_transforms
Unique Pointer to the Transforms struct.
virtual bool isOnSurface(const Amg::Vector3D &glopo, const BoundaryCheck &bchk=true, double tol1=0., double tol2=0.) const
This method returns true if the GlobalPosition is on the Surface for both, within or without check of...
Definition Surface.cxx:123
virtual const SurfaceBounds & bounds() const =0
Surface Bounds method.
const Amg::Vector3D & center() const
Returns the center position of the Surface.
virtual std::string name() const =0
Return properly formatted class name.
std::optional< Amg::Vector2D > positionOnSurface(const Amg::Vector3D &glopo, const BoundaryCheck &bchk=true, double tol1=0., double tol2=0.) const
positionOnSurface() returns the LocalPosition on the Surface, If BoundaryCheck==false it just return...
Definition Surface.cxx:106
This is the base class for all tracking detector elements with read-out relevant information.
#define ATH_FLATTEN
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
MsgStream & operator<<(MsgStream &sl, const AlignModule &alignModule)
overload of << operator for MsgStream for debug output
STL namespace.