6 #include <fakeRtsLog.h>
17 #ifdef IS_REAL_L2 //in l2-ana environment
18 #include "../L2algoUtil/L2EmcDb2012.h"
19 #include "../L2algoUtil/L2Histo.h"
21 #include "L2EmcDb2012.h"
23 #include "L2EmcGeom2012.h"
26 #include "L2etowCalAlgo12.h"
31 L2etowCalAlgo12::L2etowCalAlgo12(
const char* name,
const char *uid,
L2EmcDb2012* db,
L2EmcGeom2012 *geoX,
char* outDir,
int resOff) :
L2VirtualAlgo2012( name, uid, db, outDir, false, true, resOff) {
38 criticalError(
"L2etowCalAlgo is broken -- can't find geom.");
45 for(k=0;k<L2eventStream2012::mxToken;k++){
47 etowCalibData.nInputBlock=0;
48 etowCalibData.hitSize=0;
55 L2etowCalAlgo12::initRunUser(
int runNo,
int *rc_ints,
float *rc_floats) {
57 par_adcMask=(
unsigned short)(-0x10);
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 ETOW=%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);
86 for(k=0;k<L2eventStream2012::mxToken;k++){
88 etowCalibData.nInputBlock=0;
89 etowCalibData.hitSize=0;
96 for (i=0; i<mxHA;i++)
if(hA[i])hA[i]->reset();
100 sprintf(txt,
"ETOW tower, E_T>%.2f GeV (input); x: ETOW RDO index=chan*6+fiber; y: counts",par_hotEtThres);
101 hA[10]->setTitle(txt);
103 sprintf(txt,
"ETOW tower, Et>%.2f GeV (input); x: ETOW softID=i#phi+60*i#eta",par_hotEtThres);
104 hA[11]->setTitle(txt);
105 sprintf(txt,
"ETOW tower, Et>%.2f GeV (input); x: eta bin, [+2,+1]; y: phi bin ~ TPC sector",par_hotEtThres);
106 hA[12] ->setTitle(txt);
108 sprintf(txt,
"#ETOW towers / event , Et>%.2f GeV; x: # ETOW towers; y: counts",par_hotEtThres);
109 hA[14] ->setTitle(txt);
115 int nEneThr=0, nPedThr=0;
116 if(par_gainType>=kGainIdeal)
117 for(i=0; i<EmcDbIndexMax; i++) {
119 if(mDb->isEmpty(x))
continue;
121 if (!mDb->isETOW(x) )
continue;
122 if(x->fail)
continue;
123 if(x->gain<=0)
continue;
126 float adcThres=x->ped+par_nSigPed* fabs(x->sigPed);
127 float otherThr=x->ped+par_twEneThres*x->gain;
129 if(adcThres<otherThr) {
137 if(x->eta<=0 || x->eta>EtowGeom::mxEtaBin)
return -90;
138 int ietaTw= (x->eta-1);
141 if (par_gainType!=kGainIdeal)
return -102;
142 mGeom->etow.gain2Ene_rdo[x->rdo]=mGeom->etow.idealGain2Ene[ietaTw];
143 mGeom->etow.gain2ET_rdo[x->rdo]=mGeom->getIdealAdc2ET();
145 mGeom->etow.thr_rdo[x->rdo]=(int) (adcThres);
146 mGeom->etow.ped_rdo[x->rdo]=(int) (x->ped);
147 mGeom->etow.ped_shifted_rdo[x->rdo]=(
unsigned short)(par_pedOff - x->ped);
152 fprintf(mLogFile,
" found towers working=%d calibrated=%d, based on ASCII DB\n",nT,nTg);
153 fprintf(mLogFile,
" thresh defined by energy=%d or NsigPed=%d \n",nEneThr, nPedThr);
164 L2etowCalAlgo12::calibrateEtow(
int token,
int eemcIn,
unsigned short *rawAdc){
168 token&=L2eventStream2012::tokenMask;
173 etowCalibData.nInputBlock++;
174 etowCalibData.hitSize=0;
178 if(eemcIn && par_gainType>kGainZero) {
185 unsigned short *thr=mGeom->etow.thr_rdo;
186 unsigned short *ped=mGeom->etow.ped_rdo;
187 unsigned short *ped_shifted=mGeom->etow.ped_shifted_rdo;
188 float *gain2ET=mGeom->etow.gain2ET_rdo;
189 float *gain2Ene=mGeom->etow.gain2Ene_rdo;
191 for(rdo=0; rdo<EtowGeom::mxRdo; rdo++){
192 if(rawAdc[rdo]<thr[rdo])
continue;
193 if(nTower>=L2EtowCalibData12::mxListSize)
break;
194 adc=rawAdc[rdo]-ped[rdo];
196 low_noise_adc=(rawAdc[rdo]+ped_shifted[rdo]) & par_adcMask;
197 low_noise_et=low_noise_adc/gain2ET[rdo];
201 hit->low_noise_et=low_noise_et;
202 hit->ene=adc/gain2Ene[rdo];
206 if(et >par_hotEtThres) {
211 etowCalibData.hitSize=nTower;
214 hA[13]->fill(nTower);
215 hA[14]->fill(nHotTower);
216 if(nTower>=L2EtowCalibData12::mxListSize) mhN->fill(5);
221 LOG(DBG,
"L2-%s-compute: set adcL size=%d\n",getName(),nTower);
222 LOG(DBG,
"dbg=%s: found nTw=%d\n",getName(),nTower);
223 if(par_dbg>0) print0();
224 printCalibratedData(token);
234 L2etowCalAlgo12::clear(
int token){
235 token&=L2eventStream2012::tokenMask;
238 etowCalibData.hitSize=0;
246 L2etowCalAlgo12::computeUser(
int token ){
248 LOG(CRIT,
"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());
249 criticalError(
"L2etowCalAlgo12::computeUser has been called and should not have been. Serious problem in L2");
257 L2etowCalAlgo12::finishRunUser() {
265 hA[13]->findMean(&mean,&RMS);
267 fprintf(mLogFile,
"#ETOW_nonzero_towers_per_event: mean=%d, rms=%d\n",mean,RMS);
271 int eHotSum=1,eHotId=-1;
272 const int *data20=hA[10]->getData();
276 for(i=0; i<EmcDbIndexMax; i++) {
278 if(mDb->isEmpty(x))
continue;
279 if (!mDb->isETOW(x) )
continue;
280 int ieta= (x->eta-1);
281 int iphi= (x->sec-1)*EtowGeom::mxSubs + x->sub-
'A' ;
282 int softId= iphi+EtowGeom::mxPhiBin*ieta;
283 hA[11]->fillW(softId,data20[x->rdo]);
284 hA[12]->fillW(ieta, iphi,data20[x->rdo]);
285 if(eHotSum<data20[x->rdo]) {
286 eHotSum=data20[x->rdo];
292 int par_nHotThresh=20;
293 if (mLogFile && eHotSum>par_nHotThresh){
294 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);
298 int tkn1=99999, tkn2=0;
300 int tkn3=-1, nTkn3=-1;
303 for(k=0;k<L2eventStream2012::mxToken;k++){
305 if(etowCalibData.nInputBlock==0)
continue;
306 hA[1]->fillW(k,etowCalibData.nInputBlock);
307 if(nTkn3<etowCalibData.nInputBlock){
308 nTkn3=etowCalibData.nInputBlock;
317 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);
326 L2etowCalAlgo12::createHisto() {
327 memset(hA,0,mxHA*
sizeof(
L2Histo*));
329 hA[1]=
new L2Histo(1,
"L2-etow-calib: seen tokens; x: token value; y: events ",L2eventStream2012::mxToken);
332 hA[10]=
new L2Histo(10,
"etow hot tower 1", EtowGeom::mxRdo);
333 hA[11]=
new L2Histo(11,
"etow hot tower 2", EtowGeom::mxRdo);
334 hA[12]=
new L2Histo(12,
"etow hot tower 3", EtowGeom::mxEtaBin,EtowGeom::mxPhiBin);
335 hA[13]=
new L2Histo(13,
"ETOW #tower w/ energy /event; x: # ETOW towers; y: counts", 100);
336 hA[14]=
new L2Histo(14,
"# hot towers/event", 30);
345 L2etowCalAlgo12::print0(){