Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:48

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 namespace ActsFatras {
0025 class Particle;
0026 }  // namespace ActsFatras
0027 
0028 namespace ActsExamples {
0029 
0030 // Tools to make hists to show residual, i.e. smoothed_parameter -
0031 // truth_parameter, and pull, i.e. (smoothed_parameter -
0032 // truth_parameter)/smoothed_paramter_error, of track parameters at perigee
0033 // surface
0034 class ResPlotTool {
0035  public:
0036   /// @brief Nested configuration struct
0037   struct Config {
0038     /// parameter sets to do plots
0039     std::vector<std::string> paramNames = {"d0",    "z0",  "phi",
0040                                            "theta", "qop", "t"};
0041 
0042     /// Binning info for variables
0043     std::map<std::string, PlotHelpers::Binning> varBinning = {
0044         {"Eta", PlotHelpers::Binning("#eta", 40, -4, 4)},
0045         {"Pt", PlotHelpers::Binning("pT [GeV/c]", 40, 0, 100)},
0046         {"Pull", PlotHelpers::Binning("pull", 100, -5, 5)},
0047         {"Residual_d0", PlotHelpers::Binning("r_{d0} [mm]", 100, -0.5, 0.5)},
0048         {"Residual_z0", PlotHelpers::Binning("r_{z0} [mm]", 100, -0.5, 0.5)},
0049         {"Residual_phi",
0050          PlotHelpers::Binning("r_{#phi} [rad]", 100, -0.01, 0.01)},
0051         {"Residual_theta",
0052          PlotHelpers::Binning("r_{#theta} [rad]", 100, -0.01, 0.01)},
0053         {"Residual_qop",
0054          PlotHelpers::Binning("r_{q/p} [c/GeV]", 100, -0.1, 0.1)},
0055         {"Residual_t", PlotHelpers::Binning("r_{t} [s]", 100, -1000, 1000)}};
0056   };
0057 
0058   /// @brief Nested Cache struct
0059   struct ResPlotCache {
0060     std::map<std::string, TH1F*> res;         ///< Residual distribution
0061     std::map<std::string, TH2F*> res_vs_eta;  ///< Residual vs eta scatter plot
0062     std::map<std::string, TH1F*>
0063         resMean_vs_eta;  ///< Residual mean vs eta distribution
0064     std::map<std::string, TH1F*>
0065         resWidth_vs_eta;  ///< Residual width vs eta distribution
0066     std::map<std::string, TH2F*> res_vs_pT;  ///< Residual vs pT scatter plot
0067     std::map<std::string, TH1F*>
0068         resMean_vs_pT;  ///< Residual mean vs pT distribution
0069     std::map<std::string, TH1F*>
0070         resWidth_vs_pT;  ///< Residual width vs pT distribution
0071 
0072     std::map<std::string, TH1F*> pull;         ///< Pull distribution
0073     std::map<std::string, TH2F*> pull_vs_eta;  ///< Pull vs eta scatter plot
0074     std::map<std::string, TH1F*>
0075         pullMean_vs_eta;  ///< Pull mean vs eta distribution
0076     std::map<std::string, TH1F*>
0077         pullWidth_vs_eta;  ///< Pull width vs eta distribution
0078     std::map<std::string, TH2F*> pull_vs_pT;  ///< Pull vs pT scatter plot
0079     std::map<std::string, TH1F*>
0080         pullMean_vs_pT;  ///< Pull mean vs pT distribution
0081     std::map<std::string, TH1F*>
0082         pullWidth_vs_pT;  ///< Pull width vs pT distribution
0083   };
0084 
0085   /// Constructor
0086   ///
0087   /// @param cfg Configuration struct
0088   /// @param level Message level declaration
0089   ResPlotTool(const Config& cfg, Acts::Logging::Level lvl);
0090 
0091   /// @brief book the histograms
0092   ///
0093   /// @param resPlotCache the cache for residual/pull histograms
0094   void book(ResPlotCache& resPlotCache) const;
0095 
0096   /// @brief fill the histograms
0097   ///
0098   /// @param resPlotCache the cache for residual/pull histograms
0099   /// @param gctx the geometry context
0100   /// @param truthParticle the truth particle
0101   /// @param fittedParamters the fitted parameters at perigee surface
0102   void fill(ResPlotCache& resPlotCache, const Acts::GeometryContext& gctx,
0103             const SimParticleState& truthParticle,
0104             const Acts::BoundTrackParameters& fittedParamters) const;
0105 
0106   /// @brief extract the details of the residual/pull plots and fill details
0107   ///
0108   /// into separate histograms
0109   /// @param resPlotCache the cache object for residual/pull histograms
0110   void refinement(ResPlotCache& resPlotCache) const;
0111 
0112   /// @brief write the histograms to output file
0113   ///
0114   /// @param resPlotCache the cache object for residual/pull histograms
0115   void write(const ResPlotCache& resPlotCache) const;
0116 
0117   /// @brief delete the histograms
0118   ///
0119   /// @param resPlotCache the cache object for residual/pull histograms
0120   void clear(ResPlotCache& resPlotCache) const;
0121 
0122  private:
0123   Config m_cfg;                                  ///< The config class
0124   std::unique_ptr<const Acts::Logger> m_logger;  ///< The logging instance
0125 
0126   /// The logger
0127   const Acts::Logger& logger() const { return *m_logger; }
0128 };
0129 
0130 }  // namespace ActsExamples