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/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.inputTrackParameters.empty() == m_cfg.inputTracks.empty()) {
0029     throw std::invalid_argument(
0030         "You have to either provide track parameters or tracks");
0031   }
0032 
0033   m_inputTrackParameters.maybeInitialize(m_cfg.inputTrackParameters);
0034   m_inputTracks.maybeInitialize(m_cfg.inputTracks);
0035 }
0036 
0037 ActsExamples::CsvTrackParameterWriter::~CsvTrackParameterWriter() = default;
0038 
0039 std::string ActsExamples::CsvTrackParameterWriter::name() const {
0040   return "CsvTrackParameterWriter";
0041 }
0042 
0043 ActsExamples::ProcessCode ActsExamples::CsvTrackParameterWriter::finalize() {
0044   // Write the tree
0045   return ProcessCode::SUCCESS;
0046 }
0047 
0048 ActsExamples::ProcessCode ActsExamples::CsvTrackParameterWriter::write(
0049     const AlgorithmContext& ctx) {
0050   TrackParametersContainer inputTrackParameters;
0051 
0052   if (!m_cfg.inputTrackParameters.empty()) {
0053     const auto& tmp = m_inputTrackParameters(ctx);
0054     inputTrackParameters = tmp;
0055   } else {
0056     const auto& inputTracks = m_inputTracks(ctx);
0057 
0058     for (const auto& track : inputTracks) {
0059       if (!track.hasReferenceSurface()) {
0060         continue;
0061       }
0062       auto trackParam = track.createParametersAtReference();
0063       inputTrackParameters.push_back(trackParam);
0064     }
0065   }
0066 
0067   std::string path =
0068       perEventFilepath(m_cfg.outputDir, m_cfg.outputStem, ctx.eventNumber);
0069 
0070   ActsExamples::NamedTupleCsvWriter<TrackParameterData> writer(
0071       path, m_cfg.outputPrecision);
0072 
0073   TrackParameterData data{};
0074   for (const auto& tp : inputTrackParameters) {
0075     const auto& params = tp.parameters();
0076     const auto& cov = tp.covariance().value();
0077 
0078     data.d0 = params[Acts::eBoundLoc0];
0079     data.z0 = params[Acts::eBoundLoc1];
0080     data.phi = params[Acts::eBoundPhi];
0081     data.theta = params[Acts::eBoundTheta];
0082     data.qop = params[Acts::eBoundQOverP];
0083 
0084     data.var_d0 = cov(Acts::eBoundLoc0, Acts::eBoundLoc0);
0085     data.var_z0 = cov(Acts::eBoundLoc1, Acts::eBoundLoc1);
0086     data.var_phi = cov(Acts::eBoundPhi, Acts::eBoundPhi);
0087     data.var_theta = cov(Acts::eBoundTheta, Acts::eBoundTheta);
0088     data.var_qop = cov(Acts::eBoundQOverP, Acts::eBoundQOverP);
0089 
0090     data.cov_d0z0 = cov(Acts::eBoundLoc0, Acts::eBoundLoc1);
0091     data.cov_d0phi = cov(Acts::eBoundLoc0, Acts::eBoundPhi);
0092     data.cov_d0theta = cov(Acts::eBoundLoc0, Acts::eBoundTheta);
0093     data.cov_d0qop = cov(Acts::eBoundLoc0, Acts::eBoundQOverP);
0094 
0095     data.cov_z0d0 = cov(Acts::eBoundLoc1, Acts::eBoundLoc0);
0096     data.cov_z0phi = cov(Acts::eBoundLoc1, Acts::eBoundPhi);
0097     data.cov_z0theta = cov(Acts::eBoundLoc1, Acts::eBoundTheta);
0098     data.cov_z0qop = cov(Acts::eBoundLoc1, Acts::eBoundQOverP);
0099 
0100     data.cov_phid0 = cov(Acts::eBoundPhi, Acts::eBoundLoc0);
0101     data.cov_phiz0 = cov(Acts::eBoundPhi, Acts::eBoundLoc1);
0102     data.cov_phitheta = cov(Acts::eBoundPhi, Acts::eBoundTheta);
0103     data.cov_phiqop = cov(Acts::eBoundPhi, Acts::eBoundQOverP);
0104 
0105     data.cov_thetad0 = cov(Acts::eBoundTheta, Acts::eBoundLoc0);
0106     data.cov_thetaz0 = cov(Acts::eBoundTheta, Acts::eBoundLoc1);
0107     data.cov_thetaphi = cov(Acts::eBoundTheta, Acts::eBoundPhi);
0108     data.cov_thetaqop = cov(Acts::eBoundTheta, Acts::eBoundQOverP);
0109 
0110     data.cov_qopd0 = cov(Acts::eBoundQOverP, Acts::eBoundLoc0);
0111     data.cov_qopz0 = cov(Acts::eBoundQOverP, Acts::eBoundLoc1);
0112     data.cov_qopphi = cov(Acts::eBoundQOverP, Acts::eBoundPhi);
0113     data.cov_qoptheta = cov(Acts::eBoundQOverP, Acts::eBoundTheta);
0114 
0115     writer.append(data);
0116   }
0117 
0118   return ActsExamples::ProcessCode::SUCCESS;
0119 }