File indexing completed on 2025-05-15 07:57:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/Csv/CsvMuonSegmentReader.hpp"
0010
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "ActsExamples/EventData/MuonSegment.hpp"
0013 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0014 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0015 #include "ActsExamples/Utilities/Paths.hpp"
0016 #include "ActsFatras/EventData/Barcode.hpp"
0017 #include "ActsFatras/EventData/Hit.hpp"
0018
0019 #include <bitset>
0020 #include <stdexcept>
0021
0022 #include "CsvOutputData.hpp"
0023
0024 namespace ActsExamples {
0025 CsvMuonSegmentReader::CsvMuonSegmentReader(
0026 const CsvMuonSegmentReader::Config& config, Acts::Logging::Level level)
0027 : m_cfg(config),
0028
0029 m_eventsRange(
0030 determineEventFilesRange(m_cfg.inputDir, m_cfg.inputStem + ".csv")),
0031 m_logger(Acts::getDefaultLogger("CsvMuonSegmentReader", level)) {
0032 if (m_cfg.inputStem.empty()) {
0033 throw std::invalid_argument("Missing input filename stem");
0034 }
0035 if (m_cfg.outputSegments.empty()) {
0036 throw std::invalid_argument("Missing segment collection");
0037 }
0038
0039 m_outputSegments.initialize(m_cfg.outputSegments);
0040 }
0041
0042 std::string CsvMuonSegmentReader::CsvMuonSegmentReader::name() const {
0043 return "CsvMuonSegmentReader";
0044 }
0045
0046 std::pair<std::size_t, std::size_t> CsvMuonSegmentReader::availableEvents()
0047 const {
0048 return m_eventsRange;
0049 }
0050
0051 ProcessCode CsvMuonSegmentReader::read(const AlgorithmContext& ctx) {
0052 auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
0053 ctx.eventNumber);
0054
0055 NamedTupleCsvReader<MuonSegmentData> reader(path);
0056
0057 MuonSegmentData data{};
0058
0059 MuonSegmentContainer segments{};
0060
0061 using MuonId = MuonSegment::MuonId;
0062 while (reader.read(data)) {
0063 MuonSegment& newSeg = segments.emplace_back();
0064
0065 MuonId::StationName stName{
0066 static_cast<MuonId::StationName>(0x0FF & data.sectorId)};
0067 MuonId::DetSide side{
0068 static_cast<MuonId::DetSide>(0x0FF & (data.sectorId >> 8))};
0069 const auto sector = static_cast<int>(0x0FF & (data.sectorId >> 16));
0070 MuonId id{};
0071 id.setChamber(stName, side, sector, MuonId::TechField::UnDef);
0072 ACTS_VERBOSE("Read in new segment in "
0073 << id << ", sector id: " << data.sectorId << ", "
0074 << std::bitset<32>(data.sectorId));
0075 newSeg.setId(id);
0076 newSeg.setGlobalCoords(
0077 Acts::Vector3{data.globalPositionX, data.globalPositionY,
0078 data.globalPositionZ},
0079 Acts::Vector3{data.globalDirectionX, data.globalDirectionY,
0080 data.globalDirectionZ});
0081 newSeg.setLocalCoords(
0082 Acts::Vector3{data.localPositionX, data.localPositionY,
0083 data.localPositionZ},
0084 Acts::Vector3{data.localDirectionX, data.localDirectionY,
0085 data.localDirectionZ});
0086 newSeg.setTime(data.time, data.timeError);
0087 newSeg.setFitQuality(data.chiSquared, data.nDoF);
0088 newSeg.setHitSummary(data.precisionHits, data.trigEtaLayers,
0089 data.phiLayers);
0090 }
0091
0092 m_outputSegments(ctx, std::move(segments));
0093
0094 return ProcessCode::SUCCESS;
0095 }
0096 }