ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CsvParticleWriter.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CsvParticleWriter.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
11 #include <Acts/Utilities/Units.hpp>
12 #include <dfe/dfe_io_dsv.hpp>
13 #include <map>
14 #include <stdexcept>
15 
18 #include "TrackMlData.hpp"
19 
22  : WriterT(cfg.inputParticles, "CsvParticleWriter", lvl), m_cfg(cfg) {
23  // inputParticles is already checked by base constructor
24  if (m_cfg.outputStem.empty()) {
25  throw std::invalid_argument("Missing ouput filename stem");
26  }
27 }
28 
30  const FW::AlgorithmContext& ctx, const SimParticleContainer& particles) {
31  auto pathParticles = perEventFilepath(
32  m_cfg.outputDir, m_cfg.outputStem + ".csv", ctx.eventNumber);
33  dfe::NamedTupleCsvWriter<ParticleData> writer(pathParticles,
34  m_cfg.outputPrecision);
35 
37  for (const auto& particle : particles) {
38  data.particle_id = particle.particleId().value();
39  data.particle_type = particle.pdg();
40  data.process = static_cast<decltype(data.process)>(particle.process());
41  data.vx = particle.position().x() / Acts::UnitConstants::mm;
42  data.vy = particle.position().y() / Acts::UnitConstants::mm;
43  data.vz = particle.position().z() / Acts::UnitConstants::mm;
44  data.vt = particle.time() / Acts::UnitConstants::ns;
45  const auto p = particle.absMomentum() / Acts::UnitConstants::GeV;
46  data.px = p * particle.unitDirection().x();
47  data.py = p * particle.unitDirection().y();
48  data.pz = p * particle.unitDirection().z();
49  data.m = particle.mass() / Acts::UnitConstants::GeV;
50  data.q = particle.charge() / Acts::UnitConstants::e;
51  writer.append(data);
52  }
53 
54  return ProcessCode::SUCCESS;
55 }