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