ATLAS Offline Software
Loading...
Searching...
No Matches
RotatedDiamondBounds.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6// RotatedDiamondBounds.cxx, (c) ATLAS Detector Software
8
9// Trk
11// Gaudi
12#include "GaudiKernel/MsgStream.h"
13// STD
14#include <cmath>
15#include <iomanip>
16#include <iostream>
17
18// default constructor
24
25// constructor from arguments I
44
53
54bool
56{
57 // check the type first not to compare apples with oranges
58 const Trk::RotatedDiamondBounds* diabo = dynamic_cast<const Trk::RotatedDiamondBounds*>(&sbo);
59 if (!diabo)
60 return false;
61 return (m_boundValues == diabo->m_boundValues);
62}
63
64bool
66 const BoundaryCheck& bchk) const
67{
68 // locX and locY are interchanged wrt DiamondBounds
69 if (bchk.bcType == 0)
71 locpo, bchk.toleranceLoc1, bchk.toleranceLoc2);
72 // a fast FALSE
73 double max_ell = bchk.lCovariance(0, 0) > bchk.lCovariance(1, 1)
74 ? bchk.lCovariance(0, 0)
75 : bchk.lCovariance(1, 1);
76 double limit = bchk.nSigmas * sqrt(max_ell);
77 if (locpo[Trk::locX] <
79 return false;
80 if (locpo[Trk::locX] >
82 return false;
83 // a fast FALSE
84 double fabsX = std::abs(locpo[Trk::locY]);
86 return false;
87 // a fast TRUE
88 double min_ell = bchk.lCovariance(0, 0) < bchk.lCovariance(1, 1)
89 ? bchk.lCovariance(0, 0)
90 : bchk.lCovariance(1, 1);
91 limit = bchk.nSigmas * sqrt(min_ell);
94 limit))
95 return true;
96 // a fast TRUE
97 if (std::abs(locpo[Trk::locX]) <
100 limit))
101 return true;
102
103 // compute KDOP and axes for surface polygon
104 std::vector<KDOP> elementKDOP(5);
105 std::vector<Amg::Vector2D> elementP(6);
106 float theta =
107 (bchk.lCovariance(1, 0) != 0 &&
108 (bchk.lCovariance(1, 1) - bchk.lCovariance(0, 0)) != 0)
109 ? .5 * bchk.FastArcTan(2 * bchk.lCovariance(1, 0) /
110 (bchk.lCovariance(1, 1) - bchk.lCovariance(0, 0)))
111 : 0.;
112 sincosCache scResult = bchk.FastSinCos(theta);
113 AmgMatrix(2, 2) rotMatrix;
114 rotMatrix << scResult.cosC, scResult.sinC, -scResult.sinC, scResult.cosC;
115 AmgMatrix(2, 2) normal;
116 // cppcheck-suppress constStatement
117 normal << 0, -1, 1, 0;
118 // ellipse is always at (0,0), surface is moved to ellipse position and then
119 // rotated exchange locX and locY
120 Amg::Vector2D locpoF;
121 locpoF[0] = locpo[Trk::locY];
122 locpoF[1] = locpo[Trk::locX];
123 Amg::Vector2D p =
126 elementP[0] = (rotMatrix * (p - locpoF));
128 elementP[1] = (rotMatrix * (p - locpoF));
131 elementP[2] = (rotMatrix * (p - locpoF));
134 elementP[3] = (rotMatrix * (p - locpoF));
136 elementP[4] = (rotMatrix * (p - locpoF));
139 elementP[5] = (rotMatrix * (p - locpoF));
140 std::vector<Amg::Vector2D> axis = { normal * (elementP[1] - elementP[0]),
141 normal * (elementP[2] - elementP[1]),
142 normal * (elementP[3] - elementP[2]),
143 normal * (elementP[4] - elementP[3]),
144 normal * (elementP[5] - elementP[4]) };
145 bchk.ComputeKDOP(elementP, axis, elementKDOP);
146 // compute KDOP for error ellipse
147 std::vector<KDOP> errelipseKDOP(5);
148 bchk.ComputeKDOP(bchk.EllipseToPoly(3), axis, errelipseKDOP);
149 // check if KDOPs overlap and return result
150 return bchk.TestKDOPKDOP(elementKDOP, errelipseKDOP);
151}
152
153// checking if inside bounds (Full symmetrical Diamond)
154bool
155Trk::RotatedDiamondBounds::inside(const Amg::Vector2D& locpo, double tol1, double tol2) const
156{
157 return this->insideFull(locpo, tol1, tol2);
158}
159
160// checking if inside bounds (Full symmetrical Diamond)
161bool
162Trk::RotatedDiamondBounds::insideFull(const Amg::Vector2D& locpo, double tol1, double tol2) const
163{
164 // validity check
166
167 // quick False (radial direction)
168 if (locpo[Trk::locX] < -2. * m_boundValues[RotatedDiamondBounds::bv_halfY1] - tol1) return false;
169 if (locpo[Trk::locX] > 2. * m_boundValues[RotatedDiamondBounds::bv_halfY2] + tol1) return false;
170
171 double absY = std::abs(locpo[Trk::locY]);
172
173 // quick False (transverse direction)
174 if (absY > (m_boundValues[RotatedDiamondBounds::bv_medHalfX] + tol2)) return false;
175
176 // quick True
178
183 double k = halfH ? 0.5*(halfBaseUp - halfBaseLo)/halfH : 0.;
184 double sign = (k < 0) ? -1. : 1.;
185 return (absY - tol2 <= m_boundValues[RotatedDiamondBounds::bv_medHalfX] + k * (locpo[Trk::locX] + sign*tol1));
186}
187
188// opening angle in point A
189double
191{
192 return m_alpha1;
193}
194
195// opening angle in point A'
196double
198{
199 return m_alpha2;
200}
201
202double
204{
205 const int Np = 6;
206
209
213 double Y[6] = { -y1, 0., y2, y2, 0., -y1 };
214
215 double dm = 1.e+20;
216 double Ao = 0.;
217 bool in = true;
218
219 for (int i = 0; i != Np; ++i) {
220
221 int j = (i == Np-1 ? 0 : i+1);
222
223 // interchange locx and locy
224 double x = X[i] - pos[1];
225 double y = Y[i] - pos[0];
226 double dx = X[j] - X[i];
227 double dy = Y[j] - Y[i];
228 double A = x * dy - y * dx;
229 double S = -(x * dx + y * dy);
230
231 if (S <= 0.) {
232 double d = x * x + y * y;
233 if (d < dm)
234 dm = d;
235 } else {
236 double a = dx * dx + dy * dy;
237 if (S <= a) {
238 double d = (A * A) / a;
239 if (d < dm)
240 dm = d;
241 }
242 }
243 if (i && in && Ao * A < 0.)
244 in = false;
245 Ao = A;
246 }
247 if (in)
248 return -sqrt(dm);
249 return sqrt(dm);
250}
251
252// ostream operator overload
253
254MsgStream&
256{
257 sl << std::setiosflags(std::ios::fixed);
258 sl << std::setprecision(7);
259 sl << "Trk::RotatedDiamondBounds: (minHlenghtX, medHlengthX, maxHlengthX, hlengthY1, hlengthY2 ) = ";
263 << ")";
264 sl << std::setprecision(-1);
265 return sl;
266}
267
268std::ostream&
269Trk::RotatedDiamondBounds::dump(std::ostream& sl) const
270{
271 sl << std::setiosflags(std::ios::fixed);
272 sl << std::setprecision(7);
273 sl << "Trk::RotatedDiamondBounds: (minHlenghtX, medHlengthX, maxHlengthX, hlengthY1, hlengthY2 ) = ";
277 << ")";
278 sl << std::setprecision(-1);
279 return sl;
280}
#define AmgMatrix(rows, cols)
static Double_t a
int sign(int a)
The BoundaryCheck class allows to steer the way surface boundaries are used for inside/outside checks...
int nSigmas
allowed sigmas for chi2 boundary check
BoundaryCheckType bcType
std::vector< Amg::Vector2D > EllipseToPoly(int resolution=3) const
bool TestKDOPKDOP(const std::vector< KDOP > &a, const std::vector< KDOP > &b) const
void ComputeKDOP(const std::vector< Amg::Vector2D > &v, const std::vector< Amg::Vector2D > &KDOPAxes, std::vector< KDOP > &kdop) const
Each Bounds has a method inside, which checks if a LocalPosition is inside the bounds.
double toleranceLoc2
absolute tolerance in local 2 coordinate
double FastArcTan(double x) const
sincosCache FastSinCos(double x) const
double toleranceLoc1
absolute tolerance in local 1 coordinate
Bounds for a double trapezoidal ("diamond"), planar Surface.
double alpha2() const
This method returns the opening angle alpha in point A'.
virtual void initCache() override
initialize the alpha1/2 cache - needed also for object persistency
virtual double minDistance(const Amg::Vector2D &pos) const override
Minimal distance to boundary ( > 0 if outside and <=0 if inside)
RotatedDiamondBounds()
Default Constructor, needed for persistency.
bool insideFull(const Amg::Vector2D &locpo, double tol1=0., double tol2=0.) const
inside() method for a full symmetric diamond
virtual bool inside(const Amg::Vector2D &locpo, double tol1=0., double tol2=0.) const override
The orientation of the Diamond is according to the figure.
std::vector< TDD_real_t > m_boundValues
Internal parameters stored in the geometry.
virtual bool operator==(const SurfaceBounds &diabo) const override
Equality operator.
double alpha1() const
This method returns the opening angle alpha in point A.
virtual MsgStream & dump(MsgStream &sl) const override
Output Method for MsgStream.
Abstract base class for surface bounds to be specified.
void swap(double &b1, double &b2)
Swap method to be called from DiscBounds or TrapezoidalBounds.
Eigen::Matrix< double, 2, 1 > Vector2D
@ locY
local cartesian
Definition ParamDefs.h:38
@ x
Definition ParamDefs.h:55
@ locX
Definition ParamDefs.h:37
@ theta
Definition ParamDefs.h:66
@ y
Definition ParamDefs.h:56
hold the test vectors and ease the comparison