Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:46

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Io/Csv/CsvProtoTrackWriter.hpp"
0010 
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Surfaces/Surface.hpp"
0013 #include "Acts/Utilities/Intersection.hpp"
0014 #include "ActsExamples/EventData/Index.hpp"
0015 #include "ActsExamples/EventData/SimSpacePoint.hpp"
0016 #include "ActsExamples/Framework/WhiteBoard.hpp"
0017 #include "ActsExamples/Utilities/EventDataTransforms.hpp"
0018 #include "ActsExamples/Utilities/Paths.hpp"
0019 #include "ActsExamples/Utilities/Range.hpp"
0020 
0021 #include <ios>
0022 #include <optional>
0023 #include <stdexcept>
0024 
0025 #include <dfe/dfe_io_dsv.hpp>
0026 
0027 #include "CsvOutputData.hpp"
0028 
0029 ActsExamples::CsvProtoTrackWriter::CsvProtoTrackWriter(
0030     const ActsExamples::CsvProtoTrackWriter::Config& config,
0031     Acts::Logging::Level level)
0032     : WriterT(config.inputPrototracks, "CsvProtoTrackWriter", level),
0033       m_cfg(config) {
0034   m_inputSpacepoints.initialize(m_cfg.inputSpacepoints);
0035 }
0036 
0037 ActsExamples::CsvProtoTrackWriter::~CsvProtoTrackWriter() = default;
0038 
0039 ActsExamples::ProcessCode ActsExamples::CsvProtoTrackWriter::finalize() {
0040   // Write the tree
0041   return ProcessCode::SUCCESS;
0042 }
0043 
0044 ActsExamples::ProcessCode ActsExamples::CsvProtoTrackWriter::writeT(
0045     const AlgorithmContext& ctx, const ProtoTrackContainer& tracks) {
0046   const auto& spacepoints = m_inputSpacepoints(ctx);
0047 
0048   // Open per-event file for all components
0049   std::string path =
0050       perEventFilepath(m_cfg.outputDir, "prototracks.csv", ctx.eventNumber);
0051 
0052   dfe::NamedTupleCsvWriter<ProtoTrackData> writer(path, m_cfg.outputPrecision);
0053 
0054   for (auto trackId = 0ul; trackId < tracks.size(); ++trackId) {
0055     for (Index measurmentId : tracks[trackId]) {
0056       const auto spr = findSpacePointForIndex(measurmentId, spacepoints);
0057       if (spr == nullptr) {
0058         ACTS_WARNING("Could not convert index " << measurmentId
0059                                                 << " to spacepoint");
0060         continue;
0061       }
0062       const auto& sp = *spr;
0063       writer.append({trackId, measurmentId, sp.x(), sp.y(), sp.z()});
0064     }
0065   }
0066   return ActsExamples::ProcessCode::SUCCESS;
0067 }