Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-28 08:21:09

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Geometry/MaterialDesignatorBlueprintNode.hpp"
0010 
0011 #include "Acts/Geometry/CuboidPortalShell.hpp"
0012 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0013 #include "Acts/Geometry/CylinderPortalShell.hpp"
0014 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0015 #include "Acts/Geometry/DiamondPortalShell.hpp"
0016 #include "Acts/Geometry/DiamondVolumeBounds.hpp"
0017 #include "Acts/Geometry/Portal.hpp"
0018 #include "Acts/Geometry/PortalShell.hpp"
0019 #include "Acts/Geometry/TrapezoidPortalShell.hpp"
0020 #include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
0021 #include "Acts/Material/HomogeneousSurfaceMaterial.hpp"
0022 #include "Acts/Surfaces/Surface.hpp"
0023 #include "Acts/Utilities/Diagnostics.hpp"
0024 #include "Acts/Utilities/GraphViz.hpp"
0025 #include "Acts/Utilities/ProtoAxis.hpp"
0026 
0027 #include "./MaterialDesignator.hpp"
0028 
0029 namespace Acts {
0030 
0031 namespace detail {
0032 class MaterialDesignatorBlueprintNodeImpl {
0033  public:
0034   std::string m_name{};
0035   // Monostate is the null state, where no designator is configured.
0036   Designator m_designator{std::monostate{}};
0037 };
0038 
0039 }  // namespace detail
0040 
0041 MaterialDesignatorBlueprintNode::MaterialDesignatorBlueprintNode(
0042     const std::string& name) {
0043   m_impl = std::make_unique<detail::MaterialDesignatorBlueprintNodeImpl>();
0044   m_impl->m_name = name;
0045 }
0046 
0047 const std::string& MaterialDesignatorBlueprintNode::name() const {
0048   return impl().m_name;
0049 }
0050 
0051 void MaterialDesignatorBlueprintNode::toStream(std::ostream& os) const {
0052   os << "MaterialDesignatorBlueprintNode(" << name() << ")";
0053 }
0054 
0055 Volume& MaterialDesignatorBlueprintNode::build(const BlueprintOptions& options,
0056                                                const GeometryContext& gctx,
0057                                                const Logger& logger) {
0058   if (children().size() != 1) {
0059     ACTS_ERROR(prefix() << "MaterialDesignatorBlueprintNode must have exactly "
0060                            "one child, but has "
0061                         << children().size());
0062     throw std::runtime_error(
0063         "MaterialDesignatorBlueprintNode must have exactly one child");
0064   }
0065 
0066   return children().at(0).build(options, gctx, logger);
0067 }
0068 
0069 PortalShellBase& MaterialDesignatorBlueprintNode::connect(
0070     const BlueprintOptions& options, const GeometryContext& gctx,
0071     const Logger& logger) {
0072   ACTS_DEBUG(prefix() << "MaterialDesignatorBlueprintNode::connect");
0073   if (children().size() != 1) {
0074     ACTS_ERROR(prefix() << "MaterialDesignatorBlueprintNode must have exactly "
0075                            "one child, but has "
0076                         << children().size());
0077     throw std::runtime_error(
0078         "MaterialDesignatorBlueprintNode must have exactly one child");
0079   }
0080 
0081   auto& shell = children().at(0).connect(options, gctx, logger);
0082 
0083   ACTS_DEBUG(prefix() << "Received shell from child "
0084                       << children().at(0).name());
0085 
0086   detail::apply(impl().m_designator, shell, logger, prefix());
0087 
0088   return shell;
0089 }
0090 
0091 void MaterialDesignatorBlueprintNode::finalize(const BlueprintOptions& options,
0092                                                const GeometryContext& gctx,
0093                                                TrackingVolume& parent,
0094                                                const Logger& logger) {
0095   if (children().size() != 1) {
0096     ACTS_ERROR(prefix() << "MaterialDesignatorBlueprintNode must have exactly "
0097                            "one child, but has "
0098                         << children().size());
0099     throw std::runtime_error(
0100         "MaterialDesignatorBlueprintNode must have exactly one child");
0101   }
0102   return children().at(0).finalize(options, gctx, parent, logger);
0103 }
0104 
0105 void MaterialDesignatorBlueprintNode::addToGraphviz(std::ostream& os) const {
0106   std::stringstream ss;
0107   ss << "<b>" + name() + "</b>";
0108   ss << "<br/>MaterialDesignator";
0109 
0110   detail::graphvizLabel(impl().m_designator, ss);
0111 
0112   os << GraphViz::Node{
0113       .id = name(), .label = ss.str(), .shape = GraphViz::Shape::Hexagon};
0114   BlueprintNode::addToGraphviz(os);
0115 }
0116 
0117 namespace {
0118 
0119 ACTS_PUSH_IGNORE_DEPRECATED()
0120 /// Convert a superseded DirectedProtoAxis binning spec to a deferred
0121 /// AxisSpec. This reproduces the effective legacy semantics: only the
0122 /// binning structure was ever used, the configured range and boundary type
0123 /// were overwritten from the surface bounds during material mapping.
0124 AxisSpec toDeferredAxisSpec(const DirectedProtoAxis& dpAxis) {
0125   return AxisSpec::FromAxis(dpAxis.getAxis())
0126       .toDeferred()
0127       .withDirection(dpAxis.getAxisDirection());
0128 }
0129 ACTS_POP_IGNORE_DEPRECATED()
0130 
0131 }  // namespace
0132 
0133 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0134     CylinderVolumeBounds::Face face, const AxisSpec& loc0,
0135     const AxisSpec& loc1) {
0136   impl().m_designator = detail::merge(
0137       impl().m_designator,
0138       detail::CylinderProtoDesignator(face, loc0, loc1, prefix()));
0139   return *this;
0140 }
0141 
0142 ACTS_PUSH_IGNORE_DEPRECATED()
0143 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0144     CylinderVolumeBounds::Face face, const DirectedProtoAxis& loc0,
0145     const DirectedProtoAxis& loc1) {
0146   return configureFace(face, toDeferredAxisSpec(loc0),
0147                        toDeferredAxisSpec(loc1));
0148 }
0149 ACTS_POP_IGNORE_DEPRECATED()
0150 
0151 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0152     CylinderVolumeBounds::Face face,
0153     std::shared_ptr<const Acts::ISurfaceMaterial> material) {
0154   if (material == nullptr) {
0155     throw std::invalid_argument(prefix() + "Material is nullptr");
0156   }
0157   impl().m_designator = detail::merge(
0158       impl().m_designator,
0159       detail::CylinderHomogeneousMaterialDesignator(face, std::move(material)));
0160   return *this;
0161 }
0162 
0163 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0164     CuboidVolumeBounds::Face face, const AxisSpec& loc0, const AxisSpec& loc1) {
0165   impl().m_designator =
0166       detail::merge(impl().m_designator,
0167                     detail::CuboidProtoDesignator(face, loc0, loc1, prefix()));
0168   return *this;
0169 }
0170 
0171 ACTS_PUSH_IGNORE_DEPRECATED()
0172 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0173     CuboidVolumeBounds::Face face, const DirectedProtoAxis& loc0,
0174     const DirectedProtoAxis& loc1) {
0175   return configureFace(face, toDeferredAxisSpec(loc0),
0176                        toDeferredAxisSpec(loc1));
0177 }
0178 ACTS_POP_IGNORE_DEPRECATED()
0179 
0180 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0181     CuboidVolumeBounds::Face face,
0182     std::shared_ptr<const Acts::ISurfaceMaterial> material) {
0183   if (material == nullptr) {
0184     throw std::invalid_argument(prefix() + "Material is nullptr");
0185   }
0186   impl().m_designator = detail::merge(
0187       impl().m_designator,
0188       detail::CuboidHomogeneousMaterialDesignator(face, std::move(material)));
0189   return *this;
0190 }
0191 
0192 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0193     TrapezoidVolumeBounds::Face face,
0194     std::shared_ptr<const Acts::ISurfaceMaterial> material) {
0195   if (material == nullptr) {
0196     throw std::invalid_argument(prefix() + "Material is nullptr");
0197   }
0198   impl().m_designator = detail::merge(
0199       impl().m_designator, detail::TrapezoidHomogeneousMaterialDesignator(
0200                                face, std::move(material)));
0201   return *this;
0202 }
0203 
0204 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0205     DiamondVolumeBounds::Face face,
0206     std::shared_ptr<const Acts::ISurfaceMaterial> material) {
0207   if (material == nullptr) {
0208     throw std::invalid_argument(prefix() + "Material is nullptr");
0209   }
0210   impl().m_designator = detail::merge(
0211       impl().m_designator,
0212       detail::DiamondHomogeneousMaterialDesignator(face, std::move(material)));
0213   return *this;
0214 }
0215 
0216 detail::MaterialDesignatorBlueprintNodeImpl&
0217 MaterialDesignatorBlueprintNode::impl() {
0218   if (!m_impl) {
0219     throw std::runtime_error("MaterialDesignatorBlueprintNodeImpl is not set");
0220   }
0221   return *m_impl;
0222 }
0223 
0224 const detail::MaterialDesignatorBlueprintNodeImpl&
0225 MaterialDesignatorBlueprintNode::impl() const {
0226   if (!m_impl) {
0227     throw std::runtime_error("MaterialDesignatorBlueprintNodeImpl is not set");
0228   }
0229   return *m_impl;
0230 }
0231 
0232 MaterialDesignatorBlueprintNode::~MaterialDesignatorBlueprintNode() = default;
0233 
0234 }  // namespace Acts