ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4CylinderCellContainer.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4CylinderCellContainer.cc
2 
3 #include "PHG4CylinderCell.h" // for PHG4CylinderCell
4 #include "PHG4CylinderCellv1.h"
5 #include "PHG4CylinderCellDefs.h"
6 
7 #include <cstdlib>
8 
9 using namespace std;
10 
11 void
13 {
14  while(cellmap.begin() != cellmap.end())
15  {
16  delete cellmap.begin()->second;
17  cellmap.erase(cellmap.begin());
18  }
19  return;
20 }
21 
22 void
24 {
25  map<unsigned int,PHG4CylinderCell *>::const_iterator 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  set<int>::const_iterator siter;
33  os << "Number of layers: " << num_layers() << endl;
34  for (siter = layers.begin(); siter != layers.end(); ++siter)
35  {
36  os << "layer : " << *siter << endl;
37  }
38  return;
39 }
40 
41 
43 PHG4CylinderCellContainer::genkey(const unsigned int detid)
44 {
45  if ((detid >> PHG4CylinderCellDefs::keybits) > 0)
46  {
47  cout << " detector id too large: " << detid << endl;
48  exit(1);
49  }
50  unsigned int shiftval = detid << PHG4CylinderCellDefs::cell_idbits;
51  unsigned int cellid = cellmap.size();
52  cellid++;
53  PHG4CylinderCellDefs::keytype newkey = cellid | shiftval;
54  if (cellmap.find(newkey) != cellmap.end())
55  {
56  cout << " duplicate key: " << newkey << " exiting now" << endl;
57  exit(1);
58  }
59  return newkey;
60 }
61 
64 {
66  layers.insert(newcell->get_layer());
67  newcell->set_cell_id(key);
68  cellmap[key] = newcell;
69  return cellmap.find(key);
70 }
71 
74 {
75  if(cellmap.find(key)!=cellmap.end())
76  {
77  cout << "PHG4CylinderCellContainer::AddCylinderCellSpecifyKey: duplicate key: " << key << " exiting now" << endl;
78  exit(1);
79  }
80  layers.insert(newcell->get_layer());
81  newcell->set_cell_id(key);
82  cellmap[key] = newcell;
83  return cellmap.find(key);
84 }
85 
87 PHG4CylinderCellContainer::getCylinderCells(const unsigned int detid) const
88 {
89  if ((detid >> PHG4CylinderCellDefs::keybits) > 0)
90  {
91  cout << " detector id too large: " << detid << endl;
92  exit(1);
93  }
94  // unsigned int shiftval = detid << cell_idbits;
96  PHG4CylinderCellDefs::keytype keyup = ((detid + 1)<< PHG4CylinderCellDefs::cell_idbits) -1 ;
97 // cout << "keylow: 0x" << hex << keylow << dec << endl;
98 // cout << "keyup: 0x" << hex << keyup << dec << endl;
99  ConstRange retpair;
100  retpair.first = cellmap.lower_bound(keylow);
101  retpair.second = cellmap.upper_bound(keyup);
102  return retpair;
103 }
104 
107 { return std::make_pair( cellmap.begin(), cellmap.end() ); }
108 
109 
112 {
113  PHG4CylinderCellContainer::Iterator it = cellmap.find(key);
114  if(it == cellmap.end())
115  {
116  cellmap[key] = new PHG4CylinderCellv1();
117  it = cellmap.find(key);
118  PHG4CylinderCell* mcell = it->second;
119  mcell->set_cell_id(key);
120  layers.insert(mcell->get_layer()); // add layer to our set of layers
121  }
122  return it;
123 }
124 
127 {
128  PHG4CylinderCellContainer::ConstIterator it = cellmap.find(key);
129 
130  if(it != cellmap.end())
131  {
132  return it->second;
133  }
134 
135  return 0;
136 }
137 
138 double
140 {
141  ConstIterator iter;
142  double totalenergy = 0;
143  for (iter = cellmap.begin(); iter != cellmap.end(); ++iter)
144  {
145  totalenergy += iter->second->get_edep();
146  }
147  return totalenergy;
148 }