CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetFinderMethods.cc
Go to the documentation of this file.
1 // JetFinderMethods.cc
2 // Author: Alex Barbieri
3 //
4 // This file should contain the different algorithms used to find jets.
5 // Currently the standard is the sliding window method, used by both
6 // HI and PP.
7 
11 
13 
14 #include <vector>
15 
16 namespace l1t {
17 
18  int deltaGctPhi(const CaloRegion & region, const CaloRegion & neighbor)
19  {
20  int phi1 = region.hwPhi();
21  int phi2 = neighbor.hwPhi();
22  int diff = phi1 - phi2;
23  if (std::abs(phi1 - phi2) == L1CaloRegionDetId::N_PHI-1) { //18 regions in phi
24  diff = -diff/std::abs(diff);
25  }
26  return diff;
27  }
28 
29  // turn each central region into a jet
30  void passThroughJets(const std::vector<l1t::CaloRegion> * regions,
31  std::vector<l1t::Jet> * uncalibjets)
32  {
33  for(std::vector<CaloRegion>::const_iterator region = regions->begin(); region != regions->end(); region++) {
34  int jetQual = 0;
35  if( region->hwEta() < 4 || region->hwEta() > 17)
36  jetQual = 2;
37  int jetET = region->hwPt();
38  int jetEta = region->hwEta();
39  int jetPhi = region->hwPhi();
40 
41  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > jetLorentz(0,0,0,0);
42  l1t::Jet theJet(*&jetLorentz, jetET, jetEta, jetPhi, jetQual);
43  uncalibjets->push_back(theJet);
44  }
45  }
46 
47  void slidingWindowJetFinder(const int jetSeedThreshold,
48  const std::vector<l1t::CaloRegion> * regions,
49  std::vector<l1t::Jet> * uncalibjets)
50  {
51  // std::cout << "Jet Seed: " << jetSeedThreshold << std::endl;
52  for(std::vector<CaloRegion>::const_iterator region = regions->begin(); region != regions->end(); region++) {
53  int regionET = region->hwPt(); //regionPhysicalEt(*region);
54  if (regionET <= jetSeedThreshold) continue;
55  int neighborN_et = 0;
56  int neighborS_et = 0;
57  int neighborE_et = 0;
58  int neighborW_et = 0;
59  int neighborNE_et = 0;
60  int neighborSW_et = 0;
61  int neighborNW_et = 0;
62  int neighborSE_et = 0;
63  unsigned int nNeighbors = 0;
64  for(std::vector<CaloRegion>::const_iterator neighbor = regions->begin(); neighbor != regions->end(); neighbor++) {
65  int neighborET = neighbor->hwPt(); //regionPhysicalEt(*neighbor);
66  if(deltaGctPhi(*region, *neighbor) == 1 &&
67  (region->hwEta() ) == neighbor->hwEta()) {
68  neighborN_et = neighborET;
69  nNeighbors++;
70  continue;
71  }
72  else if(deltaGctPhi(*region, *neighbor) == -1 &&
73  (region->hwEta() ) == neighbor->hwEta()) {
74  neighborS_et = neighborET;
75  nNeighbors++;
76  continue;
77  }
78  else if(deltaGctPhi(*region, *neighbor) == 0 &&
79  (region->hwEta() + 1) == neighbor->hwEta()) {
80  neighborE_et = neighborET;
81  nNeighbors++;
82  continue;
83  }
84  else if(deltaGctPhi(*region, *neighbor) == 0 &&
85  (region->hwEta() - 1) == neighbor->hwEta()) {
86  neighborW_et = neighborET;
87  nNeighbors++;
88  continue;
89  }
90  else if(deltaGctPhi(*region, *neighbor) == 1 &&
91  (region->hwEta() + 1) == neighbor->hwEta()) {
92  neighborNE_et = neighborET;
93  nNeighbors++;
94  continue;
95  }
96  else if(deltaGctPhi(*region, *neighbor) == -1 &&
97  (region->hwEta() - 1) == neighbor->hwEta()) {
98  neighborSW_et = neighborET;
99  nNeighbors++;
100  continue;
101  }
102  else if(deltaGctPhi(*region, *neighbor) == 1 &&
103  (region->hwEta() - 1) == neighbor->hwEta()) {
104  neighborNW_et = neighborET;
105  nNeighbors++;
106  continue;
107  }
108  else if(deltaGctPhi(*region, *neighbor) == -1 &&
109  (region->hwEta() + 1) == neighbor->hwEta()) {
110  neighborSE_et = neighborET;
111  nNeighbors++;
112  continue;
113  }
114  }
115  if(regionET > neighborN_et &&
116  regionET > neighborNW_et &&
117  regionET > neighborW_et &&
118  regionET > neighborSW_et &&
119  regionET >= neighborNE_et &&
120  regionET >= neighborE_et &&
121  regionET >= neighborSE_et &&
122  regionET >= neighborS_et) {
123  unsigned int jetET = regionET +
124  neighborN_et + neighborS_et + neighborE_et + neighborW_et +
125  neighborNE_et + neighborSW_et + neighborSE_et + neighborNW_et;
126 
127  int jetPhi = region->hwPhi();
128  int jetEta = region->hwEta();
129 
130  bool neighborCheck = (nNeighbors == 8);
131  // On the eta edge we only expect 5 neighbors
132  if (!neighborCheck && (jetEta == 0 || jetEta == 21) && nNeighbors == 5)
133  neighborCheck = true;
134 
135  if (!neighborCheck) {
136  std::cout << "phi: " << jetPhi << " eta: " << jetEta << " n: " << nNeighbors << std::endl;
137  assert(false);
138  }
139 
140  //first iteration, eta cut defines forward
141  //const bool forward = (jetEta <= 4 || jetEta >= 17);
142  const bool forward = (jetEta < 4 || jetEta > 17);
143  int jetQual = 0;
144  if(forward)
145  jetQual |= 0x2;
146 
147  // check for input overflow regions
148  if(forward && regionET == 255) {
149  jetET = 1023; // 10 bit max
150  } else if(!forward && regionET == 1023) {
151  jetET = 1023; // 10 bit max
152  } else if(region->hwEta() == 17) {
153  if(neighborNE_et == 255 || neighborE_et == 255 || neighborSE_et == 255)
154  jetET = 1023; // 10 bit max
155  } else if(region->hwEta() == 4) {
156  if(neighborNW_et == 255 || neighborW_et == 255 || neighborSW_et == 255)
157  jetET = 1023; // 10 bit max
158  }
159 
160  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > jetLorentz(0,0,0,0);
161  l1t::Jet theJet(*&jetLorentz, jetET, jetEta, jetPhi, jetQual);
162  //l1t::Jet theJet(0, jetET, jetEta, jetPhi);
163 
164  uncalibjets->push_back(theJet);
165  }
166  }
167  }
168 
169  void TwelveByTwelveFinder(const int jetSeedThreshold,
170  const std::vector<l1t::CaloRegion> * regions,
171  std::vector<l1t::Jet> * uncalibjets)
172  {
173  // std::cout << "Jet Seed: " << jetSeedThreshold << std::endl;
174  for(std::vector<CaloRegion>::const_iterator region = regions->begin(); region != regions->end(); region++) {
175  int regionET = region->hwPt(); //regionPhysicalEt(*region);
176  if (regionET < jetSeedThreshold) continue;
177  int neighborN_et = 0;
178  int neighborS_et = 0;
179  int neighborE_et = 0;
180  int neighborW_et = 0;
181  int neighborNE_et = 0;
182  int neighborSW_et = 0;
183  int neighborNW_et = 0;
184  int neighborSE_et = 0;
185  unsigned int nNeighbors = 0;
186  for(std::vector<CaloRegion>::const_iterator neighbor = regions->begin(); neighbor != regions->end(); neighbor++) {
187  int neighborET = neighbor->hwPt(); //regionPhysicalEt(*neighbor);
188  if(deltaGctPhi(*region, *neighbor) == 1 &&
189  (region->hwEta() ) == neighbor->hwEta()) {
190  neighborN_et = neighborET;
191  nNeighbors++;
192  continue;
193  }
194  else if(deltaGctPhi(*region, *neighbor) == -1 &&
195  (region->hwEta() ) == neighbor->hwEta()) {
196  neighborS_et = neighborET;
197  nNeighbors++;
198  continue;
199  }
200  else if(deltaGctPhi(*region, *neighbor) == 0 &&
201  (region->hwEta() + 1) == neighbor->hwEta()) {
202  neighborE_et = neighborET;
203  nNeighbors++;
204  continue;
205  }
206  else if(deltaGctPhi(*region, *neighbor) == 0 &&
207  (region->hwEta() - 1) == neighbor->hwEta()) {
208  neighborW_et = neighborET;
209  nNeighbors++;
210  continue;
211  }
212  else if(deltaGctPhi(*region, *neighbor) == 1 &&
213  (region->hwEta() + 1) == neighbor->hwEta()) {
214  neighborNE_et = neighborET;
215  nNeighbors++;
216  continue;
217  }
218  else if(deltaGctPhi(*region, *neighbor) == -1 &&
219  (region->hwEta() - 1) == neighbor->hwEta()) {
220  neighborSW_et = neighborET;
221  nNeighbors++;
222  continue;
223  }
224  else if(deltaGctPhi(*region, *neighbor) == 1 &&
225  (region->hwEta() - 1) == neighbor->hwEta()) {
226  neighborNW_et = neighborET;
227  nNeighbors++;
228  continue;
229  }
230  else if(deltaGctPhi(*region, *neighbor) == -1 &&
231  (region->hwEta() + 1) == neighbor->hwEta()) {
232  neighborSE_et = neighborET;
233  nNeighbors++;
234  continue;
235  }
236  }
237  unsigned int jetET = regionET +
238  neighborN_et + neighborS_et + neighborE_et + neighborW_et +
239  neighborNE_et + neighborSW_et + neighborSE_et + neighborNW_et;
240 
241  int jetPhi = region->hwPhi();
242  int jetEta = region->hwEta();
243 
244  bool neighborCheck = (nNeighbors == 8);
245  // On the eta edge we only expect 5 neighbors
246  if (!neighborCheck && (jetEta == 0 || jetEta == 21) && nNeighbors == 5)
247  neighborCheck = true;
248 
249  if (!neighborCheck) {
250  std::cout << "phi: " << jetPhi << " eta: " << jetEta << " n: " << nNeighbors << std::endl;
251  assert(false);
252  }
253 
254  //first iteration, eta cut defines forward
255  //const bool forward = (jetEta <= 4 || jetEta >= 17);
256  const bool forward = (jetEta < 4 || jetEta > 17);
257  int jetQual = 0;
258  if(forward)
259  jetQual |= 0x2;
260 
261  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > jetLorentz(0,0,0,0);
262  l1t::Jet theJet(*&jetLorentz, jetET, jetEta, jetPhi, jetQual);
263  //l1t::Jet theJet(0, jetET, jetEta, jetPhi);
264 
265  uncalibjets->push_back(theJet);
266  }
267  }
268 
269  void TwoByTwoFinder(const std::vector<l1t::CaloRegion> * regions,
270  std::vector<l1t::Jet> * uncalibjets)
271  {
272  for(std::vector<CaloRegion>::const_iterator region = regions->begin(); region != regions->end(); region++) {
273  int regionET = region->hwPt();
274  int neighborN_et = 0;
275  int neighborS_et = 0;
276  int neighborE_et = 0;
277  int neighborW_et = 0;
278  int neighborNE_et = 0;
279  int neighborSW_et = 0;
280  int neighborNW_et = 0;
281  int neighborSE_et = 0;
282  unsigned int nNeighbors = 0;
283  for(std::vector<CaloRegion>::const_iterator neighbor = regions->begin(); neighbor != regions->end(); neighbor++) {
284  int neighborET = neighbor->hwPt();
285  if(deltaGctPhi(*region, *neighbor) == 1 &&
286  (region->hwEta() ) == neighbor->hwEta()) {
287  neighborN_et = neighborET;
288  nNeighbors++;
289  continue;
290  }
291  else if(deltaGctPhi(*region, *neighbor) == -1 &&
292  (region->hwEta() ) == neighbor->hwEta()) {
293  neighborS_et = neighborET;
294  nNeighbors++;
295  continue;
296  }
297  else if(deltaGctPhi(*region, *neighbor) == 0 &&
298  (region->hwEta() + 1) == neighbor->hwEta()) {
299  neighborE_et = neighborET;
300  nNeighbors++;
301  continue;
302  }
303  else if(deltaGctPhi(*region, *neighbor) == 0 &&
304  (region->hwEta() - 1) == neighbor->hwEta()) {
305  neighborW_et = neighborET;
306  nNeighbors++;
307  continue;
308  }
309  else if(deltaGctPhi(*region, *neighbor) == 1 &&
310  (region->hwEta() + 1) == neighbor->hwEta()) {
311  neighborNE_et = neighborET;
312  nNeighbors++;
313  continue;
314  }
315  else if(deltaGctPhi(*region, *neighbor) == -1 &&
316  (region->hwEta() - 1) == neighbor->hwEta()) {
317  neighborSW_et = neighborET;
318  nNeighbors++;
319  continue;
320  }
321  else if(deltaGctPhi(*region, *neighbor) == 1 &&
322  (region->hwEta() - 1) == neighbor->hwEta()) {
323  neighborNW_et = neighborET;
324  nNeighbors++;
325  continue;
326  }
327  else if(deltaGctPhi(*region, *neighbor) == -1 &&
328  (region->hwEta() + 1) == neighbor->hwEta()) {
329  neighborSE_et = neighborET;
330  nNeighbors++;
331  continue;
332  }
333 
334  }
335  if(regionET > neighborN_et &&
336  regionET > neighborNW_et &&
337  regionET > neighborW_et &&
338  regionET > neighborSW_et &&
339  regionET >= neighborNE_et &&
340  regionET >= neighborE_et &&
341  regionET >= neighborSE_et &&
342  regionET >= neighborS_et) {
343 
344  // use the highest-pT 2x2 jet inside this 3x3
345  unsigned int jetET_NW;
346  unsigned int jetET_NE;
347  unsigned int jetET_SW;
348  unsigned int jetET_SE;
349 
350  jetET_NW = regionET + neighborW_et + neighborNW_et + neighborN_et;
351  jetET_NE = regionET + neighborE_et + neighborNE_et + neighborN_et;
352  jetET_SW = regionET + neighborS_et + neighborSW_et + neighborW_et;
353  jetET_SE = regionET + neighborS_et + neighborSE_et + neighborE_et;
354 
355  unsigned int jetET = std::max(jetET_NW, jetET_NE);
356  jetET = std::max(jetET, jetET_SW);
357  jetET = std::max(jetET, jetET_SE);
358 
359  int jetPhi = region->hwPhi();
360  int jetEta = region->hwEta();
361 
362  bool neighborCheck = (nNeighbors == 8);
363  // On the eta edge we only expect 5 neighbor
364  if (!neighborCheck && (jetEta == 0 || jetEta == 21) && nNeighbors == 5)
365  neighborCheck = true;
366 
367  if (!neighborCheck) {
368  std::cout << "phi: " << jetPhi << " eta: " << jetEta << " n: " << nNeighbors << std::endl;
369  assert(false);
370  }
371 
372  //first iteration, eta cut defines forward
373  const bool forward = (jetEta < 4 || jetEta > 17);
374  int jetQual = 0;
375  if(forward)
376  jetQual |= 0x2;
377 
378  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > jetLorentz(0,0,0,0);
379  l1t::Jet theJet(*&jetLorentz, jetET, jetEta, jetPhi, jetQual);
380  uncalibjets->push_back(theJet);
381  }
382  }
383  }
384 }
assert(m_qm.get())
int hwPhi() const
Definition: L1Candidate.cc:79
void TwelveByTwelveFinder(const int, const std::vector< l1t::CaloRegion > *regions, std::vector< l1t::Jet > *uncalibjets)
void TwoByTwoFinder(const std::vector< l1t::CaloRegion > *regions, std::vector< l1t::Jet > *uncalibjets)
Definition: Jet.h:13
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void passThroughJets(const std::vector< l1t::CaloRegion > *regions, std::vector< l1t::Jet > *uncalibjets)
int deltaGctPhi(const CaloRegion &region, const CaloRegion &neighbor)
void slidingWindowJetFinder(const int, const std::vector< l1t::CaloRegion > *regions, std::vector< l1t::Jet > *uncalibjets)
tuple cout
Definition: gather_cfg.py:121
static const unsigned N_PHI