CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/L1Trigger/DTTrackFinder/src/L1MuDTTrackFinder.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: L1MuDTTrackFinder
00004 //
00005 //   Description: L1 barrel Muon Trigger Track Finder
00006 //
00007 //
00008 //   $Date: 2008/05/09 15:02:00 $
00009 //   $Revision: 1.10 $
00010 //
00011 //   Author :
00012 //   N. Neumeister            CERN EP
00013 //   J. Troconiz              UAM Madrid
00014 //
00015 //--------------------------------------------------
00016 
00017 //-----------------------
00018 // This Class's Header --
00019 //-----------------------
00020 
00021 #include "L1Trigger/DTTrackFinder/interface/L1MuDTTrackFinder.h"
00022 
00023 //---------------
00024 // C++ Headers --
00025 //---------------
00026 
00027 #include <iostream>
00028 
00029 //-------------------------------
00030 // Collaborating Class Headers --
00031 //-------------------------------
00032 
00033 #include <DataFormats/Common/interface/Handle.h>
00034 #include <FWCore/Framework/interface/Event.h>
00035 #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h"
00036 #include "DataFormats/L1DTTrackFinder/interface/L1MuDTTrackCand.h"
00037 #include "L1Trigger/DTTrackFinder/src/L1MuDTTFConfig.h"
00038 #include "L1Trigger/DTTrackFinder/src/L1MuDTSecProcId.h"
00039 #include "L1Trigger/DTTrackFinder/src/L1MuDTSecProcMap.h"
00040 #include "L1Trigger/DTTrackFinder/src/L1MuDTSectorProcessor.h"
00041 #include "L1Trigger/DTTrackFinder/src/L1MuDTEtaProcessor.h"
00042 #include "L1Trigger/DTTrackFinder/src/L1MuDTWedgeSorter.h"
00043 #include "L1Trigger/DTTrackFinder/src/L1MuDTMuonSorter.h"
00044 #include "L1Trigger/DTTrackFinder/interface/L1MuDTTrack.h"
00045 
00046 using namespace std;
00047 
00048 //---------------------------------
00049 //       class L1MuDTTrackFinder
00050 //---------------------------------
00051 
00052 
00053 //----------------
00054 // Constructors --
00055 //----------------
00056 
00057 L1MuDTTrackFinder::L1MuDTTrackFinder(const edm::ParameterSet & ps) {
00058 
00059   // set configuration parameters
00060   if ( m_config == 0 ) m_config = new L1MuDTTFConfig(ps);
00061 
00062   if ( L1MuDTTFConfig::Debug(1) ) cout << endl;
00063   if ( L1MuDTTFConfig::Debug(1) ) cout << "**** entering L1MuDTTrackFinder ****" << endl;
00064   if ( L1MuDTTFConfig::Debug(1) ) cout << endl;
00065 
00066   m_spmap = new L1MuDTSecProcMap();
00067   m_epvec.reserve(12);
00068   m_wsvec.reserve(12);
00069   m_ms = 0;
00070 
00071   _cache.reserve(4*17);
00072   _cache0.reserve(144*17);
00073 
00074 }
00075 
00076 
00077 //--------------
00078 // Destructor --
00079 //--------------
00080 
00081 L1MuDTTrackFinder::~L1MuDTTrackFinder() {
00082 
00083   delete m_spmap;
00084 
00085   vector<L1MuDTEtaProcessor*>::iterator it_ep = m_epvec.begin();
00086   while ( it_ep != m_epvec.end() ) {
00087     delete (*it_ep);
00088     it_ep++;
00089   }
00090   m_epvec.clear();
00091 
00092   vector<L1MuDTWedgeSorter*>::iterator it_ws = m_wsvec.begin();
00093   while ( it_ws != m_wsvec.end() ) {
00094     delete (*it_ws);
00095     it_ws++;
00096   }
00097   m_wsvec.clear();
00098 
00099   delete m_ms;
00100 
00101   if ( m_config ) delete m_config;
00102   m_config = 0;
00103 
00104 }
00105 
00106 
00107 //--------------
00108 // Operations --
00109 //--------------
00110 
00111 //
00112 // setup MTTF configuration
00113 //
00114 void L1MuDTTrackFinder::setup() {
00115 
00116   // build the barrel Muon Trigger Track Finder
00117 
00118   if ( L1MuDTTFConfig::Debug(1) ) cout << endl;
00119   if ( L1MuDTTFConfig::Debug(1) ) cout << "**** L1MuDTTrackFinder building ****" << endl;
00120   if ( L1MuDTTFConfig::Debug(1) ) cout << endl;
00121 
00122   // create new sector processors
00123   for ( int wh = -3; wh <= 3; wh++ ) {
00124     if ( wh == 0 ) continue;
00125     for ( int sc = 0; sc < 12; sc++ ) {
00126       L1MuDTSecProcId tmpspid(wh,sc);
00127       L1MuDTSectorProcessor* sp = new L1MuDTSectorProcessor(*this,tmpspid);
00128       if ( L1MuDTTFConfig::Debug(2) ) cout << "creating " << tmpspid << endl;
00129       m_spmap->insert(tmpspid,sp);
00130     }
00131   }
00132  
00133   // create new eta processors and wedge sorters
00134   for ( int sc = 0; sc < 12; sc++ ) {
00135     L1MuDTEtaProcessor* ep = new L1MuDTEtaProcessor(*this,sc);
00136     if ( L1MuDTTFConfig::Debug(2) ) cout << "creating Eta Processor " << sc << endl;
00137     m_epvec.push_back(ep);
00138     L1MuDTWedgeSorter* ws = new L1MuDTWedgeSorter(*this,sc);
00139     if ( L1MuDTTFConfig::Debug(2) ) cout << "creating Wedge Sorter " << sc << endl;
00140     m_wsvec.push_back(ws);
00141   }
00142 
00143   // create new muon sorter
00144   if ( L1MuDTTFConfig::Debug(2) ) cout << "creating DT Muon Sorter " << endl;
00145   m_ms = new L1MuDTMuonSorter(*this);
00146 
00147 }
00148 
00149 
00150 //
00151 // run MTTF
00152 //
00153 void L1MuDTTrackFinder::run(const edm::Event& e, const edm::EventSetup& c) {
00154 
00155   // run the barrel Muon Trigger Track Finder
00156 
00157   edm::Handle<L1MuDTChambPhContainer> dttrig;
00158   e.getByLabel(L1MuDTTFConfig::getDTDigiInputTag(),dttrig);
00159   if ( dttrig->getContainer()->size() == 0 ) return;
00160 
00161   if ( L1MuDTTFConfig::Debug(2) ) cout << endl;
00162   if ( L1MuDTTFConfig::Debug(2) ) cout << "**** L1MuDTTrackFinder processing ****" << endl;
00163   if ( L1MuDTTFConfig::Debug(2) ) cout << endl;
00164 
00165   int bx_min = L1MuDTTFConfig::getBxMin();
00166   int bx_max = L1MuDTTFConfig::getBxMax();
00167 
00168   for ( int bx = bx_min; bx <= bx_max; bx++ ) {
00169 
00170   if ( dttrig->bxEmpty(bx) ) continue;
00171 
00172   if ( L1MuDTTFConfig::Debug(2) ) cout << "L1MuDTTrackFinder processing bunch-crossing : " << bx << endl;
00173 
00174     // reset MTTF
00175     reset();
00176 
00177     // run sector processors
00178     L1MuDTSecProcMap::SPmap_iter it_sp = m_spmap->begin();
00179     while ( it_sp != m_spmap->end() ) {
00180       if ( L1MuDTTFConfig::Debug(2) ) cout << "running " 
00181                                            << (*it_sp).second->id() << endl;
00182       if ( (*it_sp).second ) (*it_sp).second->run(bx,e,c);
00183       if ( L1MuDTTFConfig::Debug(2) && (*it_sp).second ) (*it_sp).second->print();
00184       it_sp++;
00185     } 
00186 
00187     // run eta processors
00188     vector<L1MuDTEtaProcessor*>::iterator it_ep = m_epvec.begin();
00189     while ( it_ep != m_epvec.end() ) {
00190       if ( L1MuDTTFConfig::Debug(2) ) cout << "running Eta Processor "
00191                                        << (*it_ep)->id() << endl;
00192       if ( *it_ep ) (*it_ep)->run(bx,e,c);
00193       if ( L1MuDTTFConfig::Debug(2) && *it_ep ) (*it_ep)->print();
00194       it_ep++;
00195     }
00196 
00197     // read sector processors
00198     it_sp = m_spmap->begin();
00199     while ( it_sp != m_spmap->end() ) {
00200       if ( L1MuDTTFConfig::Debug(2) ) cout << "reading " 
00201                                            << (*it_sp).second->id() << endl;
00202       for ( int number = 0; number < 2; number++ ) {
00203         const L1MuDTTrack* cand = (*it_sp).second->tracK(number);
00204         if ( cand && !cand->empty() ) _cache0.push_back(L1MuDTTrackCand(cand->getDataWord(),cand->bx(),
00205                                               cand->spid().wheel(),cand->spid().sector(),number,cand->address(1),
00206                                               cand->address(2),cand->address(3),cand->address(4),cand->tc()));
00207       }
00208       it_sp++;
00209     } 
00210 
00211     // run wedge sorters
00212     vector<L1MuDTWedgeSorter*>::iterator it_ws = m_wsvec.begin();
00213     while ( it_ws != m_wsvec.end() ) {
00214       if ( L1MuDTTFConfig::Debug(2) ) cout << "running Wedge Sorter " 
00215                                            << (*it_ws)->id() << endl;
00216       if ( *it_ws ) (*it_ws)->run();
00217       if ( L1MuDTTFConfig::Debug(2) && *it_ws ) (*it_ws)->print();
00218       it_ws++;
00219     }
00220 
00221     // run muon sorter
00222     if ( L1MuDTTFConfig::Debug(2) ) cout << "running DT Muon Sorter" << endl;
00223     if ( m_ms ) m_ms->run();
00224     if ( L1MuDTTFConfig::Debug(2) && m_ms ) m_ms->print();
00225 
00226     // store found track candidates in container (cache)
00227     if ( m_ms->numberOfTracks() > 0 ) {
00228       const vector<const L1MuDTTrack*>&  mttf_cont = m_ms->tracks();
00229       vector<const L1MuDTTrack*>::const_iterator iter;
00230       for ( iter = mttf_cont.begin(); iter != mttf_cont.end(); iter++ ) {
00231         if ( *iter ) _cache.push_back(L1MuRegionalCand((*iter)->getDataWord(),(*iter)->bx()));
00232       }
00233     }
00234     
00235   }
00236 
00237 }
00238 
00239 
00240 //
00241 // reset MTTF
00242 //
00243 void L1MuDTTrackFinder::reset() {
00244 
00245   L1MuDTSecProcMap::SPmap_iter it_sp = m_spmap->begin();
00246   while ( it_sp != m_spmap->end() ) {
00247     if ( (*it_sp).second ) (*it_sp).second->reset();
00248     it_sp++;
00249   }
00250 
00251   vector<L1MuDTEtaProcessor*>::iterator it_ep = m_epvec.begin();
00252   while ( it_ep != m_epvec.end() ) {
00253     if ( *it_ep ) (*it_ep)->reset();
00254     it_ep++;
00255   }
00256     
00257   vector<L1MuDTWedgeSorter*>::iterator it_ws = m_wsvec.begin();
00258   while ( it_ws != m_wsvec.end() ) {
00259     if ( *it_ws ) (*it_ws)->reset();
00260     it_ws++;
00261   }
00262 
00263   if ( m_ms ) m_ms->reset();
00264 
00265 }
00266 
00267 
00268 //
00269 // return Sector Processor container 
00270 //
00271 const L1MuDTSectorProcessor* L1MuDTTrackFinder::sp(const L1MuDTSecProcId& id) const { 
00272 
00273   return m_spmap->sp(id); 
00274 
00275 }
00276 
00277 
00278 //
00279 // return number of muon candidates found by the barrel MTTF
00280 //
00281 int L1MuDTTrackFinder::numberOfTracks() {
00282 
00283   return _cache.size();
00284 
00285 }
00286 
00287 
00288 L1MuDTTrackFinder::TFtracks_const_iter L1MuDTTrackFinder::begin() {
00289 
00290   return _cache.begin();
00291 
00292 }
00293 
00294 
00295 L1MuDTTrackFinder::TFtracks_const_iter L1MuDTTrackFinder::end() {
00296 
00297   return _cache.end();
00298 
00299 }
00300 
00301 
00302 void L1MuDTTrackFinder::clear() {
00303 
00304   _cache.clear();
00305   _cache0.clear();
00306 
00307 }
00308 
00309 
00310 //
00311 // return number of muon candidates found by the barrel MTTF at a given bx
00312 //
00313 int L1MuDTTrackFinder::numberOfTracks(int bx) {
00314 
00315   int number = 0;
00316   for ( TFtracks_const_iter it  = _cache.begin(); it != _cache.end(); it++ ) {
00317     if ( (*it).bx() == bx ) number++;
00318   }
00319   
00320   return number;
00321 
00322 }
00323 
00324 
00325 // static data members
00326 
00327 L1MuDTTFConfig* L1MuDTTrackFinder::m_config = 0;