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