EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CylinderVolumeBounds.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CylinderVolumeBounds.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 
12 #include "Acts/Geometry/Volume.hpp"
18 
19 #include <array>
20 #include <cmath>
21 #include <exception>
22 #include <vector>
23 
24 namespace Acts {
25 
26 class Surface;
27 class CylinderBounds;
28 class RadialBounds;
29 class PlanarBounds;
30 class IVisualization3D;
31 
69 // Rectangular Acts::PlaneSurface attached to
73  public:
75  enum BoundValues : unsigned int {
76  eMinR = 0,
77  eMaxR = 1,
82  };
83 
84  CylinderVolumeBounds() = delete;
85 
93  CylinderVolumeBounds(double rmin, double rmax, double halfz,
94  double halfphi = M_PI,
95  double avgphi = 0.) noexcept(false)
96  : m_values({rmin, rmax, halfz, halfphi, avgphi}) {
99  }
100 
104  CylinderVolumeBounds(const std::array<double, eSize>& values) noexcept(false)
105  : m_values(values) {
108  }
109 
114  CylinderVolumeBounds(const CylinderBounds& cBounds,
115  double thickness) noexcept(false);
116 
121  CylinderVolumeBounds(const RadialBounds& rBounds,
122  double thickness) noexcept(false);
123 
127  CylinderVolumeBounds(const CylinderVolumeBounds& cylbo) = default;
128 
129  ~CylinderVolumeBounds() override = default;
130  CylinderVolumeBounds& operator=(const CylinderVolumeBounds& cylbo) = default;
131 
134  }
135 
139  std::vector<double> values() const final;
140 
146  bool inside(const Vector3D& pos, double tol = 0.) const override;
147 
159  const Transform3D& transform = Transform3D::Identity()) const override;
160 
166  Volume::BoundingBox boundingBox(const Transform3D* trf = nullptr,
167  const Vector3D& envelope = {0, 0, 0},
168  const Volume* entity = nullptr) const final;
169 
173  Vector3D binningOffset(BinningValue bValue) const override;
174 
178  double binningBorder(BinningValue bValue) const override;
179 
181  std::ostream& toStream(std::ostream& sl) const override;
182 
185  double get(BoundValues bValue) const { return m_values[bValue]; }
186 
187  private:
189  std::array<double, eSize> m_values;
191  std::shared_ptr<const CylinderBounds> m_innerCylinderBounds{nullptr};
193  std::shared_ptr<const CylinderBounds> m_outerCylinderBounds{nullptr};
195  std::shared_ptr<const RadialBounds> m_discBounds{nullptr};
197  std::shared_ptr<const PlanarBounds> m_sectorPlaneBounds{nullptr};
198 
201  void checkConsistency() noexcept(false);
202 
204  void buildSurfaceBounds();
205 
209  template <class stream_t>
210  stream_t& dumpT(stream_t& dt) const;
211 };
212 
214  double tol) const {
215  using VectorHelpers::perp;
216  using VectorHelpers::phi;
217  double ros = perp(pos);
218  bool insidePhi = cos(phi(pos)) >= cos(get(eHalfPhiSector)) - tol;
219  bool insideR = insidePhi
220  ? ((ros >= get(eMinR) - tol) && (ros <= get(eMaxR) + tol))
221  : false;
222  bool insideZ =
223  insideR ? (std::abs(pos.z()) <= get(eHalfLengthZ) + tol) : false;
224  return (insideZ && insideR && insidePhi);
225 }
226 
228  const { // the medium radius is taken for r-type binning
229  if (bValue == Acts::binR || bValue == Acts::binRPhi) {
230  return Vector3D(0.5 * (get(eMinR) + get(eMaxR)), 0., 0.);
231  }
232  return VolumeBounds::binningOffset(bValue);
233 }
234 
236  if (bValue == Acts::binR) {
237  return 0.5 * (get(eMaxR) - get(eMinR));
238  }
239  if (bValue == Acts::binZ) {
240  return get(eHalfLengthZ);
241  }
242  return VolumeBounds::binningBorder(bValue);
243 }
244 
245 template <class stream_t>
246 stream_t& CylinderVolumeBounds::dumpT(stream_t& dt) const {
247  dt << std::setiosflags(std::ios::fixed);
248  dt << std::setprecision(5);
249  dt << "Acts::CylinderVolumeBounds: (rMin, rMax, halfZ, halfPhi, "
250  "averagePhi) = ";
251  dt << get(eMinR) << ", " << get(eMaxR) << ", " << get(eHalfLengthZ) << ", "
252  << get(eHalfPhiSector) << get(eAveragePhi);
253  return dt;
254 }
255 
256 inline std::vector<double> CylinderVolumeBounds::values() const {
257  std::vector<double> valvector;
258  valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
259  return valvector;
260 }
261 
263  if (get(eMinR) < 0. or get(eMaxR) <= 0. or get(eMinR) >= get(eMaxR)) {
264  throw std::invalid_argument("CylinderVolumeBounds: invalid radial input.");
265  }
266  if (get(eHalfLengthZ) <= 0) {
267  throw std::invalid_argument(
268  "CylinderVolumeBounds: invalid longitudinal input.");
269  }
270  if (get(eHalfPhiSector) < 0. or get(eHalfPhiSector) > M_PI) {
271  throw std::invalid_argument(
272  "CylinderVolumeBounds: invalid phi sector setup.");
273  }
274  if (get(eAveragePhi) != detail::radian_sym(get(eAveragePhi))) {
275  throw std::invalid_argument(
276  "CylinderVolumeBounds: invalid phi positioning.");
277  }
278 }
279 
280 } // namespace Acts