00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <stdlib.h>
00004 #include <time.h>
00005 #include <math.h>
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifdef IS_REAL_L2 //in l2-ana environment
00016 #include "../L2algoUtil/L2EmcDb.h"
00017 #include "../L2algoUtil/L2Histo.h"
00018 #else //full path needed for cvs'd code
00019 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcDb.h"
00020 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2Histo.h"
00021 #endif
00022
00023 #include "L2hienAlgo09.h"
00024 #include "L2hienResult2009.h"
00025
00026
00027
00028 L2hienAlgo09::L2hienAlgo09(const char* name, L2EmcDb* db, L2EmcGeom *geoX, char* outDir, int resOff, L2VirtualAlgo2009::EmcSwitch beSwitch) : L2VirtualAlgo2009( name, db, outDir, (beSwitch==kIsBtow),(beSwitch==kIsEtow), resOff ) {
00029
00030
00031
00032
00033
00034
00035 if(!(beSwitch==kIsBtow || beSwitch==kIsEtow))
00036 {
00037 criticalError("L2hienAlgo called with broken beSwitch. L2hien cannot run.\n");
00038 }
00039
00040 if (beSwitch==kIsBtow)
00041 {
00042 if (sizeof(L2hienResult2009)!= L2hienResult2009::mySizeChar)
00043 criticalError("L2hienAlgo09 (Barrel) has failed consistency check. sizeof(L2hienResult2009)!= L2hienResult2009::mySizeChar");
00044 }
00045 mSwitch=beSwitch;
00046 setMaxHist(16);
00047 createHisto();
00048
00049 }
00050
00051
00052
00053 int
00054 L2hienAlgo09::initRunUser( int runNo, int *rc_ints, float *rc_floats) {
00055
00056
00057 par_dbg = rc_ints[0];
00058 par_adcThres = rc_ints[1];
00059 par_maxList = rc_ints[2];
00060 par_RndAcceptPrescale = 0;
00061
00062
00063 int kBad=0;
00064 kBad+=0x00001 * (par_adcThres<10);
00065
00066
00067 if(par_maxList<10 ) par_maxList=10;
00068 if(par_maxList>L2hienList09::mxListSize ) par_maxList=L2hienList09::mxListSize;
00069
00070 if (mLogFile) {
00071 fprintf(mLogFile,"L2%s algorithm initRun(R=%d), compiled: %s , %s\n params for ",getName(),mRunNumber,__DATE__,__TIME__);
00072 if(mSwitch==kIsBtow) fprintf(mLogFile," BTOW setup:\n");
00073 if(mSwitch==kIsEtow) fprintf(mLogFile," ETOW setup:\n");
00074 fprintf(mLogFile," - use adcThresh =%d, maxList=%d debug=%d\n", par_adcThres , par_maxList, par_dbg);
00075 fprintf(mLogFile,"initRun() params checked for consistency, Error flag=0x%04x\n",kBad);
00076 }
00077 if(kBad) return -kBad;
00078
00079
00080 int i;
00081 for (i=0; i<mxHA;i++) if(hA[i])hA[i]->reset();
00082 memset(mHiEnTw,0,sizeof(mHiEnTw));
00083
00084
00085
00086 char txt[1000];
00087 sprintf(txt,"compute: # towers w/ ADC-ped>%d / event; x: # towers; y: counts",par_adcThres);
00088 hA[2]->setTitle(txt);
00089
00090 sprintf(txt,"accepted: # towers w/ ADC-ped>%d / event; x: # towers; y: counts",par_adcThres);
00091 hA[3]->setTitle(txt);
00092
00093 sprintf(txt,"accepted: # towers w/ ADC-ped>%d vs. eta ring;x: BTOW eta-bin, 0=eta=-1.0; y: counts",par_adcThres*2);
00094 if(mSwitch==kIsEtow)
00095 sprintf(txt,"accepted: # towers w/ ADC-ped>%d vs. eta ring;x: ETOW eta-bin, 0=eta=+2.0; y: counts",par_adcThres*2);
00096 hA[5]->setTitle(txt);
00097
00098 sprintf(txt,"accepted: # towers w/ ADC-ped>%d vs. phi ring;x: phi-bin, 0=12:30, follows TPC; y: counts",par_adcThres*2);
00099 hA[6]->setTitle(txt);
00100
00101 sprintf(txt,"accepted: ADC sum over towers w/ ADC-ped>%d ; ADC sum/16; y: counts",par_adcThres);
00102 hA[7]->setTitle(txt);
00103
00104
00105
00106
00107 memset(mRdo2towerID_B,0,sizeof(mRdo2towerID_B));
00108 memset(mTowerID2etaBin_B,0,sizeof(mTowerID2etaBin_B));
00109 memset(mTowerID2phiBin_B,0,sizeof(mTowerID2phiBin_B));
00110
00111 memset(mRdo2towerID_E,0,sizeof(mRdo2towerID_E));
00112 memset(mTowerID2etaBin_E,0,sizeof(mTowerID2etaBin_E));
00113 memset(mTowerID2phiBin_E,0,sizeof(mTowerID2phiBin_E));
00114
00115 if(mSwitch==kIsBtow)
00116 for ( int index=0; index<EmcDbIndexMax; index++ ) {
00117 const L2EmcDb::EmcCDbItem *x = mDb->getByIndex(index);
00118 if ( x==0 ) continue;
00119 if ( !mDb->isBTOW(x) ) continue;
00120 int sec = x->sec - 1;
00121 int sub = 8192;
00122 sub = x->sub - 'a';
00123 int eta = x->eta - 1;
00124 int phi = BtowGeom::mxSubs *sec + sub;
00125 int tow = BtowGeom::mxEtaBin *phi + eta;
00126 int rdo = x->rdo;
00127 if (tow<0 || tow>mxBtow || rdo<0 || rdo>mxBtow) return -101;
00128
00129 mRdo2towerID_B[ rdo ] = tow;
00130 mTowerID2etaBin_B[tow]=eta;
00131 mTowerID2phiBin_B[tow]=phi;
00132 }
00133
00134
00135 if(mSwitch==kIsEtow)
00136 for ( int index=0; index<EmcDbIndexMax; index++ ) {
00137 const L2EmcDb::EmcCDbItem *x = mDb->getByIndex(index);
00138 if ( x==0 ) continue;
00139 if ( !mDb->isETOW(x) ) continue;
00140 int sec = x->sec - 1;
00141 int sub = 8192;
00142 sub = x->sub - 'A';
00143 int eta = x->eta - 1;
00144 int phi = EtowGeom::mxSubs *sec + sub;
00145 int tow = EtowGeom::mxEtaBin *phi + eta;
00146 int rdo = x->rdo;
00147 if (tow<0 || tow>mxEtow || rdo<0 || rdo>mxEtow) return -101;
00148
00149 mRdo2towerID_E[ rdo ] = tow;
00150 mTowerID2etaBin_E[tow]=eta;
00151 mTowerID2phiBin_E[tow]=phi;
00152 }
00153
00154 return 0;
00155 }
00156
00157
00158
00159
00160
00161 void
00162 L2hienAlgo09::computeUser(int token){
00163
00164
00165
00166
00167 mHiEnTw[token].size=0;
00168 int i;
00169
00170 const HitTower1 *hit=0;
00171 int hitSize=0;
00172 int *mRdo2towerID=0;
00173
00174 if(mSwitch==kIsBtow) {
00175 hit =mEveStream_btow[token].get_hits();
00176 hitSize=mEveStream_btow[token].get_hitSize();
00177 mRdo2towerID=mRdo2towerID_B;
00178 } else {
00179 hit =mEveStream_etow[token].get_hits();
00180 hitSize=mEveStream_etow[token].get_hitSize();
00181 mRdo2towerID=mRdo2towerID_E;
00182 }
00183
00184
00185
00186
00187 L2hienList09 *hiTwEve=mHiEnTw+token;
00188 unsigned int *value=hiTwEve->value;
00189 unsigned int tempValue=0;
00190 unsigned int totalADC=0;
00191 int resultMaxTowers=0;
00192 int softID=0;
00193 L2hienResult2009 *hienResult=mHienResult+token;
00194 if (mSwitch==kIsBtow)
00195 {
00196 resultMaxTowers=L2hienResult2009::maxTowers;
00197
00198 }
00199
00200 for(i=0;i< hitSize;i++,hit++) {
00201
00202 softID=mRdo2towerID[hit->rdo];
00203 totalADC+=hit->adc;
00204 tempValue=((hit->adc)<<16)+softID;
00205
00206 if ((mSwitch==kIsBtow) && (i<L2hienResult2009::maxTowers))
00207 hienResult->value[i]=tempValue;
00208 if (hiTwEve->size<par_maxList && hit->adc>=par_adcThres)
00209 {
00210
00211 (*value)=tempValue;
00212 hiTwEve->size++;
00213 value++;
00214 }
00215
00216
00217 if(hiTwEve->size>=par_maxList && i>=L2hienResult2009::maxTowers) break;
00218
00219 }
00220
00221 unsigned int nTow;
00222 if (hitSize>255) nTow=255;
00223 else nTow=hitSize;
00224
00225 if (totalADC>16777215) totalADC=16777215;
00226 hienResult->header=(nTow<<24)+totalADC;
00227
00228
00229
00230 hiTwEve->isFresh=L2hienList09::kDataFresh;
00231 hA[2]->fill(hiTwEve->size);
00232 }
00233
00234
00235
00236
00237 bool
00238 L2hienAlgo09::decisionUser(int token, int *myL2Result){
00239
00240
00241
00242
00243
00244
00245 L2hienList09 *hiTwEve=mHiEnTw+token;
00246 L2hienResult2009 *hienResult=mHienResult+token;
00247
00248
00249
00250
00251 hA[3]->fill(hiTwEve->size);
00252 if(hiTwEve->size>= par_maxList) mhN->fill(5);
00253 if(hiTwEve->isFresh>L2hienList09::kDataFresh) mhN->fill(6);
00254 hiTwEve->isFresh++;
00255
00256
00257 int adc4QaThres=(par_adcThres/8);
00258 int * mTowerID2etaBin=0 , *mTowerID2phiBin=0;
00259 if(mSwitch==kIsBtow) {
00260 mTowerID2etaBin=mTowerID2etaBin_B;
00261 mTowerID2phiBin=mTowerID2phiBin_B;
00262 } else {
00263 mTowerID2etaBin=mTowerID2etaBin_E;
00264 mTowerID2phiBin=mTowerID2phiBin_E;
00265 }
00266
00267 unsigned int *value=hiTwEve->value;
00268 int ic;
00269 int adcSum4=0;
00270 for(ic=0;ic<hiTwEve->size;ic++,value++) {
00271 int adc4=(*value)>>(16+4);
00272 int softID=(*value)&0xffff;
00273 adcSum4+=adc4;
00274
00275 hA[4]->fill(adc4);
00276 if(adc4<adc4QaThres) continue;
00277 hA[5]->fill(mTowerID2etaBin[softID]);
00278 hA[6]->fill(mTowerID2phiBin[softID]);
00279 }
00280 if(adcSum4>0) hA[7]->fill(adcSum4);
00281
00282
00283
00284
00285
00286 if(par_dbg>0){
00287 print2(token);
00288
00289 }
00290
00291
00292
00293
00294
00295
00296 if(mSwitch==kIsBtow)
00297 {
00298 memcpy(myL2Result,hienResult,sizeof(L2hienResult2009));
00299 hienResult->header=0;
00300 }
00301
00302
00303
00304 return true;
00305
00306 }
00307
00308
00309
00310
00311 void
00312 L2hienAlgo09::finishRunUser() {
00313
00314
00315 if (mLogFile){
00316 fprintf(mLogFile,"finishRunUser-%s bhla bhla\n",getName());
00317 }
00318
00319 }
00320
00321
00322
00323
00324 void
00325 L2hienAlgo09::createHisto() {
00326 memset(hA,0,sizeof(hA));
00327
00328 hA[2]=new L2Histo(2,"compute: #towers w/ .....energy /event; x: # towers; y: counts", 35);
00329 hA[3]=new L2Histo(3,"decision: #towers w/ .....energy /event; x: # towers; y: counts", 35);
00330
00331 int nEtaBin=BtowGeom::mxEtaBin;
00332 int nPhiBin=BtowGeom::mxPhiBin;
00333 if(mSwitch==kIsEtow) {
00334 nEtaBin=EtowGeom::mxEtaBin;
00335 nPhiBin=EtowGeom::mxPhiBin;
00336 }
00337 hA[4]=new L2Histo(4,"accepted: towers ET (watch units!) ; x: (ADC-ped)/16", 150);
00338 hA[5]=new L2Histo(5,"accepted: #towers w/ ..... vs. eta ring",nEtaBin);
00339 hA[6]=new L2Histo(6,"accepted: #towers w/ .... vs. phi ring",nPhiBin);
00340 hA[7]=new L2Histo(7,"accepted: ADC sum ...",150);
00341
00342
00343 }
00344
00345
00346
00347
00348 void
00349 L2hienAlgo09::print2(int token){
00350 if (!(token>0 && token<L2eventStream2009::mxToken))
00351 {
00352 printf("L2hienAlgo09::print2 called with token out of bounds!\n");
00353 return;
00354 }
00355
00356 int hiSize=getListSize(token);
00357 const unsigned int *value=getListData(token);
00358
00359 printf("pr2-%s: dump %d acceted towers for token=%d\n softID ADC-ped\n",getName(),hiSize, token);
00360 for(int ic=0;ic<hiSize;ic++,value++) {
00361 int adc=(*value)>>16;
00362 int softID=(*value)&0xffff;
00363 printf("%4d %d, \n",softID,adc);
00364 }
00365 }
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393