CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/L1Trigger/CSCTrackFinder/src/CSCTFPtLUT.cc

Go to the documentation of this file.
00001 /*****************************************************
00002  * 28/01/2010
00003  * GP: added new switch to use the beam start Pt LUTs
00004  * if (eta > 2.1) 2 stations tracks have quality 2
00005  *                3 stations tracks have quality 3
00006  * NB: no matter if the have ME1
00007  * 
00008  * --> by default is set to true
00009  *****************************************************/
00010 
00011 #include <L1Trigger/CSCTrackFinder/interface/CSCTFPtLUT.h>
00012 #include <DataFormats/L1CSCTrackFinder/interface/CSCTFConstants.h>
00013 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00014 #include <fstream>
00015 
00016 #include "FWCore/Framework/interface/ESHandle.h"
00017 #include <L1Trigger/CSCTrackFinder/interface/CSCTFPtLUT.h>
00018 
00019 #include "CondFormats/L1TObjects/interface/L1MuTriggerScales.h"
00020 #include "CondFormats/DataRecord/interface/L1MuTriggerScalesRcd.h"
00021 #include "CondFormats/L1TObjects/interface/L1MuTriggerPtScale.h"
00022 #include "CondFormats/DataRecord/interface/L1MuTriggerPtScaleRcd.h"
00023 
00024 // info for getPtScale() pt scale in GeV
00025 // low edges of pt bins
00026 /*     const float ptscale[33] = {  */
00027 /*       -1.,   0.0,   1.5,   2.0,   2.5,   3.0,   3.5,   4.0, */
00028 /*       4.5,   5.0,   6.0,   7.0,   8.0,  10.0,  12.0,  14.0,   */
00029 /*       16.0,  18.0,  20.0,  25.0,  30.0,  35.0,  40.0,  45.0,  */
00030 /*       50.0,  60.0,  70.0,  80.0,  90.0, 100.0, 120.0, 140.0, 1.E6 }; */
00031 
00032 /*
00033   These arrays were defined such that they take integer dPhi --> dPhi-units which are used by CSCTFPtMethods.
00034   The values were defined using:
00035   
00036   Phi_{i} = Phi_{i-1} + MAX( phi_Unit * alphi^{i}, phi_Unit), where phi_Unit = 62 deg / 4096, and alpha is solved for
00037   such that the phi-space is resonably covered. This will be better optimized in the future.
00038   
00039 */
00040 
00041 // Array that maps the 5-bit integer dPhi --> dPhi-units. It is assumed that this is used for dPhi23,
00042 // which has a maximum value of 3.83 degrees (255 units) in the extrapolation units.
00043 const int CSCTFPtLUT::dPhiNLBMap_5bit[32] =
00044      {  0       ,       1       ,       2       ,       4       ,       5       ,       7       ,       9       ,       11      ,       13      ,       15      ,       18      ,       21      ,       24      ,       28      ,       32      ,       37      ,       41      ,       47      ,       53      ,       60      ,       67      ,       75      ,       84      ,       94      ,       105     ,       117     ,       131     ,       145     ,       162     ,       180     ,       200     ,       222};
00045 
00046 // Array that maps the 7-bit integer dPhi --> dPhi-units. It is assumed that this is used for dPhi12,
00047 // which has a maximum value of 7.67 degrees (511 units) in the extrapolation units.
00048 const int CSCTFPtLUT::dPhiNLBMap_7bit[128] =
00049   {     0       ,       1       ,       2       ,       3       ,       4       ,       5       ,       6       ,       8       ,       9       ,       10      ,       11      ,       12      ,       14      ,       15      ,       16      ,       17      ,       19      ,       20      ,       21      ,       23      ,       24      ,       26      ,       27      ,       29      ,       30      ,       32      ,       33      ,       35      ,       37      ,       38      ,       40      ,       42      ,       44      ,       45      ,       47      ,       49      ,       51      ,       53      ,       55      ,       57      ,       59      ,       61      ,       63      ,       65      ,       67      ,       70      ,       72      ,       74      ,       77      ,       79      ,       81      ,       84      ,       86      ,       89      ,       92      ,       94      ,       97      ,       100     ,       103     ,       105     ,       108     ,       111     ,       114     ,       117     ,       121     ,       124     ,       127     ,       130     ,       134     ,       137     ,       141     ,       144     ,       148     ,       151     ,       155     ,       159     ,       163     ,       167     ,       171     ,       175     ,       179     ,       183     ,       188     ,       192     ,       197     ,       201     ,       206     ,       210     ,       215     ,       220     ,       225     ,       230     ,       235     ,       241     ,       246     ,       251     ,       257     ,       263     ,       268     ,       274     ,       280     ,       286     ,       292     ,       299     ,       305     ,       312     ,       318     ,       325     ,       332     ,       339     ,       346     ,       353     ,       361     ,       368     ,       376     ,       383     ,       391     ,       399     ,       408     ,       416     ,       425     ,       433     ,       442     ,       451     ,       460     ,       469     ,       479     ,       489 };
00050 
00051 // Array that maps the 8-bit integer dPhi --> dPhi-units. It is assumed that this is used for dPhi12,
00052 // which has a maximum value of 7.67 degrees (511 units) in the extrapolation units.
00053 const int CSCTFPtLUT::dPhiNLBMap_8bit[256] =
00054  {      0       ,       1       ,       2       ,       3       ,       4       ,       5       ,       6       ,       7       ,       8       ,       9       ,       10      ,       11      ,       12      ,       13      ,       14      ,       16      ,       17      ,       18      ,       19      ,       20      ,       21      ,       22      ,       23      ,       24      ,       25      ,       27      ,       28      ,       29      ,       30      ,       31      ,       32      ,       33      ,       35      ,       36      ,       37      ,       38      ,       39      ,       40      ,       42      ,       43      ,       44      ,       45      ,       46      ,       48      ,       49      ,       50      ,       51      ,       53      ,       54      ,       55      ,       56      ,       58      ,       59      ,       60      ,       61      ,       63      ,       64      ,       65      ,       67      ,       68      ,       69      ,       70      ,       72      ,       73      ,       74      ,       76      ,       77      ,       79      ,       80      ,       81      ,       83      ,       84      ,       85      ,       87      ,       88      ,       90      ,       91      ,       92      ,       94      ,       95      ,       97      ,       98      ,       100     ,       101     ,       103     ,       104     ,       105     ,       107     ,       108     ,       110     ,       111     ,       113     ,       115     ,       116     ,       118     ,       119     ,       121     ,       122     ,       124     ,       125     ,       127     ,       129     ,       130     ,       132     ,       133     ,       135     ,       137     ,       138     ,       140     ,       141     ,       143     ,       145     ,       146     ,       148     ,       150     ,       151     ,       153     ,       155     ,       157     ,       158     ,       160     ,       162     ,       163     ,       165     ,       167     ,       169     ,       171     ,       172     ,       174     ,       176     ,       178     ,       180     ,       181     ,       183     ,       185     ,       187     ,       189     ,       191     ,       192     ,       194     ,       196     ,       198     ,       200     ,       202     ,       204     ,       206     ,       208     ,       210     ,       212     ,       214     ,       216     ,       218     ,       220     ,       222     ,       224     ,       226     ,       228     ,       230     ,       232     ,       234     ,       236     ,       238     ,       240     ,       242     ,       244     ,       246     ,       249     ,       251     ,       253     ,       255     ,       257     ,       259     ,       261     ,       264     ,       266     ,       268     ,       270     ,       273     ,       275     ,       277     ,       279     ,       282     ,       284     ,       286     ,       289     ,       291     ,       293     ,       296     ,       298     ,       300     ,       303     ,       305     ,       307     ,       310     ,       312     ,       315     ,       317     ,       320     ,       322     ,       324     ,       327     ,       329     ,       332     ,       334     ,       337     ,       340     ,       342     ,       345     ,       347     ,       350     ,       352     ,       355     ,       358     ,       360     ,       363     ,       366     ,       368     ,       371     ,       374     ,       376     ,       379     ,       382     ,       385     ,       387     ,       390     ,       393     ,       396     ,       398     ,       401     ,       404     ,       407     ,       410     ,       413     ,       416     ,       419     ,       421     ,       424     ,       427     ,       430     ,       433     ,       436     ,       439     ,       442     ,       445     ,       448     ,       451     ,       454     ,       457     ,       461     ,       464     ,       467     ,       470     ,       473     ,       476     ,       479     ,       483     };
00055   
00056 
00057 //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};
00058 //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};
00059 //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};
00060 //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};
00061 //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};
00062 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};
00063 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};
00064 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};
00065 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};
00066 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};
00067 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};
00068 
00069 const int CSCTFPtLUT::getPtbyMLH = 0xFFFF; // all modes on
00070 
00071 
00072 CSCTFPtLUT::CSCTFPtLUT(const edm::EventSetup& es) 
00073     : read_pt_lut_es(true),
00074       read_pt_lut_file(false),
00075       isBinary(false)
00076 {
00077         pt_method = 32;
00078 
00079         lowQualityFlag = 4;
00080         isBeamStartConf = true;
00081 
00082         edm::ESHandle<L1MuCSCPtLut> ptLUT;
00083         es.get<L1MuCSCPtLutRcd>().get(ptLUT);
00084         theL1MuCSCPtLut_ = ptLUT.product();
00085 
00086         //std::cout << "theL1MuCSCPtLut_ pointer is "
00087         //          << theL1MuCSCPtLut_
00088         //          << std::endl;
00089 
00090         edm::ESHandle< L1MuTriggerScales > scales ;
00091         es.get< L1MuTriggerScalesRcd >().get( scales ) ;
00092         trigger_scale = scales.product() ;
00093 
00094         edm::ESHandle< L1MuTriggerPtScale > ptScale ;
00095         es.get< L1MuTriggerPtScaleRcd >().get( ptScale ) ;
00096         trigger_ptscale = ptScale.product() ;
00097 
00098         ptMethods = CSCTFPtMethods( ptScale.product() ) ;
00099  
00100 }
00101 
00102 
00103 CSCTFPtLUT::CSCTFPtLUT(const edm::ParameterSet& pset,
00104                        const L1MuTriggerScales* scales,
00105                        const L1MuTriggerPtScale* ptScale)
00106   : trigger_scale( scales ),
00107     trigger_ptscale( ptScale ),
00108     ptMethods( ptScale ),
00109     read_pt_lut_es(false),
00110     read_pt_lut_file(false),
00111     isBinary(false)
00112 {
00113 
00114   read_pt_lut_file = pset.getParameter<bool>("ReadPtLUT");
00115   if(read_pt_lut_file)
00116     {
00117       // if read from file, then need to set extra variables
00118       pt_lut_file = pset.getParameter<edm::FileInPath>("PtLUTFile");
00119       isBinary = pset.getParameter<bool>("isBinary");
00120 
00121       edm::LogInfo("CSCTFPtLUT::CSCTFPtLUT") << "Reading file: "
00122                                              << pt_lut_file.fullPath().c_str()
00123                                              << " isBinary?(1/0): "
00124                                              << isBinary;
00125     }
00126 
00127   // Determine the pt assignment method to use
00128   // 1 - Darin's parameterization method
00129   // 2 - Cathy Yeh's chi-square minimization method
00130   // 3 - Hybrid
00131   // 4 - Anna's parameterization method
00132   // 5 - Anna's parameterization method 
00133          //with improvments at ME1/1a: find max pt for 3 links hypothesis
00134   // 11 - Anna's: for fw 20101011 <- 2011 data taking <- not valide any more
00135   // 12 - Anna's: for fw 20101011 <- 2011 data taking <- not valide any more
00136           //with improvments at ME1/1a: find max pt for 3 links hypothesis
00137   // 21 - Anna's: for fw 20110118 and up, curves with data 2010 <- 2011 data taking
00138   // 22 - Anna's: for fw 20110118 and up, curves with data 2010 <- 2011 data taking
00139           //with improvments at ME1/1a: find max pt for 3 links hypothesis
00140   // 23 - Anna's: for fw 20110118 and up, curves with MC like method 4 <- 2011 data taking
00141   // 24 - Anna's: for fw 20110118 and up, curves with MC like method 4 <- 2011 data taking
00142           //with improvments at ME1/1a: find max pt for 3 links hypothesis
00143   //25 and 26 like 23 and 24 correspondenly but fix high pt assignment in DT-CSC region
00144   // 25 - Anna's: for fw 20110118 and up, curves with MC like method 4 <- 2011 data taking
00145   // 26 - Anna's: for fw 20110118 and up, curves with MC like method 4 <- 2011 data taking
00146           //with improvments at ME1/1a: find max pt for 3 links hypothesis
00147   // change Quality: Q = 3 for mode 5, Quility = 2 for mode = 8, 9, 10 at eta = 1.6-1.8   
00148   // 27 - Anna's: for fw 20110118 and up, curves with MC like method 4 <- 2011 data taking
00149   // 28 - Anna's: for fw 20110118 and up, curves with MC like method 4 <- 2011 data taking
00150           //with improvments at ME1/1a: find max pt for 3 links hypothesis
00151   // 29 - Bobby's medium Quality: using fw 2012_01_31. Switch to Global Log(L). Non-Linear dphi binning. 
00152   // 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 
00153   // 30 - Bobby's loose Quality: using fw 2012_01_31. Switch to Global Log(L). Non-Linear dphi binning. 
00154   // 31 - Bobby's tight Quality: using fw 2012_01_31. Switch to Global Log(L). Non-Linear dphi binning. 
00155   // 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. 
00156   pt_method = pset.getUntrackedParameter<unsigned>("PtMethod",32);
00157   //std::cout << "pt_method from pset " << std::endl; 
00158   // what does this mean???
00159   lowQualityFlag = pset.getUntrackedParameter<unsigned>("LowQualityFlag",4);
00160 
00161   if(read_pt_lut_file)
00162     {
00163       pt_lut = new ptdat[1<<21];
00164       readLUT();
00165     }
00166 
00167   isBeamStartConf = pset.getUntrackedParameter<bool>("isBeamStartConf", true);
00168   
00169 }
00170 
00171 ptdat CSCTFPtLUT::Pt(const ptadd& address) const
00172 {
00173   ptdat result;
00174   
00175   if(read_pt_lut_es) 
00176   {
00177     unsigned int shortAdd = (address.toint()& 0x1fffff);
00178 
00179     ptdat tmp( theL1MuCSCPtLut_->pt(shortAdd) );
00180   
00181     result = tmp;
00182   } 
00183   
00184   else if (read_pt_lut_file)
00185     {
00186       int shortAdd = (address.toint()& 0x1fffff);
00187       result = pt_lut[shortAdd];
00188     } 
00189   
00190   else
00191     result = calcPt(address);
00192 
00193   return result;
00194 }
00195 
00196 ptdat CSCTFPtLUT::Pt(const unsigned& address) const
00197 {
00198   return Pt(ptadd(address));
00199 }
00200 
00201 ptdat CSCTFPtLUT::Pt(const unsigned& delta_phi_12, const unsigned& delta_phi_23,
00202                      const unsigned& track_eta, const unsigned& track_mode,
00203                      const unsigned& track_fr, const unsigned& delta_phi_sign) const
00204 {
00205   ptadd address;
00206   address.delta_phi_12 = delta_phi_12;
00207   address.delta_phi_23 = delta_phi_23;
00208   address.track_eta = track_eta;
00209   address.track_mode = track_mode;
00210   address.track_fr = track_fr;
00211   address.delta_phi_sign = delta_phi_sign;
00212 
00213   return Pt(address);
00214 }
00215 
00216 ptdat CSCTFPtLUT::Pt(const unsigned& delta_phi_12, const unsigned& track_eta,
00217                      const unsigned& track_mode, const unsigned& track_fr,
00218                      const unsigned& delta_phi_sign) const
00219 {
00220   ptadd address;
00221   address.delta_phi_12 = ((1<<8)-1)&delta_phi_12;
00222   address.delta_phi_23 = ((1<<4)-1)&(delta_phi_12>>8);
00223   address.track_eta = track_eta;
00224   address.track_mode = track_mode;
00225   address.track_fr = track_fr;
00226   address.delta_phi_sign = delta_phi_sign;
00227 
00228   return Pt(address);
00229 }
00230 
00231 
00232 ptdat CSCTFPtLUT::calcPt(const ptadd& address) const
00233 {
00234   ptdat result;
00235 
00236   double Pi  = acos(-1.);
00237   float etaR = 0, ptR_front = 0, ptR_rear = 0, dphi12R = 0, dphi23R = 0;
00238   int charge12, charge23;
00239   unsigned type, mode, eta, fr, quality, charge, absPhi12, absPhi23;
00240 
00241   mode = address.track_mode;
00242    
00243   int usedetaCUT = true;
00244   // Chose Eta cut tightness. 1=tightest, 2=moderate, 3=loose, 4=very loose, 5=extremely loose, 6=open
00245 
00246   // modes 6, 7, 13
00247   int EtaCutLevel_1 = 2;
00248   int dEtaCut_1[24];
00249   
00250   for (int i=0;i<24;i++)
00251     {
00252       dEtaCut_1[i] = 10;
00253       if (EtaCutLevel_1 == 1)
00254         dEtaCut_1[i] = dEtaCut_Low[i];
00255       else if (EtaCutLevel_1 == 2)
00256         dEtaCut_1[i] = dEtaCut_Mid[i];
00257       else if (EtaCutLevel_1 == 3)
00258         dEtaCut_1[i] = dEtaCut_High_A[i];
00259       else if (EtaCutLevel_1 == 4)
00260         dEtaCut_1[i] = dEtaCut_High_B[i];
00261       else if (EtaCutLevel_1 == 5)
00262         dEtaCut_1[i] = dEtaCut_High_C[i];
00263       else if (EtaCutLevel_1 == 6)
00264         dEtaCut_1[i] = dEtaCut_Open[i];
00265     }
00266   // modes 8, 9, 10
00267   int EtaCutLevel_2 = 2;
00268   int dEtaCut_2[24];
00269   
00270   for (int i=0;i<24;i++)
00271     {
00272       dEtaCut_2[i] = 10;
00273       if (EtaCutLevel_2 == 1)
00274         dEtaCut_2[i] = dEtaCut_Low[i];
00275       else if (EtaCutLevel_2 == 2)
00276         dEtaCut_2[i] = dEtaCut_Mid[i];
00277       else if (EtaCutLevel_2 == 3)
00278         dEtaCut_2[i] = dEtaCut_High_A[i];
00279       else if (EtaCutLevel_2 == 4)
00280         dEtaCut_2[i] = dEtaCut_High_B[i];
00281       else if (EtaCutLevel_2 == 5)
00282         dEtaCut_2[i] = dEtaCut_High_C[i];
00283       else if (EtaCutLevel_2 == 6)
00284         dEtaCut_2[i] = dEtaCut_Open[i];
00285 
00286       float scalef = 1.0;
00287       if (mode == 8 || mode == 10)
00288         dEtaCut_2[i] = scalef*dEtaCut_2[i];
00289       
00290     }
00291   
00292   
00293 
00294   eta = address.track_eta;
00295  
00296   fr = address.track_fr;
00297   charge = address.delta_phi_sign;
00298   quality = trackQuality(eta, mode, fr);
00299   unsigned front_pt, rear_pt;
00300   front_pt = 0.; rear_pt = 0.;
00301   unsigned front_quality, rear_quality;
00302 
00303   etaR = trigger_scale->getRegionalEtaScale(2)->getLowEdge(2*eta+1);
00304 
00305   front_quality = rear_quality = quality;
00306 
00307   unsigned int remerged;
00308   int iME11;
00309   int CLCT_pattern;
00310   int dEta;
00311   int index = 0;
00312   float bestLH = -999;
00313  float bestLH_front = -999.0;
00314  float bestLH_rear = -999.0;
00315 
00316  int PtbyMLH = false;
00317   
00318   //***************************************************//
00319   if(pt_method >= 29 && pt_method <= 33)
00320     {
00321         // using fw 2012_01_31. Switch to Global Log(L). Non-Linear dphi binning.
00322       PtbyMLH = 0x1 & (getPtbyMLH >> (int)mode);
00324       // switch off any improvment for eta > 2.1
00325       if(etaR > 2.1){
00326          usedetaCUT = false;
00327          PtbyMLH = 0x0;
00328       }
00330       
00331       switch(mode)
00332         {
00333         case 2:
00334         case 3:
00335         case 4:
00336         case 5:
00337   
00338       
00339       charge12 = 1;
00340 
00341       // First remake the 12-bit dPhi word from the core
00342       remerged = (address.delta_phi_12 | (address.delta_phi_23 << 8 ) );
00343       
00344       // Now separate it into 7-bit dPhi12 and 5-bit dPhi23 parts
00345       absPhi12 = ((1<<7)-1) &  remerged; 
00346       absPhi23 = ((1<<5)-1) & (remerged >> 7);
00347 
00348       // Now get the corresponding dPhi value in our phi-units using the inverse dPhi LUTs
00349       absPhi12 = dPhiNLBMap_7bit[absPhi12];
00350       absPhi23 = dPhiNLBMap_5bit[absPhi23];
00351 
00352       if(charge) charge23 = 1;
00353       else charge23 = -1;
00354 
00355       dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00356       dphi23R = (static_cast<float>(absPhi23)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00357       if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00358 
00359       ptR_front = ptMethods.Pt3Stn2012(int(mode), etaR, dphi12R, dphi23R, PtbyMLH, bestLH, 1, int(pt_method));
00360       bestLH_front = bestLH;
00361       ptR_rear  = ptMethods.Pt3Stn2012(int(mode), etaR, dphi12R, dphi23R, PtbyMLH, bestLH, 0, int(pt_method));    
00362       bestLH_rear = bestLH;
00363       
00364       if((pt_method == 29 || pt_method == 32 || pt_method == 30 || pt_method == 31) && mode != 5 && etaR > 2.1)//exclude mode without ME11a
00365         {
00366             float dphi12Rmin = dphi12R - Pi*10/180/3; // 10/3 degrees 
00367             float dphi12Rmax = dphi12R + Pi*10/180/3; // 10/3 degrees
00368             float dphi23Rmin = dphi23R;
00369             float dphi23Rmax = dphi23R;
00370             //if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
00371             //if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
00372             float ptR_front_min = ptMethods.Pt3Stn2012(int(mode), etaR, dphi12Rmin, dphi23Rmin, PtbyMLH, bestLH, 1, int(pt_method));
00373             float bestLH_front_min = bestLH;
00374             float ptR_rear_min = ptMethods.Pt3Stn2012(int(mode), etaR, dphi12Rmin, dphi23Rmin,  PtbyMLH, bestLH, 0, int(pt_method));
00375             float bestLH_rear_min = bestLH;
00376             float ptR_front_max = ptMethods.Pt3Stn2012(int(mode), etaR, dphi12Rmax, dphi23Rmax, PtbyMLH, bestLH, 1, int(pt_method));
00377             float bestLH_front_max = bestLH;
00378             float ptR_rear_max = ptMethods.Pt3Stn2012(int(mode), etaR, dphi12Rmax, dphi23Rmax,  PtbyMLH, bestLH, 0, int(pt_method));
00379             float bestLH_rear_max = bestLH;
00380 
00381             if (PtbyMLH)
00382               {
00383                 float best_pt_front = ptR_front;
00384                 float best_LH_front = bestLH_front;
00385                 if (bestLH_front_min > best_LH_front)
00386                   {
00387                     best_pt_front = ptR_front_min;
00388                     best_LH_front = bestLH_front_min;
00389                   }
00390                 if (bestLH_front_max > best_LH_front)
00391                   {
00392                     best_pt_front = ptR_front_max;
00393                     best_LH_front = bestLH_front_max;
00394                   }
00395                 ptR_front = best_pt_front;
00396 
00397                 float best_pt_rear = ptR_rear;
00398                 float best_LH_rear = bestLH_rear;
00399                 if (bestLH_rear_min > best_LH_rear)
00400                   {
00401                     best_pt_rear = ptR_rear_min;
00402                     best_LH_rear = bestLH_rear_min;
00403                   }
00404                 if (bestLH_rear_max > best_LH_rear)
00405                   {
00406                     best_pt_rear = ptR_rear_max;
00407                     best_LH_rear = bestLH_rear_max;
00408                   }
00409                 ptR_rear = best_pt_rear;
00410               }
00411             else
00412               {
00413                 // select max pt solution for 3 links:
00414                 ptR_front = std::max(ptR_front, ptR_front_min);
00415                 ptR_front = std::max(ptR_front, ptR_front_max);
00416                 ptR_rear = std::max(ptR_rear, ptR_rear_min);
00417                 ptR_rear = std::max(ptR_rear, ptR_rear_max);
00418               }
00419         }
00420       break;
00421     case 6: // for mode 6, 7 and 13 add CLCT information in dph23 bit and iME11 in charge bit   
00422     case 7:
00423     case 13: // ME1-ME4
00424       
00425       // First remake the 12-bit dPhi word from the core
00426       remerged = (address.delta_phi_12 | (address.delta_phi_23 << 8 ) );
00427       // Now get 8-bit dPhi12 
00428       absPhi12 = ((1<<8)-1) & remerged; 
00429       // Now get 3-bit dEta
00430       dEta = ((1<<3)-1) & (remerged >> 8);
00431       // New get CLCT bit. CLCT = true if CLCTPattern = 8, 9, or 10, else 0.
00432       CLCT_pattern = 0x1 & (remerged >> 11);
00433       
00434       iME11 = int(charge); // = 0 if ME1/1, = 1 if ME1/2 or ME1/3 station 
00435       if(iME11 == 1 && etaR > 1.6) etaR = 1.55; // shift for ME1/2 station  
00436       if(iME11 == 0 && etaR < 1.6) etaR = 1.65; // shift for ME1/1 station
00437 
00438       // Get the 8-bit dPhi bin number  
00439       absPhi12 = ((1<<8)-1) & address.delta_phi_12;
00440       
00441       // Now get the corresponding dPhi value in our phi-units using the inverse dPhi LUTs
00442       absPhi12 = dPhiNLBMap_8bit[absPhi12];
00443       
00444       //int CLCT_pattern = static_cast<int>(address.delta_phi_23);
00445     
00446       dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00447       
00448       //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
00449       ptR_front = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R, PtbyMLH, bestLH, 1, int(pt_method));
00450       bestLH_front = bestLH;
00451       ptR_rear  = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R, PtbyMLH, bestLH, 0, int(pt_method));
00452       bestLH_rear = bestLH;
00453       if((pt_method == 29 || pt_method == 32 || pt_method == 30 || pt_method == 31) && etaR > 2.1)//exclude tracks without ME11a 
00454         {
00455           float dphi12Rmin = fabs(fabs(dphi12R) - Pi*10/180/3); // 10/3 degrees 
00456           float ptR_front_min = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12Rmin,  PtbyMLH, bestLH, 1, int(pt_method));
00457           float bestLH_front_min = bestLH;
00458           float ptR_rear_min = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12Rmin,   PtbyMLH, bestLH, 0, int(pt_method));
00459           float bestLH_rear_min = bestLH;
00460 
00461           if (PtbyMLH)
00462             {
00463               ptR_front = bestLH_front > bestLH_front_min ? ptR_front : ptR_front_min;
00464               ptR_rear  = bestLH_rear  > bestLH_rear_min ? ptR_rear : ptR_rear_min;
00465             }
00466           else
00467             {
00468               // select max pt solution for 3 links:
00469               ptR_front = std::max(ptR_front, ptR_front_min);
00470               ptR_rear = std::max(ptR_rear, ptR_rear_min);
00471             }
00472         }
00473       
00474       if( (!CLCT_pattern) && (ptR_front > 5.)) ptR_front = 5.;
00475       if( (!CLCT_pattern) && (ptR_rear > 5.)) ptR_rear = 5.;
00476 
00477        // Check dEta against reasonable values for high-pt muons
00478       index = 0;
00479       if (mode == 6) index = 0;
00480       if (mode == 7) index = 4;
00481       if (mode == 13) index = 8;
00482       
00483       if (usedetaCUT)
00484         {
00485           if (fabs(etaR)>1.2 && fabs(etaR)<=1.5)
00486             if (dEta>dEtaCut_1[index+0] )
00487               {
00488                 if (ptR_front > 5) ptR_front = 5;
00489                 if (ptR_rear  > 5) ptR_rear  = 5;
00490               }
00491           if (fabs(etaR)>1.5 && fabs(etaR)<=1.65)
00492             if (dEta>dEtaCut_1[index+1])
00493               {
00494                 if (ptR_front > 5) ptR_front = 5;
00495                 if (ptR_rear  > 5) ptR_rear  = 5;
00496               }
00497           
00498           if (fabs(etaR)>1.65 && fabs(etaR)<=2.1)
00499             if (dEta>dEtaCut_1[index+2] )
00500               {
00501                 if (ptR_front > 5) ptR_front = 5;
00502                 if (ptR_rear  > 5) ptR_rear  = 5;
00503               }
00504           if (fabs(etaR)>2.1)
00505             if (dEta>dEtaCut_1[index+3] )
00506               {
00507                 if (ptR_front > 5) ptR_front = 5;
00508                 if (ptR_rear  > 5) ptR_rear  = 5;
00509               }
00510         }
00511             
00512       break;
00513     
00514     case 8:
00515     case 9:
00516     case 10:
00517       
00518       
00519       // First remake the 12-bit dPhi word from the core
00520       remerged = (address.delta_phi_12 | (address.delta_phi_23 << 8 ) );
00521       // Now get 9-bit dPhi12 
00522       absPhi12 = ((1<<9)-1) & remerged; 
00523       // Now get 3-bit dEta
00524       dEta = ((1<<3)-1) & (remerged >> 9);
00525      
00526       dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00527 
00528       //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
00529       ptR_front = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R,  PtbyMLH, bestLH, 1, int(pt_method));
00530       ptR_rear  = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R,  PtbyMLH, bestLH, 0, int(pt_method));
00531 
00532       index = 0;
00533       if (mode == 8) index = 12;
00534       if (mode == 9) index = 16;
00535       if (mode == 10) index = 20;
00536 
00537       
00538       
00539       
00540       if (usedetaCUT)
00541         {
00542           if (fabs(etaR)>1.2 && fabs(etaR)<=1.5)
00543             if (dEta>dEtaCut_2[index+0] )
00544               {
00545                 if (ptR_front > 5) ptR_front = 5;
00546                 if (ptR_rear  > 5) ptR_rear  = 5;
00547               }
00548           if (fabs(etaR)>1.5 && fabs(etaR)<=1.65)
00549             if (dEta>dEtaCut_2[index+1])
00550               {
00551                 if (ptR_front > 5) ptR_front = 5;
00552                 if (ptR_rear  > 5) ptR_rear  = 5;
00553               }
00554           
00555           if (fabs(etaR)>1.65 && fabs(etaR)<=2.1)
00556             if (dEta>dEtaCut_2[index+2] )
00557               {
00558                 if (ptR_front > 5) ptR_front = 5;
00559                 if (ptR_rear  > 5) ptR_rear  = 5;
00560               }
00561           if (fabs(etaR)>2.1)
00562             if (dEta>dEtaCut_2[index+3] )
00563               {
00564                 if (ptR_front > 5) ptR_front = 5;
00565                 if (ptR_rear  > 5) ptR_rear  = 5;
00566               }
00567         }
00568             
00569       break;
00570     // for overlap DT-CSC region using curves from data 2010
00571     case 11: // FR = 1 -> b1-1-3,     FR = 0 -> b1-3 
00572     case 12: // FR = 1 -> b1-2-3,     FR = 0 -> b1-2 
00573     case 14: // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
00574     
00575       
00576     //sign definition: sign dphi12 = Phi_DT - Phi_CSC
00577     //                 sing dphi23 = 5th sign. bit of phiBend
00578     // -> charge = 1 -> dphi12 = +, phiBend = -
00579     // -> charge = 0 -> dphi12 = +, phiBend = +    
00580         charge12 = 1;
00581 
00582         // DT tracks are still using linear dPhi binning
00583         absPhi12 = address.delta_phi_12;
00584         absPhi23 = address.delta_phi_23;
00585 
00586         if(charge) charge23 = -1;
00587         else charge23 = 1;
00588 
00589         dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00590         dphi23R = float(absPhi23);
00591         if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00592 
00593         int mode1;
00594         mode1 = int(mode);
00595         if(fr == 1 && mode1 == 11) mode1 = 14; // 3 station track we use dphi12 and phiBend for 2 and 3 station track
00596 
00597         ptR_front = ptMethods.Pt3Stn2012_DT(mode1, etaR, dphi12R, dphi23R,  PtbyMLH, bestLH, int(0), int(pt_method));
00598         ptR_rear = ptMethods.Pt3Stn2012_DT(mode1, etaR, dphi12R, dphi23R,   PtbyMLH, bestLH, int(0), int(pt_method));
00599 
00600       break;
00601     case 15: // halo trigger
00602     case 1: // tracks that fail delta phi cuts
00603       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3); // 2 GeV
00604       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(3); 
00605       break;
00606     default: // Tracks in this category are not considered muons.
00607       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0); // 0 GeV 
00608       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(0);
00609     };// end switch
00610 
00611   front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
00612   rear_pt  = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
00613 
00614   } //end pt_methods 29
00615 
00616 
00617 //***************************************************//
00618   if(pt_method >= 23 && pt_method <= 28){ //here we have only pt_methods greater then 
00619                        //for fw 20110118 <- 2011 data taking, curves from MC like method 4
00620   // mode definition you could find at page 6 & 7: 
00621   // http://www.phys.ufl.edu/~madorsky/sp/2011-11-18/sp_core_interface.pdf 
00622   // it is valid starting the beggining of 2011 
00623   //std::cout << " pt_method = " << pt_method << std::endl;//test 
00624   switch(mode)
00625     {
00626     case 2:
00627     case 3:
00628     case 4:
00629     case 5:
00630 
00631       charge12 = 1;
00632       absPhi12 = address.delta_phi_12;
00633       absPhi23 = address.delta_phi_23;
00634 
00635       if(charge) charge23 = 1;
00636       else charge23 = -1;
00637 
00638       dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00639       dphi23R = (static_cast<float>(absPhi23<<4)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00640       if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00641 
00642       ptR_front = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12R, dphi23R, 1, int(pt_method));
00643       ptR_rear  = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12R, dphi23R, 0, int(pt_method));    
00644 
00645       if((pt_method == 24 || pt_method == 26 || pt_method == 28) && mode != 5 && etaR > 2.1)//exclude mode without ME11a
00646         {
00647             float dphi12Rmin = dphi12R - Pi*10/180/3; // 10/3 degrees 
00648             float dphi12Rmax = dphi12R + Pi*10/180/3; // 10/3 degrees
00649             float dphi23Rmin = dphi23R;
00650             float dphi23Rmax = dphi23R;
00651             //if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
00652             //if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
00653             float ptR_front_min = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
00654             float ptR_rear_min = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
00655             float ptR_front_max = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
00656             float ptR_rear_max = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
00657             // select max pt solution for 3 links:
00658             ptR_front = std::max(ptR_front, ptR_front_min);
00659             ptR_front = std::max(ptR_front, ptR_front_max);
00660             ptR_rear = std::max(ptR_rear, ptR_rear_min);
00661             ptR_rear = std::max(ptR_rear, ptR_rear_max);
00662         }
00663       break;
00664     case 6: // for mode 6, 7 and 13 add CLCT information in dph23 bit and iME11 in charge bit  
00665     case 7:
00666     case 13: // ME1-ME4
00667       int iME11;
00668       iME11 = int(charge); // = 0 if ME1/1, = 1 if ME1/2 or ME1/3 station 
00669       if(iME11 == 1 && etaR > 1.6) etaR = 1.55; // shift for ME1/2 station  
00670       if(iME11 == 0 && etaR < 1.6) etaR = 1.65; // shift for ME1/1 station 
00671       absPhi12 = address.delta_phi_12;
00672       //int CLCT_pattern = static_cast<int>(address.delta_phi_23);
00673       int CLCT_pattern;
00674       CLCT_pattern = int(address.delta_phi_23);
00675       dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00676 
00677       //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
00678       ptR_front = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 1, int(pt_method));
00679       ptR_rear  = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 0, int(pt_method));
00680       if((pt_method == 24 || pt_method == 26 || pt_method == 28) && etaR > 2.1)//exclude tracks without ME11a 
00681         {
00682            float dphi12Rmin = fabs(fabs(dphi12R) - Pi*10/180/3); // 10/3 degrees 
00683            float ptR_front_min = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12Rmin, 1, int(pt_method));
00684            float ptR_rear_min = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12Rmin, 0, int(pt_method));
00685            // select max pt solution for 3 links:
00686            ptR_front = std::max(ptR_front, ptR_front_min);
00687            ptR_rear = std::max(ptR_rear, ptR_rear_min);
00688         }
00689       if( ((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_front > 5.)) ptR_front = 5.;
00690       if( ((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_rear > 5.)) ptR_rear = 5.;
00691       //std::cout << "mode = "<< mode << " CLCT_pattern = " << CLCT_pattern << " ptR_rear = " << ptR_rear << std::endl;
00692 
00693       break;
00694     case 8:
00695     case 9:
00696     case 10:
00697       if(charge) absPhi12 = address.delta_phi();
00698       else
00699         {
00700           int temp_phi = address.delta_phi();
00701           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
00702         }
00703 
00704       dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00705 
00706       //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
00707       ptR_front = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 1, int(pt_method));
00708       ptR_rear  = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 0, int(pt_method));
00709 
00710       break;
00711     // for overlap DT-CSC region using curves from data 2010
00712     case 11: // FR = 1 -> b1-1-3,     FR = 0 -> b1-3 
00713     case 12: // FR = 1 -> b1-2-3,     FR = 0 -> b1-2 
00714     case 14: // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
00715 
00716     //sign definition: sign dphi12 = Phi_DT - Phi_CSC
00717     //                 sing dphi23 = 5th sign. bit of phiBend
00718     // -> charge = 1 -> dphi12 = +, phiBend = -
00719     // -> charge = 0 -> dphi12 = +, phiBend = +    
00720         charge12 = 1;
00721         absPhi12 = address.delta_phi_12;
00722         absPhi23 = address.delta_phi_23;
00723 
00724         if(charge) charge23 = -1;
00725         else charge23 = 1;
00726 
00727         dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00728         dphi23R = float(absPhi23);
00729         if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00730 
00731         int mode1;
00732         mode1 = int(mode);
00733         if(fr == 1 && mode1 == 11) mode1 = 14; // 3 station track we use dphi12 and phiBend for 2 and 3 station track
00734 
00735         ptR_front = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
00736         ptR_rear = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
00737 
00738       break;
00739     case 15: // halo trigger
00740     case 1: // tracks that fail delta phi cuts
00741       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3); // 2 GeV
00742       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(3); 
00743       break;
00744     default: // Tracks in this category are not considered muons.
00745       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0); // 0 GeV 
00746       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(0);
00747     };// end switch
00748 
00749   front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
00750   rear_pt  = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
00751 
00752   } //end pt_methods 23 - 28 
00753 
00754 //***************************************************//
00755 //***************************************************//
00756   if(pt_method == 21 || pt_method == 22){ //here we have only pt_methods greater then 
00757                        //for fw 20110118 <- 2011 data taking
00758   // mode definition you could find at page 6 & 7: 
00759   // http://www.phys.ufl.edu/~madorsky/sp/2011-11-18/sp_core_interface.pdf 
00760   // it is valid starting the beggining of 2011 
00761   switch(mode)
00762     {
00763     case 2:
00764     case 3:
00765     case 4:
00766     case 5:
00767 
00768       charge12 = 1;
00769       absPhi12 = address.delta_phi_12;
00770       absPhi23 = address.delta_phi_23;
00771 
00772       if(charge) charge23 = 1;
00773       else charge23 = -1;
00774 
00775       dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00776       dphi23R = (static_cast<float>(absPhi23<<4)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00777       if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00778 
00779       ptR_front = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12R, dphi23R, 1, int(pt_method));
00780       ptR_rear  = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12R, dphi23R, 0, int(pt_method));    
00781 
00782       if(pt_method == 22 && mode != 5 && etaR > 2.1)//exclude mode without ME11a
00783         {
00784             float dphi12Rmin = dphi12R - Pi*10/180/3; // 10/3 degrees 
00785             float dphi12Rmax = dphi12R + Pi*10/180/3; // 10/3 degrees
00786             float dphi23Rmin = dphi23R;
00787             float dphi23Rmax = dphi23R;
00788             //if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
00789             //if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
00790             float ptR_front_min = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
00791             float ptR_rear_min = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
00792             float ptR_front_max = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
00793             float ptR_rear_max = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
00794             // select max pt solution for 3 links:
00795             ptR_front = std::max(ptR_front, ptR_front_min);
00796             ptR_front = std::max(ptR_front, ptR_front_max);
00797             ptR_rear = std::max(ptR_rear, ptR_rear_min);
00798             ptR_rear = std::max(ptR_rear, ptR_rear_max);
00799         }
00800       break;
00801     case 6: // for mode 6, 7 and 13 add CLCT information in dph23 bit and iME11 in charge bit  
00802     case 7:
00803     case 13: // ME1-ME4
00804       int iME11;
00805       iME11 = int(charge);
00806       absPhi12 = address.delta_phi_12;
00807       //int CLCT_pattern = static_cast<int>(address.delta_phi_23);
00808       int CLCT_pattern;
00809       CLCT_pattern = int(address.delta_phi_23);
00810 
00811       dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00812 
00813       //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
00814       ptR_front = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 1, int(pt_method), iME11);
00815       ptR_rear  = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 0, int(pt_method), iME11);
00816       if((pt_method == 22) && etaR > 2.1)//exclude tracks without ME11a 
00817         {
00818            float dphi12Rmin = fabs(fabs(dphi12R) - Pi*10/180/3); // 10/3 degrees 
00819            float ptR_front_min = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12Rmin, 1, int(pt_method), iME11);
00820            float ptR_rear_min = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12Rmin, 0, int(pt_method), iME11);
00821            // select max pt solution for 3 links:
00822            ptR_front = std::max(ptR_front, ptR_front_min);
00823            ptR_rear = std::max(ptR_rear, ptR_rear_min);
00824         }
00825       if( ((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_front > 5.)) ptR_front = 5.;
00826       if( ((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_rear > 5.)) ptR_rear = 5.;
00827 
00828       break;
00829     case 8:
00830     case 9:
00831     case 10:
00832       if(charge) absPhi12 = address.delta_phi();
00833       else
00834         {
00835           int temp_phi = address.delta_phi();
00836           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
00837         }
00838 
00839       dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00840 
00841       //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
00842       ptR_front = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 1, int(pt_method), int(2));
00843       ptR_rear  = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 0, int(pt_method), int(2));
00844 
00845       break;
00846     case 11: // FR = 1 -> b1-1-3,     FR = 0 -> b1-3 
00847     case 12: // FR = 1 -> b1-2-3,     FR = 0 -> b1-2 
00848     case 14: // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
00849 
00850     //sign definition: sign dphi12 = Phi_DT - Phi_CSC
00851     //                 sing dphi23 = 5th sign. bit of phiBend
00852     // -> charge = 1 -> dphi12 = +, phiBend = -
00853     // -> charge = 0 -> dphi12 = +, phiBend = +    
00854         charge12 = 1;
00855         absPhi12 = address.delta_phi_12;
00856         absPhi23 = address.delta_phi_23;
00857 
00858         if(charge) charge23 = -1;
00859         else charge23 = 1;
00860 
00861         dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00862         dphi23R = float(absPhi23);
00863         if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00864 
00865         int mode1;
00866         mode1 = int(mode);
00867         if(fr == 1 && mode1 == 11) mode1 = 14; // 3 station track we use dphi12 and phiBend for 2 and 3 station track
00868 
00869         ptR_front = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
00870         ptR_rear = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
00871 
00872       break;
00873     case 15: // halo trigger
00874     case 1: // tracks that fail delta phi cuts
00875       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3); // 2 GeV
00876       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(3); 
00877       break;
00878     default: // Tracks in this category are not considered muons.
00879       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0); // 0 GeV 
00880       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(0);
00881     };// end switch
00882 
00883   front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
00884   rear_pt  = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
00885 
00886   } //end pt_methods greater or equal to 21 
00887 
00888 //***************************************************//
00889 //***************************************************//
00890   if(pt_method >= 11 && pt_method < 20){ //here we have only pt_methods greater or equal to 11 
00891                        //for fw 20101011 <- 2011 data taking
00892   // mode definition you could find at page 6 & 7: 
00893   // http://www.phys.ufl.edu/~madorsky/sp/2010-10-11/sp_core_interface.pdf 
00894   // it is valid starting the beggining of 2011 
00895   switch(mode)
00896     {
00897     case 2:
00898     case 3:
00899     case 4:
00900     case 5:
00901 
00902       charge12 = 1;
00903       absPhi12 = address.delta_phi_12;
00904       absPhi23 = address.delta_phi_23;
00905 
00906       if(charge) charge23 = 1;
00907       else charge23 = -1;
00908 
00909       dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00910       dphi23R = (static_cast<float>(absPhi23<<4)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00911       if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00912 
00913       ptR_front = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 1, int(pt_method));
00914       ptR_rear  = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 0, int(pt_method));    
00915 
00916       if(pt_method == 12 && mode != 5 && etaR > 2.1)//exclude mode without ME11a
00917         {
00918             float dphi12Rmin = dphi12R - Pi*10/180/3; // 10/3 degrees 
00919             float dphi12Rmax = dphi12R + Pi*10/180/3; // 10/3 degrees
00920             float dphi23Rmin = dphi23R;
00921             float dphi23Rmax = dphi23R;
00922             if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
00923             if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
00924             float ptR_front_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
00925             float ptR_rear_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
00926             float ptR_front_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
00927             float ptR_rear_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
00928             // select max pt solution for 3 links:
00929             ptR_front = std::max(ptR_front, ptR_front_min);
00930             ptR_front = std::max(ptR_front, ptR_front_max);
00931             ptR_rear = std::max(ptR_rear, ptR_rear_min);
00932             ptR_rear = std::max(ptR_rear, ptR_rear_max);
00933         }
00934       break;
00935     case 6:
00936     case 7:
00937     case 8:
00938     case 9:
00939     case 10:
00940     case 13: // ME1-ME4
00941       type = mode - 5;
00942 
00943       if(charge) absPhi12 = address.delta_phi();
00944       else
00945         {
00946           int temp_phi = address.delta_phi();
00947           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
00948         }
00949 
00950       dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00951 
00952       //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
00953       ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
00954       ptR_rear  = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
00955       if((pt_method == 12) && etaR > 2.1 && mode != 8 && mode !=9 && mode !=10)//exclude tracks without ME11a 
00956         {
00957            float dphi12Rmin = fabs(fabs(dphi12R) - Pi*10/180/3); // 10/3 degrees 
00958            float ptR_front_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 1, int(pt_method));
00959            float ptR_rear_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 0, int(pt_method));
00960            // select max pt solution for 3 links:
00961            ptR_front = std::max(ptR_front, ptR_front_min);
00962            ptR_rear = std::max(ptR_rear, ptR_rear_min);
00963         }
00964 
00965       break;
00966     case 11: // FR = 1 -> b1-1-3,     FR = 0 -> b1-3 
00967     case 12: // FR = 1 -> b1-2-3,     FR = 0 -> b1-2 
00968     case 14: // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
00969 
00970       if(fr == 0){ // 2 station track
00971         if(charge) absPhi12 = address.delta_phi();
00972         else
00973           {
00974             int temp_phi = address.delta_phi();
00975             absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
00976           }
00977           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00978           ptR_rear  = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
00979 
00980       }// end fr == 0
00981       if(fr == 1){ // 3 station track
00982         charge12 = 1;
00983         absPhi12 = address.delta_phi_12;
00984         absPhi23 = address.delta_phi_23;
00985 
00986         if(charge) charge23 = 1;
00987         else charge23 = -1;
00988 
00989         dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00990         dphi23R = (static_cast<float>(absPhi23<<4)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00991         if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00992 
00993         ptR_front = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 1, int(pt_method));
00994 
00995         if(pt_method == 12 && mode != 5 && etaR > 2.1)//exclude mode without ME11a
00996           {
00997               float dphi12Rmin = dphi12R - Pi*10/180/3; // 10/3 degrees 
00998               float dphi12Rmax = dphi12R + Pi*10/180/3; // 10/3 degrees
00999               float dphi23Rmin = dphi23R;
01000               float dphi23Rmax = dphi23R;
01001               if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
01002               if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
01003               float ptR_front_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
01004               float ptR_front_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
01005               // select max pt solution for 3 links:
01006               ptR_front = std::max(ptR_front, ptR_front_min);
01007               ptR_front = std::max(ptR_front, ptR_front_max);
01008           }
01009       } // end fr == 1 
01010 
01011       break;
01012     case 15: // halo trigger
01013     case 1: // tracks that fail delta phi cuts
01014       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3); // 2 GeV
01015       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(3); 
01016       break;
01017     default: // Tracks in this category are not considered muons.
01018       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0); // 0 GeV 
01019       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(0);
01020     };// end switch
01021 
01022   front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
01023   rear_pt  = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
01024 
01025   } //end pt_methods greater or equal to 11 
01026 //***************************************************//
01027   if(pt_method <= 5){ //here we have only pt_methods less or equal to 5
01028   // mode definition you could find at https://twiki.cern.ch/twiki/pub/Main/PtLUTs/mode_codes.xls
01029   // it is valid till the end 2010 
01030 
01031   //  kluge to use 2-stn track in overlap region
01032   //  see also where this routine is called, and encode LUTaddress, and assignPT
01033   if (pt_method != 4 && pt_method !=5 
01034       && (mode == 2 || mode == 3 || mode == 4) && (eta<3)) mode = 6;
01035   if (pt_method != 4 && pt_method !=5 && (mode == 5)
01036       && (eta<3)) mode = 8;
01037 
01038   switch(mode)
01039     {
01040     case 2:
01041     case 3:
01042     case 4:
01043     case 5:
01044       type = mode - 1;
01045       charge12 = 1;
01046       absPhi12 = address.delta_phi_12;
01047       absPhi23 = address.delta_phi_23;
01048 
01049       if(charge) charge23 = 1;
01050       else charge23 = -1;
01051 
01052       // now convert to real numbers for input into PT assignment algos.
01053 
01054       if(pt_method == 4 || pt_method == 5) // param method 2010
01055         {
01056           dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01057           dphi23R = (static_cast<float>(absPhi23<<4)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01058           if(charge12 * charge23 < 0) dphi23R = -dphi23R;
01059 
01060           ptR_front = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 1, int(pt_method));
01061           ptR_rear  = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 0, int(pt_method));
01062 
01063           if(pt_method == 5 && mode != 5 && etaR > 2.1)//exclude mode without ME11a
01064             {
01065                 float dphi12Rmin = dphi12R - Pi*10/180/3; // 10/3 degrees 
01066                 float dphi12Rmax = dphi12R + Pi*10/180/3; // 10/3 degrees
01067                 float dphi23Rmin = dphi23R;
01068                 float dphi23Rmax = dphi23R;
01069                 if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
01070                 if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
01071                 float ptR_front_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
01072                 float ptR_rear_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
01073                 float ptR_front_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
01074                 float ptR_rear_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
01075                 // select max pt solution for 3 links:
01076                 ptR_front = std::max(ptR_front, ptR_front_min);
01077                 ptR_front = std::max(ptR_front, ptR_front_max);
01078                 ptR_rear = std::max(ptR_rear, ptR_rear_min);
01079                 ptR_rear = std::max(ptR_rear, ptR_rear_max);
01080             }
01081         }
01082       else if(pt_method == 1) // param method
01083         {
01084           dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01085           dphi23R = (static_cast<float>(absPhi23<<4)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01086           if(charge12 * charge23 < 0) dphi23R = -dphi23R;
01087 
01088           ptR_front = ptMethods.Pt3Stn(type, etaR, dphi12R, dphi23R, 1);
01089           ptR_rear  = ptMethods.Pt3Stn(type, etaR, dphi12R, dphi23R, 0);
01090 
01091         }
01092       else if(pt_method == 2) // cathy's method
01093         {
01094           if(type <= 2)
01095             {
01096               ptR_front = ptMethods.Pt3StnChiSq(type+3, etaR, absPhi12<<1, ((charge == 0) ? -(absPhi23<<4) : (absPhi23<<4)), 1);
01097               ptR_rear  = ptMethods.Pt3StnChiSq(type+3, etaR, absPhi12<<1, ((charge == 0) ? -(absPhi23<<4) : (absPhi23<<4)), 0);
01098             }
01099           else
01100             {
01101               ptR_front = ptMethods.Pt2StnChiSq(type-2, etaR, absPhi12<<1, 1);
01102               ptR_rear  = ptMethods.Pt2StnChiSq(type-2, etaR, absPhi12<<1, 0);
01103             }
01104 
01105         }
01106       else // hybrid
01107         {
01108 
01109           if(type <= 2)
01110             {
01111               ptR_front = ptMethods.Pt3StnHybrid(type+3, etaR, absPhi12<<1, ((charge == 0) ? -(absPhi23<<4) : (absPhi23<<4)), 1);
01112               ptR_rear  = ptMethods.Pt3StnHybrid(type+3, etaR, absPhi12<<1, ((charge == 0) ? -(absPhi23<<4) : (absPhi23<<4)), 0);
01113             }
01114           else
01115             {
01116               ptR_front = ptMethods.Pt2StnHybrid(type-2, etaR, absPhi12<<1, 1);
01117               ptR_rear  = ptMethods.Pt2StnHybrid(type-2, etaR, absPhi12<<1, 0);
01118             }
01119 
01120         }
01121       break;
01122     case 6:
01123     case 7:
01124     case 8:
01125     case 9:
01126     case 10:
01127       type = mode - 5;
01128 
01129       if(charge) absPhi12 = address.delta_phi();
01130       else
01131         {
01132           int temp_phi = address.delta_phi();
01133           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
01134         }
01135 
01136       if(absPhi12 < (1<<9))
01137         {
01138           if(pt_method == 1 || type == 5)
01139             {
01140               dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01141 
01142               ptR_front = ptMethods.Pt2Stn(type, etaR, dphi12R, 1);
01143               ptR_rear  = ptMethods.Pt2Stn(type, etaR, dphi12R, 0);
01144 
01145             }
01146           else if(pt_method == 2)
01147             {
01148               ptR_front = ptMethods.Pt2StnChiSq(type-1, etaR, absPhi12, 1);
01149               ptR_rear  = ptMethods.Pt2StnChiSq(type-1, etaR, absPhi12, 0);
01150             }
01151           else
01152             {
01153               ptR_front = ptMethods.Pt2StnHybrid(type-1, etaR, absPhi12, 1);
01154               ptR_rear  = ptMethods.Pt2StnHybrid(type-1, etaR, absPhi12, 0);
01155             }
01156         }
01157       else
01158         {
01159           ptR_front = trigger_ptscale->getPtScale()->getLowEdge(1);
01160           ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(1);
01161         }
01162       if(pt_method == 4 || pt_method == 5) // param method 2010
01163         {
01164               dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01165 
01166               //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
01167               ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
01168               ptR_rear  = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
01169               if((pt_method == 5) && etaR > 2.1 && mode != 8 && mode !=9 && mode !=10)//exclude tracks without ME11a 
01170                 {
01171                    float dphi12Rmin = fabs(fabs(dphi12R) - Pi*10/180/3); // 10/3 degrees 
01172                    float ptR_front_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 1, int(pt_method));
01173                    float ptR_rear_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 0, int(pt_method));
01174                    // select max pt solution for 3 links:
01175                    ptR_front = std::max(ptR_front, ptR_front_min);
01176                    ptR_rear = std::max(ptR_rear, ptR_rear_min);
01177                 }
01178         }
01179 
01180       break;
01181     case 12:  // 1-2-b1 calculated only delta_phi12 = 2-b1
01182     case 14:
01183       type = 2;
01184 
01185       if(charge) absPhi12 = address.delta_phi();
01186       else
01187         {
01188           int temp_phi = address.delta_phi();
01189           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
01190         }
01191       if(absPhi12 < (1<<9))
01192         {
01193           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01194           ptR_front = ptMethods.Pt2Stn(type, etaR, dphi12R, 1);
01195           ptR_rear  = ptMethods.Pt2Stn(type, etaR, dphi12R, 0);
01196         }
01197       else
01198         {
01199           ptR_front = trigger_ptscale->getPtScale()->getLowEdge(1);
01200           ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(1);
01201         }
01202       if(pt_method == 4 || pt_method == 5) // param method 2010 
01203         {
01204               dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01205 
01206               ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
01207               ptR_rear  = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
01208 
01209               if(fabs(dphi12R)<0.01 && (ptR_rear < 10 || ptR_front < 10))
01210                 std::cout << "dphi12R = " << dphi12R << " ptR_rear = " << ptR_rear
01211                 << " ptR_front = " << ptR_front << " etaR = " << etaR << " mode = " << mode << std::endl;
01212         }
01213       break;
01214     case 13:
01215       type = 4;
01216 
01217       if(charge) absPhi12 = address.delta_phi();
01218       else
01219         {
01220           int temp_phi = address.delta_phi();
01221           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
01222         }
01223       if(absPhi12 < (1<<9))
01224         {
01225           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01226           ptR_front = ptMethods.Pt2Stn(type, etaR, dphi12R, 1);
01227           ptR_rear  = ptMethods.Pt2Stn(type, etaR, dphi12R, 0);
01228         }
01229       else
01230         {
01231           ptR_front = trigger_ptscale->getPtScale()->getLowEdge(1);
01232           ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(1);
01233         }
01234 
01235       if(pt_method == 4 || pt_method == 5) // param method 2010
01236         {
01237               dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01238 
01239               ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
01240               ptR_rear  = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
01241               if((pt_method == 5) && etaR > 2.1)//mode = 13: ME1-ME4 exclude tracks without ME11a 
01242                 {
01243                    float dphi12Rmin = fabs(fabs(dphi12R) - Pi*10/180/3); // 10/3 degrees 
01244                    float ptR_front_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 1, int(pt_method));
01245                    float ptR_rear_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 0, int(pt_method));
01246                    // select max pt solution for 3 links:
01247                    ptR_front = std::max(ptR_front, ptR_front_min);
01248                    ptR_rear = std::max(ptR_rear, ptR_rear_min);
01249                 }
01250         }
01251 
01252       break;
01253     case 11:
01254       // singles trigger
01255       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(5);
01256       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(5);
01257       //ptR_front = trigger_ptscale->getPtScale()->getLowEdge(31);
01258       //ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(31);
01259       break;
01260     case 15:
01261       // halo trigger
01262       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(5);
01263       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(5);
01264       break;
01265     case 1:
01266       // tracks that fail delta phi cuts
01267       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(5);
01268       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(5); 
01269      break;
01270     default: // Tracks in this category are not considered muons.
01271       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0);
01272       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(0);
01273     };
01274 
01275   front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
01276   rear_pt  = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
01277 
01278   // kluge to set arbitrary Pt for some tracks with lousy resolution (and no param)
01279   if(pt_method != 4 && pt_method != 5) 
01280     {
01281       if ((front_pt==0 || front_pt==1) && (eta<3) && quality==1 && pt_method != 2) front_pt = 31;
01282       if ((rear_pt==0  || rear_pt==1) && (eta<3) && quality==1 && pt_method != 2) rear_pt = 31;
01283     }
01284   if(pt_method != 2 && pt_method != 4 && quality == 1)
01285     {
01286       if (front_pt < 5) front_pt = 5;
01287       if (rear_pt  < 5) rear_pt  = 5;
01288     }
01289 
01290   // in order to match the pt assignement of the previous routine
01291   if(isBeamStartConf && pt_method != 2 && pt_method != 4 && pt_method !=5) {
01292     if(quality == 3 && mode == 5) {
01293       
01294       if (front_pt < 5) front_pt = 5;
01295       if (rear_pt  < 5) rear_pt  = 5;
01296     }
01297 
01298     if(quality == 2 && mode > 7 && mode < 11) {
01299       
01300       if (front_pt < 5) front_pt = 5;
01301       if (rear_pt  < 5) rear_pt  = 5;
01302     }
01303   }
01304 
01305   } // end if for pt_method less or equal to 5
01306 //***************************************************//
01307 
01308  
01309   result.front_rank = front_pt | front_quality << 5;
01310   result.rear_rank  = rear_pt  | rear_quality << 5;
01311 
01312   result.charge_valid_front = 1; //ptMethods.chargeValid(front_pt, quality, eta, pt_method);
01313   result.charge_valid_rear  = 1; //ptMethods.chargeValid(rear_pt, quality, eta, pt_method);
01314 
01315 
01316   /*  if (mode == 1) { 
01317     std::cout << "F_pt: "      << front_pt      << std::endl;
01318     std::cout << "R_pt: "      << rear_pt       << std::endl;
01319     std::cout << "F_quality: " << front_quality << std::endl;
01320     std::cout << "R_quality: " << rear_quality  << std::endl;
01321     std::cout << "F_rank: " << std::hex << result.front_rank << std::endl;
01322     std::cout << "R_rank: " << std::hex << result.rear_rank  << std::endl;
01323   }
01324   */
01325   return result;
01326 }
01327 
01328 
01329 unsigned CSCTFPtLUT::trackQuality(const unsigned& eta, const unsigned& mode, const unsigned& fr) const
01330 {
01331  // eta and mode should be only 4-bits, since that is the input to the large LUT
01332     if (eta>15 || mode>15)
01333       {
01334         //std::cout << "Error: Eta or Mode out of range in AU quality assignment" << std::endl;
01335         edm::LogError("CSCTFPtLUT::trackQuality()")<<"Eta or Mode out of range in AU quality assignment";
01336         return 0;
01337       }
01338     unsigned int quality;
01339     switch (mode) {
01340     case 2:
01341       quality = 3;
01342       if(pt_method > 10 && eta < 3) quality = 1; //eta < 1.2
01343       if(pt_method == 32 && eta >= 12) quality = 2; // eta > 2.1  
01344       break;
01345     case 3:
01346     case 4:
01348       //        quality = 2;
01349       quality = 3;
01350       if(pt_method == 32 && eta >= 12) quality = 2; // eta > 2.1  
01351       break;
01352     case 5:
01353       quality = 1;
01354       if (isBeamStartConf && eta >= 12 && pt_method < 20) // eta > 2.1
01355         quality = 3;
01356       if(pt_method == 27 || pt_method == 28 || pt_method == 29 || pt_method == 32 || pt_method == 30 || pt_method == 33) quality = 3;// all mode = 5 set to quality 3 due to a lot dead ME1/1a stations
01357       break;
01358     case 6:
01359       if (eta>=3) // eta > 1.2
01360         quality = 2;
01361       else
01362         quality = 1;
01363       if(pt_method == 32 && eta >= 12) quality = 1; // eta > 2.1  
01364       break;
01365     case 7:
01366       quality = 2;
01367       if(pt_method > 10 && eta < 3) quality = 1; //eta < 1.2  
01368       if(pt_method == 32 && eta >= 12) quality = 1; // eta > 2.1  
01369       break;
01370     case 8:
01371     case 9:
01372     case 10:
01373       quality = 1;
01374       if (isBeamStartConf && eta >= 12 && pt_method < 20) // eta > 2.1
01375         quality = 2;
01376       if((pt_method == 27 || pt_method == 28 || pt_method == 30) && (eta >= 7 && eta < 9)) quality = 2; //set to quality 2 for eta = 1.6-1.8 due to a lot dead ME1/1a stations
01377       break;
01378     case 11:
01379       // single LCTs
01380       quality = 1;
01381       // overlap region
01382       if(pt_method > 10 && fr == 0) quality = 2;
01383       if(pt_method > 10 && fr == 1) quality = 3;
01384       if(pt_method > 20 && fr == 0) quality = 3;
01385       break;
01386     case 12:
01387       quality = 3;
01388       // overlap region
01389       if(pt_method > 10 && fr == 0) quality = 2;
01390       if(pt_method > 10 && fr == 1) quality = 3;
01391       if(pt_method > 20 && fr == 0) quality = 3;
01392       break;
01393     case 13:
01394       quality = 2;
01395       if(pt_method == 32 && eta >= 12) quality = 1; // eta > 2.1  
01396       break;
01397     case 14:
01398       quality = 2;
01399       // overlap region
01400       if(pt_method > 10 && fr == 0) quality = 2;
01401       if(pt_method > 10 && fr == 1) quality = 3;
01402       if(pt_method > 20 && fr == 0) quality = 3;
01403       break;
01404     case 15:
01405       // halo triggers
01406       quality = 1;
01407       break;
01408       //DEA: keep muons that fail delta phi cut
01409     case 1:
01410       quality = 1;
01411       break;
01412     default:
01413       quality = 0;
01414       break;
01415     }
01416 
01417     // allow quality = 1 only in overlap region or eta = 1.6 region
01418     //    if ((quality == 1) && (eta >= 4) && (eta != 6) && (eta != 7)) quality = 0;
01419     //    if ( (quality == 1) && (eta >= 4) ) quality = 0;
01420 
01421     if ( (quality == 1) && (eta >= 4) && (eta < 11)
01422          && ((lowQualityFlag&4)==0) ) quality = 0;
01423     if ( (quality == 1) && (eta < 4) && ((lowQualityFlag&1)==0)
01424          && ((lowQualityFlag&4)==0) ) quality = 0;
01425     if ( (quality == 1) && (eta >=11) && ((lowQualityFlag&2)==0)
01426          && ((lowQualityFlag&4)==0) ) quality = 0;
01427 
01428     return quality;
01429 
01430 }
01431 
01432 void CSCTFPtLUT::readLUT()
01433 {
01434   std::ifstream PtLUT;
01435 
01436   if(isBinary)
01437     {
01438       PtLUT.open(pt_lut_file.fullPath().c_str(), std::ios::binary);
01439       PtLUT.seekg(0, std::ios::end);
01440       int length = PtLUT.tellg();;
01441       if( length == (1<<CSCBitWidths::kPtAddressWidth)*sizeof(short) )
01442         {
01443           PtLUT.seekg(0, std::ios::beg);
01444           PtLUT.read(reinterpret_cast<char*>(pt_lut),length);
01445         }
01446       else
01447         {
01448           edm::LogError("CSCPtLUT") << "File " << pt_lut_file.fullPath() << " is incorrect size!\n";
01449         }
01450       PtLUT.close();
01451     }
01452   else
01453     {
01454       PtLUT.open(pt_lut_file.fullPath().c_str());
01455       unsigned i = 0;
01456       unsigned short temp = 0;
01457       while(!PtLUT.eof() && i < 1 << CSCBitWidths::kPtAddressWidth)
01458         {
01459           PtLUT >> temp;
01460           pt_lut[i++] = (*reinterpret_cast<ptdat*>(&temp));
01461         }
01462       PtLUT.close();
01463     }
01464 }
01465 
01466