ATLAS Offline Software
PlaneSurface.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // PlaneSurface.cxx, (c) ATLAS Detector Software
8 
9 // Trk
16 #include "TrkSurfaces/NoBounds.h"
21 // Identifier
22 #include "Identifier/Identifier.h"
23 // Gaudi
24 #include "GaudiKernel/MsgStream.h"
25 //CxxUtils
26 #include "CxxUtils/sincos.h"
27 #include "CxxUtils/inline_hints.h"
28 // STD
29 #include <iomanip>
30 #include <iostream>
31 #include <cmath>
32 
34 
35 // default constructor
37  : Trk::Surface()
38  , m_bounds(nullptr)
39 {}
40 
41 
42 // copy constructor with shift
44  : Trk::Surface(psf, transf)
45  , m_bounds(psf.m_bounds)
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 // constructor from CurvilinearUVT
56  : Trk::Surface()
57  , m_bounds(nullptr) // curvilinear surfaces are boundless
58 {
59  Amg::Translation3D curvilinearTranslation(position.x(), position.y(), position.z());
60  // create the rotation
61  Amg::RotationMatrix3D curvilinearRotation;
62  curvilinearRotation.col(0) = curvUVT.curvU();
63  curvilinearRotation.col(1) = curvUVT.curvV();
64  curvilinearRotation.col(2) = curvUVT.curvT();
66  transform = curvilinearRotation;
67  transform.pretranslate(position);
68  Trk::Surface::m_transforms = std::make_unique<Transforms>(transform);
69 }
70 
71 // construct form TrkDetElementBase
73  : Trk::Surface(detelement)
74  , m_bounds(nullptr)
75 {
76  Trk::Surface::m_transforms = std::make_unique<Transforms>(transf);
77 }
78 
79 // construct form TrkDetElementBase
81  : Trk::Surface(detelement)
82  , m_bounds(nullptr)
83 {
84  //
85 }
86 
87 // construct from SiDetectorElement
89  const Identifier& id,
90  const Amg::Transform3D & transf)
91  : Trk::Surface(detelement, id)
92  , m_bounds(nullptr)
93 {
94  Trk::Surface::m_transforms = std::make_unique<Transforms>(transf);
95 }
96 
97 // construct from SiDetectorElement
99  const Identifier& id)
100  : Trk::Surface(detelement, id)
101  , m_bounds(nullptr)
102 {
103  //
104 }
105 
106 // construct planar surface without bounds
108  : Trk::Surface(htrans)
109  , m_bounds(nullptr)
110 {}
111 
112 // construct rectangle module
113 Trk::PlaneSurface::PlaneSurface(const Amg::Transform3D & htrans, double halephi, double haleta)
114  : Trk::Surface(htrans)
115  , m_bounds(std::make_shared<Trk::RectangleBounds>(halephi, haleta))
116 {}
117 
118 // construct trapezoidal module with parameters
119 Trk::PlaneSurface::PlaneSurface(const Amg::Transform3D & htrans, double minhalephi, double maxhalephi, double haleta)
120  : Trk::Surface(htrans)
121  , m_bounds(std::make_shared<Trk::TrapezoidBounds>(minhalephi, maxhalephi, haleta))
122 {}
123 
124 // construct with bounds
126  : Trk::Surface(htrans)
127  , m_bounds(tbounds)
128 {}
129 
130 // construct module with shared boundaries
132  const Amg::Transform3D & htrans,
134  : Trk::Surface(htrans), m_bounds(tbounds) {}
135 
136 bool
138 {
139  // first check the type not to compare apples with oranges
140  if (sf.type()!=Trk::SurfaceType::Plane){
141  return false;
142  }
143  return (*this) == static_cast<const Trk::PlaneSurface&>(sf);
144 }
145 
150  double l1,
151  double l2,
152  double phi,
153  double theta,
154  double qop,
155  std::optional<AmgSymMatrix(5)> cov) const
156 {
157  return std::make_unique<ParametersT<5, Charged, PlaneSurface>>(
158  l1, l2, phi, theta, qop, *this, std::move(cov));
159 }
164  const Amg::Vector3D& position,
165  const Amg::Vector3D& momentum,
166  double charge,
167  std::optional<AmgSymMatrix(5)> cov) const
168 {
169  return std::make_unique<ParametersT<5, Charged, PlaneSurface>>(
170  position, momentum, charge, *this, std::move(cov));
171 }
172 
177  double l1,
178  double l2,
179  double phi,
180  double theta,
181  double oop,
182  std::optional<AmgSymMatrix(5)> cov) const
183 {
184  return std::make_unique<ParametersT<5, Neutral, PlaneSurface>>(
185  l1, l2, phi, theta, oop, *this, std::move(cov));
186 }
187 
192  const Amg::Vector3D& position,
193  const Amg::Vector3D& momentum,
194  double charge,
195  std::optional<AmgSymMatrix(5)> cov) const
196 {
197  return std::make_unique<ParametersT<5, Neutral, PlaneSurface>>(
198  position, momentum, charge, *this, std::move(cov));
199 }
200 
201 // Avoid out-of-line Eigen calls
203 void
205  const Amg::Vector3D&,
206  Amg::Vector3D& glopos) const
207 {
208  Amg::Vector3D loc3Dframe(locpos[Trk::locX], locpos[Trk::locY], 0.);
209  glopos = transform() * loc3Dframe;
210 }
211 
212 bool
214  const Amg::Vector3D&,
215  Amg::Vector2D& locpos) const {
216  Amg::Vector3D loc3Dframe = inverseTransformMultHelper(glopos);
217  locpos = Amg::Vector2D(loc3Dframe.x(), loc3Dframe.y());
218  return (loc3Dframe.z() * loc3Dframe.z() <=
219  s_onSurfaceTolerance * s_onSurfaceTolerance);
220 }
221 
224  const Amg::Vector3D& dir,
225  bool forceDir,
226  Trk::BoundaryCheck bchk) const {
227  double denom = dir.dot(normal());
228  if (denom) {
229  double u = (normal().dot((center() - pos))) / (denom);
230  Amg::Vector3D intersectPoint(pos + u * dir);
231  // evaluate the intersection in terms of direction
232  bool isValid = forceDir ? (u > 0.) : true;
233  // evaluate (if necessary in terms of boundaries)
234  isValid = bchk ? (isValid && isOnSurface(intersectPoint)) : isValid;
235  // return the result
236  return Trk::Intersection(intersectPoint, u, isValid);
237  }
238  return Trk::Intersection(pos, 0., false);
239 }
240 
241 void
243 {
244 
245  CxxUtils::sincos scXZ(locdir.angleXZ());
246  CxxUtils::sincos scYZ(locdir.angleYZ());
247 
248  double norm = 1. / std::sqrt(scYZ.cs * scYZ.cs * scXZ.sn * scXZ.sn + scYZ.sn * scYZ.sn);
249 
250  // decide on the sign
251  double sign = (scXZ.sn < 0.) ? -1. : 1.;
252 
253  // now calculate the GlobalDirection in the global frame
254  globdir =
255  transform().linear() *
256  Amg::Vector3D(sign * scXZ.cs * scYZ.sn * norm, sign * scXZ.sn * scYZ.cs * norm, sign * scXZ.sn * scYZ.sn * norm);
257 }
258 
259 void
261 {
262  // bring the global direction into the surface frame
263  Amg::Vector3D d(inverseTransformHelper().linear() * glodir);
264  ldir = Trk::LocalDirection(std::atan2(d.z(), d.x()), std::atan2(d.z(), d.y()));
265 }
266 
267 bool
269  const Trk::BoundaryCheck& bchk,
270  double tol1, double tol2) const
271 {
272  Amg::Vector3D loc3Dframe = inverseTransformMultHelper(glopo);
273  if (std::abs(loc3Dframe(2)) > (s_onSurfaceTolerance + tol1)){
274  return false;
275  }
276  return (bchk ? bounds().inside(Amg::Vector2D(loc3Dframe(0), loc3Dframe(1)), tol1, tol2) : true);
277 }
278 
282 {
283  static const double tol = 0.001;
284 
285  const Amg::Vector3D& N = normal();
286 
287  const double d = (pos - center()).dot(N);
288 
289  const double A = dir.dot(N); // ignore sign
290  if (A == 0.) { // direction parallel to surface
291  if (std::abs(d) < tol) {
292  return {1, 0., true, 0.};
293  }
294  return {0, d, true, 0.};
295 
296  }
297 
298  return {1, d, true, -d / A};
299 }
300 
303 {
304  const Amg::Transform3D& T = transform();
305  double Az[3] = { T(0, 2), T(1, 2), T(2, 2) };
306 
307  // Transformation to plane system coordinates
308  //
309  double dx = pos[0] - T(0, 3);
310  double dy = pos[1] - T(1, 3);
311  double dz = pos[2] - T(2, 3);
312  double z = dx * Az[0] + dy * Az[1] + dz * Az[2];
313  double az = dir[0] * Az[0] + dir[1] * Az[1] + dir[2] * Az[2];
314 
315  // Step to surface
316  //
317  int ns = 0;
318  double s = 0.;
319  if (az != 0.) {
320  s = -z / az;
321  ns = 1;
322  }
323  double dist = std::abs(z);
324  if (!bound)
325  return {ns, std::abs(z), true, s};
326 
327  // Min distance to surface
328  //
329  double x = dx * T(0, 0) + dy * T(1, 0) + dz * T(2, 0);
330  double y = dx * T(0, 1) + dy * T(1, 1) + dz * T(2, 1);
331 
332  Amg::Vector2D lp(x, y);
333 
334  double d = bounds().minDistance(lp);
335  if (d > 0.)
336  dist = std::sqrt(dist * dist + d * d);
337 
338  return {ns, dist, true, s};
339 }
Trk::PlaneSurface::operator==
virtual bool operator==(const Surface &sf) const override
Equality operator.
Definition: PlaneSurface.cxx:137
TrapezoidBounds.h
EllipseBounds.h
Trk::y
@ y
Definition: ParamDefs.h:56
Trk::PlaneSurface::globalToLocal
virtual bool globalToLocal(const Amg::Vector3D &glob, const Amg::Vector3D &mom, Amg::Vector2D &loc) const override final
Specified for PlaneSurface: GlobalToLocal method without dynamic memory allocation - boolean checks i...
Definition: PlaneSurface.cxx:213
Trk::RectangleBounds
Definition: RectangleBounds.h:38
Trk::PlaneSurface::localToGlobalDirection
void localToGlobalDirection(const Trk::LocalDirection &locdir, Amg::Vector3D &globdir) const
This method transforms a local direction wrt the plane to a global direction.
Definition: PlaneSurface.cxx:242
PlotCalibFromCool.norm
norm
Definition: PlotCalibFromCool.py:100
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
Trk::Intersection
Definition: Intersection.h:24
inline_hints.h
Trk::z
@ z
global position (cartesian)
Definition: ParamDefs.h:57
RectangleBounds.h
Trk::locX
@ locX
Definition: ParamDefs.h:37
Trk::locY
@ locY
local cartesian
Definition: ParamDefs.h:38
Trk::DistanceSolution
Definition: DistanceSolution.h:25
Trk::Surface::ChargedTrackParametersUniquePtr
std::unique_ptr< ParametersBase< 5, Trk::Charged > > ChargedTrackParametersUniquePtr
Unique ptr types.
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:125
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
hist_file_dump.d
d
Definition: hist_file_dump.py:137
Trk::SurfaceBounds
Definition: SurfaceBounds.h:47
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:201
sincos.h
Helper to simultaneously calculate sin and cos of the same angle.
Trk::Surface::NeutralTrackParametersUniquePtr
std::unique_ptr< ParametersBase< 5, Trk::Neutral > > NeutralTrackParametersUniquePtr
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:127
Trk::TrkDetElementBase
Definition: TrkDetElementBase.h:52
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
isValid
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition: AtlasPID.h:620
Trk::PlaneSurface::straightLineDistanceEstimate
virtual DistanceSolution straightLineDistanceEstimate(const Amg::Vector3D &pos, const Amg::Vector3D &dir) const override final
fast straight line distance evaluation to Surface
Definition: PlaneSurface.cxx:281
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
Trk::PlaneSurface::PlaneSurface
PlaneSurface()
Default Constructor - needed for persistency.
Definition: PlaneSurface.cxx:36
Trk::LocalDirection::angleYZ
double angleYZ() const
access method for angle of local YZ projection
Definition: LocalDirection.h:106
Trk::AmgSymMatrix
AmgSymMatrix(5) &GXFTrackState
Definition: GXFTrackState.h:156
DiamondBounds.h
A
skel.l2
l2
Definition: skel.GENtoEVGEN.py:399
Trk::Surface::m_transforms
std::unique_ptr< Transforms > m_transforms
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:436
Trk::CurvilinearUVT::curvT
const Amg::Vector3D & curvT() const
Trk::PlaneSurface::s_boundless
static const NoBounds s_boundless
Definition: PlaneSurface.h:289
CxxUtils::sincos::cs
double cs
Definition: sincos.h:94
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
AnnulusBounds.h
Trk::CurvilinearUVT::curvU
const Amg::Vector3D & curvU() const
Access methods.
ATH_FLATTEN
#define ATH_FLATTEN
Definition: inline_hints.h:52
Trk::theta
@ theta
Definition: ParamDefs.h:66
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
sign
int sign(int a)
Definition: TRT_StrawNeighbourSvc.h:107
Trk::PlaneSurface::globalToLocalDirection
void globalToLocalDirection(const Amg::Vector3D &glodir, Trk::LocalDirection &locdir) const
This method transforms the global direction to a local direction wrt the plane.
Definition: PlaneSurface.cxx:260
Trk::LocalDirection
represents the three-dimensional global direction with respect to a planar surface frame.
Definition: LocalDirection.h:81
dot.dot
def dot(G, fn, nodesToHighlight=[])
Definition: dot.py:5
compute_lumi.denom
denom
Definition: compute_lumi.py:76
beamspotman.dir
string dir
Definition: beamspotman.py:623
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:227
Trk::PlaneSurface::createUniqueTrackParameters
virtual Surface::ChargedTrackParametersUniquePtr createUniqueTrackParameters(double l1, double l2, double phi, double theta, double qop, std::optional< AmgSymMatrix(5)> cov=std::nullopt) const override final
Use the Surface as a ParametersBase constructor, from local parameters - charged.
Definition: PlaneSurface.cxx:149
charge
double charge(const T &p)
Definition: AtlasPID.h:756
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::PlaneSurface::straightLineIntersection
virtual Intersection straightLineIntersection(const Amg::Vector3D &pos, const Amg::Vector3D &dir, bool forceDir, Trk::BoundaryCheck bchk) const override final
fast straight line intersection schema - standard: provides closest intersection and (signed) path le...
Definition: PlaneSurface.cxx:223
CurvilinearUVT.h
Trk::TrapezoidBounds
Definition: TrapezoidBounds.h:43
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
CxxUtils::sincos::sn
double sn
Definition: sincos.h:91
Trk::NoBounds
Definition: NoBounds.h:30
Trk::inside
@ inside
Definition: PropDirection.h:29
makeTRTBarrelCans.dy
tuple dy
Definition: makeTRTBarrelCans.py:21
Trk::SharedObject
std::shared_ptr< T > SharedObject
Definition: SharedObject.h:24
TriangleBounds.h
Trk::PlaneSurface::createUniqueNeutralParameters
virtual NeutralTrackParametersUniquePtr createUniqueNeutralParameters(double l1, double l2, double phi, double theta, double oop, std::optional< AmgSymMatrix(5)> cov=std::nullopt) const override final
Use the Surface as a ParametersBase constructor, from local parameters - neutral.
Definition: PlaneSurface.cxx:176
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
Trk::CurvilinearUVT
Definition: CurvilinearUVT.h:45
Trk::PlaneSurface
Definition: PlaneSurface.h:64
Amg::RotationMatrix3D
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Definition: GeoPrimitives.h:49
Trk::BoundaryCheck
Definition: BoundaryCheck.h:51
Trk::CurvilinearUVT::curvV
const Amg::Vector3D & curvV() const
PlaneSurface.h
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
Amg::Translation3D
Eigen::Translation< double, 3 > Translation3D
Definition: GeoPrimitives.h:44
CxxUtils::sincos
Helper to simultaneously calculate sin and cos of the same angle.
Definition: sincos.h:76
python.SystemOfUnits.ns
int ns
Definition: SystemOfUnits.py:130
Trk::SurfaceType::Plane
@ Plane
Trk::phi
@ phi
Definition: ParamDefs.h:75
LocalDirection.h
skel.l1
l1
Definition: skel.GENtoEVGEN.py:398
Trk::LocalDirection::angleXZ
double angleXZ() const
access method for angle of local XZ projection
Definition: LocalDirection.h:103
Trk::PlaneSurface::localToGlobal
virtual void localToGlobal(const Amg::Vector2D &locp, const Amg::Vector3D &mom, Amg::Vector3D &glob) const override final
Specified for PlaneSurface: LocalToGlobal method without dynamic memory allocation.
Definition: PlaneSurface.cxx:204
Trk::x
@ x
Definition: ParamDefs.h:55
RotatedTrapezoidBounds.h
Trk::PlaneSurface::isOnSurface
virtual bool isOnSurface(const Amg::Vector3D &glopo, const BoundaryCheck &bchk=true, double tol1=0., double tol2=0.) const override final
This method returns true if the GlobalPosition is on the Surface for both, within or without check of...
Definition: PlaneSurface.cxx:268
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::Surface::transform
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
NoBounds.h
Identifier
Definition: IdentifierFieldParser.cxx:14