CMS 3D CMS Logo

Phase2L1CaloJetEmulator.h
Go to the documentation of this file.
1 #ifndef L1TRIGGER_L1CALOTRIGGER_PHASE2L1CALOJETEMULATOR_H
2 #define L1TRIGGER_L1CALOTRIGGER_PHASE2L1CALOJETEMULATOR_H
3 
5 #include <cstdlib>
6 
7 static constexpr int nBarrelEta = 34;
8 static constexpr int nBarrelPhi = 72;
9 static constexpr int nHgcalEta = 36;
10 static constexpr int nHgcalPhi = 72;
11 static constexpr int nHfEta = 24;
12 static constexpr int nHfPhi = 72;
13 static constexpr int nSTEta = 8;
14 static constexpr int nSTPhi = 24;
15 static constexpr int nJets = 10;
16 
17 namespace gctobj {
18 
19  class towerMax {
20  public:
21  float energy;
22  int phi;
23  int eta;
24  float energyMax;
25  int phiMax;
26  int etaMax;
27  int phiCenter;
28  int etaCenter;
29 
31  energy = 0;
32  phi = 0;
33  eta = 0;
34  energyMax = 0;
35  phiMax = 0;
36  etaMax = 0;
37  phiCenter = 0;
38  etaCenter = 0;
39  }
40  };
41 
42  class jetInfo {
43  public:
44  float seedEnergy;
45  float energy;
46  float tauEt;
47  int phi;
48  int eta;
49  float energyMax;
50  int phiMax;
51  int etaMax;
52  int phiCenter;
53  int etaCenter;
54 
55  jetInfo() {
56  seedEnergy = 0;
57  energy = 0;
58  tauEt = 0;
59  phi = 0;
60  eta = 0;
61  energyMax = 0;
62  phiMax = 0;
63  etaMax = 0;
64  phiCenter = 0;
65  etaCenter = 0;
66  }
67  };
68 
69  typedef struct {
70  float et;
71  int eta;
72  int phi;
73  float towerEt;
74  int towerEta;
75  int towerPhi;
76  int centerEta;
77  int centerPhi;
79 
80  typedef struct {
82  } etaStrip_t;
83 
84  typedef struct {
86  } hgcalRegion_t;
87 
88  typedef struct {
91 
92  typedef struct {
93  float et;
94  float hoe;
95  } GCTtower_t;
96 
97  typedef struct {
100 
101  inline int getPeakBinOf3(float et0, float et1, float et2) {
102  int x;
103  float temp;
104  if (et0 > et1) {
105  x = 0;
106  temp = et0;
107  } else {
108  x = 1;
109  temp = et1;
110  }
111  if (et2 > temp) {
112  x = 2;
113  }
114  return x;
115  }
116 
117  inline int getEtCenterOf3(float et0, float et1, float et2) {
118  float etSum = et0 + et1 + et2;
119  float iEtSum = 0.5 * et0 + 1.5 * et1 + 2.5 * et2;
120  int iAve = 0xEEF;
121  if (iEtSum <= etSum)
122  iAve = 0;
123  else if (iEtSum <= 2 * etSum)
124  iAve = 1;
125  else
126  iAve = 2;
127  return iAve;
128  }
129 
130  inline void makeST(const float GCTintTowers[nBarrelEta / 2][nBarrelPhi],
131  GCTsupertower_t supertower_return[nSTEta][nSTPhi]) {
132  float et_sumEta[nSTEta][nSTPhi][3];
133  float stripEta[nSTEta][nSTPhi][3];
134  float stripPhi[nSTEta][nSTPhi][3];
135 
136  float ex_et[nBarrelEta / 2 + 1][nBarrelPhi];
137  for (int j = 0; j < nBarrelPhi; j++) {
138  ex_et[nBarrelEta / 2][j] = 0;
139  for (int i = 0; i < nBarrelEta / 2; i++) {
140  ex_et[i][j] = GCTintTowers[i][j];
141  }
142  }
143 
144  int index_i = 0;
145  int index_j = 0;
146  for (int i = 0; i < nBarrelEta / 2 + 1; i += 3) { // 17+1 to divide into 6 supertowers, 7th and 8th to be set 0
147  index_j = 0;
148  for (int j = 0; j < nBarrelPhi; j += 3) { // 72 phi to 24 supertowers
149  stripEta[index_i][index_j][0] = ex_et[i][j] + ex_et[i][j + 1] + ex_et[i][j + 2];
150  stripEta[index_i][index_j][1] = ex_et[i + 1][j] + ex_et[i + 1][j + 1] + ex_et[i + 1][j + 2];
151  stripEta[index_i][index_j][2] = ex_et[i + 2][j] + ex_et[i + 2][j + 1] + ex_et[i + 2][j + 2];
152  stripPhi[index_i][index_j][0] = ex_et[i][j] + ex_et[i + 1][j] + ex_et[i + 2][j];
153  stripPhi[index_i][index_j][1] = ex_et[i][j + 1] + ex_et[i + 1][j + 1] + ex_et[i + 2][j + 1];
154  stripPhi[index_i][index_j][2] = ex_et[i][j + 2] + ex_et[i + 1][j + 2] + ex_et[i + 2][j + 2];
155  for (int k = 0; k < 3; k++) {
156  et_sumEta[index_i][index_j][k] = ex_et[i + k][j] + ex_et[i + k][j + 1] + ex_et[i + k][j + 2];
157  }
158  index_j++;
159  }
160  index_i++;
161  }
162  for (int i = 0; i < nSTEta; i++) {
163  for (int j = 0; j < nSTPhi; j++) {
165  temp.et = 0;
166  temp.eta = 0;
167  temp.phi = 0;
168  temp.towerEta = 0;
169  temp.towerPhi = 0;
170  temp.towerEt = 0;
171  temp.centerEta = 0;
172  temp.centerPhi = 0;
173  if (i < 6) {
174  float supertowerEt = et_sumEta[i][j][0] + et_sumEta[i][j][1] + et_sumEta[i][j][2];
175  temp.et = supertowerEt;
176  temp.eta = i;
177  temp.phi = j;
178  int peakEta = getPeakBinOf3(stripEta[i][j][0], stripEta[i][j][1], stripEta[i][j][2]);
179  temp.towerEta = peakEta;
180  int peakPhi = getPeakBinOf3(stripPhi[i][j][0], stripPhi[i][j][1], stripPhi[i][j][2]);
181  temp.towerPhi = peakPhi;
182  float peakEt = ex_et[i * 3 + peakEta][j * 3 + peakPhi];
183  temp.towerEt = peakEt;
184  int cEta = getEtCenterOf3(stripEta[i][j][0], stripEta[i][j][1], stripEta[i][j][2]);
185  temp.centerEta = cEta;
186  int cPhi = getEtCenterOf3(stripPhi[i][j][0], stripPhi[i][j][1], stripPhi[i][j][2]);
187  temp.centerPhi = cPhi;
188  }
189  supertower_return[i][j] = temp;
190  }
191  }
192  }
193 
194  inline void makeST_hgcal(const float hgcalTowers[nHgcalEta / 2][nHgcalPhi],
195  GCTsupertower_t supertower_return[nSTEta][nSTPhi]) {
196  float et_sumEta[nSTEta][nSTPhi][3];
197  float stripEta[nSTEta][nSTPhi][3];
198  float stripPhi[nSTEta][nSTPhi][3];
199 
200  int index_i = 0;
201  int index_j = 0;
202  for (int i = 0; i < nHgcalEta / 2; i += 3) { // 18 eta to 6 supertowers, 7th and 8th to be set 0
203  index_j = 0;
204  for (int j = 0; j < nHgcalPhi; j += 3) { // 72 phi to 24 supertowers
205  stripEta[index_i][index_j][0] = hgcalTowers[i][j] + hgcalTowers[i][j + 1] + hgcalTowers[i][j + 2];
206  stripEta[index_i][index_j][1] = hgcalTowers[i + 1][j] + hgcalTowers[i + 1][j + 1] + hgcalTowers[i + 1][j + 2];
207  stripEta[index_i][index_j][2] = hgcalTowers[i + 2][j] + hgcalTowers[i + 2][j + 1] + hgcalTowers[i + 2][j + 2];
208  stripPhi[index_i][index_j][0] = hgcalTowers[i][j] + hgcalTowers[i + 1][j] + hgcalTowers[i + 2][j];
209  stripPhi[index_i][index_j][1] = hgcalTowers[i][j + 1] + hgcalTowers[i + 1][j + 1] + hgcalTowers[i + 2][j + 1];
210  stripPhi[index_i][index_j][2] = hgcalTowers[i][j + 2] + hgcalTowers[i + 1][j + 2] + hgcalTowers[i + 2][j + 2];
211  for (int k = 0; k < 3; k++) {
212  et_sumEta[index_i][index_j][k] =
213  hgcalTowers[i + k][j] + hgcalTowers[i + k][j + 1] + hgcalTowers[i + k][j + 2];
214  }
215  index_j++;
216  }
217  index_i++;
218  }
219 
220  for (int i = 0; i < nSTEta; i++) {
221  for (int j = 0; j < nSTPhi; j++) {
223  temp.et = 0;
224  temp.eta = 0;
225  temp.phi = 0;
226  temp.towerEta = 0;
227  temp.towerPhi = 0;
228  temp.towerEt = 0;
229  temp.centerEta = 0;
230  temp.centerPhi = 0;
231  if (i < 6) {
232  float supertowerEt = et_sumEta[i][j][0] + et_sumEta[i][j][1] + et_sumEta[i][j][2];
233  temp.et = supertowerEt;
234  temp.eta = i;
235  temp.phi = j;
236  int peakEta = getPeakBinOf3(stripEta[i][j][0], stripEta[i][j][1], stripEta[i][j][2]);
237  temp.towerEta = peakEta;
238  int peakPhi = getPeakBinOf3(stripPhi[i][j][0], stripPhi[i][j][1], stripPhi[i][j][2]);
239  temp.towerPhi = peakPhi;
240  float peakEt = hgcalTowers[i * 3 + peakEta][j * 3 + peakPhi];
241  temp.towerEt = peakEt;
242  int cEta = getEtCenterOf3(stripEta[i][j][0], stripEta[i][j][1], stripEta[i][j][2]);
243  temp.centerEta = cEta;
244  int cPhi = getEtCenterOf3(stripPhi[i][j][0], stripPhi[i][j][1], stripPhi[i][j][2]);
245  temp.centerPhi = cPhi;
246  }
247  supertower_return[i][j] = temp;
248  }
249  }
250  }
251 
252  inline void makeST_hf(const float hfTowers[nHfEta][nHfPhi], GCTsupertower_t supertower_return[nSTEta][nSTPhi]) {
253  float et_sumEta[nSTEta][nSTPhi][3];
254  float stripEta[nSTEta][nSTPhi][3];
255  float stripPhi[nSTEta][nSTPhi][3];
256 
257  int index_i = 0;
258  int index_j = 0;
259  for (int i = 0; i < nHfEta; i += 3) { // 24 eta to 8 supertowers
260  index_j = 0;
261  for (int j = 0; j < nHfPhi; j += 3) { // 72 phi to 24 supertowers
262  stripEta[index_i][index_j][0] = hfTowers[i][j] + hfTowers[i][j + 1] + hfTowers[i][j + 2];
263  stripEta[index_i][index_j][1] = hfTowers[i + 1][j] + hfTowers[i + 1][j + 1] + hfTowers[i + 1][j + 2];
264  stripEta[index_i][index_j][2] = hfTowers[i + 2][j] + hfTowers[i + 2][j + 1] + hfTowers[i + 2][j + 2];
265  stripPhi[index_i][index_j][0] = hfTowers[i][j] + hfTowers[i + 1][j] + hfTowers[i + 2][j];
266  stripPhi[index_i][index_j][1] = hfTowers[i][j + 1] + hfTowers[i + 1][j + 1] + hfTowers[i + 2][j + 1];
267  stripPhi[index_i][index_j][2] = hfTowers[i][j + 2] + hfTowers[i + 1][j + 2] + hfTowers[i + 2][j + 2];
268  for (int k = 0; k < 3; k++) {
269  et_sumEta[index_i][index_j][k] = hfTowers[i + k][j] + hfTowers[i + k][j + 1] + hfTowers[i + k][j + 2];
270  }
271  index_j++;
272  }
273  index_i++;
274  }
275 
276  for (int i = 0; i < nSTEta; i++) {
277  for (int j = 0; j < nSTPhi; j++) {
279  temp.et = 0;
280  temp.eta = 0;
281  temp.phi = 0;
282  temp.towerEta = 0;
283  temp.towerPhi = 0;
284  temp.towerEt = 0;
285  temp.centerEta = 0;
286  temp.centerPhi = 0;
287  float supertowerEt = et_sumEta[i][j][0] + et_sumEta[i][j][1] + et_sumEta[i][j][2];
288  temp.et = supertowerEt;
289  temp.eta = i;
290  temp.phi = j;
291  int peakEta = getPeakBinOf3(stripEta[i][j][0], stripEta[i][j][1], stripEta[i][j][2]);
292  temp.towerEta = peakEta;
293  int peakPhi = getPeakBinOf3(stripPhi[i][j][0], stripPhi[i][j][1], stripPhi[i][j][2]);
294  temp.towerPhi = peakPhi;
295  float peakEt = hfTowers[i * 3 + peakEta][j * 3 + peakPhi];
296  temp.towerEt = peakEt;
297  int cEta = getEtCenterOf3(stripEta[i][j][0], stripEta[i][j][1], stripEta[i][j][2]);
298  temp.centerEta = cEta;
299  int cPhi = getEtCenterOf3(stripPhi[i][j][0], stripPhi[i][j][1], stripPhi[i][j][2]);
300  temp.centerPhi = cPhi;
301  supertower_return[i][j] = temp;
302  }
303  }
304  }
305 
306  inline GCTsupertower_t bestOf2(const GCTsupertower_t& calotp0, const GCTsupertower_t& calotp1) {
308  x = (calotp0.et > calotp1.et) ? calotp0 : calotp1;
309  return x;
310  }
311 
312  inline GCTsupertower_t getPeakBin24N(const etaStrip_t& etaStrip) {
313  GCTsupertower_t best01 = bestOf2(etaStrip.cr[0], etaStrip.cr[1]);
314  GCTsupertower_t best23 = bestOf2(etaStrip.cr[2], etaStrip.cr[3]);
315  GCTsupertower_t best45 = bestOf2(etaStrip.cr[4], etaStrip.cr[5]);
316  GCTsupertower_t best67 = bestOf2(etaStrip.cr[6], etaStrip.cr[7]);
317  GCTsupertower_t best89 = bestOf2(etaStrip.cr[8], etaStrip.cr[9]);
318  GCTsupertower_t best1011 = bestOf2(etaStrip.cr[10], etaStrip.cr[11]);
319  GCTsupertower_t best1213 = bestOf2(etaStrip.cr[12], etaStrip.cr[13]);
320  GCTsupertower_t best1415 = bestOf2(etaStrip.cr[14], etaStrip.cr[15]);
321  GCTsupertower_t best1617 = bestOf2(etaStrip.cr[16], etaStrip.cr[17]);
322  GCTsupertower_t best1819 = bestOf2(etaStrip.cr[18], etaStrip.cr[19]);
323  GCTsupertower_t best2021 = bestOf2(etaStrip.cr[20], etaStrip.cr[21]);
324  GCTsupertower_t best2223 = bestOf2(etaStrip.cr[22], etaStrip.cr[23]);
325 
326  GCTsupertower_t best0123 = bestOf2(best01, best23);
327  GCTsupertower_t best4567 = bestOf2(best45, best67);
328  GCTsupertower_t best891011 = bestOf2(best89, best1011);
329  GCTsupertower_t best12131415 = bestOf2(best1213, best1415);
330  GCTsupertower_t best16171819 = bestOf2(best1617, best1819);
331  GCTsupertower_t best20212223 = bestOf2(best2021, best2223);
332 
333  GCTsupertower_t best01234567 = bestOf2(best0123, best4567);
334  GCTsupertower_t best89101112131415 = bestOf2(best891011, best12131415);
335  GCTsupertower_t best16to23 = bestOf2(best16171819, best20212223);
336 
337  GCTsupertower_t best0to15 = bestOf2(best01234567, best89101112131415);
338  GCTsupertower_t bestOf24 = bestOf2(best0to15, best16to23);
339 
340  return bestOf24;
341  }
342 
343  inline towerMax getPeakBin8N(const etaStripPeak_t& etaStrip) {
344  towerMax x;
345 
346  GCTsupertower_t best01 = bestOf2(etaStrip.pk[0], etaStrip.pk[1]);
347  GCTsupertower_t best23 = bestOf2(etaStrip.pk[2], etaStrip.pk[3]);
348  GCTsupertower_t best45 = bestOf2(etaStrip.pk[4], etaStrip.pk[5]);
349  GCTsupertower_t best67 = bestOf2(etaStrip.pk[6], etaStrip.pk[7]);
350 
351  GCTsupertower_t best0123 = bestOf2(best01, best23);
352  GCTsupertower_t best4567 = bestOf2(best45, best67);
353  GCTsupertower_t bestOf8 = bestOf2(best0123, best4567);
354 
355  x.energy = bestOf8.et;
356  x.phi = bestOf8.phi;
357  x.eta = bestOf8.eta;
358  x.energyMax = bestOf8.towerEt;
359  x.etaMax = bestOf8.towerEta;
360  x.phiMax = bestOf8.towerPhi;
361  x.etaCenter = bestOf8.centerEta;
362  x.phiCenter = bestOf8.centerPhi;
363  return x;
364  }
365 
367  etaStripPeak_t etaStripPeak;
368  jetInfo jet;
369 
370  for (int i = 0; i < nSTEta; i++) {
372  for (int j = 0; j < nSTPhi; j++) {
373  test.cr[j] = temp[i][j];
374  }
375  etaStripPeak.pk[i] = getPeakBin24N(test);
376  }
377 
378  towerMax peakIn8;
379  peakIn8 = getPeakBin8N(etaStripPeak);
380 
381  jet.seedEnergy = peakIn8.energy;
382  jet.energy = 0;
383  jet.tauEt = 0;
384  jet.eta = peakIn8.eta;
385  jet.phi = peakIn8.phi;
386  jet.energyMax = peakIn8.energyMax;
387  jet.etaMax = peakIn8.etaMax; // overwritten in getJetValues
388  jet.phiMax = peakIn8.phiMax; // overwritten in getJetValues
389  jet.etaCenter = peakIn8.etaCenter; // overwritten in getJetValues
390  jet.phiCenter = peakIn8.phiCenter; // overwritten in getJetValues
391 
392  return jet;
393  }
394 
395  inline jetInfo getJetValues(GCTsupertower_t tempX[nSTEta][nSTPhi], int seed_eta, int seed_phi) {
396  float temp[nSTEta + 2][nSTPhi + 2];
397  float eta_slice[3] = {0.};
398  jetInfo jet_tmp;
399 
400  for (int i = 0; i < nSTEta + 2; i++) {
401  for (int k = 0; k < nSTPhi + 2; k++) {
402  temp[i][k] = 0;
403  }
404  }
405 
406  for (int i = 0; i < nSTEta; i++) {
407  for (int k = 0; k < nSTPhi; k++) {
408  temp[i + 1][k + 1] = tempX[i][k].et;
409  }
410  }
411 
412  int seed_eta1, seed_phi1;
413 
414  seed_eta1 = seed_eta; //to start from corner
415  seed_phi1 = seed_phi; //to start from corner
416  float tmp1, tmp2, tmp3;
417 
418  for (int j = 0; j < nSTEta; j++) {
419  for (int k = 0; k < nSTPhi; k++) {
420  if (j == seed_eta1 && k == seed_phi1) {
421  for (int m = 0; m < 3; m++) {
422  tmp1 = temp[j + m][k];
423  tmp2 = temp[j + m][k + 1];
424  tmp3 = temp[j + m][k + 2];
425  eta_slice[m] = tmp1 + tmp2 + tmp3;
426  }
427  }
428  }
429  }
430 
431  jet_tmp.energy = eta_slice[0] + eta_slice[1] + eta_slice[2];
432  jet_tmp.tauEt = eta_slice[1]; //set tau Pt to be sum of ST energies in center eta slice
433  // To find the jet centre: note that seed supertower is always (1, 1)
434  jet_tmp.etaCenter =
435  3 * seed_eta + tempX[seed_eta][seed_phi].centerEta; //this is the ET weighted eta centre of the ST
436  jet_tmp.phiCenter =
437  3 * seed_phi + tempX[seed_eta][seed_phi].centerPhi; //this is the ET weighted phi centre of the ST
438  jet_tmp.etaMax = 3 * seed_eta + tempX[seed_eta][seed_phi].towerEta;
439  jet_tmp.phiMax = 3 * seed_phi + tempX[seed_eta][seed_phi].towerPhi;
440 
441  // set the used supertower ets to 0
442  for (int i = 0; i < nSTEta; i++) {
443  if (i + 1 >= seed_eta && i <= seed_eta + 1) {
444  for (int k = 0; k < nSTPhi; k++) {
445  if (k + 1 >= seed_phi && k <= seed_phi + 1)
446  tempX[i][k].et = 0;
447  }
448  }
449  }
450 
451  return jet_tmp;
452  }
453 
454  inline jetInfo getRegion(GCTsupertower_t temp[nSTEta][nSTPhi], float TTseedThreshold) {
455  jetInfo jet_tmp, jet;
456  jet_tmp = getJetPosition(temp);
457  int seed_phi = jet_tmp.phi;
458  int seed_eta = jet_tmp.eta;
459  float seed_tower_energy = jet_tmp.energyMax;
460  jet = getJetValues(temp, seed_eta, seed_phi);
461  if (seed_tower_energy > TTseedThreshold) { // suppress ST seeds with max TT <=5 GeV (3 GeV) in barrel (endcap/HF)
462  jet_tmp.energy = jet.energy;
463  jet_tmp.tauEt = jet.tauEt;
464  } else {
465  jet_tmp.energy = 0.;
466  jet_tmp.tauEt = 0.;
467  }
468  jet_tmp.etaCenter = jet.etaCenter; // this is the ET weighted eta centre of the ST
469  jet_tmp.phiCenter = jet.phiCenter; // this is the ET weighted phi centre of the ST
470  jet_tmp.etaMax = jet.etaMax; // this is the leading tower eta in the ST
471  jet_tmp.phiMax = jet.phiMax; // this is the leading tower phi in the ST
472  return jet_tmp;
473  }
474 
475  inline bool compareByEt(l1tp2::Phase2L1CaloJet i, l1tp2::Phase2L1CaloJet j) { return (i.jetEt() > j.jetEt()); };
476 
477 } // namespace gctobj
478 
479 #endif
GCTsupertower_t cr[nSTPhi]
static constexpr int nBarrelPhi
towerMax getPeakBin8N(const etaStripPeak_t &etaStrip)
void makeST_hf(const float hfTowers[nHfEta][nHfPhi], GCTsupertower_t supertower_return[nSTEta][nSTPhi])
static constexpr int nSTEta
GCTsupertower_t getPeakBin24N(const etaStrip_t &etaStrip)
static constexpr int nHgcalEta
GCTsupertower_t pk[nSTEta]
static constexpr int nJets
int getEtCenterOf3(float et0, float et1, float et2)
GCTsupertower_t bestOf2(const GCTsupertower_t &calotp0, const GCTsupertower_t &calotp1)
static constexpr int nHfPhi
static constexpr int nSTPhi
jetInfo getJetPosition(GCTsupertower_t temp[nSTEta][nSTPhi])
int getPeakBinOf3(float et0, float et1, float et2)
void makeST(const float GCTintTowers[nBarrelEta/2][nBarrelPhi], GCTsupertower_t supertower_return[nSTEta][nSTPhi])
static constexpr int nHgcalPhi
void makeST_hgcal(const float hgcalTowers[nHgcalEta/2][nHgcalPhi], GCTsupertower_t supertower_return[nSTEta][nSTPhi])
static constexpr int nBarrelEta
static constexpr int nHfEta
float x
jetInfo getJetValues(GCTsupertower_t tempX[nSTEta][nSTPhi], int seed_eta, int seed_phi)
jetInfo getRegion(GCTsupertower_t temp[nSTEta][nSTPhi], float TTseedThreshold)
bool compareByEt(l1tp2::Phase2L1CaloJet i, l1tp2::Phase2L1CaloJet j)