CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/L1Trigger/CSCTrackFinder/src/CSCTFSectorProcessor.cc

Go to the documentation of this file.
00001 #include <L1Trigger/CSCTrackFinder/interface/CSCTFSectorProcessor.h>
00002 #include <L1Trigger/CSCTrackFinder/interface/CSCTrackFinderDataTypes.h>
00003 #include <DataFormats/MuonDetId/interface/CSCTriggerNumbering.h>
00004 
00005 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00006 
00007 #include "CondFormats/L1TObjects/interface/L1MuCSCTFConfiguration.h"
00008 #include "CondFormats/DataRecord/interface/L1MuCSCTFConfigurationRcd.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include <stdlib.h>
00011 #include <sstream>
00012 #include <strings.h>
00013 
00014 const std::string CSCTFSectorProcessor::FPGAs[5] = {"F1","F2","F3","F4","F5"};
00015 
00016 CSCTFSectorProcessor::CSCTFSectorProcessor(const unsigned& endcap,
00017                                            const unsigned& sector,
00018                                            const edm::ParameterSet& pset,
00019                                            bool tmb07,
00020                                            const L1MuTriggerScales* scales,
00021                                            const L1MuTriggerPtScale* ptScale)
00022 {
00023   m_endcap = endcap;
00024   m_sector = sector;
00025   TMB07    = tmb07;
00026   
00027   // allows a configurable option to handle unganged ME1a
00028   m_gangedME1a = pset.getUntrackedParameter<bool>("gangedME1a", true);
00029 
00030   // Parameter below should always present in ParameterSet:
00031   m_latency = pset.getParameter<unsigned>("CoreLatency");
00032   m_minBX = pset.getParameter<int>("MinBX");
00033   m_maxBX = pset.getParameter<int>("MaxBX");
00034   initializeFromPSet = pset.getParameter<bool>("initializeFromPSet");
00035   if( m_maxBX-m_minBX >= 7 ) edm::LogWarning("CSCTFTrackBuilder::ctor")<<" BX window width >= 7BX. Resetting m_maxBX="<<(m_maxBX=m_minBX+6);
00036 
00037   // All following parameters may appear in either ParameterSet of in EventSetup; uninitialize:
00038   m_bxa_depth = -1;
00039   m_allowALCTonly = -1;
00040   m_allowCLCTonly = -1;
00041   m_preTrigger = -1;
00042 
00043   for(int index=0; index<7; index++) m_etawin[index] = -1;
00044   for(int index=0; index<8; index++) m_etamin[index] = -1;
00045   for(int index=0; index<8; index++) m_etamax[index] = -1;
00046 
00047   m_mindphip=-1;
00048   m_mindetap=-1;
00049 
00050   m_mindeta12_accp=-1;
00051   m_maxdeta12_accp=-1;
00052   m_maxdphi12_accp=-1;
00053 
00054   m_mindeta13_accp=-1;
00055   m_maxdeta13_accp=-1;
00056   m_maxdphi13_accp=-1;
00057 
00058   m_mindeta112_accp=-1;
00059   m_maxdeta112_accp=-1;
00060   m_maxdphi112_accp=-1;
00061 
00062   m_mindeta113_accp=-1;
00063   m_maxdeta113_accp=-1;
00064   m_maxdphi113_accp=-1;
00065   m_mindphip_halo=-1;
00066   m_mindetap_halo=-1;
00067 
00068   m_widePhi=-1;
00069 
00070   m_straightp=-1;
00071   m_curvedp=-1;
00072 
00073   m_mbaPhiOff=-1;
00074   m_mbbPhiOff=-1;
00075 
00076   kill_fiber = -1;
00077   QualityEnableME1a = -1;
00078   QualityEnableME1b = -1;
00079   QualityEnableME1c = -1;
00080   QualityEnableME1d = -1;
00081   QualityEnableME1e = -1;
00082   QualityEnableME1f = -1;
00083   QualityEnableME2a = -1;
00084   QualityEnableME2b = -1;
00085   QualityEnableME2c = -1;
00086   QualityEnableME3a = -1;
00087   QualityEnableME3b = -1;
00088   QualityEnableME3c = -1;
00089   QualityEnableME4a = -1;
00090   QualityEnableME4b = -1;
00091   QualityEnableME4c = -1;
00092 
00093   run_core = -1;
00094   trigger_on_ME1a = -1;
00095   trigger_on_ME1b = -1;
00096   trigger_on_ME2  = -1;
00097   trigger_on_ME3  = -1;
00098   trigger_on_ME4  = -1;
00099   trigger_on_MB1a = -1;
00100   trigger_on_MB1d = -1;
00101 
00102   singlesTrackOutput = 999;
00103   rescaleSinglesPhi  = -1;
00104 
00105   m_firmSP = -1;
00106   m_firmFA = -1;
00107   m_firmDD = -1;
00108   m_firmVM = -1;
00109 
00110   initFail_ = false;
00111 
00112   isCoreVerbose = pset.getParameter<bool>("isCoreVerbose");
00113 
00114   if(initializeFromPSet) readParameters(pset);
00115 
00116 
00117   // Sector Receiver LUTs initialization
00118   edm::ParameterSet srLUTset = pset.getParameter<edm::ParameterSet>("SRLUT");
00119   for(int i = 1; i <= 4; ++i)
00120     {
00121       if(i == 1)
00122         for(int j = 0; j < 2; j++)
00123           {
00124             srLUTs_[FPGAs[j]] = new CSCSectorReceiverLUT(endcap, sector, j+1, i, srLUTset, TMB07);
00125           }
00126       else
00127         srLUTs_[FPGAs[i]] = new CSCSectorReceiverLUT(endcap, sector, 0, i, srLUTset, TMB07);
00128     }
00129 
00130   core_ = new CSCTFSPCoreLogic();
00131 
00132   // Pt LUTs initialization
00133   if(initializeFromPSet){
00134     edm::ParameterSet ptLUTset = pset.getParameter<edm::ParameterSet>("PTLUT");
00135     ptLUT_ = new CSCTFPtLUT(ptLUTset, scales, ptScale);
00136     LogDebug("CSCTFSectorProcessor") << "Using stand-alone PT LUT for endcap="<<m_endcap<<", sector="<<m_sector;
00137   } else {
00138     ptLUT_=0;
00139     LogDebug("CSCTFSectorProcessor") << "Looking for PT LUT in EventSetup for endcap="<<m_endcap<<", sector="<<m_sector;
00140   }
00141 
00142   // firmware map initialization
00143   // all the information are based on the firmware releases 
00144   // documented at http://www.phys.ufl.edu/~uvarov/SP05/SP05.htm
00145 
00146   // map is <m_firmSP, core_version>
00147   // it may happen that the same core is used for different firmware
00148   // versions, e.g. change in the wrapper only
00149 
00150   // this mapping accounts for runs starting from 132440
00151   // schema is year+month+day
00152   firmSP_Map.insert(std::pair<int,int>(20100210,20100122));
00153   firmSP_Map.insert(std::pair<int,int>(20100617,20100122));
00154   firmSP_Map.insert(std::pair<int,int>(20100629,20100122));
00155 
00156   firmSP_Map.insert(std::pair<int,int>(20100728,20100728));
00157 
00158   firmSP_Map.insert(std::pair<int,int>(20100901,20100901));
00159 
00160   //testing firmwares
00161   firmSP_Map.insert(std::pair<int,int>(20101011,20101011));
00162   firmSP_Map.insert(std::pair<int,int>(20101210,20101210));
00163   firmSP_Map.insert(std::pair<int,int>(20110204,20110118));
00164   firmSP_Map.insert(std::pair<int,int>(20110322,20110118));
00165   // 2012 core with non linear dphi
00166   firmSP_Map.insert(std::pair<int,int>(20120131,20120131));
00167   firmSP_Map.insert(std::pair<int,int>(20120227,20120131));
00168   //2012 core: 4 station track at |eta|>2.1 -> ME2-ME3-ME4
00169   firmSP_Map.insert(std::pair<int,int>(20120313,20120313));
00170   firmSP_Map.insert(std::pair<int,int>(20120319,20120313));
00171 }
00172 
00173 
00174 void CSCTFSectorProcessor::initialize(const edm::EventSetup& c){
00175   initFail_ = false;
00176   if(!initializeFromPSet){
00177     // Only pT lut can be initialized from EventSetup, all front LUTs are initialized locally from their parametrizations
00178     LogDebug("CSCTFSectorProcessor") <<"Initializing endcap: "<<m_endcap<<" sector:"<<m_sector << "SP:" << (m_endcap-1)*6+(m_sector-1);
00179     LogDebug("CSCTFSectorProcessor") << "Initializing pT LUT from EventSetup";
00180 
00181     ptLUT_ = new CSCTFPtLUT(c);
00182 
00183     // Extract from EventSetup alternative (to the one, used in constructor) ParameterSet
00184     edm::ESHandle<L1MuCSCTFConfiguration> config;
00185     c.get<L1MuCSCTFConfigurationRcd>().get(config);
00186     // And initialize only those parameters, which left uninitialized during construction
00187     readParameters(config.product()->parameters((m_endcap-1)*6+(m_sector-1)));
00188   }
00189 
00190   // ---------------------------------------------------------------------------
00191   // This part is added per Vasile's request.
00192   // It will help people understanding the emulator configuration
00193   LogDebug("CSCTFSectorProcessor") << "\n !!! CSCTF EMULATOR CONFIGURATION !!!"
00194                                    << "\n\nCORE CONFIGURATION"
00195                                    << "\n Coincidence Trigger? " << run_core
00196                                    << "\n Singles in ME1a? "     << trigger_on_ME1a
00197                                    << "\n Singles in ME1b? "     << trigger_on_ME1b
00198                                    << "\n Singles in ME2? "      << trigger_on_ME2
00199                                    << "\n Singles in ME3? "      << trigger_on_ME3
00200                                    << "\n Singles in ME4? "      << trigger_on_ME4
00201                                    << "\n Singles in MB1a? "     << trigger_on_MB1a
00202                                    << "\n Singles in MB1d? "     << trigger_on_MB1d
00203 
00204                                    << "\n BX Analyzer depth: assemble coinc. track with stubs in +/-" << m_bxa_depth << " Bxs"
00205                                    << "\n Is Wide Phi Extrapolation (DeltaPhi valid up to ~15 degrees, otherwise ~7.67 degrees)? " << m_widePhi
00206                                    << "\n PreTrigger=" << m_preTrigger
00207 
00208                                    << "\n CoreLatency=" << m_latency
00209                                    << "\n Is Phi for singles rescaled? " << rescaleSinglesPhi
00210 
00211                                    << "\n\nVARIOUS CONFIGURATION PARAMETERS"
00212                                    << "\n Allow ALCT only? " <<  m_allowALCTonly
00213                                    << "\n Allow CLCT only? " <<  m_allowCLCTonly
00214 
00215                                    << "\nQualityEnableME1a (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME1a
00216                                    << "\nQualityEnableME1b (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME1b
00217                                    << "\nQualityEnableME1c (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME1c
00218                                    << "\nQualityEnableME1d (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME1d
00219                                    << "\nQualityEnableME1e (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME1e
00220                                    << "\nQualityEnableME1f (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME1f
00221                                    << "\nQualityEnableME2a (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME2a
00222                                    << "\nQualityEnableME2b (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME2b
00223                                    << "\nQualityEnableME2c (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME2c
00224                                    << "\nQualityEnableME3a (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME3a
00225                                    << "\nQualityEnableME3b (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME3b
00226                                    << "\nQualityEnableME3c (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME3c
00227                                    << "\nQualityEnableME4a (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME4a
00228                                    << "\nQualityEnableME4b (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME4b
00229                                    << "\nQualityEnableME4c (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME4c
00230 
00231                                    << "\nkill_fiber="          << kill_fiber
00232                                    << "\nSingles Output Link=" << singlesTrackOutput
00233 
00234     //the DAT_ETA registers meaning are explained at Table 2 of
00235     //http://www.phys.ufl.edu/~uvarov/SP05/LU-SP_ReferenceGuide_090915_Update.pdf
00236 
00237                                    << "\n\nDAT_ETA REGISTERS"
00238                                    << "\nMinimum eta difference for track cancellation logic=" << m_mindetap
00239                                    << "\nMinimum eta difference for halo track cancellation logic=" << m_mindetap_halo
00240 
00241                                    << "\nMinimum eta for ME1-ME2 collision tracks=" << m_etamin[0]
00242                                    << "\nMinimum eta for ME1-ME3 collision tracks=" << m_etamin[1]
00243                                    << "\nMinimum eta for ME2-ME3 collision tracks=" << m_etamin[2]
00244                                    << "\nMinimum eta for ME2-ME4 collision tracks=" << m_etamin[3]
00245                                    << "\nMinimum eta for ME3-ME4 collision tracks=" << m_etamin[4]
00246                                    << "\nMinimum eta for ME1-ME2 collision tracks in overlap region=" << m_etamin[5]
00247                                    << "\nMinimum eta for ME2-MB1 collision tracks=" << m_etamin[6]
00248                                    << "\nMinimum eta for ME1-ME4 collision tracks=" << m_etamin[7]
00249 
00250                                    << "\nMinimum eta difference for ME1-ME2 (except ME1/1) halo tracks=" << m_mindeta12_accp
00251                                    << "\nMinimum eta difference for ME1-ME3 (except ME1/1) halo tracks=" << m_mindeta13_accp
00252                                    << "\nMinimum eta difference for ME1/1-ME2 halo tracks=" << m_mindeta112_accp
00253                                    << "\nMinimum eta difference for ME1/1-ME3 halo tracks=" << m_mindeta113_accp
00254 
00255                                    << "\nMaximum eta for ME1-ME2 collision tracks=" << m_etamax[0]
00256                                    << "\nMaximum eta for ME1-ME3 collision tracks=" << m_etamax[1]
00257                                    << "\nMaximum eta for ME2-ME3 collision tracks=" << m_etamax[2]
00258                                    << "\nMaximum eta for ME2-ME4 collision tracks=" << m_etamax[3]
00259                                    << "\nMaximum eta for ME3-ME4 collision tracks=" << m_etamax[4]
00260                                    << "\nMaximum eta for ME1-ME2 collision tracks in overlap region=" << m_etamax[5]
00261                                    << "\nMaximum eta for ME2-MB1 collision tracks=" << m_etamax[6]
00262                                    << "\nMaximum eta for ME1-ME4 collision tracks=" << m_etamax[7]
00263 
00264                                    << "\nMaximum eta difference for ME1-ME2 (except ME1/1) halo tracks=" << m_maxdeta12_accp
00265                                    << "\nMaximum eta difference for ME1-ME3 (except ME1/1) halo tracks=" << m_maxdeta13_accp
00266                                    << "\nMaximum eta difference for ME1/1-ME2 halo tracks=" << m_maxdeta112_accp
00267                                    << "\nMaximum eta difference for ME1/1-ME3 halo tracks=" << m_maxdeta113_accp
00268 
00269                                    << "\nEta window for ME1-ME2 collision tracks=" << m_etawin[0]
00270                                    << "\nEta window for ME1-ME3 collision tracks=" << m_etawin[1]
00271                                    << "\nEta window for ME2-ME3 collision tracks=" << m_etawin[2]
00272                                    << "\nEta window for ME2-ME4 collision tracks=" << m_etawin[3]
00273                                    << "\nEta window for ME3-ME4 collision tracks=" << m_etawin[4]
00274                                    << "\nEta window for ME1-ME2 collision tracks in overlap region=" << m_etawin[5]
00275                                    << "\nEta window for ME1-ME4 collision tracks=" << m_etawin[6]
00276 
00277                                    << "\nMaximum phi difference for ME1-ME2 (except ME1/1) halo tracks=" << m_maxdphi12_accp
00278                                    << "\nMaximum phi difference for ME1-ME3 (except ME1/1) halo tracks=" << m_maxdphi13_accp
00279                                    << "\nMaximum phi difference for ME1/1-ME2 halo tracks=" << m_maxdphi112_accp
00280                                    << "\nMaximum phi difference for ME1/1-ME3 halo tracks=" << m_maxdphi113_accp
00281 
00282                                    << "\nMinimum phi difference for track cancellation logic=" << m_mindphip
00283                                    << "\nMinimum phi difference for halo track cancellation logic=" << m_mindphip_halo
00284 
00285                                    << "\nParameter for the correction of misaligned 1-2-3-4 straight tracks =" << m_straightp
00286                                    << "\nParameter for the correction of misaligned 1-2-3-4 curved tracks=" << m_curvedp
00287                                    << "\nPhi Offset for MB1A=" << m_mbaPhiOff
00288                                    << "\nPhi Offset for MB1D=" << m_mbbPhiOff 
00289 
00290                                    << "\nFirmware SP year+month+day:" << m_firmSP
00291                                    << "\nFirmware FA year+month+day:" << m_firmFA
00292                                    << "\nFirmware DD year+month+day:" << m_firmDD
00293                                    << "\nFirmware VM year+month+day:" << m_firmVM;
00294 
00295 
00296   printDisclaimer(m_firmSP,m_firmFA);
00297 
00298   // set core verbosity: for debugging only purpouses
00299   // in general the output is handled to Alex Madorsky
00300   core_ -> SetVerbose(isCoreVerbose);
00301 
00302   // Set the SP firmware 
00303   core_ -> SetSPFirmwareVersion (m_firmSP);
00304  
00305   // Set the firmware for the CORE
00306   int firmVersCore = firmSP_Map.find(m_firmSP)->second;
00307   core_ -> SetCoreFirmwareVersion (firmVersCore);
00308   edm::LogInfo( "CSCTFSectorProcessor" ) << "\nCore Firmware is set to " << core_ -> GetCoreFirmwareVersion();
00309   // ---------------------------------------------------------------------------
00310 
00311   // Check if parameters were not initialized in both: constuctor (from .cf? file) and initialize method (from EventSetup)
00312   if(m_bxa_depth<0)
00313   {
00314     initFail_ = true;
00315     edm::LogError("CSCTFSectorProcessor")<<"BXAdepth parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00316   }
00317   if(m_allowALCTonly<0)
00318   {
00319     initFail_ = true;
00320     edm::LogError("CSCTFSectorProcessor")<<"AllowALCTonly parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00321   }
00322   if(m_allowCLCTonly<0)
00323   {
00324     initFail_ = true;
00325     edm::LogError("CSCTFSectorProcessor")<<"AllowCLCTonly parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00326   }
00327   if(m_preTrigger<0)
00328   {
00329     initFail_ = true;
00330     edm::LogError("CSCTFSectorProcessor")<<"PreTrigger parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00331   }
00332   if(m_mindphip<0)
00333   {
00334     initFail_ = true;
00335     edm::LogError("CSCTFSectorProcessor")<<"mindphip parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00336   }
00337   if(m_mindetap<0)
00338   {
00339     initFail_ = true;
00340     edm::LogError("CSCTFSectorProcessor")<<"mindeta parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00341   }
00342   if(m_straightp<0)
00343   {
00344     initFail_ = true;
00345     edm::LogError("CSCTFSectorProcessor")<<"straightp parameter left unitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00346   }
00347   if(m_curvedp<0)
00348   {
00349     initFail_ = true;
00350     edm::LogError("CSCTFSectorProcessor")<<"curvedp parameter left unitialized for endcap="<<m_endcap<<",sector="<<m_sector;
00351   }
00352   if(m_mbaPhiOff<0)
00353   {
00354     initFail_ = true;
00355     edm::LogError("CSCTFSectorProcessor")<<"mbaPhiOff parameter left unitialized for endcap="<<m_endcap<<",sector="<<m_sector;
00356   }
00357   if(m_mbbPhiOff<0)
00358   {
00359     initFail_ = true;
00360     edm::LogError("CSCTFSectorProcessor")<<"mbbPhiOff parameter left unitialized for endcap="<<m_endcap<<",sector="<<m_sector;
00361   }
00362   if(m_mindeta12_accp<0)
00363   {
00364     initFail_ = true;
00365     edm::LogError("CSCTFSectorProcessor")<<"mindeta_accp12 parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00366   }
00367   if(m_maxdeta12_accp<0)
00368   {
00369     initFail_ = true;
00370     edm::LogError("CSCTFSectorProcessor")<<"maxdeta_accp12 parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00371   }
00372   if(m_maxdphi12_accp<0)
00373   {
00374     initFail_ = true;
00375     edm::LogError("CSCTFSectorProcessor")<<"maxdphi_accp12 parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00376   }
00377   if(m_mindeta13_accp<0)
00378   {
00379     initFail_ = true;
00380     edm::LogError("CSCTFSectorProcessor")<<"mindeta_accp13 parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00381   }
00382   if(m_maxdeta13_accp<0)
00383   {
00384     initFail_ = true;
00385     edm::LogError("CSCTFSectorProcessor")<<"maxdeta_accp13 parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00386   }
00387   if(m_maxdphi13_accp<0)
00388   {
00389     initFail_ = true;
00390     edm::LogError("CSCTFSectorProcessor")<<"maxdphi_accp13 parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00391   }
00392   if(m_mindeta112_accp<0)
00393   {
00394     initFail_ = true;
00395     edm::LogError("CSCTFSectorProcessor")<<"mindeta_accp112 parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00396   }
00397   if(m_maxdeta112_accp<0)
00398   {
00399     initFail_ = true;
00400     edm::LogError("CSCTFSectorProcessor")<<"maxdeta_accp112 parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00401   }
00402   if(m_maxdphi112_accp<0)
00403   {
00404     initFail_ = true;
00405     edm::LogError("CSCTFSectorProcessor")<<"maxdphi_accp112 parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00406   }
00407   if(m_mindeta113_accp<0)
00408   {
00409     initFail_ = true;
00410     edm::LogError("CSCTFSectorProcessor")<<"mindeta_accp113 parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00411   }
00412   if(m_maxdeta113_accp<0)
00413   {
00414     initFail_ = true;
00415     edm::LogError("CSCTFSectorProcessor")<<"maxdeta_accp113 parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00416   }
00417   if(m_maxdphi113_accp<0)
00418   {
00419     initFail_ = true;
00420     edm::LogError("CSCTFSectorProcessor")<<"maxdphi_accp113 parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00421   }
00422   if(m_mindphip_halo<0)
00423   {
00424     initFail_ = true;
00425     edm::LogError("CSCTFSectorProcessor")<<"mindphip_halo parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00426   }
00427   if(m_mindetap_halo<0)
00428   {
00429     initFail_ = true;
00430     edm::LogError("CSCTFSectorProcessor")<<"mindetep_halo parameter left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00431   }
00432 
00433   if(m_widePhi<0)
00434   {
00435     initFail_ = true;
00436     edm::LogError("CSCTFSectorProcessor")<<"widePhi parameter left unitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00437   }
00438 
00439   for(int index=0; index<8; index++)
00440     if(m_etamax[index]<0) 
00441     {
00442       initFail_ = true;
00443       edm::LogError("CSCTFSectorProcessor")<<"Some ("<<(8-index)<<") of EtaMax parameters left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00444     }
00445   for(int index=0; index<8; index++)
00446     if(m_etamin[index]<0) 
00447     {
00448       initFail_ = true;
00449       edm::LogError("CSCTFSectorProcessor")<<"Some ("<<(8-index)<<") of EtaMin parameters left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00450     }
00451   for(int index=0; index<7; index++)
00452     if(m_etawin[index]<0) 
00453     {
00454       initFail_ = true;
00455       edm::LogError("CSCTFSectorProcessor")<<"Some ("<<(6-index)<<") of EtaWindows parameters left uninitialized for endcap="<<m_endcap<<", sector="<<m_sector;
00456     }
00457   if(kill_fiber<0)
00458   {
00459     initFail_ = true;
00460     edm::LogError("CSCTFTrackBuilder")<<"kill_fiber parameter left uninitialized";
00461   }
00462   if(run_core<0)
00463   {
00464     initFail_ = true;
00465     edm::LogError("CSCTFTrackBuilder")<<"run_core parameter left uninitialized";
00466   }
00467   if(trigger_on_ME1a<0)
00468   {
00469     initFail_ = true;
00470     edm::LogError("CSCTFTrackBuilder")<<"trigger_on_ME1a parameter left uninitialized";
00471   }
00472   if(trigger_on_ME1b<0)
00473   {
00474     initFail_ = true;
00475     edm::LogError("CSCTFTrackBuilder")<<"trigger_on_ME1b parameter left uninitialized";
00476   }
00477   if(trigger_on_ME2 <0)
00478   {
00479     initFail_ = true;
00480     edm::LogError("CSCTFTrackBuilder")<<"trigger_on_ME2 parameter left uninitialized";
00481   }
00482   if(trigger_on_ME3 <0)
00483   {
00484     initFail_ = true;
00485     edm::LogError("CSCTFTrackBuilder")<<"trigger_on_ME3 parameter left uninitialized";
00486   }
00487   if(trigger_on_ME4 <0)
00488   {
00489     initFail_ = true;
00490     edm::LogError("CSCTFTrackBuilder")<<"trigger_on_ME4 parameter left uninitialized";
00491   }
00492   if(trigger_on_MB1a<0)
00493   {
00494     initFail_ = true;
00495     edm::LogError("CSCTFTrackBuilder")<<"trigger_on_MB1a parameter left uninitialized";
00496   }
00497   if(trigger_on_MB1d<0)
00498   {
00499     initFail_ = true;
00500     edm::LogError("CSCTFTrackBuilder")<<"trigger_on_MB1d parameter left uninitialized";
00501   }
00502   if( trigger_on_ME1a>0 || trigger_on_ME1b>0 ||trigger_on_ME2>0  ||
00503       trigger_on_ME3>0  || trigger_on_ME4>0  ||trigger_on_MB1a>0 ||trigger_on_MB1d>0 )
00504   {
00505     if(singlesTrackOutput==999)
00506     {
00507        initFail_ = true;
00508        edm::LogError("CSCTFTrackBuilder")<<"singlesTrackOutput parameter left uninitialized";
00509     }
00510     if(rescaleSinglesPhi<0)
00511     {
00512        initFail_ = true;
00513        edm::LogError("CSCTFTrackBuilder")<<"rescaleSinglesPhi parameter left uninitialized";
00514     }
00515   }
00516   if(QualityEnableME1a<0)
00517   {
00518     initFail_ = true;
00519     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME1a parameter left uninitialized";
00520   }
00521   if(QualityEnableME1b<0)
00522   {
00523     initFail_ = true;
00524     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME1b parameter left uninitialized";
00525   }
00526   if(QualityEnableME1c<0)
00527   {
00528     initFail_ = true;
00529     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME1c parameter left uninitialized";
00530   }
00531   if(QualityEnableME1d<0)
00532   {
00533     initFail_ = true;
00534     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME1d parameter left uninitialized";
00535   }
00536   if(QualityEnableME1e<0)
00537   {
00538     initFail_ = true;
00539     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME1e parameter left uninitialized";
00540   }
00541   if(QualityEnableME1f<0)
00542   {
00543     initFail_ = true;
00544     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME1f parameter left uninitialized";
00545   }
00546   if(QualityEnableME2a<0)
00547   {
00548     initFail_ = true;
00549     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME2a parameter left uninitialized";
00550   }
00551   if(QualityEnableME2b<0)
00552   {
00553     initFail_ = true;
00554     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME2b parameter left uninitialized";
00555   }
00556   if(QualityEnableME2c<0)
00557   {
00558     initFail_ = true;
00559     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME2c parameter left uninitialized";
00560   }
00561   if(QualityEnableME3a<0)
00562   {
00563     initFail_ = true;
00564     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME3a parameter left uninitialized";
00565   }
00566   if(QualityEnableME3b<0)
00567   {
00568     initFail_ = true;
00569     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME3b parameter left uninitialized";
00570   }
00571   if(QualityEnableME3c<0)
00572   {
00573     initFail_ = true;
00574     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME3c parameter left uninitialized";
00575   }
00576   if(QualityEnableME4a<0)
00577   {
00578     initFail_ = true;
00579     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME4a parameter left uninitialized";
00580   }
00581   if(QualityEnableME4b<0)
00582   {
00583     initFail_ = true;
00584     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME4b parameter left uninitialized";
00585   }
00586   if(QualityEnableME4c<0)
00587   {
00588     initFail_ = true;
00589     edm::LogError("CSCTFTrackBuilder")<<"QualityEnableME4c parameter left uninitialized";
00590   }
00591 
00592   if (m_firmSP<1)
00593   {
00594     initFail_ = true;
00595     edm::LogError("CSCTFSectorProcessor")<< " firmwareSP parameter left uninitialized!!!\n";
00596   }
00597   if (m_firmFA<1)
00598   {
00599     initFail_ = true;
00600     edm::LogError("CSCTFSectorProcessor")<< " firmwareFA parameter left uninitialized!!!\n";
00601   }
00602   if (m_firmDD<1)
00603   {
00604     initFail_ = true;
00605     edm::LogError("CSCTFSectorProcessor")<< " firmwareDD parameter left uninitialized!!!\n";
00606   }
00607   if (m_firmVM<1)
00608   {
00609     initFail_ = true;
00610     edm::LogError("CSCTFSectorProcessor")<< " firmwareVM parameter left uninitialized!!!\n";
00611   }
00612 
00613   if ( (m_firmFA != m_firmDD) ||
00614        (m_firmFA != m_firmVM) ||
00615        (m_firmDD != m_firmVM)  )
00616   {
00617     initFail_ = true;
00618     edm::LogError("CSCTFSectorProcessor::initialize")<< " firmwareFA (=" << m_firmFA << "), " 
00619                                                 << " firmwareDD (=" << m_firmDD << "), " 
00620                                                 << " firmwareVM (=" << m_firmVM << ") are NOT identical: it shoultd NOT happen!\n";
00621   }
00622 
00623 }
00624 
00625 void CSCTFSectorProcessor::readParameters(const edm::ParameterSet& pset){
00626   m_bxa_depth = pset.getParameter<unsigned>("BXAdepth");
00627   m_allowALCTonly = ( pset.getParameter<bool>("AllowALCTonly") ? 1 : 0 );
00628   m_allowCLCTonly = ( pset.getParameter<bool>("AllowCLCTonly") ? 1 : 0 );
00629   m_preTrigger = pset.getParameter<unsigned>("PreTrigger");
00630 
00631   std::vector<unsigned>::const_iterator iter;
00632   int index=0;
00633   std::vector<unsigned> etawins = pset.getParameter<std::vector<unsigned> >("EtaWindows");
00634   for(iter=etawins.begin(),index=0; iter!=etawins.end()&&index<7; iter++,index++) m_etawin[index] = *iter;
00635   std::vector<unsigned> etamins = pset.getParameter<std::vector<unsigned> >("EtaMin");
00636   for(iter=etamins.begin(),index=0; iter!=etamins.end()&&index<8; iter++,index++) m_etamin[index] = *iter;
00637   std::vector<unsigned> etamaxs = pset.getParameter<std::vector<unsigned> >("EtaMax");
00638   for(iter=etamaxs.begin(),index=0; iter!=etamaxs.end()&&index<8; iter++,index++) m_etamax[index] = *iter;
00639 
00640   m_mindphip = pset.getParameter<unsigned>("mindphip");
00641   m_mindetap = pset.getParameter<unsigned>("mindetap");
00642   m_straightp = pset.getParameter<unsigned>("straightp");
00643   m_curvedp = pset.getParameter<unsigned>("curvedp");
00644   m_mbaPhiOff = pset.getParameter<unsigned>("mbaPhiOff");
00645   m_mbbPhiOff = pset.getParameter<unsigned>("mbbPhiOff");
00646   m_widePhi = pset.getParameter<unsigned>("widePhi");
00647   m_mindeta12_accp = pset.getParameter<unsigned>("mindeta12_accp");
00648   m_maxdeta12_accp = pset.getParameter<unsigned>("maxdeta12_accp");
00649   m_maxdphi12_accp = pset.getParameter<unsigned>("maxdphi12_accp");
00650   m_mindeta13_accp = pset.getParameter<unsigned>("mindeta13_accp");
00651   m_maxdeta13_accp = pset.getParameter<unsigned>("maxdeta13_accp");
00652   m_maxdphi13_accp = pset.getParameter<unsigned>("maxdphi13_accp");
00653   m_mindeta112_accp = pset.getParameter<unsigned>("mindeta112_accp");
00654   m_maxdeta112_accp = pset.getParameter<unsigned>("maxdeta112_accp");
00655   m_maxdphi112_accp = pset.getParameter<unsigned>("maxdphi112_accp");
00656   m_mindeta113_accp = pset.getParameter<unsigned>("mindeta113_accp");
00657   m_maxdeta113_accp = pset.getParameter<unsigned>("maxdeta113_accp");
00658   m_maxdphi113_accp = pset.getParameter<unsigned>("maxdphi113_accp");
00659   m_mindphip_halo = pset.getParameter<unsigned>("mindphip_halo");
00660   m_mindetap_halo = pset.getParameter<unsigned>("mindetap_halo");
00661   kill_fiber = pset.getParameter<unsigned>("kill_fiber");
00662   run_core = pset.getParameter<bool>("run_core");
00663   trigger_on_ME1a = pset.getParameter<bool>("trigger_on_ME1a");
00664   trigger_on_ME1b = pset.getParameter<bool>("trigger_on_ME1b");
00665   trigger_on_ME2 = pset.getParameter<bool>("trigger_on_ME2");
00666   trigger_on_ME3 = pset.getParameter<bool>("trigger_on_ME3");
00667   trigger_on_ME4 = pset.getParameter<bool>("trigger_on_ME4");
00668   trigger_on_MB1a = pset.getParameter<bool>("trigger_on_MB1a");
00669   trigger_on_MB1d = pset.getParameter<bool>("trigger_on_MB1d");
00670 
00671   singlesTrackOutput = pset.getParameter<unsigned int>("singlesTrackOutput");
00672   rescaleSinglesPhi  = pset.getParameter<bool>("rescaleSinglesPhi");
00673   QualityEnableME1a = pset.getParameter<unsigned int>("QualityEnableME1a");
00674   QualityEnableME1b = pset.getParameter<unsigned int>("QualityEnableME1b");
00675   QualityEnableME1c = pset.getParameter<unsigned int>("QualityEnableME1c");
00676   QualityEnableME1d = pset.getParameter<unsigned int>("QualityEnableME1d");
00677   QualityEnableME1e = pset.getParameter<unsigned int>("QualityEnableME1e");
00678   QualityEnableME1f = pset.getParameter<unsigned int>("QualityEnableME1f");
00679   QualityEnableME2a = pset.getParameter<unsigned int>("QualityEnableME2a");
00680   QualityEnableME2b = pset.getParameter<unsigned int>("QualityEnableME2b");
00681   QualityEnableME2c = pset.getParameter<unsigned int>("QualityEnableME2c");
00682   QualityEnableME3a = pset.getParameter<unsigned int>("QualityEnableME3a");
00683   QualityEnableME3b = pset.getParameter<unsigned int>("QualityEnableME3b");
00684   QualityEnableME3c = pset.getParameter<unsigned int>("QualityEnableME3c");
00685   QualityEnableME4a = pset.getParameter<unsigned int>("QualityEnableME4a");
00686   QualityEnableME4b = pset.getParameter<unsigned int>("QualityEnableME4b");
00687   QualityEnableME4c = pset.getParameter<unsigned int>("QualityEnableME4c");
00688 
00689   m_firmSP = pset.getParameter<unsigned int>("firmwareSP");
00690   m_firmFA = pset.getParameter<unsigned int>("firmwareFA");
00691   m_firmDD = pset.getParameter<unsigned int>("firmwareDD");
00692   m_firmVM = pset.getParameter<unsigned int>("firmwareVM");
00693 
00694 }
00695 
00696 CSCTFSectorProcessor::~CSCTFSectorProcessor()
00697 {
00698   for(int i = 0; i < 5; ++i)
00699     {
00700       if(srLUTs_[FPGAs[i]]) delete srLUTs_[FPGAs[i]]; // delete the pointer
00701       srLUTs_[FPGAs[i]] = NULL; // point it at a safe place
00702     }
00703 
00704   delete core_;
00705   core_ = NULL;
00706 
00707   if(ptLUT_) delete ptLUT_;
00708   ptLUT_ = NULL;
00709 }
00710 
00711 //returns 0 for no tracks, 1 tracks found, and -1 for "exception" (what used to throw an exception)
00712 // on -1, Producer should produce empty collections for event
00713 int CSCTFSectorProcessor::run(const CSCTriggerContainer<csctf::TrackStub>& stubs)
00714 {
00715   if(initFail_)
00716     return -1;
00717 
00718   if( !ptLUT_ )
00719   {
00720     edm::LogError("CSCTFSectorProcessor::run()") << "No CSCTF PTLUTs: Initialize CSC TF LUTs first (missed call to CSCTFTrackProducer::beginJob?\n";
00721     return -1;
00722   }
00723 
00724 
00725   l1_tracks.clear();
00726   dt_stubs.clear();
00727   stub_vec_filtered.clear();
00728 
00729   std::vector<csctf::TrackStub> stub_vec = stubs.get();
00730 
00734   for(std::vector<csctf::TrackStub>::const_iterator itr=stub_vec.begin(); itr!=stub_vec.end(); itr++)
00735     switch( itr->station() ){
00736     case 5: stub_vec_filtered.push_back(*itr); break; // DT stubs get filtered by the core controll register
00737     case 4:
00738       switch( itr->getMPCLink() ){
00739       case 3: if( (kill_fiber&0x4000)==0 && QualityEnableME4c&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00740       case 2: if( (kill_fiber&0x2000)==0 && QualityEnableME4b&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00741       case 1: if( (kill_fiber&0x1000)==0 && QualityEnableME4a&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00742       default: edm::LogWarning("CSCTFSectorProcessor::run()") << "No MPC sorting for LCT: link="<<itr->getMPCLink()<<"\n";
00743       }
00744       break;
00745     case 3:
00746       switch( itr->getMPCLink() ){
00747       case 3: if( (kill_fiber&0x0800)==0 && QualityEnableME3c&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00748       case 2: if( (kill_fiber&0x0400)==0 && QualityEnableME3b&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00749       case 1: if( (kill_fiber&0x0200)==0 && QualityEnableME3a&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00750       default: edm::LogWarning("CSCTFSectorProcessor::run()") << "No MPC sorting for LCT: link="<<itr->getMPCLink()<<"\n";
00751       }
00752       break;
00753     case 2:
00754       switch( itr->getMPCLink() ){
00755       case 3: if( (kill_fiber&0x0100)==0 && QualityEnableME2c&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00756       case 2: if( (kill_fiber&0x0080)==0 && QualityEnableME2b&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00757       case 1: if( (kill_fiber&0x0040)==0 && QualityEnableME2a&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00758       default: edm::LogWarning("CSCTFSectorProcessor::run()") << "No MPC sorting for LCT: link="<<itr->getMPCLink()<<"\n";
00759       }
00760       break;
00761     case 1:
00762       switch( itr->getMPCLink() + (3*(CSCTriggerNumbering::triggerSubSectorFromLabels(CSCDetId(itr->getDetId().rawId())) - 1)) ){
00763       case 6: if( (kill_fiber&0x0020)==0 && QualityEnableME1f&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00764       case 5: if( (kill_fiber&0x0010)==0 && QualityEnableME1e&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00765       case 4: if( (kill_fiber&0x0008)==0 && QualityEnableME1d&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00766       case 3: if( (kill_fiber&0x0004)==0 && QualityEnableME1c&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00767       case 2: if( (kill_fiber&0x0002)==0 && QualityEnableME1b&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00768       case 1: if( (kill_fiber&0x0001)==0 && QualityEnableME1a&(1<<itr->getQuality()) ) stub_vec_filtered.push_back(*itr); break;
00769       default: edm::LogWarning("CSCTFSectorProcessor::run()") << "No MPC sorting for LCT: link="<<itr->getMPCLink()<<"\n";
00770       }
00771       break;
00772     default: edm::LogWarning("CSCTFSectorProcessor::run()") << "Invalid station # encountered: "<<itr->station()<<"\n";
00773     }
00774 
00783   for(std::vector<csctf::TrackStub>::iterator itr=stub_vec_filtered.begin(); itr!=stub_vec_filtered.end(); itr++)
00784     {
00785       if(itr->station() != 5)
00786         {
00787           CSCDetId id(itr->getDetId().rawId());
00788           unsigned fpga = (id.station() == 1) ? CSCTriggerNumbering::triggerSubSectorFromLabels(id) - 1 : id.station();
00789 
00790           lclphidat lclPhi;
00791           try {
00792             lclPhi = srLUTs_[FPGAs[fpga]]->localPhi(itr->getStrip(), itr->getPattern(), itr->getQuality(), itr->getBend());
00793           } catch( cms::Exception &e ) {
00794             bzero(&lclPhi,sizeof(lclPhi));
00795             edm::LogWarning("CSCTFSectorProcessor:run()") << "Exception from LocalPhi LUT in " << FPGAs[fpga]
00796                                                           << "(strip="<<itr->getStrip()<<",pattern="<<itr->getPattern()<<",quality="<<itr->getQuality()<<",bend="<<itr->getBend()<<")" <<std::endl;
00797           }
00798 
00799           gblphidat gblPhi;
00800           try {
00801             unsigned csc_id = itr->cscid();
00802             if (!m_gangedME1a) csc_id = itr->cscidSeparateME1a();
00803             gblPhi = srLUTs_[FPGAs[fpga]]->globalPhiME(lclPhi.phi_local, itr->getKeyWG(), csc_id);
00804         
00805           } catch( cms::Exception &e ) {
00806             bzero(&gblPhi,sizeof(gblPhi));
00807             edm::LogWarning("CSCTFSectorProcessor:run()") << "Exception from GlobalPhi LUT in " << FPGAs[fpga]
00808                                                           << "(phi_local="<<lclPhi.phi_local<<",KeyWG="<<itr->getKeyWG()<<",csc="<<itr->cscid()<<")"<<std::endl;
00809           }
00810 
00811           gbletadat gblEta;
00812           try {
00813             gblEta = srLUTs_[FPGAs[fpga]]->globalEtaME(lclPhi.phi_bend_local, lclPhi.phi_local, itr->getKeyWG(), itr->cscid());
00814           } catch( cms::Exception &e ) {
00815             bzero(&gblEta,sizeof(gblEta));
00816             edm::LogWarning("CSCTFSectorProcessor:run()") << "Exception from GlobalEta LUT in " << FPGAs[fpga]
00817                                                           << "(phi_bend_local="<<lclPhi.phi_bend_local<<",phi_local="<<lclPhi.phi_local<<",KeyWG="<<itr->getKeyWG()<<",csc="<<itr->cscid()<<")"<<std::endl;
00818           }
00819 
00820           gblphidat gblPhiDT;
00821           try {
00822             gblPhiDT = srLUTs_[FPGAs[fpga]]->globalPhiMB(lclPhi.phi_local, itr->getKeyWG(), itr->cscid());
00823           } catch( cms::Exception &e ) {
00824             bzero(&gblPhiDT,sizeof(gblPhiDT));
00825             edm::LogWarning("CSCTFSectorProcessor:run()") << "Exception from GlobalPhi DT LUT in " << FPGAs[fpga]
00826                                                           << "(phi_local="<<lclPhi.phi_local<<",KeyWG="<<itr->getKeyWG()<<",csc="<<itr->cscid()<<")"<<std::endl;
00827           }
00828 
00829           itr->setEtaPacked(gblEta.global_eta);
00830 
00831           if(itr->station() == 1 ) {
00832             //&& itr->cscId() > 6) { //only ring 3 
00833             itr->setPhiPacked(gblPhiDT.global_phi);// convert the DT to convert
00834             dt_stubs.push_back(*itr); // send stubs to DT
00835           }
00836 
00837           //reconvert the ME1 LCT to the CSCTF units.
00838           //the same iterator is used to fill two containers, 
00839           //the CSCTF one (stub_vec_filtered) and LCTs sent to DTTF (dt_stubs)
00840           itr->setPhiPacked(gblPhi.global_phi);
00841 
00842           LogDebug("CSCTFSectorProcessor:run()") << "LCT found, processed by FPGA: " << FPGAs[fpga] << std::endl
00843                                                  << " LCT now has (eta, phi) of: (" << itr->etaValue() << "," << itr->phiValue() <<")\n";
00844         }
00845     }
00846   
00847   CSCTriggerContainer<csctf::TrackStub> processedStubs(stub_vec_filtered);
00848 
00855   std::vector<csc::L1Track> tftks;
00856 
00857   if(run_core){
00858     core_->loadData(processedStubs, m_endcap, m_sector, m_minBX, m_maxBX);
00859     if( core_->run(m_endcap, m_sector, m_latency,
00860                    m_etamin[0], m_etamin[1], m_etamin[2], m_etamin[3],
00861                    m_etamin[4], m_etamin[5], m_etamin[6], m_etamin[7],
00862                    m_etamax[0], m_etamax[1], m_etamax[2], m_etamax[3],
00863                    m_etamax[4], m_etamax[5], m_etamax[6], m_etamax[7],
00864                    m_etawin[0], m_etawin[1], m_etawin[2],
00865                    m_etawin[3], m_etawin[4], m_etawin[5], m_etawin[6],
00866                    m_mindphip, m_mindetap,
00867                    m_mindeta12_accp,  m_maxdeta12_accp, m_maxdphi12_accp,
00868                    m_mindeta13_accp,  m_maxdeta13_accp, m_maxdphi13_accp,
00869                    m_mindeta112_accp,  m_maxdeta112_accp, m_maxdphi112_accp,
00870                    m_mindeta113_accp,  m_maxdeta113_accp, m_maxdphi113_accp,
00871                    m_mindphip_halo, m_mindetap_halo,
00872                    m_straightp, m_curvedp,
00873                    m_mbaPhiOff, m_mbbPhiOff,
00874                    m_bxa_depth, m_allowALCTonly, m_allowCLCTonly, m_preTrigger, m_widePhi,
00875                    m_minBX, m_maxBX) )
00876       {
00877         l1_tracks = core_->tracks();
00878       }
00879 
00880     tftks = l1_tracks.get();
00881 
00887     std::vector<csc::L1Track>::iterator titr = tftks.begin();
00888 
00889     for(; titr != tftks.end(); titr++)
00890       {
00891         ptadd thePtAddress(titr->ptLUTAddress());
00892         ptdat thePtData = ptLUT_->Pt(thePtAddress);
00893 
00894         if(thePtAddress.track_fr)
00895           {
00896             titr->setRank(thePtData.front_rank);
00897             titr->setChargeValidPacked(thePtData.charge_valid_front);
00898           }
00899         else
00900           {
00901             titr->setRank(thePtData.rear_rank);
00902             titr->setChargeValidPacked(thePtData.charge_valid_rear);
00903           }
00904 
00905         if( ((titr->ptLUTAddress()>>16)&0xf)==15 )
00906           {
00907             int unmodBx = titr->bx();
00908             titr->setBx(unmodBx+2);
00909           }
00910       }
00911   } //end of if(run_core)
00912 
00913   l1_tracks = tftks;
00914 
00915 
00916   // Add-on for singles:
00917   CSCTriggerContainer<csctf::TrackStub> myStubContainer[7]; //[BX]
00918   // Loop over CSC LCTs if triggering on them:
00919   if( trigger_on_ME1a || trigger_on_ME1b || trigger_on_ME2 || trigger_on_ME3 || trigger_on_ME4 || trigger_on_MB1a || trigger_on_MB1d )
00920     for(std::vector<csctf::TrackStub>::iterator itr=stub_vec_filtered.begin(); itr!=stub_vec_filtered.end(); itr++){
00921       int station = itr->station()-1;
00922       if(station != 4){
00923         int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels(CSCDetId(itr->getDetId().rawId()));
00924         int mpc = ( subSector ? subSector-1 : station+1 );
00925         if( (mpc==0&&trigger_on_ME1a) || (mpc==1&&trigger_on_ME1b) ||
00926             (mpc==2&&trigger_on_ME2)  || (mpc==3&&trigger_on_ME3)  ||
00927             (mpc==4&&trigger_on_ME4)  ||
00928             (mpc==5&& ( (trigger_on_MB1a&&subSector%2==1) || (trigger_on_MB1d&&subSector%2==0) ) ) ){
00929           int bx = itr->getBX() - m_minBX;
00930           if( bx<0 || bx>=7 ) edm::LogWarning("CSCTFTrackBuilder::buildTracks()") << " LCT BX is out of ["<<m_minBX<<","<<m_maxBX<<") range: "<<itr->getBX();
00931           else
00932             if( itr->isValid() ) myStubContainer[bx].push_back(*itr);
00933         }
00934       }
00935     }
00936 
00937   // Core's input was loaded in a relative time window BX=[0-7)
00938   // To relate it to time window of tracks (centred at BX=0) we introduce a shift:
00939   int shift = (m_maxBX + m_minBX)/2 - m_minBX;
00940 
00941   // Now we put tracks from singles in a certain bx
00942   //   if there were no tracks from the core in this endcap/sector/bx
00943   CSCTriggerContainer<csc::L1Track> tracksFromSingles;
00944   for(int bx=0; bx<7; bx++)
00945     if( myStubContainer[bx].get().size() ){ // VP in this bx
00946       bool coreTrackExists = false;
00947       // tracks are not ordered to be accessible by bx => loop them all
00948       std::vector<csc::L1Track> tracks = l1_tracks.get();
00949       for(std::vector<csc::L1Track>::iterator trk=tracks.begin(); trk<tracks.end(); trk++)
00950         if( (trk->BX() == bx-shift && trk->outputLink() == singlesTrackOutput)
00951             || (((trk->ptLUTAddress()>>16)&0xf)==15 && trk->BX()-2 == bx-shift) ){
00952           coreTrackExists = true;
00953           break;
00954         }
00955       if( coreTrackExists == false ){
00956         csc::L1TrackId trackId(m_endcap,m_sector);
00957         csc::L1Track   track(trackId);
00958         track.setBx(bx-shift);
00959         track.setOutputLink(singlesTrackOutput);
00960         //CSCCorrelatedLCTDigiCollection singles;
00961         std::vector<csctf::TrackStub> stubs = myStubContainer[bx].get();
00962         // Select best quality stub, and assign its eta/phi coordinates to the track
00963         int qualityME=0, qualityMB=0, ME=100, MB=100, linkME=7;
00964         std::vector<csctf::TrackStub>::const_iterator bestStub=stubs.end();
00965         for(std::vector<csctf::TrackStub>::const_iterator st_iter=stubs.begin(); st_iter!=stubs.end(); st_iter++){
00966           int station = st_iter->station()-1;
00967           int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels(CSCDetId(st_iter->getDetId().rawId()));
00968           int mpc = ( subSector ? subSector-1 : station+1 );
00969           // Sort MB stubs first (priority: quality OR MB1a > MB1b for the same quality)
00970           if( mpc==5 &&  (st_iter->getQuality()>qualityMB || (st_iter->getQuality()==qualityMB&&subSector<MB)) ){
00971             qualityMB = st_iter->getQuality();
00972             MB        = subSector;
00973             if(ME>4) bestStub = st_iter; // do not select this stub if ME already had any candidate
00974           }
00975           // Sort ME stubs (priority: quality OR ME1a > ME1b > ME2 > ME3 > ME4 for the same quality)
00976           if( mpc<5  && (st_iter->getQuality()> qualityME
00977                          || (st_iter->getQuality()==qualityME && mpc< ME)
00978                          || (st_iter->getQuality()==qualityME && mpc==ME && st_iter->getMPCLink()<linkME))) {
00979             qualityME = st_iter->getQuality();
00980             ME        = mpc;
00981             linkME    = st_iter->getMPCLink();
00982             bestStub  = st_iter;
00983           }
00984         }
00985         unsigned rescaled_phi = 999;
00986         if (m_firmSP <= 20100210) {
00987           // buggy implementation of the phi for singles in the wrapper... 
00988           // at the end data/emulator have to agree: e.g. wrong in the same way
00989           // BUG: getting the lowest 7 bits instead the 7 most significant ones.
00990           rescaled_phi = unsigned(24*(bestStub->phiPacked()&0x7f)/128.);
00991         }
00992         else {
00993           // correct implementation :-)
00994           rescaled_phi = unsigned(24*(bestStub->phiPacked()>>5)/128.);
00995         }
00996 
00997         unsigned unscaled_phi =              bestStub->phiPacked()>>7       ;
00998         track.setLocalPhi(rescaleSinglesPhi?rescaled_phi:unscaled_phi);
00999         track.setEtaPacked((bestStub->etaPacked()>>2)&0x1f);
01000         switch( bestStub->station() ){
01001         case 1: track.setStationIds(bestStub->getMPCLink(),0,0,0,0); break;
01002         case 2: track.setStationIds(0,bestStub->getMPCLink(),0,0,0); break;
01003         case 3: track.setStationIds(0,0,bestStub->getMPCLink(),0,0); break;
01004         case 4: track.setStationIds(0,0,0,bestStub->getMPCLink(),0); break;
01005         case 5: track.setStationIds(0,0,0,0,bestStub->getMPCLink()); break;
01006         default: edm::LogError("CSCTFSectorProcessor::run()") << "Illegal LCT link="<<bestStub->station()<<"\n"; break;
01007         }
01008         //   singles.insertDigi(CSCDetId(st_iter->getDetId().rawId()),*st_iter);
01009         //tracksFromSingles.push_back(L1CSCTrack(track,singles));
01010         track.setPtLUTAddress( (1<<16) | ((bestStub->etaPacked()<<9)&0xf000) );
01011         ptadd thePtAddress( track.ptLUTAddress() );
01012         ptdat thePtData = ptLUT_->Pt(thePtAddress);
01013         if( thePtAddress.track_fr ){
01014           track.setRank(thePtData.front_rank);
01015           track.setChargeValidPacked(thePtData.charge_valid_front);
01016         } else {
01017           track.setRank(thePtData.rear_rank);
01018           track.setChargeValidPacked(thePtData.charge_valid_rear);
01019         }
01020         tracksFromSingles.push_back(track);
01021       }
01022     }
01023   std::vector<csc::L1Track> single_tracks = tracksFromSingles.get();
01024   if( single_tracks.size() ) l1_tracks.push_many(single_tracks);
01025   // End of add-on for singles
01026 
01027   return (l1_tracks.get().size() > 0);
01028 }
01029 
01030 // according to the firmware versions print some more information
01031 void CSCTFSectorProcessor::printDisclaimer(int firmSP, int firmFA){
01032   
01033   edm::LogInfo( "CSCTFSectorProcessor" ) << "\n\n"
01034                                          << "******************************* \n"
01035                                          << "***       DISCLAIMER        *** \n"
01036                                          << "******************************* \n"
01037                                          << "\n Firmware SP version (year+month+day)=" << firmSP
01038                                          << "\n Firmware FA/VM/DD version (year+month+day)=" << firmFA;
01039   if (firmSP==20100210)
01040     edm::LogInfo( "CSCTFSectorProcessor" ) << " -> KNOWN BUGS IN THE FIRMWARE:\n"
01041                                            << "\t * Wrong phi assignment for singles\n"
01042                                            << "\t * Wrapper passes to the core only even quality DT stubs\n"
01043                                            << "\n -> BUGS ARE GOING TO BE EMULATED BY THE SOFTWARE\n\n";
01044 
01045   else 
01046     edm::LogInfo( "CSCTFSectorProcessor" ) << "\t * Correct phi assignment for singles\n";
01047   
01048   if (firmSP==20100629){
01049     edm::LogInfo( "CSCTFSectorProcessor" ) << "\t * Correct MB quality masking in the wrapper\n"
01050                                            << "\t * Core is 20100122\n";
01051   }
01052 
01053   if (firmSP==20100728)
01054     edm::LogInfo( "CSCTFSectorProcessor" ) << "\t * Inverted MB clocks\n";
01055 
01056   if (firmSP==20100901)
01057     edm::LogInfo( "CSCTFSectorProcessor" ) << "\t * Inverted charge bit\n";
01058 
01059   if (firmSP==20101011)
01060     edm::LogInfo( "CSCTFSectorProcessor" ) << "\t **** WARNING THIS FIRMWARE IS UNDER TEST ****\n"
01061                                            << "\t * Added CSC-DT assembling tracks ME1-MB2/1   \n";
01062   if (firmSP==20101210)
01063     edm::LogInfo( "CSCTFSectorProcessor" ) << "\t **** WARNING THIS FIRMWARE IS UNDER TEST ****\n"
01064                                            << "\t * New Ghost Busting Algorithm Removing Tracks\n"
01065                                            << "\t   Sharing at Least One LCT\n";
01066 
01067   if (firmSP==20110118)
01068     edm::LogInfo( "CSCTFSectorProcessor" ) << "\t **** WARNING THIS FIRMWARE IS UNDER TEST ****\n"
01069                                            << "\t * New Ghost Busting Algorithm Removing Tracks\n"
01070                                            << "\t   Sharing at Least One LCT\n"
01071                                            << "\t * Passing CLCT and PhiBend for PT LUTs\n";
01072   if (firmSP==20120131)
01073     edm::LogInfo( "CSCTFSectorProcessor" ) << "\t **** WARNING THIS FIRMWARE IS UNDER TEST ****\n"
01074                                            << "\t * non-linear dphi12 dphi23, use deta for PTLUTs \n";
01075 }