Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 07:59:43

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/BoundTrackParameters.hpp"
0012 #include "Acts/EventData/SubspaceHelpers.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 #include "Acts/Utilities/Histogram.hpp"
0015 #include "Acts/Utilities/Logger.hpp"
0016 #include "ActsExamples/EventData/SimParticle.hpp"
0017 
0018 #include <map>
0019 #include <memory>
0020 #include <string>
0021 #include <vector>
0022 
0023 namespace ActsExamples {
0024 
0025 /// Tools to make hists to show residual, i.e. smoothed_parameter -
0026 /// truth_parameter, and pull, i.e. (smoothed_parameter -
0027 /// truth_parameter)/smoothed_paramter_error, of bound track parameters
0028 class ResPlotTool {
0029  public:
0030   using AxisVariant = Acts::Experimental::AxisVariant;
0031   using BoostRegularAxis = Acts::Experimental::BoostRegularAxis;
0032   using Histogram1 = Acts::Experimental::Histogram1;
0033   using Histogram2 = Acts::Experimental::Histogram2;
0034   using Histogram3 = Acts::Experimental::Histogram3;
0035 
0036   /// @brief Nested configuration struct
0037   struct Config {
0038     /// Track parameter names, one per bound parameter.
0039     ///
0040     /// Empty by default because the first two depend on the surface the
0041     /// parameters are expressed on: `d0`/`z0` on a perigee, `loc0`/`loc1` on
0042     /// a sensor. The caller has to fill them in.
0043     std::vector<std::string> paramNames;
0044 
0045     std::string qOverPtName = "qopt";
0046     std::string relQoverPtName = "qopt_rel";
0047 
0048     /// Binning info for variables
0049     std::map<std::string, AxisVariant> varBinning = {
0050         {"Eta", BoostRegularAxis(40, -4, 4, "#eta")},
0051         {"Phi", BoostRegularAxis(40, -std::numbers::pi, std::numbers::pi,
0052                                  "#phi [rad]")},
0053         {"Pt", BoostRegularAxis(40, 0, 100, "pT [GeV/c]")},
0054         {"Pull", BoostRegularAxis(100, -5, 5, "pull")},
0055         {"Residual_d0", BoostRegularAxis(100, -0.5, 0.5, "r_{d0} [mm]")},
0056         {"Residual_z0", BoostRegularAxis(100, -0.5, 0.5, "r_{z0} [mm]")},
0057         {"Residual_loc0", BoostRegularAxis(100, -0.5, 0.5, "r_{loc0} [mm]")},
0058         {"Residual_loc1", BoostRegularAxis(100, -0.5, 0.5, "r_{loc1} [mm]")},
0059         {"Residual_phi", BoostRegularAxis(100, -0.01, 0.01, "r_{#phi} [rad]")},
0060         {"Residual_theta",
0061          BoostRegularAxis(100, -0.01, 0.01, "r_{#theta} [rad]")},
0062         {"Residual_qop", BoostRegularAxis(100, -0.1, 0.1, "r_{q/p} [c/GeV]")},
0063         {"Residual_t", BoostRegularAxis(100, -100, 100, "r_{t} [mm/c]")},
0064         {"Residual_qopt", BoostRegularAxis(100, -0.1, 0.1, "r_{q/pT} [c/GeV]")},
0065         {"Residual_qopt_rel",
0066          BoostRegularAxis(100, -0.1, 0.1, "r_{rel q/pT} [%]")}};
0067   };
0068 
0069   /// Quantities the histograms are binned in. Each `fill` overload derives
0070   /// them from its own inputs to avoid lossy conversions.
0071   struct Binning {
0072     double eta;
0073     double phi;
0074     double pt;
0075   };
0076 
0077   /// @param cfg Configuration struct
0078   /// @param level Message level declaration
0079   ResPlotTool(const Config& cfg, Acts::Logging::Level lvl);
0080 
0081   /// @param gctx the geometry context
0082   /// @param truthParticle the truth particle
0083   /// @param fittedParamters the fitted parameters at perigee surface
0084   void fill(const Acts::GeometryContext& gctx,
0085             const SimParticleState& truthParticle,
0086             const Acts::BoundTrackParameters& fittedParamters);
0087 
0088   /// Fill from truth parameters on the same surface as the fitted ones.
0089   ///
0090   /// @param truthParameters the truth bound parameters
0091   /// @param fittedParameters the fitted parameters
0092   void fill(const Acts::BoundTrackParameters& truthParameters,
0093             const Acts::BoundTrackParameters& fittedParameters);
0094 
0095   /// Fill the residual and pull of a subset of the bound parameters.
0096   ///
0097   /// For references that constrain only part of the parameters, e.g. a
0098   /// measurement. Parameters outside @p subspace are left untouched, and the
0099   /// derived `q/pT` histograms are never filled since they need theta and
0100   /// q/p.
0101   ///
0102   /// @param binning the quantities to bin the histograms in
0103   /// @param subspace the bound parameters to fill
0104   /// @param residuals the residual per bound index; only @p subspace is read
0105   /// @param residualCovariance the covariance of @p residuals; only the
0106   ///        diagonal entries of @p subspace are read
0107   void fill(const Binning& binning,
0108             const Acts::VariableBoundSubspaceHelper& subspace,
0109             const Acts::BoundVector& residuals,
0110             const Acts::BoundMatrix& residualCovariance);
0111 
0112   const std::map<std::string, Histogram1>& res() const { return m_res; }
0113   const std::map<std::string, Histogram2>& resVsEta() const {
0114     return m_resVsEta;
0115   }
0116   const std::map<std::string, Histogram2>& resVsPt() const { return m_resVsPt; }
0117   const std::map<std::string, Histogram3>& resVsEtaPhi() const {
0118     return m_resVsEtaPhi;
0119   }
0120   const std::map<std::string, Histogram3>& resVsEtaPt() const {
0121     return m_resVsEtaPt;
0122   }
0123   const std::map<std::string, Histogram1>& pull() const { return m_pull; }
0124   const std::map<std::string, Histogram2>& pullVsEta() const {
0125     return m_pullVsEta;
0126   }
0127   const std::map<std::string, Histogram2>& pullVsPt() const {
0128     return m_pullVsPt;
0129   }
0130   const std::map<std::string, Histogram3>& pullVsEtaPhi() const {
0131     return m_pullVsEtaPhi;
0132   }
0133   const std::map<std::string, Histogram3>& pullVsEtaPt() const {
0134     return m_pullVsEtaPt;
0135   }
0136 
0137  private:
0138   Config m_cfg;
0139 
0140   std::unique_ptr<const Acts::Logger> m_logger;
0141 
0142   /// Residual distribution
0143   std::map<std::string, Histogram1> m_res;
0144   /// Residual vs eta scatter plot
0145   std::map<std::string, Histogram2> m_resVsEta;
0146   /// Residual vs pT scatter plot
0147   std::map<std::string, Histogram2> m_resVsPt;
0148   /// Residual vs eta-phi scatter plot
0149   std::map<std::string, Histogram3> m_resVsEtaPhi;
0150   /// Residual vs eta-pT scatter plot
0151   std::map<std::string, Histogram3> m_resVsEtaPt;
0152 
0153   /// Pull distribution
0154   std::map<std::string, Histogram1> m_pull;
0155   /// Pull vs eta scatter plot
0156   std::map<std::string, Histogram2> m_pullVsEta;
0157   /// Pull vs pT scatter plot
0158   std::map<std::string, Histogram2> m_pullVsPt;
0159   /// Pull vs eta-phi scatter plot
0160   std::map<std::string, Histogram3> m_pullVsEtaPhi;
0161   /// Pull vs eta-pT scatter plot
0162   std::map<std::string, Histogram3> m_pullVsEtaPt;
0163 
0164   void fill(const Acts::BoundVector& truthVector, const Binning& binning,
0165             double truthCharge, double truthAbsCharge,
0166             const Acts::BoundTrackParameters& fittedParameters);
0167 
0168   void fillResidual(const std::string& paramName, double residual,
0169                     double truthEta, double truthPhi, double truthPt);
0170   void fillPull(const std::string& paramName, double pull, double truthEta,
0171                 double truthPhi, double truthPt);
0172 
0173   const Acts::Logger& logger() const { return *m_logger; }
0174 };
0175 
0176 }  // namespace ActsExamples