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 
13 #include <Acts/Utilities/Units.hpp>
14 
15 #include <map>
16 #include <stdexcept>
17 
18 #include <dfe/dfe_io_dsv.hpp>
19 
20 #include "TrackMlData.hpp"
21 
25  : WriterT(cfg.inputParticles, "CsvParticleWriter", lvl), m_cfg(cfg) {
26  // inputParticles is already checked by base constructor
27  if (m_cfg.outputStem.empty()) {
28  throw std::invalid_argument("Missing ouput filename stem");
29  }
30 }
31 
34  const SimParticleContainer& particles) {
35  auto pathParticles = perEventFilepath(
36  m_cfg.outputDir, m_cfg.outputStem + ".csv", ctx.eventNumber);
37  dfe::NamedTupleCsvWriter<ParticleData> writer(pathParticles,
38  m_cfg.outputPrecision);
39 
41  for (const auto& particle : particles) {
42  data.particle_id = particle.particleId().value();
43  data.particle_type = particle.pdg();
44  data.process = static_cast<decltype(data.process)>(particle.process());
45  data.vx = particle.position().x() / Acts::UnitConstants::mm;
46  data.vy = particle.position().y() / Acts::UnitConstants::mm;
47  data.vz = particle.position().z() / Acts::UnitConstants::mm;
48  data.vt = particle.time() / Acts::UnitConstants::ns;
49  const auto p = particle.absMomentum() / Acts::UnitConstants::GeV;
50  data.px = p * particle.unitDirection().x();
51  data.py = p * particle.unitDirection().y();
52  data.pz = p * particle.unitDirection().z();
53  data.m = particle.mass() / Acts::UnitConstants::GeV;
54  data.q = particle.charge() / Acts::UnitConstants::e;
55  writer.append(data);
56  }
57 
58  return ProcessCode::SUCCESS;
59 }