File indexing completed on 2025-07-05 08:11:30
0001
0002
0003
0004
0005
0006
0007
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/Portal.hpp"
0016 #include "Acts/Geometry/PortalShell.hpp"
0017 #include "Acts/Material/HomogeneousSurfaceMaterial.hpp"
0018 #include "Acts/Surfaces/Surface.hpp"
0019 #include "Acts/Utilities/GraphViz.hpp"
0020 #include "Acts/Utilities/ProtoAxis.hpp"
0021
0022 #include "./detail/MaterialDesignator.hpp"
0023
0024 namespace Acts::Experimental {
0025
0026 namespace detail {
0027 class MaterialDesignatorBlueprintNodeImpl {
0028 public:
0029 using CylinderBinning = std::tuple<CylinderVolumeBounds::Face,
0030 DirectedProtoAxis, DirectedProtoAxis>;
0031 using CuboidBinning = std::tuple<CuboidVolumeBounds::Face, DirectedProtoAxis,
0032 DirectedProtoAxis>;
0033
0034 using BinningConfig =
0035 std::variant<std::vector<CylinderBinning>, std::vector<CuboidBinning>>;
0036
0037 void validateCylinderFaceConfig(CylinderVolumeBounds::Face face,
0038 const DirectedProtoAxis& loc0,
0039 const DirectedProtoAxis& loc1,
0040 const std::string& prefix);
0041
0042 void validateCuboidFaceConfig(const DirectedProtoAxis& loc0,
0043 const DirectedProtoAxis& loc1,
0044 const std::string& prefix);
0045
0046 std::string m_name{};
0047
0048 std::unique_ptr<DesignatorBase> m_designator{
0049 std::make_unique<NullDesignator>()};
0050 };
0051
0052 }
0053
0054 MaterialDesignatorBlueprintNode::MaterialDesignatorBlueprintNode(
0055 const std::string& name) {
0056 m_impl = std::make_unique<detail::MaterialDesignatorBlueprintNodeImpl>();
0057 m_impl->m_name = name;
0058 }
0059
0060 const std::string& MaterialDesignatorBlueprintNode::name() const {
0061 return impl().m_name;
0062 }
0063
0064 void MaterialDesignatorBlueprintNode::toStream(std::ostream& os) const {
0065 os << "MaterialDesignatorBlueprintNode(" << name() << ")";
0066 }
0067
0068 Volume& MaterialDesignatorBlueprintNode::build(const BlueprintOptions& options,
0069 const GeometryContext& gctx,
0070 const Logger& logger) {
0071 if (children().size() != 1) {
0072 ACTS_ERROR(prefix() << "MaterialDesignatorBlueprintNode must have exactly "
0073 "one child, but has "
0074 << children().size());
0075 throw std::runtime_error(
0076 "MaterialDesignatorBlueprintNode must have exactly one child");
0077 }
0078
0079 if (!impl().m_designator) {
0080 ACTS_ERROR(prefix() << "Designator is not set");
0081 throw std::runtime_error("Designator is not set");
0082 }
0083
0084 return children().at(0).build(options, gctx, logger);
0085 }
0086
0087 PortalShellBase& MaterialDesignatorBlueprintNode::connect(
0088 const BlueprintOptions& options, const GeometryContext& gctx,
0089 const Logger& logger) {
0090 ACTS_DEBUG(prefix() << "MaterialDesignatorBlueprintNode::connect");
0091 if (children().size() != 1) {
0092 ACTS_ERROR(prefix() << "MaterialDesignatorBlueprintNode must have exactly "
0093 "one child, but has "
0094 << children().size());
0095 throw std::runtime_error(
0096 "MaterialDesignatorBlueprintNode must have exactly one child");
0097 }
0098
0099 if (!impl().m_designator) {
0100 ACTS_ERROR(prefix() << "Designator is not set");
0101 throw std::runtime_error("Designator is not set");
0102 }
0103
0104 auto& shell = children().at(0).connect(options, gctx, logger);
0105
0106 ACTS_DEBUG(prefix() << "Received shell from child "
0107 << children().at(0).name());
0108
0109 impl().m_designator->apply(shell, logger, prefix());
0110
0111 return shell;
0112 }
0113
0114 void MaterialDesignatorBlueprintNode::finalize(const BlueprintOptions& options,
0115 const GeometryContext& gctx,
0116 TrackingVolume& parent,
0117 const Logger& logger) {
0118 if (children().size() != 1) {
0119 ACTS_ERROR(prefix() << "MaterialDesignatorBlueprintNode must have exactly "
0120 "one child, but has "
0121 << children().size());
0122 throw std::runtime_error(
0123 "MaterialDesignatorBlueprintNode must have exactly one child");
0124 }
0125 return children().at(0).finalize(options, gctx, parent, logger);
0126 }
0127
0128 void MaterialDesignatorBlueprintNode::addToGraphviz(std::ostream& os) const {
0129 if (!impl().m_designator) {
0130 throw std::runtime_error("Binning is not set");
0131 }
0132
0133 std::stringstream ss;
0134 ss << "<b>" + name() + "</b>";
0135 ss << "<br/>MaterialDesignator";
0136
0137 impl().m_designator->graphvizLabel(ss);
0138
0139 os << GraphViz::Node{
0140 .id = name(), .label = ss.str(), .shape = GraphViz::Shape::Hexagon};
0141 BlueprintNode::addToGraphviz(os);
0142 }
0143
0144 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0145 CylinderVolumeBounds::Face face, const DirectedProtoAxis& loc0,
0146 const DirectedProtoAxis& loc1) {
0147 impl().m_designator = impl().m_designator->merged(
0148 detail::CylinderProtoDesignator(face, loc0, loc1, prefix()));
0149
0150 return *this;
0151 }
0152
0153 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0154 CylinderVolumeBounds::Face face,
0155 std::shared_ptr<const Acts::HomogeneousSurfaceMaterial> material) {
0156 if (material == nullptr) {
0157 throw std::invalid_argument(prefix() + "Material is nullptr");
0158 }
0159
0160 impl().m_designator = impl().m_designator->merged(
0161 detail::HomogeneousMaterialDesignator<CylinderVolumeBounds::Face,
0162 CylinderPortalShell>(
0163 face, std::move(material)));
0164
0165 return *this;
0166 }
0167
0168 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0169 CuboidVolumeBounds::Face face, const DirectedProtoAxis& loc0,
0170 const DirectedProtoAxis& loc1) {
0171 impl().m_designator = impl().m_designator->merged(
0172 detail::CuboidProtoDesignator(face, loc0, loc1, prefix()));
0173
0174 return *this;
0175 }
0176
0177 MaterialDesignatorBlueprintNode& MaterialDesignatorBlueprintNode::configureFace(
0178 CuboidVolumeBounds::Face face,
0179 std::shared_ptr<const Acts::HomogeneousSurfaceMaterial> material) {
0180 if (material == nullptr) {
0181 throw std::invalid_argument(prefix() + "Material is nullptr");
0182 }
0183
0184 impl().m_designator = impl().m_designator->merged(
0185 detail::HomogeneousMaterialDesignator<CuboidVolumeBounds::Face,
0186 CuboidPortalShell>(
0187 face, std::move(material)));
0188
0189 return *this;
0190 }
0191
0192 detail::MaterialDesignatorBlueprintNodeImpl&
0193 MaterialDesignatorBlueprintNode::impl() {
0194 if (!m_impl) {
0195 throw std::runtime_error("MaterialDesignatorBlueprintNodeImpl is not set");
0196 }
0197 return *m_impl;
0198 }
0199
0200 const detail::MaterialDesignatorBlueprintNodeImpl&
0201 MaterialDesignatorBlueprintNode::impl() const {
0202 if (!m_impl) {
0203 throw std::runtime_error("MaterialDesignatorBlueprintNodeImpl is not set");
0204 }
0205 return *m_impl;
0206 }
0207
0208 MaterialDesignatorBlueprintNode::~MaterialDesignatorBlueprintNode() = default;
0209
0210 }