Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:51

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/CsvSpacePointReader.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/EventData/SourceLink.hpp"
0013 #include "ActsExamples/EventData/SimSpacePoint.hpp"
0014 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0015 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0016 #include "ActsExamples/Utilities/Paths.hpp"
0017 
0018 #include <array>
0019 #include <fstream>
0020 #include <optional>
0021 #include <stdexcept>
0022 #include <string>
0023 
0024 #include <boost/container/static_vector.hpp>
0025 
0026 #include "CsvOutputData.hpp"
0027 
0028 ActsExamples::CsvSpacePointReader::CsvSpacePointReader(
0029     const ActsExamples::CsvSpacePointReader::Config& cfg,
0030     Acts::Logging::Level lvl) {
0031   m_cfg = cfg;
0032   if (m_cfg.inputStem.empty()) {
0033     throw std::invalid_argument("Missing input filename stem");
0034   }
0035   auto& filename = m_cfg.inputCollection.empty()
0036                        ? cfg.inputStem
0037                        : cfg.inputStem + '_' + cfg.inputCollection;
0038   m_eventsRange = determineEventFilesRange(cfg.inputDir, filename + ".csv");
0039   m_logger = Acts::getDefaultLogger("CsvSpacePointReader", lvl);
0040 
0041   m_outputSpacePoints.initialize(m_cfg.outputSpacePoints);
0042 }
0043 
0044 std::string ActsExamples::CsvSpacePointReader::CsvSpacePointReader::name()
0045     const {
0046   return "CsvSpacePointReader";
0047 }
0048 
0049 std::pair<std::size_t, std::size_t>
0050 ActsExamples::CsvSpacePointReader::availableEvents() const {
0051   return m_eventsRange;
0052 }
0053 
0054 ActsExamples::ProcessCode ActsExamples::CsvSpacePointReader::read(
0055     const ActsExamples::AlgorithmContext& ctx) {
0056   SimSpacePointContainer spacePoints;
0057 
0058   const auto& filename = m_cfg.inputCollection.empty()
0059                              ? m_cfg.inputStem
0060                              : m_cfg.inputStem + '_' + m_cfg.inputCollection;
0061   const auto& path =
0062       perEventFilepath(m_cfg.inputDir, filename + ".csv", ctx.eventNumber);
0063 
0064   ActsExamples::NamedTupleCsvReader<SpacePointData> reader(path);
0065   SpacePointData data;
0066 
0067   while (reader.read(data)) {
0068     Acts::Vector3 globalPos(data.sp_x, data.sp_y, data.sp_z);
0069 
0070     if (m_cfg.inputCollection == "pixel" || m_cfg.inputCollection == "strip" ||
0071         m_cfg.inputCollection == "overlap") {
0072       boost::container::static_vector<Acts::SourceLink, 2> sLinks;
0073       // auto sp = SimSpacePoint(globalPos, data.sp_covr, data.sp_covz, sLinks);
0074 
0075       if (m_cfg.extendCollection) {
0076         Acts::Vector3 topStripDirection(data.sp_topStripDirection[0],
0077                                         data.sp_topStripDirection[1],
0078                                         data.sp_topStripDirection[2]);
0079         Acts::Vector3 bottomStripDirection(data.sp_bottomStripDirection[0],
0080                                            data.sp_bottomStripDirection[1],
0081                                            data.sp_bottomStripDirection[2]);
0082         Acts::Vector3 stripCenterDistance(data.sp_stripCenterDistance[0],
0083                                           data.sp_stripCenterDistance[1],
0084                                           data.sp_stripCenterDistance[2]);
0085         Acts::Vector3 topStripCenterPosition(data.sp_topStripCenterPosition[0],
0086                                              data.sp_topStripCenterPosition[1],
0087                                              data.sp_topStripCenterPosition[2]);
0088 
0089         // TODO time
0090         spacePoints.emplace_back(
0091             globalPos, std::nullopt, data.sp_covr, data.sp_covz, std::nullopt,
0092             sLinks, data.sp_topHalfStripLength, data.sp_bottomHalfStripLength,
0093             topStripDirection, bottomStripDirection, stripCenterDistance,
0094             topStripCenterPosition);
0095       } else {
0096         // TODO time
0097         spacePoints.emplace_back(globalPos, std::nullopt, data.sp_covr,
0098                                  data.sp_covz, std::nullopt, sLinks);
0099       }
0100     } else {
0101       ACTS_ERROR("Invalid space point type " << m_cfg.inputStem);
0102       return ProcessCode::ABORT;
0103     }
0104   }
0105 
0106   ACTS_DEBUG("Created " << spacePoints.size() << " " << m_cfg.inputCollection
0107                         << " space points");
0108   m_outputSpacePoints(ctx, std::move(spacePoints));
0109 
0110   return ProcessCode::SUCCESS;
0111 }