File indexing completed on 2025-01-18 09:11:51
0001
0002
0003
0004
0005
0006
0007
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/Particle.hpp"
0020 #include "ActsFatras/EventData/ProcessType.hpp"
0021
0022 #include <array>
0023 #include <cmath>
0024 #include <stdexcept>
0025 #include <string>
0026
0027 #include "CsvOutputData.hpp"
0028
0029 ActsExamples::CsvParticleReader::CsvParticleReader(
0030 const ActsExamples::CsvParticleReader::Config& config,
0031 Acts::Logging::Level level)
0032 : m_cfg(config),
0033 m_eventsRange(
0034 determineEventFilesRange(m_cfg.inputDir, m_cfg.inputStem + ".csv")),
0035 m_logger(Acts::getDefaultLogger("CsvParticleReader", level)) {
0036 if (m_cfg.inputStem.empty()) {
0037 throw std::invalid_argument("Missing input filename stem");
0038 }
0039 if (m_cfg.outputParticles.empty()) {
0040 throw std::invalid_argument("Missing output collection");
0041 }
0042
0043 m_outputParticles.initialize(m_cfg.outputParticles);
0044 }
0045
0046 std::string ActsExamples::CsvParticleReader::CsvParticleReader::name() const {
0047 return "CsvParticleReader";
0048 }
0049
0050 std::pair<std::size_t, std::size_t>
0051 ActsExamples::CsvParticleReader::availableEvents() const {
0052 return m_eventsRange;
0053 }
0054
0055 ActsExamples::ProcessCode ActsExamples::CsvParticleReader::read(
0056 const ActsExamples::AlgorithmContext& ctx) {
0057 SimParticleContainer::sequence_type unordered;
0058
0059 auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
0060 ctx.eventNumber);
0061
0062 ActsExamples::NamedTupleCsvReader<ParticleData> reader(path, {"vt", "m"});
0063 ParticleData data;
0064
0065 while (reader.read(data)) {
0066 SimParticleState particle(ActsFatras::Barcode(data.particle_id),
0067 Acts::PdgParticle{data.particle_type},
0068 data.q * Acts::UnitConstants::e,
0069 data.m * Acts::UnitConstants::GeV);
0070 particle.setProcess(static_cast<ActsFatras::ProcessType>(data.process));
0071 particle.setPosition4(
0072 data.vx * Acts::UnitConstants::mm, data.vy * Acts::UnitConstants::mm,
0073 data.vz * Acts::UnitConstants::mm, data.vt * Acts::UnitConstants::mm);
0074
0075 particle.setDirection(data.px, data.py, data.pz);
0076 particle.setAbsoluteMomentum(std::hypot(data.px, data.py, data.pz) *
0077 Acts::UnitConstants::GeV);
0078 unordered.push_back(SimParticle(particle, particle));
0079 }
0080
0081
0082 SimParticleContainer particles;
0083 particles.insert(unordered.begin(), unordered.end());
0084 m_outputParticles(ctx, std::move(particles));
0085
0086 return ProcessCode::SUCCESS;
0087 }