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/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/Io/Csv/CsvInputOutput.hpp"
0018 #include "ActsExamples/Utilities/EventDataTransforms.hpp"
0019 #include "ActsExamples/Utilities/Paths.hpp"
0020 #include "ActsExamples/Utilities/Range.hpp"
0021 
0022 #include <ios>
0023 #include <optional>
0024 #include <stdexcept>
0025 
0026 #include "CsvOutputData.hpp"
0027 
0028 ActsExamples::CsvProtoTrackWriter::CsvProtoTrackWriter(
0029     const ActsExamples::CsvProtoTrackWriter::Config& config,
0030     Acts::Logging::Level level)
0031     : WriterT(config.inputPrototracks, "CsvProtoTrackWriter", level),
0032       m_cfg(config) {
0033   m_inputSpacepoints.initialize(m_cfg.inputSpacepoints);
0034 }
0035 
0036 ActsExamples::CsvProtoTrackWriter::~CsvProtoTrackWriter() = default;
0037 
0038 ActsExamples::ProcessCode ActsExamples::CsvProtoTrackWriter::finalize() {
0039   // Write the tree
0040   return ProcessCode::SUCCESS;
0041 }
0042 
0043 ActsExamples::ProcessCode ActsExamples::CsvProtoTrackWriter::writeT(
0044     const AlgorithmContext& ctx, const ProtoTrackContainer& tracks) {
0045   const auto& spacepoints = m_inputSpacepoints(ctx);
0046 
0047   // Open per-event file for all components
0048   std::string path =
0049       perEventFilepath(m_cfg.outputDir, "prototracks.csv", ctx.eventNumber);
0050 
0051   ActsExamples::NamedTupleCsvWriter<ProtoTrackData> writer(
0052       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 }