20 #ifdef IS_REAL_L2 //in l2-ana environment
21 #include "../L2algoUtil/L2EmcDb.h"
22 #include "../L2algoUtil/L2Histo.h"
24 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcDb.h"
25 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2Histo.h"
28 #include "L2jetAlgo2006.h"
29 #include "L2jetResults2006.h"
30 #include "Map_DeltaPhiJets.h"
34 L2jetAlgo2006::L2jetAlgo2006(
const char* name,
L2EmcDb* db,
char* outDir,
int resOff)
41 par_adcMask= (
unsigned short) (-0x10);
45 printf(
"L2jetAlgo2006 instantiated, logPath='%s'\n",mOutDir);
53 L2jetAlgo2006::paramsChanged(
int *rc_ints,
float *rc_floats) {
56 if(rc_ints[i]!=raw_ints[i])
goto foundProblem;
59 if(fabs(rc_floats[i]-raw_floats[i])>0.00001)
goto foundProblem;
64 if (mLogFile) fprintf(mLogFile,
"L2jet-ghost initRun - inconsistent params, ABORT initialization\n");
71 L2jetAlgo2006::initRun(
int runNo,
int *rc_ints,
float *rc_floats) {
74 if(mDb->initRun(runNo))
return -7;
77 if(run_number==runNo) {
78 if (mLogFile) fprintf(mLogFile,
"L2jet::initRun-%s(%d)=ghost already initilized, only check params\n",mName, runNo);
79 printf(
"L2jet::initRun-%s(%d)=ghost already initilized, only checking params\n",mName, runNo);
80 int ret= paramsChanged(rc_ints, rc_floats);
85 fprintf(mLogFile,
"L2jet algorithm init: crashA in internal logic\n");
94 for (i=0; i<mxHA;i++)
if(hA[i])hA[i]->reset();
97 memset(db_btowThr, 0xFFFF,
sizeof(db_btowThr));
98 memset(db_btowPedS, 0,
sizeof(db_btowPedS));
99 memset(db_btowGainCorr, 0,
sizeof(db_btowGainCorr));
100 memset(db_btowL2PhiBin, 0,
sizeof(db_btowL2PhiBin));
101 memset(db_btowL2PatchBin,0,
sizeof(db_btowL2PatchBin));
103 memset(db_etowThr, 0xFFFF,
sizeof(db_etowThr));
104 memset(db_etowPedS, 0 ,
sizeof(db_etowPedS));
105 memset(db_etowGainCorr, 0 ,
sizeof(db_etowGainCorr));
106 memset(db_etowL2PhiBin, 0 ,
sizeof(db_etowL2PhiBin));
107 memset(db_etowL2PatchBin,0 ,
sizeof(db_etowL2PatchBin));
115 int par_IgainCorrOne=30;
116 int par_IgainCorrMin=5;
117 int par_IgainCorrMax=60;
119 run_startUnix=time(0);
122 raw_floats =rc_floats;
123 run_nEventOneJet=run_nEventDiJet= run_nEventRnd=0;
126 sprintf(Fname,
"%s/run%d.l2jet.out",mOutDir,run_number);
127 printf(
"L2jet::initRun-%s('%s') ...\n",mName,Fname);
130 mLogFile = fopen(Fname,
"w");
131 if( mLogFile==0) printf(
" L2jetAlgo2006() UNABLE to open run summary log file, continue anyhow\n");
135 par_cutTag = rc_ints[0];
136 par_useBtowEast= (rc_ints[1]&1 )>0;
137 par_useBtowWest= (rc_ints[1]&2)>0;
138 par_useEndcap = rc_ints[2]&1;
139 int par_adcThr = rc_ints[3];
140 par_minPhiBinDiff=rc_ints[4];
142 par_oneJetThr = rc_floats[0];
143 par_diJetThrHigh= rc_floats[1];
144 par_diJetThrLow = rc_floats[2];
145 par_rndAccProb = rc_floats[3];
146 par_dbg =(int)rc_floats[4];
149 par_energyScale=par_maxADC*par_IgainCorrOne/par_maxEt;
151 float monTwEtThr=2.0;
152 par_hotTwEtThr= (int)(monTwEtThr*par_energyScale);
154 par_rndAccThr= int(par_rndAccProb* RAND_MAX);
155 if(par_rndAccProb<0) {
158 }
else if (par_rndAccProb>0.9999) {
159 par_rndAccThr=RAND_MAX;
163 fprintf(mLogFile,
"L2jet algorithm initRun(%d), compiled: %s , %s\n params:\n",run_number,__DATE__,__TIME__);
164 fprintf(mLogFile,
" - use BTOW: East=%d West=%d, Endcap=%d L2ResOffset=%d\n", par_useBtowEast, par_useBtowWest,par_useEndcap ,mResultOffset);
165 fprintf(mLogFile,
" - threshold: ADC-ped> %d \n", par_adcThr);
166 fprintf(mLogFile,
" - min phi opening angle Jet1<->Jet2: %d in L2phiBins\n",par_minPhiBinDiff);
167 fprintf(mLogFile,
" - diJet Et thrHigh= %.2f (GeV) thrLow= %.2f (GeV)\n", par_diJetThrHigh, par_diJetThrLow);
168 fprintf(mLogFile,
" - oneJet Et thr = %.2f (GeV) ; rndAccProb=%f; cutTag=%d \n",par_oneJetThr,par_rndAccProb,par_cutTag);
169 fprintf(mLogFile,
" - debug=%d, hot tower threshold: Et> %.1f GeV ( only monitoring)\n",par_dbg, monTwEtThr);
174 kBad+=0x0001 * ( !par_useBtowEast & !par_useBtowWest & !par_useEndcap);
175 kBad+=0x0002 * (par_adcThr<par_pedOff);
176 kBad+=0x0004 * (par_adcThr>16);
177 kBad+=0x0008 * (par_minPhiBinDiff<5);
178 kBad+=0x0010 * (par_minPhiBinDiff>=15);
179 kBad+=0x0020 * (par_oneJetThr<3.);
180 kBad+=0x0040 * (par_oneJetThr>12.);
181 kBad+=0x0080 * (par_diJetThrLow<2.9);
182 kBad+=0x0100 * (par_diJetThrHigh<par_diJetThrLow);
183 kBad+=0x0200 * (par_diJetThrHigh>12.);
184 kBad+=0x0400 * (par_cutTag<=0 || par_cutTag>255);
185 kBad+=0x0800 * (par_rndAccProb<0. || par_rndAccProb>1.);
187 fprintf(mLogFile,
"L2jet initRun() params checked for consistency, Error flag=0x%04x\n",kBad);
188 if(kBad) fprintf(mLogFile,
"L2jet initRun() ABORT\n");
194 fprintf(mLogFile,
"L2jet algorithm init: crashB in internal logic\n");
201 sprintf(tit,
"# BTOW towers>ped+%d (input); x: # of towers/event",par_adcThr);
202 hA[47]->setTitle(tit);
204 sprintf(tit,
"# ETOW towers>ped+%d (input); x: # of towers/event",par_adcThr);
205 hA[48]->setTitle(tit);
210 const float edgeEtaBinEtow[] = {
212 1.9008 , 1.8065 , 1.7168 , 1.6317 , 1.5507 , 1.4738 ,
213 1.4007 , 1.3312 , 1.2651 , 1.2023 , 1.1427 , 1.086 ,
217 const int mxEtaBinsE=12,mxEtaBinsB=40;
218 float idealGainEtow[mxEtaBinsE], idealGainBtow[mxEtaBinsB];
219 float coshEtow[mxEtaBinsE],coshBtow[mxEtaBinsB];
221 for(i=0;i<mxEtaBinsE;i++ ){
222 float avrEta=(edgeEtaBinEtow[i]+edgeEtaBinEtow[i+1])/2.;
223 coshEtow[i]=cosh(avrEta);
224 idealGainEtow[i]=par_maxADC/par_maxEt/coshEtow[i];
229 for(i=0;i<mxEtaBinsB;i++ ){
230 float avrEta=-0.975 +i*0.05;
231 coshBtow[i]=cosh(avrEta);
232 idealGainBtow[i]=par_maxADC/par_maxEt/coshBtow[i];
239 int etowEtaBin2Patch[mxEtaBinsE]={14,14,13,13,12,12,11,11,11,10,10,10};
244 for(i=0; i<EmcDbIndexMax; i++) {
246 if(mDb->isEmpty(x))
continue;
247 if(x->fail)
continue;
248 if(x->gain<=0)
continue;
253 if (mDb->isBTOW(x) ) {
256 if(x->eta<0 || x->eta>mxEtaBinsB)
goto crashIt_1;
257 if(!par_useBtowEast && x->eta<=20)
continue;
258 if(!par_useBtowWest && x->eta>=21)
continue;
260 int iphiTw=(x->sec-1)*10 + x->sub-
'a';
263 if(iphiTw<0) iphiTw=119;
268 int IgainCor=int(par_IgainCorrOne*idealGainBtow[x->eta-1]/x->gain);
271 if(IgainCor <par_IgainCorrMin)
continue;
272 if(IgainCor >par_IgainCorrMax)
continue;
273 db_btowGainCorr[x->rdo]=IgainCor;
275 db_btowL2PhiBin[x->rdo]=iphiP;
276 db_btowL2PatchBin[x->rdo]=ietaP+ iphiP*cl2jetMaxEtaBins;
277 db_btowThr[x->rdo]=(int) (x->ped+par_adcThr);
278 db_btowPedS[x->rdo]=(
unsigned short) (par_pedOff-x->ped);
280 }
else if(mDb->isETOW(x) && par_useEndcap) {
283 int iphiTw= (x->sec-1)*5 + x->sub-
'A';
286 if(iphiTw<0) iphiTw=59;
289 if(x->eta<0 || x->eta>mxEtaBinsE)
goto crashIt_1;
290 ietaP=etowEtaBin2Patch[x->eta-1];
292 int IgainCor=int(par_IgainCorrOne*idealGainEtow[x->eta-1]/x->gain);
295 if(IgainCor <par_IgainCorrMin)
continue;
296 if(IgainCor >par_IgainCorrMax)
continue;
297 db_etowGainCorr[x->rdo]=IgainCor;
299 db_etowL2PhiBin[x->rdo]=iphiP;
300 db_etowL2PatchBin[x->rdo]=ietaP+ iphiP*cl2jetMaxEtaBins;
301 db_etowThr[x->rdo]=(int) (x->ped+par_adcThr);
302 db_etowPedS[x->rdo]=(
unsigned short) (par_pedOff-x->ped);
309 fprintf(mLogFile,
"L2jet algorithm: found working/calibrated: %d/%d=ETOW & %d/%d=BTOW, based on ASCII DB\n",nE,nEg,nB,nBg);
317 fprintf(mLogFile,
"L2jet algorithm init: crashC in internal logic\n");
328 L2jetAlgo2006::doEvent(
int L0trg,
int inpEveId,
TrgDataType* trgData,
329 int bemcIn,
unsigned short *bemcData,
330 int eemcIn,
unsigned short *eemcData){
332 rdtscl_macro(mEveTimeStart);
334 if(L0trg==1) hA[10]->fill(1);
335 else if(L0trg==2) hA[10]->fill(2);
337 if(eve_ID!=inpEveId) {
348 int runTimeSec=time(0)- run_startUnix;
350 hA[12]->fill(runTimeSec);
352 if(par_dbg>1) printf(
"\n......... in L2Jet_doEvent(ID=%d)... bIn=%d eIn=%d\n",eve_ID,bemcIn,eemcIn);
354 if (bemcIn || eemcIn){
361 int nBtowTw=0, nEtowTw=0;
363 if(bemcIn==1 && (par_useBtowEast||par_useBtowWest) ) {
364 nBtowTw=projectAdc( bemcData, MaxBtowRdo,
365 db_btowThr, db_btowPedS, db_btowGainCorr,
366 db_btowL2PhiBin, db_btowL2PatchBin,
371 if(eemcIn==1 && par_useEndcap ) {
372 nEtowTw=projectAdc( eemcData, 720,
373 db_etowThr, db_etowPedS, db_etowGainCorr,
374 db_etowL2PhiBin, db_etowL2PatchBin,
380 int itotEne=scanPhi();
381 float totEneGeV=itotEne/par_energyScale;
382 int itotEneGeV=(int)totEneGeV;
386 for(iJ=0; iJ< mxJ; iJ++) {
390 L2Jet *J=eve_Jet[iJ];
391 J->eneGeV=J->iene/par_energyScale;
392 J->phiRad=0.21*(6.0-J->fphiBin);
395 while(J->phiRad<0) J->phiRad+=6.2832;
396 while(J->phiRad>6.2832) J->phiRad-=6.2832;
399 if(eve_Jet[0]->eneGeV <eve_Jet[1]->eneGeV) {
400 L2Jet *Jx=eve_Jet[0];
401 eve_Jet[0]=eve_Jet[1];
405 if(par_dbg>2) printf(
"doEvent iphiBin1=%d iene1=%d , iphiBin2=%d iene2=%d\n",eve_Jet[0]->iphiBin,eve_Jet[0]->iene,eve_Jet[1]->iphiBin,eve_Jet[1]->iene);
408 bool acceptDiJet=( eve_Jet[0]->eneGeV > par_diJetThrHigh) && ( eve_Jet[1]->eneGeV > par_diJetThrLow);
409 bool acceptOneJet=( eve_Jet[0]->eneGeV> par_oneJetThr) ;
411 bool acceptRnd=rand()< par_rndAccThr;
412 mAccept=acceptDiJet || acceptOneJet || acceptRnd;
417 int iet1 =(int)eve_Jet[0]->eneGeV;
418 int iet2 =(int)eve_Jet[1]->eneGeV;
419 int ieta1=(int)eve_Jet[0]->fetaBin;
420 int ieta2=(int)eve_Jet[1]->fetaBin;
421 int iphi1=(int)eve_Jet[0]->fphiBin;
422 int iphi2=(int)eve_Jet[1]->fphiBin;
424 hA[40]->fill(iet1,iet2);
426 hA[41]->fill(ieta1,iphi1);
427 hA[42]->fill(ieta2,iphi2);
428 hA[43]->fill(iphi1,iphi2);
431 hA[46]->fill(itotEneGeV);
432 hA[47]->fill(nBtowTw);
433 hA[48]->fill(nEtowTw);
436 int kphi1=int(eve_Jet[0]->phiRad*10.);
437 int kphi2=int(eve_Jet[1]->phiRad*10.);
438 int idelZeta=map_DelPhiJets[kphi1*MxPhiRad10 + kphi2];
440 if( mAccept) hA[10]->fill(8);
445 hA[13]->fill(runTimeSec);
447 hA[51]->fill(ieta1,iphi1);
455 hA[14]->fill(runTimeSec);
456 hA[60]->fill(iet1,iet2);
457 hA[61]->fill(ieta1,iphi1);
458 hA[62]->fill(ieta2,iphi2);
459 hA[63]->fill(iphi1,iphi2);
466 hA[70]->fill(idelZeta);
467 hA[71]->fill(ieta1,idelZeta);
468 hA[72]->fill(ieta1,ieta2);
469 hA[73]->fill((iphi1+iphi2)/2,idelZeta);
470 hA[74]->fill(itotEneGeV);
475 hA[15]->fill(runTimeSec);
481 memset(&out,0,
sizeof(out));
483 out.int0.version=L2JET_RESULTS_VERSION;
485 ( par_useBtowEast <<0 ) +
486 ( par_useBtowWest <<1 ) +
487 ( par_useEndcap <<2 ) +
491 ( acceptOneJet <<6 ) +
492 ( acceptDiJet <<7 ) ;
493 out.int0.cutTag=par_cutTag;
495 out.int1.iTotEne=(
unsigned short)(totEneGeV*100.);
496 out.int2.nBtowTw=nBtowTw;
497 out.int2.nEtowTw=nEtowTw;
499 out.jet1.jPhi=(int)(eve_Jet[0]->phiRad*28.65);
500 out.jet1.jEta=(int)(eve_Jet[0]->fetaBin*10.);
501 out.jet1.iEne=(
unsigned short)(eve_Jet[0]->eneGeV*100.);
503 out.jet2.jPhi=(int)(eve_Jet[1]->phiRad*28.65);
504 out.jet2.jEta=(int)(eve_Jet[1]->fetaBin*10.);
505 out.jet2.iEne=(
unsigned short)(eve_Jet[1]->eneGeV*100.);
507 rdtscl_macro(mEveTimeStop);
508 mEveTimeDiff=mEveTimeStop-mEveTimeStart;
509 int kTick=mEveTimeDiff/1000;
513 out.int0.kTick= kTick>255 ? 255 : kTick;
516 out.int1.checkSum=-L2jetResults2006_doCheckSum(&out);
520 unsigned int *outPlace=eve_TrigData->TrgSum.L2Result+mResultOffset;
526 L2jetResults2006_print(&out);
527 printf(
" phiRad1=%f phiRad2=%f \n",eve_Jet[0]->phiRad,eve_Jet[1]->phiRad);
528 printf(
"idelZeta=%d delZeta/deg=%.1f \n\n",idelZeta,idelZeta/31.416*180);
532 if( out.jet1.iEne+out.jet2.iEne > out.int1.iTotEne) {
533 printf(
"L2jet-fatal error, eve=%d, iEtot=%d < iEJ1=%d + iEJ2=%d, continue\n",inpEveId, out.int1.iTotEne,out.jet1.iEne,out.jet2.iEne);
536 printf(
"L2jet-fatal error,neveId=%d, phi1,2=%d,%d\n",mEventsInRun,iphi1,iphi2);
540 if( L2jetResults2006_doCheckSum(&out)) {
541 printf(
"L2jet-fatal error, wrong cSum=%d\n", L2jetResults2006_doCheckSum(&out));
542 L2jetResults2006_print(&out);
556 L2jetAlgo2006::finishRun() {
557 if(run_number<0)
return;
560 sprintf(Fname,
"%s/run%d.l2jet.hist.bin",mOutDir,run_number);
561 printf(
"L2jet::finishRun('%s') , save histo ...\n",Fname);
562 mHistFile = fopen(Fname,
"w");
565 fprintf(mLogFile,
"L2-jet algorithm finishRun(%d)\n",run_number);
566 fprintf(mLogFile,
" - %d events seen by L2 di-jet\n",mEventsInRun);
567 fprintf(mLogFile,
" - accepted: rnd=%d oneJet=%d diJet=%d \n", run_nEventRnd, run_nEventOneJet, run_nEventDiJet);
571 hA[10]->printCSV(mLogFile);
577 printf(
" L2jetAlgo2006: finishRun() UNABLE to open run summary log file, continue anyhow\n");
579 fprintf(mLogFile,
"L2 di-jet histos NOT saved, I/O error\n");
583 for(j=0;j<mxHA;j++) {
584 if(hA[j]==0)
continue;
585 hA[j]->write(mHistFile);
588 finishCommonHistos();
592 fprintf(mLogFile,
"L2 di-jet: %d histos saved to '%s'\n",nh,Fname);
598 if (mLogFile && mLogFile!=stdout) {
609 L2jetAlgo2006::createHisto() {
610 memset(hA,0,
sizeof(hA));
612 hA[10]=
new L2Histo(10, (
char*)
"total event counter; x=cases",9);
613 hA[11]=
new L2Histo(11, (
char*)
"L2 time used per input event; x: time (CPU kTics), range=100muSec; y: events ",160);
615 int mxRunDration=2500;
616 hA[12]=
new L2Histo(12, (
char*)
"rate of input events; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
618 hA[13]=
new L2Histo(13, (
char*)
"rate of accepted one-Jet; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
619 hA[14]=
new L2Histo(14, (
char*)
"rate of accepted di-Jet ; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
620 hA[15]=
new L2Histo(15, (
char*)
"rate of random accepted ; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
623 hA[20]=
new L2Histo(20, (
char*)
"BTOW tower, Et>2.0 GeV (input); x: BTOW RDO index=chan*30+fiber; y: counts", 4800);
624 hA[21]=
new L2Histo(21, (
char*)
"BTOW tower, Et>2.0 GeV (input); x: BTOW softID", 4800);
625 hA[22]=
new L2Histo(22, (
char*)
"BTOW tower, Et>2.0 GeV (input); x: eta bin, [-1,+1]; y: phi bin ~sector",40,120);
628 hA[30]=
new L2Histo(30, (
char*)
"ETOW tower, Et>2.0 GeV (input); x: ETOW RDO index=chan*6+fiber; y: counts", 720 );
629 hA[31]=
new L2Histo(31, (
char*)
"ETOW tower, Et>2.0 GeV (input); x: i=chan+128*crate", 768);
630 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);
633 hA[40]=
new L2Histo(40, (
char*)
"Et Jet1-Jet2 (input); x: Jet1 Et/GeV ; Jet2 Et/GeV",12,12);
634 hA[41]=
new L2Histo(41, (
char*)
"diJet1 eta-phi (input); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
635 hA[42]=
new L2Histo(42, (
char*)
"diJet2 eta-phi (input); x: iEta [-1,+2] ; y: iPhi ~sector",15,30);
637 hA[43]=
new L2Histo(43, (
char*)
"diJet phi1-phi2 (input); x: iPhi1 ~sector ; y: iPhi2 ~sector ",30,30);
639 hA[44]=
new L2Histo(44, (
char*)
"Jet1 Et (input); x: Et (GeV)", 60);
640 hA[45]=
new L2Histo(45, (
char*)
"Jet2 Et (input); x: Et (GeV)", 60);
641 hA[46]=
new L2Histo(46, (
char*)
"total Et (input); x: Et (GeV)", 60);
642 hA[47]=
new L2Histo(47, (
char*)
"# BTOW towers>thrXX (input); x: # of towers/event", 200);
643 hA[48]=
new L2Histo(48, (
char*)
"# ETOW towers>thrXX (input); x: # of towers/event", 100);
646 hA[50]=
new L2Histo(50, (
char*)
"one-Jet Et (accepted); x: jet Et (GeV)", 60);
647 hA[51]=
new L2Histo(51, (
char*)
"one-Jet eta-phi (accepted); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
648 hA[52]=
new L2Histo(52, (
char*)
"one-Jet eta (accepted); x: iEta [-1,+2]", 15);
649 hA[53]=
new L2Histo(53, (
char*)
"one-Jet phi (accepted); x: iPhi ~sector", 30);
652 hA[60]=
new L2Histo(60, (
char*)
"Et of Jet1 vs. Jet2 (accepted); x: Jet1/GeV ; Jet2/GeV",12,12);
653 hA[61]=
new L2Histo(61, (
char*)
"diJet1 eta-phi (accepted); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
654 hA[62]=
new L2Histo(62, (
char*)
"diJet2 eta-phi (accepted); x: iEta [-1,+2] ; y: iPhi ~sector",15,30);
656 hA[63]=
new L2Histo(63, (
char*)
"diJet phi1-phi2 (accepted); x: iPhi1 ~sector ; y: iPhi2 ~sector ",30,30);
658 hA[64]=
new L2Histo(64, (
char*)
"diJet1 Et (accepted); x: Et (GeV)", 60);
659 hA[65]=
new L2Histo(65, (
char*)
"diJet2 Et (accepted); x: Et (GeV)", 60);
661 hA[66]=
new L2Histo(66, (
char*)
"diJet1 eta (accepted); x: i Eta [-1,+2]", 15);
662 hA[67]=
new L2Histo(67, (
char*)
"diJet2 eta (accepted); x: i Eta [-1,+2]", 15);
663 hA[68]=
new L2Histo(68, (
char*)
"diJet1 phi (accepted); x: iPhi ~sector", 30);
664 hA[69]=
new L2Histo(69, (
char*)
"diJet2 phi (accepted); x: iPhi ~sector", 30);
665 hA[70]=
new L2Histo(70, (
char*)
"diJet delZeta (accepted); x: delta zeta (rad*10)", MxPhiRad10);
666 hA[71]=
new L2Histo(71, (
char*)
"diJet delZeta vs. eta1 (accepted); x: iEta1 [-1,+2] ; y: delta zeta (rad*10)",15, MxPhiRad10);
667 hA[72]=
new L2Histo(72, (
char*)
"diJet eta2 vs. eta1 (accepted); x: iEta1 [-1,+2] ;x: iEta2 [-1,+2] ",15,15);
668 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);
669 hA[74]=
new L2Histo(74, (
char*)
"total Et diJet (accepted); x: Et (GeV)", 60);
676 L2jetAlgo2006::clearEvent(){
682 memset(eve_patchEne,0,
sizeof(eve_patchEne));
683 memset(eve_phiEne,0,
sizeof(eve_phiEne));
693 L2jetAlgo2006::projectAdc(
unsigned short *rawAdc,
int nRdo,
694 unsigned short *thr,
unsigned short *pedS,
unsigned short *gainCorr,
695 unsigned short *phiBin,
unsigned short *patchBin,
702 for(rdo=0; rdo<nRdo; rdo++){
703 if(rawAdc[rdo]<thr[rdo])
continue;
705 adc=(rawAdc[rdo]+pedS[rdo]) & par_adcMask ;
706 adc4=adc*gainCorr[rdo];
707 eve_patchEne[patchBin[rdo]]+=adc4;
708 eve_phiEne[phiBin[rdo]]+=adc4;
712 if(adc4 >par_hotTwEtThr) hHot->fill(rdo);
721 L2jetAlgo2006::scanPhi(){
729 int phiEneSum[cl2jetMaxPhiBins];
730 memset(phiEneSum,0,
sizeof(phiEneSum));
733 eve_phiEne[cl2jetMaxPhiBins+0]=eve_phiEne[0];
734 eve_phiEne[cl2jetMaxPhiBins+1]=eve_phiEne[1];
738 int sumMax1=0, iMax1=-1;
741 int *phiEneA=eve_phiEne;
742 for(i=0;i<cl2jetMaxPhiBins;i++,phiEneA++){
744 sum=phiEneA[0]+phiEneA[1]+phiEneA[2];
746 if(sumMax1>sum)
continue;
751 if(par_dbg>2) printf(
"phiScan: sum1=%d, iphi1=%d\n",sumMax1,iMax1);
754 int sumMax2=0, iMax2=-1;
756 int k1=iMax1-par_minPhiBinDiff;
757 int k2=iMax1+par_minPhiBinDiff;
758 if (k1<0) { k1+=cl2jetMaxPhiBins; doWrap+=1; }
759 if (k2>=cl2jetMaxPhiBins) { k2-=cl2jetMaxPhiBins; doWrap+=2; }
762 for(i=0;i<cl2jetMaxPhiBins;i++){
764 if(i>=k1 && i<=k2)
continue;
765 if(sumMax2>phiEneSum[i])
continue;
766 sumMax2=phiEneSum[i];
772 if(sumMax2>phiEneSum[i])
continue;
773 sumMax2=phiEneSum[i];
777 if(par_dbg>2) printf(
"phiScan: sum2=%d, iphi2=%d\n",sumMax2,iMax2);
780 eve_Jet[0]->iphiBin=iMax1;
781 eve_Jet[1]->iphiBin=iMax2;
792 L2jetAlgo2006::scanEta(
int iJ){
793 L2Jet *J=eve_Jet[iJ];
795 int iphi0=J->iphiBin;
803 int eneA[cl2jetMaxEtaBins];
804 memset(eneA,0,
sizeof(eneA));
812 for(iy=0;iy<cl2jet_par_mxPhiBin;iy++) {
813 int jy=(iphi0+iy)%cl2jetMaxPhiBins;
814 int *patchEneA=eve_patchEne+(jy*cl2jetMaxEtaBins);
815 for(ix=0;ix<cl2jetMaxEtaBins;ix++,patchEneA++){
816 eneA[ix]+=*patchEneA;
821 for(ix=0;ix<cl2jetMaxEtaBins-cl2jet_par_mxEtaBin+1;ix++,eneAp++) {
824 sum=eneAp[0]+eneAp[1]+eneAp[2];
826 if(sumMax>sum)
continue;
833 for(ix=iMax;ix<iMax+cl2jet_par_mxEtaBin;ix++){
836 float fetaBin=0.5+1.*sumX/sumMax;
841 printf(
"scanEta iphi0=%d\n eta profile:\n L2eta-bin energy\n",iphi0);
842 for(ix=0;ix<cl2jetMaxEtaBins;ix++){
843 printf(
"%d %d\n",ix,eneA[ix]);
846 printf(
"scanEta: sum=%d, ietaLeft=%d\n",sumMax,iMax);
847 printf(
"sumX=%d fetaBinmax=%.1f \n",sumX,fetaBin);
858 L2jetAlgo2006:: dumpPatchEneA(){
861 for(iy=0;iy<cl2jetMaxPhiBins;iy++) {
862 int *patchEneA=eve_patchEne+(iy*cl2jetMaxEtaBins);
864 for(ix=0;ix<cl2jetMaxEtaBins;ix++,patchEneA++){
865 printf(
" %6d",*patchEneA);
867 printf(
" iPhi=%d\n",iy);
875 L2jetAlgo2006::weightedPhi(
int iJ){
876 L2Jet *J=eve_Jet[iJ];
880 if(J->iene<=1) { J->fphiBin=J->iphiBin+.333;
return;}
882 int iphi0=J->iphiBin;
883 int ieta0=J->ietaBin;
895 for(iy=iphi0;iy<iphi0+cl2jet_par_mxPhiBin;iy++) {
896 int jy=iy % cl2jetMaxPhiBins;
897 int *patchEneA=eve_patchEne+(jy*cl2jetMaxEtaBins);
899 for(ix=0;ix<cl2jetMaxEtaBins;ix++){
900 printf(
" %6d",patchEneA[ix]);
902 printf(
" iy=%d \n",iy);
906 for(ix=ieta0;ix<ieta0+cl2jet_par_mxEtaBin;ix++){
914 float fphiBinMax=0.5 + 1.*sumY/sum;
915 if( fphiBinMax>cl2jetMaxPhiBins) fphiBinMax-=cl2jetMaxPhiBins;
916 if(par_dbg>2) printf(
"weightedPhi() sum=%d sumY=%d fphiBin=%.2f\n",sum,sumY, fphiBinMax);
917 J->fphiBin=fphiBinMax;
923 L2jetAlgo2006::finishRunHisto(){
926 const int *data20=hA[20]->getData();
927 const int *data30=hA[30]->getData();
929 int bHotSum=1,bHotId=-1;
934 for(i=0; i<EmcDbIndexMax; i++) {
936 if(mDb->isEmpty(x))
continue;
937 if (mDb->isBTOW(x) ) {
938 int softId=atoi(x->tube+2);
939 int ieta= (x->eta-1);
940 int iphi= (x->sec-1)*10 + x->sub-
'a' ;
942 hA[21]->fillW(softId,data20[x->rdo]);
943 hA[22]->fillW(ieta, iphi,data20[x->rdo]);
944 if(bHotSum<data20[x->rdo]) {
945 bHotSum=data20[x->rdo];
950 else if (mDb->isETOW(x) ) {
951 int ihard=x->chan+(x->crate-1)*128;
953 int iphi= (x->sec-1)*5 + x->sub-
'A' ;
954 hA[31]->fillW(ihard,data30[x->rdo]);
955 hA[32]->fillW(ieta, iphi,data30[x->rdo]);
956 if(eHotSum<data30[x->rdo]) {
957 eHotSum=data30[x->rdo];
964 fprintf(mLogFile,
"L2jet::finishRun()\n");
965 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);
966 fprintf(mLogFile,
"#ETOW_hot tower _candidate_ (eHotSum=%d) :, name %s , crate %d , chan %d\n",eHotSum,xE->name,xE->crate,xE->chan);