6 #include "fakeRtsLog.h"
16 #ifdef IS_REAL_L2 //in l2-ana environment
17 #include "../L2algoUtil/L2EmcDb2012.h"
18 #include "../L2algoUtil/L2Histo.h"
20 #include "L2EmcDb2012.h"
22 #include "L2EmcGeom2012.h"
25 #include "L2btowCalAlgo12.h"
35 L2btowCalAlgo12::L2btowCalAlgo12(
const char* name,
const char *uid,
L2EmcDb2012* db,
L2EmcGeom2012 *geoX,
char* outDir,
int resOff) :
L2VirtualAlgo2012( name, uid, db, outDir, true, false, resOff) {
42 criticalError(
"L2btowCalAlgo is broken -- can't find geom.");
49 for(k=0;k<L2eventStream2012::mxToken;k++){
51 btowCalibData.nInputBlock=0;
52 btowCalibData.hitSize=0;
62 L2btowCalAlgo12::initRunUser(
int runNo,
int *rc_ints,
float *rc_floats) {
64 par_adcMask=(
unsigned short)(-0x10);
69 par_gainType = rc_ints[1];
70 par_nSigPed = rc_ints[2];
72 par_twEneThres = rc_floats[0];
73 par_hotEtThres = rc_floats[1];;
77 kBad+=0x00001 * (par_gainType<kGainZero || par_gainType>kGainOffline);
78 kBad+=0x00002 * (par_nSigPed<2 || par_nSigPed>5);
79 kBad+=0x00004 * (par_twEneThres<0.1 || par_twEneThres>1.5);
82 fprintf(mLogFile,
"L2%s algorithm initRun(R=%d), compiled: %s , %s\n params:\n",getName(),mRunNumber,__DATE__,__TIME__);
83 fprintf(mLogFile,
" - use BTOW=%d, gain Ideal=%d or Offline=%d, debug=%d\n",
84 par_gainType>=kGainIdeal, par_gainType==kGainIdeal, par_gainType==kGainOffline, par_dbg);
85 fprintf(mLogFile,
" - thresholds: ADC-ped> %d*sigPed .AND. energy>%.2f GeV \n", par_nSigPed, par_twEneThres);
87 fprintf(mLogFile,
" - hot tower thresholds: ET/GeV=%.2f\n",par_hotEtThres);
88 fprintf(mLogFile,
"initRun() params checked for consistency, Error flag=0x%04x\n",kBad);
93 for(k=0;k<L2eventStream2012::mxToken;k++){
95 btowCalibData.nInputBlock=0;
96 btowCalibData.hitSize=0;
100 if(kBad)
return -kBad;
104 for (i=0; i<mxHA;i++)
if(hA[i])hA[i]->reset();
108 sprintf(txt,
"BTOW tower, E_T>%.2f GeV (input); x: BTOW RDO index=chan*30+fiber; y: counts",par_hotEtThres);
109 hA[10]->setTitle(txt);
111 sprintf(txt,
"BTOW tower, Et>%.2f GeV (input); x: BTOW softID",par_hotEtThres);
112 hA[11]->setTitle(txt);
113 sprintf(txt,
"BTOW tower, Et>%.2f GeV (input); x: eta bin, [-1,+1]; y: phi bin ~ TPC sector",par_hotEtThres);
114 hA[12] ->setTitle(txt);
116 sprintf(txt,
"#BTOW towers / event , Et>%.2f GeV; x: # BTOW towers; y: counts",par_hotEtThres);
117 hA[14] ->setTitle(txt);
123 int nEneThr=0, nPedThr=0;
124 if(par_gainType>=kGainIdeal)
125 for(i=0; i<EmcDbIndexMax; i++) {
127 if(mDb->isEmpty(x))
continue;
129 if (!mDb->isBTOW(x) )
continue;
130 if(x->fail)
continue;
131 if(x->gain<=0)
continue;
134 float adcThres=x->ped+par_nSigPed* fabs(x->sigPed);
135 float otherThr=x->ped+par_twEneThres*x->gain;
137 if(adcThres<otherThr) {
145 if(x->eta<=0 || x->eta>BtowGeom::mxEtaBin)
return -90;
146 int ietaTw= (x->eta-1);
150 if (par_gainType!=kGainIdeal)
return -102;
151 geom->btow.gain2Ene_rdo[x->rdo]=geom->btow.idealGain2Ene[ietaTw];
152 geom->btow.gain2ET_rdo[x->rdo]=geom->getIdealAdc2ET();
154 geom->btow.thr_rdo[x->rdo]=(int) (adcThres);
155 geom->btow.ped_rdo[x->rdo]=(int) (x->ped);
156 geom->btow.ped_shifted_rdo[x->rdo]=(
unsigned short)(par_pedOff - x->ped);
161 fprintf(mLogFile,
" found towers working=%d calibrated=%d, based on ASCII DB\n",nB,nBg);
162 fprintf(mLogFile,
" thresh defined by energy=%d or NsigPed=%d \n",nEneThr, nPedThr);
173 L2btowCalAlgo12::calibrateBtow(
int token,
int bemcIn,
unsigned short *rawAdc){
178 token&=L2eventStream2012::tokenMask;
183 btowCalibData.nInputBlock++;
186 btowCalibData.hitSize=0;
190 if(bemcIn && par_gainType>kGainZero) {
197 unsigned short *thr=geom->btow.thr_rdo;
198 unsigned short *ped=geom->btow.ped_rdo;
199 unsigned short *ped_shifted=geom->btow.ped_shifted_rdo;
200 float *gain2ET=geom->btow.gain2ET_rdo;
201 float *gain2Ene=geom->btow.gain2Ene_rdo;
203 for(rdo=0; rdo<BtowGeom::mxRdo; rdo++){
204 if(rawAdc[rdo]<thr[rdo])
continue;
208 if(nTower>=L2BtowCalibData12::mxListSize)
break;
209 adc=rawAdc[rdo]-ped[rdo];
211 low_noise_adc=(rawAdc[rdo]+ped_shifted[rdo]) & par_adcMask;
212 low_noise_et=low_noise_adc/gain2ET[rdo];
216 hit->low_noise_et=low_noise_et;
217 hit->ene=adc/gain2Ene[rdo];
221 if(et >par_hotEtThres) {
226 btowCalibData.hitSize=nTower;
229 hA[13]->fill(nTower);
230 hA[14]->fill(nHotTower);
231 if(nTower>=L2BtowCalibData12::mxListSize) mhN->fill(5);
235 LOG(DBG,
"hits = %d hot=%d",nTower,nHotTower);
239 LOG(DBG,
"L2-%s-compute: set adcL size=%d, get=%d\n",getName(),nTower,999);
240 LOG(DBG,
"dbg=%s: found nTw=%d\n",getName(),nTower);
241 if(par_dbg>0) print0();
242 printCalibratedData(token);
253 L2btowCalAlgo12::clear(
int token){
254 token&=L2eventStream2012::tokenMask;
257 btowCalibData.hitSize=0;
264 L2btowCalAlgo12::computeUser(
int token ){
266 LOG(CRIT,
"L2btowCalAlgo12::computeUser has been called and should not have been. Serious problem in L2");
273 L2btowCalAlgo12::finishRunUser() {
278 hA[13]->findMean(&mean,&RMS);
280 fprintf(mLogFile,
"#BTOW_nonzero_towers_per_event: mean=%d, rms=%d\n",mean,RMS);
283 int bHotSum=1,bHotId=-1;
284 const int *data20=hA[10]->getData();
288 for(i=0; i<EmcDbIndexMax; i++) {
290 if(mDb->isEmpty(x))
continue;
291 if (!mDb->isBTOW(x) )
continue;
292 int softId=atoi(x->tube+2);
293 int ieta= (x->eta-1);
294 int iphi= (x->sec-1)*BtowGeom::mxSubs + x->sub-
'a' ;
295 hA[11]->fillW(softId,data20[x->rdo]);
296 hA[12]->fillW(ieta, iphi,data20[x->rdo]);
297 if(bHotSum<data20[x->rdo]) {
298 bHotSum=data20[x->rdo];
305 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);
309 int tkn1=99999, tkn2=0;
311 int tkn3=-1, nTkn3=-1;
314 for(k=0;k<L2eventStream2012::mxToken;k++){
316 if(btowCalibData.nInputBlock==0)
continue;
317 hA[1]->fillW(k,btowCalibData.nInputBlock);
318 if(nTkn3<btowCalibData.nInputBlock){
319 nTkn3=btowCalibData.nInputBlock;
328 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);
337 L2btowCalAlgo12::createHisto() {
338 memset(hA,0,mxHA*
sizeof(
L2Histo*));
340 hA[1]=
new L2Histo(1,
"L2-btow-calib: seen tokens; x: token value; y: events ",L2eventStream2012::mxToken);
343 hA[10]=
new L2Histo(10,
"btow hot tower 1", BtowGeom::mxRdo);
344 hA[11]=
new L2Histo(11,
"btow hot tower 2", BtowGeom::mxRdo);
345 hA[12]=
new L2Histo(12,
"btow hot tower 3", BtowGeom::mxEtaBin,BtowGeom::mxPhiBin);
346 hA[13]=
new L2Histo(13,
"BTOW #tower w/ energy /event; x: # BTOW towers; y: counts", 200);
347 hA[14]=
new L2Histo(14,
"# hot towers/event", 100);
356 L2btowCalAlgo12::print0(){