ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
TrkDetDescr
TrkSurfaces
src
RectangleBounds.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
// RectangleBounds.cxx, (c) ATLAS Detector Software
8
9
// Trk
10
#include "
TrkSurfaces/RectangleBounds.h
"
11
// Gaudi
12
#include "GaudiKernel/MsgStream.h"
13
// STD
14
#include <iomanip>
15
#include <iostream>
16
17
// default constructor
18
Trk::RectangleBounds::RectangleBounds
()
19
:
m_boundValues
(
RectangleBounds
::
bv_length
, 0.)
20
{}
21
22
// rectangle constructor
23
Trk::RectangleBounds::RectangleBounds
(
double
halex,
double
haley)
24
:
m_boundValues
(
RectangleBounds
::
bv_length
, 0.)
25
{
26
m_boundValues
[
RectangleBounds::bv_halfX
] = halex;
27
m_boundValues
[
RectangleBounds::bv_halfY
] = haley;
28
}
29
30
// copy constructor
31
Trk::RectangleBounds::RectangleBounds
(
const
RectangleBounds
& recbo)
32
:
Trk
::
SurfaceBounds
()
33
,
m_boundValues
(recbo.
m_boundValues
)
34
{}
35
36
37
Trk::RectangleBounds
&
38
Trk::RectangleBounds::operator=
(
const
RectangleBounds
& recbo)
39
{
40
if
(
this
!= &recbo)
41
m_boundValues
= recbo.
m_boundValues
;
42
return
*
this
;
43
}
44
45
bool
46
Trk::RectangleBounds::operator==
(
const
Trk::SurfaceBounds
& sbo)
const
47
{
48
// check the type first not to compare apples with oranges
49
const
Trk::RectangleBounds
* recbo =
dynamic_cast<
const
Trk::RectangleBounds
*
>
(&sbo);
50
if
(!recbo)
51
return
false
;
52
return
(
m_boundValues
== recbo->
m_boundValues
);
53
}
54
55
bool
56
Trk::RectangleBounds::inside
(
const
Amg::Vector2D
& locpo,
57
const
BoundaryCheck
& bchk)
const
58
{
59
if
(bchk.
bcType
== 0)
60
return
RectangleBounds::inside
(
61
locpo, bchk.
toleranceLoc1
, bchk.
toleranceLoc2
);
62
63
// a fast FALSE
64
double
max_ell = bchk.lCovariance(0, 0) > bchk.lCovariance(1, 1)
65
? bchk.lCovariance(0, 0)
66
: bchk.lCovariance(1, 1);
67
double
limit = bchk.
nSigmas
* sqrt(max_ell);
68
if
(!
RectangleBounds::inside
(locpo, limit, limit))
69
return
false
;
70
// a fast TRUE
71
double
min_ell = bchk.lCovariance(0, 0) < bchk.lCovariance(1, 1)
72
? bchk.lCovariance(0, 0)
73
: bchk.lCovariance(1, 1);
74
limit = bchk.
nSigmas
* sqrt(min_ell);
75
if
(
RectangleBounds::inside
(locpo, limit, limit))
76
return
true
;
77
78
// compute KDOP and axes for surface polygon
79
std::vector<KDOP> elementKDOP(4);
80
std::vector<Amg::Vector2D> elementP(4);
81
float
theta
=
82
(bchk.lCovariance(1, 0) != 0 &&
83
(bchk.lCovariance(1, 1) - bchk.lCovariance(0, 0)) != 0)
84
? .5 * bchk.
FastArcTan
(2 * bchk.lCovariance(1, 0) /
85
(bchk.lCovariance(1, 1) - bchk.lCovariance(0, 0)))
86
: 0.;
87
sincosCache
scResult = bchk.
FastSinCos
(
theta
);
88
AmgMatrix
(2, 2) rotMatrix;
89
rotMatrix << scResult.
cosC
, scResult.
sinC
, -scResult.
sinC
, scResult.
cosC
;
90
// ellipse is always at (0,0), surface is moved to ellipse position and then
91
// rotated
92
Amg::Vector2D
p;
93
p =
Amg::Vector2D
(
m_boundValues
[
RectangleBounds::bv_halfX
],
94
m_boundValues
[
RectangleBounds::bv_halfY
]);
95
elementP[0] = (rotMatrix * (p - locpo));
96
p =
Amg::Vector2D
(
m_boundValues
[
RectangleBounds::bv_halfX
],
97
-
m_boundValues
[
RectangleBounds::bv_halfY
]);
98
elementP[1] = (rotMatrix * (p - locpo));
99
p =
Amg::Vector2D
(-
m_boundValues
[
RectangleBounds::bv_halfX
],
100
m_boundValues
[
RectangleBounds::bv_halfY
]);
101
elementP[2] = (rotMatrix * (p - locpo));
102
p =
Amg::Vector2D
(-
m_boundValues
[
RectangleBounds::bv_halfX
],
103
-
m_boundValues
[
RectangleBounds::bv_halfY
]);
104
elementP[3] = (rotMatrix * (p - locpo));
105
std::vector<Amg::Vector2D> axis = { elementP[0] - elementP[1],
106
elementP[0] - elementP[2],
107
elementP[0] - elementP[3],
108
elementP[1] - elementP[2] };
109
bchk.
ComputeKDOP
(elementP, axis, elementKDOP);
110
// compute KDOP for error ellipse
111
std::vector<KDOP> errelipseKDOP(4);
112
bchk.
ComputeKDOP
(bchk.
EllipseToPoly
(3), axis, errelipseKDOP);
113
// check if KDOPs overlap and return result
114
return
bchk.
TestKDOPKDOP
(elementKDOP, errelipseKDOP);
115
}
116
117
double
118
Trk::RectangleBounds::minDistance
(
const
Amg::Vector2D
& pos)
const
119
{
120
double
dx = std::abs(pos[0]) -
m_boundValues
[
RectangleBounds::bv_halfX
];
121
double
dy = std::abs(pos[1]) -
m_boundValues
[
RectangleBounds::bv_halfY
];
122
123
if
(dx <= 0. || dy <= 0.) {
124
if
(dx > dy){
125
return
dx;
126
}
127
return
dy;
128
}
129
return
sqrt(dx * dx + dy * dy);
130
}
131
132
// ostream operator overload
133
MsgStream&
134
Trk::RectangleBounds::dump
(MsgStream& sl)
const
135
{
136
sl << std::setiosflags(std::ios::fixed);
137
sl << std::setprecision(7);
138
sl <<
"Trk::RectangleBounds: (halflenghtX, halflengthY) = "
139
<<
"("
<<
m_boundValues
[
RectangleBounds::bv_halfX
] <<
", "
<<
m_boundValues
[
RectangleBounds::bv_halfY
] <<
")"
;
140
sl << std::setprecision(-1);
141
return
sl;
142
}
143
144
std::ostream&
145
Trk::RectangleBounds::dump
(std::ostream& sl)
const
146
{
147
sl << std::setiosflags(std::ios::fixed);
148
sl << std::setprecision(7);
149
sl <<
"Trk::RectangleBounds: (halflenghtX, halflengthY) = "
150
<<
"("
<<
m_boundValues
[
RectangleBounds::bv_halfX
] <<
", "
<<
m_boundValues
[
RectangleBounds::bv_halfY
] <<
")"
;
151
sl << std::setprecision(-1);
152
return
sl;
153
}
AmgMatrix
#define AmgMatrix(rows, cols)
Definition
EventPrimitives.h:49
RectangleBounds.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::RectangleBounds
Bounds for a rectangular, planar surface.
Definition
RectangleBounds.h:38
Trk::RectangleBounds::m_boundValues
std::vector< TDD_real_t > m_boundValues
The internal version of the bounds can be float/double.
Definition
RectangleBounds.h:119
Trk::RectangleBounds::bv_halfY
@ bv_halfY
Definition
RectangleBounds.h:45
Trk::RectangleBounds::bv_halfX
@ bv_halfX
Definition
RectangleBounds.h:44
Trk::RectangleBounds::bv_length
@ bv_length
Definition
RectangleBounds.h:46
Trk::RectangleBounds::minDistance
virtual double minDistance(const Amg::Vector2D &pos) const override final
Minimal distance to boundary ( > 0 if outside and <=0 if inside).
Definition
RectangleBounds.cxx:118
Trk::RectangleBounds::operator==
virtual bool operator==(const SurfaceBounds &sbo) const override final
Equality operator.
Definition
RectangleBounds.cxx:46
Trk::RectangleBounds::operator=
RectangleBounds & operator=(const RectangleBounds &recbo)
Assignment Operator.
Definition
RectangleBounds.cxx:38
Trk::RectangleBounds::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.
Trk::RectangleBounds::dump
virtual MsgStream & dump(MsgStream &sl) const override
Output Method for MsgStream.
Definition
RectangleBounds.cxx:134
Trk::RectangleBounds::RectangleBounds
RectangleBounds()
Default Constructor - needed for persistency.
Definition
RectangleBounds.cxx:18
Trk::SurfaceBounds
Abstract base class for surface bounds to be specified.
Definition
SurfaceBounds.h:47
Trk::SurfaceBounds::SurfaceBounds
SurfaceBounds()=default
Default Constructor.
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition
GeoPrimitives.h:48
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition
FakeTrackBuilder.h:9
Trk::theta
@ theta
Definition
ParamDefs.h:66
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