File indexing completed on 2026-05-10 08:01:46
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/EDM4hep/DD4hepPodioConversionHelper.hpp"
0010
0011 #include "Acts/Geometry/TrackingGeometry.hpp"
0012 #include "ActsExamples/EventData/IndexSourceLink.hpp"
0013 #include "ActsPlugins/DD4hep/DD4hepDetectorElement.hpp"
0014 #include "ActsPodioEdm/TrackerHitLocalCollection.h"
0015
0016 #include <DD4hep/Detector.h>
0017 #include <DD4hep/Volumes.h>
0018
0019 namespace ActsExamples {
0020
0021 DD4hepPodioConversionHelper::DD4hepPodioConversionHelper(
0022 const DD4hepDetector& detector,
0023 const ActsPodioEdm::TrackerHitLocalCollection& trackerHitLocalCollection)
0024 : m_detector(&detector),
0025 m_trackerHitLocalCollection(&trackerHitLocalCollection) {}
0026
0027 std::optional<ActsPlugins::PodioUtil::Identifier>
0028 DD4hepPodioConversionHelper::surfaceToIdentifier(
0029 const Acts::Surface& surface) const {
0030 const auto* detElement =
0031 dynamic_cast<const ActsPlugins::DD4hepDetectorElement*>(
0032 surface.surfacePlacement());
0033 if (detElement == nullptr) {
0034 return std::nullopt;
0035 }
0036
0037 return static_cast<ActsPlugins::PodioUtil::Identifier>(
0038 detElement->sourceElement().volumeID());
0039 }
0040
0041 const Acts::Surface* DD4hepPodioConversionHelper::identifierToSurface(
0042 ActsPlugins::PodioUtil::Identifier identifier) const {
0043 auto detElement =
0044 m_detector->dd4hepDetector().volumeManager().lookupDetElement(identifier);
0045 if (!detElement.isValid()) {
0046 return nullptr;
0047 }
0048
0049 auto* dd4hepDetElementExtension =
0050 detElement.extension<ActsPlugins::DD4hepDetectorElementExtension>();
0051 if (dd4hepDetElementExtension == nullptr) {
0052 return nullptr;
0053 }
0054
0055 return &dd4hepDetElementExtension->detectorElement().surface();
0056 }
0057
0058 std::optional<ActsPodioEdm::TrackerHitLocal>
0059 DD4hepPodioConversionHelper::sourceLinkToTrackerHitLocal(
0060 const Acts::SourceLink& sourceLink) const {
0061 const auto* indexSourceLink = sourceLink.getPtr<IndexSourceLink>();
0062 if (indexSourceLink == nullptr) {
0063 return std::nullopt;
0064 }
0065
0066 return m_trackerHitLocalCollection->at(indexSourceLink->index());
0067 }
0068
0069 }