16 #ifdef IS_REAL_L2 //in l2-ana environment
17 #include "../L2algoUtil/L2EmcDb.h"
18 #include "../L2algoUtil/L2Histo.h"
19 #else //full path needed for cvs'd code
20 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcDb.h"
21 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2Histo.h"
22 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcGeom.h"
25 #include "L2bemcGamma2009.h"
30 L2bemcGamma2009::L2bemcGamma2009(
const char* name,
L2EmcDb* db,
L2EmcGeom *geoX,
char* outDir,
int resOff) :
L2VirtualAlgo2009( name, db, outDir, true, false, resOff) {
37 criticalError(
"L2bemcGamma is broken -- can't find geom.");
45 criticalError(
"L2bemcGamma has failed consistency check. sizeof(L2gammaResult2009)!= L2gammaResult2009::mySizeChar");
52 L2bemcGamma2009::initRunUser(
int runNo,
int *rc_ints,
float *rc_floats) {
56 par_RndAcceptPrescale = rc_ints[1];
57 par_seedEtThres = rc_floats[0];
58 par_clusterEtThres = rc_floats[1];
62 kBad+=0x00001 * (par_seedEtThres<1.0);
63 kBad+=0x00002 * (par_clusterEtThres<par_seedEtThres);
67 fprintf(mLogFile,
"L2%s algorithm initRun(R=%d), compiled: %s , %s\n params:\n",
68 getName(),mRunNumber,__DATE__,__TIME__);
69 fprintf(mLogFile,
" - use seedThres=%.2f (GeV), debug=%d, prescale=%d (0=off,1=100proc, 2=50proc, etc)\n",
70 par_seedEtThres,par_dbg,par_RndAcceptPrescale);
71 fprintf(mLogFile,
" - accept event cluster Thres=%.2f (GeV)\n",
73 fprintf(mLogFile,
"initRun() params checked for consistency, Error flag=0x%04x\n",
79 for (i=0; i<mxHA;i++)
if(hA[i])hA[i]->reset();
80 memset(mBtow,0,
sizeof(mBtow));
82 if(kBad>0)
return -1*kBad;
83 else if(kBad<0)
return kBad;
89 sprintf(txt,
"BTOW-decision: acc seed Tw ET>%.2f GeV; x:tower internal ID; y: counts",par_clusterEtThres);
91 sprintf(txt,
"#BTOW decision acc seed Tw, Et>%.2f GeV; eta bin [-1,+1]; y: phi bin ~ TCP sector",par_clusterEtThres);
92 hA[14]->setTitle(txt);
95 for (
int index=0; index<EmcDbIndexMax; index++ )
99 if ( !mDb->isBTOW(x) )
continue;
100 int sec = x->sec - 1;
103 int eta = x->eta - 1;
104 int phi = BtowGeom::mxSubs *sec + sub;
105 int tow = BtowGeom::mxEtaBin *phi + eta;
107 if (tow<0 || tow>mxBtow || rdo<0 || rdo>mxBtow)
return -101;
109 mTower2rdo[ tow ] = rdo;
110 mRdo2tower[ rdo ] = tow;
121 L2bemcGamma2009::sumET(
int phi,
int eta) {
122 int tow = BtowGeom::mxEtaBin *((phi+BtowGeom::mxPhiBin)%BtowGeom::mxPhiBin) + ((eta+BtowGeom::mxEtaBin)%BtowGeom::mxEtaBin);
124 const int maxTowers = BtowGeom::mxEtaBin * BtowGeom::mxPhiBin;
130 towPlusOne%= maxTowers;
131 sum+=wrkBtow_et[towPlusOne];
136 tow+=BtowGeom::mxEtaBin;
139 sum+=wrkBtow_et[tow];
142 towPlusOne%= maxTowers;
143 sum+=wrkBtow_et[towPlusOne];
156 L2bemcGamma2009::computeUser(
int token){
171 const int hitSize=mEveStream_btow[token].get_hitSize();
172 for(i=0;i< hitSize;i++,hit++) {
173 int tower=mRdo2tower[hit->rdo];
174 wrkBtow_et[tower]=hit->et;
175 if(hit->et<par_seedEtThres)
continue;
176 wrkBtow_tower_seed[wrkBtow_tower_seed_size++]=tower;
179 hA[2]->fill(hitSize);
180 int seedTow=-1,seedEta=-1,seedPhi=-1;
182 btowEve->isFresh=L2bemcGammaEvent2009::kDataFresh;
186 for(i=0; i<wrkBtow_tower_seed_size;i++) {
187 seedTow=wrkBtow_tower_seed[i];
188 seedEta=seedTow%BtowGeom::mxEtaBin;
189 seedPhi=seedTow/BtowGeom::mxEtaBin;
192 if (seedEta < BtowGeom::mxEtaBin) {
193 clustET = sumET(seedPhi,seedEta);
194 if(clustET>par_clusterEtThres)
goto ACCEPT;
195 clustET = sumET(seedPhi-1,seedEta);
196 if(clustET>par_clusterEtThres)
goto ACCEPT;
199 clustET = sumET(seedPhi-1,seedEta-1);
200 if(clustET>par_clusterEtThres)
goto ACCEPT;
201 clustET = sumET(seedPhi,seedEta-1);
202 if(clustET>par_clusterEtThres)
goto ACCEPT;
206 btowEve->resultBlob.clusterEt=0;
207 btowEve->resultBlob.meanEtaBin=0;
208 btowEve->resultBlob.meanPhiBin=0;
209 btowEve->resultBlob.trigger=0;
210 btowEve->seedTwID=-1;
211 btowEve->clusterET=0;
217 btowEve->clusterET=clustET;
218 btowEve->seedET=wrkBtow_et[seedTow];
219 btowEve->resultBlob.clusterEt=(
unsigned char)(clustET*256.0/60.0);
220 btowEve->resultBlob.meanEtaBin=seedEta;
221 btowEve->resultBlob.meanPhiBin=seedPhi;
222 btowEve->seedTwID=seedTow;
223 btowEve->resultBlob.trigger=2;
233 L2bemcGamma2009::decisionUser(
int token,
int *myL2Result){
240 bool triggerDecision=(btowEve->resultBlob.trigger>0);
243 if (par_RndAcceptPrescale>0) btowEve->resultBlob.trigger+=mRandomAccept;
246 if(btowEve->isFresh>L2bemcGammaEvent2009::kDataFresh) mhN->fill(6);
250 if(btowEve->resultBlob.trigger&2) {
252 hA[6]->fill((
int)btowEve->clusterET);
253 hA[7]->fill(btowEve->seedTwID);
254 hA[11]->fill((
int)btowEve->seedET);
255 hA[12]->fill((
int)(100.*btowEve->seedET/btowEve->clusterET));
258 if(btowEve->resultBlob.trigger&1) mhN->fill(16);
261 return triggerDecision;
268 L2bemcGamma2009::finishRunUser() {
272 fprintf(mLogFile,
"finishRunUser-%s bhla bhla\n",getName());
275 const int *hist15Data = hA[7]->getData();
276 for (
int i = 0; i < BtowGeom::mxEtaBin; i++) {
277 for (
int j = 0; j < BtowGeom::mxPhiBin; j++) {
279 hA[14]->fillW(i,j, hist15Data[i+j*BtowGeom::mxEtaBin]);
289 L2bemcGamma2009::createHisto() {
293 hA[2]=
new L2Histo(2,
"BTOW-compute: #towers w/ energy /event; x: # BTOW towers; y: counts", 100);
294 hA[6]=
new L2Histo(6,
"BTOW-decision: accepted clust ... ; x: ET(GeV)", 30);
296 hA[7]=
new L2Histo(7,
"BTOW: accepted Seed Tower .....", 5000);
297 hA[11]=
new L2Histo(11,
"BTOW: decision Cluster Seed Et; ET GeV", 30);
298 hA[12]=
new L2Histo(12,
"BTOW: decision ;100*Seed Et/Cluster Et", 100);
300 hA[14]=
new L2Histo(14,
"BTOW: hot tower projection", BtowGeom::mxEtaBin, BtowGeom::mxPhiBin);
308 L2bemcGamma2009::clearEvent(
int token){
309 memset(wrkBtow_et,0,
sizeof(wrkBtow_et));
310 wrkBtow_tower_seed_size=0;
317 L2bemcGamma2009::print2(){
319 printf(
"pr2-%s: ---BTOW ADC 2D array, only non-zero\n",getName());
321 for(i=0;i<mxBtow;i++) {
322 if(wrkBtow_et[i]<=0)
continue;
323 int rdo=mTower2rdo[i];
324 float et=wrkBtow_et[i];
325 printf(
" btow: tower=%4d rdo=%4d et=%.3f \n",i,rdo,et);
333 L2bemcGamma2009::print3(){
335 printf(
"pr3-%s: ---seed list, size=%d\n",getName(),wrkBtow_tower_seed_size);
337 for(i=0;i<wrkBtow_tower_seed_size;i++) {
338 int tower=wrkBtow_tower_seed[i];
339 float et=wrkBtow_et[tower];
340 printf(
" btow: i=%4d tower=%4d et=%.3f \n",i,tower,et);
350 L2bemcGamma2009::print4(
int token,
int hitSize){
352 printf(
"print4 IS NOT Fully FUNCTIONAL **********************\n");
353 printf(
"pr1-%s: ---BTOW Sorted ADC list--- size=%d\n",getName(),hitSize);
355 for(i=0;i< hitSize;i++) {
358 float et=wrkBtow_et[wrkBtow_tower_index[i]];
360 printf(
" tower=%2d ",wrkBtow_tower_index[i]);
361 printf(
" btow: i=%2d rdo=%4d adc=%d et=%.3f ene=%.3f\n",i,rdo,adc,et,ene);