15 #define rdtscll(val) do { \
16 unsigned int __a,__d; \
17 __asm__ __volatile__("rdtsc" : "=a" (__a), "=d" (__d)); \
18 (val) = ((unsigned long long)__a) | (((unsigned long long)__d)<<32); \
21 const float stepETH=5;
24 #ifdef IS_REAL_L2 //in l2-ana environment
25 #include "../L2algoUtil/L2EmcDb2012.h"
26 #include "../L2algoUtil/L2Histo.h"
28 #include "../L2algoUtil/L2EmcDb2012.h"
29 #include "../L2algoUtil/L2Histo.h"
30 #include "../L2algoUtil/L2EmcGeom2012.h"
33 #include "L2wBemc2012.h"
37 L2wBemc2012::L2wBemc2012(
const char* name,
const char *uid,
L2EmcDb2012* db,
L2EmcGeom2012 *geoX,
char* outDir,
int resOff) :
L2VirtualAlgo2012( name,uid, db, outDir, true, false, resOff) {
44 criticalError((
char*)
"L2wBemc is broken -- can't find geom.");
51 criticalError((
char*)
"L2wBemc has failed consistency check. sizeof(L2wResult2012)!= L2wResult2012::mySizeChar");
58 L2wBemc2012::initRunUser(
int runNo,
int *rc_ints,
float *rc_floats) {
62 par_RndAcceptPrescale = rc_ints[1];
63 par_seedEtThres = rc_floats[0];
64 par_clustEtThres = rc_floats[1];
68 kBad+=0x00002 * (par_clustEtThres<par_seedEtThres);
72 fprintf(mLogFile,
"L2%s algorithm initRun(R=%d), compiled: %s , %s\n params:\n",
73 getName(),mRunNumber,__DATE__,__TIME__);
74 fprintf(mLogFile,
" - use seedThres=%.2f (GeV), debug=%d, prescale=%d (0=off,1=100prc, 2=50proc, etc)\n",
75 par_seedEtThres,par_dbg, par_RndAcceptPrescale);
76 fprintf(mLogFile,
" - accept event cluster Thres=%.2f (GeV)\n",
78 fprintf(mLogFile,
"initRun() params checked for consistency, Error flag=0x%04x\n",
84 for (i=0; i<mxHA;i++)
if(hA[i])hA[i]->reset();
85 memset(mBtow,0,
sizeof(mBtow));
87 if(kBad>0)
return -1*kBad;
88 else if(kBad<0)
return kBad;
94 sprintf(txt,
"W-BTOW-accepted: acc seed tower ET>%.2f GeV; BTOW softID",par_seedEtThres);
97 sprintf(txt,
"W Btow accepted, seed tower Et>%.2f GeV; eta bin [-1,+1]; y: phi bin ~ TCP sector",par_seedEtThres);
98 hA[10]->setTitle(txt);
101 for (
int index=0; index<EmcDbIndexMax; index++ )
104 if ( x==0 )
continue;
105 if ( !mDb->isBTOW(x) )
continue;
106 int sec = x->sec - 1;
109 int eta = x->eta - 1;
110 int phi = BtowGeom::mxSubs *sec + sub;
111 int tow = BtowGeom::mxEtaBin *phi + eta;
113 if (tow<0 || tow>mxBtow || rdo<0 || rdo>mxBtow)
return -101;
115 mTower2rdo[ tow ] = rdo;
116 mRdo2tower[ rdo ] = tow;
127 L2wBemc2012::sumET(
int phi,
int eta) {
128 int tow = BtowGeom::mxEtaBin *((phi+BtowGeom::mxPhiBin)%BtowGeom::mxPhiBin) + ((eta+BtowGeom::mxEtaBin)%BtowGeom::mxEtaBin);
130 const int maxTowers = BtowGeom::mxEtaBin * BtowGeom::mxPhiBin;
136 towPlusOne%= maxTowers;
137 sum+=wrkBtow_et[towPlusOne];
139 tow+=BtowGeom::mxEtaBin;
142 sum+=wrkBtow_et[tow];
145 towPlusOne%= maxTowers;
146 sum+=wrkBtow_et[towPlusOne];
155 L2wBemc2012::computeUser(
int token){
164 const int hitSize=mEveStream_btow[token].get_hitSize();
168 for(i=0;i< hitSize;i++,hit++) {
169 int tower=mRdo2tower[hit->rdo];
170 wrkBtow_et[tower]=hit->et;
171 if(hit->et<par_seedEtThres)
continue;
172 wrkBtow_tower_seed[wrkBtow_tower_seed_size++]=tower;
174 hA[2]->fill(hitSize);
175 int seedTow=-1,seedEta=-1,seedPhi=-1;
177 btowEve->isFresh=L2wBemcEvent2012::kDataFresh;
180 for(i=0; i<wrkBtow_tower_seed_size;i++) {
181 seedTow=wrkBtow_tower_seed[i];
182 seedEta=seedTow%BtowGeom::mxEtaBin;
183 seedPhi=seedTow/BtowGeom::mxEtaBin;
186 if (seedEta < BtowGeom::mxEtaBin) {
187 clustET = sumET(seedPhi,seedEta);
188 if(clustET>par_clustEtThres)
goto ACCEPT;
189 clustET = sumET(seedPhi-1,seedEta);
190 if(clustET>par_clustEtThres)
goto ACCEPT;
193 clustET = sumET(seedPhi-1,seedEta-1);
194 if(clustET>par_clustEtThres)
goto ACCEPT;
195 clustET = sumET(seedPhi,seedEta-1);
196 if(clustET>par_clustEtThres)
goto ACCEPT;
200 btowEve->resultBlob.seedEt=0;
201 btowEve->resultBlob.clusterEt=0;
202 btowEve->resultBlob.seedEtaBin=0;
203 btowEve->resultBlob.seedPhiBin=0;
204 btowEve->resultBlob.trigger=0;
206 btowEve->clusterET=0;
207 btowEve->tkCompute=0;
211 btowEve->seedET=wrkBtow_et[seedTow];
212 btowEve->clusterET=clustET;
213 btowEve->resultBlob.seedEt =(
unsigned char)(wrkBtow_et[seedTow]*256.0/60.0);
214 btowEve->resultBlob.clusterEt=(
unsigned char)(clustET*256.0/60.0);
215 btowEve->resultBlob.seedEtaBin=seedEta;
216 btowEve->resultBlob.seedPhiBin=seedPhi;
217 btowEve->resultBlob.trigger=2;
218 rdtscll( btowEve->tkCompute);
229 L2wBemc2012::decisionUser(
int token,
int *myL2Result){
238 if (mRandomAccept) btowEve->resultBlob.trigger+=1;
241 if(btowEve->isFresh>L2wBemcEvent2012::kDataFresh) mhN->fill(6);
245 if(btowEve->resultBlob.trigger&2) {
246 unsigned long long tkDecision;
248 int tkDelta=tkDecision-btowEve->tkCompute;
249 hA[1]->fill(tkDelta/1000);
251 hA[3]->fill((
int)btowEve->seedET);
252 hA[4]->fill((
int)btowEve->clusterET);
253 hA[5]->fill((
int)(100.*btowEve->seedET/btowEve->clusterET));
254 int jET=(int)(btowEve->clusterET/stepETH);
257 hA[10+jET]->fill(btowEve->resultBlob.seedEtaBin,btowEve->resultBlob.seedPhiBin);
258 hA[10]->fill(btowEve->resultBlob.seedEtaBin,btowEve->resultBlob.seedPhiBin);
261 memcpy(myL2Result,&(btowEve->resultBlob),
sizeof(
L2wResult2012));
262 if(par_dbg) L2wResult2012_print((
L2wResult2012 *)&(btowEve->resultBlob));
264 return btowEve->resultBlob.trigger&2;
271 L2wBemc2012::finishRunUser() {
275 fprintf(mLogFile,
"finishRunUser-%s start\n",getName());
283 for(
int jh=10;jh<19;jh++)
286 const int *hiData = hA[jh]->getData();
288 for(
int i=0; i<EmcDbIndexMax; i++) {
290 if(mDb->isEmpty(x))
continue;
291 if (!mDb->isBTOW(x) )
continue;
292 int ieta= (x->eta-1);
293 int iphi= (x->sec-1)*10 + x->sub-
'a' ;
294 int softId=atoi(x->tube+2);
295 int ix=ieta+iphi*BtowGeom::mxEtaBin;
296 int yield=hiData[ix];
298 if(jh==10) hA[9]->fillW(softId,yield);
299 if(hotY>yield)
continue;
304 int ieta= (xB->eta-1);
305 int iphi= (xB->sec-1)*10 + xB->sub-
'a' ;
306 int softId=atoi(xB->tube+2);
307 fprintf(mLogFile,
"#BTOW hot *candidate*, hist: %d, yield: %d, totYield: %d, softID: %d, crate: %d, chan: %d, name: %s, ieta: %d, iphi: %d\n", hA[jh]->getId(),hotY,totY,softId,xB->crate,xB->chan,xB->name,ieta,iphi);
318 L2wBemc2012::createHisto() {
319 hA[1]=
new L2Histo(1,(
char*)
"W Btow delTime (decision-compute); kTicks",300);
321 hA[2]=
new L2Histo(2,(
char*)
"W Btow-compute: # btow towers w/ energy /event; x: # BTOW towers; y: counts", 100);
322 hA[3]=
new L2Histo(3,(
char*)
"W Btow-accepted: seeds ; Seed ET (GeV)", 70);
323 hA[4]=
new L2Histo(4,(
char*)
"W Btow-accepted: clusters ; Cluster ET ET(GeV)", 70);
324 hA[5]=
new L2Histo(5,(
char*)
"W Btow-accepted: cluster shape ;100*Seed Et/Cluster Et", 105);
327 hA[9]=
new L2Histo(9,(
char*)
"W Btow ...9 .....", 5000);
328 hA[10]=
new L2Histo(10,(
char*)
"W Btow ...10 ...", BtowGeom::mxEtaBin, BtowGeom::mxPhiBin);
332 for(
int j=1;j<=9;j++){
338 sprintf(tit,
"W Btow-accept: cluster %.0f <ET< %.0f GeV ; seed eta bin [-1,+1]; seed phi bin ~ TCP sector", x1,x2);
340 hA[hid]=
new L2Histo(hid,tit, BtowGeom::mxEtaBin, BtowGeom::mxPhiBin);
350 L2wBemc2012::clearEvent(
int token){
351 memset(wrkBtow_et,0,
sizeof(wrkBtow_et));
352 wrkBtow_tower_seed_size=0;
359 L2wBemc2012::print2(){
361 printf(
"pr2-%s: ---BTOW ADC 2D array, only non-zero\n",getName());
363 for(i=0;i<mxBtow;i++) {
364 if(wrkBtow_et[i]<=0)
continue;
365 int rdo=mTower2rdo[i];
366 float et=wrkBtow_et[i];
367 printf(
" btow: tower=%4d rdo=%4d et=%.3f \n",i,rdo,et);
375 L2wBemc2012::print3(){
377 printf(
"pr3-%s: ---seed list, size=%d\n",getName(),wrkBtow_tower_seed_size);
379 for(i=0;i<wrkBtow_tower_seed_size;i++) {
380 int tower=wrkBtow_tower_seed[i];
381 float et=wrkBtow_et[tower];
382 printf(
" btow: i=%4d tower=%4d et=%.3f \n",i,tower,et);
392 L2wBemc2012::print4(
int token,
int hitSize){
394 printf(
"print4 IS NOT Fully FUNCTIONAL **********************\n");
395 printf(
"pr1-%s: ---BTOW Sorted ADC list--- size=%d\n",getName(),hitSize);
397 for(i=0;i< hitSize;i++) {
400 float et=wrkBtow_et[wrkBtow_tower_index[i]];
402 printf(
" tower=%2d ",wrkBtow_tower_index[i]);
403 printf(
" btow: i=%2d rdo=%4d adc=%d et=%.3f ene=%.3f\n",i,rdo,adc,et,ene);