Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:12:58

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