ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AnnulusBounds.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AnnulusBounds.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 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 
9 #pragma once
10 
15 
16 #include <array>
17 #include <exception>
18 #include <vector>
19 
20 namespace Acts {
21 
32 class AnnulusBounds : public DiscBounds {
33  public:
34  using Transform2D = Eigen::Affine2d;
35 
36  enum BoundValues : int {
37  eMinR = 0,
38  eMaxR = 1,
42  eOriginX = 5,
43  eOriginY = 6,
44  eSize = 7
45  };
46 
47  AnnulusBounds() = delete;
48 
59  AnnulusBounds(double minR, double maxR, double minPhiRel, double maxPhiRel,
60  const Vector2D& moduleOrigin = {0, 0},
61  double avgPhi = 0) noexcept(false)
62  : AnnulusBounds({minR, maxR, minPhiRel, maxPhiRel, avgPhi,
63  moduleOrigin.x(), moduleOrigin.y()}) {}
64 
68  AnnulusBounds(const std::array<double, eSize>& values) noexcept(false);
69 
70  AnnulusBounds(const AnnulusBounds& source) = default;
71 
72  SurfaceBounds::BoundsType type() const final;
73 
77  std::vector<double> values() const final;
78 
86  virtual bool inside(const Vector2D& lposition,
87  const BoundaryCheck& bcheck) const final;
88 
93  virtual double distanceToBoundary(const Vector2D& lposition) const final;
94 
98  std::ostream& toStream(std::ostream& sl) const final;
99 
102  double get(BoundValues bValue) const { return m_values[bValue]; }
103 
106  double phiMin() const;
107 
110  double phiMax() const;
111 
113  bool coversFullAzimuth() const final;
114 
117  bool insideRadialBounds(double R, double tolerance = 0.) const final;
118 
120  double binningValueR() const final;
121 
123  double binningValuePhi() const final;
124 
129  Vector2D moduleOrigin() const;
130 
135  std::vector<Vector2D> corners() const;
136 
150  std::vector<Vector2D> vertices(unsigned int lseg) const;
151 
153  double rMin() const final;
154 
156  double rMax() const final;
157 
158  private:
159  std::array<double, eSize> m_values;
160 
161  // @TODO: Does this need to be in bound values?
163  Vector2D m_shiftXY; // == -m_moduleOrigin
165  double m_phiAvg;
168 
169  // Vectors needed for inside checking
174 
179 
184 
187  void checkConsistency() noexcept(false);
188 
197  virtual bool inside(const Vector2D& lposition, double tolR,
198  double tolPhi) const final;
199 
205  Vector2D stripXYToModulePC(const Vector2D& vStripXY) const;
206 
208  Vector2D closestOnSegment(const Vector2D& a, const Vector2D& b,
209  const Vector2D& p,
210  const Eigen::Matrix<double, 2, 2>& weight) const;
211 
213  double squaredNorm(const Vector2D& v,
214  const Eigen::Matrix<double, 2, 2>& weight) const;
215 };
216 
219 }
220 
221 inline double AnnulusBounds::rMin() const {
222  return get(eMinR);
223 }
224 
225 inline double AnnulusBounds::rMax() const {
226  return get(eMaxR);
227 }
228 
229 inline double AnnulusBounds::phiMin() const {
230  return get(eMinPhiRel) + get(eAveragePhi);
231 }
232 
233 inline double AnnulusBounds::phiMax() const {
234  return get(eMaxPhiRel) + get(eAveragePhi);
235 }
236 
237 inline bool AnnulusBounds::coversFullAzimuth() const {
238  return (std::abs((get(eMinPhiRel) - get(eMaxPhiRel)) - M_PI) <
240 }
241 
243  double tolerance) const {
244  return ((R + tolerance) > get(eMinR) and (R - tolerance) < get(eMaxR));
245 }
246 
247 inline double AnnulusBounds::binningValueR() const {
248  return 0.5 * (get(eMinR) + get(eMaxR));
249 }
250 
251 inline double AnnulusBounds::binningValuePhi() const {
252  return get(eAveragePhi);
253 }
254 
255 inline std::vector<double> AnnulusBounds::values() const {
256  std::vector<double> valvector;
257  valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
258  return valvector;
259 }
260 
261 inline void AnnulusBounds::checkConsistency() noexcept(false) {
262  if (get(eMinR) < 0. or get(eMaxR) < 0. or get(eMinR) > get(eMaxR) or
263  std::abs(get(eMinR) - get(eMaxR)) < s_epsilon) {
264  throw std::invalid_argument("AnnulusBounds: invalid radial setup.");
265  }
266  if (get(eMinPhiRel) != detail::radian_sym(get(eMinPhiRel)) or
267  get(eMaxPhiRel) != detail::radian_sym(get(eMaxPhiRel)) or
268  get(eMinPhiRel) > get(eMaxPhiRel)) {
269  throw std::invalid_argument("AnnulusBounds: invalid phi boundary setup.");
270  }
271  if (get(eAveragePhi) != detail::radian_sym(get(eAveragePhi))) {
272  throw std::invalid_argument("AnnulusBounds: invalid phi positioning.");
273  }
274 }
275 
276 } // namespace Acts