Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-11 08:02:10

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/CsvTrackParameterWriter.hpp"
0010 
0011 #include "Acts/Definitions/TrackParametrization.hpp"
0012 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0013 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0014 #include "ActsExamples/Utilities/Paths.hpp"
0015 
0016 #include <optional>
0017 #include <stdexcept>
0018 
0019 #include "CsvOutputData.hpp"
0020 
0021 namespace ActsExamples {
0022 
0023 CsvTrackParameterWriter::CsvTrackParameterWriter(const Config& config,
0024                                                  Acts::Logging::Level level)
0025     : m_cfg(config),
0026       m_logger(Acts::getDefaultLogger("CsvTrackParameterWriter", level)) {
0027   if (m_cfg.inputTracks.empty()) {
0028     throw std::invalid_argument("You have to provide tracks");
0029   }
0030 
0031   m_inputTracks.initialize(m_cfg.inputTracks);
0032 }
0033 
0034 CsvTrackParameterWriter::~CsvTrackParameterWriter() = default;
0035 
0036 std::string CsvTrackParameterWriter::name() const {
0037   return "CsvTrackParameterWriter";
0038 }
0039 
0040 ProcessCode CsvTrackParameterWriter::finalize() {
0041   // Write the tree
0042   return ProcessCode::SUCCESS;
0043 }
0044 
0045 ProcessCode CsvTrackParameterWriter::write(const AlgorithmContext& ctx) {
0046   const auto& inputTracks = m_inputTracks(ctx);
0047 
0048   std::string path = perEventFilepath(
0049       m_cfg.outputDir, m_cfg.outputStem + ".csv", ctx.eventNumber);
0050 
0051   BoostDescribeCsvWriter<TrackParameterData> writer(path,
0052                                                     m_cfg.outputPrecision);
0053 
0054   TrackParameterData data{};
0055   for (const auto& track : inputTracks) {
0056     if (!track.hasReferenceSurface()) {
0057       continue;
0058     }
0059     auto tp = track.createParametersAtReference();
0060     const auto& params = tp.parameters();
0061     const auto& cov = tp.covariance().value();
0062 
0063     data.trackId = track.index();
0064     data.d0 = params[Acts::eBoundLoc0];
0065     data.z0 = params[Acts::eBoundLoc1];
0066     data.phi = params[Acts::eBoundPhi];
0067     data.theta = params[Acts::eBoundTheta];
0068     data.qop = params[Acts::eBoundQOverP];
0069 
0070     data.var_d0 = cov(Acts::eBoundLoc0, Acts::eBoundLoc0);
0071     data.var_z0 = cov(Acts::eBoundLoc1, Acts::eBoundLoc1);
0072     data.var_phi = cov(Acts::eBoundPhi, Acts::eBoundPhi);
0073     data.var_theta = cov(Acts::eBoundTheta, Acts::eBoundTheta);
0074     data.var_qop = cov(Acts::eBoundQOverP, Acts::eBoundQOverP);
0075 
0076     data.cov_d0z0 = cov(Acts::eBoundLoc0, Acts::eBoundLoc1);
0077     data.cov_d0phi = cov(Acts::eBoundLoc0, Acts::eBoundPhi);
0078     data.cov_d0theta = cov(Acts::eBoundLoc0, Acts::eBoundTheta);
0079     data.cov_d0qop = cov(Acts::eBoundLoc0, Acts::eBoundQOverP);
0080 
0081     data.cov_z0d0 = cov(Acts::eBoundLoc1, Acts::eBoundLoc0);
0082     data.cov_z0phi = cov(Acts::eBoundLoc1, Acts::eBoundPhi);
0083     data.cov_z0theta = cov(Acts::eBoundLoc1, Acts::eBoundTheta);
0084     data.cov_z0qop = cov(Acts::eBoundLoc1, Acts::eBoundQOverP);
0085 
0086     data.cov_phid0 = cov(Acts::eBoundPhi, Acts::eBoundLoc0);
0087     data.cov_phiz0 = cov(Acts::eBoundPhi, Acts::eBoundLoc1);
0088     data.cov_phitheta = cov(Acts::eBoundPhi, Acts::eBoundTheta);
0089     data.cov_phiqop = cov(Acts::eBoundPhi, Acts::eBoundQOverP);
0090 
0091     data.cov_thetad0 = cov(Acts::eBoundTheta, Acts::eBoundLoc0);
0092     data.cov_thetaz0 = cov(Acts::eBoundTheta, Acts::eBoundLoc1);
0093     data.cov_thetaphi = cov(Acts::eBoundTheta, Acts::eBoundPhi);
0094     data.cov_thetaqop = cov(Acts::eBoundTheta, Acts::eBoundQOverP);
0095 
0096     data.cov_qopd0 = cov(Acts::eBoundQOverP, Acts::eBoundLoc0);
0097     data.cov_qopz0 = cov(Acts::eBoundQOverP, Acts::eBoundLoc1);
0098     data.cov_qopphi = cov(Acts::eBoundQOverP, Acts::eBoundPhi);
0099     data.cov_qoptheta = cov(Acts::eBoundQOverP, Acts::eBoundTheta);
0100 
0101     writer.append(data);
0102   }
0103 
0104   return ProcessCode::SUCCESS;
0105 }
0106 
0107 }  // namespace ActsExamples