CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/L1Trigger/RPCTrigger/src/RPCTBMuon.cc

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 #include "L1Trigger/RPCTrigger/interface/RPCTBMuon.h"
00003 #ifndef _STAND_ALONE
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 #endif // _STAND_ALONE
00006 #include "L1Trigger/RPCTrigger/interface/RPCException.h"
00007 
00008 #include <sstream>
00009 #include <iomanip>
00010 #include <iostream>
00011 
00012 using namespace std;
00013 //---------------------------------------------------------------------------
00014 RPCTBMuon::RPCTBMuon(): RPCMuon() {
00015     m_Killed = false;
00016 
00017     m_GBData = 0;
00018 
00019     m_EtaAddress = 0;
00020     m_PhiAddress = 0;
00021 }
00022 //---------------------------------------------------------------------------
00023 RPCTBMuon::RPCTBMuon(int ptCode, int quality, int sign,
00024                          int patternNum, unsigned short firedPlanes):
00025     RPCMuon(ptCode, quality, sign, patternNum, firedPlanes) 
00026 {
00027     m_Killed = false;
00028 
00029     m_GBData = 0;
00030 
00031     m_EtaAddress = 0;
00032     m_PhiAddress = 0;
00033     
00034     m_muonBitsType = mbtUnset;
00035 }
00036 
00037 RPCTBMuon::RPCTBMuon(int ptCode, int quality, int sign, MuonBitsType muonBitsType):
00038     RPCMuon(ptCode, quality, sign, 0, 0)  {
00039     m_Killed = false;
00040 
00041     m_GBData = 0;
00042 
00043     m_EtaAddress = 0;
00044     m_PhiAddress = 0;
00045     
00046     m_muonBitsType = muonBitsType;
00047 }
00048 
00055 std::string RPCTBMuon::printDebugInfo(int debugFormat) const {
00056 
00057   std::ostringstream sDebugInfo;
00058   if (debugFormat==1){  // Human readable
00059 
00060     sDebugInfo << "TBMuon: code: " << getPtCode()
00061                << " etaAddr: " << getEtaAddr()
00062                << " phiAddr: " << getPhiAddr()
00063                << " sgAddr: " << getSegmentAddr()
00064                << " scAddr: " << getSectorAddr()
00065                << " gbData: " << getGBData();
00066 
00067   }
00068   else {        //technicall
00069    sDebugInfo << "TBMuon pt "<< getPtCode() 
00070               <<   " ql " <<getQuality() 
00071               <<   " sgn " << getSign()
00072               <<   " tw " << getTower()
00073               <<   " sc " << getLogSector()
00074               <<   " sg " << getLogSegment()
00075               <<   " phi " << getPhiAddr()
00076               <<   " eta " << getEtaAddr()
00077               <<   " gbD " <<  getGBData()
00078               <<   " bits " << toBits(mbtFSBOut);
00079   }
00080 
00081   return sDebugInfo.str();
00082 
00083 }
00084 //---------------------------------------------------------------------------
00085 // Simple setters and getters
00086 
00088 int RPCTBMuon::getCode() const {  
00089 
00090   // 1 bit, 0 - negative, 1 - positive.
00091   unsigned int signLocal = 0;
00092   if (m_Sign==0) signLocal=1; // invert
00093   return (m_Quality<<6 | m_PtCode << 1 | signLocal);
00094 
00095 }
00096 
00098 void RPCTBMuon::setCode(int code) {
00099     m_Quality = (code & (3<<5))>>5;
00100     m_PtCode = code & 31;
00101 }
00102 
00103 
00104 void RPCTBMuon::setPhiAddr(int phiAddr) { m_PhiAddress = phiAddr;}
00105 
00106 void RPCTBMuon::setSectorAddr(int sectorAddr){ m_PhiAddress = m_PhiAddress | sectorAddr<<4;}
00107 
00108 void RPCTBMuon::setEtaAddr(int etaAddr) { m_EtaAddress = etaAddr;}
00109   
00110 void RPCTBMuon::setAddress(int etaAddr, int phiAddr) { 
00111      m_EtaAddress = etaAddr;
00112      m_PhiAddress = phiAddr;
00113 }
00114 
00115 void RPCTBMuon::setAddress(int tbNumber, int tbTower, int phiAddr) {
00116     m_EtaAddress = (tbNumber<<2) | tbTower;
00117     m_PhiAddress = phiAddr;
00118 }
00119 
00120 void RPCTBMuon::setGBData(unsigned int gbData) {
00121         m_GBData = gbData;
00122 }
00123 
00124 int RPCTBMuon::getEtaAddr() const { return m_EtaAddress; }
00125 
00126 int RPCTBMuon::getPhiAddr() const { return m_PhiAddress; }
00127 
00128 int RPCTBMuon::getSegmentAddr() const { return m_PhiAddress & 15; }
00129 
00130 int RPCTBMuon::getSectorAddr() const { return (m_PhiAddress & 0xF0)>>4; }
00131 
00132 int RPCTBMuon::getContinSegmAddr() const { return getSectorAddr()*12 + getSegmentAddr();}
00133 
00134 void RPCTBMuon::setCodeAndPhiAddr(int code, int phiAddr) {
00135     setCode(code);
00136     m_PhiAddress = phiAddr;
00137 }
00138 
00139 void RPCTBMuon::setCodeAndEtaAddr(int code, int etaAddr) {
00140     setCode(code);
00141     m_EtaAddress = etaAddr;
00142 }
00143   
00144 int RPCTBMuon::getGBData() const { return m_GBData;}
00145 
00146 std::string RPCTBMuon::getGBDataBitStr() const {
00147     std::string str = "00";
00148     if (m_GBData == 1)
00149       str = "01";
00150     else if (m_GBData == 2)
00151       str = "10";
00152     else if (m_GBData == 3)
00153       str = "11";
00154     return str;  
00155 }
00156 
00157 void RPCTBMuon::setGBDataKilledFirst() { m_GBData = m_GBData | 1;}
00158 
00159 void RPCTBMuon::setGBDataKilledLast() { m_GBData = m_GBData | 2; }
00160 
00161 bool RPCTBMuon::gBDataKilledFirst() const { return (m_GBData & 1);}
00162 
00163 bool RPCTBMuon::gBDataKilledLast() const { return (m_GBData & 2);}
00164 
00165 
00166 //---------------------------------------------------------------------------
00167 void RPCTBMuon::kill() { m_Killed = true; }
00168 
00171 bool RPCTBMuon::wasKilled() const {
00172     if(m_PtCode > 0 && m_Killed)
00173       return true;
00174     else return false;
00175 }
00176 
00179 bool RPCTBMuon::isLive() const {
00180     if(m_PtCode > 0 && !m_Killed)
00181       return true;
00182     else return false;
00183 }
00184 
00185 //---------------------------------------------------------------------------
00186 #ifndef _STAND_ALONE
00187 RPCTBMuon::RPCTBMuon(const RPCPacMuon& pacMuon):
00188     RPCMuon(pacMuon) 
00189 {
00190     m_Killed = false;
00191 
00192     m_GBData = 0;
00193 
00194     m_EtaAddress = 0;
00195     m_PhiAddress = 0;
00196 }
00197 #endif //_STAND_ALONE
00198 //---------------------------------------------------------------------------
00199 
00200 unsigned int RPCTBMuon::toBits(RPCTBMuon::MuonBitsType muonBitsType) const {
00201   if (muonBitsType == mbtPACOut) {
00202     return PACOut::toBits(*this);
00203   }
00204   else if (muonBitsType == mbtTBSortOut) {
00205     return TBOut::toBits(*this);
00206   }
00207   else if (muonBitsType == mbtTCSortOut) {
00208     return TCOut::toBits(*this);
00209   }
00210   else if (muonBitsType == mbtHSBOut) {
00211     return HSBOut::toBits(*this);
00212   }
00213   else if (muonBitsType == mbtFSBOut) {
00214     return FSBOut::toBits(*this);
00215   }
00216   else {
00217     throw RPCException("unknown value of muonBitsType");
00218     //edm::LogError("RPCTrigger")<<"unknown value of where: " + where;
00219   } 
00220   return 0;
00221 }
00222 
00223 void RPCTBMuon::fromBits(RPCTBMuon::MuonBitsType muonBitsType, unsigned int value) {
00224   if (muonBitsType == mbtPACOut) {
00225     PACOut::fromBits(*this, value);
00226   } 
00227   else if (muonBitsType == mbtTBSortOut) {
00228     TBOut::fromBits(*this, value);
00229   } 
00230   else if (muonBitsType == mbtTCSortOut) {
00231     TCOut::fromBits(*this, value);
00232   } 
00233   else if (muonBitsType == mbtHSBOut) {
00234     HSBOut::fromBits(*this, value);
00235   } 
00236   else if (muonBitsType == mbtFSBOut) {
00237     FSBOut::fromBits(*this, value);
00238   }
00239   else {
00240     RPCException("unknown value of muonBitsType");
00241     //edm::LogError("RPCTrigger")<< "unknown value of where: " + where;
00242   }
00243 }
00244 
00245 void RPCTBMuon::PACOut::fromBits(RPCTBMuon& muon, unsigned int value) {
00246   unsigned int shift = 0;
00247   muon.m_Sign       = (value & (m_signBitsMask<<shift))  >> shift;  shift += m_signBitsCnt;  
00248   muon.m_PtCode     = (value & (m_ptBitsMask<<shift))    >> shift;  shift += m_ptBitsCnt;
00249   muon.m_Quality    = (value & (m_qualBitsMask<<shift))  >> shift;  shift += m_qualBitsCnt;
00250 }
00251 
00252 unsigned int RPCTBMuon::PACOut::toBits(const RPCTBMuon& muon) {
00253   unsigned int value = 0;
00254   unsigned int shift = 0;
00255   value =         (muon.m_Sign<<shift);       shift += m_signBitsCnt;
00256   value = value | (muon.m_PtCode<<shift);     shift += m_ptBitsCnt;
00257   value = value | (muon.m_Quality<<shift);    shift += m_qualBitsCnt;
00258    
00259   return value;
00260 }
00261 
00262 //-----------------------
00263 void RPCTBMuon::TBOut::fromBits(RPCTBMuon& muon, unsigned int value) {
00264   unsigned int shift = 0;
00265   muon.m_Sign       = (value & (m_signBitsMask<<shift))  >> shift;  shift += m_signBitsCnt;  
00266   muon.m_PtCode     = (value & (m_ptBitsMask<<shift))    >> shift;  shift += m_ptBitsCnt;
00267   muon.m_Quality    = (value & (m_qualBitsMask<<shift))  >> shift;  shift += m_qualBitsCnt;
00268   muon.m_PhiAddress = (value & (m_phiBitsMask<<shift))   >> shift;  shift += m_phiBitsCnt;
00269   muon.m_EtaAddress = (value & (m_etaBitsMask<<shift))   >> shift;  shift += m_etaBitsCnt;
00270   muon.m_GBData     = (value & (m_gbDataBitsMask<<shift))>> shift;  shift += m_gbDataBitsCnt;       
00271 }
00272 
00273 unsigned int RPCTBMuon::TBOut::toBits(const RPCTBMuon& muon) {
00274   unsigned int value = 0;
00275   unsigned int shift = 0;
00276   value =         (muon.m_Sign<<shift);       shift += m_signBitsCnt;
00277   value = value | (muon.m_PtCode<<shift);     shift += m_ptBitsCnt;
00278   value = value | (muon.m_Quality<<shift);    shift += m_qualBitsCnt;
00279   value = value | (muon.m_PhiAddress<<shift); shift += m_phiBitsCnt;
00280   value = value | (muon.m_EtaAddress<<shift); shift += m_etaBitsCnt; 
00281   value = value | (muon.m_GBData<<shift);     shift += m_gbDataBitsCnt;
00282   return value;
00283 }
00284 
00285 //-----------------------
00286 void RPCTBMuon::TCOut::fromBits(RPCTBMuon& muon, unsigned int value) {
00287   unsigned int shift = 0;
00288   muon.m_Sign       = (value & (m_signBitsMask<<shift))  >> shift;  shift += m_signBitsCnt; 
00289   muon.m_PtCode     = (value & (m_ptBitsMask<<shift))    >> shift;  shift += m_ptBitsCnt;
00290   muon.m_Quality    = (value & (m_qualBitsMask<<shift))  >> shift;  shift += m_qualBitsCnt;
00291   muon.m_PhiAddress = (value & (m_phiBitsMask<<shift))   >> shift;  shift += m_phiBitsCnt;
00292   muon.m_EtaAddress = (value & (m_etaBitsMask<<shift))   >> shift;  shift += m_etaBitsCnt;
00293   muon.m_GBData     = (value & (m_gbDataBitsMask<<shift))>> shift;  shift += m_gbDataBitsCnt;     
00294 }
00295 
00296 unsigned int RPCTBMuon::TCOut::toBits(const RPCTBMuon& muon) {
00297   unsigned int value = 0;
00298   unsigned int shift = 0;
00299   value =         (muon.m_Sign<<shift);       shift += m_signBitsCnt;
00300   value = value | (muon.m_PtCode<<shift);     shift += m_ptBitsCnt;
00301   value = value | (muon.m_Quality<<shift);    shift += m_qualBitsCnt;
00302   value = value | (muon.m_PhiAddress<<shift); shift += m_phiBitsCnt;  
00303   value = value | (muon.m_EtaAddress<<shift); shift += m_etaBitsCnt; 
00304   value = value | (muon.m_GBData<<shift);     shift += m_gbDataBitsCnt;
00305   return value;
00306 }
00307 //-------------------------------
00308 
00309 unsigned int RPCTBMuon::HSBOut::toBits(const RPCTBMuon& muon) {
00310   unsigned int value = 0;
00311 
00312   unsigned int shift = 0;
00313   value = value | (muon.m_Sign<<shift);       shift += m_signBitsCnt;
00314  // value = (muon.m_Sign<<shift);       shift += m_signBitsCnt;
00315   value = value | (muon.m_PtCode<<shift);     shift += m_ptBitsCnt;
00316   value = value | (muon.m_Quality<<shift);    shift += m_qualBitsCnt;
00317   value = value | (muon.m_PhiAddress<<shift); shift += m_phiBitsCnt;
00318   value = value | (muon.m_EtaAddress<<shift); shift += m_etaBitsCnt; 
00319    
00320   return value;
00321 }
00322 
00323 void RPCTBMuon::HSBOut::fromBits(RPCTBMuon& muon, unsigned int value) {
00324   unsigned int shift = 0;
00325   muon.m_Sign       = (value & (m_signBitsMask<<shift)) >> shift;  shift += m_signBitsCnt;
00326   muon.m_PtCode     = (value & (m_ptBitsMask<<shift))   >> shift;  shift += m_ptBitsCnt;
00327   muon.m_Quality    = (value & (m_qualBitsMask<<shift)) >> shift;  shift += m_qualBitsCnt;
00328   muon.m_PhiAddress = (value & (m_phiBitsMask<<shift))  >> shift;  shift += m_phiBitsCnt;
00329   muon.m_EtaAddress = (value & (m_etaBitsMask<<shift))  >> shift;  shift += m_etaBitsCnt;
00330 }
00331 
00332 unsigned int RPCTBMuon::FSBOut::toBits(const RPCTBMuon& muon) {
00333   unsigned int value = 0;
00334         
00335   unsigned int shift = 0;
00336   //bita are reversed, to be zero when cable not connected
00337   unsigned int ptCode =  (~(muon.m_PtCode)) & m_ptBitsMask; 
00338   unsigned int quality = (~(muon.m_Quality)) & m_qualBitsMask;
00339 
00340   value = value |  muon.m_PhiAddress;         shift += m_phiBitsCnt;    
00341   value = value | (ptCode<<shift);            shift += m_ptBitsCnt;
00342   value = value | (quality<<shift);           shift += m_qualBitsCnt;
00343   
00344   //+1 beacouse H/F bits, unused in RPC:
00345   value = value | (muon.m_EtaAddress<<shift); shift += m_etaBitsCnt + 1; 
00346   value = value | (muon.m_Sign<<shift);       shift += m_signBitsCnt;
00347   
00348   return value;
00349 }
00350 
00351 void RPCTBMuon::FSBOut::fromBits(RPCTBMuon& muon, unsigned int value) {
00352   unsigned int shift = 0;
00353   muon.m_PhiAddress =  value &  m_phiBitsMask;                     shift += m_phiBitsCnt;
00354   muon.m_PtCode     = (value & (m_ptBitsMask<<shift))   >> shift;  shift += m_ptBitsCnt;
00355   muon.m_Quality    = (value & (m_qualBitsMask<<shift)) >> shift;  shift += m_qualBitsCnt;
00356   
00357   //+1 beacouse H/F bits, unused in RPC:
00358   muon.m_EtaAddress = (value & (m_etaBitsMask<<shift))  >> shift;  shift += m_etaBitsCnt + 1; 
00359   muon.m_Sign       = (value & (m_signBitsMask<<shift)) >> shift;  shift += m_signBitsCnt; 
00360   
00361   muon.m_PtCode = (~(muon.m_PtCode)) & m_ptBitsMask;
00362   muon.m_Quality = (~(muon.m_Quality)) & m_qualBitsMask;
00363 }
00364 
00365 
00366 std::string RPCTBMuon::toString(int format) const {
00367   ostringstream ostr;
00368   if(format == 0) {
00369          ostr<<"qu "<<m_Quality<<", pt "<<setw(2)<<m_PtCode<<", sig "<<m_Sign
00370          <<", phi "<<setw(3)<<m_PhiAddress<<", eta "<<setw(2)<<m_EtaAddress;
00371   }
00372   else if( format == 1) {
00373         ostr<<" "<<m_Quality<<" "<<setw(2)<<m_PtCode<<" "<<m_Sign
00374         <<" "<<setw(3)<<m_PhiAddress<<" "<<setw(2)<<m_EtaAddress;
00375   }    
00376   else if( format == 2) {
00377         ostr<<" "<<m_Quality<<" "<<setw(2)<<m_PtCode<<" "<<m_Sign;
00378   }    
00379   
00380   return ostr.str();
00381 }