Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4CellContainer.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4CellContainer.cc
1 #include "PHG4CellContainer.h"
2 
3 #include "PHG4Cell.h" // for PHG4Cell
4 #include "PHG4CellDefs.h"
5 #include "PHG4Cellv1.h"
6 
7 #include <cstdlib>
8 
9 using namespace std;
10 
12 
14 {
15  while (cellmap.begin() != cellmap.end())
16  {
17  delete cellmap.begin()->second;
18  cellmap.erase(cellmap.begin());
19  }
20  return;
21 }
22 
23 void PHG4CellContainer::identify(ostream& os) const
24 {
25  ConstIterator iter;
26  os << "Number of cells: " << size() << endl;
27  for (iter = cellmap.begin(); iter != cellmap.end(); ++iter)
28  {
29  os << "cell key 0x" << hex << iter->first << dec << endl;
30  (iter->second)->identify();
31  }
32  return;
33 }
34 
37 {
38  PHG4CellDefs::keytype key = newcell->get_cellid();
39  if (cellmap.find(key) != cellmap.end())
40  {
41  cout << "overwriting cell 0x" << hex << key << dec << endl;
42  cout << "layer: " << PHG4CellDefs::get_detid(key) << endl;
43  }
44  cellmap[key] = newcell;
45  return cellmap.find(key);
46 }
47 
50 {
51  if (cellmap.find(key) != cellmap.end())
52  {
53  cout << "PHG4CellContainer::AddCellSpecifyKey: duplicate key: " << key << " exiting now" << endl;
54  exit(1);
55  }
56  newcell->set_cellid(key);
57  cellmap[key] = newcell;
58  return cellmap.find(key);
59 }
60 
62 PHG4CellContainer::getCells(const unsigned short int detid) const
63 {
64  PHG4CellDefs::keytype tmp = detid;
65  PHG4CellDefs::keytype keylow = tmp << PHG4CellDefs::bitshift_layer;
66  PHG4CellDefs::keytype keyup = ((tmp + 1) << PHG4CellDefs::bitshift_layer) - 1;
67  // cout << "keylow: 0x" << hex << keylow << dec << endl;
68  // cout << "keyup: 0x" << hex << keyup << dec << endl;
69  ConstRange retpair;
70  retpair.first = cellmap.lower_bound(keylow);
71  retpair.second = cellmap.upper_bound(keyup);
72  return retpair;
73 }
74 
77 {
78  return std::make_pair(cellmap.begin(), cellmap.end());
79 }
80 
83 {
84  PHG4CellContainer::Iterator it = cellmap.find(key);
85  if (it == cellmap.end())
86  {
87  cellmap[key] = new PHG4Cellv1();
88  it = cellmap.find(key);
89  PHG4Cell* mcell = it->second;
90  mcell->set_cellid(key);
91  }
92  return it;
93 }
94 
95 PHG4Cell*
97 {
98  PHG4CellContainer::ConstIterator it = cellmap.find(key);
99 
100  if (it != cellmap.end())
101  {
102  return it->second;
103  }
104 
105  return nullptr;
106 }
107 
108 double
110 {
111  ConstIterator iter;
112  double totalenergy = 0;
113  for (iter = cellmap.begin(); iter != cellmap.end(); ++iter)
114  {
115  totalenergy += iter->second->get_edep();
116  }
117  return totalenergy;
118 }