ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DiamondBounds.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DiamondBounds.hpp
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 
9 #pragma once
10 
15 
16 #include <algorithm>
17 #include <array>
18 #include <cmath>
19 #include <vector>
20 
21 namespace Acts {
22 
26 class DiamondBounds : public PlanarBounds {
27  public:
28  enum BoundValues {
34  eSize = 5
35  };
36 
37  DiamondBounds() = delete;
38 
46  DiamondBounds(double halfXnegY, double halfXzeroY, double halfXposY,
47  double halfYneg, double halfYpos) noexcept(false)
48  : m_values({halfXnegY, halfXzeroY, halfXposY, halfYneg, halfYpos}),
50  Vector2D{
51  -(*std::max_element(m_values.begin(), m_values.begin() + 2)),
52  -halfYneg},
53  Vector2D{*std::max_element(m_values.begin(), m_values.begin() + 2),
54  halfYpos}) {
56  }
57 
61  DiamondBounds(const std::array<double, eSize>& values) noexcept(false)
62  : m_values(values),
64  Vector2D{-(*std::max_element(values.begin(), values.begin() + 2)),
66  Vector2D{*std::max_element(values.begin(), values.begin() + 2),
68 
69  ~DiamondBounds() override = default;
70 
71  BoundsType type() const final;
72 
76  std::vector<double> values() const final;
77 
85  bool inside(const Vector2D& lposition,
86  const BoundaryCheck& bcheck) const final;
87 
92  double distanceToBoundary(const Vector2D& lposition) const final;
93 
102  std::vector<Vector2D> vertices(unsigned int lseg = 1) const final;
103 
104  // Bounding box representation
105  const RectangleBounds& boundingBox() const final;
106 
110  std::ostream& toStream(std::ostream& sl) const final;
111 
114  double get(BoundValues bValue) const { return m_values[bValue]; }
115 
116  private:
117  std::array<double, eSize> m_values;
119 
122  void checkConsistency() noexcept(false);
123 };
124 
125 inline std::vector<double> DiamondBounds::values() const {
126  std::vector<double> valvector;
127  valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
128  return valvector;
129 }
130 
131 inline void DiamondBounds::checkConsistency() noexcept(false) {
132  if (std::any_of(m_values.begin(), m_values.end(),
133  [](auto v) { return v <= 0.; })) {
134  throw std::invalid_argument("DiamondBounds: negative half length.");
135  }
136  if (get(eHalfLengthXnegY) > get(eHalfLengthXzeroY) or
137  get(eHalfLengthXposY) > get(eHalfLengthXzeroY)) {
138  throw std::invalid_argument("DiamondBounds: not a diamond shape.");
139  }
140 }
141 
142 } // namespace Acts