Analysis Software
Documentation for sPHENIX simulation 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 "PHG4CylinderCellDefs.h"
5 #include "PHG4CylinderCellv1.h"
6 
7 #include <cstdlib>
8 
9 using namespace std;
10 
12 {
13  while (cellmap.begin() != cellmap.end())
14  {
15  delete cellmap.begin()->second;
16  cellmap.erase(cellmap.begin());
17  }
18  return;
19 }
20 
22 {
23  map<unsigned int, PHG4CylinderCell*>::const_iterator iter;
24  os << "Number of cells: " << size() << endl;
25  for (iter = cellmap.begin(); iter != cellmap.end(); ++iter)
26  {
27  os << "cell key 0x" << hex << iter->first << dec << endl;
28  (iter->second)->identify();
29  }
30  set<int>::const_iterator siter;
31  os << "Number of layers: " << num_layers() << endl;
32  for (siter = layers.begin(); siter != layers.end(); ++siter)
33  {
34  os << "layer : " << *siter << endl;
35  }
36  return;
37 }
38 
40 PHG4CylinderCellContainer::genkey(const unsigned int detid)
41 {
42  if ((detid >> PHG4CylinderCellDefs::keybits) > 0)
43  {
44  cout << " detector id too large: " << detid << endl;
45  exit(1);
46  }
47  unsigned int shiftval = detid << PHG4CylinderCellDefs::cell_idbits;
48  unsigned int cellid = cellmap.size();
49  cellid++;
50  PHG4CylinderCellDefs::keytype newkey = cellid | shiftval;
51  if (cellmap.find(newkey) != cellmap.end())
52  {
53  cout << " duplicate key: " << newkey << " exiting now" << endl;
54  exit(1);
55  }
56  return newkey;
57 }
58 
61 {
63  layers.insert(newcell->get_layer());
64  newcell->set_cell_id(key);
65  cellmap[key] = newcell;
66  return cellmap.find(key);
67 }
68 
71 {
72  if (cellmap.find(key) != cellmap.end())
73  {
74  cout << "PHG4CylinderCellContainer::AddCylinderCellSpecifyKey: duplicate key: " << key << " exiting now" << endl;
75  exit(1);
76  }
77  layers.insert(newcell->get_layer());
78  newcell->set_cell_id(key);
79  cellmap[key] = newcell;
80  return cellmap.find(key);
81 }
82 
84 PHG4CylinderCellContainer::getCylinderCells(const unsigned int detid) const
85 {
86  if ((detid >> PHG4CylinderCellDefs::keybits) > 0)
87  {
88  cout << " detector id too large: " << detid << endl;
89  exit(1);
90  }
91  // unsigned int shiftval = detid << cell_idbits;
93  PHG4CylinderCellDefs::keytype keyup = ((detid + 1) << PHG4CylinderCellDefs::cell_idbits) - 1;
94  // cout << "keylow: 0x" << hex << keylow << dec << endl;
95  // cout << "keyup: 0x" << hex << keyup << dec << endl;
96  ConstRange retpair;
97  retpair.first = cellmap.lower_bound(keylow);
98  retpair.second = cellmap.upper_bound(keyup);
99  return retpair;
100 }
101 
104 {
105  return std::make_pair(cellmap.begin(), cellmap.end());
106 }
107 
110 {
111  PHG4CylinderCellContainer::Iterator it = cellmap.find(key);
112  if (it == cellmap.end())
113  {
114  cellmap[key] = new PHG4CylinderCellv1();
115  it = cellmap.find(key);
116  PHG4CylinderCell* mcell = it->second;
117  mcell->set_cell_id(key);
118  layers.insert(mcell->get_layer()); // add layer to our set of layers
119  }
120  return it;
121 }
122 
125 {
126  PHG4CylinderCellContainer::ConstIterator it = cellmap.find(key);
127 
128  if (it != cellmap.end())
129  {
130  return it->second;
131  }
132 
133  return nullptr;
134 }
135 
136 double
138 {
139  ConstIterator iter;
140  double totalenergy = 0;
141  for (iter = cellmap.begin(); iter != cellmap.end(); ++iter)
142  {
143  totalenergy += iter->second->get_edep();
144  }
145  return totalenergy;
146 }