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
00016
00017
00018
00019
00020
00021 #ifdef IS_REAL_L2 //in l2-ana environment
00022 #include "../L2algoUtil/L2EmcDb.h"
00023 #include "../L2algoUtil/L2Histo.h"
00024 #else
00025 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcDb.h"
00026 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2Histo.h"
00027 #endif
00028
00029 #include "L2jetAlgo2009.h"
00030 #include "L2jetResults2009.h"
00031 #include "Map_DeltaPhiJets.h"
00032
00033
00034
00035 L2jetAlgo2009::L2jetAlgo2009(const char* name, L2EmcDb* db, char* outDir, int resOff, bool writeHighResult)
00036 : L2VirtualAlgo2009( name, db, outDir, true, true, resOff) {
00037
00038
00039
00040 namechar='L';
00041 if (writeHighResult) namechar='H';
00042
00043 createHisto();
00044 run_number=-1;
00045 printf("L2jetAlgo2009 instantiated, logPath='%s'\n",mOutDir1.c_str());
00046 eve_Jet[0]=new L2Jet;
00047 eve_Jet[1]=new L2Jet;
00048 }
00049
00050
00051
00052 bool
00053 L2jetAlgo2009::paramsChanged( int *rc_ints, float *rc_floats) {
00054 int i;
00055 for(i=0;i<5;i++)
00056 if(rc_ints[i]!=raw_ints[i]) goto foundProblem;
00057
00058 for(i=0;i<5;i++)
00059 if(fabs(rc_floats[i]-raw_floats[i])>0.00001) goto foundProblem;
00060
00061 return false;
00062
00063 foundProblem:
00064 if (mLogFile) fprintf(mLogFile,"L2jet-ghost initRun - inconsistent params, ABORT initialization\n");
00065 return true;
00066 }
00067
00068
00069
00070 int
00071 L2jetAlgo2009::initRunUser( int runNo, int *rc_ints, float *rc_floats) {
00072
00073
00074 int i;
00075 for (i=0; i<mxHA;i++) if(hA[i])hA[i]->reset();
00076
00077
00078 memset(db_btowL2PhiBin, 0, sizeof(db_btowL2PhiBin));
00079 memset(db_btowL2PatchBin,0, sizeof(db_btowL2PatchBin));
00080
00081 memset(db_etowL2PhiBin, 0 ,sizeof(db_etowL2PhiBin));
00082 memset(db_etowL2PatchBin,0 ,sizeof(db_etowL2PatchBin));
00083
00084 run_startUnix=time(0);
00085 run_number =runNo;
00086 raw_ints =rc_ints;
00087 raw_floats =rc_floats;
00088 run_nEventOneJet=run_nEventDiJet= run_nEventRnd=0;
00089
00090 mEventsInRun=0;
00091
00092 if( mLogFile==0) printf(" L2jetAlgo2009() UNABLE to open run summary log file, continue anyhow\n");
00093
00094
00095 par_useBtowEast= (rc_ints[0]&1 )>0;
00096 par_useBtowWest= (rc_ints[0]&2)>0;
00097 par_useEndcap = rc_ints[1]&1;
00098 int par_adcThr = rc_ints[2];
00099 par_dbg = rc_ints[3];
00100 par_RndAcceptPrescale = rc_ints[4];
00101 par_minPhiBinDiff= 7;
00102
00103 par_oneJetThr = rc_floats[0];
00104 par_diJetThrHigh= rc_floats[1];
00105 par_diJetThrLow = rc_floats[2];
00106 par_diJetThr_2 = rc_floats[3];
00107 par_diJetThr_3 = rc_floats[4];
00108 par_diJetThr_4 = rc_floats[5];
00109 par_diJetThr_5 = rc_floats[6];
00110 par_diJetEtaHigh = rc_floats[7];
00111 par_diJetEtaLow = rc_floats[8];
00112
00113
00114
00115
00116 float monTwEtThr=2.0;
00117 par_hotTwEtThr = monTwEtThr;
00118
00119 if(par_dbg) printf("Brian version is running!\n");
00120
00121 if (mLogFile) {
00122 fprintf(mLogFile,"L2jet algorithm initRun(%d), compiled: %s , %s\n params:\n",run_number,__DATE__,__TIME__);
00123 fprintf(mLogFile," - use BTOW: East=%d West=%d, Endcap=%d L2ResOffset=%d\n", par_useBtowEast, par_useBtowWest,par_useEndcap ,mResultOffset);
00124 fprintf(mLogFile," - threshold: ADC-ped> %d \n", par_adcThr);
00125 fprintf(mLogFile," - min phi opening angle Jet1<->Jet2: %d in L2phiBins\n",par_minPhiBinDiff);
00126 fprintf(mLogFile," - diJet Et thrHigh= %.2f (GeV) thrLow= %.2f (GeV)\n", par_diJetThrHigh, par_diJetThrLow);
00127 fprintf(mLogFile," - new diJet Et thr_2= %.2f (GeV) ; thr_3= %.2f (Gev) ; thr_4= %.2f (GeV) ; thr_5= %.2f (GeV)\n",par_diJetThr_2, par_diJetThr_3, par_diJetThr_4, par_diJetThr_5);
00128 fprintf(mLogFile," - oneJet Et thr = %.2f (GeV) ; rndAccPrescale=%d \n",par_oneJetThr,par_RndAcceptPrescale);
00129 fprintf(mLogFile," - new diJet Eta_low= %.2f ; diJet Eta_High= %.2f \n", par_diJetEtaLow, par_diJetEtaHigh);
00130 fprintf(mLogFile," - debug=%d, hot tower threshold: Et> %.1f GeV ( only monitoring)\n",par_dbg, monTwEtThr);
00131 }
00132
00133
00134 int kBad=0;
00135 kBad+=0x0001 * ( !par_useBtowEast & !par_useBtowWest & !par_useEndcap);
00136
00137 kBad+=0x0004 * (par_adcThr>16);
00138 kBad+=0x0008 * (par_minPhiBinDiff<5);
00139 kBad+=0x0010 * (par_minPhiBinDiff>=15);
00140 kBad+=0x0020 * (par_oneJetThr<3.);
00141 kBad+=0x0040 * (par_oneJetThr>12.);
00142 kBad+=0x0080 * (par_diJetThrLow<1.9);
00143 kBad+=0x0100 * (par_diJetThrHigh<par_diJetThrLow);
00144 kBad+=0x0200 * (par_diJetThrHigh>12.);
00145
00146 kBad+=0x0800 * ( par_RndAcceptPrescale<0 );
00147 kBad+=0x1000 * (par_diJetThr_2<par_diJetThrLow || par_diJetThr_5>par_diJetThrHigh);
00148 kBad+=0x2000 * (par_diJetThr_2>par_diJetThr_3 || par_diJetThr_3>par_diJetThr_4 || par_diJetThr_4>par_diJetThr_5);
00149 kBad+=0x4000 * (par_diJetEtaLow>par_diJetEtaHigh);
00150 if (mLogFile) {
00151 fprintf(mLogFile,"L2jet initRun() params checked for consistency, Error flag=0x%04x\n",kBad);
00152 if(kBad) fprintf(mLogFile,"L2jet initRun() ABORT\n");
00153 }
00154
00155 if(kBad) {
00156 run_number=-66;
00157 if (mLogFile) {
00158 fprintf(mLogFile,"L2jet algorithm init: crashB in internal logic\n");
00159 fclose(mLogFile);
00160 return kBad;
00161 }
00162 }
00163
00164 char tit[100];
00165 sprintf(tit,"# BTOW towers>ped+%d (input); x: # of towers/event",par_adcThr);
00166 hA[47]->setTitle(tit);
00167
00168 sprintf(tit,"# ETOW towers>ped+%d (input); x: # of towers/event",par_adcThr);
00169 hA[48]->setTitle(tit);
00170
00171
00172 const int mxEtaBinsE=12,mxEtaBinsB=40;
00173
00174
00175
00176 int etowEtaBin2Patch[mxEtaBinsE]={14,14,13,13,12,12,11,11,11,10,10,10};
00177
00178 int nB=0, nE=0;
00179 int nBg=0, nEg=0;
00180
00181 for(i=0; i<EmcDbIndexMax; i++) {
00182 const L2EmcDb::EmcCDbItem *x=mDb->getByIndex(i);
00183 if(mDb->isEmpty(x)) continue;
00184 if(x->fail) continue;
00185 if(x->gain<=0) continue;
00186
00187
00188
00189 int ietaP, iphiP;
00190 if (mDb->isBTOW(x) ) {
00191
00192 nB++;
00193 if(x->eta<0 || x->eta>mxEtaBinsB) goto crashIt_1;
00194 if(!par_useBtowEast && x->eta<=20) continue;
00195 if(!par_useBtowWest && x->eta>=21) continue;
00196 ietaP= (x->eta-1)/4;
00197 int iphiTw=(x->sec-1)*10 + x->sub-'a';
00198
00199 iphiTw--;
00200 if(iphiTw<0) iphiTw=119;
00201
00202 iphiP= iphiTw/4 ;
00203
00204
00205 db_btowL2PhiBin[x->rdo]=iphiP;
00206 db_btowL2PatchBin[x->rdo]=ietaP+ iphiP*cl2jetMaxEtaBins;
00207 nBg++;
00208 } else if(mDb->isETOW(x) && par_useEndcap) {
00209
00210 nE++;
00211 int iphiTw= (x->sec-1)*5 + x->sub-'A';
00212
00213 iphiTw--;
00214 if(iphiTw<0) iphiTw=59;
00215
00216 iphiP= iphiTw/2 ;
00217 if(x->eta<0 || x->eta>mxEtaBinsE) goto crashIt_1;
00218 ietaP=etowEtaBin2Patch[x->eta-1];
00219
00220 db_etowL2PhiBin[x->rdo]=iphiP;
00221 db_etowL2PatchBin[x->rdo]=ietaP+ iphiP*cl2jetMaxEtaBins;
00222 nEg++;
00223 }
00224
00225 }
00226
00227 if (mLogFile) {
00228 fprintf(mLogFile,"L2jet algorithm: found working/calibrated: %d/%d=ETOW & %d/%d=BTOW, based on ASCII DB\n",nE,nEg,nB,nBg);
00229 }
00230
00231 return 0;
00232
00233 crashIt_1:
00234 run_number=-55;
00235 if (mLogFile) {
00236 fprintf(mLogFile,"L2jet algorithm init: crashC in internal logic\n");
00237 fclose(mLogFile);
00238 }
00239 return -6;
00240
00241 }
00242
00243
00244
00245 void L2jetAlgo2009::computeUser(int token){
00246
00247 }
00248
00249
00250
00251 bool
00252 L2jetAlgo2009::decisionUser(int token, int *myL2Result){
00253
00254
00255
00256 unsigned long mEveTimeStart,mEveTimeStop, mEveTimeDiff;
00257 rdtscl_macro(mEveTimeStart);
00258
00259
00260
00261 if(1) {
00262
00263
00264
00265
00266
00267
00268
00269 bool bemcIn = true;
00270 bool eemcIn = true;
00271
00272
00273 mEventsInRun++;
00274 clearEvent();
00275 int runTimeSec=time(0)- run_startUnix;
00276 hA[10]->fill(0);
00277 hA[12]->fill(runTimeSec);
00278
00279 if(par_dbg>1) printf("\n......... in L2Jet_doEvent(ID=%d)... bIn=%d eIn=%d\n",eve_ID,bemcIn,eemcIn);
00280
00281
00282
00283
00284
00285 if (bemcIn || eemcIn){
00286
00287
00288
00289 int nBtowTw=0, nEtowTw=0;
00290
00291
00292
00293
00294 if(bemcIn==1 && (par_useBtowEast||par_useBtowWest) ) {
00295
00296 nBtowTw=projectAdc( mEveStream_btow[token].get_hits(), mEveStream_btow[token].get_hitSize(),
00297 db_btowL2PhiBin, db_btowL2PatchBin,
00298 hA[20] );
00299 }
00300
00301
00302
00303 if(eemcIn==1 && par_useEndcap ) {
00304 nEtowTw=projectAdc( mEveStream_etow[token].get_hits(), mEveStream_etow[token].get_hitSize(),
00305 db_etowL2PhiBin, db_etowL2PatchBin,
00306 hA[30] );
00307 }
00308
00309
00310 float totEneGeV=true2Dscan();
00311 int itotEneGeV=(int)totEneGeV;
00312 int iK;
00313 for(iK=0; iK<mxJ; iK++)
00314 {
00315 weightedEtaPhi(iK);
00316 L2Jet *K=eve_Jet[iK];
00317 K->eneGeV=K->iene;
00318 K->phiRad=0.21*(6.0-K->fphiBin);
00319 while(K->phiRad<0) K->phiRad+=6.2832;
00320 while(K->phiRad>6.2832) K->phiRad-=6.2832;
00321 }
00322
00323 if(eve_Jet[0]->eneGeV <eve_Jet[1]->eneGeV) {
00324 L2Jet *Jx=eve_Jet[0];
00325 eve_Jet[0]=eve_Jet[1];
00326 eve_Jet[1]=Jx;
00327 }
00328
00329 if(par_dbg>2) printf("doEvent iphiBin1=%d iene1=%f , iphiBin2=%d iene2=%f rms1PhiBin=%f \n",eve_Jet[0]->iphiBin,eve_Jet[0]->iene,eve_Jet[1]->iphiBin,eve_Jet[1]->iene,eve_Jet[0]->rmsPhiBin);
00330
00331
00332
00333
00334
00335
00336 float rjetEta_0=eve_Jet[0]->fetaBin*0.2 -1.0;
00337 float rjetEta_1=eve_Jet[1]->fetaBin*0.2 -1.0;
00338
00339
00340
00341
00342 bool acceptDiJet_EE=((rjetEta_0+rjetEta_1) > par_diJetEtaHigh && eve_Jet[0]->eneGeV > par_diJetThr_4 && eve_Jet[1]->eneGeV > par_diJetThrLow);
00343
00344 bool acceptDiJet_EB=((rjetEta_0+rjetEta_1) > par_diJetEtaLow && eve_Jet[0]->eneGeV > par_diJetThr_5 && eve_Jet[1]->eneGeV > par_diJetThr_2);
00345
00346
00347
00348 bool acceptDiJet_BB=(eve_Jet[0]->eneGeV > par_diJetThrHigh && eve_Jet[1]->eneGeV > par_diJetThr_3);
00349
00350 bool acceptDiJet=acceptDiJet_EE || acceptDiJet_EB || acceptDiJet_BB;
00351
00352 bool acceptOneJet=( eve_Jet[0]->eneGeV > par_oneJetThr) ;
00353
00354 bool acceptRnd=mRandomAccept>0;
00355 mAccept=acceptDiJet || acceptOneJet || acceptRnd;
00356
00357
00358
00359
00360 int iet1 =(int)eve_Jet[0]->eneGeV;
00361 int iet2 =(int)eve_Jet[1]->eneGeV;
00362 int ieta1=(int)eve_Jet[0]->fetaBin;
00363 int ieta2=(int)eve_Jet[1]->fetaBin;
00364 int iphi1=(int)eve_Jet[0]->fphiBin;
00365 int iphi2=(int)eve_Jet[1]->fphiBin;
00366
00367 hA[40]->fill(iet1,iet2);
00368
00369 hA[41]->fill(ieta1,iphi1);
00370 hA[42]->fill(ieta2,iphi2);
00371 hA[43]->fill(iphi1,iphi2);
00372 hA[44]->fill(iet1);
00373 hA[45]->fill(iet2);
00374 hA[46]->fill(itotEneGeV);
00375 hA[47]->fill(nBtowTw);
00376 hA[48]->fill(nEtowTw);
00377
00378
00379 int kphi1=int(eve_Jet[0]->phiRad*10.);
00380 int kphi2=int(eve_Jet[1]->phiRad*10.);
00381 int idelZeta=map_DelPhiJets[kphi1*MxPhiRad10 + kphi2];
00382
00383 if( mAccept) hA[10]->fill(8);
00384
00385 if(acceptOneJet ){
00386 hA[10]->fill(4);
00387 run_nEventOneJet++;
00388 hA[13]->fill(runTimeSec);
00389 hA[50]->fill(iet1);
00390 hA[51]->fill(ieta1,iphi1);
00391 hA[52]->fill(ieta1);
00392 hA[53]->fill(iphi1);
00393 }
00394
00395 if(acceptDiJet ){
00396 hA[10]->fill(5);
00397 run_nEventDiJet++;
00398 hA[14]->fill(runTimeSec);
00399 hA[60]->fill(iet1,iet2);
00400 hA[61]->fill(ieta1,iphi1);
00401 hA[62]->fill(ieta2,iphi2);
00402 hA[63]->fill(iphi1,iphi2);
00403 hA[64]->fill(iet1);
00404 hA[65]->fill(iet2);
00405 hA[66]->fill(ieta1);
00406 hA[67]->fill(ieta2);
00407 hA[68]->fill(iphi1);
00408 hA[69]->fill(iphi2);
00409 hA[70]->fill(idelZeta);
00410 hA[71]->fill(ieta1,idelZeta);
00411 hA[72]->fill(ieta1,ieta2);
00412 hA[73]->fill((iphi1+iphi2)/2,idelZeta);
00413 hA[74]->fill(itotEneGeV);
00414 }
00415
00416 if(acceptDiJet_EE ){
00417 run_nEventDiJet++;
00418 hA[80]->fill(iet1,iet2);
00419 hA[81]->fill(ieta1,iphi1);
00420 hA[82]->fill(ieta2,iphi2);
00421 hA[83]->fill(iphi1,iphi2);
00422 hA[84]->fill(iet1);
00423 hA[85]->fill(iet2);
00424 hA[86]->fill(ieta1);
00425 hA[87]->fill(ieta2);
00426 hA[88]->fill(iphi1);
00427 hA[89]->fill(iphi2);
00428 hA[90]->fill(idelZeta);
00429 hA[91]->fill(ieta1,idelZeta);
00430 hA[92]->fill(ieta1,ieta2);
00431 hA[93]->fill((iphi1+iphi2)/2,idelZeta);
00432 hA[94]->fill(itotEneGeV);
00433 }
00434
00435 if(acceptDiJet_EB ){
00436 run_nEventDiJet++;
00437 hA[100]->fill(iet1,iet2);
00438 hA[101]->fill(ieta1,iphi1);
00439 hA[102]->fill(ieta2,iphi2);
00440 hA[103]->fill(iphi1,iphi2);
00441 hA[104]->fill(iet1);
00442 hA[105]->fill(iet2);
00443 hA[106]->fill(ieta1);
00444 hA[107]->fill(ieta2);
00445 hA[108]->fill(iphi1);
00446 hA[109]->fill(iphi2);
00447 hA[110]->fill(idelZeta);
00448 hA[111]->fill(ieta1,idelZeta);
00449 hA[112]->fill(ieta1,ieta2);
00450 hA[113]->fill((iphi1+iphi2)/2,idelZeta);
00451 hA[114]->fill(itotEneGeV);
00452 }
00453
00454 if(acceptDiJet_BB ){
00455 run_nEventDiJet++;
00456 hA[120]->fill(iet1,iet2);
00457 hA[121]->fill(ieta1,iphi1);
00458 hA[122]->fill(ieta2,iphi2);
00459 hA[123]->fill(iphi1,iphi2);
00460 hA[124]->fill(iet1);
00461 hA[125]->fill(iet2);
00462 hA[126]->fill(ieta1);
00463 hA[127]->fill(ieta2);
00464 hA[128]->fill(iphi1);
00465 hA[129]->fill(iphi2);
00466 hA[130]->fill(idelZeta);
00467 hA[131]->fill(ieta1,idelZeta);
00468 hA[132]->fill(ieta1,ieta2);
00469 hA[133]->fill((iphi1+iphi2)/2,idelZeta);
00470 hA[134]->fill(itotEneGeV);
00471 }
00472
00473 if(mRandomAccept){
00474 hA[10]->fill(6);
00475 run_nEventRnd++;
00476 hA[15]->fill(runTimeSec);
00477 }
00478
00479
00480
00481 L2jetResults2009 out;
00482 memset(&out,0,sizeof(out));
00483
00484
00485
00486 out.int0.version=L2JET_RESULTS_VERSION;
00487 out.int0.decision=
00488 ( par_useBtowEast <<0 ) +
00489 ( par_useBtowWest <<1 ) +
00490 ( par_useEndcap <<2 ) +
00491 ( (bemcIn>0) <<3 ) +
00492 ( (eemcIn>0) <<4 ) +
00493 ( mRandomAccept <<5 ) +
00494 ( acceptOneJet <<6 ) +
00495 ( acceptDiJet <<7 ) +
00496 ( acceptDiJet_EE <<8 ) +
00497 ( acceptDiJet_EB <<9 ) +
00498 ( acceptDiJet_BB <<10 ) ;
00499 out.int0.dumm=namechar;
00500
00501 out.int1.iTotEne=(unsigned short)(totEneGeV*100.);
00502 out.int2.nBtowTw=nBtowTw;
00503 out.int2.nEtowTw=nEtowTw;
00504
00505 out.jet1.jPhi=(int)(eve_Jet[0]->phiRad*28.65);
00506 out.jet1.jEta=(int)(eve_Jet[0]->fetaBin*10.);
00507 out.jet1.iEne=(unsigned short)(eve_Jet[0]->eneGeV*100.);
00508
00509 out.jet2.jPhi=(int)(eve_Jet[1]->phiRad*28.65);
00510 out.jet2.jEta=(int)(eve_Jet[1]->fetaBin*10.);
00511 out.jet2.iEne=(unsigned short)(eve_Jet[1]->eneGeV*100.);
00512
00513 out.jet1.rmsEta=(unsigned short)(eve_Jet[0]->rmsEtaBin*20.);
00514 out.jet1.rmsPhi=(unsigned short)(eve_Jet[0]->rmsPhiBin*120.);
00515
00516 out.jet2.rmsEta=(unsigned short)(eve_Jet[1]->rmsEtaBin*20.);
00517 out.jet2.rmsPhi=(unsigned short)(eve_Jet[1]->rmsPhiBin*120.);
00518
00519
00520 rdtscl_macro(mEveTimeStop);
00521 mEveTimeDiff=mEveTimeStop-mEveTimeStart;
00522 int kTick=mEveTimeDiff/1000;
00523
00524
00525
00526 out.int0.kTick= kTick>255 ? 255 : kTick;
00527
00528
00529 out.int1.checkSum=-L2jetResults2009_doCheckSum(&out);
00530
00531
00532
00533
00534 memcpy(myL2Result,&out,sizeof(L2jetResults2009));
00535
00536
00537
00538 if(par_dbg){
00539 L2jetResults2009_print(&out);
00540 printf(" phiRad1=%f phiRad2=%f \n",eve_Jet[0]->phiRad,eve_Jet[1]->phiRad);
00541 printf("idelZeta=%d delZeta/deg=%.1f \n\n",idelZeta,idelZeta/31.416*180);
00542
00543
00544 if( out.jet1.iEne+out.jet2.iEne > out.int1.iTotEne) {
00545
00546 }
00547 if(iphi1==iphi2) {
00548 printf("L2jet-fatal error,neveId=%d, phi1,2=%d,%d\n",mEventsInRun,iphi1,iphi2);
00549 dumpPatchEneA();
00550 }
00551
00552 if( L2jetResults2009_doCheckSum(&out)) {
00553 printf("L2jet-fatal error, wrong cSum=%d\n", L2jetResults2009_doCheckSum(&out));
00554 L2jetResults2009_print(&out);
00555 }
00556
00557 }
00558
00559 }
00560 }
00561
00562
00563 return mAccept;
00564 }
00565
00566
00567
00568
00569 void
00570 L2jetAlgo2009::finishRunUser() {
00571 if(run_number<0) return;
00572
00573 if (mLogFile) {
00574 fprintf(mLogFile,"L2-jet algorithm finishRun(%d)\n",run_number);
00575 fprintf(mLogFile," - %d events seen by L2 di-jet\n",mEventsInRun);
00576 fprintf(mLogFile," - accepted: rnd=%d oneJet=%d diJet=%d \n", run_nEventRnd, run_nEventOneJet, run_nEventDiJet);
00577
00578
00579
00580 hA[10]->printCSV(mLogFile);
00581
00582 }
00583 finishRunHisto();
00584 if( mHistFile==0) {
00585 printf(" L2jetAlgo2009: finishRun() UNABLE to open run summary log file, continue anyhow\n");
00586 if (mLogFile)
00587 fprintf(mLogFile,"L2 di-jet histos NOT saved, I/O error\n");
00588 } else {
00589 int j;
00590 int nh=0;
00591 for(j=0;j<mxHA;j++) {
00592 if(hA[j]==0) continue;
00593 hA[j]->write(mHistFile);
00594 nh++;
00595 }
00596 }
00597
00598 run_number=-2;
00599
00600 }
00601
00602
00603
00604 void
00605 L2jetAlgo2009::createHisto() {
00606 memset(hA,0,sizeof(hA));
00607
00608 hA[10]=new L2Histo(10,"total event counter; x=cases",9);
00609 hA[11]=new L2Histo(11,"L2 time used per input event; x: time (CPU kTics), range=100muSec; y: events ",160);
00610
00611 int mxRunDration=2500;
00612 hA[12]=new L2Histo(12,"rate of input events; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
00613
00614 hA[13]=new L2Histo(13,"rate of accepted one-Jet; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
00615 hA[14]=new L2Histo(14,"rate of accepted di-Jet ; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
00616 hA[15]=new L2Histo(15,"rate of random accepted ; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
00617
00618
00619 hA[20]=new L2Histo(20,"BTOW tower, Et>2.0 GeV (input); x: BTOW RDO index=chan*30+fiber; y: counts", 4800);
00620 hA[21]=new L2Histo(21,"BTOW tower, Et>2.0 GeV (input); x: BTOW softID", 4800);
00621 hA[22]=new L2Histo(22,"BTOW tower, Et>2.0 GeV (input); x: eta bin, [-1,+1]; y: phi bin ~sector",40,120);
00622
00623
00624 hA[30]=new L2Histo(30,"ETOW tower, Et>2.0 GeV (input); x: ETOW RDO index=chan*6+fiber; y: counts", 720 );
00625 hA[31]=new L2Histo(31,"ETOW tower, Et>2.0 GeV (input); x: i=chan+128*crate", 768);
00626 hA[32]=new L2Histo(32,"ETOW tower, Et>2.0 GeV (input); x: 12 - Endcap etaBin ,[+1,+2]; y: phi bin ~sector",12,60);
00627
00628
00629 hA[40]=new L2Histo(40,"Et Jet1-Jet2 (input); x: Jet1 Et/GeV ; Jet2 Et/GeV",30,30);
00630 hA[41]=new L2Histo(41,"diJet1 eta-phi (input); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
00631 hA[42]=new L2Histo(42,"diJet2 eta-phi (input); x: iEta [-1,+2] ; y: iPhi ~sector",15,30);
00632
00633 hA[43]=new L2Histo(43,"diJet phi1-phi2 (input); x: iPhi1 ~sector ; y: iPhi2 ~sector ",30,30);
00634
00635 hA[44]=new L2Histo(44,"Jet1 Et (input); x: Et (GeV)", 60);
00636 hA[45]=new L2Histo(45,"Jet2 Et (input); x: Et (GeV)", 60);
00637 hA[46]=new L2Histo(46,"total Et (input); x: Et (GeV)", 100);
00638 hA[47]=new L2Histo(47,"# BTOW towers>thrXX (input); x: # of towers/event", 200);
00639 hA[48]=new L2Histo(48,"# ETOW towers>thrXX (input); x: # of towers/event", 100);
00640
00641
00642 hA[50]=new L2Histo(50,"one-Jet Et (accepted); x: jet Et (GeV)", 60);
00643 hA[51]=new L2Histo(51,"one-Jet eta-phi (accepted); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
00644 hA[52]=new L2Histo(52,"one-Jet eta (accepted); x: iEta [-1,+2]", 15);
00645 hA[53]=new L2Histo(53,"one-Jet phi (accepted); x: iPhi ~sector", 30);
00646
00647
00648 hA[60]=new L2Histo(60,"Et of Jet1 vs. Jet2 (accepted); x: Jet1/GeV ; Jet2/GeV",30,30);
00649 hA[61]=new L2Histo(61,"diJet1 eta-phi (accepted); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
00650 hA[62]=new L2Histo(62,"diJet2 eta-phi (accepted); x: iEta [-1,+2] ; y: iPhi ~sector",15,30);
00651
00652 hA[63]=new L2Histo(63,"diJet phi1-phi2 (accepted); x: iPhi1 ~sector ; y: iPhi2 ~sector ",30,30);
00653
00654 hA[64]=new L2Histo(64,"diJet1 Et (accepted); x: Et (GeV)", 60);
00655 hA[65]=new L2Histo(65,"diJet2 Et (accepted); x: Et (GeV)", 60);
00656
00657 hA[66]=new L2Histo(66,"diJet1 eta (accepted); x: i Eta [-1,+2]", 15);
00658 hA[67]=new L2Histo(67,"diJet2 eta (accepted); x: i Eta [-1,+2]", 15);
00659 hA[68]=new L2Histo(68,"diJet1 phi (accepted); x: iPhi ~sector", 30);
00660 hA[69]=new L2Histo(69,"diJet2 phi (accepted); x: iPhi ~sector", 30);
00661 hA[70]=new L2Histo(70,"diJet delZeta (accepted); x: delta zeta (rad*10)", MxPhiRad10);
00662 hA[71]=new L2Histo(71,"diJet delZeta vs. eta1 (accepted); x: iEta1 [-1,+2] ; y: delta zeta (rad*10)",15, MxPhiRad10);
00663 hA[72]=new L2Histo(72,"diJet eta2 vs. eta1 (accepted); x: iEta1 [-1,+2] ;x: iEta2 [-1,+2] ",15,15);
00664 hA[73]=new L2Histo(73,"diJet delZeta vs. avrPhi (accepted); x: (iphi1+iphi2)/2 (12 deg/bin); y: delta zeta (rad*10)",30, MxPhiRad10);
00665 hA[74]=new L2Histo(74,"total Et diJet (accepted); x: Et (GeV)", 100);
00666
00667
00668 hA[80]=new L2Histo(80,"Et of Jet1 vs. Jet2 (accepted_EE); x: Jet1/GeV ; Jet2/GeV",30,30);
00669 hA[81]=new L2Histo(81,"diJet1 eta-phi (accepted_EE); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
00670 hA[82]=new L2Histo(82,"diJet2 eta-phi (accepted_EE); x: iEta [-1,+2] ; y: iPhi ~sector",15,30);
00671
00672 hA[83]=new L2Histo(83,"diJet phi1-phi2 (accepted_EE); x: iPhi1 ~sector ; y: iPhi2 ~sector ",30,30);
00673
00674 hA[84]=new L2Histo(84,"diJet1 Et (accepted_EE); x: Et (GeV)", 60);
00675 hA[85]=new L2Histo(85,"diJet2 Et (accepted_EE); x: Et (GeV)", 60);
00676
00677 hA[86]=new L2Histo(86,"diJet1 eta (accepted_EE); x: i Eta [-1,+2]", 15);
00678 hA[87]=new L2Histo(87,"diJet2 eta (accepted_EE); x: i Eta [-1,+2]", 15);
00679 hA[88]=new L2Histo(88,"diJet1 phi (accepted_EE); x: iPhi ~sector", 30);
00680 hA[89]=new L2Histo(89,"diJet2 phi (accepted_EE); x: iPhi ~sector", 30);
00681 hA[90]=new L2Histo(90,"diJet delZeta (accepted_EE); x: delta zeta (rad*10)", MxPhiRad10);
00682 hA[91]=new L2Histo(91,"diJet delZeta vs. eta1 (accepted_EE); x: iEta1 [-1,+2] ; y: delta zeta (rad*10)",15, MxPhiRad10);
00683 hA[92]=new L2Histo(92,"diJet eta2 vs. eta1 (accepted_EE); x: iEta1 [-1,+2] ;x: iEta2 [-1,+2] ",15,15);
00684 hA[93]=new L2Histo(93,"diJet delZeta vs. avrPhi (accepted_EE); x: (iphi1+iphi2)/2 (12 deg/bin); y: delta zeta (rad*10)",30, MxPhiRad10);
00685 hA[94]=new L2Histo(94,"total Et diJet (accepted_EE); x: Et (GeV)", 60);
00686
00687
00688 hA[100]=new L2Histo(100,"Et of Jet1 vs. Jet2 (accepted_EB); x: Jet1/GeV ; Jet2/GeV",30,30);
00689 hA[101]=new L2Histo(101,"diJet1 eta-phi (accepted_EB); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
00690 hA[102]=new L2Histo(102,"diJet2 eta-phi (accepted_EB); x: iEta [-1,+2] ; y: iPhi ~sector",15,30);
00691
00692 hA[103]=new L2Histo(103,"diJet phi1-phi2 (accepted_EB); x: iPhi1 ~sector ; y: iPhi2 ~sector ",30,30);
00693
00694 hA[104]=new L2Histo(104,"diJet1 Et (accepted_EB); x: Et (GeV)", 60);
00695 hA[105]=new L2Histo(105,"diJet2 Et (accepted_EB); x: Et (GeV)", 60);
00696
00697 hA[106]=new L2Histo(106,"diJet1 eta (accepted_EB); x: i Eta [-1,+2]", 15);
00698 hA[107]=new L2Histo(107,"diJet2 eta (accepted_EB); x: i Eta [-1,+2]", 15);
00699 hA[108]=new L2Histo(108,"diJet1 phi (accepted_EB); x: iPhi ~sector", 30);
00700 hA[109]=new L2Histo(109,"diJet2 phi (accepted_EB); x: iPhi ~sector", 30);
00701 hA[110]=new L2Histo(110,"diJet delZeta (accepted_EB); x: delta zeta (rad*10)", MxPhiRad10);
00702 hA[111]=new L2Histo(111,"diJet delZeta vs. eta1 (accepted_EB); x: iEta1 [-1,+2] ; y: delta zeta (rad*10)",15, MxPhiRad10);
00703 hA[112]=new L2Histo(112,"diJet eta2 vs. eta1 (accepted_EB); x: iEta1 [-1,+2] ;x: iEta2 [-1,+2] ",15,15);
00704 hA[113]=new L2Histo(113,"diJet delZeta vs. avrPhi (accepted_EB); x: (iphi1+iphi2)/2 (12 deg/bin); y: delta zeta (rad*10)",30, MxPhiRad10);
00705 hA[114]=new L2Histo(114,"total Et diJet (accepted_EB); x: Et (GeV)", 60);
00706
00707
00708 hA[120]=new L2Histo(120,"Et of Jet1 vs. Jet2 (accepted_BB); x: Jet1/GeV ; Jet2/GeV",30,30);
00709 hA[121]=new L2Histo(121,"diJet1 eta-phi (accepted_BB); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
00710 hA[122]=new L2Histo(122,"diJet2 eta-phi (accepted_BB); x: iEta [-1,+2] ; y: iPhi ~sector",15,30);
00711
00712 hA[123]=new L2Histo(123,"diJet phi1-phi2 (accepted_BB); x: iPhi1 ~sector ; y: iPhi2 ~sector ",30,30);
00713
00714 hA[124]=new L2Histo(124,"diJet1 Et (accepted_BB); x: Et (GeV)", 60);
00715 hA[125]=new L2Histo(125,"diJet2 Et (accepted_BB); x: Et (GeV)", 60);
00716
00717 hA[126]=new L2Histo(126,"diJet1 eta (accepted_BB); x: i Eta [-1,+2]", 15);
00718 hA[127]=new L2Histo(127,"diJet2 eta (accepted_BB); x: i Eta [-1,+2]", 15);
00719 hA[128]=new L2Histo(128,"diJet1 phi (accepted_BB); x: iPhi ~sector", 30);
00720 hA[129]=new L2Histo(129,"diJet2 phi (accepted_BB); x: iPhi ~sector", 30);
00721 hA[130]=new L2Histo(130,"diJet delZeta (accepted_BB); x: delta zeta (rad*10)", MxPhiRad10);
00722 hA[131]=new L2Histo(131,"diJet delZeta vs. eta1 (accepted_BB); x: iEta1 [-1,+2] ; y: delta zeta (rad*10)",15, MxPhiRad10);
00723 hA[132]=new L2Histo(132,"diJet eta2 vs. eta1 (accepted_BB); x: iEta1 [-1,+2] ;x: iEta2 [-1,+2] ",15,15);
00724 hA[133]=new L2Histo(133,"diJet delZeta vs. avrPhi (accepted_BB); x: (iphi1+iphi2)/2 (12 deg/bin); y: delta zeta (rad*10)",30, MxPhiRad10);
00725 hA[134]=new L2Histo(134,"total Et diJet (accepted_BB); x: Et (GeV)", 100);
00726
00727 }
00728
00729
00730
00731 void
00732 L2jetAlgo2009::clearEvent(){
00733
00734
00735 mAccept=false;
00736 memset(eve_patchEne,0,sizeof(eve_patchEne));
00737 memset(eve_phiEne,0,sizeof(eve_phiEne));
00738 eve_Jet[0]->clear();
00739 eve_Jet[1]->clear();
00740 }
00741
00742
00743
00744
00745
00746 int
00747 L2jetAlgo2009::projectAdc(const HitTower1 *hit,const int hitSize,
00748 ushort *phiBin, ushort *patchBin,
00749 L2Histo *hHot ){
00750 int tmpNused=0;
00751 short rdo;
00752 float low_noise_et;
00753
00754 for(int i=0;i< hitSize;i++,hit++) {
00755 rdo=hit->rdo;
00756 low_noise_et=hit->low_noise_et;
00757 eve_patchEne[patchBin[rdo]]+=low_noise_et;
00758 eve_phiEne[phiBin[rdo]]+=low_noise_et;
00759 tmpNused++;
00760
00761 if(low_noise_et > par_hotTwEtThr) hHot->fill(rdo);
00762
00763 }
00764 return tmpNused;
00765 }
00766
00767
00768
00769
00770 float L2jetAlgo2009::true2Dscan(){
00771
00772 int iphiBinEdge = 0;
00773 int ietaBinEdge = 0;
00774 float maxPatchEt = 0.0;
00775 float sumTot = 0.0;
00776
00777 float *totalCaloEt=eve_phiEne;
00778 float eneA[cl2jetMaxEtaBins];
00779 float secondPatchArray[cl2jetMaxPhiBins][cl2jetMaxEtaBins-cl2jet_par_mxEtaBin+1];
00780 memset(secondPatchArray,0,sizeof(secondPatchArray));
00781
00782 int i;
00783 int j;
00784 int j1;
00785 int j2;
00786 int k;
00787
00788 for(i=0;i<cl2jetMaxPhiBins;i++)
00789 {
00790 sumTot+=totalCaloEt[i];
00791 memset(eneA,0,sizeof(eneA));
00792 for(j=0;j<cl2jet_par_mxPhiBin;j++)
00793 {
00794 j1 = (i+j)%cl2jetMaxPhiBins;
00795 float *patchEneA=eve_patchEne+(j1*cl2jetMaxEtaBins);
00796 for(j2=0;j2<cl2jetMaxEtaBins;j2++,patchEneA++)
00797 {
00798 eneA[j2]+=*patchEneA;
00799 }
00800 }
00801 float *eneAp=eneA;
00802 for(k=0;k<cl2jetMaxEtaBins-cl2jet_par_mxEtaBin+1;k++,eneAp++)
00803 {
00804
00805
00806 float sum=eneAp[0]+eneAp[1]+eneAp[2]+eneAp[3]+eneAp[4];
00807
00808 secondPatchArray[i][k]=sum;
00809 if(maxPatchEt>sum) continue;
00810
00811 maxPatchEt=sum;
00812 iphiBinEdge=i;
00813 ietaBinEdge=k;
00814 }
00815 }
00816
00817 eve_Jet[0]->iphiBin=iphiBinEdge;
00818 eve_Jet[0]->ietaBin=ietaBinEdge;
00819 eve_Jet[0]->iene=maxPatchEt;
00820
00821
00822 int iphiBinEdge2=-1;
00823 int ietaBinEdge2=-1;
00824 float maxPatchEt2=0.0;
00825 char doWrap=0;
00826 int a1=iphiBinEdge-par_minPhiBinDiff;
00827 int a2=iphiBinEdge+par_minPhiBinDiff;
00828 if (a1<0) { a1+=cl2jetMaxPhiBins; doWrap+=1; }
00829 if (a2>=cl2jetMaxPhiBins) { a2-=cl2jetMaxPhiBins; doWrap+=2; }
00830
00831 int b;
00832 int b1;
00833 if (!doWrap)
00834 {
00835 for(b=0;b<cl2jetMaxPhiBins;b++)
00836 {
00837 if(b>=a1 && b<=a2) continue;
00838 for(b1=0;b1<cl2jetMaxEtaBins-cl2jet_par_mxEtaBin+1;b1++)
00839 {
00840 if(maxPatchEt2>secondPatchArray[b][b1]) continue;
00841 maxPatchEt2=secondPatchArray[b][b1];
00842 iphiBinEdge2=b;
00843 ietaBinEdge2=b1;
00844 }
00845 }
00846 }
00847 else
00848 {
00849 for(b=a2;b<a1;b++)
00850 {
00851 for(b1=0;b1<cl2jetMaxEtaBins-cl2jet_par_mxEtaBin+1;b1++)
00852 {
00853 if(maxPatchEt2>secondPatchArray[b][b1]) continue;
00854 maxPatchEt2=secondPatchArray[b][b1];
00855 iphiBinEdge2=b;
00856 ietaBinEdge2=b1;
00857 }
00858 }
00859 }
00860
00861 eve_Jet[1]->iphiBin=iphiBinEdge2;
00862 eve_Jet[1]->ietaBin=ietaBinEdge2;
00863 eve_Jet[1]->iene=maxPatchEt2;
00864
00865 return sumTot;
00866 }
00867
00868
00869
00870 void L2jetAlgo2009::weightedEtaPhi(int iK){
00871 L2Jet *J=eve_Jet[iK];
00872
00873
00874 if(J->iene<=0.1)
00875 {
00876 J->fphiBin=J->iphiBin+.333;
00877 J->fetaBin=J->ietaBin+.333;
00878 J->rmsPhiBin=0.0;
00879 J->rmsEtaBin=0.0;
00880 return;
00881 }
00882
00883 int iphi0=J->iphiBin;
00884 int ieta0=J->ietaBin;
00885 float iene0=J->iene;
00886
00887
00888 float sumY=0.0;
00889 float sum1;
00890
00891
00892 double sumYY = 0.0;
00893 int nEnePhi=0;
00894
00895
00896 float sumX=0.0;
00897
00898
00899 double sumXX = 0.0;
00900 int nEneEta = 0;
00901
00902 float etaEneA[cl2jet_par_mxEtaBin];
00903 memset(etaEneA,0,sizeof(etaEneA));
00904
00905 int ix,iy;
00906
00907 for(iy=iphi0;iy<iphi0+cl2jet_par_mxPhiBin;iy++)
00908 {
00909 int jy=iy % cl2jetMaxPhiBins;
00910 float *patchEneA=eve_patchEne+(jy*cl2jetMaxEtaBins);
00911
00912 sum1=0.0;
00913 for(ix=ieta0;ix<ieta0+cl2jet_par_mxEtaBin;ix++)
00914 {
00915 sum1+=patchEneA[ix];
00916 etaEneA[ix-ieta0]+=patchEneA[ix];
00917 }
00918 if(sum1>0) nEnePhi++;
00919 sumY+=sum1*iy;
00920 sumYY+=sum1*iy*iy;
00921 }
00922
00923
00924 int jx;
00925 for(jx=ieta0;jx<ieta0+cl2jet_par_mxEtaBin;jx++)
00926 {
00927 if(etaEneA[jx-ieta0]>0) nEneEta++;
00928 sumX+=jx*etaEneA[jx-ieta0];
00929 sumXX+=(jx*jx*etaEneA[jx-ieta0]);
00930 }
00931
00932
00933 float phiMean= 1.*sumY/iene0;
00934 float fphiBinMax=0.5 +phiMean;
00935 float rmsPhi=0.0;
00936 if(nEnePhi>1)
00937 {
00938 rmsPhi=sqrt(nEnePhi/(nEnePhi-1.) *(sumYY/iene0 - phiMean*phiMean));
00939 }
00940 if(fphiBinMax>cl2jetMaxPhiBins) fphiBinMax-=cl2jetMaxPhiBins;
00941
00942
00943 float etaMean = 1.*sumX/iene0;
00944 float fetaBin=0.5 + etaMean;
00945 float rmsEta=0.0;
00946 if(nEneEta>1)
00947 {
00948 rmsEta=sqrt(nEneEta/(nEneEta-1.) *(sumXX/iene0 - etaMean*etaMean));
00949 }
00950
00951 J->fphiBin=fphiBinMax;
00952 J->fetaBin=fetaBin;
00953 J->rmsPhiBin=rmsPhi;
00954 J->rmsEtaBin=rmsEta;
00955
00956 }
00957
00958
00959
00960 void
00961 L2jetAlgo2009:: dumpPatchEneA(){
00962
00963 int ix,iy;
00964 for(iy=0;iy<cl2jetMaxPhiBins;iy++) {
00965 float *patchEneA=eve_patchEne+(iy*cl2jetMaxEtaBins);
00966
00967 for(ix=0;ix<cl2jetMaxEtaBins;ix++,patchEneA++){
00968 printf(" %6f",*patchEneA);
00969 }
00970 printf(" iPhi=%d\n",iy);
00971 }
00972
00973 }
00974
00975
00976
00977
00978 void
00979 L2jetAlgo2009::computeE(int token){
00980 }
00981
00982
00983 void
00984 L2jetAlgo2009::finishRunHisto(){
00985
00986
00987 const int *data20=hA[20]->getData();
00988 const int *data30=hA[30]->getData();
00989
00990 int bHotSum=1,bHotId=-1;
00991 int eHotSum=1;
00992
00993 const L2EmcDb::EmcCDbItem *xE=mDb->getByIndex(402), *xB=mDb->getByIndex(402);
00994 int i;
00995 for(i=0; i<EmcDbIndexMax; i++) {
00996 const L2EmcDb::EmcCDbItem *x=mDb->getByIndex(i);
00997 if(mDb->isEmpty(x)) continue;
00998 if (mDb->isBTOW(x) ) {
00999 int softId=atoi(x->tube+2);
01000 int ieta= (x->eta-1);
01001 int iphi= (x->sec-1)*10 + x->sub-'a' ;
01002
01003 hA[21]->fillW(softId,data20[x->rdo]);
01004 hA[22]->fillW(ieta, iphi,data20[x->rdo]);
01005 if(bHotSum<data20[x->rdo]) {
01006 bHotSum=data20[x->rdo];
01007 bHotId=softId;
01008 xB=x;
01009 }
01010 }
01011 else if (mDb->isETOW(x) ) {
01012 int ihard=x->chan+(x->crate-1)*128;
01013 int ieta= 12-x->eta;
01014 int iphi= (x->sec-1)*5 + x->sub-'A' ;
01015 hA[31]->fillW(ihard,data30[x->rdo]);
01016 hA[32]->fillW(ieta, iphi,data30[x->rdo]);
01017 if(eHotSum<data30[x->rdo]) {
01018 eHotSum=data30[x->rdo];
01019 xE=x;
01020 }
01021
01022 }
01023 }
01024 if (mLogFile){
01025 fprintf(mLogFile,"L2jet::finishRun()\n");
01026 fprintf(mLogFile,"#BTOW_hot tower _candidate_ (bHotSum=%d) :, softID %d , crate %d , chan %d , name %s\n",bHotSum,bHotId,xB->crate,xB->chan,xB->name);
01027 fprintf(mLogFile,"#ETOW_hot tower _candidate_ (eHotSum=%d) :, name %s , crate %d , chan %d\n",eHotSum,xE->name,xE->crate,xE->chan);
01028 }
01029
01030 }
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073