ATLAS Offline Software
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
17 #include "CxxUtils/inline_hints.h"
18 // STD
19 #include <iomanip>
20 #include <iostream>
21 #include <utility>
22 
23 Trk::Surface::Surface() = default;
24 
28  , m_transforms(std::make_unique<Transforms>(tform))
29 {
30 }
31 
34  , m_associatedDetElement(&detelement)
35  , m_owner(Trk::DetElOwn)
36 {
37 }
38 
40  const Identifier& id)
42  , m_associatedDetElement(&detelement)
43  , m_associatedDetElementId(id)
44  , m_owner(Trk::DetElOwn)
45 {
46 }
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
58  , m_transforms(std::make_unique<Transforms>(sf.transform()))
59  , m_associatedLayer(sf.m_associatedLayer)
60  , m_materialLayer(sf.m_materialLayer)
61  , m_owner(Trk::noOwn)
62 {
63 }
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
86 Trk::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;
96  m_associatedDetElementId = Identifier();
97  m_associatedLayer = sf.m_associatedLayer;
98  m_materialLayer = sf.m_materialLayer;
99  m_owner = Trk::noOwn;
100  }
101  return *this;
102 }
103 
104 // returns the LocalPosition on a surface of a GlobalPosition
105 std::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
122 bool
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 
140 namespace {
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
156 MsgStream&
157 Trk::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;
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
184 std::ostream&
185 Trk::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;
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 
212 MsgStream&
213 Trk::operator<<(MsgStream& sl, const Trk::Surface& sf)
214 {
215  return sf.dump(sl);
216 }
217 
218 std::ostream&
219 Trk::operator<<(std::ostream& sl, const Trk::Surface& sf)
220 {
221  return sf.dump(sl);
222 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
inline_hints.h
Surface.h
Trk::noOwn
@ noOwn
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:54
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
Trk::Surface::~Surface
virtual ~Surface()
Virtual Destructor.
Trk::TrkDetElementBase
Definition: TrkDetElementBase.h:52
Trk::ObjectCounter
Helper to enable counting number of instantiations in debug builds.
Definition: TrkObjectCounter.h:18
Trk::Surface::measurementFrame
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
SurfaceBounds.h
Trk::Surface::operator=
Surface & operator=(const Surface &sf)
Definition: Surface.cxx:91
Trk::Surface::isOnSurface
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
Trk::Surface::m_transforms
std::unique_ptr< Transforms > m_transforms
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:436
ATH_FLATTEN
#define ATH_FLATTEN
Definition: inline_hints.h:52
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
dumpNswErrorDb.linear
def linear
Definition: dumpNswErrorDb.py:23
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
Trk::DetElOwn
@ DetElOwn
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:56
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:220
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Trk::Surface::Surface
Surface()
Default Constructor for inheriting classes.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::Surface::dump
virtual MsgStream & dump(MsgStream &sl) const
Output Method for MsgStream, to be overloaded by child classes.
Definition: Surface.cxx:157
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
Amg::RotationMatrix3D
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Definition: GeoPrimitives.h:49
Trk::BoundaryCheck
Definition: BoundaryCheck.h:51
Trk::operator<<
MsgStream & operator<<(MsgStream &sl, const AlignModule &alignModule)
overload of << operator for MsgStream for debug output
Definition: AlignModule.cxx:204
Trk::Surface::positionOnSurface
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
Trk::Surface::Transforms
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:84
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::Surface::transform
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
NSWL1::globalToLocal
Polygon globalToLocal(const Polygon &pol, float z, const Trk::PlaneSurface &surf)
Definition: GeoUtils.cxx:103
Identifier
Definition: IdentifierFieldParser.cxx:14