Analysis Software
Documentation for sPHENIX simulation 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 
17 
18 #include <algorithm>
19 #include <array>
20 #include <cmath>
21 #include <iosfwd>
22 #include <stdexcept>
23 #include <vector>
24 
25 namespace Acts {
26 
30 class DiamondBounds : public PlanarBounds {
31  public:
32  enum BoundValues {
38  eSize = 5
39  };
40 
41  DiamondBounds() = delete;
42 
50  DiamondBounds(double halfXnegY, double halfXzeroY, double halfXposY,
51  double halfYneg, double halfYpos) noexcept(false)
52  : m_values({halfXnegY, halfXzeroY, halfXposY, halfYneg, halfYpos}),
54  Vector2{
55  -(*std::max_element(m_values.begin(), m_values.begin() + 2)),
56  -halfYneg},
57  Vector2{*std::max_element(m_values.begin(), m_values.begin() + 2),
58  halfYpos}) {
60  }
61 
65  DiamondBounds(const std::array<double, eSize>& values) noexcept(false)
66  : m_values(values),
68  Vector2{-(*std::max_element(values.begin(), values.begin() + 2)),
70  Vector2{*std::max_element(values.begin(), values.begin() + 2),
72 
73  ~DiamondBounds() override = default;
74 
75  BoundsType type() const final;
76 
80  std::vector<double> values() const final;
81 
89  bool inside(const Vector2& lposition,
90  const BoundaryCheck& bcheck) const final;
91 
100  std::vector<Vector2> vertices(unsigned int lseg = 1) const final;
101 
102  // Bounding box representation
103  const RectangleBounds& boundingBox() const final;
104 
108  std::ostream& toStream(std::ostream& sl) const final;
109 
112  double get(BoundValues bValue) const { return m_values[bValue]; }
113 
114  private:
115  std::array<double, eSize> m_values;
117 
120  void checkConsistency() noexcept(false);
121 };
122 
123 inline std::vector<double> DiamondBounds::values() const {
124  std::vector<double> valvector;
125  valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
126  return valvector;
127 }
128 
129 inline void DiamondBounds::checkConsistency() noexcept(false) {
130  if (std::any_of(m_values.begin(), m_values.end(),
131  [](auto v) { return v <= 0.; })) {
132  throw std::invalid_argument("DiamondBounds: negative half length.");
133  }
134  if (get(eHalfLengthXnegY) > get(eHalfLengthXzeroY) or
135  get(eHalfLengthXposY) > get(eHalfLengthXzeroY)) {
136  throw std::invalid_argument("DiamondBounds: not a diamond shape.");
137  }
138 }
139 
140 } // namespace Acts