File indexing completed on 2025-01-18 09:11:51
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/Csv/CsvParticleWriter.hpp"
0010
0011 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0012 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0013 #include "ActsExamples/Utilities/Paths.hpp"
0014 #include "ActsFatras/EventData/Barcode.hpp"
0015 #include "ActsFatras/EventData/Particle.hpp"
0016 #include <Acts/Definitions/Units.hpp>
0017
0018 #include <stdexcept>
0019 #include <vector>
0020
0021 #include "CsvOutputData.hpp"
0022
0023 ActsExamples::CsvParticleWriter::CsvParticleWriter(
0024 const ActsExamples::CsvParticleWriter::Config& cfg,
0025 Acts::Logging::Level lvl)
0026 : WriterT(cfg.inputParticles, "CsvParticleWriter", lvl), m_cfg(cfg) {
0027
0028 if (m_cfg.outputStem.empty()) {
0029 throw std::invalid_argument("Missing output filename stem");
0030 }
0031 }
0032
0033 ActsExamples::ProcessCode ActsExamples::CsvParticleWriter::writeT(
0034 const ActsExamples::AlgorithmContext& ctx,
0035 const SimParticleContainer& particles) {
0036 auto pathParticles = perEventFilepath(
0037 m_cfg.outputDir, m_cfg.outputStem + ".csv", ctx.eventNumber);
0038 ActsExamples::NamedTupleCsvWriter<ParticleData> writer(pathParticles,
0039 m_cfg.outputPrecision);
0040
0041 ParticleData data;
0042 for (const auto& particle : particles) {
0043 data.particle_id = particle.particleId().value();
0044 data.particle_type = particle.pdg();
0045 data.process = static_cast<decltype(data.process)>(particle.process());
0046 data.vx = particle.position().x() / Acts::UnitConstants::mm;
0047 data.vy = particle.position().y() / Acts::UnitConstants::mm;
0048 data.vz = particle.position().z() / Acts::UnitConstants::mm;
0049 data.vt = particle.time() / Acts::UnitConstants::mm;
0050 const auto p = particle.absoluteMomentum() / Acts::UnitConstants::GeV;
0051 data.px = p * particle.direction().x();
0052 data.py = p * particle.direction().y();
0053 data.pz = p * particle.direction().z();
0054 data.m = particle.mass() / Acts::UnitConstants::GeV;
0055 data.q = particle.charge() / Acts::UnitConstants::e;
0056 writer.append(data);
0057 }
0058
0059 return ProcessCode::SUCCESS;
0060 }