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 
14 #include <Acts/Utilities/Units.hpp>
15 
16 #include <fstream>
17 #include <ios>
18 #include <stdexcept>
19 #include <string>
20 #include <vector>
21 
22 #include <dfe/dfe_io_dsv.hpp>
23 
24 #include "TrackMlData.hpp"
25 
29  : m_cfg(cfg),
30  m_eventsRange(
31  determineEventFilesRange(cfg.inputDir, cfg.inputStem + ".csv")),
32  m_logger(Acts::getDefaultLogger("CsvParticleReader", lvl)) {
33  if (m_cfg.inputStem.empty()) {
34  throw std::invalid_argument("Missing input filename stem");
35  }
36  if (m_cfg.outputParticles.empty()) {
37  throw std::invalid_argument("Missing output collection");
38  }
39 }
40 
42  return "CsvParticleReader";
43 }
44 
46  const {
47  return m_eventsRange;
48 }
49 
51  const ActsExamples::AlgorithmContext& ctx) {
52  SimParticleContainer::sequence_type unordered;
53 
54  auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
55  ctx.eventNumber);
56  // vt and m are an optional columns
59 
60  while (reader.read(data)) {
62  Acts::PdgParticle(data.particle_type),
63  data.q * Acts::UnitConstants::e,
64  data.m * Acts::UnitConstants::GeV);
65  particle.setProcess(static_cast<ActsFatras::ProcessType>(data.process));
66  particle.setPosition4(
69  // only used for direction; normalization/units do not matter
70  particle.setDirection(data.px, data.py, data.pz);
71  particle.setAbsMomentum(std::hypot(data.px, data.py, data.pz) *
73  unordered.push_back(std::move(particle));
74  }
75 
76  // write ordered particles container to the EventStore
77  SimParticleContainer particles;
78  particles.adopt_sequence(std::move(unordered));
79  ctx.eventStore.add(m_cfg.outputParticles, std::move(particles));
80 
81  return ProcessCode::SUCCESS;
82 }