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 
27 namespace gctpf {
28 
29  typedef struct {
30  float et;
31  int eta;
32  int phi;
34 
35  typedef struct {
36  GCTpfcluster_t GCTpfclusters[nPFClusterSLR];
37  } PFcluster_t;
38 
39  typedef struct {
40  float et;
41  int eta;
42  int phi;
43  } GCTint_t;
44 
45  typedef struct {
47  } GCTEtaStrip_t;
48 
49  typedef struct {
52 
53  typedef struct {
55  } Region_t;
56 
57  inline GCTint_t bestOf2(const GCTint_t& t0, const GCTint_t& t1) {
58  GCTint_t x;
59  x = (t0.et > t1.et) ? t0 : t1;
60 
61  return x;
62  }
63 
64  inline GCTint_t getPeakOfStrip(const GCTEtaStrip_t& etaStrip) {
65  GCTint_t best12 = bestOf2(etaStrip.t[1], etaStrip.t[2]);
66  GCTint_t best34 = bestOf2(etaStrip.t[3], etaStrip.t[4]);
67  GCTint_t best56 = bestOf2(etaStrip.t[5], etaStrip.t[6]);
68  GCTint_t best1234 = bestOf2(best12, best34);
69  GCTint_t bestAll = bestOf2(best1234, best56);
70 
71  return bestAll;
72  }
73 
74  inline GCTint_t getPeakBin(const GCTEtaStripPeak_t& etaStripPeak) {
75  GCTint_t best01 = bestOf2(etaStripPeak.p[0], etaStripPeak.p[1]);
76  GCTint_t best23 = bestOf2(etaStripPeak.p[2], etaStripPeak.p[3]);
77  GCTint_t best45 = bestOf2(etaStripPeak.p[4], etaStripPeak.p[5]);
78  GCTint_t best67 = bestOf2(etaStripPeak.p[6], etaStripPeak.p[7]);
79  GCTint_t best89 = bestOf2(etaStripPeak.p[8], etaStripPeak.p[9]);
80  GCTint_t best1011 = bestOf2(etaStripPeak.p[10], etaStripPeak.p[11]);
81  GCTint_t best1213 = bestOf2(etaStripPeak.p[12], etaStripPeak.p[13]);
82  GCTint_t best1415 = bestOf2(etaStripPeak.p[14], etaStripPeak.p[15]);
83  GCTint_t best1617 = bestOf2(etaStripPeak.p[16], etaStripPeak.p[17]);
84  GCTint_t best0123 = bestOf2(best01, best23);
85  GCTint_t best4567 = bestOf2(best45, best67);
86  GCTint_t best891011 = bestOf2(best89, best1011);
87  GCTint_t best12131415 = bestOf2(best1213, best1415);
88  GCTint_t best01234567 = bestOf2(best0123, best4567);
89  GCTint_t best01234567891011 = bestOf2(best01234567, best891011);
90  GCTint_t best121314151617 = bestOf2(best12131415, best1617);
91  GCTint_t best12131415161718 = bestOf2(best121314151617, etaStripPeak.p[18]);
92  GCTint_t bestAll = bestOf2(best01234567891011, best12131415161718);
93 
94  return bestAll;
95  }
96 
98  GCTEtaStripPeak_t etaPeak;
99  for (int i = 0; i < nTowerEtaSLR - 2; i++) {
100  etaPeak.p[i] = getPeakOfStrip(region.s[i + 1]);
101  }
102  GCTint_t max = getPeakBin(etaPeak);
103 
104  return max;
105  }
106 
108  Region_t r;
109 
110  for (int i = 0; i < nTowerPhiSLR; i++) {
111  for (int j = 0; j < nTowerEtaSLR; j++) {
112  r.s[j].t[i].et = temp[j][i];
113  r.s[j].t[i].eta = j;
114  r.s[j].t[i].phi = i;
115  }
116  }
117 
118  return r;
119  }
120 
121  inline float getEt(float temp[nTowerEtaSLR][nTowerPhiSLR], int eta, int phi) {
122  float et_sumEta[3] = {0., 0., 0.};
123 
124  for (int i = 0; i < (nTowerEtaSLR - 2); i++) {
125  for (int j = 0; j < (nTowerPhiSLR - 2); j++) {
126  if (i + 1 == eta && j + 1 == phi) {
127  for (int k = 0; k < 3; k++) {
128  et_sumEta[k] = temp[i + k][j] + temp[i + k][j + 1] + temp[i + k][j + 2];
129  }
130  }
131  }
132  }
133 
134  float pfcluster_et = et_sumEta[0] + et_sumEta[1] + et_sumEta[2];
135 
136  return pfcluster_et;
137  }
138 
139  inline void RemoveTmp(float temp[nTowerEtaSLR][nTowerPhiSLR], int eta, int phi) {
140  for (int i = 0; i < nTowerEtaSLR; i++) {
141  if (i + 1 >= eta && i <= eta + 1) {
142  for (int j = 0; j < nTowerPhiSLR; j++) {
143  if (j + 1 >= phi && j <= phi + 1) {
144  temp[i][j] = 0;
145  }
146  }
147  }
148  }
149 
150  return;
151  }
152 
153  inline GCTpfcluster_t recoPfcluster(float temporary[nTowerEtaSLR][nTowerPhiSLR], int etaoffset, int phioffset) {
154  GCTpfcluster_t pfclusterReturn;
155 
157 
158  region = initStructure(temporary);
159 
160  GCTint_t regionMax = getPeakPosition(region);
161 
162  float pfcluster_et = getEt(temporary, regionMax.eta, regionMax.phi);
163 
164  RemoveTmp(temporary, regionMax.eta, regionMax.phi);
165 
166  if (!(regionMax.eta >= 2 && regionMax.eta < (nTowerEtaSLR - 2) && regionMax.phi >= 2 &&
167  regionMax.phi < (nTowerPhiSLR - 2)))
168  pfcluster_et = 0;
169 
170  pfclusterReturn.et = pfcluster_et;
171  pfclusterReturn.eta = regionMax.eta - 2 + etaoffset;
172  pfclusterReturn.phi = regionMax.phi - 2 + phioffset;
173 
174  return pfclusterReturn;
175  }
176 
177  inline PFcluster_t pfcluster(float temporary[nTowerEtaSLR][nTowerPhiSLR], int etaoffset, int phioffset) {
179 
180  for (int i = 0; i < nPFClusterSLR; i++) {
181  pfcluster[i] = recoPfcluster(temporary, etaoffset, phioffset);
182  }
183 
184  PFcluster_t GCTPfclusters;
185 
186  for (int i = 0; i < nPFClusterSLR; i++) {
187  GCTPfclusters.GCTpfclusters[i].et = pfcluster[i].et;
188  GCTPfclusters.GCTpfclusters[i].eta = pfcluster[i].eta;
189  GCTPfclusters.GCTpfclusters[i].phi = pfcluster[i].phi;
190  }
191 
192  return GCTPfclusters;
193  }
194 
195 } // namespace gctpf
196 
197 #endif
GCTpfcluster_t recoPfcluster(float temporary[nTowerEtaSLR][nTowerPhiSLR], int etaoffset, int phioffset)
static constexpr int nPFClusterSLR
static constexpr int nSLR
GCTint_t getPeakPosition(const Region_t &region)
Region_t initStructure(float temp[nTowerEtaSLR][nTowerPhiSLR])
GCTint_t getPeakBin(const GCTEtaStripPeak_t &etaStripPeak)
float getEt(float temp[nTowerEtaSLR][nTowerPhiSLR], int eta, int phi)
void RemoveTmp(float temp[nTowerEtaSLR][nTowerPhiSLR], int eta, int phi)
GCTpfcluster_t GCTpfclusters[nPFClusterSLR]
GCTint_t getPeakOfStrip(const GCTEtaStrip_t &etaStrip)
static constexpr int nTowerEtaSLR
static constexpr int nTowerEta
PFcluster_t pfcluster(float temporary[nTowerEtaSLR][nTowerPhiSLR], int etaoffset, int phioffset)
static constexpr int nTowerPhiSLR
static constexpr int nTowerPhi
float x
GCTint_t bestOf2(const GCTint_t &t0, const GCTint_t &t1)