CMS 3D CMS Logo

L1RCTElectronIsolationCard.cc
Go to the documentation of this file.
4 
5 #include <iomanip>
6 #include <iostream>
7 
9  int crateNumber, int cardNumber, const L1RCTLookupTables *rctLookupTables)
10  : crtNo(crateNumber), cardNo(cardNumber), rctLookupTables_(rctLookupTables),
11  isoElectrons(2), nonIsoElectrons(2), regions(2) {
12  regions.push_back(L1RCTRegion());
13  regions.push_back(L1RCTRegion());
14 }
15 
17 
19  std::vector<unsigned short> region0Electrons =
21  std::vector<unsigned short> region1Electrons =
23  isoElectrons.at(0) = region0Electrons.at(0);
24  isoElectrons.at(1) = region1Electrons.at(0);
25  nonIsoElectrons.at(0) = region0Electrons.at(1);
26  nonIsoElectrons.at(1) = region1Electrons.at(1);
27 }
28 
29 // This method is the bulk of this class. It finds the electrons given a
30 // pointer to a region. It will return the largest nonIsoElectron candidate and
31 // the largest isoElectron candidate. A deposit is an electron candidate if the
32 // h/e||fg bit is not on and it is higher energy than it's direct four
33 // neighbors. An electron candidate is *always* a non-isolated electron. If it
34 // also passes the neighbor cuts then it is an isolated electron as well.
35 std::vector<unsigned short>
37  int regionNum) {
38 
39  unsigned short nonIsoElectron = 0;
40  unsigned short isoElectron = 0;
41 
42  // i is row and j is column
43  for (int i = 0; i < 4; i++) {
44  for (int j = 0; j < 4; j++) {
45 
46  unsigned short primaryEt = region.getEtIn7Bits(i, j);
47  unsigned short primaryHE_FG = region.getHE_FGBit(i, j);
48 
49  unsigned short northEt = region.getEtIn7Bits(i - 1, j);
50  unsigned short southEt = region.getEtIn7Bits(i + 1, j);
51  unsigned short westEt = region.getEtIn7Bits(i, j - 1);
52  unsigned short eastEt = region.getEtIn7Bits(i, j + 1);
53  unsigned short neEt = region.getEtIn7Bits(i - 1, j + 1);
54  unsigned short nwEt = region.getEtIn7Bits(i - 1, j - 1);
55  unsigned short seEt = region.getEtIn7Bits(i + 1, j + 1);
56  unsigned short swEt = region.getEtIn7Bits(i + 1, j - 1);
57 
58  unsigned short northHE_FG = region.getHE_FGBit(i - 1, j);
59  unsigned short southHE_FG = region.getHE_FGBit(i + 1, j);
60  unsigned short westHE_FG = region.getHE_FGBit(i, j - 1);
61  unsigned short eastHE_FG = region.getHE_FGBit(i, j + 1);
62  unsigned short neHE_FG = region.getHE_FGBit(i - 1, j + 1);
63  unsigned short nwHE_FG = region.getHE_FGBit(i - 1, j - 1);
64  unsigned short seHE_FG = region.getHE_FGBit(i + 1, j + 1);
65  unsigned short swHE_FG = region.getHE_FGBit(i + 1, j - 1);
66 
67  bool top = false;
68 
69  int nCrate = crateNumber();
70  int nCard = cardNumber();
71  int nRegion = regionNum;
72 
73  // top row of crate
74  if (nCard == 0 || nCard == 2 || nCard == 4 ||
75  (nCard == 6 && nRegion == 0)) {
76  top = true;
77  }
78  // bottom row of crate
79  else if (nCard == 1 || nCard == 3 || nCard == 5 ||
80  (nCard == 6 && nRegion == 1)) {
81  } // top already false
82  else {
83  std::cerr << "Error! EIC top assignment"
84  << std::endl; // this shouldn't happen!
85  }
86 
87  // The following values are used for zeroing and determining whether or
88  // not a tower is a "candidate". The original primaryEt, northEt, neEt,
89  // etc. are used to calculate vetoes and must not be zeroed.
90 
91  unsigned short primaryTowerEt = primaryEt;
92  unsigned short northTowerEt = northEt;
93  unsigned short southTowerEt = southEt;
94  unsigned short eastTowerEt = eastEt;
95  unsigned short westTowerEt = westEt;
96 
97  // In order to ensure proper selection of candidate tower and neighbor,
98  // if two neighbor energies are equal, one is set to zero (in the
99  // appropriate regions, those for which tp_lf bit is set to 0 in
100  // Pam's JCCTest/EGWithShare.cc).
101 
102  if (primaryEt > 0) // this value should maybe be customizable?
103  {
104  if (nCard != 6) // all cards except 6
105  {
106  if (top && nCrate >= 9) // top row of regions in positive-eta crate
107  {
108  if (westTowerEt == eastTowerEt)
109  westTowerEt = 0;
110  if (southTowerEt == northTowerEt)
111  southTowerEt = 0;
112  if (southTowerEt == eastTowerEt)
113  southTowerEt = 0;
114  if (westTowerEt == northTowerEt)
115  westTowerEt = 0;
116  } else if ((!top) &&
117  nCrate < 9) // bottom row of regions in negative-eta crate
118  {
119  if (eastTowerEt == westTowerEt)
120  eastTowerEt = 0;
121  if (northTowerEt == southTowerEt)
122  northTowerEt = 0;
123  if (northTowerEt == westTowerEt)
124  northTowerEt = 0;
125  if (eastTowerEt == southTowerEt)
126  eastTowerEt = 0;
127  }
128  } else // card 6
129  {
130  // only +eta card 6 needs to have zeroing. Pam sez.
131  // -eta card 6 does what it's supposed to even w/o zeroing.
132  if (nRegion == 0 && nCrate >= 9) {
133  if (westTowerEt == eastTowerEt)
134  westTowerEt = 0;
135  if (southTowerEt == northTowerEt)
136  southTowerEt = 0;
137  if (southTowerEt == eastTowerEt)
138  southTowerEt = 0;
139  if (westTowerEt == northTowerEt)
140  westTowerEt = 0;
141  }
142  }
143  }
144 
145  // This section compares the energies in the primary tower with the
146  // surrounding towers to determine whether or not the primary tower
147  // should be considered a "candidate".
148 
149  bool candidate = false;
150 
151  // for case where primary tower et greater than all neighbors -> candidate
152  if (primaryEt > northEt && primaryEt > southEt && primaryEt > eastEt &&
153  primaryEt > westEt && !primaryHE_FG) {
154  candidate = true;
155  }
156 
157  // if primary et less than any neighbors (or HE_FG veto set) NOT a
158  // candidate!
159  else if (primaryEt < northEt || primaryEt < southEt ||
160  primaryEt < eastEt || primaryEt < westEt || primaryHE_FG) {
161  } // candidate already false
162 
163  else // Case of primary tower et being equal to any of its neighbors.
164  // This section determines which tower gets the candidate.
165  // See AboutTP.pdf document, figure on p. 4, for clarification.
166  // Zeroed values are used in this calculation.
167  {
168  if (primaryEt > 0) {
169  if (nCrate >= 9) // positive eta
170  {
171  if (top) // top row of regions in crate. tp_lf == 0
172  // priority order: east < south < north < west
173  {
174  if (westTowerEt == primaryTowerEt)
175  candidate = true;
176  else if (northTowerEt == primaryTowerEt)
177  candidate = false;
178  else if (southTowerEt == primaryTowerEt)
179  candidate = true;
180  else if (eastTowerEt == primaryTowerEt)
181  candidate = false;
182  }
183 
184  else // bottom row of regions in crate. tp_lf == 1
185  // priority order: west < north < south < east
186  {
187  if (eastTowerEt == primaryTowerEt)
188  candidate = true;
189  else if (southTowerEt == primaryTowerEt)
190  candidate = true;
191  else if (northTowerEt == primaryTowerEt)
192  candidate = false;
193  else if (westTowerEt == primaryTowerEt)
194  candidate = false;
195  if (nCard == 6) // card 6. tp_lf == 1
196  {
197  // priority order: east < north < south < west
198  if (westTowerEt == primaryTowerEt)
199  candidate = true;
200  else if (southTowerEt == primaryTowerEt)
201  candidate = true;
202  else if (northTowerEt == primaryTowerEt)
203  candidate = false;
204  else if (eastTowerEt == primaryTowerEt)
205  candidate = false;
206  }
207  }
208  } else // negative eta
209  {
210  if (top) // top row of regions in crate. tp_lf == 1
211  // priority order: east < south < north < west
212  {
213  if (westTowerEt == primaryTowerEt)
214  candidate = true;
215  else if (northTowerEt == primaryTowerEt)
216  candidate = true;
217  else if (southTowerEt == primaryTowerEt)
218  candidate = false;
219  else if (eastTowerEt == primaryTowerEt)
220  candidate = false;
221  if (nCard == 6) // card 6. tp_lf == 0
222  // east < south < north < west
223  {
224  if (westTowerEt == primaryTowerEt)
225  candidate = false;
226  else if (northTowerEt == primaryTowerEt)
227  candidate = false;
228  else if (southTowerEt == primaryTowerEt)
229  candidate = true;
230  else if (eastTowerEt == primaryTowerEt)
231  candidate = true;
232  }
233  } else // bottom row of regions. tp_lf == 0
234  // west < north < south < east
235  {
236  if (eastTowerEt == primaryTowerEt)
237  candidate = true;
238  else if (southTowerEt == primaryTowerEt)
239  candidate = false;
240  else if (northTowerEt == primaryTowerEt)
241  candidate = true;
242  else if (westTowerEt == primaryTowerEt)
243  candidate = false;
244 
245  if (nCard == 6) // card 6. tp_lf == 1
246  // west < north < south < east
247  {
248  if (eastTowerEt == primaryTowerEt)
249  candidate = true;
250  else if (southTowerEt == primaryTowerEt)
251  candidate = true;
252  else if (northTowerEt == primaryTowerEt)
253  candidate = false;
254  else if (westTowerEt == primaryTowerEt)
255  candidate = false;
256  }
257  }
258  }
259  }
260  } // end of if (primary == neighbors)
261 
262  if (candidate) {
263 
264  // Either zeroed or non-zeroed set of values can be used here --
265  // neighbor tower only zeroed if another neighbor tower of same
266  // energy. Max sum calculated from primary and only one neighbor
267  // tower, and always one neighbor tower left over, so value of sum
268  // is not affected. Currently using non-zeroed.
269  unsigned short candidateEt =
270  calcMaxSum(primaryEt, northEt, southEt, eastEt, westEt);
271 
272  // neighbor HE_FG veto true if neighbor has HE_FG set
273  bool neighborVeto = (nwHE_FG || northHE_FG || neHE_FG || westHE_FG ||
274  eastHE_FG || swHE_FG || southHE_FG || seHE_FG);
275 
276  // threshold for five-tower corner quiet veto
277  // int quietThreshold = 3; // 3 - loose isolation 0 - very tight
278  // isolation int quietThreshold = 7; // ECALGREN int quietThreshold = 0;
279  // // HCALGREN
280  unsigned quietThreshold =
282 
283  bool nw = false;
284  bool ne = false;
285  bool sw = false;
286  bool se = false;
287  bool n = false;
288  bool w = false;
289  bool s = false;
290  bool e = false;
291 
292  // individual neighbor vetoes set if neighbor is over threshold
293  if (nwEt >= quietThreshold)
294  nw = true;
295  if (neEt >= quietThreshold)
296  ne = true;
297  if (swEt >= quietThreshold)
298  sw = true;
299  if (seEt >= quietThreshold)
300  se = true;
301  if (northEt >= quietThreshold)
302  n = true;
303  if (southEt >= quietThreshold)
304  s = true;
305  if (westEt >= quietThreshold)
306  w = true;
307  if (eastEt >= quietThreshold)
308  e = true;
309 
310  // veto TRUE for each corner set if any individual tower in each set is
311  // over threshold
312  bool nwC = (sw || w || nw || n || ne);
313  bool neC = (nw || n || ne || e || se);
314  bool seC = (ne || e || se || s || sw);
315  bool swC = (se || s || sw || w || nw);
316 
317  // overall quiet veto TRUE only if NO corner sets are quiet
318  // (all are "loud") -> non-isolated
319  bool quietVeto = (nwC && neC && seC && swC);
320 
321  // only isolated if both vetoes are false
322  // Note: quietThreshold = 0 forces all candidates to be non-iso
323  if (!(quietVeto || neighborVeto)) {
324  if (candidateEt > isoElectron)
325  isoElectron = candidateEt;
326  }
327  // otherwise, non-isolated
328  else if (candidateEt > nonIsoElectron)
329  nonIsoElectron = candidateEt;
330  }
331  }
332  }
333 
334  std::vector<unsigned short> candidates;
335  unsigned short fullIsoElectron =
336  isoElectron * 16 +
337  cardNo *
338  2; // leaves room for last bit -- region number, added in Crate.cc
339  candidates.push_back(fullIsoElectron);
340  unsigned short fullNonIsoElectron =
341  nonIsoElectron * 16 +
342  cardNo * 2; // leaves room for region info in last bit
343  candidates.push_back(fullNonIsoElectron);
344 
345  return candidates;
346 }
347 
348 unsigned short L1RCTElectronIsolationCard::calcMaxSum(unsigned short primaryEt,
349  unsigned short northEt,
350  unsigned short southEt,
351  unsigned short eastEt,
352  unsigned short westEt) {
353  unsigned short cardinals[4] = {northEt, southEt, eastEt, westEt};
354  unsigned short max = 0;
355  for (int i = 0; i < 4; i++) {
356  unsigned short test = primaryEt + cardinals[i];
357  if (test > max)
358  max = test;
359  }
360  return max;
361 }
362 
364  std::cout << "Electron isolation card " << cardNo << std::endl;
365  std::cout << "Region 0 Information" << std::endl;
366  regions.at(0).print();
367 
368  std::cout << "IsoElectron Candidate " << isoElectrons.at(0) << std::endl;
369  std::cout << "NonIsoElectron Candidate " << nonIsoElectrons.at(0) << std::endl
370  << std::endl;
371 
372  std::cout << "Region 1 Information" << std::endl;
373  regions.at(1).print();
374 
375  std::cout << "IsoElectron Candidate " << isoElectrons.at(1) << std::endl;
376  std::cout << "NonIsoElectron Candidate " << nonIsoElectrons.at(1)
377  << std::endl;
378 }
const double w
Definition: UKUtility.cc:23
unsigned short getEtIn7Bits(int i, int j) const
Definition: L1RCTRegion.cc:27
unsigned eicIsolationThreshold() const
std::vector< L1RCTRegion > regions
unsigned short getHE_FGBit(int i, int j) const
Definition: L1RCTRegion.cc:40
const L1RCTLookupTables * rctLookupTables_
std::vector< unsigned short > nonIsoElectrons
std::vector< unsigned short > isoElectrons
std::vector< unsigned short > calcElectronCandidates(const L1RCTRegion &region, int regionNum)
const L1RCTParameters * rctParameters() const
unsigned short calcMaxSum(unsigned short primaryEt, unsigned short northEt, unsigned short southEt, unsigned short eastEt, unsigned short westEt)