forked from sPHENIX-Collaboration/coresoftware
/
PHG4HitContainer.cc
201 lines (179 loc) · 5.3 KB
/
PHG4HitContainer.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "PHG4HitContainer.h"
#include "PHG4Hit.h"
#include "PHG4Hitv1.h"
#include <phool/phool.h>
#include <TSystem.h>
#include <cstdlib>
using namespace std;
PHG4HitContainer::PHG4HitContainer()
: id(-1), hitmap(), layers()
{
}
PHG4HitContainer::PHG4HitContainer(const std::string &nodename)
: id(PHG4HitDefs::get_volume_id(nodename)), hitmap(), layers()
{
}
void
PHG4HitContainer::Reset()
{
while(hitmap.begin() != hitmap.end())
{
delete hitmap.begin()->second;
hitmap.erase(hitmap.begin());
}
return;
}
void
PHG4HitContainer::identify(ostream& os) const
{
ConstIterator iter;
os << "Number of hits: " << size() << endl;
for (iter = hitmap.begin(); iter != hitmap.end(); ++iter)
{
os << "hit key 0x" << hex << iter->first << dec << endl;
(iter->second)->identify();
}
set<unsigned int>::const_iterator siter;
os << "Number of layers: " << num_layers() << endl;
for (siter = layers.begin(); siter != layers.end(); ++siter)
{
os << "layer : " << *siter << endl;
}
return;
}
PHG4HitDefs::keytype
PHG4HitContainer::getmaxkey(const unsigned int detid)
{
ConstRange miter = getHits(detid);
// first handle 2 special cases where there is no hit in the current layer
// no hits in this layer and higher layers (lower layers can contain hits)
if (miter.first == hitmap.end())
{
return 0;
}
// no hits in this layer - but hits in higher layers
if (miter.first == miter.second)
{
return 0;
}
PHG4HitDefs::keytype detidlong = detid;
PHG4HitDefs::keytype shiftval = detidlong << PHG4HitDefs::hit_idbits;
ConstIterator lastlayerentry = miter.second;
--lastlayerentry;
PHG4HitDefs::keytype iret = lastlayerentry->first - shiftval; // subtract layer mask
return iret;
}
PHG4HitDefs::keytype
PHG4HitContainer::genkey(const unsigned int detid)
{
PHG4HitDefs::keytype detidlong = detid;
if ((detidlong >> PHG4HitDefs::keybits) > 0)
{
cout << PHWHERE << " detector id too large: " << detid << endl;
gSystem->Exit(1);
}
PHG4HitDefs::keytype shiftval = detidlong << PHG4HitDefs::hit_idbits;
// cout << "max index: " << (detminmax->second)->first << endl;
// after removing hits with no energy deposition, we have holes
// in our hit ranges. This construct will get us the last hit in
// a layer and return it's hit id. Adding 1 will put us at the end of this layer
PHG4HitDefs::keytype hitid = getmaxkey(detid);
hitid++;
PHG4HitDefs::keytype newkey = hitid | shiftval;
if (hitmap.find(newkey) != hitmap.end())
{
cout << PHWHERE << " duplicate key: 0x"
<< hex << newkey << dec
<< " for detector " << detid
<< " hitmap.size: " << hitmap.size()
<< " hitid: " << hitid << " exiting now" << endl;
exit(1);
}
return newkey;
}
PHG4HitContainer::ConstIterator
PHG4HitContainer::AddHit(PHG4Hit *newhit)
{
PHG4HitDefs::keytype key = newhit->get_hit_id();
if (hitmap.find(key) != hitmap.end())
{
cout << "hit with id 0x" << hex << key << dec << " exists already" << endl;
return hitmap.find(key);
}
PHG4HitDefs::keytype detidlong = key >> PHG4HitDefs::hit_idbits;
unsigned int detid = detidlong;
layers.insert(detid);
return hitmap.insert( std::make_pair( key, newhit ) ).first;
}
PHG4HitContainer::ConstIterator
PHG4HitContainer::AddHit(const unsigned int detid, PHG4Hit *newhit)
{
PHG4HitDefs::keytype key = genkey(detid);
layers.insert(detid);
newhit->set_hit_id(key);
return hitmap.insert( std::make_pair( key, newhit ) ).first;
}
PHG4HitContainer::ConstRange PHG4HitContainer::getHits(const unsigned int detid) const
{
PHG4HitDefs::keytype detidlong = detid;
if ((detidlong >> PHG4HitDefs::keybits) > 0)
{
cout << " detector id too large: " << detid << endl;
exit(1);
}
PHG4HitDefs::keytype keylow = detidlong << PHG4HitDefs::hit_idbits;
PHG4HitDefs::keytype keyup = ((detidlong + 1) << PHG4HitDefs::hit_idbits) -1 ;
ConstRange retpair;
retpair.first = hitmap.lower_bound(keylow);
retpair.second = hitmap.upper_bound(keyup);
return retpair;
}
PHG4HitContainer::ConstRange PHG4HitContainer::getHits( void ) const
{ return std::make_pair( hitmap.begin(), hitmap.end() ); }
PHG4HitContainer::Iterator PHG4HitContainer::findOrAddHit(PHG4HitDefs::keytype key)
{
PHG4HitContainer::Iterator it = hitmap.find(key);
if(it == hitmap.end())
{
hitmap[key] = new PHG4Hitv1();
it = hitmap.find(key);
PHG4Hit* mhit = it->second;
mhit->set_hit_id(key);
mhit->set_edep(0.);
layers.insert(mhit->get_layer()); // add layer to our set of layers
}
return it;
}
PHG4Hit* PHG4HitContainer::findHit(PHG4HitDefs::keytype key)
{
PHG4HitContainer::ConstIterator it = hitmap.find(key);
if(it != hitmap.end())
{
return it->second;
}
return nullptr;
}
void
PHG4HitContainer::RemoveZeroEDep()
{
// unsigned int hitsbef = hitmap.size();
Iterator itr = hitmap.begin();
Iterator last = hitmap.end();
for (; itr != last; )
{
PHG4Hit *hit = itr->second;
if (hit->get_edep() == 0)
{
delete hit;
hitmap.erase(itr++);
}
else
{
++itr;
}
}
// unsigned int hitsafter = hitmap.size();
// cout << "hist before: " << hitsbef
// << ", hits after: " << hitsafter << endl;
return;
}