Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2022-2024 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 #pragma once
0009 
0010 // Local include(s).
0011 #include "../utils/helpers.hpp"
0012 
0013 // Project include(s).
0014 #include "traccc/edm/particle.hpp"
0015 
0016 // System include(s).
0017 #include <string_view>
0018 
0019 namespace traccc {
0020 
0021 // Tools to make efficiency plots to show tracking efficiency.
0022 // For the moment, the efficiency is taken as the fraction of successfully
0023 // smoothed track over all tracks
0024 class eff_plot_tool {
0025  public:
0026   /// @brief The nested configuration struct
0027   struct config {
0028     std::map<std::string, plot_helpers::binning> var_binning = {
0029         {"Eta", plot_helpers::binning("#eta", 40, -4.f, 4.f)},
0030         {"Phi", plot_helpers::binning("#phi", 100, -3.15f, 3.15f)},
0031         {"Pt", plot_helpers::binning("pT [GeV/c]", 40, 0.f, 100.f)}};
0032   };
0033 
0034   /// @brief Nested Cache struct
0035   struct eff_plot_cache {
0036 #ifdef TRACCC_HAVE_ROOT
0037     std::unique_ptr<TEfficiency>
0038         track_eff_vs_pT;  ///< Tracking efficiency vs pT
0039     std::unique_ptr<TEfficiency>
0040         track_eff_vs_eta;  ///< Tracking efficiency vs eta
0041     std::unique_ptr<TEfficiency>
0042         track_eff_vs_phi;  ///< Tracking efficiency vs phi
0043 #endif                     // TRACCC_HAVE_ROOT
0044   };
0045 
0046   /// Constructor
0047   ///
0048   /// @param cfg Configuration struct
0049   /// @param lvl Message level declaration
0050   eff_plot_tool(const config& cfg) : m_cfg(cfg) {}
0051 
0052   /// @brief book the efficiency plots
0053   ///
0054   /// @param effPlotCache the cache for efficiency plots
0055   void book(std::string_view name, eff_plot_cache& cache) const {
0056     plot_helpers::binning b_phi = m_cfg.var_binning.at("Phi");
0057     plot_helpers::binning b_eta = m_cfg.var_binning.at("Eta");
0058     plot_helpers::binning b_pt = m_cfg.var_binning.at("Pt");
0059 
0060     // Avoid unused variable warnings when building the code without ROOT.
0061     (void)name;
0062     (void)cache;
0063 
0064 #ifdef TRACCC_HAVE_ROOT
0065     std::string header;
0066 
0067     if (name == "finding") {
0068       header = "Track finding efficiency";
0069     } else if (name == "seeding") {
0070       header = "Seed finding efficiency";
0071     } else {
0072       header = "Tracking efficiency";
0073     }
0074 
0075     // efficiency vs pT
0076     cache.track_eff_vs_pT =
0077         plot_helpers::book_eff(TString(name) + "_trackeff_vs_pT",
0078                                header + ";Truth pT [GeV/c];Efficiency", b_pt);
0079     // efficiency vs eta
0080     cache.track_eff_vs_eta =
0081         plot_helpers::book_eff(TString(name) + "_trackeff_vs_eta",
0082                                header + ";Truth #eta;Efficiency", b_eta);
0083     // efficiency vs phi
0084     cache.track_eff_vs_phi =
0085         plot_helpers::book_eff(TString(name) + "_trackeff_vs_phi",
0086                                header + ";Truth #phi;Efficiency", b_phi);
0087 #endif  // TRACCC_HAVE_ROOT
0088   }
0089 
0090   /// @brief fill efficiency plots
0091   ///
0092   /// @param effPlotCache cache object for efficiency plots
0093   /// @param truthParticle the truth Particle
0094   /// @param status the reconstruction status
0095   void fill(eff_plot_cache& cache, const particle& truth_particle,
0096             bool status) const {
0097     const auto t_phi = vector::phi(truth_particle.momentum);
0098     const auto t_eta = vector::eta(truth_particle.momentum);
0099     const auto t_pT = vector::perp(
0100         vector2{truth_particle.momentum[0], truth_particle.momentum[1]});
0101 
0102     // Avoid unused variable warnings when building the code without ROOT.
0103     (void)t_phi;
0104     (void)t_eta;
0105     (void)t_pT;
0106     (void)cache;
0107     (void)status;
0108 
0109 #ifdef TRACCC_HAVE_ROOT
0110     cache.track_eff_vs_pT->Fill(status, t_pT);
0111     cache.track_eff_vs_eta->Fill(status, t_eta);
0112     cache.track_eff_vs_phi->Fill(status, t_phi);
0113 #endif  // TRACCC_HAVE_ROOT
0114   }
0115 
0116   /// @brief write the efficiency plots to file
0117   ///
0118   /// @param effPlotCache cache object for efficiency plots
0119   void write(const eff_plot_cache& cache) const {
0120     // Avoid unused variable warnings when building the code without ROOT.
0121     (void)cache;
0122 
0123 #ifdef TRACCC_HAVE_ROOT
0124     cache.track_eff_vs_pT->Write();
0125     cache.track_eff_vs_eta->Write();
0126     cache.track_eff_vs_phi->Write();
0127 #endif  // TRACCC_HAVE_ROOT
0128   }
0129 
0130  private:
0131   config m_cfg;  ///< The Config class
0132 };
0133 
0134 }  // namespace traccc