Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-11 03:31:20

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 3-bit dEta
0413         dEta = ((1 << 3) - 1) & (remerged >> 8);
0414         // New get CLCT bit. CLCT = true if CLCTPattern = 8, 9, or 10, else 0.
0415         CLCT_pattern = 0x1 & (remerged >> 11);
0416 
0417         iME11 = int(charge);  // = 0 if ME1/1, = 1 if ME1/2 or ME1/3 station
0418         if (iME11 == 1 && etaR > 1.6)
0419           etaR = 1.55;  // shift for ME1/2 station
0420         if (iME11 == 0 && etaR < 1.6)
0421           etaR = 1.65;  // shift for ME1/1 station
0422 
0423         // Get the 8-bit dPhi bin number
0424         absPhi12 = ((1 << 8) - 1) & address.delta_phi_12;
0425 
0426         // Now get the corresponding dPhi value in our phi-units using the inverse dPhi LUTs
0427         absPhi12 = dPhiNLBMap_8bit[absPhi12];
0428 
0429         //int CLCT_pattern = static_cast<int>(address.delta_phi_23);
0430 
0431         dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0432 
0433         //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
0434         ptR_front = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R, PtbyMLH, bestLH, 1, int(pt_method));
0435         bestLH_front = bestLH;
0436         ptR_rear = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R, PtbyMLH, bestLH, 0, int(pt_method));
0437         bestLH_rear = bestLH;
0438         if ((pt_method == 29 || pt_method == 32 || pt_method == 30 || pt_method == 31) &&
0439             etaR > 2.1)  //exclude tracks without ME11a
0440         {
0441           float dphi12Rmin = fabs(fabs(dphi12R) - Pi * 10 / 180 / 3);  // 10/3 degrees
0442           float ptR_front_min = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12Rmin, PtbyMLH, bestLH, 1, int(pt_method));
0443           float bestLH_front_min = bestLH;
0444           float ptR_rear_min = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12Rmin, PtbyMLH, bestLH, 0, int(pt_method));
0445           float bestLH_rear_min = bestLH;
0446 
0447           if (PtbyMLH) {
0448             ptR_front = bestLH_front > bestLH_front_min ? ptR_front : ptR_front_min;
0449             ptR_rear = bestLH_rear > bestLH_rear_min ? ptR_rear : ptR_rear_min;
0450           } else {
0451             // select max pt solution for 3 links:
0452             ptR_front = std::max(ptR_front, ptR_front_min);
0453             ptR_rear = std::max(ptR_rear, ptR_rear_min);
0454           }
0455         }
0456 
0457         if ((!CLCT_pattern) && (ptR_front > 5.))
0458           ptR_front = 5.;
0459         if ((!CLCT_pattern) && (ptR_rear > 5.))
0460           ptR_rear = 5.;
0461 
0462         // Check dEta against reasonable values for high-pt muons
0463         index = 0;
0464         if (mode == 6)
0465           index = 0;
0466         if (mode == 7)
0467           index = 4;
0468         if (mode == 13)
0469           index = 8;
0470 
0471         if (usedetaCUT) {
0472           if (fabs(etaR) > 1.2 && fabs(etaR) <= 1.5)
0473             if (dEta > dEtaCut_1[index + 0]) {
0474               if (ptR_front > 5)
0475                 ptR_front = 5;
0476               if (ptR_rear > 5)
0477                 ptR_rear = 5;
0478             }
0479           if (fabs(etaR) > 1.5 && fabs(etaR) <= 1.65)
0480             if (dEta > dEtaCut_1[index + 1]) {
0481               if (ptR_front > 5)
0482                 ptR_front = 5;
0483               if (ptR_rear > 5)
0484                 ptR_rear = 5;
0485             }
0486 
0487           if (fabs(etaR) > 1.65 && fabs(etaR) <= 2.1)
0488             if (dEta > dEtaCut_1[index + 2]) {
0489               if (ptR_front > 5)
0490                 ptR_front = 5;
0491               if (ptR_rear > 5)
0492                 ptR_rear = 5;
0493             }
0494           if (fabs(etaR) > 2.1)
0495             if (dEta > dEtaCut_1[index + 3]) {
0496               if (ptR_front > 5)
0497                 ptR_front = 5;
0498               if (ptR_rear > 5)
0499                 ptR_rear = 5;
0500             }
0501         }
0502 
0503         break;
0504 
0505       case 8:
0506       case 9:
0507       case 10:
0508 
0509         // First remake the 12-bit dPhi word from the core
0510         remerged = (address.delta_phi_12 | (address.delta_phi_23 << 8));
0511         // Now get 9-bit dPhi12
0512         absPhi12 = ((1 << 9) - 1) & remerged;
0513         // Now get 3-bit dEta
0514         dEta = ((1 << 3) - 1) & (remerged >> 9);
0515 
0516         dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0517 
0518         //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
0519         ptR_front = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R, PtbyMLH, bestLH, 1, int(pt_method));
0520         ptR_rear = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R, PtbyMLH, bestLH, 0, int(pt_method));
0521 
0522         index = 0;
0523         if (mode == 8)
0524           index = 12;
0525         if (mode == 9)
0526           index = 16;
0527         if (mode == 10)
0528           index = 20;
0529 
0530         if (usedetaCUT) {
0531           if (fabs(etaR) > 1.2 && fabs(etaR) <= 1.5)
0532             if (dEta > dEtaCut_2[index + 0]) {
0533               if (ptR_front > 5)
0534                 ptR_front = 5;
0535               if (ptR_rear > 5)
0536                 ptR_rear = 5;
0537             }
0538           if (fabs(etaR) > 1.5 && fabs(etaR) <= 1.65)
0539             if (dEta > dEtaCut_2[index + 1]) {
0540               if (ptR_front > 5)
0541                 ptR_front = 5;
0542               if (ptR_rear > 5)
0543                 ptR_rear = 5;
0544             }
0545 
0546           if (fabs(etaR) > 1.65 && fabs(etaR) <= 2.1)
0547             if (dEta > dEtaCut_2[index + 2]) {
0548               if (ptR_front > 5)
0549                 ptR_front = 5;
0550               if (ptR_rear > 5)
0551                 ptR_rear = 5;
0552             }
0553           if (fabs(etaR) > 2.1)
0554             if (dEta > dEtaCut_2[index + 3]) {
0555               if (ptR_front > 5)
0556                 ptR_front = 5;
0557               if (ptR_rear > 5)
0558                 ptR_rear = 5;
0559             }
0560         }
0561 
0562         break;
0563       // for overlap DT-CSC region using curves from data 2010
0564       case 11:  // FR = 1 -> b1-1-3,     FR = 0 -> b1-3
0565       case 12:  // FR = 1 -> b1-2-3,     FR = 0 -> b1-2
0566       case 14:  // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
0567 
0568         //sign definition: sign dphi12 = Phi_DT - Phi_CSC
0569         //                 sing dphi23 = 5th sign. bit of phiBend
0570         // -> charge = 1 -> dphi12 = +, phiBend = -
0571         // -> charge = 0 -> dphi12 = +, phiBend = +
0572         charge12 = 1;
0573 
0574         // DT tracks are still using linear dPhi binning
0575         absPhi12 = address.delta_phi_12;
0576         absPhi23 = address.delta_phi_23;
0577 
0578         if (charge)
0579           charge23 = -1;
0580         else
0581           charge23 = 1;
0582 
0583         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0584         dphi23R = float(absPhi23);
0585         if (charge12 * charge23 < 0)
0586           dphi23R = -dphi23R;
0587 
0588         int mode1;
0589         mode1 = int(mode);
0590         if (fr == 1 && mode1 == 11)
0591           mode1 = 14;  // 3 station track we use dphi12 and phiBend for 2 and 3 station track
0592 
0593         ptR_front = ptMethods.Pt3Stn2012_DT(mode1, etaR, dphi12R, dphi23R, PtbyMLH, bestLH, int(0), int(pt_method));
0594         ptR_rear = ptMethods.Pt3Stn2012_DT(mode1, etaR, dphi12R, dphi23R, PtbyMLH, bestLH, int(0), int(pt_method));
0595 
0596         break;
0597       case 15:                                                     // halo trigger
0598       case 1:                                                      // tracks that fail delta phi cuts
0599         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3);  // 2 GeV
0600         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(3);
0601         break;
0602       default:                                                     // Tracks in this category are not considered muons.
0603         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0);  // 0 GeV
0604         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(0);
0605     };  // end switch
0606 
0607     front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
0608     rear_pt = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
0609 
0610   }  //end pt_methods 29
0611 
0612   //***************************************************//
0613   if (pt_method >= 23 && pt_method <= 28) {  //here we have only pt_methods greater then
0614                                              //for fw 20110118 <- 2011 data taking, curves from MC like method 4
0615     // mode definition you could find at page 6 & 7:
0616     // http://www.phys.ufl.edu/~madorsky/sp/2011-11-18/sp_core_interface.pdf
0617     // it is valid starting the beggining of 2011
0618     //std::cout << " pt_method = " << pt_method << std::endl;//test
0619     switch (mode) {
0620       case 2:
0621       case 3:
0622       case 4:
0623       case 5:
0624 
0625         charge12 = 1;
0626         absPhi12 = address.delta_phi_12;
0627         absPhi23 = address.delta_phi_23;
0628 
0629         if (charge)
0630           charge23 = 1;
0631         else
0632           charge23 = -1;
0633 
0634         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0635         dphi23R = (static_cast<float>(absPhi23 << 4)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0636         if (charge12 * charge23 < 0)
0637           dphi23R = -dphi23R;
0638 
0639         ptR_front = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12R, dphi23R, 1, int(pt_method));
0640         ptR_rear = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12R, dphi23R, 0, int(pt_method));
0641 
0642         if ((pt_method == 24 || pt_method == 26 || pt_method == 28) && mode != 5 &&
0643             etaR > 2.1)  //exclude mode without ME11a
0644         {
0645           float dphi12Rmin = dphi12R - Pi * 10 / 180 / 3;  // 10/3 degrees
0646           float dphi12Rmax = dphi12R + Pi * 10 / 180 / 3;  // 10/3 degrees
0647           float dphi23Rmin = dphi23R;
0648           float dphi23Rmax = dphi23R;
0649           //if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
0650           //if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
0651           float ptR_front_min = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
0652           float ptR_rear_min = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
0653           float ptR_front_max = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
0654           float ptR_rear_max = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
0655           // select max pt solution for 3 links:
0656           ptR_front = std::max(ptR_front, ptR_front_min);
0657           ptR_front = std::max(ptR_front, ptR_front_max);
0658           ptR_rear = std::max(ptR_rear, ptR_rear_min);
0659           ptR_rear = std::max(ptR_rear, ptR_rear_max);
0660         }
0661         break;
0662       case 6:  // for mode 6, 7 and 13 add CLCT information in dph23 bit and iME11 in charge bit
0663       case 7:
0664       case 13:  // ME1-ME4
0665         int iME11;
0666         iME11 = int(charge);  // = 0 if ME1/1, = 1 if ME1/2 or ME1/3 station
0667         if (iME11 == 1 && etaR > 1.6)
0668           etaR = 1.55;  // shift for ME1/2 station
0669         if (iME11 == 0 && etaR < 1.6)
0670           etaR = 1.65;  // shift for ME1/1 station
0671         absPhi12 = address.delta_phi_12;
0672         //int CLCT_pattern = static_cast<int>(address.delta_phi_23);
0673         int CLCT_pattern;
0674         CLCT_pattern = int(address.delta_phi_23);
0675         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0676 
0677         //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
0678         ptR_front = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 1, int(pt_method));
0679         ptR_rear = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 0, int(pt_method));
0680         if ((pt_method == 24 || pt_method == 26 || pt_method == 28) && etaR > 2.1)  //exclude tracks without ME11a
0681         {
0682           float dphi12Rmin = fabs(fabs(dphi12R) - Pi * 10 / 180 / 3);  // 10/3 degrees
0683           float ptR_front_min = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12Rmin, 1, int(pt_method));
0684           float ptR_rear_min = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12Rmin, 0, int(pt_method));
0685           // select max pt solution for 3 links:
0686           ptR_front = std::max(ptR_front, ptR_front_min);
0687           ptR_rear = std::max(ptR_rear, ptR_rear_min);
0688         }
0689         if (((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_front > 5.))
0690           ptR_front = 5.;
0691         if (((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_rear > 5.))
0692           ptR_rear = 5.;
0693         //std::cout << "mode = "<< mode << " CLCT_pattern = " << CLCT_pattern << " ptR_rear = " << ptR_rear << std::endl;
0694 
0695         break;
0696       case 8:
0697       case 9:
0698       case 10:
0699         if (charge)
0700           absPhi12 = address.delta_phi();
0701         else {
0702           int temp_phi = address.delta_phi();
0703           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
0704         }
0705 
0706         dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0707 
0708         //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
0709         ptR_front = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 1, int(pt_method));
0710         ptR_rear = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 0, int(pt_method));
0711 
0712         break;
0713       // for overlap DT-CSC region using curves from data 2010
0714       case 11:  // FR = 1 -> b1-1-3,     FR = 0 -> b1-3
0715       case 12:  // FR = 1 -> b1-2-3,     FR = 0 -> b1-2
0716       case 14:  // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
0717 
0718         //sign definition: sign dphi12 = Phi_DT - Phi_CSC
0719         //                 sing dphi23 = 5th sign. bit of phiBend
0720         // -> charge = 1 -> dphi12 = +, phiBend = -
0721         // -> charge = 0 -> dphi12 = +, phiBend = +
0722         charge12 = 1;
0723         absPhi12 = address.delta_phi_12;
0724         absPhi23 = address.delta_phi_23;
0725 
0726         if (charge)
0727           charge23 = -1;
0728         else
0729           charge23 = 1;
0730 
0731         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0732         dphi23R = float(absPhi23);
0733         if (charge12 * charge23 < 0)
0734           dphi23R = -dphi23R;
0735 
0736         int mode1;
0737         mode1 = int(mode);
0738         if (fr == 1 && mode1 == 11)
0739           mode1 = 14;  // 3 station track we use dphi12 and phiBend for 2 and 3 station track
0740 
0741         ptR_front = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
0742         ptR_rear = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
0743 
0744         break;
0745       case 15:                                                     // halo trigger
0746       case 1:                                                      // tracks that fail delta phi cuts
0747         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3);  // 2 GeV
0748         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(3);
0749         break;
0750       default:                                                     // Tracks in this category are not considered muons.
0751         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0);  // 0 GeV
0752         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(0);
0753     };  // end switch
0754 
0755     front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
0756     rear_pt = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
0757 
0758   }  //end pt_methods 23 - 28
0759 
0760   //***************************************************//
0761   //***************************************************//
0762   if (pt_method == 21 || pt_method == 22) {  //here we have only pt_methods greater then
0763                                              //for fw 20110118 <- 2011 data taking
0764     // mode definition you could find at page 6 & 7:
0765     // http://www.phys.ufl.edu/~madorsky/sp/2011-11-18/sp_core_interface.pdf
0766     // it is valid starting the beggining of 2011
0767     switch (mode) {
0768       case 2:
0769       case 3:
0770       case 4:
0771       case 5:
0772 
0773         charge12 = 1;
0774         absPhi12 = address.delta_phi_12;
0775         absPhi23 = address.delta_phi_23;
0776 
0777         if (charge)
0778           charge23 = 1;
0779         else
0780           charge23 = -1;
0781 
0782         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0783         dphi23R = (static_cast<float>(absPhi23 << 4)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0784         if (charge12 * charge23 < 0)
0785           dphi23R = -dphi23R;
0786 
0787         ptR_front = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12R, dphi23R, 1, int(pt_method));
0788         ptR_rear = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12R, dphi23R, 0, int(pt_method));
0789 
0790         if (pt_method == 22 && mode != 5 && etaR > 2.1)  //exclude mode without ME11a
0791         {
0792           float dphi12Rmin = dphi12R - Pi * 10 / 180 / 3;  // 10/3 degrees
0793           float dphi12Rmax = dphi12R + Pi * 10 / 180 / 3;  // 10/3 degrees
0794           float dphi23Rmin = dphi23R;
0795           float dphi23Rmax = dphi23R;
0796           //if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
0797           //if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
0798           float ptR_front_min = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
0799           float ptR_rear_min = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
0800           float ptR_front_max = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
0801           float ptR_rear_max = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
0802           // select max pt solution for 3 links:
0803           ptR_front = std::max(ptR_front, ptR_front_min);
0804           ptR_front = std::max(ptR_front, ptR_front_max);
0805           ptR_rear = std::max(ptR_rear, ptR_rear_min);
0806           ptR_rear = std::max(ptR_rear, ptR_rear_max);
0807         }
0808         break;
0809       case 6:  // for mode 6, 7 and 13 add CLCT information in dph23 bit and iME11 in charge bit
0810       case 7:
0811       case 13:  // ME1-ME4
0812         int iME11;
0813         iME11 = int(charge);
0814         absPhi12 = address.delta_phi_12;
0815         //int CLCT_pattern = static_cast<int>(address.delta_phi_23);
0816         int CLCT_pattern;
0817         CLCT_pattern = int(address.delta_phi_23);
0818 
0819         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0820 
0821         //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
0822         ptR_front = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 1, int(pt_method), iME11);
0823         ptR_rear = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 0, int(pt_method), iME11);
0824         if ((pt_method == 22) && etaR > 2.1)  //exclude tracks without ME11a
0825         {
0826           float dphi12Rmin = fabs(fabs(dphi12R) - Pi * 10 / 180 / 3);  // 10/3 degrees
0827           float ptR_front_min = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12Rmin, 1, int(pt_method), iME11);
0828           float ptR_rear_min = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12Rmin, 0, int(pt_method), iME11);
0829           // select max pt solution for 3 links:
0830           ptR_front = std::max(ptR_front, ptR_front_min);
0831           ptR_rear = std::max(ptR_rear, ptR_rear_min);
0832         }
0833         if (((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_front > 5.))
0834           ptR_front = 5.;
0835         if (((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_rear > 5.))
0836           ptR_rear = 5.;
0837 
0838         break;
0839       case 8:
0840       case 9:
0841       case 10:
0842         if (charge)
0843           absPhi12 = address.delta_phi();
0844         else {
0845           int temp_phi = address.delta_phi();
0846           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
0847         }
0848 
0849         dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0850 
0851         //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
0852         ptR_front = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 1, int(pt_method), int(2));
0853         ptR_rear = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 0, int(pt_method), int(2));
0854 
0855         break;
0856       case 11:  // FR = 1 -> b1-1-3,     FR = 0 -> b1-3
0857       case 12:  // FR = 1 -> b1-2-3,     FR = 0 -> b1-2
0858       case 14:  // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
0859 
0860         //sign definition: sign dphi12 = Phi_DT - Phi_CSC
0861         //                 sing dphi23 = 5th sign. bit of phiBend
0862         // -> charge = 1 -> dphi12 = +, phiBend = -
0863         // -> charge = 0 -> dphi12 = +, phiBend = +
0864         charge12 = 1;
0865         absPhi12 = address.delta_phi_12;
0866         absPhi23 = address.delta_phi_23;
0867 
0868         if (charge)
0869           charge23 = -1;
0870         else
0871           charge23 = 1;
0872 
0873         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0874         dphi23R = float(absPhi23);
0875         if (charge12 * charge23 < 0)
0876           dphi23R = -dphi23R;
0877 
0878         int mode1;
0879         mode1 = int(mode);
0880         if (fr == 1 && mode1 == 11)
0881           mode1 = 14;  // 3 station track we use dphi12 and phiBend for 2 and 3 station track
0882 
0883         ptR_front = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
0884         ptR_rear = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
0885 
0886         break;
0887       case 15:                                                     // halo trigger
0888       case 1:                                                      // tracks that fail delta phi cuts
0889         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3);  // 2 GeV
0890         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(3);
0891         break;
0892       default:                                                     // Tracks in this category are not considered muons.
0893         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0);  // 0 GeV
0894         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(0);
0895     };  // end switch
0896 
0897     front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
0898     rear_pt = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
0899 
0900   }  //end pt_methods greater or equal to 21
0901 
0902   //***************************************************//
0903   //***************************************************//
0904   if (pt_method >= 11 && pt_method < 20) {  //here we have only pt_methods greater or equal to 11
0905                                             //for fw 20101011 <- 2011 data taking
0906     // mode definition you could find at page 6 & 7:
0907     // http://www.phys.ufl.edu/~madorsky/sp/2010-10-11/sp_core_interface.pdf
0908     // it is valid starting the beggining of 2011
0909     switch (mode) {
0910       case 2:
0911       case 3:
0912       case 4:
0913       case 5:
0914 
0915         charge12 = 1;
0916         absPhi12 = address.delta_phi_12;
0917         absPhi23 = address.delta_phi_23;
0918 
0919         if (charge)
0920           charge23 = 1;
0921         else
0922           charge23 = -1;
0923 
0924         dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0925         dphi23R = (static_cast<float>(absPhi23 << 4)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0926         if (charge12 * charge23 < 0)
0927           dphi23R = -dphi23R;
0928 
0929         ptR_front = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 1, int(pt_method));
0930         ptR_rear = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 0, int(pt_method));
0931 
0932         if (pt_method == 12 && mode != 5 && etaR > 2.1)  //exclude mode without ME11a
0933         {
0934           float dphi12Rmin = dphi12R - Pi * 10 / 180 / 3;  // 10/3 degrees
0935           float dphi12Rmax = dphi12R + Pi * 10 / 180 / 3;  // 10/3 degrees
0936           float dphi23Rmin = dphi23R;
0937           float dphi23Rmax = dphi23R;
0938           if (dphi12Rmin * dphi12R < 0)
0939             dphi23Rmin = -dphi23R;
0940           if (dphi12Rmax * dphi12R < 0)
0941             dphi23Rmax = -dphi23R;
0942           float ptR_front_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
0943           float ptR_rear_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
0944           float ptR_front_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
0945           float ptR_rear_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
0946           // select max pt solution for 3 links:
0947           ptR_front = std::max(ptR_front, ptR_front_min);
0948           ptR_front = std::max(ptR_front, ptR_front_max);
0949           ptR_rear = std::max(ptR_rear, ptR_rear_min);
0950           ptR_rear = std::max(ptR_rear, ptR_rear_max);
0951         }
0952         break;
0953       case 6:
0954       case 7:
0955       case 8:
0956       case 9:
0957       case 10:
0958       case 13:  // ME1-ME4
0959 
0960         if (charge)
0961           absPhi12 = address.delta_phi();
0962         else {
0963           int temp_phi = address.delta_phi();
0964           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
0965         }
0966 
0967         dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0968 
0969         //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
0970         ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
0971         ptR_rear = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
0972         if ((pt_method == 12) && etaR > 2.1 && mode != 8 && mode != 9 && mode != 10)  //exclude tracks without ME11a
0973         {
0974           float dphi12Rmin = fabs(fabs(dphi12R) - Pi * 10 / 180 / 3);  // 10/3 degrees
0975           float ptR_front_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 1, int(pt_method));
0976           float ptR_rear_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 0, int(pt_method));
0977           // select max pt solution for 3 links:
0978           ptR_front = std::max(ptR_front, ptR_front_min);
0979           ptR_rear = std::max(ptR_rear, ptR_rear_min);
0980         }
0981 
0982         break;
0983       case 11:  // FR = 1 -> b1-1-3,     FR = 0 -> b1-3
0984       case 12:  // FR = 1 -> b1-2-3,     FR = 0 -> b1-2
0985       case 14:  // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
0986 
0987         if (fr == 0) {  // 2 station track
0988           if (charge)
0989             absPhi12 = address.delta_phi();
0990           else {
0991             int temp_phi = address.delta_phi();
0992             absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
0993           }
0994           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
0995           ptR_rear = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
0996 
0997         }  // end fr == 0
0998         if (fr == 1) {  // 3 station track
0999           charge12 = 1;
1000           absPhi12 = address.delta_phi_12;
1001           absPhi23 = address.delta_phi_23;
1002 
1003           if (charge)
1004             charge23 = 1;
1005           else
1006             charge23 = -1;
1007 
1008           dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1009           dphi23R = (static_cast<float>(absPhi23 << 4)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1010           if (charge12 * charge23 < 0)
1011             dphi23R = -dphi23R;
1012 
1013           ptR_front = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 1, int(pt_method));
1014 
1015           if (pt_method == 12 && mode != 5 && etaR > 2.1)  //exclude mode without ME11a
1016           {
1017             float dphi12Rmin = dphi12R - Pi * 10 / 180 / 3;  // 10/3 degrees
1018             float dphi12Rmax = dphi12R + Pi * 10 / 180 / 3;  // 10/3 degrees
1019             float dphi23Rmin = dphi23R;
1020             float dphi23Rmax = dphi23R;
1021             if (dphi12Rmin * dphi12R < 0)
1022               dphi23Rmin = -dphi23R;
1023             if (dphi12Rmax * dphi12R < 0)
1024               dphi23Rmax = -dphi23R;
1025             float ptR_front_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
1026             float ptR_front_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
1027             // select max pt solution for 3 links:
1028             ptR_front = std::max(ptR_front, ptR_front_min);
1029             ptR_front = std::max(ptR_front, ptR_front_max);
1030           }
1031         }  // end fr == 1
1032 
1033         break;
1034       case 15:                                                     // halo trigger
1035       case 1:                                                      // tracks that fail delta phi cuts
1036         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3);  // 2 GeV
1037         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(3);
1038         break;
1039       default:                                                     // Tracks in this category are not considered muons.
1040         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0);  // 0 GeV
1041         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(0);
1042     };  // end switch
1043 
1044     front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
1045     rear_pt = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
1046 
1047   }  //end pt_methods greater or equal to 11
1048   //***************************************************//
1049   if (pt_method <= 5) {  //here we have only pt_methods less or equal to 5
1050     // mode definition you could find at https://twiki.cern.ch/twiki/pub/Main/PtLUTs/mode_codes.xls
1051     // it is valid till the end 2010
1052     unsigned type;
1053 
1054     //  kluge to use 2-stn track in overlap region
1055     //  see also where this routine is called, and encode LUTaddress, and assignPT
1056     if (pt_method != 4 && pt_method != 5 && (mode == 2 || mode == 3 || mode == 4) && (eta < 3))
1057       mode = 6;
1058     if (pt_method != 4 && pt_method != 5 && (mode == 5) && (eta < 3))
1059       mode = 8;
1060 
1061     switch (mode) {
1062       case 2:
1063       case 3:
1064       case 4:
1065       case 5:
1066         type = mode - 1;
1067         charge12 = 1;
1068         absPhi12 = address.delta_phi_12;
1069         absPhi23 = address.delta_phi_23;
1070 
1071         if (charge)
1072           charge23 = 1;
1073         else
1074           charge23 = -1;
1075 
1076         // now convert to real numbers for input into PT assignment algos.
1077 
1078         if (pt_method == 4 || pt_method == 5)  // param method 2010
1079         {
1080           dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1081           dphi23R = (static_cast<float>(absPhi23 << 4)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1082           if (charge12 * charge23 < 0)
1083             dphi23R = -dphi23R;
1084 
1085           ptR_front = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 1, int(pt_method));
1086           ptR_rear = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 0, int(pt_method));
1087 
1088           if (pt_method == 5 && mode != 5 && etaR > 2.1)  //exclude mode without ME11a
1089           {
1090             float dphi12Rmin = dphi12R - Pi * 10 / 180 / 3;  // 10/3 degrees
1091             float dphi12Rmax = dphi12R + Pi * 10 / 180 / 3;  // 10/3 degrees
1092             float dphi23Rmin = dphi23R;
1093             float dphi23Rmax = dphi23R;
1094             if (dphi12Rmin * dphi12R < 0)
1095               dphi23Rmin = -dphi23R;
1096             if (dphi12Rmax * dphi12R < 0)
1097               dphi23Rmax = -dphi23R;
1098             float ptR_front_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
1099             float ptR_rear_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
1100             float ptR_front_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
1101             float ptR_rear_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
1102             // select max pt solution for 3 links:
1103             ptR_front = std::max(ptR_front, ptR_front_min);
1104             ptR_front = std::max(ptR_front, ptR_front_max);
1105             ptR_rear = std::max(ptR_rear, ptR_rear_min);
1106             ptR_rear = std::max(ptR_rear, ptR_rear_max);
1107           }
1108         } else if (pt_method == 1)  // param method
1109         {
1110           dphi12R = (static_cast<float>(absPhi12 << 1)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1111           dphi23R = (static_cast<float>(absPhi23 << 4)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1112           if (charge12 * charge23 < 0)
1113             dphi23R = -dphi23R;
1114 
1115           ptR_front = ptMethods.Pt3Stn(type, etaR, dphi12R, dphi23R, 1);
1116           ptR_rear = ptMethods.Pt3Stn(type, etaR, dphi12R, dphi23R, 0);
1117 
1118         } else if (pt_method == 2)  // cathy's method
1119         {
1120           if (type <= 2) {
1121             ptR_front = ptMethods.Pt3StnChiSq(
1122                 type + 3, etaR, absPhi12 << 1, ((charge == 0) ? -(absPhi23 << 4) : (absPhi23 << 4)), 1);
1123             ptR_rear = ptMethods.Pt3StnChiSq(
1124                 type + 3, etaR, absPhi12 << 1, ((charge == 0) ? -(absPhi23 << 4) : (absPhi23 << 4)), 0);
1125           } else {
1126             ptR_front = ptMethods.Pt2StnChiSq(type - 2, etaR, absPhi12 << 1, 1);
1127             ptR_rear = ptMethods.Pt2StnChiSq(type - 2, etaR, absPhi12 << 1, 0);
1128           }
1129 
1130         } else  // hybrid
1131         {
1132           if (type <= 2) {
1133             ptR_front = ptMethods.Pt3StnHybrid(
1134                 type + 3, etaR, absPhi12 << 1, ((charge == 0) ? -(absPhi23 << 4) : (absPhi23 << 4)), 1);
1135             ptR_rear = ptMethods.Pt3StnHybrid(
1136                 type + 3, etaR, absPhi12 << 1, ((charge == 0) ? -(absPhi23 << 4) : (absPhi23 << 4)), 0);
1137           } else {
1138             ptR_front = ptMethods.Pt2StnHybrid(type - 2, etaR, absPhi12 << 1, 1);
1139             ptR_rear = ptMethods.Pt2StnHybrid(type - 2, etaR, absPhi12 << 1, 0);
1140           }
1141         }
1142         break;
1143       case 6:
1144       case 7:
1145       case 8:
1146       case 9:
1147       case 10:
1148         type = mode - 5;
1149 
1150         if (charge)
1151           absPhi12 = address.delta_phi();
1152         else {
1153           int temp_phi = address.delta_phi();
1154           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
1155         }
1156 
1157         if (absPhi12 < (1 << 9)) {
1158           if (pt_method == 1 || type == 5) {
1159             dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1160 
1161             ptR_front = ptMethods.Pt2Stn(type, etaR, dphi12R, 1);
1162             ptR_rear = ptMethods.Pt2Stn(type, etaR, dphi12R, 0);
1163 
1164           } else if (pt_method == 2) {
1165             ptR_front = ptMethods.Pt2StnChiSq(type - 1, etaR, absPhi12, 1);
1166             ptR_rear = ptMethods.Pt2StnChiSq(type - 1, etaR, absPhi12, 0);
1167           } else {
1168             ptR_front = ptMethods.Pt2StnHybrid(type - 1, etaR, absPhi12, 1);
1169             ptR_rear = ptMethods.Pt2StnHybrid(type - 1, etaR, absPhi12, 0);
1170           }
1171         } else {
1172           ptR_front = trigger_ptscale->getPtScale()->getLowEdge(1);
1173           ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(1);
1174         }
1175         if (pt_method == 4 || pt_method == 5)  // param method 2010
1176         {
1177           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1178 
1179           //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
1180           ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
1181           ptR_rear = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
1182           if ((pt_method == 5) && etaR > 2.1 && mode != 8 && mode != 9 && mode != 10)  //exclude tracks without ME11a
1183           {
1184             float dphi12Rmin = fabs(fabs(dphi12R) - Pi * 10 / 180 / 3);  // 10/3 degrees
1185             float ptR_front_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 1, int(pt_method));
1186             float ptR_rear_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 0, int(pt_method));
1187             // select max pt solution for 3 links:
1188             ptR_front = std::max(ptR_front, ptR_front_min);
1189             ptR_rear = std::max(ptR_rear, ptR_rear_min);
1190           }
1191         }
1192 
1193         break;
1194       case 12:  // 1-2-b1 calculated only delta_phi12 = 2-b1
1195       case 14:
1196         type = 2;
1197 
1198         if (charge)
1199           absPhi12 = address.delta_phi();
1200         else {
1201           int temp_phi = address.delta_phi();
1202           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
1203         }
1204         if (absPhi12 < (1 << 9)) {
1205           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1206           ptR_front = ptMethods.Pt2Stn(type, etaR, dphi12R, 1);
1207           ptR_rear = ptMethods.Pt2Stn(type, etaR, dphi12R, 0);
1208         } else {
1209           ptR_front = trigger_ptscale->getPtScale()->getLowEdge(1);
1210           ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(1);
1211         }
1212         if (pt_method == 4 || pt_method == 5)  // param method 2010
1213         {
1214           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1215 
1216           ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
1217           ptR_rear = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
1218 
1219           if (fabs(dphi12R) < 0.01 && (ptR_rear < 10 || ptR_front < 10))
1220             std::cout << "dphi12R = " << dphi12R << " ptR_rear = " << ptR_rear << " ptR_front = " << ptR_front
1221                       << " etaR = " << etaR << " mode = " << mode << std::endl;
1222         }
1223         break;
1224       case 13:
1225         type = 4;
1226 
1227         if (charge)
1228           absPhi12 = address.delta_phi();
1229         else {
1230           int temp_phi = address.delta_phi();
1231           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
1232         }
1233         if (absPhi12 < (1 << 9)) {
1234           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1235           ptR_front = ptMethods.Pt2Stn(type, etaR, dphi12R, 1);
1236           ptR_rear = ptMethods.Pt2Stn(type, etaR, dphi12R, 0);
1237         } else {
1238           ptR_front = trigger_ptscale->getPtScale()->getLowEdge(1);
1239           ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(1);
1240         }
1241 
1242         if (pt_method == 4 || pt_method == 5)  // param method 2010
1243         {
1244           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1 << 12)) * CSCTFConstants::SECTOR_RAD;
1245 
1246           ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
1247           ptR_rear = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
1248           if ((pt_method == 5) && etaR > 2.1)  //mode = 13: ME1-ME4 exclude tracks without ME11a
1249           {
1250             float dphi12Rmin = fabs(fabs(dphi12R) - Pi * 10 / 180 / 3);  // 10/3 degrees
1251             float ptR_front_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 1, int(pt_method));
1252             float ptR_rear_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 0, int(pt_method));
1253             // select max pt solution for 3 links:
1254             ptR_front = std::max(ptR_front, ptR_front_min);
1255             ptR_rear = std::max(ptR_rear, ptR_rear_min);
1256           }
1257         }
1258 
1259         break;
1260       case 11:
1261         // singles trigger
1262         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(5);
1263         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(5);
1264         //ptR_front = trigger_ptscale->getPtScale()->getLowEdge(31);
1265         //ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(31);
1266         break;
1267       case 15:
1268         // halo trigger
1269         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(5);
1270         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(5);
1271         break;
1272       case 1:
1273         // tracks that fail delta phi cuts
1274         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(5);
1275         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(5);
1276         break;
1277       default:  // Tracks in this category are not considered muons.
1278         ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0);
1279         ptR_rear = trigger_ptscale->getPtScale()->getLowEdge(0);
1280     };
1281 
1282     front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
1283     rear_pt = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
1284 
1285     // kluge to set arbitrary Pt for some tracks with lousy resolution (and no param)
1286     if (pt_method != 4 && pt_method != 5) {
1287       if ((front_pt == 0 || front_pt == 1) && (eta < 3) && quality == 1 && pt_method != 2)
1288         front_pt = 31;
1289       if ((rear_pt == 0 || rear_pt == 1) && (eta < 3) && quality == 1 && pt_method != 2)
1290         rear_pt = 31;
1291     }
1292     if (pt_method != 2 && pt_method != 4 && quality == 1) {
1293       if (front_pt < 5)
1294         front_pt = 5;
1295       if (rear_pt < 5)
1296         rear_pt = 5;
1297     }
1298 
1299     // in order to match the pt assignement of the previous routine
1300     if (isBeamStartConf && pt_method != 2 && pt_method != 4 && pt_method != 5) {
1301       if (quality == 3 && mode == 5) {
1302         if (front_pt < 5)
1303           front_pt = 5;
1304         if (rear_pt < 5)
1305           rear_pt = 5;
1306       }
1307 
1308       if (quality == 2 && mode > 7 && mode < 11) {
1309         if (front_pt < 5)
1310           front_pt = 5;
1311         if (rear_pt < 5)
1312           rear_pt = 5;
1313       }
1314     }
1315 
1316   }  // end if for pt_method less or equal to 5
1317   //***************************************************//
1318 
1319   result.front_rank = front_pt | front_quality << 5;
1320   result.rear_rank = rear_pt | rear_quality << 5;
1321 
1322   result.charge_valid_front = 1;  //ptMethods.chargeValid(front_pt, quality, eta, pt_method);
1323   result.charge_valid_rear = 1;   //ptMethods.chargeValid(rear_pt, quality, eta, pt_method);
1324 
1325   /*  if (mode == 1) { 
1326     std::cout << "F_pt: "      << front_pt      << std::endl;
1327     std::cout << "R_pt: "      << rear_pt       << std::endl;
1328     std::cout << "F_quality: " << front_quality << std::endl;
1329     std::cout << "R_quality: " << rear_quality  << std::endl;
1330     std::cout << "F_rank: " << std::hex << result.front_rank << std::endl;
1331     std::cout << "R_rank: " << std::hex << result.rear_rank  << std::endl;
1332   }
1333   */
1334   return result;
1335 }
1336 
1337 unsigned CSCTFPtLUT::trackQuality(const unsigned& eta, const unsigned& mode, const unsigned& fr) const {
1338   // eta and mode should be only 4-bits, since that is the input to the large LUT
1339   if (eta > 15 || mode > 15) {
1340     //std::cout << "Error: Eta or Mode out of range in AU quality assignment" << std::endl;
1341     edm::LogError("CSCTFPtLUT::trackQuality()") << "Eta or Mode out of range in AU quality assignment";
1342     return 0;
1343   }
1344   unsigned int quality;
1345   switch (mode) {
1346     case 2:
1347       quality = 3;
1348       if (pt_method > 10 && eta < 3)
1349         quality = 1;  //eta < 1.2
1350       if (pt_method == 32 && eta >= 12)
1351         quality = 2;  // eta > 2.1
1352       break;
1353     case 3:
1354     case 4:
1355       /// DEA try increasing quality
1356       //        quality = 2;
1357       quality = 3;
1358       if (pt_method == 32 && eta >= 12)
1359         quality = 2;  // eta > 2.1
1360       break;
1361     case 5:
1362       quality = 1;
1363       if (isBeamStartConf && eta >= 12 && pt_method < 20)  // eta > 2.1
1364         quality = 3;
1365       if (pt_method == 27 || pt_method == 28 || pt_method == 29 || pt_method == 32 || pt_method == 30 ||
1366           pt_method == 33 || pt_method == 34)
1367         quality = 3;  // all mode = 5 set to quality 3 due to a lot dead ME1/1a stations
1368       break;
1369     case 6:
1370       if (eta >= 3)  // eta > 1.2
1371         quality = 2;
1372       else
1373         quality = 1;
1374       if (pt_method == 32 && eta >= 12)
1375         quality = 1;  // eta > 2.1
1376       break;
1377     case 7:
1378       quality = 2;
1379       if (pt_method > 10 && eta < 3)
1380         quality = 1;  //eta < 1.2
1381       if (pt_method == 32 && eta >= 12)
1382         quality = 1;  // eta > 2.1
1383       break;
1384     case 8:
1385     case 9:
1386     case 10:
1387       quality = 1;
1388       if (isBeamStartConf && eta >= 12 && pt_method < 20)  // eta > 2.1
1389         quality = 2;
1390       if ((pt_method == 27 || pt_method == 28 || pt_method == 30) && (eta >= 7 && eta < 9))
1391         quality = 2;  //set to quality 2 for eta = 1.6-1.8 due to a lot dead ME1/1a stations
1392       break;
1393     case 11:
1394       // single LCTs
1395       quality = 1;
1396       // overlap region
1397       if (pt_method > 10 && fr == 0)
1398         quality = 2;
1399       if (pt_method > 10 && fr == 1)
1400         quality = 3;
1401       if (pt_method > 20 && fr == 0)
1402         quality = 3;
1403       break;
1404     case 12:
1405       quality = 3;
1406       // overlap region
1407       if (pt_method > 10 && fr == 0)
1408         quality = 2;
1409       if (pt_method > 10 && fr == 1)
1410         quality = 3;
1411       if (pt_method > 20 && fr == 0)
1412         quality = 3;
1413       break;
1414     case 13:
1415       quality = 2;
1416       if (pt_method == 32 && eta >= 12)
1417         quality = 1;  // eta > 2.1
1418       break;
1419     case 14:
1420       quality = 2;
1421       // overlap region
1422       if (pt_method > 10 && fr == 0)
1423         quality = 2;
1424       if (pt_method > 10 && fr == 1)
1425         quality = 3;
1426       if (pt_method > 20 && fr == 0)
1427         quality = 3;
1428       break;
1429     case 15:
1430       // halo triggers
1431       quality = 1;
1432       break;
1433       //DEA: keep muons that fail delta phi cut
1434     case 1:
1435       quality = 1;
1436       break;
1437     default:
1438       quality = 0;
1439       break;
1440   }
1441 
1442   // allow quality = 1 only in overlap region or eta = 1.6 region
1443   //    if ((quality == 1) && (eta >= 4) && (eta != 6) && (eta != 7)) quality = 0;
1444   //    if ( (quality == 1) && (eta >= 4) ) quality = 0;
1445 
1446   if ((quality == 1) && (eta >= 4) && (eta < 11) && ((lowQualityFlag & 4) == 0))
1447     quality = 0;
1448   if ((quality == 1) && (eta < 4) && ((lowQualityFlag & 1) == 0) && ((lowQualityFlag & 4) == 0))
1449     quality = 0;
1450   if ((quality == 1) && (eta >= 11) && ((lowQualityFlag & 2) == 0) && ((lowQualityFlag & 4) == 0))
1451     quality = 0;
1452 
1453   return quality;
1454 }
1455 
1456 void CSCTFPtLUT::readLUT() {
1457   std::ifstream PtLUT;
1458 
1459   if (isBinary) {
1460     PtLUT.open(pt_lut_file.fullPath().c_str(), std::ios::binary);
1461     PtLUT.seekg(0, std::ios::end);
1462     int length = PtLUT.tellg();
1463     ;
1464     if (length == (1 << CSCBitWidths::kPtAddressWidth) * sizeof(short)) {
1465       PtLUT.seekg(0, std::ios::beg);
1466       PtLUT.read(reinterpret_cast<char*>(pt_lut), length);
1467     } else {
1468       edm::LogError("CSCPtLUT") << "File " << pt_lut_file.fullPath() << " is incorrect size!\n";
1469     }
1470     PtLUT.close();
1471   } else {
1472     PtLUT.open(pt_lut_file.fullPath().c_str());
1473     unsigned i = 0;
1474     unsigned short temp = 0;
1475     while (!PtLUT.eof() && i < 1 << CSCBitWidths::kPtAddressWidth) {
1476       PtLUT >> temp;
1477       pt_lut[i++] = temp;
1478     }
1479     PtLUT.close();
1480   }
1481 }