Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:41

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2019 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/DD4hepDetector/DD4hepDetector.hpp"
0010 
0011 #include "Acts/Geometry/GeometryContext.hpp"
0012 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
0013 #include "Acts/Plugins/DD4hep/DD4hepFieldAdapter.hpp"
0014 #include "ActsExamples/DD4hepDetector/DD4hepGeometryService.hpp"
0015 
0016 #include <cstddef>
0017 #include <memory>
0018 #include <stdexcept>
0019 #include <string>
0020 
0021 #include <DD4hep/DetElement.h>
0022 #include <DD4hep/Detector.h>
0023 #include <DD4hep/Fields.h>
0024 #include <boost/program_options.hpp>
0025 
0026 namespace ActsExamples::DD4hep {
0027 
0028 DD4hepDetector::DD4hepDetector(
0029     std::shared_ptr<DD4hepGeometryService> _geometryService)
0030     : geometryService(std::move(_geometryService)) {}
0031 
0032 auto DD4hepDetector::finalize(
0033     ActsExamples::DD4hep::DD4hepGeometryService::Config config,
0034     std::shared_ptr<const Acts::IMaterialDecorator> mdecorator)
0035     -> std::pair<TrackingGeometryPtr, ContextDecorators> {
0036   Acts::GeometryContext dd4HepContext;
0037   config.matDecorator = std::move(mdecorator);
0038   geometryService =
0039       std::make_shared<ActsExamples::DD4hep::DD4hepGeometryService>(config);
0040   TrackingGeometryPtr dd4tGeometry =
0041       geometryService->trackingGeometry(dd4HepContext);
0042   if (!dd4tGeometry) {
0043     throw std::runtime_error{
0044         "Did not receive tracking geometry from DD4hep geometry service"};
0045   }
0046   ContextDecorators dd4ContextDecorators = {};
0047   // return the pair of geometry and empty decorators
0048   return std::make_pair<TrackingGeometryPtr, ContextDecorators>(
0049       std::move(dd4tGeometry), std::move(dd4ContextDecorators));
0050 }
0051 
0052 auto DD4hepDetector::finalize(
0053     const Acts::GeometryContext& gctx,
0054     const Acts::Experimental::DD4hepDetectorStructure::Options& options)
0055     -> std::tuple<DetectorPtr, ContextDecorators,
0056                   Acts::DD4hepDetectorElement::Store> {
0057   if (geometryService == nullptr) {
0058     throw std::runtime_error{
0059         "No DD4hep geometry service configured, can not build "
0060         "TrackingGeometry."};
0061   }
0062 
0063   auto world = geometryService->geometry();
0064   // Build the detector structure
0065   Acts::Experimental::DD4hepDetectorStructure dd4hepStructure(
0066       Acts::getDefaultLogger("DD4hepDetectorStructure", options.logLevel));
0067 
0068   /// @return a detector and the detector store
0069   auto [detector, detectorElements] =
0070       dd4hepStructure.construct(gctx, world, options);
0071 
0072   // Prepare the return objects
0073   ContextDecorators contextDecorators = {};
0074 
0075   return {detector, contextDecorators, detectorElements};
0076 }
0077 
0078 std::shared_ptr<Acts::DD4hepFieldAdapter> DD4hepDetector::field() const {
0079   const auto& detector = geometryService->detector();
0080 
0081   return std::make_shared<Acts::DD4hepFieldAdapter>(detector.field());
0082 }
0083 
0084 }  // namespace ActsExamples::DD4hep