Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-14 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/EDM4hepParticleOutputConverter.hpp"
0010 
0011 #include "ActsExamples/Io/EDM4hep/EDM4hepUtil.hpp"
0012 
0013 #include <stdexcept>
0014 
0015 #include <edm4hep/MCParticle.h>
0016 #include <edm4hep/MCParticleCollection.h>
0017 #include <podio/Frame.h>
0018 
0019 namespace ActsExamples {
0020 
0021 EDM4hepParticleOutputConverter::EDM4hepParticleOutputConverter(
0022     const EDM4hepParticleOutputConverter::Config& cfg,
0023     std::unique_ptr<const Acts::Logger> logger)
0024     : PodioOutputConverter("EDM4hepParticleOutputConverter", std::move(logger)),
0025       m_cfg(cfg) {
0026   if (m_cfg.inputParticles.empty()) {
0027     throw std::invalid_argument("Missing particles input collection");
0028   }
0029 
0030   if (m_cfg.outputParticles.empty()) {
0031     throw std::invalid_argument("Missing particles output collection");
0032   }
0033 
0034   m_inputParticles.initialize(m_cfg.inputParticles);
0035   m_outputParticles.initialize(m_cfg.outputParticles);
0036 }
0037 
0038 ProcessCode EDM4hepParticleOutputConverter::execute(
0039     const AlgorithmContext& ctx) const {
0040   const SimParticleContainer particles = m_inputParticles(ctx);
0041 
0042   edm4hep::MCParticleCollection mcParticleCollection;
0043 
0044   for (const auto& particle : particles) {
0045     auto p = mcParticleCollection.create();
0046     EDM4hepUtil::writeParticle(particle, p);
0047   }
0048 
0049   m_outputParticles(ctx, std::move(mcParticleCollection));
0050 
0051   return ProcessCode::SUCCESS;
0052 }
0053 
0054 std::vector<std::string> EDM4hepParticleOutputConverter::collections() const {
0055   return {m_cfg.outputParticles};
0056 }
0057 
0058 }  // namespace ActsExamples