Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-26 09:22:33

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, const AxisSpec& loc1,
0135     std::optional<std::string> materialKey) {
0136   impl().m_designator =
0137       detail::merge(impl().m_designator,
0138                     detail::CylinderProtoDesignator(face, loc0, loc1, prefix(),
0139                                                     std::move(materialKey)));
0140   return *this;
0141 }
0142 
0143 ACTS_PUSH_IGNORE_DEPRECATED()
0144 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0145     CylinderVolumeBounds::Face face, const DirectedProtoAxis& loc0,
0146     const DirectedProtoAxis& loc1) {
0147   return configureFace(face, toDeferredAxisSpec(loc0),
0148                        toDeferredAxisSpec(loc1));
0149 }
0150 ACTS_POP_IGNORE_DEPRECATED()
0151 
0152 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0153     CylinderVolumeBounds::Face face,
0154     std::shared_ptr<const Acts::ISurfaceMaterial> material) {
0155   if (material == nullptr) {
0156     throw std::invalid_argument(prefix() + "Material is nullptr");
0157   }
0158   impl().m_designator = detail::merge(
0159       impl().m_designator,
0160       detail::CylinderHomogeneousMaterialDesignator(face, std::move(material)));
0161   return *this;
0162 }
0163 
0164 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0165     CuboidVolumeBounds::Face face, const AxisSpec& loc0, const AxisSpec& loc1,
0166     std::optional<std::string> materialKey) {
0167   impl().m_designator =
0168       detail::merge(impl().m_designator,
0169                     detail::CuboidProtoDesignator(face, loc0, loc1, prefix(),
0170                                                   std::move(materialKey)));
0171   return *this;
0172 }
0173 
0174 ACTS_PUSH_IGNORE_DEPRECATED()
0175 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0176     CuboidVolumeBounds::Face face, const DirectedProtoAxis& loc0,
0177     const DirectedProtoAxis& loc1) {
0178   return configureFace(face, toDeferredAxisSpec(loc0),
0179                        toDeferredAxisSpec(loc1));
0180 }
0181 ACTS_POP_IGNORE_DEPRECATED()
0182 
0183 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0184     CuboidVolumeBounds::Face face,
0185     std::shared_ptr<const Acts::ISurfaceMaterial> material) {
0186   if (material == nullptr) {
0187     throw std::invalid_argument(prefix() + "Material is nullptr");
0188   }
0189   impl().m_designator = detail::merge(
0190       impl().m_designator,
0191       detail::CuboidHomogeneousMaterialDesignator(face, std::move(material)));
0192   return *this;
0193 }
0194 
0195 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0196     TrapezoidVolumeBounds::Face face,
0197     std::shared_ptr<const Acts::ISurfaceMaterial> material) {
0198   if (material == nullptr) {
0199     throw std::invalid_argument(prefix() + "Material is nullptr");
0200   }
0201   impl().m_designator = detail::merge(
0202       impl().m_designator, detail::TrapezoidHomogeneousMaterialDesignator(
0203                                face, std::move(material)));
0204   return *this;
0205 }
0206 
0207 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0208     DiamondVolumeBounds::Face face,
0209     std::shared_ptr<const Acts::ISurfaceMaterial> material) {
0210   if (material == nullptr) {
0211     throw std::invalid_argument(prefix() + "Material is nullptr");
0212   }
0213   impl().m_designator = detail::merge(
0214       impl().m_designator,
0215       detail::DiamondHomogeneousMaterialDesignator(face, std::move(material)));
0216   return *this;
0217 }
0218 
0219 detail::MaterialDesignatorBlueprintNodeImpl&
0220 MaterialDesignatorBlueprintNode::impl() {
0221   if (!m_impl) {
0222     throw std::runtime_error("MaterialDesignatorBlueprintNodeImpl is not set");
0223   }
0224   return *m_impl;
0225 }
0226 
0227 const detail::MaterialDesignatorBlueprintNodeImpl&
0228 MaterialDesignatorBlueprintNode::impl() const {
0229   if (!m_impl) {
0230     throw std::runtime_error("MaterialDesignatorBlueprintNodeImpl is not set");
0231   }
0232   return *m_impl;
0233 }
0234 
0235 MaterialDesignatorBlueprintNode::~MaterialDesignatorBlueprintNode() = default;
0236 
0237 }  // namespace Acts