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