CMS 3D CMS Logo

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