Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EmbRecoMatchContainerv1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EmbRecoMatchContainerv1.cc
2 #include "EmbRecoMatch.h"
3 #include "EmbRecoMatchv1.h"
4 
5 #include <algorithm>
6 #include <iomanip>
7 
8 // WARNING to user:
9 // methods depend on the internal data being sorted appropriately
10 // -> BE SURE TO CALL *SORT*
11 
13  std::sort(m_data.begin(), m_data.end(), EmbRecoMatch::Comp());
14  std::sort(m_RecoToTruth.begin(), m_RecoToTruth.end());
16 }
17 
19  m_data.push_back(match);
20  auto id_true = match->idTruthTrack();
21  auto id_reco = match->idRecoTrack();
22 
23  m_RecoToTruth.push_back({id_reco, id_true}); // vector of which to go to
24 
25  if (m_nTruthPerReco.find(id_reco) == m_nTruthPerReco.end()) {
26  m_nTruthPerReco[id_reco] = 1;
27  } else {
28  m_nTruthPerReco[id_reco] += 1;
29  }
30  if (m_nRecoPerTruth.find(id_true) == m_nRecoPerTruth.end()) {
31  m_nRecoPerTruth[id_true] = 1;
32  } else {
33  m_nRecoPerTruth[id_true] += 1;
34  }
35 }
36 
38  if (m_nRecoPerTruth.find(id_true) == m_nRecoPerTruth.end()) {
39  m_idsTruthUnmatched.push_back(id_true);
40  }
41 }
42 
44  for (auto &m : m_data) delete m;
45  m_data .clear();
46  m_RecoToTruth .clear();
47  m_idsTruthUnmatched .clear();
48  m_nTruthPerReco .clear();
49  m_nRecoPerTruth .clear();
50 }
51 
52 std::vector<unsigned short> EmbRecoMatchContainerv1::ids_TruthMatched() const {
53  std::vector<unsigned short> vec;
54  for (auto& id : m_data) vec.push_back(id->idTruthTrack());
55  return vec;
56 }
57 
58 std::vector<unsigned short> EmbRecoMatchContainerv1::ids_RecoMatched() const {
59  std::vector<unsigned short> vec;
60  for (auto& id : m_RecoToTruth) vec.push_back(id.first);
61  return vec;
62 }
63 
64 EmbRecoMatch* EmbRecoMatchContainerv1::getMatchTruth(unsigned short idtruth, unsigned short offset) {
65  auto iter = std::lower_bound(m_data.begin(), m_data.end(), idtruth, EmbRecoMatch::Comp());
66  iter += offset;
67 
68  if (iter >= m_data.end() || (*iter)->idTruthTrack() != idtruth) {
69  std::cout << "Error: asking for match (offset by " << offset <<") for truth track id " << idtruth
70  << " which is not present. Returning null pointer." << nullptr;
71  return nullptr;
72  }
73  return *iter;
74 }
75 
76 EmbRecoMatch* EmbRecoMatchContainerv1::getMatchReco(unsigned short idreco, unsigned short offset) {
77  auto iter = std::lower_bound(m_RecoToTruth.begin(), m_RecoToTruth.end(), idreco, CompShortToPair());
78  iter += offset;
79  if (iter >= m_RecoToTruth.end() || iter->first != idreco) {
80  std::cout << "Error: asking for match (offset by " << offset <<") for reco track id " << idreco
81  << " which is not present. Returning null pointer." << nullptr;
82  return nullptr;
83  }
84  return getMatchTruth(iter->second, offset);
85 }
86 
87 bool EmbRecoMatchContainerv1::hasTruthMatch(unsigned short idtruth) {
88  return std::binary_search(m_data.begin(), m_data.end(), idtruth, EmbRecoMatch::Comp());
89 }
90 
91 bool EmbRecoMatchContainerv1::hasRecoMatch(unsigned short idreco) {
92  return std::binary_search(m_RecoToTruth.begin(), m_RecoToTruth.end(), idreco, CompShortToPair());
93 }
94 
95 void EmbRecoMatchContainerv1::identify(std::ostream& os) const {
96  os << " EmbRecoMatchContainerv1 data. N(matched emb. tracks) = "
97  << nMatches() << ", N(not matched) " << nTruthUnmatched() << std::endl;
98  os << " Matched track data: " << std::endl;
99  // id-Emb id-Reco id-Seed id-SvtxSeed nClus-Emb nClus-Reco meanZClus meanPhiClus
100  os << std::setw(6) << "id-Emb "
101  << std::setw(7) << "id-Reco "
102  << std::setw(7) << "id-Seed "
103  << std::setw(11) << "id-SvtxSeed "
104  << std::setw(9) << "nClus-Emb "
105  << std::setw(10) << "nClus-Reco "
106  << std::setw(12) << "nClus_Matched " << std::endl;
107  for (auto& _m : m_data) {
108  auto m = static_cast<EmbRecoMatchv1*> (_m);
109  os << std::setw(6) << m->idTruthTrack() << " " //id-Emb"
110  << std::setw(7) << m->idRecoTrack() << " " //"id-Reco"
111  << std::setw(7) << m->idTpcTrackSeed() << " " //"id-Seed"
112  << std::setw(11) << m->idSvtxTrackSeed() << " " //id-SvtxSeed"
113  << std::setw(9) << m->nClustersTruth() << " " //nClus-Emb"
114  << std::setw(10) << m->nClustersReco() << " " //"nClus-Reco"
115  << std::setw(12) << m->nClustersMatched() << std::endl; // //"nClus-Reco"
116  /* << std::setw(9) << m->meanClusterZDiff() << " " //"meanZclus" */
117  /* << std::setw(11) << m->meanClusterPhiDiff() << std::endl; //"meanPhiclus" << std::endl; */
118 
119  /* os << Form(" %7i %7i %8s %11s %11s %10s %10s %10s", */
120  /* m->idTruthTrack(), m->idRecoTrack(), m->idTrackSeed(), m->idSvtxTrackSeed(), */
121  /* m->nClustersTruth(), m->nClustersReco(), m->meanClusterZDiff(), m->meanClusterPhiDiff()) << std::endl; */
122  }
123  os << " IDs of embedded tracks that were not reconstructed: " << std::endl;
124  for (const auto n : m_idsTruthUnmatched) os << n << " ";
125  os << std::endl;
126 }