Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "L1Trigger/L1TMuonEndCap/interface/PtAssignmentEngineAux.h"
0002 
0003 // _____________________________________________________________________________
0004 static const int GMT_eta_from_theta[128] = {
0005     239, 235, 233, 230, 227, 224, 222, 219, 217, 214, 212, 210, 207, 205, 203, 201, 199, 197, 195, 193, 191, 189,
0006     187, 186, 184, 182, 180, 179, 177, 176, 174, 172, 171, 169, 168, 166, 165, 164, 162, 161, 160, 158, 157, 156,
0007     154, 153, 152, 151, 149, 148, 147, 146, 145, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131,
0008     130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 116, 115, 114, 113, 112, 111, 110,
0009     110, 109, 108, 107, 106, 106, 105, 104, 103, 102, 102, 101, 100, 99,  99,  98,  97,  96,  96,  95,  94,  93,
0010     93,  92,  91,  91,  90,  89,  89,  88,  87,  87,  86,  85,  84,  84,  83,  83,  82,  81};
0011 
0012 int PtAssignmentEngineAux::getGMTPt(float pt) const {
0013   // compressed pt = pt*2 (scale) + 1 (pt = 0 is empty candidate)
0014   int gmt_pt = (pt * 2) + 1;
0015   gmt_pt = (gmt_pt > 511) ? 511 : gmt_pt;
0016   return gmt_pt;
0017 }
0018 
0019 int PtAssignmentEngineAux::getGMTPtDxy(float pt) const {
0020   // compressed pt = pt*1 (scale) + 1 (pt = 0 is empty candidate)
0021   int gmt_pt_dxy = (pt * 1) + 1;
0022   gmt_pt_dxy = (gmt_pt_dxy > 255) ? 255 : gmt_pt_dxy;
0023   return gmt_pt_dxy;
0024 }
0025 
0026 int PtAssignmentEngineAux::getGMTDxy(float dxy) const {
0027   int gmt_dxy = 0;
0028   if (std::abs(dxy) < 32.) {
0029     gmt_dxy = 0;
0030   } else if (std::abs(dxy) < 64.) {
0031     gmt_dxy = 1;
0032   } else if (std::abs(dxy) < 96.) {
0033     gmt_dxy = 2;
0034   } else {
0035     gmt_dxy = 3;
0036   }
0037   return gmt_dxy;
0038 }
0039 
0040 float PtAssignmentEngineAux::getPtFromGMTPt(int gmt_pt) const {
0041   float pt = (gmt_pt <= 0) ? 0 : 0.5 * (gmt_pt - 1);
0042   return pt;
0043 }
0044 
0045 float PtAssignmentEngineAux::getPtFromGMTPtDxy(int gmt_pt_dxy) const {
0046   float pt = (gmt_pt_dxy <= 0) ? 0 : 1.0 * (gmt_pt_dxy - 1);
0047   return pt;
0048 }
0049 
0050 int PtAssignmentEngineAux::getGMTPhi(int phi) const {
0051   // convert phi into gmt scale according to DN15-017
0052   // full scale is -16 to 100, or 116 values, covers range -10 to 62.5 deg
0053   // my internal ph scale is 0..5000, covers from -22 to 63.333 deg
0054   // converted to GMT scale it is from -35 to 95
0055   // bt_phi * 107.01/4096, equivalent to bt_phi * 6849/0x40000
0056   phi *= 6849;
0057   phi >>= 18;  // divide by 0x40000
0058   phi -= 35;   // offset of -22 deg
0059   return phi;
0060 }
0061 
0062 int PtAssignmentEngineAux::getGMTPhiV2(int phi) const {
0063   // convert phi into gmt scale according to DN15-017
0064   phi *= 6991;
0065   phi >>= 18;  // divide by 0x40000
0066   phi -= 35;   // offset of -22 deg
0067   return phi;
0068 }
0069 
0070 int PtAssignmentEngineAux::getGMTEta(int theta, int endcap) const {  // [-1,+1]
0071   if (theta < 0)
0072     return 0;
0073   if (endcap == -1 && theta > 127)
0074     return -240;
0075   if (endcap == +1 && theta > 127)
0076     return 239;
0077 
0078   int eta = GMT_eta_from_theta[theta];
0079   if (endcap == -1)
0080     eta = -eta;
0081   return eta;
0082 }
0083 
0084 int PtAssignmentEngineAux::getGMTQuality(int mode, int theta, bool promoteMode7, int version) const {
0085   int quality = 0;
0086 
0087   if (version == 2) {  // 2018 mode <--> quality mapping
0088     switch (mode) {
0089       case 15:
0090         quality = 15;
0091         break;
0092       case 14:
0093         quality = 14;
0094         break;
0095       case 13:
0096         quality = 13;
0097         break;
0098       case 12:
0099         quality = 7;
0100         break;
0101       case 11:
0102         quality = 12;
0103         break;
0104       case 10:
0105         quality = 10;
0106         break;
0107       case 9:
0108         quality = 9;
0109         break;
0110       case 7:
0111         quality = 11;
0112         break;
0113       case 6:
0114         quality = 6;
0115         break;
0116       case 5:
0117         quality = 5;
0118         break;
0119       case 3:
0120         quality = 4;
0121         break;
0122       default:
0123         quality = 0;
0124         break;
0125     }
0126 
0127     if (theta > 88) {  // if (eta < 1.19)
0128       quality /= 4;
0129     }
0130   }  // End 2018 mode <--> quality mapping
0131 
0132   else {               // 2016 and 2017 mode <--> quality mapping
0133     if (theta > 87) {  // if (eta < 1.2)
0134       switch (mode) {
0135         case 15:
0136           quality = 8;
0137           break;
0138         case 14:
0139           quality = 4;
0140           break;
0141         case 13:
0142           quality = 4;
0143           break;
0144         case 12:
0145           quality = 4;
0146           break;
0147         case 11:
0148           quality = 4;
0149           break;
0150         default:
0151           quality = 4;
0152           break;
0153       }
0154     } else {
0155       switch (mode) {
0156         case 15:
0157           quality = 12;
0158           break;
0159         case 14:
0160           quality = 12;
0161           break;
0162         case 13:
0163           quality = 12;
0164           break;
0165         case 12:
0166           quality = 8;
0167           break;
0168         case 11:
0169           quality = 12;
0170           break;
0171         case 10:
0172           quality = 8;
0173           break;
0174         case 7:
0175           quality = 8;
0176           break;
0177         default:
0178           quality = 4;
0179           break;
0180       }
0181     }
0182     quality |= (mode & 3);
0183   }  // End 2016 and 2017 mode <--> quality mapping
0184 
0185   // Fix for missing CSC LCTs in ME1/1, including dead "water-leak" chambers ME1/1/34 and 35
0186   if (promoteMode7 && mode == 7 && theta <= 50)
0187     quality = 12;
0188 
0189   return quality;
0190 }
0191 
0192 std::pair<int, int> PtAssignmentEngineAux::getGMTCharge(int mode, const std::vector<int>& phidiffs) const {
0193   // -1 = postive physical charge to match pdgId code (i.e. -13 is positive, anti-muon). +1 = negative physical charge.
0194   // Also matches DN-2015/017 format for track finder --> uGMT interface format, where 0 indicates positive, 1 negative.
0195   int emuCharge = 0;
0196 
0197   // Note: sign_ph[0] == 1 in firmware actually translates to phidiffs[0] >= 0 (instead of phidiffs[0] > 0 in the old emulator)
0198   // The effect needs to be checked
0199 
0200   switch (mode) {
0201     case 15:                 // 1-2-3-4
0202       if (phidiffs[0] >= 0)  // 1-2 (should use > 0)
0203         emuCharge = 1;
0204       else if (phidiffs[0] == 0 && phidiffs[1] < 0)  // 1-3
0205         emuCharge = 1;
0206       else if (phidiffs[1] == 0 && phidiffs[2] < 0)  // 1-4
0207         emuCharge = 1;
0208       else
0209         emuCharge = -1;
0210       break;
0211 
0212     case 14:                // 1-2-3
0213       if (phidiffs[0] < 0)  // 1-2
0214         emuCharge = -1;
0215       else if (phidiffs[0] == 0 && phidiffs[1] < 0)  // 1-3
0216         emuCharge = -1;
0217       else
0218         emuCharge = 1;
0219       break;
0220 
0221     case 13:                 // 1-2-4
0222       if (phidiffs[0] >= 0)  // 1-2 (should use > 0)
0223         emuCharge = 1;
0224       else if (phidiffs[0] == 0 && phidiffs[2] < 0)  // 1-4
0225         emuCharge = 1;
0226       else
0227         emuCharge = -1;
0228       break;
0229 
0230     case 12:                 // 1-2
0231       if (phidiffs[0] >= 0)  // 1-2
0232         emuCharge = 1;
0233       else
0234         emuCharge = -1;
0235       break;
0236 
0237     case 11:                 // 1-3-4
0238       if (phidiffs[1] >= 0)  // 1-3 (should use > 0)
0239         emuCharge = 1;
0240       else if (phidiffs[1] == 0 && phidiffs[2] < 0)  // 1-4
0241         emuCharge = 1;
0242       else
0243         emuCharge = -1;
0244       break;
0245 
0246     case 10:                 // 1-3
0247       if (phidiffs[1] >= 0)  // 1-3
0248         emuCharge = 1;
0249       else
0250         emuCharge = -1;
0251       break;
0252 
0253     case 9:                  // 1-4
0254       if (phidiffs[2] >= 0)  // 1-4
0255         emuCharge = 1;
0256       else
0257         emuCharge = -1;
0258       break;
0259 
0260     case 7:                  // 2-3-4
0261       if (phidiffs[3] >= 0)  // 2-3 (should use > 0)
0262         emuCharge = 1;
0263       else if (phidiffs[3] == 0 && phidiffs[4] < 0)  // 2-4
0264         emuCharge = 1;
0265       else
0266         emuCharge = -1;
0267       break;
0268 
0269     case 6:                  // 2-3
0270       if (phidiffs[3] >= 0)  // 2-3
0271         emuCharge = 1;
0272       else
0273         emuCharge = -1;
0274       break;
0275 
0276     case 5:                  // 2-4
0277       if (phidiffs[4] >= 0)  // 2-4
0278         emuCharge = 1;
0279       else
0280         emuCharge = -1;
0281       break;
0282 
0283     case 3:                  // 3-4
0284       if (phidiffs[5] >= 0)  // 3-4
0285         emuCharge = 1;
0286       else
0287         emuCharge = -1;
0288       break;
0289 
0290     default:
0291       //emuCharge = -1;
0292       emuCharge = 0;
0293       break;
0294   }
0295 
0296   int charge = 0;
0297   if (emuCharge == 1)
0298     charge = 1;
0299 
0300   int charge_valid = 1;
0301   if (emuCharge == 0)
0302     charge_valid = 0;
0303   return std::make_pair(charge, charge_valid);
0304 }