Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 /**
0002  * @file trackbase/TrkrClusterHitAssocv3.cc
0003  * @author D. McGlinchey
0004  * @date June 2018
0005  * @brief TrkrClusterHitAssoc implementation
0006  */
0007 
0008 #include "TrkrClusterHitAssocv3.h"
0009 #include "TrkrDefs.h"
0010 
0011 #include <ostream>  // for operator<<, endl, basic_ostream, ostream, basic_o...
0012 
0013 namespace
0014 {
0015   TrkrClusterHitAssocv3::Map dummy_map;
0016 }
0017 
0018 //_________________________________________________________________________
0019 void TrkrClusterHitAssocv3::Reset()
0020 {
0021   std::map<TrkrDefs::hitsetkey, Map> empty_map;
0022   m_map.swap(empty_map);
0023 }
0024 //_________________________________________________________________________
0025 void TrkrClusterHitAssocv3::identify(std::ostream& os) const
0026 {
0027   std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator iter;
0028   os << "-----TrkrClusterHitAssocv3-----" << std::endl;
0029   os << "Number of associations: " << size() << std::endl;
0030   for (const auto& map_pair : m_map)
0031   {
0032     for (const auto& pair : map_pair.second)
0033     {
0034       os << "clus key " << pair.first << std::dec
0035          << " layer " << (unsigned int) TrkrDefs::getLayer(pair.first)
0036          << " hit key: " << pair.second << std::endl;
0037     }
0038   }
0039   os << "------------------------------" << std::endl;
0040 
0041   return;
0042 }
0043 
0044 //_________________________________________________________________________
0045 void TrkrClusterHitAssocv3::removeAssocs(TrkrDefs::hitsetkey hitsetkey)
0046 {
0047   m_map.erase(hitsetkey);
0048 }
0049 
0050 //_________________________________________________________________________
0051 void TrkrClusterHitAssocv3::addAssoc(TrkrDefs::cluskey ckey, unsigned int hidx)
0052 {
0053   // get hitset key from cluster
0054   const TrkrDefs::hitsetkey hitsetkey = TrkrDefs::getHitSetKeyFromClusKey(ckey);
0055 
0056   // find relevant association map, create one if not found
0057   Map& clusterMap = m_map[hitsetkey];
0058 
0059   // insert association
0060   clusterMap.insert(std::make_pair(ckey, hidx));
0061 }
0062 
0063 //_________________________________________________________________________
0064 TrkrClusterHitAssocv3::Map* TrkrClusterHitAssocv3::getClusterMap(TrkrDefs::hitsetkey hitsetkey)
0065 {
0066   // find relevant association map, create one if not found, and return adress
0067   return &m_map[hitsetkey];
0068 }
0069 
0070 //_________________________________________________________________________
0071 TrkrClusterHitAssocv3::ConstRange TrkrClusterHitAssocv3::getHits(TrkrDefs::cluskey ckey)
0072 {
0073   // get hitset key from cluster
0074   const TrkrDefs::hitsetkey hitsetkey = TrkrDefs::getHitSetKeyFromClusKey(ckey);
0075 
0076   // find relevant association map, create one if not found
0077   const auto iter = m_map.find(hitsetkey);
0078   if (iter != m_map.end())
0079   {
0080     return std::make_pair(iter->second.lower_bound(ckey), iter->second.upper_bound(ckey));
0081   }
0082   else
0083   {
0084     return std::make_pair(dummy_map.cbegin(), dummy_map.cend());
0085   }
0086 }
0087 
0088 //_________________________________________________________________________
0089 unsigned int TrkrClusterHitAssocv3::size() const
0090 {
0091   unsigned int size = 0;
0092   for (const auto& map_pair : m_map)
0093   {
0094     size += map_pair.second.size();
0095   }
0096 
0097   return size;
0098 }