Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:23:46

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/EventData/TrackParameters.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "Acts/Utilities/Logger.hpp"
0014 #include "ActsExamples/EventData/SimParticle.hpp"
0015 #include "ActsExamples/Utilities/Helpers.hpp"
0016 
0017 #include <map>
0018 #include <memory>
0019 #include <string>
0020 #include <vector>
0021 
0022 class TH1F;
0023 class TH2F;
0024 
0025 namespace ActsExamples {
0026 
0027 /// Tools to make hists to show residual, i.e. smoothed_parameter -
0028 /// truth_parameter, and pull, i.e. (smoothed_parameter -
0029 /// truth_parameter)/smoothed_paramter_error, of track parameters at perigee
0030 /// surface
0031 class ResPlotTool {
0032  public:
0033   /// @brief Nested configuration struct
0034   struct Config {
0035     /// parameter sets to do plots
0036     std::vector<std::string> paramNames = {"d0",    "z0",  "phi",
0037                                            "theta", "qop", "t"};
0038 
0039     /// Binning info for variables
0040     std::map<std::string, PlotHelpers::Binning> varBinning = {
0041         {"Eta", PlotHelpers::Binning::Uniform("#eta", 40, -4, 4)},
0042         {"Pt", PlotHelpers::Binning::Uniform("pT [GeV/c]", 40, 0, 100)},
0043         {"Pull", PlotHelpers::Binning::Uniform("pull", 100, -5, 5)},
0044         {"Residual_d0",
0045          PlotHelpers::Binning::Uniform("r_{d0} [mm]", 100, -0.5, 0.5)},
0046         {"Residual_z0",
0047          PlotHelpers::Binning::Uniform("r_{z0} [mm]", 100, -0.5, 0.5)},
0048         {"Residual_phi",
0049          PlotHelpers::Binning::Uniform("r_{#phi} [rad]", 100, -0.01, 0.01)},
0050         {"Residual_theta",
0051          PlotHelpers::Binning::Uniform("r_{#theta} [rad]", 100, -0.01, 0.01)},
0052         {"Residual_qop",
0053          PlotHelpers::Binning::Uniform("r_{q/p} [c/GeV]", 100, -0.1, 0.1)},
0054         {"Residual_t",
0055          PlotHelpers::Binning::Uniform("r_{t} [s]", 100, -1000, 1000)}};
0056   };
0057 
0058   /// @brief Nested Cache struct
0059   struct Cache {
0060     /// Residual distribution
0061     std::map<std::string, TH1F*> res;
0062     /// Residual vs eta scatter plot
0063     std::map<std::string, TH2F*> res_vs_eta;
0064     /// Residual mean vs eta distribution
0065     std::map<std::string, TH1F*> resMean_vs_eta;
0066     /// Residual width vs eta distribution
0067     std::map<std::string, TH1F*> resWidth_vs_eta;
0068     /// Residual vs pT scatter plot
0069     std::map<std::string, TH2F*> res_vs_pT;
0070     /// Residual mean vs pT distribution
0071     std::map<std::string, TH1F*> resMean_vs_pT;
0072     /// Residual width vs pT distribution
0073     std::map<std::string, TH1F*> resWidth_vs_pT;
0074 
0075     /// Pull distribution
0076     std::map<std::string, TH1F*> pull;
0077     /// Pull vs eta scatter plot
0078     std::map<std::string, TH2F*> pull_vs_eta;
0079     /// Pull mean vs eta distribution
0080     std::map<std::string, TH1F*> pullMean_vs_eta;
0081     /// Pull width vs eta distribution
0082     std::map<std::string, TH1F*> pullWidth_vs_eta;
0083     /// Pull vs pT scatter plot
0084     std::map<std::string, TH2F*> pull_vs_pT;
0085     /// Pull mean vs pT distribution
0086     std::map<std::string, TH1F*> pullMean_vs_pT;
0087     /// Pull width vs pT distribution
0088     std::map<std::string, TH1F*> pullWidth_vs_pT;
0089   };
0090 
0091   /// Constructor
0092   ///
0093   /// @param cfg Configuration struct
0094   /// @param level Message level declaration
0095   ResPlotTool(const Config& cfg, Acts::Logging::Level lvl);
0096 
0097   /// @brief book the histograms
0098   ///
0099   /// @param cache the cache for residual/pull histograms
0100   void book(Cache& cache) const;
0101 
0102   /// @brief fill the histograms
0103   ///
0104   /// @param cache the cache for residual/pull histograms
0105   /// @param gctx the geometry context
0106   /// @param truthParticle the truth particle
0107   /// @param fittedParamters the fitted parameters at perigee surface
0108   void fill(Cache& cache, const Acts::GeometryContext& gctx,
0109             const SimParticleState& truthParticle,
0110             const Acts::BoundTrackParameters& fittedParamters) const;
0111 
0112   /// @brief extract the details of the residual/pull plots and fill details
0113   ///
0114   /// into separate histograms
0115   /// @param cache the cache object for residual/pull histograms
0116   void refinement(Cache& cache) const;
0117 
0118   /// @brief write the histograms to output file
0119   ///
0120   /// @param cache the cache object for residual/pull histograms
0121   void write(const Cache& cache) const;
0122 
0123   /// @brief delete the histograms
0124   ///
0125   /// @param cache the cache object for residual/pull histograms
0126   void clear(Cache& cache) const;
0127 
0128  private:
0129   /// The config class
0130   Config m_cfg;
0131   /// The logging instance
0132   std::unique_ptr<const Acts::Logger> m_logger;
0133 
0134   /// The logger
0135   const Acts::Logger& logger() const { return *m_logger; }
0136 };
0137 
0138 }  // namespace ActsExamples