Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "PHG4CylinderCellContainer.h"
0002 
0003 #include "PHG4CylinderCell.h"  // for PHG4CylinderCell
0004 #include "PHG4CylinderCellDefs.h"
0005 #include "PHG4CylinderCellv1.h"
0006 
0007 #include <cstdlib>
0008 
0009 using namespace std;
0010 
0011 void PHG4CylinderCellContainer::Reset()
0012 {
0013   while (cellmap.begin() != cellmap.end())
0014   {
0015     delete cellmap.begin()->second;
0016     cellmap.erase(cellmap.begin());
0017   }
0018   return;
0019 }
0020 
0021 void PHG4CylinderCellContainer::identify(ostream& os) const
0022 {
0023   map<unsigned int, PHG4CylinderCell*>::const_iterator iter;
0024   os << "Number of cells: " << size() << endl;
0025   for (iter = cellmap.begin(); iter != cellmap.end(); ++iter)
0026   {
0027     os << "cell key 0x" << hex << iter->first << dec << endl;
0028     (iter->second)->identify();
0029   }
0030   set<int>::const_iterator siter;
0031   os << "Number of layers: " << num_layers() << endl;
0032   for (siter = layers.begin(); siter != layers.end(); ++siter)
0033   {
0034     os << "layer : " << *siter << endl;
0035   }
0036   return;
0037 }
0038 
0039 PHG4CylinderCellDefs::keytype
0040 PHG4CylinderCellContainer::genkey(const unsigned int detid)
0041 {
0042   if ((detid >> PHG4CylinderCellDefs::keybits) > 0)
0043   {
0044     cout << " detector id too large: " << detid << endl;
0045     exit(1);
0046   }
0047   unsigned int shiftval = detid << PHG4CylinderCellDefs::cell_idbits;
0048   unsigned int cellid = cellmap.size();
0049   cellid++;
0050   PHG4CylinderCellDefs::keytype newkey = cellid | shiftval;
0051   if (cellmap.find(newkey) != cellmap.end())
0052   {
0053     cout << " duplicate key: " << newkey << " exiting now" << endl;
0054     exit(1);
0055   }
0056   return newkey;
0057 }
0058 
0059 PHG4CylinderCellContainer::ConstIterator
0060 PHG4CylinderCellContainer::AddCylinderCell(const unsigned int detid, PHG4CylinderCell* newcell)
0061 {
0062   PHG4CylinderCellDefs::keytype key = genkey(detid);
0063   layers.insert(newcell->get_layer());
0064   newcell->set_cell_id(key);
0065   cellmap[key] = newcell;
0066   return cellmap.find(key);
0067 }
0068 
0069 PHG4CylinderCellContainer::ConstIterator
0070 PHG4CylinderCellContainer::AddCylinderCellSpecifyKey(const PHG4CylinderCellDefs::keytype key, PHG4CylinderCell* newcell)
0071 {
0072   if (cellmap.find(key) != cellmap.end())
0073   {
0074     cout << "PHG4CylinderCellContainer::AddCylinderCellSpecifyKey: duplicate key: " << key << " exiting now" << endl;
0075     exit(1);
0076   }
0077   layers.insert(newcell->get_layer());
0078   newcell->set_cell_id(key);
0079   cellmap[key] = newcell;
0080   return cellmap.find(key);
0081 }
0082 
0083 PHG4CylinderCellContainer::ConstRange
0084 PHG4CylinderCellContainer::getCylinderCells(const unsigned int detid) const
0085 {
0086   if ((detid >> PHG4CylinderCellDefs::keybits) > 0)
0087   {
0088     cout << " detector id too large: " << detid << endl;
0089     exit(1);
0090   }
0091   //  unsigned int shiftval = detid << cell_idbits;
0092   PHG4CylinderCellDefs::keytype keylow = detid << PHG4CylinderCellDefs::cell_idbits;
0093   PHG4CylinderCellDefs::keytype keyup = ((detid + 1) << PHG4CylinderCellDefs::cell_idbits) - 1;
0094   //   cout << "keylow: 0x" << hex << keylow << dec << endl;
0095   //   cout << "keyup: 0x" << hex << keyup << dec << endl;
0096   ConstRange retpair;
0097   retpair.first = cellmap.lower_bound(keylow);
0098   retpair.second = cellmap.upper_bound(keyup);
0099   return retpair;
0100 }
0101 
0102 PHG4CylinderCellContainer::ConstRange
0103 PHG4CylinderCellContainer::getCylinderCells() const
0104 {
0105   return std::make_pair(cellmap.begin(), cellmap.end());
0106 }
0107 
0108 PHG4CylinderCellContainer::Iterator
0109 PHG4CylinderCellContainer::findOrAddCylinderCell(PHG4CylinderCellDefs::keytype key)
0110 {
0111   PHG4CylinderCellContainer::Iterator it = cellmap.find(key);
0112   if (it == cellmap.end())
0113   {
0114     cellmap[key] = new PHG4CylinderCellv1();
0115     it = cellmap.find(key);
0116     PHG4CylinderCell* mcell = it->second;
0117     mcell->set_cell_id(key);
0118     layers.insert(mcell->get_layer());  // add layer to our set of layers
0119   }
0120   return it;
0121 }
0122 
0123 PHG4CylinderCell*
0124 PHG4CylinderCellContainer::findCylinderCell(PHG4CylinderCellDefs::keytype key)
0125 {
0126   PHG4CylinderCellContainer::ConstIterator it = cellmap.find(key);
0127 
0128   if (it != cellmap.end())
0129   {
0130     return it->second;
0131   }
0132 
0133   return nullptr;
0134 }
0135 
0136 double
0137 PHG4CylinderCellContainer::getTotalEdep() const
0138 {
0139   ConstIterator iter;
0140   double totalenergy = 0;
0141   for (iter = cellmap.begin(); iter != cellmap.end(); ++iter)
0142   {
0143     totalenergy += iter->second->get_edep();
0144   }
0145   return totalenergy;
0146 }