Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-04 06:14:37

0001 #include "L1Trigger/CSCTrackFinder/interface/CSCTFSectorProcessor.h"
0002 #include "L1Trigger/CSCTrackFinder/interface/CSCTrackFinderDataTypes.h"
0003 #include "DataFormats/MuonDetId/interface/CSCTriggerNumbering.h"
0004 #include "parameters.h"
0005 
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 
0008 #include <cstdlib>
0009 #include <sstream>
0010 #include <strings.h>
0011 
0012 const std::string CSCTFSectorProcessor::FPGAs[5] = {"F1", "F2", "F3", "F4", "F5"};
0013 
0014 CSCTFSectorProcessor::Tokens CSCTFSectorProcessor::consumes(const edm::ParameterSet& pset, edm::ConsumesCollector iC) {
0015   Tokens tok;
0016   if (not pset.getParameter<bool>("initializeFromPSet")) {
0017     tok.ptLUT = CSCTFPtLUT::consumes(iC);
0018     tok.config = iC.esConsumes();
0019   }
0020   return tok;
0021 }
0022 
0023 CSCTFSectorProcessor::CSCTFSectorProcessor(const unsigned& endcap,
0024                                            const unsigned& sector,
0025                                            const edm::ParameterSet& pset,
0026                                            bool tmb07,
0027                                            const L1MuTriggerScales* scales,
0028                                            const L1MuTriggerPtScale* ptScale) {
0029   m_endcap = endcap;
0030   m_sector = sector;
0031   TMB07 = tmb07;
0032 
0033   // allows a configurable option to handle unganged ME1a
0034   m_gangedME1a = pset.getUntrackedParameter<bool>("gangedME1a", true);
0035 
0036   // Parameter below should always present in ParameterSet:
0037   m_latency = pset.getParameter<unsigned>("CoreLatency");
0038   m_minBX = pset.getParameter<int>("MinBX");
0039   m_maxBX = pset.getParameter<int>("MaxBX");
0040   initializeFromPSet = pset.getParameter<bool>("initializeFromPSet");
0041   if (m_maxBX - m_minBX >= 7)
0042     edm::LogWarning("CSCTFTrackBuilder::ctor")
0043         << " BX window width >= 7BX. Resetting m_maxBX=" << (m_maxBX = m_minBX + 6);
0044 
0045   // All following parameters may appear in either ParameterSet of in EventSetup; uninitialize:
0046   m_bxa_depth = -1;
0047   m_allowALCTonly = -1;
0048   m_allowCLCTonly = -1;
0049   m_preTrigger = -1;
0050 
0051   for (int index = 0; index < 7; index++)
0052     m_etawin[index] = -1;
0053   for (int index = 0; index < 8; index++)
0054     m_etamin[index] = -1;
0055   for (int index = 0; index < 8; index++)
0056     m_etamax[index] = -1;
0057 
0058   m_mindphip = -1;
0059   m_mindetap = -1;
0060 
0061   m_mindeta12_accp = -1;
0062   m_maxdeta12_accp = -1;
0063   m_maxdphi12_accp = -1;
0064 
0065   m_mindeta13_accp = -1;
0066   m_maxdeta13_accp = -1;
0067   m_maxdphi13_accp = -1;
0068 
0069   m_mindeta112_accp = -1;
0070   m_maxdeta112_accp = -1;
0071   m_maxdphi112_accp = -1;
0072 
0073   m_mindeta113_accp = -1;
0074   m_maxdeta113_accp = -1;
0075   m_maxdphi113_accp = -1;
0076   m_mindphip_halo = -1;
0077   m_mindetap_halo = -1;
0078 
0079   m_widePhi = -1;
0080 
0081   m_straightp = -1;
0082   m_curvedp = -1;
0083 
0084   m_mbaPhiOff = -1;
0085   m_mbbPhiOff = -1;
0086 
0087   kill_fiber = -1;
0088   QualityEnableME1a = -1;
0089   QualityEnableME1b = -1;
0090   QualityEnableME1c = -1;
0091   QualityEnableME1d = -1;
0092   QualityEnableME1e = -1;
0093   QualityEnableME1f = -1;
0094   QualityEnableME2a = -1;
0095   QualityEnableME2b = -1;
0096   QualityEnableME2c = -1;
0097   QualityEnableME3a = -1;
0098   QualityEnableME3b = -1;
0099   QualityEnableME3c = -1;
0100   QualityEnableME4a = -1;
0101   QualityEnableME4b = -1;
0102   QualityEnableME4c = -1;
0103 
0104   run_core = -1;
0105   trigger_on_ME1a = -1;
0106   trigger_on_ME1b = -1;
0107   trigger_on_ME2 = -1;
0108   trigger_on_ME3 = -1;
0109   trigger_on_ME4 = -1;
0110   trigger_on_MB1a = -1;
0111   trigger_on_MB1d = -1;
0112 
0113   singlesTrackOutput = 999;
0114   rescaleSinglesPhi = -1;
0115 
0116   m_firmSP = -1;
0117   m_firmFA = -1;
0118   m_firmDD = -1;
0119   m_firmVM = -1;
0120 
0121   initFail_ = false;
0122 
0123   isCoreVerbose = pset.getParameter<bool>("isCoreVerbose");
0124 
0125   if (initializeFromPSet)
0126     readParameters(pset);
0127 
0128   // Sector Receiver LUTs initialization
0129   edm::ParameterSet srLUTset = pset.getParameter<edm::ParameterSet>("SRLUT");
0130   for (int i = 1; i <= 4; ++i) {
0131     if (i == 1)
0132       for (int j = 0; j < 2; j++) {
0133         srLUTs_[FPGAs[j]] = new CSCSectorReceiverLUT(endcap, sector, j + 1, i, srLUTset, TMB07);
0134       }
0135     else
0136       srLUTs_[FPGAs[i]] = new CSCSectorReceiverLUT(endcap, sector, 0, i, srLUTset, TMB07);
0137   }
0138 
0139   core_ = new CSCTFSPCoreLogic();
0140 
0141   // Pt LUTs initialization
0142   if (initializeFromPSet) {
0143     edm::ParameterSet ptLUTset = pset.getParameter<edm::ParameterSet>("PTLUT");
0144     ptLUT_ = new CSCTFPtLUT(ptLUTset, scales, ptScale);
0145     LogDebug("CSCTFSectorProcessor") << "Using stand-alone PT LUT for endcap=" << m_endcap << ", sector=" << m_sector;
0146   } else {
0147     ptLUT_ = nullptr;
0148     LogDebug("CSCTFSectorProcessor") << "Looking for PT LUT in EventSetup for endcap=" << m_endcap
0149                                      << ", sector=" << m_sector;
0150   }
0151 
0152   // firmware map initialization
0153   // all the information are based on the firmware releases
0154   // documented at http://www.phys.ufl.edu/~uvarov/SP05/SP05.htm
0155 
0156   // map is <m_firmSP, core_version>
0157   // it may happen that the same core is used for different firmware
0158   // versions, e.g. change in the wrapper only
0159 
0160   // this mapping accounts for runs starting from 132440
0161   // schema is year+month+day
0162   firmSP_Map.insert(std::pair<int, int>(20100210, 20100122));
0163   firmSP_Map.insert(std::pair<int, int>(20100617, 20100122));
0164   firmSP_Map.insert(std::pair<int, int>(20100629, 20100122));
0165 
0166   firmSP_Map.insert(std::pair<int, int>(20100728, 20100728));
0167 
0168   firmSP_Map.insert(std::pair<int, int>(20100901, 20100901));
0169 
0170   //testing firmwares
0171   firmSP_Map.insert(std::pair<int, int>(20101011, 20101011));
0172   firmSP_Map.insert(std::pair<int, int>(20101210, 20101210));
0173   firmSP_Map.insert(std::pair<int, int>(20110204, 20110118));
0174   firmSP_Map.insert(std::pair<int, int>(20110322, 20110118));
0175   // 2012 core with non linear dphi
0176   firmSP_Map.insert(std::pair<int, int>(20120131, 20120131));
0177   firmSP_Map.insert(std::pair<int, int>(20120227, 20120131));
0178   //2012 core: 4 station track at |eta|>2.1 -> ME2-ME3-ME4
0179   firmSP_Map.insert(std::pair<int, int>(20120313, 20120313));
0180   firmSP_Map.insert(std::pair<int, int>(20120319, 20120313));
0181   //2012 core: 4 station track at |eta|>2.1 -> ME1-ME2-ME3 test
0182   firmSP_Map.insert(std::pair<int, int>(20120730, 20120730));
0183   //2014 core: 4 station track at |eta|>2.1 -> ME1-ME2-ME3 test + correct F/R bit set
0184   firmSP_Map.insert(std::pair<int, int>(20140424, 20140424));
0185   //2014 core: 4 station track at |eta|>2.1 -> ME1-ME2-ME3 test + correct F/R bit set + bug fix
0186   firmSP_Map.insert(std::pair<int, int>(20140515, 20140515));
0187 }
0188 
0189 void CSCTFSectorProcessor::initialize(const edm::EventSetup& c, const Tokens& tokens) {
0190   initFail_ = false;
0191   if (!initializeFromPSet) {
0192     // Only pT lut can be initialized from EventSetup, all front LUTs are initialized locally from their parametrizations
0193     LogDebug("CSCTFSectorProcessor") << "Initializing endcap: " << m_endcap << " sector:" << m_sector
0194                                      << "SP:" << (m_endcap - 1) * 6 + (m_sector - 1);
0195     LogDebug("CSCTFSectorProcessor") << "Initializing pT LUT from EventSetup";
0196 
0197     ptLUT_ = new CSCTFPtLUT(c, tokens.ptLUT);
0198 
0199     // Extract from EventSetup alternative (to the one, used in constructor) ParameterSet
0200     const L1MuCSCTFConfiguration& config = c.getData(tokens.config);
0201     // And initialize only those parameters, which left uninitialized during construction
0202     readParameters(parameters(config, (m_endcap - 1) * 6 + (m_sector - 1)));
0203   }
0204 
0205   // ---------------------------------------------------------------------------
0206   // This part is added per Vasile's request.
0207   // It will help people understanding the emulator configuration
0208   LogDebug("CSCTFSectorProcessor")
0209       << "\n !!! CSCTF EMULATOR CONFIGURATION !!!"
0210       << "\n\nCORE CONFIGURATION"
0211       << "\n Coincidence Trigger? " << run_core << "\n Singles in ME1a? " << trigger_on_ME1a << "\n Singles in ME1b? "
0212       << trigger_on_ME1b << "\n Singles in ME2? " << trigger_on_ME2 << "\n Singles in ME3? " << trigger_on_ME3
0213       << "\n Singles in ME4? " << trigger_on_ME4 << "\n Singles in MB1a? " << trigger_on_MB1a << "\n Singles in MB1d? "
0214       << trigger_on_MB1d
0215 
0216       << "\n BX Analyzer depth: assemble coinc. track with stubs in +/-" << m_bxa_depth << " Bxs"
0217       << "\n Is Wide Phi Extrapolation (DeltaPhi valid up to ~15 degrees, otherwise ~7.67 degrees)? " << m_widePhi
0218       << "\n PreTrigger=" << m_preTrigger
0219 
0220       << "\n CoreLatency=" << m_latency << "\n Is Phi for singles rescaled? " << rescaleSinglesPhi
0221 
0222       << "\n\nVARIOUS CONFIGURATION PARAMETERS"
0223       << "\n Allow ALCT only? " << m_allowALCTonly << "\n Allow CLCT only? " << m_allowCLCTonly
0224 
0225       << "\nQualityEnableME1a (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME1a
0226       << "\nQualityEnableME1b (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME1b
0227       << "\nQualityEnableME1c (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME1c
0228       << "\nQualityEnableME1d (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME1d
0229       << "\nQualityEnableME1e (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME1e
0230       << "\nQualityEnableME1f (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME1f
0231       << "\nQualityEnableME2a (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME2a
0232       << "\nQualityEnableME2b (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME2b
0233       << "\nQualityEnableME2c (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME2c
0234       << "\nQualityEnableME3a (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME3a
0235       << "\nQualityEnableME3b (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME3b
0236       << "\nQualityEnableME3c (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME3c
0237       << "\nQualityEnableME4a (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME4a
0238       << "\nQualityEnableME4b (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME4b
0239       << "\nQualityEnableME4c (in general accept all LCT qualities, i.e. 0xFFFF is expected)=" << QualityEnableME4c
0240 
0241       << "\nkill_fiber=" << kill_fiber << "\nSingles Output Link="
0242       << singlesTrackOutput
0243 
0244       //the DAT_ETA registers meaning are explained at Table 2 of
0245       //http://www.phys.ufl.edu/~uvarov/SP05/LU-SP_ReferenceGuide_090915_Update.pdf
0246 
0247       << "\n\nDAT_ETA REGISTERS"
0248       << "\nMinimum eta difference for track cancellation logic=" << m_mindetap
0249       << "\nMinimum eta difference for halo track cancellation logic=" << m_mindetap_halo
0250 
0251       << "\nMinimum eta for ME1-ME2 collision tracks=" << m_etamin[0]
0252       << "\nMinimum eta for ME1-ME3 collision tracks=" << m_etamin[1]
0253       << "\nMinimum eta for ME2-ME3 collision tracks=" << m_etamin[2]
0254       << "\nMinimum eta for ME2-ME4 collision tracks=" << m_etamin[3]
0255       << "\nMinimum eta for ME3-ME4 collision tracks=" << m_etamin[4]
0256       << "\nMinimum eta for ME1-ME2 collision tracks in overlap region=" << m_etamin[5]
0257       << "\nMinimum eta for ME2-MB1 collision tracks=" << m_etamin[6]
0258       << "\nMinimum eta for ME1-ME4 collision tracks=" << m_etamin[7]
0259 
0260       << "\nMinimum eta difference for ME1-ME2 (except ME1/1) halo tracks=" << m_mindeta12_accp
0261       << "\nMinimum eta difference for ME1-ME3 (except ME1/1) halo tracks=" << m_mindeta13_accp
0262       << "\nMinimum eta difference for ME1/1-ME2 halo tracks=" << m_mindeta112_accp
0263       << "\nMinimum eta difference for ME1/1-ME3 halo tracks=" << m_mindeta113_accp
0264 
0265       << "\nMaximum eta for ME1-ME2 collision tracks=" << m_etamax[0]
0266       << "\nMaximum eta for ME1-ME3 collision tracks=" << m_etamax[1]
0267       << "\nMaximum eta for ME2-ME3 collision tracks=" << m_etamax[2]
0268       << "\nMaximum eta for ME2-ME4 collision tracks=" << m_etamax[3]
0269       << "\nMaximum eta for ME3-ME4 collision tracks=" << m_etamax[4]
0270       << "\nMaximum eta for ME1-ME2 collision tracks in overlap region=" << m_etamax[5]
0271       << "\nMaximum eta for ME2-MB1 collision tracks=" << m_etamax[6]
0272       << "\nMaximum eta for ME1-ME4 collision tracks=" << m_etamax[7]
0273 
0274       << "\nMaximum eta difference for ME1-ME2 (except ME1/1) halo tracks=" << m_maxdeta12_accp
0275       << "\nMaximum eta difference for ME1-ME3 (except ME1/1) halo tracks=" << m_maxdeta13_accp
0276       << "\nMaximum eta difference for ME1/1-ME2 halo tracks=" << m_maxdeta112_accp
0277       << "\nMaximum eta difference for ME1/1-ME3 halo tracks=" << m_maxdeta113_accp
0278 
0279       << "\nEta window for ME1-ME2 collision tracks=" << m_etawin[0]
0280       << "\nEta window for ME1-ME3 collision tracks=" << m_etawin[1]
0281       << "\nEta window for ME2-ME3 collision tracks=" << m_etawin[2]
0282       << "\nEta window for ME2-ME4 collision tracks=" << m_etawin[3]
0283       << "\nEta window for ME3-ME4 collision tracks=" << m_etawin[4]
0284       << "\nEta window for ME1-ME2 collision tracks in overlap region=" << m_etawin[5]
0285       << "\nEta window for ME1-ME4 collision tracks=" << m_etawin[6]
0286 
0287       << "\nMaximum phi difference for ME1-ME2 (except ME1/1) halo tracks=" << m_maxdphi12_accp
0288       << "\nMaximum phi difference for ME1-ME3 (except ME1/1) halo tracks=" << m_maxdphi13_accp
0289       << "\nMaximum phi difference for ME1/1-ME2 halo tracks=" << m_maxdphi112_accp
0290       << "\nMaximum phi difference for ME1/1-ME3 halo tracks=" << m_maxdphi113_accp
0291 
0292       << "\nMinimum phi difference for track cancellation logic=" << m_mindphip
0293       << "\nMinimum phi difference for halo track cancellation logic=" << m_mindphip_halo
0294 
0295       << "\nParameter for the correction of misaligned 1-2-3-4 straight tracks =" << m_straightp
0296       << "\nParameter for the correction of misaligned 1-2-3-4 curved tracks=" << m_curvedp
0297       << "\nPhi Offset for MB1A=" << m_mbaPhiOff << "\nPhi Offset for MB1D=" << m_mbbPhiOff
0298 
0299       << "\nFirmware SP year+month+day:" << m_firmSP << "\nFirmware FA year+month+day:" << m_firmFA
0300       << "\nFirmware DD year+month+day:" << m_firmDD << "\nFirmware VM year+month+day:" << m_firmVM;
0301 
0302   printDisclaimer(m_firmSP, m_firmFA);
0303 
0304   // set core verbosity: for debugging only purpouses
0305   // in general the output is handled to Alex Madorsky
0306   core_->SetVerbose(isCoreVerbose);
0307 
0308   // Set the SP firmware
0309   core_->SetSPFirmwareVersion(m_firmSP);
0310 
0311   // Set the firmware for the CORE
0312   int firmVersCore = firmSP_Map.find(m_firmSP)->second;
0313   core_->SetCoreFirmwareVersion(firmVersCore);
0314   edm::LogInfo("CSCTFSectorProcessor") << "\nCore Firmware is set to " << core_->GetCoreFirmwareVersion();
0315   // ---------------------------------------------------------------------------
0316 
0317   // Check if parameters were not initialized in both: constuctor (from .cf? file) and initialize method (from EventSetup)
0318   if (m_bxa_depth < 0) {
0319     initFail_ = true;
0320     edm::LogError("CSCTFSectorProcessor")
0321         << "BXAdepth parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0322   }
0323   if (m_allowALCTonly < 0) {
0324     initFail_ = true;
0325     edm::LogError("CSCTFSectorProcessor")
0326         << "AllowALCTonly parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0327   }
0328   if (m_allowCLCTonly < 0) {
0329     initFail_ = true;
0330     edm::LogError("CSCTFSectorProcessor")
0331         << "AllowCLCTonly parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0332   }
0333   if (m_preTrigger < 0) {
0334     initFail_ = true;
0335     edm::LogError("CSCTFSectorProcessor")
0336         << "PreTrigger parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0337   }
0338   if (m_mindphip < 0) {
0339     initFail_ = true;
0340     edm::LogError("CSCTFSectorProcessor")
0341         << "mindphip parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0342   }
0343   if (m_mindetap < 0) {
0344     initFail_ = true;
0345     edm::LogError("CSCTFSectorProcessor")
0346         << "mindeta parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0347   }
0348   if (m_straightp < 0) {
0349     initFail_ = true;
0350     edm::LogError("CSCTFSectorProcessor")
0351         << "straightp parameter left unitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0352   }
0353   if (m_curvedp < 0) {
0354     initFail_ = true;
0355     edm::LogError("CSCTFSectorProcessor")
0356         << "curvedp parameter left unitialized for endcap=" << m_endcap << ",sector=" << m_sector;
0357   }
0358   if (m_mbaPhiOff < 0) {
0359     initFail_ = true;
0360     edm::LogError("CSCTFSectorProcessor")
0361         << "mbaPhiOff parameter left unitialized for endcap=" << m_endcap << ",sector=" << m_sector;
0362   }
0363   if (m_mbbPhiOff < 0) {
0364     initFail_ = true;
0365     edm::LogError("CSCTFSectorProcessor")
0366         << "mbbPhiOff parameter left unitialized for endcap=" << m_endcap << ",sector=" << m_sector;
0367   }
0368   if (m_mindeta12_accp < 0) {
0369     initFail_ = true;
0370     edm::LogError("CSCTFSectorProcessor")
0371         << "mindeta_accp12 parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0372   }
0373   if (m_maxdeta12_accp < 0) {
0374     initFail_ = true;
0375     edm::LogError("CSCTFSectorProcessor")
0376         << "maxdeta_accp12 parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0377   }
0378   if (m_maxdphi12_accp < 0) {
0379     initFail_ = true;
0380     edm::LogError("CSCTFSectorProcessor")
0381         << "maxdphi_accp12 parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0382   }
0383   if (m_mindeta13_accp < 0) {
0384     initFail_ = true;
0385     edm::LogError("CSCTFSectorProcessor")
0386         << "mindeta_accp13 parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0387   }
0388   if (m_maxdeta13_accp < 0) {
0389     initFail_ = true;
0390     edm::LogError("CSCTFSectorProcessor")
0391         << "maxdeta_accp13 parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0392   }
0393   if (m_maxdphi13_accp < 0) {
0394     initFail_ = true;
0395     edm::LogError("CSCTFSectorProcessor")
0396         << "maxdphi_accp13 parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0397   }
0398   if (m_mindeta112_accp < 0) {
0399     initFail_ = true;
0400     edm::LogError("CSCTFSectorProcessor")
0401         << "mindeta_accp112 parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0402   }
0403   if (m_maxdeta112_accp < 0) {
0404     initFail_ = true;
0405     edm::LogError("CSCTFSectorProcessor")
0406         << "maxdeta_accp112 parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0407   }
0408   if (m_maxdphi112_accp < 0) {
0409     initFail_ = true;
0410     edm::LogError("CSCTFSectorProcessor")
0411         << "maxdphi_accp112 parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0412   }
0413   if (m_mindeta113_accp < 0) {
0414     initFail_ = true;
0415     edm::LogError("CSCTFSectorProcessor")
0416         << "mindeta_accp113 parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0417   }
0418   if (m_maxdeta113_accp < 0) {
0419     initFail_ = true;
0420     edm::LogError("CSCTFSectorProcessor")
0421         << "maxdeta_accp113 parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0422   }
0423   if (m_maxdphi113_accp < 0) {
0424     initFail_ = true;
0425     edm::LogError("CSCTFSectorProcessor")
0426         << "maxdphi_accp113 parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0427   }
0428   if (m_mindphip_halo < 0) {
0429     initFail_ = true;
0430     edm::LogError("CSCTFSectorProcessor")
0431         << "mindphip_halo parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0432   }
0433   if (m_mindetap_halo < 0) {
0434     initFail_ = true;
0435     edm::LogError("CSCTFSectorProcessor")
0436         << "mindetep_halo parameter left uninitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0437   }
0438 
0439   if (m_widePhi < 0) {
0440     initFail_ = true;
0441     edm::LogError("CSCTFSectorProcessor")
0442         << "widePhi parameter left unitialized for endcap=" << m_endcap << ", sector=" << m_sector;
0443   }
0444 
0445   for (int index = 0; index < 8; index++)
0446     if (m_etamax[index] < 0) {
0447       initFail_ = true;
0448       edm::LogError("CSCTFSectorProcessor")
0449           << "Some (" << (8 - index) << ") of EtaMax parameters left uninitialized for endcap=" << m_endcap
0450           << ", sector=" << m_sector;
0451     }
0452   for (int index = 0; index < 8; index++)
0453     if (m_etamin[index] < 0) {
0454       initFail_ = true;
0455       edm::LogError("CSCTFSectorProcessor")
0456           << "Some (" << (8 - index) << ") of EtaMin parameters left uninitialized for endcap=" << m_endcap
0457           << ", sector=" << m_sector;
0458     }
0459   for (int index = 0; index < 7; index++)
0460     if (m_etawin[index] < 0) {
0461       initFail_ = true;
0462       edm::LogError("CSCTFSectorProcessor")
0463           << "Some (" << (6 - index) << ") of EtaWindows parameters left uninitialized for endcap=" << m_endcap
0464           << ", sector=" << m_sector;
0465     }
0466   if (kill_fiber < 0) {
0467     initFail_ = true;
0468     edm::LogError("CSCTFTrackBuilder") << "kill_fiber parameter left uninitialized";
0469   }
0470   if (run_core < 0) {
0471     initFail_ = true;
0472     edm::LogError("CSCTFTrackBuilder") << "run_core parameter left uninitialized";
0473   }
0474   if (trigger_on_ME1a < 0) {
0475     initFail_ = true;
0476     edm::LogError("CSCTFTrackBuilder") << "trigger_on_ME1a parameter left uninitialized";
0477   }
0478   if (trigger_on_ME1b < 0) {
0479     initFail_ = true;
0480     edm::LogError("CSCTFTrackBuilder") << "trigger_on_ME1b parameter left uninitialized";
0481   }
0482   if (trigger_on_ME2 < 0) {
0483     initFail_ = true;
0484     edm::LogError("CSCTFTrackBuilder") << "trigger_on_ME2 parameter left uninitialized";
0485   }
0486   if (trigger_on_ME3 < 0) {
0487     initFail_ = true;
0488     edm::LogError("CSCTFTrackBuilder") << "trigger_on_ME3 parameter left uninitialized";
0489   }
0490   if (trigger_on_ME4 < 0) {
0491     initFail_ = true;
0492     edm::LogError("CSCTFTrackBuilder") << "trigger_on_ME4 parameter left uninitialized";
0493   }
0494   if (trigger_on_MB1a < 0) {
0495     initFail_ = true;
0496     edm::LogError("CSCTFTrackBuilder") << "trigger_on_MB1a parameter left uninitialized";
0497   }
0498   if (trigger_on_MB1d < 0) {
0499     initFail_ = true;
0500     edm::LogError("CSCTFTrackBuilder") << "trigger_on_MB1d parameter left uninitialized";
0501   }
0502   if (trigger_on_ME1a > 0 || trigger_on_ME1b > 0 || trigger_on_ME2 > 0 || trigger_on_ME3 > 0 || trigger_on_ME4 > 0 ||
0503       trigger_on_MB1a > 0 || trigger_on_MB1d > 0) {
0504     if (singlesTrackOutput == 999) {
0505       initFail_ = true;
0506       edm::LogError("CSCTFTrackBuilder") << "singlesTrackOutput parameter left uninitialized";
0507     }
0508     if (rescaleSinglesPhi < 0) {
0509       initFail_ = true;
0510       edm::LogError("CSCTFTrackBuilder") << "rescaleSinglesPhi parameter left uninitialized";
0511     }
0512   }
0513   if (QualityEnableME1a < 0) {
0514     initFail_ = true;
0515     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME1a parameter left uninitialized";
0516   }
0517   if (QualityEnableME1b < 0) {
0518     initFail_ = true;
0519     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME1b parameter left uninitialized";
0520   }
0521   if (QualityEnableME1c < 0) {
0522     initFail_ = true;
0523     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME1c parameter left uninitialized";
0524   }
0525   if (QualityEnableME1d < 0) {
0526     initFail_ = true;
0527     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME1d parameter left uninitialized";
0528   }
0529   if (QualityEnableME1e < 0) {
0530     initFail_ = true;
0531     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME1e parameter left uninitialized";
0532   }
0533   if (QualityEnableME1f < 0) {
0534     initFail_ = true;
0535     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME1f parameter left uninitialized";
0536   }
0537   if (QualityEnableME2a < 0) {
0538     initFail_ = true;
0539     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME2a parameter left uninitialized";
0540   }
0541   if (QualityEnableME2b < 0) {
0542     initFail_ = true;
0543     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME2b parameter left uninitialized";
0544   }
0545   if (QualityEnableME2c < 0) {
0546     initFail_ = true;
0547     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME2c parameter left uninitialized";
0548   }
0549   if (QualityEnableME3a < 0) {
0550     initFail_ = true;
0551     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME3a parameter left uninitialized";
0552   }
0553   if (QualityEnableME3b < 0) {
0554     initFail_ = true;
0555     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME3b parameter left uninitialized";
0556   }
0557   if (QualityEnableME3c < 0) {
0558     initFail_ = true;
0559     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME3c parameter left uninitialized";
0560   }
0561   if (QualityEnableME4a < 0) {
0562     initFail_ = true;
0563     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME4a parameter left uninitialized";
0564   }
0565   if (QualityEnableME4b < 0) {
0566     initFail_ = true;
0567     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME4b parameter left uninitialized";
0568   }
0569   if (QualityEnableME4c < 0) {
0570     initFail_ = true;
0571     edm::LogError("CSCTFTrackBuilder") << "QualityEnableME4c parameter left uninitialized";
0572   }
0573 
0574   if (m_firmSP < 1) {
0575     initFail_ = true;
0576     edm::LogError("CSCTFSectorProcessor") << " firmwareSP parameter left uninitialized!!!\n";
0577   }
0578   if (m_firmFA < 1) {
0579     initFail_ = true;
0580     edm::LogError("CSCTFSectorProcessor") << " firmwareFA parameter left uninitialized!!!\n";
0581   }
0582   if (m_firmDD < 1) {
0583     initFail_ = true;
0584     edm::LogError("CSCTFSectorProcessor") << " firmwareDD parameter left uninitialized!!!\n";
0585   }
0586   if (m_firmVM < 1) {
0587     initFail_ = true;
0588     edm::LogError("CSCTFSectorProcessor") << " firmwareVM parameter left uninitialized!!!\n";
0589   }
0590 
0591   if ((m_firmFA != m_firmDD) || (m_firmFA != m_firmVM) || (m_firmDD != m_firmVM)) {
0592     initFail_ = true;
0593     edm::LogError("CSCTFSectorProcessor::initialize")
0594         << " firmwareFA (=" << m_firmFA << "), "
0595         << " firmwareDD (=" << m_firmDD << "), "
0596         << " firmwareVM (=" << m_firmVM << ") are NOT identical: it shoultd NOT happen!\n";
0597   }
0598 }
0599 
0600 void CSCTFSectorProcessor::readParameters(const edm::ParameterSet& pset) {
0601   m_bxa_depth = pset.getParameter<unsigned>("BXAdepth");
0602   m_allowALCTonly = (pset.getParameter<bool>("AllowALCTonly") ? 1 : 0);
0603   m_allowCLCTonly = (pset.getParameter<bool>("AllowCLCTonly") ? 1 : 0);
0604   m_preTrigger = pset.getParameter<unsigned>("PreTrigger");
0605 
0606   std::vector<unsigned>::const_iterator iter;
0607   int index = 0;
0608   std::vector<unsigned> etawins = pset.getParameter<std::vector<unsigned> >("EtaWindows");
0609   for (iter = etawins.begin(), index = 0; iter != etawins.end() && index < 7; iter++, index++)
0610     m_etawin[index] = *iter;
0611   std::vector<unsigned> etamins = pset.getParameter<std::vector<unsigned> >("EtaMin");
0612   for (iter = etamins.begin(), index = 0; iter != etamins.end() && index < 8; iter++, index++)
0613     m_etamin[index] = *iter;
0614   std::vector<unsigned> etamaxs = pset.getParameter<std::vector<unsigned> >("EtaMax");
0615   for (iter = etamaxs.begin(), index = 0; iter != etamaxs.end() && index < 8; iter++, index++)
0616     m_etamax[index] = *iter;
0617 
0618   m_mindphip = pset.getParameter<unsigned>("mindphip");
0619   m_mindetap = pset.getParameter<unsigned>("mindetap");
0620   m_straightp = pset.getParameter<unsigned>("straightp");
0621   m_curvedp = pset.getParameter<unsigned>("curvedp");
0622   m_mbaPhiOff = pset.getParameter<unsigned>("mbaPhiOff");
0623   m_mbbPhiOff = pset.getParameter<unsigned>("mbbPhiOff");
0624   m_widePhi = pset.getParameter<unsigned>("widePhi");
0625   m_mindeta12_accp = pset.getParameter<unsigned>("mindeta12_accp");
0626   m_maxdeta12_accp = pset.getParameter<unsigned>("maxdeta12_accp");
0627   m_maxdphi12_accp = pset.getParameter<unsigned>("maxdphi12_accp");
0628   m_mindeta13_accp = pset.getParameter<unsigned>("mindeta13_accp");
0629   m_maxdeta13_accp = pset.getParameter<unsigned>("maxdeta13_accp");
0630   m_maxdphi13_accp = pset.getParameter<unsigned>("maxdphi13_accp");
0631   m_mindeta112_accp = pset.getParameter<unsigned>("mindeta112_accp");
0632   m_maxdeta112_accp = pset.getParameter<unsigned>("maxdeta112_accp");
0633   m_maxdphi112_accp = pset.getParameter<unsigned>("maxdphi112_accp");
0634   m_mindeta113_accp = pset.getParameter<unsigned>("mindeta113_accp");
0635   m_maxdeta113_accp = pset.getParameter<unsigned>("maxdeta113_accp");
0636   m_maxdphi113_accp = pset.getParameter<unsigned>("maxdphi113_accp");
0637   m_mindphip_halo = pset.getParameter<unsigned>("mindphip_halo");
0638   m_mindetap_halo = pset.getParameter<unsigned>("mindetap_halo");
0639   kill_fiber = pset.getParameter<unsigned>("kill_fiber");
0640   run_core = pset.getParameter<bool>("run_core");
0641   trigger_on_ME1a = pset.getParameter<bool>("trigger_on_ME1a");
0642   trigger_on_ME1b = pset.getParameter<bool>("trigger_on_ME1b");
0643   trigger_on_ME2 = pset.getParameter<bool>("trigger_on_ME2");
0644   trigger_on_ME3 = pset.getParameter<bool>("trigger_on_ME3");
0645   trigger_on_ME4 = pset.getParameter<bool>("trigger_on_ME4");
0646   trigger_on_MB1a = pset.getParameter<bool>("trigger_on_MB1a");
0647   trigger_on_MB1d = pset.getParameter<bool>("trigger_on_MB1d");
0648 
0649   singlesTrackOutput = pset.getParameter<unsigned int>("singlesTrackOutput");
0650   rescaleSinglesPhi = pset.getParameter<bool>("rescaleSinglesPhi");
0651   QualityEnableME1a = pset.getParameter<unsigned int>("QualityEnableME1a");
0652   QualityEnableME1b = pset.getParameter<unsigned int>("QualityEnableME1b");
0653   QualityEnableME1c = pset.getParameter<unsigned int>("QualityEnableME1c");
0654   QualityEnableME1d = pset.getParameter<unsigned int>("QualityEnableME1d");
0655   QualityEnableME1e = pset.getParameter<unsigned int>("QualityEnableME1e");
0656   QualityEnableME1f = pset.getParameter<unsigned int>("QualityEnableME1f");
0657   QualityEnableME2a = pset.getParameter<unsigned int>("QualityEnableME2a");
0658   QualityEnableME2b = pset.getParameter<unsigned int>("QualityEnableME2b");
0659   QualityEnableME2c = pset.getParameter<unsigned int>("QualityEnableME2c");
0660   QualityEnableME3a = pset.getParameter<unsigned int>("QualityEnableME3a");
0661   QualityEnableME3b = pset.getParameter<unsigned int>("QualityEnableME3b");
0662   QualityEnableME3c = pset.getParameter<unsigned int>("QualityEnableME3c");
0663   QualityEnableME4a = pset.getParameter<unsigned int>("QualityEnableME4a");
0664   QualityEnableME4b = pset.getParameter<unsigned int>("QualityEnableME4b");
0665   QualityEnableME4c = pset.getParameter<unsigned int>("QualityEnableME4c");
0666 
0667   m_firmSP = pset.getParameter<unsigned int>("firmwareSP");
0668   m_firmFA = pset.getParameter<unsigned int>("firmwareFA");
0669   m_firmDD = pset.getParameter<unsigned int>("firmwareDD");
0670   m_firmVM = pset.getParameter<unsigned int>("firmwareVM");
0671 }
0672 
0673 CSCTFSectorProcessor::~CSCTFSectorProcessor() {
0674   for (int i = 0; i < 5; ++i) {
0675     if (srLUTs_[FPGAs[i]])
0676       delete srLUTs_[FPGAs[i]];   // delete the pointer
0677     srLUTs_[FPGAs[i]] = nullptr;  // point it at a safe place
0678   }
0679 
0680   delete core_;
0681   core_ = nullptr;
0682 
0683   if (ptLUT_)
0684     delete ptLUT_;
0685   ptLUT_ = nullptr;
0686 }
0687 
0688 //returns 0 for no tracks, 1 tracks found, and -1 for "exception" (what used to throw an exception)
0689 // on -1, Producer should produce empty collections for event
0690 int CSCTFSectorProcessor::run(const CSCTriggerContainer<csctf::TrackStub>& stubs) {
0691   if (initFail_)
0692     return -1;
0693 
0694   if (!ptLUT_) {
0695     edm::LogError("CSCTFSectorProcessor::run()")
0696         << "No CSCTF PTLUTs: Initialize CSC TF LUTs first (missed call to CSCTFTrackProducer::beginJob?\n";
0697     return -1;
0698   }
0699 
0700   l1_tracks.clear();
0701   dt_stubs.clear();
0702   stub_vec_filtered.clear();
0703 
0704   std::vector<csctf::TrackStub> stub_vec = stubs.get();
0705 
0706   /** STEP ZERO
0707    *  Remove stubs, which were masked out by kill_fiber or QualityEnable parameters
0708    */
0709   for (std::vector<csctf::TrackStub>::const_iterator itr = stub_vec.begin(); itr != stub_vec.end(); itr++)
0710     switch (itr->station()) {
0711       case 5:
0712         stub_vec_filtered.push_back(*itr);
0713         break;  // DT stubs get filtered by the core controll register
0714       case 4:
0715         switch (itr->getMPCLink()) {
0716           case 3:
0717             if ((kill_fiber & 0x4000) == 0 && QualityEnableME4c & (1 << itr->getQuality()))
0718               stub_vec_filtered.push_back(*itr);
0719             break;
0720           case 2:
0721             if ((kill_fiber & 0x2000) == 0 && QualityEnableME4b & (1 << itr->getQuality()))
0722               stub_vec_filtered.push_back(*itr);
0723             break;
0724           case 1:
0725             if ((kill_fiber & 0x1000) == 0 && QualityEnableME4a & (1 << itr->getQuality()))
0726               stub_vec_filtered.push_back(*itr);
0727             break;
0728           default:
0729             edm::LogWarning("CSCTFSectorProcessor::run()")
0730                 << "No MPC sorting for LCT: link=" << itr->getMPCLink() << "\n";
0731         }
0732         break;
0733       case 3:
0734         switch (itr->getMPCLink()) {
0735           case 3:
0736             if ((kill_fiber & 0x0800) == 0 && QualityEnableME3c & (1 << itr->getQuality()))
0737               stub_vec_filtered.push_back(*itr);
0738             break;
0739           case 2:
0740             if ((kill_fiber & 0x0400) == 0 && QualityEnableME3b & (1 << itr->getQuality()))
0741               stub_vec_filtered.push_back(*itr);
0742             break;
0743           case 1:
0744             if ((kill_fiber & 0x0200) == 0 && QualityEnableME3a & (1 << itr->getQuality()))
0745               stub_vec_filtered.push_back(*itr);
0746             break;
0747           default:
0748             edm::LogWarning("CSCTFSectorProcessor::run()")
0749                 << "No MPC sorting for LCT: link=" << itr->getMPCLink() << "\n";
0750         }
0751         break;
0752       case 2:
0753         switch (itr->getMPCLink()) {
0754           case 3:
0755             if ((kill_fiber & 0x0100) == 0 && QualityEnableME2c & (1 << itr->getQuality()))
0756               stub_vec_filtered.push_back(*itr);
0757             break;
0758           case 2:
0759             if ((kill_fiber & 0x0080) == 0 && QualityEnableME2b & (1 << itr->getQuality()))
0760               stub_vec_filtered.push_back(*itr);
0761             break;
0762           case 1:
0763             if ((kill_fiber & 0x0040) == 0 && QualityEnableME2a & (1 << itr->getQuality()))
0764               stub_vec_filtered.push_back(*itr);
0765             break;
0766           default:
0767             edm::LogWarning("CSCTFSectorProcessor::run()")
0768                 << "No MPC sorting for LCT: link=" << itr->getMPCLink() << "\n";
0769         }
0770         break;
0771       case 1:
0772         switch (itr->getMPCLink() +
0773                 (3 * (CSCTriggerNumbering::triggerSubSectorFromLabels(CSCDetId(itr->getDetId().rawId())) - 1))) {
0774           case 6:
0775             if ((kill_fiber & 0x0020) == 0 && QualityEnableME1f & (1 << itr->getQuality()))
0776               stub_vec_filtered.push_back(*itr);
0777             break;
0778           case 5:
0779             if ((kill_fiber & 0x0010) == 0 && QualityEnableME1e & (1 << itr->getQuality()))
0780               stub_vec_filtered.push_back(*itr);
0781             break;
0782           case 4:
0783             if ((kill_fiber & 0x0008) == 0 && QualityEnableME1d & (1 << itr->getQuality()))
0784               stub_vec_filtered.push_back(*itr);
0785             break;
0786           case 3:
0787             if ((kill_fiber & 0x0004) == 0 && QualityEnableME1c & (1 << itr->getQuality()))
0788               stub_vec_filtered.push_back(*itr);
0789             break;
0790           case 2:
0791             if ((kill_fiber & 0x0002) == 0 && QualityEnableME1b & (1 << itr->getQuality()))
0792               stub_vec_filtered.push_back(*itr);
0793             break;
0794           case 1:
0795             if ((kill_fiber & 0x0001) == 0 && QualityEnableME1a & (1 << itr->getQuality()))
0796               stub_vec_filtered.push_back(*itr);
0797             break;
0798           default:
0799             edm::LogWarning("CSCTFSectorProcessor::run()")
0800                 << "No MPC sorting for LCT: link=" << itr->getMPCLink() << "\n";
0801         }
0802         break;
0803       default:
0804         edm::LogWarning("CSCTFSectorProcessor::run()") << "Invalid station # encountered: " << itr->station() << "\n";
0805     }
0806 
0807   /** STEP ONE
0808    *  We take stubs from the MPC and assign their eta and phi
0809    *  coordinates using the SR Lookup tables.
0810    *  This is independent of what BX we are on so we can
0811    *  process one large vector of stubs.
0812    *  After this we append the stubs gained from the DT system.
0813    */
0814 
0815   for (std::vector<csctf::TrackStub>::iterator itr = stub_vec_filtered.begin(); itr != stub_vec_filtered.end(); itr++) {
0816     if (itr->station() != 5) {
0817       CSCDetId id(itr->getDetId().rawId());
0818       unsigned fpga = (id.station() == 1) ? CSCTriggerNumbering::triggerSubSectorFromLabels(id) - 1 : id.station();
0819 
0820       lclphidat lclPhi;
0821       try {
0822         lclPhi = srLUTs_[FPGAs[fpga]]->localPhi(
0823             itr->getStrip(), itr->getPattern(), itr->getQuality(), itr->getBend(), m_gangedME1a);
0824       } catch (cms::Exception& e) {
0825         bzero(&lclPhi, sizeof(lclPhi));
0826         edm::LogWarning("CSCTFSectorProcessor:run()")
0827             << "Exception from LocalPhi LUT in " << FPGAs[fpga] << "(strip=" << itr->getStrip()
0828             << ",pattern=" << itr->getPattern() << ",quality=" << itr->getQuality() << ",bend=" << itr->getBend() << ")"
0829             << std::endl;
0830       }
0831 
0832       gblphidat gblPhi;
0833       try {
0834         unsigned csc_id = itr->cscid();
0835         if (!m_gangedME1a)
0836           csc_id = itr->cscidSeparateME1a();
0837         //std::cout << "station="<<id.station()<<" ring="<<id.ring()<<" strip="<<itr->getStrip()<<" WG="<<itr->getKeyWG()<<std::endl;
0838         //std::cout << "csc_id=" << csc_id << std::endl;
0839         gblPhi = srLUTs_[FPGAs[fpga]]->globalPhiME(lclPhi.phi_local, itr->getKeyWG(), csc_id, m_gangedME1a);
0840 
0841       } catch (cms::Exception& e) {
0842         bzero(&gblPhi, sizeof(gblPhi));
0843         edm::LogWarning("CSCTFSectorProcessor:run()")
0844             << "Exception from GlobalPhi LUT in " << FPGAs[fpga] << "(phi_local=" << lclPhi.phi_local
0845             << ",KeyWG=" << itr->getKeyWG() << ",csc=" << itr->cscid() << ")" << std::endl;
0846       }
0847 
0848       gbletadat gblEta;
0849       try {
0850         unsigned csc_id = itr->cscid();
0851         if (!m_gangedME1a)
0852           csc_id = itr->cscidSeparateME1a();
0853         gblEta = srLUTs_[FPGAs[fpga]]->globalEtaME(
0854             lclPhi.phi_bend_local, lclPhi.phi_local, itr->getKeyWG(), csc_id, m_gangedME1a);
0855         //gblEta = srLUTs_[FPGAs[fpga]]->globalEtaME(lclPhi.phi_bend_local, lclPhi.phi_local, itr->getKeyWG(), itr->cscid());
0856       } catch (cms::Exception& e) {
0857         bzero(&gblEta, sizeof(gblEta));
0858         edm::LogWarning("CSCTFSectorProcessor:run()")
0859             << "Exception from GlobalEta LUT in " << FPGAs[fpga] << "(phi_bend_local=" << lclPhi.phi_bend_local
0860             << ",phi_local=" << lclPhi.phi_local << ",KeyWG=" << itr->getKeyWG() << ",csc=" << itr->cscid() << ")"
0861             << std::endl;
0862       }
0863 
0864       gblphidat gblPhiDT;
0865       try {
0866         gblPhiDT = srLUTs_[FPGAs[fpga]]->globalPhiMB(lclPhi.phi_local, itr->getKeyWG(), itr->cscid(), m_gangedME1a);
0867       } catch (cms::Exception& e) {
0868         bzero(&gblPhiDT, sizeof(gblPhiDT));
0869         edm::LogWarning("CSCTFSectorProcessor:run()")
0870             << "Exception from GlobalPhi DT LUT in " << FPGAs[fpga] << "(phi_local=" << lclPhi.phi_local
0871             << ",KeyWG=" << itr->getKeyWG() << ",csc=" << itr->cscid() << ")" << std::endl;
0872       }
0873 
0874       itr->setEtaPacked(gblEta.global_eta);
0875 
0876       if (itr->station() == 1) {
0877         //&& itr->cscId() > 6) { //only ring 3
0878         itr->setPhiPacked(gblPhiDT.global_phi);  // convert the DT to convert
0879         dt_stubs.push_back(*itr);                // send stubs to DT
0880       }
0881 
0882       //reconvert the ME1 LCT to the CSCTF units.
0883       //the same iterator is used to fill two containers,
0884       //the CSCTF one (stub_vec_filtered) and LCTs sent to DTTF (dt_stubs)
0885       itr->setPhiPacked(gblPhi.global_phi);
0886 
0887       LogDebug("CSCTFSectorProcessor:run()")
0888           << "LCT found, processed by FPGA: " << FPGAs[fpga] << std::endl
0889           << " LCT now has (eta, phi) of: (" << itr->etaValue() << "," << itr->phiValue() << ")\n";
0890     }
0891   }
0892 
0893   CSCTriggerContainer<csctf::TrackStub> processedStubs(stub_vec_filtered);
0894 
0895   /** STEP TWO
0896    *  We take the stubs filled by the SR LUTs and load them
0897    *  for processing into the SP core logic.
0898    *  After loading we run and then retrieve any tracks generated.
0899    */
0900 
0901   std::vector<csc::L1Track> tftks;
0902 
0903   if (run_core) {
0904     core_->loadData(processedStubs, m_endcap, m_sector, m_minBX, m_maxBX, m_gangedME1a);
0905     //    core_->loadData(processedStubs, m_endcap, m_sector, m_minBX, m_maxBX, true);
0906     if (core_->run(m_endcap,
0907                    m_sector,
0908                    m_latency,
0909                    m_etamin[0],
0910                    m_etamin[1],
0911                    m_etamin[2],
0912                    m_etamin[3],
0913                    m_etamin[4],
0914                    m_etamin[5],
0915                    m_etamin[6],
0916                    m_etamin[7],
0917                    m_etamax[0],
0918                    m_etamax[1],
0919                    m_etamax[2],
0920                    m_etamax[3],
0921                    m_etamax[4],
0922                    m_etamax[5],
0923                    m_etamax[6],
0924                    m_etamax[7],
0925                    m_etawin[0],
0926                    m_etawin[1],
0927                    m_etawin[2],
0928                    m_etawin[3],
0929                    m_etawin[4],
0930                    m_etawin[5],
0931                    m_etawin[6],
0932                    m_mindphip,
0933                    m_mindetap,
0934                    m_mindeta12_accp,
0935                    m_maxdeta12_accp,
0936                    m_maxdphi12_accp,
0937                    m_mindeta13_accp,
0938                    m_maxdeta13_accp,
0939                    m_maxdphi13_accp,
0940                    m_mindeta112_accp,
0941                    m_maxdeta112_accp,
0942                    m_maxdphi112_accp,
0943                    m_mindeta113_accp,
0944                    m_maxdeta113_accp,
0945                    m_maxdphi113_accp,
0946                    m_mindphip_halo,
0947                    m_mindetap_halo,
0948                    m_straightp,
0949                    m_curvedp,
0950                    m_mbaPhiOff,
0951                    m_mbbPhiOff,
0952                    m_bxa_depth,
0953                    m_allowALCTonly,
0954                    m_allowCLCTonly,
0955                    m_preTrigger,
0956                    m_widePhi,
0957                    m_minBX,
0958                    m_maxBX)) {
0959       l1_tracks = core_->tracks();
0960     }
0961 
0962     tftks = l1_tracks.get();
0963 
0964     /** STEP THREE
0965      *  Now that we have the found tracks from the core,
0966      *  we must assign their Pt.
0967      */
0968 
0969     std::vector<csc::L1Track>::iterator titr = tftks.begin();
0970 
0971     for (; titr != tftks.end(); titr++) {
0972       ptadd thePtAddress(titr->ptLUTAddress());
0973       ptdat thePtData = ptLUT_->Pt(thePtAddress);
0974       if (thePtAddress.track_fr) {
0975         titr->setRank(thePtData.front_rank);
0976         titr->setChargeValidPacked(thePtData.charge_valid_front);
0977       } else {
0978         titr->setRank(thePtData.rear_rank);
0979         titr->setChargeValidPacked(thePtData.charge_valid_rear);
0980       }
0981 
0982       if (((titr->ptLUTAddress() >> 16) & 0xf) == 15) {
0983         int unmodBx = titr->bx();
0984         titr->setBx(unmodBx + 2);
0985       }
0986     }
0987   }  //end of if(run_core)
0988 
0989   l1_tracks = tftks;
0990 
0991   // Add-on for singles:
0992   CSCTriggerContainer<csctf::TrackStub> myStubContainer[7];  //[BX]
0993   // Loop over CSC LCTs if triggering on them:
0994   if (trigger_on_ME1a || trigger_on_ME1b || trigger_on_ME2 || trigger_on_ME3 || trigger_on_ME4 || trigger_on_MB1a ||
0995       trigger_on_MB1d)
0996     for (std::vector<csctf::TrackStub>::iterator itr = stub_vec_filtered.begin(); itr != stub_vec_filtered.end();
0997          itr++) {
0998       int station = itr->station() - 1;
0999       if (station != 4) {
1000         int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels(CSCDetId(itr->getDetId().rawId()));
1001         int mpc = (subSector ? subSector - 1 : station + 1);
1002         if ((mpc == 0 && trigger_on_ME1a) || (mpc == 1 && trigger_on_ME1b) || (mpc == 2 && trigger_on_ME2) ||
1003             (mpc == 3 && trigger_on_ME3) || (mpc == 4 && trigger_on_ME4) ||
1004             (mpc == 5 && ((trigger_on_MB1a && subSector % 2 == 1) || (trigger_on_MB1d && subSector % 2 == 0)))) {
1005           int bx = itr->getBX() - m_minBX;
1006           if (bx < 0 || bx >= 7)
1007             edm::LogWarning("CSCTFTrackBuilder::buildTracks()")
1008                 << " LCT BX is out of [" << m_minBX << "," << m_maxBX << ") range: " << itr->getBX();
1009           else if (itr->isValid())
1010             myStubContainer[bx].push_back(*itr);
1011         }
1012       }
1013     }
1014 
1015   // Core's input was loaded in a relative time window BX=[0-7)
1016   // To relate it to time window of tracks (centred at BX=0) we introduce a shift:
1017   int shift = (m_maxBX + m_minBX) / 2 - m_minBX;
1018 
1019   // Now we put tracks from singles in a certain bx
1020   //   if there were no tracks from the core in this endcap/sector/bx
1021   CSCTriggerContainer<csc::L1Track> tracksFromSingles;
1022   for (int bx = 0; bx < 7; bx++)
1023     if (!myStubContainer[bx].get().empty()) {  // VP in this bx
1024       bool coreTrackExists = false;
1025       // tracks are not ordered to be accessible by bx => loop them all
1026       std::vector<csc::L1Track> tracks = l1_tracks.get();
1027       for (std::vector<csc::L1Track>::iterator trk = tracks.begin(); trk < tracks.end(); trk++)
1028         if ((trk->BX() == bx - shift && trk->outputLink() == singlesTrackOutput) ||
1029             (((trk->ptLUTAddress() >> 16) & 0xf) == 15 && trk->BX() - 2 == bx - shift)) {
1030           coreTrackExists = true;
1031           break;
1032         }
1033       if (coreTrackExists == false) {
1034         csc::L1TrackId trackId(m_endcap, m_sector);
1035         csc::L1Track track(trackId);
1036         track.setBx(bx - shift);
1037         track.setOutputLink(singlesTrackOutput);
1038         //CSCCorrelatedLCTDigiCollection singles;
1039         std::vector<csctf::TrackStub> stubs = myStubContainer[bx].get();
1040         // Select best quality stub, and assign its eta/phi coordinates to the track
1041         int qualityME = 0, qualityMB = 0, ME = 100, MB = 100, linkME = 7;
1042         std::vector<csctf::TrackStub>::const_iterator bestStub = stubs.end();
1043         for (std::vector<csctf::TrackStub>::const_iterator st_iter = stubs.begin(); st_iter != stubs.end(); st_iter++) {
1044           int station = st_iter->station() - 1;
1045           int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels(CSCDetId(st_iter->getDetId().rawId()));
1046           int mpc = (subSector ? subSector - 1 : station + 1);
1047           // Sort MB stubs first (priority: quality OR MB1a > MB1b for the same quality)
1048           if (mpc == 5 &&
1049               (st_iter->getQuality() > qualityMB || (st_iter->getQuality() == qualityMB && subSector < MB))) {
1050             qualityMB = st_iter->getQuality();
1051             MB = subSector;
1052             if (ME > 4)
1053               bestStub = st_iter;  // do not select this stub if ME already had any candidate
1054           }
1055           // Sort ME stubs (priority: quality OR ME1a > ME1b > ME2 > ME3 > ME4 for the same quality)
1056           if (mpc < 5 && (st_iter->getQuality() > qualityME || (st_iter->getQuality() == qualityME && mpc < ME) ||
1057                           (st_iter->getQuality() == qualityME && mpc == ME && st_iter->getMPCLink() < linkME))) {
1058             qualityME = st_iter->getQuality();
1059             ME = mpc;
1060             linkME = st_iter->getMPCLink();
1061             bestStub = st_iter;
1062           }
1063         }
1064         unsigned rescaled_phi = 999;
1065         if (m_firmSP <= 20100210) {
1066           // buggy implementation of the phi for singles in the wrapper...
1067           // at the end data/emulator have to agree: e.g. wrong in the same way
1068           // BUG: getting the lowest 7 bits instead the 7 most significant ones.
1069           rescaled_phi = unsigned(24 * (bestStub->phiPacked() & 0x7f) / 128.);
1070         } else {
1071           // correct implementation :-)
1072           rescaled_phi = unsigned(24 * (bestStub->phiPacked() >> 5) / 128.);
1073         }
1074 
1075         unsigned unscaled_phi = bestStub->phiPacked() >> 7;
1076         track.setLocalPhi(rescaleSinglesPhi ? rescaled_phi : unscaled_phi);
1077         track.setEtaPacked((bestStub->etaPacked() >> 2) & 0x1f);
1078         switch (bestStub->station()) {
1079           case 1:
1080             track.setStationIds(bestStub->getMPCLink(), 0, 0, 0, 0);
1081             break;
1082           case 2:
1083             track.setStationIds(0, bestStub->getMPCLink(), 0, 0, 0);
1084             break;
1085           case 3:
1086             track.setStationIds(0, 0, bestStub->getMPCLink(), 0, 0);
1087             break;
1088           case 4:
1089             track.setStationIds(0, 0, 0, bestStub->getMPCLink(), 0);
1090             break;
1091           case 5:
1092             track.setStationIds(0, 0, 0, 0, bestStub->getMPCLink());
1093             break;
1094           default:
1095             edm::LogError("CSCTFSectorProcessor::run()") << "Illegal LCT link=" << bestStub->station() << "\n";
1096             break;
1097         }
1098         //   singles.insertDigi(CSCDetId(st_iter->getDetId().rawId()),*st_iter);
1099         //tracksFromSingles.push_back(L1CSCTrack(track,singles));
1100         track.setPtLUTAddress((1 << 16) | ((bestStub->etaPacked() << 9) & 0xf000));
1101         ptadd thePtAddress(track.ptLUTAddress());
1102         ptdat thePtData = ptLUT_->Pt(thePtAddress);
1103         if (thePtAddress.track_fr) {
1104           track.setRank(thePtData.front_rank);
1105           track.setChargeValidPacked(thePtData.charge_valid_front);
1106         } else {
1107           track.setRank(thePtData.rear_rank);
1108           track.setChargeValidPacked(thePtData.charge_valid_rear);
1109         }
1110         tracksFromSingles.push_back(track);
1111       }
1112     }
1113   std::vector<csc::L1Track> single_tracks = tracksFromSingles.get();
1114   if (!single_tracks.empty())
1115     l1_tracks.push_many(single_tracks);
1116   // End of add-on for singles
1117 
1118   return (!l1_tracks.get().empty());
1119 }
1120 
1121 // according to the firmware versions print some more information
1122 void CSCTFSectorProcessor::printDisclaimer(int firmSP, int firmFA) {
1123   edm::LogInfo("CSCTFSectorProcessor") << "\n\n"
1124                                        << "******************************* \n"
1125                                        << "***       DISCLAIMER        *** \n"
1126                                        << "******************************* \n"
1127                                        << "\n Firmware SP version (year+month+day)=" << firmSP
1128                                        << "\n Firmware FA/VM/DD version (year+month+day)=" << firmFA;
1129   if (firmSP == 20100210)
1130     edm::LogInfo("CSCTFSectorProcessor") << " -> KNOWN BUGS IN THE FIRMWARE:\n"
1131                                          << "\t * Wrong phi assignment for singles\n"
1132                                          << "\t * Wrapper passes to the core only even quality DT stubs\n"
1133                                          << "\n -> BUGS ARE GOING TO BE EMULATED BY THE SOFTWARE\n\n";
1134 
1135   else
1136     edm::LogInfo("CSCTFSectorProcessor") << "\t * Correct phi assignment for singles\n";
1137 
1138   if (firmSP == 20100629) {
1139     edm::LogInfo("CSCTFSectorProcessor") << "\t * Correct MB quality masking in the wrapper\n"
1140                                          << "\t * Core is 20100122\n";
1141   }
1142 
1143   if (firmSP == 20100728)
1144     edm::LogInfo("CSCTFSectorProcessor") << "\t * Inverted MB clocks\n";
1145 
1146   if (firmSP == 20100901)
1147     edm::LogInfo("CSCTFSectorProcessor") << "\t * Inverted charge bit\n";
1148 
1149   if (firmSP == 20101011)
1150     edm::LogInfo("CSCTFSectorProcessor") << "\t **** WARNING THIS FIRMWARE IS UNDER TEST ****\n"
1151                                          << "\t * Added CSC-DT assembling tracks ME1-MB2/1   \n";
1152   if (firmSP == 20101210)
1153     edm::LogInfo("CSCTFSectorProcessor") << "\t **** WARNING THIS FIRMWARE IS UNDER TEST ****\n"
1154                                          << "\t * New Ghost Busting Algorithm Removing Tracks\n"
1155                                          << "\t   Sharing at Least One LCT\n";
1156 
1157   if (firmSP == 20110118)
1158     edm::LogInfo("CSCTFSectorProcessor") << "\t **** WARNING THIS FIRMWARE IS UNDER TEST ****\n"
1159                                          << "\t * New Ghost Busting Algorithm Removing Tracks\n"
1160                                          << "\t   Sharing at Least One LCT\n"
1161                                          << "\t * Passing CLCT and PhiBend for PT LUTs\n";
1162   if (firmSP == 20120131)
1163     edm::LogInfo("CSCTFSectorProcessor") << "\t **** WARNING THIS FIRMWARE IS UNDER TEST ****\n"
1164                                          << "\t * non-linear dphi12 dphi23, use deta for PTLUTs \n";
1165 }