CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
RecEmcCluster.cxx
Go to the documentation of this file.
1//
2// Bes EMC Rec Cluster
3//
4// Created by Zhe Wang 2003, 10, 1
5//
6#include <iostream>
7
10#include "GaudiKernel/Bootstrap.h"
11#include "GaudiKernel/ISvcLocator.h"
12
13//Constructors and destructors
18
23
24//Copy and assignment
25/*RecEmcCluster::RecEmcCluster(const RecEmcCluster& aCluster)
26 :ContainedObject(aCluster)
27{
28 RecEmcHitMap::const_iterator pHitMap;
29
30 Clear();
31
32 for(pHitMap=aCluster.Begin();
33 pHitMap!=aCluster.End();
34 pHitMap++)
35 {
36 Insert(pHitMap->second);
37 }
38
39 RecEmcHitMap::const_iterator pSeedMap;
40 for(pSeedMap=aCluster.BeginSeed();
41 pSeedMap!=aCluster.EndSeed();
42 pSeedMap++)
43 {
44 InsertSeed(pSeedMap->second);
45 }
46
47 map<RecEmcID,RecEmcShower*,less<RecEmcID> >::const_iterator pShowerMap;
48 for(pShowerMap=aCluster.BeginShower();
49 pShowerMap!=aCluster.EndShower();
50 pShowerMap++)
51 {
52 InsertShower(pShowerMap->second);
53 }
54
55 fClusterId=aCluster.ClusterId();
56}
57
58RecEmcCluster& RecEmcCluster::operator=(const RecEmcCluster& aCluster)
59{
60 RecEmcHitMap::const_iterator pHitMap;
61
62 Clear();
63
64 if(this!=&aCluster)
65 {
66 for(pHitMap=aCluster.Begin();
67 pHitMap!=aCluster.End();
68 pHitMap++)
69 {
70 Insert(pHitMap->second);
71 }
72
73 RecEmcHitMap::const_iterator pSeedMap;
74 for(pSeedMap=aCluster.BeginSeed();
75 pSeedMap!=aCluster.EndSeed();
76 pSeedMap++)
77 {
78 InsertSeed(pSeedMap->second);
79 }
80
81 map<RecEmcID,RecEmcShower*,less<RecEmcID> >::const_iterator pShowerMap;
82 for(pShowerMap=aCluster.BeginShower();
83 pShowerMap!=aCluster.EndShower();
84 pShowerMap++)
85 {
86 InsertShower(pShowerMap->second);
87 }
88
89 fClusterId=aCluster.ClusterId();
90 }
91
92 return *this;
93}*/
94
95//Other methods
97{
99 fHitMap.clear();
100 fSeedMap.clear();
101 fShowerIdVec.clear();
102}
103
104//Access a cluster
105//RecEmcID RecEmcCluster::ClusterId() const
106//{
107// return fClusterId;
108//}
109
111{
112 fClusterId=id;
113}
114
115RecEmcHitMap::const_iterator RecEmcCluster::Begin() const
116{
117 return fHitMap.begin();
118}
119
120RecEmcHitMap::const_iterator RecEmcCluster::End() const
121{
122 return fHitMap.end();
123}
124
125RecEmcHitMap::const_iterator RecEmcCluster::Find(const RecEmcID& CellId) const
126{
127 // If failed the return vale is End().
128 return fHitMap.find(CellId);
129}
130
131//Insert and Erase a hit
133{
134 fHitMap[aHit.getCellId()]=aHit;
135 //fClusterId=fHitMap.begin()->first;
136 return;
137}
138
140{
141 RecEmcHitMap::const_iterator pHitMap;
142 pHitMap=fHitMap.find(aHit.getCellId());
143
144 //blank HitMap
145 if(fHitMap.empty())
146 {
147 return;
148 }
149
150 //not find
151 if(pHitMap==End())
152 {
153 return;
154 }
155
156 //find it
157 if(pHitMap!=End())
158 {
159 fHitMap.erase(pHitMap->first);
160 //empty
161 if(fHitMap.empty())
162 {
163 Clear();
164 return;
165 }
166 //not empty
167 else
168 {
169 fClusterId=fHitMap.begin()->first;
170 return;
171 }
172 }
173}
174
175//======== Seed map
176RecEmcHitMap::const_iterator RecEmcCluster::BeginSeed() const
177{
178 return fSeedMap.begin();
179}
180
181RecEmcHitMap::const_iterator RecEmcCluster::EndSeed() const
182{
183 return fSeedMap.end();
184}
185
186RecEmcHitMap::const_iterator RecEmcCluster::FindSeed(const RecEmcID& CellId) const
187{
188 // If failed the return vale is End().
189 return fSeedMap.find(CellId);
190}
191
192//Insert and Erase a seed
194{
195 fSeedMap[aSeed.getCellId()]=aSeed;
196 return;
197}
198
200{
201 return fSeedMap.size();
202}
203
205{
206 return fShowerIdVec.size();
207}
208
209//Insert and Erase a shower
211{
212 fShowerIdVec.push_back(id);
213}
214
215//Cluster energy
217{
218 RecEmcHitMap::const_iterator pHitMap;
219 double etot=0;
220
221 for(pHitMap=fHitMap.begin();
222 pHitMap!=fHitMap.end();
223 pHitMap++) {
224 etot+=pHitMap->second.getEnergy();
225 }
226 return etot;
227}
228
229//Cluster position
231{
232 IEmcRecGeoSvc* iGeoSvc;
233 ISvcLocator* svcLocator = Gaudi::svcLocator();
234 StatusCode sc = svcLocator->service("EmcRecGeoSvc",iGeoSvc);
235 if(sc!=StatusCode::SUCCESS) {
236 cout<<"Error: Can't get EmcRecGeoSvc"<<endl;
237 }
238
239 RecEmcHitMap::const_iterator pHitMap;
240 HepPoint3D pos(0,0,0);
241 HepPoint3D possum(0,0,0);
242 double etot=0;
243
244 for(pHitMap=fHitMap.begin();
245 pHitMap!=fHitMap.end();
246 pHitMap++) {
247 etot+=pHitMap->second.getEnergy();
248 pos=iGeoSvc->GetCFrontCenter(pHitMap->second.getCellId());
249 possum+=pos*pHitMap->second.getEnergy();
250 }
251
252 if(etot>0) {
253 possum/=etot;
254 }
255 return possum;
256}
257
258//Cluster second moment
260{
261 IEmcRecGeoSvc* iGeoSvc;
262 ISvcLocator* svcLocator = Gaudi::svcLocator();
263 StatusCode sc = svcLocator->service("EmcRecGeoSvc",iGeoSvc);
264 if(sc!=StatusCode::SUCCESS) {
265 cout<<"Error: Can't get EmcRecGeoSvc"<<endl;
266 }
267
268 double etot=0;
269 double sum=0;
270 HepPoint3D center(getPosition());
271 RecEmcHitMap::const_iterator pHitMap;
272
273 for(pHitMap=fHitMap.begin();
274 pHitMap!=fHitMap.end();
275 pHitMap++) {
276 HepPoint3D pos(pHitMap->second.getFrontCenter());
277 etot+=pHitMap->second.getEnergy();
278 sum+=pHitMap->second.getEnergy()*pos.distance2(center);
279 }
280
281 if(etot>0) {
282 sum/=etot;
283 }
284 return sum;
285}
286
287//Dump out.
289{
290 RecEmcHitMap::const_iterator pHitMap;
291
292 cout<<"EMC Cluster: ";
293
294 cout<<"Cluster Id= ";
295 cout<<fClusterId<<endl;
296
297 for(pHitMap=fHitMap.begin();
298 pHitMap!=fHitMap.end();
299 pHitMap++)
300 {
301 pHitMap->second.Dump();
302 }
303}
304
305ostream& operator<<(ostream & os, const RecEmcCluster& aCluster)
306{
307 RecEmcHitMap::const_iterator pHitMap;
308
309 cout<<"EMC Cluster: ";
310
311 cout<<"Cluster Id= ";
312 cout<<aCluster.getClusterId()<<endl;
313
314 for(pHitMap=aCluster.Begin();
315 pHitMap!=aCluster.End();
316 pHitMap++)
317 {
318 os<< (pHitMap->second);
319 }
320
321 if(aCluster.getSeedSize()>0) {
322 cout<<"Contains "<<aCluster.getSeedSize()<<" Seeds:"<<endl;
323 RecEmcHitMap::const_iterator pSeedMap;
324 for(pSeedMap=aCluster.BeginSeed();
325 pSeedMap!=aCluster.EndSeed();
326 pSeedMap++)
327 {
328 os<< (pSeedMap->second);
329 }
330 }
331
332 if(aCluster.getShowerSize()>0) {
333 vector<RecEmcID> aShowerIdVec=aCluster.getShowerIdVec();
334 vector<RecEmcID>::iterator iShowerId;
335 os<<"Contains "<<aCluster.getShowerSize()<<" Showers:"<<endl;
336 for(iShowerId=aShowerIdVec.begin();
337 iShowerId!=aShowerIdVec.end();
338 iShowerId++) {
339 os << *iShowerId <<endl;
340 }
341 }
342
343 return os;
344}
Double_t etot
ostream & operator<<(ostream &os, const RecEmcCluster &aCluster)
double RecEmcEnergy
virtual HepPoint3D GetCFrontCenter(const Identifier &id) const =0
virtual void clear()
Reset to invalid state.
Definition Identifier.h:152
RecEmcEnergy getEnergy() const
RecEmcID getClusterId() const
HepPoint3D getPosition() const
void Insert(const RecEmcHit &aHit)
RecEmcHitMap::const_iterator FindSeed(const RecEmcID &CellId) const
RecEmcHitMap::const_iterator EndSeed() const
RecEmcHitMap::const_iterator BeginSeed() const
RecEmcHitMap::const_iterator Find(const RecEmcID &CellId) const
int getSeedSize() const
RecEmcHitMap fHitMap
double getSecondMoment() const
RecEmcID fClusterId
RecEmcHitMap::const_iterator Begin() const
void Dump() const
RecEmcHitMap fSeedMap
void Erase(const RecEmcHit &aHit)
void InsertSeed(const RecEmcHit &aSeed)
RecEmcHitMap::const_iterator End() const
vector< RecEmcID > fShowerIdVec
void ClusterId(const RecEmcID id)
vector< RecEmcID > getShowerIdVec() const
void InsertShowerId(const RecEmcID id)
int getShowerSize() const
RecEmcID getCellId() const
Definition RecEmcHit.h:47