CMS 3D CMS Logo

Phase2L1CaloPFClusterEmulator.h
Go to the documentation of this file.
1 #ifndef _PHASE_2_L1_CALO_PFCLUSTER_EMULATOR_H_
2 #define _PHASE_2_L1_CALO_PFCLUSTER_EMULATOR_H_
3 
4 #include <cstdlib>
5 
6 // eta: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
7 // 0 | |
8 // 1 | |
9 // |-----------------------------------------------------|
10 // 2 | |
11 // 3 | |
12 // 4 | |
13 // 5 | |
14 // | ----------------------------------------------------|
15 // 6 | |
16 // 7 | |
17 //
18 // 8 PFclusters are created in one 21x8 (2+17+2 x 2+4+2)
19 
20 static constexpr int nTowerEta = 34;
21 static constexpr int nTowerPhi = 72;
22 static constexpr int nSLR = 36;
23 static constexpr int nTowerEtaSLR = 21; // including overlap: 2+17+2
24 static constexpr int nTowerPhiSLR = 8; // including overlap: 2+4+2
25 static constexpr int nPFClusterSLR = 8;
26 static constexpr int nHfEta = 24;
27 static constexpr int nHfPhi = 72;
28 static constexpr int nHfRegions = 12;
29 
30 namespace gctpf {
31 
32  typedef struct {
33  float et;
34  int eta;
35  int phi;
37 
38  typedef struct {
39  GCTpfcluster_t GCTpfclusters[nPFClusterSLR];
40  } PFcluster_t;
41 
42  typedef struct {
43  float et;
44  int eta;
45  int phi;
46  } GCTint_t;
47 
48  typedef struct {
50  } GCTEtaStrip_t;
51 
52  typedef struct {
55 
56  typedef struct {
59 
60  typedef struct {
63 
64  typedef struct {
66  } Region_t;
67 
68  typedef struct {
70  } RegionHF_t;
71 
72  inline GCTint_t bestOf2(const GCTint_t& t0, const GCTint_t& t1) {
73  GCTint_t x;
74  x = (t0.et > t1.et) ? t0 : t1;
75 
76  return x;
77  }
78 
79  inline GCTint_t getPeakOfStrip(const GCTEtaStrip_t& etaStrip) {
80  GCTint_t best12 = bestOf2(etaStrip.t[1], etaStrip.t[2]);
81  GCTint_t best34 = bestOf2(etaStrip.t[3], etaStrip.t[4]);
82  GCTint_t best56 = bestOf2(etaStrip.t[5], etaStrip.t[6]);
83  GCTint_t best1234 = bestOf2(best12, best34);
84  GCTint_t bestAll = bestOf2(best1234, best56);
85 
86  return bestAll;
87  }
88 
89  inline GCTint_t getPeakOfHFStrip(const GCTEtaHFStrip_t& etaStrip) {
90  GCTint_t best01 = bestOf2(etaStrip.t[0], etaStrip.t[1]);
91  GCTint_t best23 = bestOf2(etaStrip.t[2], etaStrip.t[3]);
92  GCTint_t best45 = bestOf2(etaStrip.t[4], etaStrip.t[5]);
93  GCTint_t best67 = bestOf2(etaStrip.t[6], etaStrip.t[7]);
94  GCTint_t best89 = bestOf2(etaStrip.t[8], etaStrip.t[9]);
95  GCTint_t best1011 = bestOf2(etaStrip.t[10], etaStrip.t[11]);
96  GCTint_t best0123 = bestOf2(best01, best23);
97  GCTint_t best4567 = bestOf2(best45, best67);
98  GCTint_t best891011 = bestOf2(best89, best1011);
99  GCTint_t best01234567 = bestOf2(best0123, best4567);
100  GCTint_t bestAll = bestOf2(best01234567, best891011);
101 
102  return bestAll;
103  }
104 
105  inline GCTint_t getPeakBin(const GCTEtaStripPeak_t& etaStripPeak) {
106  GCTint_t best01 = bestOf2(etaStripPeak.p[0], etaStripPeak.p[1]);
107  GCTint_t best23 = bestOf2(etaStripPeak.p[2], etaStripPeak.p[3]);
108  GCTint_t best45 = bestOf2(etaStripPeak.p[4], etaStripPeak.p[5]);
109  GCTint_t best67 = bestOf2(etaStripPeak.p[6], etaStripPeak.p[7]);
110  GCTint_t best89 = bestOf2(etaStripPeak.p[8], etaStripPeak.p[9]);
111  GCTint_t best1011 = bestOf2(etaStripPeak.p[10], etaStripPeak.p[11]);
112  GCTint_t best1213 = bestOf2(etaStripPeak.p[12], etaStripPeak.p[13]);
113  GCTint_t best1415 = bestOf2(etaStripPeak.p[14], etaStripPeak.p[15]);
114  GCTint_t best1617 = bestOf2(etaStripPeak.p[16], etaStripPeak.p[17]);
115  GCTint_t best0123 = bestOf2(best01, best23);
116  GCTint_t best4567 = bestOf2(best45, best67);
117  GCTint_t best891011 = bestOf2(best89, best1011);
118  GCTint_t best12131415 = bestOf2(best1213, best1415);
119  GCTint_t best01234567 = bestOf2(best0123, best4567);
120  GCTint_t best01234567891011 = bestOf2(best01234567, best891011);
121  GCTint_t best121314151617 = bestOf2(best12131415, best1617);
122  GCTint_t best12131415161718 = bestOf2(best121314151617, etaStripPeak.p[18]);
123  GCTint_t bestAll = bestOf2(best01234567891011, best12131415161718);
124 
125  return bestAll;
126  }
127 
128  inline GCTint_t getPeakBinHF(const GCTEtaHFStripPeak_t& etaStripPeak) {
129  GCTint_t best01 = bestOf2(etaStripPeak.p[0], etaStripPeak.p[1]);
130  GCTint_t best23 = bestOf2(etaStripPeak.p[2], etaStripPeak.p[3]);
131  GCTint_t best45 = bestOf2(etaStripPeak.p[4], etaStripPeak.p[5]);
132  GCTint_t best67 = bestOf2(etaStripPeak.p[6], etaStripPeak.p[7]);
133  GCTint_t best89 = bestOf2(etaStripPeak.p[8], etaStripPeak.p[9]);
134  GCTint_t best1011 = bestOf2(etaStripPeak.p[10], etaStripPeak.p[11]);
135  GCTint_t best1213 = bestOf2(etaStripPeak.p[12], etaStripPeak.p[13]);
136  GCTint_t best1415 = bestOf2(etaStripPeak.p[14], etaStripPeak.p[15]);
137  GCTint_t best1617 = bestOf2(etaStripPeak.p[16], etaStripPeak.p[17]);
138  GCTint_t best1819 = bestOf2(etaStripPeak.p[18], etaStripPeak.p[19]);
139  GCTint_t best2021 = bestOf2(etaStripPeak.p[20], etaStripPeak.p[21]);
140  GCTint_t best2223 = bestOf2(etaStripPeak.p[22], etaStripPeak.p[23]);
141  GCTint_t best0123 = bestOf2(best01, best23);
142  GCTint_t best4567 = bestOf2(best45, best67);
143  GCTint_t best891011 = bestOf2(best89, best1011);
144  GCTint_t best12131415 = bestOf2(best1213, best1415);
145  GCTint_t best16171819 = bestOf2(best1617, best1819);
146  GCTint_t best20212223 = bestOf2(best2021, best2223);
147  GCTint_t best0to7 = bestOf2(best0123, best4567);
148  GCTint_t best8to15 = bestOf2(best891011, best12131415);
149  GCTint_t best16to23 = bestOf2(best16171819, best20212223);
150  GCTint_t best0to15 = bestOf2(best0to7, best8to15);
151  GCTint_t bestAll = bestOf2(best0to15, best16to23);
152 
153  return bestAll;
154  }
155 
157  GCTEtaStripPeak_t etaPeak;
158  for (int i = 0; i < nTowerEtaSLR - 2; i++) {
159  etaPeak.p[i] = getPeakOfStrip(region.s[i + 1]);
160  }
161  GCTint_t max = getPeakBin(etaPeak);
162 
163  return max;
164  }
165 
167  GCTEtaHFStripPeak_t etaPeak;
168  for (int i = 0; i < nHfPhi / 6; i++) {
169  etaPeak.p[i] = getPeakOfHFStrip(region.s[i]);
170  }
171  GCTint_t max = getPeakBinHF(etaPeak);
172 
173  return max;
174  }
175 
177  Region_t r;
178 
179  for (int i = 0; i < nTowerPhiSLR; i++) {
180  for (int j = 0; j < nTowerEtaSLR; j++) {
181  r.s[j].t[i].et = temp[j][i];
182  r.s[j].t[i].eta = j;
183  r.s[j].t[i].phi = i;
184  }
185  }
186 
187  return r;
188  }
189 
191  RegionHF_t r;
192 
193  for (int i = 0; i < nHfPhi / 6; i++) {
194  for (int j = 0; j < nHfEta; j++) {
195  r.s[j].t[i].et = temp[j][i];
196  r.s[j].t[i].eta = j;
197  r.s[j].t[i].phi = i;
198  }
199  }
200 
201  return r;
202  }
203 
204  inline float getEt(float temp[nTowerEtaSLR][nTowerPhiSLR], int eta, int phi) {
205  float et_sumEta[3] = {0., 0., 0.};
206 
207  for (int i = 0; i < (nTowerEtaSLR - 2); i++) {
208  for (int j = 0; j < (nTowerPhiSLR - 2); j++) {
209  if (i + 1 == eta && j + 1 == phi) {
210  for (int k = 0; k < 3; k++) {
211  et_sumEta[k] = temp[i + k][j] + temp[i + k][j + 1] + temp[i + k][j + 2];
212  }
213  }
214  }
215  }
216 
217  float pfcluster_et = et_sumEta[0] + et_sumEta[1] + et_sumEta[2];
218 
219  return pfcluster_et;
220  }
221 
222  inline float getEtHF(float temp[nHfEta][nHfPhi / 6], int eta, int phi) {
223  float tempX[nHfEta + 2][nHfPhi / 6 + 2];
224  float et_sumEta[3] = {0., 0., 0.};
225 
226  for (int i = 0; i < nHfEta + 2; i++) {
227  for (int k = 0; k < nHfPhi / 6 + 2; k++) {
228  tempX[i][k] = 0;
229  }
230  }
231 
232  for (int i = 0; i < nHfEta; i++) {
233  for (int k = 0; k < nHfPhi / 6; k++) {
234  tempX[i + 1][k + 1] = temp[i][k];
235  }
236  }
237 
238  for (int i = 0; i < nHfEta; i++) {
239  for (int j = 0; j < nHfPhi / 6; j++) {
240  if (i == eta && j == phi) {
241  for (int k = 0; k < 3; k++) {
242  et_sumEta[k] = tempX[i + k][j] + tempX[i + k][j + 1] + tempX[i + k][j + 2];
243  }
244  }
245  }
246  }
247 
248  float pfcluster_et = et_sumEta[0] + et_sumEta[1] + et_sumEta[2];
249 
250  return pfcluster_et;
251  }
252 
253  inline void RemoveTmp(float temp[nTowerEtaSLR][nTowerPhiSLR], int eta, int phi) {
254  for (int i = 0; i < nTowerEtaSLR; i++) {
255  if (i + 1 >= eta && i <= eta + 1) {
256  for (int j = 0; j < nTowerPhiSLR; j++) {
257  if (j + 1 >= phi && j <= phi + 1) {
258  temp[i][j] = 0;
259  }
260  }
261  }
262  }
263 
264  return;
265  }
266 
267  inline void RemoveTmpHF(float temp[nHfEta][nHfPhi / 6], int eta, int phi) {
268  for (int i = 0; i < nHfEta; i++) {
269  if (i + 1 >= eta && i <= eta + 1) {
270  for (int j = 0; j < nHfPhi / 6; j++) {
271  if (j + 1 >= phi && j <= phi + 1) {
272  temp[i][j] = 0;
273  }
274  }
275  }
276  }
277 
278  return;
279  }
280 
281  inline GCTpfcluster_t recoPfcluster(float temporary[nTowerEtaSLR][nTowerPhiSLR], int etaoffset, int phioffset) {
282  GCTpfcluster_t pfclusterReturn;
283 
285 
286  region = initStructure(temporary);
287 
288  GCTint_t regionMax = getPeakPosition(region);
289 
290  float pfcluster_et = getEt(temporary, regionMax.eta, regionMax.phi);
291 
292  RemoveTmp(temporary, regionMax.eta, regionMax.phi);
293 
294  if (!(regionMax.eta >= 2 && regionMax.eta < (nTowerEtaSLR - 2) && regionMax.phi >= 2 &&
295  regionMax.phi < (nTowerPhiSLR - 2)))
296  pfcluster_et = 0;
297 
298  pfclusterReturn.et = pfcluster_et;
299  pfclusterReturn.eta = regionMax.eta - 2 + etaoffset;
300  pfclusterReturn.phi = regionMax.phi - 2 + phioffset;
301 
302  return pfclusterReturn;
303  }
304 
305  inline GCTpfcluster_t recoPfclusterHF(float temporary[nHfEta][nHfPhi / 6], int etaoffset, int phioffset) {
306  GCTpfcluster_t pfclusterReturn;
307 
309 
310  region = initStructureHF(temporary);
311 
312  GCTint_t regionMax = getPeakPositionHF(region);
313 
314  float pfcluster_et = getEtHF(temporary, regionMax.eta, regionMax.phi);
315 
316  RemoveTmpHF(temporary, regionMax.eta, regionMax.phi);
317 
318  pfclusterReturn.et = pfcluster_et;
319  pfclusterReturn.eta = regionMax.eta + etaoffset;
320  pfclusterReturn.phi = regionMax.phi + phioffset;
321  if (pfclusterReturn.phi < 0)
322  pfclusterReturn.phi += nHfPhi;
323 
324  return pfclusterReturn;
325  }
326 
327  inline PFcluster_t pfcluster(float temporary[nTowerEtaSLR][nTowerPhiSLR], int etaoffset, int phioffset) {
329 
330  for (int i = 0; i < nPFClusterSLR; i++) {
331  pfcluster[i] = recoPfcluster(temporary, etaoffset, phioffset);
332  }
333 
334  PFcluster_t GCTPfclusters;
335 
336  for (int i = 0; i < nPFClusterSLR; i++) {
337  GCTPfclusters.GCTpfclusters[i].et = pfcluster[i].et;
338  GCTPfclusters.GCTpfclusters[i].eta = pfcluster[i].eta;
339  GCTPfclusters.GCTpfclusters[i].phi = pfcluster[i].phi;
340  }
341 
342  return GCTPfclusters;
343  }
344 
345  inline PFcluster_t pfclusterHF(float temporary[nHfEta][nHfPhi / 6], int etaoffset, int phioffset) {
347 
348  for (int i = 0; i < nPFClusterSLR; i++) {
349  pfcluster[i] = recoPfclusterHF(temporary, etaoffset, phioffset);
350  }
351 
352  PFcluster_t GCTPfclusters;
353 
354  for (int i = 0; i < nPFClusterSLR; i++) {
355  GCTPfclusters.GCTpfclusters[i].et = pfcluster[i].et;
356  GCTPfclusters.GCTpfclusters[i].eta = pfcluster[i].eta;
357  GCTPfclusters.GCTpfclusters[i].phi = pfcluster[i].phi;
358  }
359 
360  return GCTPfclusters;
361  }
362 
363 } // namespace gctpf
364 
365 #endif
static constexpr int nHfRegions
PFcluster_t pfclusterHF(float temporary[nHfEta][nHfPhi/6], int etaoffset, int phioffset)
GCTpfcluster_t recoPfcluster(float temporary[nTowerEtaSLR][nTowerPhiSLR], int etaoffset, int phioffset)
static constexpr int nPFClusterSLR
static constexpr int nHfEta
static constexpr int nSLR
static constexpr int nHfPhi
GCTint_t getPeakPosition(const Region_t &region)
void RemoveTmpHF(float temp[nHfEta][nHfPhi/6], int eta, int phi)
Region_t initStructure(float temp[nTowerEtaSLR][nTowerPhiSLR])
GCTint_t getPeakBin(const GCTEtaStripPeak_t &etaStripPeak)
float getEt(float temp[nTowerEtaSLR][nTowerPhiSLR], int eta, int phi)
RegionHF_t initStructureHF(float temp[nHfEta][nHfPhi/6])
void RemoveTmp(float temp[nTowerEtaSLR][nTowerPhiSLR], int eta, int phi)
GCTpfcluster_t GCTpfclusters[nPFClusterSLR]
GCTint_t getPeakOfStrip(const GCTEtaStrip_t &etaStrip)
GCTint_t getPeakBinHF(const GCTEtaHFStripPeak_t &etaStripPeak)
static constexpr int nTowerEtaSLR
static constexpr int nTowerEta
PFcluster_t pfcluster(float temporary[nTowerEtaSLR][nTowerPhiSLR], int etaoffset, int phioffset)
GCTint_t getPeakOfHFStrip(const GCTEtaHFStrip_t &etaStrip)
static constexpr int nTowerPhiSLR
static constexpr int nTowerPhi
GCTint_t getPeakPositionHF(const RegionHF_t &region)
float x
GCTpfcluster_t recoPfclusterHF(float temporary[nHfEta][nHfPhi/6], int etaoffset, int phioffset)
float getEtHF(float temp[nHfEta][nHfPhi/6], int eta, int phi)
GCTint_t bestOf2(const GCTint_t &t0, const GCTint_t &t1)