5#ifndef ACTSTRK_TRACKTRUTHMATCHINGBASEALG_H
6#define ACTSTRK_TRACKTRUTHMATCHINGBASEALG_H 1
12#include "Gaudi/Property.h"
45 template <
bool DetailEnabled>
48 template <
bool DetailEnabled>
52 using AthReentrantAlgorithm::AthReentrantAlgorithm;
55 virtual StatusCode
finalize()
override;
62 throw std::runtime_error(
"Failed to get truth particle hit count map");
64 return *truth_particle_hit_counts_handle;
67 return m_detailedStat.perEtaSize();
70 return m_detailedStat.perPdgIdSize();
73 template <
bool DetailEnabled>
75 static constexpr bool doDetail = DetailEnabled;
78 std::size_t per_eta_size,
79 std::size_t per_pdg_size,
80 [[maybe_unused]] std::size_t track_to_truth_size)
81 :
BaseStat<DetailEnabled>(truth_selection_tool, per_eta_size, per_pdg_size),
84 if constexpr(DetailEnabled) {
89 void fill([[maybe_unused]]
unsigned int eta_category_i,
90 [[maybe_unused]]
unsigned int pdg_id_category_i,
91 [[maybe_unused]]
float hit_efficiency,
92 [[maybe_unused]]
float hit_purity,
93 [[maybe_unused]]
float match_prob,
100 if constexpr(DetailEnabled) {
113 std::unordered_set<const xAOD::TruthParticle *>,
143 std::size_t n_tracks,
146 ToolHandle<IAthSelectionTool>
m_truthSelectionTool{
this,
"TruthSelectionTool",
"AthTruthSelectionTool",
"Truth selection tool (for efficiencies and resolutions)"};
149 {
this,
"TruthParticleHitCounts",
"",
"Map from truth particle to hit counts." };
153 "Weights applied to the counts per measurement type for weighted sums"
154 " which are used compute the match probability." };
157 "Weights applied to the counts per measurement type for weighted sums"
158 " which are used to compute hit efficiencies and purities." };
160 {
this,
"TruthLinkedFakeRate",
false,
"Compute the match probability from the truth-linked measurements only:"
161 " measurements without truth particle weigh 1 and cannot be the best match, so a"
162 " track made only of them has probability 0. By default the probability is"
163 " computed the way the legacy truth matching does (DetailedTrackTruthBuilder,"
164 " TruthMatchRatio): measurements without truth particle keep their full weight and"
165 " together compete for the best match as one pseudo particle; if it wins, the"
166 " probability is their weighted fraction and there is no matching truth particle." };
168 {
this,
"StatisticEtaBins", {-4, -2.6, -2, 0, 2., 2.6, 4},
"Gather statistics separately for these eta bins."};
170 {
this,
"StatisticPtBins", {1.e3,2.5e3,10e3, 100e3},
"Gather statistics separately for these pt bins."};
172 {
this,
"PdgIdCategorisation",
false,
"Categorise by pdg id."};
174 {
this,
"ShowRawCounts",
false,
"Show all counters."};
176 {
this,
"ShowDetailedTables",
false,
"Show more details; stat. uncert., RMS, entries"};
178 {
this,
"ComputeTrackRecoEfficiency",
true,
"Compute and print track reconstruction efficiency."};
181 template <
bool IsDebug>
184 template <
typename... T_Args>
187 mutable typename std::conditional<IsDebug,
190 mutable typename std::conditional<IsDebug,
193 mutable typename std::conditional<IsDebug,
196 mutable typename std::conditional<IsDebug,
200 template <
class T_OutStream>
240 template <
bool DetailEnabled>
244 [[maybe_unused]] std::size_t per_eta_size,
245 [[maybe_unused]] std::size_t per_pdg_size)
248 if constexpr(DetailEnabled) {
257 [[maybe_unused]] std::size_t per_eta_size,
258 [[maybe_unused]] std::size_t per_pdg_size)
261 if constexpr(DetailEnabled) {
272 void fill([[maybe_unused]]
unsigned int eta_category_i,
273 [[maybe_unused]]
unsigned int pdg_id_category_i,
274 [[maybe_unused]]
float hit_efficiency,
275 [[maybe_unused]]
float hit_purity,
276 [[maybe_unused]]
float match_prob) {
293 [[maybe_unused]]
unsigned int pdg_id_category_i) {
294 if constexpr(DetailEnabled) {
303 const std::vector<float> &statPtBins,
304 const std::vector<float> &statEtaBins,
305 std::vector< int > &pdgId,
307 bool pdgIdCategorisation,
308 bool useAbsEtaForStat);
323 std::vector< std::array< std::size_t, kNCategorisedCounter> >,
326 std::vector< std::array<ActsUtils::Stat, kNCategorisedStat> >,
343 void checkBinOrder(
const std::vector<float> &bin_edges,
const std::string &bin_label)
const;
358 void printCategories(
const std::vector<std::string> &pt_category_labels,
359 const std::vector<std::string> &eta_category_labels,
360 std::vector<std::string> &counter_labels,
361 std::vector< std::array< ActsUtils::Stat, kNCategorisedStat> > &stat_per_category,
362 std::vector< std::array< std::size_t, kNCategorisedCounter> > &counts_per_category,
363 const std::string &top_left_label,
364 bool print_sub_categories)
const;
365 void printData2D(
const std::vector<std::string> &row_category_labels,
366 const std::vector<std::string> &col_category_labels,
367 const std::string &top_left_label,
368 std::vector< std::array< ActsUtils::Stat, kNCategorisedStat> > &stat_per_category,
369 std::vector< std::array< std::size_t, kNCategorisedCounter> > &counts_per_category,
375 const std::vector<float> &
weights);
377 const std::vector<float> &
weights);
Scalar eta() const
pseudorapidity method
#define ATH_MSG_ERROR(x,...)
Property holding a SG store/key/clid from which a ReadHandle is made.
Property holding a SG store/key/clid from which a WriteHandle is made.
void rotate(double angler, GeoTrf::Vector2D &vector)
Container for hit counts per track Contains hit counts per associated truth particle and the total hi...
void checkBinOrder(const std::vector< float > &bin_edges, const std::string &bin_label) const
check that bins are in increasing order.
static constexpr unsigned int s_NMeasurementTypes
static constexpr int s_pdgIdMax
void printData2D(const std::vector< std::string > &row_category_labels, const std::vector< std::string > &col_category_labels, const std::string &top_left_label, std::vector< std::array< ActsUtils::Stat, kNCategorisedStat > > &stat_per_category, std::vector< std::array< std::size_t, kNCategorisedCounter > > &counts_per_category, bool rotate) const
Gaudi::Property< bool > m_showRawCounts
std::mutex m_statMutex ATLAS_THREAD_SAFE
std::size_t perEtaSize() const
SG::ReadHandleKey< TruthParticleHitCounts > m_truthHitCounts
TruthMatchResult analyseTrackTruth(const TruthParticleHitCounts &truth_particle_hit_counts, const HitCountsPerTrack &track_hit_counts, EventStat &event_stat) const
DebugCounter< TrackFindingValidationDebugHists > m_debugCounter
void printCategories(const std::vector< std::string > &pt_category_labels, const std::vector< std::string > &eta_category_labels, std::vector< std::string > &counter_labels, std::vector< std::array< ActsUtils::Stat, kNCategorisedStat > > &stat_per_category, std::vector< std::array< std::size_t, kNCategorisedCounter > > &counts_per_category, const std::string &top_left_label, bool print_sub_categories) const
const TruthParticleHitCounts & getTruthParticleHitCounts(const EventContext &ctx) const
StatusCode checkMatchWeights()
EventStatBase< TrackFindingValidationDetailedStat > EventStat
static double noiseCorrection(const ActsTrk::HitCounterArray &noise_counts, const std::vector< float > &weights)
std::size_t getPtPdgIdStatCategory(float pt, int pdg_id) const
Return the category based on the PDG ID.
static double weightedCountSum(const ActsTrk::HitCounterArray &counts, const std::vector< float > &weights)
@ NoAssociatedTruthParticle
@ TruthParticleNoNoiseMismatch
@ MissingTruthParticleHitCounts
@ NoSelectedTruthParticle
std::size_t perPdgIdSize() const
Gaudi::Property< bool > m_printDetails
void postProcessEventStat(const TruthParticleHitCounts &truth_particle_hit_counts, std::size_t n_tracks, EventStat &event_stat) const
Gaudi::Property< std::vector< float > > m_weightsForProb
Gaudi::Property< bool > m_computeTrackRecoEfficiency
Gaudi::Property< std::vector< float > > m_statEtaBins
void printStatTables() const
std::size_t getPtEtaStatCategory(float pt, float eta) const
Return the category based on the provided eta value.
Gaudi::Property< std::vector< float > > m_statPtBins
@ kNParticleWithAssociatedTrack
@ kNParticleWithMultipleAssociatedTracks
Gaudi::Property< bool > m_pdgIdCategorisation
virtual StatusCode initialize() override
Gaudi::Property< bool > m_truthLinkedFakeRate
Gaudi::Property< std::vector< float > > m_weights
virtual StatusCode finalize() override
ToolHandle< IAthSelectionTool > m_truthSelectionTool
Extend Stat helper by an equidistant binned histogram.
An algorithm that can be simultaneously executed in multiple threads.
Property holding a SG store/key/clid from which a ReadHandle is made.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::unordered_map< const xAOD::TruthParticle *, HitCounterArray > TruthParticleHitCounts
constexpr bool TrackFindingValidationDetailedStat
constexpr bool TrackFindingValidationDebugHists
std::array< uint8_t, NHitCounter > HitCounterArray
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
TruthParticle_v1 TruthParticle
Typedef to implementation.
void reset(const IAthSelectionTool &truth_selection_tool, std::size_t per_eta_size, std::size_t per_pdg_size)
void incrementTotal(unsigned int eta_category_i, unsigned int pdg_id_category_i)
BaseStat< DetailEnabled > & operator+=(const BaseStat< DetailEnabled > &event_stat)
std::size_t perEtaSize() const
std::conditional< DetailEnabled, std::vector< std::array< std::size_t, kNCategorisedCounter > >, Empty >::type CounterArrayVec
StatArrayVec m_statPerPdgId
CounterArrayVec m_counterPerPdgId
std::conditional< DetailEnabled, std::vector< std::array< ActsUtils::Stat, kNCategorisedStat > >, Empty >::type StatArrayVec
StatArrayVec m_statPerEta
std::size_t perPdgIdSize() const
void fill(unsigned int eta_category_i, unsigned int pdg_id_category_i, float hit_efficiency, float hit_purity, float match_prob)
ActsUtils::StatHist m_truthSelectionCuts
BaseStat(const IAthSelectionTool &truth_selection_tool, std::size_t per_eta_size, std::size_t per_pdg_size)
CounterArrayVec m_counterPerEta
void fillMeasForTruthParticleWithoutCount(double weighted_measurement_sum) const
void dumpStatistics(T_OutStream &out) const
std::conditional< IsDebug, std::mutex, Empty >::type m_mutex ATLAS_THREAD_SAFE
void fillTruthMatchProb(const std::array< float, 2 > &best_match_prob) const
unsigned int m_nTruthParticleWithoutAssociatedCounts
TruthParticleSet m_truthParticlesWithAssociatedTrack
EventStatBase(const IAthSelectionTool &truth_selection_tool, std::size_t per_eta_size, std::size_t per_pdg_size, std::size_t track_to_truth_size)
std::conditional_t< DetailEnabled, std::unordered_set< const xAOD::TruthParticle * >, typename BaseStat< DetailEnabled >::Empty > TruthParticleSet
static constexpr bool doDetail
unsigned int m_nTracksWithoutAssociatedTruthParticle
unsigned int m_nTruthCuts
unsigned int m_nTracksWithoutSelectedTruthParticle
void fill(unsigned int eta_category_i, unsigned int pdg_id_category_i, float hit_efficiency, float hit_purity, float match_prob, const xAOD::TruthParticle *best_match)
unsigned int m_nTruthParticleNonoiseMismatches
Match result returned by analyseTrackTruth.
float m_hitPurity
fraction of hits originting from best match over total reco hits
float m_matchProbability
the matching probability based on weighted hit sums
float m_hitEfficiency
fraction of hits originting from best match over total best match hits
const xAOD::TruthParticle * m_truthParticle
best matching truth particle or nullptr