StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EEdsm0.cxx
1 /**************************************************************
2  * $Id: EEdsm0.cxx,v 1.1 2009/10/12 18:04:25 pibero Exp $
3  **************************************************************/
4 
5 #include <iostream>
6 #include <assert.h>
7 
8 #include "EEdsm0.h"
9 
10 //--------------------------------------------------
11 //--------------------------------------------------
12 EEdsm0::EEdsm0() {
13  clear();
14  type=1; // 0.6 JP type is the default
15  mYear=-1;
16  memset( HTthr,0,sizeof(HTthr)); // year 2006+
17  memset( TPthr,0,sizeof(TPthr));
18 }
19 
20 //--------------------------------------------------
21 //--------------------------------------------------
22 EEdsm0::~EEdsm0() { }
23 
24 //--------------------------------------------------
25 //--------------------------------------------------
26 void
27 EEdsm0::setYear(int y, int*HTth, int*TPth ) {
28  mYear=y;
29  assert(type==1 || type==2);
30  int i;
31  for(i=0;i<mxTh;i++) {
32  HTthr[i]= HTth[i];
33  TPthr[i]= TPth[i];
34  }
35 }
36 //--------------------------------------------------
37 //--------------------------------------------------
38 void
39 EEdsm0::clear() {
40  memset(data,0,sizeof(data));
41  memset(value,0,sizeof(value));
42  memset(outHT2bit,0,sizeof(outHT2bit));
43  memset(outTP2bit,0,sizeof(outTP2bit));
44  memset(outHTTP2bit,0,sizeof(outHTTP2bit));
45  memset(outTPsum,0,sizeof(outTPsum));
46  memset(out16bit,0,sizeof(out16bit));
47 }
48 
49 //--------------------------------------------------
50 //--------------------------------------------------
51 void
52 EEdsm0::setBite(int b, unsigned char val){
53  assert(b>=0 && b<nw);
54  data[b]=val;
55 }
56 
57 //--------------------------------------------------
58 //--------------------------------------------------
59 void
60 EEdsm0::setInp12bit(int ch, short val){
61  assert(ch>=0 && ch<nc);
62  value[ch]=val;
63 }
64 
65 //--------------------------------------------------
66 //--------------------------------------------------
67 int
68 EEdsm0::getInp12bit(int ch) const {
69  assert(ch>=0 && ch<nc);
70  return value[ch];
71 }
72 
73 
74 //--------------------------------------------------
75 //--------------------------------------------------
76 void
77 EEdsm0::unpack() {
78  int ch;
79  for(ch=0;ch<nc;ch++) {
80 
81  unsigned int val=99999;
82  switch( ch%2 ) {
83  case 0: // even: take 4 lower bytes form higher bite + lower bite
84  {// hi daddy! how are you? no! it's not red! uh!?
85  int k=ch/2*3; // position of low bite
86  val = ((data[k+1] & 0xf) <<8) + data[k];
87  // printf("even k=%d d1=x%2.2x d0=x%2.2x val=x%4.4x\n",k,data[k+1],data[k],val);
88  } break;
89  case 1: // odd: take higher bite + higher 4 bytes from lower bite
90  {
91  int k=(ch-1)/2*3+1; // position of low bite
92  val =( data[k+1] <<4) + (data[k]>>4);
93  // printf("odd k=%d d1=x%2.2x d0=x%2.2x val=x%4.4x\n",k,data[k+1],data[k],val);
94  } break;
95  }
96 
97  value[ch]= val;
98  }
99 }
100 
101 
102 //--------------------------------------------------
103 //--------------------------------------------------
104 void
105 EEdsm0::print( int k) const {
106  printf("EEdsm0 type=%d year=%d \n",type,mYear);
107 
108  int i;
109  printf("thresholds HT="); for(i=0;i<mxTh;i++) printf(" %2d ", HTthr[i]);
110  printf(" TP="); for(i=0;i<mxTh;i++) printf(" %2d ", TPthr[i]);printf("\n");
111 
112  printf("byte = ");
113  for(i=0;i<nw;i++) printf(" %2d ",nw-i-1);
114  printf("\nraw = ");
115  for(i=0;i<nw;i++) printf("x%2.2x ",data[nw-i-1]);
116  // printf("\n");
117 
118  printf("\nch = ");
119  for(i=nc-1;i>=0;i--) printf(" %3d ",i);
120  printf("\nTP+HT = ");
121  for(i=nc-1;i>=0;i--) printf(" x%3.3x ", getInp12bit(i) );
122  printf("\n[dec] = ");
123  for(i=nc-1;i>=0;i--) printf("%2d+%2d ", getInpTP6bit(i), getInpHT6bit(i) );
124 
125  printf("\n output(s) TPsum=%d HT2b=%d HTTP2b=%d",outTPsum[0],outHT2bit[0],outHTTP2bit[0]);
126  if(type==1) printf("\n");
127  else printf(" AND TPsum=%d HT2b=%d HTTP2b=%d\n",outTPsum[1],outHT2bit[1],outHTTP2bit[1]);
128 
129 }
130 
131 
132 
133 //--------------------------------------------------
134 //--------------------------------------------------
135 void
136 EEdsm0::compute() {
137  /*Hi Jan,
138 
139  In layer 0 DSM's, the HTTP bits are set as follows:
140 
141  1) for each input, check whether HT > HTth0 .AND.
142  TPsum > TPth0. Perform similar checks for th1 and
143  th2.
144 
145  2) If any of the 10 input trigger patches pass th2 in
146  test (1), then set HTTP output bits = 11;
147  if none of the 10 input trigger patches pass th2, but
148  at least one passes th1, set HTTP output bits = 10;
149  if none of the 10 input trigger patches pass th2 or
150  th1, but at least one passes th0, set HTTP output = 01;
151  if none of the 10 input trigger patches pass th0, set
152  HTTP output = 00.
153 
154  At layer 1 DSM's, the "HTTP threshold select register"
155  is used to determine which of the three thresholds of
156  HTTP output from layer 0 to pass on. We did not
157  change this register value throughout run 6, but I
158  thought we set the value = 1, meaning we used
159  HTth1 combined with TPth1. I assume that would
160  mean that if any HTTP output from layer 0 DSM's
161  is set to 10 or 11, then the HTTP output bit from
162  layer 1 will be set to 1.
163 
164  The only other register values you will need (eventually)
165  to use are ones for layer 2 DSM's to indicate whether
166  both E and W barrel, and whether both barrel and endcap,
167  contribute to E_tot.
168 
169 
170  In her written documentation, Eleanor doesn't actually specify the
171  values of the HTTP register. It is possible that value = 2 selects
172  threshold 1 -- i.e., that possible register values are 1,2,3 corresponding
173  to thresholds 0,1,2.
174 
175  Steve
176  */
177 
178  assert(mYear=2006);
179 
180  int iOu=0;
181  int i;
182  for(i=0;i<nc;i++) {
183  if(type==2 && i>=5) iOu=1;
184  outTPsum[iOu]+=getInpTP6bit(i);
185  int k;
186  for(k=0;k<mxTh; k++) {
187  int lev=k+1;
188  if( getInpHT6bit(i)>HTthr[k] && outHT2bit[iOu]<lev) outHT2bit[iOu]=lev;
189  if( getInpTP6bit(i)>TPthr[k] && outTP2bit[iOu]<lev) outTP2bit[iOu]=lev;
190  if( getInpHT6bit(i)>HTthr[k] && getInpTP6bit(i)>TPthr[k] && outHTTP2bit[iOu]<lev) outHTTP2bit[iOu]=lev;
191  }
192 
193  out16bit[iOu] = outTPsum[iOu] + ( outHT2bit[iOu] << 10 ) + ( outTP2bit[iOu] << 12 ) + ( outHTTP2bit[iOu] << 14 );
194 
195  // printf("i=%d iOu=%d HT=%d TP=%d TPsum=%d HT2b=%d HTTP2b=%d\n",i,iOu, getHT(i), getTP(i),outTPsum[iOu],outHT2bit[iOu],outHTTP2bit[iOu]);
196  }
197 
198 }
199 
200 
201 #if 0
202 probably wrong, do not account for type 1 & 2
203 //--------------------------------------------------
204 //--------------------------------------------------
205 int EEdsm0 :: maxHT() {
206  int i;
207  int k=0;
208  unsigned int max=getHT(k);
209  for(i=1;i<nc;i++) {
210  unsigned int val=getHT(i);
211  if(val<=max) continue;
212  max=val;
213  k=i;
214  }
215  // printf(" maxHT[ch=%d]=%2d\n",k,max);
216  return k;
217 }
218 
219 
220 //--------------------------------------------------
221 //--------------------------------------------------
222 int EEdsm0 :: maxTP() {
223  int i;
224  int k=0;
225  unsigned int max=getTP(k);
226  for(i=1;i<nc;i++) {
227  unsigned int val=getTP(i);
228  if(val<=max) continue;
229  max=val;
230  k=i;
231  }
232  // printf(" maxTP[ch=%d]=%2d\n",k,max);
233  return k;
234 }
235 #endif
236 
237 
238 /*
239  * $Log: EEdsm0.cxx,v $
240  * Revision 1.1 2009/10/12 18:04:25 pibero
241  * Moved StEEmcUtil/EEdsm to StTriggerUtilities/Eemc
242  *
243  * Revision 1.3 2009/02/24 03:56:18 ogrebeny
244  * Corrected const-ness
245  *
246  * Revision 1.2 2007/08/17 01:15:35 balewski
247  * full blown Endcap trigger simu, by Xin
248  *
249  * Revision 1.1 2004/11/29 20:12:59 balewski
250  * first
251  *
252  * Revision 1.1 2004/02/17 03:09:17 balewski
253  * *** empty log message ***
254  *
255  * Revision 1.1 2003/12/29 02:18:38 balewski
256  * star
257  *
258  * Revision 1.1 2003/05/22 19:39:00 balewski
259  */
260