Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:55:22

0001 #include "L1Trigger/L1TMuon/interface/MicroGMTMatchQualLUT.h"
0002 #include "TMath.h"
0003 
0004 l1t::MicroGMTMatchQualFineLUT::MicroGMTMatchQualFineLUT(const std::string& fname,
0005                                                         const double maxDR,
0006                                                         const double fEta,
0007                                                         const double fEtaCoarse,
0008                                                         const double fPhi,
0009                                                         cancel_t cancelType)
0010     : MicroGMTMatchQualLUT(), m_fEtaCoarse(fEtaCoarse) {
0011   m_dEtaRedInWidth = 5;
0012   m_dPhiRedInWidth = 3;
0013   m_maxDR = maxDR;
0014   m_fEta = fEta;
0015   m_fPhi = fPhi;
0016   m_cancelType = cancelType;
0017 
0018   m_totalInWidth = 1 + m_dPhiRedInWidth + m_dEtaRedInWidth;
0019   m_outWidth = 1;
0020 
0021   m_dPhiRedMask = (1 << m_dPhiRedInWidth) - 1;
0022   m_dEtaRedMask = ((1 << m_dEtaRedInWidth) - 1) << m_dPhiRedInWidth;
0023   m_etaFineMask = 1 << (m_dEtaRedInWidth + m_dPhiRedInWidth);
0024 
0025   m_inputs.push_back(MicroGMTConfiguration::ETA_FINE_BIT);
0026   m_inputs.push_back(MicroGMTConfiguration::DELTA_ETA_RED);
0027   m_inputs.push_back(MicroGMTConfiguration::DELTA_PHI_RED);
0028 
0029   m_phiScale = 2 * TMath::Pi() / 576.0;
0030   m_etaScale = 0.010875;
0031 
0032   if (fname != std::string("")) {
0033     load(fname);
0034   } else {
0035     initialize();
0036   }
0037 }
0038 
0039 l1t::MicroGMTMatchQualFineLUT::MicroGMTMatchQualFineLUT(l1t::LUT* lut, cancel_t cancelType)
0040     : MicroGMTMatchQualLUT(lut) {
0041   m_dEtaRedInWidth = 5;
0042   m_dPhiRedInWidth = 3;
0043   m_cancelType = cancelType;
0044 
0045   m_totalInWidth = 1 + m_dPhiRedInWidth + m_dEtaRedInWidth;
0046   m_outWidth = 1;
0047 
0048   m_dPhiRedMask = (1 << m_dPhiRedInWidth) - 1;
0049   m_dEtaRedMask = ((1 << m_dEtaRedInWidth) - 1) << m_dPhiRedInWidth;
0050   m_etaFineMask = 1 << (m_dEtaRedInWidth + m_dPhiRedInWidth);
0051 
0052   m_inputs.push_back(MicroGMTConfiguration::ETA_FINE_BIT);
0053   m_inputs.push_back(MicroGMTConfiguration::DELTA_ETA_RED);
0054   m_inputs.push_back(MicroGMTConfiguration::DELTA_PHI_RED);
0055 
0056   m_phiScale = 2 * TMath::Pi() / 576.0;
0057   m_etaScale = 0.010875;
0058 
0059   m_initialized = true;
0060 }
0061 
0062 int l1t::MicroGMTMatchQualFineLUT::lookup(int etaFine, int dEtaRed, int dPhiRed) const {
0063   // normalize these two to the same scale and then calculate?
0064   if (m_initialized) {
0065     return data((unsigned)hashInput(
0066         checkedInput(etaFine, 1), checkedInput(dEtaRed, m_dEtaRedInWidth), checkedInput(dPhiRed, m_dPhiRedInWidth)));
0067   }
0068   double dEta = m_fEtaCoarse * dEtaRed * m_etaScale;
0069   if (etaFine > 0) {
0070     dEta = m_fEta * dEtaRed * m_etaScale;
0071   }
0072   double dPhi = m_fPhi * dPhiRed * m_phiScale;
0073   double dR = std::sqrt(dEta * dEta + dPhi * dPhi);
0074 
0075   int retVal = dR <= m_maxDR ? 1 : 0;
0076 
0077   return retVal;
0078 }
0079 
0080 int l1t::MicroGMTMatchQualFineLUT::lookupPacked(int in) const {
0081   if (m_initialized) {
0082     return data((unsigned)in);
0083   }
0084 
0085   int etaFine = 0;
0086   int dEtaRed = 0;
0087   int dPhiRed = 0;
0088   unHashInput(in, etaFine, dEtaRed, dPhiRed);
0089   return lookup(etaFine, dEtaRed, dPhiRed);
0090 }
0091 
0092 int l1t::MicroGMTMatchQualFineLUT::hashInput(int etaFine, int dEtaRed, int dPhiRed) const {
0093   int result = 0;
0094   result += dPhiRed;
0095   result += dEtaRed << m_dPhiRedInWidth;
0096   result += etaFine << (m_dEtaRedInWidth + m_dPhiRedInWidth);
0097   return result;
0098 }
0099 
0100 void l1t::MicroGMTMatchQualFineLUT::unHashInput(int input, int& etaFine, int& dEtaRed, int& dPhiRed) const {
0101   dPhiRed = input & m_dPhiRedMask;
0102   dEtaRed = (input & m_dEtaRedMask) >> m_dPhiRedInWidth;
0103   etaFine = (input & m_etaFineMask) >> (m_dEtaRedInWidth + m_dPhiRedInWidth);
0104 }