ATLAS Offline Software
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>
16 namespace {
17 //closeToZero = 1.17549e-38
18 constexpr double closeToZero = std::numeric_limits<float>::min();
19 }
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 {
35  }
38  }
39  //Make sure we do not get exactly 0 but something else small
40  if(std::abs(m_boundValues[EllipseBounds::bv_rMinX])<closeToZero){
42  }
43  if(std::abs(m_boundValues[EllipseBounds::bv_rMinY])<closeToZero){
45  }
46 
47 
48 }
49 
51  double minradY,
52  double maxradX,
53  double maxradY,
54  double avephi,
55  double hphisec)
56  : m_boundValues(EllipseBounds::bv_length, 0.)
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 
83 bool
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
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 }
EllipseBounds.h
beamspotman.r
def r
Definition: beamspotman.py:676
Trk::EllipseBounds::bv_rMaxY
@ bv_rMaxY
Definition: EllipseBounds.h:46
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
Trk::EllipseBounds
Definition: EllipseBounds.h:38
Trk::SurfaceBounds
Definition: SurfaceBounds.h:47
Trk::EllipseBounds::dump
virtual MsgStream & dump(MsgStream &sl) const override
Output Method for MsgStream.
Definition: EllipseBounds.cxx:172
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
Trk::SurfaceBounds::swap
void swap(double &b1, double &b2)
Swap method to be called from DiscBounds or TrapezoidalBounds.
Definition: SurfaceBounds.h:133
python.PhysicalConstants.pi2
float pi2
Definition: PhysicalConstants.py:52
M_PI
#define M_PI
Definition: ActiveFraction.h:11
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
Trk::EllipseBounds::EllipseBounds
EllipseBounds()
Default Constructor.
Definition: EllipseBounds.cxx:20
Trk::EllipseBounds::bv_averagePhi
@ bv_averagePhi
Definition: EllipseBounds.h:47
Trk::EllipseBounds::operator==
virtual bool operator==(const SurfaceBounds &sbo) const override
Equality operator.
Definition: EllipseBounds.cxx:84
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::bv_rMinY
@ bv_rMinY
Definition: EllipseBounds.h:44
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
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
a
TList * a
Definition: liststreamerinfos.cxx:10
Trk::EllipseBounds::bv_rMaxX
@ bv_rMaxX
Definition: EllipseBounds.h:45
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
Trk::EllipseBounds::bv_rMinX
@ bv_rMinX
Definition: EllipseBounds.h:43
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
Trk::EllipseBounds::bv_halfPhiSector
@ bv_halfPhiSector
Definition: EllipseBounds.h:48
python.TriggerAPI.TriggerAPISession.df
df
Definition: TriggerAPISession.py:432