ATLAS Offline Software
RectangleBounds.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // RectangleBounds.cxx, (c) ATLAS Detector Software
8 
9 // Trk
11 // Gaudi
12 #include "GaudiKernel/MsgStream.h"
13 // STD
14 #include <iomanip>
15 #include <iostream>
16 
17 // default constructor
19  : m_boundValues(RectangleBounds::bv_length, 0.)
20 {}
21 
22 // rectangle constructor
23 Trk::RectangleBounds::RectangleBounds(double halex, double haley)
24  : m_boundValues(RectangleBounds::bv_length, 0.)
25 {
28 }
29 
30 // copy constructor
32  : Trk::SurfaceBounds()
33  , m_boundValues(recbo.m_boundValues)
34 {}
35 
36 
39 {
40  if (this != &recbo)
41  m_boundValues = recbo.m_boundValues;
42  return *this;
43 }
44 
45 bool
47 {
48  // check the type first not to compare apples with oranges
49  const Trk::RectangleBounds* recbo = dynamic_cast<const Trk::RectangleBounds*>(&sbo);
50  if (!recbo)
51  return false;
52  return (m_boundValues == recbo->m_boundValues);
53 }
54 
55 bool
57  const BoundaryCheck& bchk) const
58 {
59  if (bchk.bcType == 0)
61  locpo, bchk.toleranceLoc1, bchk.toleranceLoc2);
62 
63  // a fast FALSE
64  double max_ell = bchk.lCovariance(0, 0) > bchk.lCovariance(1, 1)
65  ? bchk.lCovariance(0, 0)
66  : bchk.lCovariance(1, 1);
67  double limit = bchk.nSigmas * sqrt(max_ell);
68  if (!RectangleBounds::inside(locpo, limit, limit))
69  return false;
70  // a fast TRUE
71  double min_ell = bchk.lCovariance(0, 0) < bchk.lCovariance(1, 1)
72  ? bchk.lCovariance(0, 0)
73  : bchk.lCovariance(1, 1);
74  limit = bchk.nSigmas * sqrt(min_ell);
75  if (RectangleBounds::inside(locpo, limit, limit))
76  return true;
77 
78  // compute KDOP and axes for surface polygon
79  std::vector<KDOP> elementKDOP(4);
80  std::vector<Amg::Vector2D> elementP(4);
81  float theta =
82  (bchk.lCovariance(1, 0) != 0 &&
83  (bchk.lCovariance(1, 1) - bchk.lCovariance(0, 0)) != 0)
84  ? .5 * bchk.FastArcTan(2 * bchk.lCovariance(1, 0) /
85  (bchk.lCovariance(1, 1) - bchk.lCovariance(0, 0)))
86  : 0.;
87  sincosCache scResult = bchk.FastSinCos(theta);
88  AmgMatrix(2, 2) rotMatrix;
89  rotMatrix << scResult.cosC, scResult.sinC, -scResult.sinC, scResult.cosC;
90  // ellipse is always at (0,0), surface is moved to ellipse position and then
91  // rotated
93  p = Amg::Vector2D (m_boundValues[RectangleBounds::bv_halfX],
94  m_boundValues[RectangleBounds::bv_halfY]);
95  elementP[0] = (rotMatrix * (p - locpo));
96  p = Amg::Vector2D (m_boundValues[RectangleBounds::bv_halfX],
97  -m_boundValues[RectangleBounds::bv_halfY]);
98  elementP[1] = (rotMatrix * (p - locpo));
99  p = Amg::Vector2D (-m_boundValues[RectangleBounds::bv_halfX],
100  m_boundValues[RectangleBounds::bv_halfY]);
101  elementP[2] = (rotMatrix * (p - locpo));
102  p = Amg::Vector2D (-m_boundValues[RectangleBounds::bv_halfX],
103  -m_boundValues[RectangleBounds::bv_halfY]);
104  elementP[3] = (rotMatrix * (p - locpo));
105  std::vector<Amg::Vector2D> axis = { elementP[0] - elementP[1],
106  elementP[0] - elementP[2],
107  elementP[0] - elementP[3],
108  elementP[1] - elementP[2] };
109  bchk.ComputeKDOP(elementP, axis, elementKDOP);
110  // compute KDOP for error ellipse
111  std::vector<KDOP> errelipseKDOP(4);
112  bchk.ComputeKDOP(bchk.EllipseToPoly(3), axis, errelipseKDOP);
113  // check if KDOPs overlap and return result
114  return bchk.TestKDOPKDOP(elementKDOP, errelipseKDOP);
115 }
116 
117 double
119 {
120  double dx = std::abs(pos[0]) - m_boundValues[RectangleBounds::bv_halfX];
121  double dy = std::abs(pos[1]) - m_boundValues[RectangleBounds::bv_halfY];
122 
123  if (dx <= 0. || dy <= 0.) {
124  if (dx > dy){
125  return dx;
126  }
127  return dy;
128  }
129  return sqrt(dx * dx + dy * dy);
130 }
131 
132 // ostream operator overload
133 MsgStream&
134 Trk::RectangleBounds::dump(MsgStream& sl) const
135 {
136  sl << std::setiosflags(std::ios::fixed);
137  sl << std::setprecision(7);
138  sl << "Trk::RectangleBounds: (halflenghtX, halflengthY) = "
139  << "(" << m_boundValues[RectangleBounds::bv_halfX] << ", " << m_boundValues[RectangleBounds::bv_halfY] << ")";
140  sl << std::setprecision(-1);
141  return sl;
142 }
143 
144 std::ostream&
145 Trk::RectangleBounds::dump(std::ostream& sl) const
146 {
147  sl << std::setiosflags(std::ios::fixed);
148  sl << std::setprecision(7);
149  sl << "Trk::RectangleBounds: (halflenghtX, halflengthY) = "
150  << "(" << m_boundValues[RectangleBounds::bv_halfX] << ", " << m_boundValues[RectangleBounds::bv_halfY] << ")";
151  sl << std::setprecision(-1);
152  return sl;
153 }
Trk::RectangleBounds
Definition: RectangleBounds.h:38
Trk::AmgMatrix
AmgMatrix(3, 3) NeutralParticleParameterCalculator
Definition: NeutralParticleParameterCalculator.cxx:233
RectangleBounds.h
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
Trk::SurfaceBounds
Definition: SurfaceBounds.h:47
Trk::RectangleBounds::bv_halfX
@ bv_halfX
Definition: RectangleBounds.h:44
yodamerge_tmp.axis
list axis
Definition: yodamerge_tmp.py:241
Trk::RectangleBounds::dump
virtual MsgStream & dump(MsgStream &sl) const override
Output Method for MsgStream.
Definition: RectangleBounds.cxx:134
Trk::RectangleBounds::bv_halfY
@ bv_halfY
Definition: RectangleBounds.h:45
Trk::RectangleBounds::inside
virtual bool inside(const Amg::Vector2D &locpo, double tol1=0., double tol2=0.) const override final
This method checks if the provided local coordinates are inside the surface bounds.
Trk::BoundaryCheck::EllipseToPoly
std::vector< Amg::Vector2D > EllipseToPoly(int resolution=3) const
Trk::BoundaryCheck::toleranceLoc1
double toleranceLoc1
absolute tolerance in local 1 coordinate
Definition: BoundaryCheck.h:68
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
Trk::theta
@ theta
Definition: ParamDefs.h:66
Trk::BoundaryCheck::bcType
BoundaryCheckType bcType
Definition: BoundaryCheck.h:70
Trk::RectangleBounds::minDistance
virtual double minDistance(const Amg::Vector2D &pos) const override final
Minimal distance to boundary ( > 0 if outside and <=0 if inside)
Definition: RectangleBounds.cxx:118
Trk::sincosCache
Definition: BoundaryCheck.h:45
Trk::BoundaryCheck::TestKDOPKDOP
bool TestKDOPKDOP(const std::vector< KDOP > &a, const std::vector< KDOP > &b) const
Trk::sincosCache::sinC
double sinC
Definition: BoundaryCheck.h:46
Trk::BoundaryCheck::nSigmas
int nSigmas
allowed sigmas for chi2 boundary check
Definition: BoundaryCheck.h:67
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::BoundaryCheck::ComputeKDOP
void ComputeKDOP(const std::vector< Amg::Vector2D > &v, const std::vector< Amg::Vector2D > &KDOPAxes, std::vector< KDOP > &kdop) const
Each Bounds has a method inside, which checks if a LocalPosition is inside the bounds.
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::BoundaryCheck::FastArcTan
double FastArcTan(double x) const
makeTRTBarrelCans.dy
tuple dy
Definition: makeTRTBarrelCans.py:21
Trk::RectangleBounds::m_boundValues
std::vector< TDD_real_t > m_boundValues
The internal version of the bounds can be float/double.
Definition: RectangleBounds.h:119
Trk::BoundaryCheck
Definition: BoundaryCheck.h:51
Trk::sincosCache::cosC
double cosC
Definition: BoundaryCheck.h:47
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
Trk::BoundaryCheck::FastSinCos
sincosCache FastSinCos(double x) const
Trk::BoundaryCheck::toleranceLoc2
double toleranceLoc2
absolute tolerance in local 2 coordinate
Definition: BoundaryCheck.h:69
Trk::RectangleBounds::operator==
virtual bool operator==(const SurfaceBounds &sbo) const override final
Equality operator.
Definition: RectangleBounds.cxx:46
updateCoolNtuple.limit
int limit
Definition: updateCoolNtuple.py:45
Trk::RectangleBounds::RectangleBounds
RectangleBounds()
Default Constructor - needed for persistency.
Definition: RectangleBounds.cxx:18
Trk::RectangleBounds::operator=
RectangleBounds & operator=(const RectangleBounds &recbo)
Assignment Operator.
Definition: RectangleBounds.cxx:38