CMS 3D CMS Logo

L1RCTJetSummaryCard.cc
Go to the documentation of this file.
4 
5 #include <iostream>
6 using std::cout;
7 using std::endl;
8 #include <vector>
9 using std::vector;
10 #include <bitset>
11 using std::bitset;
12 
14  : crtNo(crtNo),
15  rctLookupTables_(rctLookupTables),
16  isolatedEGObjects(4),
17  nonisolatedEGObjects(4),
18  jetRegions(22),
19  HFRegions(8),
20  barrelRegions(14),
21  mipBits(0),
22  quietBits(0),
23  tauBits(0),
24  overFlowBits(0),
25  hfFineGrainBits(8)
26 // quietThreshold(3)
27 {}
28 
29 void L1RCTJetSummaryCard::fillHFRegionSums(const std::vector<unsigned short> &hfRegionSums) {
30  // std::cout << "JSC.fillHFRegionSums() entered" << std::endl;
31  for (int i = 0; i < 8; i++) {
32  // std::cout << "filling hf region at " << i << std::endl;
33  HFRegions.at(i) = rctLookupTables_->lookup((hfRegionSums.at(i) / 2), crtNo, 999, i);
34  // std::cout << "hf region " << i << " et filled" << std::endl;
35  hfFineGrainBits.at(i) = (hfRegionSums.at(i) & 1);
36  // std::cout << "hf region " << i << " fine grain bit filled" << std::endl;
37  }
38 }
39 
41  if (crtNo < 9) {
42  for (int i = 0; i < 4; i++) {
43  jetRegions.at(i) = HFRegions.at(i);
44  jetRegions.at(i + 11) = HFRegions.at(i + 4);
45  }
46  jetRegions.at(4) = barrelRegions.at(12);
47  jetRegions.at(5) = barrelRegions.at(9);
48  jetRegions.at(6) = barrelRegions.at(8);
49  jetRegions.at(7) = barrelRegions.at(5);
50  jetRegions.at(8) = barrelRegions.at(4);
51  jetRegions.at(9) = barrelRegions.at(1);
52  jetRegions.at(10) = barrelRegions.at(0);
53 
54  jetRegions.at(15) = barrelRegions.at(13);
55  jetRegions.at(16) = barrelRegions.at(11);
56  jetRegions.at(17) = barrelRegions.at(10);
57  jetRegions.at(18) = barrelRegions.at(7);
58  jetRegions.at(19) = barrelRegions.at(6);
59  jetRegions.at(20) = barrelRegions.at(3);
60  jetRegions.at(21) = barrelRegions.at(2);
61  }
62  if (crtNo >= 9) {
63  jetRegions.at(0) = barrelRegions.at(0);
64  jetRegions.at(1) = barrelRegions.at(1);
65  jetRegions.at(2) = barrelRegions.at(4);
66  jetRegions.at(3) = barrelRegions.at(5);
67  jetRegions.at(4) = barrelRegions.at(8);
68  jetRegions.at(5) = barrelRegions.at(9);
69  jetRegions.at(6) = barrelRegions.at(12);
70 
71  jetRegions.at(11) = barrelRegions.at(2);
72  jetRegions.at(12) = barrelRegions.at(3);
73  jetRegions.at(13) = barrelRegions.at(6);
74  jetRegions.at(14) = barrelRegions.at(7);
75  jetRegions.at(15) = barrelRegions.at(10);
76  jetRegions.at(16) = barrelRegions.at(11);
77  jetRegions.at(17) = barrelRegions.at(13);
78  for (int i = 0; i < 4; i++) {
79  jetRegions.at(i + 7) = HFRegions.at(i);
80  jetRegions.at(i + 18) = HFRegions.at(i + 4);
81  }
82  }
83 }
84 
85 void L1RCTJetSummaryCard::fillIsolatedEGObjects(const std::vector<unsigned short> &isoElectrons) {
86  // sort(isoElectrons.begin(),isoElectrons.end());
87  // reverse(isoElectrons.begin(),isoElectrons.end());
88 
89  std::vector<unsigned short> isoCards03(8);
90  std::vector<unsigned short> isoCards46(8);
91  std::vector<unsigned short> sortIso(8);
92 
93  for (int i = 0; i < 8; i++) {
94  isoCards03.at(i) = isoElectrons.at(i);
95  }
96  for (int i = 0; i < 6; i++) {
97  isoCards46.at(i) = isoElectrons.at(i + 8);
98  }
99  isoCards46.at(6) = 0;
100  isoCards46.at(7) = 0;
101 
102  asicSort(isoCards03);
103  asicSort(isoCards46);
104 
105  sortIso.at(0) = isoCards03.at(0);
106  sortIso.at(2) = isoCards03.at(2);
107  sortIso.at(4) = isoCards03.at(4);
108  sortIso.at(6) = isoCards03.at(6);
109  sortIso.at(1) = isoCards46.at(0);
110  sortIso.at(3) = isoCards46.at(2);
111  sortIso.at(5) = isoCards46.at(4);
112  sortIso.at(7) = isoCards46.at(6);
113 
114  asicSort(sortIso);
115 
116  // for(int i = 0; i<4; i++){
117  // isolatedEGObjects.at(i) = isoElectrons.at(i);
118  // isolatedEGObjects.at(i) = sortIso.at(2*i);
119  //}
120  isolatedEGObjects.at(0) = sortIso.at(4);
121  isolatedEGObjects.at(1) = sortIso.at(6);
122  isolatedEGObjects.at(2) = sortIso.at(0);
123  isolatedEGObjects.at(3) = sortIso.at(2);
124 }
125 
126 void L1RCTJetSummaryCard::fillNonIsolatedEGObjects(const std::vector<unsigned short> &nonIsoElectrons) {
127  // sort(nonIsoElectrons.begin(),nonIsoElectrons.end());
128  // reverse(nonIsoElectrons.begin(),nonIsoElectrons.end());
129 
130  std::vector<unsigned short> nonIsoCards03(8);
131  std::vector<unsigned short> nonIsoCards46(8);
132  std::vector<unsigned short> sortNonIso(8);
133 
134  for (int i = 0; i < 8; i++) {
135  nonIsoCards03.at(i) = nonIsoElectrons.at(i);
136  }
137  for (int i = 0; i < 6; i++) {
138  nonIsoCards46.at(i) = nonIsoElectrons.at(i + 8);
139  }
140  nonIsoCards46.at(6) = 0;
141  nonIsoCards46.at(7) = 0;
142 
143  asicSort(nonIsoCards03);
144  asicSort(nonIsoCards46);
145 
146  sortNonIso.at(0) = nonIsoCards03.at(0);
147  sortNonIso.at(2) = nonIsoCards03.at(2);
148  sortNonIso.at(4) = nonIsoCards03.at(4);
149  sortNonIso.at(6) = nonIsoCards03.at(6);
150  sortNonIso.at(1) = nonIsoCards46.at(0);
151  sortNonIso.at(3) = nonIsoCards46.at(2);
152  sortNonIso.at(5) = nonIsoCards46.at(4);
153  sortNonIso.at(7) = nonIsoCards46.at(6);
154 
155  asicSort(sortNonIso);
156 
157  // for(int i = 0; i<4; i++){
158  // nonisolatedEGObjects.at(i) = nonIsoElectrons.at(i);
159  // nonisolatedEGObjects.at(i) = sortNonIso.at(2*i);
160  //}
161  nonisolatedEGObjects.at(0) = sortNonIso.at(4);
162  nonisolatedEGObjects.at(1) = sortNonIso.at(6);
163  nonisolatedEGObjects.at(2) = sortNonIso.at(0);
164  nonisolatedEGObjects.at(3) = sortNonIso.at(2);
165 }
166 
167 void L1RCTJetSummaryCard::fillMIPBits(const std::vector<unsigned short> &mip) {
168  bitset<14> mips;
169  for (int i = 0; i < 14; i++)
170  mips[i] = mip.at(i);
171  mipBits = mips.to_ulong();
172 }
173 
174 void L1RCTJetSummaryCard::fillTauBits(const std::vector<unsigned short> &tau) {
175  bitset<14> taus;
176  for (int i = 0; i < 14; i++)
177  taus[i] = tau.at(i);
178  tauBits = taus.to_ulong();
179 }
180 
181 void L1RCTJetSummaryCard::fillOverFlowBits(const std::vector<unsigned short> &overflow) {
182  bitset<14> overflows;
183  for (int i = 0; i < 14; i++)
184  overflows[i] = overflow.at(i);
185  overFlowBits = overflows.to_ulong();
186 }
187 
189  bitset<14> quiet;
190 
193 
194  // use one threshold for barrel regions (first 8 in list, cards 0-3)
195  for (int i = 0; i < 8; i++) {
197  quiet[i] = false; // switched 0 and 1
198  else
199  quiet[i] = true;
200  }
201  // use second for endcap regions (last 6 in list, cards 4-6)
202  for (int i = 8; i < 14; i++) {
204  quiet[i] = false; // switched 0 and 1
205  else
206  quiet[i] = true;
207  }
208 
209  quietBits = quiet.to_ulong();
210 }
211 
212 // Sorts the egamma candidates with the algorithm used in the ASIC
213 void L1RCTJetSummaryCard::asicSort(std::vector<unsigned short> &electrons) {
214  unsigned short temp, temp2;
215 
217 
218  // Rotate items prior to next compare
219 
220  temp = electrons.at(7);
221  electrons.at(7) = electrons.at(5);
222  electrons.at(5) = electrons.at(3);
223  electrons.at(3) = electrons.at(1);
224  electrons.at(1) = temp;
225 
226  // Second compare
227 
229 
230  // Second rotate, different order this time
231 
232  temp = electrons.at(7);
233  temp2 = electrons.at(5);
234  electrons.at(7) = electrons.at(3);
235  electrons.at(5) = electrons.at(1);
236  electrons.at(3) = temp;
237  electrons.at(1) = temp2;
238 
239  // Third compare
240 
242 
243  // Third rotate, different again
244 
245  temp = electrons.at(1);
246  electrons.at(1) = electrons.at(3);
247  electrons.at(3) = electrons.at(5);
248  electrons.at(5) = electrons.at(7);
249  electrons.at(7) = temp;
250 
251  // Fourth compare
252 
254 }
255 
256 // Used in ASIC sort algorithm
257 void L1RCTJetSummaryCard::asicCompare(std::vector<unsigned short> &array) {
258  int i;
259  unsigned short temp;
260  for (i = 0; i < 4; i++) {
261  unsigned short rank1 = rctLookupTables_->emRank(array.at(2 * i) >> 4);
262  unsigned short rank2 = rctLookupTables_->emRank(array.at(2 * i + 1) >> 4);
263 
264  if (rank1 < rank2) // currently bottom 3 bits are rgn,crd
265  {
266  temp = array.at(2 * i);
267  array.at(2 * i) = array.at((2 * i) + 1);
268  array.at((2 * i) + 1) = temp;
269  }
270  }
271 }
272 
274  std::cout << "tauBits " << tauBits << std::endl;
275  std::cout << "MIPBits " << mipBits << std::endl;
276  std::cout << "QuietBits " << quietBits << std::endl;
277  for (int i = 0; i < 4; i++) {
278  std::cout << "isoElectron " << i << " " << isolatedEGObjects.at(i) << std::endl;
279  ;
280  std::cout << "nonIsoElectron " << i << " " << nonisolatedEGObjects.at(i) << std::endl;
281  }
282  std::cout << "Jets ";
283  for (int i = 0; i < 22; i++)
284  std::cout << jetRegions.at(i) << " ";
285  std::cout << std::endl;
286 }
unsigned short overFlowBits
void fillIsolatedEGObjects(const std::vector< unsigned short > &isoElectrons)
std::vector< unsigned short > nonisolatedEGObjects
unsigned int lookup(unsigned short ecalInput, unsigned short hcalInput, unsigned short fgbit, unsigned short crtNo, unsigned short crdNo, unsigned short twrNo) const
std::vector< unsigned short > isolatedEGObjects
std::vector< unsigned short > HFRegions
void asicCompare(std::vector< unsigned short > &array)
void fillOverFlowBits(const std::vector< unsigned short > &overflow)
void fillHFRegionSums(const std::vector< unsigned short > &hfRegionSums)
std::vector< unsigned short > jetRegions
std::vector< unsigned short > barrelRegions
const L1RCTParameters * rctParameters() const
void fillTauBits(const std::vector< unsigned short > &tau)
unsigned jscQuietThresholdBarrel() const
void asicSort(std::vector< unsigned short > &electrons)
std::vector< unsigned short > hfFineGrainBits
void fillNonIsolatedEGObjects(const std::vector< unsigned short > &nonIsoElectrons)
void fillMIPBits(const std::vector< unsigned short > &mip)
L1RCTJetSummaryCard()=delete
unsigned jscQuietThresholdEndcap() const
unsigned int emRank(unsigned short energy) const
const L1RCTLookupTables * rctLookupTables_