** Warning **

Issuing rollback() due to DESTROY without explicit disconnect() of DBD::mysql::db handle dbname=lxr_eic at /usr/local/share/lxr/lxr-2.3.7/lib/LXR/Common.pm line 1161, <GEN335> line 1.

Last-Modified: Thu, 26 Aug 2026 09:32:49 GMT Content-Type: text/html; charset=utf-8 /master/acts/Examples/Framework/include/ActsExamples/Validation/TrackParameterPerformanceCollector.hpp
Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-26 08:20:24

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/Geometry/GeometryContext.hpp"
0012 #include "Acts/Geometry/GeometryHierarchyMap.hpp"
0013 #include "Acts/Geometry/GeometryIdentifier.hpp"
0014 #include "Acts/Utilities/Histogram.hpp"
0015 #include "Acts/Utilities/Logger.hpp"
0016 #include "ActsExamples/EventData/SimHit.hpp"
0017 #include "ActsExamples/EventData/SimParticle.hpp"
0018 #include "ActsExamples/EventData/Track.hpp"
0019 #include "ActsExamples/EventData/TruthMatching.hpp"
0020 #include "ActsExamples/Validation/EffPlotTool.hpp"
0021 #include "ActsExamples/Validation/HistogramFit.hpp"
0022 #include "ActsExamples/Validation/ParametersOnSurface.hpp"
0023 #include "ActsExamples/Validation/ResPlotTool.hpp"
0024 #include "ActsExamples/Validation/TrackSummaryPlotTool.hpp"
0025 
0026 #include <cstddef>
0027 #include <map>
0028 #include <optional>
0029 #include <string>
0030 #include <vector>
0031 
0032 namespace ActsExamples {
0033 
0034 /// Where to take the reconstructed parameters from.
0035 enum class TrackParameterSource {
0036   /// The track parameters at the track reference surface, i.e. the fitter
0037   /// output as delivered.
0038   Track,
0039   /// The parameters of the individual track states, on the surface they sit
0040   /// on. Compared against the simulated hits of the state's measurement.
0041   TrackState,
0042 };
0043 
0044 /// Collects performance histograms of the track parameters, without any file
0045 /// I/O.
0046 ///
0047 /// Collects residual/pull histograms, efficiency plots, and track summary
0048 /// information for track fitting performance evaluation. The Gaussian fit
0049 /// backend is supplied by the caller via @c Config::fitFunction.
0050 ///
0051 /// With `parameterSource = Track` the track parameters at the track reference
0052 /// surface are compared to the truth particle. With `TrackState` every
0053 /// selected measurement state is compared to the truth on its own surface,
0054 /// which is what makes per-sensor estimates, e.g. from a seed, measurable.
0055 ///
0056 /// @note The caller must ensure exclusive access (e.g. hold a mutex) when
0057 ///       calling fill(). This class applies no locking of its own.
0058 class TrackParameterPerformanceCollector {
0059  public:
0060   struct Config {
0061     ResPlotTool::Config resPlotToolConfig;
0062     EffPlotTool::Config effPlotToolConfig;
0063     TrackSummaryPlotTool::Config trackSummaryPlotToolConfig;
0064 
0065     /// Where to take the reconstructed parameters from.
0066     TrackParameterSource parameterSource = TrackParameterSource::Track;
0067     /// Which track-state parameters to use. If not set, the best available
0068     /// ones (smoothed, filtered, or predicted). `TrackState` source only.
0069     std::optional<TrackParameterType> parameterType;
0070     /// If non-empty, only track states in these geometry regions are used.
0071     /// `TrackState` source only.
0072     std::vector<Acts::GeometryIdentifier> geometrySelection;
0073 
0074     /// The Gaussian fit backend used by @c fitProfiles. If unset,
0075     /// @c fitProfiles logs a warning and returns no profiles.
0076     HistogramFitFunction fitFunction;
0077 
0078     /// Minimum number of entries in a bin for it to be included in the
0079     /// mean/width fit.
0080     int fitMinEntries = 10;
0081     /// The range in sigma for the iterative Gaussian fit
0082     double fitSigmaRange = 3.0;
0083     /// The maximum number of iterations for the iterative Gaussian fit
0084     int fitIterations = 3;
0085     /// Threshold for warning about fit failure fraction in profile
0086     /// extraction.
0087     double warningThresholdFitFailureFraction = 0.55;
0088   };
0089 
0090   TrackParameterPerformanceCollector(
0091       Config cfg, std::unique_ptr<const Acts::Logger> logger);
0092 
0093   /// Fill histograms for one event.
0094   ///
0095   /// @param geoContext the geometry context
0096   /// @param tracks the input tracks
0097   /// @param particles the truth particles
0098   /// @param trackParticleMatching the track to particle matching
0099   /// @param simHits the simulated hits, required for `TrackState`
0100   /// @param measurementSimHitsMap the measurement to simulated hits map,
0101   ///        required for `TrackState`
0102   ///
0103   /// @note The caller must ensure exclusive access (e.g. hold a mutex).
0104   void fill(const Acts::GeometryContext& geoContext,
0105             const ConstTrackContainer& tracks,
0106             const SimParticleContainer& particles,
0107             const TrackParticleMatching& trackParticleMatching,
0108             const SimHitContainer* simHits = nullptr,
0109             const MeasurementSimHitsMap* measurementSimHitsMap = nullptr);
0110 
0111   /// Summary count statistics accumulated across all filled events.
0112   struct Stats {
0113     std::size_t nTotalTracks = 0;
0114     std::size_t nTotalMatchedTracks = 0;
0115     std::size_t nTotalFakeTracks = 0;
0116     std::size_t nTotalParticles = 0;
0117     std::size_t nTotalMatchedParticles = 0;
0118     /// Track states skipped for lack of the requested parameters.
0119     std::size_t nMissingStateParameters = 0;
0120     /// Track states skipped for lack of truth hits.
0121     std::size_t nMissingStateTruth = 0;
0122   };
0123 
0124   /// Return accumulated event counts.
0125   const Stats& stats() const { return m_stats; }
0126 
0127   /// Emit summary statistics via the internal logger.
0128   void logSummary() const;
0129 
0130   /// @name Accessors for the underlying plot tools
0131   /// @{
0132   const ResPlotTool& resPlotTool() const { return m_resPlotTool; }
0133   const EffPlotTool& effPlotTool() const { return m_effPlotTool; }
0134   const TrackSummaryPlotTool& trackSummaryPlotTool() const {
0135     return m_trackSummaryPlotTool;
0136   }
0137   /// @}
0138 
0139   /// Mean/width profiles fitted from every residual and pull histogram.
0140   ///
0141   /// @c profiles1 holds the 2D (vs. eta, vs. pT) outputs; @c profiles2 the
0142   /// 3D (vs. eta-phi, vs. eta-pT) ones.
0143   struct FittedProfiles {
0144     std::vector<Acts::Experimental::Histogram1> profiles1;
0145     std::vector<Acts::Experimental::Histogram2> profiles2;
0146   };
0147 
0148   /// Fit every residual/pull profile histogram with @c Config::fitFunction.
0149   ///
0150   /// Warns if a histogram's fit failure fraction reaches
0151   /// @c Config::warningThresholdFitFailureFraction.
0152   FittedProfiles fitProfiles() const;
0153 
0154  private:
0155   const Acts::Logger& logger() const { return *m_logger; }
0156 
0157   /// Fill the residuals of the selected measurement states of one track
0158   /// against the truth on their own surfaces.
0159   void fillTrackStates(const Acts::GeometryContext& geoContext,
0160                        const ConstTrackProxy& track,
0161                        const SimParticle& particle,
0162                        const SimHitContainer& simHits,
0163                        const MeasurementSimHitsMap& measurementSimHitsMap);
0164 
0165   /// Fit every histogram in @p histMap and append the resulting mean/width
0166   /// profiles to @p out, warning on excessive fit failures.
0167   template <std::size_t Dim>
0168   void addFittedProfiles(
0169       const std::map<std::string, Acts::Experimental::Histogram<Dim>>& histMap,
0170       const std::string& meanPrefix, const std::string& widthPrefix,
0171       std::vector<Acts::Experimental::Histogram<Dim - 1>>& out) const;
0172 
0173   Config m_cfg;
0174   std::unique_ptr<const Acts::Logger> m_logger;
0175 
0176   ResPlotTool m_resPlotTool;
0177   EffPlotTool m_effPlotTool;
0178   TrackSummaryPlotTool m_trackSummaryPlotTool;
0179 
0180   Acts::GeometryHierarchyMap<unsigned int> m_geometrySelection;
0181 
0182   Stats m_stats;
0183 };
0184 
0185 }  // namespace ActsExamples