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