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