4 #include <fakeRtsLog.h>
16 #ifdef IS_REAL_L2 //in l2-ana environment
17 #include "../L2algoUtil/L2EmcDb2012.h"
18 #include "../L2algoUtil/L2EmcGeom2012.h"
19 #include "../L2algoUtil/L2Histo.h"
21 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcDb2012.h"
22 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2Histo.h"
25 #include "L2pedAlgo12.h"
26 #include "L2pedResults2012.h"
30 L2pedAlgo12::L2pedAlgo12(
const char* name,
const char *uid,
L2EmcDb2012* db,
char* outDir,
int resOff)
43 for(i=0;i<BtowGeom::mxRdo;i++) {
44 sprintf(tit,
"BTOW ADC for rdo=%d; ADC+%d",i,-minAdc);
45 btowAdc[i]=
new L2Histo(20000+i,tit,maxAdc-minAdc+1);
48 for(i=0;i<EtowGeom::mxRdo;i++) {
49 sprintf(tit,
"ETOW ADC for rdo=%d; ADC ",i);
50 etowAdc[i]=
new L2Histo(10000+i,tit,maxAdc-minAdc+1);
58 hA[10]=
new L2Histo(10,
"total event counter; x=cases",6);
59 hA[11]=
new L2Histo(11,
"L2 time used per input event; x: time (CPU 20*kTics); y: events ",500);
62 hA[20]=
new L2Histo(20,
"BTOW pedRes Y=ADC-DBped ; x: chan + 160*crate", 4800);
63 hA[21]=
new L2Histo(21,
"BTOW pedRes Z=ADC-DBped, saturated @ |3|; x: etaBin ,[-1,+1]; y: phi bin ~sector",40,120);
64 sprintf(tit,
"BTOW pedRes ; x: chan + 160*crate ;y: ADC+%d",-minAdc);
66 hA[22]=
new L2Histo(22,tit,4800,par_maxMatt);
69 hA[30]=
new L2Histo(30,
"ETOW pedRes Y=ADC-DBped ; x: chan + 128*crate", 768);
70 hA[31]=
new L2Histo(31,
"ETOW pedRes Z=ADC-DBped, saturated @ |3|; x: 12 - Endcap etaBin ,[+1,+2]; y: phi bin ~sector",12,60);
71 sprintf(tit,
"ETOW pedRes ; x: chan + 128*crate ;y: ADC+%d",-minAdc);
73 hA[33]=
new L2Histo(33,tit,768,par_maxMatt);
78 criticalError(
"L2pedAlgo12 has failed consistency check. sizeof(L2pedAlgo12)!= L2pedResults2012::mySizeChar");
84 L2pedAlgo12::initRunUser(
int runNo,
int *rc_ints,
float *rc_floats) {
90 if(mDb->getRun()!=runNo)
return -700;
93 par_pedSubtr =rc_ints[0]!=0;
94 par_speedFact =rc_ints[1];
95 par_saveBinary=rc_ints[2]!=0;
97 par_prescAccept=rc_ints[4];
99 if(par_prescAccept<0) par_prescAccept=0;
101 if(par_speedFact<1) par_speedFact=1;
102 if(par_speedFact>2) {
103 if(par_speedFact<4) par_speedFact=2;
104 else if(par_speedFact<8) par_speedFact=4;
105 else if(par_speedFact<16) par_speedFact=8;
106 else if(par_speedFact<32) par_speedFact=16;
107 else if(par_speedFact<64) par_speedFact=32;
108 else if(par_speedFact<192) par_speedFact=64;
109 else par_speedFact=192;
114 s_stepB=BtowGeom::mxRdo/ par_speedFact ;
115 s_stepE=EtowGeom::mxRdo/ par_speedFact ;
119 memset(db_btowPed, 0,
sizeof(db_btowPed));
120 memset(db_etowPed, 0,
sizeof(db_etowPed));
124 int nBtowOk=0, nEtowOk=0;
125 for(i=0; i<EmcDbIndexMax; i++) {
127 if(mDb->isEmpty(x))
continue;
128 if (mDb->isBTOW(x) ) {
129 db_btowPed[x->rdo]=(int) (x->ped);
131 }
else if (mDb->isETOW(x) ) {
132 db_etowPed[x->rdo]=(int) (x->ped);
137 for(i=0;i<BtowGeom::mxRdo;i++) btowAdc[i]->reset();
138 for(i=0;i<EtowGeom::mxRdo;i++) etowAdc[i]->reset();
139 for(i=0;i<mxHA;i++)
if(hA[i]) hA[i]->reset();
150 L2pedAlgo12::doPedestals(
int inpEveId,
int* L2Result,
151 int bemcIn,
unsigned short *bemcData,
152 int eemcIn,
unsigned short *eemcData){
154 unsigned long mEveTimeStart;
155 rdtscl_macro(mEveTimeStart);
159 if(par_prescAccept>0) {
160 if((rand()>>4) % par_prescAccept )
return false;
175 short first=s_lastB%BtowGeom::mxRdo;
176 s_lastB=first+s_stepB;
177 if(first==0) hA[10]->fill(1);
179 for(rdo=first; rdo<s_lastB; rdo++){
180 int adc=bemcData[rdo];
181 if(par_pedSubtr) adc-=db_btowPed[rdo];
182 btowAdc[rdo]->fill(adc-minAdc);
188 short first=s_lastE%EtowGeom::mxRdo;
189 s_lastE=first+s_stepE;
190 if(first==0) hA[10]->fill(2);
192 for(rdo=first; rdo<s_lastE; rdo++){
193 int adc=eemcData[rdo];
194 if(par_pedSubtr) adc-=db_etowPed[rdo];
195 etowAdc[rdo]->fill(adc-minAdc);
201 memset(&out,0,
sizeof(out));
206 ( par_pedSubtr <<6 ) ;
208 unsigned long mEveTimeStop;
209 rdtscl_macro(mEveTimeStop);
210 unsigned long mEveTimeDiff=mEveTimeStop-mEveTimeStart;
211 int kTick=mEveTimeDiff/1000;
212 hA[11]->fill(kTick/20);
214 const unsigned short maxKT=30000;
215 out.int0.kTick= kTick>maxKT ? maxKT : (int)kTick;
217 int *outPlace=L2Result+ mResultOffset;
220 if(par_dbg) L2pedResults2012_print(&out);
231 L2pedAlgo12::computeUser(
int token ){
233 criticalError(
"L2pedAlgo12::computeUser has been called and should not have been. Serious problem in L2");
240 L2pedAlgo12::finishRunUser() {
241 if(run_number<=0)
return;
243 int nBtowLow=0, nBtowHigh=0 ,nEtowLow=0, nEtowHigh=0 ;
245 if(mLogFile==0) { LOG(ERR,
"no open output log file,skip ped_finish()\n");
return;}
246 fprintf(mLogFile,
"#L2-ped algorithm finishRun(%d), compiled: %s , %s\n",run_number,__DATE__,__TIME__);
247 fprintf(mLogFile,
"#params: pedSubtr=%d speedFact=%d saveBin=%d debug=%d prescAccept=%d\n",par_pedSubtr,par_speedFact,par_saveBinary,par_dbg,par_prescAccept);
248 hA[10]->printCSV(mLogFile);
249 int iMax=-3, iFWHM=-4;
250 hA[11]->findMax( &iMax, &iFWHM);
251 fprintf(mLogFile,
"#L2ped CPU/eve MPV %d kTicks, FWHM=%d, seen eve=%d\n",iMax, iFWHM,nInp);
252 if(par_saveBinary) fprintf(mLogFile,
"#L2ped will save full spectra for all towers\n");
255 int maxPedDeviation=5;
256 int iadcHigh=maxAdc - maxPedDeviation;
257 int iadcLow =minAdc + maxPedDeviation;
260 sprintf(xAxis,
"raw ADC + %d",-minAdc);
261 if(par_pedSubtr) sprintf(xAxis,
"ADC - ped + %d",-minAdc);
264 fprintf(mLogFile,
"# L2ped-Adc spectra, run=%d, Z-scale is ln(yield), only first digit shown; maxPedDev=%d table format:\n# name, ped, sigPed, crate, chan, softID-m-s-e, RDO_ID;\n# ADC spectrum: [%d ... <=-10 ... *=0 ... >=+10 ... :=+20 ... %d], Xaxis=%s\n",run_number,maxPedDeviation,minAdc,par_topAdc,xAxis);
268 for(i=0; i<EmcDbIndexMax; i++) {
270 if(mDb->isEmpty(x))
continue;
271 if (mDb->isBTOW(x) ||mDb->isETOW(x) ) {
274 int iMax=-3, iFWHM=-4;
277 if(mDb->isBTOW(x)) h= btowAdc[x->rdo];
278 else if(mDb->isETOW(x)) h= etowAdc[x->rdo];
284 if(h->findMax( &iMax, &iFWHM)) {
286 if(iMax<iadcLow) pedQA=
'-';
287 else if(iMax>iadcHigh) pedQA=
'+';
289 if(!par_pedSubtr) pedRes=int(pedRes - x->ped);
293 if(pedQA==
'-' ) nBtowLow++;
294 else if(pedQA==
'+') nBtowHigh++;
296 int ieta= (x->eta-1);
297 int iphi= (x->sec-1)*10 + x->sub-
'a' ;
298 int ihard=x->chan+(x->crate-1)*160;
299 if(x->fail) pedRes =0;
300 hA[20]->fillW(ihard,pedRes);
304 if(pedRes<-maxRes) pedRes=-maxRes;
305 if(pedRes>maxRes) pedRes=maxRes;
307 hA[21]->fillW(ieta, iphi,pedRes);
310 const int *Data=h->getData();
311 for(
int k=0;k<par_maxMatt;k++)
312 hA[22]->fillW(ihard,k,Data[k]);
315 if(pedQA==
'-' ) nEtowLow++;
316 else if(pedQA==
'+') nEtowHigh++;
319 int iphi= (x->sec-1)*5 + x->sub-
'A' ;
320 int ihard=x->chan+(x->crate-1)*128;
321 if(x->fail) pedRes =0;
322 hA[30]->fillW(ihard,pedRes);
326 if(pedRes<-maxRes) pedRes=-maxRes;
327 if(pedRes>maxRes) pedRes=maxRes;
329 hA[31]->fillW(ieta, iphi,pedRes);
332 const int *Data=h->getData();
333 for(
int k=0;k<par_maxMatt;k++)
334 hA[33]->fillW(ihard,k,Data[k]);
340 fprintf(mLogFile,
"%c%s %3d %4.1f 0x%02x 0x%02x %15s %4d ",okC,x->name,iMax+minAdc,iFWHM/2.3,x->crate, x->chan,x->tube, x->rdo);
341 h->printPed(mLogFile,minAdc,par_topAdc,
' ');
342 fprintf(mLogFile,
"qa=%c\n",pedQA);
348 fprintf(mLogFile,
"#L2ped_finishRun() # of towers with |ped-pedDB| >10 chan\n# BTOW: nLow=%d nHigh=%d ; ETOW nLow=%d, nHigh=%d\n",nBtowLow, nBtowHigh,nEtowLow, nEtowHigh);
349 fprintf(mLogFile,
"# found peds for nB+E=%d , seen events=%d\n",nB,nInp);
354 LOG(ERR,
"Can't open .hist.bin file,skip ped_finish()\n");
360 LOG(DBG,
"l2ped_finish() , save FULL spectra binary...\n");
363 for(i=0; i<EmcDbIndexMax; i++) {
365 if(mDb->isEmpty(x))
continue;
371 sprintf(tit,
"BTOW=%s cr/ch=%03d/%03d stat/0x=%04x+%04x soft=%s; %s",x->name, x->crate, x->chan, x->stat, x->fail,x->tube,xAxis);
372 }
else if(mDb->isETOW(x) ) {
375 sprintf(tit,
"ETOW=%s cr/ch=%03d/%03d stat/0x=%04x+%04x pname=%s; %s",x->name, x->crate, x->chan, x->stat, x->fail,x->tube,xAxis);