ATLAS Offline Software
Loading...
Searching...
No Matches
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
11// Gaudi
12#include "GaudiKernel/MsgStream.h"
13// STD
14#include <cmath>
15#include <iomanip>
16#include <iostream>
17
24
38
52
64
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
73double
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.
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
144MsgStream&
145Trk::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
156std::ostream&
157Trk::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}
#define M_PI
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
const double MAXBOUNDVALUE
Definition ConeBounds.h:24
Bounds for a conical Surface, the opening angle is stored in and always positively defined.
Definition ConeBounds.h:44
TDD_real_t m_sinAlpha
Definition ConeBounds.h:153
double minZ() const
This method returns the minimum z value in the local framee.
TDD_real_t m_tanAlpha
Definition ConeBounds.h:152
double alpha() const
double tanAlpha() const
This method returns the average phi.
virtual MsgStream & dump(MsgStream &sl) const override
Output Method for MsgStream.
virtual bool operator==(const SurfaceBounds &sbo) const override
Equality operator.
double maxZ() const
This method returns the maximum z value in the local framee.
double halfPhiSector() const
This method returns the half-phi width of the sector (so that averagePhi +/- halfPhiSector gives the ...
std::vector< TDD_real_t > m_boundValues
internal storage of the geometry parameters
Definition ConeBounds.h:151
virtual void initCache() override final
Helper function for angle parameter initialization.
ConeBounds()
Default Constructor.
double averagePhi() const
This method returns the average phi value (i.e.
TDD_real_t m_cosAlpha
Definition ConeBounds.h:154
virtual double minDistance(const Amg::Vector2D &pos) const override
Minimal distance to boundary ( > 0 if outside and <=0 if inside)
SurfaceBounds()=default
Default Constructor.
Eigen::Matrix< double, 2, 1 > Vector2D
@ locRPhi
Definition ParamDefs.h:40
@ locZ
local cylindrical
Definition ParamDefs.h:42