Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-18 09:15:08

0001 /*****************************************************
0002  * 28/01/2010
0003  * GP: added new switch to use the beam start Pt LUTs
0004  * if (eta > 2.1) 2 stations tracks have quality 2
0005  *                3 stations tracks have quality 3
0006  * NB: no matter if the have ME1
0007  * 
0008  * --> by default is set to true
0009  *****************************************************/
0010 
0011 #include <L1Trigger/CSCTrackFinder/interface/CSCTFPtLUT.h>
0012 #include <DataFormats/L1CSCTrackFinder/interface/CSCTFConstants.h>
0013 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0014 #include <fstream>
0015 
0016 ptdat* CSCTFPtLUT::pt_lut = nullptr;
0017 bool CSCTFPtLUT::lut_read_in = false;
0018 // L1MuTriggerScales CSCTFPtLUT::trigger_scale;
0019 // L1MuTriggerPtScale CSCTFPtLUT::trigger_ptscale;
0020 // CSCTFPtMethods CSCTFPtLUT::ptMethods;
0021 
0022 ///KK
0023 #include <L1Trigger/CSCTrackFinder/interface/CSCTFPtLUT.h>
0024 
0025 // info for getPtScale() pt scale in GeV
0026 // low edges of pt bins
0027 /*     const float ptscale[33] = {  */
0028 /*       -1.,   0.0,   1.5,   2.0,   2.5,   3.0,   3.5,   4.0, */
0029 /*       4.5,   5.0,   6.0,   7.0,   8.0,  10.0,  12.0,  14.0,   */
0030 /*       16.0,  18.0,  20.0,  25.0,  30.0,  35.0,  40.0,  45.0,  */
0031 /*       50.0,  60.0,  70.0,  80.0,  90.0, 100.0, 120.0, 140.0, 1.E6 }; */
0032 
0033 /*
0034   These arrays were defined such that they take integer dPhi --> dPhi-units which are used by CSCTFPtMethods.
0035   The values were defined using:
0036   
0037   Phi_{i} = Phi_{i-1} + MAX( phi_Unit * alphi^{i}, phi_Unit), where phi_Unit = 62 deg / 4096, and alpha is solved for
0038   such that the phi-space is resonably covered. This will be better optimized in the future.
0039   
0040 */
0041 
0042 // Array that maps the 5-bit integer dPhi --> dPhi-units. It is assumed that this is used for dPhi23,
0043 // which has a maximum value of 3.83 degrees (255 units) in the extrapolation units.
0044 const int CSCTFPtLUT::dPhiNLBMap_5bit[32] = {0,  1,  2,  4,  5,  7,  9,  11, 13,  15,  18,  21,  24,  28,  32,  37,
0045                                              41, 47, 53, 60, 67, 75, 84, 94, 105, 117, 131, 145, 162, 180, 200, 222};
0046 
0047 // Array that maps the 7-bit integer dPhi --> dPhi-units. It is assumed that this is used for dPhi12,
0048 // which has a maximum value of 7.67 degrees (511 units) in the extrapolation units.
0049 const int CSCTFPtLUT::dPhiNLBMap_7bit[128] = {
0050     0,   1,   2,   3,   4,   5,   6,   8,   9,   10,  11,  12,  14,  15,  16,  17,  19,  20,  21,  23,  24,  26,
0051     27,  29,  30,  32,  33,  35,  37,  38,  40,  42,  44,  45,  47,  49,  51,  53,  55,  57,  59,  61,  63,  65,
0052     67,  70,  72,  74,  77,  79,  81,  84,  86,  89,  92,  94,  97,  100, 103, 105, 108, 111, 114, 117, 121, 124,
0053     127, 130, 134, 137, 141, 144, 148, 151, 155, 159, 163, 167, 171, 175, 179, 183, 188, 192, 197, 201, 206, 210,
0054     215, 220, 225, 230, 235, 241, 246, 251, 257, 263, 268, 274, 280, 286, 292, 299, 305, 312, 318, 325, 332, 339,
0055     346, 353, 361, 368, 376, 383, 391, 399, 408, 416, 425, 433, 442, 451, 460, 469, 479, 489};
0056 
0057 // Array that maps the 8-bit integer dPhi --> dPhi-units. It is assumed that this is used for dPhi12,
0058 // which has a maximum value of 7.67 degrees (511 units) in the extrapolation units.
0059 const int CSCTFPtLUT::dPhiNLBMap_8bit[256] = {
0060     0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   10,  11,  12,  13,  14,  16,  17,  18,  19,  20,  21,  22,
0061     23,  24,  25,  27,  28,  29,  30,  31,  32,  33,  35,  36,  37,  38,  39,  40,  42,  43,  44,  45,  46,  48,
0062     49,  50,  51,  53,  54,  55,  56,  58,  59,  60,  61,  63,  64,  65,  67,  68,  69,  70,  72,  73,  74,  76,
0063     77,  79,  80,  81,  83,  84,  85,  87,  88,  90,  91,  92,  94,  95,  97,  98,  100, 101, 103, 104, 105, 107,
0064     108, 110, 111, 113, 115, 116, 118, 119, 121, 122, 124, 125, 127, 129, 130, 132, 133, 135, 137, 138, 140, 141,
0065     143, 145, 146, 148, 150, 151, 153, 155, 157, 158, 160, 162, 163, 165, 167, 169, 171, 172, 174, 176, 178, 180,
0066     181, 183, 185, 187, 189, 191, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222,
0067     224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 249, 251, 253, 255, 257, 259, 261, 264, 266, 268,
0068     270, 273, 275, 277, 279, 282, 284, 286, 289, 291, 293, 296, 298, 300, 303, 305, 307, 310, 312, 315, 317, 320,
0069     322, 324, 327, 329, 332, 334, 337, 340, 342, 345, 347, 350, 352, 355, 358, 360, 363, 366, 368, 371, 374, 376,
0070     379, 382, 385, 387, 390, 393, 396, 398, 401, 404, 407, 410, 413, 416, 419, 421, 424, 427, 430, 433, 436, 439,
0071     442, 445, 448, 451, 454, 457, 461, 464, 467, 470, 473, 476, 479, 483};
0072 
0073 //const int CSCTFPtLUT::dEtaCut_Low[24]    = {2,2,2,4,2,1,2,4,7,7,3,4,1,1,1,1,7,7,2,2,7,7,1,1};
0074 //const int CSCTFPtLUT::dEtaCut_Mid[24]    = {2,2,3,5,2,2,3,5,7,7,4,5,2,2,2,2,7,7,2,2,7,7,2,2};
0075 //const int CSCTFPtLUT::dEtaCut_High_A[24] = {3,3,4,6,3,2,4,6,7,7,5,6,2,2,2,2,7,7,3,3,7,7,2,2};
0076 //const int CSCTFPtLUT::dEtaCut_High_B[24] = {3,3,4,7,3,3,5,7,7,7,6,7,2,2,3,3,7,7,3,3,7,7,3,2};
0077 //const int CSCTFPtLUT::dEtaCut_High_C[24] = {4,4,5,7,4,3,6,7,7,7,7,7,3,3,3,3,7,7,4,4,7,7,3,3};
0078 const int CSCTFPtLUT::dEtaCut_Low[24] = {2, 2, 2, 7, 2, 1, 2, 7, 3, 3, 3, 7, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1};
0079 const int CSCTFPtLUT::dEtaCut_Mid[24] = {2, 2, 3, 7, 2, 2, 3, 7, 4, 4, 4, 7, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
0080 const int CSCTFPtLUT::dEtaCut_High_A[24] = {3, 3, 4, 7, 3, 2, 4, 7, 5, 5, 5, 7, 2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2};
0081 const int CSCTFPtLUT::dEtaCut_High_B[24] = {3, 3, 4, 7, 3, 3, 5, 7, 6, 6, 6, 7, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2};
0082 const int CSCTFPtLUT::dEtaCut_High_C[24] = {4, 4, 5, 7, 4, 3, 6, 7, 7, 7, 7, 7, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3};
0083 const int CSCTFPtLUT::dEtaCut_Open[24] = {7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
0084 
0085 const int CSCTFPtLUT::getPtbyMLH = 0xFFFF;  // all modes on
0086 
0087 CSCTFPtLUT::Tokens CSCTFPtLUT::consumes(edm::ConsumesCollector iC) {
0088   Tokens tok;
0089   if (not lut_read_in) {
0090     tok.ptLUT = iC.esConsumes();
0091   }
0092   tok.scales = iC.esConsumes();
0093   tok.ptScale = iC.esConsumes();
0094   return tok;
0095 }
0096 
0097 CSCTFPtLUT::CSCTFPtLUT(const edm::EventSetup& es, const Tokens& tokens) : read_pt_lut(true), isBinary(false) {
0098   pt_method = 34;
0099   //std::cout << "pt_method from 4 " << std::endl;
0100   lowQualityFlag = 4;
0101   isBeamStartConf = true;
0102   if (!lut_read_in) {
0103     pt_lut = new ptdat[1 << 21];
0104 
0105     const L1MuCSCPtLut& myConfigPt_ = es.getData(tokens.ptLUT);
0106 
0107     memcpy((void*)pt_lut, (void*)myConfigPt_.lut(), (1 << 21) * sizeof(ptdat));
0108 
0109     lut_read_in = true;
0110   }
0111   trigger_scale = &es.getData(tokens.scales);
0112   trigger_ptscale = &es.getData(tokens.ptScale);
0113 
0114   ptMethods = CSCTFPtMethods(trigger_ptscale);
0115 }
0116 ///
0117 
0118 CSCTFPtLUT::CSCTFPtLUT(const edm::ParameterSet& pset,
0119                        const L1MuTriggerScales* scales,
0120                        const L1MuTriggerPtScale* ptScale)
0121     : trigger_scale(scales), trigger_ptscale(ptScale), ptMethods(ptScale), read_pt_lut(false), isBinary(false) {
0122   //read_pt_lut = pset.getUntrackedParameter<bool>("ReadPtLUT",false);
0123   read_pt_lut = pset.getParameter<bool>("ReadPtLUT");
0124   if (read_pt_lut) {
0125     pt_lut_file = pset.getParameter<edm::FileInPath>("PtLUTFile");
0126     //isBinary = pset.getUntrackedParameter<bool>("isBinary", false);
0127     isBinary = pset.getParameter<bool>("isBinary");
0128 
0129     edm::LogInfo("CSCTFPtLUT::CSCTFPtLUT")
0130         << "Reading file: " << pt_lut_file.fullPath().c_str() << " isBinary?(1/0): " << isBinary;
0131   }
0132 
0133   // Determine the pt assignment method to use
0134   // 1 - Darin's parameterization method
0135   // 2 - Cathy Yeh's chi-square minimization method
0136   // 3 - Hybrid
0137   // 4 - Anna's parameterization method
0138   // 5 - Anna's parameterization method
0139   //with improvments at ME1/1a: find max pt for 3 links hypothesis
0140   // 11 - Anna's: for fw 20101011 <- 2011 data taking <- not valide any more
0141   // 12 - Anna's: for fw 20101011 <- 2011 data taking <- not valide any more
0142   //with improvments at ME1/1a: find max pt for 3 links hypothesis
0143   // 21 - Anna's: for fw 20110118 and up, curves with data 2010 <- 2011 data taking
0144   // 22 - Anna's: for fw 20110118 and up, curves with data 2010 <- 2011 data taking
0145   //with improvments at ME1/1a: find max pt for 3 links hypothesis
0146   // 23 - Anna's: for fw 20110118 and up, curves with MC like method 4 <- 2011 data taking
0147   // 24 - Anna's: for fw 20110118 and up, curves with MC like method 4 <- 2011 data taking
0148   //with improvments at ME1/1a: find max pt for 3 links hypothesis
0149   //25 and 26 like 23 and 24 correspondenly but fix high pt assignment in DT-CSC region
0150   // 25 - Anna's: for fw 20110118 and up, curves with MC like method 4 <- 2011 data taking
0151   // 26 - Anna's: for fw 20110118 and up, curves with MC like method 4 <- 2011 data taking
0152   //with improvments at ME1/1a: find max pt for 3 links hypothesis
0153   // change Quality: Q = 3 for mode 5, Quility = 2 for mode = 8, 9, 10 at eta = 1.6-1.8
0154   // 27 - Anna's: for fw 20110118 and up, curves with MC like method 4 <- 2011 data taking
0155   // 28 - Anna's: for fw 20110118 and up, curves with MC like method 4 <- 2011 data taking
0156   //with improvments at ME1/1a: find max pt for 3 links hypothesis
0157   // 29 - Bobby's medium Quality: using fw 2012_01_31. Switch to Global Log(L). Non-Linear dphi binning.
0158   // 33 - Bobby's medium Quality: using fw 2012_01_31. Switch to Global Log(L). Non-Linear dphi binning. No max pt at eta > 2.1
0159   // 30 - Bobby's loose Quality: using fw 2012_01_31. Switch to Global Log(L). Non-Linear dphi binning.
0160   // 31 - Bobby's tight Quality: using fw 2012_01_31. Switch to Global Log(L). Non-Linear dphi binning.
0161   // 32 - Bobby's medium Quality+ {tight only mode5 at eta > 2.1}: using fw 2012_01_31. Switch to Global Log(L). Non-Linear dphi binning.
0162   // 34 - Michele. As 33 plus  Non-Linear dphi binning also for eta > 2.1
0163 
0164   pt_method = pset.getUntrackedParameter<unsigned>("PtMethod", 32);
0165   //std::cout << "pt_method from pset " << std::endl;
0166   // what does this mean???
0167   lowQualityFlag = pset.getUntrackedParameter<unsigned>("LowQualityFlag", 4);
0168 
0169   if (read_pt_lut && !lut_read_in) {
0170     pt_lut = new ptdat[1 << 21];
0171     readLUT();
0172     lut_read_in = true;
0173   }
0174 
0175   isBeamStartConf = pset.getUntrackedParameter<bool>("isBeamStartConf", true);
0176 }
0177 
0178 ptdat CSCTFPtLUT::Pt(const ptadd& address) const {
0179   ptdat result;
0180   /*
0181   if(read_pt_lut) 
0182   {
0183     int shortAdd = (address.toint()& 0x1fffff);
0184     result = pt_lut[shortAdd];
0185   } else
0186   */
0187   result = calcPt(address);
0188   return result;
0189 }
0190 
0191 ptdat CSCTFPtLUT::Pt(const unsigned& address) const { return Pt(ptadd(address)); }
0192 
0193 ptdat CSCTFPtLUT::Pt(const unsigned& delta_phi_12,
0194                      const unsigned& delta_phi_23,
0195                      const unsigned& track_eta,
0196                      const unsigned& track_mode,
0197                      const unsigned& track_fr,
0198                      const unsigned& delta_phi_sign) const {
0199   ptadd address;
0200   address.delta_phi_12 = delta_phi_12;
0201   address.delta_phi_23 = delta_phi_23;
0202   address.track_eta = track_eta;
0203   address.track_mode = track_mode;
0204   address.track_fr = track_fr;
0205   address.delta_phi_sign = delta_phi_sign;
0206 
0207   return Pt(address);
0208 }
0209 
0210 ptdat CSCTFPtLUT::Pt(const unsigned& delta_phi_12,
0211                      const unsigned& track_eta,
0212                      const unsigned& track_mode,
0213                      const unsigned& track_fr,
0214                      const unsigned& delta_phi_sign) const {
0215   ptadd address;
0216   address.delta_phi_12 = ((1 << 8) - 1) & delta_phi_12;
0217   address.delta_phi_23 = ((1 << 4) - 1) & (delta_phi_12 >> 8);
0218   address.track_eta = track_eta;
0219   address.track_mode = track_mode;
0220   address.track_fr = track_fr;
0221   address.delta_phi_sign = delta_phi_sign;
0222 
0223   return Pt(address);
0224 }
0225 
0226 ptdat CSCTFPtLUT::calcPt(const ptadd& address) const {
0227   ptdat result;
0228 
0229   double Pi = acos(-1.);
0230   float etaR = 0, ptR_front = 0, ptR_rear = 0, dphi12R = 0, dphi23R = 0;
0231   int charge12, charge23;
0232   unsigned mode, eta, fr, quality, charge, absPhi12, absPhi23;
0233 
0234   mode = address.track_mode;
0235 
0236   int usedetaCUT = true;
0237   // Chose Eta cut tightness. 1=tightest, 2=moderate, 3=loose, 4=very loose, 5=extremely loose, 6=open
0238 
0239   // modes 6, 7, 13
0240   int EtaCutLevel_1 = 2;
0241   int dEtaCut_1[24];
0242 
0243   for (int i = 0; i < 24; i++) {
0244     dEtaCut_1[i] = 10;
0245     if (EtaCutLevel_1 == 1)
0246       dEtaCut_1[i] = dEtaCut_Low[i];
0247     else if (EtaCutLevel_1 == 2)
0248       dEtaCut_1[i] = dEtaCut_Mid[i];
0249     else if (EtaCutLevel_1 == 3)
0250       dEtaCut_1[i] = dEtaCut_High_A[i];
0251     else if (EtaCutLevel_1 == 4)
0252       dEtaCut_1[i] = dEtaCut_High_B[i];
0253     else if (EtaCutLevel_1 == 5)
0254       dEtaCut_1[i] = dEtaCut_High_C[i];
0255     else if (EtaCutLevel_1 == 6)
0256       dEtaCut_1[i] = dEtaCut_Open[i];
0257   }
0258   // modes 8, 9, 10
0259   int EtaCutLevel_2 = 2;
0260   int dEtaCut_2[24];
0261 
0262   for (int i = 0; i < 24; i++) {
0263     dEtaCut_2[i] = 10;
0264     if (EtaCutLevel_2 == 1)
0265       dEtaCut_2[i] = dEtaCut_Low[i];
0266     else if (EtaCutLevel_2 == 2)
0267       dEtaCut_2[i] = dEtaCut_Mid[i];
0268     else if (EtaCutLevel_2 == 3)
0269       dEtaCut_2[i] = dEtaCut_High_A[i];
0270     else if (EtaCutLevel_2 == 4)
0271       dEtaCut_2[i] = dEtaCut_High_B[i];
0272     else if (EtaCutLevel_2 == 5)
0273       dEtaCut_2[i] = dEtaCut_High_C[i];
0274     else if (EtaCutLevel_2 == 6)
0275       dEtaCut_2[i] = dEtaCut_Open[i];
0276 
0277     float scalef = 1.0;
0278     if (mode == 8 || mode == 10)
0279       dEtaCut_2[i] = scalef * dEtaCut_2[i];
0280   }
0281 
0282   eta = address.track_eta;
0283 
0284   fr = address.track_fr;
0285   charge = address.delta_phi_sign;
0286   quality = trackQuality(eta, mode, fr);
0287   unsigned front_pt, rear_pt;
0288   front_pt = 0.;
0289   rear_pt = 0.;
0290   unsigned front_quality, rear_quality;
0291 
0292   etaR = trigger_scale->getRegionalEtaScale(2)->getLowEdge(2 * eta + 1);
0293 
0294   front_quality = rear_quality = quality;
0295 
0296   unsigned int remerged;
0297   int iME11;
0298   int CLCT_pattern;
0299   int dEta;
0300   int index = 0;
0301   float bestLH = -999;
0302   float bestLH_front = -999.0;
0303   float bestLH_rear = -999.0;
0304 
0305   int PtbyMLH = false;
0306 
0307   //***************************************************//
0308   if (pt_method >= 29 && pt_method <= 34) {
0309     // using fw 2012_01_31. Switch to Global Log(L). Non-Linear dphi binning.
0310     PtbyMLH = 0x1 & (getPtbyMLH >> (int)mode);
0311     ///////////////////////////////////////////////////////////
0312     // switch off any improvment for eta > 2.1
0313     if (etaR > 2.1 && pt_method <= 33) {
0314       usedetaCUT = false;
0315       PtbyMLH = 0x0;
0316     }
0317     ///////////////////////////////////////////////////////////
0318 
0319     switch (mode) {
0320       case 2:
0321       case 3:
0322       case 4:
0323       case 5:
0324 
0325         charge12 = 1;
0326 
0327         // First remake the 12-bit dPhi word from the core
0328         remerged = (address.delta_phi_12 | (address.delta_phi_23 << 8));
0329 
0330         // Now separate it into 7-bit dPhi12 and 5-bit dPhi23 parts
0331         absPhi12 = ((1 << 7) - 1) & remerged;
0332         absPhi23 = ((1 << 5) - 1) & (remerged >> 7);
0333 
0334         // Now get the corresponding dPhi value in our phi-units using the inverse dPhi LUTs
0335         absPhi12 = dPhiNLBMap_7bit[absPhi12];
0336         absPhi23 = dPhiNLBMap_5bit[absPhi23];
0337 
0338         if (charge)
0339           charge23 = 1;
0340         else
0341           charge23 = -1;
0342 
0343         dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0344         dphi23R = (static_cast<float>(absPhi23)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0345         if (charge12 * charge23 < 0)
0346           dphi23R = -dphi23R;
0347 
0348         ptR_front = ptMethods.Pt3Stn2012(int(mode), etaR, dphi12R, dphi23R, PtbyMLH, bestLH, 1, int(pt_method));
0349         bestLH_front = bestLH;
0350         ptR_rear = ptMethods.Pt3Stn2012(int(mode), etaR, dphi12R, dphi23R, PtbyMLH, bestLH, 0, int(pt_method));
0351         bestLH_rear = bestLH;
0352 
0353         if ((pt_method == 29 || pt_method == 32 || pt_method == 30 || pt_method == 31) && mode != 5 &&
0354             etaR > 2.1)  //exclude mode without ME11a
0355         {
0356           float dphi12Rmin = dphi12R - Pi * 10 / 180 / 3;  // 10/3 degrees
0357           float dphi12Rmax = dphi12R + Pi * 10 / 180 / 3;  // 10/3 degrees
0358           float dphi23Rmin = dphi23R;
0359           float dphi23Rmax = dphi23R;
0360           //if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
0361           //if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
0362           float ptR_front_min =
0363               ptMethods.Pt3Stn2012(int(mode), etaR, dphi12Rmin, dphi23Rmin, PtbyMLH, bestLH, 1, int(pt_method));
0364           float bestLH_front_min = bestLH;
0365           float ptR_rear_min =
0366               ptMethods.Pt3Stn2012(int(mode), etaR, dphi12Rmin, dphi23Rmin, PtbyMLH, bestLH, 0, int(pt_method));
0367           float bestLH_rear_min = bestLH;
0368           float ptR_front_max =
0369               ptMethods.Pt3Stn2012(int(mode), etaR, dphi12Rmax, dphi23Rmax, PtbyMLH, bestLH, 1, int(pt_method));
0370           float bestLH_front_max = bestLH;
0371           float ptR_rear_max =
0372               ptMethods.Pt3Stn2012(int(mode), etaR, dphi12Rmax, dphi23Rmax, PtbyMLH, bestLH, 0, int(pt_method));
0373           float bestLH_rear_max = bestLH;
0374 
0375           if (PtbyMLH) {
0376             float best_pt_front = ptR_front;
0377             float best_LH_front = bestLH_front;
0378             if (bestLH_front_min > best_LH_front) {
0379               best_pt_front = ptR_front_min;
0380               best_LH_front = bestLH_front_min;
0381             }
0382             if (bestLH_front_max > best_LH_front) {
0383               best_pt_front = ptR_front_max;
0384             }
0385             ptR_front = best_pt_front;
0386 
0387             float best_pt_rear = ptR_rear;
0388             float best_LH_rear = bestLH_rear;
0389             if (bestLH_rear_min > best_LH_rear) {
0390               best_pt_rear = ptR_rear_min;
0391               best_LH_rear = bestLH_rear_min;
0392             }
0393             if (bestLH_rear_max > best_LH_rear) {
0394               best_pt_rear = ptR_rear_max;
0395             }
0396             ptR_rear = best_pt_rear;
0397           } else {
0398             // select max pt solution for 3 links:
0399             ptR_front = std::max(ptR_front, ptR_front_min);
0400             ptR_front = std::max(ptR_front, ptR_front_max);
0401             ptR_rear = std::max(ptR_rear, ptR_rear_min);
0402             ptR_rear = std::max(ptR_rear, ptR_rear_max);
0403           }
0404         }
0405         break;
0406       case 6:  // for mode 6, 7 and 13 add CLCT information in dph23 bit and iME11 in charge bit
0407       case 7:
0408       case 13:  // ME1-ME4
0409 
0410         // First remake the 12-bit dPhi word from the core
0411         remerged = (address.delta_phi_12 | (address.delta_phi_23 << 8));
0412         // Now get 8-bit dPhi12
0413         absPhi12 = ((1 << 8) - 1) & remerged;
0414         // Now get 3-bit dEta
0415         dEta = ((1 << 3) - 1) & (remerged >> 8);
0416         // New get CLCT bit. CLCT = true if CLCTPattern = 8, 9, or 10, else 0.
0417         CLCT_pattern = 0x1 & (remerged >> 11);
0418 
0419         iME11 = int(charge);  // = 0 if ME1/1, = 1 if ME1/2 or ME1/3 station
0420         if (iME11 == 1 && etaR > 1.6)
0421           etaR = 1.55;  // shift for ME1/2 station
0422         if (iME11 == 0 && etaR < 1.6)
0423           etaR = 1.65;  // shift for ME1/1 station
0424 
0425         // Get the 8-bit dPhi bin number
0426         absPhi12 = ((1 << 8) - 1) & address.delta_phi_12;
0427 
0428         // Now get the corresponding dPhi value in our phi-units using the inverse dPhi LUTs
0429         absPhi12 = dPhiNLBMap_8bit[absPhi12];
0430 
0431         //int CLCT_pattern = static_cast<int>(address.delta_phi_23);
0432 
0433         dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0434 
0435         //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
0436         ptR_front = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R, PtbyMLH, bestLH, 1, int(pt_method));
0437         bestLH_front = bestLH;
0438         ptR_rear = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R, PtbyMLH, bestLH, 0, int(pt_method));
0439         bestLH_rear = bestLH;
0440         if ((pt_method == 29 || pt_method == 32 || pt_method == 30 || pt_method == 31) &&
0441             etaR > 2.1)  //exclude tracks without ME11a
0442         {
0443           float dphi12Rmin = fabs(fabs(dphi12R) - Pi * 10 / 180 / 3);  // 10/3 degrees
0444           float ptR_front_min = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12Rmin, PtbyMLH, bestLH, 1, int(pt_method));
0445           float bestLH_front_min = bestLH;
0446           float ptR_rear_min = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12Rmin, PtbyMLH, bestLH, 0, int(pt_method));
0447           float bestLH_rear_min = bestLH;
0448 
0449           if (PtbyMLH) {
0450             ptR_front = bestLH_front > bestLH_front_min ? ptR_front : ptR_front_min;
0451             ptR_rear = bestLH_rear > bestLH_rear_min ? ptR_rear : ptR_rear_min;
0452           } else {
0453             // select max pt solution for 3 links:
0454             ptR_front = std::max(ptR_front, ptR_front_min);
0455             ptR_rear = std::max(ptR_rear, ptR_rear_min);
0456           }
0457         }
0458 
0459         if ((!CLCT_pattern) && (ptR_front > 5.))
0460           ptR_front = 5.;
0461         if ((!CLCT_pattern) && (ptR_rear > 5.))
0462           ptR_rear = 5.;
0463 
0464         // Check dEta against reasonable values for high-pt muons
0465         index = 0;
0466         if (mode == 6)
0467           index = 0;
0468         if (mode == 7)
0469           index = 4;
0470         if (mode == 13)
0471           index = 8;
0472 
0473         if (usedetaCUT) {
0474           if (fabs(etaR) > 1.2 && fabs(etaR) <= 1.5)
0475             if (dEta > dEtaCut_1[index + 0]) {
0476               if (ptR_front > 5)
0477                 ptR_front = 5;
0478               if (ptR_rear > 5)
0479                 ptR_rear = 5;
0480             }
0481           if (fabs(etaR) > 1.5 && fabs(etaR) <= 1.65)
0482             if (dEta > dEtaCut_1[index + 1]) {
0483               if (ptR_front > 5)
0484                 ptR_front = 5;
0485               if (ptR_rear > 5)
0486                 ptR_rear = 5;
0487             }
0488 
0489           if (fabs(etaR) > 1.65 && fabs(etaR) <= 2.1)
0490             if (dEta > dEtaCut_1[index + 2]) {
0491               if (ptR_front > 5)
0492                 ptR_front = 5;
0493               if (ptR_rear > 5)
0494                 ptR_rear = 5;
0495             }
0496           if (fabs(etaR) > 2.1)
0497             if (dEta > dEtaCut_1[index + 3]) {
0498               if (ptR_front > 5)
0499                 ptR_front = 5;
0500               if (ptR_rear > 5)
0501                 ptR_rear = 5;
0502             }
0503         }
0504 
0505         break;
0506 
0507       case 8:
0508       case 9:
0509       case 10:
0510 
0511         // First remake the 12-bit dPhi word from the core
0512         remerged = (address.delta_phi_12 | (address.delta_phi_23 << 8));
0513         // Now get 9-bit dPhi12
0514         absPhi12 = ((1 << 9) - 1) & remerged;
0515         // Now get 3-bit dEta
0516         dEta = ((1 << 3) - 1) & (remerged >> 9);
0517 
0518         dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0519 
0520         //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
0521         ptR_front = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R, PtbyMLH, bestLH, 1, int(pt_method));
0522         ptR_rear = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R, PtbyMLH, bestLH, 0, int(pt_method));
0523 
0524         index = 0;
0525         if (mode == 8)
0526           index = 12;
0527         if (mode == 9)
0528           index = 16;
0529         if (mode == 10)
0530           index = 20;
0531 
0532         if (usedetaCUT) {
0533           if (fabs(etaR) > 1.2 && fabs(etaR) <= 1.5)
0534             if (dEta > dEtaCut_2[index + 0]) {
0535               if (ptR_front > 5)
0536                 ptR_front = 5;
0537               if (ptR_rear > 5)
0538                 ptR_rear = 5;
0539             }
0540           if (fabs(etaR) > 1.5 && fabs(etaR) <= 1.65)
0541             if (dEta > dEtaCut_2[index + 1]) {
0542               if (ptR_front > 5)
0543                 ptR_front = 5;
0544               if (ptR_rear > 5)
0545                 ptR_rear = 5;
0546             }
0547 
0548           if (fabs(etaR) > 1.65 && fabs(etaR) <= 2.1)
0549             if (dEta > dEtaCut_2[index + 2]) {
0550               if (ptR_front > 5)
0551                 ptR_front = 5;
0552               if (ptR_rear > 5)
0553                 ptR_rear = 5;
0554             }
0555           if (fabs(etaR) > 2.1)
0556             if (dEta > dEtaCut_2[index + 3]) {
0557               if (ptR_front > 5)
0558                 ptR_front = 5;
0559               if (ptR_rear > 5)
0560                 ptR_rear = 5;
0561             }
0562         }
0563 
0564         break;
0565       // for overlap DT-CSC region using curves from data 2010
0566       case 11:  // FR = 1 -> b1-1-3,     FR = 0 -> b1-3
0567       case 12:  // FR = 1 -> b1-2-3,     FR = 0 -> b1-2
0568       case 14:  // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
0569 
0570         //sign definition: sign dphi12 = Phi_DT - Phi_CSC
0571         //                 sing dphi23 = 5th sign. bit of phiBend
0572         // -> charge = 1 -> dphi12 = +, phiBend = -
0573         // -> charge = 0 -> dphi12 = +, phiBend = +
0574         charge12 = 1;
0575 
0576         // DT tracks are still using linear dPhi binning
0577         absPhi12 = address.delta_phi_12;
0578         absPhi23 = address.delta_phi_23;
0579 
0580         if (charge)
0581           charge23 = -1;
0582         else
0583           charge23 = 1;
0584 
0585         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0586         dphi23R = float(absPhi23);
0587         if (charge12 * charge23 < 0)
0588           dphi23R = -dphi23R;
0589 
0590         int mode1;
0591         mode1 = int(mode);
0592         if (fr == 1 && mode1 == 11)
0593           mode1 = 14;  // 3 station track we use dphi12 and phiBend for 2 and 3 station track
0594 
0595         ptR_front = ptMethods.Pt3Stn2012_DT(mode1, etaR, dphi12R, dphi23R, PtbyMLH, bestLH, int(0), int(pt_method));
0596         ptR_rear = ptMethods.Pt3Stn2012_DT(mode1, etaR, dphi12R, dphi23R, PtbyMLH, bestLH, int(0), int(pt_method));
0597 
0598         break;
0599       case 15:                                                     // halo trigger
0600       case 1:                                                      // tracks that fail delta phi cuts
0601         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3);  // 2 GeV
0602         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(3);
0603         break;
0604       default:                                                     // Tracks in this category are not considered muons.
0605         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0);  // 0 GeV
0606         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(0);
0607     };  // end switch
0608 
0609     front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
0610     rear_pt = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
0611 
0612   }  //end pt_methods 29
0613 
0614   //***************************************************//
0615   if (pt_method >= 23 && pt_method <= 28) {  //here we have only pt_methods greater then
0616                                              //for fw 20110118 <- 2011 data taking, curves from MC like method 4
0617     // mode definition you could find at page 6 & 7:
0618     // http://www.phys.ufl.edu/~madorsky/sp/2011-11-18/sp_core_interface.pdf
0619     // it is valid starting the beggining of 2011
0620     //std::cout << " pt_method = " << pt_method << std::endl;//test
0621     switch (mode) {
0622       case 2:
0623       case 3:
0624       case 4:
0625       case 5:
0626 
0627         charge12 = 1;
0628         absPhi12 = address.delta_phi_12;
0629         absPhi23 = address.delta_phi_23;
0630 
0631         if (charge)
0632           charge23 = 1;
0633         else
0634           charge23 = -1;
0635 
0636         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0637         dphi23R = (static_cast<float>(absPhi23 << 4)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0638         if (charge12 * charge23 < 0)
0639           dphi23R = -dphi23R;
0640 
0641         ptR_front = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12R, dphi23R, 1, int(pt_method));
0642         ptR_rear = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12R, dphi23R, 0, int(pt_method));
0643 
0644         if ((pt_method == 24 || pt_method == 26 || pt_method == 28) && mode != 5 &&
0645             etaR > 2.1)  //exclude mode without ME11a
0646         {
0647           float dphi12Rmin = dphi12R - Pi * 10 / 180 / 3;  // 10/3 degrees
0648           float dphi12Rmax = dphi12R + Pi * 10 / 180 / 3;  // 10/3 degrees
0649           float dphi23Rmin = dphi23R;
0650           float dphi23Rmax = dphi23R;
0651           //if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
0652           //if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
0653           float ptR_front_min = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
0654           float ptR_rear_min = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
0655           float ptR_front_max = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
0656           float ptR_rear_max = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
0657           // select max pt solution for 3 links:
0658           ptR_front = std::max(ptR_front, ptR_front_min);
0659           ptR_front = std::max(ptR_front, ptR_front_max);
0660           ptR_rear = std::max(ptR_rear, ptR_rear_min);
0661           ptR_rear = std::max(ptR_rear, ptR_rear_max);
0662         }
0663         break;
0664       case 6:  // for mode 6, 7 and 13 add CLCT information in dph23 bit and iME11 in charge bit
0665       case 7:
0666       case 13:  // ME1-ME4
0667         int iME11;
0668         iME11 = int(charge);  // = 0 if ME1/1, = 1 if ME1/2 or ME1/3 station
0669         if (iME11 == 1 && etaR > 1.6)
0670           etaR = 1.55;  // shift for ME1/2 station
0671         if (iME11 == 0 && etaR < 1.6)
0672           etaR = 1.65;  // shift for ME1/1 station
0673         absPhi12 = address.delta_phi_12;
0674         //int CLCT_pattern = static_cast<int>(address.delta_phi_23);
0675         int CLCT_pattern;
0676         CLCT_pattern = int(address.delta_phi_23);
0677         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0678 
0679         //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
0680         ptR_front = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 1, int(pt_method));
0681         ptR_rear = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 0, int(pt_method));
0682         if ((pt_method == 24 || pt_method == 26 || pt_method == 28) && etaR > 2.1)  //exclude tracks without ME11a
0683         {
0684           float dphi12Rmin = fabs(fabs(dphi12R) - Pi * 10 / 180 / 3);  // 10/3 degrees
0685           float ptR_front_min = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12Rmin, 1, int(pt_method));
0686           float ptR_rear_min = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12Rmin, 0, int(pt_method));
0687           // select max pt solution for 3 links:
0688           ptR_front = std::max(ptR_front, ptR_front_min);
0689           ptR_rear = std::max(ptR_rear, ptR_rear_min);
0690         }
0691         if (((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_front > 5.))
0692           ptR_front = 5.;
0693         if (((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_rear > 5.))
0694           ptR_rear = 5.;
0695         //std::cout << "mode = "<< mode << " CLCT_pattern = " << CLCT_pattern << " ptR_rear = " << ptR_rear << std::endl;
0696 
0697         break;
0698       case 8:
0699       case 9:
0700       case 10:
0701         if (charge)
0702           absPhi12 = address.delta_phi();
0703         else {
0704           int temp_phi = address.delta_phi();
0705           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
0706         }
0707 
0708         dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0709 
0710         //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
0711         ptR_front = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 1, int(pt_method));
0712         ptR_rear = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 0, int(pt_method));
0713 
0714         break;
0715       // for overlap DT-CSC region using curves from data 2010
0716       case 11:  // FR = 1 -> b1-1-3,     FR = 0 -> b1-3
0717       case 12:  // FR = 1 -> b1-2-3,     FR = 0 -> b1-2
0718       case 14:  // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
0719 
0720         //sign definition: sign dphi12 = Phi_DT - Phi_CSC
0721         //                 sing dphi23 = 5th sign. bit of phiBend
0722         // -> charge = 1 -> dphi12 = +, phiBend = -
0723         // -> charge = 0 -> dphi12 = +, phiBend = +
0724         charge12 = 1;
0725         absPhi12 = address.delta_phi_12;
0726         absPhi23 = address.delta_phi_23;
0727 
0728         if (charge)
0729           charge23 = -1;
0730         else
0731           charge23 = 1;
0732 
0733         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0734         dphi23R = float(absPhi23);
0735         if (charge12 * charge23 < 0)
0736           dphi23R = -dphi23R;
0737 
0738         int mode1;
0739         mode1 = int(mode);
0740         if (fr == 1 && mode1 == 11)
0741           mode1 = 14;  // 3 station track we use dphi12 and phiBend for 2 and 3 station track
0742 
0743         ptR_front = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
0744         ptR_rear = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
0745 
0746         break;
0747       case 15:                                                     // halo trigger
0748       case 1:                                                      // tracks that fail delta phi cuts
0749         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3);  // 2 GeV
0750         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(3);
0751         break;
0752       default:                                                     // Tracks in this category are not considered muons.
0753         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0);  // 0 GeV
0754         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(0);
0755     };  // end switch
0756 
0757     front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
0758     rear_pt = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
0759 
0760   }  //end pt_methods 23 - 28
0761 
0762   //***************************************************//
0763   //***************************************************//
0764   if (pt_method == 21 || pt_method == 22) {  //here we have only pt_methods greater then
0765                                              //for fw 20110118 <- 2011 data taking
0766     // mode definition you could find at page 6 & 7:
0767     // http://www.phys.ufl.edu/~madorsky/sp/2011-11-18/sp_core_interface.pdf
0768     // it is valid starting the beggining of 2011
0769     switch (mode) {
0770       case 2:
0771       case 3:
0772       case 4:
0773       case 5:
0774 
0775         charge12 = 1;
0776         absPhi12 = address.delta_phi_12;
0777         absPhi23 = address.delta_phi_23;
0778 
0779         if (charge)
0780           charge23 = 1;
0781         else
0782           charge23 = -1;
0783 
0784         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0785         dphi23R = (static_cast<float>(absPhi23 << 4)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0786         if (charge12 * charge23 < 0)
0787           dphi23R = -dphi23R;
0788 
0789         ptR_front = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12R, dphi23R, 1, int(pt_method));
0790         ptR_rear = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12R, dphi23R, 0, int(pt_method));
0791 
0792         if (pt_method == 22 && mode != 5 && etaR > 2.1)  //exclude mode without ME11a
0793         {
0794           float dphi12Rmin = dphi12R - Pi * 10 / 180 / 3;  // 10/3 degrees
0795           float dphi12Rmax = dphi12R + Pi * 10 / 180 / 3;  // 10/3 degrees
0796           float dphi23Rmin = dphi23R;
0797           float dphi23Rmax = dphi23R;
0798           //if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
0799           //if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
0800           float ptR_front_min = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
0801           float ptR_rear_min = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
0802           float ptR_front_max = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
0803           float ptR_rear_max = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
0804           // select max pt solution for 3 links:
0805           ptR_front = std::max(ptR_front, ptR_front_min);
0806           ptR_front = std::max(ptR_front, ptR_front_max);
0807           ptR_rear = std::max(ptR_rear, ptR_rear_min);
0808           ptR_rear = std::max(ptR_rear, ptR_rear_max);
0809         }
0810         break;
0811       case 6:  // for mode 6, 7 and 13 add CLCT information in dph23 bit and iME11 in charge bit
0812       case 7:
0813       case 13:  // ME1-ME4
0814         int iME11;
0815         iME11 = int(charge);
0816         absPhi12 = address.delta_phi_12;
0817         //int CLCT_pattern = static_cast<int>(address.delta_phi_23);
0818         int CLCT_pattern;
0819         CLCT_pattern = int(address.delta_phi_23);
0820 
0821         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0822 
0823         //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
0824         ptR_front = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 1, int(pt_method), iME11);
0825         ptR_rear = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 0, int(pt_method), iME11);
0826         if ((pt_method == 22) && etaR > 2.1)  //exclude tracks without ME11a
0827         {
0828           float dphi12Rmin = fabs(fabs(dphi12R) - Pi * 10 / 180 / 3);  // 10/3 degrees
0829           float ptR_front_min = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12Rmin, 1, int(pt_method), iME11);
0830           float ptR_rear_min = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12Rmin, 0, int(pt_method), iME11);
0831           // select max pt solution for 3 links:
0832           ptR_front = std::max(ptR_front, ptR_front_min);
0833           ptR_rear = std::max(ptR_rear, ptR_rear_min);
0834         }
0835         if (((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_front > 5.))
0836           ptR_front = 5.;
0837         if (((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_rear > 5.))
0838           ptR_rear = 5.;
0839 
0840         break;
0841       case 8:
0842       case 9:
0843       case 10:
0844         if (charge)
0845           absPhi12 = address.delta_phi();
0846         else {
0847           int temp_phi = address.delta_phi();
0848           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
0849         }
0850 
0851         dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0852 
0853         //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
0854         ptR_front = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 1, int(pt_method), int(2));
0855         ptR_rear = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 0, int(pt_method), int(2));
0856 
0857         break;
0858       case 11:  // FR = 1 -> b1-1-3,     FR = 0 -> b1-3
0859       case 12:  // FR = 1 -> b1-2-3,     FR = 0 -> b1-2
0860       case 14:  // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
0861 
0862         //sign definition: sign dphi12 = Phi_DT - Phi_CSC
0863         //                 sing dphi23 = 5th sign. bit of phiBend
0864         // -> charge = 1 -> dphi12 = +, phiBend = -
0865         // -> charge = 0 -> dphi12 = +, phiBend = +
0866         charge12 = 1;
0867         absPhi12 = address.delta_phi_12;
0868         absPhi23 = address.delta_phi_23;
0869 
0870         if (charge)
0871           charge23 = -1;
0872         else
0873           charge23 = 1;
0874 
0875         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0876         dphi23R = float(absPhi23);
0877         if (charge12 * charge23 < 0)
0878           dphi23R = -dphi23R;
0879 
0880         int mode1;
0881         mode1 = int(mode);
0882         if (fr == 1 && mode1 == 11)
0883           mode1 = 14;  // 3 station track we use dphi12 and phiBend for 2 and 3 station track
0884 
0885         ptR_front = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
0886         ptR_rear = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
0887 
0888         break;
0889       case 15:                                                     // halo trigger
0890       case 1:                                                      // tracks that fail delta phi cuts
0891         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3);  // 2 GeV
0892         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(3);
0893         break;
0894       default:                                                     // Tracks in this category are not considered muons.
0895         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0);  // 0 GeV
0896         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(0);
0897     };  // end switch
0898 
0899     front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
0900     rear_pt = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
0901 
0902   }  //end pt_methods greater or equal to 21
0903 
0904   //***************************************************//
0905   //***************************************************//
0906   if (pt_method >= 11 && pt_method < 20) {  //here we have only pt_methods greater or equal to 11
0907                                             //for fw 20101011 <- 2011 data taking
0908     // mode definition you could find at page 6 & 7:
0909     // http://www.phys.ufl.edu/~madorsky/sp/2010-10-11/sp_core_interface.pdf
0910     // it is valid starting the beggining of 2011
0911     switch (mode) {
0912       case 2:
0913       case 3:
0914       case 4:
0915       case 5:
0916 
0917         charge12 = 1;
0918         absPhi12 = address.delta_phi_12;
0919         absPhi23 = address.delta_phi_23;
0920 
0921         if (charge)
0922           charge23 = 1;
0923         else
0924           charge23 = -1;
0925 
0926         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0927         dphi23R = (static_cast<float>(absPhi23 << 4)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0928         if (charge12 * charge23 < 0)
0929           dphi23R = -dphi23R;
0930 
0931         ptR_front = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 1, int(pt_method));
0932         ptR_rear = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 0, int(pt_method));
0933 
0934         if (pt_method == 12 && mode != 5 && etaR > 2.1)  //exclude mode without ME11a
0935         {
0936           float dphi12Rmin = dphi12R - Pi * 10 / 180 / 3;  // 10/3 degrees
0937           float dphi12Rmax = dphi12R + Pi * 10 / 180 / 3;  // 10/3 degrees
0938           float dphi23Rmin = dphi23R;
0939           float dphi23Rmax = dphi23R;
0940           if (dphi12Rmin * dphi12R < 0)
0941             dphi23Rmin = -dphi23R;
0942           if (dphi12Rmax * dphi12R < 0)
0943             dphi23Rmax = -dphi23R;
0944           float ptR_front_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
0945           float ptR_rear_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
0946           float ptR_front_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
0947           float ptR_rear_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
0948           // select max pt solution for 3 links:
0949           ptR_front = std::max(ptR_front, ptR_front_min);
0950           ptR_front = std::max(ptR_front, ptR_front_max);
0951           ptR_rear = std::max(ptR_rear, ptR_rear_min);
0952           ptR_rear = std::max(ptR_rear, ptR_rear_max);
0953         }
0954         break;
0955       case 6:
0956       case 7:
0957       case 8:
0958       case 9:
0959       case 10:
0960       case 13:  // ME1-ME4
0961 
0962         if (charge)
0963           absPhi12 = address.delta_phi();
0964         else {
0965           int temp_phi = address.delta_phi();
0966           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
0967         }
0968 
0969         dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0970 
0971         //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
0972         ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
0973         ptR_rear = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
0974         if ((pt_method == 12) && etaR > 2.1 && mode != 8 && mode != 9 && mode != 10)  //exclude tracks without ME11a
0975         {
0976           float dphi12Rmin = fabs(fabs(dphi12R) - Pi * 10 / 180 / 3);  // 10/3 degrees
0977           float ptR_front_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 1, int(pt_method));
0978           float ptR_rear_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 0, int(pt_method));
0979           // select max pt solution for 3 links:
0980           ptR_front = std::max(ptR_front, ptR_front_min);
0981           ptR_rear = std::max(ptR_rear, ptR_rear_min);
0982         }
0983 
0984         break;
0985       case 11:  // FR = 1 -> b1-1-3,     FR = 0 -> b1-3
0986       case 12:  // FR = 1 -> b1-2-3,     FR = 0 -> b1-2
0987       case 14:  // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
0988 
0989         if (fr == 0) {  // 2 station track
0990           if (charge)
0991             absPhi12 = address.delta_phi();
0992           else {
0993             int temp_phi = address.delta_phi();
0994             absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
0995           }
0996           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0997           ptR_rear = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
0998 
0999         }               // end fr == 0
1000         if (fr == 1) {  // 3 station track
1001           charge12 = 1;
1002           absPhi12 = address.delta_phi_12;
1003           absPhi23 = address.delta_phi_23;
1004 
1005           if (charge)
1006             charge23 = 1;
1007           else
1008             charge23 = -1;
1009 
1010           dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1011           dphi23R = (static_cast<float>(absPhi23 << 4)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1012           if (charge12 * charge23 < 0)
1013             dphi23R = -dphi23R;
1014 
1015           ptR_front = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 1, int(pt_method));
1016 
1017           if (pt_method == 12 && mode != 5 && etaR > 2.1)  //exclude mode without ME11a
1018           {
1019             float dphi12Rmin = dphi12R - Pi * 10 / 180 / 3;  // 10/3 degrees
1020             float dphi12Rmax = dphi12R + Pi * 10 / 180 / 3;  // 10/3 degrees
1021             float dphi23Rmin = dphi23R;
1022             float dphi23Rmax = dphi23R;
1023             if (dphi12Rmin * dphi12R < 0)
1024               dphi23Rmin = -dphi23R;
1025             if (dphi12Rmax * dphi12R < 0)
1026               dphi23Rmax = -dphi23R;
1027             float ptR_front_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
1028             float ptR_front_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
1029             // select max pt solution for 3 links:
1030             ptR_front = std::max(ptR_front, ptR_front_min);
1031             ptR_front = std::max(ptR_front, ptR_front_max);
1032           }
1033         }  // end fr == 1
1034 
1035         break;
1036       case 15:                                                     // halo trigger
1037       case 1:                                                      // tracks that fail delta phi cuts
1038         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3);  // 2 GeV
1039         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(3);
1040         break;
1041       default:                                                     // Tracks in this category are not considered muons.
1042         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0);  // 0 GeV
1043         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(0);
1044     };  // end switch
1045 
1046     front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
1047     rear_pt = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
1048 
1049   }                      //end pt_methods greater or equal to 11
1050                          //***************************************************//
1051   if (pt_method <= 5) {  //here we have only pt_methods less or equal to 5
1052     // mode definition you could find at https://twiki.cern.ch/twiki/pub/Main/PtLUTs/mode_codes.xls
1053     // it is valid till the end 2010
1054     unsigned type;
1055 
1056     //  kluge to use 2-stn track in overlap region
1057     //  see also where this routine is called, and encode LUTaddress, and assignPT
1058     if (pt_method != 4 && pt_method != 5 && (mode == 2 || mode == 3 || mode == 4) && (eta < 3))
1059       mode = 6;
1060     if (pt_method != 4 && pt_method != 5 && (mode == 5) && (eta < 3))
1061       mode = 8;
1062 
1063     switch (mode) {
1064       case 2:
1065       case 3:
1066       case 4:
1067       case 5:
1068         type = mode - 1;
1069         charge12 = 1;
1070         absPhi12 = address.delta_phi_12;
1071         absPhi23 = address.delta_phi_23;
1072 
1073         if (charge)
1074           charge23 = 1;
1075         else
1076           charge23 = -1;
1077 
1078         // now convert to real numbers for input into PT assignment algos.
1079 
1080         if (pt_method == 4 || pt_method == 5)  // param method 2010
1081         {
1082           dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1083           dphi23R = (static_cast<float>(absPhi23 << 4)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1084           if (charge12 * charge23 < 0)
1085             dphi23R = -dphi23R;
1086 
1087           ptR_front = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 1, int(pt_method));
1088           ptR_rear = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 0, int(pt_method));
1089 
1090           if (pt_method == 5 && mode != 5 && etaR > 2.1)  //exclude mode without ME11a
1091           {
1092             float dphi12Rmin = dphi12R - Pi * 10 / 180 / 3;  // 10/3 degrees
1093             float dphi12Rmax = dphi12R + Pi * 10 / 180 / 3;  // 10/3 degrees
1094             float dphi23Rmin = dphi23R;
1095             float dphi23Rmax = dphi23R;
1096             if (dphi12Rmin * dphi12R < 0)
1097               dphi23Rmin = -dphi23R;
1098             if (dphi12Rmax * dphi12R < 0)
1099               dphi23Rmax = -dphi23R;
1100             float ptR_front_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
1101             float ptR_rear_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
1102             float ptR_front_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
1103             float ptR_rear_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
1104             // select max pt solution for 3 links:
1105             ptR_front = std::max(ptR_front, ptR_front_min);
1106             ptR_front = std::max(ptR_front, ptR_front_max);
1107             ptR_rear = std::max(ptR_rear, ptR_rear_min);
1108             ptR_rear = std::max(ptR_rear, ptR_rear_max);
1109           }
1110         } else if (pt_method == 1)  // param method
1111         {
1112           dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1113           dphi23R = (static_cast<float>(absPhi23 << 4)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1114           if (charge12 * charge23 < 0)
1115             dphi23R = -dphi23R;
1116 
1117           ptR_front = ptMethods.Pt3Stn(type, etaR, dphi12R, dphi23R, 1);
1118           ptR_rear = ptMethods.Pt3Stn(type, etaR, dphi12R, dphi23R, 0);
1119 
1120         } else if (pt_method == 2)  // cathy's method
1121         {
1122           if (type <= 2) {
1123             ptR_front = ptMethods.Pt3StnChiSq(
1124                 type + 3, etaR, absPhi12 << 1, ((charge == 0) ? -(absPhi23 << 4) : (absPhi23 << 4)), 1);
1125             ptR_rear = ptMethods.Pt3StnChiSq(
1126                 type + 3, etaR, absPhi12 << 1, ((charge == 0) ? -(absPhi23 << 4) : (absPhi23 << 4)), 0);
1127           } else {
1128             ptR_front = ptMethods.Pt2StnChiSq(type - 2, etaR, absPhi12 << 1, 1);
1129             ptR_rear = ptMethods.Pt2StnChiSq(type - 2, etaR, absPhi12 << 1, 0);
1130           }
1131 
1132         } else  // hybrid
1133         {
1134           if (type <= 2) {
1135             ptR_front = ptMethods.Pt3StnHybrid(
1136                 type + 3, etaR, absPhi12 << 1, ((charge == 0) ? -(absPhi23 << 4) : (absPhi23 << 4)), 1);
1137             ptR_rear = ptMethods.Pt3StnHybrid(
1138                 type + 3, etaR, absPhi12 << 1, ((charge == 0) ? -(absPhi23 << 4) : (absPhi23 << 4)), 0);
1139           } else {
1140             ptR_front = ptMethods.Pt2StnHybrid(type - 2, etaR, absPhi12 << 1, 1);
1141             ptR_rear = ptMethods.Pt2StnHybrid(type - 2, etaR, absPhi12 << 1, 0);
1142           }
1143         }
1144         break;
1145       case 6:
1146       case 7:
1147       case 8:
1148       case 9:
1149       case 10:
1150         type = mode - 5;
1151 
1152         if (charge)
1153           absPhi12 = address.delta_phi();
1154         else {
1155           int temp_phi = address.delta_phi();
1156           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
1157         }
1158 
1159         if (absPhi12 < (1 << 9)) {
1160           if (pt_method == 1 || type == 5) {
1161             dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1162 
1163             ptR_front = ptMethods.Pt2Stn(type, etaR, dphi12R, 1);
1164             ptR_rear = ptMethods.Pt2Stn(type, etaR, dphi12R, 0);
1165 
1166           } else if (pt_method == 2) {
1167             ptR_front = ptMethods.Pt2StnChiSq(type - 1, etaR, absPhi12, 1);
1168             ptR_rear = ptMethods.Pt2StnChiSq(type - 1, etaR, absPhi12, 0);
1169           } else {
1170             ptR_front = ptMethods.Pt2StnHybrid(type - 1, etaR, absPhi12, 1);
1171             ptR_rear = ptMethods.Pt2StnHybrid(type - 1, etaR, absPhi12, 0);
1172           }
1173         } else {
1174           ptR_front = trigger_ptscale->getPtScale()->getLowEdge(1);
1175           ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(1);
1176         }
1177         if (pt_method == 4 || pt_method == 5)  // param method 2010
1178         {
1179           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1180 
1181           //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
1182           ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
1183           ptR_rear = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
1184           if ((pt_method == 5) && etaR > 2.1 && mode != 8 && mode != 9 && mode != 10)  //exclude tracks without ME11a
1185           {
1186             float dphi12Rmin = fabs(fabs(dphi12R) - Pi * 10 / 180 / 3);  // 10/3 degrees
1187             float ptR_front_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 1, int(pt_method));
1188             float ptR_rear_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 0, int(pt_method));
1189             // select max pt solution for 3 links:
1190             ptR_front = std::max(ptR_front, ptR_front_min);
1191             ptR_rear = std::max(ptR_rear, ptR_rear_min);
1192           }
1193         }
1194 
1195         break;
1196       case 12:  // 1-2-b1 calculated only delta_phi12 = 2-b1
1197       case 14:
1198         type = 2;
1199 
1200         if (charge)
1201           absPhi12 = address.delta_phi();
1202         else {
1203           int temp_phi = address.delta_phi();
1204           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
1205         }
1206         if (absPhi12 < (1 << 9)) {
1207           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1208           ptR_front = ptMethods.Pt2Stn(type, etaR, dphi12R, 1);
1209           ptR_rear = ptMethods.Pt2Stn(type, etaR, dphi12R, 0);
1210         } else {
1211           ptR_front = trigger_ptscale->getPtScale()->getLowEdge(1);
1212           ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(1);
1213         }
1214         if (pt_method == 4 || pt_method == 5)  // param method 2010
1215         {
1216           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1217 
1218           ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
1219           ptR_rear = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
1220 
1221           if (fabs(dphi12R) < 0.01 && (ptR_rear < 10 || ptR_front < 10))
1222             std::cout << "dphi12R = " << dphi12R << " ptR_rear = " << ptR_rear << " ptR_front = " << ptR_front
1223                       << " etaR = " << etaR << " mode = " << mode << std::endl;
1224         }
1225         break;
1226       case 13:
1227         type = 4;
1228 
1229         if (charge)
1230           absPhi12 = address.delta_phi();
1231         else {
1232           int temp_phi = address.delta_phi();
1233           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
1234         }
1235         if (absPhi12 < (1 << 9)) {
1236           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1237           ptR_front = ptMethods.Pt2Stn(type, etaR, dphi12R, 1);
1238           ptR_rear = ptMethods.Pt2Stn(type, etaR, dphi12R, 0);
1239         } else {
1240           ptR_front = trigger_ptscale->getPtScale()->getLowEdge(1);
1241           ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(1);
1242         }
1243 
1244         if (pt_method == 4 || pt_method == 5)  // param method 2010
1245         {
1246           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1247 
1248           ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
1249           ptR_rear = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
1250           if ((pt_method == 5) && etaR > 2.1)  //mode = 13: ME1-ME4 exclude tracks without ME11a
1251           {
1252             float dphi12Rmin = fabs(fabs(dphi12R) - Pi * 10 / 180 / 3);  // 10/3 degrees
1253             float ptR_front_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 1, int(pt_method));
1254             float ptR_rear_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 0, int(pt_method));
1255             // select max pt solution for 3 links:
1256             ptR_front = std::max(ptR_front, ptR_front_min);
1257             ptR_rear = std::max(ptR_rear, ptR_rear_min);
1258           }
1259         }
1260 
1261         break;
1262       case 11:
1263         // singles trigger
1264         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(5);
1265         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(5);
1266         //ptR_front = trigger_ptscale->getPtScale()->getLowEdge(31);
1267         //ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(31);
1268         break;
1269       case 15:
1270         // halo trigger
1271         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(5);
1272         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(5);
1273         break;
1274       case 1:
1275         // tracks that fail delta phi cuts
1276         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(5);
1277         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(5);
1278         break;
1279       default:  // Tracks in this category are not considered muons.
1280         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0);
1281         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(0);
1282     };
1283 
1284     front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
1285     rear_pt = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
1286 
1287     // kluge to set arbitrary Pt for some tracks with lousy resolution (and no param)
1288     if (pt_method != 4 && pt_method != 5) {
1289       if ((front_pt == 0 || front_pt == 1) && (eta < 3) && quality == 1 && pt_method != 2)
1290         front_pt = 31;
1291       if ((rear_pt == 0 || rear_pt == 1) && (eta < 3) && quality == 1 && pt_method != 2)
1292         rear_pt = 31;
1293     }
1294     if (pt_method != 2 && pt_method != 4 && quality == 1) {
1295       if (front_pt < 5)
1296         front_pt = 5;
1297       if (rear_pt < 5)
1298         rear_pt = 5;
1299     }
1300 
1301     // in order to match the pt assignement of the previous routine
1302     if (isBeamStartConf && pt_method != 2 && pt_method != 4 && pt_method != 5) {
1303       if (quality == 3 && mode == 5) {
1304         if (front_pt < 5)
1305           front_pt = 5;
1306         if (rear_pt < 5)
1307           rear_pt = 5;
1308       }
1309 
1310       if (quality == 2 && mode > 7 && mode < 11) {
1311         if (front_pt < 5)
1312           front_pt = 5;
1313         if (rear_pt < 5)
1314           rear_pt = 5;
1315       }
1316     }
1317 
1318   }  // end if for pt_method less or equal to 5
1319      //***************************************************//
1320 
1321   result.front_rank = front_pt | front_quality << 5;
1322   result.rear_rank = rear_pt | rear_quality << 5;
1323 
1324   result.charge_valid_front = 1;  //ptMethods.chargeValid(front_pt, quality, eta, pt_method);
1325   result.charge_valid_rear = 1;   //ptMethods.chargeValid(rear_pt, quality, eta, pt_method);
1326 
1327   /*  if (mode == 1) { 
1328     std::cout << "F_pt: "      << front_pt      << std::endl;
1329     std::cout << "R_pt: "      << rear_pt       << std::endl;
1330     std::cout << "F_quality: " << front_quality << std::endl;
1331     std::cout << "R_quality: " << rear_quality  << std::endl;
1332     std::cout << "F_rank: " << std::hex << result.front_rank << std::endl;
1333     std::cout << "R_rank: " << std::hex << result.rear_rank  << std::endl;
1334   }
1335   */
1336   return result;
1337 }
1338 
1339 unsigned CSCTFPtLUT::trackQuality(const unsigned& eta, const unsigned& mode, const unsigned& fr) const {
1340   // eta and mode should be only 4-bits, since that is the input to the large LUT
1341   if (eta > 15 || mode > 15) {
1342     //std::cout << "Error: Eta or Mode out of range in AU quality assignment" << std::endl;
1343     edm::LogError("CSCTFPtLUT::trackQuality()") << "Eta or Mode out of range in AU quality assignment";
1344     return 0;
1345   }
1346   unsigned int quality;
1347   switch (mode) {
1348     case 2:
1349       quality = 3;
1350       if (pt_method > 10 && eta < 3)
1351         quality = 1;  //eta < 1.2
1352       if (pt_method == 32 && eta >= 12)
1353         quality = 2;  // eta > 2.1
1354       break;
1355     case 3:
1356     case 4:
1357       /// DEA try increasing quality
1358       //        quality = 2;
1359       quality = 3;
1360       if (pt_method == 32 && eta >= 12)
1361         quality = 2;  // eta > 2.1
1362       break;
1363     case 5:
1364       quality = 1;
1365       if (isBeamStartConf && eta >= 12 && pt_method < 20)  // eta > 2.1
1366         quality = 3;
1367       if (pt_method == 27 || pt_method == 28 || pt_method == 29 || pt_method == 32 || pt_method == 30 ||
1368           pt_method == 33 || pt_method == 34)
1369         quality = 3;  // all mode = 5 set to quality 3 due to a lot dead ME1/1a stations
1370       break;
1371     case 6:
1372       if (eta >= 3)  // eta > 1.2
1373         quality = 2;
1374       else
1375         quality = 1;
1376       if (pt_method == 32 && eta >= 12)
1377         quality = 1;  // eta > 2.1
1378       break;
1379     case 7:
1380       quality = 2;
1381       if (pt_method > 10 && eta < 3)
1382         quality = 1;  //eta < 1.2
1383       if (pt_method == 32 && eta >= 12)
1384         quality = 1;  // eta > 2.1
1385       break;
1386     case 8:
1387     case 9:
1388     case 10:
1389       quality = 1;
1390       if (isBeamStartConf && eta >= 12 && pt_method < 20)  // eta > 2.1
1391         quality = 2;
1392       if ((pt_method == 27 || pt_method == 28 || pt_method == 30) && (eta >= 7 && eta < 9))
1393         quality = 2;  //set to quality 2 for eta = 1.6-1.8 due to a lot dead ME1/1a stations
1394       break;
1395     case 11:
1396       // single LCTs
1397       quality = 1;
1398       // overlap region
1399       if (pt_method > 10 && fr == 0)
1400         quality = 2;
1401       if (pt_method > 10 && fr == 1)
1402         quality = 3;
1403       if (pt_method > 20 && fr == 0)
1404         quality = 3;
1405       break;
1406     case 12:
1407       quality = 3;
1408       // overlap region
1409       if (pt_method > 10 && fr == 0)
1410         quality = 2;
1411       if (pt_method > 10 && fr == 1)
1412         quality = 3;
1413       if (pt_method > 20 && fr == 0)
1414         quality = 3;
1415       break;
1416     case 13:
1417       quality = 2;
1418       if (pt_method == 32 && eta >= 12)
1419         quality = 1;  // eta > 2.1
1420       break;
1421     case 14:
1422       quality = 2;
1423       // overlap region
1424       if (pt_method > 10 && fr == 0)
1425         quality = 2;
1426       if (pt_method > 10 && fr == 1)
1427         quality = 3;
1428       if (pt_method > 20 && fr == 0)
1429         quality = 3;
1430       break;
1431     case 15:
1432       // halo triggers
1433       quality = 1;
1434       break;
1435       //DEA: keep muons that fail delta phi cut
1436     case 1:
1437       quality = 1;
1438       break;
1439     default:
1440       quality = 0;
1441       break;
1442   }
1443 
1444   // allow quality = 1 only in overlap region or eta = 1.6 region
1445   //    if ((quality == 1) && (eta >= 4) && (eta != 6) && (eta != 7)) quality = 0;
1446   //    if ( (quality == 1) && (eta >= 4) ) quality = 0;
1447 
1448   if ((quality == 1) && (eta >= 4) && (eta < 11) && ((lowQualityFlag & 4) == 0))
1449     quality = 0;
1450   if ((quality == 1) && (eta < 4) && ((lowQualityFlag & 1) == 0) && ((lowQualityFlag & 4) == 0))
1451     quality = 0;
1452   if ((quality == 1) && (eta >= 11) && ((lowQualityFlag & 2) == 0) && ((lowQualityFlag & 4) == 0))
1453     quality = 0;
1454 
1455   return quality;
1456 }
1457 
1458 void CSCTFPtLUT::readLUT() {
1459   std::ifstream PtLUT;
1460 
1461   if (isBinary) {
1462     PtLUT.open(pt_lut_file.fullPath().c_str(), std::ios::binary);
1463     PtLUT.seekg(0, std::ios::end);
1464     int length = PtLUT.tellg();
1465     ;
1466     if (length == (1 << CSCBitWidths::kPtAddressWidth) * sizeof(short)) {
1467       PtLUT.seekg(0, std::ios::beg);
1468       PtLUT.read(reinterpret_cast<char*>(pt_lut), length);
1469     } else {
1470       edm::LogError("CSCPtLUT") << "File " << pt_lut_file.fullPath() << " is incorrect size!\n";
1471     }
1472     PtLUT.close();
1473   } else {
1474     PtLUT.open(pt_lut_file.fullPath().c_str());
1475     unsigned i = 0;
1476     unsigned short temp = 0;
1477     while (!PtLUT.eof() && i < 1 << CSCBitWidths::kPtAddressWidth) {
1478       PtLUT >> temp;
1479       pt_lut[i++] = temp;
1480     }
1481     PtLUT.close();
1482   }
1483 }