Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-11 08:21:39

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/Csv/CsvParticleReader.hpp"
0010 
0011 #include "Acts/Definitions/PdgParticle.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/Utilities/Logger.hpp"
0014 #include "ActsExamples/EventData/SimParticle.hpp"
0015 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0016 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0017 #include "ActsExamples/Utilities/Paths.hpp"
0018 #include "ActsFatras/EventData/Barcode.hpp"
0019 #include "ActsFatras/EventData/GenerationProcess.hpp"
0020 
0021 #include <cmath>
0022 #include <stdexcept>
0023 #include <string>
0024 
0025 #include "CsvOutputData.hpp"
0026 
0027 namespace ActsExamples {
0028 
0029 CsvParticleReader::CsvParticleReader(const Config& config,
0030                                      Acts::Logging::Level level)
0031     : m_cfg(config),
0032       m_eventsRange(
0033           determineEventFilesRange(m_cfg.inputDir, m_cfg.inputStem + ".csv")),
0034       m_logger(Acts::getDefaultLogger("CsvParticleReader", level)) {
0035   if (m_cfg.inputStem.empty()) {
0036     throw std::invalid_argument("Missing input filename stem");
0037   }
0038   if (m_cfg.outputParticles.empty()) {
0039     throw std::invalid_argument("Missing output collection");
0040   }
0041 
0042   m_outputParticles.initialize(m_cfg.outputParticles);
0043 }
0044 
0045 std::string CsvParticleReader::name() const {
0046   return "CsvParticleReader";
0047 }
0048 
0049 std::pair<std::size_t, std::size_t> CsvParticleReader::availableEvents() const {
0050   return m_eventsRange;
0051 }
0052 
0053 ProcessCode CsvParticleReader::read(const AlgorithmContext& ctx) {
0054   SimParticleContainer::sequence_type unordered;
0055 
0056   auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
0057                                ctx.eventNumber);
0058   // vt and m are an optional columns
0059   BoostDescribeCsvReader<ParticleData> reader(path, {"vt", "m"});
0060   ParticleData data;
0061 
0062   while (reader.read(data)) {
0063     SimParticleState particle(SimBarcode()
0064                                   .withVertexPrimary(data.particle_id_pv)
0065                                   .withVertexSecondary(data.particle_id_sv)
0066                                   .withParticle(data.particle_id_part)
0067                                   .withGeneration(data.particle_id_gen)
0068                                   .withSubParticle(data.particle_id_subpart),
0069                               Acts::PdgParticle{data.particle_type},
0070                               data.q * Acts::UnitConstants::e,
0071                               data.m * Acts::UnitConstants::GeV);
0072     particle.setProcess(
0073         static_cast<ActsFatras::GenerationProcess>(data.process));
0074     particle.setPosition4(
0075         data.vx * Acts::UnitConstants::mm, data.vy * Acts::UnitConstants::mm,
0076         data.vz * Acts::UnitConstants::mm, data.vt * Acts::UnitConstants::mm);
0077     // Only used for direction; normalization/units do not matter
0078     particle.setDirection(data.px, data.py, data.pz);
0079     particle.setAbsoluteMomentum(std::hypot(data.px, data.py, data.pz) *
0080                                  Acts::UnitConstants::GeV);
0081     unordered.push_back(SimParticle(particle, particle));
0082   }
0083 
0084   // Write ordered particles container to the EventStore
0085   SimParticleContainer particles;
0086   particles.insert(unordered.begin(), unordered.end());
0087   m_outputParticles(ctx, std::move(particles));
0088 
0089   return ProcessCode::SUCCESS;
0090 }
0091 
0092 }  // namespace ActsExamples