LDMX Software
tracking::sim::TruthMatchingTool Class Reference

Classes

struct  TruthInfo
 

Public Member Functions

 TruthMatchingTool (const std::map< int, ldmx::SimParticle > &particleMap, const std::vector< ldmx::Measurement > &measurements)
 Constructor.
 
void setup (const std::map< int, ldmx::SimParticle > &particleMap, const std::vector< ldmx::Measurement > &measurements)
 
virtual ~TruthMatchingTool ()=default
 Destructor.
 
TruthInfo truthMatch (const ldmx::Track &trk)
 Performs the truth matching by checking all the trackIDs associated to the measurements on track.
 
TruthInfo evaluate (const std::unordered_map< unsigned int, unsigned int > &trk_trackIDs, int n_meas)
 
TruthInfo truthMatch (const std::vector< ldmx::Measurement > &vmeas)
 
bool configured ()
 

Private Attributes

std::map< int, ldmx::SimParticlemap_
 
std::vector< ldmx::Measurementmeasurements_
 
bool debug_ {false}
 
std::shared_ptr< tracking::sim::TruthMatchingTooltruth_matching_tool_
 
bool configured_ {false}
 

Detailed Description

Definition at line 11 of file TruthMatchingTool.h.

Constructor & Destructor Documentation

◆ TruthMatchingTool()

tracking::sim::TruthMatchingTool::TruthMatchingTool ( const std::map< int, ldmx::SimParticle > & particleMap,
const std::vector< ldmx::Measurement > & measurements )
inline

Constructor.

Parameters
particleMapThe map of all the simulated particles in the event.
measurementsAll the measurements in the event.

Definition at line 28 of file TruthMatchingTool.h.

29 {
30 setup(particleMap, measurements);
31 };

Member Function Documentation

◆ configured()

bool tracking::sim::TruthMatchingTool::configured ( )
inline

Definition at line 51 of file TruthMatchingTool.h.

51{ return configured_; }

◆ evaluate()

TruthMatchingTool::TruthInfo tracking::sim::TruthMatchingTool::evaluate ( const std::unordered_map< unsigned int, unsigned int > & trk_trackIDs,
int n_meas )

Definition at line 8 of file TruthMatchingTool.cxx.

10 {
11 TruthInfo ti;
12 ti.truth_prob_ = 0.;
13 ti.track_id_ = -1;
14 ti.pdg_id_ = 0;
15
16 for (std::unordered_map<unsigned int, unsigned int>::const_iterator it =
17 trk_trackIDs.begin();
18 it != trk_trackIDs.end(); it++) {
19 double current_truth_prob = (double)it->second / (double)n_meas;
20 if (current_truth_prob > ti.truth_prob_) {
21 ti.truth_prob_ = current_truth_prob;
22 ti.track_id_ = it->first;
23 }
24 }
25
26 if (ti.track_id_ > 0) ti.pdg_id_ = map_[ti.track_id_].getPdgID();
27
28 return ti;
29}

◆ setup()

void tracking::sim::TruthMatchingTool::setup ( const std::map< int, ldmx::SimParticle > & particleMap,
const std::vector< ldmx::Measurement > & measurements )
inline

Definition at line 33 of file TruthMatchingTool.h.

34 {
35 map_ = particleMap;
36 measurements_ = measurements;
37 configured_ = true;
38 }

◆ truthMatch() [1/2]

TruthMatchingTool::TruthInfo tracking::sim::TruthMatchingTool::truthMatch ( const ldmx::Track & trk)

Performs the truth matching by checking all the trackIDs associated to the measurements on track.

Parameters
trkThe track that needs to be truth matched
Returns
TruthInfo a struct containing the truth information regarding the track Each measurement weights the same.

Definition at line 56 of file TruthMatchingTool.cxx.

57 {
58 // Map holding all tracksIds and their frequency
59 std::unordered_map<unsigned int, unsigned int> trk_track_i_ds;
60
61 for (auto meas_id : trk.getMeasurementsIdxs()) {
62 auto meas = measurements_.at(meas_id);
63 if (debug_) {
64 std::cout << "Getting measurement at ID:" << meas_id << std::endl;
65 std::cout << meas << std::endl;
66 std::cout << meas.getTrackIds().size() << std::endl;
67 }
68
69 for (auto trk_id : meas.getTrackIds()) {
70 if (trk_track_i_ds.find(trk_id) != trk_track_i_ds.end()) {
71 trk_track_i_ds[trk_id]++;
72 } else {
73 trk_track_i_ds[trk_id] = 1;
74 }
75
76 } // loop on measurements trackIDs
77
78 if (debug_) {
79 std::cout << "The trackIDs maps look like:" << std::endl;
80 for (std::unordered_map<unsigned int, unsigned int>::iterator it =
81 trk_track_i_ds.begin();
82 it != trk_track_i_ds.end(); it++) {
83 std::cout << it->first << " " << it->second << std::endl;
84 }
85 }
86 } // loop on measurements
87
88 return evaluate(trk_track_i_ds, trk.getMeasurementsIdxs().size());
89
90} // Match Track

◆ truthMatch() [2/2]

TruthMatchingTool::TruthInfo tracking::sim::TruthMatchingTool::truthMatch ( const std::vector< ldmx::Measurement > & vmeas)

Definition at line 31 of file TruthMatchingTool.cxx.

32 {
33 std::unordered_map<unsigned int, unsigned int> trk_track_i_ds;
34
35 for (auto meas : vmeas) {
36 for (auto trk_id : meas.getTrackIds()) {
37 if (trk_track_i_ds.find(trk_id) != trk_track_i_ds.end())
38 trk_track_i_ds[trk_id]++;
39 else
40 trk_track_i_ds[trk_id] = 1;
41 }
42 } // loop on measurements
43
44 return evaluate(trk_track_i_ds, vmeas.size());
45}

Member Data Documentation

◆ configured_

bool tracking::sim::TruthMatchingTool::configured_ {false}
private

Definition at line 59 of file TruthMatchingTool.h.

59{false};

◆ debug_

bool tracking::sim::TruthMatchingTool::debug_ {false}
private

Definition at line 56 of file TruthMatchingTool.h.

56{false};

◆ map_

std::map<int, ldmx::SimParticle> tracking::sim::TruthMatchingTool::map_
private

Definition at line 54 of file TruthMatchingTool.h.

◆ measurements_

std::vector<ldmx::Measurement> tracking::sim::TruthMatchingTool::measurements_
private

Definition at line 55 of file TruthMatchingTool.h.

◆ truth_matching_tool_

std::shared_ptr<tracking::sim::TruthMatchingTool> tracking::sim::TruthMatchingTool::truth_matching_tool_
private
Initial value:
=
nullptr

Definition at line 57 of file TruthMatchingTool.h.


The documentation for this class was generated from the following files: