CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/L1Trigger/GlobalMuonTrigger/src/L1MuGlobalMuonTrigger.cc

Go to the documentation of this file.
00001 //---------------------------------------------
00002 //
00003 //   \class L1MuGlobalMuonTrigger
00004 //
00005 //   Description: L1 Global Muon Trigger
00006 //
00007 //
00008 //   $Date: 2010/02/12 12:07:37 $
00009 //   $Revision: 1.14 $
00010 //
00011 //   Author :
00012 //   Norbert Neumeister              CERN EP
00013 //   Hannes Sakulin                  HEPHY Vienna
00014 //   Ivan Mikulec                    HEPHY Vienna
00015 //
00016 //--------------------------------------------------
00017 
00018 //-----------------------
00019 // This Class's Header --
00020 //-----------------------
00021 
00022 #include "L1Trigger/GlobalMuonTrigger/interface/L1MuGlobalMuonTrigger.h"
00023 
00024 //---------------
00025 // C++ Headers --
00026 //---------------
00027 
00028 #include <iostream>
00029 #include <sys/stat.h>
00030 #include <sys/types.h>
00031 
00032 //-------------------------------
00033 // Collaborating Class Headers --
00034 //-------------------------------
00035 
00036 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTCand.h"
00037 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTExtendedCand.h"
00038 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutRecord.h"
00039 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutCollection.h"
00040 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTConfig.h"
00041 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTPSB.h"
00042 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTMatcher.h"
00043 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTCancelOutUnit.h"
00044 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTMipIsoAU.h"
00045 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTMerger.h"
00046 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTSorter.h"
00047 
00048 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTDebugBlock.h"
00049 
00050 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00051 
00052 #include "FWCore/Framework/interface/EventSetup.h"
00053 #include "FWCore/Framework/interface/ESHandle.h"
00054 #include "CondFormats/L1TObjects/interface/L1MuGMTScales.h"
00055 #include "CondFormats/DataRecord/interface/L1MuGMTScalesRcd.h"
00056 #include "CondFormats/L1TObjects/interface/L1MuTriggerScales.h"
00057 #include "CondFormats/DataRecord/interface/L1MuTriggerScalesRcd.h"
00058 #include "CondFormats/L1TObjects/interface/L1MuTriggerPtScale.h"
00059 #include "CondFormats/DataRecord/interface/L1MuTriggerPtScaleRcd.h"
00060 #include "CondFormats/L1TObjects/interface/L1MuGMTParameters.h"
00061 #include "CondFormats/DataRecord/interface/L1MuGMTParametersRcd.h"
00062 #include "CondFormats/L1TObjects/interface/L1MuGMTChannelMask.h"
00063 #include "CondFormats/DataRecord/interface/L1MuGMTChannelMaskRcd.h"
00064 
00065 #include "CondFormats/L1TObjects/interface/L1CaloGeometry.h"
00066 #include "CondFormats/DataRecord/interface/L1CaloGeometryRecord.h"
00067 
00068 //----------------
00069 // Constructors --
00070 //----------------
00071 L1MuGlobalMuonTrigger::L1MuGlobalMuonTrigger(const edm::ParameterSet& ps) {
00072   produces<std::vector<L1MuGMTCand> >();
00073   produces<L1MuGMTReadoutCollection>();
00074   m_sendMipIso = ps.getUntrackedParameter<bool>("SendMipIso",false);
00075   if( m_sendMipIso ) {
00076     produces<std::vector<unsigned> >();
00077   }
00078   
00079   m_L1MuGMTScalesCacheID = 0ULL;
00080   m_L1MuTriggerScalesCacheID = 0ULL;
00081   m_L1MuTriggerPtScaleCacheID = 0ULL;
00082   m_L1MuGMTParametersCacheID = 0ULL;
00083   m_L1MuGMTChannelMaskCacheID = 0ULL;
00084   m_L1CaloGeometryCacheID = 0ULL;
00085   
00086   m_ExtendedCands.reserve(20);
00087 
00088   // set configuration parameters
00089   if(!m_config) m_config = new L1MuGMTConfig(ps);
00090   m_writeLUTsAndRegs = ps.getUntrackedParameter<bool>("WriteLUTsAndRegs",false);
00091 
00092   // build GMT
00093   if ( L1MuGMTConfig::Debug(1) ) edm::LogVerbatim("GMT_info");
00094   if ( L1MuGMTConfig::Debug(1) ) edm::LogVerbatim("GMT_info") << "**** L1GlobalMuonTrigger building ****";
00095   if ( L1MuGMTConfig::Debug(1) ) edm::LogVerbatim("GMT_info");
00096 
00097   // create new PSB
00098   if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT PSB";
00099   m_PSB = new L1MuGMTPSB(*this);
00100 
00101   // create new matcher
00102   if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT Matcher (0,1)";
00103   m_Matcher[0] = new L1MuGMTMatcher(*this,0);   // barrel
00104   m_Matcher[1] = new L1MuGMTMatcher(*this,1);   // endcap
00105 
00106   // create new cancel-out units
00107   if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT Cancel Out Unit (0,1,2,3)";
00108   m_CancelOutUnit[0] = new L1MuGMTCancelOutUnit(*this,0);   // barrel
00109   m_CancelOutUnit[1] = new L1MuGMTCancelOutUnit(*this,1);   // endcap
00110   m_CancelOutUnit[2] = new L1MuGMTCancelOutUnit(*this,2);   // CSC/bRPC
00111   m_CancelOutUnit[3] = new L1MuGMTCancelOutUnit(*this,3);   // DT/fRPC
00112 
00113   // create new MIP & ISO bit assignment units
00114   if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT MIP & ISO bit Assigment Unit (0,1)";
00115   m_MipIsoAU[0] = new L1MuGMTMipIsoAU(*this,0);   // barrel
00116   m_MipIsoAU[1] = new L1MuGMTMipIsoAU(*this,1);   // endcap
00117 
00118   // create new Merger
00119   if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT Merger (0,1)";
00120   m_Merger[0] = new L1MuGMTMerger(*this,0);   // barrel
00121   m_Merger[1] = new L1MuGMTMerger(*this,1);   // endcap
00122 
00123   // create new sorter
00124   if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT Sorter";
00125   m_Sorter = new L1MuGMTSorter(*this);   // barrel
00126 
00127   if(!m_db) m_db = new L1MuGMTDebugBlock(m_config->getBxMin(),m_config->getBxMax());
00128 }
00129 
00130 //--------------
00131 // Destructor --
00132 //--------------
00133 L1MuGlobalMuonTrigger::~L1MuGlobalMuonTrigger() {
00134 
00135   if(m_db) delete m_db;
00136   m_db = 0;
00137 
00138   delete m_Sorter;
00139   delete m_Merger[1];        // endcap Merger
00140   delete m_Merger[0];        // barrel Merger
00141   delete m_MipIsoAU[1];      // barrel MIP & ISO bit assignment unit
00142   delete m_MipIsoAU[0];      // barrel MIP & ISO bit assignment unit
00143   delete m_CancelOutUnit[3]; // DT/fRPC cancel-out unit (in endcap chip)
00144   delete m_CancelOutUnit[2]; // CSC/bRPC cancel-out unit (in barrel chip)
00145   delete m_CancelOutUnit[1]; // endcap DT/CSC cancel out unit
00146   delete m_CancelOutUnit[0]; // barrel DT/CSC cancel out unit
00147   delete m_Matcher[1];       // endcap matcher
00148   delete m_Matcher[0];       // barrel matcher
00149   delete m_PSB;
00150 
00151   if(m_config) delete m_config;
00152   m_config = 0;
00153 
00154   // copied from produce() by Jim B, 7 Aug 2007
00155   std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
00156   for ( ;irr!=m_ReadoutRingbuffer.end(); irr++) delete (*irr);
00157   m_ReadoutRingbuffer.clear();
00158   // end Jim B edit
00159 
00160 }
00161 
00162 //--------------
00163 // Operations --
00164 //--------------
00165 
00166 void L1MuGlobalMuonTrigger::beginJob() {
00167     
00168 }
00169 
00170 void L1MuGlobalMuonTrigger::produce(edm::Event& e, const edm::EventSetup& es) {
00171   
00172   // configure from the event setup
00173   
00174   unsigned long long L1MuGMTScalesCacheID = es.get< L1MuGMTScalesRcd >().cacheIdentifier();
00175   if(L1MuGMTScalesCacheID != m_L1MuGMTScalesCacheID) {
00176     edm::ESHandle< L1MuGMTScales > gmtscales_h;
00177     es.get< L1MuGMTScalesRcd >().get( gmtscales_h );
00178     m_config->setGMTScales( gmtscales_h.product() );
00179   }
00180 
00181   unsigned long long L1MuTriggerScalesCacheID = es.get< L1MuTriggerScalesRcd >().cacheIdentifier();
00182   if(L1MuTriggerScalesCacheID != m_L1MuTriggerScalesCacheID) {
00183     edm::ESHandle< L1MuTriggerScales > trigscales_h;
00184     es.get< L1MuTriggerScalesRcd >().get( trigscales_h );
00185     m_config->setTriggerScales( trigscales_h.product() );
00186   }
00187 
00188   unsigned long long L1MuTriggerPtScaleCacheID = es.get< L1MuTriggerPtScaleRcd >().cacheIdentifier();
00189   if(L1MuTriggerPtScaleCacheID != m_L1MuTriggerPtScaleCacheID) {
00190     edm::ESHandle< L1MuTriggerPtScale > trigptscale_h;
00191     es.get< L1MuTriggerPtScaleRcd >().get( trigptscale_h );
00192     m_config->setTriggerPtScale( trigptscale_h.product() );
00193   }
00194 
00195   unsigned long long L1MuGMTParametersCacheID = es.get< L1MuGMTParametersRcd >().cacheIdentifier();
00196   if(L1MuGMTParametersCacheID != m_L1MuGMTParametersCacheID) {
00197     edm::ESHandle< L1MuGMTParameters > gmtparams_h;
00198     es.get< L1MuGMTParametersRcd >().get( gmtparams_h );
00199     m_config->setGMTParams( gmtparams_h.product() );
00200     m_config->setDefaults();
00201   }
00202 
00203   unsigned long long L1MuGMTChannelMaskCacheID = es.get< L1MuGMTChannelMaskRcd >().cacheIdentifier();
00204   if(L1MuGMTChannelMaskCacheID != m_L1MuGMTChannelMaskCacheID) {
00205     edm::ESHandle< L1MuGMTChannelMask > gmtchanmask_h;
00206     es.get< L1MuGMTChannelMaskRcd >().get( gmtchanmask_h );
00207     m_config->setGMTChanMask( gmtchanmask_h.product() );
00208     if ( L1MuGMTConfig::Debug(1) ) {
00209       std::string onoff;
00210       const L1MuGMTChannelMask* theChannelMask = L1MuGMTConfig::getGMTChanMask();
00211       unsigned mask = theChannelMask->getSubsystemMask();
00212       
00213       edm::LogVerbatim("GMT_info");
00214       edm::LogVerbatim("GMT_info") << " GMT input Channel Mask:" << std::hex << mask << std::dec;
00215       onoff = mask&1 ? "OFF" : "ON";
00216       edm::LogVerbatim("GMT_info") << " DT   input " << onoff;
00217       onoff = mask&2 ? "OFF" : "ON";
00218       edm::LogVerbatim("GMT_info") << " RPCb input " << onoff;
00219       onoff = mask&4 ? "OFF" : "ON";
00220       edm::LogVerbatim("GMT_info") << " CSC  input " << onoff;
00221       onoff = mask&8 ? "OFF" : "ON";
00222       edm::LogVerbatim("GMT_info") << " RPCf input " << onoff;
00223       edm::LogVerbatim("GMT_info");
00224     }
00225   }
00226 
00227   unsigned long long L1CaloGeometryCacheID = es.get< L1CaloGeometryRecord >().cacheIdentifier();
00228   if(L1CaloGeometryCacheID != m_L1CaloGeometryCacheID) {
00229     edm::ESHandle< L1CaloGeometry > caloGeom_h ;
00230     es.get< L1CaloGeometryRecord >().get( caloGeom_h ) ;
00231     m_config->setCaloGeom( caloGeom_h.product() ) ;
00232   }
00233   
00234   m_config->createLUTsRegs();
00235   
00236   // write LUTs and Regs if required
00237   
00238   if(m_writeLUTsAndRegs) {
00239     std::string dir = "gmtconfig";
00240   
00241     mkdir(dir.c_str(), S_ISUID|S_ISGID|S_ISVTX|S_IRUSR|S_IWUSR|S_IXUSR);
00242 
00243     m_config->dumpLUTs(dir);
00244     m_config->dumpRegs(dir);
00245   }
00246   
00247   // process the event
00248   if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info");
00249   if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "**** L1GlobalMuonTrigger processing ****";
00250   if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info");
00251 
00252   int bx_min = L1MuGMTConfig::getBxMin();
00253   int bx_max = L1MuGMTConfig::getBxMax();
00254 
00255   m_ExtendedCands.clear();
00256 
00257   // clear readout ring buffer
00258   std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
00259   for ( ;irr!=m_ReadoutRingbuffer.end(); irr++) delete (*irr);
00260   m_ReadoutRingbuffer.clear();
00261 
00262   if(m_db) m_db->reset(); // reset debug block
00263 
00264   for ( int bx = bx_min; bx <= bx_max; bx++ ) {
00265     m_db->SetBX(bx);
00266 
00267     // create new element in readout ring buffer
00268     m_ReadoutRingbuffer.push_back( new L1MuGMTReadoutRecord(bx) );
00269 
00270     if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "L1GlobalMuonTrigger processing bunch-crossing : " << bx;
00271 
00272     // get data into the data buffer
00273     if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT PSB";
00274     if ( m_PSB ) {
00275       m_PSB->receiveData(e,bx);
00276       if ( L1MuGMTConfig::Debug(4) ) m_PSB->print();
00277     }
00278 
00279     if ( m_PSB && !m_PSB->empty() ) {
00280 
00281       // run matcher
00282       if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT barrel Matcher";
00283       if ( m_Matcher[0] ) m_Matcher[0]->run();
00284       if ( L1MuGMTConfig::Debug(3) && m_Matcher[0] ) m_Matcher[0]->print();
00285       if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT endcap Matcher";
00286       if ( m_Matcher[1] ) m_Matcher[1]->run();
00287       if ( L1MuGMTConfig::Debug(3) && m_Matcher[1] ) m_Matcher[1]->print();
00288 
00289       // run cancel-out units
00290       if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT barrel Cancel Out Unit";
00291       if ( m_CancelOutUnit[0] ) m_CancelOutUnit[0]->run();
00292       if ( L1MuGMTConfig::Debug(3) && m_CancelOutUnit[0] ) m_CancelOutUnit[0]->print();
00293 
00294       if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT endcap Cancel Out Unit";
00295       if ( m_CancelOutUnit[1] ) m_CancelOutUnit[1]->run();
00296       if ( L1MuGMTConfig::Debug(3) && m_CancelOutUnit[1] ) m_CancelOutUnit[1]->print();
00297 
00298       if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT CSC/fRPC Cancel Out Unit";
00299       if ( m_CancelOutUnit[2] ) m_CancelOutUnit[2]->run();
00300       if ( L1MuGMTConfig::Debug(3) && m_CancelOutUnit[2] ) m_CancelOutUnit[2]->print();
00301 
00302       if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT DT/bRPC Cancel Out Unit";
00303       if ( m_CancelOutUnit[3] ) m_CancelOutUnit[3]->run();
00304       if ( L1MuGMTConfig::Debug(3) && m_CancelOutUnit[3] ) m_CancelOutUnit[3]->print();
00305 
00306       // run MIP & ISO bit assignment units
00307       if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT barrel MIP & ISO bit Assignment Unit";
00308       if ( m_MipIsoAU[0] ) m_MipIsoAU[0]->run();
00309       if ( L1MuGMTConfig::Debug(3) && m_MipIsoAU[0] ) m_MipIsoAU[0]->print();
00310       if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT endcap MIP & ISO bit Assignment Unit";
00311       if ( m_MipIsoAU[1] ) m_MipIsoAU[1]->run();
00312       if ( L1MuGMTConfig::Debug(3) && m_MipIsoAU[1] ) m_MipIsoAU[1]->print();
00313 
00314       // run Merger
00315       if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT barrel Merger";
00316       if ( m_Merger[0] ) m_Merger[0]->run();
00317       if ( L1MuGMTConfig::Debug(3) && m_Merger[0] ) m_Merger[0]->print();
00318       if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT endcap Merger";
00319       if ( m_Merger[1] ) m_Merger[1]->run();
00320       if ( L1MuGMTConfig::Debug(3) && m_Merger[1] ) m_Merger[1]->print();
00321 
00322       // run sorter
00323       if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT Sorter";
00324       if ( m_Sorter ) m_Sorter->run();
00325       if ( L1MuGMTConfig::Debug(1) && m_Sorter ) m_Sorter->print();
00326 
00327       // store found track candidates in a container
00328       if ( m_Sorter->numberOfCands() > 0 ) {
00329         const std::vector<const L1MuGMTExtendedCand*>&  gmt_cont = m_Sorter->Cands();
00330         std::vector<const L1MuGMTExtendedCand*>::const_iterator iexc;
00331         for ( iexc = gmt_cont.begin(); iexc != gmt_cont.end(); iexc++ ) {
00332           if ( *iexc ) m_ExtendedCands.push_back( **iexc );
00333         }
00334       }
00335 
00336       // reset GMT
00337       reset();
00338 
00339     }
00340   }
00341 
00342   // produce the output
00343   std::auto_ptr<std::vector<L1MuGMTCand> > GMTCands(new std::vector<L1MuGMTCand>);
00344   std::vector<L1MuGMTExtendedCand>::const_iterator iexc;
00345   for(iexc=m_ExtendedCands.begin(); iexc!=m_ExtendedCands.end(); iexc++) {
00346     GMTCands->push_back(*iexc);
00347   }
00348   e.put(GMTCands);
00349 
00350   std::auto_ptr<L1MuGMTReadoutCollection> GMTRRC(getReadoutCollection());
00351   e.put(GMTRRC);
00352 
00353   if( m_sendMipIso ) {
00354     std::auto_ptr<std::vector<unsigned> > mipiso(new std::vector<unsigned>);
00355     for(int i=0; i<32; i++) {
00356       mipiso->push_back(m_db->IsMIPISO(0,i));
00357     }  
00358     e.put(mipiso);
00359   }
00360   
00361 // delete registers and LUTs
00362   m_config->clearLUTsRegs();
00363 }
00364 
00365 //
00366 // reset GMT
00367 //
00368 void L1MuGlobalMuonTrigger::reset() {
00369 
00370   if ( m_PSB ) m_PSB->reset();
00371   if ( m_Matcher[0] ) m_Matcher[0]->reset();
00372   if ( m_Matcher[1] ) m_Matcher[1]->reset();
00373   if ( m_CancelOutUnit[0] ) m_CancelOutUnit[0]->reset();
00374   if ( m_CancelOutUnit[1] ) m_CancelOutUnit[1]->reset();
00375   if ( m_CancelOutUnit[2] ) m_CancelOutUnit[2]->reset();
00376   if ( m_CancelOutUnit[3] ) m_CancelOutUnit[3]->reset();
00377   if ( m_MipIsoAU[0] ) m_MipIsoAU[0]->reset();
00378   if ( m_MipIsoAU[1] ) m_MipIsoAU[1]->reset();
00379   if ( m_Merger[0] ) m_Merger[0]->reset();
00380   if ( m_Merger[1] ) m_Merger[1]->reset();
00381   if ( m_Sorter) m_Sorter->reset();
00382 
00383 }
00384 
00385 // get the GMT readout data for the triggered bx
00386 std::auto_ptr<L1MuGMTReadoutCollection> L1MuGlobalMuonTrigger::getReadoutCollection() {
00387 
00388   int bx_min_ro = L1MuGMTConfig::getBxMinRo();
00389   int bx_max_ro = L1MuGMTConfig::getBxMaxRo();
00390   int bx_size = bx_max_ro - bx_min_ro + 1;
00391 
00392   std::auto_ptr<L1MuGMTReadoutCollection> rrc(new L1MuGMTReadoutCollection(bx_size));
00393 
00394   for (int bx = bx_min_ro; bx <= bx_max_ro; bx++) {
00395     std::vector<L1MuGMTReadoutRecord*>::const_iterator iter = m_ReadoutRingbuffer.begin();
00396 
00397     for ( ;iter!=m_ReadoutRingbuffer.end(); iter++) {
00398 
00399       if ( (*iter)->getBxInEvent() == bx ) {
00400         rrc->addRecord(**iter);
00401         break;
00402       }
00403     }
00404 
00405   }
00406 
00407   return rrc;
00408 }
00409 
00410 // static data members
00411 
00412 L1MuGMTConfig* L1MuGlobalMuonTrigger::m_config = 0;
00413 L1MuGMTDebugBlock* L1MuGlobalMuonTrigger::m_db = 0;