BOSS 8.0.0
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
8#include "EmcRecEventModel/RecEmcCluster.h"
9#include "EmcRecGeoSvc/IEmcRecGeoSvc.h"
10#include "GaudiKernel/Bootstrap.h"
11#include "GaudiKernel/ISvcLocator.h"
12
13// Constructors and destructors
15
17
18// Copy and assignment
19/*RecEmcCluster::RecEmcCluster(const RecEmcCluster& aCluster)
20 :ContainedObject(aCluster)
21{
22 RecEmcHitMap::const_iterator pHitMap;
23
24 Clear();
25
26 for(pHitMap=aCluster.Begin();
27 pHitMap!=aCluster.End();
28 pHitMap++)
29 {
30 Insert(pHitMap->second);
31 }
32
33 RecEmcHitMap::const_iterator pSeedMap;
34 for(pSeedMap=aCluster.BeginSeed();
35 pSeedMap!=aCluster.EndSeed();
36 pSeedMap++)
37 {
38 InsertSeed(pSeedMap->second);
39 }
40
41 map<RecEmcID,RecEmcShower*,less<RecEmcID> >::const_iterator pShowerMap;
42 for(pShowerMap=aCluster.BeginShower();
43 pShowerMap!=aCluster.EndShower();
44 pShowerMap++)
45 {
46 InsertShower(pShowerMap->second);
47 }
48
49 fClusterId=aCluster.ClusterId();
50}
51
52RecEmcCluster& RecEmcCluster::operator=(const RecEmcCluster& aCluster)
53{
54 RecEmcHitMap::const_iterator pHitMap;
55
56 Clear();
57
58 if(this!=&aCluster)
59 {
60 for(pHitMap=aCluster.Begin();
61 pHitMap!=aCluster.End();
62 pHitMap++)
63 {
64 Insert(pHitMap->second);
65 }
66
67 RecEmcHitMap::const_iterator pSeedMap;
68 for(pSeedMap=aCluster.BeginSeed();
69 pSeedMap!=aCluster.EndSeed();
70 pSeedMap++)
71 {
72 InsertSeed(pSeedMap->second);
73 }
74
75 map<RecEmcID,RecEmcShower*,less<RecEmcID> >::const_iterator pShowerMap;
76 for(pShowerMap=aCluster.BeginShower();
77 pShowerMap!=aCluster.EndShower();
78 pShowerMap++)
79 {
80 InsertShower(pShowerMap->second);
81 }
82
83 fClusterId=aCluster.ClusterId();
84 }
85
86 return *this;
87}*/
88
89// Other methods
91 fClusterId.clear();
92 fHitMap.clear();
93 fSeedMap.clear();
94 fShowerIdVec.clear();
95}
96
97// Access a cluster
98// RecEmcID RecEmcCluster::ClusterId() const
99//{
100// return fClusterId;
101// }
102
104
105RecEmcHitMap::const_iterator RecEmcCluster::Begin() const { return fHitMap.begin(); }
106
107RecEmcHitMap::const_iterator RecEmcCluster::End() const { return fHitMap.end(); }
108
109RecEmcHitMap::const_iterator RecEmcCluster::Find( const RecEmcID& CellId ) const {
110 // If failed the return vale is End().
111 return fHitMap.find( CellId );
112}
113
114// Insert and Erase a hit
115void RecEmcCluster::Insert( const RecEmcHit& aHit ) {
116 fHitMap[aHit.getCellId()] = aHit;
117 // fClusterId=fHitMap.begin()->first;
118 return;
119}
120
121void RecEmcCluster::Erase( const RecEmcHit& aHit ) {
122 RecEmcHitMap::const_iterator pHitMap;
123 pHitMap = fHitMap.find( aHit.getCellId() );
124
125 // blank HitMap
126 if ( fHitMap.empty() ) { return; }
127
128 // not find
129 if ( pHitMap == End() ) { return; }
130
131 // find it
132 if ( pHitMap != End() )
133 {
134 fHitMap.erase( pHitMap->first );
135 // empty
136 if ( fHitMap.empty() )
137 {
138 Clear();
139 return;
140 }
141 // not empty
142 else
143 {
144 fClusterId = fHitMap.begin()->first;
145 return;
146 }
147 }
148}
149
150//======== Seed map
151RecEmcHitMap::const_iterator RecEmcCluster::BeginSeed() const { return fSeedMap.begin(); }
152
153RecEmcHitMap::const_iterator RecEmcCluster::EndSeed() const { return fSeedMap.end(); }
154
155RecEmcHitMap::const_iterator RecEmcCluster::FindSeed( const RecEmcID& CellId ) const {
156 // If failed the return vale is End().
157 return fSeedMap.find( CellId );
158}
159
160// Insert and Erase a seed
162 fSeedMap[aSeed.getCellId()] = aSeed;
163 return;
164}
165
166int RecEmcCluster::getSeedSize() const { return fSeedMap.size(); }
167
168int RecEmcCluster::getShowerSize() const { return fShowerIdVec.size(); }
169
170// Insert and Erase a shower
171void RecEmcCluster::InsertShowerId( const RecEmcID id ) { fShowerIdVec.push_back( id ); }
172
173// Cluster energy
175 RecEmcHitMap::const_iterator pHitMap;
176 double etot = 0;
177
178 for ( pHitMap = fHitMap.begin(); pHitMap != fHitMap.end(); pHitMap++ )
179 { etot += pHitMap->second.getEnergy(); }
180 return etot;
181}
182
183// Cluster position
185 IEmcRecGeoSvc* iGeoSvc;
186 ISvcLocator* svcLocator = Gaudi::svcLocator();
187 StatusCode sc = svcLocator->service( "EmcRecGeoSvc", iGeoSvc );
188 if ( sc != StatusCode::SUCCESS ) { cout << "Error: Can't get EmcRecGeoSvc" << endl; }
189
190 RecEmcHitMap::const_iterator pHitMap;
191 HepPoint3D pos( 0, 0, 0 );
192 HepPoint3D possum( 0, 0, 0 );
193 double etot = 0;
194
195 for ( pHitMap = fHitMap.begin(); pHitMap != fHitMap.end(); pHitMap++ )
196 {
197 etot += pHitMap->second.getEnergy();
198 pos = iGeoSvc->GetCFrontCenter( pHitMap->second.getCellId() );
199 possum += pos * pHitMap->second.getEnergy();
200 }
201
202 if ( etot > 0 ) { possum /= etot; }
203 return possum;
204}
205
206// Cluster second moment
208 IEmcRecGeoSvc* iGeoSvc;
209 ISvcLocator* svcLocator = Gaudi::svcLocator();
210 StatusCode sc = svcLocator->service( "EmcRecGeoSvc", iGeoSvc );
211 if ( sc != StatusCode::SUCCESS ) { cout << "Error: Can't get EmcRecGeoSvc" << endl; }
212
213 double etot = 0;
214 double sum = 0;
215 HepPoint3D center( getPosition() );
216 RecEmcHitMap::const_iterator pHitMap;
217
218 for ( pHitMap = fHitMap.begin(); pHitMap != fHitMap.end(); pHitMap++ )
219 {
220 HepPoint3D pos( pHitMap->second.getFrontCenter() );
221 etot += pHitMap->second.getEnergy();
222 sum += pHitMap->second.getEnergy() * pos.distance2( center );
223 }
224
225 if ( etot > 0 ) { sum /= etot; }
226 return sum;
227}
228
229// Dump out.
231 RecEmcHitMap::const_iterator pHitMap;
232
233 cout << "EMC Cluster: ";
234
235 cout << "Cluster Id= ";
236 cout << fClusterId << endl;
237
238 for ( pHitMap = fHitMap.begin(); pHitMap != fHitMap.end(); pHitMap++ )
239 { pHitMap->second.Dump(); }
240}
241
242ostream& operator<<( ostream& os, const RecEmcCluster& aCluster ) {
243 RecEmcHitMap::const_iterator pHitMap;
244
245 cout << "EMC Cluster: ";
246
247 cout << "Cluster Id= ";
248 cout << aCluster.getClusterId() << endl;
249
250 for ( pHitMap = aCluster.Begin(); pHitMap != aCluster.End(); pHitMap++ )
251 { os << ( pHitMap->second ); }
252
253 if ( aCluster.getSeedSize() > 0 )
254 {
255 cout << "Contains " << aCluster.getSeedSize() << " Seeds:" << endl;
256 RecEmcHitMap::const_iterator pSeedMap;
257 for ( pSeedMap = aCluster.BeginSeed(); pSeedMap != aCluster.EndSeed(); pSeedMap++ )
258 { os << ( pSeedMap->second ); }
259 }
260
261 if ( aCluster.getShowerSize() > 0 )
262 {
263 vector<RecEmcID> aShowerIdVec = aCluster.getShowerIdVec();
264 vector<RecEmcID>::iterator iShowerId;
265 os << "Contains " << aCluster.getShowerSize() << " Showers:" << endl;
266 for ( iShowerId = aShowerIdVec.begin(); iShowerId != aShowerIdVec.end(); iShowerId++ )
267 { os << *iShowerId << endl; }
268 }
269
270 return os;
271}
HepGeom::Point3D< double > HepPoint3D
Double_t etot
ostream & operator<<(ostream &os, const RecEmcCluster &aCluster)
virtual HepPoint3D GetCFrontCenter(const Identifier &id) const =0
RecEmcEnergy getEnergy() 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
double getSecondMoment() const
RecEmcHitMap::const_iterator Begin() const
void Dump() const
void Erase(const RecEmcHit &aHit)
void InsertSeed(const RecEmcHit &aSeed)
RecEmcHitMap::const_iterator End() const
void ClusterId(const RecEmcID id)
void InsertShowerId(const RecEmcID id)
int getShowerSize() const