Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-05-15 07:57:12

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/CsvMuonSpacePointReader.hpp"
0010 
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "ActsExamples/EventData/MuonSpacePoint.hpp"
0013 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0014 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0015 #include "ActsExamples/Utilities/Paths.hpp"
0016 
0017 #include <stdexcept>
0018 
0019 #include "CsvOutputData.hpp"
0020 
0021 namespace ActsExamples {
0022 CsvMuonSpacePointReader::CsvMuonSpacePointReader(const Config& config,
0023                                                  Acts::Logging::Level level)
0024     : m_cfg{config},
0025       m_eventsRange{
0026           determineEventFilesRange(m_cfg.inputDir, m_cfg.inputStem + ".csv")},
0027       m_logger{Acts::getDefaultLogger("CsvMuonSpacePointReader", level)} {
0028   if (m_cfg.inputStem.empty()) {
0029     throw std::invalid_argument("Missing input filename stem");
0030   }
0031   if (m_cfg.outputSpacePoints.empty()) {
0032     throw std::invalid_argument("Missing space point output collection");
0033   }
0034 
0035   m_outputSpacePoints.initialize(m_cfg.outputSpacePoints);
0036 }
0037 
0038 std::string CsvMuonSpacePointReader::CsvMuonSpacePointReader::name() const {
0039   return "CsvMuonSpacePointReader";
0040 }
0041 
0042 std::pair<std::size_t, std::size_t> CsvMuonSpacePointReader::availableEvents()
0043     const {
0044   return m_eventsRange;
0045 }
0046 
0047 ProcessCode CsvMuonSpacePointReader::read(const AlgorithmContext& ctx) {
0048   auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
0049                                ctx.eventNumber);
0050 
0051   NamedTupleCsvReader<MuonSpacePointData> reader(path);
0052 
0053   MuonSpacePointData data{};
0054 
0055   MuonSpacePointContainer spacePoints{};
0056 
0057   using MuonId = MuonSpacePoint::MuonId;
0058   int lastBucketId{-1};
0059   while (reader.read(data)) {
0060     /// Decode the stationName, sector & side of the chamber
0061     MuonId::StationName stName{
0062         static_cast<MuonId::StationName>(0x0FF & data.sectorId)};
0063     MuonId::DetSide side{
0064         static_cast<MuonId::DetSide>(0x0FF & (data.sectorId >> 8))};
0065     const auto sector = static_cast<int>(0x0FF & (data.sectorId >> 16));
0066     MuonId::TechField tech{
0067         static_cast<MuonId::TechField>(0x0FF & (data.sectorId >> 24))};
0068     MuonId id{};
0069     id.setChamber(stName, side, sector, tech);
0070     id.setLayAndCh(data.gasGap, data.primaryCh);
0071     id.setCoordFlags(data.measuresEta, data.measuresPhi);
0072     /// Start a new bucket if the sector id or the bucket Id are different
0073     if (spacePoints.empty() ||
0074         !spacePoints.back().back().id().sameStation(id) ||
0075         lastBucketId != data.bucketId) {
0076       spacePoints.emplace_back();
0077       lastBucketId = data.bucketId;
0078     }
0079     MuonSpacePoint& newSpacePoint{spacePoints.back().emplace_back()};
0080 
0081     newSpacePoint.setId(id);
0082 
0083     newSpacePoint.defineCoordinates(
0084         Acts::Vector3{data.locPositionX, data.locPositionY, data.locPositionZ},
0085         Acts::Vector3{data.locSensorDirX, data.locSensorDirY,
0086                       data.locSensorDirZ});
0087     newSpacePoint.defineNormal(Acts::Vector3{
0088         data.locPlaneNormX, data.locPlaneNormY, data.locPlaneNormZ});
0089     newSpacePoint.setRadius(data.driftR);
0090 
0091     newSpacePoint.setSpatialCov(data.covXX, data.covXY, data.covYX, data.covYY);
0092     ACTS_VERBOSE("New spacepoint loaded: " << newSpacePoint);
0093   }
0094 
0095   // write the ordered data to the EventStore (according to geometry_id).
0096   m_outputSpacePoints(ctx, std::move(spacePoints));
0097 
0098   return ProcessCode::SUCCESS;
0099 }
0100 
0101 }  // namespace ActsExamples