Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-03 01:58:09

0001 #include <iostream>
0002 #include <cstdlib>
0003 #include <cstdint>
0004 #include <array>
0005 
0006 #include "UCTGeometry.hh"
0007 #include "UCTLogging.hh"
0008 using namespace l1tcalo;
0009 
0010 UCTGeometry::UCTGeometry() {}
0011 
0012 uint32_t UCTGeometry::getLinkNumber(bool negativeEta, uint32_t region, uint32_t iEta, uint32_t iPhi) {
0013   if (checkRegion(region)) {
0014     LOG_ERROR << "Invalid region number: region = " << region << std::endl;
0015     exit(1);
0016   }
0017   if (checkEtaIndex(region, iEta)) {
0018     LOG_ERROR << "Invalid eta index: iEta = " << iEta << std::endl;
0019     exit(1);
0020   }
0021   if (checkPhiIndex(region, iPhi)) {
0022     LOG_ERROR << "Invalid eta index: iPhi = " << iPhi << std::endl;
0023     exit(1);
0024   }
0025   uint32_t linkNumber = 0xDEADBEEF;
0026   if (region < MaxRegionNumber) {
0027     if (iEta < NEtaInRegion / 2) {
0028       linkNumber = region * 2;
0029     } else {
0030       linkNumber = region * 2 + 1;
0031     }
0032   } else {
0033     linkNumber = NRegionsInCard * 2 + iPhi;
0034   }
0035 
0036   if (!negativeEta) {
0037     linkNumber += NRegionsInCard * 2 + 2;
0038   }
0039   return linkNumber;
0040 }
0041 
0042 int UCTGeometry::getCaloEtaIndex(bool negativeSide, uint32_t region, uint32_t iEta) {
0043   if (checkRegion(region)) {
0044     LOG_ERROR << "Invalid region number: region = " << region << std::endl;
0045     exit(1);
0046   }
0047   if (checkEtaIndex(region, iEta)) {
0048     LOG_ERROR << "Invalid eta index: iEta = " << iEta << std::endl;
0049     exit(1);
0050   }
0051 
0052   int caloEtaIndex = region * NEtaInRegion + iEta + 1;
0053   if (region > 6) {
0054     caloEtaIndex = (region - 7) * NHFEtaInRegion + iEta + 30;
0055   }
0056 
0057   if (negativeSide)
0058     return -caloEtaIndex;
0059   return caloEtaIndex;
0060 }
0061 
0062 int UCTGeometry::getCaloPhiIndex(uint32_t crate, uint32_t card, uint32_t region, uint32_t iPhi) {
0063   if (checkCrate(crate)) {
0064     LOG_ERROR << "Invalid crate number: crate = " << crate << std::endl;
0065     exit(1);
0066   }
0067   if (checkCard(card)) {
0068     LOG_ERROR << "Invalid card number: card = " << card << std::endl;
0069     exit(1);
0070   }
0071   if (checkPhiIndex(region, iPhi)) {
0072     LOG_ERROR << "Invalid phi index: iPhi = " << iPhi << std::endl;
0073     exit(1);
0074   }
0075   int caloPhiIndex = 0xDEADBEEF;
0076   if (crate == 0) {
0077     caloPhiIndex = 11 + card * 4 + iPhi;
0078   } else if (crate == 1) {
0079     caloPhiIndex = 59 + card * 4 + iPhi;
0080   } else if (crate == 2) {
0081     caloPhiIndex = 35 + card * 4 + iPhi;
0082   }
0083   if (caloPhiIndex > 72)
0084     caloPhiIndex -= 72;
0085   return caloPhiIndex;
0086 }
0087 
0088 uint32_t UCTGeometry::getUCTRegionPhiIndex(uint32_t crate, uint32_t card) {
0089   if (checkCrate(crate)) {
0090     LOG_ERROR << "Invalid crate number: crate = " << crate << std::endl;
0091     exit(1);
0092   }
0093   if (checkCard(card)) {
0094     LOG_ERROR << "Invalid card number: card = " << card << std::endl;
0095     exit(1);
0096   }
0097   uint32_t uctRegionPhiIndex = 0xDEADBEEF;
0098   if (crate == 0) {
0099     uctRegionPhiIndex = 3 + card;
0100   } else if (crate == 1) {
0101     if (card < 3) {
0102       uctRegionPhiIndex = 15 + card;
0103     } else {
0104       uctRegionPhiIndex = card - 3;
0105     }
0106   } else if (crate == 2) {
0107     uctRegionPhiIndex = 9 + card;
0108   }
0109   return uctRegionPhiIndex;
0110 }
0111 
0112 uint32_t UCTGeometry::getCrate(int caloEta, int caloPhi) {
0113   uint32_t crate = 0xDEADBEEF;
0114   if (caloPhi >= 11 && caloPhi <= 34)
0115     crate = 0;
0116   else if (caloPhi >= 35 && caloPhi <= 58)
0117     crate = 2;
0118   else if (caloPhi >= 59 && caloPhi <= 72)
0119     crate = 1;
0120   else if (caloPhi >= 1 && caloPhi <= 10)
0121     crate = 1;
0122   return crate;
0123 }
0124 
0125 uint32_t UCTGeometry::getCard(int caloEta, int caloPhi) {
0126   uint32_t crate = getCrate(caloEta, caloPhi);
0127   uint32_t card = 0xDEADBEEF;
0128   if (crate == 0) {
0129     card = (caloPhi - 11) / 4;
0130   } else if (crate == 2) {
0131     card = (caloPhi - 35) / 4;
0132   } else if (crate == 1 && caloPhi > 58) {
0133     card = (caloPhi - 59) / 4;
0134   } else if (crate == 1 && caloPhi <= 10) {
0135     card = (caloPhi + 13) / 4;
0136   }
0137   return card;
0138 }
0139 
0140 uint32_t UCTGeometry::getRegion(int caloEta, int caloPhi) {
0141   uint32_t absCEta = std::abs(caloEta);
0142   if ((absCEta - 1) < (NRegionsInCard * NEtaInRegion))
0143     return (absCEta - 1) / NEtaInRegion;
0144   else
0145     return NRegionsInCard + ((absCEta - 2 - (NRegionsInCard * NEtaInRegion)) / NHFEtaInRegion);
0146 }
0147 
0148 uint32_t UCTGeometry::getiEta(int caloEta) {
0149   uint32_t absCEta = std::abs(caloEta);
0150   if ((absCEta - 1) < (NRegionsInCard * NEtaInRegion))
0151     return (absCEta - 1) % NEtaInRegion;
0152   else
0153     return absCEta % NHFEtaInRegion;  // To account for missing tower 29
0154 }
0155 
0156 uint32_t UCTGeometry::getiPhi(int caloPhi) { return (caloPhi + 1) % NPhiInCard; }
0157 
0158 uint32_t UCTGeometry::getNEta(uint32_t region) {
0159   uint32_t nEta = 0xDEADBEEF;
0160   if (region < CaloHFRegionStart) {
0161     nEta = NEtaInRegion;
0162   } else {
0163     nEta = NHFEtaInRegion;
0164   }
0165   return nEta;
0166 }
0167 
0168 uint32_t UCTGeometry::getNPhi(uint32_t region) { return NPhiInRegion; }
0169 
0170 UCTRegionIndex UCTGeometry::getUCTRegionIndex(int caloEta, int caloPhi) {
0171   uint32_t regionPhi = getUCTRegionPhiIndex(getCrate(caloEta, caloPhi), getCard(caloEta, caloPhi));
0172   int regionEta = getUCTRegionEtaIndex((caloEta < 0), getRegion(caloEta, caloPhi));
0173   return UCTRegionIndex(regionEta, regionPhi);
0174 }
0175 
0176 UCTRegionIndex UCTGeometry::getUCTRegionIndex(bool negativeSide, uint32_t crate, uint32_t card, uint32_t region) {
0177   uint32_t regionPhi = getUCTRegionPhiIndex(crate, card);
0178   int regionEta = getUCTRegionEtaIndex(negativeSide, region);
0179   return UCTRegionIndex(regionEta, regionPhi);
0180 }
0181 
0182 UCTTowerIndex UCTGeometry::getUCTTowerIndex(UCTRegionIndex region, uint32_t iEta, uint32_t iPhi) {
0183   if (iPhi >= NPhiInRegion || iEta >= NEtaInRegion) {
0184     return UCTTowerIndex(0, 0);  // Illegal values
0185   }
0186   int regionEta = region.first;
0187   uint32_t regionPhi = region.second;
0188   bool negativeSide = (regionEta < 0);
0189   uint32_t regionNo = std::abs(regionEta) - 1;
0190   int towerEta = 0xDEADBEEF;
0191   if (regionNo < NRegionsInCard) {
0192     towerEta = 1 + regionNo * getNEta(regionNo) + iEta;  // Ranges 1 - 28
0193   } else if (regionNo < (NRegionsInCard + NHFRegionsInCard)) {
0194     towerEta = HFEtaOffset + 1 + (regionNo - NRegionsInCard) * getNEta(regionNo) + iEta;  // Ranges 30 - 42
0195   }
0196   if (negativeSide)
0197     towerEta = -towerEta;
0198   int towerPhi = regionPhi * NPhiInRegion + iPhi - 1;  // Always pretend that there are 4 phi-regions
0199   if (towerPhi <= 0)
0200     towerPhi += 72;
0201   // Legal values of towerPhi = 1, 2, 5, 6, ..., 69, 70 for towerEta 30-39
0202   // Legal values of towerPhi = 1, 5, ..., 69 for towerEta 40-41
0203   return UCTTowerIndex(towerEta, towerPhi);
0204 }
0205 
0206 namespace {
0207   constexpr std::array<double, 42> fillTwrEtaValues() {
0208     std::array<double, 42> twrEtaValues = {{0}};
0209     twrEtaValues[0] = 0;
0210     for (unsigned int i = 0; i < 20; i++) {
0211       twrEtaValues[i + 1] = 0.0436 + i * 0.0872;
0212     }
0213     twrEtaValues[21] = 1.785;
0214     twrEtaValues[22] = 1.880;
0215     twrEtaValues[23] = 1.9865;
0216     twrEtaValues[24] = 2.1075;
0217     twrEtaValues[25] = 2.247;
0218     twrEtaValues[26] = 2.411;
0219     twrEtaValues[27] = 2.575;
0220     twrEtaValues[28] = 2.825;
0221     twrEtaValues[29] = 999.;
0222     twrEtaValues[30] = (3.15 + 2.98) / 2.;
0223     twrEtaValues[31] = (3.33 + 3.15) / 2.;
0224     twrEtaValues[32] = (3.50 + 3.33) / 2.;
0225     twrEtaValues[33] = (3.68 + 3.50) / 2.;
0226     twrEtaValues[34] = (3.68 + 3.85) / 2.;
0227     twrEtaValues[35] = (3.85 + 4.03) / 2.;
0228     twrEtaValues[36] = (4.03 + 4.20) / 2.;
0229     twrEtaValues[37] = (4.20 + 4.38) / 2.;
0230     twrEtaValues[38] = (4.74 + 4.38 * 3) / 4.;
0231     twrEtaValues[39] = (4.38 + 4.74 * 3) / 4.;
0232     twrEtaValues[40] = (5.21 + 4.74 * 3) / 4.;
0233     twrEtaValues[41] = (4.74 + 5.21 * 3) / 4.;
0234     return twrEtaValues;
0235   }
0236   constexpr std::array<double, 42> twrEtaValues = fillTwrEtaValues();
0237 }  // namespace
0238 
0239 double UCTGeometry::getUCTTowerEta(int caloEta) {
0240   uint32_t absCaloEta = std::abs(caloEta);
0241   if (absCaloEta <= 41) {
0242     if (caloEta < 0)
0243       return -twrEtaValues[absCaloEta];
0244     else
0245       return +twrEtaValues[absCaloEta];
0246   } else
0247     return -999.;
0248 }
0249 
0250 double UCTGeometry::getUCTTowerPhi(int caloPhi) {
0251   if (caloPhi < 1)
0252     return -999.;
0253   else if (caloPhi > 72)
0254     return +999.;
0255   uint32_t absCaloPhi = std::abs(caloPhi) - 1;
0256   if (absCaloPhi < 36)
0257     return (((double)absCaloPhi + 0.5) * 0.0872);
0258   else
0259     return (-(71.5 - (double)absCaloPhi) * 0.0872);
0260 }
0261 
0262 UCTRegionIndex UCTGeometry::getUCTRegionIndexFromL1CaloRegion(uint32_t caloRegionEta, uint32_t caloRegionPhi) {
0263   uint32_t region = 0xDEADBEEF;
0264   bool negativeEtaSide = false;
0265   if (caloRegionEta == 31) {
0266     region = 12;
0267     negativeEtaSide = true;
0268   } else if (caloRegionEta == 30) {
0269     region = 11;
0270     negativeEtaSide = true;
0271   } else if (caloRegionEta <= 10) {
0272     region = 10 - caloRegionEta;
0273     negativeEtaSide = true;
0274   } else if (caloRegionEta >= 11 && caloRegionEta <= 23) {
0275     region = caloRegionEta - 11;
0276   }
0277   return UCTRegionIndex(getUCTRegionEtaIndex(negativeEtaSide, region), caloRegionPhi);
0278 }
0279 
0280 UCTTowerIndex UCTGeometry::getUCTTowerIndexFromL1CaloRegion(UCTRegionIndex r, uint32_t rawData) {
0281   uint32_t iEta = (rawData >> 14) & 0x3;
0282   uint32_t iPhi = (rawData >> 12) & 0x3;
0283   return getUCTTowerIndex(r, iEta, iPhi);
0284 }