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