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 
96  std::vector<Vector2D> vertices(unsigned int lseg = 1) const final;
97 
98  // Bounding box representation
99  const RectangleBounds& boundingBox() const final;
100 
104  std::ostream& toStream(std::ostream& sl) const final;
105 
108  double get(BoundValues bValue) const { return m_values[bValue]; }
109 
110  private:
111  std::array<double, eSize> m_values;
113 
116  void checkConsistency() noexcept(false);
117 };
118 
119 inline std::vector<double> DiamondBounds::values() const {
120  std::vector<double> valvector;
121  valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
122  return valvector;
123 }
124 
125 inline void DiamondBounds::checkConsistency() noexcept(false) {
126  if (std::any_of(m_values.begin(), m_values.end(),
127  [](auto v) { return v <= 0.; })) {
128  throw std::invalid_argument("DiamondBounds: negative half length.");
129  }
130  if (get(eHalfLengthXnegY) > get(eHalfLengthXzeroY) or
131  get(eHalfLengthXposY) > get(eHalfLengthXzeroY)) {
132  throw std::invalid_argument("DiamondBounds: not a diamond shape.");
133  }
134 }
135 
136 } // namespace Acts