ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
TrkDetDescr
TrkSurfaces
src
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
10
#include "
TrkSurfaces/RotatedDiamondBounds.h
"
11
// Gaudi
12
#include "GaudiKernel/MsgStream.h"
13
// STD
14
#include <cmath>
15
#include <iomanip>
16
#include <iostream>
17
18
// default constructor
19
Trk::RotatedDiamondBounds::RotatedDiamondBounds
()
20
:
m_boundValues
(
RotatedDiamondBounds
::
bv_length
, 0.)
21
,
m_alpha1
(0.)
22
,
m_alpha2
(0.)
23
{}
24
25
// constructor from arguments I
26
Trk::RotatedDiamondBounds::RotatedDiamondBounds
(
double
minhalex,
27
double
medhalex,
28
double
maxhalex,
29
double
haley1,
30
double
haley2)
31
:
m_boundValues
(
RotatedDiamondBounds
::
bv_length
, 0.)
32
,
m_alpha1
(0.)
33
,
m_alpha2
(0.)
34
{
35
m_boundValues
[
RotatedDiamondBounds::bv_minHalfX
] = minhalex;
36
m_boundValues
[
RotatedDiamondBounds::bv_medHalfX
] = medhalex;
37
m_boundValues
[
RotatedDiamondBounds::bv_maxHalfX
] = maxhalex;
38
m_boundValues
[
RotatedDiamondBounds::bv_halfY1
] = haley1;
39
m_boundValues
[
RotatedDiamondBounds::bv_halfY2
] = haley2;
40
if
(minhalex > maxhalex)
41
swap
(
m_boundValues
[
RotatedDiamondBounds::bv_minHalfX
],
m_boundValues
[
RotatedDiamondBounds::bv_maxHalfX
]);
42
RotatedDiamondBounds::initCache
();
43
}
44
45
void
Trk::RotatedDiamondBounds::initCache
() {
46
m_alpha1
= atan2(
m_boundValues
[
RotatedDiamondBounds::bv_medHalfX
] -
47
m_boundValues
[
RotatedDiamondBounds::bv_minHalfX
],
48
2. *
m_boundValues
[
RotatedDiamondBounds::bv_halfY1
]);
49
m_alpha2
= atan2(
m_boundValues
[
RotatedDiamondBounds::bv_medHalfX
] -
50
m_boundValues
[
RotatedDiamondBounds::bv_maxHalfX
],
51
2. *
m_boundValues
[
RotatedDiamondBounds::bv_halfY2
]);
52
}
53
54
bool
55
Trk::RotatedDiamondBounds::operator==
(
const
Trk::SurfaceBounds
& sbo)
const
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
64
bool
65
Trk::RotatedDiamondBounds::inside
(
const
Amg::Vector2D
& locpo,
66
const
BoundaryCheck
& bchk)
const
67
{
68
// locX and locY are interchanged wrt DiamondBounds
69
if
(bchk.
bcType
== 0)
70
return
RotatedDiamondBounds::inside
(
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
] <
78
-2 *
m_boundValues
[
RotatedDiamondBounds::bv_halfY1
] - limit)
79
return
false
;
80
if
(locpo[
Trk::locX
] >
81
2 *
m_boundValues
[
RotatedDiamondBounds::bv_halfY2
] + limit)
82
return
false
;
83
// a fast FALSE
84
double
fabsX = std::abs(locpo[
Trk::locY
]);
85
if
(fabsX > (
m_boundValues
[
RotatedDiamondBounds::bv_medHalfX
] + limit))
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);
92
if
(fabsX < (fmin(
m_boundValues
[
RotatedDiamondBounds::bv_minHalfX
],
93
m_boundValues
[
RotatedDiamondBounds::bv_maxHalfX
]) -
94
limit))
95
return
true
;
96
// a fast TRUE
97
if
(std::abs(locpo[
Trk::locX
]) <
98
(fmin(
m_boundValues
[
RotatedDiamondBounds::bv_halfY1
],
99
m_boundValues
[
RotatedDiamondBounds::bv_halfY2
]) -
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 =
124
Amg::Vector2D
(-
m_boundValues
[
RotatedDiamondBounds::bv_minHalfX
],
125
-2. *
m_boundValues
[
RotatedDiamondBounds::bv_halfY1
]);
126
elementP[0] = (rotMatrix * (p - locpoF));
127
p =
Amg::Vector2D
(-
m_boundValues
[
RotatedDiamondBounds::bv_medHalfX
], 0.);
128
elementP[1] = (rotMatrix * (p - locpoF));
129
p =
Amg::Vector2D
(-
m_boundValues
[
RotatedDiamondBounds::bv_maxHalfX
],
130
2. *
m_boundValues
[
RotatedDiamondBounds::bv_halfY2
]);
131
elementP[2] = (rotMatrix * (p - locpoF));
132
p =
Amg::Vector2D
(
m_boundValues
[
RotatedDiamondBounds::bv_maxHalfX
],
133
2. *
m_boundValues
[
RotatedDiamondBounds::bv_halfY2
]);
134
elementP[3] = (rotMatrix * (p - locpoF));
135
p =
Amg::Vector2D
(
m_boundValues
[
RotatedDiamondBounds::bv_medHalfX
], 0.);
136
elementP[4] = (rotMatrix * (p - locpoF));
137
p =
Amg::Vector2D
(
m_boundValues
[
RotatedDiamondBounds::bv_minHalfX
],
138
-2. *
m_boundValues
[
RotatedDiamondBounds::bv_halfY1
]);
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)
154
bool
155
Trk::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)
161
bool
162
Trk::RotatedDiamondBounds::insideFull
(
const
Amg::Vector2D
& locpo,
double
tol1,
double
tol2)
const
163
{
164
// validity check
165
if
(!
m_boundValues
[
RotatedDiamondBounds::bv_halfY1
] && !
m_boundValues
[
RotatedDiamondBounds::bv_minHalfX
])
return
false
;
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
177
if
(absY < std::min(
m_boundValues
[
RotatedDiamondBounds::bv_minHalfX
],
m_boundValues
[
RotatedDiamondBounds::bv_maxHalfX
]) + tol2)
return
true
;
178
180
const
double
& halfBaseUp = locpo[
Trk::locX
] < 0 ?
m_boundValues
[
RotatedDiamondBounds::bv_medHalfX
] :
m_boundValues
[
RotatedDiamondBounds::bv_maxHalfX
];
181
const
double
& halfBaseLo = locpo[
Trk::locX
] < 0 ?
m_boundValues
[
RotatedDiamondBounds::bv_minHalfX
] :
m_boundValues
[
RotatedDiamondBounds::bv_medHalfX
];
182
const
double
& halfH = locpo[
Trk::locX
] < 0 ?
m_boundValues
[
RotatedDiamondBounds::bv_halfY1
] :
m_boundValues
[
RotatedDiamondBounds::bv_halfY2
];
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
189
double
190
Trk::RotatedDiamondBounds::alpha1
()
const
191
{
192
return
m_alpha1
;
193
}
194
195
// opening angle in point A'
196
double
197
Trk::RotatedDiamondBounds::alpha2
()
const
198
{
199
return
m_alpha2
;
200
}
201
202
double
203
Trk::RotatedDiamondBounds::minDistance
(
const
Amg::Vector2D
& pos)
const
204
{
205
const
int
Np = 6;
206
207
double
y1 = 2. *
m_boundValues
[
RotatedDiamondBounds::bv_halfY1
];
208
double
y2 = 2. *
m_boundValues
[
RotatedDiamondBounds::bv_halfY2
];
209
210
double
X[6] = { -
m_boundValues
[
RotatedDiamondBounds::bv_minHalfX
], -
m_boundValues
[
RotatedDiamondBounds::bv_medHalfX
],
211
-
m_boundValues
[
RotatedDiamondBounds::bv_maxHalfX
],
m_boundValues
[
RotatedDiamondBounds::bv_maxHalfX
],
212
m_boundValues
[
RotatedDiamondBounds::bv_medHalfX
],
m_boundValues
[
RotatedDiamondBounds::bv_minHalfX
] };
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
254
MsgStream&
255
Trk::RotatedDiamondBounds::dump
(MsgStream& sl)
const
256
{
257
sl << std::setiosflags(std::ios::fixed);
258
sl << std::setprecision(7);
259
sl <<
"Trk::RotatedDiamondBounds: (minHlenghtX, medHlengthX, maxHlengthX, hlengthY1, hlengthY2 ) = "
;
260
sl <<
"("
<<
m_boundValues
[
RotatedDiamondBounds::bv_minHalfX
] <<
", "
261
<<
m_boundValues
[
RotatedDiamondBounds::bv_medHalfX
] <<
", "
<<
m_boundValues
[
RotatedDiamondBounds::bv_maxHalfX
]
262
<<
", "
<<
m_boundValues
[
RotatedDiamondBounds::bv_halfY1
] <<
", "
<<
m_boundValues
[
RotatedDiamondBounds::bv_halfY2
]
263
<<
")"
;
264
sl << std::setprecision(-1);
265
return
sl;
266
}
267
268
std::ostream&
269
Trk::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 ) = "
;
274
sl <<
"("
<<
m_boundValues
[
RotatedDiamondBounds::bv_minHalfX
] <<
", "
275
<<
m_boundValues
[
RotatedDiamondBounds::bv_medHalfX
] <<
", "
<<
m_boundValues
[
RotatedDiamondBounds::bv_maxHalfX
]
276
<<
", "
<<
m_boundValues
[
RotatedDiamondBounds::bv_halfY1
] <<
", "
<<
m_boundValues
[
RotatedDiamondBounds::bv_halfY2
]
277
<<
")"
;
278
sl << std::setprecision(-1);
279
return
sl;
280
}
AmgMatrix
#define AmgMatrix(rows, cols)
Definition
EventPrimitives.h:49
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
RotatedDiamondBounds.h
sign
int sign(int a)
Definition
TRT_StrawNeighbourSvc.h:108
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::RotatedDiamondBounds
Bounds for a double trapezoidal ("diamond"), planar Surface.
Definition
RotatedDiamondBounds.h:42
Trk::RotatedDiamondBounds::alpha2
double alpha2() const
This method returns the opening angle alpha in point A'.
Definition
RotatedDiamondBounds.cxx:197
Trk::RotatedDiamondBounds::initCache
virtual void initCache() override
initialize the alpha1/2 cache - needed also for object persistency
Definition
RotatedDiamondBounds.cxx:45
Trk::RotatedDiamondBounds::minDistance
virtual double minDistance(const Amg::Vector2D &pos) const override
Minimal distance to boundary ( > 0 if outside and <=0 if inside).
Definition
RotatedDiamondBounds.cxx:203
Trk::RotatedDiamondBounds::m_alpha2
TDD_real_t m_alpha2
Definition
RotatedDiamondBounds.h:147
Trk::RotatedDiamondBounds::RotatedDiamondBounds
RotatedDiamondBounds()
Default Constructor, needed for persistency.
Definition
RotatedDiamondBounds.cxx:19
Trk::RotatedDiamondBounds::insideFull
bool insideFull(const Amg::Vector2D &locpo, double tol1=0., double tol2=0.) const
inside() method for a full symmetric diamond
Definition
RotatedDiamondBounds.cxx:162
Trk::RotatedDiamondBounds::m_alpha1
TDD_real_t m_alpha1
Definition
RotatedDiamondBounds.h:146
Trk::RotatedDiamondBounds::inside
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.
Definition
RotatedDiamondBounds.cxx:155
Trk::RotatedDiamondBounds::m_boundValues
std::vector< TDD_real_t > m_boundValues
Internal parameters stored in the geometry.
Definition
RotatedDiamondBounds.h:145
Trk::RotatedDiamondBounds::operator==
virtual bool operator==(const SurfaceBounds &diabo) const override
Equality operator.
Definition
RotatedDiamondBounds.cxx:55
Trk::RotatedDiamondBounds::alpha1
double alpha1() const
This method returns the opening angle alpha in point A.
Definition
RotatedDiamondBounds.cxx:190
Trk::RotatedDiamondBounds::dump
virtual MsgStream & dump(MsgStream &sl) const override
Output Method for MsgStream.
Definition
RotatedDiamondBounds.cxx:255
Trk::RotatedDiamondBounds::bv_medHalfX
@ bv_medHalfX
Definition
RotatedDiamondBounds.h:49
Trk::RotatedDiamondBounds::bv_halfY1
@ bv_halfY1
Definition
RotatedDiamondBounds.h:51
Trk::RotatedDiamondBounds::bv_maxHalfX
@ bv_maxHalfX
Definition
RotatedDiamondBounds.h:50
Trk::RotatedDiamondBounds::bv_minHalfX
@ bv_minHalfX
Definition
RotatedDiamondBounds.h:48
Trk::RotatedDiamondBounds::bv_halfY2
@ bv_halfY2
Definition
RotatedDiamondBounds.h:52
Trk::RotatedDiamondBounds::bv_length
@ bv_length
Definition
RotatedDiamondBounds.h:53
Trk::SurfaceBounds
Abstract base class for surface bounds to be specified.
Definition
SurfaceBounds.h:47
Trk::SurfaceBounds::swap
void swap(double &b1, double &b2)
Swap method to be called from DiscBounds or TrapezoidalBounds.
Definition
SurfaceBounds.h:133
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