File indexing completed on 2025-12-16 09:20:37
0001
0002
0003
0004
0005
0006
0007
0008 #include "TrkrHitTruthAssocv1.h"
0009 #include "TrkrDefs.h"
0010
0011 #include "MvtxDefs.h"
0012
0013 #include <g4main/PHG4HitDefs.h>
0014
0015 #include <algorithm>
0016 #include <ostream> // for operator<<, endl, basic_ostream, bas...
0017
0018 void TrkrHitTruthAssocv1::Reset()
0019 {
0020 m_map.clear();
0021 }
0022
0023 void TrkrHitTruthAssocv1::identify(std::ostream& os) const
0024 {
0025 os << "-----TrkrHitTruthAssocv1-----" << std::endl;
0026 os << "Number of associations: " << m_map.size() << std::endl;
0027
0028 for (const auto& entry : m_map)
0029 {
0030 int layer = TrkrDefs::getLayer(entry.first);
0031 os << " hitset key: " << entry.first << " layer " << layer
0032 << " hit key: " << entry.second.first
0033 << " g4hit key: " << entry.second.second
0034 << std::endl;
0035 }
0036
0037 os << "------------------------------" << std::endl;
0038
0039 return;
0040 }
0041
0042 void TrkrHitTruthAssocv1::addAssoc(const TrkrDefs::hitsetkey hitsetkey, const TrkrDefs::hitkey hitkey, const PHG4HitDefs::keytype g4hitkey)
0043 {
0044
0045 m_map.insert(std::make_pair(hitsetkey, std::make_pair(hitkey, g4hitkey)));
0046 }
0047
0048 void TrkrHitTruthAssocv1::findOrAddAssoc(const TrkrDefs::hitsetkey hitsetkey, const TrkrDefs::hitkey hitkey, const PHG4HitDefs::keytype g4hitkey)
0049 {
0050
0051
0052
0053 const auto hitsetrange = m_map.equal_range(hitsetkey);
0054 if (std::any_of(
0055 hitsetrange.first,
0056 hitsetrange.second,
0057 [&hitkey, &g4hitkey](const MMap::value_type& pair)
0058 { return pair.second.first == hitkey && pair.second.second == g4hitkey; }))
0059 {
0060 return;
0061 }
0062
0063
0064 const auto assoc = std::make_pair(hitkey, g4hitkey);
0065 m_map.insert(hitsetrange.second, std::make_pair(hitsetkey, assoc));
0066 }
0067
0068 void TrkrHitTruthAssocv1::removeAssoc(const TrkrDefs::hitsetkey hitsetkey, const TrkrDefs::hitkey hitkey)
0069 {
0070
0071
0072
0073 const auto hitsetrange = m_map.equal_range(hitsetkey);
0074 for (auto mapiter = hitsetrange.first; mapiter != hitsetrange.second; ++mapiter)
0075 {
0076 if (mapiter->second.first == hitkey)
0077 {
0078 m_map.erase(mapiter);
0079 return;
0080 }
0081 }
0082 }
0083
0084 void TrkrHitTruthAssocv1::getG4Hits(const TrkrDefs::hitsetkey hitsetkey, const unsigned int hidx, MMap& temp_map) const
0085 {
0086 const auto hitsetrange = m_map.equal_range(hitsetkey);
0087
0088 bool found = false;
0089 for (auto it = hitsetrange.first; it != hitsetrange.second; ++it)
0090 {
0091 if (it->second.first == hidx)
0092 {
0093 temp_map.emplace_hint(temp_map.end(), it->first, it->second);
0094 found = true;
0095 }
0096 }
0097
0098
0099 const auto layer = TrkrDefs::getLayer(hitsetkey);
0100 if (!found && layer < 3)
0101 {
0102 const auto stave = MvtxDefs::getStaveId(hitsetkey);
0103 const auto chip = MvtxDefs::getChipId(hitsetkey);
0104 const TrkrDefs::hitsetkey bare_hitsetkey = MvtxDefs::genHitSetKey(layer, stave, chip, 0);
0105
0106 const auto bare_hitsetrange = m_map.equal_range(bare_hitsetkey);
0107 for (auto it = bare_hitsetrange.first; it != bare_hitsetrange.second; ++it)
0108 {
0109 if (it->second.first == hidx)
0110 {
0111 temp_map.emplace_hint(temp_map.end(), it->first, it->second);
0112 }
0113 }
0114 }
0115 }