Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-03 07:48:11

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/EDM4hepMeasurementOutputConverter.hpp"
0010 
0011 #include "ActsExamples/EventData/Measurement.hpp"
0012 #include "ActsExamples/Io/EDM4hep/EDM4hepUtil.hpp"
0013 #include "ActsPlugins/EDM4hep/TrackerHitCompatibility.hpp"
0014 #include <ActsPodioEdm/TrackerHitLocalCollection.h>
0015 
0016 #include <stdexcept>
0017 
0018 #include <edm4hep/TrackerHitPlane.h>
0019 #include <edm4hep/TrackerHitPlaneCollection.h>
0020 #include <podio/Frame.h>
0021 
0022 namespace ActsExamples {
0023 
0024 EDM4hepMeasurementOutputConverter::EDM4hepMeasurementOutputConverter(
0025     const EDM4hepMeasurementOutputConverter::Config& config,
0026     std::unique_ptr<const Acts::Logger> logger)
0027     : PodioOutputConverter("EDM4hepMeasurementOutputConverter",
0028                            std::move(logger)),
0029       m_cfg(config) {
0030   if (m_cfg.trackingGeometry == nullptr) {
0031     throw std::runtime_error(
0032         "EDM4hepMeasurementOutputConverter: trackingGeometry is null");
0033   }
0034 
0035   m_inputMeasurements.initialize(m_cfg.inputMeasurements);
0036   m_outputTrackerHitsLocal.initialize(m_cfg.outputTrackerHitsLocal);
0037 }
0038 
0039 ProcessCode EDM4hepMeasurementOutputConverter::execute(
0040     const AlgorithmContext& ctx) const {
0041   ActsPodioEdm::TrackerHitLocalCollection hits;
0042 
0043   const auto measurements = m_inputMeasurements(ctx);
0044 
0045   ACTS_VERBOSE("Writing " << measurements.size()
0046                           << " measurements in this event.");
0047 
0048   for (Index hitIdx = 0u; hitIdx < measurements.size(); ++hitIdx) {
0049     ConstVariableBoundMeasurementProxy from =
0050         measurements.getMeasurement(hitIdx);
0051 
0052     const Acts::Surface* surface =
0053         m_cfg.trackingGeometry->findSurface(from.geometryId());
0054     if (surface == nullptr) {
0055       throw std::runtime_error(
0056           "EDM4hepMeasurementOutputConverter: surface not found for geometry "
0057           "id " +
0058           std::to_string(from.geometryId().value()));
0059     }
0060 
0061     auto to = hits.create();
0062     EDM4hepUtil::writeMeasurement(ctx.geoContext, from, to, *surface);
0063   }
0064 
0065   m_outputTrackerHitsLocal(ctx, std::move(hits));
0066 
0067   return ProcessCode::SUCCESS;
0068 }
0069 
0070 std::vector<std::string> EDM4hepMeasurementOutputConverter::collections()
0071     const {
0072   return {m_cfg.outputTrackerHitsLocal};
0073 }
0074 
0075 }  // namespace ActsExamples