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