File indexing completed on 2025-01-18 09:11:50
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/Csv/CsvMuonSimHitReader.hpp"
0010
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Geometry/GeometryIdentifier.hpp"
0013 #include "ActsExamples/EventData/MuonSimHit.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::CsvMuonSimHitReader::CsvMuonSimHitReader(
0026 const ActsExamples::CsvMuonSimHitReader::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("CsvMuonSimHitReader", 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::CsvMuonSimHitReader::CsvMuonSimHitReader::name()
0044 const {
0045 return "CsvMuonSimHitReader";
0046 }
0047
0048 std::pair<std::size_t, std::size_t>
0049 ActsExamples::CsvMuonSimHitReader::availableEvents() const {
0050 return m_eventsRange;
0051 }
0052
0053 ActsExamples::ProcessCode ActsExamples::CsvMuonSimHitReader::read(
0054 const ActsExamples::AlgorithmContext& ctx) {
0055 auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
0056 ctx.eventNumber);
0057
0058 ActsExamples::NamedTupleCsvReader<MuonSimHitData> reader(path);
0059
0060 MuonSimHitData data;
0061
0062 SimHitContainer::sequence_type unordered;
0063 while (reader.read(data)) {
0064 Acts::Vector4 pos{data.LocalPositionExtrx * Acts::UnitConstants::mm,
0065 data.LocalPositionExtry * Acts::UnitConstants::mm,
0066 data.LocalPositionExtrz * Acts::UnitConstants::mm, 0};
0067 Acts::Vector4 mom{data.LocalDirectionx * Acts::UnitConstants::GeV,
0068 data.LocalDirectiony * Acts::UnitConstants::GeV,
0069 data.LocalDirectionz * Acts::UnitConstants::GeV,
0070 std::sqrt(data.LocalDirectionx * data.LocalDirectionx +
0071 data.LocalDirectiony * data.LocalDirectiony +
0072 data.LocalDirectionz * data.LocalDirectionz) *
0073 Acts::UnitConstants::GeV};
0074 MuonMdtIdentifierFields f;
0075 f.multilayer = 0;
0076 f.tube = 0;
0077 f.tubeLayer = 0;
0078 f.stationEta = data.StationEta;
0079 f.stationPhi = data.StationPhi;
0080 f.stationName = data.StationName;
0081
0082 unordered.push_back(SimHit(compressId(f), data.pdgId, pos, mom, mom, -1));
0083 }
0084 SimHitContainer simHits;
0085 simHits.insert(unordered.begin(), unordered.end());
0086
0087
0088 m_outputSimHits(ctx, std::move(simHits));
0089
0090 return ActsExamples::ProcessCode::SUCCESS;
0091 }