CMS 3D CMS Logo

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