Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:36

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2019 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Geometry/CutoutCylinderVolumeBounds.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Direction.hpp"
0013 #include "Acts/Definitions/Tolerance.hpp"
0014 #include "Acts/Geometry/BoundarySurfaceFace.hpp"
0015 #include "Acts/Geometry/Volume.hpp"
0016 #include "Acts/Geometry/VolumeBounds.hpp"
0017 #include "Acts/Surfaces/CylinderBounds.hpp"
0018 #include "Acts/Surfaces/CylinderSurface.hpp"
0019 #include "Acts/Surfaces/DiscSurface.hpp"
0020 #include "Acts/Surfaces/RadialBounds.hpp"
0021 #include "Acts/Surfaces/Surface.hpp"
0022 #include "Acts/Utilities/BoundingBox.hpp"
0023 
0024 #include <memory>
0025 #include <ostream>
0026 #include <type_traits>
0027 #include <utility>
0028 
0029 bool Acts::CutoutCylinderVolumeBounds::inside(const Acts::Vector3& gpos,
0030                                               double tol) const {
0031   // first check whether we are in the outer envelope at all (ignore r_med)
0032   using VectorHelpers::perp;
0033   using VectorHelpers::phi;
0034   double ros = perp(gpos);
0035 
0036   bool insideR = (ros >= get(eMinR) - tol) && (ros <= get(eMaxR) + tol);
0037   bool insideZ = std::abs(gpos.z()) <= get(eHalfLengthZ) + tol;
0038 
0039   if (!insideR || !insideZ) {
0040     return false;
0041   }
0042 
0043   // we're inside the outer volume, but we might be in inside the
0044   // cutout section in the middle
0045   bool insideRInner = ros <= get(eMedR) - tol;
0046   bool insideZInner = std::abs(gpos.z()) < get(eHalfLengthZcutout) - tol;
0047 
0048   return !insideRInner || !insideZInner;  // we are not, inside bounds
0049 }
0050 
0051 std::vector<Acts::OrientedSurface>
0052 Acts::CutoutCylinderVolumeBounds::orientedSurfaces(
0053     const Transform3& transform) const {
0054   std::vector<OrientedSurface> oSurfaces;
0055 
0056   if (get(eMinR) == 0.) {
0057     oSurfaces.resize(6);  // exactly six surfaces (no choke inner cover)
0058   } else {
0059     oSurfaces.resize(8);  // exactly eight surfaces
0060   }
0061 
0062   // Outer cylinder envelope
0063   auto outer =
0064       Surface::makeShared<CylinderSurface>(transform, m_outerCylinderBounds);
0065   oSurfaces.at(tubeOuterCover) =
0066       OrientedSurface{std::move(outer), Direction::OppositeNormal};
0067 
0068   // Inner (cutout) cylinder envelope
0069   auto cutoutInner =
0070       Surface::makeShared<CylinderSurface>(transform, m_cutoutCylinderBounds);
0071   oSurfaces.at(tubeInnerCover) =
0072       OrientedSurface{std::move(cutoutInner), Direction::AlongNormal};
0073 
0074   // z position of the pos and neg choke points
0075   double hlChoke = (get(eHalfLengthZ) - get(eHalfLengthZcutout)) * 0.5;
0076   double zChoke = get(eHalfLengthZcutout) + hlChoke;
0077 
0078   if (m_innerCylinderBounds != nullptr) {
0079     auto posChokeTrf = transform * Translation3(Vector3(0, 0, zChoke));
0080     auto posInner = Surface::makeShared<CylinderSurface>(posChokeTrf,
0081                                                          m_innerCylinderBounds);
0082     oSurfaces.at(index7) =
0083         OrientedSurface{std::move(posInner), Direction::AlongNormal};
0084 
0085     auto negChokeTrf = transform * Translation3(Vector3(0, 0, -zChoke));
0086     auto negInner = Surface::makeShared<CylinderSurface>(negChokeTrf,
0087                                                          m_innerCylinderBounds);
0088     oSurfaces.at(index6) =
0089         OrientedSurface{std::move(negInner), Direction::AlongNormal};
0090   }
0091 
0092   // Two Outer disks
0093   auto posOutDiscTrf =
0094       transform * Translation3(Vector3(0, 0, get(eHalfLengthZ)));
0095   auto posOutDisc =
0096       Surface::makeShared<DiscSurface>(posOutDiscTrf, m_outerDiscBounds);
0097   oSurfaces.at(positiveFaceXY) =
0098       OrientedSurface{std::move(posOutDisc), Direction::OppositeNormal};
0099 
0100   auto negOutDiscTrf =
0101       transform * Translation3(Vector3(0, 0, -get(eHalfLengthZ)));
0102   auto negOutDisc =
0103       Surface::makeShared<DiscSurface>(negOutDiscTrf, m_outerDiscBounds);
0104   oSurfaces.at(negativeFaceXY) =
0105       OrientedSurface{std::move(negOutDisc), Direction::AlongNormal};
0106 
0107   // Two Inner disks
0108   auto posInDiscTrf =
0109       transform * Translation3(Vector3(0, 0, get(eHalfLengthZcutout)));
0110   auto posInDisc =
0111       Surface::makeShared<DiscSurface>(posInDiscTrf, m_innerDiscBounds);
0112   oSurfaces.at(index5) =
0113       OrientedSurface{std::move(posInDisc), Direction::AlongNormal};
0114 
0115   auto negInDiscTrf =
0116       transform * Translation3(Vector3(0, 0, -get(eHalfLengthZcutout)));
0117   auto negInDisc =
0118       Surface::makeShared<DiscSurface>(negInDiscTrf, m_innerDiscBounds);
0119   oSurfaces.at(index4) =
0120       OrientedSurface{std::move(negInDisc), Direction::OppositeNormal};
0121 
0122   return oSurfaces;
0123 }
0124 
0125 Acts::Volume::BoundingBox Acts::CutoutCylinderVolumeBounds::boundingBox(
0126     const Acts::Transform3* trf, const Acts::Vector3& envelope,
0127     const Acts::Volume* entity) const {
0128   Vector3 vmin, vmax;
0129 
0130   // no phi sector is possible, so this is just the outer size of
0131   // the cylinder
0132 
0133   vmax = {get(eMaxR), get(eMaxR), get(eHalfLengthZ)};
0134   vmin = {-get(eMaxR), -get(eMaxR), -get(eHalfLengthZ)};
0135 
0136   Acts::Volume::BoundingBox box(entity, vmin - envelope, vmax + envelope);
0137   // transform at the very end, if required
0138   return trf == nullptr ? box : box.transformed(*trf);
0139 }
0140 
0141 std::ostream& Acts::CutoutCylinderVolumeBounds::toStream(
0142     std::ostream& sl) const {
0143   sl << "Acts::CutoutCylinderVolumeBounds(\n";
0144   sl << "rmin = " << get(eMinR) << " rmed = " << get(eMedR)
0145      << " rmax = " << get(eMaxR) << "\n";
0146   sl << "dz1 = " << get(eHalfLengthZ) << " dz2 = " << get(eHalfLengthZcutout);
0147   return sl;
0148 }
0149 
0150 void Acts::CutoutCylinderVolumeBounds::buildSurfaceBounds() {
0151   if (get(eMinR) > s_epsilon) {
0152     double hlChoke = (get(eHalfLengthZ) - get(eHalfLengthZcutout)) * 0.5;
0153     m_innerCylinderBounds =
0154         std::make_shared<CylinderBounds>(get(eMinR), hlChoke);
0155   }
0156 
0157   m_cutoutCylinderBounds =
0158       std::make_shared<CylinderBounds>(get(eMedR), get(eHalfLengthZcutout));
0159 
0160   m_outerCylinderBounds =
0161       std::make_shared<CylinderBounds>(get(eMaxR), get(eHalfLengthZ));
0162 
0163   m_innerDiscBounds = std::make_shared<RadialBounds>(get(eMinR), get(eMedR));
0164 
0165   m_outerDiscBounds = std::make_shared<RadialBounds>(get(eMinR), get(eMaxR));
0166 }