Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:58

0001 #include "L1Trigger/L1TMuonEndCap/interface/PtAssignmentEngineAux2016.h"
0002 
0003 //ModeVariables is a 2D arrary indexed by [TrackMode(13 Total Listed Below)][VariableNumber(20 Total Constructed Above)]
0004 // Variable numbering
0005 // 0 = dPhi12
0006 // 1 = dPhi13
0007 // 2 = dPhi14
0008 // 3 = dPhi23
0009 // 4 = dPhi24
0010 // 5 = dPhi34
0011 // 6 = dEta12
0012 // 7 = dEta13
0013 // 8 = dEta14
0014 // 9 = dEta23
0015 // 10 = dEta24
0016 // 11 = dEta34
0017 // 12 = CLCT1
0018 // 13 = CLCT2
0019 // 14 = CLCT3
0020 // 15 = CLCT4
0021 // 16 = CSCID1
0022 // 17 = CSCID2
0023 // 18 = CSCID3
0024 // 19 = CSCID4
0025 // 20 = FR1
0026 // 21 = FR2
0027 // 22 = FR3
0028 // 23 = FR4
0029 
0030 // Bobby's Scheme3 (or "SchemeC"), with 30 bit compression //
0031 //3:TrackEta:dPhi12:dEta12:CLCT1:CLCT2:FR1
0032 //4:Single Station Track Not Possible
0033 //5:TrackEta:dPhi13:dEta13:CLCT1:CLCT3:FR1
0034 //6:TrackEta:dPhi23:dEta23:CLCT2:CLCT3:FR2
0035 //7:TrackEta:dPhi12:dPhi23:dEta13:CLCT1:FR1
0036 //8:Single Station Track Not Possible
0037 //9:TrackEta:dPhi14:dEta14:CLCT1:CLCT4:FR1
0038 //10:TrackEta:dPhi24:dEta24:CLCT2:CLCT4:FR2
0039 //11:TrackEta:dPhi12:dPhi24:dEta14:CLCT1:FR1
0040 //12:TrackEta:dPhi34:dEta34:CLCT3:CLCT4:FR3
0041 //13:TrackEta:dPhi13:dPhi34:dEta14:CLCT1:FR1
0042 //14:TrackEta:dPhi23:dPhi34:dEta24:CLCT2
0043 //15:TrackEta:dPhi12:dPhi23:dPhi34:FR1
0044 
0045 static const int ModeVariables_Scheme3[13][6] = {
0046     {0, 6, 12, 13, 20, -999},              // 3
0047     {-999, -999, -999, -999, -999, -999},  // 4
0048     {1, 7, 12, 14, 20, -999},              // 5
0049     {3, 9, 13, 14, 21, -999},              // 6
0050     {0, 3, 7, 12, 20, -999},               // 7
0051     {-999, -999, -999, -999, -999, -999},  // 8
0052     {2, 8, 12, 15, 20, -999},              // 9
0053     {4, 10, 13, 15, 21, -999},             // 10
0054     {0, 4, 8, 12, 20, -999},               // 11
0055     {5, 11, 14, 15, 22, -999},             // 12
0056     {1, 5, 8, 16, 20, -999},               // 13
0057     {3, 5, 10, 13, -999, -999},            // 14
0058     {0, 3, 5, 20, -999, -999}              // 15
0059 };
0060 
0061 // 256 max units----
0062 
0063 static const int dPhiNLBMap_5bit_256Max[32] = {0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15,
0064                                                16, 17, 19, 20, 21, 23, 25, 28, 31, 34, 39, 46, 55, 68, 91, 136};
0065 
0066 static const int dPhiNLBMap_6bit_256Max[64] = {0,  1,  2,  3,  4,  5,  6,  7,  8,  9,   10,  11,  12,  13,  14,  15,
0067                                                16, 17, 18, 19, 20, 21, 22, 23, 24, 25,  26,  27,  28,  29,  30,  31,
0068                                                32, 33, 34, 36, 37, 38, 39, 40, 42, 43,  45,  47,  49,  51,  53,  56,
0069                                                58, 61, 65, 68, 73, 78, 83, 89, 97, 106, 116, 129, 145, 166, 193, 232};
0070 
0071 static const int dPhiNLBMap_7bit_256Max[128] = {
0072     0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,
0073     22,  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,
0074     44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,  65,
0075     66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  77,  78,  79,  80,  81,  82,  83,  84,  86,  87,  88,  90,
0076     91,  93,  94,  96,  97,  99,  101, 103, 105, 107, 109, 111, 113, 115, 118, 120, 123, 125, 128, 131, 134, 138,
0077     141, 145, 149, 153, 157, 161, 166, 171, 176, 182, 188, 194, 201, 209, 217, 225, 235, 245};
0078 
0079 // 512 max units----
0080 
0081 static const int dPhiNLBMap_7bit_512Max[128] = {
0082     0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,
0083     22,  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,
0084     44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,  65,
0085     66,  67,  68,  69,  71,  72,  73,  74,  75,  76,  77,  79,  80,  81,  83,  84,  86,  87,  89,  91,  92,  94,
0086     96,  98,  100, 102, 105, 107, 110, 112, 115, 118, 121, 124, 127, 131, 135, 138, 143, 147, 152, 157, 162, 168,
0087     174, 181, 188, 196, 204, 214, 224, 235, 247, 261, 276, 294, 313, 336, 361, 391, 427, 470};
0088 
0089 static const int dPhiNLBMap_8bit_512Max[256] = {
0090     0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,
0091     22,  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,
0092     44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,  65,
0093     66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,  78,  79,  80,  81,  82,  83,  84,  85,  86,  87,
0094     88,  89,  90,  91,  92,  93,  94,  95,  96,  97,  98,  99,  100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
0095     110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
0096     132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 152, 153, 154,
0097     155, 156, 157, 158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 170, 171, 172, 174, 175, 176, 178, 179, 180,
0098     182, 183, 185, 186, 188, 190, 191, 193, 194, 196, 198, 200, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219,
0099     221, 223, 225, 228, 230, 232, 235, 237, 240, 242, 245, 248, 250, 253, 256, 259, 262, 265, 268, 272, 275, 278,
0100     282, 285, 289, 293, 297, 300, 305, 309, 313, 317, 322, 327, 331, 336, 341, 347, 352, 358, 363, 369, 375, 382,
0101     388, 395, 402, 410, 417, 425, 433, 442, 450, 460, 469, 479, 490, 500};
0102 
0103 const int (*PtAssignmentEngineAux2016::getModeVariables() const)[6] { return ModeVariables_Scheme3; }
0104 
0105 int PtAssignmentEngineAux2016::getNLBdPhi(int dPhi, int bits, int max) const {
0106   int dPhi_ = max;
0107   int sign_ = 1;
0108   if (dPhi < 0)
0109     sign_ = -1;
0110   dPhi = sign_ * dPhi;
0111 
0112   if (max == 256) {
0113     if (bits == 5) {
0114       dPhi_ = dPhiNLBMap_5bit_256Max[(1 << bits) - 1];
0115       for (int edge = 0; edge < (1 << bits) - 1; edge++) {
0116         if (dPhiNLBMap_5bit_256Max[edge] <= dPhi && dPhiNLBMap_5bit_256Max[edge + 1] > dPhi) {
0117           dPhi_ = dPhiNLBMap_5bit_256Max[edge];
0118           break;
0119         }
0120       }
0121     }
0122     if (bits == 6) {
0123       dPhi_ = dPhiNLBMap_6bit_256Max[(1 << bits) - 1];
0124       for (int edge = 0; edge < (1 << bits) - 1; edge++) {
0125         if (dPhiNLBMap_6bit_256Max[edge] <= dPhi && dPhiNLBMap_6bit_256Max[edge + 1] > dPhi) {
0126           dPhi_ = dPhiNLBMap_6bit_256Max[edge];
0127           break;
0128         }
0129       }
0130     }
0131     if (bits == 7) {
0132       dPhi_ = dPhiNLBMap_7bit_256Max[(1 << bits) - 1];
0133       for (int edge = 0; edge < (1 << bits) - 1; edge++) {
0134         if (dPhiNLBMap_7bit_256Max[edge] <= dPhi && dPhiNLBMap_7bit_256Max[edge + 1] > dPhi) {
0135           dPhi_ = dPhiNLBMap_7bit_256Max[edge];
0136           break;
0137         }
0138       }
0139     }
0140   }
0141 
0142   else if (max == 512) {
0143     if (bits == 7) {
0144       dPhi_ = dPhiNLBMap_7bit_512Max[(1 << bits) - 1];
0145       for (int edge = 0; edge < (1 << bits) - 1; edge++) {
0146         if (dPhiNLBMap_7bit_512Max[edge] <= dPhi && dPhiNLBMap_7bit_512Max[edge + 1] > dPhi) {
0147           dPhi_ = dPhiNLBMap_7bit_512Max[edge];
0148           break;
0149         }
0150       }
0151     }
0152     if (bits == 8) {
0153       dPhi_ = dPhiNLBMap_8bit_512Max[(1 << bits) - 1];
0154       for (int edge = 0; edge < (1 << bits) - 1; edge++) {
0155         if (dPhiNLBMap_8bit_512Max[edge] <= dPhi && dPhiNLBMap_8bit_512Max[edge + 1] > dPhi) {
0156           dPhi_ = dPhiNLBMap_8bit_512Max[edge];
0157           break;
0158         }
0159       }
0160     }
0161   }
0162 
0163   if (dPhi >= max)
0164     dPhi_ = max;
0165   return (sign_ * dPhi_);
0166 }
0167 
0168 int PtAssignmentEngineAux2016::getNLBdPhiBin(int dPhi, int bits, int max) const {
0169   int dPhiBin_ = (1 << bits) - 1;
0170   int sign_ = 1;
0171   if (dPhi < 0)
0172     sign_ = -1;
0173   dPhi = sign_ * dPhi;
0174 
0175   if (max == 256) {
0176     if (bits == 5) {
0177       for (int edge = 0; edge < (1 << bits) - 1; edge++) {
0178         if (dPhiNLBMap_5bit_256Max[edge] <= dPhi && dPhiNLBMap_5bit_256Max[edge + 1] > dPhi) {
0179           dPhiBin_ = edge;
0180           break;
0181         }
0182       }
0183     }
0184     if (bits == 6) {
0185       for (int edge = 0; edge < (1 << bits) - 1; edge++) {
0186         if (dPhiNLBMap_6bit_256Max[edge] <= dPhi && dPhiNLBMap_6bit_256Max[edge + 1] > dPhi) {
0187           dPhiBin_ = edge;
0188           break;
0189         }
0190       }
0191     }
0192     if (bits == 7) {
0193       for (int edge = 0; edge < (1 << bits) - 1; edge++) {
0194         if (dPhiNLBMap_7bit_256Max[edge] <= dPhi && dPhiNLBMap_7bit_256Max[edge + 1] > dPhi) {
0195           dPhiBin_ = edge;
0196           break;
0197         }
0198       }
0199     }
0200   }
0201 
0202   else if (max == 512) {
0203     if (bits == 7) {
0204       for (int edge = 0; edge < (1 << bits) - 1; edge++) {
0205         if (dPhiNLBMap_7bit_512Max[edge] <= dPhi && dPhiNLBMap_7bit_512Max[edge + 1] > dPhi) {
0206           dPhiBin_ = edge;
0207           break;
0208         }
0209       }
0210     }
0211     if (bits == 8) {
0212       for (int edge = 0; edge < (1 << bits) - 1; edge++) {
0213         if (dPhiNLBMap_8bit_512Max[edge] <= dPhi && dPhiNLBMap_8bit_512Max[edge + 1] > dPhi) {
0214           dPhiBin_ = edge;
0215           break;
0216         }
0217       }
0218     }
0219   }
0220 
0221   return (dPhiBin_);
0222 }
0223 
0224 int PtAssignmentEngineAux2016::getdPhiFromBin(int dPhiBin, int bits, int max) const {
0225   int dPhi_ = (1 << bits) - 1;
0226 
0227   if (dPhiBin > (1 << bits) - 1)
0228     dPhiBin = (1 << bits) - 1;
0229 
0230   if (max == 256) {
0231     if (bits == 5)
0232       dPhi_ = dPhiNLBMap_5bit_256Max[dPhiBin];
0233     if (bits == 6)
0234       dPhi_ = dPhiNLBMap_6bit_256Max[dPhiBin];
0235     if (bits == 7)
0236       dPhi_ = dPhiNLBMap_7bit_256Max[dPhiBin];
0237   }
0238 
0239   else if (max == 512) {
0240     if (bits == 7)
0241       dPhi_ = dPhiNLBMap_7bit_512Max[dPhiBin];
0242     if (bits == 8)
0243       dPhi_ = dPhiNLBMap_8bit_512Max[dPhiBin];
0244   }
0245 
0246   return (dPhi_);
0247 }
0248 
0249 int PtAssignmentEngineAux2016::getCLCT(int clct) const {
0250   int clct_ = 0;
0251   int sign_ = 1;
0252 
0253   switch (clct) {
0254     case 10:
0255       clct_ = 0;
0256       sign_ = -1;
0257       break;
0258     case 9:
0259       clct_ = 1;
0260       sign_ = 1;
0261       break;
0262     case 8:
0263       clct_ = 1;
0264       sign_ = -1;
0265       break;
0266     case 7:
0267       clct_ = 2;
0268       sign_ = 1;
0269       break;
0270     case 6:
0271       clct_ = 2;
0272       sign_ = -1;
0273       break;
0274     case 5:
0275       clct_ = 3;
0276       sign_ = 1;
0277       break;
0278     case 4:
0279       clct_ = 3;
0280       sign_ = -1;
0281       break;
0282     case 3:
0283       clct_ = 3;
0284       sign_ = 1;
0285       break;
0286     case 2:
0287       clct_ = 3;
0288       sign_ = -1;
0289       break;
0290     case 1:
0291       clct_ = 3;
0292       sign_ = -1;
0293       break;  //case  1: clct_ = 3; sign_ =  1; break;
0294     case 0:
0295       clct_ = 3;
0296       sign_ = -1;
0297       break;
0298     default:
0299       clct_ = 3;
0300       sign_ = -1;
0301       break;
0302   }
0303   return (sign_ * clct_);
0304 }
0305 
0306 int PtAssignmentEngineAux2016::getdTheta(int dTheta) const {
0307   int dTheta_ = 0;
0308 
0309   if (dTheta <= -3)
0310     dTheta_ = 0;
0311   else if (dTheta <= -2)
0312     dTheta_ = 1;
0313   else if (dTheta <= -1)
0314     dTheta_ = 2;
0315   else if (dTheta <= 0)
0316     dTheta_ = 3;
0317   else if (dTheta <= 1)
0318     dTheta_ = 4;
0319   else if (dTheta <= 2)
0320     dTheta_ = 5;
0321   else if (dTheta <= 3)
0322     dTheta_ = 6;
0323   else
0324     dTheta_ = 7;
0325   return (dTheta_);
0326 }
0327 
0328 int PtAssignmentEngineAux2016::getdEta(int dEta) const {
0329   int dEta_ = 0;
0330 
0331   if (dEta <= -5)
0332     dEta_ = 0;
0333   else if (dEta <= -2)
0334     dEta_ = 1;
0335   else if (dEta <= -1)
0336     dEta_ = 2;
0337   else if (dEta <= 0)
0338     dEta_ = 3;
0339   else if (dEta <= 1)
0340     dEta_ = 4;
0341   else if (dEta <= 3)
0342     dEta_ = 5;
0343   else if (dEta <= 6)
0344     dEta_ = 6;
0345   else
0346     dEta_ = 7;
0347   return (dEta_);
0348 }
0349 
0350 int PtAssignmentEngineAux2016::getEtaInt(float eta, int bits) const {
0351   eta = std::abs(eta);
0352   eta = (eta < 0.9) ? 0.9 : eta;
0353   bits = (bits > 5) ? 5 : bits;
0354   // encode 0.9<abs(eta)<1.6 in 5-bit (32 possible values)
0355   int etaInt = ((eta - 0.9) * 32) / (1.6) - 0.5;
0356   int shift = 5 - bits;
0357   etaInt >>= shift;
0358   etaInt = (etaInt > 31) ? 31 : etaInt;
0359   return etaInt;
0360 }
0361 
0362 float PtAssignmentEngineAux2016::getEtaFromThetaInt(int thetaInt, int bits) const {
0363   thetaInt = (thetaInt > 127) ? 127 : thetaInt;  // 7-bit
0364   thetaInt = (thetaInt < 0) ? 0 : thetaInt;
0365   float theta = thetaInt;
0366   theta = (theta * 0.2874016 + 8.5) *
0367           (3.14159265359 / 180);  // use this version to reproduce what happened when the pT LUT was made
0368   //theta = (theta*(45.0-8.5)/128. + 8.5) * M_PI/180.;
0369   float eta = -std::log(std::tan(theta / 2));
0370   return eta;
0371 }
0372 
0373 float PtAssignmentEngineAux2016::getEtaFromEtaInt(int etaInt, int bits) const {
0374   etaInt = (etaInt > 31) ? 31 : etaInt;  // 5-bit
0375   etaInt = (etaInt < 0) ? 0 : etaInt;
0376   bits = (bits > 5) ? 5 : bits;
0377   int shift = 5 - bits;
0378   etaInt <<= shift;
0379   // decode 5-bit etaInt to 0.9<abs(eta)<1.6
0380   float eta = ((0.5 + etaInt) * 1.6) / 32 + 0.9;
0381   return eta;
0382 }
0383 
0384 float PtAssignmentEngineAux2016::getEtaFromBin(int etaBin, int bits) const {
0385   // For backward compatibility
0386   return getEtaFromEtaInt(etaBin, bits);
0387 }
0388 
0389 // front-rear LUTs
0390 // [sector[0]][station 0-4][chamber id]
0391 // chamber numbers start from 1, so add an extra low bit for invalid chamber = 0
0392 static const int FRLUT[2][5] = {{0b0000000100100, 0b0000001011010, 0b0101010101010, 0b0010101010100, 0b0010101010100},
0393                                 {0b0000000100100, 0b0000001011010, 0b0111010100100, 0b0000101011010, 0b0000101011010}};
0394 
0395 int PtAssignmentEngineAux2016::getFRLUT(int sector, int station, int chamber) const {
0396   int bits = FRLUT[(sector - 1) % 2][station];
0397   bool isFront = bits & (1 << chamber);
0398   return isFront;
0399 }