StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EEdsm1.cxx
1 #include <iostream>
2 #include <assert.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <string.h>
6 
7 
8 #include "EEdsm1.h"
9 
10 //--------------------------------------------------
11 //
12 //--------------------------------------------------
13 EEdsm1 :: EEdsm1() {
14  type=0;
15  clear();
16  mYear=2005;
17 }
18 
19 //--------------------------------------------------
20 //--------------------------------------------------
21 EEdsm1::~EEdsm1() { }
22 
23 //--------------------------------------------------
24 //--------------------------------------------------
25 void
26 EEdsm1::clear() {
27  memset(data,0,sizeof(data));
28  memset(intJP11bit,0,sizeof(intJP11bit));
29  intJPsum13bit=0;
30  outJPsum5bit=0;
31  outHTTP1bit=0;
32  outTP1bit=0;
33  outJP2bit=0;
34  outHT2bit=0;
35 }
36 //--------------------------------------------------
37 //--------------------------------------------------
38 void EEdsm1::setYear(int y, int *JPth, int TPthrSelc, int HTTPthrSelc){
39  mYear=y;
40  int i;
41  for( i=0; i<mxTh; i++){
42  JPthr[i]=JPth[i];
43  }
44  TPthrSelect=TPthrSelc;
45  HTTPthrSelect=HTTPthrSelc;
46 }
47 
48 
49 //--------------------------------------------------
50 //--------------------------------------------------
51 void EEdsm1::setWord(int ch, unsigned short val){
52 
53  assert(ch>=0 && ch<nc);
54  data[ch]=val;
55 }
56 
57 
58 //--------------------------------------------------
59 //--------------------------------------------------
60 int
61 EEdsm1::getInp16bit(int ch) const {
62  assert(ch>=0 && ch<nc);
63  unsigned short val=data[ch];
64  return val;
65 }
66 
67 //--------------------------------------------------
68 //--------------------------------------------------
69 int
70 EEdsm1::getInpHT2bit(int ch) const {
71  assert(ch>=0 && ch<nc);
72  unsigned short val=(data[ch]& 0xfff) >>10;
73  return val;
74 }
75 
76 /* 2006 change in tier1 file:
77 a) selected TP threshold passed?: extract bits 12-13; .
78 b) HTxTP bits for highest threshold passed: repeat (a), but now for bits 14-15
79 */
80 
81 //--------------------------------------------------
82 //--------------------------------------------------
83 int
84 EEdsm1::getInpTP2bit(int ch) const {
85  assert(ch>=0 && ch<nc);
86  assert(mYear>=2006);
87  unsigned short val=data[ch] >>12;
88  return val&3;
89 }
90 
91 //--------------------------------------------------
92 //--------------------------------------------------
93 int
94 EEdsm1::getInpHTTP2bit(int ch) const {
95  assert(ch>=0 && ch<nc);
96  assert(mYear>=2006);
97  unsigned short val=data[ch] >>14;
98  return val&3;
99 }
100 
101 //--------------------------------------------------
102 //--------------------------------------------------
103 int
104 EEdsm1::getInpTPsum(int ch) const {
105  assert(ch>=0 && ch<nc);
106 
107  /* The first board
108  has patches .6 .3 .3 .6 .6 .3
109  Steve's JP# \_3_/ \_4_/ \_5_/
110 
111  The second board
112  has patches .3 .6 .6 .3 .3 .6
113  Steve's JP# \_6_/ \_1_/ \_2_/
114  */
115 
116  unsigned short val=0xfff;
117 
118  if (type == 1) {
119  switch (ch) {
120  case 0: // use last 10 bits for 0.6x1 patches
121  case 3:
122  case 4:
123  val=data[ch]& 0x3ff;
124  break;
125  case 1: // use last 9 bits for 0.3x1 patches
126  case 2:
127  case 5:
128  val=data[ch]& 0x1ff;
129  break;
130  }
131  }
132  else if (type == 2) {
133  switch (ch) {
134  case 1: // use last 10 bits for 0.6x1 patches
135  case 2:
136  case 5:
137  val=data[ch]& 0x3ff;
138  break;
139  case 0: // use last 9 bits for 0.3x1 patches
140  case 3:
141  case 4:
142  val=data[ch]& 0x1ff;
143  break;
144  }
145  }
146  else assert (1==2);
147 
148  return val;
149 
150 }
151 
152 
153 //--------------------------------------------------
154 //--------------------------------------------------
155 void
156 EEdsm1::compute() {
157  /* At layer 1 DSM's, the "HTTP threshold select register"
158  is used to determine which of the three thresholds of
159  HTTP output from layer 0 to pass on. We did not
160  change this register value throughout run 6, but I
161  thought we set the value = 1, meaning we used
162  HTth1 combined with TPth1. I assume that would
163  mean that if any HTTP output from layer 0 DSM's
164  is set to 10 or 11, then the HTTP output bit from
165  layer 1 will be set to 1.
166  */
167  assert(mYear>=2006);
168  int combHT2bit=0, combTP2bit=0, combHTTP2bit=0;
169  int i;
170  for ( i=0; i<nc; i++ ){
171  int iJP=i/2;
172  intJP11bit[iJP]+=getInpTPsum(i);
173  intJPsum13bit +=getInpTPsum(i);
174  if ( combHT2bit <= getInpHT2bit(i) ) combHT2bit = getInpHT2bit(i);
175  if ( combTP2bit <= getInpTP2bit(i) ) combTP2bit = getInpTP2bit(i);
176  if ( combHTTP2bit <= getInpHTTP2bit(i) ) combHTTP2bit = getInpHTTP2bit(i);
177  }
178 
179  outHT2bit = combHT2bit;
180 
181  //printf("!!!TPthrSelect=%d\n",TPthrSelect);
182  //printf("!!!HTTPthrSelect=%d\n",HTTPthrSelect);
183 
184  if ( combTP2bit >= TPthrSelect ) outTP1bit=1;
185  else outTP1bit=0;
186 
187  if ( combHTTP2bit >= HTTPthrSelect ) outHTTP1bit=1;
188  else outHTTP1bit=0;
189 
190  int mxJP=0;
191  int j;
192  for ( j=0; j<nJP; j++ ){
193  if ( mxJP <= intJP11bit[j] ) mxJP = intJP11bit[j];
194  }
195 
196  if ( mxJP <= JPthr[0]) outJP2bit=0;
197  if ( mxJP > JPthr[0] && mxJP <= JPthr[1] ) outJP2bit=1;
198  if ( mxJP > JPthr[1] && mxJP <= JPthr[2] ) outJP2bit=2;
199  if ( mxJP > JPthr[2] ) outJP2bit=3;
200 
201  int flag;
202  flag =( intJPsum13bit >>7 ) & 0x3f;
203  if ( flag > 0 ) outJPsum5bit = 31;
204  else outJPsum5bit = ( intJPsum13bit >>2 ) & 0x1f;
205 
206  out16bit= outJPsum5bit + ( outHTTP1bit << 7 ) + ( outTP1bit << 9 ) + ( outJP2bit << 10 ) + ( outHT2bit << 12 );
207  //printf("done processing jet patch sums \n");
208 
209 
210 }
211 
212 //--------------------------------------------------
213 //--------------------------------------------------
214 void
215 EEdsm1::print( int k ) const {
216  printf("EEdsm1:: print() INPUTS, year=%d \n",mYear);
217  int i;
218 
219  printf("\nch = ");
220  for(i=nc-1;i>=0;i--) printf(" %4d ",i);
221  printf("\nword = ");
222  for(i=nc-1;i>=0;i--) printf(" x%4.4x ", data[i] );
223 
224  printf("\nTPsum = ");
225  for(i=nc-1;i>=0;i--) printf(" %4d ", getInpTPsum(i));
226 
227  printf("\nJPsum = ");
228  for(i=2;i>=0;i--) printf(" %8d ", intJP11bit[i]);
229 
230  printf("\nHT2bit= ");
231  for(i=nc-1;i>=0;i--) printf(" %4d ", getInpHT2bit(i));
232 
233  if(mYear>=2006) {
234  printf("\nTP2bit= ");
235  for(i=nc-1;i>=0;i--) printf(" %4d ", getInpTP2bit(i));
236 
237  printf("\nHTTP2bit=");
238  for(i=nc-1;i>=0;i--) printf(" %4d ", getInpHTTP2bit(i));
239  }
240 
241  printf("\n output: HT2bit=%d, JP2bit=%d, TP1bit=%d, HTTP1bit=%d, JPsum5bit=%d\n", outHT2bit ,outJP2bit, outTP1bit ,outHTTP1bit,outJPsum5bit);
242 
243 }
244 
245 // $Log: EEdsm1.cxx,v $
246 // Revision 1.1 2009/10/12 18:04:25 pibero
247 // Moved StEEmcUtil/EEdsm to StTriggerUtilities/Eemc
248 //
249 // Revision 1.5 2009/02/24 03:56:18 ogrebeny
250 // Corrected const-ness
251 //
252 // Revision 1.4 2007/08/17 01:15:36 balewski
253 // full blown Endcap trigger simu, by Xin
254 //
255 // Revision 1.3 2006/04/05 18:34:10 balewski
256 // new DSM bit assignment in 2006,
257 // possibly lost backward compatibility
258 // use tagged 2005 version if needed
259 //
260 // Revision 1.2 2005/02/01 22:13:39 perev
261 // Compatibility to redhat
262 //
263 // Revision 1.1 2004/11/29 20:12:59 balewski
264 // first
265 //
266 // Revision 1.2 2004/04/23 20:16:56 balewski
267 // trig patch fix
268 //
269 // Revision 1.1 2004/02/17 03:09:17 balewski
270 // *** empty log message ***
271 //
272