CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/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     ptdat tmp( theL1MuCSCPtLut_->pt(shortAdd) );
00179   
00180     result = tmp;
00181   } 
00182   
00183   else if (read_pt_lut_file)
00184     {
00185       int shortAdd = (address.toint()& 0x1fffff);
00186       result = pt_lut[shortAdd];
00187     } 
00188   
00189   else
00190     result = calcPt(address);
00191 
00192   return result;
00193 }
00194 
00195 ptdat CSCTFPtLUT::Pt(const unsigned& address) const
00196 {
00197   return Pt(ptadd(address));
00198 }
00199 
00200 ptdat CSCTFPtLUT::Pt(const unsigned& delta_phi_12, const unsigned& delta_phi_23,
00201                      const unsigned& track_eta, const unsigned& track_mode,
00202                      const unsigned& track_fr, const unsigned& delta_phi_sign) const
00203 {
00204   ptadd address;
00205   address.delta_phi_12 = delta_phi_12;
00206   address.delta_phi_23 = delta_phi_23;
00207   address.track_eta = track_eta;
00208   address.track_mode = track_mode;
00209   address.track_fr = track_fr;
00210   address.delta_phi_sign = delta_phi_sign;
00211 
00212   return Pt(address);
00213 }
00214 
00215 ptdat CSCTFPtLUT::Pt(const unsigned& delta_phi_12, const unsigned& track_eta,
00216                      const unsigned& track_mode, const unsigned& track_fr,
00217                      const unsigned& delta_phi_sign) const
00218 {
00219   ptadd address;
00220   address.delta_phi_12 = ((1<<8)-1)&delta_phi_12;
00221   address.delta_phi_23 = ((1<<4)-1)&(delta_phi_12>>8);
00222   address.track_eta = track_eta;
00223   address.track_mode = track_mode;
00224   address.track_fr = track_fr;
00225   address.delta_phi_sign = delta_phi_sign;
00226 
00227   return Pt(address);
00228 }
00229 
00230 
00231 ptdat CSCTFPtLUT::calcPt(const ptadd& address) const
00232 {
00233   ptdat result;
00234 
00235   double Pi  = acos(-1.);
00236   float etaR = 0, ptR_front = 0, ptR_rear = 0, dphi12R = 0, dphi23R = 0;
00237   int charge12, charge23;
00238   unsigned type, mode, eta, fr, quality, charge, absPhi12, absPhi23;
00239 
00240   mode = address.track_mode;
00241    
00242   int usedetaCUT = true;
00243   // Chose Eta cut tightness. 1=tightest, 2=moderate, 3=loose, 4=very loose, 5=extremely loose, 6=open
00244 
00245   // modes 6, 7, 13
00246   int EtaCutLevel_1 = 2;
00247   int dEtaCut_1[24];
00248   
00249   for (int i=0;i<24;i++)
00250     {
00251       dEtaCut_1[i] = 10;
00252       if (EtaCutLevel_1 == 1)
00253         dEtaCut_1[i] = dEtaCut_Low[i];
00254       else if (EtaCutLevel_1 == 2)
00255         dEtaCut_1[i] = dEtaCut_Mid[i];
00256       else if (EtaCutLevel_1 == 3)
00257         dEtaCut_1[i] = dEtaCut_High_A[i];
00258       else if (EtaCutLevel_1 == 4)
00259         dEtaCut_1[i] = dEtaCut_High_B[i];
00260       else if (EtaCutLevel_1 == 5)
00261         dEtaCut_1[i] = dEtaCut_High_C[i];
00262       else if (EtaCutLevel_1 == 6)
00263         dEtaCut_1[i] = dEtaCut_Open[i];
00264     }
00265   // modes 8, 9, 10
00266   int EtaCutLevel_2 = 2;
00267   int dEtaCut_2[24];
00268   
00269   for (int i=0;i<24;i++)
00270     {
00271       dEtaCut_2[i] = 10;
00272       if (EtaCutLevel_2 == 1)
00273         dEtaCut_2[i] = dEtaCut_Low[i];
00274       else if (EtaCutLevel_2 == 2)
00275         dEtaCut_2[i] = dEtaCut_Mid[i];
00276       else if (EtaCutLevel_2 == 3)
00277         dEtaCut_2[i] = dEtaCut_High_A[i];
00278       else if (EtaCutLevel_2 == 4)
00279         dEtaCut_2[i] = dEtaCut_High_B[i];
00280       else if (EtaCutLevel_2 == 5)
00281         dEtaCut_2[i] = dEtaCut_High_C[i];
00282       else if (EtaCutLevel_2 == 6)
00283         dEtaCut_2[i] = dEtaCut_Open[i];
00284 
00285       float scalef = 1.0;
00286       if (mode == 8 || mode == 10)
00287         dEtaCut_2[i] = scalef*dEtaCut_2[i];
00288       
00289     }
00290   
00291   
00292 
00293   eta = address.track_eta;
00294  
00295   fr = address.track_fr;
00296   charge = address.delta_phi_sign;
00297   quality = trackQuality(eta, mode, fr);
00298   unsigned front_pt, rear_pt;
00299   front_pt = 0.; rear_pt = 0.;
00300   unsigned front_quality, rear_quality;
00301 
00302   etaR = trigger_scale->getRegionalEtaScale(2)->getLowEdge(2*eta+1);
00303 
00304   front_quality = rear_quality = quality;
00305 
00306   unsigned int remerged;
00307   int iME11;
00308   int CLCT_pattern;
00309   int dEta;
00310   int index = 0;
00311   float bestLH = -999;
00312  float bestLH_front = -999.0;
00313  float bestLH_rear = -999.0;
00314 
00315  int PtbyMLH = false;
00316   
00317   //***************************************************//
00318   if(pt_method >= 29 && pt_method <= 33)
00319     {
00320         // using fw 2012_01_31. Switch to Global Log(L). Non-Linear dphi binning.
00321       PtbyMLH = 0x1 & (getPtbyMLH >> (int)mode);
00323       // switch off any improvment for eta > 2.1
00324       if(etaR > 2.1){
00325          usedetaCUT = false;
00326          PtbyMLH = 0x0;
00327       }
00329       
00330       switch(mode)
00331         {
00332         case 2:
00333         case 3:
00334         case 4:
00335         case 5:
00336   
00337       
00338       charge12 = 1;
00339 
00340       // First remake the 12-bit dPhi word from the core
00341       remerged = (address.delta_phi_12 | (address.delta_phi_23 << 8 ) );
00342       
00343       // Now separate it into 7-bit dPhi12 and 5-bit dPhi23 parts
00344       absPhi12 = ((1<<7)-1) &  remerged; 
00345       absPhi23 = ((1<<5)-1) & (remerged >> 7);
00346 
00347       // Now get the corresponding dPhi value in our phi-units using the inverse dPhi LUTs
00348       absPhi12 = dPhiNLBMap_7bit[absPhi12];
00349       absPhi23 = dPhiNLBMap_5bit[absPhi23];
00350 
00351       if(charge) charge23 = 1;
00352       else charge23 = -1;
00353 
00354       dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00355       dphi23R = (static_cast<float>(absPhi23)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00356       if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00357 
00358       ptR_front = ptMethods.Pt3Stn2012(int(mode), etaR, dphi12R, dphi23R, PtbyMLH, bestLH, 1, int(pt_method));
00359       bestLH_front = bestLH;
00360       ptR_rear  = ptMethods.Pt3Stn2012(int(mode), etaR, dphi12R, dphi23R, PtbyMLH, bestLH, 0, int(pt_method));    
00361       bestLH_rear = bestLH;
00362       
00363       if((pt_method == 29 || pt_method == 32 || pt_method == 30 || pt_method == 31) && mode != 5 && etaR > 2.1)//exclude mode without ME11a
00364         {
00365             float dphi12Rmin = dphi12R - Pi*10/180/3; // 10/3 degrees 
00366             float dphi12Rmax = dphi12R + Pi*10/180/3; // 10/3 degrees
00367             float dphi23Rmin = dphi23R;
00368             float dphi23Rmax = dphi23R;
00369             //if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
00370             //if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
00371             float ptR_front_min = ptMethods.Pt3Stn2012(int(mode), etaR, dphi12Rmin, dphi23Rmin, PtbyMLH, bestLH, 1, int(pt_method));
00372             float bestLH_front_min = bestLH;
00373             float ptR_rear_min = ptMethods.Pt3Stn2012(int(mode), etaR, dphi12Rmin, dphi23Rmin,  PtbyMLH, bestLH, 0, int(pt_method));
00374             float bestLH_rear_min = bestLH;
00375             float ptR_front_max = ptMethods.Pt3Stn2012(int(mode), etaR, dphi12Rmax, dphi23Rmax, PtbyMLH, bestLH, 1, int(pt_method));
00376             float bestLH_front_max = bestLH;
00377             float ptR_rear_max = ptMethods.Pt3Stn2012(int(mode), etaR, dphi12Rmax, dphi23Rmax,  PtbyMLH, bestLH, 0, int(pt_method));
00378             float bestLH_rear_max = bestLH;
00379 
00380             if (PtbyMLH)
00381               {
00382                 float best_pt_front = ptR_front;
00383                 float best_LH_front = bestLH_front;
00384                 if (bestLH_front_min > best_LH_front)
00385                   {
00386                     best_pt_front = ptR_front_min;
00387                     best_LH_front = bestLH_front_min;
00388                   }
00389                 if (bestLH_front_max > best_LH_front)
00390                   {
00391                     best_pt_front = ptR_front_max;
00392                     best_LH_front = bestLH_front_max;
00393                   }
00394                 ptR_front = best_pt_front;
00395 
00396                 float best_pt_rear = ptR_rear;
00397                 float best_LH_rear = bestLH_rear;
00398                 if (bestLH_rear_min > best_LH_rear)
00399                   {
00400                     best_pt_rear = ptR_rear_min;
00401                     best_LH_rear = bestLH_rear_min;
00402                   }
00403                 if (bestLH_rear_max > best_LH_rear)
00404                   {
00405                     best_pt_rear = ptR_rear_max;
00406                     best_LH_rear = bestLH_rear_max;
00407                   }
00408                 ptR_rear = best_pt_rear;
00409               }
00410             else
00411               {
00412                 // select max pt solution for 3 links:
00413                 ptR_front = std::max(ptR_front, ptR_front_min);
00414                 ptR_front = std::max(ptR_front, ptR_front_max);
00415                 ptR_rear = std::max(ptR_rear, ptR_rear_min);
00416                 ptR_rear = std::max(ptR_rear, ptR_rear_max);
00417               }
00418         }
00419       break;
00420     case 6: // for mode 6, 7 and 13 add CLCT information in dph23 bit and iME11 in charge bit   
00421     case 7:
00422     case 13: // ME1-ME4
00423       
00424       // First remake the 12-bit dPhi word from the core
00425       remerged = (address.delta_phi_12 | (address.delta_phi_23 << 8 ) );
00426       // Now get 8-bit dPhi12 
00427       absPhi12 = ((1<<8)-1) & remerged; 
00428       // Now get 3-bit dEta
00429       dEta = ((1<<3)-1) & (remerged >> 8);
00430       // New get CLCT bit. CLCT = true if CLCTPattern = 8, 9, or 10, else 0.
00431       CLCT_pattern = 0x1 & (remerged >> 11);
00432       
00433       iME11 = int(charge); // = 0 if ME1/1, = 1 if ME1/2 or ME1/3 station 
00434       if(iME11 == 1 && etaR > 1.6) etaR = 1.55; // shift for ME1/2 station  
00435       if(iME11 == 0 && etaR < 1.6) etaR = 1.65; // shift for ME1/1 station
00436 
00437       // Get the 8-bit dPhi bin number  
00438       absPhi12 = ((1<<8)-1) & address.delta_phi_12;
00439       
00440       // Now get the corresponding dPhi value in our phi-units using the inverse dPhi LUTs
00441       absPhi12 = dPhiNLBMap_8bit[absPhi12];
00442       
00443       //int CLCT_pattern = static_cast<int>(address.delta_phi_23);
00444     
00445       dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00446       
00447       //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
00448       ptR_front = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R, PtbyMLH, bestLH, 1, int(pt_method));
00449       bestLH_front = bestLH;
00450       ptR_rear  = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R, PtbyMLH, bestLH, 0, int(pt_method));
00451       bestLH_rear = bestLH;
00452       if((pt_method == 29 || pt_method == 32 || pt_method == 30 || pt_method == 31) && etaR > 2.1)//exclude tracks without ME11a 
00453         {
00454           float dphi12Rmin = fabs(fabs(dphi12R) - Pi*10/180/3); // 10/3 degrees 
00455           float ptR_front_min = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12Rmin,  PtbyMLH, bestLH, 1, int(pt_method));
00456           float bestLH_front_min = bestLH;
00457           float ptR_rear_min = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12Rmin,   PtbyMLH, bestLH, 0, int(pt_method));
00458           float bestLH_rear_min = bestLH;
00459 
00460           if (PtbyMLH)
00461             {
00462               ptR_front = bestLH_front > bestLH_front_min ? ptR_front : ptR_front_min;
00463               ptR_rear  = bestLH_rear  > bestLH_rear_min ? ptR_rear : ptR_rear_min;
00464             }
00465           else
00466             {
00467               // select max pt solution for 3 links:
00468               ptR_front = std::max(ptR_front, ptR_front_min);
00469               ptR_rear = std::max(ptR_rear, ptR_rear_min);
00470             }
00471         }
00472       
00473       if( (!CLCT_pattern) && (ptR_front > 5.)) ptR_front = 5.;
00474       if( (!CLCT_pattern) && (ptR_rear > 5.)) ptR_rear = 5.;
00475 
00476        // Check dEta against reasonable values for high-pt muons
00477       index = 0;
00478       if (mode == 6) index = 0;
00479       if (mode == 7) index = 4;
00480       if (mode == 13) index = 8;
00481       
00482       if (usedetaCUT)
00483         {
00484           if (fabs(etaR)>1.2 && fabs(etaR)<=1.5)
00485             if (dEta>dEtaCut_1[index+0] )
00486               {
00487                 if (ptR_front > 5) ptR_front = 5;
00488                 if (ptR_rear  > 5) ptR_rear  = 5;
00489               }
00490           if (fabs(etaR)>1.5 && fabs(etaR)<=1.65)
00491             if (dEta>dEtaCut_1[index+1])
00492               {
00493                 if (ptR_front > 5) ptR_front = 5;
00494                 if (ptR_rear  > 5) ptR_rear  = 5;
00495               }
00496           
00497           if (fabs(etaR)>1.65 && fabs(etaR)<=2.1)
00498             if (dEta>dEtaCut_1[index+2] )
00499               {
00500                 if (ptR_front > 5) ptR_front = 5;
00501                 if (ptR_rear  > 5) ptR_rear  = 5;
00502               }
00503           if (fabs(etaR)>2.1)
00504             if (dEta>dEtaCut_1[index+3] )
00505               {
00506                 if (ptR_front > 5) ptR_front = 5;
00507                 if (ptR_rear  > 5) ptR_rear  = 5;
00508               }
00509         }
00510             
00511       break;
00512     
00513     case 8:
00514     case 9:
00515     case 10:
00516       
00517       
00518       // First remake the 12-bit dPhi word from the core
00519       remerged = (address.delta_phi_12 | (address.delta_phi_23 << 8 ) );
00520       // Now get 9-bit dPhi12 
00521       absPhi12 = ((1<<9)-1) & remerged; 
00522       // Now get 3-bit dEta
00523       dEta = ((1<<3)-1) & (remerged >> 9);
00524      
00525       dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00526 
00527       //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
00528       ptR_front = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R,  PtbyMLH, bestLH, 1, int(pt_method));
00529       ptR_rear  = ptMethods.Pt2Stn2012(int(mode), etaR, dphi12R,  PtbyMLH, bestLH, 0, int(pt_method));
00530 
00531       index = 0;
00532       if (mode == 8) index = 12;
00533       if (mode == 9) index = 16;
00534       if (mode == 10) index = 20;
00535 
00536       
00537       
00538       
00539       if (usedetaCUT)
00540         {
00541           if (fabs(etaR)>1.2 && fabs(etaR)<=1.5)
00542             if (dEta>dEtaCut_2[index+0] )
00543               {
00544                 if (ptR_front > 5) ptR_front = 5;
00545                 if (ptR_rear  > 5) ptR_rear  = 5;
00546               }
00547           if (fabs(etaR)>1.5 && fabs(etaR)<=1.65)
00548             if (dEta>dEtaCut_2[index+1])
00549               {
00550                 if (ptR_front > 5) ptR_front = 5;
00551                 if (ptR_rear  > 5) ptR_rear  = 5;
00552               }
00553           
00554           if (fabs(etaR)>1.65 && fabs(etaR)<=2.1)
00555             if (dEta>dEtaCut_2[index+2] )
00556               {
00557                 if (ptR_front > 5) ptR_front = 5;
00558                 if (ptR_rear  > 5) ptR_rear  = 5;
00559               }
00560           if (fabs(etaR)>2.1)
00561             if (dEta>dEtaCut_2[index+3] )
00562               {
00563                 if (ptR_front > 5) ptR_front = 5;
00564                 if (ptR_rear  > 5) ptR_rear  = 5;
00565               }
00566         }
00567             
00568       break;
00569     // for overlap DT-CSC region using curves from data 2010
00570     case 11: // FR = 1 -> b1-1-3,     FR = 0 -> b1-3 
00571     case 12: // FR = 1 -> b1-2-3,     FR = 0 -> b1-2 
00572     case 14: // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
00573     
00574       
00575     //sign definition: sign dphi12 = Phi_DT - Phi_CSC
00576     //                 sing dphi23 = 5th sign. bit of phiBend
00577     // -> charge = 1 -> dphi12 = +, phiBend = -
00578     // -> charge = 0 -> dphi12 = +, phiBend = +    
00579         charge12 = 1;
00580 
00581         // DT tracks are still using linear dPhi binning
00582         absPhi12 = address.delta_phi_12;
00583         absPhi23 = address.delta_phi_23;
00584 
00585         if(charge) charge23 = -1;
00586         else charge23 = 1;
00587 
00588         dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00589         dphi23R = float(absPhi23);
00590         if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00591 
00592         int mode1;
00593         mode1 = int(mode);
00594         if(fr == 1 && mode1 == 11) mode1 = 14; // 3 station track we use dphi12 and phiBend for 2 and 3 station track
00595 
00596         ptR_front = ptMethods.Pt3Stn2012_DT(mode1, etaR, dphi12R, dphi23R,  PtbyMLH, bestLH, int(0), int(pt_method));
00597         ptR_rear = ptMethods.Pt3Stn2012_DT(mode1, etaR, dphi12R, dphi23R,   PtbyMLH, bestLH, int(0), int(pt_method));
00598 
00599       break;
00600     case 15: // halo trigger
00601     case 1: // tracks that fail delta phi cuts
00602       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3); // 2 GeV
00603       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(3); 
00604       break;
00605     default: // Tracks in this category are not considered muons.
00606       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0); // 0 GeV 
00607       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(0);
00608     };// end switch
00609 
00610   front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
00611   rear_pt  = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
00612 
00613   } //end pt_methods 29
00614 
00615 
00616 //***************************************************//
00617   if(pt_method >= 23 && pt_method <= 28){ //here we have only pt_methods greater then 
00618                        //for fw 20110118 <- 2011 data taking, curves from MC like method 4
00619   // mode definition you could find at page 6 & 7: 
00620   // http://www.phys.ufl.edu/~madorsky/sp/2011-11-18/sp_core_interface.pdf 
00621   // it is valid starting the beggining of 2011 
00622   //std::cout << " pt_method = " << pt_method << std::endl;//test 
00623   switch(mode)
00624     {
00625     case 2:
00626     case 3:
00627     case 4:
00628     case 5:
00629 
00630       charge12 = 1;
00631       absPhi12 = address.delta_phi_12;
00632       absPhi23 = address.delta_phi_23;
00633 
00634       if(charge) charge23 = 1;
00635       else charge23 = -1;
00636 
00637       dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00638       dphi23R = (static_cast<float>(absPhi23<<4)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00639       if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00640 
00641       ptR_front = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12R, dphi23R, 1, int(pt_method));
00642       ptR_rear  = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12R, dphi23R, 0, int(pt_method));    
00643 
00644       if((pt_method == 24 || pt_method == 26 || pt_method == 28) && mode != 5 && etaR > 2.1)//exclude mode without ME11a
00645         {
00646             float dphi12Rmin = dphi12R - Pi*10/180/3; // 10/3 degrees 
00647             float dphi12Rmax = dphi12R + Pi*10/180/3; // 10/3 degrees
00648             float dphi23Rmin = dphi23R;
00649             float dphi23Rmax = dphi23R;
00650             //if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
00651             //if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
00652             float ptR_front_min = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
00653             float ptR_rear_min = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
00654             float ptR_front_max = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
00655             float ptR_rear_max = ptMethods.Pt3Stn2010(int(mode), etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
00656             // select max pt solution for 3 links:
00657             ptR_front = std::max(ptR_front, ptR_front_min);
00658             ptR_front = std::max(ptR_front, ptR_front_max);
00659             ptR_rear = std::max(ptR_rear, ptR_rear_min);
00660             ptR_rear = std::max(ptR_rear, ptR_rear_max);
00661         }
00662       break;
00663     case 6: // for mode 6, 7 and 13 add CLCT information in dph23 bit and iME11 in charge bit  
00664     case 7:
00665     case 13: // ME1-ME4
00666       int iME11;
00667       iME11 = int(charge); // = 0 if ME1/1, = 1 if ME1/2 or ME1/3 station 
00668       if(iME11 == 1 && etaR > 1.6) etaR = 1.55; // shift for ME1/2 station  
00669       if(iME11 == 0 && etaR < 1.6) etaR = 1.65; // shift for ME1/1 station 
00670       absPhi12 = address.delta_phi_12;
00671       //int CLCT_pattern = static_cast<int>(address.delta_phi_23);
00672       int CLCT_pattern;
00673       CLCT_pattern = int(address.delta_phi_23);
00674       dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00675 
00676       //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
00677       ptR_front = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 1, int(pt_method));
00678       ptR_rear  = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 0, int(pt_method));
00679       if((pt_method == 24 || pt_method == 26 || pt_method == 28) && etaR > 2.1)//exclude tracks without ME11a 
00680         {
00681            float dphi12Rmin = fabs(fabs(dphi12R) - Pi*10/180/3); // 10/3 degrees 
00682            float ptR_front_min = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12Rmin, 1, int(pt_method));
00683            float ptR_rear_min = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12Rmin, 0, int(pt_method));
00684            // select max pt solution for 3 links:
00685            ptR_front = std::max(ptR_front, ptR_front_min);
00686            ptR_rear = std::max(ptR_rear, ptR_rear_min);
00687         }
00688       if( ((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_front > 5.)) ptR_front = 5.;
00689       if( ((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_rear > 5.)) ptR_rear = 5.;
00690       //std::cout << "mode = "<< mode << " CLCT_pattern = " << CLCT_pattern << " ptR_rear = " << ptR_rear << std::endl;
00691 
00692       break;
00693     case 8:
00694     case 9:
00695     case 10:
00696       if(charge) absPhi12 = address.delta_phi();
00697       else
00698         {
00699           int temp_phi = address.delta_phi();
00700           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
00701         }
00702 
00703       dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00704 
00705       //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
00706       ptR_front = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 1, int(pt_method));
00707       ptR_rear  = ptMethods.Pt2Stn2010(int(mode), etaR, dphi12R, 0, int(pt_method));
00708 
00709       break;
00710     // for overlap DT-CSC region using curves from data 2010
00711     case 11: // FR = 1 -> b1-1-3,     FR = 0 -> b1-3 
00712     case 12: // FR = 1 -> b1-2-3,     FR = 0 -> b1-2 
00713     case 14: // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
00714 
00715     //sign definition: sign dphi12 = Phi_DT - Phi_CSC
00716     //                 sing dphi23 = 5th sign. bit of phiBend
00717     // -> charge = 1 -> dphi12 = +, phiBend = -
00718     // -> charge = 0 -> dphi12 = +, phiBend = +    
00719         charge12 = 1;
00720         absPhi12 = address.delta_phi_12;
00721         absPhi23 = address.delta_phi_23;
00722 
00723         if(charge) charge23 = -1;
00724         else charge23 = 1;
00725 
00726         dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00727         dphi23R = float(absPhi23);
00728         if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00729 
00730         int mode1;
00731         mode1 = int(mode);
00732         if(fr == 1 && mode1 == 11) mode1 = 14; // 3 station track we use dphi12 and phiBend for 2 and 3 station track
00733 
00734         ptR_front = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
00735         ptR_rear = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
00736 
00737       break;
00738     case 15: // halo trigger
00739     case 1: // tracks that fail delta phi cuts
00740       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3); // 2 GeV
00741       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(3); 
00742       break;
00743     default: // Tracks in this category are not considered muons.
00744       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0); // 0 GeV 
00745       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(0);
00746     };// end switch
00747 
00748   front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
00749   rear_pt  = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
00750 
00751   } //end pt_methods 23 - 28 
00752 
00753 //***************************************************//
00754 //***************************************************//
00755   if(pt_method == 21 || pt_method == 22){ //here we have only pt_methods greater then 
00756                        //for fw 20110118 <- 2011 data taking
00757   // mode definition you could find at page 6 & 7: 
00758   // http://www.phys.ufl.edu/~madorsky/sp/2011-11-18/sp_core_interface.pdf 
00759   // it is valid starting the beggining of 2011 
00760   switch(mode)
00761     {
00762     case 2:
00763     case 3:
00764     case 4:
00765     case 5:
00766 
00767       charge12 = 1;
00768       absPhi12 = address.delta_phi_12;
00769       absPhi23 = address.delta_phi_23;
00770 
00771       if(charge) charge23 = 1;
00772       else charge23 = -1;
00773 
00774       dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00775       dphi23R = (static_cast<float>(absPhi23<<4)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00776       if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00777 
00778       ptR_front = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12R, dphi23R, 1, int(pt_method));
00779       ptR_rear  = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12R, dphi23R, 0, int(pt_method));    
00780 
00781       if(pt_method == 22 && mode != 5 && etaR > 2.1)//exclude mode without ME11a
00782         {
00783             float dphi12Rmin = dphi12R - Pi*10/180/3; // 10/3 degrees 
00784             float dphi12Rmax = dphi12R + Pi*10/180/3; // 10/3 degrees
00785             float dphi23Rmin = dphi23R;
00786             float dphi23Rmax = dphi23R;
00787             //if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
00788             //if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
00789             float ptR_front_min = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
00790             float ptR_rear_min = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
00791             float ptR_front_max = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
00792             float ptR_rear_max = ptMethods.Pt3Stn2011(int(mode), etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
00793             // select max pt solution for 3 links:
00794             ptR_front = std::max(ptR_front, ptR_front_min);
00795             ptR_front = std::max(ptR_front, ptR_front_max);
00796             ptR_rear = std::max(ptR_rear, ptR_rear_min);
00797             ptR_rear = std::max(ptR_rear, ptR_rear_max);
00798         }
00799       break;
00800     case 6: // for mode 6, 7 and 13 add CLCT information in dph23 bit and iME11 in charge bit  
00801     case 7:
00802     case 13: // ME1-ME4
00803       int iME11;
00804       iME11 = int(charge);
00805       absPhi12 = address.delta_phi_12;
00806       //int CLCT_pattern = static_cast<int>(address.delta_phi_23);
00807       int CLCT_pattern;
00808       CLCT_pattern = int(address.delta_phi_23);
00809 
00810       dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00811 
00812       //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
00813       ptR_front = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 1, int(pt_method), iME11);
00814       ptR_rear  = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 0, int(pt_method), iME11);
00815       if((pt_method == 22) && etaR > 2.1)//exclude tracks without ME11a 
00816         {
00817            float dphi12Rmin = fabs(fabs(dphi12R) - Pi*10/180/3); // 10/3 degrees 
00818            float ptR_front_min = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12Rmin, 1, int(pt_method), iME11);
00819            float ptR_rear_min = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12Rmin, 0, int(pt_method), iME11);
00820            // select max pt solution for 3 links:
00821            ptR_front = std::max(ptR_front, ptR_front_min);
00822            ptR_rear = std::max(ptR_rear, ptR_rear_min);
00823         }
00824       if( ((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_front > 5.)) ptR_front = 5.;
00825       if( ((CLCT_pattern < 8) || (CLCT_pattern > 10)) && (ptR_rear > 5.)) ptR_rear = 5.;
00826 
00827       break;
00828     case 8:
00829     case 9:
00830     case 10:
00831       if(charge) absPhi12 = address.delta_phi();
00832       else
00833         {
00834           int temp_phi = address.delta_phi();
00835           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
00836         }
00837 
00838       dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00839 
00840       //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
00841       ptR_front = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 1, int(pt_method), int(2));
00842       ptR_rear  = ptMethods.Pt2Stn2011(int(mode), etaR, dphi12R, 0, int(pt_method), int(2));
00843 
00844       break;
00845     case 11: // FR = 1 -> b1-1-3,     FR = 0 -> b1-3 
00846     case 12: // FR = 1 -> b1-2-3,     FR = 0 -> b1-2 
00847     case 14: // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
00848 
00849     //sign definition: sign dphi12 = Phi_DT - Phi_CSC
00850     //                 sing dphi23 = 5th sign. bit of phiBend
00851     // -> charge = 1 -> dphi12 = +, phiBend = -
00852     // -> charge = 0 -> dphi12 = +, phiBend = +    
00853         charge12 = 1;
00854         absPhi12 = address.delta_phi_12;
00855         absPhi23 = address.delta_phi_23;
00856 
00857         if(charge) charge23 = -1;
00858         else charge23 = 1;
00859 
00860         dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00861         dphi23R = float(absPhi23);
00862         if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00863 
00864         int mode1;
00865         mode1 = int(mode);
00866         if(fr == 1 && mode1 == 11) mode1 = 14; // 3 station track we use dphi12 and phiBend for 2 and 3 station track
00867 
00868         ptR_front = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
00869         ptR_rear = ptMethods.Pt3Stn2011(mode1, etaR, dphi12R, dphi23R, int(0), int(pt_method));
00870 
00871       break;
00872     case 15: // halo trigger
00873     case 1: // tracks that fail delta phi cuts
00874       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3); // 2 GeV
00875       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(3); 
00876       break;
00877     default: // Tracks in this category are not considered muons.
00878       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0); // 0 GeV 
00879       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(0);
00880     };// end switch
00881 
00882   front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
00883   rear_pt  = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
00884 
00885   } //end pt_methods greater or equal to 21 
00886 
00887 //***************************************************//
00888 //***************************************************//
00889   if(pt_method >= 11 && pt_method < 20){ //here we have only pt_methods greater or equal to 11 
00890                        //for fw 20101011 <- 2011 data taking
00891   // mode definition you could find at page 6 & 7: 
00892   // http://www.phys.ufl.edu/~madorsky/sp/2010-10-11/sp_core_interface.pdf 
00893   // it is valid starting the beggining of 2011 
00894   switch(mode)
00895     {
00896     case 2:
00897     case 3:
00898     case 4:
00899     case 5:
00900 
00901       charge12 = 1;
00902       absPhi12 = address.delta_phi_12;
00903       absPhi23 = address.delta_phi_23;
00904 
00905       if(charge) charge23 = 1;
00906       else charge23 = -1;
00907 
00908       dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00909       dphi23R = (static_cast<float>(absPhi23<<4)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00910       if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00911 
00912       ptR_front = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 1, int(pt_method));
00913       ptR_rear  = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 0, int(pt_method));    
00914 
00915       if(pt_method == 12 && mode != 5 && etaR > 2.1)//exclude mode without ME11a
00916         {
00917             float dphi12Rmin = dphi12R - Pi*10/180/3; // 10/3 degrees 
00918             float dphi12Rmax = dphi12R + Pi*10/180/3; // 10/3 degrees
00919             float dphi23Rmin = dphi23R;
00920             float dphi23Rmax = dphi23R;
00921             if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
00922             if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
00923             float ptR_front_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
00924             float ptR_rear_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
00925             float ptR_front_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
00926             float ptR_rear_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
00927             // select max pt solution for 3 links:
00928             ptR_front = std::max(ptR_front, ptR_front_min);
00929             ptR_front = std::max(ptR_front, ptR_front_max);
00930             ptR_rear = std::max(ptR_rear, ptR_rear_min);
00931             ptR_rear = std::max(ptR_rear, ptR_rear_max);
00932         }
00933       break;
00934     case 6:
00935     case 7:
00936     case 8:
00937     case 9:
00938     case 10:
00939     case 13: // ME1-ME4
00940       type = mode - 5;
00941 
00942       if(charge) absPhi12 = address.delta_phi();
00943       else
00944         {
00945           int temp_phi = address.delta_phi();
00946           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
00947         }
00948 
00949       dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00950 
00951       //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
00952       ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
00953       ptR_rear  = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
00954       if((pt_method == 12) && etaR > 2.1 && mode != 8 && mode !=9 && mode !=10)//exclude tracks without ME11a 
00955         {
00956            float dphi12Rmin = fabs(fabs(dphi12R) - Pi*10/180/3); // 10/3 degrees 
00957            float ptR_front_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 1, int(pt_method));
00958            float ptR_rear_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 0, int(pt_method));
00959            // select max pt solution for 3 links:
00960            ptR_front = std::max(ptR_front, ptR_front_min);
00961            ptR_rear = std::max(ptR_rear, ptR_rear_min);
00962         }
00963 
00964       break;
00965     case 11: // FR = 1 -> b1-1-3,     FR = 0 -> b1-3 
00966     case 12: // FR = 1 -> b1-2-3,     FR = 0 -> b1-2 
00967     case 14: // FR = 1 -> b1-1-2-(3), FR = 0 -> b1-1
00968 
00969       if(fr == 0){ // 2 station track
00970         if(charge) absPhi12 = address.delta_phi();
00971         else
00972           {
00973             int temp_phi = address.delta_phi();
00974             absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
00975           }
00976           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00977           ptR_rear  = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
00978 
00979       }// end fr == 0
00980       if(fr == 1){ // 3 station track
00981         charge12 = 1;
00982         absPhi12 = address.delta_phi_12;
00983         absPhi23 = address.delta_phi_23;
00984 
00985         if(charge) charge23 = 1;
00986         else charge23 = -1;
00987 
00988         dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00989         dphi23R = (static_cast<float>(absPhi23<<4)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
00990         if(charge12 * charge23 < 0) dphi23R = -dphi23R;
00991 
00992         ptR_front = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 1, int(pt_method));
00993 
00994         if(pt_method == 12 && mode != 5 && etaR > 2.1)//exclude mode without ME11a
00995           {
00996               float dphi12Rmin = dphi12R - Pi*10/180/3; // 10/3 degrees 
00997               float dphi12Rmax = dphi12R + Pi*10/180/3; // 10/3 degrees
00998               float dphi23Rmin = dphi23R;
00999               float dphi23Rmax = dphi23R;
01000               if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
01001               if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
01002               float ptR_front_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
01003               float ptR_front_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
01004               // select max pt solution for 3 links:
01005               ptR_front = std::max(ptR_front, ptR_front_min);
01006               ptR_front = std::max(ptR_front, ptR_front_max);
01007           }
01008       } // end fr == 1 
01009 
01010       break;
01011     case 15: // halo trigger
01012     case 1: // tracks that fail delta phi cuts
01013       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(3); // 2 GeV
01014       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(3); 
01015       break;
01016     default: // Tracks in this category are not considered muons.
01017       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0); // 0 GeV 
01018       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(0);
01019     };// end switch
01020 
01021   front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
01022   rear_pt  = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
01023 
01024   } //end pt_methods greater or equal to 11 
01025 //***************************************************//
01026   if(pt_method <= 5){ //here we have only pt_methods less or equal to 5
01027   // mode definition you could find at https://twiki.cern.ch/twiki/pub/Main/PtLUTs/mode_codes.xls
01028   // it is valid till the end 2010 
01029 
01030   //  kluge to use 2-stn track in overlap region
01031   //  see also where this routine is called, and encode LUTaddress, and assignPT
01032   if (pt_method != 4 && pt_method !=5 
01033       && (mode == 2 || mode == 3 || mode == 4) && (eta<3)) mode = 6;
01034   if (pt_method != 4 && pt_method !=5 && (mode == 5)
01035       && (eta<3)) mode = 8;
01036 
01037   switch(mode)
01038     {
01039     case 2:
01040     case 3:
01041     case 4:
01042     case 5:
01043       type = mode - 1;
01044       charge12 = 1;
01045       absPhi12 = address.delta_phi_12;
01046       absPhi23 = address.delta_phi_23;
01047 
01048       if(charge) charge23 = 1;
01049       else charge23 = -1;
01050 
01051       // now convert to real numbers for input into PT assignment algos.
01052 
01053       if(pt_method == 4 || pt_method == 5) // param method 2010
01054         {
01055           dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01056           dphi23R = (static_cast<float>(absPhi23<<4)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01057           if(charge12 * charge23 < 0) dphi23R = -dphi23R;
01058 
01059           ptR_front = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 1, int(pt_method));
01060           ptR_rear  = ptMethods.Pt3Stn2010(mode, etaR, dphi12R, dphi23R, 0, int(pt_method));
01061 
01062           if(pt_method == 5 && mode != 5 && etaR > 2.1)//exclude mode without ME11a
01063             {
01064                 float dphi12Rmin = dphi12R - Pi*10/180/3; // 10/3 degrees 
01065                 float dphi12Rmax = dphi12R + Pi*10/180/3; // 10/3 degrees
01066                 float dphi23Rmin = dphi23R;
01067                 float dphi23Rmax = dphi23R;
01068                 if(dphi12Rmin*dphi12R < 0) dphi23Rmin = -dphi23R;
01069                 if(dphi12Rmax*dphi12R < 0) dphi23Rmax = -dphi23R;
01070                 float ptR_front_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 1, int(pt_method));
01071                 float ptR_rear_min = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmin, dphi23Rmin, 0, int(pt_method));
01072                 float ptR_front_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 1, int(pt_method));
01073                 float ptR_rear_max = ptMethods.Pt3Stn2010(mode, etaR, dphi12Rmax, dphi23Rmax, 0, int(pt_method));
01074                 // select max pt solution for 3 links:
01075                 ptR_front = std::max(ptR_front, ptR_front_min);
01076                 ptR_front = std::max(ptR_front, ptR_front_max);
01077                 ptR_rear = std::max(ptR_rear, ptR_rear_min);
01078                 ptR_rear = std::max(ptR_rear, ptR_rear_max);
01079             }
01080         }
01081       else if(pt_method == 1) // param method
01082         {
01083           dphi12R = (static_cast<float>(absPhi12<<1)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01084           dphi23R = (static_cast<float>(absPhi23<<4)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01085           if(charge12 * charge23 < 0) dphi23R = -dphi23R;
01086 
01087           ptR_front = ptMethods.Pt3Stn(type, etaR, dphi12R, dphi23R, 1);
01088           ptR_rear  = ptMethods.Pt3Stn(type, etaR, dphi12R, dphi23R, 0);
01089 
01090         }
01091       else if(pt_method == 2) // cathy's method
01092         {
01093           if(type <= 2)
01094             {
01095               ptR_front = ptMethods.Pt3StnChiSq(type+3, etaR, absPhi12<<1, ((charge == 0) ? -(absPhi23<<4) : (absPhi23<<4)), 1);
01096               ptR_rear  = ptMethods.Pt3StnChiSq(type+3, etaR, absPhi12<<1, ((charge == 0) ? -(absPhi23<<4) : (absPhi23<<4)), 0);
01097             }
01098           else
01099             {
01100               ptR_front = ptMethods.Pt2StnChiSq(type-2, etaR, absPhi12<<1, 1);
01101               ptR_rear  = ptMethods.Pt2StnChiSq(type-2, etaR, absPhi12<<1, 0);
01102             }
01103 
01104         }
01105       else // hybrid
01106         {
01107 
01108           if(type <= 2)
01109             {
01110               ptR_front = ptMethods.Pt3StnHybrid(type+3, etaR, absPhi12<<1, ((charge == 0) ? -(absPhi23<<4) : (absPhi23<<4)), 1);
01111               ptR_rear  = ptMethods.Pt3StnHybrid(type+3, etaR, absPhi12<<1, ((charge == 0) ? -(absPhi23<<4) : (absPhi23<<4)), 0);
01112             }
01113           else
01114             {
01115               ptR_front = ptMethods.Pt2StnHybrid(type-2, etaR, absPhi12<<1, 1);
01116               ptR_rear  = ptMethods.Pt2StnHybrid(type-2, etaR, absPhi12<<1, 0);
01117             }
01118 
01119         }
01120       break;
01121     case 6:
01122     case 7:
01123     case 8:
01124     case 9:
01125     case 10:
01126       type = mode - 5;
01127 
01128       if(charge) absPhi12 = address.delta_phi();
01129       else
01130         {
01131           int temp_phi = address.delta_phi();
01132           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
01133         }
01134 
01135       if(absPhi12 < (1<<9))
01136         {
01137           if(pt_method == 1 || type == 5)
01138             {
01139               dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01140 
01141               ptR_front = ptMethods.Pt2Stn(type, etaR, dphi12R, 1);
01142               ptR_rear  = ptMethods.Pt2Stn(type, etaR, dphi12R, 0);
01143 
01144             }
01145           else if(pt_method == 2)
01146             {
01147               ptR_front = ptMethods.Pt2StnChiSq(type-1, etaR, absPhi12, 1);
01148               ptR_rear  = ptMethods.Pt2StnChiSq(type-1, etaR, absPhi12, 0);
01149             }
01150           else
01151             {
01152               ptR_front = ptMethods.Pt2StnHybrid(type-1, etaR, absPhi12, 1);
01153               ptR_rear  = ptMethods.Pt2StnHybrid(type-1, etaR, absPhi12, 0);
01154             }
01155         }
01156       else
01157         {
01158           ptR_front = trigger_ptscale->getPtScale()->getLowEdge(1);
01159           ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(1);
01160         }
01161       if(pt_method == 4 || pt_method == 5) // param method 2010
01162         {
01163               dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01164 
01165               //std::cout<< " Sector_rad = " << (CSCTFConstants::SECTOR_RAD) << std::endl;
01166               ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
01167               ptR_rear  = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
01168               if((pt_method == 5) && etaR > 2.1 && mode != 8 && mode !=9 && mode !=10)//exclude tracks without ME11a 
01169                 {
01170                    float dphi12Rmin = fabs(fabs(dphi12R) - Pi*10/180/3); // 10/3 degrees 
01171                    float ptR_front_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 1, int(pt_method));
01172                    float ptR_rear_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 0, int(pt_method));
01173                    // select max pt solution for 3 links:
01174                    ptR_front = std::max(ptR_front, ptR_front_min);
01175                    ptR_rear = std::max(ptR_rear, ptR_rear_min);
01176                 }
01177         }
01178 
01179       break;
01180     case 12:  // 1-2-b1 calculated only delta_phi12 = 2-b1
01181     case 14:
01182       type = 2;
01183 
01184       if(charge) absPhi12 = address.delta_phi();
01185       else
01186         {
01187           int temp_phi = address.delta_phi();
01188           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
01189         }
01190       if(absPhi12 < (1<<9))
01191         {
01192           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01193           ptR_front = ptMethods.Pt2Stn(type, etaR, dphi12R, 1);
01194           ptR_rear  = ptMethods.Pt2Stn(type, etaR, dphi12R, 0);
01195         }
01196       else
01197         {
01198           ptR_front = trigger_ptscale->getPtScale()->getLowEdge(1);
01199           ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(1);
01200         }
01201       if(pt_method == 4 || pt_method == 5) // param method 2010 
01202         {
01203               dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01204 
01205               ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
01206               ptR_rear  = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
01207 
01208               if(fabs(dphi12R)<0.01 && (ptR_rear < 10 || ptR_front < 10))
01209                 std::cout << "dphi12R = " << dphi12R << " ptR_rear = " << ptR_rear
01210                 << " ptR_front = " << ptR_front << " etaR = " << etaR << " mode = " << mode << std::endl;
01211         }
01212       break;
01213     case 13:
01214       type = 4;
01215 
01216       if(charge) absPhi12 = address.delta_phi();
01217       else
01218         {
01219           int temp_phi = address.delta_phi();
01220           absPhi12 = static_cast<unsigned>(-temp_phi) & 0xfff;
01221         }
01222       if(absPhi12 < (1<<9))
01223         {
01224           dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01225           ptR_front = ptMethods.Pt2Stn(type, etaR, dphi12R, 1);
01226           ptR_rear  = ptMethods.Pt2Stn(type, etaR, dphi12R, 0);
01227         }
01228       else
01229         {
01230           ptR_front = trigger_ptscale->getPtScale()->getLowEdge(1);
01231           ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(1);
01232         }
01233 
01234       if(pt_method == 4 || pt_method == 5) // param method 2010
01235         {
01236               dphi12R = (static_cast<float>(absPhi12)) / (static_cast<float>(1<<12)) * CSCTFConstants::SECTOR_RAD;
01237 
01238               ptR_front = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 1, int(pt_method));
01239               ptR_rear  = ptMethods.Pt2Stn2010(mode, etaR, dphi12R, 0, int(pt_method));
01240               if((pt_method == 5) && etaR > 2.1)//mode = 13: ME1-ME4 exclude tracks without ME11a 
01241                 {
01242                    float dphi12Rmin = fabs(fabs(dphi12R) - Pi*10/180/3); // 10/3 degrees 
01243                    float ptR_front_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 1, int(pt_method));
01244                    float ptR_rear_min = ptMethods.Pt2Stn2010(mode, etaR, dphi12Rmin, 0, int(pt_method));
01245                    // select max pt solution for 3 links:
01246                    ptR_front = std::max(ptR_front, ptR_front_min);
01247                    ptR_rear = std::max(ptR_rear, ptR_rear_min);
01248                 }
01249         }
01250 
01251       break;
01252     case 11:
01253       // singles trigger
01254       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(5);
01255       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(5);
01256       //ptR_front = trigger_ptscale->getPtScale()->getLowEdge(31);
01257       //ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(31);
01258       break;
01259     case 15:
01260       // halo trigger
01261       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(5);
01262       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(5);
01263       break;
01264     case 1:
01265       // tracks that fail delta phi cuts
01266       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(5);
01267       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(5); 
01268      break;
01269     default: // Tracks in this category are not considered muons.
01270       ptR_front = trigger_ptscale->getPtScale()->getLowEdge(0);
01271       ptR_rear  = trigger_ptscale->getPtScale()->getLowEdge(0);
01272     };
01273 
01274   front_pt = trigger_ptscale->getPtScale()->getPacked(ptR_front);
01275   rear_pt  = trigger_ptscale->getPtScale()->getPacked(ptR_rear);
01276 
01277   // kluge to set arbitrary Pt for some tracks with lousy resolution (and no param)
01278   if(pt_method != 4 && pt_method != 5) 
01279     {
01280       if ((front_pt==0 || front_pt==1) && (eta<3) && quality==1 && pt_method != 2) front_pt = 31;
01281       if ((rear_pt==0  || rear_pt==1) && (eta<3) && quality==1 && pt_method != 2) rear_pt = 31;
01282     }
01283   if(pt_method != 2 && pt_method != 4 && quality == 1)
01284     {
01285       if (front_pt < 5) front_pt = 5;
01286       if (rear_pt  < 5) rear_pt  = 5;
01287     }
01288 
01289   // in order to match the pt assignement of the previous routine
01290   if(isBeamStartConf && pt_method != 2 && pt_method != 4 && pt_method !=5) {
01291     if(quality == 3 && mode == 5) {
01292       
01293       if (front_pt < 5) front_pt = 5;
01294       if (rear_pt  < 5) rear_pt  = 5;
01295     }
01296 
01297     if(quality == 2 && mode > 7 && mode < 11) {
01298       
01299       if (front_pt < 5) front_pt = 5;
01300       if (rear_pt  < 5) rear_pt  = 5;
01301     }
01302   }
01303 
01304   } // end if for pt_method less or equal to 5
01305 //***************************************************//
01306 
01307  
01308   result.front_rank = front_pt | front_quality << 5;
01309   result.rear_rank  = rear_pt  | rear_quality << 5;
01310 
01311   result.charge_valid_front = 1; //ptMethods.chargeValid(front_pt, quality, eta, pt_method);
01312   result.charge_valid_rear  = 1; //ptMethods.chargeValid(rear_pt, quality, eta, pt_method);
01313 
01314 
01315   /*  if (mode == 1) { 
01316     std::cout << "F_pt: "      << front_pt      << std::endl;
01317     std::cout << "R_pt: "      << rear_pt       << std::endl;
01318     std::cout << "F_quality: " << front_quality << std::endl;
01319     std::cout << "R_quality: " << rear_quality  << std::endl;
01320     std::cout << "F_rank: " << std::hex << result.front_rank << std::endl;
01321     std::cout << "R_rank: " << std::hex << result.rear_rank  << std::endl;
01322   }
01323   */
01324   return result;
01325 }
01326 
01327 
01328 unsigned CSCTFPtLUT::trackQuality(const unsigned& eta, const unsigned& mode, const unsigned& fr) const
01329 {
01330  // eta and mode should be only 4-bits, since that is the input to the large LUT
01331     if (eta>15 || mode>15)
01332       {
01333         //std::cout << "Error: Eta or Mode out of range in AU quality assignment" << std::endl;
01334         edm::LogError("CSCTFPtLUT::trackQuality()")<<"Eta or Mode out of range in AU quality assignment";
01335         return 0;
01336       }
01337     unsigned int quality;
01338     switch (mode) {
01339     case 2:
01340       quality = 3;
01341       if(pt_method > 10 && eta < 3) quality = 1; //eta < 1.2
01342       if(pt_method == 32 && eta >= 12) quality = 2; // eta > 2.1  
01343       break;
01344     case 3:
01345     case 4:
01347       //        quality = 2;
01348       quality = 3;
01349       if(pt_method == 32 && eta >= 12) quality = 2; // eta > 2.1  
01350       break;
01351     case 5:
01352       quality = 1;
01353       if (isBeamStartConf && eta >= 12 && pt_method < 20) // eta > 2.1
01354         quality = 3;
01355       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
01356       break;
01357     case 6:
01358       if (eta>=3) // eta > 1.2
01359         quality = 2;
01360       else
01361         quality = 1;
01362       if(pt_method == 32 && eta >= 12) quality = 1; // eta > 2.1  
01363       break;
01364     case 7:
01365       quality = 2;
01366       if(pt_method > 10 && eta < 3) quality = 1; //eta < 1.2  
01367       if(pt_method == 32 && eta >= 12) quality = 1; // eta > 2.1  
01368       break;
01369     case 8:
01370     case 9:
01371     case 10:
01372       quality = 1;
01373       if (isBeamStartConf && eta >= 12 && pt_method < 20) // eta > 2.1
01374         quality = 2;
01375       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
01376       break;
01377     case 11:
01378       // single LCTs
01379       quality = 1;
01380       // overlap region
01381       if(pt_method > 10 && fr == 0) quality = 2;
01382       if(pt_method > 10 && fr == 1) quality = 3;
01383       if(pt_method > 20 && fr == 0) quality = 3;
01384       break;
01385     case 12:
01386       quality = 3;
01387       // overlap region
01388       if(pt_method > 10 && fr == 0) quality = 2;
01389       if(pt_method > 10 && fr == 1) quality = 3;
01390       if(pt_method > 20 && fr == 0) quality = 3;
01391       break;
01392     case 13:
01393       quality = 2;
01394       if(pt_method == 32 && eta >= 12) quality = 1; // eta > 2.1  
01395       break;
01396     case 14:
01397       quality = 2;
01398       // overlap region
01399       if(pt_method > 10 && fr == 0) quality = 2;
01400       if(pt_method > 10 && fr == 1) quality = 3;
01401       if(pt_method > 20 && fr == 0) quality = 3;
01402       break;
01403     case 15:
01404       // halo triggers
01405       quality = 1;
01406       break;
01407       //DEA: keep muons that fail delta phi cut
01408     case 1:
01409       quality = 1;
01410       break;
01411     default:
01412       quality = 0;
01413       break;
01414     }
01415 
01416     // allow quality = 1 only in overlap region or eta = 1.6 region
01417     //    if ((quality == 1) && (eta >= 4) && (eta != 6) && (eta != 7)) quality = 0;
01418     //    if ( (quality == 1) && (eta >= 4) ) quality = 0;
01419 
01420     if ( (quality == 1) && (eta >= 4) && (eta < 11)
01421          && ((lowQualityFlag&4)==0) ) quality = 0;
01422     if ( (quality == 1) && (eta < 4) && ((lowQualityFlag&1)==0)
01423          && ((lowQualityFlag&4)==0) ) quality = 0;
01424     if ( (quality == 1) && (eta >=11) && ((lowQualityFlag&2)==0)
01425          && ((lowQualityFlag&4)==0) ) quality = 0;
01426 
01427     return quality;
01428 
01429 }
01430 
01431 void CSCTFPtLUT::readLUT()
01432 {
01433   std::ifstream PtLUT;
01434 
01435   if(isBinary)
01436     {
01437       PtLUT.open(pt_lut_file.fullPath().c_str(), std::ios::binary);
01438       PtLUT.seekg(0, std::ios::end);
01439       int length = PtLUT.tellg();;
01440       if( length == (1<<CSCBitWidths::kPtAddressWidth)*sizeof(short) )
01441         {
01442           PtLUT.seekg(0, std::ios::beg);
01443           PtLUT.read(reinterpret_cast<char*>(pt_lut),length);
01444         }
01445       else
01446         {
01447           edm::LogError("CSCPtLUT") << "File " << pt_lut_file.fullPath() << " is incorrect size!\n";
01448         }
01449       PtLUT.close();
01450     }
01451   else
01452     {
01453       PtLUT.open(pt_lut_file.fullPath().c_str());
01454       unsigned i = 0;
01455       unsigned short temp = 0;
01456       while(!PtLUT.eof() && i < 1 << CSCBitWidths::kPtAddressWidth)
01457         {
01458           PtLUT >> temp;
01459           pt_lut[i++] = (*reinterpret_cast<ptdat*>(&temp));
01460         }
01461       PtLUT.close();
01462     }
01463 }
01464 
01465