CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/L1Trigger/DTTrackFinder/src/L1MuDTExtrapolationUnit.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: L1MuDTExtrapolationUnit
00004 //
00005 //   Description: Extrapolation Unit
00006 //
00007 //
00008 //   $Date: 2008/11/28 10:30:51 $
00009 //   $Revision: 1.5 $
00010 //
00011 //   Author :
00012 //   N. Neumeister            CERN EP
00013 //
00014 //--------------------------------------------------
00015 
00016 //-----------------------
00017 // This Class's Header --
00018 //-----------------------
00019 
00020 #include "L1Trigger/DTTrackFinder/src/L1MuDTExtrapolationUnit.h"
00021 
00022 //---------------
00023 // C++ Headers --
00024 //---------------
00025 
00026 #include <iostream>
00027 #include <bitset>
00028 #include <cassert>
00029 
00030 //-------------------------------
00031 // Collaborating Class Headers --
00032 //-------------------------------
00033 
00034 #include "L1Trigger/DTTrackFinder/src/L1MuDTTFConfig.h"
00035 #include "CondFormats/L1TObjects/interface/L1MuDTExtParam.h"
00036 #include "L1Trigger/DTTrackFinder/src/L1MuDTSEU.h"
00037 #include "L1Trigger/DTTrackFinder/src/L1MuDTEUX.h"
00038 #include "L1Trigger/DTTrackFinder/src/L1MuDTERS.h"
00039 #include "L1Trigger/DTTrackFinder/src/L1MuDTSectorProcessor.h"
00040 #include "L1Trigger/DTTrackFinder/src/L1MuDTSecProcId.h"
00041 #include "L1Trigger/DTTrackFinder/src/L1MuDTDataBuffer.h"
00042 #include "L1Trigger/DTTrackFinder/src/L1MuDTTrackSegPhi.h"
00043 #include "CondFormats/L1TObjects/interface/L1MuDTTFParameters.h"
00044 #include "CondFormats/DataRecord/interface/L1MuDTTFParametersRcd.h"
00045 
00046 using namespace std;
00047 
00048 // --------------------------------
00049 //       class L1MuDTExtrapolationUnit
00050 //---------------------------------
00051 
00052 //----------------
00053 // Constructors --
00054 //----------------
00055 
00056 L1MuDTExtrapolationUnit::L1MuDTExtrapolationUnit(const L1MuDTSectorProcessor& sp) :
00057                     m_sp(sp), m_SEUs() {
00058 
00059   for ( int ext_idx = 0; ext_idx < MAX_EXT; ext_idx++ ) {
00060   
00061     Extrapolation ext = static_cast<Extrapolation>(ext_idx);   
00062 
00063     if ( ext == EX12 || ext == EX13 || ext == EX14 ||
00064          ext == EX21 || ext == EX23 || ext == EX24 || ext == EX34 ) {
00065          
00066       unsigned int maxaddr = 4;   
00067       
00068       if ( ext == EX12 || ext == EX13 || ext == EX14 ) maxaddr = 2;
00069 
00070       for ( unsigned int startAddress = 0; startAddress < maxaddr; startAddress++ ) {
00071         SEUId id = make_pair(ext, startAddress);
00072         m_SEUs[id] = new L1MuDTSEU(sp,ext,startAddress);
00073         if ( L1MuDTTFConfig::Debug(6) ) cout << "  creating SEU " << ext << " " << startAddress << endl;
00074       }  
00075     }
00076   }
00077 
00078 }
00079 
00080 
00081 //--------------
00082 // Destructor --
00083 //--------------
00084 
00085 L1MuDTExtrapolationUnit::~L1MuDTExtrapolationUnit() {
00086 
00087   for ( SEUmap::iterator iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
00088     delete (*iter).second;
00089     (*iter).second = 0;
00090   }
00091   m_SEUs.clear();
00092 
00093 }
00094 
00095 
00096 //--------------
00097 // Operations --
00098 //--------------
00099 
00100 //
00101 // run Extrapolation Unit
00102 //
00103 void L1MuDTExtrapolationUnit::run(const edm::EventSetup& c) {
00104 
00105   c.get< L1MuDTTFParametersRcd >().get( pars );
00106 
00107   SEUmap::const_iterator iter;
00108   for ( iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
00109 
00110     pair<int,int> ext_pair = which_ext(((*iter).second)->ext());
00111     int start = ext_pair.first;
00112 
00113     const L1MuDTTrackSegPhi* ts = 0;
00114 
00115     //get start track segment
00116     ts = m_sp.data()->getTSphi(start, ((*iter).second)->tsId() );
00117 
00118     if ( ts != 0 && !ts->empty() ) {
00119       ((*iter).second)->load(ts);
00120       ((*iter).second)->run(c);
00121     }
00122 
00123   }
00124 
00125   //
00126   // use EX21 to cross-check EX12
00127   //
00128   bool run_21 = pars->get_soc_run_21(m_sp.id().wheel(), m_sp.id().sector());
00129   if ( L1MuDTTFConfig::getUseEX21() || run_21 ) {
00130 
00131     // search for EX12 + EX21 single extrapolation units
00132     for ( unsigned int startAdr = 0; startAdr < 2; startAdr++ ) {
00133     
00134       bitset<12> extab12 = this->getEXTable( EX12, startAdr );
00135       bitset<12> extab21 = this->getEXTable( EX21, startAdr );
00136 
00137       for ( int eux = 0; eux < 12; eux++ ) {
00138         if ( extab12.test(eux) && !extab21.test(eux) ) {
00139           reset(EX12,startAdr,eux); 
00140           if ( L1MuDTTFConfig::Debug(6) ) {
00141             SEUId seuid = make_pair(EX12, startAdr);
00142             L1MuDTSEU* SEU12 = m_SEUs[seuid];
00143             cout << "  EX12 - EX21 mismatch : "
00144                  << " EX12 : " << extab12 << " , " 
00145                  << " EX21 : " << extab21 << endl
00146                  << "  Cancel: " << SEU12->ext()
00147                  << " start addr = " << SEU12->tsId()
00148                  << " target addr = " << eux << endl;
00149           }  
00150         }
00151       }
00152 
00153     }
00154   }
00155 
00156 }
00157 
00158 
00159 //
00160 // reset Extrapolation Unit
00161 //
00162 void L1MuDTExtrapolationUnit::reset() {
00163 
00164   SEUmap::const_iterator iter; 
00165   for ( iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
00166     ((*iter).second)->reset();
00167   }
00168 
00169 }
00170 
00171 
00172 //
00173 // reset a single extrapolation
00174 //
00175 void L1MuDTExtrapolationUnit::reset(Extrapolation ext, unsigned int startAdr, unsigned int relAdr) {
00176 
00177   //  assert( startAdr >= 0 && startAdr <= 3 );
00178   //  assert( relAdr >= 0 && relAdr <= 12 );
00179 
00180   SEUId seuid = make_pair(ext, startAdr);
00181   SEUmap::const_iterator iter = m_SEUs.find(seuid);
00182   if ( iter != m_SEUs.end() ) ((*iter).second)->reset(relAdr);
00183 
00184 }
00185 
00186 
00187 //
00188 // get extrapolation address from ERS
00189 //
00190 unsigned short int L1MuDTExtrapolationUnit::getAddress(Extrapolation ext, unsigned int startAdr, int id) const {
00191 
00192   // get extrapolation address from ERS 
00193   // startAdr = 0, 1  : own wheel
00194   // startAdr = 2, 3  : next wheel neighbour
00195 
00196   //  assert( startAdr >= 0 && startAdr <= 3 );
00197   //  assert( id == 0 || id == 1 );
00198   
00199   unsigned short int address = 15;
00200   
00201   SEUId seuid = make_pair(ext, startAdr);
00202   SEUmap::const_iterator iter = m_SEUs.find(seuid);
00203   if ( iter != m_SEUs.end() ) address = ((*iter).second)->ers()->address(id);
00204 
00205   return address;
00206 
00207 }
00208 
00209 
00210 //
00211 // get extrapolation quality from ERS
00212 //
00213 unsigned short int L1MuDTExtrapolationUnit::getQuality(Extrapolation ext, unsigned int startAdr, int id) const {
00214 
00215   // get extrapolation quality from ERS 
00216   // startAdr = 0, 1  : own wheel
00217   // startAdr = 2, 3  : next wheel neighbour
00218 
00219   //  assert( startAdr >= 0 && startAdr <= 3 );
00220   //  assert( id == 0 || id == 1 );
00221   
00222   unsigned short int quality = 0;
00223 
00224   SEUId seuid = make_pair(ext, startAdr);
00225   SEUmap::const_iterator iter = m_SEUs.find(seuid);
00226   if ( iter != m_SEUs.end() ) quality = ((*iter).second)->ers()->quality(id);
00227 
00228   return quality;
00229   
00230 }
00231 
00232 
00233 //
00234 // get Extrapolator table for a given SEU
00235 //
00236 const bitset<12>& L1MuDTExtrapolationUnit::getEXTable(Extrapolation ext, unsigned int startAdr) const {
00237 
00238   // startAdr = 0, 1  : own wheel
00239   // startAdr = 2, 3  : next wheel neighbour
00240 
00241   //  assert( startAdr >= 0 && startAdr <= 3 );
00242   
00243   SEUId seuid = make_pair(ext, startAdr);
00244   return m_SEUs[seuid]->exTable();
00245 
00246 }
00247 
00248 
00249 //
00250 // get Quality Sorter table for a given SEU
00251 //
00252 const bitset<12>& L1MuDTExtrapolationUnit::getQSTable(Extrapolation ext, unsigned int startAdr) const {
00253 
00254   // startAdr = 0, 1  : own wheel
00255   // startAdr = 2, 3  : next wheel neighbour
00256 
00257   //  assert( startAdr >= 0 && startAdr <= 3 );
00258   
00259   SEUId seuid = make_pair(ext, startAdr);
00260   return m_SEUs[seuid]->qsTable();
00261 
00262 }
00263 
00264 
00265 //
00266 // get number of successful extrapolations
00267 //
00268 int L1MuDTExtrapolationUnit::numberOfExt() const {
00269 
00270   int number = 0;
00271   SEUmap::const_iterator iter;
00272   for ( iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
00273     number += ((*iter).second)->numberOfExt();
00274   }
00275  
00276   return number;
00277 
00278 }
00279 
00280 
00281 //
00282 // print all successful extrapolations
00283 //
00284 void L1MuDTExtrapolationUnit::print(int level) const {
00285 
00286   SEUmap::const_iterator iter_seu;
00287 
00288   if ( level == 0 ) {
00289     for ( iter_seu = m_SEUs.begin(); iter_seu != m_SEUs.end(); iter_seu++ ) {
00290       vector<L1MuDTEUX*> vec_eux = ((*iter_seu).second)->eux();
00291       vector<L1MuDTEUX*>::const_iterator iter_eux;
00292       for ( iter_eux  = vec_eux.begin(); 
00293             iter_eux != vec_eux.end(); iter_eux++ ) {
00294         if ( (*iter_eux)->result() ) {
00295           cout << ((*iter_seu).second)->ext() << " "
00296                << ((*iter_seu).second)->tsId() << " " 
00297                << (*iter_eux)->id() << endl; 
00298           cout << "start  : " << *(*iter_eux)->ts().first << endl;
00299           cout << "target : " << *(*iter_eux)->ts().second << endl;
00300           cout << "result : " << "quality = " << (*iter_eux)->quality() << '\t' 
00301                               << "address = " << (*iter_eux)->address() << endl;
00302         }
00303       }
00304     }
00305   }
00306 
00307   //
00308   // print all results from Extrapolator and Quality Sorter
00309   //
00310   if ( level == 1 ) {
00311     cout << "Results from Extrapolator and Quality Sorter of " << m_sp.id()
00312          << " : \n" << endl;
00313 
00314     cout << "             EXT            QSU      " << endl;
00315     cout << "  S E U   11            11           " << endl;
00316     cout << "          109876543210  109876543210 " << endl;
00317     cout << "-------------------------------------" << endl;     
00318     for ( iter_seu = m_SEUs.begin(); iter_seu != m_SEUs.end(); iter_seu++ ) {
00319 
00320       cout << ((*iter_seu).second)->ext() << "_ "
00321            << ((*iter_seu).second)->tsId() << ": "
00322            << ((*iter_seu).second)->exTable() << "  "
00323            << ((*iter_seu).second)->qsTable() << endl; 
00324 
00325     }
00326   
00327     cout << endl;
00328   }
00329 
00330 }
00331 
00332 
00333 // static 
00334 
00335 //
00336 // get station of start and target track segment for a given extrapolation
00337 //
00338 pair<int,int> L1MuDTExtrapolationUnit::which_ext(Extrapolation ext) {
00339 
00340   int source = 0;
00341   int target = 0;
00342 
00343   //  assert( ext >= 0 && ext < MAX_EXT );
00344 
00345   switch ( ext ) {
00346     case EX12 : { source = 1; target = 2; break; }
00347     case EX13 : { source = 1; target = 3; break; }
00348     case EX14 : { source = 1; target = 4; break; }
00349     case EX21 : { source = 1; target = 2; break; }
00350     case EX23 : { source = 2; target = 3; break; }
00351     case EX24 : { source = 2; target = 4; break; }
00352     case EX34 : { source = 3; target = 4; break; }
00353     case EX15 : { source = 1; target = 3; break; }
00354     case EX25 : { source = 2; target = 3; break; }
00355     default : { source = 1; target = 2; break; }
00356   }
00357 
00358   return pair<int,int>(source,target);
00359 
00360 }