17 #ifdef IS_REAL_L2 //in l2-ana environment
18 #include "../L2algoUtil/L2EmcDb.h"
19 #include "../L2algoUtil/L2Histo.h"
23 #include "L2EmcGeom.h"
26 #include "L2btowCalAlgo08.h"
41 geom=geoX; assert(geom);
48 for(k=0;k<L2eventStream2008::mxToken;k++){
50 btowCalibData.nInputBlock=0;
57 L2btowCalAlgo08::initRunUser(
int runNo,
int *rc_ints,
float *rc_floats) {
62 par_gainType = rc_ints[1];
63 par_nSigPed = rc_ints[2];
65 par_twEneThres = rc_floats[0];
66 par_hotEtThres = rc_floats[1];;
70 kBad+=0x00001 * (par_gainType<kGainZero || par_gainType>kGainOffline);
71 kBad+=0x00002 * (par_nSigPed<2 || par_nSigPed>5);
72 kBad+=0x00004 * (par_twEneThres<0.1 || par_twEneThres>1.5);
75 fprintf(mLogFile,
"L2%s algorithm initRun(R=%d), compiled: %s , %s\n params:\n",getName(),mRunNumber,__DATE__,__TIME__);
76 fprintf(mLogFile,
" - use BTOW=%d, gain Ideal=%d or Offline=%d, debug=%d\n",
77 par_gainType>=kGainIdeal, par_gainType==kGainIdeal, par_gainType==kGainOffline, par_dbg);
78 fprintf(mLogFile,
" - thresholds: ADC-ped> %d*sigPed .AND. energy>%.2f GeV \n", par_nSigPed, par_twEneThres);
80 fprintf(mLogFile,
" - hot tower thresholds: ET/GeV=%.2f\n",par_hotEtThres);
81 fprintf(mLogFile,
"initRun() params checked for consistency, Error flag=0x%04x\n",kBad);
88 for (i=0; i<mxHA;i++)
if(hA[i])hA[i]->reset();
92 sprintf(txt,
"BTOW tower, E_T>%.2f GeV (input); x: BTOW RDO index=chan*30+fiber; y: counts",par_hotEtThres);
93 hA[10]->setTitle(txt);
95 sprintf(txt,
"BTOW tower, Et>%.2f GeV (input); x: BTOW softID",par_hotEtThres);
96 hA[11]->setTitle(txt);
97 sprintf(txt,
"BTOW tower, Et>%.2f GeV (input); x: eta bin, [-1,+1]; y: phi bin ~ TPC sector",par_hotEtThres);
98 hA[12] ->setTitle(txt);
100 sprintf(txt,
"#BTOW towers / event , Et>%.2f GeV; x: # BTOW towers; y: counts",par_hotEtThres);
101 hA[14] ->setTitle(txt);
107 int nEneThr=0, nPedThr=0;
108 if(par_gainType>=kGainIdeal)
109 for(i=0; i<EmcDbIndexMax; i++) {
111 if(mDb->isEmpty(x))
continue;
113 if (!mDb->isBTOW(x) )
continue;
114 if(x->fail)
continue;
115 if(x->gain<=0)
continue;
118 float adcThres=x->ped+par_nSigPed* fabs(x->sigPed);
119 float otherThr=x->ped+par_twEneThres*x->gain;
122 if(adcThres<otherThr) {
130 if(x->eta<=0 || x->eta>BtowGeom::mxEtaBin)
return -90;
131 int ietaTw= (x->eta-1);
134 assert(par_gainType==kGainIdeal);
135 geom->btow.gain2Ene_rdo[x->rdo]=geom->btow.idealGain2Ene[ietaTw];
136 geom->btow.gain2ET_rdo[x->rdo]=geom->getIdealAdc2ET();
138 geom->btow.thr_rdo[x->rdo]=(int) (adcThres);
139 geom->btow.ped_rdo[x->rdo]=(int) (x->ped);
144 fprintf(mLogFile,
" found towers working=%d calibrated=%d, based on ASCII DB\n",nB,nBg);
145 fprintf(mLogFile,
" thresh defined by energy=%d or NsigPed=%d \n",nEneThr, nPedThr);
156 L2btowCalAlgo08::calibrateBtow(
int token,
int bemcIn,
unsigned short *rawAdc){
160 token&=L2eventStream2008::tokenMask;
164 btowCalibData.nInputBlock++;
167 btowCalibData.hitSize=0;
171 if(bemcIn && par_gainType>kGainZero) {
176 unsigned short *thr=geom->btow.thr_rdo;
177 unsigned short *ped=geom->btow.ped_rdo;
178 float *gain2ET=geom->btow.gain2ET_rdo;
179 float *gain2Ene=geom->btow.gain2Ene_rdo;
181 for(rdo=0; rdo<BtowGeom::mxRdo; rdo++){
182 if(rawAdc[rdo]<thr[rdo])
continue;
183 if(nTower>=L2BtowCalibData08::mxListSize)
break;
184 adc=rawAdc[rdo]-ped[rdo];
189 hit->ene=adc/gain2Ene[rdo];
193 if(et >par_hotEtThres) {
198 btowCalibData.hitSize=nTower;
201 hA[13]->fill(nTower);
202 hA[14]->fill(nHotTower);
203 if(nTower>=L2BtowCalibData08::mxListSize) mhN->fill(5);
209 printf(
"L2-%s-compute: set adcL size=%d, get=%d\n",getName(),nTower,999);
210 printf(
"dbg=%s: found nTw=%d\n",getName(),nTower);
211 if(par_dbg>0) print0();
212 printCalibratedData(token);
222 L2btowCalAlgo08::computeUser(
int token ){
224 printf(
"computeUser-%s FATAL CRASH\n If you see this message it means l2new is very badly misconfigured \n and L2-btow-calib algo was not executed properly\n before calling other individual L2-algos. \n\n l2new will aborted now - fix the code, Jan B.\n",getName());
232 L2btowCalAlgo08::finishRunUser() {
236 int bHotSum=1,bHotId=-1;
237 const int *data20=hA[10]->getData();
241 for(i=0; i<EmcDbIndexMax; i++) {
243 if(mDb->isEmpty(x))
continue;
244 if (!mDb->isBTOW(x) )
continue;
245 int softId=atoi(x->tube+2);
246 int ieta= (x->eta-1);
247 int iphi= (x->sec-1)*BtowGeom::mxSubs + x->sub-
'a' ;
248 hA[11]->fillW(softId,data20[x->rdo]);
249 hA[12]->fillW(ieta, iphi,data20[x->rdo]);
250 if(bHotSum<data20[x->rdo]) {
251 bHotSum=data20[x->rdo];
258 fprintf(mLogFile,
"#BTOW_hot tower _candidate_ (bHotSum=%d of %d eve) :, softID %d , crate %d , chan %d , name %s\n",bHotSum,mEventsInRun,bHotId,xB->crate,xB->chan,xB->name);
262 int tkn1=99999, tkn2=0;
264 int tkn3=-1, nTkn3=-1;
267 for(k=0;k<L2eventStream2008::mxToken;k++){
269 if(btowCalibData.nInputBlock==0)
continue;
270 hA[1]->fillW(k,btowCalibData.nInputBlock);
271 if(nTkn3<btowCalibData.nInputBlock){
272 nTkn3=btowCalibData.nInputBlock;
281 fprintf(mLogFile,
"#BTOW_token_QA: _candidate_ hot token=%d used %d for %d events, token range [%d, %d], used %d tokens\n",tkn3,nTkn3,mEventsInRun,tkn1,tkn2,nTkn);
290 L2btowCalAlgo08::createHisto() {
291 memset(hA,0,
sizeof(hA));
293 hA[1]=
new L2Histo(1,
"L2-btow-calib: seen tokens; x: token value; y: events ",L2eventStream2008::mxToken);
296 hA[10]=
new L2Histo(10,
"btow hot tower 1", BtowGeom::mxRdo);
297 hA[11]=
new L2Histo(11,
"btow hot tower 2", BtowGeom::mxRdo);
298 hA[12]=
new L2Histo(12,
"btow hot tower 3", BtowGeom::mxEtaBin,BtowGeom::mxPhiBin);
299 hA[13]=
new L2Histo(13,
"BTOW #tower w/ energy /event; x: # BTOW towers; y: counts", 100);
300 hA[14]=
new L2Histo(14,
"# hot towers/event", 100);
309 L2btowCalAlgo08::print0(){