Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:28

0001 #include "RawClusterContainer.h"
0002 
0003 #include "RawCluster.h"
0004 
0005 #include <iostream>
0006 
0007 RawClusterContainer::ConstRange
0008 RawClusterContainer::getClusters() const
0009 {
0010   return std::make_pair(_clusters.begin(), _clusters.end());
0011 }
0012 
0013 RawClusterContainer::Range
0014 RawClusterContainer::getClusters()
0015 {
0016   return std::make_pair(_clusters.begin(), _clusters.end());
0017 }
0018 
0019 RawClusterContainer::ConstIterator
0020 RawClusterContainer::AddCluster(RawCluster* rawcluster)
0021 {
0022   unsigned int key = _clusters.size();
0023   // just to be safe in case someone deleted a cluster and key is
0024   // a valid index of a cluster, increment key until there is no cluster
0025   // in our map
0026   while (_clusters.find(key) != _clusters.end())
0027   {
0028     key++;
0029   }
0030   rawcluster->set_id(key);
0031   _clusters[key] = rawcluster;
0032   return _clusters.find(key);
0033 }
0034 
0035 RawCluster*
0036 RawClusterContainer::getCluster(const unsigned int key)
0037 {
0038   ConstIterator it = _clusters.find(key);
0039   if (it != _clusters.end())
0040   {
0041     return it->second;
0042   }
0043   return nullptr;
0044 }
0045 
0046 const RawCluster*
0047 RawClusterContainer::getCluster(const unsigned int key) const
0048 {
0049   ConstIterator it = _clusters.find(key);
0050   if (it != _clusters.end())
0051   {
0052     return it->second;
0053   }
0054   return nullptr;
0055 }
0056 
0057 int RawClusterContainer::isValid() const
0058 {
0059   return (!_clusters.empty());
0060 }
0061 
0062 void RawClusterContainer::Reset()
0063 {
0064   while (_clusters.begin() != _clusters.end())
0065   {
0066     delete _clusters.begin()->second;
0067     _clusters.erase(_clusters.begin());
0068   }
0069 }
0070 
0071 void RawClusterContainer::identify(std::ostream& os) const
0072 {
0073   os << "RawClusterContainer, number of clusters: " << size() << std::endl;
0074 }
0075 
0076 double
0077 RawClusterContainer::getTotalEdep() const
0078 {
0079   double totalenergy = 0;
0080   ConstIterator iter;
0081   for (iter = _clusters.begin(); iter != _clusters.end(); ++iter)
0082   {
0083     totalenergy += iter->second->get_energy();
0084   }
0085   return totalenergy;
0086 }