ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
TrkDetDescr
TrkSurfaces
src
ConeBounds.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
// ConeBounds.cxx, (c) ATLAS Detector Software
8
9
// Trk
10
#include "
TrkSurfaces/ConeBounds.h
"
11
// Gaudi
12
#include "GaudiKernel/MsgStream.h"
13
// STD
14
#include <cmath>
15
#include <iomanip>
16
#include <iostream>
17
18
Trk::ConeBounds::ConeBounds
()
19
:
m_boundValues
(
ConeBounds
::
bv_length
, 0.)
20
,
m_tanAlpha
(0.)
21
,
m_sinAlpha
(0.)
22
,
m_cosAlpha
(0.)
23
{}
24
25
Trk::ConeBounds::ConeBounds
(
double
alpha
,
bool
symm,
double
halfphi,
double
avphi)
26
:
m_boundValues
(
ConeBounds
::
bv_length
, 0.)
27
,
m_tanAlpha
(0.)
28
,
m_sinAlpha
(0.)
29
,
m_cosAlpha
(0.)
30
{
31
m_boundValues
[
ConeBounds::bv_alpha
] =
alpha
;
32
m_boundValues
[
ConeBounds::bv_minZ
] = symm ? -
MAXBOUNDVALUE
: 0.;
33
m_boundValues
[
ConeBounds::bv_maxZ
] =
MAXBOUNDVALUE
;
34
m_boundValues
[
ConeBounds::bv_averagePhi
] = avphi;
35
m_boundValues
[
ConeBounds::bv_halfPhiSector
] = halfphi;
36
ConeBounds::initCache
();
37
}
38
39
Trk::ConeBounds::ConeBounds
(
double
alpha
,
double
zmin,
double
zmax,
40
double
halfphi,
double
avphi)
41
:
m_boundValues
(
ConeBounds
::
bv_length
, 0.),
42
m_tanAlpha
(0.),
43
m_sinAlpha
(0.),
44
m_cosAlpha
(0.) {
45
m_boundValues
[
ConeBounds::bv_alpha
] =
alpha
;
46
m_boundValues
[
ConeBounds::bv_minZ
] = zmin;
47
m_boundValues
[
ConeBounds::bv_maxZ
] = zmax;
48
m_boundValues
[
ConeBounds::bv_averagePhi
] = avphi;
49
m_boundValues
[
ConeBounds::bv_halfPhiSector
] = halfphi;
50
ConeBounds::initCache
();
51
}
52
53
void
Trk::ConeBounds::initCache
() {
54
m_tanAlpha
= tan(
m_boundValues
[
ConeBounds::bv_alpha
]);
55
m_sinAlpha
= sin(
m_boundValues
[
ConeBounds::bv_alpha
]);
56
m_cosAlpha
= cos(
m_boundValues
[
ConeBounds::bv_alpha
]);
57
// validate the halfphi
58
if
(
m_boundValues
[
ConeBounds::bv_halfPhiSector
] < 0.)
59
m_boundValues
[
ConeBounds::bv_halfPhiSector
] =
60
-
m_boundValues
[
ConeBounds::bv_halfPhiSector
];
61
if
(
m_boundValues
[
ConeBounds::bv_halfPhiSector
] >
M_PI
)
62
m_boundValues
[
ConeBounds::bv_halfPhiSector
] =
M_PI
;
63
}
64
65
bool
Trk::ConeBounds::operator==
(
const
SurfaceBounds
& sbo)
const
{
66
// check the type first not to compare apples with oranges
67
const
Trk::ConeBounds
* conebo =
dynamic_cast<
const
Trk::ConeBounds
*
>
(&sbo);
68
if
(!conebo)
69
return
false
;
70
return
(
m_boundValues
== conebo->
m_boundValues
);
71
}
72
73
double
74
Trk::ConeBounds::minDistance
(
const
Amg::Vector2D
& pos)
const
75
{
76
// This needs to be split based on where pos is with respect to the
77
// cone. Inside, its easy, inside the z-region or inside the phi
78
// region, just get the difference from the outside quantity, for
79
// outside both the z and dphi regions, need to get the distance to
80
// the cone corner, but remember, the cone piece will be symmetric
81
// about the center of phi
82
83
// TODO: The whole scheme here assumes that the local position is in
84
// a half of R^3 where the cone is defined. If the local position is
85
// in say the z < 0 half, and the cone is only defined for z > 0,
86
// then it won't work
87
88
// find the minimum distance along the z direction
89
double
toMinZ =
m_boundValues
[
ConeBounds::bv_minZ
] - pos[
locZ
];
90
double
toMaxZ = pos[
locZ
] -
m_boundValues
[
ConeBounds::bv_maxZ
];
91
double
toZ = (fabs(toMinZ) < fabs(toMaxZ)) ? toMinZ : toMaxZ;
92
93
// NB this works only if the localPos is in the same hemisphere as
94
// the cone (i.e. if the localPos has z < 0 and the cone only
95
// defined for z > z_min where z_min > 0, this is wrong)
96
double
zDist = sqrt(toZ * toZ * (1. +
m_tanAlpha
*
m_tanAlpha
));
97
if
(toZ < 0.)
// positive if outside the cone only
98
zDist = -zDist;
99
100
// if the cone is complete, or pos is in the same phi range as the
101
// cone piece then its just the distance along the cone.
102
if
(
m_boundValues
[
ConeBounds::bv_halfPhiSector
] >=
M_PI
)
103
return
zDist;
104
105
// we have a conical segment, so find also the phi distance
106
// Note that here we take the phi distance as the distance from
107
// going to the correct phi by a straight line at the point that was
108
// input by the user (not at the point of closest approach to the
109
// cone)
110
double
posR = pos[
locZ
] *
m_tanAlpha
;
111
double
deltaPhi
= pos[
locRPhi
] / posR -
m_boundValues
[
ConeBounds::bv_averagePhi
];
// from center
112
if
(
deltaPhi
>
M_PI
)
113
deltaPhi
= 2 *
M_PI
-
deltaPhi
;
114
if
(
deltaPhi
< -
M_PI
)
115
deltaPhi
= 2 *
M_PI
+
deltaPhi
;
116
117
// straight line distance (goes off cone)
118
double
phiDist = 2 * posR * sin(.5 * (
deltaPhi
-
m_boundValues
[
ConeBounds::bv_halfPhiSector
]));
119
120
// if inside the cone, return the smaller length (since both are
121
// negative, the *larger* of the 2 is the *smaller* distance)
122
if
(phiDist <= 0. && zDist <= 0) {
123
if
(phiDist > zDist){
124
return
phiDist;
125
}
126
return
zDist;
127
}
128
129
// if inside the phi or z boundary, return the other
130
if
(phiDist <= 0.){
131
return
zDist;
132
}
133
if
(zDist <= 0.){
134
return
phiDist;
135
}
136
137
// otherwise, return both (this should be the distance to the corner
138
// closest to the cone
139
return
sqrt(zDist * zDist + phiDist * phiDist);
140
}
141
142
// ostream operator overload
143
144
MsgStream&
145
Trk::ConeBounds::dump
(MsgStream& sl)
const
146
{
147
sl << std::setiosflags(std::ios::fixed);
148
sl << std::setprecision(7);
149
sl <<
"Trk::ConeBounds: (tanAlpha, minZ, maxZ, averagePhi, halfPhiSector) = "
;
150
sl <<
"("
<< this->
tanAlpha
() <<
", "
<< this->
minZ
() <<
", "
<< this->
maxZ
() <<
", "
<< this->
averagePhi
() <<
", "
151
<< this->
halfPhiSector
() <<
")"
;
152
sl << std::setprecision(-1);
153
return
sl;
154
}
155
156
std::ostream&
157
Trk::ConeBounds::dump
(std::ostream& sl)
const
158
{
159
sl << std::setiosflags(std::ios::fixed);
160
sl << std::setprecision(7);
161
sl <<
"Trk::ConeBounds: (tanAlpha, minZ, maxZ, averagePhi, halfPhiSector) = "
;
162
sl <<
"("
<< this->
tanAlpha
() <<
", "
<< this->
minZ
() <<
", "
<< this->
maxZ
() <<
", "
<< this->
averagePhi
() <<
", "
163
<< this->
halfPhiSector
() <<
")"
;
164
sl << std::setprecision(-1);
165
return
sl;
166
}
M_PI
#define M_PI
Definition
ActiveFraction.h:14
deltaPhi
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
Definition
AmgMatrixBasePlugin.h:112
ConeBounds.h
MAXBOUNDVALUE
const double MAXBOUNDVALUE
Definition
ConeBounds.h:24
Trk::ConeBounds
Bounds for a conical Surface, the opening angle is stored in and always positively defined.
Definition
ConeBounds.h:44
Trk::ConeBounds::m_sinAlpha
TDD_real_t m_sinAlpha
Definition
ConeBounds.h:153
Trk::ConeBounds::minZ
double minZ() const
This method returns the minimum z value in the local framee.
Trk::ConeBounds::m_tanAlpha
TDD_real_t m_tanAlpha
Definition
ConeBounds.h:152
Trk::ConeBounds::alpha
double alpha() const
Trk::ConeBounds::tanAlpha
double tanAlpha() const
This method returns the average phi.
Trk::ConeBounds::dump
virtual MsgStream & dump(MsgStream &sl) const override
Output Method for MsgStream.
Definition
ConeBounds.cxx:145
Trk::ConeBounds::operator==
virtual bool operator==(const SurfaceBounds &sbo) const override
Equality operator.
Definition
ConeBounds.cxx:65
Trk::ConeBounds::maxZ
double maxZ() const
This method returns the maximum z value in the local framee.
Trk::ConeBounds::halfPhiSector
double halfPhiSector() const
This method returns the half-phi width of the sector (so that averagePhi +/- halfPhiSector gives the ...
Trk::ConeBounds::m_boundValues
std::vector< TDD_real_t > m_boundValues
internal storage of the geometry parameters
Definition
ConeBounds.h:151
Trk::ConeBounds::bv_minZ
@ bv_minZ
Definition
ConeBounds.h:50
Trk::ConeBounds::bv_alpha
@ bv_alpha
Definition
ConeBounds.h:49
Trk::ConeBounds::bv_maxZ
@ bv_maxZ
Definition
ConeBounds.h:51
Trk::ConeBounds::bv_length
@ bv_length
Definition
ConeBounds.h:54
Trk::ConeBounds::bv_halfPhiSector
@ bv_halfPhiSector
Definition
ConeBounds.h:53
Trk::ConeBounds::bv_averagePhi
@ bv_averagePhi
Definition
ConeBounds.h:52
Trk::ConeBounds::initCache
virtual void initCache() override final
Helper function for angle parameter initialization.
Definition
ConeBounds.cxx:53
Trk::ConeBounds::ConeBounds
ConeBounds()
Default Constructor.
Definition
ConeBounds.cxx:18
Trk::ConeBounds::averagePhi
double averagePhi() const
This method returns the average phi value (i.e.
Trk::ConeBounds::m_cosAlpha
TDD_real_t m_cosAlpha
Definition
ConeBounds.h:154
Trk::ConeBounds::minDistance
virtual double minDistance(const Amg::Vector2D &pos) const override
Minimal distance to boundary ( > 0 if outside and <=0 if inside).
Definition
ConeBounds.cxx:74
Trk::SurfaceBounds::SurfaceBounds
SurfaceBounds()=default
Default Constructor.
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition
GeoPrimitives.h:48
Trk::locRPhi
@ locRPhi
Definition
ParamDefs.h:40
Trk::locZ
@ locZ
local cylindrical
Definition
ParamDefs.h:42
Generated on
for ATLAS Offline Software by
1.17.0