diff --git a/Examples/Algorithms/Geant4/include/ActsExamples/DDG4/DDG4DetectorConstruction.hpp b/Examples/Algorithms/Geant4/include/ActsExamples/DDG4/DDG4DetectorConstruction.hpp index 529a3725980..f08297d2a85 100644 --- a/Examples/Algorithms/Geant4/include/ActsExamples/DDG4/DDG4DetectorConstruction.hpp +++ b/Examples/Algorithms/Geant4/include/ActsExamples/DDG4/DDG4DetectorConstruction.hpp @@ -8,6 +8,7 @@ #pragma once +#include "ActsExamples/DD4hepDetector/DD4hepDetector.hpp" #include "ActsExamples/Geant4/DetectorConstructionFactory.hpp" #include "ActsExamples/Geant4/RegionCreator.hpp" @@ -23,7 +24,7 @@ class Detector; namespace ActsExamples { namespace DD4hep { -struct DD4hepDetector; +class DD4hepDetector; } /// Construct the Geant4 detector from a DD4hep description. @@ -32,7 +33,6 @@ class DDG4DetectorConstruction final : public G4VUserDetectorConstruction { DDG4DetectorConstruction( std::shared_ptr detector, std::vector> regionCreators = {}); - ~DDG4DetectorConstruction() final; /// Convert the stored DD4hep detector to a Geant4 description. /// @@ -50,9 +50,6 @@ class DDG4DetectorConstruction final : public G4VUserDetectorConstruction { std::vector> m_regionCreators; /// The world volume G4VPhysicalVolume* m_world = nullptr; - - /// The DD4hep detector instance - dd4hep::Detector& dd4hepDetector() const; }; class DDG4DetectorConstructionFactory final diff --git a/Examples/Algorithms/Geant4/src/DDG4DetectorConstruction.cpp b/Examples/Algorithms/Geant4/src/DDG4DetectorConstruction.cpp index ae6a4609180..7f2a8fe366a 100644 --- a/Examples/Algorithms/Geant4/src/DDG4DetectorConstruction.cpp +++ b/Examples/Algorithms/Geant4/src/DDG4DetectorConstruction.cpp @@ -18,32 +18,26 @@ #include #include #include -#include class G4VPhysicalVolume; -ActsExamples::DDG4DetectorConstruction::DDG4DetectorConstruction( +namespace ActsExamples { + +DDG4DetectorConstruction::DDG4DetectorConstruction( std::shared_ptr detector, std::vector> regionCreators) : G4VUserDetectorConstruction(), m_detector(std::move(detector)), m_regionCreators(std::move(regionCreators)) {} -ActsExamples::DDG4DetectorConstruction::~DDG4DetectorConstruction() = default; - -dd4hep::Detector& ActsExamples::DDG4DetectorConstruction::dd4hepDetector() - const { - return m_detector->geometryService->detector(); -} - // See DD4hep::Simulation::Geant4DetectorConstruction::Construct() -G4VPhysicalVolume* ActsExamples::DDG4DetectorConstruction::Construct() { +G4VPhysicalVolume* DDG4DetectorConstruction::Construct() { if (m_world == nullptr) { dd4hep::sim::Geant4Mapping& g4map = dd4hep::sim::Geant4Mapping::instance(); - auto conv = dd4hep::sim::Geant4Converter(dd4hepDetector(), + auto conv = dd4hep::sim::Geant4Converter(m_detector->dd4hepDetector(), dd4hep::PrintLevel::VERBOSE); dd4hep::sim::Geant4GeometryInfo* geoInfo = - conv.create(dd4hepDetector().world()).detach(); + conv.create(m_detector->dd4hepGeometry()).detach(); g4map.attach(geoInfo); // All volumes are deleted in ~G4PhysicalVolumeStore() m_world = geoInfo->world(); @@ -58,17 +52,18 @@ G4VPhysicalVolume* ActsExamples::DDG4DetectorConstruction::Construct() { return m_world; } -ActsExamples::DDG4DetectorConstructionFactory::DDG4DetectorConstructionFactory( +DDG4DetectorConstructionFactory::DDG4DetectorConstructionFactory( std::shared_ptr detector, std::vector> regionCreators) : m_detector(std::move(detector)), m_regionCreators(std::move(regionCreators)) {} -ActsExamples::DDG4DetectorConstructionFactory:: - ~DDG4DetectorConstructionFactory() = default; +DDG4DetectorConstructionFactory::~DDG4DetectorConstructionFactory() = default; std::unique_ptr -ActsExamples::DDG4DetectorConstructionFactory::factorize() const { +DDG4DetectorConstructionFactory::factorize() const { return std::make_unique(m_detector, m_regionCreators); } + +} // namespace ActsExamples diff --git a/Examples/Detectors/CMakeLists.txt b/Examples/Detectors/CMakeLists.txt index 7e7aed5daed..d1ec565e08f 100644 --- a/Examples/Detectors/CMakeLists.txt +++ b/Examples/Detectors/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(Common) add_subdirectory(ContextualDetector) add_subdirectory_if(DD4hepDetector ACTS_BUILD_EXAMPLES_DD4HEP) add_subdirectory(GenericDetector) diff --git a/Examples/Detectors/Common/CMakeLists.txt b/Examples/Detectors/Common/CMakeLists.txt new file mode 100644 index 00000000000..85f232de9f2 --- /dev/null +++ b/Examples/Detectors/Common/CMakeLists.txt @@ -0,0 +1,14 @@ +add_library(ActsExamplesDetectorCommons SHARED src/Detector.cpp) +target_include_directories( + ActsExamplesDetectorCommons + PUBLIC $ +) +target_link_libraries( + ActsExamplesDetectorCommons + PUBLIC ActsCore ActsExamplesFramework +) + +install( + TARGETS ActsExamplesDetectorCommons + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) diff --git a/Examples/Detectors/Common/include/ActsExamples/DetectorCommons/Detector.hpp b/Examples/Detectors/Common/include/ActsExamples/DetectorCommons/Detector.hpp new file mode 100644 index 00000000000..2b4115ab48b --- /dev/null +++ b/Examples/Detectors/Common/include/ActsExamples/DetectorCommons/Detector.hpp @@ -0,0 +1,75 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// This file is part of the Acts project. +// +// Copyright (C) 2024 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Geometry/GeometryContext.hpp" + +#include +#include + +namespace Acts { +class TrackingGeometry; +class DetectorElementBase; +class IMaterialDecorator; +class Logger; +namespace Experimental { +class Detector; +} // namespace Experimental +} // namespace Acts + +namespace ActsExamples { +class IContextDecorator; +} // namespace ActsExamples + +namespace ActsExamples::DetectorCommons { + +class Detector { + public: + using TrackingGeometryPtr = std::shared_ptr; + using DetectorPtr = std::shared_ptr; + using ContextDecorators = + std::vector>; + + using DetectorElement = Acts::DetectorElementBase; + using DetectorStore = std::vector>; + + explicit Detector(std::unique_ptr logger); + virtual ~Detector() = default; + + virtual std::tuple + trackingGeometry(); + + virtual std::tuple detector(); + + virtual void drop(); + + protected: + TrackingGeometryPtr m_trackingGeometry; + DetectorPtr m_detector; + ContextDecorators m_contextDecorators; + DetectorStore m_detectorStore; + + std::unique_ptr m_logger; + + const Acts::Logger& logger() const { return *m_logger; } + + virtual void buildTrackingGeometry() = 0; + + virtual void buildDetector(); +}; + +} // namespace ActsExamples::DetectorCommons diff --git a/Examples/Detectors/Common/src/Detector.cpp b/Examples/Detectors/Common/src/Detector.cpp new file mode 100644 index 00000000000..26363cc32a6 --- /dev/null +++ b/Examples/Detectors/Common/src/Detector.cpp @@ -0,0 +1,53 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// This file is part of the Acts project. +// +// Copyright (C) 2024 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "ActsExamples/DetectorCommons/Detector.hpp" + +#include "Acts/Utilities/Logger.hpp" + +namespace ActsExamples::DetectorCommons { + +Detector::Detector(std::unique_ptr logger) + : m_logger(std::move(logger)) {} + +std::tuple +Detector::trackingGeometry() { + if (m_trackingGeometry == nullptr) { + buildTrackingGeometry(); + } + return {m_trackingGeometry, m_contextDecorators, m_detectorStore}; +} + +std::tuple +Detector::detector() { + if (m_detector == nullptr) { + buildDetector(); + } + return {m_detector, m_contextDecorators, m_detectorStore}; +} + +void Detector::drop() { + m_trackingGeometry.reset(); + m_detector.reset(); + m_contextDecorators.clear(); + m_detectorStore.clear(); +} + +void Detector::buildDetector() {} + +} // namespace ActsExamples::DetectorCommons diff --git a/Examples/Detectors/ContextualDetector/CMakeLists.txt b/Examples/Detectors/ContextualDetector/CMakeLists.txt index 2cb61207c53..821e2763d64 100644 --- a/Examples/Detectors/ContextualDetector/CMakeLists.txt +++ b/Examples/Detectors/ContextualDetector/CMakeLists.txt @@ -5,13 +5,19 @@ add_library( src/InternalAlignmentDecorator.cpp src/ExternalAlignmentDecorator.cpp ) + target_include_directories( ActsExamplesDetectorContextual PUBLIC $ ) + target_link_libraries( ActsExamplesDetectorContextual - PUBLIC ActsCore ActsExamplesFramework ActsExamplesDetectorGeneric + PUBLIC + ActsCore + ActsExamplesFramework + ActsExamplesDetectorCommons + ActsExamplesDetectorGeneric ) install( diff --git a/Examples/Detectors/ContextualDetector/include/ActsExamples/ContextualDetector/AlignedDetector.hpp b/Examples/Detectors/ContextualDetector/include/ActsExamples/ContextualDetector/AlignedDetector.hpp index 66a0f3b6b42..d4393ef9c20 100644 --- a/Examples/Detectors/ContextualDetector/include/ActsExamples/ContextualDetector/AlignedDetector.hpp +++ b/Examples/Detectors/ContextualDetector/include/ActsExamples/ContextualDetector/AlignedDetector.hpp @@ -10,6 +10,7 @@ #include "Acts/Definitions/Units.hpp" #include "Acts/Utilities/Logger.hpp" +#include "ActsExamples/DetectorCommons/Detector.hpp" #include "ActsExamples/GenericDetector/GenericDetector.hpp" #include @@ -17,29 +18,20 @@ #include #include -namespace Acts { -class TrackingGeometry; -class IMaterialDecorator; -} // namespace Acts - -namespace ActsExamples { -class IContextDecorator; -namespace Generic { -class GenericDetectorElement; -} // namespace Generic -} // namespace ActsExamples - namespace ActsExamples::Contextual { class InternallyAlignedDetectorElement; class InternalAlignmentDecorator; -class AlignedDetector { +class AlignedDetector : public DetectorCommons::Detector { public: + using TrackingGeometryPtr = std::shared_ptr; using ContextDecorators = std::vector>; - using TrackingGeometryPtr = std::shared_ptr; - struct Config : public GenericDetector::Config { + using DetectorStore = std::vector< + std::vector>>; + + struct Config : public Generic::GenericDetector::Config { /// Seed for the decorator random numbers. std::size_t seed = 1324354657; /// Size of a valid IOV. @@ -63,21 +55,21 @@ class AlignedDetector { enum class Mode { Internal, External }; Mode mode = Mode::Internal; + + std::shared_ptr materialDecorator; }; - std::pair finalize( - const Config& cfg, - std::shared_ptr mdecorator); + explicit AlignedDetector(const Config& cfg); - std::vector>>& - detectorStore() { - return m_detectorStore; - } + const DetectorStore& detectorStore() const { return m_detectorStore; } private: + Config m_cfg; + /// The Store of the detector elements (lifetime: job) - std::vector>> - m_detectorStore; + DetectorStore m_detectorStore; + + void buildTrackingGeometry() final; }; } // namespace ActsExamples::Contextual diff --git a/Examples/Detectors/ContextualDetector/src/AlignedDetector.cpp b/Examples/Detectors/ContextualDetector/src/AlignedDetector.cpp index 044cc943a81..eed3967eed7 100644 --- a/Examples/Detectors/ContextualDetector/src/AlignedDetector.cpp +++ b/Examples/Detectors/ContextualDetector/src/AlignedDetector.cpp @@ -9,6 +9,7 @@ #include "ActsExamples/ContextualDetector/AlignedDetector.hpp" #include "Acts/Definitions/Units.hpp" +#include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Geometry/ILayerBuilder.hpp" #include "Acts/Geometry/TrackingGeometry.hpp" #include "Acts/Utilities/Logger.hpp" @@ -17,44 +18,46 @@ #include "ActsExamples/ContextualDetector/ExternallyAlignedDetectorElement.hpp" #include "ActsExamples/ContextualDetector/InternalAlignmentDecorator.hpp" #include "ActsExamples/ContextualDetector/InternallyAlignedDetectorElement.hpp" +#include "ActsExamples/DetectorCommons/Detector.hpp" #include "ActsExamples/Framework/RandomNumbers.hpp" #include "ActsExamples/GenericDetector/BuildGenericDetector.hpp" #include "ActsExamples/GenericDetector/ProtoLayerCreatorT.hpp" using namespace Acts::UnitLiterals; + namespace ActsExamples::Contextual { -auto AlignedDetector::finalize( - const Config& cfg, - std::shared_ptr mdecorator) - -> std::pair { - ContextDecorators aContextDecorators; +AlignedDetector::AlignedDetector(const Config& cfg) + : DetectorCommons::Detector( + Acts::getDefaultLogger("AlignedDetector", m_cfg.logLevel)), + m_cfg(cfg) {} +void AlignedDetector::buildTrackingGeometry() { // Let's create a random number service ActsExamples::RandomNumbers::Config randomNumberConfig; - randomNumberConfig.seed = cfg.seed; + randomNumberConfig.seed = m_cfg.seed; auto randomNumberSvc = std::make_shared(randomNumberConfig); auto fillDecoratorConfig = [&](AlignmentDecorator::Config& config) { - config.iovSize = cfg.iovSize; - config.flushSize = cfg.flushSize; - config.doGarbageCollection = cfg.doGarbageCollection; + config.iovSize = m_cfg.iovSize; + config.flushSize = m_cfg.flushSize; + config.doGarbageCollection = m_cfg.doGarbageCollection; // The misalignments - config.gSigmaX = cfg.sigmaInPlane; - config.gSigmaY = cfg.sigmaInPlane; - config.gSigmaZ = cfg.sigmaOutPlane; - config.aSigmaX = cfg.sigmaOutRot; - config.aSigmaY = cfg.sigmaOutRot; - config.aSigmaZ = cfg.sigmaInRot; + config.gSigmaX = m_cfg.sigmaInPlane; + config.gSigmaY = m_cfg.sigmaInPlane; + config.gSigmaZ = m_cfg.sigmaOutPlane; + config.aSigmaX = m_cfg.sigmaOutRot; + config.aSigmaY = m_cfg.sigmaOutRot; + config.aSigmaZ = m_cfg.sigmaInRot; config.randomNumberSvc = randomNumberSvc; - config.firstIovNominal = cfg.firstIovNominal; + config.firstIovNominal = m_cfg.firstIovNominal; }; - TrackingGeometryPtr aTrackingGeometry; - if (cfg.mode == Config::Mode::External) { - ExternallyAlignedDetectorElement::ContextType nominalContext; + if (m_cfg.mode == Config::Mode::External) { + InternallyAlignedDetectorElement::ContextType nominalContext; + auto gctx = Acts::GeometryContext(nominalContext); ExternalAlignmentDecorator::Config agcsConfig; fillDecoratorConfig(agcsConfig); @@ -62,13 +65,12 @@ auto AlignedDetector::finalize( std::vector>> detectorStore; - aTrackingGeometry = + m_trackingGeometry = ActsExamples::Generic::buildDetector( - nominalContext, detectorStore, cfg.buildLevel, - std::move(mdecorator), cfg.buildProto, cfg.surfaceLogLevel, - cfg.layerLogLevel, cfg.volumeLogLevel); - - agcsConfig.trackingGeometry = aTrackingGeometry; + gctx, detectorStore, m_cfg.buildLevel, m_cfg.materialDecorator, + m_cfg.buildProto, m_cfg.surfaceLogLevel, m_cfg.layerLogLevel, + m_cfg.volumeLogLevel); + agcsConfig.trackingGeometry = m_trackingGeometry; // need to upcast to store in this object as well for (auto& lstore : detectorStore) { @@ -78,21 +80,22 @@ auto AlignedDetector::finalize( } } - aContextDecorators.push_back(std::make_shared( + m_contextDecorators.push_back(std::make_shared( std::move(agcsConfig), - Acts::getDefaultLogger("AlignmentDecorator", cfg.decoratorLogLevel))); + Acts::getDefaultLogger("AlignmentDecorator", m_cfg.decoratorLogLevel))); } else { InternallyAlignedDetectorElement::ContextType nominalContext; nominalContext.nominal = true; + auto gctx = Acts::GeometryContext(nominalContext); InternalAlignmentDecorator::Config agcsConfig; fillDecoratorConfig(agcsConfig); - aTrackingGeometry = + m_trackingGeometry = ActsExamples::Generic::buildDetector( - nominalContext, agcsConfig.detectorStore, cfg.buildLevel, - std::move(mdecorator), cfg.buildProto, cfg.surfaceLogLevel, - cfg.layerLogLevel, cfg.volumeLogLevel); + gctx, agcsConfig.detectorStore, m_cfg.buildLevel, + m_cfg.materialDecorator, m_cfg.buildProto, m_cfg.surfaceLogLevel, + m_cfg.layerLogLevel, m_cfg.volumeLogLevel); // need to upcast to store in this object as well for (auto& lstore : agcsConfig.detectorStore) { @@ -102,14 +105,10 @@ auto AlignedDetector::finalize( } } - aContextDecorators.push_back(std::make_shared( + m_contextDecorators.push_back(std::make_shared( std::move(agcsConfig), - Acts::getDefaultLogger("AlignmentDecorator", cfg.decoratorLogLevel))); + Acts::getDefaultLogger("AlignmentDecorator", m_cfg.decoratorLogLevel))); } - - // return the pair of geometry and the alignment decorator(s) - return std::make_pair( - std::move(aTrackingGeometry), std::move(aContextDecorators)); } } // namespace ActsExamples::Contextual diff --git a/Examples/Detectors/DD4hepDetector/CMakeLists.txt b/Examples/Detectors/DD4hepDetector/CMakeLists.txt index 244b4f20a6d..1a19a9a5fce 100644 --- a/Examples/Detectors/DD4hepDetector/CMakeLists.txt +++ b/Examples/Detectors/DD4hepDetector/CMakeLists.txt @@ -1,9 +1,4 @@ -add_library( - ActsExamplesDetectorDD4hep - SHARED - src/DD4hepDetector.cpp - src/DD4hepGeometryService.cpp -) +add_library(ActsExamplesDetectorDD4hep SHARED src/DD4hepDetector.cpp) target_include_directories( ActsExamplesDetectorDD4hep @@ -11,7 +6,11 @@ target_include_directories( ) target_link_libraries( ActsExamplesDetectorDD4hep - PUBLIC ActsCore ActsPluginDD4hep ActsExamplesFramework + PUBLIC + ActsCore + ActsPluginDD4hep + ActsExamplesFramework + ActsExamplesDetectorCommons ) if(${DD4hep_VERSION} VERSION_LESS 1.11) diff --git a/Examples/Detectors/DD4hepDetector/include/ActsExamples/DD4hepDetector/DD4hepDetector.hpp b/Examples/Detectors/DD4hepDetector/include/ActsExamples/DD4hepDetector/DD4hepDetector.hpp index 015b511825f..96ab072c3d3 100644 --- a/Examples/Detectors/DD4hepDetector/include/ActsExamples/DD4hepDetector/DD4hepDetector.hpp +++ b/Examples/Detectors/DD4hepDetector/include/ActsExamples/DD4hepDetector/DD4hepDetector.hpp @@ -8,88 +8,109 @@ #pragma once -#include "Acts/MagneticField/MagneticFieldProvider.hpp" -#include "Acts/Plugins/DD4hep/DD4hepDetectorElement.hpp" -#include "Acts/Plugins/DD4hep/DD4hepDetectorStructure.hpp" -#include "ActsExamples/DD4hepDetector/DD4hepGeometryService.hpp" - +#include "Acts/Definitions/Units.hpp" +#include "Acts/Geometry/GeometryContext.hpp" +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Geometry/TrackingGeometry.hpp" +#include "Acts/Material/IMaterialDecorator.hpp" +#include "Acts/Utilities/BinningType.hpp" +#include "Acts/Utilities/Logger.hpp" +#include "ActsExamples/DetectorCommons/Detector.hpp" +#include "ActsExamples/Framework/ProcessCode.hpp" + +#include #include -#include -#include +#include #include -namespace dd4hep { -class Detector; -} // namespace dd4hep - -namespace Acts { -class TrackingGeometry; -class IMaterialDecorator; -class DD4hepFieldAdapter; -namespace Experimental { -class Detector; -} // namespace Experimental -} // namespace Acts +#include +#include -namespace ActsExamples { -class IContextDecorator; -} // namespace ActsExamples +class TGeoNode; namespace ActsExamples::DD4hep { -struct DD4hepDetector { +void sortFCChhDetElements(std::vector& det); + +/// @class DD4hepDetector +/// +/// @brief geometries from dd4hep input +/// +/// The DD4hepDetector creates the DD4hep, the TGeo and the ACTS +/// TrackingGeometry from DD4hep xml input. The geometries are created only on +/// demand. +class DD4hepDetector : public DetectorCommons::Detector { + public: /// @brief The context decorators using ContextDecorators = std::vector>; - /// @brief The tracking geometry - using TrackingGeometryPtr = std::shared_ptr; - - /// @brief The detector geometry - using DetectorPtr = std::shared_ptr; - - /// @brief Default constructor - DD4hepDetector() = default; - /// @brief Constructor from geometry service - /// @param _geometryService the geometry service - explicit DD4hepDetector( - std::shared_ptr _geometryService); - /// @brief Default destructor - ~DD4hepDetector() = default; - - /// @brief The DD4hep geometry service - std::shared_ptr geometryService = nullptr; - - /// @brief Build the tracking geometry from the DD4hep geometry - /// - /// @param config is the configuration of the geometry service - /// @param mdecorator is the material decorator provided - /// - /// @return a pair of tracking geometry and context decorators - std::pair finalize( - DD4hepGeometryService::Config config, - std::shared_ptr mdecorator); - - /// @brief Build the detector from the DD4hep geometry - /// - /// @param gctx is the geometry context - /// @param options is the options struct for the building process - /// - /// @note the lifetime of the detector store has to exceed that of the - /// detector object as the converted surfaces point back to the - /// detector elements - /// - /// @return a tuple of detector, context decorators, and the element store - std::tuple - finalize( - const Acts::GeometryContext& gctx, - const Acts::Experimental::DD4hepDetectorStructure::Options& options = {}); - - void drop(); - - /// @brief Access to the DD4hep field - /// @return a shared pointer to the DD4hep field - std::shared_ptr field() const; + struct Config { + /// Log level for the geometry service. + Acts::Logging::Level logLevel = Acts::Logging::Level::INFO; + /// Log level for DD4hep itself + Acts::Logging::Level dd4hepLogLevel = Acts::Logging::Level::INFO; + /// XML-file with the detector description + std::vector xmlFileNames; + /// The name of the service + std::string name; + /// Binningtype in phi + Acts::BinningType bTypePhi = Acts::equidistant; + /// Binningtype in r + Acts::BinningType bTypeR = Acts::arbitrary; + /// Binningtype in z + Acts::BinningType bTypeZ = Acts::equidistant; + /// The tolerance added to the geometrical extension in r + /// of the layers contained to build the volume envelope around + /// @note this parameter only needs to be set if the volumes containing + /// the + /// layers (e.g. barrel, endcap volumes) have no specific shape + /// (assemblies) + double envelopeR = 1 * Acts::UnitConstants::mm; + /// The tolerance added to the geometrical extension in z + /// of the layers contained to build the volume envelope around + /// @note this parameter only needs to be set if the volumes containing + /// the layers (e.g. barrel, endcap volumes) have no specific shape + /// (assemblies) + double envelopeZ = 1 * Acts::UnitConstants::mm; + double defaultLayerThickness = 1e-10; + std::function& detectors)> + sortDetectors = sortFCChhDetElements; + /// Material decorator + std::shared_ptr materialDecorator; + + /// Optional geometry identifier hook to be used during closure + std::shared_ptr geometryIdentifierHook = + std::make_shared(); + }; + + explicit DD4hepDetector(const Config& cfg); + + /// Interface method to access to the DD4hep geometry + dd4hep::Detector& dd4hepDetector(); + + /// Interface method to access the DD4hep geometry + /// @return The world DD4hep DetElement + dd4hep::DetElement& dd4hepGeometry(); + + /// Interface method to Access the TGeo geometry + /// @return The world TGeoNode (physical volume) + TGeoNode& tgeoGeometry(); + + void drop() final; + + private: + /// Private method to initiate building of the DD4hep geometry + void buildDD4hepGeometry(); + + void buildTrackingGeometry() final; + + /// The config class + Config m_cfg; + /// Pointer to the interface to the DD4hep geometry + std::unique_ptr m_detector; + /// The world DD4hep DetElement + dd4hep::DetElement m_geometry; }; } // namespace ActsExamples::DD4hep diff --git a/Examples/Detectors/DD4hepDetector/include/ActsExamples/DD4hepDetector/DD4hepGeometryService.hpp b/Examples/Detectors/DD4hepDetector/include/ActsExamples/DD4hepDetector/DD4hepGeometryService.hpp deleted file mode 100644 index 9ce1ca5f2e9..00000000000 --- a/Examples/Detectors/DD4hepDetector/include/ActsExamples/DD4hepDetector/DD4hepGeometryService.hpp +++ /dev/null @@ -1,138 +0,0 @@ -// This file is part of the ACTS project. -// -// Copyright (C) 2016 CERN for the benefit of the ACTS project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#pragma once - -#include "Acts/Geometry/GeometryContext.hpp" -#include "Acts/Geometry/GeometryIdentifier.hpp" -#include "ActsExamples/Framework/ProcessCode.hpp" -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -class TGeoNode; -namespace Acts { -class IMaterialDecorator; -class TrackingGeometry; -} // namespace Acts -namespace dd4hep { -class Detector; -} // namespace dd4hep - -namespace ActsExamples::DD4hep { - -void sortFCChhDetElements(std::vector& det); - -/// @class DD4hepGeometryService -/// -/// @brief service creating geometries from dd4hep input -/// -/// The DD4hepGeometryService creates the DD4hep, the TGeo and the ACTS -/// TrackingGeometry -/// from DD4hep xml input. The geometries are created only on demand. -class DD4hepGeometryService { - public: - struct Config { - /// Log level for the geometry service. - Acts::Logging::Level logLevel = Acts::Logging::Level::INFO; - /// Log level for DD4hep itself - Acts::Logging::Level dd4hepLogLevel = Acts::Logging::Level::INFO; - /// XML-file with the detector description - std::vector xmlFileNames; - /// The name of the service - std::string name = "default"; - /// Binningtype in phi - Acts::BinningType bTypePhi = Acts::equidistant; - /// Binningtype in r - Acts::BinningType bTypeR = Acts::arbitrary; - /// Binningtype in z - Acts::BinningType bTypeZ = Acts::equidistant; - /// The tolerance added to the geometrical extension in r - /// of the layers contained to build the volume envelope around - /// @note this parameter only needs to be set if the volumes containing - /// the - /// layers (e.g. barrel, endcap volumes) have no specific shape - /// (assemblies) - double envelopeR = 1 * Acts::UnitConstants::mm; - /// The tolerance added to the geometrical extension in z - /// of the layers contained to build the volume envelope around - /// @note this parameter only needs to be set if the volumes containing - /// the layers (e.g. barrel, endcap volumes) have no specific shape - /// (assemblies) - double envelopeZ = 1 * Acts::UnitConstants::mm; - double defaultLayerThickness = 10e-10; - std::function& detectors)> - sortDetectors = sortFCChhDetElements; - /// Material decorator - std::shared_ptr matDecorator; - - /// Optional geometry identifier hook to be used during closure - std::shared_ptr geometryIdentifierHook = - std::make_shared(); - }; - - explicit DD4hepGeometryService(const Config& cfg); - DD4hepGeometryService(const DD4hepGeometryService&) = delete; - DD4hepGeometryService(DD4hepGeometryService&&) = delete; - ~DD4hepGeometryService(); - DD4hepGeometryService& operator=(const DD4hepGeometryService&) = delete; - DD4hepGeometryService& operator=(DD4hepGeometryService&&) = delete; - - /// Interface method to access to the DD4hep geometry - dd4hep::Detector& detector(); - - /// Interface method to access the DD4hep geometry - /// @return The world DD4hep DetElement - dd4hep::DetElement& geometry(); - - /// Interface method to Access the TGeo geometry - /// @return The world TGeoNode (physical volume) - TGeoNode& tgeoGeometry(); - - /// Interface method to access the ACTS TrackingGeometry - /// - /// @param gctx is the geometry context object - std::shared_ptr trackingGeometry( - const Acts::GeometryContext& gctx); - - void drop(); - - private: - /// Private method to initiate building of the DD4hep geometry - ActsExamples::ProcessCode buildDD4hepGeometry(); - - /// Private method to initiate building of the ACTS tracking geometry - ActsExamples::ProcessCode buildTrackingGeometry( - const Acts::GeometryContext& gctx); - - /// The config class - Config m_cfg; - /// Pointer to the interface to the DD4hep geometry - dd4hep::Detector* m_detector = nullptr; - /// The world DD4hep DetElement - dd4hep::DetElement m_geometry; - /// The ACTS TrackingGeometry - std::shared_ptr m_trackingGeometry; - - const Acts::Logger& logger() const { return *m_logger; } - - std::unique_ptr m_logger; -}; - -} // namespace ActsExamples::DD4hep diff --git a/Examples/Detectors/DD4hepDetector/src/DD4hepDetector.cpp b/Examples/Detectors/DD4hepDetector/src/DD4hepDetector.cpp index a6494ce0860..a4b9ec0fd34 100644 --- a/Examples/Detectors/DD4hepDetector/src/DD4hepDetector.cpp +++ b/Examples/Detectors/DD4hepDetector/src/DD4hepDetector.cpp @@ -9,80 +9,162 @@ #include "ActsExamples/DD4hepDetector/DD4hepDetector.hpp" #include "Acts/Geometry/GeometryContext.hpp" -#include "Acts/MagneticField/MagneticFieldProvider.hpp" -#include "Acts/Plugins/DD4hep/DD4hepFieldAdapter.hpp" -#include "ActsExamples/DD4hepDetector/DD4hepGeometryService.hpp" +#include "Acts/Geometry/TrackingGeometry.hpp" +#include "Acts/Plugins/DD4hep/ConvertDD4hepDetector.hpp" +#include "Acts/Utilities/Logger.hpp" +#include "ActsExamples/DetectorCommons/Detector.hpp" -#include +#include #include #include -#include +#include -#include #include -#include -#include +#include +#include +#include +#include + +class TGeoNode; namespace ActsExamples::DD4hep { -DD4hepDetector::DD4hepDetector( - std::shared_ptr _geometryService) - : geometryService(std::move(_geometryService)) {} - -auto DD4hepDetector::finalize( - ActsExamples::DD4hep::DD4hepGeometryService::Config config, - std::shared_ptr mdecorator) - -> std::pair { - Acts::GeometryContext dd4HepContext; - config.matDecorator = std::move(mdecorator); - geometryService = - std::make_shared(config); - TrackingGeometryPtr dd4tGeometry = - geometryService->trackingGeometry(dd4HepContext); - if (!dd4tGeometry) { - throw std::runtime_error{ - "Did not receive tracking geometry from DD4hep geometry service"}; +DD4hepDetector::DD4hepDetector(const DD4hepDetector::Config& cfg) + : DetectorCommons::Detector( + Acts::getDefaultLogger("DD4hepDetector", cfg.logLevel)), + m_cfg(cfg) { + if (m_cfg.xmlFileNames.empty()) { + throw std::invalid_argument("Missing DD4hep XML filenames"); } - ContextDecorators dd4ContextDecorators = {}; - // return the pair of geometry and empty decorators - return std::make_pair( - std::move(dd4tGeometry), std::move(dd4ContextDecorators)); } -auto DD4hepDetector::finalize( - const Acts::GeometryContext& gctx, - const Acts::Experimental::DD4hepDetectorStructure::Options& options) - -> std::tuple { - if (geometryService == nullptr) { - throw std::runtime_error{ - "No DD4hep geometry service configured, can not build " - "TrackingGeometry."}; +dd4hep::Detector& DD4hepDetector::DD4hepDetector::dd4hepDetector() { + if (m_detector == nullptr) { + buildDD4hepGeometry(); } + return *m_detector; +} - auto world = geometryService->geometry(); - // Build the detector structure - Acts::Experimental::DD4hepDetectorStructure dd4hepStructure( - Acts::getDefaultLogger("DD4hepDetectorStructure", options.logLevel)); +dd4hep::DetElement& DD4hepDetector::dd4hepGeometry() { + if (!m_geometry) { + buildDD4hepGeometry(); + } + return m_geometry; +} - /// @return a detector and the detector store - auto [detector, detectorElements] = - dd4hepStructure.construct(gctx, world, options); +TGeoNode& DD4hepDetector::tgeoGeometry() { + if (!m_geometry) { + buildDD4hepGeometry(); + } + return *m_geometry.placement().ptr(); +} - // Prepare the return objects - ContextDecorators contextDecorators = {}; +void DD4hepDetector::buildDD4hepGeometry() { + const int old_gErrorIgnoreLevel = gErrorIgnoreLevel; + switch (m_cfg.dd4hepLogLevel) { + case Acts::Logging::Level::VERBOSE: + dd4hep::setPrintLevel(dd4hep::PrintLevel::VERBOSE); + break; + case Acts::Logging::Level::DEBUG: + dd4hep::setPrintLevel(dd4hep::PrintLevel::DEBUG); + break; + case Acts::Logging::Level::INFO: + dd4hep::setPrintLevel(dd4hep::PrintLevel::INFO); + break; + case Acts::Logging::Level::WARNING: + dd4hep::setPrintLevel(dd4hep::PrintLevel::WARNING); + gErrorIgnoreLevel = kWarning; + break; + case Acts::Logging::Level::ERROR: + dd4hep::setPrintLevel(dd4hep::PrintLevel::ERROR); + gErrorIgnoreLevel = kError; + break; + case Acts::Logging::Level::FATAL: + dd4hep::setPrintLevel(dd4hep::PrintLevel::FATAL); + gErrorIgnoreLevel = kFatal; + break; + case Acts::Logging::Level::MAX: + dd4hep::setPrintLevel(dd4hep::PrintLevel::ALWAYS); + break; + } + // completely silence std::cout as DD4HEP is using it for logging + if (m_cfg.dd4hepLogLevel >= Acts::Logging::Level::WARNING) { + std::cout.setstate(std::ios_base::failbit); + } - return {detector, contextDecorators, detectorElements}; -} + m_detector = dd4hep::Detector::make_unique(m_cfg.name); + for (auto& file : m_cfg.xmlFileNames) { + m_detector->fromCompact(file.c_str()); + } + m_detector->volumeManager(); + m_detector->apply("DD4hepVolumeManager", 0, nullptr); + m_geometry = m_detector->world(); -void DD4hepDetector::drop() { - geometryService->drop(); + // restore the logging + gErrorIgnoreLevel = old_gErrorIgnoreLevel; + std::cout.clear(); } -std::shared_ptr DD4hepDetector::field() const { - const auto& detector = geometryService->detector(); +void DD4hepDetector::buildTrackingGeometry() { + if (m_detector == nullptr) { + buildDD4hepGeometry(); + } - return std::make_shared(detector.field()); + Acts::GeometryContext gctx; + auto logger = Acts::getDefaultLogger("DD4hepConversion", m_cfg.logLevel); + m_trackingGeometry = Acts::convertDD4hepDetector( + m_geometry, *logger, m_cfg.bTypePhi, m_cfg.bTypeR, m_cfg.bTypeZ, + m_cfg.envelopeR, m_cfg.envelopeZ, m_cfg.defaultLayerThickness, + m_cfg.sortDetectors, gctx, m_cfg.materialDecorator, + m_cfg.geometryIdentifierHook); +} + +void DD4hepDetector::drop() { + m_detector = nullptr; + m_geometry = dd4hep::DetElement(); + m_trackingGeometry.reset(); } } // namespace ActsExamples::DD4hep + +void ActsExamples::DD4hep::sortFCChhDetElements( + std::vector& det) { + std::vector tracker; + std::vector eCal; + std::vector hCal; + std::vector muon; + for (auto& detElement : det) { + std::string detName = detElement.name(); + if (detName.find("Muon") != std::string::npos) { + muon.push_back(detElement); + } else if (detName.find("ECal") != std::string::npos) { + eCal.push_back(detElement); + } else if (detName.find("HCal") != std::string::npos) { + hCal.push_back(detElement); + } else { + tracker.push_back(detElement); + } + } + sort(muon.begin(), muon.end(), + [](const dd4hep::DetElement& a, const dd4hep::DetElement& b) { + return (a.id() < b.id()); + }); + sort(eCal.begin(), eCal.end(), + [](const dd4hep::DetElement& a, const dd4hep::DetElement& b) { + return (a.id() < b.id()); + }); + sort(hCal.begin(), hCal.end(), + [](const dd4hep::DetElement& a, const dd4hep::DetElement& b) { + return (a.id() < b.id()); + }); + sort(tracker.begin(), tracker.end(), + [](const dd4hep::DetElement& a, const dd4hep::DetElement& b) { + return (a.id() < b.id()); + }); + det.clear(); + det = tracker; + + det.insert(det.end(), eCal.begin(), eCal.end()); + det.insert(det.end(), hCal.begin(), hCal.end()); + det.insert(det.end(), muon.begin(), muon.end()); +} diff --git a/Examples/Detectors/DD4hepDetector/src/DD4hepGeometryService.cpp b/Examples/Detectors/DD4hepDetector/src/DD4hepGeometryService.cpp deleted file mode 100644 index 2912e39b757..00000000000 --- a/Examples/Detectors/DD4hepDetector/src/DD4hepGeometryService.cpp +++ /dev/null @@ -1,183 +0,0 @@ -// This file is part of the ACTS project. -// -// Copyright (C) 2016 CERN for the benefit of the ACTS project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#include "ActsExamples/DD4hepDetector/DD4hepGeometryService.hpp" - -#include "Acts/Geometry/TrackingGeometry.hpp" -#include "Acts/Plugins/DD4hep/ConvertDD4hepDetector.hpp" -#include "Acts/Utilities/Logger.hpp" - -#include -#include -#include - -#include -#include -#include -#include -#include - -class TGeoNode; - -ActsExamples::DD4hep::DD4hepGeometryService::DD4hepGeometryService( - const ActsExamples::DD4hep::DD4hepGeometryService::Config& cfg) - : m_cfg(cfg), - m_logger{Acts::getDefaultLogger("DD4hepGeometryService", cfg.logLevel)} { - if (m_cfg.xmlFileNames.empty()) { - throw std::invalid_argument("Missing DD4hep XML filenames"); - } -} - -ActsExamples::DD4hep::DD4hepGeometryService::~DD4hepGeometryService() { - drop(); -} - -ActsExamples::ProcessCode -ActsExamples::DD4hep::DD4hepGeometryService::buildDD4hepGeometry() { - const int old_gErrorIgnoreLevel = gErrorIgnoreLevel; - switch (m_cfg.dd4hepLogLevel) { - case Acts::Logging::Level::VERBOSE: - dd4hep::setPrintLevel(dd4hep::PrintLevel::VERBOSE); - break; - case Acts::Logging::Level::DEBUG: - dd4hep::setPrintLevel(dd4hep::PrintLevel::DEBUG); - break; - case Acts::Logging::Level::INFO: - dd4hep::setPrintLevel(dd4hep::PrintLevel::INFO); - break; - case Acts::Logging::Level::WARNING: - dd4hep::setPrintLevel(dd4hep::PrintLevel::WARNING); - gErrorIgnoreLevel = kWarning; - break; - case Acts::Logging::Level::ERROR: - dd4hep::setPrintLevel(dd4hep::PrintLevel::ERROR); - gErrorIgnoreLevel = kError; - break; - case Acts::Logging::Level::FATAL: - dd4hep::setPrintLevel(dd4hep::PrintLevel::FATAL); - gErrorIgnoreLevel = kFatal; - break; - case Acts::Logging::Level::MAX: - dd4hep::setPrintLevel(dd4hep::PrintLevel::ALWAYS); - break; - } - // completely silence std::cout as DD4HEP is using it for logging - if (m_cfg.dd4hepLogLevel >= Acts::Logging::Level::WARNING) { - std::cout.setstate(std::ios_base::failbit); - } - - m_detector = &dd4hep::Detector::getInstance(); - for (auto& file : m_cfg.xmlFileNames) { - m_detector->fromCompact(file.c_str()); - } - m_detector->volumeManager(); - m_detector->apply("DD4hepVolumeManager", 0, nullptr); - m_geometry = m_detector->world(); - - // restore the logging - gErrorIgnoreLevel = old_gErrorIgnoreLevel; - std::cout.clear(); - - return ActsExamples::ProcessCode::SUCCESS; -} - -dd4hep::Detector& -ActsExamples::DD4hep::DD4hepGeometryService::DD4hepGeometryService::detector() { - if (m_detector == nullptr) { - buildDD4hepGeometry(); - } - return *m_detector; -} - -dd4hep::DetElement& ActsExamples::DD4hep::DD4hepGeometryService::geometry() { - if (!m_geometry) { - buildDD4hepGeometry(); - } - return m_geometry; -} - -TGeoNode& ActsExamples::DD4hep::DD4hepGeometryService::tgeoGeometry() { - if (!m_geometry) { - buildDD4hepGeometry(); - } - return *m_geometry.placement().ptr(); -} - -ActsExamples::ProcessCode -ActsExamples::DD4hep::DD4hepGeometryService::buildTrackingGeometry( - const Acts::GeometryContext& gctx) { - // Set the tracking geometry - auto logger = Acts::getDefaultLogger("DD4hepConversion", m_cfg.logLevel); - m_trackingGeometry = Acts::convertDD4hepDetector( - geometry(), *logger, m_cfg.bTypePhi, m_cfg.bTypeR, m_cfg.bTypeZ, - m_cfg.envelopeR, m_cfg.envelopeZ, m_cfg.defaultLayerThickness, - m_cfg.sortDetectors, gctx, m_cfg.matDecorator, - m_cfg.geometryIdentifierHook); - return ActsExamples::ProcessCode::SUCCESS; -} - -std::shared_ptr -ActsExamples::DD4hep::DD4hepGeometryService::trackingGeometry( - const Acts::GeometryContext& gctx) { - if (!m_trackingGeometry) { - buildTrackingGeometry(gctx); - } - return m_trackingGeometry; -} - -void ActsExamples::DD4hep::DD4hepGeometryService::drop() { - if (m_detector == nullptr) { - return; - } - dd4hep::Detector::destroyInstance(m_cfg.name); - m_detector = nullptr; - m_geometry = dd4hep::DetElement(); - m_trackingGeometry = nullptr; -} - -void ActsExamples::DD4hep::sortFCChhDetElements( - std::vector& det) { - std::vector tracker; - std::vector eCal; - std::vector hCal; - std::vector muon; - for (auto& detElement : det) { - std::string detName = detElement.name(); - if (detName.find("Muon") != std::string::npos) { - muon.push_back(detElement); - } else if (detName.find("ECal") != std::string::npos) { - eCal.push_back(detElement); - } else if (detName.find("HCal") != std::string::npos) { - hCal.push_back(detElement); - } else { - tracker.push_back(detElement); - } - } - sort(muon.begin(), muon.end(), - [](const dd4hep::DetElement& a, const dd4hep::DetElement& b) { - return (a.id() < b.id()); - }); - sort(eCal.begin(), eCal.end(), - [](const dd4hep::DetElement& a, const dd4hep::DetElement& b) { - return (a.id() < b.id()); - }); - sort(hCal.begin(), hCal.end(), - [](const dd4hep::DetElement& a, const dd4hep::DetElement& b) { - return (a.id() < b.id()); - }); - sort(tracker.begin(), tracker.end(), - [](const dd4hep::DetElement& a, const dd4hep::DetElement& b) { - return (a.id() < b.id()); - }); - det.clear(); - det = tracker; - - det.insert(det.end(), eCal.begin(), eCal.end()); - det.insert(det.end(), hCal.begin(), hCal.end()); - det.insert(det.end(), muon.begin(), muon.end()); -} diff --git a/Examples/Detectors/Geant4Detector/CMakeLists.txt b/Examples/Detectors/Geant4Detector/CMakeLists.txt index 8a83657de5a..15b3597f539 100644 --- a/Examples/Detectors/Geant4Detector/CMakeLists.txt +++ b/Examples/Detectors/Geant4Detector/CMakeLists.txt @@ -1,11 +1,18 @@ add_library(ActsExamplesDetectorGeant4 SHARED src/Geant4Detector.cpp) + target_include_directories( ActsExamplesDetectorGeant4 PUBLIC $ ) + target_link_libraries( ActsExamplesDetectorGeant4 - PUBLIC ActsCore ActsExamplesFramework ActsExamplesGeant4 ActsPluginGeant4 + PUBLIC + ActsCore + ActsExamplesFramework + ActsExamplesGeant4 + ActsPluginGeant4 + ActsExamplesDetectorCommons ) install( diff --git a/Examples/Detectors/Geant4Detector/include/ActsExamples/Geant4Detector/Geant4Detector.hpp b/Examples/Detectors/Geant4Detector/include/ActsExamples/Geant4Detector/Geant4Detector.hpp index 5a948c3f3b5..6deed5777cf 100644 --- a/Examples/Detectors/Geant4Detector/include/ActsExamples/Geant4Detector/Geant4Detector.hpp +++ b/Examples/Detectors/Geant4Detector/include/ActsExamples/Geant4Detector/Geant4Detector.hpp @@ -12,6 +12,7 @@ #include "Acts/Geometry/GeometryIdentifier.hpp" #include "Acts/Plugins/Geant4/Geant4DetectorSurfaceFactory.hpp" #include "Acts/Utilities/Logger.hpp" +#include "ActsExamples/DetectorCommons/Detector.hpp" #include #include @@ -32,18 +33,19 @@ class Detector; namespace ActsExamples { class IContextDecorator; +} // namespace ActsExamples -namespace Geant4 { +namespace ActsExamples::Geant4 { -struct Geant4Detector { - using DetectorElements = - std::vector>; +struct Geant4Detector : public DetectorCommons::Detector { + using TrackingGeometryPtr = std::shared_ptr; using DetectorPtr = std::shared_ptr; - using Surfaces = std::vector>; - using ContextDecorators = std::vector>; - using TrackingGeometryPtr = std::shared_ptr; + + using DetectorElements = + std::vector>; + using Surfaces = std::vector>; /// Nested configuration struct struct Config { @@ -62,12 +64,30 @@ struct Geant4Detector { Acts::Logging::Level logLevel = Acts::Logging::INFO; }; + explicit Geant4Detector(const Config& cfg); + + const DetectorElements& detectorElements() const; + + void drop() final; + + private: + Config m_cfg; + + DetectorElements m_detectorElements; + + std::unique_ptr m_logger; + + const Acts::Logger& logger() const { return *m_logger; } + + void buildTrackingGeometry() final; + void buildDetector() final; + /// @brief Construct an Acts::Detector from a Geant4 world volume /// @param cfg the configuration of the Geant4 detector /// @param logger a logger instance /// @return a tuple of an Acts::Detector object, a ContextDecorator & the created detector elements std::tuple - constructDetector(const Config& cfg, const Acts::Logger& logger); + constructDetector() const; /// @brief Construct a TrackingGeometry from a Geant4 world volume using the KDTreeTrackingGeometryBuilder builder /// @@ -77,18 +97,15 @@ struct Geant4Detector { /// /// @return a tuple of an Acts::TrackingGeometry object, a ContextDecorator & the created detector elements std::tuple - constructTrackingGeometry(const Config& cfg, const Acts::Logger& logger); + constructTrackingGeometry() const; - private: /// @brief Convert Geant4VPhysicalVolume objects into Acts components /// /// @param cfg the configuration of the Geant4 detector /// @param logger a logger instance /// /// @return a tuple of surfaces and detector elements - std::tuple convertGeant4Volumes( - const Config& cfg, const Acts::Logger& logger) const; + std::tuple convertGeant4Volumes() const; }; -} // namespace Geant4 -} // namespace ActsExamples +} // namespace ActsExamples::Geant4 diff --git a/Examples/Detectors/Geant4Detector/src/Geant4Detector.cpp b/Examples/Detectors/Geant4Detector/src/Geant4Detector.cpp index e3b52f36cd3..cbdeab994dd 100644 --- a/Examples/Detectors/Geant4Detector/src/Geant4Detector.cpp +++ b/Examples/Detectors/Geant4Detector/src/Geant4Detector.cpp @@ -16,6 +16,7 @@ #include "Acts/Geometry/SurfaceArrayCreator.hpp" #include "Acts/Geometry/TrackingGeometry.hpp" #include "Acts/Geometry/TrackingVolumeArrayCreator.hpp" +#include "ActsExamples/DetectorCommons/Detector.hpp" #include #include @@ -23,97 +24,123 @@ #include "G4Transform3D.hh" #include "G4VPhysicalVolume.hh" -auto ActsExamples::Geant4::Geant4Detector::constructDetector( - const ActsExamples::Geant4::Geant4Detector::Config& cfg, - const Acts::Logger& logger) - -> std::tuple { - if (cfg.g4World == nullptr) { +namespace ActsExamples::Geant4 { + +Geant4Detector::Geant4Detector(const Geant4Detector::Config& cfg) + : DetectorCommons::Detector( + Acts::getDefaultLogger("Geant4Detector", m_cfg.logLevel)), + m_cfg(cfg) {} + +const Geant4Detector::DetectorElements& Geant4Detector::detectorElements() + const { + return m_detectorElements; +} + +void Geant4Detector::drop() { + Detector::drop(); + + m_detectorElements.clear(); +} + +void Geant4Detector::buildTrackingGeometry() { + std::tie(m_trackingGeometry, m_contextDecorators, m_detectorElements) = + constructTrackingGeometry(); +} + +void Geant4Detector::buildDetector() { + std::tie(m_detector, m_contextDecorators, m_detectorElements) = + constructDetector(); +} + +std::tuple +Geant4Detector::constructDetector() const { + if (m_cfg.g4World == nullptr) { throw std::invalid_argument( "Geant4Detector: no world Geant4 volume provided"); } ACTS_INFO("Building an Acts::Detector called '" - << cfg.name << "' from the Geant4PhysVolume '" - << cfg.g4World->GetName() << "'"); + << m_cfg.name << "' from the Geant4PhysVolume '" + << m_cfg.g4World->GetName() << "'"); DetectorPtr detector = nullptr; ContextDecorators decorators = {}; - auto [surfaces, elements] = convertGeant4Volumes(cfg, logger); + auto [surfaces, elements] = convertGeant4Volumes(); - return std::tie(detector, decorators, elements); + return {std::move(detector), std::move(decorators), std::move(elements)}; } -auto ActsExamples::Geant4::Geant4Detector::constructTrackingGeometry( - const ActsExamples::Geant4::Geant4Detector::Config& cfg, - const Acts::Logger& logger) - -> std::tuple { - if (cfg.g4World == nullptr) { +std::tuple +Geant4Detector::constructTrackingGeometry() const { + if (m_cfg.g4World == nullptr) { throw std::invalid_argument( "Geant4Detector: no world Geant4 volume provided"); } ACTS_INFO("Building an Acts::TrackingGeometry called '" - << cfg.name << "' from the Geant4PhysVolume '" - << cfg.g4World->GetName() << "'"); + << m_cfg.name << "' from the Geant4PhysVolume '" + << m_cfg.g4World->GetName() << "'"); ContextDecorators decorators = {}; - auto [surfaces, elements] = convertGeant4Volumes(cfg, logger); + auto [surfaces, elements] = convertGeant4Volumes(); // Surface array creator auto surfaceArrayCreator = std::make_shared( - Acts::SurfaceArrayCreator::Config(), logger.clone("SurfaceArrayCreator")); + Acts::SurfaceArrayCreator::Config(), + logger().clone("SurfaceArrayCreator")); // Layer Creator Acts::LayerCreator::Config lcConfig; lcConfig.surfaceArrayCreator = surfaceArrayCreator; auto layerCreator = std::make_shared( - lcConfig, logger.clone("LayerCreator")); + lcConfig, logger().clone("LayerCreator")); // Layer array creator Acts::LayerArrayCreator::Config lacConfig; auto layerArrayCreator = std::make_shared( - lacConfig, logger.clone("LayerArrayCreator")); + lacConfig, logger().clone("LayerArrayCreator")); // Tracking volume array creator Acts::TrackingVolumeArrayCreator::Config tvacConfig; auto tVolumeArrayCreator = std::make_shared( - tvacConfig, logger.clone("TrackingVolumeArrayCreator")); + tvacConfig, logger().clone("TrackingVolumeArrayCreator")); // configure the cylinder volume helper Acts::CylinderVolumeHelper::Config cvhConfig; cvhConfig.layerArrayCreator = layerArrayCreator; cvhConfig.trackingVolumeArrayCreator = tVolumeArrayCreator; auto cylinderVolumeHelper = std::make_shared( - cvhConfig, logger.clone("CylinderVolumeHelper")); + cvhConfig, logger().clone("CylinderVolumeHelper")); // Configure the tracking geometry builder, copy the surfaces in Acts::KDTreeTrackingGeometryBuilder::Config kdtCfg; kdtCfg.surfaces = surfaces; kdtCfg.layerCreator = layerCreator; kdtCfg.trackingVolumeHelper = cylinderVolumeHelper; - kdtCfg.protoDetector = cfg.protoDetector; - kdtCfg.geometryIdentifierHook = cfg.geometryIdentifierHook; + kdtCfg.protoDetector = m_cfg.protoDetector; + kdtCfg.geometryIdentifierHook = m_cfg.geometryIdentifierHook; // The KDT tracking geometry builder auto kdtBuilder = Acts::KDTreeTrackingGeometryBuilder( - kdtCfg, logger.clone("KDTreeTrackingGeometryBuilder")); + kdtCfg, logger().clone("KDTreeTrackingGeometryBuilder")); Acts::GeometryContext tContext; TrackingGeometryPtr trackingGeometry = kdtBuilder.trackingGeometry(tContext); - return std::tie(trackingGeometry, decorators, elements); + return {std::move(trackingGeometry), std::move(decorators), + std::move(elements)}; } -auto ActsExamples::Geant4::Geant4Detector::convertGeant4Volumes( - const Geant4Detector::Config& cfg, const Acts::Logger& logger) const - -> std::tuple { +std::tuple +Geant4Detector::convertGeant4Volumes() const { // Generate the surface cache Acts::Geant4DetectorSurfaceFactory::Cache g4SurfaceCache; G4Transform3D g4ToWorld; Acts::Geant4DetectorSurfaceFactory{}.construct( - g4SurfaceCache, g4ToWorld, *cfg.g4World, cfg.g4SurfaceOptions); + g4SurfaceCache, g4ToWorld, *m_cfg.g4World, m_cfg.g4SurfaceOptions); ACTS_INFO("Found " << g4SurfaceCache.matchedG4Volumes << " matching Geant4 Physical volumes."); @@ -141,5 +168,7 @@ auto ActsExamples::Geant4::Geant4Detector::convertGeant4Volumes( surfaces.insert(surfaces.end(), g4SurfaceCache.passiveSurfaces.begin(), g4SurfaceCache.passiveSurfaces.end()); - return std::tie(surfaces, elements); + return {std::move(surfaces), std::move(elements)}; } + +} // namespace ActsExamples::Geant4 diff --git a/Examples/Detectors/GenericDetector/CMakeLists.txt b/Examples/Detectors/GenericDetector/CMakeLists.txt index 242e710df42..a0802109de6 100644 --- a/Examples/Detectors/GenericDetector/CMakeLists.txt +++ b/Examples/Detectors/GenericDetector/CMakeLists.txt @@ -5,12 +5,16 @@ add_library( src/GenericDetector.cpp src/GenericDetectorElement.cpp ) + target_include_directories( ActsExamplesDetectorGeneric PUBLIC $ ) -target_link_libraries(ActsExamplesDetectorGeneric PUBLIC ActsCore) -target_link_libraries(ActsExamplesDetectorGeneric PUBLIC ActsExamplesFramework) + +target_link_libraries( + ActsExamplesDetectorGeneric + PUBLIC ActsCore ActsExamplesFramework ActsExamplesDetectorCommons +) install( TARGETS ActsExamplesDetectorGeneric diff --git a/Examples/Detectors/GenericDetector/include/ActsExamples/GenericDetector/BuildGenericDetector.hpp b/Examples/Detectors/GenericDetector/include/ActsExamples/GenericDetector/BuildGenericDetector.hpp index c5968ef4ca3..fe633500b3b 100644 --- a/Examples/Detectors/GenericDetector/include/ActsExamples/GenericDetector/BuildGenericDetector.hpp +++ b/Examples/Detectors/GenericDetector/include/ActsExamples/GenericDetector/BuildGenericDetector.hpp @@ -108,7 +108,7 @@ std::vector> modulePositionsDisc( /// return a unique vector to the tracking geometry template std::unique_ptr buildDetector( - const typename detector_element_t::ContextType& gctxIn, + const Acts::GeometryContext& gctxIn, std::vector>>& detectorStore, std::size_t level, diff --git a/Examples/Detectors/GenericDetector/include/ActsExamples/GenericDetector/GenericDetector.hpp b/Examples/Detectors/GenericDetector/include/ActsExamples/GenericDetector/GenericDetector.hpp index c487f43d3a6..755efa608da 100644 --- a/Examples/Detectors/GenericDetector/include/ActsExamples/GenericDetector/GenericDetector.hpp +++ b/Examples/Detectors/GenericDetector/include/ActsExamples/GenericDetector/GenericDetector.hpp @@ -9,46 +9,40 @@ #pragma once #include "Acts/Utilities/Logger.hpp" +#include "ActsExamples/DetectorCommons/Detector.hpp" #include #include #include #include -namespace Acts { -class TrackingGeometry; -class IMaterialDecorator; -} // namespace Acts - -namespace ActsExamples { -class IContextDecorator; -} // namespace ActsExamples - namespace ActsExamples::Generic { class GenericDetectorElement; -} // namespace ActsExamples::Generic - -struct GenericDetector { - using DetectorElement = ActsExamples::Generic::GenericDetectorElement; - using DetectorElementPtr = std::shared_ptr; - using DetectorStore = std::vector>; +class GenericDetector : public ActsExamples::DetectorCommons::Detector { + public: + using TrackingGeometryPtr = std::shared_ptr; using ContextDecorators = std::vector>; - using TrackingGeometryPtr = std::shared_ptr; + + using DetectorElement = ActsExamples::Generic::GenericDetectorElement; struct Config { std::size_t buildLevel{3}; + Acts::Logging::Level logLevel{Acts::Logging::INFO}; Acts::Logging::Level surfaceLogLevel{Acts::Logging::INFO}; Acts::Logging::Level layerLogLevel{Acts::Logging::INFO}; Acts::Logging::Level volumeLogLevel{Acts::Logging::INFO}; bool buildProto{false}; + std::shared_ptr materialDecorator; }; - /// The Store of the detector elements (lifetime: job) - DetectorStore detectorStore; + explicit GenericDetector(const Config& cfg); - std::pair finalize( - const Config& cfg, - std::shared_ptr mdecorator); + private: + Config m_cfg; + + void buildTrackingGeometry() final; }; + +} // namespace ActsExamples::Generic diff --git a/Examples/Detectors/GenericDetector/src/GenericDetector.cpp b/Examples/Detectors/GenericDetector/src/GenericDetector.cpp index 6a152128edc..6f46ad9e166 100644 --- a/Examples/Detectors/GenericDetector/src/GenericDetector.cpp +++ b/Examples/Detectors/GenericDetector/src/GenericDetector.cpp @@ -8,25 +8,34 @@ #include "ActsExamples/GenericDetector/GenericDetector.hpp" +#include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Geometry/ILayerBuilder.hpp" #include "Acts/Geometry/TrackingGeometry.hpp" +#include "Acts/Utilities/Logger.hpp" +#include "ActsExamples/DetectorCommons/Detector.hpp" #include "ActsExamples/GenericDetector/BuildGenericDetector.hpp" #include "ActsExamples/GenericDetector/GenericDetectorElement.hpp" #include "ActsExamples/GenericDetector/ProtoLayerCreatorT.hpp" -auto GenericDetector::finalize( - const Config& cfg, - std::shared_ptr mdecorator) - -> std::pair { - DetectorElement::ContextType nominalContext; - /// Return the generic detector - TrackingGeometryPtr gGeometry = - ActsExamples::Generic::buildDetector( - nominalContext, detectorStore, cfg.buildLevel, std::move(mdecorator), - cfg.buildProto, cfg.surfaceLogLevel, cfg.layerLogLevel, - cfg.volumeLogLevel); - ContextDecorators gContextDecorators = {}; - // return the pair of geometry and empty decorators - return std::make_pair( - std::move(gGeometry), std::move(gContextDecorators)); +namespace ActsExamples::Generic { + +GenericDetector::GenericDetector(const Config& cfg) + : DetectorCommons::Detector( + Acts::getDefaultLogger("GenericDetector", m_cfg.logLevel)), + m_cfg(cfg) {} + +void GenericDetector::buildTrackingGeometry() { + Acts::GeometryContext gctx; + std::vector>> detectorStore; + m_trackingGeometry = ActsExamples::Generic::buildDetector( + gctx, detectorStore, m_cfg.buildLevel, m_cfg.materialDecorator, + m_cfg.buildProto, m_cfg.surfaceLogLevel, m_cfg.layerLogLevel, + m_cfg.volumeLogLevel); + for (auto& something : detectorStore) { + for (auto& element : something) { + m_detectorStore.push_back(std::move(element)); + } + } } + +} // namespace ActsExamples::Generic diff --git a/Examples/Detectors/MuonSpectrometerMockupDetector/src/MockupSectorBuilder.cpp b/Examples/Detectors/MuonSpectrometerMockupDetector/src/MockupSectorBuilder.cpp index bdfe8fe532c..a3dce05c112 100644 --- a/Examples/Detectors/MuonSpectrometerMockupDetector/src/MockupSectorBuilder.cpp +++ b/Examples/Detectors/MuonSpectrometerMockupDetector/src/MockupSectorBuilder.cpp @@ -77,10 +77,9 @@ ActsExamples::MockupSectorBuilder::buildChamber( g4SurfaceOptions.passiveSurfaceSelector = g4Passive; g4WorldConfig.g4SurfaceOptions = g4SurfaceOptions; - auto g4detector = ActsExamples::Geant4::Geant4Detector(); - - auto [detector, surfaces, detectorElements] = - g4detector.constructDetector(g4WorldConfig, Acts::getDummyLogger()); + auto g4detector = ActsExamples::Geant4::Geant4Detector(g4WorldConfig); + // Trigger the build of the detector + g4detector.detector(); // The vector that holds the converted sensitive surfaces of the chamber std::vector> strawSurfaces = {}; @@ -91,7 +90,7 @@ ActsExamples::MockupSectorBuilder::buildChamber( -std::numeric_limits::max())); // Convert the physical volumes of the detector elements to straw surfaces - for (auto& detectorElement : detectorElements) { + for (auto& detectorElement : g4detector.detectorElements()) { auto context = Acts::GeometryContext(); auto g4conv = Acts::Geant4PhysicalVolumeConverter(); diff --git a/Examples/Detectors/TGeoDetector/CMakeLists.txt b/Examples/Detectors/TGeoDetector/CMakeLists.txt index 3df36c62f15..2d5c0c0efe3 100644 --- a/Examples/Detectors/TGeoDetector/CMakeLists.txt +++ b/Examples/Detectors/TGeoDetector/CMakeLists.txt @@ -9,6 +9,7 @@ target_include_directories( ActsExamplesDetectorTGeo PUBLIC $ ) + target_link_libraries( ActsExamplesDetectorTGeo PUBLIC @@ -17,6 +18,7 @@ target_link_libraries( ActsPluginJson ActsExamplesFramework ActsExamplesDetectorGeneric + ActsExamplesDetectorCommons ActsExamplesITkModuleSplitting ) diff --git a/Examples/Detectors/TGeoDetector/include/ActsExamples/TGeoDetector/JsonTGeoDetectorConfig.hpp b/Examples/Detectors/TGeoDetector/include/ActsExamples/TGeoDetector/JsonTGeoDetectorConfig.hpp index eb038572fcf..6246d0a9c77 100644 --- a/Examples/Detectors/TGeoDetector/include/ActsExamples/TGeoDetector/JsonTGeoDetectorConfig.hpp +++ b/Examples/Detectors/TGeoDetector/include/ActsExamples/TGeoDetector/JsonTGeoDetectorConfig.hpp @@ -53,29 +53,26 @@ NLOHMANN_JSON_SERIALIZE_ENUM(Acts::BinningType, } // namespace Acts -namespace ActsExamples { - -namespace Options { +namespace ActsExamples::Options { /// Read config for options interval -void from_json(const nlohmann::json& j, - ActsExamples::Options::Interval& interval) { +void from_json(const nlohmann::json& j, Interval& interval) { interval.lower = j.at("lower"); interval.upper = j.at("upper"); } /// Write config for options interval -void to_json(nlohmann::json& j, - const ActsExamples::Options::Interval& interval) { +void to_json(nlohmann::json& j, const Interval& interval) { // no direct conversion from std::optional to json j = nlohmann::json{{"lower", interval.lower.value_or(0)}, {"upper", interval.upper.value_or(0)}}; } -} // namespace Options +} // namespace ActsExamples::Options -void from_json(const nlohmann::json& j, - ActsExamples::TGeoITkModuleSplitter::Config& msc) { +namespace ActsExamples::TGeo { + +void from_json(const nlohmann::json& j, TGeoITkModuleSplitter::Config& msc) { msc.barrelMap = j["geo-tgeo-barrel-map"].get>(); msc.discMap = @@ -83,8 +80,7 @@ void from_json(const nlohmann::json& j, .get>>>(); } -void to_json(nlohmann::json& j, - const ActsExamples::TGeoITkModuleSplitter::Config& msc) { +void to_json(nlohmann::json& j, const TGeoITkModuleSplitter::Config& msc) { j["geo-tgeo-barrel-map"] = msc.barrelMap; j["geo-tgeo-disc-map"] = msc.discMap; } @@ -92,7 +88,7 @@ void to_json(nlohmann::json& j, /// Read layer configuration triplets template void from_json(const nlohmann::json& j, - ActsExamples::TGeoDetector::Config::LayerTriplet& ltr) { + TGeoDetector::Config::LayerTriplet& ltr) { ltr.negative = j.at("negative").get(); ltr.central = j.at("central").get(); ltr.positive = j.at("positive").get(); @@ -101,15 +97,14 @@ void from_json(const nlohmann::json& j, /// Write layer configuration triplets template void to_json(nlohmann::json& j, - const ActsExamples::TGeoDetector::Config::LayerTriplet& ltr) { + const TGeoDetector::Config::LayerTriplet& ltr) { j = nlohmann::json{{"negative", ltr.negative}, {"central", ltr.central}, {"positive", ltr.positive}}; } /// Read volume struct -void from_json(const nlohmann::json& j, - ActsExamples::TGeoDetector::Config::Volume& vol) { +void from_json(const nlohmann::json& j, TGeoDetector::Config::Volume& vol) { // subdetector selection vol.name = j.at("geo-tgeo-volume-name"); @@ -145,8 +140,7 @@ void from_json(const nlohmann::json& j, if (j.count("geo-tgeo-itk-module-split") != 0) { vol.itkModuleSplit = j.at("geo-tgeo-itk-module-split"); if (vol.itkModuleSplit) { - ActsExamples::TGeoITkModuleSplitter::Config itkConfig = - j.at("Splitters").at("ITk"); + TGeoITkModuleSplitter::Config itkConfig = j.at("Splitters").at("ITk"); vol.barrelMap = itkConfig.barrelMap; vol.discMap = itkConfig.discMap; } @@ -185,11 +179,11 @@ void to_json(nlohmann::json& j, const TGeoDetector::Config::Volume& vol) { j["Splitters"]["CylinderDisk"] = cdConfig; if (vol.itkModuleSplit) { - ActsExamples::TGeoITkModuleSplitter::Config itkConfig; + TGeoITkModuleSplitter::Config itkConfig; itkConfig.barrelMap = vol.barrelMap; itkConfig.discMap = vol.discMap; j["Splitters"]["ITk"] = itkConfig; } } -} // namespace ActsExamples +} // namespace ActsExamples::TGeo diff --git a/Examples/Detectors/TGeoDetector/include/ActsExamples/TGeoDetector/TGeoDetector.hpp b/Examples/Detectors/TGeoDetector/include/ActsExamples/TGeoDetector/TGeoDetector.hpp index 0fae0df1c5a..e4c53bcd1d1 100644 --- a/Examples/Detectors/TGeoDetector/include/ActsExamples/TGeoDetector/TGeoDetector.hpp +++ b/Examples/Detectors/TGeoDetector/include/ActsExamples/TGeoDetector/TGeoDetector.hpp @@ -9,9 +9,11 @@ #pragma once #include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Material/IMaterialDecorator.hpp" #include "Acts/Plugins/TGeo/TGeoLayerBuilder.hpp" #include "Acts/Utilities/BinningType.hpp" #include "Acts/Utilities/Logger.hpp" +#include "ActsExamples/DetectorCommons/Detector.hpp" #include "ActsExamples/Utilities/Options.hpp" #include @@ -22,30 +24,18 @@ #include #include -namespace Acts { -class TGeoDetectorElement; -class TrackingGeometry; -class IMaterialDecorator; -} // namespace Acts - -namespace ActsExamples { -class IContextDecorator; -} // namespace ActsExamples - -namespace ActsExamples { - -struct TGeoDetector { - using DetectorElementPtr = std::shared_ptr; - using DetectorStore = std::vector; +namespace ActsExamples::TGeo { +class TGeoDetector : public DetectorCommons::Detector { + public: + using TrackingGeometryPtr = std::shared_ptr; using ContextDecorators = std::vector>; - using TrackingGeometryPtr = std::shared_ptr; - /// The Store of the detector elements (lifetime: job) - DetectorStore detectorStore; + using DetectorElement = Acts::TGeoDetectorElement; struct Config { + Acts::Logging::Level logLevel = Acts::Logging::WARNING; Acts::Logging::Level surfaceLogLevel = Acts::Logging::WARNING; Acts::Logging::Level layerLogLevel = Acts::Logging::WARNING; Acts::Logging::Level volumeLogLevel = Acts::Logging::WARNING; @@ -69,6 +59,8 @@ struct TGeoDetector { std::shared_ptr geometryIdentifierHook = std::make_shared(); + std::shared_ptr materialDecorator; + enum SubVolume : std::size_t { Negative = 0, Central, Positive }; template @@ -150,9 +142,12 @@ struct TGeoDetector { static void readTGeoLayerBuilderConfigsFile(const std::string& path, Config& config); - std::pair finalize( - const Config& cfg, - std::shared_ptr mdecorator); + explicit TGeoDetector(const Config& cfg); + + private: + Config m_cfg; + + void buildTrackingGeometry() final; }; -} // namespace ActsExamples +} // namespace ActsExamples::TGeo diff --git a/Examples/Detectors/TGeoDetector/include/ActsExamples/TGeoDetector/TGeoITkModuleSplitter.hpp b/Examples/Detectors/TGeoDetector/include/ActsExamples/TGeoDetector/TGeoITkModuleSplitter.hpp index ab928752f49..640a388692e 100644 --- a/Examples/Detectors/TGeoDetector/include/ActsExamples/TGeoDetector/TGeoITkModuleSplitter.hpp +++ b/Examples/Detectors/TGeoDetector/include/ActsExamples/TGeoDetector/TGeoITkModuleSplitter.hpp @@ -26,7 +26,7 @@ namespace Acts { class TGeoDetectorElement; } -namespace ActsExamples { +namespace ActsExamples::TGeo { /// @brief TGeoITkModuleSplitter /// @@ -120,4 +120,4 @@ class TGeoITkModuleSplitter : public Acts::ITGeoDetectorElementSplitter { std::unique_ptr m_logger; }; -} // namespace ActsExamples +} // namespace ActsExamples::TGeo diff --git a/Examples/Detectors/TGeoDetector/src/TGeoDetector.cpp b/Examples/Detectors/TGeoDetector/src/TGeoDetector.cpp index aeed881eb1e..487a3b2caa9 100644 --- a/Examples/Detectors/TGeoDetector/src/TGeoDetector.cpp +++ b/Examples/Detectors/TGeoDetector/src/TGeoDetector.cpp @@ -10,6 +10,7 @@ #include "Acts/Geometry/CylinderVolumeBuilder.hpp" #include "Acts/Geometry/CylinderVolumeHelper.hpp" +#include "Acts/Geometry/DetectorElementBase.hpp" #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Geometry/ITrackingVolumeBuilder.hpp" #include "Acts/Geometry/LayerArrayCreator.hpp" @@ -26,7 +27,6 @@ #include "Acts/Utilities/Logger.hpp" #include "ActsExamples/TGeoDetector/JsonTGeoDetectorConfig.hpp" #include "ActsExamples/TGeoDetector/TGeoITkModuleSplitter.hpp" -#include "ActsExamples/Utilities/Options.hpp" #include #include @@ -43,8 +43,7 @@ #include "TGeoManager.h" -namespace ActsExamples { -using namespace Options; +namespace ActsExamples::TGeo { namespace { @@ -135,12 +134,12 @@ std::vector makeLayerBuilderConfigs( cdsConfig, logger.clone("TGeoCylinderDiscSplitter", config.layerLogLevel)); } else if (volume.itkModuleSplit) { - ActsExamples::TGeoITkModuleSplitter::Config itkConfig; + TGeoITkModuleSplitter::Config itkConfig; itkConfig.barrelMap = volume.barrelMap; itkConfig.discMap = volume.discMap; itkConfig.splitPatterns = volume.splitPatterns; layerBuilderConfig.detectorElementSplitter = - std::make_shared( + std::make_shared( itkConfig, logger.clone("TGeoITkModuleSplitter", config.layerLogLevel)); } @@ -162,7 +161,7 @@ std::vector makeLayerBuilderConfigs( /// @param vm is the variable map from the options std::shared_ptr buildTGeoDetector( const TGeoDetector::Config& config, const Acts::GeometryContext& context, - std::vector>& + std::vector>& detElementStore, std::shared_ptr mdecorator, const Acts::Logger& logger) { @@ -367,23 +366,20 @@ void TGeoDetector::readTGeoLayerBuilderConfigsFile(const std::string& path, } } -auto TGeoDetector::finalize( - const Config& cfg, - std::shared_ptr mdecorator) - -> std::pair { - Acts::GeometryContext tGeoContext; - auto logger = Acts::getDefaultLogger("TGeoDetector", Acts::Logging::INFO); - TrackingGeometryPtr tgeoTrackingGeometry = buildTGeoDetector( - cfg, tGeoContext, detectorStore, std::move(mdecorator), *logger); - - ContextDecorators tgeoContextDecorators = {}; - // Return the pair of geometry and empty decorators - return std::make_pair( - std::move(tgeoTrackingGeometry), std::move(tgeoContextDecorators)); -} +TGeoDetector::TGeoDetector(const Config& cfg) + : DetectorCommons::Detector( + Acts::getDefaultLogger("TGeoDetector", m_cfg.logLevel)), + m_cfg(cfg) {} void TGeoDetector::Config::readJson(const std::string& jsonFile) { readTGeoLayerBuilderConfigsFile(jsonFile, *this); } -} // namespace ActsExamples +void TGeoDetector::buildTrackingGeometry() { + Acts::GeometryContext tGeoContext; + + m_trackingGeometry = buildTGeoDetector(m_cfg, tGeoContext, m_detectorStore, + m_cfg.materialDecorator, logger()); +} + +} // namespace ActsExamples::TGeo diff --git a/Examples/Detectors/TGeoDetector/src/TGeoITkModuleSplitter.cpp b/Examples/Detectors/TGeoDetector/src/TGeoITkModuleSplitter.cpp index 42bbbd9c882..a0f88391ce2 100644 --- a/Examples/Detectors/TGeoDetector/src/TGeoITkModuleSplitter.cpp +++ b/Examples/Detectors/TGeoDetector/src/TGeoITkModuleSplitter.cpp @@ -21,14 +21,16 @@ #include #include -ActsExamples::TGeoITkModuleSplitter::TGeoITkModuleSplitter( - const ActsExamples::TGeoITkModuleSplitter::Config& cfg, +namespace ActsExamples::TGeo { + +TGeoITkModuleSplitter::TGeoITkModuleSplitter( + const TGeoITkModuleSplitter::Config& cfg, std::unique_ptr logger) : m_cfg(cfg), m_logger(std::move(logger)) { initSplitCategories(); } -void ActsExamples::TGeoITkModuleSplitter::initSplitCategories() { +void TGeoITkModuleSplitter::initSplitCategories() { m_splitCategories.reserve(m_cfg.splitPatterns.size()); for (const std::pair& pattern_split_category : m_cfg.splitPatterns) { @@ -50,7 +52,7 @@ void ActsExamples::TGeoITkModuleSplitter::initSplitCategories() { /// If applicable, returns a split detector element inline std::vector> -ActsExamples::TGeoITkModuleSplitter::split( +TGeoITkModuleSplitter::split( const Acts::GeometryContext& gctx, std::shared_ptr detElement) const { // Is the current node covered by this splitter? @@ -66,10 +68,10 @@ ActsExamples::TGeoITkModuleSplitter::split( " node " + sensorName + " using split ranges of category " + std::get<1>(split_category)); if (!std::get<2>(split_category)) { - return ActsExamples::TGeoITkModuleSplitter::splitBarrelModule( + return TGeoITkModuleSplitter::splitBarrelModule( gctx, detElement, m_cfg.barrelMap.at(std::get<1>(split_category))); } else { - return ActsExamples::TGeoITkModuleSplitter::splitDiscModule( + return TGeoITkModuleSplitter::splitDiscModule( gctx, detElement, m_cfg.discMap.at(std::get<1>(split_category))); } } @@ -83,7 +85,7 @@ ActsExamples::TGeoITkModuleSplitter::split( /// If applicable, returns a split detector element inline std::vector> -ActsExamples::TGeoITkModuleSplitter::splitBarrelModule( +TGeoITkModuleSplitter::splitBarrelModule( const Acts::GeometryContext& gctx, const std::shared_ptr& detElement, unsigned int nSegments) const { @@ -101,11 +103,10 @@ ActsExamples::TGeoITkModuleSplitter::splitBarrelModule( /// If applicable, returns a split detector element inline std::vector> -ActsExamples::TGeoITkModuleSplitter::splitDiscModule( +TGeoITkModuleSplitter::splitDiscModule( const Acts::GeometryContext& gctx, const std::shared_ptr& detElement, - const std::vector& - splitRanges) const { + const std::vector& splitRanges) const { auto name = detElement->tgeoNode().GetName(); auto factory = [&](const auto& trafo, const auto& bounds) { @@ -117,3 +118,5 @@ ActsExamples::TGeoITkModuleSplitter::splitDiscModule( return ITk::splitDiscModule(gctx, detElement, splitRanges, factory, name, logger()); } + +} // namespace ActsExamples::TGeo diff --git a/Examples/Detectors/TelescopeDetector/CMakeLists.txt b/Examples/Detectors/TelescopeDetector/CMakeLists.txt index 9b41a082c42..cfc0373d1d9 100644 --- a/Examples/Detectors/TelescopeDetector/CMakeLists.txt +++ b/Examples/Detectors/TelescopeDetector/CMakeLists.txt @@ -5,13 +5,15 @@ add_library( src/TelescopeDetectorElement.cpp src/BuildTelescopeDetector.cpp ) + target_include_directories( ActsExamplesDetectorTelescope PUBLIC $ ) + target_link_libraries( ActsExamplesDetectorTelescope - PUBLIC ActsCore ActsExamplesFramework + PUBLIC ActsCore ActsExamplesFramework ActsExamplesDetectorCommons ) install( diff --git a/Examples/Detectors/TelescopeDetector/include/ActsExamples/TelescopeDetector/BuildTelescopeDetector.hpp b/Examples/Detectors/TelescopeDetector/include/ActsExamples/TelescopeDetector/BuildTelescopeDetector.hpp index 9e3b5977a6a..b2363a58976 100644 --- a/Examples/Detectors/TelescopeDetector/include/ActsExamples/TelescopeDetector/BuildTelescopeDetector.hpp +++ b/Examples/Detectors/TelescopeDetector/include/ActsExamples/TelescopeDetector/BuildTelescopeDetector.hpp @@ -46,8 +46,9 @@ enum class TelescopeSurfaceType { /// @param binValue indicates which axis the detector surface normals are /// parallel to std::unique_ptr buildDetector( - const typename TelescopeDetectorElement::ContextType& gctx, - std::vector>& detectorStore, + const Acts::GeometryContext& gctx, + std::vector>& + detectorStore, const std::vector& positions, const std::vector& stereoAngles, const std::array& offsets, const std::array& bounds, diff --git a/Examples/Detectors/TelescopeDetector/include/ActsExamples/TelescopeDetector/TelescopeDetector.hpp b/Examples/Detectors/TelescopeDetector/include/ActsExamples/TelescopeDetector/TelescopeDetector.hpp index 31095f42636..3d346db9e52 100644 --- a/Examples/Detectors/TelescopeDetector/include/ActsExamples/TelescopeDetector/TelescopeDetector.hpp +++ b/Examples/Detectors/TelescopeDetector/include/ActsExamples/TelescopeDetector/TelescopeDetector.hpp @@ -10,6 +10,7 @@ #include "Acts/Definitions/Units.hpp" #include "Acts/Utilities/Logger.hpp" +#include "ActsExamples/DetectorCommons/Detector.hpp" #include "ActsExamples/Utilities/Options.hpp" #include @@ -17,48 +18,37 @@ #include #include -using namespace Acts::UnitLiterals; - -namespace Acts { -class TrackingGeometry; -class IMaterialDecorator; -} // namespace Acts - -namespace ActsExamples { -class IContextDecorator; -} // namespace ActsExamples - namespace ActsExamples::Telescope { class TelescopeDetectorElement; class TelescopeG4DetectorConstruction; -struct TelescopeDetector { - using DetectorElement = ActsExamples::Telescope::TelescopeDetectorElement; - using DetectorElementPtr = std::shared_ptr; - using DetectorStore = std::vector; - +class TelescopeDetector : public ActsExamples::DetectorCommons::Detector { + public: + using TrackingGeometryPtr = std::shared_ptr; using ContextDecorators = std::vector>; - using TrackingGeometryPtr = std::shared_ptr; + + using DetectorElement = ActsExamples::Telescope::TelescopeDetectorElement; struct Config { std::vector positions{{0, 30, 60, 120, 150, 180}}; std::vector stereos{{0, 0, 0, 0, 0, 0}}; std::array offsets{{0, 0}}; std::array bounds{{25, 100}}; - double thickness{80_um}; + double thickness{80 * Acts::UnitConstants::um}; int surfaceType{0}; int binValue{2}; + std::shared_ptr materialDecorator; + Acts::Logging::Level logLevel{Acts::Logging::WARNING}; }; - Config config; - /// The store of the detector elements (lifetime: job) - DetectorStore detectorStore; + explicit TelescopeDetector(const Config& cfg); + + private: + Config m_cfg; - std::pair finalize( - const Config& cfg, - const std::shared_ptr& mdecorator); + void buildTrackingGeometry() final; }; } // namespace ActsExamples::Telescope diff --git a/Examples/Detectors/TelescopeDetector/src/BuildTelescopeDetector.cpp b/Examples/Detectors/TelescopeDetector/src/BuildTelescopeDetector.cpp index 7e01a9499bd..c5931239986 100644 --- a/Examples/Detectors/TelescopeDetector/src/BuildTelescopeDetector.cpp +++ b/Examples/Detectors/TelescopeDetector/src/BuildTelescopeDetector.cpp @@ -12,6 +12,7 @@ #include "Acts/Definitions/Units.hpp" #include "Acts/Geometry/CuboidVolumeBounds.hpp" #include "Acts/Geometry/CylinderVolumeBounds.hpp" +#include "Acts/Geometry/DetectorElementBase.hpp" #include "Acts/Geometry/DiscLayer.hpp" #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Geometry/ILayerArrayCreator.hpp" @@ -35,10 +36,8 @@ std::unique_ptr ActsExamples::Telescope::buildDetector( - const typename ActsExamples::Telescope::TelescopeDetectorElement:: - ContextType& gctx, - std::vector< - std::shared_ptr>& + const Acts::GeometryContext& gctx, + std::vector>& detectorStore, const std::vector& positions, const std::vector& stereoAngles, diff --git a/Examples/Detectors/TelescopeDetector/src/TelescopeDetector.cpp b/Examples/Detectors/TelescopeDetector/src/TelescopeDetector.cpp index 7a5e262067a..4df110e0848 100644 --- a/Examples/Detectors/TelescopeDetector/src/TelescopeDetector.cpp +++ b/Examples/Detectors/TelescopeDetector/src/TelescopeDetector.cpp @@ -8,55 +8,56 @@ #include "ActsExamples/TelescopeDetector/TelescopeDetector.hpp" +#include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Geometry/TrackingGeometry.hpp" #include "Acts/Utilities/BinningType.hpp" #include "ActsExamples/TelescopeDetector/BuildTelescopeDetector.hpp" #include "ActsExamples/TelescopeDetector/TelescopeDetectorElement.hpp" #include +#include #include -auto ActsExamples::Telescope::TelescopeDetector::finalize( - const Config& cfg, const std::shared_ptr& - /*mdecorator*/) -> std::pair { - DetectorElement::ContextType nominalContext; +namespace ActsExamples::Telescope { - if (cfg.surfaceType > 1) { +TelescopeDetector::TelescopeDetector(const Config& cfg) + : DetectorCommons::Detector( + Acts::getDefaultLogger("TelescopeDetector", cfg.logLevel)), + m_cfg(cfg) {} + +void TelescopeDetector::buildTrackingGeometry() { + Acts::GeometryContext gctx; + + if (m_cfg.surfaceType > 1) { throw std::invalid_argument( "The surface type could either be 0 for plane surface or 1 for disc " "surface."); } - if (cfg.binValue > 2) { + if (m_cfg.binValue > 2) { throw std::invalid_argument("The axis value could only be 0, 1, or 2."); } // Check if the bounds values are valid - if (cfg.surfaceType == 1 && cfg.bounds[0] >= cfg.bounds[1]) { + if (m_cfg.surfaceType == 1 && m_cfg.bounds[0] >= m_cfg.bounds[1]) { throw std::invalid_argument( "The minR should be smaller than the maxR for disc surface bounds."); } - if (cfg.positions.size() != cfg.stereos.size()) { + if (m_cfg.positions.size() != m_cfg.stereos.size()) { throw std::invalid_argument( "The number of provided positions must match the number of " "provided stereo angles."); } - config = cfg; - // Sort the provided distances - std::vector positions = cfg.positions; - std::vector stereos = cfg.stereos; - std::ranges::sort(positions); + std::vector positions = m_cfg.positions; + std::vector stereos = m_cfg.stereos; + std::sort(positions.begin(), positions.end()); /// Return the telescope detector - TrackingGeometryPtr gGeometry = ActsExamples::Telescope::buildDetector( - nominalContext, detectorStore, positions, stereos, cfg.offsets, - cfg.bounds, cfg.thickness, - static_cast( - cfg.surfaceType), - static_cast(cfg.binValue)); - ContextDecorators gContextDecorators = {}; - // return the pair of geometry and empty decorators - return std::make_pair( - std::move(gGeometry), std::move(gContextDecorators)); + m_trackingGeometry = ActsExamples::Telescope::buildDetector( + gctx, m_detectorStore, positions, stereos, m_cfg.offsets, m_cfg.bounds, + m_cfg.thickness, static_cast(m_cfg.surfaceType), + static_cast(m_cfg.binValue)); } + +} // namespace ActsExamples::Telescope diff --git a/Examples/Io/EDM4hep/include/ActsExamples/Io/EDM4hep/EDM4hepReader.hpp b/Examples/Io/EDM4hep/include/ActsExamples/Io/EDM4hep/EDM4hepReader.hpp index bfa87a6a7da..6bc9a66f43e 100644 --- a/Examples/Io/EDM4hep/include/ActsExamples/Io/EDM4hep/EDM4hepReader.hpp +++ b/Examples/Io/EDM4hep/include/ActsExamples/Io/EDM4hep/EDM4hepReader.hpp @@ -27,7 +27,7 @@ namespace ActsExamples { namespace DD4hep { -struct DD4hepDetector; +class DD4hepDetector; } /// Read particles from EDM4hep. diff --git a/Examples/Io/EDM4hep/src/EDM4hepReader.cpp b/Examples/Io/EDM4hep/src/EDM4hepReader.cpp index dfb11c84c9e..684803d23ce 100644 --- a/Examples/Io/EDM4hep/src/EDM4hepReader.cpp +++ b/Examples/Io/EDM4hep/src/EDM4hepReader.cpp @@ -328,8 +328,8 @@ ProcessCode EDM4hepReader::read(const AlgorithmContext& ctx) { [&](std::uint64_t cellId) { ACTS_VERBOSE("CellID: " << cellId); - const auto& vm = m_cfg.dd4hepDetector->geometryService->detector() - .volumeManager(); + const auto& vm = + m_cfg.dd4hepDetector->dd4hepDetector().volumeManager(); const auto detElement = vm.lookupDetElement(cellId); diff --git a/Examples/Python/python/acts/examples/dd4hep.py b/Examples/Python/python/acts/examples/dd4hep.py index cd23533dfda..6d1820df76c 100644 --- a/Examples/Python/python/acts/examples/dd4hep.py +++ b/Examples/Python/python/acts/examples/dd4hep.py @@ -19,7 +19,7 @@ _patch_detectors(ActsPythonBindingsDD4hep) ActsPythonBindingsDD4hep.DD4hepDetector.create = _detector_create( ActsPythonBindingsDD4hep.DD4hepDetector, - ActsPythonBindingsDD4hep.DD4hepGeometryService.Config, + ActsPythonBindingsDD4hep.DD4hepDetector.Config, ) from acts.ActsPythonBindingsDD4hep import * diff --git a/Examples/Python/src/DD4hepComponent.cpp b/Examples/Python/src/DD4hepComponent.cpp index f4ad0277aea..6c6944eb564 100644 --- a/Examples/Python/src/DD4hepComponent.cpp +++ b/Examples/Python/src/DD4hepComponent.cpp @@ -7,6 +7,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. #include "Acts/Detector/GeometryIdGenerator.hpp" +#include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Plugins/DD4hep/DD4hepDetectorElement.hpp" #include "Acts/Plugins/DD4hep/DD4hepDetectorStructure.hpp" #include "Acts/Plugins/DD4hep/DD4hepFieldAdapter.hpp" @@ -14,7 +15,7 @@ #include "Acts/Plugins/Python/Utilities.hpp" #include "Acts/Utilities/Logger.hpp" #include "ActsExamples/DD4hepDetector/DD4hepDetector.hpp" -#include "ActsExamples/DD4hepDetector/DD4hepGeometryService.hpp" +#include "ActsExamples/DetectorCommons/Detector.hpp" #include "ActsExamples/Framework/IContextDecorator.hpp" #include "ActsExamples/Framework/ProcessCode.hpp" @@ -36,12 +37,18 @@ using namespace Acts::Python; PYBIND11_MODULE(ActsPythonBindingsDD4hep, m) { { - using Config = DD4hep::DD4hepGeometryService::Config; - auto s = py::class_>( - m, "DD4hepGeometryService") - .def(py::init()) - .def("drop", &DD4hep::DD4hepGeometryService::drop); + py::class_>( + m, "DD4hepDetectorElement"); + } + + { + using Detector = DD4hep::DD4hepDetector; + using Config = Detector::Config; + + auto s = py::class_>(m, "DD4hepDetector") + .def(py::init()); auto c = py::class_(s, "Config").def(py::init<>()); ACTS_PYTHON_STRUCT_BEGIN(c, Config); @@ -55,6 +62,7 @@ PYBIND11_MODULE(ActsPythonBindingsDD4hep, m) { ACTS_PYTHON_MEMBER(envelopeR); ACTS_PYTHON_MEMBER(envelopeZ); ACTS_PYTHON_MEMBER(defaultLayerThickness); + ACTS_PYTHON_MEMBER(materialDecorator); ACTS_PYTHON_MEMBER(geometryIdentifierHook); ACTS_PYTHON_STRUCT_END(); @@ -67,12 +75,6 @@ PYBIND11_MODULE(ActsPythonBindingsDD4hep, m) { "DD4hepFieldAdapter"); } - { - py::class_>( - m, "DD4hepDetectorElement"); - } - { m.def("createDD4hepIdGeoIdMap", [](const Acts::TrackingGeometry& tGeometry) @@ -153,22 +155,4 @@ PYBIND11_MODULE(ActsPythonBindingsDD4hep, m) { options.geoIdGenerator = chainedGeoIdGenerator; }); } - - { - py::class_>( - m, "DD4hepDetector") - .def(py::init<>()) - .def(py::init>()) - .def("finalize", - py::overload_cast>( - &DD4hep::DD4hepDetector::finalize)) - .def("finalize", - py::overload_cast< - const Acts::GeometryContext&, - const Acts::Experimental::DD4hepDetectorStructure::Options&>( - &DD4hep::DD4hepDetector::finalize)) - .def("drop", &DD4hep::DD4hepDetector::drop) - .def_property_readonly("field", &DD4hep::DD4hepDetector::field); - } } diff --git a/Examples/Python/src/Detector.cpp b/Examples/Python/src/Detector.cpp index 6b9ef68f927..02a74b70fec 100644 --- a/Examples/Python/src/Detector.cpp +++ b/Examples/Python/src/Detector.cpp @@ -6,6 +6,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#include "ActsExamples/DetectorCommons/Detector.hpp" + +#include "Acts/Geometry/DetectorElementBase.hpp" #include "Acts/Geometry/TrackingGeometry.hpp" #include "Acts/Material/IMaterialDecorator.hpp" #include "Acts/Plugins/Python/Utilities.hpp" @@ -36,6 +39,7 @@ using namespace ActsExamples; namespace Acts::Python { void addDetector(Context& ctx) { auto [m, mex] = ctx.get("main", "examples"); + { py::class_>( mex, "IContextDecorator") @@ -44,16 +48,25 @@ void addDetector(Context& ctx) { } { - using Config = GenericDetector::Config; + py::class_>( + mex, "DetectorElementBase"); + } - auto gd = py::class_>( - mex, "GenericDetector") - .def(py::init<>()) - .def("finalize", - py::overload_cast< - const Config&, - std::shared_ptr>( - &GenericDetector::finalize)); + { + using Detector = DetectorCommons::Detector; + + py::class_>(mex, "Detector") + .def("trackingGeometry", &Detector::trackingGeometry) + .def("drop", &Detector::drop); + } + + { + using Detector = Generic::GenericDetector; + using Config = Detector::Config; + + auto gd = py::class_>(mex, "GenericDetector") + .def(py::init()); py::class_(gd, "Config") .def(py::init<>()) @@ -61,22 +74,17 @@ void addDetector(Context& ctx) { .def_readwrite("surfaceLogLevel", &Config::surfaceLogLevel) .def_readwrite("layerLogLevel", &Config::layerLogLevel) .def_readwrite("volumeLogLevel", &Config::volumeLogLevel) - .def_readwrite("buildProto", &Config::buildProto); + .def_readwrite("buildProto", &Config::buildProto) + .def_readwrite("materialDecorator", &Config::materialDecorator); } { - using TelescopeDetector = Telescope::TelescopeDetector; - using Config = TelescopeDetector::Config; - - auto td = - py::class_>( - mex, "TelescopeDetector") - .def(py::init<>()) - .def("finalize", - py::overload_cast< - const Config&, - const std::shared_ptr&>( - &TelescopeDetector::finalize)); + using Detector = Telescope::TelescopeDetector; + using Config = Detector::Config; + + auto td = py::class_>(mex, "TelescopeDetector") + .def(py::init()); py::class_(td, "Config") .def(py::init<>()) @@ -90,19 +98,14 @@ void addDetector(Context& ctx) { } { - using AlignedDetector = Contextual::AlignedDetector; - using Config = AlignedDetector::Config; - - auto d = py::class_>( - mex, "AlignedDetector") - .def(py::init<>()) - .def("finalize", - py::overload_cast< - const Config&, - std::shared_ptr>( - &AlignedDetector::finalize)); - - auto c = py::class_(d, "Config") + using Detector = Contextual::AlignedDetector; + using Config = Detector::Config; + + auto d = py::class_>(mex, "AlignedDetector") + .def(py::init()); + + auto c = py::class_(d, "Config") .def(py::init<>()); ACTS_PYTHON_STRUCT_BEGIN(c, Config); ACTS_PYTHON_MEMBER(seed); @@ -124,16 +127,12 @@ void addDetector(Context& ctx) { } { - using Config = TGeoDetector::Config; - - auto d = py::class_>( - mex, "TGeoDetector") - .def(py::init<>()) - .def("finalize", - py::overload_cast< - const Config&, - std::shared_ptr>( - &TGeoDetector::finalize)); + using Detector = TGeo::TGeoDetector; + using Config = Detector::Config; + + auto d = py::class_>(mex, "TGeoDetector") + .def(py::init()); py::class_(mex, "Interval") .def(py::init<>()) diff --git a/Examples/Python/src/Geant4Component.cpp b/Examples/Python/src/Geant4Component.cpp index ff34da94cc0..c39af806643 100644 --- a/Examples/Python/src/Geant4Component.cpp +++ b/Examples/Python/src/Geant4Component.cpp @@ -290,31 +290,15 @@ PYBIND11_MODULE(ActsPythonBindingsGeant4, mod) { std::shared_ptr>( mod, "Geant4DetectorElement"); - using Geant4Detector = Geant4::Geant4Detector; + using Detector = Geant4::Geant4Detector; + using Config = Detector::Config; auto g = - py::class_>( - mod, "Geant4Detector") - .def(py::init<>()) - .def( - "constructDetector", - [](Geant4Detector& self, const Geant4Detector::Config& cfg, - Logging::Level logLevel) { - auto logger = getDefaultLogger("Geant4Detector", logLevel); - return self.constructDetector(cfg, *logger); - }, - py::arg("cfg"), py::arg("logLevel") = Logging::INFO) - .def( - "constructTrackingGeometry", - [](Geant4Detector& self, const Geant4Detector::Config& cfg, - Logging::Level logLevel) { - auto logger = getDefaultLogger("Geant4Detector", logLevel); - return self.constructTrackingGeometry(cfg, *logger); - }, - py::arg("cfg"), py::arg("logLevel") = Logging::INFO); - - auto c = py::class_(g, "Config").def(py::init<>()); - ACTS_PYTHON_STRUCT_BEGIN(c, Geant4Detector::Config); + py::class_>(mod, "Geant4Detector") + .def(py::init()); + + auto c = py::class_(g, "Config").def(py::init<>()); + ACTS_PYTHON_STRUCT_BEGIN(c, Config); ACTS_PYTHON_MEMBER(name); ACTS_PYTHON_MEMBER(g4World); ACTS_PYTHON_MEMBER(g4SurfaceOptions); diff --git a/Examples/Python/src/Geant4DD4hepComponent.cpp b/Examples/Python/src/Geant4DD4hepComponent.cpp index 16ed3b40223..fc58a3abd18 100644 --- a/Examples/Python/src/Geant4DD4hepComponent.cpp +++ b/Examples/Python/src/Geant4DD4hepComponent.cpp @@ -30,7 +30,7 @@ PYBIND11_MODULE(ActsPythonBindingsDDG4, m) { m, "DDG4DetectorConstructionFactory") .def(py::init, std::vector>>(), - py::arg("detector"), + py::arg("geometryService"), py::arg("regionCreators") = std::vector>()); }