Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:18:13

0001 /**
0002  * @file trackbase/TrkrHitTruthAssocv1.cc
0003  * @author D. McGlinchey, H. PEREIRA DA COSTA
0004  * @date June 2018
0005  * @brief Implementation of TrkrHitTruthAssocv1
0006  */
0007 
0008 #include "TrkrHitTruthAssocv1.h"
0009 #include "TrkrDefs.h"
0010 
0011 #include <g4main/PHG4HitDefs.h>
0012 
0013 #include <algorithm>
0014 #include <ostream>  // for operator<<, endl, basic_ostream, bas...
0015 
0016 void TrkrHitTruthAssocv1::Reset()
0017 {
0018   m_map.clear();
0019 }
0020 
0021 void TrkrHitTruthAssocv1::identify(std::ostream& os) const
0022 {
0023   os << "-----TrkrHitTruthAssocv1-----" << std::endl;
0024   os << "Number of associations: " << m_map.size() << std::endl;
0025 
0026   for (const auto& entry : m_map)
0027   {
0028     int layer = TrkrDefs::getLayer(entry.first);
0029     os << "   hitset key: " << entry.first << " layer " << layer
0030        << " hit key: " << entry.second.first
0031        << " g4hit key: " << entry.second.second
0032        << std::endl;
0033   }
0034 
0035   os << "------------------------------" << std::endl;
0036 
0037   return;
0038 }
0039 
0040 void TrkrHitTruthAssocv1::addAssoc(const TrkrDefs::hitsetkey hitsetkey, const TrkrDefs::hitkey hitkey, const PHG4HitDefs::keytype g4hitkey)
0041 {
0042   // the association we want is between TrkrHit and PHG4Hit, but we need to know which TrkrHitSet the TrkrHit is in
0043   m_map.insert(std::make_pair(hitsetkey, std::make_pair(hitkey, g4hitkey)));
0044 }
0045 
0046 void TrkrHitTruthAssocv1::findOrAddAssoc(const TrkrDefs::hitsetkey hitsetkey, const TrkrDefs::hitkey hitkey, const PHG4HitDefs::keytype g4hitkey)
0047 {
0048   // the association we want is between TrkrHit and PHG4Hit, but we need to know which TrkrHitSet the TrkrHit is in
0049   // check if this association already exists
0050   // We need all hitsets with this key
0051   const auto hitsetrange = m_map.equal_range(hitsetkey);
0052   if (std::any_of(
0053           hitsetrange.first,
0054           hitsetrange.second,
0055           [&hitkey, &g4hitkey](const MMap::value_type& pair)
0056           { return pair.second.first == hitkey && pair.second.second == g4hitkey; }))
0057   {
0058     return;
0059   }
0060 
0061   // Does not exist, create it
0062   const auto assoc = std::make_pair(hitkey, g4hitkey);
0063   m_map.insert(hitsetrange.second, std::make_pair(hitsetkey, assoc));
0064 }
0065 
0066 void TrkrHitTruthAssocv1::removeAssoc(const TrkrDefs::hitsetkey hitsetkey, const TrkrDefs::hitkey hitkey)
0067 {
0068   // remove all entries for this TrkrHit and its PHG4Hits, but we need to know which TrkrHitSet the TrkrHit is in
0069   // check if this association already exists
0070   // We need all hitsets with this key
0071   const auto hitsetrange = m_map.equal_range(hitsetkey);
0072   for (auto mapiter = hitsetrange.first; mapiter != hitsetrange.second; ++mapiter)
0073   {
0074     if (mapiter->second.first == hitkey)
0075     {
0076       m_map.erase(mapiter);
0077       return;
0078     }
0079   }
0080 }
0081 
0082 void TrkrHitTruthAssocv1::getG4Hits(const TrkrDefs::hitsetkey hitsetkey, const unsigned int hidx, MMap& temp_map) const
0083 {
0084   const auto hitsetrange = m_map.equal_range(hitsetkey);
0085   std::copy_if(hitsetrange.first, hitsetrange.second, std::inserter(temp_map, temp_map.end()),
0086                [hidx](MMap::const_reference pair)
0087                { return pair.second.first == hidx; });
0088 }