StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DSMAlgo_EM201_2009.cc
1 //
2 // Pibero Djawotho <pibero@comp.tamu.edu>
3 // Texas A&M University Cyclotron Institute
4 // 7 Jan 2009
5 //
6 
7 #include "DSM.hh"
8 #include "DSMAlgo_EM201_2009.hh"
9 
10 int DSMAlgo_EM201_2009::ajpBarrel(const DSM& dsm, int offset) const
11 {
12  int jpBits[6];
13 
14  // BC101-106
15 
16  for (int ch = 0; ch < 6; ++ch)
17  {
18  jpBits[ch] = dsm.channels[ch] >> offset & 0x3;
19 // printf("The channel %d jp bit is %d\n", ch, jpBits[ch]); //Test by Z. Chang
20  }
21  const int R3 = dsm.registers[3];
22 // printf("R3 is %d out of %d\n", R3,dsm.registers[3]);
23 
24  return (((jpBits[0] > R3) && (jpBits[1] > R3)) ||
25  ((jpBits[1] > R3) && (jpBits[2] > R3)) ||
26  ((jpBits[2] > R3) && (jpBits[3] > R3)) ||
27  ((jpBits[3] > R3) && (jpBits[4] > R3)) ||
28  ((jpBits[4] > R3) && (jpBits[5] > R3)) ||
29  ((jpBits[5] > R3) && (jpBits[0] > R3)));
30 }
31 
32 int DSMAlgo_EM201_2009::ajpEndcap(const DSM& dsm) const
33 {
34  int jpBits[6];
35  const int R3 = dsm.registers[3];
36 
37  // EE101
38 
39  jpBits[0] = dsm.channels[6] & 0x3; // JPA (4 o'clock)
40  jpBits[1] = dsm.channels[6] >> 2 & 0x3; // JPB (6 o'clock)
41  jpBits[2] = dsm.channels[6] >> 4 & 0x3; // JPC (8 o'clock)
42 
43  // EE102
44 
45  jpBits[3] = dsm.channels[7] & 0x3; // JPA (10 o'clock)
46  jpBits[4] = dsm.channels[7] >> 2 & 0x3; // JPB (12 o'clock)
47  jpBits[5] = dsm.channels[7] >> 4 & 0x3; // JPC (2 o'clock)
48 
49  return (((jpBits[0] > R3) && (jpBits[1] > R3)) ||
50  ((jpBits[1] > R3) && (jpBits[2] > R3)) ||
51  ((jpBits[2] > R3) && (jpBits[3] > R3)) ||
52  ((jpBits[3] > R3) && (jpBits[4] > R3)) ||
53  ((jpBits[4] > R3) && (jpBits[5] > R3)) ||
54  ((jpBits[5] > R3) && (jpBits[0] > R3)));
55 }
56 
57 void DSMAlgo_EM201_2009::operator()(DSM& dsm)
58 {
59  // INPUT:
60 
61  // EM201 - ch0 - BEMC BC101 - 10' - JP0 & JP6 (West & East)
62  // ch1 - BEMC BC102 - 12' - JP1 & JP7
63  // ch2 - BEMC BC103 - 2' - JP2 & JP8
64  // ch3 - BEMC BC104 - 4' - JP3 & JP9
65  // ch4 - BEMC BC105 - 6' - JP4 & JP10
66  // ch5 - BEMC BC106 - 8' - JP5 & JP11
67  // ch6 - EEMC EE101 - 4', 6' and 8' - JP3, JP4 & JP5
68  // ch7 - EEMC EE102 - 10', 12' and 2' - JP0, JP1 & JP2
69 
70  // From BC101-106 (16):
71 
72  // (0-1) JPX (east, -1 < eta < 0) threshold bits (2)
73  // (2-3) JPY (middle, -0.6 < eta < 0.4) threshold bits (2)
74  // (4-5) JPZ (west, 0 < eta < 1) threshold bits (2)
75  // (6-11) JPpartial (0.4 < eta < 1) sum (6)
76  // (12-15) HT bits (4)
77 
78  // From EE101 (16):
79 
80  // (0-1) JPA (4 o'clock) threshold bits (2)
81  // (2-3) JPB (6 o'clock) threshold bits (2)
82  // (4-5) JPC (8 o'clock) threshold bits (2)
83  // (6-11) Selected partial jet patch sum (6)
84  // (12-13) Partial jet patch ID (1=A, 2=B, 3=C) (2)
85  // (14-15) HT bits (2)
86 
87  // From EE102 (16):
88 
89  // (0-1) JPA (10 o'clock) threshold bits (2)
90  // (2-3) JPB (12 o'clock) threshold bits (2)
91  // (4-5) JPC (2 o'clock) threshold bits (2)
92  // (6-11) Selected partial jet patch sum (6)
93  // (12-13) Partial jet patch ID (1=A, 2=B, 3=C) (2)
94  // (14-15) HT bits (2)
95 
96  // REGISTERS:
97 
98  // R0: Hybrid jet patch threshold-0
99  // R1: Hybrid jet patch threshold-1
100  // R2: Hybrid jet patch threshold-2
101 
102  // ACTION:
103 
104  // Complete hybrid jet patches using partial jet patch ID from EEMC
105 
106  int jpSum1 = dsm.channels[6] >> 6 & 0x3f; // Partial sum from EE101
107  int jpSum2 = dsm.channels[7] >> 6 & 0x3f; // Partial sum from EE102
108  //printf("ee: jpSum1 = %d jpSum2 = %d\n", jpSum1, jpSum2);
109  int jpId1 = dsm.channels[6] >> 12 & 0x3; // Partial jet patch ID from EE101
110  int jpId2 = dsm.channels[7] >> 12 & 0x3; // Partial jet patch ID from EE102
111  //printf("ee: jpId1 = %d jpId2 = %d\n", jpId1, jpId2);
112  switch (jpId1) {
113  case 1: jpSum1 += dsm.channels[3] >> 6 & 0x3f; break; // Add partial sum from BC104 (4')
114  case 2: jpSum1 += dsm.channels[4] >> 6 & 0x3f; break; // Add partial sum from BC105 (6')
115  case 3: jpSum1 += dsm.channels[5] >> 6 & 0x3f; break; // Add partial sum from BC106 (8')
116  }
117 
118  switch (jpId2) {
119  case 1: jpSum2 += dsm.channels[0] >> 6 & 0x3f; break; // Add partial sum from BC101 (10')
120  case 2: jpSum2 += dsm.channels[1] >> 6 & 0x3f; break; // Add partial sum from BC102 (12')
121  case 3: jpSum2 += dsm.channels[2] >> 6 & 0x3f; break; // Add partial sum from BC103 (2')
122  }
123  //printf("jpId1=%d jpsum1=%d jpId2=%d jpsum2=%d\n", jpId1, jpSum1, jpId2, jpSum2);
124 
125  // Combine (OR) the HT bits from the six BEMC layer 1 DSM's
126 
127  int htBitsBarrel = 0;
128 
129  for (int ch = 0; ch < 6; ++ch)
130  htBitsBarrel |= dsm.channels[ch] >> 12 & 0xf;
131 
132  // Combine (OR) the HT bits from the two EEMC layer 1 DSM's
133 
134  int htBitsEndcap = 0;
135 
136  for (int ch = 6; ch < 8; ++ch)
137  htBitsEndcap |= dsm.channels[ch] >> 14 & 0x3;
138 
139  // Combine (OR) the JP bits for the BEMC and EEMC separately
140 
141  int jpBitsBarrel = 0;
142 
143  for (int ch = 0; ch < 6; ++ch) {
144  int jpx = dsm.channels[ch] & 0x3;
145  int jpy = dsm.channels[ch] >> 2 & 0x3;
146  int jpz = dsm.channels[ch] >> 4 & 0x3;
147 
148  if (jpx > jpBitsBarrel) jpBitsBarrel = jpx;
149  if (jpy > jpBitsBarrel) jpBitsBarrel = jpy;
150  if (jpz > jpBitsBarrel) jpBitsBarrel = jpz;
151  }
152 
153  int bjp1 = jpBitsBarrel > 1;
154  int bjp2 = jpBitsBarrel > 2;
155 
156  int jpBitsEndcap = 0;
157 
158  for (int ch = 6; ch < 8; ++ch) {
159  int jpa = dsm.channels[ch] & 0x3;
160  int jpb = dsm.channels[ch] >> 2 & 0x3;
161  int jpc = dsm.channels[ch] >> 4 & 0x3;
162 
163  if (jpa > jpBitsEndcap) jpBitsEndcap = jpa;
164  if (jpb > jpBitsEndcap) jpBitsEndcap = jpb;
165  if (jpc > jpBitsEndcap) jpBitsEndcap = jpc;
166  }
167  //printf("jpBitsEndcap=%d\n", jpBitsEndcap);
168  int ejp1 = jpBitsEndcap > 1;
169  int ejp2 = jpBitsEndcap > 2;
170 
171  // Compare the two completed hybrid jet patches to three thresholds
172  // and combine (OR) the results with the BEMC-only and EEMC-only bits
173 
174  int jpBits = 0;
175 
176  for (int reg = 0; reg < 3; ++reg)
177  if (jpSum1 > dsm.registers[reg] || jpSum2 > dsm.registers[reg]) ++jpBits;
178  //printf("jpSum1 = %d jpSum2 = %d\n", jpSum1, jpSum2);
179  //printf("r0 = %d r1 = %d r2 = %d\n", dsm.registers[0], dsm.registers[1], dsm.registers[2]);
180  if (jpBitsBarrel > jpBits) jpBits = jpBitsBarrel;
181  if (jpBitsEndcap > jpBits) jpBits = jpBitsEndcap;
182 
183  int jp0 = jpBits > 0;
184  int jp1 = jpBits > 1;
185  int jp2 = jpBits > 2;
186 
187  // Adjacent jet patch logic
188 
189  int ajpx = ajpBarrel(dsm, 0);
190  int ajpy = ajpBarrel(dsm, 2);
191  int ajpz = ajpBarrel(dsm, 4);
192  int bajp = ajpx || ajpy || ajpz;
193  int eajp = ajpEndcap(dsm);
194  int ajp = bajp || eajp;
195 
196  // OUTPUT (16):
197 
198  // (0:3) Barrel HT bits (4)
199  // (4:5) Endcap HT bits (2)
200  // (6) JP1, unified over the BEMC+EEMC (1)
201  // (7) JP2, unified over the BEMC+EEMC (1)
202  // (8) BJP1 for the 18 BEMC-only patches (1)
203  // (9) BJP2 for the 18 BEMC-only patches (1)
204  // (10) EJP1 for the 6 EEMC-only patches (1)
205  // (11) EJP2 for the 6 EEMC-only patches (1)
206  // (12) AJP for BEMC and EEMC but NOT the boundary (1)
207  // (13) BAJP for the BEMC-only patches (1)
208  // (14) EAJP for the EEMC-only patches (1)
209  // (15) JP0, unified over the BEMC+EEMC (1)
210 
211  int out = 0;
212 
213  out |= htBitsBarrel;
214  out |= htBitsEndcap << 4;
215  out |= jp1 << 6;
216  out |= jp2 << 7;
217  out |= bjp1 << 8;
218  out |= bjp2 << 9;
219  out |= ejp1 << 10;
220  out |= ejp2 << 11;
221  out |= ajp << 12;
222  out |= bajp << 13;
223  out |= eajp << 14;
224  out |= jp0 << 15;
225 
226  dsm.output = out;
227 
228  // INFO
229 
230  dsm.info[0] = jpSum1;
231  dsm.info[1] = jpSum2;
232 }
Definition: DSM.hh:16