Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30: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 }
0178 #endif  //_STAND_ALONE
0179 //---------------------------------------------------------------------------
0180 
0181 unsigned int RPCTBMuon::toBits(RPCTBMuon::MuonBitsType muonBitsType) const {
0182   if (muonBitsType == mbtPACOut) {
0183     return PACOut::toBits(*this);
0184   } else if (muonBitsType == mbtTBSortOut) {
0185     return TBOut::toBits(*this);
0186   } else if (muonBitsType == mbtTCSortOut) {
0187     return TCOut::toBits(*this);
0188   } else if (muonBitsType == mbtHSBOut) {
0189     return HSBOut::toBits(*this);
0190   } else if (muonBitsType == mbtFSBOut) {
0191     return FSBOut::toBits(*this);
0192   } else {
0193     throw RPCException("unknown value of muonBitsType");
0194     //edm::LogError("RPCTrigger")<<"unknown value of where: " + where;
0195   }
0196   return 0;
0197 }
0198 
0199 void RPCTBMuon::fromBits(RPCTBMuon::MuonBitsType muonBitsType, unsigned int value) {
0200   if (muonBitsType == mbtPACOut) {
0201     PACOut::fromBits(*this, value);
0202   } else if (muonBitsType == mbtTBSortOut) {
0203     TBOut::fromBits(*this, value);
0204   } else if (muonBitsType == mbtTCSortOut) {
0205     TCOut::fromBits(*this, value);
0206   } else if (muonBitsType == mbtHSBOut) {
0207     HSBOut::fromBits(*this, value);
0208   } else if (muonBitsType == mbtFSBOut) {
0209     FSBOut::fromBits(*this, value);
0210   } else {
0211     RPCException("unknown value of muonBitsType");
0212     //edm::LogError("RPCTrigger")<< "unknown value of where: " + where;
0213   }
0214 }
0215 
0216 void RPCTBMuon::PACOut::fromBits(RPCTBMuon& muon, unsigned int value) {
0217   unsigned int shift = 0;
0218   muon.m_Sign = (value & (m_signBitsMask << shift)) >> shift;
0219   shift += m_signBitsCnt;
0220   muon.m_PtCode = (value & (m_ptBitsMask << shift)) >> shift;
0221   shift += m_ptBitsCnt;
0222   muon.m_Quality = (value & (m_qualBitsMask << shift)) >> shift;
0223   shift += m_qualBitsCnt;
0224 }
0225 
0226 unsigned int RPCTBMuon::PACOut::toBits(const RPCTBMuon& muon) {
0227   unsigned int value = 0;
0228   unsigned int shift = 0;
0229   value = (muon.m_Sign << shift);
0230   shift += m_signBitsCnt;
0231   value = value | (muon.m_PtCode << shift);
0232   shift += m_ptBitsCnt;
0233   value = value | (muon.m_Quality << shift);
0234   shift += m_qualBitsCnt;
0235 
0236   return value;
0237 }
0238 
0239 //-----------------------
0240 void RPCTBMuon::TBOut::fromBits(RPCTBMuon& muon, unsigned int value) {
0241   unsigned int shift = 0;
0242   muon.m_Sign = (value & (m_signBitsMask << shift)) >> shift;
0243   shift += m_signBitsCnt;
0244   muon.m_PtCode = (value & (m_ptBitsMask << shift)) >> shift;
0245   shift += m_ptBitsCnt;
0246   muon.m_Quality = (value & (m_qualBitsMask << shift)) >> shift;
0247   shift += m_qualBitsCnt;
0248   muon.m_PhiAddress = (value & (m_phiBitsMask << shift)) >> shift;
0249   shift += m_phiBitsCnt;
0250   muon.m_EtaAddress = (value & (m_etaBitsMask << shift)) >> shift;
0251   shift += m_etaBitsCnt;
0252   muon.m_GBData = (value & (m_gbDataBitsMask << shift)) >> shift;
0253   shift += m_gbDataBitsCnt;
0254 }
0255 
0256 unsigned int RPCTBMuon::TBOut::toBits(const RPCTBMuon& muon) {
0257   unsigned int value = 0;
0258   unsigned int shift = 0;
0259   value = (muon.m_Sign << shift);
0260   shift += m_signBitsCnt;
0261   value = value | (muon.m_PtCode << shift);
0262   shift += m_ptBitsCnt;
0263   value = value | (muon.m_Quality << shift);
0264   shift += m_qualBitsCnt;
0265   value = value | (muon.m_PhiAddress << shift);
0266   shift += m_phiBitsCnt;
0267   value = value | (muon.m_EtaAddress << shift);
0268   shift += m_etaBitsCnt;
0269   value = value | (muon.m_GBData << shift);
0270   shift += m_gbDataBitsCnt;
0271   return value;
0272 }
0273 
0274 //-----------------------
0275 void RPCTBMuon::TCOut::fromBits(RPCTBMuon& muon, unsigned int value) {
0276   unsigned int shift = 0;
0277   muon.m_Sign = (value & (m_signBitsMask << shift)) >> shift;
0278   shift += m_signBitsCnt;
0279   muon.m_PtCode = (value & (m_ptBitsMask << shift)) >> shift;
0280   shift += m_ptBitsCnt;
0281   muon.m_Quality = (value & (m_qualBitsMask << shift)) >> shift;
0282   shift += m_qualBitsCnt;
0283   muon.m_PhiAddress = (value & (m_phiBitsMask << shift)) >> shift;
0284   shift += m_phiBitsCnt;
0285   muon.m_EtaAddress = (value & (m_etaBitsMask << shift)) >> shift;
0286   shift += m_etaBitsCnt;
0287   muon.m_GBData = (value & (m_gbDataBitsMask << shift)) >> shift;
0288   shift += m_gbDataBitsCnt;
0289 }
0290 
0291 unsigned int RPCTBMuon::TCOut::toBits(const RPCTBMuon& muon) {
0292   unsigned int value = 0;
0293   unsigned int shift = 0;
0294   value = (muon.m_Sign << shift);
0295   shift += m_signBitsCnt;
0296   value = value | (muon.m_PtCode << shift);
0297   shift += m_ptBitsCnt;
0298   value = value | (muon.m_Quality << shift);
0299   shift += m_qualBitsCnt;
0300   value = value | (muon.m_PhiAddress << shift);
0301   shift += m_phiBitsCnt;
0302   value = value | (muon.m_EtaAddress << shift);
0303   shift += m_etaBitsCnt;
0304   value = value | (muon.m_GBData << shift);
0305   shift += m_gbDataBitsCnt;
0306   return value;
0307 }
0308 //-------------------------------
0309 
0310 unsigned int RPCTBMuon::HSBOut::toBits(const RPCTBMuon& muon) {
0311   unsigned int value = 0;
0312 
0313   unsigned int shift = 0;
0314   value = value | (muon.m_Sign << shift);
0315   shift += m_signBitsCnt;
0316   // value = (muon.m_Sign<<shift);       shift += m_signBitsCnt;
0317   value = value | (muon.m_PtCode << shift);
0318   shift += m_ptBitsCnt;
0319   value = value | (muon.m_Quality << shift);
0320   shift += m_qualBitsCnt;
0321   value = value | (muon.m_PhiAddress << shift);
0322   shift += m_phiBitsCnt;
0323   value = value | (muon.m_EtaAddress << shift);
0324   shift += m_etaBitsCnt;
0325 
0326   return value;
0327 }
0328 
0329 void RPCTBMuon::HSBOut::fromBits(RPCTBMuon& muon, unsigned int value) {
0330   unsigned int shift = 0;
0331   muon.m_Sign = (value & (m_signBitsMask << shift)) >> shift;
0332   shift += m_signBitsCnt;
0333   muon.m_PtCode = (value & (m_ptBitsMask << shift)) >> shift;
0334   shift += m_ptBitsCnt;
0335   muon.m_Quality = (value & (m_qualBitsMask << shift)) >> shift;
0336   shift += m_qualBitsCnt;
0337   muon.m_PhiAddress = (value & (m_phiBitsMask << shift)) >> shift;
0338   shift += m_phiBitsCnt;
0339   muon.m_EtaAddress = (value & (m_etaBitsMask << shift)) >> shift;
0340   shift += m_etaBitsCnt;
0341 }
0342 
0343 unsigned int RPCTBMuon::FSBOut::toBits(const RPCTBMuon& muon) {
0344   unsigned int value = 0;
0345 
0346   unsigned int shift = 0;
0347   //bita are reversed, to be zero when cable not connected
0348   unsigned int ptCode = (~(muon.m_PtCode)) & m_ptBitsMask;
0349   unsigned int quality = (~(muon.m_Quality)) & m_qualBitsMask;
0350 
0351   value = value | muon.m_PhiAddress;
0352   shift += m_phiBitsCnt;
0353   value = value | (ptCode << shift);
0354   shift += m_ptBitsCnt;
0355   value = value | (quality << shift);
0356   shift += m_qualBitsCnt;
0357 
0358   //+1 beacouse H/F bits, unused in RPC:
0359   value = value | (muon.m_EtaAddress << shift);
0360   shift += m_etaBitsCnt + 1;
0361   value = value | (muon.m_Sign << shift);
0362   shift += m_signBitsCnt;
0363 
0364   return value;
0365 }
0366 
0367 void RPCTBMuon::FSBOut::fromBits(RPCTBMuon& muon, unsigned int value) {
0368   unsigned int shift = 0;
0369   muon.m_PhiAddress = value & m_phiBitsMask;
0370   shift += m_phiBitsCnt;
0371   muon.m_PtCode = (value & (m_ptBitsMask << shift)) >> shift;
0372   shift += m_ptBitsCnt;
0373   muon.m_Quality = (value & (m_qualBitsMask << shift)) >> shift;
0374   shift += m_qualBitsCnt;
0375 
0376   //+1 beacouse H/F bits, unused in RPC:
0377   muon.m_EtaAddress = (value & (m_etaBitsMask << shift)) >> shift;
0378   shift += m_etaBitsCnt + 1;
0379   muon.m_Sign = (value & (m_signBitsMask << shift)) >> shift;
0380   shift += m_signBitsCnt;
0381 
0382   muon.m_PtCode = (~(muon.m_PtCode)) & m_ptBitsMask;
0383   muon.m_Quality = (~(muon.m_Quality)) & m_qualBitsMask;
0384 }
0385 
0386 std::string RPCTBMuon::toString(int format) const {
0387   ostringstream ostr;
0388   if (format == 0) {
0389     ostr << "qu " << m_Quality << ", pt " << setw(2) << m_PtCode << ", sig " << m_Sign << ", phi " << setw(3)
0390          << m_PhiAddress << ", eta " << setw(2) << m_EtaAddress;
0391   } else if (format == 1) {
0392     ostr << " " << m_Quality << " " << setw(2) << m_PtCode << " " << m_Sign << " " << setw(3) << m_PhiAddress << " "
0393          << setw(2) << m_EtaAddress;
0394   } else if (format == 2) {
0395     ostr << " " << m_Quality << " " << setw(2) << m_PtCode << " " << m_Sign;
0396   }
0397 
0398   return ostr.str();
0399 }