Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:17:43

0001 #include "PHG4CellContainer.h"
0002 
0003 #include "PHG4Cell.h"  // for PHG4Cell
0004 #include "PHG4CellDefs.h"
0005 #include "PHG4Cellv1.h"
0006 
0007 #include <cstdlib>
0008 
0009 using namespace std;
0010 
0011 PHG4CellContainer::PHG4CellContainer() = default;
0012 
0013 void PHG4CellContainer::Reset()
0014 {
0015   while (cellmap.begin() != cellmap.end())
0016   {
0017     delete cellmap.begin()->second;
0018     cellmap.erase(cellmap.begin());
0019   }
0020   return;
0021 }
0022 
0023 void PHG4CellContainer::identify(ostream& os) const
0024 {
0025   ConstIterator iter;
0026   os << "Number of cells: " << size() << endl;
0027   for (iter = cellmap.begin(); iter != cellmap.end(); ++iter)
0028   {
0029     os << "cell key 0x" << hex << iter->first << dec << endl;
0030     (iter->second)->identify();
0031   }
0032   return;
0033 }
0034 
0035 PHG4CellContainer::ConstIterator
0036 PHG4CellContainer::AddCell(PHG4Cell* newcell)
0037 {
0038   PHG4CellDefs::keytype key = newcell->get_cellid();
0039   if (cellmap.find(key) != cellmap.end())
0040   {
0041     cout << "overwriting cell 0x" << hex << key << dec << endl;
0042     cout << "layer: " << PHG4CellDefs::get_detid(key) << endl;
0043   }
0044   cellmap[key] = newcell;
0045   return cellmap.find(key);
0046 }
0047 
0048 PHG4CellContainer::ConstIterator
0049 PHG4CellContainer::AddCellSpecifyKey(const PHG4CellDefs::keytype key, PHG4Cell* newcell)
0050 {
0051   if (cellmap.find(key) != cellmap.end())
0052   {
0053     cout << "PHG4CellContainer::AddCellSpecifyKey: duplicate key: " << key << " exiting now" << endl;
0054     exit(1);
0055   }
0056   newcell->set_cellid(key);
0057   cellmap[key] = newcell;
0058   return cellmap.find(key);
0059 }
0060 
0061 PHG4CellContainer::ConstRange
0062 PHG4CellContainer::getCells(const unsigned short int detid) const
0063 {
0064   PHG4CellDefs::keytype tmp = detid;
0065   PHG4CellDefs::keytype keylow = tmp << PHG4CellDefs::bitshift_layer;
0066   PHG4CellDefs::keytype keyup = ((tmp + 1) << PHG4CellDefs::bitshift_layer) - 1;
0067   //   cout << "keylow: 0x" << hex << keylow << dec << endl;
0068   //   cout << "keyup: 0x" << hex << keyup << dec << endl;
0069   ConstRange retpair;
0070   retpair.first = cellmap.lower_bound(keylow);
0071   retpair.second = cellmap.upper_bound(keyup);
0072   return retpair;
0073 }
0074 
0075 PHG4CellContainer::ConstRange
0076 PHG4CellContainer::getCells() const
0077 {
0078   return std::make_pair(cellmap.begin(), cellmap.end());
0079 }
0080 
0081 PHG4CellContainer::Iterator
0082 PHG4CellContainer::findOrAddCell(PHG4CellDefs::keytype key)
0083 {
0084   PHG4CellContainer::Iterator it = cellmap.find(key);
0085   if (it == cellmap.end())
0086   {
0087     cellmap[key] = new PHG4Cellv1();
0088     it = cellmap.find(key);
0089     PHG4Cell* mcell = it->second;
0090     mcell->set_cellid(key);
0091   }
0092   return it;
0093 }
0094 
0095 PHG4Cell*
0096 PHG4CellContainer::findCell(PHG4CellDefs::keytype key)
0097 {
0098   PHG4CellContainer::ConstIterator it = cellmap.find(key);
0099 
0100   if (it != cellmap.end())
0101   {
0102     return it->second;
0103   }
0104 
0105   return nullptr;
0106 }
0107 
0108 double
0109 PHG4CellContainer::getTotalEdep() const
0110 {
0111   ConstIterator iter;
0112   double totalenergy = 0;
0113   for (iter = cellmap.begin(); iter != cellmap.end(); ++iter)
0114   {
0115     totalenergy += iter->second->get_edep();
0116   }
0117   return totalenergy;
0118 }