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  enum BoundValues : int {
35  eMinR = 0,
36  eMaxR = 1,
40  eOriginX = 5,
41  eOriginY = 6,
42  eSize = 7
43  };
44 
45  AnnulusBounds() = delete;
46 
57  AnnulusBounds(double minR, double maxR, double minPhiRel, double maxPhiRel,
58  const Vector2D& moduleOrigin = {0, 0},
59  double avgPhi = 0) noexcept(false)
60  : AnnulusBounds({minR, maxR, minPhiRel, maxPhiRel, avgPhi,
61  moduleOrigin.x(), moduleOrigin.y()}) {}
62 
66  AnnulusBounds(const std::array<double, eSize>& values) noexcept(false);
67 
68  AnnulusBounds(const AnnulusBounds& source) = default;
69 
70  SurfaceBounds::BoundsType type() const final;
71 
75  std::vector<double> values() const final;
76 
84  virtual bool inside(const Vector2D& lposition,
85  const BoundaryCheck& bcheck) const final;
86 
90  std::ostream& toStream(std::ostream& sl) const final;
91 
94  double get(BoundValues bValue) const { return m_values[bValue]; }
95 
98  double phiMin() const;
99 
102  double phiMax() const;
103 
105  bool coversFullAzimuth() const final;
106 
109  bool insideRadialBounds(double R, double tolerance = 0.) const final;
110 
112  double binningValueR() const final;
113 
115  double binningValuePhi() const final;
116 
121  Vector2D moduleOrigin() const;
122 
127  std::vector<Vector2D> corners() const;
128 
142  std::vector<Vector2D> vertices(unsigned int lseg) const;
143 
145  double rMin() const final;
146 
148  double rMax() const final;
149 
150  private:
151  std::array<double, eSize> m_values;
152 
153  // @TODO: Does this need to be in bound values?
155  Vector2D m_shiftXY; // == -m_moduleOrigin
157  double m_phiAvg;
160 
161  // Vectors needed for inside checking
166 
171 
176 
179  void checkConsistency() noexcept(false);
180 
189  virtual bool inside(const Vector2D& lposition, double tolR,
190  double tolPhi) const final;
191 
197  Vector2D stripXYToModulePC(const Vector2D& vStripXY) const;
198 
200  Vector2D closestOnSegment(const Vector2D& a, const Vector2D& b,
201  const Vector2D& p,
202  const Eigen::Matrix<double, 2, 2>& weight) const;
203 
205  double squaredNorm(const Vector2D& v,
206  const Eigen::Matrix<double, 2, 2>& weight) const;
207 };
208 
211 }
212 
213 inline double AnnulusBounds::rMin() const {
214  return get(eMinR);
215 }
216 
217 inline double AnnulusBounds::rMax() const {
218  return get(eMaxR);
219 }
220 
221 inline double AnnulusBounds::phiMin() const {
222  return get(eMinPhiRel) + get(eAveragePhi);
223 }
224 
225 inline double AnnulusBounds::phiMax() const {
226  return get(eMaxPhiRel) + get(eAveragePhi);
227 }
228 
229 inline bool AnnulusBounds::coversFullAzimuth() const {
230  return (std::abs((get(eMinPhiRel) - get(eMaxPhiRel)) - M_PI) <
232 }
233 
235  double tolerance) const {
236  return ((R + tolerance) > get(eMinR) and (R - tolerance) < get(eMaxR));
237 }
238 
239 inline double AnnulusBounds::binningValueR() const {
240  return 0.5 * (get(eMinR) + get(eMaxR));
241 }
242 
243 inline double AnnulusBounds::binningValuePhi() const {
244  return get(eAveragePhi);
245 }
246 
247 inline std::vector<double> AnnulusBounds::values() const {
248  std::vector<double> valvector;
249  valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
250  return valvector;
251 }
252 
253 inline void AnnulusBounds::checkConsistency() noexcept(false) {
254  if (get(eMinR) < 0. or get(eMaxR) < 0. or get(eMinR) > get(eMaxR) or
255  std::abs(get(eMinR) - get(eMaxR)) < s_epsilon) {
256  throw std::invalid_argument("AnnulusBounds: invalid radial setup.");
257  }
258  if (get(eMinPhiRel) != detail::radian_sym(get(eMinPhiRel)) or
259  get(eMaxPhiRel) != detail::radian_sym(get(eMaxPhiRel)) or
260  get(eMinPhiRel) > get(eMaxPhiRel)) {
261  throw std::invalid_argument("AnnulusBounds: invalid phi boundary setup.");
262  }
263  if (get(eAveragePhi) != detail::radian_sym(get(eAveragePhi))) {
264  throw std::invalid_argument("AnnulusBounds: invalid phi positioning.");
265  }
266 }
267 
268 } // namespace Acts