15 #ifdef IS_REAL_L2 //in l2-ana environment
16 #include "../L2algoUtil/L2EmcDb.h"
17 #include "../L2algoUtil/L2EmcGeom.h"
18 #include "../L2algoUtil/L2Histo.h"
20 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcDb.h"
21 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2Histo.h"
24 #include "L2pedAlgo09.h"
25 #include "L2pedResults2009.h"
29 L2pedAlgo09::L2pedAlgo09(
const char* name,
L2EmcDb* db,
char* outDir,
int resOff)
42 for(i=0;i<BtowGeom::mxRdo;i++) {
43 sprintf(tit,
"BTOW ADC for rdo=%d; ADC+%d",i,-minAdc);
44 btowAdc[i]=
new L2Histo(20000+i,tit,maxAdc-minAdc+1);
47 for(i=0;i<EtowGeom::mxRdo;i++) {
48 sprintf(tit,
"ETOW ADC for rdo=%d; ADC ",i);
49 etowAdc[i]=
new L2Histo(10000+i,tit,maxAdc-minAdc+1);
57 hA[10]=
new L2Histo(10,
"total event counter; x=cases",6);
58 hA[11]=
new L2Histo(11,
"L2 time used per input event; x: time (CPU 20*kTics); y: events ",500);
61 hA[20]=
new L2Histo(20,
"BTOW pedRes Y=ADC-DBped ; x: chan + 160*crate", 4800);
62 hA[21]=
new L2Histo(21,
"BTOW pedRes Z=ADC-DBped, saturated @ |3|; x: etaBin ,[-1,+1]; y: phi bin ~sector",40,120);
63 sprintf(tit,
"BTOW pedRes ; x: chan + 160*crate ;y: ADC+%d",-minAdc);
65 hA[22]=
new L2Histo(22,tit,4800,par_maxMatt);
68 hA[30]=
new L2Histo(30,
"ETOW pedRes Y=ADC-DBped ; x: chan + 128*crate", 768);
69 hA[31]=
new L2Histo(31,
"ETOW pedRes Z=ADC-DBped, saturated @ |3|; x: 12 - Endcap etaBin ,[+1,+2]; y: phi bin ~sector",12,60);
70 sprintf(tit,
"ETOW pedRes ; x: chan + 128*crate ;y: ADC+%d",-minAdc);
72 hA[33]=
new L2Histo(33,tit,768,par_maxMatt);
78 criticalError(
"L2pedAlgo09 has failed consistency check. sizeof(L2pedAlgo09)!= L2pedResults2009::mySizeChar");
86 L2pedAlgo09::initRunUser(
int runNo,
int *rc_ints,
float *rc_floats) {
93 if(mDb->getRun()!=runNo)
return -700;
96 par_pedSubtr =rc_ints[0]!=0;
97 par_speedFact =rc_ints[1];
98 par_saveBinary=rc_ints[2]!=0;
100 par_prescAccept=rc_ints[4];
102 if(par_prescAccept<0) par_prescAccept=0;
104 if(par_speedFact<1) par_speedFact=1;
105 if(par_speedFact>2) {
106 if(par_speedFact<4) par_speedFact=2;
107 else if(par_speedFact<8) par_speedFact=4;
108 else if(par_speedFact<16) par_speedFact=8;
109 else if(par_speedFact<32) par_speedFact=16;
110 else if(par_speedFact<64) par_speedFact=32;
111 else if(par_speedFact<192) par_speedFact=64;
112 else par_speedFact=192;
117 s_stepB=BtowGeom::mxRdo/ par_speedFact ;
118 s_stepE=EtowGeom::mxRdo/ par_speedFact ;
122 memset(db_btowPed, 0,
sizeof(db_btowPed));
123 memset(db_etowPed, 0,
sizeof(db_etowPed));
127 int nBtowOk=0, nEtowOk=0;
128 for(i=0; i<EmcDbIndexMax; i++) {
130 if(mDb->isEmpty(x))
continue;
131 if (mDb->isBTOW(x) ) {
132 db_btowPed[x->rdo]=(int) (x->ped);
134 }
else if (mDb->isETOW(x) ) {
135 db_etowPed[x->rdo]=(int) (x->ped);
142 for(i=0;i<BtowGeom::mxRdo;i++) btowAdc[i]->reset();
143 for(i=0;i<EtowGeom::mxRdo;i++) etowAdc[i]->reset();
144 for(i=0;i<mxHA;i++)
if(hA[i]) hA[i]->reset();
155 L2pedAlgo09::doPedestals(
int inpEveId,
int* L2Result,
156 int bemcIn,
unsigned short *bemcData,
157 int eemcIn,
unsigned short *eemcData){
160 unsigned long mEveTimeStart;
161 rdtscl_macro(mEveTimeStart);
165 if(par_prescAccept>0) {
166 if((rand()>>4) % par_prescAccept )
return false;
181 short first=s_lastB%BtowGeom::mxRdo;
182 s_lastB=first+s_stepB;
183 if(first==0) hA[10]->fill(1);
186 for(rdo=first; rdo<s_lastB; rdo++){
187 int adc=bemcData[rdo];
188 if(par_pedSubtr) adc-=db_btowPed[rdo];
189 btowAdc[rdo]->fill(adc-minAdc);
196 short first=s_lastE%EtowGeom::mxRdo;
197 s_lastE=first+s_stepE;
198 if(first==0) hA[10]->fill(2);
201 for(rdo=first; rdo<s_lastE; rdo++){
202 int adc=eemcData[rdo];
203 if(par_pedSubtr) adc-=db_etowPed[rdo];
204 etowAdc[rdo]->fill(adc-minAdc);
211 memset(&out,0,
sizeof(out));
216 ( par_pedSubtr <<6 ) ;
218 unsigned long mEveTimeStop;
219 rdtscl_macro(mEveTimeStop);
220 unsigned long mEveTimeDiff=mEveTimeStop-mEveTimeStart;
221 int kTick=mEveTimeDiff/1000;
222 hA[11]->fill(kTick/20);
225 const unsigned short maxKT=30000;
226 out.int0.kTick= kTick>maxKT ? maxKT : (int)kTick;
228 int *outPlace=L2Result+ mResultOffset;
231 if(par_dbg) L2pedResults2009_print(&out);
242 L2pedAlgo09::computeUser(
int token ){
244 printf(
"computeUser-%s FATAL CRASH\n If you see this message it means l2new is very badly misconfigured \n and L2-emc-ped algo was not executed properly\n before calling other individual L2-algos. \n\n l2new will aborted now - fix the code, Ross C (In the words of Jan B).\n",getName());
245 criticalError(
"L2pedAlgo09::computeUser has been called and should not have been. Serious problem in L2");
252 L2pedAlgo09::finishRunUser() {
253 if(run_number<=0)
return;
255 int nBtowLow=0, nBtowHigh=0 ,nEtowLow=0, nEtowHigh=0 ;
257 printf(
"L2ped_finish() , finding pedestals...\n");
260 if(mLogFile==0) {printf(
"no open output log file,skip ped_finish()\n");
return;}
261 fprintf(mLogFile,
"#L2-ped algorithm finishRun(%d), compiled: %s , %s\n",run_number,__DATE__,__TIME__);
262 fprintf(mLogFile,
"#params: pedSubtr=%d speedFact=%d saveBin=%d debug=%d prescAccept=%d\n",par_pedSubtr,par_speedFact,par_saveBinary,par_dbg,par_prescAccept);
263 hA[10]->printCSV(mLogFile);
264 int iMax=-3, iFWHM=-4;
265 hA[11]->findMax( &iMax, &iFWHM);
266 fprintf(mLogFile,
"#L2ped CPU/eve MPV %d kTicks, FWHM=%d, seen eve=%d\n",iMax, iFWHM,nInp);
268 if(par_saveBinary) fprintf(mLogFile,
"#L2ped will save full spectra for all towers\n");
271 int maxPedDeviation=5;
272 int iadcHigh=maxAdc - maxPedDeviation;
273 int iadcLow =minAdc + maxPedDeviation;
276 sprintf(xAxis,
"raw ADC + %d",-minAdc);
277 if(par_pedSubtr) sprintf(xAxis,
"ADC - ped + %d",-minAdc);
280 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);
284 for(i=0; i<EmcDbIndexMax; i++) {
286 if(mDb->isEmpty(x))
continue;
287 if (mDb->isBTOW(x) ||mDb->isETOW(x) ) {
291 int iMax=-3, iFWHM=-4;
294 if(mDb->isBTOW(x)) h= btowAdc[x->rdo];
295 else if(mDb->isETOW(x)) h= etowAdc[x->rdo];
301 if(h->findMax( &iMax, &iFWHM)) {
303 if(iMax<iadcLow) pedQA=
'-';
304 else if(iMax>iadcHigh) pedQA=
'+';
306 if(!par_pedSubtr) pedRes=int(pedRes - x->ped);
310 if(pedQA==
'-' ) nBtowLow++;
311 else if(pedQA==
'+') nBtowHigh++;
313 int ieta= (x->eta-1);
314 int iphi= (x->sec-1)*10 + x->sub-
'a' ;
315 int ihard=x->chan+(x->crate-1)*160;
316 if(x->fail) pedRes =0;
317 hA[20]->fillW(ihard,pedRes);
321 if(pedRes<-maxRes) pedRes=-maxRes;
322 if(pedRes>maxRes) pedRes=maxRes;
324 hA[21]->fillW(ieta, iphi,pedRes);
327 const int *Data=h->getData();
328 for(
int k=0;k<par_maxMatt;k++)
329 hA[22]->fillW(ihard,k,Data[k]);
332 if(pedQA==
'-' ) nEtowLow++;
333 else if(pedQA==
'+') nEtowHigh++;
336 int iphi= (x->sec-1)*5 + x->sub-
'A' ;
337 int ihard=x->chan+(x->crate-1)*128;
338 if(x->fail) pedRes =0;
339 hA[30]->fillW(ihard,pedRes);
343 if(pedRes<-maxRes) pedRes=-maxRes;
344 if(pedRes>maxRes) pedRes=maxRes;
346 hA[31]->fillW(ieta, iphi,pedRes);
349 const int *Data=h->getData();
350 for(
int k=0;k<par_maxMatt;k++)
351 hA[33]->fillW(ihard,k,Data[k]);
357 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);
358 h->printPed(mLogFile,minAdc,par_topAdc,
' ');
359 fprintf(mLogFile,
"qa=%c\n",pedQA);
365 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);
366 fprintf(mLogFile,
"# found peds for nB+E=%d , seen events=%d\n",nB,nInp);
374 printf(
"Can't open .hist.bin file,skip ped_finish()\n");
380 printf(
"l2ped_finish() , save FULL spectra binary...\n");
383 for(i=0; i<EmcDbIndexMax; i++) {
385 if(mDb->isEmpty(x))
continue;
391 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);
393 }
else if(mDb->isETOW(x) ) {
396 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);
403 printf(
"l2ped_finish() binary full spectra saved\n");