15 #ifdef IS_REAL_L2 //in l2-ana environment
16 #include "../L2algoUtil/L2EmcDb.h"
17 #include "../L2algoUtil/L2Histo.h"
18 #else //full path needed for cvs'd code
19 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcDb.h"
20 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2Histo.h"
23 #include "L2hienAlgo09.h"
24 #include "L2hienResult2009.h"
28 L2hienAlgo09::L2hienAlgo09(
const char* name,
L2EmcDb* db,
L2EmcGeom *geoX,
char* outDir,
int resOff, L2VirtualAlgo2009::EmcSwitch beSwitch) :
L2VirtualAlgo2009( name, 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(
"L2hienAlgo09 (Barrel) has failed consistency check. sizeof(L2hienResult2009)!= L2hienResult2009::mySizeChar");
54 L2hienAlgo09::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>L2hienList09::mxListSize ) par_maxList=L2hienList09::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 L2hienAlgo09::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;
188 unsigned int *value=hiTwEve->value;
189 unsigned int tempValue=0;
190 unsigned int totalADC=0;
191 int resultMaxTowers=0;
194 if (mSwitch==kIsBtow)
196 resultMaxTowers=L2hienResult2009::maxTowers;
200 for(i=0;i< hitSize;i++,hit++) {
202 softID=mRdo2towerID[hit->rdo];
204 tempValue=((hit->adc)<<16)+softID;
206 if ((mSwitch==kIsBtow) && (i<L2hienResult2009::maxTowers))
207 hienResult->value[i]=tempValue;
208 if (hiTwEve->size<par_maxList && hit->adc>=par_adcThres)
217 if(hiTwEve->size>=par_maxList && i>=L2hienResult2009::maxTowers)
break;
222 if (hitSize>255) nTow=255;
225 if (totalADC>16777215) totalADC=16777215;
226 hienResult->header=(nTow<<24)+totalADC;
230 hiTwEve->isFresh=L2hienList09::kDataFresh;
231 hA[2]->fill(hiTwEve->size);
238 L2hienAlgo09::decisionUser(
int token,
int *myL2Result){
251 hA[3]->fill(hiTwEve->size);
252 if(hiTwEve->size>= par_maxList) mhN->fill(5);
253 if(hiTwEve->isFresh>L2hienList09::kDataFresh) mhN->fill(6);
257 int adc4QaThres=(par_adcThres/8);
258 int * mTowerID2etaBin=0 , *mTowerID2phiBin=0;
259 if(mSwitch==kIsBtow) {
260 mTowerID2etaBin=mTowerID2etaBin_B;
261 mTowerID2phiBin=mTowerID2phiBin_B;
263 mTowerID2etaBin=mTowerID2etaBin_E;
264 mTowerID2phiBin=mTowerID2phiBin_E;
267 unsigned int *value=hiTwEve->value;
270 for(ic=0;ic<hiTwEve->size;ic++,value++) {
271 int adc4=(*value)>>(16+4);
272 int softID=(*value)&0xffff;
276 if(adc4<adc4QaThres)
continue;
277 hA[5]->fill(mTowerID2etaBin[softID]);
278 hA[6]->fill(mTowerID2phiBin[softID]);
280 if(adcSum4>0) hA[7]->fill(adcSum4);
299 hienResult->header=0;
312 L2hienAlgo09::finishRunUser() {
316 fprintf(mLogFile,
"finishRunUser-%s bhla bhla\n",getName());
325 L2hienAlgo09::createHisto() {
326 memset(hA,0,
sizeof(hA));
328 hA[2]=
new L2Histo(2,
"compute: #towers w/ .....energy /event; x: # towers; y: counts", 35);
329 hA[3]=
new L2Histo(3,
"decision: #towers w/ .....energy /event; x: # towers; y: counts", 35);
331 int nEtaBin=BtowGeom::mxEtaBin;
332 int nPhiBin=BtowGeom::mxPhiBin;
333 if(mSwitch==kIsEtow) {
334 nEtaBin=EtowGeom::mxEtaBin;
335 nPhiBin=EtowGeom::mxPhiBin;
337 hA[4]=
new L2Histo(4,
"accepted: towers ET (watch units!) ; x: (ADC-ped)/16", 150);
338 hA[5]=
new L2Histo(5,
"accepted: #towers w/ ..... vs. eta ring",nEtaBin);
339 hA[6]=
new L2Histo(6,
"accepted: #towers w/ .... vs. phi ring",nPhiBin);
340 hA[7]=
new L2Histo(7,
"accepted: ADC sum ...",150);
349 L2hienAlgo09::print2(
int token){
350 if (!(token>0 && token<L2eventStream2009::mxToken))
352 printf(
"L2hienAlgo09::print2 called with token out of bounds!\n");
356 int hiSize=getListSize(token);
357 const unsigned int *value=getListData(token);
359 printf(
"pr2-%s: dump %d acceted towers for token=%d\n softID ADC-ped\n",getName(),hiSize, token);
360 for(
int ic=0;ic<hiSize;ic++,value++) {
361 int adc=(*value)>>16;
362 int softID=(*value)&0xffff;
363 printf(
"%4d %d, \n",softID,adc);