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  public:
50  enum BoundValues : unsigned int {
55  };
56 
57  CuboidVolumeBounds() = delete;
58 
64  CuboidVolumeBounds(double halex, double haley, double halez) noexcept(false);
65 
69  CuboidVolumeBounds(const std::array<double, eSize>& values) noexcept(false)
70  : m_values(values) {
73  }
74 
79 
84 
85  ~CuboidVolumeBounds() override = default;
86 
88 
92  std::vector<double> values() const final;
93 
99  bool inside(const Vector3D& pos, double tol = 0.) const override;
100 
112  const Transform3D& transform = Transform3D::Identity()) const override;
113 
119  Volume::BoundingBox boundingBox(const Transform3D* trf = nullptr,
120  const Vector3D& envelope = {0, 0, 0},
121  const Volume* entity = nullptr) const final;
122 
125  double get(BoundValues bValue) const { return m_values[bValue]; }
126 
130  std::ostream& toStream(std::ostream& sl) const override;
131 
132  private:
136  template <class stream_t>
137  stream_t& dumpT(stream_t& dt) const;
138 
140  std::array<double, eSize> m_values;
141 
142  std::shared_ptr<const RectangleBounds> m_xyBounds{nullptr};
143  std::shared_ptr<const RectangleBounds> m_yzBounds{nullptr};
144  std::shared_ptr<const RectangleBounds> m_zxBounds{nullptr};
145 
147  void buildSurfaceBounds();
148 
151  void checkConsistency() noexcept(false);
152 };
153 
154 inline bool CuboidVolumeBounds::inside(const Vector3D& pos, double tol) const {
155  return (std::abs(pos.x()) <= get(eHalfLengthX) + tol &&
156  std::abs(pos.y()) <= get(eHalfLengthY) + tol &&
157  std::abs(pos.z()) <= get(eHalfLengthZ) + tol);
158 }
159 
160 inline std::vector<double> CuboidVolumeBounds::values() const {
161  std::vector<double> valvector;
162  valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
163  return valvector;
164 }
165 
167  if (get(eHalfLengthX) <= 0 or get(eHalfLengthY) <= 0 or
168  get(eHalfLengthZ) <= 0.) {
169  throw std::invalid_argument(
170  "CuboidVolumeBounds: invalid input, zero or negative.");
171  }
172 }
173 
174 template <class stream_t>
175 stream_t& CuboidVolumeBounds::dumpT(stream_t& dt) const {
176  dt << std::setiosflags(std::ios::fixed);
177  dt << std::setprecision(5);
178  dt << "Acts::CuboidVolumeBounds: (halfLengthX, halfLengthY, halfLengthZ) = ";
179  dt << "(" << get(eHalfLengthX) << ", " << get(eHalfLengthY) << ", "
180  << get(eHalfLengthZ) << ")";
181  return dt;
182 }
183 } // namespace Acts