ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
TrkDetDescr
TrkSurfaces
src
TriangleBounds.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
// TriangleBounds.cxx, (c) ATLAS Detector Software
8
9
// Trk
10
#include "
TrkSurfaces/TriangleBounds.h
"
11
// Gaudi
12
#include "GaudiKernel/MsgStream.h"
13
// STD
14
#include <iomanip>
15
#include <iostream>
16
#include "
CxxUtils/inline_hints.h
"
17
18
// default constructor
19
Trk::TriangleBounds::TriangleBounds
()
20
:
m_boundValues
(
TriangleBounds
::
bv_length
, 0.)
21
{}
22
23
// rectangle constructor - float constructor
24
Trk::TriangleBounds::TriangleBounds
(
const
std::vector<std::pair<float, float>>&
vertices
)
25
:
m_boundValues
(
TriangleBounds
::
bv_length
, 0.)
26
{
27
size_t
ib = 0;
28
for
(
const
std::pair<float, float>& p :
vertices
) {
29
m_boundValues
[2 * ib] = p.first;
30
m_boundValues
[2 * ib + 1] = p.second;
31
if
(ib == 2)
32
break
;
33
++ib;
34
}
35
}
36
37
// Inline Eigen in dbg builds.
38
ATH_FLATTEN
39
// rectangle constructor - double constructor
40
Trk::TriangleBounds::TriangleBounds
(
const
std::vector<std::pair<double, double>>&
vertices
)
41
:
m_boundValues
(
TriangleBounds
::
bv_length
, 0.)
42
{
43
size_t
ib = 0;
44
for
(
const
std::pair<double, double>& p :
vertices
) {
45
m_boundValues
[2 * ib] = p.first;
46
m_boundValues
[2 * ib + 1] = p.second;
47
if
(ib == 2)
48
break
;
49
++ib;
50
}
51
}
52
53
// constructor from three points
54
Trk::TriangleBounds::TriangleBounds
(
const
Amg::Vector2D
& p1,
const
Amg::Vector2D
& p2,
const
Amg::Vector2D
& p3)
55
:
m_boundValues
(
TriangleBounds
::
bv_length
, 0.)
56
{
57
m_boundValues
[
TriangleBounds::bv_x1
] = p1.x();
58
m_boundValues
[
TriangleBounds::bv_y1
] = p1.y();
59
m_boundValues
[
TriangleBounds::bv_x2
] = p2.x();
60
m_boundValues
[
TriangleBounds::bv_y2
] = p2.y();
61
m_boundValues
[
TriangleBounds::bv_x3
] = p3.x();
62
m_boundValues
[
TriangleBounds::bv_y3
] = p3.y();
63
}
64
65
bool
66
Trk::TriangleBounds::operator==
(
const
Trk::SurfaceBounds
& sbo)
const
67
{
68
// check the type first not to compare apples with oranges
69
const
Trk::TriangleBounds
* tribo =
dynamic_cast<
const
Trk::TriangleBounds
*
>
(&sbo);
70
if
(!tribo)
71
return
false
;
72
return
(
m_boundValues
== tribo->
m_boundValues
);
73
}
74
75
bool
76
Trk::TriangleBounds::inside
(
const
Amg::Vector2D
& locpo,
77
double
tol1,
78
double
tol2)
const
79
{
80
std::pair<double, double> locB(
m_boundValues
[
TriangleBounds::bv_x2
] -
81
m_boundValues
[
TriangleBounds::bv_x1
],
82
m_boundValues
[
TriangleBounds::bv_y2
] -
83
m_boundValues
[
TriangleBounds::bv_y1
]);
84
std::pair<double, double> locT(
85
m_boundValues
[
TriangleBounds::bv_x3
] - locpo[0],
86
m_boundValues
[
TriangleBounds::bv_y3
] - locpo[1]);
87
std::pair<double, double> locV(
88
m_boundValues
[
TriangleBounds::bv_x1
] - locpo[0],
89
m_boundValues
[
TriangleBounds::bv_y1
] - locpo[1]);
90
91
// special case :: third vertex ?
92
if
(locT.first * locT.first + locT.second * locT.second < tol1 * tol1)
93
return
true
;
94
95
// special case : lies on base ?
96
double
db = locB.first * locV.second - locB.second * locV.first;
97
if
(std::abs(db) < tol1) {
98
double
a
=
99
(locB.first != 0) ? -locV.first / locB.first : -locV.second / locB.second;
100
return
a
> -tol2 &&
a
- 1. < tol2;
101
}
102
103
double
dn = locB.first * locT.second - locB.second * locT.first;
104
105
if
(std::abs(dn) > std::abs(tol1)) {
106
double
t = (locB.first * locV.second - locB.second * locV.first) / dn;
107
if
(t > 0.)
108
return
false
;
109
110
double
a
= (locB.first != 0.)
111
? (t * locT.first - locV.first) / locB.first
112
: (t * locT.second - locV.second) / locB.second;
113
if
(
a < -tol2 || a - 1. >
tol2)
114
return
false
;
115
}
else
{
116
return
false
;
117
}
118
return
true
;
119
}
120
121
bool
122
Trk::TriangleBounds::inside
(
const
Amg::Vector2D
& locpo,
123
const
BoundaryCheck
& bchk)
const
124
{
125
if
(bchk.
bcType
== 0)
126
return
TriangleBounds::inside
(
127
locpo, bchk.
toleranceLoc1
, bchk.
toleranceLoc2
);
128
129
// a fast FALSE
130
double
fabsR = std::sqrt(locpo[
Trk::locX
] * locpo[
Trk::locX
] +
131
locpo[
Trk::locY
] * locpo[
Trk::locY
]);
132
double
max_ell = bchk.lCovariance(0, 0) > bchk.lCovariance(1, 1)
133
? bchk.lCovariance(0, 0)
134
: bchk.lCovariance(1, 1);
135
double
limit = bchk.
nSigmas
* std::sqrt(max_ell);
136
double
r_max =
TriangleBounds::r
();
137
if
(fabsR > (r_max + limit))
138
return
false
;
139
140
// compute KDOP and axes for surface polygon
141
std::vector<KDOP> elementKDOP(3);
142
std::vector<Amg::Vector2D> elementP(3);
143
float
theta
=
144
(bchk.lCovariance(1, 0) != 0 &&
145
(bchk.lCovariance(1, 1) - bchk.lCovariance(0, 0)) != 0)
146
? .5 * bchk.
FastArcTan
(2 * bchk.lCovariance(1, 0) /
147
(bchk.lCovariance(1, 1) - bchk.lCovariance(0, 0)))
148
: 0.;
149
sincosCache
scResult = bchk.
FastSinCos
(
theta
);
150
AmgMatrix
(2, 2) rotMatrix;
151
rotMatrix << scResult.
cosC
, scResult.
sinC
, -scResult.
sinC
, scResult.
cosC
;
152
AmgMatrix
(2, 2) normal;
153
// cppcheck-suppress constStatement
154
normal << 0, -1, 1, 0;
155
// ellipse is always at (0,0), surface is moved to ellipse position and then
156
// rotated
157
Amg::Vector2D
p;
158
p <<
m_boundValues
[
TriangleBounds::bv_x1
],
159
m_boundValues
[
TriangleBounds::bv_y1
];
160
elementP[0] = (rotMatrix * (p - locpo));
161
p <<
m_boundValues
[
TriangleBounds::bv_x2
],
162
m_boundValues
[
TriangleBounds::bv_y2
];
163
elementP[1] = (rotMatrix * (p - locpo));
164
p <<
m_boundValues
[
TriangleBounds::bv_x3
],
165
m_boundValues
[
TriangleBounds::bv_y3
];
166
elementP[2] = (rotMatrix * (p - locpo));
167
std::vector<Amg::Vector2D> axis = { normal * (elementP[1] - elementP[0]),
168
normal * (elementP[2] - elementP[1]),
169
normal * (elementP[2] - elementP[0]) };
170
bchk.
ComputeKDOP
(elementP, axis, elementKDOP);
171
// compute KDOP for error ellipse
172
std::vector<KDOP> errelipseKDOP(3);
173
bchk.
ComputeKDOP
(bchk.
EllipseToPoly
(3), axis, errelipseKDOP);
174
// check if KDOPs overlap and return result
175
return
bchk.
TestKDOPKDOP
(elementKDOP, errelipseKDOP);
176
}
177
178
double
179
Trk::TriangleBounds::minDistance
(
const
Amg::Vector2D
& pos)
const
180
{
181
const
int
Np = 3;
182
183
double
X[3] = {
m_boundValues
[
TriangleBounds::bv_x1
],
184
m_boundValues
[
TriangleBounds::bv_x2
],
185
m_boundValues
[
TriangleBounds::bv_x3
] };
186
double
Y[3] = {
m_boundValues
[
TriangleBounds::bv_y1
],
187
m_boundValues
[
TriangleBounds::bv_y2
],
188
m_boundValues
[
TriangleBounds::bv_y3
] };
189
190
double
dm = 1.e+20;
191
double
Ao = 0.;
192
bool
in =
true
;
193
194
for
(
int
i = 0; i != Np; ++i) {
195
196
int
j = (i == Np-1 ? 0 : i+1);
197
198
double
x
= X[i] - pos[0];
199
double
y
= Y[i] - pos[1];
200
double
dx = X[j] - X[i];
201
double
dy = Y[j] - Y[i];
202
double
A
=
x
* dy -
y
* dx;
203
double
S = -(
x
* dx +
y
* dy);
204
205
if
(S <= 0.) {
206
double
d =
x
*
x
+
y
*
y
;
207
if
(d < dm)
208
dm = d;
209
}
else
{
210
double
a
= dx * dx + dy * dy;
211
if
(S <=
a
) {
212
double
d = (
A
*
A
) /
a
;
213
if
(d < dm)
214
dm = d;
215
}
216
}
217
if
(i && in && Ao *
A
< 0.)
218
in =
false
;
219
Ao =
A
;
220
}
221
if
(in){
222
return
-sqrt(dm);
223
}
224
return
sqrt(dm);
225
}
226
227
// ostream operator overload
228
MsgStream&
229
Trk::TriangleBounds::dump
(MsgStream& sl)
const
230
{
231
sl << std::setiosflags(std::ios::fixed);
232
sl << std::setprecision(7);
233
sl <<
"Trk::TriangleBounds: generating vertices (X, Y) "
<<
'\n'
;
234
sl <<
"("
<<
m_boundValues
[
TriangleBounds::bv_x1
] <<
" , "
<<
m_boundValues
[
TriangleBounds::bv_y1
] <<
") "
<<
'\n'
;
235
sl <<
"("
<<
m_boundValues
[
TriangleBounds::bv_x2
] <<
" , "
<<
m_boundValues
[
TriangleBounds::bv_y2
] <<
") "
<<
'\n'
;
236
sl <<
"("
<<
m_boundValues
[
TriangleBounds::bv_x3
] <<
" , "
<<
m_boundValues
[
TriangleBounds::bv_y3
] <<
") "
;
237
sl << std::setprecision(-1);
238
return
sl;
239
}
240
241
std::ostream&
242
Trk::TriangleBounds::dump
(std::ostream& sl)
const
243
{
244
sl << std::setiosflags(std::ios::fixed);
245
sl << std::setprecision(7);
246
sl <<
"Trk::TriangleBounds: generating vertices (X, Y)"
;
247
sl <<
"("
<<
m_boundValues
[
TriangleBounds::bv_x1
] <<
" , "
<<
m_boundValues
[
TriangleBounds::bv_y1
] <<
") "
<<
'\n'
;
248
sl <<
"("
<<
m_boundValues
[
TriangleBounds::bv_x2
] <<
" , "
<<
m_boundValues
[
TriangleBounds::bv_y2
] <<
") "
<<
'\n'
;
249
sl <<
"("
<<
m_boundValues
[
TriangleBounds::bv_x3
] <<
" , "
<<
m_boundValues
[
TriangleBounds::bv_y3
] <<
") "
;
250
sl << std::setprecision(-1);
251
return
sl;
252
}
AmgMatrix
#define AmgMatrix(rows, cols)
Definition
EventPrimitives.h:49
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
TriangleBounds.h
Trk::BoundaryCheck
The BoundaryCheck class allows to steer the way surface boundaries are used for inside/outside checks...
Definition
BoundaryCheck.h:51
Trk::BoundaryCheck::nSigmas
int nSigmas
allowed sigmas for chi2 boundary check
Definition
BoundaryCheck.h:67
Trk::BoundaryCheck::bcType
BoundaryCheckType bcType
Definition
BoundaryCheck.h:70
Trk::BoundaryCheck::EllipseToPoly
std::vector< Amg::Vector2D > EllipseToPoly(int resolution=3) const
Trk::BoundaryCheck::TestKDOPKDOP
bool TestKDOPKDOP(const std::vector< KDOP > &a, const std::vector< KDOP > &b) const
Trk::BoundaryCheck::ComputeKDOP
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.
Trk::BoundaryCheck::toleranceLoc2
double toleranceLoc2
absolute tolerance in local 2 coordinate
Definition
BoundaryCheck.h:69
Trk::BoundaryCheck::FastArcTan
double FastArcTan(double x) const
Trk::BoundaryCheck::FastSinCos
sincosCache FastSinCos(double x) const
Trk::BoundaryCheck::toleranceLoc1
double toleranceLoc1
absolute tolerance in local 1 coordinate
Definition
BoundaryCheck.h:68
Trk::SurfaceBounds
Abstract base class for surface bounds to be specified.
Definition
SurfaceBounds.h:47
Trk::TriangleBounds
Bounds for a triangular, planar surface.
Definition
TriangleBounds.h:39
Trk::TriangleBounds::TriangleBounds
TriangleBounds()
Default Constructor - needed for persistency.
Definition
TriangleBounds.cxx:19
Trk::TriangleBounds::r
virtual double r() const override final
This method returns the maximal extension on the local plane, i.e.
Trk::TriangleBounds::bv_y1
@ bv_y1
Definition
TriangleBounds.h:46
Trk::TriangleBounds::bv_length
@ bv_length
Definition
TriangleBounds.h:51
Trk::TriangleBounds::bv_x2
@ bv_x2
Definition
TriangleBounds.h:47
Trk::TriangleBounds::bv_x3
@ bv_x3
Definition
TriangleBounds.h:49
Trk::TriangleBounds::bv_x1
@ bv_x1
Definition
TriangleBounds.h:45
Trk::TriangleBounds::bv_y2
@ bv_y2
Definition
TriangleBounds.h:48
Trk::TriangleBounds::bv_y3
@ bv_y3
Definition
TriangleBounds.h:50
Trk::TriangleBounds::operator==
virtual bool operator==(const SurfaceBounds &sbo) const override
Equality operator.
Definition
TriangleBounds.cxx:66
Trk::TriangleBounds::inside
virtual bool inside(const Amg::Vector2D &locpo, double tol1=0., double tol2=0.) const override final
This method checks if the provided local coordinates are inside the surface bounds.
Definition
TriangleBounds.cxx:76
Trk::TriangleBounds::dump
virtual MsgStream & dump(MsgStream &sl) const override
Output Method for MsgStream.
Definition
TriangleBounds.cxx:229
Trk::TriangleBounds::m_boundValues
std::vector< TDD_real_t > m_boundValues
Definition
TriangleBounds.h:118
Trk::TriangleBounds::vertices
std::vector< std::pair< TDD_real_t, TDD_real_t > > vertices() const
This method returns the coordinates of vertices.
Trk::TriangleBounds::minDistance
virtual double minDistance(const Amg::Vector2D &pos) const override final
Minimal distance to boundary ( > 0 if outside and <=0 if inside).
Definition
TriangleBounds.cxx:179
inline_hints.h
ATH_FLATTEN
#define ATH_FLATTEN
Definition
inline_hints.h:52
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition
GeoPrimitives.h:48
Trk::locY
@ locY
local cartesian
Definition
ParamDefs.h:38
Trk::x
@ x
Definition
ParamDefs.h:55
Trk::locX
@ locX
Definition
ParamDefs.h:37
Trk::theta
@ theta
Definition
ParamDefs.h:66
Trk::y
@ y
Definition
ParamDefs.h:56
A
hold the test vectors and ease the comparison
Trk::sincosCache
Definition
BoundaryCheck.h:45
Trk::sincosCache::sinC
double sinC
Definition
BoundaryCheck.h:46
Trk::sincosCache::cosC
double cosC
Definition
BoundaryCheck.h:47
Generated on
for ATLAS Offline Software by
1.17.0