CMS 3D CMS Logo

L1MuDTExtrapolationUnit.cc

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

Generated on Tue Jun 9 17:40:01 2009 for CMSSW by  doxygen 1.5.4