File indexing completed on 2025-08-06 08:10:47
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/Csv/CsvTrackParameterReader.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/TrackParametrization.hpp"
0013 #include "Acts/Surfaces/PerigeeSurface.hpp"
0014 #include "Acts/Surfaces/Surface.hpp"
0015 #include "ActsExamples/EventData/Track.hpp"
0016 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0017 #include "ActsExamples/Utilities/Paths.hpp"
0018
0019 #include <algorithm>
0020 #include <stdexcept>
0021 #include <string>
0022
0023 #include <dfe/dfe_io_dsv.hpp>
0024
0025 #include "CsvOutputData.hpp"
0026
0027 ActsExamples::CsvTrackParameterReader::CsvTrackParameterReader(
0028 const ActsExamples::CsvTrackParameterReader::Config& config,
0029 Acts::Logging::Level level)
0030 : m_cfg(config),
0031 m_eventsRange(
0032 determineEventFilesRange(m_cfg.inputDir, m_cfg.inputStem + ".csv")),
0033 m_logger(Acts::getDefaultLogger("CsvTrackParameterReader", level)) {
0034 if (m_cfg.inputStem.empty()) {
0035 throw std::invalid_argument("Missing input filename stem");
0036 }
0037 if (m_cfg.outputTrackParameters.empty()) {
0038 throw std::invalid_argument("Missing output collection");
0039 }
0040
0041 m_outputTrackParameters.initialize(m_cfg.outputTrackParameters);
0042 }
0043
0044 std::string
0045 ActsExamples::CsvTrackParameterReader::CsvTrackParameterReader::name() const {
0046 return "CsvTrackParameterReader";
0047 }
0048
0049 std::pair<std::size_t, std::size_t>
0050 ActsExamples::CsvTrackParameterReader::availableEvents() const {
0051 return m_eventsRange;
0052 }
0053
0054 ActsExamples::ProcessCode ActsExamples::CsvTrackParameterReader::read(
0055 const ActsExamples::AlgorithmContext& ctx) {
0056 TrackParametersContainer trackParameters;
0057
0058 auto surface = Acts::Surface::makeShared<Acts::PerigeeSurface>(
0059 Acts::Vector3(m_cfg.beamspot[0], m_cfg.beamspot[1], m_cfg.beamspot[2]));
0060
0061 auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
0062 ctx.eventNumber);
0063 dfe::NamedTupleCsvReader<TrackParameterData> reader(path);
0064 TrackParameterData d{};
0065
0066 while (reader.read(d)) {
0067 Acts::BoundVector params = Acts::BoundVector::Zero();
0068 params[Acts::eBoundLoc0] = d.d0;
0069 params[Acts::eBoundLoc1] = d.z0;
0070 params[Acts::eBoundPhi] = d.phi;
0071 params[Acts::eBoundTheta] = d.theta;
0072 params[Acts::eBoundQOverP] = d.qop;
0073
0074 Acts::BoundSquareMatrix cov = Acts::BoundSquareMatrix::Zero();
0075 cov(Acts::eBoundLoc0, Acts::eBoundLoc0) = d.var_d0;
0076 cov(Acts::eBoundLoc1, Acts::eBoundLoc1) = d.var_z0;
0077 cov(Acts::eBoundPhi, Acts::eBoundPhi) = d.var_phi;
0078 cov(Acts::eBoundTheta, Acts::eBoundTheta) = d.var_theta;
0079 cov(Acts::eBoundQOverP, Acts::eBoundQOverP) = d.var_qop;
0080 cov(Acts::eBoundTime, Acts::eBoundTime) = 1;
0081
0082 cov(Acts::eBoundLoc0, Acts::eBoundLoc1) = d.cov_d0z0;
0083 cov(Acts::eBoundLoc0, Acts::eBoundPhi) = d.cov_d0phi;
0084 cov(Acts::eBoundLoc0, Acts::eBoundTheta) = d.cov_d0theta;
0085 cov(Acts::eBoundLoc0, Acts::eBoundQOverP) = d.cov_d0qop;
0086
0087 cov(Acts::eBoundLoc1, Acts::eBoundLoc0) = d.cov_z0d0;
0088 cov(Acts::eBoundLoc1, Acts::eBoundPhi) = d.cov_z0phi;
0089 cov(Acts::eBoundLoc1, Acts::eBoundTheta) = d.cov_z0theta;
0090 cov(Acts::eBoundLoc1, Acts::eBoundQOverP) = d.cov_z0qop;
0091
0092 cov(Acts::eBoundPhi, Acts::eBoundLoc0) = d.cov_phid0;
0093 cov(Acts::eBoundPhi, Acts::eBoundLoc1) = d.cov_phiz0;
0094 cov(Acts::eBoundPhi, Acts::eBoundTheta) = d.cov_phitheta;
0095 cov(Acts::eBoundPhi, Acts::eBoundQOverP) = d.cov_phiqop;
0096
0097 cov(Acts::eBoundTheta, Acts::eBoundLoc0) = d.cov_thetad0;
0098 cov(Acts::eBoundTheta, Acts::eBoundLoc1) = d.cov_thetaz0;
0099 cov(Acts::eBoundTheta, Acts::eBoundPhi) = d.cov_thetaphi;
0100 cov(Acts::eBoundTheta, Acts::eBoundQOverP) = d.cov_thetaqop;
0101
0102 cov(Acts::eBoundQOverP, Acts::eBoundLoc0) = d.cov_qopd0;
0103 cov(Acts::eBoundQOverP, Acts::eBoundLoc1) = d.cov_qopz0;
0104 cov(Acts::eBoundQOverP, Acts::eBoundPhi) = d.cov_qopphi;
0105 cov(Acts::eBoundQOverP, Acts::eBoundTheta) = d.cov_qoptheta;
0106
0107
0108 trackParameters.emplace_back(surface, params, cov,
0109 Acts::ParticleHypothesis::pion());
0110 }
0111
0112 m_outputTrackParameters(ctx, std::move(trackParameters));
0113
0114 return ProcessCode::SUCCESS;
0115 }