LDMX Software
Classes | Public Member Functions | Private Attributes | List of all members
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)
 
 ~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::TruthMatchingTooltruthMatchingTool = nullptr
 
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 52 of file TruthMatchingTool.h.

52{ 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 6 of file TruthMatchingTool.cxx.

8 {
9 TruthInfo ti;
10 ti.truthProb = 0.;
11 ti.trackID = -1;
12 ti.pdgID = 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 currentTruthProb = (double)it->second / (double)n_meas;
18 if (currentTruthProb > ti.truthProb) {
19 ti.truthProb = currentTruthProb;
20 ti.trackID = it->first;
21 }
22 }
23
24 if (ti.trackID > 0) ti.pdgID = map_[ti.trackID].getPdgID();
25
26 return ti;
27}

◆ 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 54 of file TruthMatchingTool.cxx.

55 {
56 // Map holding all tracksIds and their frequency
57 std::unordered_map<unsigned int, unsigned int> trk_trackIDs;
58
59 for (auto measID : trk.getMeasurementsIdxs()) {
60 auto meas = measurements_.at(measID);
61 if (debug_) {
62 std::cout << "Getting measurement at ID:" << measID << std::endl;
63 std::cout << meas << std::endl;
64 std::cout << meas.getTrackIds().size() << std::endl;
65 }
66
67 for (auto trkId : meas.getTrackIds()) {
68 if (trk_trackIDs.find(trkId) != trk_trackIDs.end()) {
69 trk_trackIDs[trkId]++;
70 } else {
71 trk_trackIDs[trkId] = 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_trackIDs.begin();
80 it != trk_trackIDs.end(); it++) {
81 std::cout << it->first << " " << it->second << std::endl;
82 }
83 }
84 } // loop on measurements
85
86 return Evaluate(trk_trackIDs, trk.getMeasurementsIdxs().size());
87
88} // Match Track

◆ TruthMatch() [2/2]

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

Definition at line 29 of file TruthMatchingTool.cxx.

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

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 57 of file TruthMatchingTool.h.

57{false};

◆ map_

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

Definition at line 55 of file TruthMatchingTool.h.

◆ measurements_

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

Definition at line 56 of file TruthMatchingTool.h.

◆ truthMatchingTool

std::shared_ptr<tracking::sim::TruthMatchingTool> tracking::sim::TruthMatchingTool::truthMatchingTool = nullptr
private

Definition at line 58 of file TruthMatchingTool.h.


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