ECCE @ EIC 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 
11 #include <Acts/Utilities/Units.hpp>
12 #include <dfe/dfe_io_dsv.hpp>
13 #include <fstream>
14 #include <ios>
15 #include <stdexcept>
16 #include <string>
17 #include <vector>
18 
22 #include "TrackMlData.hpp"
23 
26  : m_cfg(cfg),
27  m_eventsRange(
28  determineEventFilesRange(cfg.inputDir, cfg.inputStem + ".csv")),
29  m_logger(Acts::getDefaultLogger("CsvParticleReader", lvl)) {
30  if (m_cfg.inputStem.empty()) {
31  throw std::invalid_argument("Missing input filename stem");
32  }
33  if (m_cfg.outputParticles.empty()) {
34  throw std::invalid_argument("Missing output collection");
35  }
36 }
37 
39  return "CsvParticleReader";
40 }
41 
42 std::pair<size_t, size_t> FW::CsvParticleReader::availableEvents() const {
43  return m_eventsRange;
44 }
45 
47  SimParticleContainer::sequence_type unordered;
48 
49  auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
50  ctx.eventNumber);
51  // vt and m are an optional columns
52  dfe::NamedTupleCsvReader<ParticleData> reader(path, {"vt", "m"});
54 
55  while (reader.read(data)) {
57  Acts::PdgParticle(data.particle_type),
58  data.q * Acts::UnitConstants::e,
59  data.m * Acts::UnitConstants::GeV);
60  particle.setProcess(static_cast<ActsFatras::ProcessType>(data.process));
61  particle.setPosition4(
64  // only used for direction; normalization/units do not matter
65  particle.setDirection(data.px, data.py, data.pz);
66  particle.setAbsMomentum(std::hypot(data.px, data.py, data.pz) *
68  unordered.push_back(std::move(particle));
69  }
70 
71  // write ordered particles container to the EventStore
72  SimParticleContainer particles;
73  particles.adopt_sequence(std::move(unordered));
74  ctx.eventStore.add(m_cfg.outputParticles, std::move(particles));
75 
76  return ProcessCode::SUCCESS;
77 }