ATLAS Offline Software
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 
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 {
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.) {
51 }
52 
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 
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
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 }
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
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
PixelAthClusterMonAlgCfg.zmin
zmin
Definition: PixelAthClusterMonAlgCfg.py:176
Trk::SurfaceBounds
Definition: SurfaceBounds.h:47
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
Trk::locRPhi
@ locRPhi
Definition: ParamDefs.h:46
M_PI
#define M_PI
Definition: ActiveFraction.h:11
Trk::ConeBounds
Definition: ConeBounds.h:44
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
Trk::ConeBounds::dump
virtual MsgStream & dump(MsgStream &sl) const override
Output Method for MsgStream.
Definition: ConeBounds.cxx:145
Trk::ConeBounds::m_boundValues
std::vector< TDD_real_t > m_boundValues
internal storage of the geometry parameters
Definition: ConeBounds.h:151
Trk::ConeBounds::bv_maxZ
@ bv_maxZ
Definition: ConeBounds.h:51
Trk::ConeBounds::bv_halfPhiSector
@ bv_halfPhiSector
Definition: ConeBounds.h:53
Trk::locZ
@ locZ
local cylindrical
Definition: ParamDefs.h:48
Trk::ConeBounds::bv_alpha
@ bv_alpha
Definition: ConeBounds.h:49
Trk::ConeBounds::initCache
virtual void initCache() override final
Helper function for angle parameter initialization.
Definition: ConeBounds.cxx:53
PixelAthClusterMonAlgCfg.zmax
zmax
Definition: PixelAthClusterMonAlgCfg.py:176
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
Trk::ConeBounds::operator==
virtual bool operator==(const SurfaceBounds &sbo) const override
Equality operator.
Definition: ConeBounds.cxx:65
Trk::ConeBounds::bv_averagePhi
@ bv_averagePhi
Definition: ConeBounds.h:52
Trk::ConeBounds::ConeBounds
ConeBounds()
Default Constructor.
Definition: ConeBounds.cxx:18
Trk::ConeBounds::bv_minZ
@ bv_minZ
Definition: ConeBounds.h:50
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::ConeBounds::alpha
double alpha() const
ConeBounds.h
MAXBOUNDVALUE
const double MAXBOUNDVALUE
Definition: ConeBounds.h:24
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36