CMS 3D CMS Logo

L1RCTReceiverCard.cc
Go to the documentation of this file.
3 
4 #include <vector>
5 using std::vector;
6 
7 #include <bitset>
8 using std::bitset;
9 
10 #include <iostream>
11 using std::cerr;
12 using std::cout;
13 using std::endl;
14 
15 #include <string>
16 using std::string;
17 
18 L1RCTReceiverCard::L1RCTReceiverCard(int crateNumber, int cardNumber,
19  const L1RCTLookupTables *rctLookupTables)
20  : regions(2), crtNo(crateNumber), cardNo(cardNumber),
21  rctLookupTables_(rctLookupTables), etIn10Bits(2), overFlowBits(2),
22  muonBits(2), tauBits(2) {}
23 
25 
27  std::vector<unsigned short> input(64);
28  for (int i = 0; i < 64; i++)
29  input.at(i) = rand() & 511;
30  fillInput(input);
31 }
32 
34  std::vector<unsigned short> input(64);
35  unsigned short x;
36  std::ifstream instream(filename);
37  if (instream) {
38  for (int i = 0; i < 64; i++) {
39  if (!(instream >> x))
40  break;
41  else
42  input.at(i) = x;
43  }
44  }
45  fillInput(input);
46 }
47 
48 // First layer is ecal the second is hcal.
49 // goes in order of (for crate 0,card 0)
50 // (Region 1) (Region 0)
51 // 28 24 20 16 12 08 04 00
52 // 29 25 21 17 13 09 05 01
53 // 30 26 22 18 14 10 06 02
54 // 31 27 23 19 15 11 07 03
55 //
56 // For card 6 of crate 0 it would look like
57 //
58 // 12 08 04 00
59 // 13 09 05 01
60 // 14 10 06 02
61 // 15 11 07 03
62 // 16 20 24 28
63 // 17 21 25 29
64 // 18 22 26 30
65 // 19 23 27 31
66 
67 void L1RCTReceiverCard::fillInput(const std::vector<unsigned short> &input) {
68 
69  std::vector<unsigned short> ecalInput(32);
70  std::vector<unsigned short> ecalFG(32);
71  std::vector<unsigned short> hcalInput(32);
72  std::vector<unsigned short> hcalMuon(32);
73 
74  for (int i = 0; i < 32; i++) {
75  ecalInput.at(i) = input.at(i) / 2;
76  ecalFG.at(i) = input.at(i) & 1;
77  hcalInput.at(i) = input.at(i + 32) / 2;
78  hcalMuon.at(i) = input.at(i + 32) & 1;
79  unsigned long lookup =
80  rctLookupTables_->lookup(ecalInput.at(i), hcalInput.at(i), ecalFG.at(i),
81  crtNo, cardNo, i); // tower number 0-31 now
82  unsigned short etIn7Bits = lookup & 127;
83  unsigned short etIn9Bits = (lookup >> 8) & 511;
84  unsigned short HE_FGBit = (lookup >> 7) & 1;
85  unsigned short activityBit = (lookup >> 17) & 1;
86  std::vector<unsigned short> indices = towerToRegionMap(i);
87  unsigned short r = indices.at(0);
88  unsigned short row = indices.at(1);
89  unsigned short col = indices.at(2);
90  regions.at(r).setEtIn7Bits(row, col, etIn7Bits);
91  regions.at(r).setEtIn9Bits(row, col, etIn9Bits);
92  regions.at(r).setHE_FGBit(row, col, HE_FGBit);
93  regions.at(r).setMuonBit(row, col, hcalMuon.at(i));
94  regions.at(r).setActivityBit(row, col, activityBit);
95  }
96 }
97 
98 vector<unsigned short> L1RCTReceiverCard::towerToRegionMap(int towernum) {
99  std::vector<unsigned short> returnVec(3);
100  unsigned short region;
101  unsigned short towerrow;
102  unsigned short towercol;
103  if (crtNo < 9) {
104  if (cardNo != 6) {
105  if (towernum < 16) {
106  region = 0;
107  towerrow = towernum % 4;
108  towercol = 3 - (towernum / 4);
109  } else {
110  region = 1;
111  towerrow = towernum % 4;
112  towercol = 7 - (towernum / 4);
113  }
114  } else {
115  if (towernum < 16) {
116  region = 0;
117  towerrow = towernum % 4;
118  towercol = 3 - (towernum / 4);
119  } else {
120  region = 1;
121  towerrow = towernum % 4;
122  towercol = (towernum / 4) - 4;
123  }
124  }
125  } else {
126  if (cardNo != 6) {
127  if (towernum < 16) {
128  region = 0;
129  towerrow = towernum % 4;
130  towercol = towernum / 4;
131  } else {
132  region = 1;
133  towerrow = towernum % 4;
134  towercol = (towernum / 4) - 4;
135  }
136  } else {
137  if (towernum < 16) {
138  region = 0;
139  towerrow = towernum % 4;
140  towercol = towernum / 4;
141  } else {
142  region = 1;
143  towerrow = towernum % 4;
144  towercol = 7 - (towernum / 4);
145  }
146  }
147  }
148  returnVec.at(0) = region;
149  returnVec.at(1) = towerrow;
150  returnVec.at(2) = towercol;
151  return returnVec;
152 }
153 
155  for (int i = 0; i < 2; i++)
156  tauBits.at(i) = calcTauBit(regions.at(i));
157 }
158 
160  bitset<4> etaPattern;
161  bitset<4> phiPattern;
162 
163  bitset<4> badPattern5(string("0101"));
164  bitset<4> badPattern7(string("0111"));
165  bitset<4> badPattern9(string("1001"));
166  bitset<4> badPattern10(string("1010"));
167  bitset<4> badPattern11(string("1011"));
168  bitset<4> badPattern13(string("1101"));
169  bitset<4> badPattern14(string("1110"));
170  bitset<4> badPattern15(string("1111"));
171 
172  for (int i = 0; i < 4; i++) {
173  phiPattern[i] = region.getActivityBit(i, 0) ||
174  region.getActivityBit(i, 1) ||
175  region.getActivityBit(i, 2) || region.getActivityBit(i, 3);
176  etaPattern[i] = region.getActivityBit(0, i) ||
177  region.getActivityBit(1, i) ||
178  region.getActivityBit(2, i) || region.getActivityBit(3, i);
179  }
180 
181  bool answer;
182 
183  if (etaPattern != badPattern5 && etaPattern != badPattern7 &&
184  etaPattern != badPattern10 && etaPattern != badPattern11 &&
185  etaPattern != badPattern13 && etaPattern != badPattern14 &&
186  etaPattern != badPattern15 && phiPattern != badPattern5 &&
187  phiPattern != badPattern7 && phiPattern != badPattern10 &&
188  phiPattern != badPattern11 && phiPattern != badPattern13 &&
189  phiPattern != badPattern14 && phiPattern != badPattern15 &&
190  etaPattern != badPattern9 && phiPattern != badPattern9) { // adding in "9"
191  // return false;
192  answer = false;
193  }
194  // else return true;
195  else {
196  answer = true;
197  }
198  // std::cout << "Tau veto set to " << answer << std::endl;
199  return answer;
200 }
201 
203  for (int i = 0; i < 2; i++) {
204  etIn10Bits.at(i) = (calcRegionSum(regions.at(i))) / 2;
205  overFlowBits.at(i) = (calcRegionSum(regions.at(i)) & 1);
206  }
207 }
208 
210  unsigned short sum = 0;
211  unsigned short overflow = 0;
212  for (int i = 0; i < 4; i++) {
213  for (int j = 0; j < 4; j++) {
214  unsigned short towerEt = region.getEtIn9Bits(i, j);
215  // If tower is saturated, peg the region to max value
216  // if(towerEt == 0x1FF) sum = 0x3FF; // HARDWARE DOESN'T DO THIS!!
217  // else
218  sum = sum + towerEt;
219  }
220  }
221  if (sum > 1023) {
222  sum = 1023;
223  overflow = 1;
224  }
225  unsigned short sumFullInfo = sum * 2 + overflow;
226  return sumFullInfo;
227 }
228 
230  for (int i = 0; i < 2; i++)
231  muonBits.at(i) = calcMuonBit(regions.at(i));
232 }
233 
235  unsigned short muonBit = 0;
236  for (int i = 0; i < 4; i++) {
237  for (int j = 0; j < 4; j++) {
238  muonBit = muonBit || region.getMuonBit(i, j);
239  }
240  }
241  return muonBit;
242 }
243 
245  std::cout << "Receiver Card " << cardNo << " in Crate " << crtNo << std::endl;
246 
247  for (int i = 0; i < 2; i++) {
248  std::cout << "Region " << i << " information" << std::endl;
249  regions.at(i).print();
250  std::cout << "Region Et sum " << etIn10Bits.at(i) << std::endl;
251  std::cout << "Tau Veto Bit " << tauBits.at(i) << std::endl;
252  std::cout << "Muon Bit " << muonBits.at(i) << std::endl;
253  }
254 }
L1RCTReceiverCard()=delete
unsigned short cardNo
unsigned short crtNo
unsigned short getEtIn9Bits(int i, int j) const
Definition: L1RCTRegion.cc:51
unsigned short getMuonBit(int i, int j) const
Definition: L1RCTRegion.cc:62
void fillInput(const std::vector< unsigned short > &input)
static std::string const input
Definition: EdmProvDump.cc:48
const L1RCTLookupTables * rctLookupTables_
std::vector< unsigned short > overFlowBits
unsigned short getActivityBit(int i, int j) const
Definition: L1RCTRegion.cc:74
unsigned short calcTauBit(L1RCTRegion region)
std::vector< unsigned short > etIn10Bits
void fileInput(char *filename)
unsigned short calcMuonBit(L1RCTRegion region)
std::vector< unsigned short > muonBits
std::vector< unsigned short > tauBits
unsigned short calcRegionSum(L1RCTRegion region)
col
Definition: cuy.py:1010
Signal rand(Signal arg)
Definition: vlib.cc:442
std::vector< unsigned short > towerToRegionMap(int towernum)
std::vector< L1RCTRegion > regions
answer
Definition: submit.py:45
unsigned int lookup(unsigned short ecalInput, unsigned short hcalInput, unsigned short fgbit, unsigned short crtNo, unsigned short crdNo, unsigned short twrNo) const