File indexing completed on 2026-09-15 08:20:25
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/EDM4hep/EDM4hepMeasurementInputConverter.hpp"
0010
0011 #include "ActsExamples/DD4hepDetector/DD4hepDetector.hpp"
0012 #include "ActsExamples/EventData/Cluster.hpp"
0013 #include "ActsExamples/EventData/Measurement.hpp"
0014 #include "ActsExamples/Io/EDM4hep/EDM4hepUtil.hpp"
0015 #include "ActsPlugins/DD4hep/DD4hepDetectorElement.hpp"
0016 #include <ActsPodioEdm/TrackerHitLocalCollection.h>
0017
0018 #include <stdexcept>
0019
0020 #include <DD4hep/Detector.h>
0021 #include <podio/Frame.h>
0022
0023 namespace ActsExamples {
0024
0025 EDM4hepMeasurementInputConverter::EDM4hepMeasurementInputConverter(
0026 const EDM4hepMeasurementInputConverter::Config& config,
0027 std::unique_ptr<const Acts::Logger> logger)
0028 : PodioInputConverter("EDM4hepMeasurementInputConverter", config.inputFrame,
0029 std::move(logger)),
0030 m_cfg(config) {
0031 if (m_cfg.outputMeasurements.empty()) {
0032 throw std::invalid_argument("Missing measurement output collection");
0033 }
0034 const bool hasDetector = m_cfg.dd4hepDetector != nullptr;
0035 const bool hasMapper = static_cast<bool>(m_cfg.geometryMapper);
0036 if (hasDetector == hasMapper) {
0037 throw std::invalid_argument(
0038 "EDM4hepMeasurementInputConverter: exactly one of dd4hepDetector or "
0039 "geometryMapper must be set");
0040 }
0041
0042 m_outputMeasurements.initialize(m_cfg.outputMeasurements);
0043 m_outputMeasurementSimHitsMap.initialize(m_cfg.outputMeasurementSimHitsMap);
0044 m_outputClusters.maybeInitialize(m_cfg.outputClusters);
0045
0046 if (hasMapper) {
0047 m_geometryMapper = m_cfg.geometryMapper;
0048 } else {
0049 m_geometryMapper = [detector = m_cfg.dd4hepDetector](std::uint64_t cellId) {
0050 const auto& vm = detector->dd4hepDetector().volumeManager();
0051 const auto detElement = vm.lookupDetElement(cellId);
0052
0053 const auto* ext =
0054 detElement.extension<ActsPlugins::DD4hepDetectorElementExtension>(
0055 false);
0056 if (ext == nullptr) {
0057 throw std::runtime_error(
0058 "EDM4hepMeasurementInputConverter: DetElement has no "
0059 "DD4hepDetectorElementExtension for cellId " +
0060 std::to_string(cellId));
0061 }
0062 return ext->detectorElement().surface().geometryId();
0063 };
0064 }
0065 }
0066
0067 ProcessCode EDM4hepMeasurementInputConverter::convert(
0068 const AlgorithmContext& ctx, const podio::Frame& frame) const {
0069 MeasurementContainer measurements;
0070 ClusterContainer clusters;
0071 MeasurementSimHitsMap measurementSimHitsMap;
0072
0073 const auto& trackerHitLocalCollection =
0074 frame.get<ActsPodioEdm::TrackerHitLocalCollection>(
0075 m_cfg.inputTrackerHitsLocal);
0076
0077 for (const auto& trackerHitLocal : trackerHitLocalCollection) {
0078 EDM4hepUtil::readMeasurement(measurements, trackerHitLocal,
0079 m_geometryMapper);
0080 }
0081
0082 m_outputMeasurements(ctx, std::move(measurements));
0083 m_outputMeasurementSimHitsMap(ctx, std::move(measurementSimHitsMap));
0084 if (!m_cfg.outputClusters.empty()) {
0085 m_outputClusters(ctx, std::move(clusters));
0086 }
0087
0088 return ProcessCode::SUCCESS;
0089 }
0090
0091 }