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 // This is a duplicate of file "duplication_plot_tool.hpp", adapted to "fake
0020 // tracks".
0021 
0022 namespace traccc {
0023 
0024 // Tools for creating "fake tracks" plots to show the proportion of fake tracks
0025 // in the reconstruction data.
0026 //
0027 class fake_tracks_plot_tool {
0028  public:
0029   /// @brief The nested configuration struct
0030   struct config {
0031     std::map<std::string, plot_helpers::binning> var_binning = {
0032         {"Eta", plot_helpers::binning("#eta", 40, -4.f, 4.f)},
0033         {"Phi", plot_helpers::binning("#phi", 100, -3.15f, 3.15f)},
0034         {"Pt", plot_helpers::binning("pT [GeV/c]", 40, 0.f, 100.f)},
0035         {"Num", plot_helpers::binning("N", 30, -0.5f, 29.5f)}};
0036   };
0037 
0038   /// @brief Nested Cache struct
0039   struct fake_tracks_plot_cache {
0040 #ifdef TRACCC_HAVE_ROOT
0041     std::unique_ptr<TProfile> n_fake_vs_pT;   ///< Number of fake tracks vs pT
0042     std::unique_ptr<TProfile> n_fake_vs_eta;  ///< Number of fake tracks vs eta
0043     std::unique_ptr<TProfile> n_fake_vs_phi;  ///< Number of fake tracks vs phi
0044     std::unique_ptr<TEfficiency>
0045         fake_rate_vs_pT;  ///< Tracking fake tracks rate vs pT
0046     std::unique_ptr<TEfficiency>
0047         fake_rate_vs_eta;  ///< Tracking fake tracks rate vs eta
0048     std::unique_ptr<TEfficiency>
0049         fake_rate_vs_phi;  ///< Tracking fake tracks rate vs phi
0050 #endif                     // TRACCC_HAVE_ROOT
0051   };
0052 
0053   /// Constructor
0054   ///
0055   /// @param cfg Configuration struct
0056   fake_tracks_plot_tool(const config& cfg) : m_cfg(cfg) {}
0057 
0058   /// @brief book the fake tracks plots
0059   ///
0060   /// @param fakePlotCache the cache for fake tracks plots
0061   void book(std::string_view name, fake_tracks_plot_cache& cache) const {
0062     plot_helpers::binning b_pt = m_cfg.var_binning.at("Pt");
0063     plot_helpers::binning b_eta = m_cfg.var_binning.at("Eta");
0064     plot_helpers::binning b_phi = m_cfg.var_binning.at("Phi");
0065     plot_helpers::binning b_num = m_cfg.var_binning.at("Num");
0066 
0067     // Avoid unused variable warnings when building the code without ROOT.
0068     (void)name;
0069     (void)cache;
0070 
0071 #ifdef TRACCC_HAVE_ROOT
0072     // fake tracks rate vs pT
0073     cache.fake_rate_vs_pT = plot_helpers::book_eff(
0074         TString(name) + "_fakeTracksRate_vs_pT",
0075         "Fake tracks rate;pT [GeV/c];Fake tracks rate", b_pt);
0076     // fake tracks rate vs eta
0077     cache.fake_rate_vs_eta =
0078         plot_helpers::book_eff(TString(name) + "_fakeTracksRate_vs_eta",
0079                                "Fake tracks rate;#eta;Fake tracks rate", b_eta);
0080     // fake tracks rate vs phi
0081     cache.fake_rate_vs_phi =
0082         plot_helpers::book_eff(TString(name) + "_fakeTracksRate_vs_phi",
0083                                "Fake tracks rate;#phi;Fake tracks rate", b_phi);
0084 
0085     // fake tracks number vs pT
0086     cache.n_fake_vs_pT = plot_helpers::book_prof(
0087         TString(name) + "_nFakeTracks_vs_pT",
0088         "Averaged number of fake tracks per particle", b_pt, b_num);
0089     // fake tracks number vs eta
0090     cache.n_fake_vs_eta = plot_helpers::book_prof(
0091         TString(name) + "_nFakeTracks_vs_eta",
0092         "Averaged number of fake tracks per particle", b_eta, b_num);
0093     // fake tracks number vs phi
0094     cache.n_fake_vs_phi = plot_helpers::book_prof(
0095         TString(name) + "_nFakeTracks_vs_phi",
0096         "Averaged number of fake tracks per particle", b_phi, b_num);
0097 #endif  // TRACCC_HAVE_ROOT
0098   }
0099 
0100   /// @brief fill number of fake tracks for a truth particle seed
0101   ///
0102   /// @param fakePlotCache cache object for fake tracks plots
0103   /// @param truthParticle the truth Particle
0104   /// @param nDuplicatedTracks the number of fake tracks
0105   void fill(fake_tracks_plot_cache& cache, const particle& truth_particle,
0106             size_t n_fake_tracks) const {
0107     const auto t_phi = vector::phi(truth_particle.momentum);
0108     const auto t_eta = vector::eta(truth_particle.momentum);
0109     const auto t_pT = vector::perp(
0110         vector2{truth_particle.momentum[0], truth_particle.momentum[1]});
0111 
0112     // Avoid unused variable warnings when building the code without ROOT.
0113     (void)t_phi;
0114     (void)t_eta;
0115     (void)t_pT;
0116     (void)cache;
0117     (void)n_fake_tracks;
0118 
0119 #ifdef TRACCC_HAVE_ROOT
0120     cache.n_fake_vs_pT->Fill(t_pT, static_cast<double>(n_fake_tracks));
0121     cache.n_fake_vs_eta->Fill(t_eta, static_cast<double>(n_fake_tracks));
0122     cache.n_fake_vs_phi->Fill(t_phi, static_cast<double>(n_fake_tracks));
0123 #endif  // TRACCC_HAVE_ROOT
0124   }
0125 
0126   /// @brief write the fake tracks plots to file
0127   ///
0128   /// @param fakePlotCache cache object for fake tracks plots
0129   void write(const fake_tracks_plot_cache& cache) const {
0130     // Avoid unused variable warnings when building the code without ROOT.
0131     (void)cache;
0132 
0133 #ifdef TRACCC_HAVE_ROOT
0134     cache.fake_rate_vs_pT->Write();
0135     cache.fake_rate_vs_eta->Write();
0136     cache.fake_rate_vs_phi->Write();
0137     cache.n_fake_vs_pT->Write();
0138     cache.n_fake_vs_eta->Write();
0139     cache.n_fake_vs_phi->Write();
0140 #endif  // TRACCC_HAVE_ROOT
0141   }
0142 
0143  private:
0144   config m_cfg;  ///< The Config class
0145 };
0146 
0147 }  // namespace traccc