ATLAS Offline Software
SlidingCylinderSurface.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // SlidingCylinderSurface.cxx, (c) ATLAS Detector Software
8 
9 // Trk
13 
14 // Eigen
16 // STD
17 #include <cmath>
18 
19 
20 
21 // constructor
23  const Trk::BinUtility & bu,
24  const std::vector<float> & offset)
25  : Trk::CylinderSurface(dsf)
26  , m_depth(offset)
27  , m_etaBin(bu)
28 {}
29 
30 
31 bool
33 {
34  // first check the type not to compare apples with oranges
35  const Trk::SlidingCylinderSurface* dsf = dynamic_cast<const Trk::SlidingCylinderSurface*>(&sf);
36  if (!dsf)
37  return false;
38  if (this == dsf)
39  return true;
40  bool transfEqual(transform().isApprox(dsf->transform(), 10e-8));
41  bool centerEqual = (transfEqual) ? (center() == dsf->center()) : false;
42  bool boundsEqual = (centerEqual) ? (bounds() == dsf->bounds()) : false;
43  return boundsEqual;
44 }
45 
46 void
48  const Amg::Vector3D&,
49  Amg::Vector3D& glopos) const
50 {
51  // create the position in the local 3d frame
52  double r0 = bounds().r();
53  double phi0 = locpos[Trk::locRPhi] / r0;
54  Amg::Vector3D loc3D0(r0 * std::cos(phi0), r0 * std::sin(phi0), locpos[Trk::locZ]);
55  // correct for alignment, retrieve offset correction
57  float offset = m_depth[m_etaBin.bin(t0 * loc3D0)];
58  double r = r0 + offset;
59  double phi = locpos[Trk::locRPhi] / r;
60  Amg::Vector3D loc3Dframe(r * std::cos(phi), r * std::sin(phi), locpos[Trk::locZ]);
61  // transport it to the globalframe
62  glopos = Trk::Surface::transform() * loc3Dframe;
63 }
64 
66 bool
68  const Amg::Vector3D&,
69  Amg::Vector2D& locpos) const
70 {
71  // get the transform & transform global position into cylinder frame
72  // transform it to the globalframe: CylinderSurfaces are allowed to have 0 pointer transform
73  double radius = 0.;
74  const double inttol = std::max(bounds().r() * 0.0001, 0.01);
75  // realign to find local eta bin
76  const Amg::Vector3D& loc3D0 = glopos;
77  float offset = m_depth[m_etaBin.bin(loc3D0)];
78  // do the transformation or not
80  const Amg::Transform3D& surfaceTrans = transform();
81  Amg::Transform3D inverseTrans(surfaceTrans.inverse());
82  Amg::Vector3D loc3Dframe(inverseTrans * glopos);
83  locpos = Amg::Vector2D((bounds().r() + offset) * loc3Dframe.phi(), loc3Dframe.z());
84  radius = loc3Dframe.perp();
85  } else {
86  locpos = Amg::Vector2D((bounds().r() + offset) * glopos.phi(), glopos.z());
87  radius = glopos.perp();
88  }
89  // return true or false
90  return (std::abs(radius - bounds().r() - offset) <= inttol);
91 }
92 
93 bool
95  const Trk::BoundaryCheck& bchk,
96  double tol1,
97  double tol2) const
98 {
99  const Amg::Vector3D& loc3D0 = glopo;
100  Amg::Vector3D loc3Dframe = m_transforms ? (transform().inverse()) * glopo : glopo;
101  float offset = m_depth[m_etaBin.bin(loc3D0)];
102  // recalculate r to match bounds
103  Amg::Vector3D loc3Dbase((loc3Dframe.perp() - offset) * std::cos(loc3Dframe.phi()),
104  (loc3Dframe.perp() - offset) * std::sin(loc3Dframe.phi()),
105  loc3Dframe.z());
106 
107  return (bchk ? bounds().inside3D(loc3Dbase, tol1, tol2) : true);
108 }
109 
113 {
114  double tol = 0.001;
115 
116  // retrieve localEta bin using current position
117  const Amg::Vector3D& loc3D0 = pos; // used to retrieve localEta bin
118  float offset = m_depth[m_etaBin.bin(loc3D0)];
119 
120  const Amg::Vector3D& X = Trk::Surface::center(); // point
121  const Amg::Vector3D& S = Trk::Surface::normal(); // vector
122 
123  double radius = bounds().r() + offset;
124  double sp = pos.dot(S);
125  double sc = X.dot(S);
126  double dp = dir.dot(S);
127  Amg::Vector3D dx = X - pos - (sc - sp) * S; // vector
128  Amg::Vector3D ax = dir - dp * S; // vector
129 
130  double A = ax.dot(ax); // size of projected direction (squared)
131  double B = ax.dot(dx); // dot product (->cos angle)
132  double C = dx.dot(dx); // distance to axis (squared)
133  double currDist = radius - std::sqrt(C);
134  const double bOverA{B/A};
135  if (A == 0.) { // direction parallel to cylinder axis
136  if (std::abs(currDist) < tol) {
137  return {1, 0., true, 0.}; // solution at surface
138  }
139  return {0, currDist, true, 0.}; // point of closest approach without intersection
140 
141  }
142  // minimal distance to cylinder axis
143  double rmin = C - B * bOverA < 0. ? 0. : std::sqrt(C - B * bOverA);
144  if (rmin > radius) { // no intersection
145  return {0, currDist, true, bOverA}; // point of closest approach without intersection
146  }
147  if (std::abs(rmin - radius) < tol) { // tangential 'intersection' - return double solution
148  return {2, currDist, true, bOverA, bOverA};
149  }
150  const double sqrtTerm = std::sqrt((radius - rmin) * (radius + rmin)/A) ;
151  double first = bOverA - sqrtTerm;
152  double second = bOverA + sqrtTerm;
153  if (first >= 0.) {
154  return {2, currDist, true, first, second};
155  } if (second <= 0.) {
156  return {2, currDist, true, second, first};
157  } // inside cylinder
158  return {2, currDist, true, second, first};
159 }
160 
163  const Amg::Vector3D& dir,
164  bool /*bound*/) const
165 {
166  return straightLineDistanceEstimate(pos, dir);
167 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
beamspotman.r
def r
Definition: beamspotman.py:676
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
TileDCSDataPlotter.dp
dp
Definition: TileDCSDataPlotter.py:840
SlidingCylinderSurface.h
max
#define max(a, b)
Definition: cfImp.cxx:41
fitman.ax
ax
Definition: fitman.py:522
Trk::SlidingCylinderSurface::globalToLocal
virtual bool globalToLocal(const Amg::Vector3D &glob, const Amg::Vector3D &mom, Amg::Vector2D &loc) const override final
Specialized for DiscSurface: GlobalToLocal method without dynamic memory allocation - boolean checks ...
Definition: SlidingCylinderSurface.cxx:67
Trk::SlidingCylinderSurface::straightLineDistanceEstimate
virtual DistanceSolution straightLineDistanceEstimate(const Amg::Vector3D &pos, const Amg::Vector3D &dir) const override final
fast straight line distance evaluation to Surface
Definition: SlidingCylinderSurface.cxx:112
Trk::DistanceSolution
Definition: DistanceSolution.h:25
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
Trk::locRPhi
@ locRPhi
Definition: ParamDefs.h:40
Trk::CylinderSurface::bounds
virtual const CylinderBounds & bounds() const override final
This method returns the CylinderBounds by reference (NoBounds is not possible for cylinder)
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
Trk::Surface::center
const Amg::Vector3D & center() const
Returns the center position of the Surface.
JetTiledMap::S
@ S
Definition: TiledEtaPhiMap.h:44
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Monitored::X
@ X
Definition: HistogramFillerUtils.h:24
GeoPrimitives.h
Trk::SlidingCylinderSurface::operator==
virtual bool operator==(const Surface &sf) const override final
Equality operator.
Definition: SlidingCylinderSurface.cxx:32
Trk::Surface::m_transforms
std::unique_ptr< Transforms > m_transforms
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:436
Trk::locZ
@ locZ
local cylindrical
Definition: ParamDefs.h:42
Trk::SlidingCylinderSurface::SlidingCylinderSurface
SlidingCylinderSurface(const CylinderSurface &surf, const Trk::BinUtility &bu, const std::vector< float > &offset)
Constructor.
Definition: SlidingCylinderSurface.cxx:22
Trk::CylinderSurface
Definition: CylinderSurface.h:55
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
Trk::Surface::normal
virtual const Amg::Vector3D & normal() const
Returns the normal vector of the Surface (i.e.
beamspotman.dir
string dir
Definition: beamspotman.py:623
Trk::BinUtility
Definition: BinUtility.h:39
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
LocalParameters.h
ParticleGun_SamplingFraction.radius
radius
Definition: ParticleGun_SamplingFraction.py:96
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::SlidingCylinderSurface::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: SlidingCylinderSurface.cxx:94
CylinderBounds.h
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
Trk::BoundaryCheck
Definition: BoundaryCheck.h:51
DeMoScan.first
bool first
Definition: DeMoScan.py:536
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
Trk::SlidingCylinderSurface
Definition: SlidingCylinderSurface.h:34
Trk::phi
@ phi
Definition: ParamDefs.h:75
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::Surface::transform
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
Trk::SlidingCylinderSurface::localToGlobal
virtual void localToGlobal(const Amg::Vector2D &locp, const Amg::Vector3D &mom, Amg::Vector3D &glob) const override final
Specialized for DiscSurface: LocalToGlobal method without dynamic memory allocation.
Definition: SlidingCylinderSurface.cxx:47
Trk::phi0
@ phi0
Definition: ParamDefs.h:65