File indexing completed on 2025-10-14 08:01:36
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsPlugins/DD4hep/DD4hepDetectorStructure.hpp"
0010
0011 #include "Acts/Detector/CylindricalContainerBuilder.hpp"
0012 #include "Acts/Detector/DetectorBuilder.hpp"
0013 #include "Acts/Detector/detail/BlueprintDrawer.hpp"
0014 #include "Acts/Detector/detail/BlueprintHelper.hpp"
0015 #include "ActsPlugins/DD4hep/DD4hepBlueprintFactory.hpp"
0016 #include "ActsPlugins/DD4hep/DD4hepDetectorSurfaceFactory.hpp"
0017 #include "ActsPlugins/DD4hep/DD4hepLayerStructure.hpp"
0018
0019 #include <fstream>
0020
0021 #include <DD4hep/DetElement.h>
0022
0023 using namespace Acts;
0024 using namespace Acts::Experimental;
0025 using namespace Acts::Experimental::detail;
0026
0027 namespace ActsPlugins {
0028
0029 DD4hepDetectorStructure::DD4hepDetectorStructure(
0030 std::unique_ptr<const Logger> mlogger)
0031 : m_logger(std::move(mlogger)) {}
0032
0033 std::tuple<std::shared_ptr<const Detector>, DD4hepDetectorElement::Store>
0034 DD4hepDetectorStructure::construct(const GeometryContext& gctx,
0035 const dd4hep::DetElement& dd4hepElement,
0036 const Options& options) const {
0037 ACTS_DEBUG("Building detector from " << dd4hepElement.name());
0038
0039
0040 std::shared_ptr<const Detector> detector = nullptr;
0041 DD4hepDetectorElement::Store detectorStore;
0042
0043
0044 DD4hepDetectorSurfaceFactory::Config surfaceFactoryConfig;
0045 auto surfaceFactory = std::make_shared<DD4hepDetectorSurfaceFactory>(
0046 surfaceFactoryConfig,
0047 getDefaultLogger("DD4hepDetectorSurfaceFactory", options.logLevel));
0048
0049 auto layerStructure = std::make_shared<DD4hepLayerStructure>(
0050 std::move(surfaceFactory),
0051 getDefaultLogger("DD4hepLayerStructure", options.logLevel));
0052
0053
0054 DD4hepBlueprintFactory::Config bpdCfg{layerStructure};
0055 DD4hepBlueprintFactory::Cache bpdCache;
0056
0057 DD4hepBlueprintFactory dd4hepBlueprintDrawer(
0058 bpdCfg, getDefaultLogger("DD4hepBlueprintFactory", options.logLevel));
0059 auto dd4hepBlueprint =
0060 dd4hepBlueprintDrawer.create(bpdCache, gctx, dd4hepElement);
0061 detectorStore = bpdCache.dd4hepStore;
0062
0063
0064 if (!options.emulateToGraph.empty()) {
0065 ACTS_DEBUG("Writing the initial bluepring to file before gap filling.");
0066 std::ofstream bpi(options.emulateToGraph + "_initial.dot");
0067 BlueprintDrawer::dotStream(bpi, *dd4hepBlueprint);
0068 bpi.close();
0069 }
0070
0071 if (dd4hepBlueprint->boundsType == VolumeBounds::eCylinder) {
0072 ACTS_DEBUG("Cylindrical detector building detected.");
0073
0074
0075 BlueprintHelper::fillGaps(*dd4hepBlueprint);
0076
0077
0078 if (!options.emulateToGraph.empty()) {
0079 ACTS_DEBUG("Writing the final bluepring to file.");
0080 std::ofstream bpf(options.emulateToGraph + "_final.dot");
0081 BlueprintDrawer::dotStream(bpf, *dd4hepBlueprint);
0082 bpf.close();
0083
0084 return {detector, detectorStore};
0085 }
0086
0087
0088 auto detectorBuilder = std::make_shared<CylindricalContainerBuilder>(
0089 *dd4hepBlueprint, options.logLevel);
0090
0091
0092 DetectorBuilder::Config dCfg;
0093 dCfg.auxiliary =
0094 "*** DD4hep : auto generated cylindrical detector builder ***";
0095 dCfg.name = "Cylindrical detector from DD4hep blueprint";
0096 dCfg.builder = detectorBuilder;
0097 dCfg.geoIdGenerator = options.geoIdGenerator != nullptr
0098 ? options.geoIdGenerator
0099 : dd4hepBlueprint->geoIdGenerator;
0100 dCfg.materialDecorator = options.materialDecorator;
0101 detector = DetectorBuilder(dCfg, getDefaultLogger("DD4hepDetectorBuilder",
0102 options.logLevel))
0103 .construct(gctx);
0104 } else {
0105 throw std::invalid_argument(
0106 "DD4hepDetectorStructure: Only cylindrical detectors are (currently) "
0107 "supported.");
0108 }
0109 return {detector, detectorStore};
0110 }
0111
0112 }