Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CsvParticleReader.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CsvParticleReader.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017 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 
20 
21 #include <array>
22 #include <cmath>
23 #include <stdexcept>
24 #include <string>
25 
26 #include <dfe/dfe_io_dsv.hpp>
27 
28 #include "CsvOutputData.hpp"
29 
33  : m_cfg(config),
34  m_eventsRange(
35  determineEventFilesRange(m_cfg.inputDir, m_cfg.inputStem + ".csv")),
36  m_logger(Acts::getDefaultLogger("CsvParticleReader", level)) {
37  if (m_cfg.inputStem.empty()) {
38  throw std::invalid_argument("Missing input filename stem");
39  }
40  if (m_cfg.outputParticles.empty()) {
41  throw std::invalid_argument("Missing output collection");
42  }
43 
45 }
46 
48  return "CsvParticleReader";
49 }
50 
52  const {
53  return m_eventsRange;
54 }
55 
57  const ActsExamples::AlgorithmContext& ctx) {
58  SimParticleContainer::sequence_type unordered;
59 
60  auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
61  ctx.eventNumber);
62  // vt and m are an optional columns
63  dfe::NamedTupleCsvReader<ParticleData> reader(path, {"vt", "m"});
65 
66  while (reader.read(data)) {
68  Acts::PdgParticle(data.particle_type),
69  data.q * Acts::UnitConstants::e,
70  data.m * Acts::UnitConstants::GeV);
71  particle.setProcess(static_cast<ActsFatras::ProcessType>(data.process));
72  particle.setPosition4(
75  // Only used for direction; normalization/units do not matter
76  particle.setDirection(data.px, data.py, data.pz);
77  particle.setAbsoluteMomentum(std::hypot(data.px, data.py, data.pz) *
79  unordered.push_back(std::move(particle));
80  }
81 
82  // Write ordered particles container to the EventStore
84  particles.insert(unordered.begin(), unordered.end());
85  m_outputParticles(ctx, std::move(particles));
86 
87  return ProcessCode::SUCCESS;
88 }