File indexing completed on 2025-01-18 09:11:51
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/Csv/CsvSimHitReader.hpp"
0010
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Geometry/GeometryIdentifier.hpp"
0013 #include "ActsExamples/EventData/SimHit.hpp"
0014 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0015 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0016 #include "ActsExamples/Utilities/Paths.hpp"
0017 #include "ActsFatras/EventData/Barcode.hpp"
0018 #include "ActsFatras/EventData/Hit.hpp"
0019
0020 #include <array>
0021 #include <stdexcept>
0022
0023 #include "CsvOutputData.hpp"
0024
0025 ActsExamples::CsvSimHitReader::CsvSimHitReader(
0026 const ActsExamples::CsvSimHitReader::Config& config,
0027 Acts::Logging::Level level)
0028 : m_cfg(config),
0029
0030 m_eventsRange(
0031 determineEventFilesRange(m_cfg.inputDir, m_cfg.inputStem + ".csv")),
0032 m_logger(Acts::getDefaultLogger("CsvSimHitReader", level)) {
0033 if (m_cfg.inputStem.empty()) {
0034 throw std::invalid_argument("Missing input filename stem");
0035 }
0036 if (m_cfg.outputSimHits.empty()) {
0037 throw std::invalid_argument("Missing simulated hits output collection");
0038 }
0039
0040 m_outputSimHits.initialize(m_cfg.outputSimHits);
0041 }
0042
0043 std::string ActsExamples::CsvSimHitReader::CsvSimHitReader::name() const {
0044 return "CsvSimHitReader";
0045 }
0046
0047 std::pair<std::size_t, std::size_t>
0048 ActsExamples::CsvSimHitReader::availableEvents() const {
0049 return m_eventsRange;
0050 }
0051
0052 ActsExamples::ProcessCode ActsExamples::CsvSimHitReader::read(
0053 const ActsExamples::AlgorithmContext& ctx) {
0054 auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
0055 ctx.eventNumber);
0056
0057 ActsExamples::NamedTupleCsvReader<SimHitData> reader(path);
0058
0059 SimHitContainer::sequence_type unordered;
0060 SimHitData data;
0061
0062 ACTS_DEBUG("start to read hits ");
0063 while (reader.read(data)) {
0064 ACTS_DEBUG("found a sim hit");
0065 const auto geometryId = Acts::GeometryIdentifier(data.geometry_id);
0066
0067 const auto particleId = ActsFatras::Barcode(data.particle_id);
0068
0069 Acts::Vector4 pos4{
0070 data.tx * Acts::UnitConstants::mm,
0071 data.ty * Acts::UnitConstants::mm,
0072 data.tz * Acts::UnitConstants::mm,
0073 data.tt * Acts::UnitConstants::mm,
0074 };
0075 Acts::Vector4 mom4{
0076 data.tpx * Acts::UnitConstants::GeV,
0077 data.tpy * Acts::UnitConstants::GeV,
0078 data.tpz * Acts::UnitConstants::GeV,
0079 data.te * Acts::UnitConstants::GeV,
0080 };
0081 Acts::Vector4 delta4{
0082 data.deltapx * Acts::UnitConstants::GeV,
0083 data.deltapy * Acts::UnitConstants::GeV,
0084 data.deltapz * Acts::UnitConstants::GeV,
0085 data.deltae * Acts::UnitConstants::GeV,
0086 };
0087
0088 ActsFatras::Hit hit(geometryId, particleId, pos4, mom4, mom4 + delta4,
0089 data.index);
0090 unordered.push_back(std::move(hit));
0091 }
0092
0093
0094 SimHitContainer simHits;
0095 simHits.insert(unordered.begin(), unordered.end());
0096 m_outputSimHits(ctx, std::move(simHits));
0097
0098 return ActsExamples::ProcessCode::SUCCESS;
0099 }