Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-31 07:48:33

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Io/Csv/CsvMuonSegmentReader.hpp"
0010 
0011 #include "ActsExamples/EventData/MuonSegment.hpp"
0012 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0013 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0014 #include "ActsExamples/Utilities/Paths.hpp"
0015 
0016 #include <bitset>
0017 #include <stdexcept>
0018 
0019 #include "CsvOutputData.hpp"
0020 
0021 namespace ActsExamples {
0022 
0023 CsvMuonSegmentReader::CsvMuonSegmentReader(const Config& config,
0024                                            Acts::Logging::Level level)
0025     : m_cfg(config),
0026       // TODO check that all files (hits,cells,truth) exists
0027       m_eventsRange(
0028           determineEventFilesRange(m_cfg.inputDir, m_cfg.inputStem + ".csv")),
0029       m_logger(Acts::getDefaultLogger("CsvMuonSegmentReader", level)) {
0030   if (m_cfg.inputStem.empty()) {
0031     throw std::invalid_argument("Missing input filename stem");
0032   }
0033   if (m_cfg.outputSegments.empty()) {
0034     throw std::invalid_argument("Missing segment collection");
0035   }
0036 
0037   m_outputSegments.initialize(m_cfg.outputSegments);
0038 }
0039 
0040 std::string CsvMuonSegmentReader::CsvMuonSegmentReader::name() const {
0041   return "CsvMuonSegmentReader";
0042 }
0043 
0044 std::pair<std::size_t, std::size_t> CsvMuonSegmentReader::availableEvents()
0045     const {
0046   return m_eventsRange;
0047 }
0048 
0049 ProcessCode CsvMuonSegmentReader::read(const AlgorithmContext& ctx) {
0050   auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
0051                                ctx.eventNumber);
0052 
0053   BoostDescribeCsvReader<MuonSegmentData> reader(path);
0054 
0055   MuonSegmentData data{};
0056 
0057   MuonSegmentContainer segments{};
0058 
0059   using MuonId = MuonSegment::MuonId;
0060   while (reader.read(data)) {
0061     MuonSegment& newSeg = segments.emplace_back();
0062     /// Decode the stationName, sector & side of the chamber
0063     MuonId::StationName stName{
0064         static_cast<MuonId::StationName>(0x0FF & data.sectorId)};
0065     MuonId::DetSide side{
0066         static_cast<MuonId::DetSide>(0x0FF & (data.sectorId >> 8))};
0067     const auto sector = static_cast<int>(0x0FF & (data.sectorId >> 16));
0068     MuonId id{};
0069     id.setChamber(stName, side, sector, MuonId::TechField::UnDef);
0070     ACTS_VERBOSE("Read in new segment in "
0071                  << id << ", sector id: " << data.sectorId << ", "
0072                  << std::bitset<32>(data.sectorId));
0073     newSeg.setId(id);
0074     newSeg.setGlobalCoords(
0075         Acts::Vector3{data.globalPositionX, data.globalPositionY,
0076                       data.globalPositionZ},
0077         Acts::Vector3{data.globalDirectionX, data.globalDirectionY,
0078                       data.globalDirectionZ});
0079     newSeg.setLocalCoords(
0080         Acts::Vector3{data.localPositionX, data.localPositionY,
0081                       data.localPositionZ},
0082         Acts::Vector3{data.localDirectionX, data.localDirectionY,
0083                       data.localDirectionZ});
0084     newSeg.setTime(data.time, data.timeError);
0085     newSeg.setFitQuality(data.chiSquared, data.nDoF);
0086     newSeg.setHitSummary(data.precisionHits, data.trigEtaLayers,
0087                          data.phiLayers);
0088   }
0089   // write the ordered data to the EventStore (according to geometry_id).
0090   m_outputSegments(ctx, std::move(segments));
0091 
0092   return ProcessCode::SUCCESS;
0093 }
0094 }  // namespace ActsExamples