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 "L2bemcGamma2012.h"
31 L2bemcGamma2012::L2bemcGamma2012(
const char* name,
const char *uid,
L2EmcDb2012* db,
L2EmcGeom2012 *geoX,
char* outDir,
int resOff) :
L2VirtualAlgo2012( name, uid, db, outDir, true, false, resOff) {
38 criticalError(
"L2bemcGamma is broken -- can't find geom.");
45 criticalError(
"L2bemcGamma has failed consistency check. sizeof(L2gammaResult2012)!= L2gammaResult2012::mySizeChar");
52 L2bemcGamma2012::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 L2bemcGamma2012::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];
133 tow+=BtowGeom::mxEtaBin;
136 sum+=wrkBtow_et[tow];
139 towPlusOne%= maxTowers;
140 sum+=wrkBtow_et[towPlusOne];
149 L2bemcGamma2012::computeUser(
int token){
163 LOG(DBG,
"token = %d mBtow = 0x%x btowEve=0x%x",token, mBtow, btowEve);
166 const int hitSize=mEveStream_btow[token].get_hitSize();
168 LOG(DBG,
"Hits = %d",hitSize);
170 for(i=0;i< hitSize;i++,hit++) {
171 int tower=mRdo2tower[hit->rdo];
172 wrkBtow_et[tower]=hit->et;
173 if(hit->et<par_seedEtThres)
continue;
174 wrkBtow_tower_seed[wrkBtow_tower_seed_size++]=tower;
176 hA[2]->fill(hitSize);
177 int seedTow=-1,seedEta=-1,seedPhi=-1;
179 btowEve->isFresh=L2bemcGammaEvent2012::kDataFresh;
181 LOG(DBG,
"seed size = %d",wrkBtow_tower_seed_size);
183 for(i=0; i<wrkBtow_tower_seed_size;i++) {
184 seedTow=wrkBtow_tower_seed[i];
185 seedEta=seedTow%BtowGeom::mxEtaBin;
186 seedPhi=seedTow/BtowGeom::mxEtaBin;
189 if (seedEta < BtowGeom::mxEtaBin) {
190 clustET = sumET(seedPhi,seedEta);
191 LOG(DBG,
"clustET1=%f, thresh=%f",clustET, par_clusterEtThres);
193 if(clustET>par_clusterEtThres)
goto ACCEPT;
194 clustET = sumET(seedPhi-1,seedEta);
196 LOG(DBG,
"clustET2=%f, thresh=%f",clustET, par_clusterEtThres);
198 if(clustET>par_clusterEtThres)
goto ACCEPT;
201 clustET = sumET(seedPhi-1,seedEta-1);
203 LOG(DBG,
"clustET3=%f, thresh=%f",clustET, par_clusterEtThres);
205 if(clustET>par_clusterEtThres)
goto ACCEPT;
206 clustET = sumET(seedPhi,seedEta-1);
208 LOG(DBG,
"clustET4=%f, thresh=%f",clustET, par_clusterEtThres);
210 if(clustET>par_clusterEtThres)
goto ACCEPT;
214 btowEve->resultBlob.clusterEt=0;
215 btowEve->resultBlob.meanEtaBin=0;
216 btowEve->resultBlob.meanPhiBin=0;
217 btowEve->resultBlob.trigger=0;
218 btowEve->seedTwID=-1;
219 btowEve->clusterET=0;
224 btowEve->clusterET=clustET;
225 btowEve->seedET=wrkBtow_et[seedTow];
226 btowEve->resultBlob.clusterEt=(
unsigned char)(clustET*256.0/60.0);
227 btowEve->resultBlob.meanEtaBin=seedEta;
228 btowEve->resultBlob.meanPhiBin=seedPhi;
229 btowEve->seedTwID=seedTow;
230 btowEve->resultBlob.trigger=2;
232 LOG(DBG,
"trigger = %d",btowEve->resultBlob.trigger);
242 L2bemcGamma2012::decisionUser(
int token,
int *myL2Result){
249 LOG(DBG,
"token = %d mBtow = 0x%x btowEve=0x%x",token, mBtow, btowEve);
251 LOG(DBG,
"trigger = %d",btowEve->resultBlob.trigger);
253 bool triggerDecision=(btowEve->resultBlob.trigger>0);
256 if (par_RndAcceptPrescale>0) btowEve->resultBlob.trigger+=mRandomAccept;
259 if(btowEve->isFresh>L2bemcGammaEvent2012::kDataFresh) mhN->fill(6);
266 if(btowEve->resultBlob.trigger&2) {
268 hA[6]->fill((
int)btowEve->clusterET);
269 hA[7]->fill(btowEve->seedTwID);
270 hA[11]->fill((
int)btowEve->seedET);
271 hA[12]->fill((
int)(100.*btowEve->seedET/btowEve->clusterET));
274 if(btowEve->resultBlob.trigger&1) mhN->fill(16);
278 return triggerDecision;
285 L2bemcGamma2012::finishRunUser() {
289 fprintf(mLogFile,
"finishRunUser-%s bhla bhla\n",getName());
292 const int *hist15Data = hA[7]->getData();
293 for (
int i = 0; i < BtowGeom::mxEtaBin; i++) {
294 for (
int j = 0; j < BtowGeom::mxPhiBin; j++) {
295 hA[14]->fillW(i,j, hist15Data[i+j*BtowGeom::mxEtaBin]);
305 L2bemcGamma2012::createHisto() {
309 hA[2]=
new L2Histo(2,
"BTOW-compute: #towers w/ energy /event; x: # BTOW towers; y: counts", 100);
310 hA[6]=
new L2Histo(6,
"BTOW-decision: accepted clust ... ; x: ET(GeV)", 30);
312 hA[7]=
new L2Histo(7,
"BTOW: accepted Seed Tower .....", 5000);
313 hA[11]=
new L2Histo(11,
"BTOW: decision Cluster Seed Et; ET GeV", 30);
314 hA[12]=
new L2Histo(12,
"BTOW: decision ;100*Seed Et/Cluster Et", 100);
316 hA[14]=
new L2Histo(14,
"BTOW: hot tower projection", BtowGeom::mxEtaBin, BtowGeom::mxPhiBin);
323 L2bemcGamma2012::clearEvent(
int token){
324 memset(wrkBtow_et,0,
sizeof(wrkBtow_et));
325 wrkBtow_tower_seed_size=0;
332 L2bemcGamma2012::print2(){
334 printf(
"pr2-%s: ---BTOW ADC 2D array, only non-zero\n",getName());
336 for(i=0;i<mxBtow;i++) {
337 if(wrkBtow_et[i]<=0)
continue;
338 int rdo=mTower2rdo[i];
339 float et=wrkBtow_et[i];
340 printf(
" btow: tower=%4d rdo=%4d et=%.3f \n",i,rdo,et);
348 L2bemcGamma2012::print3(){
350 printf(
"pr3-%s: ---seed list, size=%d\n",getName(),wrkBtow_tower_seed_size);
352 for(i=0;i<wrkBtow_tower_seed_size;i++) {
353 int tower=wrkBtow_tower_seed[i];
354 float et=wrkBtow_et[tower];
355 printf(
" btow: i=%4d tower=%4d et=%.3f \n",i,tower,et);
365 L2bemcGamma2012::print4(
int token,
int hitSize){
367 printf(
"print4 IS NOT Fully FUNCTIONAL **********************\n");
368 printf(
"pr1-%s: ---BTOW Sorted ADC list--- size=%d\n",getName(),hitSize);
370 for(i=0;i< hitSize;i++) {
373 float et=wrkBtow_et[wrkBtow_tower_index[i]];
375 printf(
" tower=%2d ",wrkBtow_tower_index[i]);
376 printf(
" btow: i=%2d rdo=%4d adc=%d et=%.3f ene=%.3f\n",i,rdo,adc,et,ene);