6 #include "UCTGeometry.hh"
7 #include "UCTLogging.hh"
8 using namespace l1tcalo;
10 UCTGeometry::UCTGeometry() {}
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;
17 if (checkEtaIndex(region, iEta)) {
18 LOG_ERROR <<
"Invalid eta index: iEta = " << iEta << std::endl;
21 if (checkPhiIndex(region, iPhi)) {
22 LOG_ERROR <<
"Invalid eta index: iPhi = " << iPhi << std::endl;
25 uint32_t linkNumber = 0xDEADBEEF;
26 if (region < MaxRegionNumber) {
27 if (iEta < NEtaInRegion / 2) {
28 linkNumber = region * 2;
30 linkNumber = region * 2 + 1;
33 linkNumber = NRegionsInCard * 2 + iPhi;
37 linkNumber += NRegionsInCard * 2 + 2;
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;
47 if (checkEtaIndex(region, iEta)) {
48 LOG_ERROR <<
"Invalid eta index: iEta = " << iEta << std::endl;
52 int caloEtaIndex = region * NEtaInRegion + iEta + 1;
54 caloEtaIndex = (region - 7) * NHFEtaInRegion + iEta + 30;
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;
67 if (checkCard(card)) {
68 LOG_ERROR <<
"Invalid card number: card = " << card << std::endl;
71 if (checkPhiIndex(region, iPhi)) {
72 LOG_ERROR <<
"Invalid phi index: iPhi = " << iPhi << std::endl;
75 int caloPhiIndex = 0xDEADBEEF;
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;
83 if (caloPhiIndex > 72)
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;
93 if (checkCard(card)) {
94 LOG_ERROR <<
"Invalid card number: card = " << card << std::endl;
97 uint32_t uctRegionPhiIndex = 0xDEADBEEF;
99 uctRegionPhiIndex = 3 + card;
100 }
else if (crate == 1) {
102 uctRegionPhiIndex = 15 + card;
104 uctRegionPhiIndex = card - 3;
106 }
else if (crate == 2) {
107 uctRegionPhiIndex = 9 + card;
109 return uctRegionPhiIndex;
112 uint32_t UCTGeometry::getCrate(
int caloEta,
int caloPhi) {
113 uint32_t crate = 0xDEADBEEF;
114 if (caloPhi >= 11 && caloPhi <= 34)
116 else if (caloPhi >= 35 && caloPhi <= 58)
118 else if (caloPhi >= 59 && caloPhi <= 72)
120 else if (caloPhi >= 1 && caloPhi <= 10)
125 uint32_t UCTGeometry::getCard(
int caloEta,
int caloPhi) {
126 uint32_t crate = getCrate(caloEta, caloPhi);
127 uint32_t card = 0xDEADBEEF;
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;
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;
145 return NRegionsInCard + ((absCEta - 2 - (NRegionsInCard * NEtaInRegion)) / NHFEtaInRegion);
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;
153 return absCEta % NHFEtaInRegion;
156 uint32_t UCTGeometry::getiPhi(
int caloPhi) {
return (caloPhi + 1) % NPhiInCard; }
158 uint32_t UCTGeometry::getNEta(uint32_t region) {
159 uint32_t
nEta = 0xDEADBEEF;
160 if (region < CaloHFRegionStart) {
163 nEta = NHFEtaInRegion;
168 uint32_t UCTGeometry::getNPhi(uint32_t region) {
return NPhiInRegion; }
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);
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);
182 UCTTowerIndex UCTGeometry::getUCTTowerIndex(UCTRegionIndex region, uint32_t iEta, uint32_t iPhi) {
183 if (iPhi >= NPhiInRegion || iEta >= NEtaInRegion) {
184 return UCTTowerIndex(0, 0);
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;
193 }
else if (regionNo < (NRegionsInCard + NHFRegionsInCard)) {
194 towerEta = HFEtaOffset + 1 + (regionNo - NRegionsInCard) * getNEta(regionNo) + iEta;
197 towerEta = -towerEta;
198 int towerPhi = regionPhi * NPhiInRegion + iPhi - 1;
203 return UCTTowerIndex(towerEta, towerPhi);
207 constexpr std::array<double, 42> fillTwrEtaValues() {
208 std::array<double, 42> twrEtaValues = {{0}};
210 for (
unsigned int i = 0;
i < 20;
i++) {
211 twrEtaValues[
i + 1] = 0.0436 +
i * 0.0872;
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.;
236 constexpr std::array<double, 42> twrEtaValues = fillTwrEtaValues();
239 double UCTGeometry::getUCTTowerEta(
int caloEta) {
240 uint32_t absCaloEta =
std::abs(caloEta);
241 if (absCaloEta <= 41) {
243 return -twrEtaValues[absCaloEta];
245 return +twrEtaValues[absCaloEta];
250 double UCTGeometry::getUCTTowerPhi(
int caloPhi) {
253 else if (caloPhi > 72)
255 uint32_t absCaloPhi =
std::abs(caloPhi) - 1;
257 return (((
double)absCaloPhi + 0.5) * 0.0872);
259 return (-(71.5 - (
double)absCaloPhi) * 0.0872);
262 UCTRegionIndex UCTGeometry::getUCTRegionIndexFromL1CaloRegion(uint32_t caloRegionEta, uint32_t caloRegionPhi) {
263 uint32_t region = 0xDEADBEEF;
264 bool negativeEtaSide =
false;
265 if (caloRegionEta == 31) {
267 negativeEtaSide =
true;
268 }
else if (caloRegionEta == 30) {
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;
277 return UCTRegionIndex(getUCTRegionEtaIndex(negativeEtaSide, region), caloRegionPhi);
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);
Abs< T >::type abs(const T &t)