Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:52

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/EDM4hepMultiTrajectoryWriter.hpp"
0010 
0011 #include "ActsExamples/Io/EDM4hep/EDM4hepUtil.hpp"
0012 #include "ActsExamples/Utilities/Paths.hpp"
0013 #include "ActsExamples/Validation/TrackClassification.hpp"
0014 
0015 #include <stdexcept>
0016 
0017 #include <edm4hep/TrackCollection.h>
0018 #include <podio/Frame.h>
0019 
0020 namespace ActsExamples {
0021 
0022 EDM4hepMultiTrajectoryWriter::EDM4hepMultiTrajectoryWriter(
0023     const EDM4hepMultiTrajectoryWriter::Config& config,
0024     Acts::Logging::Level level)
0025     : WriterT<TrajectoriesContainer>(config.inputTrajectories,
0026                                      "EDM4hepMultiTrajectoryWriter", level),
0027       m_cfg(config),
0028       m_writer(config.outputPath) {
0029   if (m_cfg.inputTrajectories.empty()) {
0030     throw std::invalid_argument("Missing input trajectories collection");
0031   }
0032 
0033   if (m_cfg.inputMeasurementParticlesMap.empty()) {
0034     throw std::invalid_argument{"Missing input hit to particle map"};
0035   }
0036 
0037   m_inputMeasurementParticlesMap.initialize(m_cfg.inputMeasurementParticlesMap);
0038 }
0039 
0040 ActsExamples::ProcessCode EDM4hepMultiTrajectoryWriter::finalize() {
0041   m_writer.finish();
0042 
0043   return ProcessCode::SUCCESS;
0044 }
0045 
0046 ProcessCode EDM4hepMultiTrajectoryWriter::writeT(
0047     const AlgorithmContext& context,
0048     const TrajectoriesContainer& trajectories) {
0049   podio::Frame frame{};
0050 
0051   const auto& hitParticlesMap = m_inputMeasurementParticlesMap(context);
0052 
0053   edm4hep::TrackCollection trackCollection;
0054 
0055   for (const auto& from : trajectories) {
0056     for (const auto& trackTip : from.tips()) {
0057       auto to = trackCollection.create();
0058       EDM4hepUtil::writeTrajectory(context.geoContext, m_cfg.Bz, from, to,
0059                                    trackTip, m_cfg.particleHypothesis,
0060                                    hitParticlesMap);
0061     }
0062   }
0063 
0064   frame.put(std::move(trackCollection), "ActsTracks");
0065 
0066   std::lock_guard guard(m_writeMutex);
0067   m_writer.writeFrame(frame, "events");
0068 
0069   return ProcessCode::SUCCESS;
0070 }
0071 
0072 }  // namespace ActsExamples