Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-12-19 23:38:37

0001 //---------------------------------------------------------------------------
0002 #include "L1Trigger/RPCTrigger/interface/RPCTBMuon.h"
0003 #ifndef _STAND_ALONE
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #endif  // _STAND_ALONE
0006 #include "L1Trigger/RPCTrigger/interface/RPCException.h"
0007 
0008 #include <sstream>
0009 #include <iomanip>
0010 #include <iostream>
0011 
0012 using namespace std;
0013 //---------------------------------------------------------------------------
0014 RPCTBMuon::RPCTBMuon() : RPCMuon() {
0015   m_Killed = false;
0016 
0017   m_GBData = 0;
0018 
0019   m_EtaAddress = 0;
0020   m_PhiAddress = 0;
0021 
0022   m_muonBitsType = mbtUnset;
0023 }
0024 //---------------------------------------------------------------------------
0025 RPCTBMuon::RPCTBMuon(int ptCode, int quality, int sign, int patternNum, unsigned short firedPlanes)
0026     : RPCMuon(ptCode, quality, sign, patternNum, firedPlanes) {
0027   m_Killed = false;
0028 
0029   m_GBData = 0;
0030 
0031   m_EtaAddress = 0;
0032   m_PhiAddress = 0;
0033 
0034   m_muonBitsType = mbtUnset;
0035 }
0036 
0037 RPCTBMuon::RPCTBMuon(int ptCode, int quality, int sign, MuonBitsType muonBitsType)
0038     : RPCMuon(ptCode, quality, sign, 0, 0) {
0039   m_Killed = false;
0040 
0041   m_GBData = 0;
0042 
0043   m_EtaAddress = 0;
0044   m_PhiAddress = 0;
0045 
0046   m_muonBitsType = muonBitsType;
0047 }
0048 
0049 /**
0050 *
0051 * \brief Gives debuging info in human readable format (1) or technicall format (2)
0052 * \note Possible debugFormat codes (1,2) are defined in RPCTrigger constructor
0053 *
0054 */
0055 std::string RPCTBMuon::printDebugInfo(int debugFormat) const {
0056   std::ostringstream sDebugInfo;
0057   if (debugFormat == 1) {  // Human readable
0058 
0059     sDebugInfo << "TBMuon: code: " << getPtCode() << " etaAddr: " << getEtaAddr() << " phiAddr: " << getPhiAddr()
0060                << " sgAddr: " << getSegmentAddr() << " scAddr: " << getSectorAddr() << " gbData: " << getGBData();
0061 
0062   } else {  //technicall
0063     sDebugInfo << "TBMuon pt " << getPtCode() << " ql " << getQuality() << " sgn " << getSign() << " tw " << getTower()
0064                << " sc " << getLogSector() << " sg " << getLogSegment() << " phi " << getPhiAddr() << " eta "
0065                << getEtaAddr() << " gbD " << getGBData() << " bits " << toBits(mbtFSBOut);
0066   }
0067 
0068   return sDebugInfo.str();
0069 }
0070 //---------------------------------------------------------------------------
0071 // Simple setters and getters
0072 
0073 ///Combined quality and ptCode, 8 bits [7...6 m_Quality, 5...1 m_PtCode, 0 sign], used in GhoustBusters
0074 int RPCTBMuon::getCode() const {
0075   // 1 bit, 0 - negative, 1 - positive.
0076   unsigned int signLocal = 0;
0077   if (m_Sign == 0)
0078     signLocal = 1;  // invert
0079   return (m_Quality << 6 | m_PtCode << 1 | signLocal);
0080 }
0081 
0082 ///Sets combined code: 8 bits [7...5 m_Quality, 4...0 m_PtCode].
0083 void RPCTBMuon::setCode(int code) {
0084   m_Quality = (code & (3 << 5)) >> 5;
0085   m_PtCode = code & 31;
0086 }
0087 
0088 void RPCTBMuon::setPhiAddr(int phiAddr) { m_PhiAddress = phiAddr; }
0089 
0090 void RPCTBMuon::setSectorAddr(int sectorAddr) { m_PhiAddress = m_PhiAddress | sectorAddr << 4; }
0091 
0092 void RPCTBMuon::setEtaAddr(int etaAddr) { m_EtaAddress = etaAddr; }
0093 
0094 void RPCTBMuon::setAddress(int etaAddr, int phiAddr) {
0095   m_EtaAddress = etaAddr;
0096   m_PhiAddress = phiAddr;
0097 }
0098 
0099 void RPCTBMuon::setAddress(int tbNumber, int tbTower, int phiAddr) {
0100   m_EtaAddress = (tbNumber << 2) | tbTower;
0101   m_PhiAddress = phiAddr;
0102 }
0103 
0104 void RPCTBMuon::setGBData(unsigned int gbData) { m_GBData = gbData; }
0105 
0106 int RPCTBMuon::getEtaAddr() const { return m_EtaAddress; }
0107 
0108 int RPCTBMuon::getPhiAddr() const { return m_PhiAddress; }
0109 
0110 int RPCTBMuon::getSegmentAddr() const { return m_PhiAddress & 15; }
0111 
0112 int RPCTBMuon::getSectorAddr() const { return (m_PhiAddress & 0xF0) >> 4; }
0113 
0114 int RPCTBMuon::getContinSegmAddr() const { return getSectorAddr() * 12 + getSegmentAddr(); }
0115 
0116 void RPCTBMuon::setCodeAndPhiAddr(int code, int phiAddr) {
0117   setCode(code);
0118   m_PhiAddress = phiAddr;
0119 }
0120 
0121 void RPCTBMuon::setCodeAndEtaAddr(int code, int etaAddr) {
0122   setCode(code);
0123   m_EtaAddress = etaAddr;
0124 }
0125 
0126 int RPCTBMuon::getGBData() const { return m_GBData; }
0127 
0128 std::string RPCTBMuon::getGBDataBitStr() const {
0129   std::string str = "00";
0130   if (m_GBData == 1)
0131     str = "01";
0132   else if (m_GBData == 2)
0133     str = "10";
0134   else if (m_GBData == 3)
0135     str = "11";
0136   return str;
0137 }
0138 
0139 void RPCTBMuon::setGBDataKilledFirst() { m_GBData = m_GBData | 1; }
0140 
0141 void RPCTBMuon::setGBDataKilledLast() { m_GBData = m_GBData | 2; }
0142 
0143 bool RPCTBMuon::gBDataKilledFirst() const { return (m_GBData & 1); }
0144 
0145 bool RPCTBMuon::gBDataKilledLast() const { return (m_GBData & 2); }
0146 
0147 //---------------------------------------------------------------------------
0148 void RPCTBMuon::kill() { m_Killed = true; }
0149 
0150 /** @return true = was non-empty muon and was killed
0151   * false = was not killed or is zero */
0152 bool RPCTBMuon::wasKilled() const {
0153   if (m_PtCode > 0 && m_Killed)
0154     return true;
0155   else
0156     return false;
0157 }
0158 
0159 /** @return true = was no-zero muon and was not killed
0160   * false = is killed or is zero */
0161 bool RPCTBMuon::isLive() const {
0162   if (m_PtCode > 0 && !m_Killed)
0163     return true;
0164   else
0165     return false;
0166 }
0167 
0168 //---------------------------------------------------------------------------
0169 #ifndef _STAND_ALONE
0170 RPCTBMuon::RPCTBMuon(const RPCPacMuon& pacMuon) : RPCMuon(pacMuon) {
0171   m_Killed = false;
0172 
0173   m_GBData = 0;
0174 
0175   m_EtaAddress = 0;
0176   m_PhiAddress = 0;
0177   m_muonBitsType = mbtUnset;
0178 }
0179 #endif  //_STAND_ALONE
0180 //---------------------------------------------------------------------------
0181 
0182 unsigned int RPCTBMuon::toBits(RPCTBMuon::MuonBitsType muonBitsType) const {
0183   if (muonBitsType == mbtPACOut) {
0184     return PACOut::toBits(*this);
0185   } else if (muonBitsType == mbtTBSortOut) {
0186     return TBOut::toBits(*this);
0187   } else if (muonBitsType == mbtTCSortOut) {
0188     return TCOut::toBits(*this);
0189   } else if (muonBitsType == mbtHSBOut) {
0190     return HSBOut::toBits(*this);
0191   } else if (muonBitsType == mbtFSBOut) {
0192     return FSBOut::toBits(*this);
0193   } else {
0194     throw RPCException("unknown value of muonBitsType");
0195     //edm::LogError("RPCTrigger")<<"unknown value of where: " + where;
0196   }
0197   return 0;
0198 }
0199 
0200 void RPCTBMuon::fromBits(RPCTBMuon::MuonBitsType muonBitsType, unsigned int value) {
0201   if (muonBitsType == mbtPACOut) {
0202     PACOut::fromBits(*this, value);
0203   } else if (muonBitsType == mbtTBSortOut) {
0204     TBOut::fromBits(*this, value);
0205   } else if (muonBitsType == mbtTCSortOut) {
0206     TCOut::fromBits(*this, value);
0207   } else if (muonBitsType == mbtHSBOut) {
0208     HSBOut::fromBits(*this, value);
0209   } else if (muonBitsType == mbtFSBOut) {
0210     FSBOut::fromBits(*this, value);
0211   } else {
0212     RPCException("unknown value of muonBitsType");
0213     //edm::LogError("RPCTrigger")<< "unknown value of where: " + where;
0214   }
0215 }
0216 
0217 void RPCTBMuon::PACOut::fromBits(RPCTBMuon& muon, unsigned int value) {
0218   unsigned int shift = 0;
0219   muon.m_Sign = (value & (m_signBitsMask << shift)) >> shift;
0220   shift += m_signBitsCnt;
0221   muon.m_PtCode = (value & (m_ptBitsMask << shift)) >> shift;
0222   shift += m_ptBitsCnt;
0223   muon.m_Quality = (value & (m_qualBitsMask << shift)) >> shift;
0224   shift += m_qualBitsCnt;
0225 }
0226 
0227 unsigned int RPCTBMuon::PACOut::toBits(const RPCTBMuon& muon) {
0228   unsigned int value = 0;
0229   unsigned int shift = 0;
0230   value = (muon.m_Sign << shift);
0231   shift += m_signBitsCnt;
0232   value = value | (muon.m_PtCode << shift);
0233   shift += m_ptBitsCnt;
0234   value = value | (muon.m_Quality << shift);
0235   shift += m_qualBitsCnt;
0236 
0237   return value;
0238 }
0239 
0240 //-----------------------
0241 void RPCTBMuon::TBOut::fromBits(RPCTBMuon& muon, unsigned int value) {
0242   unsigned int shift = 0;
0243   muon.m_Sign = (value & (m_signBitsMask << shift)) >> shift;
0244   shift += m_signBitsCnt;
0245   muon.m_PtCode = (value & (m_ptBitsMask << shift)) >> shift;
0246   shift += m_ptBitsCnt;
0247   muon.m_Quality = (value & (m_qualBitsMask << shift)) >> shift;
0248   shift += m_qualBitsCnt;
0249   muon.m_PhiAddress = (value & (m_phiBitsMask << shift)) >> shift;
0250   shift += m_phiBitsCnt;
0251   muon.m_EtaAddress = (value & (m_etaBitsMask << shift)) >> shift;
0252   shift += m_etaBitsCnt;
0253   muon.m_GBData = (value & (m_gbDataBitsMask << shift)) >> shift;
0254   shift += m_gbDataBitsCnt;
0255 }
0256 
0257 unsigned int RPCTBMuon::TBOut::toBits(const RPCTBMuon& muon) {
0258   unsigned int value = 0;
0259   unsigned int shift = 0;
0260   value = (muon.m_Sign << shift);
0261   shift += m_signBitsCnt;
0262   value = value | (muon.m_PtCode << shift);
0263   shift += m_ptBitsCnt;
0264   value = value | (muon.m_Quality << shift);
0265   shift += m_qualBitsCnt;
0266   value = value | (muon.m_PhiAddress << shift);
0267   shift += m_phiBitsCnt;
0268   value = value | (muon.m_EtaAddress << shift);
0269   shift += m_etaBitsCnt;
0270   value = value | (muon.m_GBData << shift);
0271   shift += m_gbDataBitsCnt;
0272   return value;
0273 }
0274 
0275 //-----------------------
0276 void RPCTBMuon::TCOut::fromBits(RPCTBMuon& muon, unsigned int value) {
0277   unsigned int shift = 0;
0278   muon.m_Sign = (value & (m_signBitsMask << shift)) >> shift;
0279   shift += m_signBitsCnt;
0280   muon.m_PtCode = (value & (m_ptBitsMask << shift)) >> shift;
0281   shift += m_ptBitsCnt;
0282   muon.m_Quality = (value & (m_qualBitsMask << shift)) >> shift;
0283   shift += m_qualBitsCnt;
0284   muon.m_PhiAddress = (value & (m_phiBitsMask << shift)) >> shift;
0285   shift += m_phiBitsCnt;
0286   muon.m_EtaAddress = (value & (m_etaBitsMask << shift)) >> shift;
0287   shift += m_etaBitsCnt;
0288   muon.m_GBData = (value & (m_gbDataBitsMask << shift)) >> shift;
0289   shift += m_gbDataBitsCnt;
0290 }
0291 
0292 unsigned int RPCTBMuon::TCOut::toBits(const RPCTBMuon& muon) {
0293   unsigned int value = 0;
0294   unsigned int shift = 0;
0295   value = (muon.m_Sign << shift);
0296   shift += m_signBitsCnt;
0297   value = value | (muon.m_PtCode << shift);
0298   shift += m_ptBitsCnt;
0299   value = value | (muon.m_Quality << shift);
0300   shift += m_qualBitsCnt;
0301   value = value | (muon.m_PhiAddress << shift);
0302   shift += m_phiBitsCnt;
0303   value = value | (muon.m_EtaAddress << shift);
0304   shift += m_etaBitsCnt;
0305   value = value | (muon.m_GBData << shift);
0306   shift += m_gbDataBitsCnt;
0307   return value;
0308 }
0309 //-------------------------------
0310 
0311 unsigned int RPCTBMuon::HSBOut::toBits(const RPCTBMuon& muon) {
0312   unsigned int value = 0;
0313 
0314   unsigned int shift = 0;
0315   value = value | (muon.m_Sign << shift);
0316   shift += m_signBitsCnt;
0317   // value = (muon.m_Sign<<shift);       shift += m_signBitsCnt;
0318   value = value | (muon.m_PtCode << shift);
0319   shift += m_ptBitsCnt;
0320   value = value | (muon.m_Quality << shift);
0321   shift += m_qualBitsCnt;
0322   value = value | (muon.m_PhiAddress << shift);
0323   shift += m_phiBitsCnt;
0324   value = value | (muon.m_EtaAddress << shift);
0325   shift += m_etaBitsCnt;
0326 
0327   return value;
0328 }
0329 
0330 void RPCTBMuon::HSBOut::fromBits(RPCTBMuon& muon, unsigned int value) {
0331   unsigned int shift = 0;
0332   muon.m_Sign = (value & (m_signBitsMask << shift)) >> shift;
0333   shift += m_signBitsCnt;
0334   muon.m_PtCode = (value & (m_ptBitsMask << shift)) >> shift;
0335   shift += m_ptBitsCnt;
0336   muon.m_Quality = (value & (m_qualBitsMask << shift)) >> shift;
0337   shift += m_qualBitsCnt;
0338   muon.m_PhiAddress = (value & (m_phiBitsMask << shift)) >> shift;
0339   shift += m_phiBitsCnt;
0340   muon.m_EtaAddress = (value & (m_etaBitsMask << shift)) >> shift;
0341   shift += m_etaBitsCnt;
0342 }
0343 
0344 unsigned int RPCTBMuon::FSBOut::toBits(const RPCTBMuon& muon) {
0345   unsigned int value = 0;
0346 
0347   unsigned int shift = 0;
0348   //bita are reversed, to be zero when cable not connected
0349   unsigned int ptCode = (~(muon.m_PtCode)) & m_ptBitsMask;
0350   unsigned int quality = (~(muon.m_Quality)) & m_qualBitsMask;
0351 
0352   value = value | muon.m_PhiAddress;
0353   shift += m_phiBitsCnt;
0354   value = value | (ptCode << shift);
0355   shift += m_ptBitsCnt;
0356   value = value | (quality << shift);
0357   shift += m_qualBitsCnt;
0358 
0359   //+1 beacouse H/F bits, unused in RPC:
0360   value = value | (muon.m_EtaAddress << shift);
0361   shift += m_etaBitsCnt + 1;
0362   value = value | (muon.m_Sign << shift);
0363   shift += m_signBitsCnt;
0364 
0365   return value;
0366 }
0367 
0368 void RPCTBMuon::FSBOut::fromBits(RPCTBMuon& muon, unsigned int value) {
0369   unsigned int shift = 0;
0370   muon.m_PhiAddress = value & m_phiBitsMask;
0371   shift += m_phiBitsCnt;
0372   muon.m_PtCode = (value & (m_ptBitsMask << shift)) >> shift;
0373   shift += m_ptBitsCnt;
0374   muon.m_Quality = (value & (m_qualBitsMask << shift)) >> shift;
0375   shift += m_qualBitsCnt;
0376 
0377   //+1 beacouse H/F bits, unused in RPC:
0378   muon.m_EtaAddress = (value & (m_etaBitsMask << shift)) >> shift;
0379   shift += m_etaBitsCnt + 1;
0380   muon.m_Sign = (value & (m_signBitsMask << shift)) >> shift;
0381   shift += m_signBitsCnt;
0382 
0383   muon.m_PtCode = (~(muon.m_PtCode)) & m_ptBitsMask;
0384   muon.m_Quality = (~(muon.m_Quality)) & m_qualBitsMask;
0385 }
0386 
0387 std::string RPCTBMuon::toString(int format) const {
0388   ostringstream ostr;
0389   if (format == 0) {
0390     ostr << "qu " << m_Quality << ", pt " << setw(2) << m_PtCode << ", sig " << m_Sign << ", phi " << setw(3)
0391          << m_PhiAddress << ", eta " << setw(2) << m_EtaAddress;
0392   } else if (format == 1) {
0393     ostr << " " << m_Quality << " " << setw(2) << m_PtCode << " " << m_Sign << " " << setw(3) << m_PhiAddress << " "
0394          << setw(2) << m_EtaAddress;
0395   } else if (format == 2) {
0396     ostr << " " << m_Quality << " " << setw(2) << m_PtCode << " " << m_Sign;
0397   }
0398 
0399   return ostr.str();
0400 }