00001
00002
00003
00004
00005
00006
00007
00008 #include <string.h>
00009
00010 #include "StMuEmcCollection.h"
00011 #include "Stiostream.h"
00012 #include "StMuEmcUtil.h"
00013 static StMuEmcUtil util;
00014 ClassImp(StMuEmcCollection)
00015
00016 StMuEmcCollection::StMuEmcCollection()
00017 : TObject()
00018 {
00019 int n = (char*)&mEndcapEmcPoints - (char*)&mTowerADC + sizeof(mEndcapEmcPoints);
00020 memset(&mTowerADC,0,n);
00021 }
00022
00023 StMuEmcCollection::StMuEmcCollection(const StMuEmcCollection& o)
00024 : TObject(o)
00025 {
00026 memcpy( mTowerADC, o.mTowerADC, sizeof(mTowerADC) );
00027 memcpy( mEndcapTowerADC, o.mEndcapTowerADC, sizeof(mEndcapTowerADC) );
00028
00029 for ( int i=0; i<2; i++) {
00030 mSmdHits[i] = (TClonesArray*)o.mSmdHits[i]->Clone();
00031 mEndcapSmdHits[i] = (TClonesArray*)o.mEndcapSmdHits[i]->Clone();
00032 }
00033 for ( int i=0; i<4; i++) {
00034 mEmcClusters[i] = (TClonesArray*)o.mEmcClusters[i]->Clone();
00035 mEndcapEmcClusters[i] = (TClonesArray*)o.mEndcapEmcClusters[i]->Clone();
00036 }
00037 mPrsHits = (TClonesArray*)o.mPrsHits->Clone();
00038 mEmcPoints = (TClonesArray*)o.mEmcPoints->Clone();
00039 mEndcapPrsHits = (TClonesArray*)o.mEndcapPrsHits->Clone();
00040 mEndcapEmcPoints = (TClonesArray*)o.mEndcapEmcPoints->Clone();
00041 }
00042
00043 void StMuEmcCollection::init()
00044 {
00045 if (mPrsHits) return;
00046 mEmcPoints = new TClonesArray("StMuEmcPoint",0);
00047 mPrsHits = new TClonesArray("StMuEmcHit",0);
00048 mEndcapEmcPoints= new TClonesArray("StMuEmcPoint",0);
00049 mEndcapPrsHits = new TClonesArray("StMuEmcHit",0);
00050 for(int i=0;i<4;i++)
00051 {
00052 mEmcClusters[i] = new TClonesArray("StMuEmcCluster",0);
00053 mEndcapEmcClusters[i] = new TClonesArray("StMuEmcCluster",0);
00054 if(i>=2) continue;
00055 mSmdHits[i] = new TClonesArray("StMuEmcHit",0);
00056 mEndcapSmdHits[i] = new TClonesArray("StMuEmcHit",0);
00057 }
00058 }
00059
00060
00061 StMuEmcCollection::~StMuEmcCollection()
00062 {
00063 int n = &mEndcapEmcPoints-&mPrsHits +1;
00064 TClonesArray **arr = &mPrsHits;
00065 for(int i=0;i<n;i++) { delete arr[i]; arr[i] = 0;}
00066 }
00067 void StMuEmcCollection::DeleteThis()
00068 {
00069 for ( int i=0; i<2; i++) mSmdHits[i]->Delete();
00070 for ( int i=0; i<4; i++) mEmcClusters[i]->Delete();
00071 mEmcPoints->Delete();
00072 }
00073
00074 void StMuEmcCollection::clear(Option_t *option)
00075 {
00076 int n = &mEndcapEmcPoints-&mPrsHits +1;
00077 TClonesArray **arr = &mPrsHits;
00078 for(int i=0;i<n;i++) { if (arr[i]) arr[i]->Clear();}
00079
00080 return;
00081 }
00082 void StMuEmcCollection::packbits(unsigned char *data, unsigned int value, unsigned int nbits, unsigned int index)
00083 {
00084 unsigned int start = index*nbits;
00085 unsigned int startByte = start/8;
00086 unsigned int startBit = start%8;
00087 unsigned int a = 0;
00088 unsigned int s = 1;
00089 for(int i=0;i<4;i++) { a+=data[startByte+i]*s; s*=256; }
00090 unsigned int mask = ((unsigned int)(1<<nbits)-1);
00091 unsigned int b = ((value&mask)<<startBit) | (a&(~(mask<<startBit)));
00092 data[startByte+0] = (unsigned char)((b & 0x000000FF));
00093 data[startByte+1] = (unsigned char)((b & 0x0000FF00)>>8);
00094 data[startByte+2] = (unsigned char)((b & 0x00FF0000)>>16);
00095 data[startByte+3] = (unsigned char)((b & 0xFF000000)>>24);
00096 return;
00097 }
00098 unsigned int StMuEmcCollection::unpackbits(const unsigned char *data, unsigned int nbits, unsigned int index) const
00099 {
00100 unsigned int start = index*nbits;
00101 unsigned int startByte = start/8;
00102 unsigned int startBit = start%8;
00103 unsigned int a = 0;
00104 unsigned int s = 1;
00105 for(int i=0;i<4;i++) { a+=data[startByte+i]*s; s*=256; }
00106 unsigned int mask = ((unsigned int)(1<<nbits)-1);
00107 unsigned int b = (unsigned int)(a&(mask<<startBit))>>startBit;
00108 return b;
00109 }
00110 int StMuEmcCollection::getTowerADC(int id, int detector) const
00111 {
00112 if (mTowerData)
00113 return mTowerData->towerADC(id,detector);
00114 if(detector == bemc)
00115 {
00116 if(id<1 || id>4800) return 0;
00117 return (int)unpackbits(mTowerADC,12,(unsigned int)(id-1));
00118 }
00119 if(detector == eemc)
00120 {
00121 if(id<1 || id>720) return 0;
00122 return (int)unpackbits(mEndcapTowerADC,12,(unsigned int)(id-1));
00123 }
00124 return 0;
00125 }
00126
00127
00128 int StMuEmcCollection::getNSmdHits(int detector) const
00129 {
00130 TClonesArray *tca = NULL;
00131 if (!mPrsHits) return 0;
00132 if(detector==bsmde || detector==bsmdp) tca = mSmdHits[detector-bsmde];
00133 if(detector==esmdu || detector==esmdv) tca = mEndcapSmdHits[detector-esmdu];
00134 if(tca) return tca->GetEntriesFast();
00135 else return 0;
00136 }
00137
00138 StMuEmcHit* StMuEmcCollection::getSmdHit(int hitId,int detector)
00139 {
00140 TClonesArray *tca = NULL;
00141 if (!mPrsHits) return 0;
00142 if(detector==bsmde || detector==bsmdp) tca = mSmdHits[detector-bsmde];
00143 if(detector==esmdu || detector==esmdv) tca = mEndcapSmdHits[detector-esmdu];
00144 if(tca)
00145 {
00146 int counter = tca->GetEntriesFast();
00147 if(hitId<0 || hitId>counter) return NULL;
00148 return (StMuEmcHit*)tca->UncheckedAt(hitId);
00149 }
00150 return NULL;
00151 }
00152
00153 const StMuEmcHit* StMuEmcCollection::getSmdHit(int hitId,int detector) const
00154 {
00155 const TClonesArray *tca = NULL;
00156 if (!mPrsHits) return 0;
00157 if(detector==bsmde || detector==bsmdp) tca = mSmdHits[detector-bsmde];
00158 if(detector==esmdu || detector==esmdv) tca = mEndcapSmdHits[detector-esmdu];
00159 if(tca)
00160 {
00161 int counter = tca->GetEntriesFast();
00162 if(hitId<0 || hitId>counter) return NULL;
00163 return (const StMuEmcHit*)tca->UncheckedAt(hitId);
00164 }
00165 return NULL;
00166 }
00167
00168 int StMuEmcCollection::getNPrsHits(int detector) const
00169 {
00170 if (!mPrsHits) return 0;
00171 TClonesArray *tca = NULL;
00172 if(detector == bprs) tca = mPrsHits;
00173 if(detector == eprs) tca = mEndcapPrsHits;
00174 if(tca) return tca->GetEntriesFast();
00175 else return 0;
00176 }
00177
00178 StMuEmcHit* StMuEmcCollection::getPrsHit(int hitId, int detector)
00179 {
00180 if (!mPrsHits) return 0;
00181 TClonesArray *tca = NULL;
00182 if(detector == bprs) tca = mPrsHits;
00183 if(detector == eprs) tca = mEndcapPrsHits;
00184 if(tca)
00185 {
00186 int counter = tca->GetEntriesFast();
00187 if(hitId<0 || hitId>counter) return NULL;
00188 return (StMuEmcHit*)tca->UncheckedAt(hitId);
00189 }
00190 return NULL;
00191 }
00192
00193 const StMuEmcHit* StMuEmcCollection::getPrsHit(int hitId, int detector) const
00194 {
00195 if (!mPrsHits) return 0;
00196 const TClonesArray *tca = NULL;
00197 if(detector == bprs) tca = mPrsHits;
00198 if(detector == eprs) tca = mEndcapPrsHits;
00199 if(tca)
00200 {
00201 int counter = tca->GetEntriesFast();
00202 if(hitId<0 || hitId>counter) return NULL;
00203 return (const StMuEmcHit*)tca->UncheckedAt(hitId);
00204 }
00205 return NULL;
00206 }
00207
00208 int StMuEmcCollection::getNClusters(int detector) const
00209 {
00210 if (!mPrsHits) return 0;
00211 if(detector<bemc && detector>esmdv) return 0;
00212 TClonesArray *tca =NULL;
00213 if(detector>=bemc && detector <= bsmdp) tca = mEmcClusters[detector-bemc];
00214 else tca = mEndcapEmcClusters[detector-eemc];
00215
00216
00217
00218
00219 if (tca) return tca->GetEntries();
00220 else return 0;
00221 }
00222
00223 StMuEmcCluster* StMuEmcCollection::getCluster(int clusterId,int detector)
00224 {
00225 if (!mPrsHits) return 0;
00226 if(detector<bemc && detector>esmdv) return NULL;
00227 TClonesArray *tca = NULL;
00228 if(detector>=bemc && detector <= bsmdp) tca = mEmcClusters[detector-bemc];
00229 else tca = mEndcapEmcClusters[detector-eemc];
00230 int counter = tca->GetEntries();
00231 if(clusterId<0 || clusterId>counter) return NULL;
00232 return (StMuEmcCluster*)tca->At(clusterId);
00233 }
00234
00235 const StMuEmcCluster* StMuEmcCollection::getCluster(int clusterId,int detector) const
00236 {
00237 if (!mPrsHits) return 0;
00238 if(detector<bemc && detector>esmdv) return NULL;
00239 const TClonesArray *tca = NULL;
00240 if(detector>=bemc && detector <= bsmdp) tca = mEmcClusters[detector-bemc];
00241 else tca = mEndcapEmcClusters[detector-eemc];
00242 int counter = tca->GetEntries();
00243 if(clusterId<0 || clusterId>counter) return NULL;
00244 return (const StMuEmcCluster*)tca->At(clusterId);
00245 }
00246
00247 int StMuEmcCollection::getNPoints() const
00248 {
00249 if (!mPrsHits) return 0;
00250 const TClonesArray *tca =mEmcPoints;
00251 if (tca) return tca->GetEntries();
00252 else return 0;
00253 }
00254
00255 int StMuEmcCollection::getNEndcapPoints() const
00256 {
00257 if (!mPrsHits) return 0;
00258 const TClonesArray *tca =mEndcapEmcPoints;
00259 if (tca) return tca->GetEntries();
00260 else return 0;
00261 }
00262
00263 StMuEmcPoint* StMuEmcCollection::getPoint(int pointId)
00264 {
00265 if (!mPrsHits) return 0;
00266 TClonesArray *tca =mEmcPoints;
00267 int counter = tca->GetEntries();
00268 if(pointId<0 || pointId>counter) return NULL;
00269 return (StMuEmcPoint*)tca->At(pointId);
00270 }
00271
00272 const StMuEmcPoint* StMuEmcCollection::getPoint(int pointId) const
00273 {
00274 if (!mPrsHits) return 0;
00275 const TClonesArray *tca =mEmcPoints;
00276 int counter = tca->GetEntries();
00277 if(pointId<0 || pointId>counter) return NULL;
00278 return (const StMuEmcPoint*)tca->At(pointId);
00279 }
00280
00281 StMuEmcPoint* StMuEmcCollection::getEndcapPoint(int pointId)
00282 {
00283 if (!mPrsHits) return 0;
00284 TClonesArray *tca =mEndcapEmcPoints;
00285
00286 if (tca){
00287 int counter = tca->GetEntries();
00288 if(pointId<0 || pointId>counter) return NULL;
00289 return (StMuEmcPoint*)tca->At(pointId);
00290 } else {
00291 return NULL;
00292 }
00293 }
00294
00295 const StMuEmcPoint* StMuEmcCollection::getEndcapPoint(int pointId) const
00296 {
00297 if (!mPrsHits) return 0;
00298 const TClonesArray *tca =mEndcapEmcPoints;
00299
00300 if (tca){
00301 int counter = tca->GetEntries();
00302 if(pointId<0 || pointId>counter) return NULL;
00303 return (const StMuEmcPoint*)tca->At(pointId);
00304 } else {
00305 return NULL;
00306 }
00307 }
00308
00309 void StMuEmcCollection::setTowerADC(int id,int adc, int detector)
00310 {
00311 if (!mPrsHits) init();
00312 if (mTowerData) {
00313 mTowerData->setTowerADC(id,adc,detector);
00314 return;
00315 }
00316
00317 if(detector == bemc)
00318 {
00319 if(id<1 || id>4800) return;
00320 packbits(mTowerADC,adc,12,(unsigned int)(id-1));
00321 }
00322 if(detector == eemc)
00323 {
00324 if(id<1 || id>720) return;
00325 packbits(mEndcapTowerADC,adc,12,(unsigned int)(id-1));
00326 }
00327 return;
00328 }
00329
00330 void StMuEmcCollection::addSmdHit(int detector)
00331 {
00332 if (!mPrsHits) init();
00333 TClonesArray *tca = NULL;
00334 if(detector==bsmde || detector==bsmdp) tca = mSmdHits[detector-bsmde];
00335 if(detector==esmdu || detector==esmdv) tca = mEndcapSmdHits[detector-esmdu];
00336 if(tca)
00337 {
00338 int counter = tca->GetEntriesFast();
00339 new ((*tca)[counter]) StMuEmcHit();
00340 }
00341 return;
00342 }
00343
00344 void StMuEmcCollection::addPrsHit(int detector)
00345 {
00346 if (!mPrsHits) init();
00347 TClonesArray *tca = NULL;
00348 if(detector == bprs) tca = mPrsHits;
00349 if(detector == eprs) tca = mEndcapPrsHits;
00350 if(tca)
00351 {
00352 int counter = tca->GetEntriesFast();
00353 new ((*tca)[counter]) StMuEmcHit();
00354 }
00355 return;
00356 }
00357
00358 void StMuEmcCollection::addCluster(int detector)
00359 {
00360 if(detector<bemc && detector>esmdv) return;
00361 if (!mPrsHits) init();
00362 TClonesArray *tca =NULL;
00363 if(detector>=bemc && detector <= bsmdp) tca = mEmcClusters[detector-bemc];
00364 else tca = mEndcapEmcClusters[detector-eemc];
00365 int counter = tca->GetEntriesFast();
00366 new ((*tca)[counter]) StMuEmcCluster();
00367 return;
00368 }
00369
00370 void StMuEmcCollection::addPoint()
00371 {
00372 if (!mPrsHits) init();
00373 TClonesArray *tca =mEmcPoints;
00374 int counter = tca->GetEntries();
00375 new ((*tca)[counter]) StMuEmcPoint();
00376 return;
00377 }
00378 void StMuEmcCollection::addEndcapPoint()
00379 {
00380 if (!mPrsHits) init();
00381 TClonesArray *tca =mEndcapEmcPoints;
00382 int counter = tca->GetEntries();
00383 new ((*tca)[counter]) StMuEmcPoint();
00384 return;
00385 }
00386
00387
00388 void StMuEmcCollection::getEndcapTowerADC(int ihit1, int &adc, int &sec, int &sub, int & eta) const
00389 {
00390 int ihit=ihit1+1;
00391 adc=getTowerADC(ihit,eemc);
00392 if(! util.getEndcapBin(eemc,ihit,sec,eta,sub)) return ;
00393 adc=sec=sub=eta=-1;
00394 return;
00395 }
00396
00397 StMuEmcHit * StMuEmcCollection::getEndcapPrsHit(int ihit, int &sec, int &sub, int & eta, int &pre)
00398 {
00399 if (!mPrsHits) return 0;
00400 StMuEmcHit * h = getPrsHit(ihit,eprs);
00401 int ssub;
00402 if( util.getEndcapBin(eprs,h->getId(),sec,eta,ssub)) return 0;
00403 pre=1+(ssub-1)/5;
00404 sub=1+(ssub-1)%5;
00405 return h;
00406 }
00407
00408 const StMuEmcHit * StMuEmcCollection::getEndcapPrsHit(int ihit, int &sec, int &sub, int & eta, int &pre) const
00409 {
00410 if (!mPrsHits) return 0;
00411 const StMuEmcHit * h = getPrsHit(ihit,eprs);
00412 int ssub;
00413 if( util.getEndcapBin(eprs,h->getId(),sec,eta,ssub)) return 0;
00414 pre=1+(ssub-1)/5;
00415 sub=1+(ssub-1)%5;
00416 return h;
00417 }
00418
00419 int StMuEmcCollection::getNEndcapSmdHits(char uv) const
00420 {
00421 if(uv!='U' && uv!='V') return 0;
00422 return getNSmdHits((int)esmdu+uv-'U');
00423 }
00424
00425
00426 StMuEmcHit * StMuEmcCollection::getEndcapSmdHit(char uv, int ihit,int &sec, int &strip)
00427 {
00428 if(uv!='U' && uv!='V') return 0;
00429 if (!mPrsHits) return 0;
00430 int det=(int)esmdu+uv-'U';
00431 StMuEmcHit * h =getSmdHit(ihit,det);
00432 int idum;
00433 if( util.getEndcapBin(det,h->getId(),sec,strip,idum)) return 0;
00434 return h;
00435 }
00436
00437 const StMuEmcHit * StMuEmcCollection::getEndcapSmdHit(char uv, int ihit,int &sec, int &strip) const
00438 {
00439 if(uv!='U' && uv!='V') return 0;
00440 if (!mPrsHits) return 0;
00441 int det=(int)esmdu+uv-'U';
00442 const StMuEmcHit * h =getSmdHit(ihit,det);
00443 int idum;
00444 if( util.getEndcapBin(det,h->getId(),sec,strip,idum)) return 0;
00445 return h;
00446 }
00447
00448 void StMuEmcCollection::setPrsArray(int detector, TClonesArray *cl) {
00449 if (detector==bprs)
00450 mPrsHits=cl;
00451 else if (detector==eprs)
00452 mEndcapPrsHits=cl;
00453 }
00454
00455 void StMuEmcCollection::setSmdArray(int detector, TClonesArray *cl) {
00456 switch (detector) {
00457 case bsmde:
00458 mSmdHits[0]=cl;
00459 break;
00460 case bsmdp:
00461 mSmdHits[1]=cl;
00462 break;
00463 case esmdu:
00464 mEndcapSmdHits[0]=cl;
00465 break;
00466 case esmdv:
00467 mEndcapSmdHits[1]=cl;
00468 break;
00469 }
00470 }
00471