ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CuboidVolumeBounds.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CuboidVolumeBounds.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 
11 #include "Acts/Geometry/Volume.hpp"
15 
16 #include <array>
17 #include <cmath>
18 #include <exception>
19 #include <vector>
20 
21 namespace Acts {
22 
23 class RectangleBounds;
24 class Volume;
25 class Surface;
26 
48 
50  public:
52  enum BoundValues : int {
56  eSize = 3
57  };
58 
59  CuboidVolumeBounds() = delete;
60 
66  CuboidVolumeBounds(double halex, double haley, double halez) noexcept(false);
67 
71  CuboidVolumeBounds(const std::array<double, eSize>& values) noexcept(false)
72  : m_values(values) {
74  }
75 
80 
85 
86  ~CuboidVolumeBounds() override = default;
87 
89 
93  std::vector<double> values() const final;
94 
100  bool inside(const Vector3D& pos, double tol = 0.) const override;
101 
106  const Transform3D* transformPtr) const override;
107 
113  Volume::BoundingBox boundingBox(const Transform3D* trf = nullptr,
114  const Vector3D& envelope = {0, 0, 0},
115  const Volume* entity = nullptr) const final;
116 
120  std::ostream& toStream(std::ostream& sl) const override;
121 
124  double get(BoundValues bValue) const { return m_values[bValue]; }
125 
126  private:
128  template <class T>
129  T& dumpT(T& dt) const;
130 
132  std::array<double, eSize> m_values;
133 
134  std::shared_ptr<const RectangleBounds> m_xyBounds = nullptr;
135  std::shared_ptr<const RectangleBounds> m_yzBounds = nullptr;
136  std::shared_ptr<const RectangleBounds> m_zxBounds = nullptr;
137 
140  void checkConsistency() noexcept(false);
141 };
142 
143 inline bool CuboidVolumeBounds::inside(const Vector3D& pos, double tol) const {
144  return (std::abs(pos.x()) <= get(eHalfLengthX) + tol &&
145  std::abs(pos.y()) <= get(eHalfLengthY) + tol &&
146  std::abs(pos.z()) <= get(eHalfLengthZ) + tol);
147 }
148 
149 inline std::vector<double> CuboidVolumeBounds::values() const {
150  std::vector<double> valvector;
151  valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
152  return valvector;
153 }
154 
156  if (get(eHalfLengthX) <= 0 or get(eHalfLengthY) <= 0 or
157  get(eHalfLengthZ) <= 0.) {
158  throw std::invalid_argument(
159  "CuboidVolumeBounds: invalid input, zero or negative.");
160  }
161 }
162 
163 template <class T>
165  dt << std::setiosflags(std::ios::fixed);
166  dt << std::setprecision(5);
167  dt << "Acts::CuboidVolumeBounds: (halfLengthX, halfLengthY, halfLengthZ) = ";
168  dt << "(" << get(eHalfLengthX) << ", " << get(eHalfLengthY) << ", "
169  << get(eHalfLengthZ) << ")";
170  return dt;
171 }
172 } // namespace Acts