LDMX Software
TruthMatchingTool.cxx
1#include "Tracking/Reco/TruthMatchingTool.h"
2
3namespace tracking {
4namespace sim {
5
6TruthMatchingTool::TruthInfo TruthMatchingTool::evaluate(
7 const std::unordered_map<unsigned int, unsigned int>& trk_trackIDs,
8 int n_meas) {
9 TruthInfo ti;
10 ti.truth_prob_ = 0.;
11 ti.track_id_ = -1;
12 ti.pdg_id_ = 0;
13
14 for (std::unordered_map<unsigned int, unsigned int>::const_iterator it =
15 trk_trackIDs.begin();
16 it != trk_trackIDs.end(); it++) {
17 double current_truth_prob = (double)it->second / (double)n_meas;
18 if (current_truth_prob > ti.truth_prob_) {
19 ti.truth_prob_ = current_truth_prob;
20 ti.track_id_ = it->first;
21 }
22 }
23
24 if (ti.track_id_ > 0) ti.pdg_id_ = map_[ti.track_id_].getPdgID();
25
26 return ti;
27}
28
29TruthMatchingTool::TruthInfo TruthMatchingTool::truthMatch(
30 const std::vector<ldmx::Measurement>& vmeas) {
31 std::unordered_map<unsigned int, unsigned int> trk_track_i_ds;
32
33 for (auto meas : vmeas) {
34 for (auto trk_id : meas.getTrackIds()) {
35 if (trk_track_i_ds.find(trk_id) != trk_track_i_ds.end())
36 trk_track_i_ds[trk_id]++;
37 else
38 trk_track_i_ds[trk_id] = 1;
39 }
40 } // loop on measurements
41
42 return evaluate(trk_track_i_ds, vmeas.size());
43}
44
55 const ldmx::Track& trk) {
56 // Map holding all tracksIds and their frequency
57 std::unordered_map<unsigned int, unsigned int> trk_track_i_ds;
58
59 for (auto meas_id : trk.getMeasurementsIdxs()) {
60 auto meas = measurements_.at(meas_id);
61 if (debug_) {
62 std::cout << "Getting measurement at ID:" << meas_id << std::endl;
63 std::cout << meas << std::endl;
64 std::cout << meas.getTrackIds().size() << std::endl;
65 }
66
67 for (auto trk_id : meas.getTrackIds()) {
68 if (trk_track_i_ds.find(trk_id) != trk_track_i_ds.end()) {
69 trk_track_i_ds[trk_id]++;
70 } else {
71 trk_track_i_ds[trk_id] = 1;
72 }
73
74 } // loop on measurements trackIDs
75
76 if (debug_) {
77 std::cout << "The trackIDs maps look like:" << std::endl;
78 for (std::unordered_map<unsigned int, unsigned int>::iterator it =
79 trk_track_i_ds.begin();
80 it != trk_track_i_ds.end(); it++) {
81 std::cout << it->first << " " << it->second << std::endl;
82 }
83 }
84 } // loop on measurements
85
86 return evaluate(trk_track_i_ds, trk.getMeasurementsIdxs().size());
87
88} // Match Track
89
90} // namespace sim
91} // namespace tracking
Implementation of a track object.
Definition Track.h:53
TruthInfo truthMatch(const ldmx::Track &trk)
Performs the truth matching by checking all the trackIDs associated to the measurements on track.
The measurement calibrator can be a function or a class/struct able to retrieve the sim hits containe...