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