Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track Parameter CSV Writing, main branch (2025.02.10.) #849

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion io/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TRACCC library, part of the ACTS project (R&D line)
#
# (c) 2021-2024 CERN for the benefit of the ACTS project
# (c) 2021-2025 CERN for the benefit of the ACTS project
#
# Mozilla Public License Version 2.0

@@ -61,6 +61,8 @@ traccc_add_library( traccc_io io TYPE SHARED
"src/csv/read_cells.cpp"
"src/csv/write_cells.hpp"
"src/csv/write_cells.cpp"
"src/csv/write_track_parameters.hpp"
"src/csv/write_track_parameters.cpp"
"src/csv/read_spacepoints.hpp"
"src/csv/read_spacepoints.cpp"
"src/csv/make_measurement_reader.cpp"
14 changes: 13 additions & 1 deletion io/include/traccc/io/write.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2021-2024 CERN for the benefit of the ACTS project
* (c) 2021-2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
@@ -12,6 +12,7 @@
#include "traccc/edm/silicon_cell_collection.hpp"
#include "traccc/edm/spacepoint.hpp"
#include "traccc/edm/track_candidate.hpp"
#include "traccc/edm/track_parameters.hpp"
#include "traccc/geometry/detector.hpp"
#include "traccc/geometry/silicon_detector_description.hpp"
#include "traccc/io/data_format.hpp"
@@ -73,6 +74,17 @@ void write(std::size_t event, std::string_view directory,
traccc::data_format format, seed_collection_types::const_view seeds,
spacepoint_collection_types::const_view spacepoints);

/// Function for track parameter writing
///
/// @param event is the event index
/// @param directory is the directory for the output seed file
/// @param format is the data format (obj only right now) of output file
/// @param track_params is the track parameter collection to write
///
void write(std::size_t event, std::string_view directory,
traccc::data_format format,
bound_track_parameters_collection_types::const_view track_params);

/// Function for track candidate writing
///
/// @param event is the event index
47 changes: 47 additions & 0 deletions io/src/csv/write_track_parameters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

// Local include(s).
#include "write_track_parameters.hpp"

// System include(s).
#include <format>
#include <fstream>
#include <stdexcept>

namespace traccc::io::csv {

void write_track_parameters(
std::string_view filename,
bound_track_parameters_collection_types::const_view track_params_view) {

// Open the file for writing.
std::ofstream ofile(filename.data());
if (!ofile.is_open()) {
throw std::runtime_error(
std::format("Could not open file \"{}\"", filename));
}

// Create device objects.
const bound_track_parameters_collection_types::const_device track_params(
track_params_view);

// Write the header.
ofile << "surface_link,local0,local1,phi,theta,time,qop\n";

// Write out each track parameter.
for (const traccc::bound_track_parameters& track : track_params) {

// Write the track parameter info to the file.
ofile << track.surface_link().value() << ","
<< track.bound_local().at(0) << "," << track.bound_local().at(1)
<< "," << track.phi() << "," << track.theta() << ","
<< track.time() << "," << track.qop() << '\n';
}
}

} // namespace traccc::io::csv
27 changes: 27 additions & 0 deletions io/src/csv/write_track_parameters.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Project include(s).
#include "traccc/edm/track_parameters.hpp"

// System include(s).
#include <string_view>

namespace traccc::io::csv {

/// Function for track parameter writing to CSV files
///
/// @param filename The name of the file to write the data to
/// @param track_params Track parameters to write
///
void write_track_parameters(
std::string_view filename,
bound_track_parameters_collection_types::const_view track_params);

} // namespace traccc::io::csv
21 changes: 20 additions & 1 deletion io/src/write.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2022-2024 CERN for the benefit of the ACTS project
* (c) 2022-2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
@@ -9,6 +9,7 @@
#include "traccc/io/write.hpp"

#include "csv/write_cells.hpp"
#include "csv/write_track_parameters.hpp"
#include "json/write_digitization_config.hpp"
#include "obj/write_seeds.hpp"
#include "obj/write_spacepoints.hpp"
@@ -76,6 +77,24 @@ void write(std::size_t event, std::string_view directory,
}
}

void write(std::size_t event, std::string_view directory,
traccc::data_format format,
bound_track_parameters_collection_types::const_view track_params) {

switch (format) {
case data_format::csv:
csv::write_track_parameters(
get_absolute_path((std::filesystem::path(directory) /
std::filesystem::path(get_event_filename(
event, "-trackparams.csv")))
.native()),
track_params);
break;
default:
throw std::invalid_argument("Unsupported data format");
}
}

void write(std::size_t event, std::string_view directory,
traccc::data_format format,
measurement_collection_types::const_view measurements) {