ATLAS Offline Software
DiscSurface.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 // DiscSurface.cxx, (c) ATLAS Detector Software
8 
9 // Trk
12 #include "TrkSurfaces/DiscBounds.h"
16 // CxxUtils
17 #include "CxxUtils/inline_hints.h"
18 // Gaudi
19 #include "GaudiKernel/MsgStream.h"
20 // Eigen
22 
24 
25 // default constructor
27  : Trk::Surface()
28  , m_bounds(nullptr)
29  , m_referencePoint(nullptr)
30 {}
31 
32 // copy constructor
34  : Trk::Surface(dsf)
35  , m_bounds(dsf.m_bounds)
36  , m_referencePoint(nullptr)
37 {}
38 
39 // copy constructor with shift
41  const Amg::Transform3D& transf)
42  : Trk::Surface(dsf, transf)
43  , m_bounds(dsf.m_bounds)
44  , m_referencePoint(nullptr)
45 {}
46 
47 // construct a disc with full phi coverage
49  double rmin,
50  double rmax)
51  : Trk::Surface(htrans)
52  , m_bounds(std::make_shared<Trk::DiscBounds>(rmin, rmax))
53  , m_referencePoint(nullptr)
54 {}
55 
56 // construct a disc with given phi coverage
58  double rmin,
59  double rmax,
60  double hphisec)
61  : Trk::Surface(htrans)
62  , m_bounds(std::make_shared<Trk::DiscBounds>(rmin, rmax, hphisec))
63  , m_referencePoint(nullptr)
64 {}
65 
67  double minhalfx,
68  double maxhalfx,
69  double maxR,
70  double minR,
71  double avephi,
72  double stereo)
73  : Trk::Surface(htrans)
74  , m_bounds(std::make_shared<Trk::DiscTrapezoidalBounds>(minhalfx,
75  maxhalfx,
76  maxR,
77  minR,
78  avephi,
79  stereo))
80  , m_referencePoint(nullptr)
81 {}
82 
83 // construct a disc with given bounds
85  Trk::DiscBounds* dbounds)
86  : Trk::Surface(htrans)
87  , m_bounds(dbounds)
88  , m_referencePoint(nullptr)
89 {}
90 
91 // construct a disc with given bounds
94  : Trk::Surface(htrans)
95  , m_bounds(dbounds)
96  , m_referencePoint(nullptr)
97 {}
98 
100  : Trk::Surface(htrans),
101  m_bounds(annpcbounds),
102  m_referencePoint(nullptr)
103 {}
104 
105 Trk::DiscSurface::DiscSurface(const Amg::Transform3D& htrans, std::unique_ptr<Trk::AnnulusBounds> annbounds, const TrkDetElementBase* detElem)
106  : Trk::Surface(htrans),
107  m_referencePoint(nullptr)
108 {
109 
110  if(detElem != nullptr) {
111  m_associatedDetElement = detElem;
113  }
114 
115  // build AnnulusBoundsPC from XY AnnulusBounds
116  std::pair<AnnulusBoundsPC, double> res = AnnulusBoundsPC::fromCartesian(*annbounds);
117  std::shared_ptr<AnnulusBoundsPC> annpcbounds(res.first.clone());
118  double phiShift = res.second;
119  m_bounds = annpcbounds; // this casts to SurfaceBounds
120 
121  // construct shifted transform
122  // we get the necessary rotation from ::fromCartesian(), and we need to make
123  // the local coordinate system to be rotated correctly here
124  Amg::Vector2D origin2D = annpcbounds->moduleOrigin();
125  Amg::Translation3D transl(Amg::Vector3D(origin2D.x(), origin2D.y(), 0));
126  Amg::Rotation3D rot(Amg::AngleAxis3D(-phiShift, Amg::Vector3D::UnitZ()));
127  Amg::Transform3D originTrf;
128  originTrf = transl * rot;
129 
130  m_transforms->transform = m_transforms->transform * originTrf.inverse();
131 }
132 
133 // construct a disc from a transform, bounds is not set.
135  : Trk::Surface(htrans)
136  , m_bounds(nullptr)
137  , m_referencePoint(nullptr)
138 {}
139 
140 // construct form TrkDetElementBase
142  : Trk::Surface(detelement)
143  , m_bounds(nullptr)
144  , m_referencePoint(nullptr)
145 {}
146 
149 {
150  if (this != &dsf) {
152  m_bounds = dsf.m_bounds;
153  m_referencePoint.store(nullptr);
154  }
155  return *this;
156 }
157 
158 bool
160 {
161  // first check the type not to compare apples with oranges
162  if (sf.type()!=Trk::SurfaceType::Disc){
163  return false;
164  }
165  return (*this) == static_cast<const Trk::DiscSurface&>(sf);
166 }
167 
168 /* Use the Surface as a ParametersBase constructor, from local parameters -
169  * charged */
172  double l1, double l2, double phi, double theta, double qop,
173  std::optional<AmgSymMatrix(5)> cov) const {
174  return std::make_unique<ParametersT<5, Charged, DiscSurface>>(
175  l1, l2, phi, theta, qop, *this, std::move(cov));
176 }
181  const Amg::Vector3D& position, const Amg::Vector3D& momentum, double charge,
182  std::optional<AmgSymMatrix(5)> cov) const {
183  return std::make_unique<ParametersT<5, Charged, DiscSurface>>(
184  position, momentum, charge, *this, std::move(cov));
185 }
186 
191  double l1, double l2, double phi, double theta, double qop,
192  std::optional<AmgSymMatrix(5)> cov) const {
193  return std::make_unique<ParametersT<5, Neutral, DiscSurface>>(
194  l1, l2, phi, theta, qop, *this, std::move(cov));
195 }
196 
201  const Amg::Vector3D& position, const Amg::Vector3D& momentum, double charge,
202  std::optional<AmgSymMatrix(5)> cov) const {
203  return std::make_unique<ParametersT<5, Neutral, DiscSurface>>(
204  position, momentum, charge, *this, std::move(cov));
205 }
206 
207 const Amg::Vector3D&
209 {
210  if (!m_referencePoint) {
211  const Trk::DiscBounds* dbo =
212  dynamic_cast<const Trk::DiscBounds*>(&(bounds()));
213  if (dbo) {
214  double rMedium = bounds().r();
215  double phi = dbo->averagePhi();
216  Amg::Vector3D gp(rMedium * cos(phi), rMedium * sin(phi), 0.);
217  m_referencePoint.set(std::make_unique<Amg::Vector3D>(transform() * gp));
218  } else {
219  const Trk::DiscTrapezoidalBounds* dtbo =
220  dynamic_cast<const Trk::DiscTrapezoidalBounds*>(&(bounds()));
221  // double rMedium = dtbo ? bounds().r() : dtbo->rCenter() ; //nonsense, or
222  // logic inverted?
223  double rMedium = bounds().r();
224  double phi = dtbo ? dtbo->averagePhi() : 0.;
225  Amg::Vector3D gp(rMedium * cos(phi), rMedium * sin(phi), 0.);
226  m_referencePoint.set(std::make_unique<Amg::Vector3D>(transform() * gp));
227  }
228  }
229  return (*m_referencePoint);
230 }
231 
232 // Avoid out-of-line Eigen calls
234 void
236  const Amg::Vector3D&,
237  Amg::Vector3D& glopos) const
238 {
239  // create the position in the local 3d frame
240  Amg::Vector3D loc3Dframe(locpos[Trk::locR] * cos(locpos[Trk::locPhi]),
241  locpos[Trk::locR] * sin(locpos[Trk::locPhi]),
242  0.);
243  // transport it to the globalframe
244  glopos = transform() * loc3Dframe;
245 }
246 
248 bool
250  const Amg::Vector3D&,
251  Amg::Vector2D& locpos) const
252 {
253  Amg::Vector3D loc3Dframe = inverseTransformMultHelper(glopos);
254  locpos = Amg::Vector2D(loc3Dframe.perp(), loc3Dframe.phi());
255  return (std::fabs(loc3Dframe.z()) <= s_onSurfaceTolerance);
256 }
257 
260  const Amg::Vector3D& dir,
261  bool forceDir,
262  Trk::BoundaryCheck bchk) const {
263  double denom = dir.dot(normal());
264  if (denom) {
265  double u = (normal().dot((center() - pos))) / (denom);
266  Amg::Vector3D intersectPoint(pos + u * dir);
267  // evaluate the intersection in terms of direction
268  bool isValid = forceDir ? (u > 0.) : true;
269  // evaluate (if necessary in terms of boundaries)
270  isValid = bchk ? (isValid && isOnSurface(intersectPoint)) : isValid;
271  // return the result
272  return Trk::Intersection(intersectPoint, u, isValid);
273  }
274  return Trk::Intersection(pos, 0., false);
275 }
276 
277 #if defined(FLATTEN)
278 // We compile this function with optimization, even in debug builds; otherwise,
279 // the heavy use of Eigen makes it too slow. However, from here we may call
280 // to out-of-line Eigen code that is linked from other DSOs; in that case,
281 // it would not be optimized. Avoid this by forcing all Eigen code
282 // to be inlined here if possible.
284 #endif
285 bool
287  const Trk::BoundaryCheck& bchk,
288  double tol1,
289  double tol2) const
290 {
291  Amg::Vector3D loc3Dframe = inverseTransformMultHelper(glopo);
292  if (std::abs(loc3Dframe.z()) > (s_onSurfaceTolerance + tol1)) {
293  return false;
294  }
295  return (bchk
296  ? bounds().inside(
297  Amg::Vector2D(loc3Dframe.perp(), loc3Dframe.phi()), tol1, tol2)
298  : true);
299 }
300 
304  const Amg::Vector3D& dir) const
305 {
306  double tol = 0.001;
307 
308  const Amg::Vector3D& C = center();
309  const Amg::Vector3D& N = normal();
310 
311  double S = C.dot(N);
312  double b = S < 0. ? -1 : 1;
313  double d = (pos - C).dot(N); // distance to surface
314 
315  double A = b * dir.dot(N);
316  if (A == 0.) { // direction parallel to surface
317  if (fabs(d) < tol) {
318  return {1, 0., true, 0.};
319  }
320  return {0, d, true, 0.};
321  }
322 
323  double D = b * (S - (pos.dot(N))) / A;
324  return {1, d, true, D};
325 }
326 
329  const Amg::Vector3D& dir,
330  bool bound) const
331 {
332  const Amg::Transform3D& T = transform();
333  const double Az[3] = { T(0, 2), T(1, 2), T(2, 2) };
334 
335  // Transformation to cylinder system coordinates
336  //
337  const double dx = pos[0] - T(0, 3);
338  const double dy = pos[1] - T(1, 3);
339  const double dz = pos[2] - T(2, 3);
340  const double z = dx * Az[0] + dy * Az[1] + dz * Az[2];
341  const double az = dir[0] * Az[0] + dir[1] * Az[1] + dir[2] * Az[2];
342 
343  // Step to surface
344  //
345  int ns = 0;
346  double s = 0.;
347  if (az != 0.) {
348  s = -z / az;
349  ns = 1;
350  }
351  double dist = std::abs(z);
352  if (!bound) {
353  return {ns, dist, true, s};
354  }
355 
356  // Min distance to surface
357  //
358  const double x = dx * T(0, 0) + dy * T(1, 0) + dz * T(2, 0);
359  const double y = dx * T(0, 1) + dy * T(1, 1) + dz * T(2, 1);
360 
361  Amg::Vector2D lp(sqrt(x * x + y * y), atan2(y, x));
362 
363  double d = bounds().minDistance(lp);
364  if (d > 0.) {
365  dist = std::sqrt(dist * dist + d * d);
366  }
367 
368  return {ns, dist, true, s};
369 }
Trk::Surface::m_associatedDetElement
const TrkDetElementBase * m_associatedDetElement
Not owning Pointer to the TrkDetElementBase.
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:439
Trk::y
@ y
Definition: ParamDefs.h:56
Amg::Rotation3D
Eigen::Quaternion< double > Rotation3D
Definition: GeoPrimitives.h:43
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
Trk::DiscBounds::averagePhi
double averagePhi() const
This method returns the average phi.
Trk::Intersection
Definition: Intersection.h:24
inline_hints.h
DiscBounds.h
Trk::z
@ z
global position (cartesian)
Definition: ParamDefs.h:57
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
Trk::DiscSurface::isOnSurface
virtual bool isOnSurface(const Amg::Vector3D &glopo, const BoundaryCheck &bchk=true, double tol1=0., double tol2=0.) const override
This method returns true if the GlobalPosition is on the Surface for both, within or without check of...
Definition: DiscSurface.cxx:286
hist_file_dump.d
d
Definition: hist_file_dump.py:137
Trk::DiscSurface::operator=
DiscSurface & operator=(const DiscSurface &dsf)
Assignement operator.
Definition: DiscSurface.cxx:148
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:201
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::DiscSurface
Definition: DiscSurface.h:54
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
Trk::locR
@ locR
Definition: ParamDefs.h:44
Trk::DiscTrapezoidalBounds::r
virtual double r() const override
This method returns the maximum expansion on the plane (=rMax)
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
Trk::TrkDetElementBase::identify
virtual Identifier identify() const =0
Identifier.
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
DiscTrapezoidalBounds.h
Trk::DiscSurface::globalReferencePoint
virtual const Amg::Vector3D & globalReferencePoint() const override final
Returns a global reference point: For the Disc this is Where denote the r(), averagePhi() of the Bo...
Definition: DiscSurface.cxx:208
JetTiledMap::S
@ S
Definition: TiledEtaPhiMap.h:44
Trk::DiscSurface::DiscSurface
DiscSurface()
Default Constructor.
Definition: DiscSurface.cxx:26
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
AnnulusBoundsPC.h
Trk::DiscTrapezoidalBounds
Definition: DiscTrapezoidalBounds.h:42
Trk::DiscSurface::straightLineIntersection
virtual Intersection straightLineIntersection(const Amg::Vector3D &pos, const Amg::Vector3D &dir, bool forceDir=false, Trk::BoundaryCheck bchk=false) const override final
fast straight line intersection schema - standard: provides closest intersection and (signed) path le...
Definition: DiscSurface.cxx:259
Trk::AmgSymMatrix
AmgSymMatrix(5) &GXFTrackState
Definition: GXFTrackState.h:156
GeoPrimitives.h
Trk::Surface::operator=
Surface & operator=(const Surface &sf)
Definition: Surface.cxx:91
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
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
AnnulusBounds.h
ATH_FLATTEN
#define ATH_FLATTEN
Definition: inline_hints.h:52
Trk::theta
@ theta
Definition: ParamDefs.h:66
Trk::AnnulusBoundsPC
Class that implements the asymmetric shape of the ITk strip endcap modules.
Definition: AnnulusBoundsPC.h:30
Trk::DiscSurface::m_bounds
SharedObject< const SurfaceBounds > m_bounds
reference Point on the Surface
Definition: DiscSurface.h:285
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
Trk::DiscTrapezoidalBounds::averagePhi
double averagePhi() const
This method returns the average phi.
dot.dot
def dot(G, fn, nodesToHighlight=[])
Definition: dot.py:5
Trk::AnnulusBoundsPC::fromCartesian
static std::pair< AnnulusBoundsPC, double > fromCartesian(AnnulusBounds &annbo)
Static factory method to produce an instance of this class from the cartesian implementation.
Definition: AnnulusBoundsPC.cxx:83
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
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
Trk::locPhi
@ locPhi
local polar
Definition: ParamDefs.h:45
Trk::DiscSurface::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: DiscSurface.cxx:171
charge
double charge(const T &p)
Definition: AtlasPID.h:756
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
LocalParameters.h
Trk::DiscSurface::operator==
virtual bool operator==(const Surface &sf) const override
Equality operator.
Definition: DiscSurface.cxx:159
Trk::Surface::m_associatedDetElementId
Identifier m_associatedDetElementId
Identifier for the TrkDetElementBase.
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:442
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::NoBounds
Definition: NoBounds.h:30
Trk::inside
@ inside
Definition: PropDirection.h:29
makeTRTBarrelCans.dy
tuple dy
Definition: makeTRTBarrelCans.py:21
Trk::DiscSurface::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: DiscSurface.cxx:190
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
Trk::DiscSurface::globalToLocal
virtual bool globalToLocal(const Amg::Vector3D &glob, const Amg::Vector3D &mom, Amg::Vector2D &loc) const override
Specialized for DiscSurface: GlobalToLocal method without dynamic memory allocation - boolean checks ...
Definition: DiscSurface.cxx:249
Trk::BoundaryCheck
Definition: BoundaryCheck.h:51
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
Amg::Translation3D
Eigen::Translation< double, 3 > Translation3D
Definition: GeoPrimitives.h:44
Trk::SurfaceType::Disc
@ Disc
DiscSurface.h
python.SystemOfUnits.ns
int ns
Definition: SystemOfUnits.py:130
Amg::AngleAxis3D
Eigen::AngleAxisd AngleAxis3D
Definition: GeoPrimitives.h:45
Trk::phi
@ phi
Definition: ParamDefs.h:75
skel.l1
l1
Definition: skel.GENtoEVGEN.py:398
Trk::DiscSurface::localToGlobal
virtual void localToGlobal(const Amg::Vector2D &locp, const Amg::Vector3D &mom, Amg::Vector3D &glob) const override
Specialized for DiscSurface: LocalToGlobal method without dynamic memory allocation.
Definition: DiscSurface.cxx:235
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
Trk::x
@ x
Definition: ParamDefs.h:55
Trk::DiscBounds::r
virtual double r() const override final
This method returns the maximum expansion on the plane (=rMax)
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::DiscBounds
Definition: DiscBounds.h:44
Trk::DiscSurface::s_boundless
static const NoBounds s_boundless
Definition: DiscSurface.h:289
Trk::DiscSurface::straightLineDistanceEstimate
virtual DistanceSolution straightLineDistanceEstimate(const Amg::Vector3D &pos, const Amg::Vector3D &dir) const override
fast straight line distance evaluation to Surface
Definition: DiscSurface.cxx:303