6 #include <fakeRtsLog.h>
17 #ifdef IS_REAL_L2 //in l2-ana environment
18 #include "../L2algoUtil/L2EmcDb2012.h"
19 #include "../L2algoUtil/L2Histo.h"
20 #else //full path needed for cvs'd code
21 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcDb2012.h"
22 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2Histo.h"
23 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcGeom2012.h"
26 #include "L2eemcGamma2012.h"
31 void L2eemcGamma2012::quickSort(
int array[],
int start,
int end)
38 float pivot = wrkEtow_et[array[start]];
42 while (wrkEtow_et[array[i]] <= pivot && i <= end && k > i)
44 while (wrkEtow_et[array[k]] > pivot && k >= start && k >= i)
49 swap(array, start, k);
51 quickSort(array, start, k - 1);
52 quickSort(array, k + 1, end);
60 void L2eemcGamma2012::swap(
int array[],
int index1,
int index2)
64 int temp = array[index1];
65 array[index1] = array[index2];
73 L2eemcGamma2012::L2eemcGamma2012(
const char* name,
const char *uid,
L2EmcDb2012* db,
L2EmcGeom2012 *geoX,
char* outDir,
int resOff) :
L2VirtualAlgo2012( name, uid, db, outDir, false,true, resOff) {
79 criticalError(
"L2eemcGamma is broken -- can't find geom.");
87 criticalError(
"L2eemcGamma has failed consistency check. sizeof(L2gammaResult2012)!= L2gammaResult2012::mySizeChar");
96 L2eemcGamma2012::initRunUser(
int runNo,
int *rc_ints,
float *rc_floats) {
100 par_RndAcceptPrescale = rc_ints[1];
101 par_seedEtThres = rc_floats[0];
102 par_clusterEtThres= rc_floats[1];
103 par_eventEtThres = rc_floats[2];
107 kBad+=0x00001 * (par_seedEtThres<1.0);
108 kBad+=0x00002 * (par_clusterEtThres<par_seedEtThres);
111 fprintf(mLogFile,
"L2%s algorithm initRun(R=%d), compiled: %s , %s\n params:\n",getName(),mRunNumber,__DATE__,__TIME__);
112 fprintf(mLogFile,
" - use Thres/GeV seed=%.2f, clusterList=%.2f debug=%d, prescale=%d\n", par_seedEtThres,par_clusterEtThres, par_dbg,par_RndAcceptPrescale);
114 fprintf(mLogFile,
" - accept event cluster Thres/GeV=%.2f\n",par_eventEtThres);
115 fprintf(mLogFile,
"initRun() params checked for consistency, Error flag=0x%04x\n",kBad);
121 for (i=0; i<mxHA;i++)
if(hA[i])hA[i]->reset();
123 if(kBad)
return -1*kBad;
125 memset(mEtow,0,
sizeof(mEtow));
129 sprintf(txt,
"ETOW-compute: #seed towers ET>%.2f GeV / event; x: # ETOW towers; y: counts",par_seedEtThres);
130 hA[3]->setTitle(txt);
132 sprintf(txt,
"ETOW-decision: #cluster ET>%.2f GeV / event ; x: # ETOW towers; y: counts",par_clusterEtThres);
133 hA[4]->setTitle(txt);
135 sprintf(txt,
"ETOW-decision: acc cluster ET>%.2f GeV; x:cluster ET(GeV) ; y: counts",par_eventEtThres);
136 hA[4]->setTitle(txt);
140 for (
int index=0; index<EmcDbIndexMax; index++ )
143 if ( x==0 )
continue;
144 if ( !mDb->isETOW(x) )
continue;
145 int sec = x->sec - 1;
148 int eta = x->eta - 1;
149 int phi = EtowGeom::mxSubs *sec + sub;
150 int tow = EtowGeom::mxEtaBin *phi + eta;
152 if (tow<0 || tow>mxEtow || rdo<0 || rdo>mxEtow)
return -101;
154 mTower2rdo[ tow ] = rdo;
155 mRdo2tower[ rdo ] = tow;
164 L2eemcGamma2012::countNonZeroTow(
int phi,
int eta) {
165 int tow = EtowGeom::mxEtaBin *((phi+EtowGeom::mxPhiBin)%EtowGeom::mxPhiBin) + ((eta+EtowGeom::mxEtaBin)%EtowGeom::mxEtaBin);
166 const int maxTowers = EtowGeom::mxEtaBin * EtowGeom::mxPhiBin;
170 if (etow_used[tow]==0) {
171 if(wrkEtow_et[tow]!=0) count++;
175 towPlusOne%= maxTowers;
176 if (etow_used[towPlusOne]==0) {
177 if(wrkEtow_et[towPlusOne]!=0) count++;
180 tow+=EtowGeom::mxEtaBin;
182 if (etow_used[tow]==0) {
183 if(wrkEtow_et[tow]!=0) count++;
187 towPlusOne%= maxTowers;
188 if (etow_used[towPlusOne]==0) {
189 if(wrkEtow_et[towPlusOne]!=0) count++;
198 L2eemcGamma2012::flagUsed(
int phi,
int eta) {
199 int tow = EtowGeom::mxEtaBin *((phi+EtowGeom::mxPhiBin)%EtowGeom::mxPhiBin) + ((eta+EtowGeom::mxEtaBin)%EtowGeom::mxEtaBin);
200 const int maxTowers = EtowGeom::mxEtaBin * EtowGeom::mxPhiBin;
205 towPlusOne%= maxTowers;
206 etow_used[towPlusOne] = 1;
208 tow+=EtowGeom::mxEtaBin;
213 towPlusOne%= maxTowers;
214 etow_used[towPlusOne] = 1;
220 L2eemcGamma2012::averageEtaPhi(
int phi,
int eta,
float *avePhi,
float *aveEta) {
221 int tow = EtowGeom::mxEtaBin *((phi+EtowGeom::mxPhiBin)%EtowGeom::mxPhiBin) + ((eta+EtowGeom::mxEtaBin)%EtowGeom::mxEtaBin);
222 const int maxTowers = EtowGeom::mxEtaBin * EtowGeom::mxPhiBin;
228 ETsum=wrkEtow_et[tow];
229 etaSum = wrkEtow_et[tow]*(float)eta;
230 phiSum = wrkEtow_et[tow]*(float)phi;
233 towPlusOne%= maxTowers;
234 ETsum+=wrkEtow_et[towPlusOne];
235 etaSum += wrkEtow_et[towPlusOne]*(float)(eta+1);
236 phiSum += wrkEtow_et[towPlusOne]*(float)phi;
238 tow+=EtowGeom::mxEtaBin;
240 ETsum+=wrkEtow_et[tow];
241 etaSum += wrkEtow_et[tow]*(float)eta;
242 phiSum += wrkEtow_et[tow]*(float)(phi+1);
245 towPlusOne%= maxTowers;
246 ETsum+=wrkEtow_et[towPlusOne];
247 etaSum += wrkEtow_et[towPlusOne]*(float)(eta+1);
248 phiSum += wrkEtow_et[towPlusOne]*(float)(phi+1);
251 *aveEta = etaSum/ETsum;
252 *avePhi = phiSum/ETsum;
259 L2eemcGamma2012::sumET(
int phi,
int eta) {
260 int tow = EtowGeom::mxEtaBin *((phi+EtowGeom::mxPhiBin)%EtowGeom::mxPhiBin) + ((eta+EtowGeom::mxEtaBin)%EtowGeom::mxEtaBin);
262 const int maxTowers = EtowGeom::mxEtaBin * EtowGeom::mxPhiBin;
266 if (etow_used[tow]==0) {
270 towPlusOne%= maxTowers;
271 if (etow_used[towPlusOne]==0) {
272 sum+=wrkEtow_et[towPlusOne];
275 tow+=EtowGeom::mxEtaBin;
277 if (etow_used[tow]==0) {
278 sum+=wrkEtow_et[tow];
281 towPlusOne%= maxTowers;
282 if (etow_used[towPlusOne]==0) {
283 sum+=wrkEtow_et[towPlusOne];
307 const int hitSize=mEveStream_etow[token].get_hitSize();
308 for(i=0;i< hitSize;i++,hit++) {
310 int tower=mRdo2tower[hit->rdo];
311 wrkEtow_tower_index[i]=tower;
312 wrkEtow_et[tower]=hit->et;
316 hA[2]->fill(hitSize);
319 quickSort(wrkEtow_tower_index,0,hitSize-1);
323 for(i=hitSize-1;i >= 0; i--) {
324 if(wrkEtow_et[wrkEtow_tower_index[i]] < par_seedEtThres) {
328 int seedTow=wrkEtow_tower_index[i];
329 int seedEta=seedTow%EtowGeom::mxEtaBin;
330 int seedPhi=seedTow/EtowGeom::mxEtaBin;
342 if (etow_used[seedTow]!=0)
continue;
343 wrkEtow_tower_seed_size++;
348 if(seedEta < EtowGeom::mxEtaBin) {
349 maxET = sumET(seedPhi,seedEta);
350 sum=sumET(seedPhi-1,seedEta);
357 sum=sumET(seedPhi-1,seedEta-1);
362 sum=sumET(seedPhi,seedEta-1);
369 if(maxET<par_clusterEtThres)
continue;
372 hA[6]->fill((
int)(maxET));
373 hA[7]->fill(seedTow);
374 hA[8]->fill(hitSize-i);
377 hA[11]->fill((
int)wrkEtow_et[seedTow]);
378 hA[12]->fill((
int)(10.*wrkEtow_et[seedTow]/maxET));
380 if(etowEve->size>=L2eemcGammaEvent2012::mxClust)
continue;
381 etowEve->clusterET[etowEve->size]=maxET;
382 etowEve->clusterQuad[etowEve->size]=high_quadrant;
383 etowEve->clusterSeedTow[etowEve->size]=seedTow;
392 if (high_quadrant==0) {
393 numNonZeroTow = countNonZeroTow(seedPhi, seedEta);
394 flagUsed(seedPhi, seedEta);
395 averageEtaPhi(seedPhi, seedEta,&clusterPhi, &clusterEta);
396 }
else if (high_quadrant==1) {
397 numNonZeroTow = countNonZeroTow(seedPhi-1, seedEta);
398 flagUsed(seedPhi-1, seedEta);
399 averageEtaPhi(seedPhi-1, seedEta,&clusterPhi, &clusterEta);
400 }
else if (high_quadrant==2) {
401 numNonZeroTow = countNonZeroTow(seedPhi-1, seedEta-1);
402 flagUsed(seedPhi-1, seedEta-1);
403 averageEtaPhi(seedPhi-1, seedEta-1,&clusterPhi, &clusterEta);
404 }
else if (high_quadrant==3) {
405 numNonZeroTow = countNonZeroTow(seedPhi, seedEta-1);
406 flagUsed(seedPhi, seedEta-1);
407 averageEtaPhi(seedPhi, seedEta-1,&clusterPhi, &clusterEta);
409 hA[13]->fill(numNonZeroTow);
410 etowEve->clusterEta[etowEve->size]=clusterEta;
411 etowEve->clusterPhi[etowEve->size]=clusterPhi;
417 hA[3]->fill(wrkEtow_tower_seed_size);
418 hA[4]->fill(etowEve->size);
422 LOG(DBG,
"dbg=%s, etow-adcL-size=%d\n",getName(),hitSize);
433 L2eemcGamma2012::decisionUser(
int token,
int *myL2Result){
449 if(etowEve->size>= L2eemcGammaEvent2012::mxClust) mhN->fill(5);
450 if(etowEve->isFresh>L2eemcGammaEvent2012::kDataFresh) mhN->fill(6);
453 hA[4]->fill(etowEve->size);
455 for(ic=0;ic<etowEve->size;ic++) {
456 float clustET=etowEve->clusterET[ic];
457 hA[5]->fill((
int)clustET);
458 if(clustET<par_eventEtThres)
continue;
459 hA[6]->fill((
int)clustET);
473 for(ic=0;ic<etowEve->size;ic++) {
474 if(etowEve->clusterET[ic]>maxClusterEt) {
475 maxClusterEt = etowEve->clusterET[ic];
479 if(maxClusterEt>par_eventEtThres) {
480 etowEve->resultBlob.clusterEt=(
unsigned char)(etowEve->clusterET[maxClusterID]*256.0/60.0);
481 etowEve->resultBlob.TowerID=(
unsigned short)etowEve->clusterSeedTow[maxClusterID]+(etowEve->clusterQuad[maxClusterID]<<13);
482 etowEve->resultBlob.meanEtaBin=(
unsigned char)((
int)(etowEve->clusterEta[maxClusterID]*256.0/EtowGeom::mxEtaBin)%256);
483 etowEve->resultBlob.meanPhiBin=(
unsigned char)((
int)(etowEve->clusterPhi[maxClusterID]*256.0/EtowGeom::mxPhiBin)%256);
484 etowEve->resultBlob.isolationSum=(
unsigned char)1;
485 etowEve->resultBlob.Time=(
unsigned char)(mComputeTimeDiff[token]/1000);
486 etowEve->resultBlob.trigger=(
unsigned char)5;
488 etowEve->resultBlob.trigger=(
unsigned char)7;
491 hA[9]->fill(etowEve->clusterQuad[maxClusterID]);
492 hA[10]->fill((
int)etowEve->clusterET[maxClusterID]);
493 if(etowEve->size>= L2eemcGammaEvent2012::mxClust) mhN->fill(15);
501 etowEve->resultBlob.trigger=(
unsigned char)6;
502 etowEve->resultBlob.Time=(
unsigned char)(mComputeTimeDiff[token]/1000);
517 L2eemcGamma2012::finishRunUser() {
521 fprintf(mLogFile,
"finishRunUser-%s bhla bhla\n",getName());
530 L2eemcGamma2012::createHisto() {
534 hA[2]=
new L2Histo(2,
"ETOW-compute: #towers w/ energy /event; x: # ETOW towers; y: counts", 100);
535 hA[3]=
new L2Histo(3,
"ETOW-compute: #seed ....... ", 100);
536 hA[4]=
new L2Histo(4,
"ETOW-decision: #clust ....... ", 50);
538 hA[5]=
new L2Histo(5,
"ETOW-decision: any cluster ; x: ET(GeV)", 30);
539 hA[6]=
new L2Histo(6,
"ETOW-decision: accepted clust ... ; x: ET(GeV)", 30);
541 hA[7]=
new L2Histo(7,
"ETOW: Seed Tower Number", 5000);
542 hA[8]=
new L2Histo(8,
"ETOW: Seed Tower Rank", 20);
543 hA[9]=
new L2Histo(9,
"ETOW: Seed Tower Quadrant", 5);
544 hA[10]=
new L2Histo(10,
"ETOW: Cluster Et Sum GeV", 30);
545 hA[11]=
new L2Histo(11,
"ETOW: Cluster Seed Et GeV", 30);
546 hA[12]=
new L2Histo(12,
"ETOW: 10*Seed Et/Cluster Et GeV", 30);
547 hA[13]=
new L2Histo(13,
"ETOW: # non-zero towers per cluster", 5);
554 L2eemcGamma2012::clearEvent(
int token){
555 memset(wrkEtow_et,0,
sizeof(wrkEtow_et));
556 memset(etow_used,0,
sizeof(etow_used));
557 memset(wrkEtow_tower_seed,0,
sizeof(wrkEtow_tower_seed));
558 wrkEtow_tower_seed_size=0;
562 mEtow[token].isFresh=L2eemcGammaEvent2012::kDataFresh;
570 L2eemcGamma2012::print2(){
572 printf(
"pr2-%s: ---ETOW ADC 2D array, only non-zero\n",getName());
574 for(i=0;i<mxEtow;i++) {
575 if(wrkEtow_et[i]<=0)
continue;
576 int rdo=mTower2rdo[i];
577 float et=wrkEtow_et[i];
578 printf(
" etow: tower=%4d rdo=%4d et=%.3f \n",i,rdo,et);
586 L2eemcGamma2012::print3(){
588 printf(
"pr3-%s: ---seed list, size=%d\n",getName(),wrkEtow_tower_seed_size);
590 for(i=0;i<wrkEtow_tower_seed_size;i++) {
591 int tower=wrkEtow_tower_seed[i];
592 float et=wrkEtow_et[tower];
593 printf(
" etow: i=%4d tower=%4d et=%.3f \n",i,tower,et);
601 L2eemcGamma2012::print4(
int token,
int hitSize){
603 printf(
"print4 IS NOT Fully FUNCTIONAL **********************\n");
604 printf(
"pr1-%s: ---ETOW Sorted ADC list--- size=%d\n",getName(),hitSize);
606 for(i=0;i< hitSize;i++) {
609 float et=wrkEtow_et[wrkEtow_tower_index[i]];
611 printf(
" tower=%2d ",wrkEtow_tower_index[i]);
612 printf(
" etow: i=%2d rdo=%4d adc=%d et=%.3f ene=%.3f\n",i,rdo,adc,et,ene);
void computeUser(int token)