ECCE @ EIC 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 "PHG4Cellv1.h"
5 #include "PHG4CellDefs.h"
6 
7 #include <cstdlib>
8 
9 using namespace std;
10 
12 {}
13 
14 void
16 {
17  while(cellmap.begin() != cellmap.end())
18  {
19  delete cellmap.begin()->second;
20  cellmap.erase(cellmap.begin());
21  }
22  return;
23 }
24 
25 void
26 PHG4CellContainer::identify(ostream& os) const
27 {
28  ConstIterator iter;
29  os << "Number of cells: " << size() << endl;
30  for (iter = cellmap.begin(); iter != cellmap.end(); ++iter)
31  {
32  os << "cell key 0x" << hex << iter->first << dec << endl;
33  (iter->second)->identify();
34  }
35  return;
36 }
37 
40 {
41  PHG4CellDefs::keytype key = newcell->get_cellid();
42  if (cellmap.find(key) != cellmap.end())
43  {
44  cout << "overwriting cell 0x" << hex << key << dec << endl;
45  cout << "layer: " << PHG4CellDefs::get_detid(key) << endl;
46  }
47  cellmap[key] = newcell;
48  return cellmap.find(key);
49 }
50 
53 {
54  if(cellmap.find(key)!=cellmap.end())
55  {
56  cout << "PHG4CellContainer::AddCellSpecifyKey: duplicate key: " << key << " exiting now" << endl;
57  exit(1);
58  }
59  newcell->set_cellid(key);
60  cellmap[key] = newcell;
61  return cellmap.find(key);
62 }
63 
65 PHG4CellContainer::getCells(const unsigned short int detid) const
66 {
67  PHG4CellDefs::keytype tmp = detid;
68  PHG4CellDefs::keytype keylow = tmp << PHG4CellDefs::bitshift_layer;
69  PHG4CellDefs::keytype keyup = ((tmp + 1)<< PHG4CellDefs::bitshift_layer) -1 ;
70 // cout << "keylow: 0x" << hex << keylow << dec << endl;
71 // cout << "keyup: 0x" << hex << keyup << dec << endl;
72  ConstRange retpair;
73  retpair.first = cellmap.lower_bound(keylow);
74  retpair.second = cellmap.upper_bound(keyup);
75  return retpair;
76 }
77 
80 { return std::make_pair( cellmap.begin(), cellmap.end() ); }
81 
82 
85 {
86  PHG4CellContainer::Iterator it = cellmap.find(key);
87  if(it == cellmap.end())
88  {
89  cellmap[key] = new PHG4Cellv1();
90  it = cellmap.find(key);
91  PHG4Cell* mcell = it->second;
92  mcell->set_cellid(key);
93  }
94  return it;
95 }
96 
97 PHG4Cell*
99 {
100  PHG4CellContainer::ConstIterator it = cellmap.find(key);
101 
102  if(it != cellmap.end())
103  {
104  return it->second;
105  }
106 
107  return 0;
108 }
109 
110 double
112 {
113  ConstIterator iter;
114  double totalenergy = 0;
115  for (iter = cellmap.begin(); iter != cellmap.end(); ++iter)
116  {
117  totalenergy += iter->second->get_edep();
118  }
119  return totalenergy;
120 }