Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-29 09:18:22

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/Podio/PodioMeasurementOutputConverter.hpp"
0010 
0011 #include "ActsExamples/EventData/Measurement.hpp"
0012 #include "ActsExamples/Io/Podio/PodioOutputConverter.hpp"
0013 #include "ActsPodioEdm/MeasurementCollection.h"
0014 
0015 #include <cstdint>
0016 
0017 #include <podio/CollectionBase.h>
0018 
0019 namespace ActsExamples {
0020 
0021 PodioMeasurementOutputConverter::PodioMeasurementOutputConverter(
0022     const Config& config, Acts::Logging::Level level)
0023     : PodioOutputConverter{"PodioMeasurementOutputConverter", level},
0024       m_cfg{config} {
0025   m_inputMeasurements.initialize(m_cfg.inputMeasurements);
0026   m_outputMeasurements.initialize(m_cfg.outputMeasurements);
0027 
0028   if (m_cfg.inputSimHitAssociation.has_value() !=
0029       m_cfg.inputMeasurementSimHitsMap.has_value()) {
0030     throw std::invalid_argument(
0031         "PodioMeasurementOutputConverter: inputSimHitAssociation and "
0032         "inputMeasurementSimHitsMap must be both set or both unset");
0033   }
0034 
0035   m_inputSimHitAssociation.maybeInitialize(m_cfg.inputSimHitAssociation);
0036   m_inputMeasurementSimHitsMap.maybeInitialize(
0037       m_cfg.inputMeasurementSimHitsMap);
0038 }
0039 
0040 ProcessCode PodioMeasurementOutputConverter::execute(
0041     const AlgorithmContext& context) const {
0042   const auto& measurements = m_inputMeasurements(context);
0043 
0044   const auto& measToSimHits = m_inputMeasurementSimHitsMap(context);
0045   // Map internal sim hits to edm4hep input sim hits
0046   const auto& simHitAssociation = m_inputSimHitAssociation(context);
0047 
0048   auto outputMeasurements =
0049       std::make_unique<ActsPodioEdm::MeasurementCollection>();
0050 
0051   for (const MeasurementContainer::ConstVariableProxy& meas : measurements) {
0052     auto to = outputMeasurements->create();
0053     for (const auto val : meas.subspaceIndexVector()) {
0054       to.addToIndices(static_cast<std::uint16_t>(val));
0055     }
0056 
0057     for (const double val : meas.parameters()) {
0058       to.addToParameterValues(val);
0059     }
0060 
0061     std::span<const double> cov{meas.covariance().data(),
0062                                 meas.size() * meas.size()};
0063 
0064     for (const double val : cov) {
0065       to.addToCovarianceValues(val);
0066     }
0067 
0068     to.setGeometryId(meas.geometryId().value());
0069 
0070     throw_assert(to.size() == meas.size(), "Invalid sizes after filling");
0071 
0072     // Get the sim hit associated with this measurement
0073     const auto simHitIt = measToSimHits.find(meas.index());
0074     if (simHitIt == measToSimHits.end()) {
0075       ACTS_ERROR("No sim hit found for measurement index " << meas.index());
0076       return ProcessCode::ABORT;
0077     }
0078 
0079     // Get the edm4hep input sim hit from the internal index
0080     const auto& sourceHit = simHitAssociation.lookup(simHitIt->second);
0081     to.setSimHit(sourceHit);
0082   }
0083 
0084   m_outputMeasurements(context, std::move(outputMeasurements));
0085 
0086   return ProcessCode::SUCCESS;
0087 }
0088 
0089 std::vector<std::string> PodioMeasurementOutputConverter::collections() const {
0090   return {m_cfg.outputMeasurements};
0091 }
0092 
0093 }  // namespace ActsExamples