Analysis Software
Documentation for sPHENIX simulation 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 
18 
19 #include <array>
20 #include <cmath>
21 #include <exception>
22 #include <iosfwd>
23 #include <stdexcept>
24 #include <vector>
25 
26 namespace Acts {
27 
38 class AnnulusBounds : public DiscBounds {
39  public:
40  enum BoundValues : int {
41  eMinR = 0,
42  eMaxR = 1,
46  eOriginX = 5,
47  eOriginY = 6,
48  eSize = 7
49  };
50 
51  AnnulusBounds() = delete;
52 
63  AnnulusBounds(double minR, double maxR, double minPhiRel, double maxPhiRel,
64  const Vector2& moduleOrigin = {0, 0},
65  double avgPhi = 0) noexcept(false)
66  : AnnulusBounds({minR, maxR, minPhiRel, maxPhiRel, avgPhi,
67  moduleOrigin.x(), moduleOrigin.y()}) {}
68 
72  AnnulusBounds(const std::array<double, eSize>& values) noexcept(false);
73 
74  AnnulusBounds(const AnnulusBounds& source) = default;
75 
76  SurfaceBounds::BoundsType type() const final;
77 
81  std::vector<double> values() const final;
82 
90  bool inside(const Vector2& lposition,
91  const BoundaryCheck& bcheck) const final;
92 
96  std::ostream& toStream(std::ostream& sl) const final;
97 
100  double get(BoundValues bValue) const { return m_values[bValue]; }
101 
104  double phiMin() const;
105 
108  double phiMax() const;
109 
111  bool coversFullAzimuth() const final;
112 
115  bool insideRadialBounds(double R, double tolerance = 0.) const final;
116 
118  double binningValueR() const final;
119 
121  double binningValuePhi() const final;
122 
127  Vector2 moduleOrigin() const;
128 
133  std::vector<Vector2> corners() const;
134 
148  std::vector<Vector2> vertices(unsigned int lseg) const override;
149 
151  double rMin() const final;
152 
154  double rMax() const final;
155 
156  private:
157  std::array<double, eSize> m_values;
158 
159  // @TODO: Does this need to be in bound values?
161  Vector2 m_shiftXY; // == -m_moduleOrigin
165 
166  // Vectors needed for inside checking
171 
176 
181 
184  void checkConsistency() noexcept(false);
185 
194  virtual bool inside(const Vector2& lposition, double tolR,
195  double tolPhi) const final;
196 
202  Vector2 stripXYToModulePC(const Vector2& vStripXY) const;
203 
205  Vector2 closestOnSegment(const Vector2& a, const Vector2& b, const Vector2& p,
206  const SquareMatrix2& weight) const;
207 
209  double squaredNorm(const Vector2& v, const SquareMatrix2& weight) const;
210 };
211 
214 }
215 
216 inline double AnnulusBounds::rMin() const {
217  return get(eMinR);
218 }
219 
220 inline double AnnulusBounds::rMax() const {
221  return get(eMaxR);
222 }
223 
224 inline double AnnulusBounds::phiMin() const {
225  return get(eMinPhiRel) + get(eAveragePhi);
226 }
227 
228 inline double AnnulusBounds::phiMax() const {
229  return get(eMaxPhiRel) + get(eAveragePhi);
230 }
231 
232 inline bool AnnulusBounds::coversFullAzimuth() const {
233  return (std::abs((get(eMinPhiRel) - get(eMaxPhiRel)) - M_PI) <
235 }
236 
238  double tolerance) const {
239  return ((R + tolerance) > get(eMinR) and (R - tolerance) < get(eMaxR));
240 }
241 
242 inline double AnnulusBounds::binningValueR() const {
243  return 0.5 * (get(eMinR) + get(eMaxR));
244 }
245 
246 inline double AnnulusBounds::binningValuePhi() const {
247  return get(eAveragePhi);
248 }
249 
250 inline std::vector<double> AnnulusBounds::values() const {
251  std::vector<double> valvector;
252  valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
253  return valvector;
254 }
255 
256 inline void AnnulusBounds::checkConsistency() noexcept(false) {
257  if (get(eMinR) < 0. or get(eMaxR) < 0. or get(eMinR) > get(eMaxR) or
258  std::abs(get(eMinR) - get(eMaxR)) < s_epsilon) {
259  throw std::invalid_argument("AnnulusBounds: invalid radial setup.");
260  }
261  if (get(eMinPhiRel) != detail::radian_sym(get(eMinPhiRel)) or
262  get(eMaxPhiRel) != detail::radian_sym(get(eMaxPhiRel)) or
263  get(eMinPhiRel) > get(eMaxPhiRel)) {
264  throw std::invalid_argument("AnnulusBounds: invalid phi boundary setup.");
265  }
266  if (get(eAveragePhi) != detail::radian_sym(get(eAveragePhi))) {
267  throw std::invalid_argument("AnnulusBounds: invalid phi positioning.");
268  }
269 }
270 
271 } // namespace Acts