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
00017 #ifdef IS_REAL_L2 //in l2-ana environment
00018 #include "../L2algoUtil/L2EmcDb.h"
00019 #include "../L2algoUtil/L2Histo.h"
00020 #else
00021 #include "../L2algoUtil/L2EmcDb.h"
00022 #include "../L2algoUtil/L2Histo.h"
00023 #include "../L2algoUtil/L2EmcGeom.h"
00024 #endif
00025
00026 #include "L2exampleAlgo08.h"
00027
00028
00029
00030
00031 L2exampleAlgo08::L2exampleAlgo08(const char* name, L2EmcDb* db, L2EmcGeom *geoX, char* outDir) : L2VirtualAlgo2008( name, db, outDir) {
00032
00033
00034
00035
00036 mGeom=geoX; assert(mGeom);
00037 setMaxHist(16);
00038 createHisto();
00039
00040
00041
00042 assert(sizeof(L2exampleResult08)== L2exampleResult08::mySizeChar);
00043 }
00044
00045
00046
00047 int
00048 L2exampleAlgo08::initRunUser( int runNo, int *rc_ints, float *rc_floats) {
00049
00050
00051 par_dbg = rc_ints[0];
00052 par_seedEtThres = rc_floats[0];
00053 par_clusterEtThres= rc_floats[1];
00054 par_eventEtThres = rc_floats[2];
00055
00056
00057 int kBad=0;
00058 kBad+=0x00001 * (par_seedEtThres<1.0);
00059 kBad+=0x00002 * (par_clusterEtThres<par_seedEtThres);
00060
00061 if (mLogFile) {
00062 fprintf(mLogFile,"L2%s algorithm initRun(R=%d), compiled: %s , %s\n params:\n",getName(),mRunNumber,__DATE__,__TIME__);
00063 fprintf(mLogFile," - use Thres/GeV seed=%.2f, clusterList=%.2f debug=%d\n", par_seedEtThres,par_clusterEtThres, par_dbg);
00064 fprintf(mLogFile," - accept event cluster Thres/GeV=%.2f\n",par_eventEtThres);
00065 fprintf(mLogFile,"initRun() params checked for consistency, Error flag=0x%04x\n",kBad);
00066 }
00067
00068 if(kBad) return kBad;
00069
00070
00071
00072 int i;
00073 for (i=0; i<mxHA;i++) if(hA[i])hA[i]->reset();
00074 memset(mBtow,0,sizeof(mBtow));
00075
00076
00077 char txt[1000];
00078 sprintf(txt,"BTOW-compute: #seed towers ET>%.2f GeV / event; x: # BTOW towers; y: counts",par_seedEtThres);
00079 hA[3]->setTitle(txt);
00080
00081 sprintf(txt,"BTOW-decision: #cluster ET>%.2f GeV / event ; x: # BTOW towers; y: counts",par_clusterEtThres);
00082 hA[4]->setTitle(txt);
00083
00084 sprintf(txt,"BTOW-decision: acc cluster ET>%.2f GeV; x:cluster ET(GeV) ; y: counts",par_eventEtThres);
00085 hA[4]->setTitle(txt);
00086
00087
00088
00089 for ( int index=0; index<EmcDbIndexMax; index++ )
00090 {
00091 const L2EmcDb::EmcCDbItem *x = mDb->getByIndex(index);
00092 if ( x==0 ) continue;
00093 if ( !mDb->isBTOW(x) ) continue;
00094 int sec = x->sec - 1;
00095 int sub = 8192;
00096 sub = x->sub - 'a';
00097 int eta = x->eta - 1;
00098 int phi = BtowGeom::mxSubs *sec + sub;
00099 int tow = BtowGeom::mxEtaBin *phi + eta;
00100 int rdo = x->rdo;
00101 assert(tow>=0); assert(tow<=mxBtow);
00102 assert(rdo>=0); assert(rdo<=mxBtow);
00103
00104 mTower2rdo[ tow ] = rdo;
00105 mRdo2tower[ rdo ] = tow;
00106 }
00107 return 0;
00108
00109 }
00110
00111
00112
00113 float
00114 L2exampleAlgo08::sumET(int phi, int eta) {
00115 int tow = BtowGeom::mxEtaBin *phi + eta;
00116 float sum=wrkBtow_et[tow]+wrkBtow_et[tow+1];
00117
00118 tow+=BtowGeom::mxEtaBin;
00119
00120 sum+=wrkBtow_et[tow]+wrkBtow_et[tow+1];
00121 return sum;
00122 }
00123
00124
00125
00126
00127 void
00128 L2exampleAlgo08::computeUser(int token){
00129
00130
00131
00132
00133
00134
00135
00136 clearEvent(token);
00137
00138
00139 int i;
00140
00141
00142 const HitTower1 *hit=mEveStream_btow[token].get_hits();
00143 const int hitSize=mEveStream_btow[token].get_hitSize();
00144 for(i=0;i< hitSize;i++,hit++) {
00145 int tower=mRdo2tower[hit->rdo];
00146 wrkBtow_et[tower]=hit->et;
00147 if(hit->et<par_seedEtThres)continue;
00148 wrkBtow_tower_seed[wrkBtow_tower_seed_size++]=tower;
00149 }
00150 hA[2]->fill(hitSize);
00151 hA[3]->fill(wrkBtow_tower_seed_size);
00152
00153
00154
00155
00156 L2exampleEvent08 *btowEve=mBtow+token;
00157
00158
00159 for(i=0;i<wrkBtow_tower_seed_size;i++) {
00160 int seedTow=wrkBtow_tower_seed[i];
00161 int seedEta=seedTow%BtowGeom::mxEtaBin;
00162 int seedPhi=seedTow/BtowGeom::mxEtaBin;
00163
00164
00165
00166
00167 if(seedEta==0 || seedEta==BtowGeom::mxEtaBin-1) continue;
00168 if(seedPhi==0 || seedPhi==BtowGeom::mxPhiBin-1) continue;
00169
00170
00171
00172
00173
00174
00175
00176
00177 float maxET=sumET(seedPhi,seedEta);
00178 float sum=sumET(seedPhi-1,seedEta);
00179 if(maxET<sum) maxET=sum;
00180 sum=sumET(seedPhi-1,seedEta-1);
00181 if(maxET<sum) maxET=sum;
00182 sum=sumET(seedPhi,seedEta-1);
00183 if(maxET<sum) maxET=sum;
00184
00185 if(maxET<par_clusterEtThres)continue;
00186 if(btowEve->size>=L2exampleEvent08::mxClust) continue;
00187
00188 btowEve->clusterET[btowEve->size++]=maxET;
00189 }
00190
00191 btowEve->isFresh=L2exampleEvent08::kDataFresh;
00192
00193
00194
00195 if(par_dbg>0){
00196 printf("dbg=%s, btow-adcL-size=%d\n",getName(),hitSize);
00197
00198 print2();
00199 print3();
00200 }
00201 }
00202
00203
00204
00205
00206 bool
00207 L2exampleAlgo08::decisionUser(int token, void **myL2Result){
00208
00209
00210
00211
00212 L2exampleEvent08 *btowEve=mBtow+token;
00213 (*myL2Result)=&(btowEve->resultBlob);
00214
00215 int ic;
00216
00217
00218 if(btowEve->size>= L2exampleEvent08::mxClust) mhN->fill(5);
00219 if(btowEve->isFresh>L2exampleEvent08::kDataFresh) mhN->fill(6);
00220 btowEve->isFresh++;
00221
00222 hA[4]->fill(btowEve->size);
00223
00224 for(ic=0;ic<btowEve->size;ic++) {
00225 float clustET=btowEve->clusterET[ic];
00226 hA[5]->fill((int)clustET);
00227
00228 if(clustET<par_eventEtThres) continue;
00229 hA[6]->fill((int)clustET);
00230 }
00231
00232
00233
00234 btowEve->resultBlob.kTicksCompute=mComputeTimeDiff[token]/1000;
00235 btowEve->resultBlob.decision=0;
00236 btowEve->resultBlob.numberOfL2Clust=btowEve->size;
00237
00238
00239 for(ic=0;ic<btowEve->size;ic++) {
00240 if(btowEve->clusterET[ic]<par_eventEtThres) continue;
00241 btowEve->resultBlob.decision=1;
00242 btowEve->resultBlob.clusterET=btowEve->clusterET[ic];
00243 goto accepted;
00244 }
00245 return false;
00246
00247
00248 accepted:
00249
00250 if(btowEve->size>= L2exampleEvent08::mxClust) mhN->fill(15);
00251 return true;
00252
00253 }
00254
00255
00256
00257
00258 void
00259 L2exampleAlgo08::finishRunUser() {
00260
00261
00262 if (mLogFile){
00263 fprintf(mLogFile,"finishRunUser-%s bhla bhla\n",getName());
00264 }
00265
00266 }
00267
00268
00269
00270
00271 void
00272 L2exampleAlgo08::createHisto() {
00273 memset(hA,0,sizeof(hA));
00274
00275 hA[2]=new L2Histo(2,"BTOW-compute: #towers w/ energy /event; x: # BTOW towers; y: counts", 100);
00276 hA[3]=new L2Histo(3,"BTOW-compute: #seed ....... ", 100);
00277 hA[4]=new L2Histo(4,"BTOW-decision: #clust ....... ", 50);
00278
00279 hA[5]=new L2Histo(5,"BTOW-decision: any cluster ; x: ET(GeV)", 30);
00280 hA[6]=new L2Histo(6,"BTOW-decision: accepted clust ... ; x: ET(GeV)", 30);
00281
00282
00283 }
00284
00285
00286
00287 void
00288 L2exampleAlgo08::clearEvent(int token){
00289 memset(wrkBtow_et,0,sizeof(wrkBtow_et));
00290 memset(wrkBtow_tower_seed,0,sizeof(wrkBtow_tower_seed));
00291 wrkBtow_tower_seed_size=0;
00292 mBtow[token].size=0;
00293 memset(&(mBtow[token].resultBlob),0, sizeof(L2exampleResult08));
00294 }
00295
00296
00297
00298 void
00299 L2exampleAlgo08::print2(){
00300 int i;
00301 printf("pr2-%s: ---BTOW ADC 2D array, only non-zero\n",getName());
00302
00303 for(i=0;i<mxBtow;i++) {
00304 if(wrkBtow_et[i]<=0) continue;
00305 int rdo=mTower2rdo[i];
00306 float et=wrkBtow_et[i];
00307 printf(" btow: tower=%4d rdo=%4d et=%.3f \n",i,rdo,et);
00308 }
00309
00310 }
00311
00312
00313
00314 void
00315 L2exampleAlgo08::print3(){
00316 int i;
00317 printf("pr3-%s: ---seed list, size=%d\n",getName(),wrkBtow_tower_seed_size);
00318
00319 for(i=0;i<wrkBtow_tower_seed_size;i++) {
00320 int tower=wrkBtow_tower_seed[i];
00321 float et=wrkBtow_et[tower];
00322 printf(" btow: i=%4d tower=%4d et=%.3f \n",i,tower,et);
00323 }
00324
00325 }
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351