Skip to content

Commit 279db8f

Browse files
authored
Merge pull request #1119 from stephenswat/feat/root_purity_completeness
Add track purity and completeness to ROOT output
2 parents 3bd51e0 + 1cade54 commit 279db8f

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

performance/include/traccc/resolution/stat_plot_tool_config.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ struct stat_plot_tool_config {
2525
{"chi2", plot_helpers::binning("chi2", 100, 0.f, 50.f)},
2626
{"reduced_chi2", plot_helpers::binning("chi2/ndf", 100, 0.f, 10.f)},
2727
{"pval", plot_helpers::binning("pval", 50, 0.f, 1.f)},
28-
{"chi2_local", plot_helpers::binning("chi2", 100, 0.f, 10.f)}};
28+
{"chi2_local", plot_helpers::binning("chi2", 100, 0.f, 10.f)},
29+
{"completeness", plot_helpers::binning("completeness", 20, 0.f, 1.f)},
30+
{"purity", plot_helpers::binning("purity", 20, 0.f, 1.f)}};
2931
};
3032

3133
} // namespace traccc

performance/src/efficiency/finding_performance_writer.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,20 @@ void finding_performance_writer::write_common(
205205
// of the number of measurements
206206
assert(found_measurements.size() > 0u);
207207
assert(truth_measurements.size() > 0u);
208-
const bool reco_matched =
208+
209+
const double purity = static_cast<double>(n_major_hits) /
210+
static_cast<double>(found_measurements.size());
211+
const double completeness =
209212
static_cast<double>(n_major_hits) /
210-
static_cast<double>(found_measurements.size()) >
211-
m_cfg.track_truth_config.matching_ratio;
213+
static_cast<double>(truth_measurements.size());
214+
215+
const bool reco_matched =
216+
purity > m_cfg.track_truth_config.matching_ratio;
212217
const bool truth_matched =
213-
static_cast<double>(n_major_hits) /
214-
static_cast<double>(truth_measurements.size()) >
215-
m_cfg.track_truth_config.matching_ratio;
218+
completeness > m_cfg.track_truth_config.matching_ratio;
219+
220+
m_data->m_stat_plot_tool.fill(m_data->m_stat_plot_cache, purity,
221+
completeness);
216222

217223
if ((!m_cfg.track_truth_config.double_matching && reco_matched) ||
218224
(m_cfg.track_truth_config.double_matching && reco_matched &&

performance/src/resolution/stat_plot_tool.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ void stat_plot_tool::book(stat_plot_cache& cache) const {
2626
plot_helpers::binning b_reduced_chi2 = m_cfg.var_binning.at("reduced_chi2");
2727
plot_helpers::binning b_pval = m_cfg.var_binning.at("pval");
2828
plot_helpers::binning b_chi2_local = m_cfg.var_binning.at("chi2_local");
29+
plot_helpers::binning b_purity = m_cfg.var_binning.at("purity");
30+
plot_helpers::binning b_completeness = m_cfg.var_binning.at("completeness");
2931
cache.ndf_hist = plot_helpers::book_histo("ndf", "NDF", b_ndf);
3032
cache.chi2_hist = plot_helpers::book_histo("chi2", "Chi2", b_chi2);
3133
cache.reduced_chi2_hist =
3234
plot_helpers::book_histo("reduced_chi2", "Chi2/NDF", b_reduced_chi2);
3335
cache.pval_hist = plot_helpers::book_histo("pval", "p value", b_pval);
36+
cache.purity_hist = plot_helpers::book_histo("purity", "Ratio", b_purity);
37+
cache.completeness_hist =
38+
plot_helpers::book_histo("completeness", "Ratio", b_completeness);
3439
for (unsigned int D = 1u; D <= 2u; D++) {
3540
cache.chi2_filtered_hist[D] = plot_helpers::book_histo(
3641
Form("chi2_%dD_filtered", D),
@@ -87,6 +92,20 @@ void stat_plot_tool::fill(
8792
#endif // TRACCC_HAVE_ROOT
8893
}
8994

95+
void stat_plot_tool::fill(stat_plot_cache& cache, double purity,
96+
double completeness) const {
97+
98+
// Avoid unused variable warnings when building the code without ROOT.
99+
(void)cache;
100+
(void)purity;
101+
(void)completeness;
102+
103+
#ifdef TRACCC_HAVE_ROOT
104+
cache.purity_hist->Fill(purity);
105+
cache.completeness_hist->Fill(completeness);
106+
#endif // TRACCC_HAVE_ROOT
107+
}
108+
90109
void stat_plot_tool::write(const stat_plot_cache& cache) const {
91110

92111
// Avoid unused variable warnings when building the code without ROOT.
@@ -101,6 +120,8 @@ void stat_plot_tool::write(const stat_plot_cache& cache) const {
101120
cache.chi2_hist->Write();
102121
cache.reduced_chi2_hist->Write();
103122
cache.pval_hist->Write();
123+
cache.purity_hist->Write();
124+
cache.completeness_hist->Write();
104125

105126
for (const auto& flt : cache.chi2_filtered_hist) {
106127
flt.second->Write();

performance/src/resolution/stat_plot_tool.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class stat_plot_tool {
3131
std::unique_ptr<TH1> reduced_chi2_hist;
3232
// Histogram for the pvalue
3333
std::unique_ptr<TH1> pval_hist;
34+
// Histogram for the purity
35+
std::unique_ptr<TH1> purity_hist;
36+
// Histogram for the completeness
37+
std::unique_ptr<TH1> completeness_hist;
3438
// Histogram for chi2 of filtered states
3539
std::map<unsigned int, std::unique_ptr<TH1>> chi2_filtered_hist;
3640
// Histogram for chi2 of smoothed states
@@ -74,6 +78,12 @@ class stat_plot_tool {
7478
void fill(stat_plot_cache& cache,
7579
const track_state<traccc::default_algebra>& trk_state) const;
7680

81+
/// @brief fill the cache
82+
/// @param cache the cache for statistics plots
83+
/// @param purity the track purity
84+
/// @param completeness the track completeness
85+
void fill(stat_plot_cache& cache, double purity, double completeness) const;
86+
7787
/// @brief write the statistics plots into ROOT
7888
///
7989
/// @param cache the cache for statistics plots

performance/src/resolution/stat_plot_tool.ipp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#include "traccc/utils/prob.hpp"
11+
1012
namespace traccc {
1113

1214
template <typename T>
@@ -22,8 +24,8 @@ void stat_plot_tool::fill(stat_plot_cache& cache,
2224
const auto& chi2 = find_res.chi2();
2325
cache.ndf_hist->Fill(ndf);
2426
cache.chi2_hist->Fill(chi2);
27+
cache.pval_hist->Fill(prob(chi2, ndf));
2528
cache.reduced_chi2_hist->Fill(chi2 / ndf);
26-
// cache.pval_hist->Fill(ROOT::Math::chisquared_cdf_c(chi2, ndf));
2729
#endif // TRACCC_HAVE_ROOT
2830
}
2931

0 commit comments

Comments
 (0)