CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
UCTGeometry.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cstdlib>
3 #include <cstdint>
4 #include <array>
5 
6 #include "UCTGeometry.hh"
7 #include "UCTLogging.hh"
8 using namespace l1tcalo;
9 
10 UCTGeometry::UCTGeometry() {}
11 
12 uint32_t UCTGeometry::getLinkNumber(bool negativeEta, uint32_t region, uint32_t iEta, uint32_t iPhi) {
13  if (checkRegion(region)) {
14  LOG_ERROR << "Invalid region number: region = " << region << std::endl;
15  exit(1);
16  }
17  if (checkEtaIndex(region, iEta)) {
18  LOG_ERROR << "Invalid eta index: iEta = " << iEta << std::endl;
19  exit(1);
20  }
21  if (checkPhiIndex(region, iPhi)) {
22  LOG_ERROR << "Invalid eta index: iPhi = " << iPhi << std::endl;
23  exit(1);
24  }
25  uint32_t linkNumber = 0xDEADBEEF;
26  if (region < MaxRegionNumber) {
27  if (iEta < NEtaInRegion / 2) {
28  linkNumber = region * 2;
29  } else {
30  linkNumber = region * 2 + 1;
31  }
32  } else {
33  linkNumber = NRegionsInCard * 2 + iPhi;
34  }
35 
36  if (!negativeEta) {
37  linkNumber += NRegionsInCard * 2 + 2;
38  }
39  return linkNumber;
40 }
41 
42 int UCTGeometry::getCaloEtaIndex(bool negativeSide, uint32_t region, uint32_t iEta) {
43  if (checkRegion(region)) {
44  LOG_ERROR << "Invalid region number: region = " << region << std::endl;
45  exit(1);
46  }
47  if (checkEtaIndex(region, iEta)) {
48  LOG_ERROR << "Invalid eta index: iEta = " << iEta << std::endl;
49  exit(1);
50  }
51 
52  int caloEtaIndex = region * NEtaInRegion + iEta + 1;
53  if (region > 6) {
54  caloEtaIndex = (region - 7) * NHFEtaInRegion + iEta + 30;
55  }
56 
57  if (negativeSide)
58  return -caloEtaIndex;
59  return caloEtaIndex;
60 }
61 
62 int UCTGeometry::getCaloPhiIndex(uint32_t crate, uint32_t card, uint32_t region, uint32_t iPhi) {
63  if (checkCrate(crate)) {
64  LOG_ERROR << "Invalid crate number: crate = " << crate << std::endl;
65  exit(1);
66  }
67  if (checkCard(card)) {
68  LOG_ERROR << "Invalid card number: card = " << card << std::endl;
69  exit(1);
70  }
71  if (checkPhiIndex(region, iPhi)) {
72  LOG_ERROR << "Invalid phi index: iPhi = " << iPhi << std::endl;
73  exit(1);
74  }
75  int caloPhiIndex = 0xDEADBEEF;
76  if (crate == 0) {
77  caloPhiIndex = 11 + card * 4 + iPhi;
78  } else if (crate == 1) {
79  caloPhiIndex = 59 + card * 4 + iPhi;
80  } else if (crate == 2) {
81  caloPhiIndex = 35 + card * 4 + iPhi;
82  }
83  if (caloPhiIndex > 72)
84  caloPhiIndex -= 72;
85  return caloPhiIndex;
86 }
87 
88 uint32_t UCTGeometry::getUCTRegionPhiIndex(uint32_t crate, uint32_t card) {
89  if (checkCrate(crate)) {
90  LOG_ERROR << "Invalid crate number: crate = " << crate << std::endl;
91  exit(1);
92  }
93  if (checkCard(card)) {
94  LOG_ERROR << "Invalid card number: card = " << card << std::endl;
95  exit(1);
96  }
97  uint32_t uctRegionPhiIndex = 0xDEADBEEF;
98  if (crate == 0) {
99  uctRegionPhiIndex = 3 + card;
100  } else if (crate == 1) {
101  if (card < 3) {
102  uctRegionPhiIndex = 15 + card;
103  } else {
104  uctRegionPhiIndex = card - 3;
105  }
106  } else if (crate == 2) {
107  uctRegionPhiIndex = 9 + card;
108  }
109  return uctRegionPhiIndex;
110 }
111 
112 uint32_t UCTGeometry::getCrate(int caloEta, int caloPhi) {
113  uint32_t crate = 0xDEADBEEF;
114  if (caloPhi >= 11 && caloPhi <= 34)
115  crate = 0;
116  else if (caloPhi >= 35 && caloPhi <= 58)
117  crate = 2;
118  else if (caloPhi >= 59 && caloPhi <= 72)
119  crate = 1;
120  else if (caloPhi >= 1 && caloPhi <= 10)
121  crate = 1;
122  return crate;
123 }
124 
125 uint32_t UCTGeometry::getCard(int caloEta, int caloPhi) {
126  uint32_t crate = getCrate(caloEta, caloPhi);
127  uint32_t card = 0xDEADBEEF;
128  if (crate == 0) {
129  card = (caloPhi - 11) / 4;
130  } else if (crate == 2) {
131  card = (caloPhi - 35) / 4;
132  } else if (crate == 1 && caloPhi > 58) {
133  card = (caloPhi - 59) / 4;
134  } else if (crate == 1 && caloPhi <= 10) {
135  card = (caloPhi + 13) / 4;
136  }
137  return card;
138 }
139 
140 uint32_t UCTGeometry::getRegion(int caloEta, int caloPhi) {
141  uint32_t absCEta = std::abs(caloEta);
142  if ((absCEta - 1) < (NRegionsInCard * NEtaInRegion))
143  return (absCEta - 1) / NEtaInRegion;
144  else
145  return NRegionsInCard + ((absCEta - 2 - (NRegionsInCard * NEtaInRegion)) / NHFEtaInRegion);
146 }
147 
148 uint32_t UCTGeometry::getiEta(int caloEta) {
149  uint32_t absCEta = std::abs(caloEta);
150  if ((absCEta - 1) < (NRegionsInCard * NEtaInRegion))
151  return (absCEta - 1) % NEtaInRegion;
152  else
153  return absCEta % NHFEtaInRegion; // To account for missing tower 29
154 }
155 
156 uint32_t UCTGeometry::getiPhi(int caloPhi) { return (caloPhi + 1) % NPhiInCard; }
157 
158 uint32_t UCTGeometry::getNEta(uint32_t region) {
159  uint32_t nEta = 0xDEADBEEF;
160  if (region < CaloHFRegionStart) {
161  nEta = NEtaInRegion;
162  } else {
163  nEta = NHFEtaInRegion;
164  }
165  return nEta;
166 }
167 
168 uint32_t UCTGeometry::getNPhi(uint32_t region) { return NPhiInRegion; }
169 
170 UCTRegionIndex UCTGeometry::getUCTRegionIndex(int caloEta, int caloPhi) {
171  uint32_t regionPhi = getUCTRegionPhiIndex(getCrate(caloEta, caloPhi), getCard(caloEta, caloPhi));
172  int regionEta = getUCTRegionEtaIndex((caloEta < 0), getRegion(caloEta, caloPhi));
173  return UCTRegionIndex(regionEta, regionPhi);
174 }
175 
176 UCTRegionIndex UCTGeometry::getUCTRegionIndex(bool negativeSide, uint32_t crate, uint32_t card, uint32_t region) {
177  uint32_t regionPhi = getUCTRegionPhiIndex(crate, card);
178  int regionEta = getUCTRegionEtaIndex(negativeSide, region);
179  return UCTRegionIndex(regionEta, regionPhi);
180 }
181 
182 UCTTowerIndex UCTGeometry::getUCTTowerIndex(UCTRegionIndex region, uint32_t iEta, uint32_t iPhi) {
183  if (iPhi >= NPhiInRegion || iEta >= NEtaInRegion) {
184  return UCTTowerIndex(0, 0); // Illegal values
185  }
186  int regionEta = region.first;
187  uint32_t regionPhi = region.second;
188  bool negativeSide = (regionEta < 0);
189  uint32_t regionNo = std::abs(regionEta) - 1;
190  int towerEta = 0xDEADBEEF;
191  if (regionNo < NRegionsInCard) {
192  towerEta = 1 + regionNo * getNEta(regionNo) + iEta; // Ranges 1 - 28
193  } else if (regionNo < (NRegionsInCard + NHFRegionsInCard)) {
194  towerEta = HFEtaOffset + 1 + (regionNo - NRegionsInCard) * getNEta(regionNo) + iEta; // Ranges 30 - 42
195  }
196  if (negativeSide)
197  towerEta = -towerEta;
198  int towerPhi = regionPhi * NPhiInRegion + iPhi - 1; // Always pretend that there are 4 phi-regions
199  if (towerPhi <= 0)
200  towerPhi += 72;
201  // Legal values of towerPhi = 1, 2, 5, 6, ..., 69, 70 for towerEta 30-39
202  // Legal values of towerPhi = 1, 5, ..., 69 for towerEta 40-41
203  return UCTTowerIndex(towerEta, towerPhi);
204 }
205 
206 namespace {
207  constexpr std::array<double, 42> fillTwrEtaValues() {
208  std::array<double, 42> twrEtaValues = {{0}};
209  twrEtaValues[0] = 0;
210  for (unsigned int i = 0; i < 20; i++) {
211  twrEtaValues[i + 1] = 0.0436 + i * 0.0872;
212  }
213  twrEtaValues[21] = 1.785;
214  twrEtaValues[22] = 1.880;
215  twrEtaValues[23] = 1.9865;
216  twrEtaValues[24] = 2.1075;
217  twrEtaValues[25] = 2.247;
218  twrEtaValues[26] = 2.411;
219  twrEtaValues[27] = 2.575;
220  twrEtaValues[28] = 2.825;
221  twrEtaValues[29] = 999.;
222  twrEtaValues[30] = (3.15 + 2.98) / 2.;
223  twrEtaValues[31] = (3.33 + 3.15) / 2.;
224  twrEtaValues[32] = (3.50 + 3.33) / 2.;
225  twrEtaValues[33] = (3.68 + 3.50) / 2.;
226  twrEtaValues[34] = (3.68 + 3.85) / 2.;
227  twrEtaValues[35] = (3.85 + 4.03) / 2.;
228  twrEtaValues[36] = (4.03 + 4.20) / 2.;
229  twrEtaValues[37] = (4.20 + 4.38) / 2.;
230  twrEtaValues[38] = (4.74 + 4.38 * 3) / 4.;
231  twrEtaValues[39] = (4.38 + 4.74 * 3) / 4.;
232  twrEtaValues[40] = (5.21 + 4.74 * 3) / 4.;
233  twrEtaValues[41] = (4.74 + 5.21 * 3) / 4.;
234  return twrEtaValues;
235  }
236  constexpr std::array<double, 42> twrEtaValues = fillTwrEtaValues();
237 } // namespace
238 
239 double UCTGeometry::getUCTTowerEta(int caloEta) {
240  uint32_t absCaloEta = std::abs(caloEta);
241  if (absCaloEta <= 41) {
242  if (caloEta < 0)
243  return -twrEtaValues[absCaloEta];
244  else
245  return +twrEtaValues[absCaloEta];
246  } else
247  return -999.;
248 }
249 
250 double UCTGeometry::getUCTTowerPhi(int caloPhi) {
251  if (caloPhi < 1)
252  return -999.;
253  else if (caloPhi > 72)
254  return +999.;
255  uint32_t absCaloPhi = std::abs(caloPhi) - 1;
256  if (absCaloPhi < 36)
257  return (((double)absCaloPhi + 0.5) * 0.0872);
258  else
259  return (-(71.5 - (double)absCaloPhi) * 0.0872);
260 }
261 
262 UCTRegionIndex UCTGeometry::getUCTRegionIndexFromL1CaloRegion(uint32_t caloRegionEta, uint32_t caloRegionPhi) {
263  uint32_t region = 0xDEADBEEF;
264  bool negativeEtaSide = false;
265  if (caloRegionEta == 31) {
266  region = 12;
267  negativeEtaSide = true;
268  } else if (caloRegionEta == 30) {
269  region = 11;
270  negativeEtaSide = true;
271  } else if (caloRegionEta <= 10) {
272  region = 10 - caloRegionEta;
273  negativeEtaSide = true;
274  } else if (caloRegionEta >= 11 && caloRegionEta <= 23) {
275  region = caloRegionEta - 11;
276  }
277  return UCTRegionIndex(getUCTRegionEtaIndex(negativeEtaSide, region), caloRegionPhi);
278 }
279 
280 UCTTowerIndex UCTGeometry::getUCTTowerIndexFromL1CaloRegion(UCTRegionIndex r, uint32_t rawData) {
281  uint32_t iEta = (rawData >> 14) & 0x3;
282  uint32_t iPhi = (rawData >> 12) & 0x3;
283  return getUCTTowerIndex(r, iEta, iPhi);
284 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define LOG_ERROR
Definition: CSCDQM_Logger.h:40