16 #ifdef IS_REAL_L2 //in l2-ana environment
17 #include "../L2algoUtil/L2EmcDb.h"
18 #include "../L2algoUtil/L2Histo.h"
22 #include "L2EmcGeom.h"
25 #include "L2etowCalAlgo09.h"
30 L2etowCalAlgo09::L2etowCalAlgo09(
const char* name,
L2EmcDb* db,
L2EmcGeom *geoX,
char* outDir,
int resOff) :
L2VirtualAlgo2009( name, db, outDir, false, true, resOff) {
37 criticalError(
"L2etowCalAlgo is broken -- can't find geom.");
44 for(k=0;k<L2eventStream2009::mxToken;k++){
46 etowCalibData.nInputBlock=0;
47 etowCalibData.hitSize=0;
54 L2etowCalAlgo09::initRunUser(
int runNo,
int *rc_ints,
float *rc_floats) {
56 par_adcMask=(
unsigned short)(-0x10);
61 par_gainType = rc_ints[1];
62 par_nSigPed = rc_ints[2];
64 par_twEneThres = rc_floats[0];
65 par_hotEtThres = rc_floats[1];;
69 kBad+=0x00001 * (par_gainType<kGainZero || par_gainType>kGainOffline);
70 kBad+=0x00002 * (par_nSigPed<2 || par_nSigPed>5);
71 kBad+=0x00004 * (par_twEneThres<0.1 || par_twEneThres>1.5);
74 fprintf(mLogFile,
"L2%s algorithm initRun(R=%d), compiled: %s , %s\n params:\n",getName(),mRunNumber,__DATE__,__TIME__);
75 fprintf(mLogFile,
" - use ETOW=%d, gain Ideal=%d or Offline=%d, debug=%d\n",
76 par_gainType>=kGainIdeal, par_gainType==kGainIdeal, par_gainType==kGainOffline, par_dbg);
77 fprintf(mLogFile,
" - thresholds: ADC-ped> %d*sigPed .AND. energy>%.2f GeV \n", par_nSigPed, par_twEneThres);
79 fprintf(mLogFile,
" - hot tower thresholds: ET/GeV=%.2f\n",par_hotEtThres);
80 fprintf(mLogFile,
"initRun() params checked for consistency, Error flag=0x%04x\n",kBad);
85 for(k=0;k<L2eventStream2009::mxToken;k++){
87 etowCalibData.nInputBlock=0;
88 etowCalibData.hitSize=0;
95 for (i=0; i<mxHA;i++)
if(hA[i])hA[i]->reset();
99 sprintf(txt,
"ETOW tower, E_T>%.2f GeV (input); x: ETOW RDO index=chan*6+fiber; y: counts",par_hotEtThres);
100 hA[10]->setTitle(txt);
102 sprintf(txt,
"ETOW tower, Et>%.2f GeV (input); x: ETOW softID=i#phi+60*i#eta",par_hotEtThres);
103 hA[11]->setTitle(txt);
104 sprintf(txt,
"ETOW tower, Et>%.2f GeV (input); x: eta bin, [+2,+1]; y: phi bin ~ TPC sector",par_hotEtThres);
105 hA[12] ->setTitle(txt);
107 sprintf(txt,
"#ETOW towers / event , Et>%.2f GeV; x: # ETOW towers; y: counts",par_hotEtThres);
108 hA[14] ->setTitle(txt);
114 int nEneThr=0, nPedThr=0;
115 if(par_gainType>=kGainIdeal)
116 for(i=0; i<EmcDbIndexMax; i++) {
118 if(mDb->isEmpty(x))
continue;
120 if (!mDb->isETOW(x) )
continue;
121 if(x->fail)
continue;
122 if(x->gain<=0)
continue;
125 float adcThres=x->ped+par_nSigPed* fabs(x->sigPed);
126 float otherThr=x->ped+par_twEneThres*x->gain;
128 if(adcThres<otherThr) {
136 if(x->eta<=0 || x->eta>EtowGeom::mxEtaBin)
return -90;
137 int ietaTw= (x->eta-1);
140 if (par_gainType!=kGainIdeal)
return -102;
141 mGeom->etow.gain2Ene_rdo[x->rdo]=mGeom->etow.idealGain2Ene[ietaTw];
142 mGeom->etow.gain2ET_rdo[x->rdo]=mGeom->getIdealAdc2ET();
144 mGeom->etow.thr_rdo[x->rdo]=(int) (adcThres);
145 mGeom->etow.ped_rdo[x->rdo]=(int) (x->ped);
146 mGeom->etow.ped_shifted_rdo[x->rdo]=(
unsigned short)(par_pedOff - x->ped);
151 fprintf(mLogFile,
" found towers working=%d calibrated=%d, based on ASCII DB\n",nT,nTg);
152 fprintf(mLogFile,
" thresh defined by energy=%d or NsigPed=%d \n",nEneThr, nPedThr);
163 L2etowCalAlgo09::calibrateEtow(
int token,
int eemcIn,
unsigned short *rawAdc){
167 token&=L2eventStream2009::tokenMask;
172 etowCalibData.nInputBlock++;
173 etowCalibData.hitSize=0;
177 if(eemcIn && par_gainType>kGainZero) {
184 unsigned short *thr=mGeom->etow.thr_rdo;
185 unsigned short *ped=mGeom->etow.ped_rdo;
186 unsigned short *ped_shifted=mGeom->etow.ped_shifted_rdo;
187 float *gain2ET=mGeom->etow.gain2ET_rdo;
188 float *gain2Ene=mGeom->etow.gain2Ene_rdo;
190 for(rdo=0; rdo<EtowGeom::mxRdo; rdo++){
191 if(rawAdc[rdo]<thr[rdo])
continue;
192 if(nTower>=L2EtowCalibData09::mxListSize)
break;
193 adc=rawAdc[rdo]-ped[rdo];
195 low_noise_adc=(rawAdc[rdo]+ped_shifted[rdo]) & par_adcMask;
196 low_noise_et=low_noise_adc/gain2ET[rdo];
200 hit->low_noise_et=low_noise_et;
201 hit->ene=adc/gain2Ene[rdo];
205 if(et >par_hotEtThres) {
210 etowCalibData.hitSize=nTower;
213 hA[13]->fill(nTower);
214 hA[14]->fill(nHotTower);
215 if(nTower>=L2EtowCalibData09::mxListSize) mhN->fill(5);
220 printf(
"L2-%s-compute: set adcL size=%d\n",getName(),nTower);
221 printf(
"dbg=%s: found nTw=%d\n",getName(),nTower);
222 if(par_dbg>0) print0();
223 printCalibratedData(token);
233 L2etowCalAlgo09::clear(
int token){
234 token&=L2eventStream2009::tokenMask;
237 etowCalibData.hitSize=0;
245 L2etowCalAlgo09::computeUser(
int token ){
247 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());
248 criticalError(
"L2etowCalAlgo09::computeUser has been called and should not have been. Serious problem in L2");
256 L2etowCalAlgo09::finishRunUser() {
264 hA[13]->findMean(&mean,&RMS);
266 fprintf(mLogFile,
"#ETOW_nonzero_towers_per_event: mean=%d, rms=%d\n",mean,RMS);
270 int eHotSum=1,eHotId=-1;
271 const int *data20=hA[10]->getData();
275 for(i=0; i<EmcDbIndexMax; i++) {
277 if(mDb->isEmpty(x))
continue;
278 if (!mDb->isETOW(x) )
continue;
279 int ieta= (x->eta-1);
280 int iphi= (x->sec-1)*EtowGeom::mxSubs + x->sub-
'A' ;
281 int softId= iphi+EtowGeom::mxPhiBin*ieta;
282 hA[11]->fillW(softId,data20[x->rdo]);
283 hA[12]->fillW(ieta, iphi,data20[x->rdo]);
284 if(eHotSum<data20[x->rdo]) {
285 eHotSum=data20[x->rdo];
291 int par_nHotThresh=20;
292 if (mLogFile && eHotSum>par_nHotThresh){
293 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);
297 int tkn1=99999, tkn2=0;
299 int tkn3=-1, nTkn3=-1;
302 for(k=0;k<L2eventStream2009::mxToken;k++){
304 if(etowCalibData.nInputBlock==0)
continue;
305 hA[1]->fillW(k,etowCalibData.nInputBlock);
306 if(nTkn3<etowCalibData.nInputBlock){
307 nTkn3=etowCalibData.nInputBlock;
316 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);
325 L2etowCalAlgo09::createHisto() {
326 memset(hA,0,mxHA*
sizeof(
L2Histo*));
328 hA[1]=
new L2Histo(1,
"L2-etow-calib: seen tokens; x: token value; y: events ",L2eventStream2009::mxToken);
331 hA[10]=
new L2Histo(10,
"etow hot tower 1", EtowGeom::mxRdo);
332 hA[11]=
new L2Histo(11,
"etow hot tower 2", EtowGeom::mxRdo);
333 hA[12]=
new L2Histo(12,
"etow hot tower 3", EtowGeom::mxEtaBin,EtowGeom::mxPhiBin);
334 hA[13]=
new L2Histo(13,
"ETOW #tower w/ energy /event; x: # ETOW towers; y: counts", 100);
335 hA[14]=
new L2Histo(14,
"# hot towers/event", 30);
344 L2etowCalAlgo09::print0(){