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