Skip to content

Commit

Permalink
Add a event tree writer
Browse files Browse the repository at this point in the history
  • Loading branch information
beomki-yeo committed Nov 28, 2023
1 parent de62e50 commit d0dce88
Show file tree
Hide file tree
Showing 10 changed files with 330 additions and 2 deletions.
7 changes: 7 additions & 0 deletions examples/run/cpu/seeding_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// performance
#include "traccc/efficiency/finding_performance_writer.hpp"
#include "traccc/efficiency/seeding_performance_writer.hpp"
#include "traccc/event/event_tree_writer.hpp"
#include "traccc/resolution/fitting_performance_writer.hpp"

// options
Expand Down Expand Up @@ -74,6 +75,8 @@ int seq_run(const traccc::seeding_input_config& /*i_cfg*/,
vecmem::host_memory_resource host_mr;

// Performance writer
traccc::event_tree_writer evt_tree_writer(
traccc::event_tree_writer::config{});
traccc::seeding_performance_writer sd_performance_writer(
traccc::seeding_performance_writer::config{});
traccc::finding_performance_writer find_performance_writer(
Expand Down Expand Up @@ -207,6 +210,9 @@ int seq_run(const traccc::seeding_input_config& /*i_cfg*/,
traccc::event_map2 evt_map(event, common_opts.input_directory,
common_opts.input_directory,
common_opts.input_directory);

evt_tree_writer.write(traccc::get_data(track_states), evt_map);

sd_performance_writer.write(vecmem::get_data(seeds),
vecmem::get_data(spacepoints_per_event),
evt_map);
Expand All @@ -226,6 +232,7 @@ int seq_run(const traccc::seeding_input_config& /*i_cfg*/,
}

if (common_opts.check_performance) {
evt_tree_writer.finalize();
sd_performance_writer.finalize();
find_performance_writer.finalize();
fit_performance_writer.finalize();
Expand Down
7 changes: 7 additions & 0 deletions examples/run/cpu/truth_finding_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "traccc/definitions/common.hpp"
#include "traccc/definitions/primitives.hpp"
#include "traccc/efficiency/finding_performance_writer.hpp"
#include "traccc/event/event_tree_writer.hpp"
#include "traccc/finding/finding_algorithm.hpp"
#include "traccc/fitting/fitting_algorithm.hpp"
#include "traccc/fitting/kalman_filter/kalman_fitter.hpp"
Expand Down Expand Up @@ -65,6 +66,8 @@ int seq_run(const traccc::finding_input_config& i_cfg,
vecmem::host_memory_resource host_mr;

// Performance writer
traccc::event_tree_writer evt_tree_writer(
traccc::event_tree_writer::config{});
traccc::finding_performance_writer find_performance_writer(
traccc::finding_performance_writer::config{});
traccc::fitting_performance_writer fit_performance_writer(
Expand Down Expand Up @@ -172,6 +175,9 @@ int seq_run(const traccc::finding_input_config& i_cfg,
const unsigned int n_fitted_tracks = track_states.size();

if (common_opts.check_performance) {

evt_tree_writer.write(traccc::get_data(track_states), evt_map2);

find_performance_writer.write(traccc::get_data(track_candidates),
evt_map2);

Expand All @@ -187,6 +193,7 @@ int seq_run(const traccc::finding_input_config& i_cfg,
}

if (common_opts.check_performance) {
evt_tree_writer.finalize();
find_performance_writer.finalize();
fit_performance_writer.finalize();
}
Expand Down
6 changes: 6 additions & 0 deletions examples/run/cpu/truth_fitting_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Project include(s).
#include "traccc/definitions/common.hpp"
#include "traccc/definitions/primitives.hpp"
#include "traccc/event/event_tree_writer.hpp"
#include "traccc/fitting/fitting_algorithm.hpp"
#include "traccc/fitting/kalman_filter/kalman_fitter.hpp"
#include "traccc/io/read_geometry.hpp"
Expand Down Expand Up @@ -84,6 +85,8 @@ int main(int argc, char* argv[]) {
vecmem::host_memory_resource host_mr;

// Performance writer
traccc::event_tree_writer evt_tree_writer(
traccc::event_tree_writer::config{});
traccc::fitting_performance_writer fit_performance_writer(
traccc::fitting_performance_writer::config{});

Expand Down Expand Up @@ -153,6 +156,8 @@ int main(int argc, char* argv[]) {

if (common_opts.check_performance) {

evt_tree_writer.write(traccc::get_data(track_states), evt_map2);

for (unsigned int i = 0; i < n_fitted_tracks; i++) {
const auto& trk_states_per_track = track_states.at(i).items;

Expand All @@ -165,6 +170,7 @@ int main(int argc, char* argv[]) {
}

if (common_opts.check_performance) {
evt_tree_writer.finalize();
fit_performance_writer.finalize();
}

Expand Down
6 changes: 6 additions & 0 deletions examples/run/cuda/seeding_example_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "traccc/efficiency/nseed_performance_writer.hpp"
#include "traccc/efficiency/seeding_performance_writer.hpp"
#include "traccc/efficiency/track_filter.hpp"
#include "traccc/event/event_tree_writer.hpp"
#include "traccc/finding/finding_algorithm.hpp"
#include "traccc/fitting/fitting_algorithm.hpp"
#include "traccc/io/read_geometry.hpp"
Expand Down Expand Up @@ -92,6 +93,8 @@ int seq_run(const traccc::seeding_input_config& /*i_cfg*/,
traccc::memory_resource mr{device_mr, &cuda_host_mr};

// Performance writer
traccc::event_tree_writer evt_tree_writer(
traccc::event_tree_writer::config{});
traccc::seeding_performance_writer sd_performance_writer(
traccc::seeding_performance_writer::config{});
traccc::finding_performance_writer find_performance_writer(
Expand Down Expand Up @@ -432,6 +435,8 @@ int seq_run(const traccc::seeding_input_config& /*i_cfg*/,
traccc::event_map2 evt_map(event, common_opts.input_directory,
common_opts.input_directory,
common_opts.input_directory);

evt_tree_writer.write(traccc::get_data(track_states), evt_map);
sd_performance_writer.write(
vecmem::get_data(seeds_cuda),
vecmem::get_data(sp_reader_output.spacepoints), evt_map);
Expand All @@ -452,6 +457,7 @@ int seq_run(const traccc::seeding_input_config& /*i_cfg*/,
}

if (common_opts.check_performance) {
evt_tree_writer.finalize();
sd_performance_writer.finalize();
nsd_performance_writer.finalize();
find_performance_writer.finalize();
Expand Down
5 changes: 5 additions & 0 deletions examples/run/cuda/truth_finding_example_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "traccc/device/container_d2h_copy_alg.hpp"
#include "traccc/device/container_h2d_copy_alg.hpp"
#include "traccc/efficiency/finding_performance_writer.hpp"
#include "traccc/event/event_tree_writer.hpp"
#include "traccc/finding/finding_algorithm.hpp"
#include "traccc/fitting/fitting_algorithm.hpp"
#include "traccc/fitting/kalman_filter/kalman_fitter.hpp"
Expand Down Expand Up @@ -86,6 +87,8 @@ int seq_run(const traccc::finding_input_config& i_cfg,
traccc::memory_resource mr{device_mr, &cuda_host_mr};

// Performance writer
traccc::event_tree_writer evt_tree_writer(
traccc::event_tree_writer::config{});
traccc::finding_performance_writer find_performance_writer(
traccc::finding_performance_writer::config{});
traccc::fitting_performance_writer fit_performance_writer(
Expand Down Expand Up @@ -318,6 +321,7 @@ int seq_run(const traccc::finding_input_config& i_cfg,
n_fitted_tracks_cuda += track_states_cuda.size();

if (common_opts.check_performance) {
evt_tree_writer.write(traccc::get_data(track_states), evt_map2);
find_performance_writer.write(
traccc::get_data(track_candidates_cuda), evt_map2);

Expand All @@ -334,6 +338,7 @@ int seq_run(const traccc::finding_input_config& i_cfg,
}

if (common_opts.check_performance) {
evt_tree_writer.finalize();
find_performance_writer.finalize();
fit_performance_writer.finalize();
}
Expand Down
8 changes: 8 additions & 0 deletions examples/run/cuda/truth_fitting_example_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "traccc/definitions/primitives.hpp"
#include "traccc/device/container_d2h_copy_alg.hpp"
#include "traccc/device/container_h2d_copy_alg.hpp"
#include "traccc/event/event_tree_writer.hpp"
#include "traccc/fitting/fitting_algorithm.hpp"
#include "traccc/fitting/kalman_filter/kalman_fitter.hpp"
#include "traccc/io/read_geometry.hpp"
Expand Down Expand Up @@ -107,6 +108,8 @@ int main(int argc, char* argv[]) {
traccc::memory_resource mr{device_mr, &cuda_host_mr};

// Performance writer
traccc::event_tree_writer evt_tree_writer(
traccc::event_tree_writer::config{});
traccc::fitting_performance_writer fit_performance_writer(
traccc::fitting_performance_writer::config{});

Expand Down Expand Up @@ -246,6 +249,10 @@ int main(int argc, char* argv[]) {
n_fitted_tracks_cuda += track_states_cuda.size();

if (common_opts.check_performance) {

evt_tree_writer.write(traccc::get_data(track_states_cuda),
evt_map2);

for (unsigned int i = 0; i < track_states_cuda.size(); i++) {
const auto& trk_states_per_track =
track_states_cuda.at(i).items;
Expand All @@ -259,6 +266,7 @@ int main(int argc, char* argv[]) {
}

if (common_opts.check_performance) {
evt_tree_writer.finalize();
fit_performance_writer.finalize();
}

Expand Down
8 changes: 6 additions & 2 deletions performance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ include( traccc-compiler-options-cpp )

# Set up the build of the traccc::performance library.
traccc_add_library( traccc_performance performance TYPE SHARED
# Event plot code
"src/event/event_tree_tool.hpp"
"src/event/event_tree_writer.cpp"
"include/traccc/event/event_tree_writer.hpp"
# Efficiency calculation code.
"src/efficiency/duplication_plot_tool.hpp"
"src/efficiency/eff_plot_tool.hpp"
Expand Down Expand Up @@ -68,9 +72,9 @@ target_link_libraries( traccc_performance

# Use ROOT in traccc::performance, if requested.
if( TRACCC_USE_ROOT )
find_package( ROOT COMPONENTS Core RIO Hist REQUIRED )
find_package( ROOT COMPONENTS Core RIO Hist Tree REQUIRED )
target_link_libraries( traccc_performance
PRIVATE ROOT::Core ROOT::RIO ROOT::Hist )
PRIVATE ROOT::Core ROOT::RIO ROOT::Hist ROOT::Tree )
target_compile_definitions( traccc_performance
PRIVATE TRACCC_HAVE_ROOT )
endif()
Expand Down
60 changes: 60 additions & 0 deletions performance/include/traccc/event/event_tree_writer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2023 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Local include(s).
#include "traccc/utils/helpers.hpp"

// Project include(s).
#include "traccc/edm/track_state.hpp"
#include "traccc/io/event_map2.hpp"

namespace traccc {
namespace details {

/// Data members that should not pollute the API of
/// @c traccc::event_tree_writer
struct event_tree_writer_data;

} // namespace details

class event_tree_writer {

public:
/// Configuration for the tool
struct config {

/// Output filename.
std::string file_path = "event_tree.root";
/// Output file mode
std::string file_mode = "RECREATE";
};

/// Construct from configuration and log level.
/// @param cfg The configuration
///
event_tree_writer(const config& cfg);

/// Destructor
~event_tree_writer();

void write(const track_state_container_types::const_view& track_states_view,
const event_map2& evt_map);

void finalize();

private:
/// Configuration for the tool
config m_cfg;

/// Opaque data members for the class
std::unique_ptr<details::event_tree_writer_data> m_data;

}; // class event_tree_writer

} // namespace traccc
Loading

0 comments on commit d0dce88

Please sign in to comment.