Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CsvSimHitReader.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CsvSimHitReader.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 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 
18 
19 #include <array>
20 #include <stdexcept>
21 
22 #include <dfe/dfe_io_dsv.hpp>
23 
24 #include "CsvOutputData.hpp"
25 
29  : m_cfg(config),
30  // TODO check that all files (hits,cells,truth) exists
31  m_eventsRange(
32  determineEventFilesRange(m_cfg.inputDir, m_cfg.inputStem + ".csv")),
33  m_logger(Acts::getDefaultLogger("CsvSimHitReader", level)) {
34  if (m_cfg.inputStem.empty()) {
35  throw std::invalid_argument("Missing input filename stem");
36  }
37  if (m_cfg.outputSimHits.empty()) {
38  throw std::invalid_argument("Missing simulated hits output collection");
39  }
40 
42 }
43 
45  return "CsvSimHitReader";
46 }
47 
49  const {
50  return m_eventsRange;
51 }
52 
54  const ActsExamples::AlgorithmContext& ctx) {
55  auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
56  ctx.eventNumber);
57 
58  dfe::NamedTupleCsvReader<SimHitData> reader(path);
59 
60  SimHitContainer::sequence_type unordered;
62 
63  while (reader.read(data)) {
64  const auto geometryId = Acts::GeometryIdentifier(data.geometry_id);
65  // TODO validate geo id consistency
66  const auto particleId = ActsFatras::Barcode(data.particle_id);
67 
73  };
79  };
85  };
86 
87  ActsFatras::Hit hit(geometryId, particleId, pos4, mom4, mom4 + delta4,
88  data.index);
89  unordered.push_back(std::move(hit));
90  }
91 
92  // write the ordered data to the EventStore (according to geometry_id).
93  SimHitContainer simHits;
94  simHits.insert(unordered.begin(), unordered.end());
95  m_outputSimHits(ctx, std::move(simHits));
96 
98 }