ATLAS Offline Software
Loading...
Searching...
No Matches
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
11// Gaudi
12#include "GaudiKernel/MsgStream.h"
13// STD
14#include <iomanip>
15#include <iostream>
16namespace {
17//closeToZero = 1.17549e-38
18constexpr double closeToZero = std::numeric_limits<float>::min();
19}
23
49
51 double minradY,
52 double maxradX,
53 double maxradY,
54 double avephi,
55 double hphisec)
57{
58
67 }
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){
75 }
76 if(std::abs(m_boundValues[EllipseBounds::bv_rMinY])<closeToZero){
78 }
79
80
81}
82
83bool
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//
97double
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.) {
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
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
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;
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;
152 sn = sin(fb);
153 cs = cos(fb);
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 }
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
171MsgStream&
172Trk::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
183std::ostream&
184Trk::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}
#define M_PI
static Double_t a
Class to describe the bounds for a planar EllipseSurface, i.e.
double rMinX() const
This method returns first inner radius.
double rMinY() const
This method returns second inner radius.
virtual double minDistance(const Amg::Vector2D &pos) const override final
Minimal distance to boundary ( > 0 if outside and <=0 if inside)
EllipseBounds()
Default Constructor.
double averagePhi() const
This method returns the average phi.
std::vector< TDD_real_t > m_boundValues
The internal storage of the bounds can be float/double.
double rMaxY() const
This method returns second outer radius.
virtual bool operator==(const SurfaceBounds &sbo) const override
Equality operator.
double halfPhiSector() const
This method returns the halfPhiSector which is covered by the disc.
virtual MsgStream & dump(MsgStream &sl) const override
Output Method for MsgStream.
double rMaxX() const
This method returns first outer radius.
virtual double r() const override final
This method returns the maximum expansion on the plane (=max(rMaxX,rMaxY))
Abstract base class for surface bounds to be specified.
void swap(double &b1, double &b2)
Swap method to be called from DiscBounds or TrapezoidalBounds.
Eigen::Matrix< double, 2, 1 > Vector2D