5#ifndef ACTSTRK_TRACKTRUTHMATCHINGBASEALG_H
6#define ACTSTRK_TRACKTRUTHMATCHINGBASEALG_H 1
12#include "Gaudi/Property.h"
46 template <
bool DetailEnabled>
49 template <
bool DetailEnabled>
54 ISvcLocator *pSvcLocator);
57 virtual StatusCode
finalize()
override;
62 if (!truth_particle_hit_counts_handle.
isValid()) {
64 std::runtime_error(
"Failed to get truth particle hit count map");
66 return *truth_particle_hit_counts_handle;
72 return m_detailedStat.perEtaSize();
75 return m_detailedStat.perPdgIdSize();
78 template <
bool DetailEnabled>
80 static constexpr bool doDetail = DetailEnabled;
83 std::size_t per_eta_size,
84 std::size_t per_pdg_size,
85 [[maybe_unused]] std::size_t track_to_truth_size)
86 :
BaseStat<DetailEnabled>(truth_selection_tool, per_eta_size, per_pdg_size),
89 if constexpr(DetailEnabled) {
94 void fill([[maybe_unused]]
unsigned int eta_category_i,
95 [[maybe_unused]]
unsigned int pdg_id_category_i,
96 [[maybe_unused]]
float hit_efficiency,
97 [[maybe_unused]]
float hit_purity,
98 [[maybe_unused]]
float match_prob,
105 if constexpr(DetailEnabled) {
118 std::unordered_set<const xAOD::TruthParticle *>,
148 std::size_t n_tracks,
153 {
this,
"TruthParticleHitCounts",
"",
"Map from truth particle to hit counts." };
156 {
this,
"MatchWeights", {},
"Weights applied to the counts per measurement type for weighted sums"
157 " which are used compute the match probability." };
159 {
this,
"CountWeights", {},
"Weights applied to the counts per measurement type for weighted sums"
160 " which are used to compute hit efficiencies and purities." };
163 template <
class Base>
165 template <
class OWNER>
171 std::size_t
size()
const {
return 0u; }
173 auto operator[](std::size_t ) {
throw std::out_of_range(
"DummyProperty");}
176 template <
class...
Args>
177 decltype( std::declval<Base>()( std::declval<Args&&>()... ) )
operator()(
Args&&... args )
const
178 noexcept(
noexcept( std::declval<Base>()( std::declval<Args&&>()... ) ) ) {
179 return value()( std::forward<Args>( args )... );
183 template <
class Base>
187 {
this,
"StatisticEtaBins", {-4, -2.6, -2, 0, 2., 2.6, 4},
"Gather statistics separately for these eta bins."};
189 {
this,
"StatisticPtBins", {1.e3,2.5e3,10e3, 100e3},
"Gather statistics separately for these pt bins."};
191 {
this,
"PdgIdCategorisation",
false,
"Categorise by pdg id."};
193 {
this,
"ShowRawCounts",
false,
"Show all counters."};
195 {
this,
"ShowDetailedTables",
false,
"Show more details; stat. uncert., RMS, entries"};
197 {
this,
"ComputeTrackRecoEfficiency",
true,
"Compute and print track reconstruction efficiency."};
199 ToolHandle<IAthSelectionTool>
m_truthSelectionTool{
this,
"TruthSelectionTool",
"AthTruthSelectionTool",
"Truth selection tool (for efficiencies and resolutions)"};
203 template <
bool IsDebug>
206 template <
typename... T_Args>
209 mutable typename std::conditional<IsDebug,
212 mutable typename std::conditional<IsDebug,
215 mutable typename std::conditional<IsDebug,
218 mutable typename std::conditional<IsDebug,
222 template <
class T_OutStream>
262 template <
bool DetailEnabled>
266 [[maybe_unused]] std::size_t per_eta_size,
267 [[maybe_unused]] std::size_t per_pdg_size)
270 if constexpr(DetailEnabled) {
279 [[maybe_unused]] std::size_t per_eta_size,
280 [[maybe_unused]] std::size_t per_pdg_size)
283 if constexpr(DetailEnabled) {
294 void fill([[maybe_unused]]
unsigned int eta_category_i,
295 [[maybe_unused]]
unsigned int pdg_id_category_i,
296 [[maybe_unused]]
float hit_efficiency,
297 [[maybe_unused]]
float hit_purity,
298 [[maybe_unused]]
float match_prob) {
315 [[maybe_unused]]
unsigned int pdg_id_category_i) {
316 if constexpr(DetailEnabled) {
325 const std::vector<float> &statPtBins,
326 const std::vector<float> &statEtaBins,
327 std::vector< int > &pdgId,
329 bool pdgIdCategorisation,
330 bool useAbsEtaForStat);
345 std::vector< std::array< std::size_t, kNCategorisedCounter> >,
348 std::vector< std::array<ActsUtils::Stat, kNCategorisedStat> >,
365 void checkBinOrder(
const std::vector<float> &bin_edges,
const std::string &bin_label)
const;
380 void printCategories(
const std::vector<std::string> &pt_category_labels,
381 const std::vector<std::string> &eta_category_labels,
382 std::vector<std::string> &counter_labels,
383 std::vector< std::array< ActsUtils::Stat, kNCategorisedStat> > &stat_per_category,
384 std::vector< std::array< std::size_t, kNCategorisedCounter> > &counts_per_category,
385 const std::string &top_left_label,
386 bool print_sub_categories)
const;
387 void printData2D(
const std::vector<std::string> &row_category_labels,
388 const std::vector<std::string> &col_category_labels,
389 const std::string &top_left_label,
390 std::vector< std::array< ActsUtils::Stat, kNCategorisedStat> > &stat_per_category,
391 std::vector< std::array< std::size_t, kNCategorisedCounter> > &counts_per_category,
397 const std::vector<float> &
weights);
399 const std::vector<float> &
weights);
Scalar eta() const
pseudorapidity method
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
const IAthSelectionTool & truthSelectionTool() const
std::conditional< TrackFindingValidationDetailedStat, Gaudi::Property< Base >, DummyProperty< Base > >::type Property
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
Property< std::vector< float > > m_statPtBins
std::size_t perPdgIdSize() const
Property< bool > m_showRawCounts
void postProcessEventStat(const TruthParticleHitCounts &truth_particle_hit_counts, std::size_t n_tracks, EventStat &event_stat) const
Gaudi::Property< std::vector< float > > m_weightsForProb
void printStatTables() const
std::size_t getPtEtaStatCategory(float pt, float eta) const
Return the category based on the provided eta value.
TrackTruthMatchingBaseAlg(const std::string &name, ISvcLocator *pSvcLocator)
Property< bool > m_computeTrackRecoEfficiency
Property< bool > m_pdgIdCategorisation
@ kNParticleWithAssociatedTrack
@ kNParticleWithMultipleAssociatedTracks
Property< std::vector< float > > m_statEtaBins
Property< bool > m_printDetails
virtual StatusCode initialize() override
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.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
TruthParticle_v1 TruthParticle
Typedef to implementation.
std::conditional< DetailEnabled, std::vector< std::array< ActsUtils::Stat, kNCategorisedStat > >, Empty >::type StatArrayVec
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
StatArrayVec m_statPerPdgId
std::conditional< DetailEnabled, std::vector< std::array< std::size_t, kNCategorisedCounter > >, Empty >::type CounterArrayVec
CounterArrayVec m_counterPerPdgId
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
DummyProperty(OWNER *, std::string, Base &&, std::string)
decltype(std::declval< Base >()(std::declval< Args && >()...)) operator()(Args &&... args) const noexcept(noexcept(std::declval< Base >()(std::declval< Args && >()...)))
auto operator[](std::size_t)
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)
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)
std::conditional< DetailEnabled, std::unordered_set< const xAOD::TruthParticle * >, typename BaseStat< DetailEnabled >::Empty >::type TruthParticleSet
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