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 "L2etowCalAlgo08.h"
36 mGeom=geoX; assert(mGeom);
43 for(k=0;k<L2eventStream2008::mxToken;k++){
45 etowCalibData.nInputBlock=0;
46 etowCalibData.hitSize=0;
53 L2etowCalAlgo08::initRunUser(
int runNo,
int *rc_ints,
float *rc_floats) {
58 par_gainType = rc_ints[1];
59 par_nSigPed = rc_ints[2];
61 par_twEneThres = rc_floats[0];
62 par_hotEtThres = rc_floats[1];;
66 kBad+=0x00001 * (par_gainType<kGainZero || par_gainType>kGainOffline);
67 kBad+=0x00002 * (par_nSigPed<2 || par_nSigPed>5);
68 kBad+=0x00004 * (par_twEneThres<0.1 || par_twEneThres>1.5);
71 fprintf(mLogFile,
"L2%s algorithm initRun(R=%d), compiled: %s , %s\n params:\n",getName(),mRunNumber,__DATE__,__TIME__);
72 fprintf(mLogFile,
" - use ETOW=%d, gain Ideal=%d or Offline=%d, debug=%d\n",
73 par_gainType>=kGainIdeal, par_gainType==kGainIdeal, par_gainType==kGainOffline, par_dbg);
74 fprintf(mLogFile,
" - thresholds: ADC-ped> %d*sigPed .AND. energy>%.2f GeV \n", par_nSigPed, par_twEneThres);
76 fprintf(mLogFile,
" - hot tower thresholds: ET/GeV=%.2f\n",par_hotEtThres);
77 fprintf(mLogFile,
"initRun() params checked for consistency, Error flag=0x%04x\n",kBad);
84 for (i=0; i<mxHA;i++)
if(hA[i])hA[i]->reset();
88 sprintf(txt,
"ETOW tower, E_T>%.2f GeV (input); x: ETOW RDO index=chan*6+fiber; y: counts",par_hotEtThres);
89 hA[10]->setTitle(txt);
91 sprintf(txt,
"ETOW tower, Et>%.2f GeV (input); x: ETOW softID=i#phi+60*i#eta",par_hotEtThres);
92 hA[11]->setTitle(txt);
93 sprintf(txt,
"ETOW tower, Et>%.2f GeV (input); x: eta bin, [-1,+1]; y: phi bin ~ TPC sector",par_hotEtThres);
94 hA[12] ->setTitle(txt);
96 sprintf(txt,
"#ETOW towers / event , Et>%.2f GeV; x: # ETOW towers; y: counts",par_hotEtThres);
97 hA[14] ->setTitle(txt);
103 int nEneThr=0, nPedThr=0;
104 if(par_gainType>=kGainIdeal)
105 for(i=0; i<EmcDbIndexMax; i++) {
107 if(mDb->isEmpty(x))
continue;
109 if (!mDb->isETOW(x) )
continue;
110 if(x->fail)
continue;
111 if(x->gain<=0)
continue;
114 float adcThres=x->ped+par_nSigPed* fabs(x->sigPed);
115 float otherThr=x->ped+par_twEneThres*x->gain;
117 if(adcThres<otherThr) {
125 if(x->eta<=0 || x->eta>EtowGeom::mxEtaBin)
return -90;
126 int ietaTw= (x->eta-1);
129 assert(par_gainType==kGainIdeal);
130 mGeom->etow.gain2Ene_rdo[x->rdo]=mGeom->etow.idealGain2Ene[ietaTw];
131 mGeom->etow.gain2ET_rdo[x->rdo]=mGeom->getIdealAdc2ET();
133 mGeom->etow.thr_rdo[x->rdo]=(int) (adcThres);
134 mGeom->etow.ped_rdo[x->rdo]=(int) (x->ped);
139 fprintf(mLogFile,
" found towers working=%d calibrated=%d, based on ASCII DB\n",nT,nTg);
140 fprintf(mLogFile,
" thresh defined by energy=%d or NsigPed=%d \n",nEneThr, nPedThr);
151 L2etowCalAlgo08::calibrateEtow(
int token,
int eemcIn,
unsigned short *rawAdc){
155 token&=L2eventStream2008::tokenMask;
160 etowCalibData.nInputBlock++;
161 etowCalibData.hitSize=0;
165 if(eemcIn && par_gainType>kGainZero) {
170 unsigned short *thr=mGeom->etow.thr_rdo;
171 unsigned short *ped=mGeom->etow.ped_rdo;
172 float *gain2ET=mGeom->etow.gain2ET_rdo;
173 float *gain2Ene=mGeom->etow.gain2Ene_rdo;
175 for(rdo=0; rdo<EtowGeom::mxRdo; rdo++){
176 if(rawAdc[rdo]<thr[rdo])
continue;
177 if(nTower>=L2EtowCalibData08::mxListSize)
break;
178 adc=rawAdc[rdo]-ped[rdo];
183 hit->ene=adc/gain2Ene[rdo];
187 if(et >par_hotEtThres) {
192 etowCalibData.hitSize=nTower;
195 hA[13]->fill(nTower);
196 hA[14]->fill(nHotTower);
197 if(nTower>=L2EtowCalibData08::mxListSize) mhN->fill(5);
202 printf(
"L2-%s-compute: set adcL size=%d\n",getName(),nTower);
203 printf(
"dbg=%s: found nTw=%d\n",getName(),nTower);
204 if(par_dbg>0) print0();
205 printCalibratedData(token);
215 L2etowCalAlgo08::computeUser(
int token ){
217 printf(
"computeUser-%s FATAL CRASH\n If you see this message it means l2new is very badly misconfigured \n and L2-etow-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());
225 L2etowCalAlgo08::finishRunUser() {
231 int eHotSum=1,eHotId=-1;
232 const int *data20=hA[10]->getData();
236 for(i=0; i<EmcDbIndexMax; i++) {
238 if(mDb->isEmpty(x))
continue;
239 if (!mDb->isETOW(x) )
continue;
240 int ieta= (x->eta-1);
241 int iphi= (x->sec-1)*EtowGeom::mxSubs + x->sub-
'A' ;
242 int softId= iphi+EtowGeom::mxPhiBin*ieta;
243 hA[11]->fillW(softId,data20[x->rdo]);
244 hA[12]->fillW(ieta, iphi,data20[x->rdo]);
245 if(eHotSum<data20[x->rdo]) {
246 eHotSum=data20[x->rdo];
252 int par_nHotThresh=20;
253 if (mLogFile && eHotSum>par_nHotThresh){
254 fprintf(mLogFile,
"#ETOW_hot tower _candidate_ (eHotSum=%d of %d eve) :, softID %d , crate %d , chan %d , name %s\n",eHotSum,mEventsInRun,eHotId,xE->crate,xE->chan,xE->name);
258 int tkn1=99999, tkn2=0;
260 int tkn3=-1, nTkn3=-1;
263 for(k=0;k<L2eventStream2008::mxToken;k++){
265 if(etowCalibData.nInputBlock==0)
continue;
266 hA[1]->fillW(k,etowCalibData.nInputBlock);
267 if(nTkn3<etowCalibData.nInputBlock){
268 nTkn3=etowCalibData.nInputBlock;
277 fprintf(mLogFile,
"#ETOW_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);
286 L2etowCalAlgo08::createHisto() {
287 memset(hA,0,
sizeof(hA));
289 hA[1]=
new L2Histo(1,
"L2-etow-calib: seen tokens; x: token value; y: events ",L2eventStream2008::mxToken);
292 hA[10]=
new L2Histo(10,
"etow hot tower 1", EtowGeom::mxRdo);
293 hA[11]=
new L2Histo(11,
"etow hot tower 2", EtowGeom::mxRdo);
294 hA[12]=
new L2Histo(12,
"etow hot tower 3", EtowGeom::mxEtaBin,EtowGeom::mxPhiBin);
295 hA[13]=
new L2Histo(13,
"ETOW #tower w/ energy /event; x: # ETOW towers; y: counts", 30);
296 hA[14]=
new L2Histo(14,
"# hot towers/event", 30);
305 L2etowCalAlgo08::print0(){