File indexing completed on 2025-08-05 08:18:19
0001 #include "EmbRecoMatchContainerv1.h"
0002 #include "EmbRecoMatch.h"
0003 #include "EmbRecoMatchv1.h"
0004
0005 #include <algorithm>
0006 #include <iomanip>
0007
0008
0009
0010
0011
0012 void EmbRecoMatchContainerv1::sort()
0013 {
0014 std::sort(m_data.begin(), m_data.end(), EmbRecoMatch::Comp());
0015 std::sort(m_RecoToTruth.begin(), m_RecoToTruth.end());
0016 std::sort(m_idsTruthUnmatched.begin(), m_idsTruthUnmatched.end());
0017 }
0018
0019 void EmbRecoMatchContainerv1::addMatch(EmbRecoMatch* match)
0020 {
0021 m_data.push_back(match);
0022 auto id_true = match->idTruthTrack();
0023 auto id_reco = match->idRecoTrack();
0024
0025 m_RecoToTruth.emplace_back(id_reco, id_true);
0026
0027 if (m_nTruthPerReco.find(id_reco) == m_nTruthPerReco.end())
0028 {
0029 m_nTruthPerReco[id_reco] = 1;
0030 }
0031 else
0032 {
0033 m_nTruthPerReco[id_reco] += 1;
0034 }
0035 if (m_nRecoPerTruth.find(id_true) == m_nRecoPerTruth.end())
0036 {
0037 m_nRecoPerTruth[id_true] = 1;
0038 }
0039 else
0040 {
0041 m_nRecoPerTruth[id_true] += 1;
0042 }
0043 }
0044
0045 void EmbRecoMatchContainerv1::checkfill_idsTruthUnmatched(unsigned short id_true)
0046 {
0047 if (m_nRecoPerTruth.find(id_true) == m_nRecoPerTruth.end())
0048 {
0049 m_idsTruthUnmatched.push_back(id_true);
0050 }
0051 }
0052
0053 void EmbRecoMatchContainerv1::Reset()
0054 {
0055 for (auto& m : m_data)
0056 {
0057 delete m;
0058 }
0059 m_data.clear();
0060 m_RecoToTruth.clear();
0061 m_idsTruthUnmatched.clear();
0062 m_nTruthPerReco.clear();
0063 m_nRecoPerTruth.clear();
0064 }
0065
0066 std::vector<unsigned short> EmbRecoMatchContainerv1::ids_TruthMatched() const
0067 {
0068 std::vector<unsigned short> vec;
0069 for (auto& id : m_data)
0070 {
0071 vec.push_back(id->idTruthTrack());
0072 }
0073 return vec;
0074 }
0075
0076 std::vector<unsigned short> EmbRecoMatchContainerv1::ids_RecoMatched() const
0077 {
0078 std::vector<unsigned short> vec;
0079 for (auto& id : m_RecoToTruth)
0080 {
0081 vec.push_back(id.first);
0082 }
0083 return vec;
0084 }
0085
0086 EmbRecoMatch* EmbRecoMatchContainerv1::getMatchTruth(unsigned short idtruth, unsigned short offset)
0087 {
0088 auto iter = std::lower_bound(m_data.begin(), m_data.end(), idtruth, EmbRecoMatch::Comp());
0089 iter += offset;
0090
0091 if (iter >= m_data.end() || (*iter)->idTruthTrack() != idtruth)
0092 {
0093 std::cout << "Error: asking for match (offset by " << offset << ") for truth track id " << idtruth
0094 << " which is not present. Returning null pointer." << nullptr;
0095 return nullptr;
0096 }
0097 return *iter;
0098 }
0099
0100 EmbRecoMatch* EmbRecoMatchContainerv1::getMatchReco(unsigned short idreco, unsigned short offset)
0101 {
0102 auto iter = std::lower_bound(m_RecoToTruth.begin(), m_RecoToTruth.end(), idreco, CompShortToPair());
0103 iter += offset;
0104 if (iter >= m_RecoToTruth.end() || iter->first != idreco)
0105 {
0106 std::cout << "Error: asking for match (offset by " << offset << ") for reco track id " << idreco
0107 << " which is not present. Returning null pointer." << nullptr;
0108 return nullptr;
0109 }
0110 return getMatchTruth(iter->second, offset);
0111 }
0112
0113 bool EmbRecoMatchContainerv1::hasTruthMatch(unsigned short idtruth)
0114 {
0115 return std::binary_search(m_data.begin(), m_data.end(), idtruth, EmbRecoMatch::Comp());
0116 }
0117
0118 bool EmbRecoMatchContainerv1::hasRecoMatch(unsigned short idreco)
0119 {
0120 return std::binary_search(m_RecoToTruth.begin(), m_RecoToTruth.end(), idreco, CompShortToPair());
0121 }
0122
0123 void EmbRecoMatchContainerv1::identify(std::ostream& os) const
0124 {
0125 os << " EmbRecoMatchContainerv1 data. N(matched emb. tracks) = "
0126 << nMatches() << ", N(not matched) " << nTruthUnmatched() << std::endl;
0127 os << " Matched track data: " << std::endl;
0128
0129 os << std::setw(6) << "id-Emb "
0130 << std::setw(7) << "id-Reco "
0131 << std::setw(7) << "id-Seed "
0132 << std::setw(11) << "id-SvtxSeed "
0133 << std::setw(9) << "nClus-Emb "
0134 << std::setw(10) << "nClus-Reco "
0135 << std::setw(12) << "nClus_Matched " << std::endl;
0136 for (auto& _m : m_data)
0137 {
0138 auto m = static_cast<EmbRecoMatchv1*>(_m);
0139 os << std::setw(6) << m->idTruthTrack() << " "
0140 << std::setw(7) << m->idRecoTrack() << " "
0141 << std::setw(7) << m->idTpcTrackSeed() << " "
0142 << std::setw(11) << m->idSvtxTrackSeed() << " "
0143 << std::setw(9) << m->nClustersTruth() << " "
0144 << std::setw(10) << m->nClustersReco() << " "
0145 << std::setw(12) << m->nClustersMatched() << std::endl;
0146
0147
0148
0149
0150
0151
0152 }
0153 os << " IDs of embedded tracks that were not reconstructed: " << std::endl;
0154 for (const auto n : m_idsTruthUnmatched)
0155 {
0156 os << n << " ";
0157 }
0158 os << std::endl;
0159 }