10 #include "StMuEmcCollection.h"
12 #include "StMuEmcUtil.h"
19 int n = (
char*)&mEndcapEmcPoints - (
char*)&mTowerADC +
sizeof(mEndcapEmcPoints);
20 memset(&mTowerADC,0,n);
26 memcpy( mTowerADC, o.mTowerADC,
sizeof(mTowerADC) );
27 memcpy( mEndcapTowerADC, o.mEndcapTowerADC,
sizeof(mEndcapTowerADC) );
29 for (
int i=0; i<2; i++) {
30 mSmdHits[i] = (TClonesArray*)o.mSmdHits[i]->Clone();
31 mEndcapSmdHits[i] = (TClonesArray*)o.mEndcapSmdHits[i]->Clone();
33 for (
int i=0; i<4; i++) {
34 mEmcClusters[i] = (TClonesArray*)o.mEmcClusters[i]->Clone();
35 mEndcapEmcClusters[i] = (TClonesArray*)o.mEndcapEmcClusters[i]->Clone();
37 mPrsHits = (TClonesArray*)o.mPrsHits->Clone();
38 mEmcPoints = (TClonesArray*)o.mEmcPoints->Clone();
39 mEndcapPrsHits = (TClonesArray*)o.mEndcapPrsHits->Clone();
40 mEndcapEmcPoints = (TClonesArray*)o.mEndcapEmcPoints->Clone();
43 void StMuEmcCollection::init()
46 mEmcPoints =
new TClonesArray(
"StMuEmcPoint",0);
47 mPrsHits =
new TClonesArray(
"StMuEmcHit",0);
48 mEndcapEmcPoints=
new TClonesArray(
"StMuEmcPoint",0);
49 mEndcapPrsHits =
new TClonesArray(
"StMuEmcHit",0);
52 mEmcClusters[i] =
new TClonesArray(
"StMuEmcCluster",0);
53 mEndcapEmcClusters[i] =
new TClonesArray(
"StMuEmcCluster",0);
55 mSmdHits[i] =
new TClonesArray(
"StMuEmcHit",0);
56 mEndcapSmdHits[i] =
new TClonesArray(
"StMuEmcHit",0);
61 StMuEmcCollection::~StMuEmcCollection()
63 int n = &mEndcapEmcPoints-&mPrsHits +1;
64 TClonesArray **arr = &mPrsHits;
65 for(
int i=0;i<n;i++) {
delete arr[i]; arr[i] = 0;}
67 void StMuEmcCollection::DeleteThis()
69 for (
int i=0; i<2; i++) mSmdHits[i]->Delete();
70 for (
int i=0; i<4; i++) mEmcClusters[i]->Delete();
74 void StMuEmcCollection::clear(Option_t *option)
76 int n = &mEndcapEmcPoints-&mPrsHits +1;
77 TClonesArray **arr = &mPrsHits;
78 for(
int i=0;i<n;i++) {
if (arr[i]) arr[i]->Clear();}
82 void StMuEmcCollection::packbits(
unsigned char *
data,
unsigned int value,
unsigned int nbits,
unsigned int index)
84 unsigned int start = index*nbits;
85 unsigned int startByte = start/8;
86 unsigned int startBit = start%8;
89 for(
int i=0;i<4;i++) { a+=data[startByte+i]*s; s*=256; }
90 unsigned int mask = ((
unsigned int)(1<<nbits)-1);
91 unsigned int b = ((value&mask)<<startBit) | (a&(~(mask<<startBit)));
92 data[startByte+0] = (
unsigned char)((b & 0x000000FF));
93 data[startByte+1] = (
unsigned char)((b & 0x0000FF00)>>8);
94 data[startByte+2] = (
unsigned char)((b & 0x00FF0000)>>16);
95 data[startByte+3] = (
unsigned char)((b & 0xFF000000)>>24);
98 unsigned int StMuEmcCollection::unpackbits(
const unsigned char *data,
unsigned int nbits,
unsigned int index)
const
100 unsigned int start = index*nbits;
101 unsigned int startByte = start/8;
102 unsigned int startBit = start%8;
105 for(
int i=0;i<4;i++) { a+=data[startByte+i]*s; s*=256; }
106 unsigned int mask = ((
unsigned int)(1<<nbits)-1);
107 unsigned int b = (
unsigned int)(a&(mask<<startBit))>>startBit;
110 int StMuEmcCollection::getTowerADC(
int id,
int detector)
const
113 return mTowerData->towerADC(
id,detector);
116 if(id<1 || id>4800)
return 0;
117 return (
int)unpackbits(mTowerADC,12,(
unsigned int)(
id-1));
121 if(id<1 || id>720)
return 0;
122 return (
int)unpackbits(mEndcapTowerADC,12,(
unsigned int)(
id-1));
128 int StMuEmcCollection::getNSmdHits(
int detector)
const
130 TClonesArray *tca = NULL;
131 if (!mPrsHits)
return 0;
132 if(detector==bsmde || detector==bsmdp) tca = mSmdHits[detector-bsmde];
133 if(detector==esmdu || detector==esmdv) tca = mEndcapSmdHits[detector-esmdu];
134 if(tca)
return tca->GetEntriesFast();
138 StMuEmcHit* StMuEmcCollection::getSmdHit(
int hitId,
int detector)
140 TClonesArray *tca = NULL;
141 if (!mPrsHits)
return 0;
142 if(detector==bsmde || detector==bsmdp) tca = mSmdHits[detector-bsmde];
143 if(detector==esmdu || detector==esmdv) tca = mEndcapSmdHits[detector-esmdu];
146 int counter = tca->GetEntriesFast();
147 if(hitId<0 || hitId>counter)
return NULL;
153 const StMuEmcHit* StMuEmcCollection::getSmdHit(
int hitId,
int detector)
const
155 const TClonesArray *tca = NULL;
156 if (!mPrsHits)
return 0;
157 if(detector==bsmde || detector==bsmdp) tca = mSmdHits[detector-bsmde];
158 if(detector==esmdu || detector==esmdv) tca = mEndcapSmdHits[detector-esmdu];
161 int counter = tca->GetEntriesFast();
162 if(hitId<0 || hitId>counter)
return NULL;
163 return (
const StMuEmcHit*)tca->UncheckedAt(hitId);
168 int StMuEmcCollection::getNPrsHits(
int detector)
const
170 if (!mPrsHits)
return 0;
171 TClonesArray *tca = NULL;
172 if(detector == bprs) tca = mPrsHits;
173 if(detector == eprs) tca = mEndcapPrsHits;
174 if(tca)
return tca->GetEntriesFast();
178 StMuEmcHit* StMuEmcCollection::getPrsHit(
int hitId,
int detector)
180 if (!mPrsHits)
return 0;
181 TClonesArray *tca = NULL;
182 if(detector == bprs) tca = mPrsHits;
183 if(detector == eprs) tca = mEndcapPrsHits;
186 int counter = tca->GetEntriesFast();
187 if(hitId<0 || hitId>counter)
return NULL;
193 const StMuEmcHit* StMuEmcCollection::getPrsHit(
int hitId,
int detector)
const
195 if (!mPrsHits)
return 0;
196 const TClonesArray *tca = NULL;
197 if(detector == bprs) tca = mPrsHits;
198 if(detector == eprs) tca = mEndcapPrsHits;
201 int counter = tca->GetEntriesFast();
202 if(hitId<0 || hitId>counter)
return NULL;
203 return (
const StMuEmcHit*)tca->UncheckedAt(hitId);
208 int StMuEmcCollection::getNClusters(
int detector)
const
210 if (!mPrsHits)
return 0;
211 if(detector<bemc && detector>esmdv)
return 0;
212 TClonesArray *tca =NULL;
213 if(detector>=bemc && detector <= bsmdp) tca = mEmcClusters[detector-bemc];
214 else tca = mEndcapEmcClusters[detector-eemc];
219 if (tca)
return tca->GetEntriesFast();
223 StMuEmcCluster* StMuEmcCollection::getCluster(
int clusterId,
int detector)
225 if (!mPrsHits)
return 0;
226 if(detector<bemc && detector>esmdv)
return NULL;
227 TClonesArray *tca = NULL;
228 if(detector>=bemc && detector <= bsmdp) tca = mEmcClusters[detector-bemc];
229 else tca = mEndcapEmcClusters[detector-eemc];
230 int counter = tca->GetEntriesFast();
231 if(clusterId<0 || clusterId>counter)
return NULL;
235 const StMuEmcCluster* StMuEmcCollection::getCluster(
int clusterId,
int detector)
const
237 if (!mPrsHits)
return 0;
238 if(detector<bemc && detector>esmdv)
return NULL;
239 const TClonesArray *tca = NULL;
240 if(detector>=bemc && detector <= bsmdp) tca = mEmcClusters[detector-bemc];
241 else tca = mEndcapEmcClusters[detector-eemc];
242 int counter = tca->GetEntriesFast();
243 if(clusterId<0 || clusterId>counter)
return NULL;
247 int StMuEmcCollection::getNPoints()
const
249 if (!mPrsHits)
return 0;
250 const TClonesArray *tca =mEmcPoints;
251 if (tca)
return tca->GetEntriesFast();
255 int StMuEmcCollection::getNEndcapPoints()
const
257 if (!mPrsHits)
return 0;
258 const TClonesArray *tca =mEndcapEmcPoints;
259 if (tca)
return tca->GetEntriesFast();
265 if (!mPrsHits)
return 0;
266 TClonesArray *tca =mEmcPoints;
267 int counter = tca->GetEntriesFast();
268 if(pointId<0 || pointId>counter)
return NULL;
272 const StMuEmcPoint* StMuEmcCollection::getPoint(
int pointId)
const
274 if (!mPrsHits)
return 0;
275 const TClonesArray *tca =mEmcPoints;
276 int counter = tca->GetEntriesFast();
277 if(pointId<0 || pointId>counter)
return NULL;
281 StMuEmcPoint* StMuEmcCollection::getEndcapPoint(
int pointId)
283 if (!mPrsHits)
return 0;
284 TClonesArray *tca =mEndcapEmcPoints;
287 int counter = tca->GetEntriesFast();
288 if(pointId<0 || pointId>counter)
return NULL;
295 const StMuEmcPoint* StMuEmcCollection::getEndcapPoint(
int pointId)
const
297 if (!mPrsHits)
return 0;
298 const TClonesArray *tca =mEndcapEmcPoints;
301 int counter = tca->GetEntriesFast();
302 if(pointId<0 || pointId>counter)
return NULL;
309 void StMuEmcCollection::setTowerADC(
int id,
int adc,
int detector)
311 if (!mPrsHits) init();
313 mTowerData->setTowerADC(
id,adc,detector);
319 if(id<1 || id>4800)
return;
320 packbits(mTowerADC,adc,12,(
unsigned int)(
id-1));
324 if(id<1 || id>720)
return;
325 packbits(mEndcapTowerADC,adc,12,(
unsigned int)(
id-1));
330 void StMuEmcCollection::addSmdHit(
int detector)
332 if (!mPrsHits) init();
333 TClonesArray *tca = NULL;
334 if(detector==bsmde || detector==bsmdp) tca = mSmdHits[detector-bsmde];
335 if(detector==esmdu || detector==esmdv) tca = mEndcapSmdHits[detector-esmdu];
338 int counter = tca->GetEntriesFast();
344 void StMuEmcCollection::addPrsHit(
int detector)
346 if (!mPrsHits) init();
347 TClonesArray *tca = NULL;
348 if(detector == bprs) tca = mPrsHits;
349 if(detector == eprs) tca = mEndcapPrsHits;
352 int counter = tca->GetEntriesFast();
358 void StMuEmcCollection::addCluster(
int detector)
360 if(detector<bemc && detector>esmdv)
return;
361 if (!mPrsHits) init();
362 TClonesArray *tca =NULL;
363 if(detector>=bemc && detector <= bsmdp) tca = mEmcClusters[detector-bemc];
364 else tca = mEndcapEmcClusters[detector-eemc];
365 int counter = tca->GetEntriesFast();
370 void StMuEmcCollection::addPoint()
372 if (!mPrsHits) init();
373 TClonesArray *tca =mEmcPoints;
374 int counter = tca->GetEntriesFast();
378 void StMuEmcCollection::addEndcapPoint()
380 if (!mPrsHits) init();
381 TClonesArray *tca =mEndcapEmcPoints;
382 int counter = tca->GetEntriesFast();
388 void StMuEmcCollection::getEndcapTowerADC(
int ihit1,
int &adc,
int &sec,
int &sub,
int & eta)
const
391 adc=getTowerADC(ihit,eemc);
392 if(! util.getEndcapBin(eemc,ihit,sec,eta,sub))
return ;
397 StMuEmcHit * StMuEmcCollection::getEndcapPrsHit(
int ihit,
int &sec,
int &sub,
int & eta,
int &pre)
399 if (!mPrsHits)
return 0;
402 if( util.getEndcapBin(eprs,h->
getId(),sec,eta,ssub))
return 0;
408 const StMuEmcHit * StMuEmcCollection::getEndcapPrsHit(
int ihit,
int &sec,
int &sub,
int & eta,
int &pre)
const
410 if (!mPrsHits)
return 0;
413 if( util.getEndcapBin(eprs,h->
getId(),sec,eta,ssub))
return 0;
419 int StMuEmcCollection::getNEndcapSmdHits(
char uv)
const
421 if(uv!=
'U' && uv!=
'V')
return 0;
422 return getNSmdHits((
int)esmdu+uv-
'U');
426 StMuEmcHit * StMuEmcCollection::getEndcapSmdHit(
char uv,
int ihit,
int &sec,
int &strip)
428 if(uv!=
'U' && uv!=
'V')
return 0;
429 if (!mPrsHits)
return 0;
430 int det=(int)esmdu+uv-
'U';
433 if( util.getEndcapBin(det,h->
getId(),sec,strip,idum))
return 0;
437 const StMuEmcHit * StMuEmcCollection::getEndcapSmdHit(
char uv,
int ihit,
int &sec,
int &strip)
const
439 if(uv!=
'U' && uv!=
'V')
return 0;
440 if (!mPrsHits)
return 0;
441 int det=(int)esmdu+uv-
'U';
444 if( util.getEndcapBin(det,h->
getId(),sec,strip,idum))
return 0;
448 void StMuEmcCollection::setPrsArray(
int detector, TClonesArray *cl) {
451 else if (detector==eprs)
455 void StMuEmcCollection::setSmdArray(
int detector, TClonesArray *cl) {
464 mEndcapSmdHits[0]=cl;
467 mEndcapSmdHits[1]=cl;
int getId() const
Return Module number.