CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/L1Trigger/GlobalMuonTrigger/src/L1MuGMTPSB.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: L1MuGMTPSB
00004 //
00005 //   Description: Pipelined Synchronising Buffer module 
00006 //
00007 //
00008 //   $Date: 2009/03/30 09:46:14 $
00009 //   $Revision: 1.16 $
00010 //
00011 //   Author :
00012 //   N. Neumeister            CERN EP 
00013 //
00014 //   Migrated to CMSSW:
00015 //   I. Mikulec
00016 //
00017 //--------------------------------------------------
00018 
00019 //-----------------------
00020 // This Class's Header --
00021 //-----------------------
00022 
00023 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTPSB.h"
00024 
00025 //---------------
00026 // C++ Headers --
00027 //---------------
00028 
00029 #include <iostream>
00030 #include <iomanip>
00031 #include <vector>
00032 
00033 //-------------------------------
00034 // Collaborating Class Headers --
00035 //-------------------------------
00036 
00037 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTConfig.h"
00038 #include "CondFormats/L1TObjects/interface/L1MuTriggerScales.h"
00039 #include "CondFormats/L1TObjects/interface/L1MuTriggerPtScale.h"
00040 #include "CondFormats/L1TObjects/interface/L1MuGMTChannelMask.h"
00041 
00042 #include "L1Trigger/GlobalMuonTrigger/interface/L1MuGlobalMuonTrigger.h"
00043 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
00044 
00045 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00046 
00047 // --------------------------------
00048 //       class L1MuGMTPSB
00049 //---------------------------------
00050 
00051 //----------------
00052 // Constructors --
00053 //----------------
00054 L1MuGMTPSB::L1MuGMTPSB(const L1MuGlobalMuonTrigger& gmt) : 
00055                m_gmt(gmt), 
00056                m_RpcMuons(L1MuGMTConfig::MAXRPC),
00057                m_DtbxMuons(L1MuGMTConfig::MAXDTBX), 
00058                m_CscMuons(L1MuGMTConfig::MAXCSC),
00059                m_Isol(14,18), m_Mip(14,18) {
00060 
00061   m_RpcMuons.reserve(L1MuGMTConfig::MAXRPC);
00062   m_DtbxMuons.reserve(L1MuGMTConfig::MAXDTBX);
00063   m_CscMuons.reserve(L1MuGMTConfig::MAXCSC);
00064   m_Isol.init(false);
00065   m_Mip.init(false);
00066 
00067 }
00068 
00069 //--------------
00070 // Destructor --
00071 //--------------
00072 L1MuGMTPSB::~L1MuGMTPSB() { 
00073 
00074   reset();
00075   m_RpcMuons.clear();
00076   m_DtbxMuons.clear();
00077   m_CscMuons.clear();
00078   
00079 }
00080 
00081 //--------------
00082 // Operations --
00083 //--------------
00084 
00085 //
00086 // receive data
00087 //
00088 void L1MuGMTPSB::receiveData(edm::Event& e, int bx) {
00089 
00091 
00092   edm::Handle<std::vector<L1MuRegionalCand> > rc_handle;
00093 
00094   const L1MuGMTChannelMask* theChannelMask = L1MuGMTConfig::getGMTChanMask();
00095   unsigned mask = theChannelMask->getSubsystemMask();
00096   
00097   if((L1MuGMTConfig::getDTInputTag()).label() != "none" && !(mask&1) ) {
00098     e.getByLabel(L1MuGMTConfig::getDTInputTag(),rc_handle);
00099     if(rc_handle.isValid()) {
00100       getDTBX(rc_handle.product(),bx);
00101     } else {
00102       if( L1MuGMTConfig::Debug(1) ) {
00103         edm::LogWarning("GlobalMuonTrigger")
00104         << "\nWarning: GlobalMuonTrigger: input tag " << L1MuGMTConfig::getDTInputTag()
00105         << "\nrequested, but not found in the event." << std::endl;      
00106       }
00107     }
00108   }
00109   if((L1MuGMTConfig::getCSCInputTag()).label() != "none" && !(mask&4) ) {
00110     e.getByLabel(L1MuGMTConfig::getCSCInputTag(),rc_handle);
00111     if(rc_handle.isValid()) {
00112       getCSC(rc_handle.product(),bx);
00113     } else {
00114       if( L1MuGMTConfig::Debug(1) ) {
00115         edm::LogWarning("GlobalMuonTrigger")
00116         << "\nWarning: GlobalMuonTrigger: input tag " << L1MuGMTConfig::getCSCInputTag()
00117         << "\nrequested, but not found in the event." << std::endl;      
00118       }
00119     }
00120   }
00121   if((L1MuGMTConfig::getRPCbInputTag()).label() != "none" && !(mask&2) ) {
00122     e.getByLabel(L1MuGMTConfig::getRPCbInputTag(),rc_handle);
00123     if(rc_handle.isValid()) {
00124       getRPCb(rc_handle.product(),bx);
00125     } else {
00126       if( L1MuGMTConfig::Debug(1) ) {
00127         edm::LogWarning("GlobalMuonTrigger")
00128         << "\nWarning: GlobalMuonTrigger: input tag " << L1MuGMTConfig::getRPCbInputTag()
00129         << "\nrequested, but not found in the event." << std::endl;      
00130       }
00131     }
00132   }
00133   if((L1MuGMTConfig::getRPCfInputTag()).label() != "none" && !(mask&8) ) {
00134     e.getByLabel(L1MuGMTConfig::getRPCfInputTag(),rc_handle);
00135     if(rc_handle.isValid()) {
00136       getRPCf(rc_handle.product(),bx);
00137     } else {
00138       if( L1MuGMTConfig::Debug(1) ) {
00139         edm::LogWarning("GlobalMuonTrigger")
00140         << "\nWarning: GlobalMuonTrigger: input tag " << L1MuGMTConfig::getRPCfInputTag()
00141         << "\nrequested, but not found in the event." << std::endl;      
00142       }
00143     }
00144   }
00145 
00147 
00148   const L1MuTriggerScales* theTriggerScales = L1MuGMTConfig::getTriggerScales();
00149   const L1MuTriggerPtScale* theTriggerPtScale = L1MuGMTConfig::getTriggerPtScale();
00150 
00151   // store data in readout record
00152   for (int i=0; i<4; i++) {
00153     L1MuRegionalCand* cand = &(m_DtbxMuons[i]);
00154     cand->setPhiValue( theTriggerScales->getPhiScale()->getLowEdge(cand->phi_packed()) );
00155     cand->setEtaValue( theTriggerScales->getRegionalEtaScale(cand->type_idx())->getCenter(cand->eta_packed()) );
00156     cand->setPtValue( theTriggerPtScale->getPtScale()->getLowEdge(cand->pt_packed()) );
00157     // cand->setPtValue( theTriggerScales->getPtScale()->getLowEdge(cand->pt_packed()) );
00158     m_gmt.currentReadoutRecord()->setInputCand ( i, *cand );
00159   }
00160   for (int i=0; i<4; i++) {
00161     L1MuRegionalCand* cand = &(m_RpcMuons[i]);
00162     cand->setPhiValue( theTriggerScales->getPhiScale()->getLowEdge(cand->phi_packed()) );
00163     cand->setEtaValue( theTriggerScales->getRegionalEtaScale(cand->type_idx())->getCenter(cand->eta_packed()) );
00164     cand->setPtValue( theTriggerPtScale->getPtScale()->getLowEdge(cand->pt_packed()) );
00165     // cand->setPtValue( theTriggerScales->getPtScale()->getLowEdge(cand->pt_packed()) );
00166     m_gmt.currentReadoutRecord()->setInputCand ( i+4, *cand );
00167   }
00168   for (int i=0; i<4; i++) {
00169     L1MuRegionalCand* cand = &(m_CscMuons[i]);
00170     cand->setPhiValue( theTriggerScales->getPhiScale()->getLowEdge(cand->phi_packed()) );
00171     cand->setEtaValue( theTriggerScales->getRegionalEtaScale(cand->type_idx())->getCenter(cand->eta_packed()) );
00172     cand->setPtValue( theTriggerPtScale->getPtScale()->getLowEdge(cand->pt_packed()) );
00173     // cand->setPtValue( theTriggerScales->getPtScale()->getLowEdge(cand->pt_packed()) );
00174     m_gmt.currentReadoutRecord()->setInputCand ( i+8, *cand );
00175   }
00176   for (int i=0; i<4; i++) {
00177     L1MuRegionalCand* cand = &(m_RpcMuons[i+4]);
00178     cand->setPhiValue( theTriggerScales->getPhiScale()->getLowEdge(cand->phi_packed()) );
00179     cand->setEtaValue( theTriggerScales->getRegionalEtaScale(cand->type_idx())->getCenter(cand->eta_packed()) );
00180     cand->setPtValue( theTriggerPtScale->getPtScale()->getLowEdge(cand->pt_packed()) );
00181     // cand->setPtValue( theTriggerScales->getPtScale()->getLowEdge(cand->pt_packed()) );
00182     m_gmt.currentReadoutRecord()->setInputCand ( i+12, *cand );
00183   }
00184 
00185 
00186   // if there is at least one muon start the calorimeter trigger 
00187 
00188   if ( L1MuGMTConfig::getCaloTrigger() && !empty() ) getCalo(e);
00189 
00190 }
00191 
00192 
00193 //
00194 // clear PSB
00195 //
00196 void L1MuGMTPSB::reset() {
00197 
00198   std::vector<L1MuRegionalCand>::iterator iter; 
00199   iter = m_RpcMuons.begin();
00200   while ( iter != m_RpcMuons.end() ) (*(iter++)).reset();
00201 
00202   iter = m_DtbxMuons.begin();
00203   while ( iter != m_DtbxMuons.end() )(*(iter++)).reset();
00204 
00205   iter = m_CscMuons.begin();
00206   while ( iter != m_CscMuons.end() ) (*(iter++)).reset();
00207   
00208   m_Isol.init(false);
00209   m_Mip.init(false);
00210 
00211 }
00212 
00213 
00214 //
00215 // print muons
00216 //
00217 void L1MuGMTPSB::print() const {
00218 
00219   edm::LogVerbatim("GMT_PSB_info") << " ";
00220   printDTBX();
00221   printRPCbarrel();
00222   printCSC();
00223   printRPCendcap();
00224   edm::LogVerbatim("GMT_PSB_info") << " ";
00225   
00226 }
00227 
00228 
00229 //
00230 // return RPC muon
00231 //
00232 const L1MuRegionalCand* L1MuGMTPSB::RPCMuon(int index) const {
00233   
00234   return ( index < (int)L1MuGMTConfig::MAXRPC && index >= 0 ) ? &(m_RpcMuons[index]) : 0;
00235   
00236 }
00237 
00238 
00239 //
00240 // return DTBX muon
00241 //
00242 const L1MuRegionalCand* L1MuGMTPSB::DTBXMuon(int index) const {
00243       
00244   return ( index < (int)L1MuGMTConfig::MAXDTBX && index >= 0 ) ? &(m_DtbxMuons[index]) : 0;
00245   
00246 }
00247 
00248 
00249 //
00250 // return CSC muon
00251 //
00252 const L1MuRegionalCand* L1MuGMTPSB::CSCMuon(int index) const {
00253  
00254   return ( index < (int)L1MuGMTConfig::MAXCSC && index >= 0 ) ? &(m_CscMuons[index]) : 0;
00255   
00256 }
00257 
00258 //
00259 // count number of non empty RPC muons
00260 //
00261 int L1MuGMTPSB::numberRPC() const {
00262 
00263   int count = 0;
00264   std::vector<L1MuRegionalCand>::const_iterator iter = m_RpcMuons.begin();
00265   while ( iter != m_RpcMuons.end() ) {
00266     if ( !(*iter).empty() ) count++;
00267     iter++;
00268   }
00269   return count;
00270 
00271 }
00272 
00273 
00274 //
00275 // count number of non empty DT muons
00276 //
00277 int L1MuGMTPSB::numberDTBX() const {
00278 
00279   int count = 0;
00280   std::vector<L1MuRegionalCand>::const_iterator iter = m_DtbxMuons.begin();
00281   while ( iter != m_DtbxMuons.end() ) {
00282     if ( !(*iter).empty() ) count++;
00283     iter++;
00284   }
00285   return count;
00286 
00287 }
00288 
00289 
00290 //
00291 // count number of non empty CSC muons
00292 //
00293 int L1MuGMTPSB::numberCSC() const {
00294 
00295   int count = 0;
00296   std::vector<L1MuRegionalCand>::const_iterator iter = m_CscMuons.begin();
00297   while ( iter != m_CscMuons.end() ) {
00298     if ( !(*iter).empty() ) count++;
00299     iter++;
00300   }
00301   return count;
00302 
00303 }
00304 
00305 
00306 //
00307 // are there any data in the PSB
00308 //
00309 bool L1MuGMTPSB::empty() const {
00310 
00311   int number = numberRPC() + numberDTBX() + numberCSC();
00312 
00313   return ( number == 0 );
00314 
00315 }
00316 
00317 
00318 //
00319 // get muons from RPCb Trigger
00320 //
00321 void L1MuGMTPSB::getRPCb(std::vector<L1MuRegionalCand> const* data, int bx) {
00322 
00323   int irpcb = 0;
00324   std::vector<L1MuRegionalCand>::const_iterator iter;
00325   for ( iter = data->begin(); iter != data->end(); iter++ ) {
00326     if ( (*iter).bx() != bx ) continue;
00327     if ( irpcb < (int)L1MuGMTConfig::MAXRPCbarrel ) { 
00328       if(!(*iter).empty()) m_RpcMuons[irpcb] = (*iter);
00329       irpcb++;
00330     }  
00331   }
00332   
00333 }
00334 
00335 
00336 //
00337 // get muons from RPCf Trigger
00338 //
00339 void L1MuGMTPSB::getRPCf(std::vector<L1MuRegionalCand> const* data, int bx) {
00340 
00341   int irpcf = 0;
00342   std::vector<L1MuRegionalCand>::const_iterator iter;
00343   for ( iter = data->begin(); iter != data->end(); iter++ ) {
00344     if ( (*iter).bx() != bx ) continue;
00345     if ( irpcf < (int)L1MuGMTConfig::MAXRPCendcap ) { 
00346       if(!(*iter).empty()) m_RpcMuons[irpcf+4] = (*iter);
00347       irpcf++;
00348     }  
00349   }
00350   
00351 }
00352 
00353 
00354 //
00355 // get muons from barrel Muon Trigger Track Finder
00356 //
00357 void L1MuGMTPSB::getDTBX(std::vector<L1MuRegionalCand> const* data, int bx) {
00358 
00359   // temporary hack with bxoffset - to be removed, trigger bx should be 0
00360   int bxoffset = 0;
00361   int idtbx = 0;
00362   std::vector<L1MuRegionalCand>::const_iterator iter;
00363   for ( iter = data->begin(); iter != data->end(); iter++ ) {
00364     if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("") << "DTTF BX: " << (*iter).bx() << " my bx: " << bx;
00365     if ( (*iter).bx() > 10) bxoffset=16;
00366     if ( (*iter).bx() != bx+bxoffset ) continue;
00367     if ( idtbx < (int)L1MuGMTConfig::MAXDTBX ) { 
00368       m_DtbxMuons[idtbx] = (*iter);
00369       m_DtbxMuons[idtbx].setBx(bx);
00370       idtbx++;
00371     }  
00372   }
00373 
00374 }
00375 
00376 
00377 //
00378 // get muons from CSC Track Finder
00379 //
00380 void L1MuGMTPSB::getCSC(std::vector<L1MuRegionalCand> const* data, int bx) {
00381 
00382   int icsc = 0;
00383   std::vector<L1MuRegionalCand>::const_iterator iter;
00384   for ( iter = data->begin(); iter != data->end(); iter++ ) {
00385     if ( (*iter).bx() != bx ) continue;
00386     if ( icsc < (int)L1MuGMTConfig::MAXCSC ) { 
00387       m_CscMuons[icsc] = (*iter);
00388       icsc++;
00389     }
00390   }
00391 
00392 }
00393 
00394 
00395 //
00396 // print barrel RPC muons
00397 //
00398 void L1MuGMTPSB::printRPCbarrel() const {
00399 
00400   edm::LogVerbatim("GMT_PSB_info") << "RPC barrel  muons received by the GMT :";
00401 
00402   for ( unsigned i = 0; i < L1MuGMTConfig::MAXRPCbarrel; i++ ) {
00403     if (!m_RpcMuons[i].empty()) m_RpcMuons[i].print();
00404   }
00405   
00406 }
00407 
00408 
00409 //
00410 // print endcap RPC muons
00411 //
00412 void L1MuGMTPSB::printRPCendcap() const {
00413 
00414   edm::LogVerbatim("GMT_PSB_info") << "RPC endcap  muons received by the GMT :";
00415 
00416   for ( unsigned i = 0; i < L1MuGMTConfig::MAXRPCendcap; i++ ) {
00417     if (!m_RpcMuons[i+4].empty()) m_RpcMuons[i+4].print();
00418   }
00419 
00420 }
00421 
00422 
00423 //
00424 // print DTBX muons
00425 //
00426 void L1MuGMTPSB::printDTBX() const {
00427 
00428   edm::LogVerbatim("GMT_PSB_info") << "DTBX muons received by the GMT :";
00429 
00430   for ( unsigned i = 0; i < L1MuGMTConfig::MAXDTBX; i++ ) {
00431     if (!m_DtbxMuons[i].empty()) m_DtbxMuons[i].print();
00432   }
00433   
00434 }
00435 
00436 
00437 //
00438 // print CSC muons
00439 //
00440 void L1MuGMTPSB::printCSC() const {
00441 
00442   edm::LogVerbatim("GMT_PSB_info") << "CSC  muons received by the GMT :";
00443 
00444   for ( unsigned i = 0; i < L1MuGMTConfig::MAXCSC; i++ ) {
00445     if (!m_CscMuons[i].empty()) m_CscMuons[i].print();
00446   }
00447 
00448 }
00449 
00450 
00451 //
00452 // get data from regional calorimeter trigger
00453 //
00454 void L1MuGMTPSB::getCalo(edm::Event& e) {
00455   
00456   edm::Handle<L1CaloRegionCollection> calocoll_h;
00457   e.getByLabel(L1MuGMTConfig::getMipIsoInputTag(),calocoll_h);
00458   if(calocoll_h.isValid())
00459   {
00460     L1CaloRegionCollection const* regions = calocoll_h.product();
00461     L1CaloRegionCollection::const_iterator iter;
00462 
00463     //  edm::LogVerbatim("GMT_PSB_info") << "MIP/QUIET bits rceived by the GMT :";
00464 
00465     for ( iter = regions->begin(); iter != regions->end(); iter++ ) {
00466       if ( (*iter).id().ieta() < 4 || (*iter).id().ieta() > 17 || (*iter).id().iphi() > 17 ) continue;
00467       m_Isol.set( (*iter).id().ieta()-4, (*iter).id().iphi(), (*iter).quiet() );
00468       m_Mip.set( (*iter).id().ieta()-4, (*iter).id().iphi(), (*iter).mip() );
00469 
00470       if ( (*iter).quiet() )
00471         m_gmt.currentReadoutRecord()->setQuietbit ((*iter).id().ieta()-4, (*iter).id().iphi());
00472 
00473       if ( (*iter).mip() )
00474         m_gmt.currentReadoutRecord()->setMIPbit ((*iter).id().ieta()-4, (*iter).id().iphi());
00475 
00476       //    edm::LogVerbatim("GMT_PSB_info") << (*iter).id().ieta()-4 << " "
00477       //                                     << (*iter).id().iphi() << " "
00478       //                                     << (*iter).quiet() << " "
00479       //                                     << (*iter).mip();
00480     }
00481   } else {
00482     if( L1MuGMTConfig::Debug(1) ) {
00483       edm::LogWarning("GlobalMuonTrigger")
00484       << "\nWarning: GlobalMuonTrigger: input tag " << L1MuGMTConfig::getMipIsoInputTag()
00485       << "\nrequested, but not found in the event." << std::endl;
00486     }
00487   }
00488 
00489 }