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
00018
00019
00020 #ifdef IS_REAL_L2 //in l2-ana environment
00021 #include "../L2algoUtil/L2EmcDb.h"
00022 #include "../L2algoUtil/L2Histo.h"
00023 #else
00024 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcDb.h"
00025 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2Histo.h"
00026 #endif
00027
00028 #include "L2adc2energyAlgo.h"
00029 #include "Map_DeltaPhiJets.h"
00030
00031
00032
00033 L2adc2energyAlgo::L2adc2energyAlgo(const char* name, L2EmcDb* db, char* outDir, int resOff)
00034 : L2VirtualAlgo( name, db, outDir, resOff) {
00035
00036
00037
00038 par_maxADC=4095;
00039 par_maxEt=60;
00040 par_adcMask= (unsigned short) (-0x10);
00041 par_pedOff=0x10/2;
00042 createHisto();
00043 run_number=-1;
00044 printf("L2adc2energyAlgo instantiated, logPath='%s'\n",mOutDir);
00045 }
00046
00047
00048
00049 bool
00050 L2adc2energyAlgo::paramsChanged( int *rc_ints, float *rc_floats) {
00051 int i;
00052 for(i=0;i<5;i++)
00053 if(rc_ints[i]!=raw_ints[i]) goto foundProblem;
00054
00055 for(i=0;i<5;i++)
00056 if(fabs(rc_floats[i]-raw_floats[i])>0.00001) goto foundProblem;
00057
00058 return false;
00059
00060 foundProblem:
00061 if (mLogFile) fprintf(mLogFile,"L2jet-ghost initRun - inconsistent params, ABORT initialization\n");
00062 return true;
00063 }
00064
00065
00066
00067 int
00068 L2adc2energyAlgo::initRun( int runNo, int *rc_ints, float *rc_floats) {
00069
00070
00071 if(mDb->initRun(runNo)) return -7;
00072
00073
00074 if(run_number==runNo) {
00075 if (mLogFile) fprintf(mLogFile,"L2jet::initRun-%s(%d)=ghost already initilized, only check params\n",mName, runNo);
00076 printf("L2jet::initRun-%s(%d)=ghost already initilized, only checking params\n",mName, runNo);
00077 int ret= paramsChanged(rc_ints, rc_floats);
00078
00079 if(ret){
00080 run_number=-77;
00081 if (mLogFile) {
00082 fprintf(mLogFile,"L2jet algorithm init: crashA in internal logic\n");
00083 fclose(mLogFile);
00084 }
00085 return ret;
00086 }
00087 }
00088
00089
00090 int i;
00091 for (i=0; i<mxHA;i++) if(hA[i])hA[i]->reset();
00092
00093
00094 memset(db_btowThr, 0xFFFF,sizeof(db_btowThr));
00095 memset(db_btowPedS, 0, sizeof(db_btowPedS));
00096 memset(db_btowGainCorr, 0, sizeof(db_btowGainCorr));
00097 memset(db_btowL2PhiBin, 0, sizeof(db_btowL2PhiBin));
00098 memset(db_btowL2PatchBin,0, sizeof(db_btowL2PatchBin));
00099
00100 memset(db_etowThr, 0xFFFF,sizeof(db_etowThr));
00101 memset(db_etowPedS, 0 ,sizeof(db_etowPedS));
00102 memset(db_etowGainCorr, 0 ,sizeof(db_etowGainCorr));
00103 memset(db_etowL2PhiBin, 0 ,sizeof(db_etowL2PhiBin));
00104 memset(db_etowL2PatchBin,0 ,sizeof(db_etowL2PatchBin));
00105
00106
00107
00108
00109
00110
00111
00112 int par_IgainCorrOne=30;
00113 int par_IgainCorrMin=5;
00114 int par_IgainCorrMax=60;
00115
00116 run_startUnix=time(0);
00117 run_number =runNo;
00118 raw_ints =rc_ints;
00119 raw_floats =rc_floats;
00120 run_nEventOneJet=run_nEventDiJet= run_nEventRnd=0;
00121
00122 char Fname[1000];
00123 sprintf(Fname,"%s/run%d.l2jet.out",mOutDir,run_number);
00124 printf("L2jet::initRun-%s('%s') ...\n",mName,Fname);
00125
00126 mEventsInRun=0;
00127 mLogFile = fopen(Fname,"w");
00128 if( mLogFile==0) printf(" L2adc2energyAlgo() UNABLE to open run summary log file, continue anyhow\n");
00129
00130
00131
00132 par_cutTag = rc_ints[0];
00133 par_useBtowEast= (rc_ints[1]&1 )>0;
00134 par_useBtowWest= (rc_ints[1]&2)>0;
00135 par_useEndcap = rc_ints[2]&1;
00136 int par_adcThr = rc_ints[3];
00137 par_minPhiBinDiff=rc_ints[4];
00138
00139 par_oneJetThr = rc_floats[0];
00140 par_diJetThrHigh= rc_floats[1];
00141 par_diJetThrLow = rc_floats[2];
00142 par_rndAccProb = rc_floats[3];
00143 par_dbg =(int)rc_floats[4];
00144
00145
00146 par_energyScale=par_maxADC*par_IgainCorrOne/par_maxEt;
00147
00148 float monTwEtThr=2.0;
00149 par_hotTwEtThr= (int)(monTwEtThr*par_energyScale);
00150
00151 par_rndAccThr= int(par_rndAccProb* RAND_MAX);
00152 if(par_rndAccProb<0) {
00153 par_rndAccThr=0;
00154 par_rndAccProb=0.;
00155 } else if (par_rndAccProb>0.9999) {
00156 par_rndAccThr=RAND_MAX;
00157 par_rndAccProb=1.0;
00158 }
00159 if (mLogFile) {
00160 fprintf(mLogFile,"L2jet algorithm initRun(%d), compiled: %s , %s\n params:\n",run_number,__DATE__,__TIME__);
00161 fprintf(mLogFile," - use BTOW: East=%d West=%d, Endcap=%d L2ResOffset=%d\n", par_useBtowEast, par_useBtowWest,par_useEndcap ,mResultOffset);
00162 fprintf(mLogFile," - threshold: ADC-ped> %d \n", par_adcThr);
00163 fprintf(mLogFile," - min phi opening angle Jet1<->Jet2: %d in L2phiBins\n",par_minPhiBinDiff);
00164 fprintf(mLogFile," - diJet Et thrHigh= %.2f (GeV) thrLow= %.2f (GeV)\n", par_diJetThrHigh, par_diJetThrLow);
00165 fprintf(mLogFile," - oneJet Et thr = %.2f (GeV) ; rndAccProb=%f; cutTag=%d \n",par_oneJetThr,par_rndAccProb,par_cutTag);
00166 fprintf(mLogFile," - debug=%d, hot tower threshold: Et> %.1f GeV ( only monitoring)\n",par_dbg, monTwEtThr);
00167 }
00168
00169
00170 int kBad=0;
00171 kBad+=0x0001 * ( !par_useBtowEast & !par_useBtowWest & !par_useEndcap);
00172 kBad+=0x0002 * (par_adcThr<par_pedOff);
00173 kBad+=0x0004 * (par_adcThr>16);
00174 kBad+=0x0008 * (par_minPhiBinDiff<5);
00175 kBad+=0x0010 * (par_minPhiBinDiff>=15);
00176 kBad+=0x0020 * (par_oneJetThr<3.);
00177 kBad+=0x0040 * (par_oneJetThr>12.);
00178 kBad+=0x0080 * (par_diJetThrLow<2.9);
00179 kBad+=0x0100 * (par_diJetThrHigh<par_diJetThrLow);
00180 kBad+=0x0200 * (par_diJetThrHigh>12.);
00181 kBad+=0x0400 * (par_cutTag<=0 || par_cutTag>255);
00182 kBad+=0x0800 * (par_rndAccProb<0. || par_rndAccProb>1.);
00183 if (mLogFile) {
00184 fprintf(mLogFile,"L2jet initRun() params checked for consistency, Error flag=0x%04x\n",kBad);
00185 if(kBad) fprintf(mLogFile,"L2jet initRun() ABORT\n");
00186 }
00187
00188 if(kBad) {
00189 run_number=-66;
00190 if (mLogFile) {
00191 fprintf(mLogFile,"L2jet algorithm init: crashB in internal logic\n");
00192 fclose(mLogFile);
00193 return kBad;
00194 }
00195 }
00196
00197 char tit[100];
00198 sprintf(tit,"# BTOW towers>ped+%d (input); x: # of towers/event",par_adcThr);
00199 hA[47]->setTitle(tit);
00200
00201 sprintf(tit,"# ETOW towers>ped+%d (input); x: # of towers/event",par_adcThr);
00202 hA[48]->setTitle(tit);
00203
00204
00205
00206
00207 const float edgeEtaBinEtow[] = {
00208 2.0 ,
00209 1.9008 , 1.8065 , 1.7168 , 1.6317 , 1.5507 , 1.4738 ,
00210 1.4007 , 1.3312 , 1.2651 , 1.2023 , 1.1427 , 1.086 ,
00211 0.0
00212 };
00213
00214 const int mxEtaBinsE=12,mxEtaBinsB=40;
00215 float idealGainEtow[mxEtaBinsE], idealGainBtow[mxEtaBinsB];
00216 float coshEtow[mxEtaBinsE],coshBtow[mxEtaBinsB];
00217
00218 for(i=0;i<mxEtaBinsE;i++ ){
00219 float avrEta=(edgeEtaBinEtow[i]+edgeEtaBinEtow[i+1])/2.;
00220 coshEtow[i]=cosh(avrEta);
00221 idealGainEtow[i]=par_maxADC/par_maxEt/coshEtow[i];
00222
00223 }
00224
00225
00226 for(i=0;i<mxEtaBinsB;i++ ){
00227 float avrEta=-0.975 +i*0.05;
00228 coshBtow[i]=cosh(avrEta);
00229 idealGainBtow[i]=par_maxADC/par_maxEt/coshBtow[i];
00230
00231 }
00232
00233
00234
00235
00236 int etowEtaBin2Patch[mxEtaBinsE]={14,14,13,13,12,12,11,11,11,10,10,10};
00237
00238 int nB=0, nE=0;
00239 int nBg=0, nEg=0;
00240
00241 for(i=0; i<EmcDbIndexMax; i++) {
00242 const L2EmcDb::EmcCDbItem *x=mDb->getByIndex(i);
00243 if(mDb->isEmpty(x)) continue;
00244 if(x->fail) continue;
00245 if(x->gain<=0) continue;
00246
00247
00248
00249 int ietaP, iphiP;
00250 if (mDb->isBTOW(x) ) {
00251
00252 nB++;
00253 if(x->eta<0 || x->eta>mxEtaBinsB) goto crashIt_1;
00254 if(!par_useBtowEast && x->eta<=20) continue;
00255 if(!par_useBtowWest && x->eta>=21) continue;
00256 ietaP= (x->eta-1)/4;
00257 int iphiTw=(x->sec-1)*10 + x->sub-'a';
00258
00259 iphiTw--;
00260 if(iphiTw<0) iphiTw=119;
00261
00262 iphiP= iphiTw/4 ;
00263
00264
00265 int IgainCor=int(par_IgainCorrOne*idealGainBtow[x->eta-1]/x->gain);
00266
00267
00268 if(IgainCor <par_IgainCorrMin) continue;
00269 if(IgainCor >par_IgainCorrMax) continue;
00270 db_btowGainCorr[x->rdo]=IgainCor;
00271
00272 db_btowL2PhiBin[x->rdo]=iphiP;
00273 db_btowL2PatchBin[x->rdo]=ietaP+ iphiP*cl2jetMaxEtaBins;
00274 db_btowThr[x->rdo]=(int) (x->ped+par_adcThr);
00275 db_btowPedS[x->rdo]=(unsigned short) (par_pedOff-x->ped);
00276 nBg++;
00277 } else if(mDb->isETOW(x) && par_useEndcap) {
00278
00279 nE++;
00280 int iphiTw= (x->sec-1)*5 + x->sub-'A';
00281
00282 iphiTw--;
00283 if(iphiTw<0) iphiTw=59;
00284
00285 iphiP= iphiTw/2 ;
00286 if(x->eta<0 || x->eta>mxEtaBinsE) goto crashIt_1;
00287 ietaP=etowEtaBin2Patch[x->eta-1];
00288
00289 int IgainCor=int(par_IgainCorrOne*idealGainEtow[x->eta-1]/x->gain);
00290
00291
00292 if(IgainCor <par_IgainCorrMin) continue;
00293 if(IgainCor >par_IgainCorrMax) continue;
00294 db_etowGainCorr[x->rdo]=IgainCor;
00295
00296 db_etowL2PhiBin[x->rdo]=iphiP;
00297 db_etowL2PatchBin[x->rdo]=ietaP+ iphiP*cl2jetMaxEtaBins;
00298 db_etowThr[x->rdo]=(int) (x->ped+par_adcThr);
00299 db_etowPedS[x->rdo]=(unsigned short) (par_pedOff-x->ped);
00300 nEg++;
00301 }
00302
00303 }
00304
00305 if (mLogFile) {
00306 fprintf(mLogFile,"L2jet algorithm: found working/calibrated: %d/%d=ETOW & %d/%d=BTOW, based on ASCII DB\n",nE,nEg,nB,nBg);
00307 }
00308
00309 return 0;
00310
00311 crashIt_1:
00312 run_number=-55;
00313 if (mLogFile) {
00314 fprintf(mLogFile,"L2jet algorithm init: crashC in internal logic\n");
00315 fclose(mLogFile);
00316 }
00317 return -6;
00318
00319 }
00320
00321
00322
00323
00324 bool
00325 L2adc2energyAlgo::doEvent(int L0trg, int inpEveId, TrgDataType* trgData,
00326 int bemcIn, ushort *bemcData,
00327 int eemcIn, ushort *eemcData){
00328
00329 rdtscl_macro(mEveTimeStart);
00330
00331 if(L0trg==1) hA[10]->fill(1);
00332 else if(L0trg==2) hA[10]->fill(2);
00333
00334 if(eve_ID!=inpEveId) {
00335
00336
00337
00338
00339
00340
00341
00342 eve_ID=inpEveId;
00343 mEventsInRun++;
00344 clearEvent();
00345 int runTimeSec=time(0)- run_startUnix;
00346 hA[10]->fill(0);
00347 hA[12]->fill(runTimeSec);
00348
00349 if(par_dbg>1) printf("\n......... in L2adc2E_doEvent(ID=%d)... bIn=%d eIn=%d\n",eve_ID,bemcIn,eemcIn);
00350
00351 if (bemcIn || eemcIn){
00352
00353
00354
00355
00356 int nBtowTw=0, nEtowTw=0;
00357
00358 if(bemcIn==1 && (par_useBtowEast||par_useBtowWest) ) {
00359 nBtowTw=projectAdc( bemcData, MaxBtowRdo,
00360 db_btowThr, db_btowPedS, db_btowGainCorr,
00361 db_btowL2PhiBin, db_btowL2PatchBin,
00362 hA[20] );
00363 }
00364
00365
00366 if(eemcIn==1 && par_useEndcap ) {
00367 nEtowTw=projectAdc( eemcData, 720,
00368 db_etowThr, db_etowPedS, db_etowGainCorr,
00369 db_etowL2PhiBin, db_etowL2PatchBin,
00370 hA[30] );
00371 }
00372
00373
00374 mAccept=true;
00375
00376 if( mAccept) hA[10]->fill(8);
00377
00378
00379
00380
00381
00382 rdtscl_macro(mEveTimeStop);
00383 mEveTimeDiff=mEveTimeStop-mEveTimeStart;
00384 int kTick=mEveTimeDiff/1000;
00385
00386 mhT->fill(kTick);
00387
00388
00389 if(par_dbg){
00390
00391 }
00392
00393 }
00394 }
00395
00396
00397 return mAccept;
00398 }
00399
00400
00401
00402
00403 void
00404 L2adc2energyAlgo::finishRun() {
00405 if(run_number<0) return;
00406
00407 char Fname[1000];
00408 sprintf(Fname,"%s/run%d.l2adc2E.hist.bin",mOutDir,run_number);
00409 printf("L2jet::finishRun('%s') , save histo ...\n",Fname);
00410 mHistFile = fopen(Fname,"w");
00411
00412 if (mLogFile) {
00413 fprintf(mLogFile,"L2-jet algorithm finishRun(%d)\n",run_number);
00414 fprintf(mLogFile," - %d events seen by L2 di-jet\n",mEventsInRun);
00415 fprintf(mLogFile," - accepted: rnd=%d oneJet=%d diJet=%d \n", run_nEventRnd, run_nEventOneJet, run_nEventDiJet);
00416
00417
00418
00419 hA[10]->printCSV(mLogFile);
00420
00421 }
00422 finishRunHisto();
00423
00424 if( mHistFile==0) {
00425 printf(" L2adc2energyAlgo: finishRun() UNABLE to open run summary log file, continue anyhow\n");
00426 if (mLogFile)
00427 fprintf(mLogFile,"L2 di-jet histos NOT saved, I/O error\n");
00428 } else {
00429 int j;
00430 int nh=0;
00431 for(j=0;j<mxHA;j++) {
00432 if(hA[j]==0) continue;
00433 hA[j]->write(mHistFile);
00434 nh++;
00435 }
00436 finishCommonHistos();
00437 fclose(mHistFile);
00438 mHistFile=0;
00439 if (mLogFile)
00440 fprintf(mLogFile,"L2 di-jet: %d histos saved to '%s'\n",nh,Fname);
00441 }
00442
00443 run_number=-2;
00444
00445
00446 if (mLogFile && mLogFile!=stdout) {
00447 fclose(mLogFile);
00448 mLogFile=0;
00449 }
00450
00451 }
00452
00453
00454
00455
00456 void
00457 L2adc2energyAlgo::createHisto() {
00458 memset(hA,0,sizeof(hA));
00459
00460 hA[10]=new L2Histo(10, (char*)"total event counter; x=cases",9);
00461 hA[11]=new L2Histo(11, (char*)"L2 time used per input event; x: time (CPU kTics), range=100muSec; y: events ",160);
00462
00463 int mxRunDration=2500;
00464 hA[12]=new L2Histo(12, (char*)"rate of input events; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
00465
00466 hA[13]=new L2Histo(13, (char*)"rate of accepted one-Jet; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
00467 hA[14]=new L2Histo(14, (char*)"rate of accepted di-Jet ; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
00468 hA[15]=new L2Histo(15, (char*)"rate of random accepted ; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
00469
00470
00471 hA[20]=new L2Histo(20, (char*)"BTOW tower, Et>2.0 GeV (input); x: BTOW RDO index=chan*30+fiber; y: counts", 4800);
00472 hA[21]=new L2Histo(21, (char*)"BTOW tower, Et>2.0 GeV (input); x: BTOW softID", 4800);
00473 hA[22]=new L2Histo(22, (char*)"BTOW tower, Et>2.0 GeV (input); x: eta bin, [-1,+1]; y: phi bin ~sector",40,120);
00474
00475
00476 hA[30]=new L2Histo(30, (char*)"ETOW tower, Et>2.0 GeV (input); x: ETOW RDO index=chan*6+fiber; y: counts", 720 );
00477 hA[31]=new L2Histo(31, (char*)"ETOW tower, Et>2.0 GeV (input); x: i=chan+128*crate", 768);
00478 hA[32]=new L2Histo(32, (char*)"ETOW tower, Et>2.0 GeV (input); x: 12 - Endcap etaBin ,[+1,+2]; y: phi bin ~sector",12,60);
00479
00480
00481 hA[40]=new L2Histo(40, (char*)"Et Jet1-Jet2 (input); x: Jet1 Et/GeV ; Jet2 Et/GeV",12,12);
00482 hA[41]=new L2Histo(41, (char*)"diJet1 eta-phi (input); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
00483 hA[42]=new L2Histo(42, (char*)"diJet2 eta-phi (input); x: iEta [-1,+2] ; y: iPhi ~sector",15,30);
00484
00485 hA[43]=new L2Histo(43, (char*)"diJet phi1-phi2 (input); x: iPhi1 ~sector ; y: iPhi2 ~sector ",30,30);
00486
00487 hA[44]=new L2Histo(44, (char*)"Jet1 Et (input); x: Et (GeV)", 60);
00488 hA[45]=new L2Histo(45, (char*)"Jet2 Et (input); x: Et (GeV)", 60);
00489 hA[46]=new L2Histo(46, (char*)"total Et (input); x: Et (GeV)", 60);
00490 hA[47]=new L2Histo(47, (char*)"# BTOW towers>thrXX (input); x: # of towers/event", 200);
00491 hA[48]=new L2Histo(48, (char*)"# ETOW towers>thrXX (input); x: # of towers/event", 100);
00492
00493
00494 hA[50]=new L2Histo(50, (char*)"one-Jet Et (accepted); x: jet Et (GeV)", 60);
00495 hA[51]=new L2Histo(51, (char*)"one-Jet eta-phi (accepted); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
00496 hA[52]=new L2Histo(52, (char*)"one-Jet eta (accepted); x: iEta [-1,+2]", 15);
00497 hA[53]=new L2Histo(53, (char*)"one-Jet phi (accepted); x: iPhi ~sector", 30);
00498
00499
00500 hA[60]=new L2Histo(60, (char*)"Et of Jet1 vs. Jet2 (accepted); x: Jet1/GeV ; Jet2/GeV",12,12);
00501 hA[61]=new L2Histo(61, (char*)"diJet1 eta-phi (accepted); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
00502 hA[62]=new L2Histo(62, (char*)"diJet2 eta-phi (accepted); x: iEta [-1,+2] ; y: iPhi ~sector",15,30);
00503
00504 hA[63]=new L2Histo(63, (char*)"diJet phi1-phi2 (accepted); x: iPhi1 ~sector ; y: iPhi2 ~sector ",30,30);
00505
00506 hA[64]=new L2Histo(64, (char*)"diJet1 Et (accepted); x: Et (GeV)", 60);
00507 hA[65]=new L2Histo(65, (char*)"diJet2 Et (accepted); x: Et (GeV)", 60);
00508
00509 hA[66]=new L2Histo(66, (char*)"diJet1 eta (accepted); x: i Eta [-1,+2]", 15);
00510 hA[67]=new L2Histo(67, (char*)"diJet2 eta (accepted); x: i Eta [-1,+2]", 15);
00511 hA[68]=new L2Histo(68, (char*)"diJet1 phi (accepted); x: iPhi ~sector", 30);
00512 hA[69]=new L2Histo(69, (char*)"diJet2 phi (accepted); x: iPhi ~sector", 30);
00513 hA[70]=new L2Histo(70, (char*)"diJet delZeta (accepted); x: delta zeta (rad*10)", MxPhiRad10);
00514 hA[71]=new L2Histo(71, (char*)"diJet delZeta vs. eta1 (accepted); x: iEta1 [-1,+2] ; y: delta zeta (rad*10)",15, MxPhiRad10);
00515 hA[72]=new L2Histo(72, (char*)"diJet eta2 vs. eta1 (accepted); x: iEta1 [-1,+2] ;x: iEta2 [-1,+2] ",15,15);
00516 hA[73]=new L2Histo(73, (char*)"diJet delZeta vs. avrPhi (accepted); x: (iphi1+iphi2)/2 (12 deg/bin); y: delta zeta (rad*10)",30, MxPhiRad10);
00517 hA[74]=new L2Histo(74, (char*)"total Et diJet (accepted); x: Et (GeV)", 60);
00518
00519 }
00520
00521
00522
00523 void
00524 L2adc2energyAlgo::clearEvent(){
00525
00526
00527 mAccept=false;
00528 mEveTimeDiff=0;
00529 memset(eve_patchEne,0,sizeof(eve_patchEne));
00530 memset(eve_phiEne,0,sizeof(eve_phiEne));
00531 }
00532
00533
00534
00535
00536
00537 int
00538 L2adc2energyAlgo::projectAdc( ushort *rawAdc, int nRdo,
00539 ushort *thr, ushort *pedS, ushort *gainCorr,
00540 ushort *phiBin, ushort *patchBin,
00541 L2Histo *hHot ){
00542
00543 int tmpNused=0;
00544
00545 short rdo;
00546 int adc,adc4;
00547 for(rdo=0; rdo<nRdo; rdo++){
00548 if(rawAdc[rdo]<thr[rdo])continue;
00549
00550 adc=(rawAdc[rdo]+pedS[rdo]) & par_adcMask ;
00551 adc4=adc*gainCorr[rdo];
00552 eve_patchEne[patchBin[rdo]]+=adc4;
00553 eve_phiEne[phiBin[rdo]]+=adc4;
00554 tmpNused++;
00555
00556
00557 if(adc4 >par_hotTwEtThr) hHot->fill(rdo);
00558 }
00559
00560 return tmpNused;
00561 }
00562
00563
00564
00565
00566 void
00567 L2adc2energyAlgo:: dumpPatchEneA(){
00568
00569 int ix,iy;
00570 for(iy=0;iy<cl2jetMaxPhiBins;iy++) {
00571 int *patchEneA=eve_patchEne+(iy*cl2jetMaxEtaBins);
00572
00573 for(ix=0;ix<cl2jetMaxEtaBins;ix++,patchEneA++){
00574 printf(" %6d",*patchEneA);
00575 }
00576 printf(" iPhi=%d\n",iy);
00577 }
00578
00579 }
00580
00581
00582
00583
00584 void
00585 L2adc2energyAlgo::finishRunHisto(){
00586
00587
00588 const int *data20=hA[20]->getData();
00589 const int *data30=hA[30]->getData();
00590
00591 int bHotSum=1,bHotId=-1;
00592 int eHotSum=1;
00593
00594 const L2EmcDb::EmcCDbItem *xE=mDb->getByIndex(402), *xB=mDb->getByIndex(402);
00595 int i;
00596 for(i=0; i<EmcDbIndexMax; i++) {
00597 const L2EmcDb::EmcCDbItem *x=mDb->getByIndex(i);
00598 if(mDb->isEmpty(x)) continue;
00599 if (mDb->isBTOW(x) ) {
00600 int softId=atoi(x->tube+2);
00601 int ieta= (x->eta-1);
00602 int iphi= (x->sec-1)*10 + x->sub-'a' ;
00603
00604 hA[21]->fillW(softId,data20[x->rdo]);
00605 hA[22]->fillW(ieta, iphi,data20[x->rdo]);
00606 if(bHotSum<data20[x->rdo]) {
00607 bHotSum=data20[x->rdo];
00608 bHotId=softId;
00609 xB=x;
00610 }
00611 }
00612 else if (mDb->isETOW(x) ) {
00613 int ihard=x->chan+(x->crate-1)*128;
00614 int ieta= 12-x->eta;
00615 int iphi= (x->sec-1)*5 + x->sub-'A' ;
00616 hA[31]->fillW(ihard,data30[x->rdo]);
00617 hA[32]->fillW(ieta, iphi,data30[x->rdo]);
00618 if(eHotSum<data30[x->rdo]) {
00619 eHotSum=data30[x->rdo];
00620 xE=x;
00621 }
00622
00623 }
00624 }
00625 if (mLogFile){
00626 fprintf(mLogFile,"L2jet::finishRun()\n");
00627 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);
00628 fprintf(mLogFile,"#ETOW_hot tower _candidate_ (eHotSum=%d) :, name %s , crate %d , chan %d\n",eHotSum,xE->name,xE->crate,xE->chan);
00629 }
00630
00631
00632 }
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646