ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Volume.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Volume.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2019 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 
10 // Volume.cpp, Acts project
12 
13 #include "Acts/Geometry/Volume.hpp"
14 
15 #include <iostream>
16 #include <utility>
17 
19 #include "Acts/Utilities/Units.hpp"
20 
21 using namespace Acts::UnitLiterals;
22 
24  : GeometryObject(),
25  m_transform(nullptr),
26  m_center(s_origin),
27  m_volumeBounds(nullptr),
28  m_orientedBoundingBox(BoundingBox(this, {0, 0, 0}, {0, 0, 0})) {}
29 
30 Acts::Volume::Volume(const std::shared_ptr<const Transform3D>& htrans,
31  std::shared_ptr<const VolumeBounds> volbounds)
32  : GeometryObject(),
33  m_transform(htrans),
34  m_itransform(m_transform ? m_transform->inverse()
35  : Transform3D::Identity()),
36  m_center(s_origin),
37  m_volumeBounds(std::move(volbounds)),
38  m_orientedBoundingBox(m_volumeBounds->boundingBox(
39  nullptr, {0.05_mm, 0.05_mm, 0.05_mm}, this)) {
40  if (htrans) {
41  m_center = htrans->translation();
42  }
43 }
44 
45 Acts::Volume::Volume(const Volume& vol, const Transform3D* shift)
46  : GeometryObject(),
47  m_transform(vol.m_transform),
48  m_itransform(m_transform ? m_transform->inverse()
49  : Transform3D::Identity()),
50  m_center(s_origin),
51  m_volumeBounds(vol.m_volumeBounds),
52  m_orientedBoundingBox(m_volumeBounds->boundingBox(
53  nullptr, {0.05_mm, 0.05_mm, 0.05_mm}, this)) {
54  // apply the shift if it exists
55  if (shift != nullptr) {
56  m_transform = std::make_shared<const Transform3D>(transform() * (*shift));
57  // reset inverse
58  m_itransform = m_transform->inverse();
59  }
60  // now set the center
61  m_center = transform().translation();
62 }
63 
64 Acts::Volume::~Volume() = default;
65 
67  const GeometryContext& /*gctx*/, Acts::BinningValue bValue) const {
68  // for most of the binning types it is actually the center,
69  // just for R-binning types the
70  if (bValue == Acts::binR || bValue == Acts::binRPhi) {
71  // the binning Position for R-type may have an offset
72  return (center() + m_volumeBounds->binningOffset(bValue));
73  }
74  // return the center
75  return center();
76 }
77 
78 // assignment operator
80  if (this != &vol) {
81  m_transform = vol.m_transform;
82  m_center = vol.m_center;
83  m_volumeBounds = vol.m_volumeBounds;
84  }
85  return *this;
86 }
87 
88 bool Acts::Volume::inside(const Acts::Vector3D& gpos, double tol) const {
89  if (!m_transform) {
90  return (volumeBounds()).inside(gpos, tol);
91  }
92  Acts::Vector3D posInVolFrame((transform().inverse()) * gpos);
93  return (volumeBounds()).inside(posInVolFrame, tol);
94 }
95 
96 std::ostream& Acts::operator<<(std::ostream& sl, const Acts::Volume& vol) {
97  sl << "Volume with " << vol.volumeBounds() << std::endl;
98  return sl;
99 }
100 
102  const Vector3D& envelope) const {
103  return m_volumeBounds->boundingBox(m_transform.get(), envelope, this);
104 }
105 
107  return m_orientedBoundingBox;
108 }