ATLAS Offline Software
CylinderBounds.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 namespace Trk {
6 inline bool CylinderBounds::operator==(const CylinderBounds& bo) const
7 {
8  return *this == static_cast<const SurfaceBounds &>(bo);
9 }
10 
11 inline CylinderBounds*
12 CylinderBounds::clone() const
13 {
14  return new CylinderBounds(*this);
15 }
16 
17 inline bool
18 CylinderBounds::inside(const Amg::Vector2D& locpo,
19  double tol1,
20  double tol2) const
21 {
22  double z = locpo[locZ];
23  bool insideZ = insideLocZ(z, tol2);
24  if (!insideZ)
25  return false;
26  // no check on Phi neccesary
27  if (!m_checkPhi)
28  return true;
29  // now check insidePhi
30  double localPhi =
31  (locpo[locRPhi] / m_boundValues[CylinderBounds::bv_radius]) -
32  m_boundValues[CylinderBounds::bv_averagePhi];
33  localPhi -= (localPhi > M_PI) ? 2. * M_PI : 0.;
34  return (localPhi * localPhi <
35  (m_boundValues[CylinderBounds::bv_halfPhiSector] + tol1) *
36  (m_boundValues[CylinderBounds::bv_halfPhiSector] + tol1));
37 }
38 
39 inline bool
40 CylinderBounds::inside(const Amg::Vector2D& locpo,
41  const BoundaryCheck& bchk) const
42 {
43  if (bchk.bcType == 0 || bchk.nSigmas == 0 ||
44  m_boundValues[CylinderBounds::bv_halfPhiSector] != M_PI)
45  return CylinderBounds::inside(
46  locpo, bchk.toleranceLoc1, bchk.toleranceLoc2);
47 
48  float theta =
49  (bchk.lCovariance(1, 0) != 0 &&
50  (bchk.lCovariance(1, 1) - bchk.lCovariance(0, 0)) != 0)
51  ? .5 * bchk.FastArcTan(2 * bchk.lCovariance(1, 0) /
52  (bchk.lCovariance(1, 1) - bchk.lCovariance(0, 0)))
53  : 0.;
54  sincosCache scResult = bchk.FastSinCos(theta);
55  double dphi = scResult.sinC * scResult.sinC * bchk.lCovariance(0, 0);
56  double dz = scResult.cosC * scResult.cosC * bchk.lCovariance(0, 1);
57  double max_ell = dphi > dz ? dphi : dz;
58  double limit = bchk.nSigmas * sqrt(max_ell);
59  return insideLocZ(locpo[locZ], limit);
60 }
61 
62 inline bool
63 CylinderBounds::inside3D(const Amg::Vector3D& glopo,
64  double tol1,
65  double tol2) const
66 {
67  return inside(glopo.perp(), glopo.phi(), glopo.z(), tol1, tol2);
68 }
69 
70 inline bool
71 CylinderBounds::inside(double r, double phi, double z, double tol1, double tol2)
72  const
73 {
74 
75  bool insideZ = insideLocZ(z, tol2);
76  if (!insideZ)
77  return false;
78  double diffR = (m_boundValues[CylinderBounds::bv_radius] - r);
79  bool insideR = diffR * diffR < tol1 * tol1;
80  if (!insideR)
81  return false;
82  // now check insidePhi if needed
83  if (!m_checkPhi)
84  return true;
85  // phi needs to be checked
86  double localPhi = phi - m_boundValues[CylinderBounds::bv_averagePhi];
87  localPhi -= (localPhi > M_PI) ? 2. * M_PI : 0.;
88  return (localPhi * localPhi <
89  m_boundValues[CylinderBounds::bv_halfPhiSector] *
90  m_boundValues[CylinderBounds::bv_halfPhiSector]);
91 }
92 
93 inline bool
94 CylinderBounds::insideLocZ(double z, double tol2) const
95 {
96  return (m_boundValues[CylinderBounds::bv_halfZ] + tol2) - fabs(z) > 0.;
97 }
98 
99 inline bool
100 CylinderBounds::insideLoc1(const Amg::Vector2D& locpo, double tol1) const
101 {
102  bool insideRphi = false;
103  if (fabs(m_boundValues[CylinderBounds::bv_averagePhi]) < 10e-7)
104  insideRphi =
105  (fabs(locpo[locRPhi] / m_boundValues[CylinderBounds::bv_radius]) <
106  (m_boundValues[CylinderBounds::bv_halfPhiSector] + tol1));
107  else {
108  double localPhi =
109  (locpo[locRPhi] / m_boundValues[CylinderBounds::bv_radius]) -
110  m_boundValues[CylinderBounds::bv_averagePhi];
111  localPhi -= (localPhi > M_PI) ? 2. * M_PI : 0.;
112  insideRphi =
113  (localPhi < (m_boundValues[CylinderBounds::bv_halfPhiSector] + tol1));
114  }
115  return (insideRphi);
116 }
117 
118 inline bool
119 CylinderBounds::insideLoc2(const Amg::Vector2D& locpo, double tol2) const
120 {
121  return insideLocZ(locpo[locZ], tol2);
122 }
123 
124 inline bool
125 CylinderBounds::insideRadius(const Amg::Vector2D& locpo, double tol) const
126 {
127  return (this->inside(locpo, tol, 0) &&
128  fabs(locpo[locR]) < m_boundValues[CylinderBounds::bv_radius] + tol);
129 }
130 
131 inline double
132 CylinderBounds::r() const
133 {
134  return m_boundValues[CylinderBounds::bv_radius];
135 }
136 
137 inline double
138 CylinderBounds::averagePhi() const
139 {
140  return m_boundValues[CylinderBounds::bv_averagePhi];
141 }
142 
143 inline double
144 CylinderBounds::halfPhiSector() const
145 {
146  return m_boundValues[CylinderBounds::bv_halfPhiSector];
147 }
148 
149 inline double
150 CylinderBounds::halflengthZ() const
151 {
152  return m_boundValues[CylinderBounds::bv_halfZ];
153 }
154 
155 }
156