Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:23:51

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, Acts::Logging::Level lvl)
0023     : PodioOutputConverter("EDM4hepParticleOutputConverter", lvl), m_cfg(cfg) {
0024   if (m_cfg.inputParticles.empty()) {
0025     throw std::invalid_argument("Missing particles input collection");
0026   }
0027 
0028   if (m_cfg.outputParticles.empty()) {
0029     throw std::invalid_argument("Missing particles output collection");
0030   }
0031 
0032   m_inputParticles.initialize(m_cfg.inputParticles);
0033   m_outputParticles.initialize(m_cfg.outputParticles);
0034 }
0035 
0036 ProcessCode EDM4hepParticleOutputConverter::execute(
0037     const AlgorithmContext& ctx) const {
0038   const SimParticleContainer particles = m_inputParticles(ctx);
0039 
0040   edm4hep::MCParticleCollection mcParticleCollection;
0041 
0042   for (const auto& particle : particles) {
0043     auto p = mcParticleCollection.create();
0044     EDM4hepUtil::writeParticle(particle, p);
0045   }
0046 
0047   m_outputParticles(ctx, std::move(mcParticleCollection));
0048 
0049   return ProcessCode::SUCCESS;
0050 }
0051 
0052 std::vector<std::string> EDM4hepParticleOutputConverter::collections() const {
0053   return {m_cfg.outputParticles};
0054 }
0055 
0056 }  // namespace ActsExamples