File indexing completed on 2026-11-24 09:27:58
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsPlugins/DD4hep/DD4hepMaterialHelpers.hpp"
0010
0011 #include "Acts/Geometry/ApproachDescriptor.hpp"
0012 #include "Acts/Geometry/Layer.hpp"
0013 #include "Acts/Surfaces/Surface.hpp"
0014 #include "Acts/Utilities/AxisSpec.hpp"
0015 #include "Acts/Utilities/BinningType.hpp"
0016 #include "ActsPlugins/DD4hep/DD4hepConversionHelpers.hpp"
0017
0018 #include <algorithm>
0019 #include <array>
0020 #include <cstddef>
0021 #include <ostream>
0022 #include <stdexcept>
0023
0024 #include <boost/foreach.hpp>
0025 #include <boost/tokenizer.hpp>
0026
0027 using namespace Acts;
0028
0029 std::shared_ptr<ProtoGridSurfaceMaterial> ActsPlugins::createProtoMaterial(
0030 const dd4hep::rec::VariantParameters& params, const std::string& valueTag,
0031 const std::vector<std::pair<const std::string, BinningOption> >& binning,
0032 const Logger& logger) {
0033 if (binning.size() != 2) {
0034 throw std::invalid_argument("DD4hep surface material requires two axes");
0035 }
0036 const bool cylinder = std::ranges::any_of(binning, [](const auto& axis) {
0037 return axisDirectionFromName(axis.first) == AxisDirection::AxisZ;
0038 });
0039 auto axisSpec = [&](const auto& axis) {
0040 auto direction = axisDirectionFromName(axis.first);
0041 if (cylinder && direction == AxisDirection::AxisPhi) {
0042 direction = AxisDirection::AxisRPhi;
0043 }
0044 const int bins = params.get<int>(valueTag + "_" + axis.first);
0045 ACTS_VERBOSE(" - material binning for " << axis.first << " on " << valueTag
0046 << ": " << bins);
0047
0048
0049 return AxisSpec::Equidistant(
0050 static_cast<std::size_t>(std::max(1, bins)), std::nullopt, std::nullopt,
0051 axis.second == closed ? AxisBoundaryType::Closed
0052 : AxisBoundaryType::Bound,
0053 direction);
0054 };
0055 return std::make_shared<ProtoGridSurfaceMaterial>(
0056 MultiAxisSpec2D({axisSpec(binning[0]), axisSpec(binning[1])}));
0057 }
0058
0059 void ActsPlugins::addLayerProtoMaterial(
0060 const dd4hep::rec::VariantParameters& params, Layer& layer,
0061 const std::vector<std::pair<const std::string, BinningOption> >& binning,
0062 const Logger& logger) {
0063 ACTS_VERBOSE("addLayerProtoMaterial");
0064
0065 std::vector<std::string> materialOptions = {"layer_material_representing"};
0066 std::vector<const Surface*> materialSurfaces = {
0067 &(layer.surfaceRepresentation())};
0068
0069 auto aDescriptor = layer.approachDescriptor();
0070 if (aDescriptor != nullptr && aDescriptor->containedSurfaces().size() >= 2) {
0071
0072 const std::vector<const Surface*>& aSurfaces =
0073 aDescriptor->containedSurfaces();
0074 materialOptions.push_back("layer_material_inner");
0075 materialSurfaces.push_back(aSurfaces[0]);
0076 materialOptions.push_back("layer_material_outer");
0077 materialSurfaces.push_back(aSurfaces[1]);
0078 }
0079
0080
0081 for (unsigned int is = 0; is < materialOptions.size(); ++is) {
0082
0083 ACTS_VERBOSE(" - checking material for: " << materialOptions[is]);
0084 if (params.contains(materialOptions[is])) {
0085 ACTS_VERBOSE(" - have material");
0086
0087 auto psMaterial =
0088 createProtoMaterial(params, materialOptions[is], binning, logger);
0089
0090
0091 Surface* surface = const_cast<Surface*>(materialSurfaces[is]);
0092 surface->assignSurfaceMaterial(psMaterial);
0093 }
0094 }
0095 }
0096
0097 void ActsPlugins::addCylinderLayerProtoMaterial(dd4hep::DetElement detElement,
0098 Layer& cylinderLayer,
0099 const Logger& logger) {
0100 ACTS_VERBOSE(
0101 "Translating DD4hep material into Acts material for CylinderLayer : "
0102 << detElement.name());
0103 if (hasParams(detElement)) {
0104 ACTS_VERBOSE(" params: " << getParams(detElement));
0105 } else {
0106 ACTS_VERBOSE(" NO params");
0107 }
0108 if (getParamOr<bool>("layer_material", detElement, false)) {
0109 addLayerProtoMaterial(getParams(detElement), cylinderLayer,
0110 {{"binPhi", closed}, {"binZ", open}}, logger);
0111 }
0112 }
0113
0114 void ActsPlugins::addDiscLayerProtoMaterial(dd4hep::DetElement detElement,
0115 Layer& discLayer,
0116 const Logger& logger) {
0117 ACTS_VERBOSE("Translating DD4hep material into Acts material for DiscLayer : "
0118 << detElement.name());
0119
0120 if (hasParams(detElement)) {
0121 ACTS_VERBOSE(" params: " << getParams(detElement));
0122 } else {
0123 ACTS_VERBOSE(" NO params");
0124 }
0125 if (getParamOr<bool>("layer_material", detElement, false)) {
0126 addLayerProtoMaterial(getParams(detElement), discLayer,
0127 {{"binPhi", closed}, {"binR", open}}, logger);
0128 }
0129 }