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 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  int absRegionEta = std::abs(regionEta);
188  int towerEta = (regionEta / absRegionEta) * (absRegionEta * NEtaInRegion + iEta);
189  uint32_t regionPhi = region.second;
190  int towerPhi = regionPhi * NPhiInRegion + iPhi + 1;
191  return UCTTowerIndex(towerEta, towerPhi);
192 }
193 
194 namespace {
195  constexpr std::array<double, 42> fillTwrEtaValues() {
196  std::array<double, 42> twrEtaValues = {{0}};
197  twrEtaValues[0] = 0;
198  for (unsigned int i = 0; i < 20; i++) {
199  twrEtaValues[i + 1] = 0.0436 + i * 0.0872;
200  }
201  twrEtaValues[21] = 1.785;
202  twrEtaValues[22] = 1.880;
203  twrEtaValues[23] = 1.9865;
204  twrEtaValues[24] = 2.1075;
205  twrEtaValues[25] = 2.247;
206  twrEtaValues[26] = 2.411;
207  twrEtaValues[27] = 2.575;
208  twrEtaValues[28] = 2.825;
209  twrEtaValues[29] = 999.;
210  twrEtaValues[30] = (3.15 + 2.98) / 2.;
211  twrEtaValues[31] = (3.33 + 3.15) / 2.;
212  twrEtaValues[32] = (3.50 + 3.33) / 2.;
213  twrEtaValues[33] = (3.68 + 3.50) / 2.;
214  twrEtaValues[34] = (3.68 + 3.85) / 2.;
215  twrEtaValues[35] = (3.85 + 4.03) / 2.;
216  twrEtaValues[36] = (4.03 + 4.20) / 2.;
217  twrEtaValues[37] = (4.20 + 4.38) / 2.;
218  twrEtaValues[38] = (4.74 + 4.38 * 3) / 4.;
219  twrEtaValues[39] = (4.38 + 4.74 * 3) / 4.;
220  twrEtaValues[40] = (5.21 + 4.74 * 3) / 4.;
221  twrEtaValues[41] = (4.74 + 5.21 * 3) / 4.;
222  return twrEtaValues;
223  }
224  constexpr std::array<double, 42> twrEtaValues = fillTwrEtaValues();
225 } // namespace
226 
227 double UCTGeometry::getUCTTowerEta(int caloEta) {
228  uint32_t absCaloEta = std::abs(caloEta);
229  if (absCaloEta <= 41) {
230  if (caloEta < 0)
231  return -twrEtaValues[absCaloEta];
232  else
233  return +twrEtaValues[absCaloEta];
234  } else
235  return -999.;
236 }
237 
238 double UCTGeometry::getUCTTowerPhi(int caloPhi) {
239  if (caloPhi < 1)
240  return -999.;
241  else if (caloPhi > 72)
242  return +999.;
243  uint32_t absCaloPhi = std::abs(caloPhi) - 1;
244  if (absCaloPhi < 36)
245  return (((double)absCaloPhi + 0.5) * 0.0872);
246  else
247  return (-(71.5 - (double)absCaloPhi) * 0.0872);
248 }
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.nEta
nEta
Definition: HLT_FULL_cff.py:6586
HLT_FULL_cff.region
region
Definition: HLT_FULL_cff.py:88267
SurfaceOrientation::negativeSide
Definition: Surface.h:18
L1TowerCalibrationProducer_cfi.iEta
iEta
Definition: L1TowerCalibrationProducer_cfi.py:60
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
LOG_ERROR
#define LOG_ERROR
Definition: CSCDQM_Logger.h:40