File indexing completed on 2025-11-29 09:18:22
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/Podio/PodioMeasurementInputConverter.hpp"
0010
0011 #include "Acts/Geometry/GeometryIdentifier.hpp"
0012 #include "ActsExamples/EventData/Index.hpp"
0013 #include "ActsPodioEdm/MeasurementCollection.h"
0014
0015 #include <podio/Frame.h>
0016
0017 namespace ActsExamples {
0018
0019 PodioMeasurementInputConverter::PodioMeasurementInputConverter(
0020 const Config& config, Acts::Logging::Level level)
0021 : PodioInputConverter{"PodioMeasurementInputConverter", level,
0022 config.inputFrame},
0023 m_cfg(config) {
0024 if (m_cfg.inputMeasurements.empty()) {
0025 throw std::invalid_argument(
0026 "PodioMeasurementInputConverter: "
0027 "inputMeasurements is not set");
0028 }
0029
0030 m_outputMeasurements.initialize(m_cfg.outputMeasurements);
0031
0032 m_outputMeasurementParticlesMap.initialize(
0033 m_cfg.outputMeasurementParticlesMap);
0034 m_outputParticleMeasurementsMap.initialize(
0035 m_cfg.outputParticleMeasurementsMap);
0036
0037 m_outputMeasurementSimHitsMap.initialize(m_cfg.outputMeasurementSimHitsMap);
0038 m_outputSimHitMeasurementsMap.initialize(m_cfg.outputSimHitMeasurementsMap);
0039
0040 m_inputSimHits.initialize(m_cfg.inputSimHits);
0041 m_inputSimHitAssociation.initialize(m_cfg.inputSimHitAssociation);
0042 }
0043
0044 ProcessCode PodioMeasurementInputConverter::convert(
0045 const AlgorithmContext& ctx, const podio::Frame& frame) const {
0046 const auto& inputMeasurements =
0047 frame.get<ActsPodioEdm::MeasurementCollection>(m_cfg.inputMeasurements);
0048
0049 ACTS_DEBUG("Read " << inputMeasurements.size() << " measurements from PODIO");
0050
0051 MeasurementContainer outputMeasurements;
0052
0053 const auto& simHits = m_inputSimHits(ctx);
0054 const auto& simHitAssociations = m_inputSimHitAssociation(ctx);
0055
0056 IndexMultimap<SimBarcode> measurementToParticles;
0057 measurementToParticles.reserve(inputMeasurements.size());
0058 IndexMultimap<Index> measurementToSimHits;
0059 measurementToParticles.reserve(inputMeasurements.size());
0060
0061 for (const auto& inputMeas : inputMeasurements) {
0062 std::size_t index = outputMeasurements.addMeasurement(
0063 inputMeas.size(), Acts::GeometryIdentifier{inputMeas.getGeometryId()});
0064
0065 auto meas = outputMeasurements.at(index);
0066
0067 std::copy(inputMeas.parameterValues_begin(),
0068 inputMeas.parameterValues_end(), meas.parameters().begin());
0069
0070 std::span<double> cov{meas.covariance().data(), meas.size() * meas.size()};
0071
0072 std::copy(inputMeas.covarianceValues_begin(),
0073 inputMeas.covarianceValues_end(), cov.begin());
0074
0075 meas.setSubspaceIndices(inputMeas.getIndices());
0076
0077
0078
0079 const auto& externalSimHit = inputMeas.getSimHit();
0080
0081 auto simHitIdx = simHitAssociations.lookup(externalSimHit);
0082 auto internalSimHitIt = simHits.nth(simHitIdx);
0083 if (internalSimHitIt == simHits.end()) {
0084 throw std::invalid_argument("Invalid sim hit index");
0085 }
0086 const auto& internalSimHit = *internalSimHitIt;
0087
0088 ACTS_VERBOSE("Hit lookup ext -> int "
0089 << externalSimHit.id() << " -> " << "#" << simHitIdx << " ("
0090 << simHitIdx << ") " << internalSimHit.position().transpose());
0091
0092 measurementToSimHits.emplace_hint(measurementToSimHits.end(), index,
0093 simHitIdx);
0094 measurementToParticles.emplace_hint(measurementToParticles.end(), index,
0095 internalSimHit.particleId());
0096 }
0097
0098 m_outputMeasurements(ctx, std::move(outputMeasurements));
0099
0100 m_outputParticleMeasurementsMap(ctx,
0101 invertIndexMultimap(measurementToParticles));
0102 m_outputMeasurementParticlesMap(ctx, std::move(measurementToParticles));
0103
0104 m_outputSimHitMeasurementsMap(ctx, invertIndexMultimap(measurementToSimHits));
0105 m_outputMeasurementSimHitsMap(ctx, std::move(measurementToSimHits));
0106
0107 return ProcessCode::SUCCESS;
0108 }
0109
0110 }