Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:01:46

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
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   // This assumes that the conversion was index preserving!
0066   return m_trackerHitLocalCollection->at(indexSourceLink->index());
0067 }
0068 
0069 }  // namespace ActsExamples