ATLAS Offline Software
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
15 #include "CxxUtils/inline_hints.h"
16 // Gaudi
17 #include "GaudiKernel/MsgStream.h"
18 // STD
19 #include <iomanip>
20 #include <iostream>
21 
23 
24 // default constructor
26  : Surface()
27  , m_lineDirection{}
28  , m_bounds(nullptr)
29 {}
30 
31 // constructors by arguments: boundless surface
33  : Surface(htrans)
34  , m_lineDirection{}
35  , m_bounds(nullptr)
36 {}
37 
38 // constructors by arguments
40  const Amg::Transform3D& htrans,
41  double radius,
42  double halez)
43  : Surface(htrans)
44  , m_lineDirection{}
45  , m_bounds(std::make_shared<Trk::CylinderBounds>(radius, halez))
46 {}
47 
48 // dummy implementation
50  const Trk::TrkDetElementBase& detelement,
51  const Identifier& id)
52  : Surface(detelement, id)
53  , m_lineDirection{}
54  , m_bounds(nullptr)
55 {}
56 
57 // copy constructor
59  const Trk::StraightLineSurface& slsf)
60  : Surface(slsf)
61  , m_lineDirection{}
62  , m_bounds(slsf.m_bounds)
63 {}
64 
65 // copy constructor with shift
67  const StraightLineSurface& csf,
68  const Amg::Transform3D& transf)
69  : Surface(csf, transf)
70  , m_lineDirection{}
71  , m_bounds(csf.m_bounds)
72 {}
73 
74 // assignment operator
77 {
78  if (this != &slsf) {
80  m_lineDirection=slsf.m_lineDirection;
81  m_bounds = slsf.m_bounds;
82  }
83  return *this;
84 }
85 
86 bool
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 }
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
138 void
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
163 bool
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
187 bool
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
195  if (!(m_bounds.get()) && !Surface::m_associatedDetElement)
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 {
227  Amg::RotationMatrix3D mFrame;
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();
270  } else if (Surface::m_associatedDetElement) {
271 
272  const Trk::CylinderBounds* cb = nullptr;
273 
274  if (Surface::m_associatedDetElementId.is_valid()) {
275  cb = dynamic_cast<const Trk::CylinderBounds*>(&m_associatedDetElement->bounds(Surface::m_associatedDetElementId));
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 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
Trk::Surface::m_associatedDetElement
const TrkDetElementBase * m_associatedDetElement
Not owning Pointer to the TrkDetElementBase.
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:439
beamspotman.r
def r
Definition: beamspotman.py:676
Trk::LocalParameters
Definition: LocalParameters.h:98
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
Trk::Intersection
Definition: Intersection.h:24
inline_hints.h
get_generator_info.result
result
Definition: get_generator_info.py:21
StraightLineSurface.h
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
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:201
Trk::StraightLineSurface::isOnSurface
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,...
Definition: StraightLineSurface.cxx:188
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
Trk::locR
@ locR
Definition: ParamDefs.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
JetTiledMap::S
@ S
Definition: TiledEtaPhiMap.h:44
Trk::StraightLineSurface::globalToLocal
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...
Definition: StraightLineSurface.cxx:164
Trk::AmgSymMatrix
AmgSymMatrix(5) &GXFTrackState
Definition: GXFTrackState.h:156
Trk::StraightLineSurface::operator==
virtual bool operator==(const Surface &sf) const override
Equality operator.
Definition: StraightLineSurface.cxx:87
Trk::Surface::operator=
Surface & operator=(const Surface &sf)
Definition: Surface.cxx:91
A
skel.l2
l2
Definition: skel.GENtoEVGEN.py:399
Trk::StraightLineSurface::measurementFrame
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...
Definition: StraightLineSurface.cxx:225
Trk::locZ
@ locZ
local cylindrical
Definition: ParamDefs.h:42
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
ATH_FLATTEN
#define ATH_FLATTEN
Definition: inline_hints.h:52
Trk::theta
@ theta
Definition: ParamDefs.h:66
Trk::StraightLineSurface::straightLineDistanceEstimate
virtual DistanceSolution straightLineDistanceEstimate(const Amg::Vector3D &pos, const Amg::Vector3D &dir) const override final
fast straight line distance evaluation to Surface
Definition: StraightLineSurface.cxx:205
Trk::CylinderBounds
Definition: CylinderBounds.h:46
Trk::driftRadius
@ driftRadius
trt, straws
Definition: ParamDefs.h:53
Trk::StraightLineSurface::StraightLineSurface
StraightLineSurface()
Default Constructor - needed for persistency.
Definition: StraightLineSurface.cxx:25
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
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::StraightLineSurface::s_boundless
static const NoBounds s_boundless
Definition: StraightLineSurface.h:291
Trk::StraightLineSurface::m_bounds
SharedObject< const CylinderBounds > m_bounds
NoBounds as return object when no bounds are declared.
Definition: StraightLineSurface.h:289
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::StraightLineSurface::m_lineDirection
CxxUtils::CachedValue< Amg::Vector3D > m_lineDirection
bounds (shared)
Definition: StraightLineSurface.h:287
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
charge
double charge(const T &p)
Definition: AtlasPID.h:756
Trk::StraightLineSurface::localToGlobal
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.
Definition: StraightLineSurface.cxx:139
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::Surface::m_associatedDetElementId
Identifier m_associatedDetElementId
Identifier for the TrkDetElementBase.
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:442
ParticleGun_SamplingFraction.radius
radius
Definition: ParticleGun_SamplingFraction.py:96
Trk::StraightLineSurface::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: StraightLineSurface.cxx:295
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::NoBounds
Definition: NoBounds.h:30
CylinderBounds.h
PowhegPythia8EvtGen_H2a4X_ctauY.ma
int ma
Definition: PowhegPythia8EvtGen_H2a4X_ctauY.py:26
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
TRT_PAI_physicsConstants::mb
const double mb
1mb to cm2
Definition: TRT_PAI_physicsConstants.h:15
Amg::RotationMatrix3D
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Definition: GeoPrimitives.h:49
Trk::BoundaryCheck
Definition: BoundaryCheck.h:51
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
Trk::StraightLineSurface::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: StraightLineSurface.cxx:99
Trk::phi
@ phi
Definition: ParamDefs.h:75
skel.l1
l1
Definition: skel.GENtoEVGEN.py:398
Trk::SurfaceType::Line
@ Line
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::StraightLineSurface::operator=
StraightLineSurface & operator=(const StraightLineSurface &slsf)
Assignment operator.
Definition: StraightLineSurface.cxx:76
Trk::Surface::localToGlobal
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.
Trk::StraightLineSurface
Definition: StraightLineSurface.h:51
Trk::CylinderBounds::halflengthZ
double halflengthZ() const
This method returns the halflengthZ.
Trk::StraightLineSurface::createUniqueNeutralParameters
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.
Definition: StraightLineSurface.cxx:118
Trk::CylinderBounds::r
virtual double r() const override final
This method returns the radius.
Identifier
Definition: IdentifierFieldParser.cxx:14