CMS 3D CMS Logo

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