StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
L2wEemc2012.cxx
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <time.h>
5 #include <math.h>
6 
7 /***********************************************************
8  * $Id: L2wEemc2012.cxx,v 1.4 2012/03/23 20:12:09 balewski Exp $
9  * \author Jan Balewski, MIT, 2008
10  ***********************************************************
11  * Descripion: see .h
12  **********************************************************
13  */
14 
15 #include "../L2algoUtil/L2Histo.h"
16 #include "../L2algoUtil/L2EmcDb2012.h"
17 
18 #include "L2wEemc2012.h"
19 
20 //=================================================
21 //=================================================
22 L2wEemc2012::L2wEemc2012(const char* name, const char *uid, L2EmcDb2012* db, L2EmcGeom2012 *geoX, char* outDir, int resOff) : L2VirtualAlgo2012( name, uid, db, outDir, false,true, resOff ) {
23  /* called one per days
24  all memory allocation must be done here
25  */
26 
27  // geoX is not used, ignore
28 
29  setMaxHist(4); // set upper range, I uses only 2^N -it is easier to remember
30  createHisto();
31 
32 }
33 
34 /* ========================================
35  ======================================== */
36 int
37 L2wEemc2012::initRunUser( int runNo, int *rc_ints, float *rc_floats) {
38 
39  // unpack params from run control GUI
40  par_dbg = rc_ints[0];
41  par_RndAcceptPrescale = rc_ints[1];
42  par_EtThresh = rc_floats[0];
43 
44  // verify consistency of input params
45  int kBad=0;
46  kBad+=2*(par_EtThresh<0);
47 
48  //FIX log output
49  if (mLogFile) {
50  fprintf(mLogFile,"L2%s algorithm initRun(R=%d), compiled: %s , %s\n",getName(),mRunNumber,__DATE__,__TIME__);
51  fprintf(mLogFile," - use ET Thresh =%f, RndAcceptPrescale=%d debug=%d\n", par_EtThresh , par_RndAcceptPrescale, par_dbg);
52  fprintf(mLogFile,"initRun() params checked for consistency, Error flag=0x%04x\n",kBad);
53  }
54  if(kBad) return -kBad;
55 
56  // clear content of all histograms & token-dependent memory
57  int i;
58  for (i=0; i<mxHA;i++) if(hA[i])hA[i]->reset();
59 
60  // update titles of histos, add values of params
61  char txt[1000];
62 
63  sprintf(txt,"highest endcap tower ET; x: tower ET; y: counts");
64  hA[1]->setTitle(txt);
65 
66  return 0; //OK
67 }
68 
69 
70 
71 /* ========================================
72  ======================================== */
73 void
74 L2wEemc2012::computeUser(int token){
75  // token range is guaranteed by virtual12-class
76  // ----------- SCAN FOR HIGHEST TOWER ----
77 
78  int i;
79  // get pointer to input list towers from calib-algo
80  const HitTower1 *hit=0;
81  int hitSize=0;
82 
83  hit =mEveStream_etow[token].get_hits();
84  hitSize=mEveStream_etow[token].get_hitSize();
85 
86  float highestEt=0.;
87  unsigned short highestRDO=8888;
88  for(i=0;i< hitSize;i++,hit++) {
89  if (hit->et>highestEt) {
90  highestEt=hit->et;
91  highestRDO=hit->rdo;
92  }
93  }
94 
95  resultBlob[token].trigger=0;
96  resultBlob[token].highestEt=(unsigned char)(highestEt*256.0/60.0);
97  resultBlob[token].highestRDO=highestRDO;
98  hA[1]->fill((int)highestEt);
99  if (highestEt>par_EtThresh) {
100  hA[2]->fill((int)highestRDO);
101  resultBlob[token].trigger+=2;
102  }
103 
104 }
105 
106 
107 /* ========================================
108  ======================================== */
109 bool
110 L2wEemc2012::decisionUser(int token, int *myL2Result){
111  // INPUT: token + comput() results stored internally
112  // OUTPUT: YES if the highestEt>par_EtThresh. Plot highestEt.
113  if (mRandomAccept) resultBlob[token].trigger+=1;
114 
115  memcpy(myL2Result,&(resultBlob[token]),sizeof( L2weResult2012));
116  return resultBlob[token].trigger&2;
117 }
118 
119 
120 /* ========================================
121  ======================================== */
122 void
123 L2wEemc2012::finishRunUser() { /* called once at the end of the run */
124  // do whatever you want, log-file & histo-file are still open
125 
126  // if (mLogFile){
127  // fprintf(mLogFile,"finishRunUser-%s bhla bhla\n",getName());
128  // }
129 
130 }
131 
132 
133 //=======================================
134 //=======================================
135 void
136 L2wEemc2012::createHisto() {
137  //memset(hA,0,sizeof(hA));
138 
139  hA[1]=new L2Histo(1,(char*)"Highest endcap tower ET; x: tower ET; y: counts", 100); // title set in initRun
140  hA[2]=new L2Histo(2,(char*)"ETOW: Seed Tower RDO", 720); // title in initRun
141  //hA[1]=new L2Histo(1,(char*)"accepted: highest endcap tower ET; x: tower ET; y: counts", 100); // title set in initRun
142 
143 
144  // printf("L2-%s::createHisto() done\n",getName());
145 }
146 
147 /**********************************************************************
148  $Log: L2wEemc2012.cxx,v $
149  Revision 1.4 2012/03/23 20:12:09 balewski
150  changes are to write a L2weResult to the L2Result array so we can differentiate random and real accepts, and update the plots so we can have some monitoring,no intended changes to the actual algo
151 
152  Revision 1.3 2011/10/19 16:12:12 jml
153  more 2012 stuff
154 
155  Revision 1.2 2011/10/19 15:39:45 jml
156  2012
157 
158  Revision 1.1 2011/10/18 15:11:45 jml
159  adding 2012 algorithms
160 
161  Revision 1.2 2009/11/19 15:48:49 balewski
162  add (char*) to many strings to make SL5 happ, few other adjustments
163 
164  Revision 1.1 2009/03/28 19:43:53 balewski
165  2009 code
166 
167  Revision 1.0 2009/03/20 05:00:00 rcorliss
168  adapted from L2hienAlgo.
169 
170 */
171 
172