ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
TrkDetDescr
TrkSurfaces
src
EllipseBounds.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
// EllipseBounds.cxx, (c) ATLAS Detector Software
8
9
// Trk
10
#include "
TrkSurfaces/EllipseBounds.h
"
11
// Gaudi
12
#include "GaudiKernel/MsgStream.h"
13
// STD
14
#include <iomanip>
15
#include <iostream>
16
namespace
{
17
//closeToZero = 1.17549e-38
18
constexpr
double
closeToZero = std::numeric_limits<float>::min();
19
}
20
Trk::EllipseBounds::EllipseBounds
()
21
:
m_boundValues
(
EllipseBounds
::
bv_length
, 0.)
22
{}
23
24
Trk::EllipseBounds::EllipseBounds
(
double
minradX,
double
minradY,
double
maxradX,
double
maxradY,
double
hphisec)
25
:
m_boundValues
(
EllipseBounds
::
bv_length
, 0.)
26
{
27
m_boundValues
[
EllipseBounds::bv_rMinX
] = minradX;
28
m_boundValues
[
EllipseBounds::bv_rMinY
] = minradY;
29
m_boundValues
[
EllipseBounds::bv_rMaxX
] = maxradX;
30
m_boundValues
[
EllipseBounds::bv_rMaxY
] = maxradY;
31
m_boundValues
[
EllipseBounds::bv_averagePhi
] = 0.;
32
m_boundValues
[
EllipseBounds::bv_halfPhiSector
] = hphisec;
33
if
(
m_boundValues
[
EllipseBounds::bv_rMinX
] >
m_boundValues
[
EllipseBounds::bv_rMaxX
]){
34
swap
(
m_boundValues
[
EllipseBounds::bv_rMinX
],
m_boundValues
[
EllipseBounds::bv_rMaxX
]);
35
}
36
if
(
m_boundValues
[
EllipseBounds::bv_rMinY
] >
m_boundValues
[
EllipseBounds::bv_rMaxY
]){
37
swap
(
m_boundValues
[
EllipseBounds::bv_rMinY
],
m_boundValues
[
EllipseBounds::bv_rMaxY
]);
38
}
39
//Make sure we do not get exactly 0 but something else small
40
if
(std::abs(
m_boundValues
[
EllipseBounds::bv_rMinX
])<closeToZero){
41
m_boundValues
[
EllipseBounds::bv_rMinX
]= closeToZero;
42
}
43
if
(std::abs(
m_boundValues
[
EllipseBounds::bv_rMinY
])<closeToZero){
44
m_boundValues
[
EllipseBounds::bv_rMinY
]= closeToZero;
45
}
46
47
48
}
49
50
Trk::EllipseBounds::EllipseBounds
(
double
minradX,
51
double
minradY,
52
double
maxradX,
53
double
maxradY,
54
double
avephi,
55
double
hphisec)
56
:
m_boundValues
(
EllipseBounds
::
bv_length
, 0.)
57
{
58
59
m_boundValues
[
EllipseBounds::bv_rMinX
] = minradX;
60
m_boundValues
[
EllipseBounds::bv_rMinY
] = minradY;
61
m_boundValues
[
EllipseBounds::bv_rMaxX
] = maxradX;
62
m_boundValues
[
EllipseBounds::bv_rMaxY
] = maxradY;
63
m_boundValues
[
EllipseBounds::bv_averagePhi
] = avephi;
64
m_boundValues
[
EllipseBounds::bv_halfPhiSector
] = hphisec;
65
if
(
m_boundValues
[
EllipseBounds::bv_rMinX
] >
m_boundValues
[
EllipseBounds::bv_rMaxX
]){
66
swap
(
m_boundValues
[
EllipseBounds::bv_rMinX
],
m_boundValues
[
EllipseBounds::bv_rMaxX
]);
67
}
68
if
(
m_boundValues
[
EllipseBounds::bv_rMinY
] >
m_boundValues
[
EllipseBounds::bv_rMaxY
]){
69
swap
(
m_boundValues
[
EllipseBounds::bv_rMinY
],
m_boundValues
[
EllipseBounds::bv_rMaxY
]);
70
}
71
72
//Make sure we do not get exactly 0 but something else small
73
if
(std::abs(
m_boundValues
[
EllipseBounds::bv_rMinX
])<closeToZero){
74
m_boundValues
[
EllipseBounds::bv_rMinX
]= closeToZero;
75
}
76
if
(std::abs(
m_boundValues
[
EllipseBounds::bv_rMinY
])<closeToZero){
77
m_boundValues
[
EllipseBounds::bv_rMinY
]= closeToZero;
78
}
79
80
81
}
82
83
bool
84
Trk::EllipseBounds::operator==
(
const
Trk::SurfaceBounds
& sbo)
const
85
{
86
// check the type first not to compare apples with oranges
87
const
Trk::EllipseBounds
* discbo =
dynamic_cast<
const
Trk::EllipseBounds
*
>
(&sbo);
88
if
(!discbo)
89
return
false
;
90
return
(
m_boundValues
== discbo->
m_boundValues
);
91
}
92
93
// For ellipse bound this is only approximation which is valid
94
// only if m_boundValues[EllipseBounds::bv_rMinX] ~= m_boundValues[EllipseBounds::bv_rMinY]
95
// and m_boundValues[EllipseBounds::bv_rMaxX] ~= m_boundValues[EllipseBounds::bv_rMaxY]
96
//
97
double
98
Trk::EllipseBounds::minDistance
(
const
Amg::Vector2D
& pos)
const
99
{
100
const
double
pi2 = 2. *
M_PI
;
101
102
double
r
= sqrt(pos[0] * pos[0] + pos[1] * pos[1]);
103
if
(
r
== 0.) {
104
if
(
m_boundValues
[
EllipseBounds::bv_rMinX
] <=
m_boundValues
[
EllipseBounds::bv_rMinY
])
105
return
m_boundValues
[
EllipseBounds::bv_rMinX
];
106
return
m_boundValues
[
EllipseBounds::bv_rMinY
];
107
}
108
109
const
double
inv_r = 1. /
r
;
110
double
sn = pos[1] * inv_r;
111
double
cs = pos[0] * inv_r;
112
double
sf = 0.;
113
double
dF = 0.;
114
115
if
(
m_boundValues
[
EllipseBounds::bv_halfPhiSector
] <
M_PI
) {
116
dF = atan2(cs, sn) -
m_boundValues
[
EllipseBounds::bv_averagePhi
];
117
dF += (dF >
M_PI
) ? -pi2 : (dF < -
M_PI
) ? pi2 : 0;
118
double
df = std::abs(dF) -
m_boundValues
[
EllipseBounds::bv_halfPhiSector
];
119
sf =
r
* sin(df);
120
if
(df > 0.){
121
r
*= cos(df);
122
}
123
}
else
{
124
sf = -1.e+10;
125
}
126
127
if
(sf <= 0.) {
128
129
double
a
= cs /
m_boundValues
[
EllipseBounds::bv_rMaxX
];
130
double
b = sn /
m_boundValues
[
EllipseBounds::bv_rMaxY
];
131
double
sr0 =
r
- 1. / std::sqrt(
a
*
a
+ b * b);
132
if
(sr0 >= 0.)
133
return
sr0;
134
a
= cs /
m_boundValues
[
EllipseBounds::bv_rMinX
];
135
b = sn /
m_boundValues
[
EllipseBounds::bv_rMinY
];
136
double
sr1 = 1. / std::sqrt(
a
*
a
+ b * b) -
r
;
137
if
(sr1 >= 0.){
138
return
sr1;
139
}
140
if
(sf < sr0){
141
sf = sr0;
142
}
143
if
(sf < sr1){
144
sf = sr1;
145
}
146
return
sf;
147
}
148
149
double
fb;
150
fb = (dF > 0.) ?
m_boundValues
[
EllipseBounds::bv_averagePhi
] +
m_boundValues
[
EllipseBounds::bv_halfPhiSector
]
151
:
m_boundValues
[
EllipseBounds::bv_averagePhi
] -
m_boundValues
[
EllipseBounds::bv_halfPhiSector
];
152
sn = sin(fb);
153
cs = cos(fb);
154
double
a
= cs /
m_boundValues
[
EllipseBounds::bv_rMaxX
];
155
double
b = sn /
m_boundValues
[
EllipseBounds::bv_rMaxY
];
156
double
sr0 =
r
- 1. / std::sqrt(
a
*
a
+ b * b);
157
if
(sr0 >= 0.){
158
return
std::sqrt(sr0 * sr0 + sf * sf);
159
}
160
a
= cs /
m_boundValues
[
EllipseBounds::bv_rMinX
];
161
b = sn /
m_boundValues
[
EllipseBounds::bv_rMinY
];
162
double
sr1 = 1. / sqrt(
a
*
a
+ b * b) -
r
;
163
if
(sr1 >= 0.){
164
return
std::sqrt(sr1 * sr1 + sf * sf);
165
}
166
return
sf;
167
}
168
169
// ostream operator overload
170
171
MsgStream&
172
Trk::EllipseBounds::dump
(MsgStream& sl)
const
173
{
174
sl << std::setiosflags(std::ios::fixed);
175
sl << std::setprecision(7);
176
sl <<
"Trk::EllipseBounds: (innerRadiusX, innerRadiusY, outerRadiusX, outerRadiusY, averagePhi, hPhiSector) = "
;
177
sl <<
"("
<< this->
rMinX
() <<
", "
<< this->
rMinY
() <<
", "
<< this->
rMaxX
() <<
", "
<< this->
rMaxY
() <<
", "
178
<< this->
averagePhi
() <<
", "
<< this->
halfPhiSector
() <<
")"
;
179
sl << std::setprecision(-1);
180
return
sl;
181
}
182
183
std::ostream&
184
Trk::EllipseBounds::dump
(std::ostream& sl)
const
185
{
186
sl << std::setiosflags(std::ios::fixed);
187
sl << std::setprecision(7);
188
sl <<
"Trk::EllipseBounds: (innerRadiusX, innerRadiusY, outerRadiusX, outerRadiusY, hPhiSector) = "
;
189
sl <<
"("
<< this->
rMinX
() <<
", "
<< this->
rMinY
() <<
", "
<< this->
rMaxX
() <<
", "
<< this->
rMaxY
() <<
", "
190
<< this->
averagePhi
() <<
", "
<< this->
halfPhiSector
() <<
")"
;
191
sl << std::setprecision(-1);
192
return
sl;
193
}
M_PI
#define M_PI
Definition
ActiveFraction.h:14
EllipseBounds.h
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
Trk::EllipseBounds
Class to describe the bounds for a planar EllipseSurface, i.e.
Definition
EllipseBounds.h:38
Trk::EllipseBounds::rMinX
double rMinX() const
This method returns first inner radius.
Definition
EllipseBounds.h:188
Trk::EllipseBounds::rMinY
double rMinY() const
This method returns second inner radius.
Definition
EllipseBounds.h:193
Trk::EllipseBounds::bv_averagePhi
@ bv_averagePhi
Definition
EllipseBounds.h:47
Trk::EllipseBounds::bv_rMaxY
@ bv_rMaxY
Definition
EllipseBounds.h:46
Trk::EllipseBounds::bv_rMaxX
@ bv_rMaxX
Definition
EllipseBounds.h:45
Trk::EllipseBounds::bv_halfPhiSector
@ bv_halfPhiSector
Definition
EllipseBounds.h:48
Trk::EllipseBounds::bv_length
@ bv_length
Definition
EllipseBounds.h:49
Trk::EllipseBounds::bv_rMinY
@ bv_rMinY
Definition
EllipseBounds.h:44
Trk::EllipseBounds::bv_rMinX
@ bv_rMinX
Definition
EllipseBounds.h:43
Trk::EllipseBounds::minDistance
virtual double minDistance(const Amg::Vector2D &pos) const override final
Minimal distance to boundary ( > 0 if outside and <=0 if inside).
Definition
EllipseBounds.cxx:98
Trk::EllipseBounds::EllipseBounds
EllipseBounds()
Default Constructor.
Definition
EllipseBounds.cxx:20
Trk::EllipseBounds::averagePhi
double averagePhi() const
This method returns the average phi.
Definition
EllipseBounds.h:213
Trk::EllipseBounds::m_boundValues
std::vector< TDD_real_t > m_boundValues
The internal storage of the bounds can be float/double.
Definition
EllipseBounds.h:127
Trk::EllipseBounds::rMaxY
double rMaxY() const
This method returns second outer radius.
Definition
EllipseBounds.h:203
Trk::EllipseBounds::operator==
virtual bool operator==(const SurfaceBounds &sbo) const override
Equality operator.
Definition
EllipseBounds.cxx:84
Trk::EllipseBounds::halfPhiSector
double halfPhiSector() const
This method returns the halfPhiSector which is covered by the disc.
Definition
EllipseBounds.h:218
Trk::EllipseBounds::dump
virtual MsgStream & dump(MsgStream &sl) const override
Output Method for MsgStream.
Definition
EllipseBounds.cxx:172
Trk::EllipseBounds::rMaxX
double rMaxX() const
This method returns first outer radius.
Definition
EllipseBounds.h:198
Trk::EllipseBounds::r
virtual double r() const override final
This method returns the maximum expansion on the plane (=max(rMaxX,rMaxY)).
Definition
EllipseBounds.h:208
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
Generated on
for ATLAS Offline Software by
1.17.0