Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:58

0001 //-------------------------------------------------
0002 //
0003 //   Class: L1MuGMTPSB
0004 //
0005 //   Description: Pipelined Synchronising Buffer module
0006 //
0007 //
0008 //
0009 //   Author :
0010 //   N. Neumeister            CERN EP
0011 //
0012 //   Migrated to CMSSW:
0013 //   I. Mikulec
0014 //
0015 //--------------------------------------------------
0016 
0017 //-----------------------
0018 // This Class's Header --
0019 //-----------------------
0020 
0021 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTPSB.h"
0022 
0023 //---------------
0024 // C++ Headers --
0025 //---------------
0026 
0027 #include <iostream>
0028 #include <iomanip>
0029 #include <vector>
0030 
0031 //-------------------------------
0032 // Collaborating Class Headers --
0033 //-------------------------------
0034 
0035 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTConfig.h"
0036 #include "CondFormats/L1TObjects/interface/L1MuTriggerScales.h"
0037 #include "CondFormats/L1TObjects/interface/L1MuTriggerPtScale.h"
0038 #include "CondFormats/L1TObjects/interface/L1MuGMTChannelMask.h"
0039 
0040 #include "L1Trigger/GlobalMuonTrigger/interface/L1MuGlobalMuonTrigger.h"
0041 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
0042 
0043 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0044 
0045 // --------------------------------
0046 //       class L1MuGMTPSB
0047 //---------------------------------
0048 
0049 //----------------
0050 // Constructors --
0051 //----------------
0052 L1MuGMTPSB::L1MuGMTPSB(const L1MuGlobalMuonTrigger& gmt, edm::ConsumesCollector&& iC)
0053     : m_gmt(gmt),
0054       m_RpcMuons(L1MuGMTConfig::MAXRPC),
0055       m_DtbxMuons(L1MuGMTConfig::MAXDTBX),
0056       m_CscMuons(L1MuGMTConfig::MAXCSC),
0057       m_Isol(14, 18, false),
0058       m_Mip(14, 18, false) {
0059   m_RpcMuons.reserve(L1MuGMTConfig::MAXRPC);
0060   m_DtbxMuons.reserve(L1MuGMTConfig::MAXDTBX);
0061   m_CscMuons.reserve(L1MuGMTConfig::MAXCSC);
0062   iC.consumes<std::vector<L1MuRegionalCand> >(L1MuGMTConfig::getDTInputTag());
0063   iC.consumes<std::vector<L1MuRegionalCand> >(L1MuGMTConfig::getCSCInputTag());
0064   iC.consumes<std::vector<L1MuRegionalCand> >(L1MuGMTConfig::getRPCbInputTag());
0065   iC.consumes<std::vector<L1MuRegionalCand> >(L1MuGMTConfig::getRPCfInputTag());
0066   iC.consumes<L1CaloRegionCollection>(L1MuGMTConfig::getMipIsoInputTag());
0067 }
0068 
0069 //--------------
0070 // Destructor --
0071 //--------------
0072 L1MuGMTPSB::~L1MuGMTPSB() {
0073   reset();
0074   m_RpcMuons.clear();
0075   m_DtbxMuons.clear();
0076   m_CscMuons.clear();
0077 }
0078 
0079 //--------------
0080 // Operations --
0081 //--------------
0082 
0083 //
0084 // receive data
0085 //
0086 void L1MuGMTPSB::receiveData(edm::Event& e, int bx) {
0087   ////////////////////////////////////
0088 
0089   edm::Handle<std::vector<L1MuRegionalCand> > rc_handle;
0090 
0091   const L1MuGMTChannelMask* theChannelMask = L1MuGMTConfig::getGMTChanMask();
0092   unsigned mask = theChannelMask->getSubsystemMask();
0093 
0094   if ((L1MuGMTConfig::getDTInputTag()).label() != "none" && !(mask & 1)) {
0095     e.getByLabel(L1MuGMTConfig::getDTInputTag(), rc_handle);
0096     if (rc_handle.isValid()) {
0097       getDTBX(rc_handle.product(), bx);
0098     } else {
0099       if (L1MuGMTConfig::Debug(1)) {
0100         edm::LogWarning("GlobalMuonTrigger")
0101             << "\nWarning: GlobalMuonTrigger: input tag " << L1MuGMTConfig::getDTInputTag()
0102             << "\nrequested, but not found in the event." << std::endl;
0103       }
0104     }
0105   }
0106   if ((L1MuGMTConfig::getCSCInputTag()).label() != "none" && !(mask & 4)) {
0107     e.getByLabel(L1MuGMTConfig::getCSCInputTag(), rc_handle);
0108     if (rc_handle.isValid()) {
0109       getCSC(rc_handle.product(), bx);
0110     } else {
0111       if (L1MuGMTConfig::Debug(1)) {
0112         edm::LogWarning("GlobalMuonTrigger")
0113             << "\nWarning: GlobalMuonTrigger: input tag " << L1MuGMTConfig::getCSCInputTag()
0114             << "\nrequested, but not found in the event." << std::endl;
0115       }
0116     }
0117   }
0118   if ((L1MuGMTConfig::getRPCbInputTag()).label() != "none" && !(mask & 2)) {
0119     e.getByLabel(L1MuGMTConfig::getRPCbInputTag(), rc_handle);
0120     if (rc_handle.isValid()) {
0121       getRPCb(rc_handle.product(), bx);
0122     } else {
0123       if (L1MuGMTConfig::Debug(1)) {
0124         edm::LogWarning("GlobalMuonTrigger")
0125             << "\nWarning: GlobalMuonTrigger: input tag " << L1MuGMTConfig::getRPCbInputTag()
0126             << "\nrequested, but not found in the event." << std::endl;
0127       }
0128     }
0129   }
0130   if ((L1MuGMTConfig::getRPCfInputTag()).label() != "none" && !(mask & 8)) {
0131     e.getByLabel(L1MuGMTConfig::getRPCfInputTag(), rc_handle);
0132     if (rc_handle.isValid()) {
0133       getRPCf(rc_handle.product(), bx);
0134     } else {
0135       if (L1MuGMTConfig::Debug(1)) {
0136         edm::LogWarning("GlobalMuonTrigger")
0137             << "\nWarning: GlobalMuonTrigger: input tag " << L1MuGMTConfig::getRPCfInputTag()
0138             << "\nrequested, but not found in the event." << std::endl;
0139       }
0140     }
0141   }
0142 
0143   ////////////////////////////////////
0144 
0145   const L1MuTriggerScales* theTriggerScales = L1MuGMTConfig::getTriggerScales();
0146   const L1MuTriggerPtScale* theTriggerPtScale = L1MuGMTConfig::getTriggerPtScale();
0147 
0148   // store data in readout record
0149   for (int i = 0; i < 4; i++) {
0150     L1MuRegionalCand* cand = &(m_DtbxMuons[i]);
0151     cand->setPhiValue(theTriggerScales->getPhiScale()->getLowEdge(cand->phi_packed()));
0152     cand->setEtaValue(theTriggerScales->getRegionalEtaScale(cand->type_idx())->getCenter(cand->eta_packed()));
0153     cand->setPtValue(theTriggerPtScale->getPtScale()->getLowEdge(cand->pt_packed()));
0154     // cand->setPtValue( theTriggerScales->getPtScale()->getLowEdge(cand->pt_packed()) );
0155     m_gmt.currentReadoutRecord()->setInputCand(i, *cand);
0156   }
0157   for (int i = 0; i < 4; i++) {
0158     L1MuRegionalCand* cand = &(m_RpcMuons[i]);
0159     cand->setPhiValue(theTriggerScales->getPhiScale()->getLowEdge(cand->phi_packed()));
0160     cand->setEtaValue(theTriggerScales->getRegionalEtaScale(cand->type_idx())->getCenter(cand->eta_packed()));
0161     cand->setPtValue(theTriggerPtScale->getPtScale()->getLowEdge(cand->pt_packed()));
0162     // cand->setPtValue( theTriggerScales->getPtScale()->getLowEdge(cand->pt_packed()) );
0163     m_gmt.currentReadoutRecord()->setInputCand(i + 4, *cand);
0164   }
0165   for (int i = 0; i < 4; i++) {
0166     L1MuRegionalCand* cand = &(m_CscMuons[i]);
0167     cand->setPhiValue(theTriggerScales->getPhiScale()->getLowEdge(cand->phi_packed()));
0168     cand->setEtaValue(theTriggerScales->getRegionalEtaScale(cand->type_idx())->getCenter(cand->eta_packed()));
0169     cand->setPtValue(theTriggerPtScale->getPtScale()->getLowEdge(cand->pt_packed()));
0170     // cand->setPtValue( theTriggerScales->getPtScale()->getLowEdge(cand->pt_packed()) );
0171     m_gmt.currentReadoutRecord()->setInputCand(i + 8, *cand);
0172   }
0173   for (int i = 0; i < 4; i++) {
0174     L1MuRegionalCand* cand = &(m_RpcMuons[i + 4]);
0175     cand->setPhiValue(theTriggerScales->getPhiScale()->getLowEdge(cand->phi_packed()));
0176     cand->setEtaValue(theTriggerScales->getRegionalEtaScale(cand->type_idx())->getCenter(cand->eta_packed()));
0177     cand->setPtValue(theTriggerPtScale->getPtScale()->getLowEdge(cand->pt_packed()));
0178     // cand->setPtValue( theTriggerScales->getPtScale()->getLowEdge(cand->pt_packed()) );
0179     m_gmt.currentReadoutRecord()->setInputCand(i + 12, *cand);
0180   }
0181 
0182   // if there is at least one muon start the calorimeter trigger
0183 
0184   if (L1MuGMTConfig::getCaloTrigger() && !empty())
0185     getCalo(e);
0186 }
0187 
0188 //
0189 // clear PSB
0190 //
0191 void L1MuGMTPSB::reset() {
0192   std::vector<L1MuRegionalCand>::iterator iter;
0193   iter = m_RpcMuons.begin();
0194   while (iter != m_RpcMuons.end())
0195     (*(iter++)).reset();
0196 
0197   iter = m_DtbxMuons.begin();
0198   while (iter != m_DtbxMuons.end())
0199     (*(iter++)).reset();
0200 
0201   iter = m_CscMuons.begin();
0202   while (iter != m_CscMuons.end())
0203     (*(iter++)).reset();
0204 
0205   m_Isol.reset(false);
0206   m_Mip.reset(false);
0207 }
0208 
0209 //
0210 // print muons
0211 //
0212 void L1MuGMTPSB::print() const {
0213   edm::LogVerbatim("GMT_PSB_info") << " ";
0214   printDTBX();
0215   printRPCbarrel();
0216   printCSC();
0217   printRPCendcap();
0218   edm::LogVerbatim("GMT_PSB_info") << " ";
0219 }
0220 
0221 //
0222 // return RPC muon
0223 //
0224 const L1MuRegionalCand* L1MuGMTPSB::RPCMuon(int index) const {
0225   return (index < (int)L1MuGMTConfig::MAXRPC && index >= 0) ? &(m_RpcMuons[index]) : nullptr;
0226 }
0227 
0228 //
0229 // return DTBX muon
0230 //
0231 const L1MuRegionalCand* L1MuGMTPSB::DTBXMuon(int index) const {
0232   return (index < (int)L1MuGMTConfig::MAXDTBX && index >= 0) ? &(m_DtbxMuons[index]) : nullptr;
0233 }
0234 
0235 //
0236 // return CSC muon
0237 //
0238 const L1MuRegionalCand* L1MuGMTPSB::CSCMuon(int index) const {
0239   return (index < (int)L1MuGMTConfig::MAXCSC && index >= 0) ? &(m_CscMuons[index]) : nullptr;
0240 }
0241 
0242 //
0243 // count number of non empty RPC muons
0244 //
0245 int L1MuGMTPSB::numberRPC() const {
0246   int count = 0;
0247   std::vector<L1MuRegionalCand>::const_iterator iter = m_RpcMuons.begin();
0248   while (iter != m_RpcMuons.end()) {
0249     if (!(*iter).empty())
0250       count++;
0251     iter++;
0252   }
0253   return count;
0254 }
0255 
0256 //
0257 // count number of non empty DT muons
0258 //
0259 int L1MuGMTPSB::numberDTBX() const {
0260   int count = 0;
0261   std::vector<L1MuRegionalCand>::const_iterator iter = m_DtbxMuons.begin();
0262   while (iter != m_DtbxMuons.end()) {
0263     if (!(*iter).empty())
0264       count++;
0265     iter++;
0266   }
0267   return count;
0268 }
0269 
0270 //
0271 // count number of non empty CSC muons
0272 //
0273 int L1MuGMTPSB::numberCSC() const {
0274   int count = 0;
0275   std::vector<L1MuRegionalCand>::const_iterator iter = m_CscMuons.begin();
0276   while (iter != m_CscMuons.end()) {
0277     if (!(*iter).empty())
0278       count++;
0279     iter++;
0280   }
0281   return count;
0282 }
0283 
0284 //
0285 // are there any data in the PSB
0286 //
0287 bool L1MuGMTPSB::empty() const {
0288   int number = numberRPC() + numberDTBX() + numberCSC();
0289 
0290   return (number == 0);
0291 }
0292 
0293 //
0294 // get muons from RPCb Trigger
0295 //
0296 void L1MuGMTPSB::getRPCb(std::vector<L1MuRegionalCand> const* data, int bx) {
0297   int irpcb = 0;
0298   std::vector<L1MuRegionalCand>::const_iterator iter;
0299   for (iter = data->begin(); iter != data->end(); iter++) {
0300     if ((*iter).bx() != bx)
0301       continue;
0302     if (irpcb < (int)L1MuGMTConfig::MAXRPCbarrel) {
0303       if (!(*iter).empty())
0304         m_RpcMuons[irpcb] = (*iter);
0305       irpcb++;
0306     }
0307   }
0308 }
0309 
0310 //
0311 // get muons from RPCf Trigger
0312 //
0313 void L1MuGMTPSB::getRPCf(std::vector<L1MuRegionalCand> const* data, int bx) {
0314   int irpcf = 0;
0315   std::vector<L1MuRegionalCand>::const_iterator iter;
0316   for (iter = data->begin(); iter != data->end(); iter++) {
0317     if ((*iter).bx() != bx)
0318       continue;
0319     if (irpcf < (int)L1MuGMTConfig::MAXRPCendcap) {
0320       if (!(*iter).empty())
0321         m_RpcMuons[irpcf + 4] = (*iter);
0322       irpcf++;
0323     }
0324   }
0325 }
0326 
0327 //
0328 // get muons from barrel Muon Trigger Track Finder
0329 //
0330 void L1MuGMTPSB::getDTBX(std::vector<L1MuRegionalCand> const* data, int bx) {
0331   // temporary hack with bxoffset - to be removed, trigger bx should be 0
0332   int bxoffset = 0;
0333   int idtbx = 0;
0334   std::vector<L1MuRegionalCand>::const_iterator iter;
0335   for (iter = data->begin(); iter != data->end(); iter++) {
0336     if (L1MuGMTConfig::Debug(2))
0337       edm::LogVerbatim("") << "DTTF BX: " << (*iter).bx() << " my bx: " << bx;
0338     if ((*iter).bx() > 10)
0339       bxoffset = 16;
0340     if ((*iter).bx() != bx + bxoffset)
0341       continue;
0342     if (idtbx < (int)L1MuGMTConfig::MAXDTBX) {
0343       m_DtbxMuons[idtbx] = (*iter);
0344       m_DtbxMuons[idtbx].setBx(bx);
0345       idtbx++;
0346     }
0347   }
0348 }
0349 
0350 //
0351 // get muons from CSC Track Finder
0352 //
0353 void L1MuGMTPSB::getCSC(std::vector<L1MuRegionalCand> const* data, int bx) {
0354   int icsc = 0;
0355   std::vector<L1MuRegionalCand>::const_iterator iter;
0356   for (iter = data->begin(); iter != data->end(); iter++) {
0357     if ((*iter).bx() != bx)
0358       continue;
0359     if (icsc < (int)L1MuGMTConfig::MAXCSC) {
0360       m_CscMuons[icsc] = (*iter);
0361       icsc++;
0362     }
0363   }
0364 }
0365 
0366 //
0367 // print barrel RPC muons
0368 //
0369 void L1MuGMTPSB::printRPCbarrel() const {
0370   edm::LogVerbatim("GMT_PSB_info") << "RPC barrel  muons received by the GMT :";
0371 
0372   for (unsigned i = 0; i < L1MuGMTConfig::MAXRPCbarrel; i++) {
0373     if (!m_RpcMuons[i].empty())
0374       m_RpcMuons[i].print();
0375   }
0376 }
0377 
0378 //
0379 // print endcap RPC muons
0380 //
0381 void L1MuGMTPSB::printRPCendcap() const {
0382   edm::LogVerbatim("GMT_PSB_info") << "RPC endcap  muons received by the GMT :";
0383 
0384   for (unsigned i = 0; i < L1MuGMTConfig::MAXRPCendcap; i++) {
0385     if (!m_RpcMuons[i + 4].empty())
0386       m_RpcMuons[i + 4].print();
0387   }
0388 }
0389 
0390 //
0391 // print DTBX muons
0392 //
0393 void L1MuGMTPSB::printDTBX() const {
0394   edm::LogVerbatim("GMT_PSB_info") << "DTBX muons received by the GMT :";
0395 
0396   for (unsigned i = 0; i < L1MuGMTConfig::MAXDTBX; i++) {
0397     if (!m_DtbxMuons[i].empty())
0398       m_DtbxMuons[i].print();
0399   }
0400 }
0401 
0402 //
0403 // print CSC muons
0404 //
0405 void L1MuGMTPSB::printCSC() const {
0406   edm::LogVerbatim("GMT_PSB_info") << "CSC  muons received by the GMT :";
0407 
0408   for (unsigned i = 0; i < L1MuGMTConfig::MAXCSC; i++) {
0409     if (!m_CscMuons[i].empty())
0410       m_CscMuons[i].print();
0411   }
0412 }
0413 
0414 //
0415 // get data from regional calorimeter trigger
0416 //
0417 void L1MuGMTPSB::getCalo(edm::Event& e) {
0418   edm::Handle<L1CaloRegionCollection> calocoll_h;
0419   e.getByLabel(L1MuGMTConfig::getMipIsoInputTag(), calocoll_h);
0420   if (calocoll_h.isValid()) {
0421     L1CaloRegionCollection const* regions = calocoll_h.product();
0422     L1CaloRegionCollection::const_iterator iter;
0423 
0424     //  edm::LogVerbatim("GMT_PSB_info") << "MIP/QUIET bits rceived by the GMT :";
0425 
0426     for (iter = regions->begin(); iter != regions->end(); iter++) {
0427       if ((*iter).id().ieta() < 4 || (*iter).id().ieta() > 17 || (*iter).id().iphi() > 17)
0428         continue;
0429       m_Isol.set((*iter).id().ieta() - 4, (*iter).id().iphi(), (*iter).quiet());
0430       m_Mip.set((*iter).id().ieta() - 4, (*iter).id().iphi(), (*iter).mip());
0431 
0432       if ((*iter).quiet())
0433         m_gmt.currentReadoutRecord()->setQuietbit((*iter).id().ieta() - 4, (*iter).id().iphi());
0434 
0435       if ((*iter).mip())
0436         m_gmt.currentReadoutRecord()->setMIPbit((*iter).id().ieta() - 4, (*iter).id().iphi());
0437 
0438       //    edm::LogVerbatim("GMT_PSB_info") << (*iter).id().ieta()-4 << " "
0439       //                                     << (*iter).id().iphi() << " "
0440       //                                     << (*iter).quiet() << " "
0441       //                                     << (*iter).mip();
0442     }
0443   } else {
0444     if (L1MuGMTConfig::Debug(1)) {
0445       edm::LogWarning("GlobalMuonTrigger")
0446           << "\nWarning: GlobalMuonTrigger: input tag " << L1MuGMTConfig::getMipIsoInputTag()
0447           << "\nrequested, but not found in the event." << std::endl;
0448     }
0449   }
0450 }