StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
L2adc2energyAlgo.cxx
1 #include <stdio.h>
2 #include <assert.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <time.h>
6 #include <math.h>
7 
8 /*********************************************************************
9  * $Id: L2adc2energyAlgo.cxx,v 1.2 2009/11/19 15:48:45 balewski Exp $
10  * \author Jan Balewski, IUCF, 2006
11  *********************************************************************
12  * Descripion:
13  Reco of mono- & di-jets in L2 using BTOW+ETOW
14  depends on L2-DB class
15  *********************************************************************
16  */
17 
18 
19 
20 #ifdef IS_REAL_L2 //in l2-ana environment
21  #include "../L2algoUtil/L2EmcDb.h"
22  #include "../L2algoUtil/L2Histo.h"
23 #else
24  #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcDb.h"
25  #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2Histo.h"
26 #endif
27 
28 #include "L2adc2energyAlgo.h"
29 #include "Map_DeltaPhiJets.h"
30 
31 //=================================================
32 //=================================================
33 L2adc2energyAlgo::L2adc2energyAlgo(const char* name, L2EmcDb* db, char* outDir, int resOff)
34  : L2VirtualAlgo( name, db, outDir, resOff) {
35  /* called one per days
36  all memory allocation must be done here
37  */
38  par_maxADC=4095;
39  par_maxEt=60;
40  par_adcMask= (unsigned short) (-0x10); // to clear 4 LSF bits
41  par_pedOff=0x10/2; //WARN, must match 'par_adcMask'
42  createHisto();
43  run_number=-1;
44  printf("L2adc2energyAlgo instantiated, logPath='%s'\n",mOutDir);
45 }
46 
47 /*========================================
48  ======================================== */
49 bool
50 L2adc2energyAlgo::paramsChanged( int *rc_ints, float *rc_floats) {
51  int i;
52  for(i=0;i<5;i++)
53  if(rc_ints[i]!=raw_ints[i]) goto foundProblem;
54 
55  for(i=0;i<5;i++)
56  if(fabs(rc_floats[i]-raw_floats[i])>0.00001) goto foundProblem;
57 
58  return false;
59 
60  foundProblem:
61  if (mLogFile) fprintf(mLogFile,"L2jet-ghost initRun - inconsistent params, ABORT initialization\n");
62  return true;
63 }
64 
65 /*========================================
66  ======================================== */
67 int
68 L2adc2energyAlgo::initRun( int runNo, int *rc_ints, float *rc_floats) {
69 
70  // update DB if run # has changed
71  if(mDb->initRun(runNo)) return -7;
72  // DB must be initialized prior to lookup tables
73 
74  if(run_number==runNo) {
75  if (mLogFile) fprintf(mLogFile,"L2jet::initRun-%s(%d)=ghost already initilized, only check params\n",mName, runNo);
76  printf("L2jet::initRun-%s(%d)=ghost already initilized, only checking params\n",mName, runNo);
77  int ret= paramsChanged(rc_ints, rc_floats);
78  // 0=ok, 1=fatal problem
79  if(ret){
80  run_number=-77;
81  if (mLogFile) {
82  fprintf(mLogFile,"L2jet algorithm init: crashA in internal logic\n");
83  fclose(mLogFile);
84  }
85  return ret;
86  }
87  }
88 
89  // clear content of all histograms
90  int i;
91  for (i=0; i<mxHA;i++) if(hA[i])hA[i]->reset();
92 
93  /* .... clear content, set threshold @ max as default */
94  memset(db_btowThr, 0xFFFF,sizeof(db_btowThr));
95  memset(db_btowPedS, 0, sizeof(db_btowPedS));
96  memset(db_btowGainCorr, 0, sizeof(db_btowGainCorr));
97  memset(db_btowL2PhiBin, 0, sizeof(db_btowL2PhiBin));
98  memset(db_btowL2PatchBin,0, sizeof(db_btowL2PatchBin));
99 
100  memset(db_etowThr, 0xFFFF,sizeof(db_etowThr));
101  memset(db_etowPedS, 0 ,sizeof(db_etowPedS));
102  memset(db_etowGainCorr, 0 ,sizeof(db_etowGainCorr));
103  memset(db_etowL2PhiBin, 0 ,sizeof(db_etowL2PhiBin));
104  memset(db_etowL2PatchBin,0 ,sizeof(db_etowL2PatchBin));
105 
106  /* gain correction factor is mapped to 6 bits,
107  range: [5,60]
108  WARN: do NOT change 3 params below w/o understaning of
109  projection algo,JB
110  */
111 
112  int par_IgainCorrOne=30;
113  int par_IgainCorrMin=5;
114  int par_IgainCorrMax=60;
115 
116  run_startUnix=time(0);
117  run_number =runNo; // serves as a flag this run is initialized
118  raw_ints =rc_ints;
119  raw_floats =rc_floats;
120  run_nEventOneJet=run_nEventDiJet= run_nEventRnd=0;
121 
122  char Fname[1000];
123  sprintf(Fname,"%s/run%d.l2jet.out",mOutDir,run_number);
124  printf("L2jet::initRun-%s('%s') ...\n",mName,Fname);
125 
126  mEventsInRun=0;
127  mLogFile = fopen(Fname,"w");
128  if( mLogFile==0) printf(" L2adc2energyAlgo() UNABLE to open run summary log file, continue anyhow\n");
129  // mLogFile = stdout; //tmp
130 
131  // unpack params from run control GUI
132  par_cutTag = rc_ints[0];
133  par_useBtowEast= (rc_ints[1]&1 )>0;
134  par_useBtowWest= (rc_ints[1]&2)>0;
135  par_useEndcap = rc_ints[2]&1;
136  int par_adcThr = rc_ints[3]; // needed only in initRun()
137  par_minPhiBinDiff=rc_ints[4];
138 
139  par_oneJetThr = rc_floats[0];
140  par_diJetThrHigh= rc_floats[1];
141  par_diJetThrLow = rc_floats[2];
142  par_rndAccProb = rc_floats[3];
143  par_dbg =(int)rc_floats[4];
144 
145  // set other hardcoded or calculated params
146  par_energyScale=par_maxADC*par_IgainCorrOne/par_maxEt;
147  // to monitor hot towers in E+B Emc
148  float monTwEtThr=2.0; // (GeV) Et threshold,WARN, edit histo title by hand
149  par_hotTwEtThr= (int)(monTwEtThr*par_energyScale); // now it is integer4 energy
150  // thres for rnd accept
151  par_rndAccThr= int(par_rndAccProb* RAND_MAX);
152  if(par_rndAccProb<0) {
153  par_rndAccThr=0;
154  par_rndAccProb=0.;
155  } else if (par_rndAccProb>0.9999) {
156  par_rndAccThr=RAND_MAX;
157  par_rndAccProb=1.0;
158  }
159  if (mLogFile) {
160  fprintf(mLogFile,"L2jet algorithm initRun(%d), compiled: %s , %s\n params:\n",run_number,__DATE__,__TIME__);
161  fprintf(mLogFile," - use BTOW: East=%d West=%d, Endcap=%d L2ResOffset=%d\n", par_useBtowEast, par_useBtowWest,par_useEndcap ,mResultOffset);
162  fprintf(mLogFile," - threshold: ADC-ped> %d \n", par_adcThr);
163  fprintf(mLogFile," - min phi opening angle Jet1<->Jet2: %d in L2phiBins\n",par_minPhiBinDiff);
164  fprintf(mLogFile," - diJet Et thrHigh= %.2f (GeV) thrLow= %.2f (GeV)\n", par_diJetThrHigh, par_diJetThrLow);
165  fprintf(mLogFile," - oneJet Et thr = %.2f (GeV) ; rndAccProb=%f; cutTag=%d \n",par_oneJetThr,par_rndAccProb,par_cutTag);
166  fprintf(mLogFile," - debug=%d, hot tower threshold: Et> %.1f GeV ( only monitoring)\n",par_dbg, monTwEtThr);
167  }
168 
169  // verify consistency of input params
170  int kBad=0;
171  kBad+=0x0001 * ( !par_useBtowEast & !par_useBtowWest & !par_useEndcap);
172  kBad+=0x0002 * (par_adcThr<par_pedOff);
173  kBad+=0x0004 * (par_adcThr>16);
174  kBad+=0x0008 * (par_minPhiBinDiff<5);
175  kBad+=0x0010 * (par_minPhiBinDiff>=15);
176  kBad+=0x0020 * (par_oneJetThr<3.);
177  kBad+=0x0040 * (par_oneJetThr>12.);
178  kBad+=0x0080 * (par_diJetThrLow<2.9);
179  kBad+=0x0100 * (par_diJetThrHigh<par_diJetThrLow);
180  kBad+=0x0200 * (par_diJetThrHigh>12.);
181  kBad+=0x0400 * (par_cutTag<=0 || par_cutTag>255);
182  kBad+=0x0800 * (par_rndAccProb<0. || par_rndAccProb>1.);
183  if (mLogFile) {
184  fprintf(mLogFile,"L2jet initRun() params checked for consistency, Error flag=0x%04x\n",kBad);
185  if(kBad) fprintf(mLogFile,"L2jet initRun() ABORT\n");
186  }
187 
188  if(kBad) {
189  run_number=-66;
190  if (mLogFile) {
191  fprintf(mLogFile,"L2jet algorithm init: crashB in internal logic\n");
192  fclose(mLogFile);
193  return kBad;
194  }
195  }
196 
197  char tit[100];
198  sprintf(tit,"# BTOW towers>ped+%d (input); x: # of towers/event",par_adcThr);
199  hA[47]->setTitle(tit);
200 
201  sprintf(tit,"# ETOW towers>ped+%d (input); x: # of towers/event",par_adcThr);
202  hA[48]->setTitle(tit);
203 
204  /* const float eta[mxEta]={1.95,1.855,1.765,1.675,1.59,1.51,1.435,1.365,1.3,1.235,1.17,1.115}; */
205 
206  /* the first 13 entries mark the bounds of the 12 eta Bins. 14th value is not used */
207  const float edgeEtaBinEtow[] = {
208  2.0 ,
209  1.9008 , 1.8065 , 1.7168 , 1.6317 , 1.5507 , 1.4738 ,
210  1.4007 , 1.3312 , 1.2651 , 1.2023 , 1.1427 , 1.086 ,
211  0.0
212  };
213 
214  const int mxEtaBinsE=12,mxEtaBinsB=40;
215  float idealGainEtow[mxEtaBinsE], idealGainBtow[mxEtaBinsB];
216  float coshEtow[mxEtaBinsE],coshBtow[mxEtaBinsB];
217 
218  for(i=0;i<mxEtaBinsE;i++ ){
219  float avrEta=(edgeEtaBinEtow[i]+edgeEtaBinEtow[i+1])/2.;
220  coshEtow[i]=cosh(avrEta);
221  idealGainEtow[i]=par_maxADC/par_maxEt/coshEtow[i];
222  // if (mLogFile && i%4==0) fprintf(mLogFile,"aim: ETow iEtaBin=%d eta=%.3f idealG=%.2f (GeV E_T), cosH=%.3f\n",i,avrEta, idealGainEtow[i], coshEtow[i]);
223  }
224 
225 
226  for(i=0;i<mxEtaBinsB;i++ ){
227  float avrEta=-0.975 +i*0.05; /* assume BTOW has fixed eta bin size */
228  coshBtow[i]=cosh(avrEta);
229  idealGainBtow[i]=par_maxADC/par_maxEt/coshBtow[i];
230  // if (mLogFile && i%4==0) fprintf(mLogFile,"aim: Btow iEtaBin=%2d eta=%.3f idealG=%.2f (GeV E_T), cosH=%.3f\n",i,avrEta, idealGainBtow[i], coshBtow[i]);
231  }
232 
233 
234  // rebuild local lookup tables
235 
236  int etowEtaBin2Patch[mxEtaBinsE]={14,14,13,13,12,12,11,11,11,10,10,10};
237 
238  int nB=0, nE=0; /* counts # of unmasekd towers */
239  int nBg=0, nEg=0; /* counts # of reasonable calibrated towers */
240 
241  for(i=0; i<EmcDbIndexMax; i++) {
242  const L2EmcDb::EmcCDbItem *x=mDb->getByIndex(i);
243  if(mDb->isEmpty(x)) continue; /* dropped not mapped channels */
244  if(x->fail) continue; /* dropped masked channels */
245  if(x->gain<=0) continue; /* dropped uncalibrated towers , tmp */
246  /* if(x->sec!=1) continue; tmp, to test patch mapping */
247 
248  /* WARN, calculate index to match RDO order in the ADC data banks */
249  int ietaP, iphiP;
250  if (mDb->isBTOW(x) ) {
251  /*....... B A R R E L .................*/
252  nB++;
253  if(x->eta<0 || x->eta>mxEtaBinsB) goto crashIt_1;
254  if(!par_useBtowEast && x->eta<=20) continue;
255  if(!par_useBtowWest && x->eta>=21) continue;
256  ietaP= (x->eta-1)/4; /* correct */
257  int iphiTw=(x->sec-1)*10 + x->sub-'a';
258  // allign in phi TP @ L2 w/ L0
259  iphiTw--;
260  if(iphiTw<0) iphiTw=119;
261  // now cr0x1e, mod1, subm2, is beginning of the first BTOW TP
262  iphiP= iphiTw/4 ; /* correct */
263  // if(ietaP==0 && iphiP==5)
264  //if( (iphiTw==21 || iphiTw==22) && x->eta<=4) printf("%s %s ietaP=%d iPhiP=%d cr0x%02x ch=%03d\n",x->name, x->tube,ietaP, iphiP,x->crate,x->chan);
265  int IgainCor=int(par_IgainCorrOne*idealGainBtow[x->eta-1]/x->gain);
266  //printf("%s IgainCor=%d\n",x->name,IgainCor);
267  /* gain outliers ignored */
268  if(IgainCor <par_IgainCorrMin) continue;
269  if(IgainCor >par_IgainCorrMax) continue;
270  db_btowGainCorr[x->rdo]=IgainCor;
271 
272  db_btowL2PhiBin[x->rdo]=iphiP;
273  db_btowL2PatchBin[x->rdo]=ietaP+ iphiP*cl2jetMaxEtaBins;
274  db_btowThr[x->rdo]=(int) (x->ped+par_adcThr);
275  db_btowPedS[x->rdo]=(unsigned short) (par_pedOff-x->ped);
276  nBg++;
277  } else if(mDb->isETOW(x) && par_useEndcap) {
278  /*....... E N D C A P ........................*/
279  nE++;
280  int iphiTw= (x->sec-1)*5 + x->sub-'A';
281  // allign in phi TP @ L2 w/ L0
282  iphiTw--;
283  if(iphiTw<0) iphiTw=59;
284  // now subsector 01TB is beginning of the first(==0) ETOW TP in phi
285  iphiP= iphiTw/2 ; /* correct */
286  if(x->eta<0 || x->eta>mxEtaBinsE) goto crashIt_1;
287  ietaP=etowEtaBin2Patch[x->eta-1];
288  //printf("%s %s ietaP=%d iPhiP=%d\n",x->name, x->tube,ietaP, iphiP);
289  int IgainCor=int(par_IgainCorrOne*idealGainEtow[x->eta-1]/x->gain);
290  // printf("%s IgainCor=%d\n",x->name,IgainCor);
291  /* gain outliers ignored */
292  if(IgainCor <par_IgainCorrMin) continue;
293  if(IgainCor >par_IgainCorrMax) continue;
294  db_etowGainCorr[x->rdo]=IgainCor;
295 
296  db_etowL2PhiBin[x->rdo]=iphiP;
297  db_etowL2PatchBin[x->rdo]=ietaP+ iphiP*cl2jetMaxEtaBins;
298  db_etowThr[x->rdo]=(int) (x->ped+par_adcThr);
299  db_etowPedS[x->rdo]=(unsigned short) (par_pedOff-x->ped);
300  nEg++;
301  }
302 
303  }
304 
305  if (mLogFile) {
306  fprintf(mLogFile,"L2jet algorithm: found working/calibrated: %d/%d=ETOW & %d/%d=BTOW, based on ASCII DB\n",nE,nEg,nB,nBg);
307  }
308 
309  return 0; //OK
310 
311  crashIt_1: /* fatal initialization error */
312  run_number=-55;
313  if (mLogFile) {
314  fprintf(mLogFile,"L2jet algorithm init: crashC in internal logic\n");
315  fclose(mLogFile);
316  }
317  return -6;
318 
319 }
320 
321 
322 /*========================================
323  ======================================== */
324 bool
325 L2adc2energyAlgo::doEvent(int L0trg, int inpEveId, TrgDataType* trgData,
326  int bemcIn, unsigned short *bemcData,
327  int eemcIn, unsigned short *eemcData){
328  /* STRICT TIME BUDGET START ....*/
329  rdtscl_macro(mEveTimeStart);
330 
331  if(L0trg==1) hA[10]->fill(1);
332  else if(L0trg==2) hA[10]->fill(2);
333 
334  if(eve_ID!=inpEveId) {//UUUU
335  //.................... this event has NOT been processed
336 
337  /*
338  Chris doesn't want us to write out anything
339  during event processing ...
340  */
341 
342  eve_ID=inpEveId; // every events is processed only once
343  mEventsInRun++;
344  clearEvent(); /* price=13 kTicks */
345  int runTimeSec=time(0)- run_startUnix;
346  hA[10]->fill(0);
347  hA[12]->fill(runTimeSec);
348 
349  if(par_dbg>1) printf("\n......... in L2adc2E_doEvent(ID=%d)... bIn=%d eIn=%d\n",eve_ID,bemcIn,eemcIn);
350 
351  if (bemcIn || eemcIn){//VVVV this algo has nothing to do w/o any Ecal data
352 
353 
354  //===== step 1: unpack raw data blocks ==============
355 
356  int nBtowTw=0, nEtowTw=0;
357  /*......... BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB */
358  if(bemcIn==1 && (par_useBtowEast||par_useBtowWest) ) {
359  nBtowTw=projectAdc( bemcData, MaxBtowRdo,
360  db_btowThr, db_btowPedS, db_btowGainCorr,
361  db_btowL2PhiBin, db_btowL2PatchBin,
362  hA[20] );
363  }
364 
365  /*........... EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE */
366  if(eemcIn==1 && par_useEndcap ) {
367  nEtowTw=projectAdc( eemcData, 720,
368  db_etowThr, db_etowPedS, db_etowGainCorr,
369  db_etowL2PhiBin, db_etowL2PatchBin,
370  hA[30] );
371  }
372 
373 
374  mAccept=true;
375 
376  if( mAccept) hA[10]->fill(8);
377 
378 
379  //====== step 6: fill L2Result (except time)
380  //nn removed
381 
382  rdtscl_macro(mEveTimeStop);
383  mEveTimeDiff=mEveTimeStop-mEveTimeStart;
384  int kTick=mEveTimeDiff/1000;
385  // printf("jj=%f t1=%d t2=%d \n",mEveTimeDiff/1000.,mEveTimeStart,mEveTimeStop);
386  mhT->fill(kTick);
387 
388 
389  if(par_dbg){//WWWW
390 
391  } // end of WWW
392 
393  }// end of VVVV (etow or btow has some data)
394  }// end of UUUU event processing
395 
396 
397  return mAccept;
398 }
399 
400 
401 /*========================================
402  ======================================== */
403 void
404 L2adc2energyAlgo::finishRun() { /* called once at the end of the run */
405  if(run_number<0) return; // already finished
406  // save run summary histos
407  char Fname[1000];
408  sprintf(Fname,"%s/run%d.l2adc2E.hist.bin",mOutDir,run_number);
409  printf("L2jet::finishRun('%s') , save histo ...\n",Fname);
410  mHistFile = fopen(Fname,"w");
411 
412  if (mLogFile) {
413  fprintf(mLogFile,"L2-jet algorithm finishRun(%d)\n",run_number);
414  fprintf(mLogFile," - %d events seen by L2 di-jet\n",mEventsInRun);
415  fprintf(mLogFile," - accepted: rnd=%d oneJet=%d diJet=%d \n", run_nEventRnd, run_nEventOneJet, run_nEventDiJet);
416 
417  // print few basic histos
418 
419  hA[10]->printCSV(mLogFile); // event accumulated
420 
421  }
422  finishRunHisto(); // still needs current DB
423 
424  if( mHistFile==0) {
425  printf(" L2adc2energyAlgo: finishRun() UNABLE to open run summary log file, continue anyhow\n");
426  if (mLogFile)
427  fprintf(mLogFile,"L2 di-jet histos NOT saved, I/O error\n");
428  } else { // save histos
429  int j;
430  int nh=0;
431  for(j=0;j<mxHA;j++) {
432  if(hA[j]==0) continue;
433  hA[j]->write(mHistFile);
434  nh++;
435  }
436  finishCommonHistos();
437  fclose(mHistFile);
438  mHistFile=0;
439  if (mLogFile)
440  fprintf(mLogFile,"L2 di-jet: %d histos saved to '%s'\n",nh,Fname);
441  }
442 
443  run_number=-2; // clear run #
444 
445  /* close the output file if it is open */
446  if (mLogFile && mLogFile!=stdout) {
447  fclose(mLogFile);
448  mLogFile=0;
449  }
450 
451 }
452 
453 
454 //=======================================
455 //=======================================
456 void
457 L2adc2energyAlgo::createHisto() {
458  memset(hA,0,sizeof(hA));
459 
460  hA[10]=new L2Histo(10, (char*)"total event counter; x=cases",9);
461  hA[11]=new L2Histo(11, (char*)"L2 time used per input event; x: time (CPU kTics), range=100muSec; y: events ",160);
462 
463  int mxRunDration=2500;
464  hA[12]=new L2Histo(12, (char*)"rate of input events; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
465 
466  hA[13]=new L2Histo(13, (char*)"rate of accepted one-Jet; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
467  hA[14]=new L2Histo(14, (char*)"rate of accepted di-Jet ; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
468  hA[15]=new L2Histo(15, (char*)"rate of random accepted ; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
469 
470  // BTOW raw spectra
471  hA[20]=new L2Histo(20, (char*)"BTOW tower, Et>2.0 GeV (input); x: BTOW RDO index=chan*30+fiber; y: counts", 4800);
472  hA[21]=new L2Histo(21, (char*)"BTOW tower, Et>2.0 GeV (input); x: BTOW softID", 4800);
473  hA[22]=new L2Histo(22, (char*)"BTOW tower, Et>2.0 GeV (input); x: eta bin, [-1,+1]; y: phi bin ~sector",40,120);
474 
475  // ETOW raw spectra
476  hA[30]=new L2Histo(30, (char*)"ETOW tower, Et>2.0 GeV (input); x: ETOW RDO index=chan*6+fiber; y: counts", 720 );
477  hA[31]=new L2Histo(31, (char*)"ETOW tower, Et>2.0 GeV (input); x: i=chan+128*crate", 768);
478  hA[32]=new L2Histo(32, (char*)"ETOW tower, Et>2.0 GeV (input); x: 12 - Endcap etaBin ,[+1,+2]; y: phi bin ~sector",12,60);
479 
480  // Di-Jet raw yields
481  hA[40]=new L2Histo(40, (char*)"Et Jet1-Jet2 (input); x: Jet1 Et/GeV ; Jet2 Et/GeV",12,12);
482  hA[41]=new L2Histo(41, (char*)"diJet1 eta-phi (input); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
483  hA[42]=new L2Histo(42, (char*)"diJet2 eta-phi (input); x: iEta [-1,+2] ; y: iPhi ~sector",15,30);
484 
485  hA[43]=new L2Histo(43, (char*)"diJet phi1-phi2 (input); x: iPhi1 ~sector ; y: iPhi2 ~sector ",30,30);
486 
487  hA[44]=new L2Histo(44, (char*)"Jet1 Et (input); x: Et (GeV)", 60);
488  hA[45]=new L2Histo(45, (char*)"Jet2 Et (input); x: Et (GeV)", 60);
489  hA[46]=new L2Histo(46, (char*)"total Et (input); x: Et (GeV)", 60);
490  hA[47]=new L2Histo(47, (char*)"# BTOW towers>thrXX (input); x: # of towers/event", 200);
491  hA[48]=new L2Histo(48, (char*)"# ETOW towers>thrXX (input); x: # of towers/event", 100);
492 
493  // ........accepted one-jet events
494  hA[50]=new L2Histo(50, (char*)"one-Jet Et (accepted); x: jet Et (GeV)", 60);
495  hA[51]=new L2Histo(51, (char*)"one-Jet eta-phi (accepted); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
496  hA[52]=new L2Histo(52, (char*)"one-Jet eta (accepted); x: iEta [-1,+2]", 15);
497  hA[53]=new L2Histo(53, (char*)"one-Jet phi (accepted); x: iPhi ~sector", 30);
498 
499  // Di-Jet accepted
500  hA[60]=new L2Histo(60, (char*)"Et of Jet1 vs. Jet2 (accepted); x: Jet1/GeV ; Jet2/GeV",12,12);
501  hA[61]=new L2Histo(61, (char*)"diJet1 eta-phi (accepted); x: iEta [-1,+2] ; y: iPhi ~sector ",15,30);
502  hA[62]=new L2Histo(62, (char*)"diJet2 eta-phi (accepted); x: iEta [-1,+2] ; y: iPhi ~sector",15,30);
503 
504  hA[63]=new L2Histo(63, (char*)"diJet phi1-phi2 (accepted); x: iPhi1 ~sector ; y: iPhi2 ~sector ",30,30);
505 
506  hA[64]=new L2Histo(64, (char*)"diJet1 Et (accepted); x: Et (GeV)", 60);
507  hA[65]=new L2Histo(65, (char*)"diJet2 Et (accepted); x: Et (GeV)", 60);
508 
509  hA[66]=new L2Histo(66, (char*)"diJet1 eta (accepted); x: i Eta [-1,+2]", 15);
510  hA[67]=new L2Histo(67, (char*)"diJet2 eta (accepted); x: i Eta [-1,+2]", 15);
511  hA[68]=new L2Histo(68, (char*)"diJet1 phi (accepted); x: iPhi ~sector", 30);
512  hA[69]=new L2Histo(69, (char*)"diJet2 phi (accepted); x: iPhi ~sector", 30);
513  hA[70]=new L2Histo(70, (char*)"diJet delZeta (accepted); x: delta zeta (rad*10)", MxPhiRad10);
514  hA[71]=new L2Histo(71, (char*)"diJet delZeta vs. eta1 (accepted); x: iEta1 [-1,+2] ; y: delta zeta (rad*10)",15, MxPhiRad10);
515  hA[72]=new L2Histo(72, (char*)"diJet eta2 vs. eta1 (accepted); x: iEta1 [-1,+2] ;x: iEta2 [-1,+2] ",15,15);
516  hA[73]=new L2Histo(73, (char*)"diJet delZeta vs. avrPhi (accepted); x: (iphi1+iphi2)/2 (12 deg/bin); y: delta zeta (rad*10)",30, MxPhiRad10);
517  hA[74]=new L2Histo(74, (char*)"total Et diJet (accepted); x: Et (GeV)", 60);
518 
519 }
520 
521 //=======================================
522 //=======================================
523 void
524 L2adc2energyAlgo::clearEvent(){
525  /* printf("clearEvent_L2jet() executed\n"); */
526 
527  mAccept=false;
528  mEveTimeDiff=0;
529  memset(eve_patchEne,0,sizeof(eve_patchEne));
530  memset(eve_phiEne,0,sizeof(eve_phiEne));
531 }
532 
533 
534 
535 //=======================================
536 //=======================================
537 int
538 L2adc2energyAlgo::projectAdc( unsigned short *rawAdc, int nRdo,
539  unsigned short *thr, unsigned short *pedS, unsigned short *gainCorr,
540  unsigned short *phiBin, unsigned short *patchBin,
541  L2Histo *hHot ){
542 
543  int tmpNused=0; /* counts mapped & used ADC channels */
544 
545  short rdo;
546  int adc,adc4;
547  for(rdo=0; rdo<nRdo; rdo++){
548  if(rawAdc[rdo]<thr[rdo])continue;
549  // adc=rawAdc[rdo]-ped[rdo]; // old, before drop of 4 LSB was introduced.
550  adc=(rawAdc[rdo]+pedS[rdo]) & par_adcMask ;
551  adc4=adc*gainCorr[rdo];
552  eve_patchEne[patchBin[rdo]]+=adc4;
553  eve_phiEne[phiBin[rdo]]+=adc4;
554  tmpNused++; /* drop it later */
555  // only monitoring
556  // if(par_dbg>3) printf("pro rdo=%d adc=%d nTw=%d\n",rdo,adc,tmpNused);
557  if(adc4 >par_hotTwEtThr) hHot->fill(rdo);
558  }
559 
560  return tmpNused;
561 }
562 
563 
564 //========================================
565 //========================================
566 void
567 L2adc2energyAlgo:: dumpPatchEneA(){
568  // dump L2 array with energy
569  int ix,iy;
570  for(iy=0;iy<cl2jetMaxPhiBins;iy++) {
571  int *patchEneA=eve_patchEne+(iy*cl2jetMaxEtaBins);// phi bins are consecutive
572 
573  for(ix=0;ix<cl2jetMaxEtaBins;ix++,patchEneA++){
574  printf(" %6d",*patchEneA);
575  }
576  printf(" iPhi=%d\n",iy);
577  }
578 
579 }
580 
581 
582 //=======================================
583 //=======================================
584 void
585 L2adc2energyAlgo::finishRunHisto(){
586  // auxialiary operations on histograms at the end of the run
587 
588  const int *data20=hA[20]->getData();
589  const int *data30=hA[30]->getData();
590 
591  int bHotSum=1,bHotId=-1;
592  int eHotSum=1;
593 
594  const L2EmcDb::EmcCDbItem *xE=mDb->getByIndex(402), *xB=mDb->getByIndex(402);
595  int i;
596  for(i=0; i<EmcDbIndexMax; i++) {
597  const L2EmcDb::EmcCDbItem *x=mDb->getByIndex(i);
598  if(mDb->isEmpty(x)) continue;
599  if (mDb->isBTOW(x) ) {
600  int softId=atoi(x->tube+2);
601  int ieta= (x->eta-1);
602  int iphi= (x->sec-1)*10 + x->sub-'a' ;
603  //mDb->printItem(x); printf("softID=%d\n",softId);
604  hA[21]->fillW(softId,data20[x->rdo]);
605  hA[22]->fillW(ieta, iphi,data20[x->rdo]);
606  if(bHotSum<data20[x->rdo]) {
607  bHotSum=data20[x->rdo];
608  bHotId=softId;
609  xB=x;
610  }
611  }// end of BTOW
612  else if (mDb->isETOW(x) ) {
613  int ihard=x->chan+(x->crate-1)*128;
614  int ieta= 12-x->eta;
615  int iphi= (x->sec-1)*5 + x->sub-'A' ;
616  hA[31]->fillW(ihard,data30[x->rdo]);
617  hA[32]->fillW(ieta, iphi,data30[x->rdo]);
618  if(eHotSum<data30[x->rdo]) {
619  eHotSum=data30[x->rdo];
620  xE=x;
621  }
622 
623  }// end of BTOW
624  }
625  if (mLogFile){
626  fprintf(mLogFile,"L2jet::finishRun()\n");
627  fprintf(mLogFile,"#BTOW_hot tower _candidate_ (bHotSum=%d) :, softID %d , crate %d , chan %d , name %s\n",bHotSum,bHotId,xB->crate,xB->chan,xB->name);
628  fprintf(mLogFile,"#ETOW_hot tower _candidate_ (eHotSum=%d) :, name %s , crate %d , chan %d\n",eHotSum,xE->name,xE->crate,xE->chan);
629  }
630 
631 
632 }
633 
634 
635 /**********************************************************************
636  $Log: L2adc2energyAlgo.cxx,v $
637  Revision 1.2 2009/11/19 15:48:45 balewski
638  add (char*) to many strings to make SL5 happ, few other adjustments
639 
640  Revision 1.1 2007/11/19 22:18:25 balewski
641  most L2algos provide triggerID's
642 
643 
644 */
645 
646