ATLAS Offline Software
Loading...
Searching...
No Matches
StraightLineSurface.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// StraightLineSurface.cxx, (c) ATLAS Detector Software
8
9// Trk
12// Identifier
13#include "Identifier/Identifier.h"
14// CxxUtils
16// Gaudi
17#include "GaudiKernel/MsgStream.h"
18// STD
19#include <iomanip>
20#include <iostream>
21
23
24// default constructor
30
31// constructors by arguments: boundless surface
37
38// constructors by arguments
40 const Amg::Transform3D& htrans,
41 double radius,
42 double halez)
43 : Surface(htrans)
45 , m_bounds(std::make_shared<const Trk::CylinderBounds>(radius, halez))
46{}
47
48// dummy implementation
50 const Trk::TrkDetElementBase& detelement,
51 const Identifier& id)
52 : Surface(detelement, id)
54 , m_bounds(nullptr)
55{}
56
57// copy constructor
64
65// copy constructor with shift
67 const StraightLineSurface& csf,
68 const Amg::Transform3D& transf)
69 : Surface(csf, transf)
71 , m_bounds(csf.m_bounds)
72{}
73
74// assignment operator
77{
78 if (this != &slsf) {
81 m_bounds = slsf.m_bounds;
82 }
83 return *this;
84}
85
86bool
88{
89 // first check the type not to compare apples with oranges
90 if (sf.type()!=Trk::SurfaceType::Line){
91 return false;
92 }
93 return (*this) == static_cast<const Trk::StraightLineSurface&>(sf);
94}
95
100 double l1, double l2, double phi, double theta, double qop,
101 std::optional<AmgSymMatrix(5)> cov) const {
102 return std::make_unique<ParametersT<5, Charged, StraightLineSurface>>(
103 l1, l2, phi, theta, qop, *this, std::move(cov));
104}
105
109 const Amg::Vector3D& position, const Amg::Vector3D& momentum, double charge,
110 std::optional<AmgSymMatrix(5)> cov) const {
111 return std::make_unique<ParametersT<5, Charged, StraightLineSurface>>(
112 position, momentum, charge, *this, std::move(cov));
113}
114
119 double l1, double l2, double phi, double theta, double qop,
120 std::optional<AmgSymMatrix(5)> cov) const {
121 return std::make_unique<ParametersT<5, Neutral, StraightLineSurface>>(
122 l1, l2, phi, theta, qop, *this, std::move(cov));
123}
124
129 const Amg::Vector3D& position, const Amg::Vector3D& momentum, double charge,
130 std::optional<AmgSymMatrix(5)> cov) const {
131 return std::make_unique<ParametersT<5, Neutral, StraightLineSurface>>(
132 position, momentum, charge, *this, std::move(cov));
133}
134
135// true local to global method - fully defined
136//Avoid out-of-line eigen calls
138void
140 const Amg::Vector3D& glomom,
141 Amg::Vector3D& glopos) const
142{
143 // get the vector perpenticular to the momentum and the straw axis
144 Amg::Vector3D radiusAxisGlobal(lineDirection().cross(glomom));
145 Amg::Vector3D locZinGlobal = transform() * Amg::Vector3D(0., 0., locpos[Trk::locZ]);
146 // transform zPosition into global coordinates and add locR * radiusAxis
147 glopos = Amg::Vector3D(locZinGlobal + locpos[Trk::locR] * radiusAxisGlobal.normalized());
148}
149
150
153 const Amg::Vector3D& glomom,
154 double locZ) const
155{
156 // create a local Position
157 Amg::Vector2D locPos(locpars[Trk::driftRadius], locZ);
158 return Surface::localToGlobal(locPos, glomom);
159}
160
161
162// true global to local method - fully defined
163bool
165 const Amg::Vector3D& glomom,
166 Amg::Vector2D& locpos) const
167{
168 Amg::Vector3D loc3Dframe = inverseTransformMultHelper(glopos);
169 // construct localPosition with sign*candidate.perp() and z.()
170 locpos = Amg::Vector2D(loc3Dframe.perp(), loc3Dframe.z());
171 Amg::Vector3D decVec(glopos - center());
172 // assign the right sign
173 double sign = ((lineDirection().cross(glomom)).dot(decVec) < 0.) ? -1. : 1.;
174 locpos[Trk::locR] *= sign;
175 return true;
176}
177
178#if defined(FLATTEN)
179// We compile this function with optimization, even in debug builds; otherwise,
180// the heavy use of Eigen makes it too slow. However, from here we may call
181// to out-of-line Eigen code that is linked from other DSOs; in that case,
182// it would not be optimized. Avoid this by forcing all Eigen code
183// to be inlined here if possible.
185#endif
186// isOnSurface check
187bool
189 const BoundaryCheck& bchk,
190 double tol1, double tol2) const
191{
192 if (!bchk)
193 return true;
194 // check whether this is a boundless surface
196 return true;
197 // get the standard bounds
198 Amg::Vector3D loc3Dframe = inverseTransformMultHelper(glopo);
199 Amg::Vector2D locCand(loc3Dframe.perp(), loc3Dframe.z());
200 return (locCand[Trk::locR] < bounds().r() + tol1 && bounds().insideLoc2(locCand, tol2));
201}
202
206{
207 const Amg::Vector3D& C = center();
208 const Amg::Vector3D& S = lineDirection();
209
210 double D = dir.dot(S);
211 double A = (1. - D) * (1. + D);
212
213 Amg::Vector3D dx = C - pos - (C.dot(S) - pos.dot(S)) * S;
214 double currDist = sqrt(dx.dot(dx));
215
216 if (A < 0.0001) {
217 return {1, currDist, false, 0.};
218 }
219 double sol = (pos - C).dot(D * S - dir) / A;
220 return {1, currDist, false, sol};
221}
222
223// return the measurement frame
226{
228 // construct the measurement frame
229 const Amg::Vector3D& measY = lineDirection();
230 Amg::Vector3D measX(measY.cross(glomom).unit());
231 Amg::Vector3D measDepth(measX.cross(measY));
232 // assign the columnes
233 mFrame.col(0) = measX;
234 mFrame.col(1) = measY;
235 mFrame.col(2) = measDepth;
236 // return the rotation matrix
237 return mFrame;
238}
239
242 const Amg::Vector3D& dir,
243 bool bound) const
244{
245 const Amg::Transform3D& T = transform();
246 Amg::Vector3D Az(T(0, 2), T(1, 2), T(2, 2));
247
248 Amg::Vector3D dxyz = pos - T.translation();
249
250 double D = dir.dot(Az);
251 double Lz = dxyz.dot(Az);
252 double A = (1. - D) * (1. + D);
253
254 // Step to surface
255 //
256 double s = 0.;
257 if (A > 0.)
258 s = (D * Lz - (dir.dot(dxyz))) / A;
259 if (!bound)
260 return {1, 0., false, s};
261
262 // Min distance to surface
263 //
264 double Rm = 20.;
265 double Lzm = 1.e+10;
266
267 if (m_bounds.get()) {
268 Rm = m_bounds.get()->r();
269 Lzm = m_bounds.get()->halflengthZ();
271
272 const Trk::CylinderBounds* cb = nullptr;
273
274 if (Surface::m_associatedDetElementId.is_valid()) {
276 } else {
277 cb = dynamic_cast<const Trk::CylinderBounds*>(&m_associatedDetElement->bounds());
278 }
279 if (cb) {
280 Rm = cb->r();
281 Lzm = cb->halflengthZ();
282 }
283 }
284
285 double dist = dxyz.dot(dxyz) - Lz * Lz;
286 dist = (dist > Rm * Rm) ? sqrt(dist) - Rm : 0.;
287 double dL = fabs(Lz) - Lzm;
288 if (dL > 0.){
289 dist = sqrt(dist * dist + dL * dL);
290 }
291 return {1, dist, false, s};
292}
293
296 const Amg::Vector3D& dir,
297 bool forceDir,
298 Trk::BoundaryCheck bchk) const
299{
300 // following nominclature found in header file and doxygen documentation
301 // line one is the straight track
302 const Amg::Vector3D& ma = pos;
303 const Amg::Vector3D& ea = dir;
304 // line two is the line surface
305 const Amg::Vector3D& mb = center();
306 const Amg::Vector3D& eb = lineDirection();
307 // now go ahead and solve for the closest approach
308 Amg::Vector3D mab(mb - ma);
309 double eaTeb = ea.dot(eb);
310 double denom = 1 - eaTeb * eaTeb;
311 if (fabs(denom) > 10e-7) {
312 double lambda0 = (mab.dot(ea) - mab.dot(eb) * eaTeb) / denom;
313 // evaluate in terms of direction
314 bool isValid = forceDir ? (lambda0 > 0.) : true;
315 // evaluate validaty in terms of bounds
316 Amg::Vector3D result = (ma + lambda0 * ea);
317 isValid = bchk ? (isValid && isOnSurface(result)) : isValid;
318 // return the result
319 return {result, lambda0, isValid};
320 }
321 return {pos, 0., false};
322}
double charge(const T &p)
Definition AtlasPID.h:997
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
#define AmgSymMatrix(dim)
int sign(int a)
The BoundaryCheck class allows to steer the way surface boundaries are used for inside/outside checks...
Bounds for a cylindrical Surface.
virtual double r() const override final
This method returns the radius.
double halflengthZ() const
This method returns the halflengthZ.
Access to distance solutions.
Bounds object for a boundless surface (...)
Definition NoBounds.h:30
Class for a StraightLineSurface in the ATLAS detector to describe dirft tube and straw like detectors...
static const NoBounds s_boundless
virtual bool globalToLocal(const Amg::Vector3D &glob, const Amg::Vector3D &mom, Amg::Vector2D &loc) const override final
Specified for StraightLineSurface: GlobalToLocal method without dynamic memory allocation This method...
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.
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...
virtual DistanceSolution straightLineDistanceEstimate(const Amg::Vector3D &pos, const Amg::Vector3D &dir) const override final
fast straight line distance evaluation to Surface
virtual bool operator==(const Surface &sf) const override
Equality operator.
CxxUtils::CachedValue< Amg::Vector3D > m_lineDirection
bounds (shared)
StraightLineSurface & operator=(const StraightLineSurface &slsf)
Assignment operator.
virtual NeutralTrackParametersUniquePtr createUniqueNeutralParameters(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 - neutral.
std::shared_ptr< const CylinderBounds > m_bounds
NoBounds as return object when no bounds are declared.
virtual Amg::RotationMatrix3D measurementFrame(const Amg::Vector3D &glopos, const Amg::Vector3D &glomom) const override final
Return the measurement frame - this is needed for alignment, in particular for StraightLine and Perig...
virtual void localToGlobal(const Amg::Vector2D &locp, const Amg::Vector3D &mom, Amg::Vector3D &glob) const override final
Specified for StraightLineSurface: LocalToGlobal method without dynamic memory allocation.
virtual const SurfaceBounds & bounds() const override final
This method returns the bounds of the Surface by reference.
StraightLineSurface()
Default Constructor - needed for persistency.
virtual bool isOnSurface(const Amg::Vector3D &glopo, const BoundaryCheck &bchk=true, double tol1=0., double tol2=0.) const override final
This method checks if the provided GlobalPosition is inside the assigned straw radius,...
const Amg::Vector3D & lineDirection() const
Special method for StraightLineSurface - provides the Line direction from cache: speedup.
Abstract Base Class for tracking surfaces.
std::unique_ptr< ParametersBase< 5, Trk::Charged > > ChargedTrackParametersUniquePtr
Unique ptr types.
Surface & operator=(const Surface &sf)
Definition Surface.cxx:91
const TrkDetElementBase * m_associatedDetElement
Not owning Pointer to the Detector Element.
Amg::Vector3D inverseTransformMultHelper(const Amg::Vector3D &glopos) const
Surface()
Default Constructor for inheriting classes.
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
Identifier m_associatedDetElementId
Identifier to the Detector Element.
const Amg::Vector3D & center() const
Returns the center position of the Surface.
virtual void localToGlobal(const Amg::Vector2D &locp, const Amg::Vector3D &mom, Amg::Vector3D &glob) const =0
Specified by each surface type: LocalToGlobal method without dynamic memory allocation.
std::unique_ptr< ParametersBase< 5, Trk::Neutral > > NeutralTrackParametersUniquePtr
This is the base class for all tracking detector elements with read-out relevant information.
int r
Definition globals.cxx:22
#define ATH_FLATTEN
struct color C
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
@ driftRadius
trt, straws
Definition ParamDefs.h:53
@ locR
Definition ParamDefs.h:44
@ theta
Definition ParamDefs.h:66
@ phi
Definition ParamDefs.h:75
@ locZ
local cylindrical
Definition ParamDefs.h:42
Definition dot.py:1
STL namespace.
hold the test vectors and ease the comparison