Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:28

0001 //-------------------------------------------------
0002 //
0003 /** \class L1MuGMTReadoutRecord
0004  *
0005  *  L1 Global Muon Trigger Readout Record
0006  *
0007  *  Contains the data that the GMT will send to readout
0008  *  for one bunch crossing.
0009 */
0010 //
0011 //
0012 //   Author :
0013 //   H. Sakulin                  HEPHY Vienna
0014 //
0015 //   Migrated to CMSSW:
0016 //   I. Mikulec
0017 //
0018 //--------------------------------------------------
0019 
0020 //-----------------------
0021 // This Class's Header --
0022 //-----------------------
0023 
0024 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutRecord.h"
0025 
0026 //---------------
0027 // C++ Headers --
0028 //---------------
0029 
0030 #include <iostream>
0031 #include <iomanip>
0032 #include <cmath>
0033 #include <algorithm>
0034 
0035 //-------------------------------
0036 // Collaborating Class Headers --
0037 //-------------------------------
0038 
0039 using namespace std;
0040 
0041 //--------------------------------------
0042 //       class L1MuGMTReadoutRecord
0043 //--------------------------------------
0044 
0045 //----------------
0046 // Constructors --
0047 //----------------
0048 
0049 L1MuGMTReadoutRecord::L1MuGMTReadoutRecord() : m_InputCands(16), m_BarrelCands(4), m_ForwardCands(4), m_GMTCands(4) {
0050   reset();
0051 }
0052 
0053 L1MuGMTReadoutRecord::L1MuGMTReadoutRecord(int bxie)
0054     : m_InputCands(16), m_BarrelCands(4), m_ForwardCands(4), m_GMTCands(4) {
0055   reset();
0056   m_BxInEvent = bxie;
0057 }
0058 
0059 //--------------
0060 // Destructor --
0061 //--------------
0062 L1MuGMTReadoutRecord::~L1MuGMTReadoutRecord() {}
0063 
0064 //--------------
0065 // Operations --
0066 //--------------
0067 
0068 /// reset the record
0069 void L1MuGMTReadoutRecord::reset() {
0070   m_BxNr = 0;
0071   m_BxInEvent = 0;
0072   m_EvNr = 0;
0073   m_BCERR = 0;
0074 
0075   std::vector<L1MuRegionalCand>::iterator itr;
0076   for (itr = m_InputCands.begin(); itr != m_InputCands.end(); itr++)
0077     (*itr).reset();
0078 
0079   std::vector<L1MuGMTExtendedCand>::iterator itg;
0080   for (itg = m_BarrelCands.begin(); itg != m_BarrelCands.end(); itg++)
0081     (*itg).reset();
0082   for (itg = m_ForwardCands.begin(); itg != m_ForwardCands.end(); itg++)
0083     (*itg).reset();
0084   for (itg = m_GMTCands.begin(); itg != m_GMTCands.end(); itg++)
0085     (*itg).reset();
0086   for (int i = 0; i < 8; i++) {
0087     m_MIPbits[i] = 0;
0088     m_Quietbits[i] = 0;
0089   }
0090 }
0091 
0092 /// get GMT candidates vector
0093 vector<L1MuGMTExtendedCand> L1MuGMTReadoutRecord::getGMTCands() const {
0094   vector<L1MuGMTExtendedCand> cands;
0095 
0096   std::vector<L1MuGMTExtendedCand>::const_iterator it;
0097   for (it = m_BarrelCands.begin(); it != m_BarrelCands.end(); it++) {
0098     if ((*it).getDataWord() != 0)
0099       cands.push_back(*it);
0100   }
0101   for (it = m_ForwardCands.begin(); it != m_ForwardCands.end(); it++) {
0102     if ((*it).getDataWord() != 0)
0103       cands.push_back(*it);
0104   }
0105 
0106   // sort by rank
0107   stable_sort(cands.begin(), cands.end(), L1MuGMTExtendedCand::rankRef);
0108 
0109   return cands;
0110 }
0111 
0112 /// get GMT candidates vector as stored in data (no rank info)
0113 vector<L1MuGMTExtendedCand>& L1MuGMTReadoutRecord::getGMTCandsData() { return m_GMTCands; }
0114 
0115 /// get GMT barrel candidates vector
0116 vector<L1MuGMTExtendedCand> L1MuGMTReadoutRecord::getGMTBrlCands() const {
0117   vector<L1MuGMTExtendedCand> cands;
0118   std::vector<L1MuGMTExtendedCand>::const_iterator it;
0119   for (it = m_BarrelCands.begin(); it != m_BarrelCands.end(); it++) {
0120     if ((*it).getDataWord() != 0)
0121       cands.push_back(*it);
0122   }
0123 
0124   return cands;
0125 }
0126 
0127 /// get GMT forward candidates vector
0128 vector<L1MuGMTExtendedCand> L1MuGMTReadoutRecord::getGMTFwdCands() const {
0129   vector<L1MuGMTExtendedCand> cands;
0130   std::vector<L1MuGMTExtendedCand>::const_iterator it;
0131   for (it = m_ForwardCands.begin(); it != m_ForwardCands.end(); it++) {
0132     if ((*it).getDataWord() != 0)
0133       cands.push_back(*it);
0134   }
0135 
0136   return cands;
0137 }
0138 
0139 /// get DT candidates vector
0140 vector<L1MuRegionalCand> L1MuGMTReadoutRecord::getDTBXCands() const {
0141   vector<L1MuRegionalCand> cands;
0142 
0143   for (int i = 0; i < 4; i++)
0144     if (m_InputCands[i].getDataWord() != 0)
0145       cands.push_back(m_InputCands[i]);
0146 
0147   return cands;
0148 }
0149 
0150 /// get CSC candidates vector
0151 vector<L1MuRegionalCand> L1MuGMTReadoutRecord::getCSCCands() const {
0152   vector<L1MuRegionalCand> cands;
0153 
0154   for (int i = 0; i < 4; i++)
0155     if (m_InputCands[i + 8].getDataWord() != 0)
0156       cands.push_back(m_InputCands[i + 8]);
0157 
0158   return cands;
0159 }
0160 
0161 /// get barrel RPC candidates vector
0162 vector<L1MuRegionalCand> L1MuGMTReadoutRecord::getBrlRPCCands() const {
0163   vector<L1MuRegionalCand> cands;
0164 
0165   for (int i = 0; i < 4; i++)
0166     if (m_InputCands[i + 4].getDataWord() != 0)
0167       cands.push_back(m_InputCands[i + 4]);
0168 
0169   return cands;
0170 }
0171 
0172 /// get forward RPC candidates vector
0173 vector<L1MuRegionalCand> L1MuGMTReadoutRecord::getFwdRPCCands() const {
0174   vector<L1MuRegionalCand> cands;
0175 
0176   for (int i = 0; i < 4; i++)
0177     if (m_InputCands[i + 12].getDataWord() != 0)
0178       cands.push_back(m_InputCands[i + 12]);
0179 
0180   return cands;
0181 }
0182 
0183 /// get MIP bit
0184 unsigned L1MuGMTReadoutRecord::getMIPbit(int eta, int phi) const {
0185   if (phi < 0 || phi > 17 || eta < 0 || eta > 13)
0186     return 0;
0187 
0188   int idx = eta * 18 + phi;
0189   int idx_word = idx / 32;
0190   int idx_bit = idx % 32;
0191 
0192   unsigned mask = 1 << (idx_bit - 1);
0193 
0194   return (m_MIPbits[idx_word] & mask) ? 1 : 0;
0195 }
0196 
0197 /// get Quiet bit
0198 unsigned L1MuGMTReadoutRecord::getQuietbit(int eta, int phi) const {
0199   if (phi < 0 || phi > 17 || eta < 0 || eta > 13)
0200     return 0;
0201 
0202   int idx = eta * 18 + phi;
0203   int idx_word = idx / 32;
0204   int idx_bit = idx % 32;
0205 
0206   unsigned mask = 1 << (idx_bit - 1);
0207 
0208   return (m_Quietbits[idx_word] & mask) ? 1 : 0;
0209 }
0210 
0211 //
0212 // Setters
0213 //
0214 
0215 /// set Regional Candidates
0216 void L1MuGMTReadoutRecord::setInputCand(int nr, L1MuRegionalCand const& cand) {
0217   if (nr >= 0 && nr < 16) {
0218     m_InputCands[nr] = cand;
0219   }
0220 }
0221 
0222 /// set Regional Candidates
0223 void L1MuGMTReadoutRecord::setInputCand(int nr, unsigned data) {
0224   if (nr >= 0 && nr < 16) {
0225     m_InputCands[nr] = L1MuRegionalCand(data, m_BxInEvent);
0226   }
0227 }
0228 
0229 /// set GMT barrel candidate
0230 void L1MuGMTReadoutRecord::setGMTBrlCand(int nr, L1MuGMTExtendedCand const& cand) {
0231   if (nr >= 0 && nr < 4) {
0232     m_BarrelCands[nr] = cand;
0233   }
0234 }
0235 
0236 /// set GMT barrel candidate
0237 void L1MuGMTReadoutRecord::setGMTBrlCand(int nr, unsigned data, unsigned rank) {
0238   if (nr >= 0 && nr < 4) {
0239     m_BarrelCands[nr] = L1MuGMTExtendedCand(data, rank, m_BxInEvent);
0240   }
0241 }
0242 
0243 /// set GMT forward candidate
0244 void L1MuGMTReadoutRecord::setGMTFwdCand(int nr, L1MuGMTExtendedCand const& cand) {
0245   if (nr >= 0 && nr < 4) {
0246     m_ForwardCands[nr] = cand;
0247   }
0248 }
0249 
0250 /// set GMT forward candidate
0251 void L1MuGMTReadoutRecord::setGMTFwdCand(int nr, unsigned data, unsigned rank) {
0252   if (nr >= 0 && nr < 4) {
0253     m_ForwardCands[nr] = L1MuGMTExtendedCand(data, rank, m_BxInEvent);
0254   }
0255 }
0256 
0257 /// set GMT candidate
0258 void L1MuGMTReadoutRecord::setGMTCand(int nr, L1MuGMTExtendedCand const& cand) {
0259   if (nr >= 0 && nr < 4) {
0260     m_GMTCands[nr] = cand;
0261   }
0262 }
0263 
0264 /// set GMT candidate
0265 void L1MuGMTReadoutRecord::setGMTCand(int nr, unsigned data) {
0266   if (nr >= 0 && nr < 4) {
0267     m_GMTCands[nr] = L1MuGMTExtendedCand(data, 0, m_BxInEvent);
0268   }
0269 }
0270 
0271 /// get rank of brl cand i
0272 unsigned L1MuGMTReadoutRecord::getBrlRank(int i) const { return m_BarrelCands[i].rank(); }
0273 
0274 /// get rank of fwd cand i
0275 unsigned L1MuGMTReadoutRecord::getFwdRank(int i) const { return m_ForwardCands[i].rank(); }
0276 
0277 /// set rank of brl cand i
0278 void L1MuGMTReadoutRecord::setBrlRank(int i, unsigned value) {
0279   if (i >= 0 && i < 4) {
0280     m_BarrelCands[i].setRank(value);
0281   }
0282 }
0283 
0284 /// set rank of fwd cand i
0285 void L1MuGMTReadoutRecord::setFwdRank(int i, unsigned value) {
0286   if (i >= 0 && i < 4) {
0287     m_ForwardCands[i].setRank(value);
0288   }
0289 }
0290 
0291 /// set MIP bit
0292 void L1MuGMTReadoutRecord::setMIPbit(int eta, int phi) {
0293   if (phi < 0 || phi > 17 || eta < 0 || eta > 13)
0294     return;
0295 
0296   int idx = eta * 18 + phi;
0297   int idx_word = idx / 32;
0298   int idx_bit = idx % 32;
0299 
0300   unsigned mask = 1 << (idx_bit - 1);
0301 
0302   m_MIPbits[idx_word] |= mask;
0303 }
0304 
0305 /// set Quiet bit
0306 void L1MuGMTReadoutRecord::setQuietbit(int eta, int phi) {
0307   if (phi < 0 || phi > 17 || eta < 0 || eta > 13)
0308     return;
0309 
0310   int idx = eta * 18 + phi;
0311   int idx_word = idx / 32;
0312   int idx_bit = idx % 32;
0313 
0314   unsigned mask = 0;
0315   if (idx_bit > 0)
0316     mask = 1 << (idx_bit - 1);
0317 
0318   m_Quietbits[idx_word] |= mask;
0319 }