ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EllipseBounds.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EllipseBounds.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
12 
13 #include <cmath>
14 #include <iomanip>
15 #include <iostream>
16 
19 
22 }
23 
24 static inline double square(double x) {
25  return x * x;
26 }
27 
29 bool Acts::EllipseBounds::inside(const Vector2D& lposition,
30  const BoundaryCheck& bcheck) const {
31  double tol0 = bcheck.m_tolerance[0];
32  double tol1 = bcheck.m_tolerance[1];
33  double phi =
34  detail::radian_sym(VectorHelpers::phi(lposition) - get(eAveragePhi));
35  double phiHalf = get(eHalfPhiSector) + tol1;
36 
37  bool insidePhi = (-phiHalf <= phi) && (phi < phiHalf);
38  bool insideInner =
39  (get(eInnerRx) <= tol0) || (get(eOuterRx) <= tol0) ||
40  (1 < (square(lposition[Acts::eLOC_X] / (get(eInnerRx) - tol0)) +
41  square(lposition[Acts::eLOC_Y] / (get(eOuterRx) - tol0))));
42  bool insideOuter =
43  ((square(lposition[Acts::eLOC_X] / (get(eInnerRy) + tol0)) +
44  square(lposition[Acts::eLOC_Y] / (get(eOuterRy) + tol0))) < 1);
45  return (insidePhi && insideInner && insideOuter);
46 }
47 
48 // For ellipse bound this is only approximation which is valid
49 // only if m_values.at(EllipseBounds::bv_rMinX) ~=
50 // m_values.at(EllipseBounds::bv_rMinY)
51 // and m_values.at(EllipseBounds::bv_rMaxX) ~=
52 // m_values.at(EllipseBounds::bv_rMaxY)
53 //
55  const Vector2D& lposition) const {
56  double r = perp(lposition);
57  if (r == 0) {
58  return std::min(get(eInnerRx), get(eOuterRx));
59  }
60 
61  double sn = lposition[eLOC_X] / r;
62  double cs = lposition[eLOC_Y] / r;
63  double dF = detail::radian_sym(phi(lposition) - get(eAveragePhi));
64  double sf = 0.;
65 
66  if (get(eHalfPhiSector) < M_PI) {
67  double df = std::abs(dF) - get(eHalfPhiSector);
68  sf = r * std::sin(df);
69  if (df > 0.) {
70  r *= std::cos(df);
71  }
72  } else {
73  sf = -1.e+10;
74  }
75 
76  if (sf <= 0.) {
77  double a = cs / get(eInnerRy);
78  double b = sn / get(eOuterRy);
79  double sr0 = r - 1. / std::hypot(a, b);
80  if (sr0 >= 0.) {
81  return sr0;
82  }
83  a = cs / get(eInnerRx);
84  b = sn / get(eOuterRx);
85  double sr1 = 1. / std::hypot(a, b) - r;
86  if (sr1 >= 0.) {
87  return sr1;
88  }
89  if (sf < sr0) {
90  sf = sr0;
91  }
92  if (sf < sr1) {
93  sf = sr1;
94  }
95  return sf;
96  }
97 
98  double fb;
99  fb = (dF > 0.) ? (get(eAveragePhi) + get(eHalfPhiSector))
100  : (get(eAveragePhi) - get(eHalfPhiSector));
101  sn = sin(fb);
102  cs = cos(fb);
103  double a = cs / get(eInnerRy);
104  double b = sn / get(eOuterRy);
105  double sr0 = r - 1. / std::hypot(a, b);
106  if (sr0 >= 0.) {
107  return std::hypot(sr0, sf);
108  }
109  a = cs / get(eInnerRx);
110  b = sn / get(eOuterRx);
111  double sr1 = (1. / std::hypot(a, b)) - r;
112  if (sr1 >= 0.) {
113  return std::hypot(sr1, sf);
114  }
115  return sf;
116 }
117 
118 std::vector<Acts::Vector2D> Acts::EllipseBounds::vertices(
119  unsigned int lseg) const {
121  get(eInnerRx), get(eInnerRy), get(eOuterRx), get(eOuterRy),
122  get(eAveragePhi), get(eHalfPhiSector), lseg);
123 }
124 
126  return m_boundingBox;
127 }
128 
129 // ostream operator overload
130 std::ostream& Acts::EllipseBounds::toStream(std::ostream& sl) const {
131  sl << std::setiosflags(std::ios::fixed);
132  sl << std::setprecision(7);
133  sl << "Acts::EllipseBounds: (innerRadius0, outerRadius0, innerRadius1, "
134  "outerRadius1, hPhiSector, averagePhi) = ";
135  sl << "(" << get(eInnerRx) << ", " << get(eInnerRy) << ", " << get(eOuterRx)
136  << ", " << get(eOuterRy) << ", " << get(eAveragePhi) << ", "
137  << get(eHalfPhiSector) << ", " << get(eAveragePhi) << ")";
138  sl << std::setprecision(-1);
139  return sl;
140 }