15 #ifdef IS_REAL_L2 //in l2-ana environment
16 #include "../L2algoUtil/L2EmcDb2012.h"
17 #include "../L2algoUtil/L2Histo.h"
18 #else //full path needed for cvs'd code
19 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcDb2012.h"
20 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2Histo.h"
23 #include "L2hienAlgo12.h"
24 #include "L2hienResult2012.h"
28 L2hienAlgo12::L2hienAlgo12(
const char* name,
const char *uid,
L2EmcDb2012* db,
L2EmcGeom2012 *geoX,
char* outDir,
int resOff, L2VirtualAlgo2012::EmcSwitch beSwitch) :
L2VirtualAlgo2012( name, uid, db, outDir, (beSwitch==kIsBtow),(beSwitch==kIsEtow), resOff ) {
35 if(!(beSwitch==kIsBtow || beSwitch==kIsEtow))
37 criticalError(
"L2hienAlgo called with broken beSwitch. L2hien cannot run.\n");
40 if (beSwitch==kIsBtow)
43 criticalError(
"L2hienAlgo12 (Barrel) has failed consistency check. sizeof(L2hienResult2012)!= L2hienResult2012::mySizeChar");
54 L2hienAlgo12::initRunUser(
int runNo,
int *rc_ints,
float *rc_floats) {
58 par_adcThres = rc_ints[1];
59 par_maxList = rc_ints[2];
60 par_RndAcceptPrescale = 0;
64 kBad+=0x00001 * (par_adcThres<10);
67 if(par_maxList<10 ) par_maxList=10;
68 if(par_maxList>L2hienList12::mxListSize ) par_maxList=L2hienList12::mxListSize;
71 fprintf(mLogFile,
"L2%s algorithm initRun(R=%d), compiled: %s , %s\n params for ",getName(),mRunNumber,__DATE__,__TIME__);
72 if(mSwitch==kIsBtow) fprintf(mLogFile,
" BTOW setup:\n");
73 if(mSwitch==kIsEtow) fprintf(mLogFile,
" ETOW setup:\n");
74 fprintf(mLogFile,
" - use adcThresh =%d, maxList=%d debug=%d\n", par_adcThres , par_maxList, par_dbg);
75 fprintf(mLogFile,
"initRun() params checked for consistency, Error flag=0x%04x\n",kBad);
77 if(kBad)
return -kBad;
81 for (i=0; i<mxHA;i++)
if(hA[i])hA[i]->reset();
82 memset(mHiEnTw,0,
sizeof(mHiEnTw));
87 sprintf(txt,
"compute: # towers w/ ADC-ped>%d / event; x: # towers; y: counts",par_adcThres);
90 sprintf(txt,
"accepted: # towers w/ ADC-ped>%d / event; x: # towers; y: counts",par_adcThres);
93 sprintf(txt,
"accepted: # towers w/ ADC-ped>%d vs. eta ring;x: BTOW eta-bin, 0=eta=-1.0; y: counts",par_adcThres*2);
95 sprintf(txt,
"accepted: # towers w/ ADC-ped>%d vs. eta ring;x: ETOW eta-bin, 0=eta=+2.0; y: counts",par_adcThres*2);
98 sprintf(txt,
"accepted: # towers w/ ADC-ped>%d vs. phi ring;x: phi-bin, 0=12:30, follows TPC; y: counts",par_adcThres*2);
101 sprintf(txt,
"accepted: ADC sum over towers w/ ADC-ped>%d ; ADC sum/16; y: counts",par_adcThres);
102 hA[7]->setTitle(txt);
107 memset(mRdo2towerID_B,0,
sizeof(mRdo2towerID_B));
108 memset(mTowerID2etaBin_B,0,
sizeof(mTowerID2etaBin_B));
109 memset(mTowerID2phiBin_B,0,
sizeof(mTowerID2phiBin_B));
111 memset(mRdo2towerID_E,0,
sizeof(mRdo2towerID_E));
112 memset(mTowerID2etaBin_E,0,
sizeof(mTowerID2etaBin_E));
113 memset(mTowerID2phiBin_E,0,
sizeof(mTowerID2phiBin_E));
116 for (
int index=0; index<EmcDbIndexMax; index++ ) {
118 if ( x==0 )
continue;
119 if ( !mDb->isBTOW(x) )
continue;
120 int sec = x->sec - 1;
123 int eta = x->eta - 1;
124 int phi = BtowGeom::mxSubs *sec + sub;
125 int tow = BtowGeom::mxEtaBin *phi + eta;
127 if (tow<0 || tow>mxBtow || rdo<0 || rdo>mxBtow)
return -101;
129 mRdo2towerID_B[ rdo ] = tow;
130 mTowerID2etaBin_B[tow]=eta;
131 mTowerID2phiBin_B[tow]=phi;
136 for (
int index=0; index<EmcDbIndexMax; index++ ) {
138 if ( x==0 )
continue;
139 if ( !mDb->isETOW(x) )
continue;
140 int sec = x->sec - 1;
143 int eta = x->eta - 1;
144 int phi = EtowGeom::mxSubs *sec + sub;
145 int tow = EtowGeom::mxEtaBin *phi + eta;
147 if (tow<0 || tow>mxEtow || rdo<0 || rdo>mxEtow)
return -101;
149 mRdo2towerID_E[ rdo ] = tow;
150 mTowerID2etaBin_E[tow]=eta;
151 mTowerID2phiBin_E[tow]=phi;
162 L2hienAlgo12::computeUser(
int token){
167 mHiEnTw[token].size=0;
174 if(mSwitch==kIsBtow) {
175 hit =mEveStream_btow[token].get_hits();
176 hitSize=mEveStream_btow[token].get_hitSize();
177 mRdo2towerID=mRdo2towerID_B;
179 hit =mEveStream_etow[token].get_hits();
180 hitSize=mEveStream_etow[token].get_hitSize();
181 mRdo2towerID=mRdo2towerID_E;
187 unsigned int *value=hiTwEve->value;
188 unsigned int tempValue=0;
189 unsigned int totalADC=0;
190 int resultMaxTowers=0;
193 if (mSwitch==kIsBtow)
195 resultMaxTowers=L2hienResult2012::maxTowers;
199 for(i=0;i< hitSize;i++,hit++) {
201 softID=mRdo2towerID[hit->rdo];
203 tempValue=((hit->adc)<<16)+softID;
205 if ((mSwitch==kIsBtow) && (i<L2hienResult2012::maxTowers))
206 hienResult->value[i]=tempValue;
207 if (hiTwEve->size<par_maxList && hit->adc>=par_adcThres)
215 if(hiTwEve->size>=par_maxList && i>=L2hienResult2012::maxTowers)
break;
219 if (hitSize>255) nTow=255;
222 if (totalADC>16777215) totalADC=16777215;
223 hienResult->header=(nTow<<24)+totalADC;
225 hiTwEve->isFresh=L2hienList12::kDataFresh;
226 hA[2]->fill(hiTwEve->size);
233 L2hienAlgo12::decisionUser(
int token,
int *myL2Result){
245 hA[3]->fill(hiTwEve->size);
246 if(hiTwEve->size>= par_maxList) mhN->fill(5);
247 if(hiTwEve->isFresh>L2hienList12::kDataFresh) mhN->fill(6);
251 int adc4QaThres=(par_adcThres/8);
252 int * mTowerID2etaBin=0 , *mTowerID2phiBin=0;
253 if(mSwitch==kIsBtow) {
254 mTowerID2etaBin=mTowerID2etaBin_B;
255 mTowerID2phiBin=mTowerID2phiBin_B;
257 mTowerID2etaBin=mTowerID2etaBin_E;
258 mTowerID2phiBin=mTowerID2phiBin_E;
261 unsigned int *value=hiTwEve->value;
264 for(ic=0;ic<hiTwEve->size;ic++,value++) {
265 int adc4=(*value)>>(16+4);
266 int softID=(*value)&0xffff;
269 if(adc4<adc4QaThres)
continue;
270 hA[5]->fill(mTowerID2etaBin[softID]);
271 hA[6]->fill(mTowerID2phiBin[softID]);
273 if(adcSum4>0) hA[7]->fill(adcSum4);
289 hienResult->header=0;
302 L2hienAlgo12::finishRunUser() {
306 fprintf(mLogFile,
"finishRunUser-%s bhla bhla\n",getName());
315 L2hienAlgo12::createHisto() {
316 memset(hA,0,
sizeof(hA));
318 hA[2]=
new L2Histo(2,
"compute: #towers w/ .....energy /event; x: # towers; y: counts", 35);
319 hA[3]=
new L2Histo(3,
"decision: #towers w/ .....energy /event; x: # towers; y: counts", 35);
321 int nEtaBin=BtowGeom::mxEtaBin;
322 int nPhiBin=BtowGeom::mxPhiBin;
323 if(mSwitch==kIsEtow) {
324 nEtaBin=EtowGeom::mxEtaBin;
325 nPhiBin=EtowGeom::mxPhiBin;
327 hA[4]=
new L2Histo(4,
"accepted: towers ET (watch units!) ; x: (ADC-ped)/16", 150);
328 hA[5]=
new L2Histo(5,
"accepted: #towers w/ ..... vs. eta ring",nEtaBin);
329 hA[6]=
new L2Histo(6,
"accepted: #towers w/ .... vs. phi ring",nPhiBin);
330 hA[7]=
new L2Histo(7,
"accepted: ADC sum ...",150);
338 L2hienAlgo12::print2(
int token){
339 if (!(token>0 && token<L2eventStream2012::mxToken))
341 printf(
"L2hienAlgo12::print2 called with token out of bounds!\n");
345 int hiSize=getListSize(token);
346 const unsigned int *value=getListData(token);
348 printf(
"pr2-%s: dump %d acceted towers for token=%d\n softID ADC-ped\n",getName(),hiSize, token);
349 for(
int ic=0;ic<hiSize;ic++,value++) {
350 int adc=(*value)>>16;
351 int softID=(*value)&0xffff;
352 printf(
"%4d %d, \n",softID,adc);