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 duplication rate and duplication number plots to show tracking
0022 // duplication.
0023 //
0024 // The duplication is investigated for those truth-matched reco tracks. If there
0025 // are a few reco tracks matched to the same truth particle, the reco track with
0026 // the highest matching probability is tagges as 'real' and the others are
0027 // 'duplicated'.
0028 class duplication_plot_tool {
0029  public:
0030   /// @brief The nested configuration struct
0031   struct config {
0032     std::map<std::string, plot_helpers::binning> var_binning = {
0033         {"Eta", plot_helpers::binning("#eta", 40, -4.f, 4.f)},
0034         {"Phi", plot_helpers::binning("#phi", 100, -3.15f, 3.15f)},
0035         {"Pt", plot_helpers::binning("pT [GeV/c]", 40, 0.f, 100.f)},
0036         {"Num", plot_helpers::binning("N", 30, -0.5f, 29.5f)}};
0037   };
0038 
0039   /// @brief Nested Cache struct
0040   struct duplication_plot_cache {
0041 #ifdef TRACCC_HAVE_ROOT
0042     std::unique_ptr<TProfile>
0043         n_duplicated_vs_pT;  ///< Number of duplicated tracks vs pT
0044     std::unique_ptr<TProfile>
0045         n_duplicated_vs_eta;  ///< Number of duplicated tracks vs eta
0046     std::unique_ptr<TProfile>
0047         n_duplicated_vs_phi;  ///< Number of duplicated tracks vs phi
0048     std::unique_ptr<TEfficiency>
0049         duplication_rate_vs_pT;  ///< Tracking duplication rate vs pT
0050     std::unique_ptr<TEfficiency>
0051         duplication_rate_vs_eta;  ///< Tracking duplication rate vs eta
0052     std::unique_ptr<TEfficiency>
0053         duplication_rate_vs_phi;  ///< Tracking duplication rate vs phi
0054 #endif                            // TRACCC_HAVE_ROOT
0055   };
0056 
0057   /// Constructor
0058   ///
0059   /// @param cfg Configuration struct
0060   duplication_plot_tool(const config& cfg) : m_cfg(cfg) {}
0061 
0062   /// @brief book the duplication plots
0063   ///
0064   /// @param duplicationPlotCache the cache for duplication plots
0065   void book(std::string_view name, duplication_plot_cache& cache) const {
0066     plot_helpers::binning b_pt = m_cfg.var_binning.at("Pt");
0067     plot_helpers::binning b_eta = m_cfg.var_binning.at("Eta");
0068     plot_helpers::binning b_phi = m_cfg.var_binning.at("Phi");
0069     plot_helpers::binning b_num = m_cfg.var_binning.at("Num");
0070 
0071     // Avoid unused variable warnings when building the code without ROOT.
0072     (void)name;
0073     (void)cache;
0074 
0075 #ifdef TRACCC_HAVE_ROOT
0076     // duplication rate vs pT
0077     cache.duplication_rate_vs_pT = plot_helpers::book_eff(
0078         TString(name) + "_duplicationRate_vs_pT",
0079         "Duplication rate;pT [GeV/c];Duplication rate", b_pt);
0080     // duplication rate vs eta
0081     cache.duplication_rate_vs_eta =
0082         plot_helpers::book_eff(TString(name) + "_duplicationRate_vs_eta",
0083                                "Duplication rate;#eta;Duplication rate", b_eta);
0084     // duplication rate vs phi
0085     cache.duplication_rate_vs_phi =
0086         plot_helpers::book_eff(TString(name) + "_duplicationRate_vs_phi",
0087                                "Duplication rate;#phi;Duplication rate", b_phi);
0088 
0089     // duplication number vs pT
0090     cache.n_duplicated_vs_pT = plot_helpers::book_prof(
0091         TString(name) + "_nDuplicated_vs_pT",
0092         "Number of duplicated track candidates", b_pt, b_num);
0093     // duplication number vs eta
0094     cache.n_duplicated_vs_eta = plot_helpers::book_prof(
0095         TString(name) + "_nDuplicated_vs_eta",
0096         "Number of duplicated track candidates", b_eta, b_num);
0097     // duplication number vs phi
0098     cache.n_duplicated_vs_phi = plot_helpers::book_prof(
0099         TString(name) + "_nDuplicated_vs_phi",
0100         "Number of duplicated track candidates", b_phi, b_num);
0101 #endif  // TRACCC_HAVE_ROOT
0102   }
0103 
0104   /// @brief fill number of duplicated tracks for a truth particle seed
0105   ///
0106   /// @param duplicationPlotCache cache object for duplication plots
0107   /// @param truthParticle the truth Particle
0108   /// @param nDuplicatedTracks the number of duplicated tracks
0109   void fill(duplication_plot_cache& cache, const particle& truth_particle,
0110             size_t n_duplicated_tracks) const {
0111     const auto t_phi = vector::phi(truth_particle.momentum);
0112     const auto t_eta = vector::eta(truth_particle.momentum);
0113     const auto t_pT = vector::perp(
0114         vector2{truth_particle.momentum[0], truth_particle.momentum[1]});
0115 
0116     // Avoid unused variable warnings when building the code without ROOT.
0117     (void)t_phi;
0118     (void)t_eta;
0119     (void)t_pT;
0120     (void)cache;
0121     (void)n_duplicated_tracks;
0122 
0123 #ifdef TRACCC_HAVE_ROOT
0124     cache.n_duplicated_vs_pT->Fill(t_pT,
0125                                    static_cast<double>(n_duplicated_tracks));
0126     cache.n_duplicated_vs_eta->Fill(t_eta,
0127                                     static_cast<double>(n_duplicated_tracks));
0128     cache.n_duplicated_vs_phi->Fill(t_phi,
0129                                     static_cast<double>(n_duplicated_tracks));
0130 #endif  // TRACCC_HAVE_ROOT
0131   }
0132 
0133   /// @brief write the duplication plots to file
0134   ///
0135   /// @param duplicationPlotCache cache object for duplication plots
0136   void write(const duplication_plot_cache& cache) const {
0137     // Avoid unused variable warnings when building the code without ROOT.
0138     (void)cache;
0139 
0140 #ifdef TRACCC_HAVE_ROOT
0141     cache.duplication_rate_vs_pT->Write();
0142     cache.duplication_rate_vs_eta->Write();
0143     cache.duplication_rate_vs_phi->Write();
0144     cache.n_duplicated_vs_pT->Write();
0145     cache.n_duplicated_vs_eta->Write();
0146     cache.n_duplicated_vs_phi->Write();
0147 #endif  // TRACCC_HAVE_ROOT
0148   }
0149 
0150  private:
0151   config m_cfg;  ///< The Config class
0152 };
0153 
0154 }  // namespace traccc