Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:22:21

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2022-2026 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 // Library include(s).
0009 #include "traccc/resolution/fitting_performance_writer.hpp"
0010 
0011 #include "res_plot_tool.hpp"
0012 #include "stat_plot_tool.hpp"
0013 
0014 // ROOT include(s).
0015 #ifdef TRACCC_HAVE_ROOT
0016 #include <TFile.h>
0017 #endif  // TRACCC_HAVE_ROOT
0018 
0019 // System include(s).
0020 #include <iostream>
0021 #include <memory>
0022 #include <stdexcept>
0023 
0024 namespace traccc {
0025 namespace details {
0026 
0027 struct fitting_performance_writer_data {
0028   /// Constructor
0029   fitting_performance_writer_data(const fitting_performance_writer::config& cfg)
0030       : m_res_plot_tool(cfg.res_config), m_stat_plot_tool(cfg.stat_config) {}
0031 
0032   /// Plot tool for resolution
0033   res_plot_tool m_res_plot_tool;
0034   res_plot_tool::res_plot_cache m_res_plot_cache;
0035   /// Plot tool for statistics
0036   stat_plot_tool m_stat_plot_tool;
0037   stat_plot_tool::stat_plot_cache m_stat_plot_cache;
0038 };
0039 
0040 }  // namespace details
0041 
0042 fitting_performance_writer::fitting_performance_writer(
0043     const config& cfg, std::unique_ptr<const traccc::Logger> logger)
0044     : messaging(std::move(logger)),
0045       m_cfg(cfg),
0046       m_data(std::make_unique<details::fitting_performance_writer_data>(cfg)) {
0047   m_data->m_res_plot_tool.book(m_data->m_res_plot_cache);
0048   m_data->m_stat_plot_tool.book(m_data->m_stat_plot_cache);
0049 }
0050 
0051 fitting_performance_writer::~fitting_performance_writer() {}
0052 
0053 void fitting_performance_writer::finalize() {
0054 #ifdef TRACCC_HAVE_ROOT
0055   // Open the output file.
0056   std::unique_ptr<TFile> ofile(
0057       TFile::Open(m_cfg.file_path.c_str(), m_cfg.file_mode.c_str()));
0058   if ((!ofile) || ofile->IsZombie()) {
0059     throw std::runtime_error("Could not open output file \"" + m_cfg.file_path +
0060                              "\" in mode \"" + m_cfg.file_mode + "\"");
0061   }
0062   ofile->cd();
0063 #else
0064   std::cout << "ROOT file \"" << m_cfg.file_path << "\" is NOT created"
0065             << std::endl;
0066 #endif  // TRACCC_HAVE_ROOT
0067 
0068   m_data->m_res_plot_tool.write(m_data->m_res_plot_cache);
0069   m_data->m_stat_plot_tool.write(m_data->m_stat_plot_cache);
0070 }
0071 
0072 void fitting_performance_writer::write_res(
0073     const bound_track_parameters<>& truth_param,
0074     const bound_track_parameters<>& fit_param, const particle& ptc) {
0075   m_data->m_res_plot_tool.fill(m_data->m_res_plot_cache, truth_param, fit_param,
0076                                ptc);
0077 }
0078 
0079 void fitting_performance_writer::write_stat(
0080     const edm::track_collection<traccc::default_algebra>::host::proxy_type
0081         track,
0082     const edm::track_state_collection<traccc::default_algebra>::host&
0083         track_states,
0084     const edm::measurement_collection::host& measurements) {
0085   m_data->m_stat_plot_tool.fill(m_data->m_stat_plot_cache, track);
0086 
0087   for (const edm::track_constituent_link& link : track.constituent_links()) {
0088     assert(link.type == edm::track_constituent_link::track_state);
0089     m_data->m_stat_plot_tool.fill(m_data->m_stat_plot_cache,
0090                                   track_states.at(link.index), measurements);
0091   }
0092 }
0093 
0094 }  // namespace traccc