Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-05-15 07:57:13

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