Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-28 23:48:40

0001 //-------------------------------------------------
0002 //
0003 //   Class: L1MuDTExtrapolationUnit
0004 //
0005 //   Description: Extrapolation Unit
0006 //
0007 //
0008 //
0009 //   Author :
0010 //   N. Neumeister            CERN EP
0011 //
0012 //--------------------------------------------------
0013 
0014 //-----------------------
0015 // This Class's Header --
0016 //-----------------------
0017 
0018 #include "L1Trigger/DTTrackFinder/src/L1MuDTExtrapolationUnit.h"
0019 
0020 //---------------
0021 // C++ Headers --
0022 //---------------
0023 
0024 #include <iostream>
0025 #include <bitset>
0026 #include <cassert>
0027 
0028 //-------------------------------
0029 // Collaborating Class Headers --
0030 //-------------------------------
0031 
0032 #include "L1Trigger/DTTrackFinder/interface/L1MuDTTFConfig.h"
0033 #include "L1Trigger/DTTrackFinder/interface/L1MuDTTrackFinder.h"
0034 #include "CondFormats/L1TObjects/interface/L1MuDTExtParam.h"
0035 #include "L1Trigger/DTTrackFinder/src/L1MuDTSEU.h"
0036 #include "L1Trigger/DTTrackFinder/src/L1MuDTEUX.h"
0037 #include "L1Trigger/DTTrackFinder/src/L1MuDTERS.h"
0038 #include "L1Trigger/DTTrackFinder/src/L1MuDTSectorProcessor.h"
0039 #include "L1Trigger/DTTrackFinder/interface/L1MuDTSecProcId.h"
0040 #include "L1Trigger/DTTrackFinder/src/L1MuDTDataBuffer.h"
0041 #include "L1Trigger/DTTrackFinder/interface/L1MuDTTrackSegPhi.h"
0042 #include "CondFormats/L1TObjects/interface/L1MuDTTFParameters.h"
0043 #include "CondFormats/DataRecord/interface/L1MuDTTFParametersRcd.h"
0044 #include "CondFormats/DataRecord/interface/L1MuDTExtLutRcd.h"
0045 
0046 using namespace std;
0047 
0048 // --------------------------------
0049 //       class L1MuDTExtrapolationUnit
0050 //---------------------------------
0051 
0052 //----------------
0053 // Constructors --
0054 //----------------
0055 
0056 L1MuDTExtrapolationUnit::L1MuDTExtrapolationUnit(const L1MuDTSectorProcessor& sp, edm::ConsumesCollector iC)
0057     : m_sp(sp), m_SEUs(), m_parsToken(iC.esConsumes()), m_extLUTsToken(iC.esConsumes()) {
0058   for (int ext_idx = 0; ext_idx < MAX_EXT; ext_idx++) {
0059     Extrapolation ext = static_cast<Extrapolation>(ext_idx);
0060 
0061     if (ext == EX12 || ext == EX13 || ext == EX14 || ext == EX21 || ext == EX23 || ext == EX24 || ext == EX34) {
0062       unsigned int maxaddr = 4;
0063 
0064       if (ext == EX12 || ext == EX13 || ext == EX14)
0065         maxaddr = 2;
0066 
0067       for (unsigned int startAddress = 0; startAddress < maxaddr; startAddress++) {
0068         SEUId id = make_pair(ext, startAddress);
0069         m_SEUs[id] = new L1MuDTSEU(sp, ext, startAddress);
0070         if (L1MuDTTFConfig::Debug(6))
0071           cout << "  creating SEU " << ext << " " << startAddress << endl;
0072       }
0073     }
0074   }
0075 }
0076 
0077 //--------------
0078 // Destructor --
0079 //--------------
0080 
0081 L1MuDTExtrapolationUnit::~L1MuDTExtrapolationUnit() {
0082   for (SEUmap::iterator iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++) {
0083     delete (*iter).second;
0084     (*iter).second = nullptr;
0085   }
0086   m_SEUs.clear();
0087 }
0088 
0089 //--------------
0090 // Operations --
0091 //--------------
0092 
0093 //
0094 // run Extrapolation Unit
0095 //
0096 void L1MuDTExtrapolationUnit::run(const edm::EventSetup& c) {
0097   auto const& pars = c.getData(m_parsToken);
0098 
0099   L1MuDTExtLut const& extLUTs = c.getData(m_extLUTsToken);
0100 
0101   SEUmap::const_iterator iter;
0102   for (iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++) {
0103     pair<int, int> ext_pair = which_ext(((*iter).second)->ext());
0104     int start = ext_pair.first;
0105 
0106     const L1MuDTTrackSegPhi* ts = nullptr;
0107 
0108     //get start track segment
0109     ts = m_sp.data()->getTSphi(start, ((*iter).second)->tsId());
0110 
0111     if (ts != nullptr && !ts->empty()) {
0112       ((*iter).second)->load(ts);
0113       ((*iter).second)->run(extLUTs, pars);
0114     }
0115   }
0116 
0117   //
0118   // use EX21 to cross-check EX12
0119   //
0120   bool run_21 = pars.get_soc_run_21(m_sp.id().wheel(), m_sp.id().sector());
0121   if (m_sp.tf().config()->getUseEX21() || run_21) {
0122     // search for EX12 + EX21 single extrapolation units
0123     for (unsigned int startAdr = 0; startAdr < 2; startAdr++) {
0124       bitset<12> extab12 = this->getEXTable(EX12, startAdr);
0125       bitset<12> extab21 = this->getEXTable(EX21, startAdr);
0126 
0127       for (int eux = 0; eux < 12; eux++) {
0128         if (extab12.test(eux) && !extab21.test(eux)) {
0129           reset(EX12, startAdr, eux);
0130           if (L1MuDTTFConfig::Debug(6)) {
0131             SEUId seuid = make_pair(EX12, startAdr);
0132             L1MuDTSEU* SEU12 = m_SEUs[seuid];
0133             cout << "  EX12 - EX21 mismatch : "
0134                  << " EX12 : " << extab12 << " , "
0135                  << " EX21 : " << extab21 << endl
0136                  << "  Cancel: " << SEU12->ext() << " start addr = " << SEU12->tsId() << " target addr = " << eux
0137                  << endl;
0138           }
0139         }
0140       }
0141     }
0142   }
0143 }
0144 
0145 //
0146 // reset Extrapolation Unit
0147 //
0148 void L1MuDTExtrapolationUnit::reset() {
0149   SEUmap::const_iterator iter;
0150   for (iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++) {
0151     ((*iter).second)->reset();
0152   }
0153 }
0154 
0155 //
0156 // reset a single extrapolation
0157 //
0158 void L1MuDTExtrapolationUnit::reset(Extrapolation ext, unsigned int startAdr, unsigned int relAdr) {
0159   //  assert( startAdr >= 0 && startAdr <= 3 );
0160   //  assert( relAdr >= 0 && relAdr <= 12 );
0161 
0162   SEUId seuid = make_pair(ext, startAdr);
0163   SEUmap::const_iterator iter = m_SEUs.find(seuid);
0164   if (iter != m_SEUs.end())
0165     ((*iter).second)->reset(relAdr);
0166 }
0167 
0168 //
0169 // get extrapolation address from ERS
0170 //
0171 unsigned short int L1MuDTExtrapolationUnit::getAddress(Extrapolation ext, unsigned int startAdr, int id) const {
0172   // get extrapolation address from ERS
0173   // startAdr = 0, 1  : own wheel
0174   // startAdr = 2, 3  : next wheel neighbour
0175 
0176   //  assert( startAdr >= 0 && startAdr <= 3 );
0177   //  assert( id == 0 || id == 1 );
0178 
0179   unsigned short int address = 15;
0180 
0181   SEUId seuid = make_pair(ext, startAdr);
0182   SEUmap::const_iterator iter = m_SEUs.find(seuid);
0183   if (iter != m_SEUs.end())
0184     address = ((*iter).second)->ers()->address(id);
0185 
0186   return address;
0187 }
0188 
0189 //
0190 // get extrapolation quality from ERS
0191 //
0192 unsigned short int L1MuDTExtrapolationUnit::getQuality(Extrapolation ext, unsigned int startAdr, int id) const {
0193   // get extrapolation quality from ERS
0194   // startAdr = 0, 1  : own wheel
0195   // startAdr = 2, 3  : next wheel neighbour
0196 
0197   //  assert( startAdr >= 0 && startAdr <= 3 );
0198   //  assert( id == 0 || id == 1 );
0199 
0200   unsigned short int quality = 0;
0201 
0202   SEUId seuid = make_pair(ext, startAdr);
0203   SEUmap::const_iterator iter = m_SEUs.find(seuid);
0204   if (iter != m_SEUs.end())
0205     quality = ((*iter).second)->ers()->quality(id);
0206 
0207   return quality;
0208 }
0209 
0210 //
0211 // get Extrapolator table for a given SEU
0212 //
0213 const bitset<12>& L1MuDTExtrapolationUnit::getEXTable(Extrapolation ext, unsigned int startAdr) const {
0214   // startAdr = 0, 1  : own wheel
0215   // startAdr = 2, 3  : next wheel neighbour
0216 
0217   //  assert( startAdr >= 0 && startAdr <= 3 );
0218 
0219   SEUId seuid = make_pair(ext, startAdr);
0220   return m_SEUs.find(seuid)->second->exTable();
0221 }
0222 
0223 //
0224 // get Quality Sorter table for a given SEU
0225 //
0226 const bitset<12>& L1MuDTExtrapolationUnit::getQSTable(Extrapolation ext, unsigned int startAdr) const {
0227   // startAdr = 0, 1  : own wheel
0228   // startAdr = 2, 3  : next wheel neighbour
0229 
0230   //  assert( startAdr >= 0 && startAdr <= 3 );
0231 
0232   SEUId seuid = make_pair(ext, startAdr);
0233   return m_SEUs.find(seuid)->second->qsTable();
0234 }
0235 
0236 //
0237 // get number of successful extrapolations
0238 //
0239 int L1MuDTExtrapolationUnit::numberOfExt() const {
0240   int number = 0;
0241   SEUmap::const_iterator iter;
0242   for (iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++) {
0243     number += ((*iter).second)->numberOfExt();
0244   }
0245 
0246   return number;
0247 }
0248 
0249 //
0250 // print all successful extrapolations
0251 //
0252 void L1MuDTExtrapolationUnit::print(int level) const {
0253   SEUmap::const_iterator iter_seu;
0254 
0255   if (level == 0) {
0256     for (iter_seu = m_SEUs.begin(); iter_seu != m_SEUs.end(); iter_seu++) {
0257       vector<L1MuDTEUX*> vec_eux = ((*iter_seu).second)->eux();
0258       vector<L1MuDTEUX*>::const_iterator iter_eux;
0259       for (iter_eux = vec_eux.begin(); iter_eux != vec_eux.end(); iter_eux++) {
0260         if ((*iter_eux)->result()) {
0261           cout << ((*iter_seu).second)->ext() << " " << ((*iter_seu).second)->tsId() << " " << (*iter_eux)->id()
0262                << endl;
0263           cout << "start  : " << *(*iter_eux)->ts().first << endl;
0264           cout << "target : " << *(*iter_eux)->ts().second << endl;
0265           cout << "result : "
0266                << "quality = " << (*iter_eux)->quality() << '\t' << "address = " << (*iter_eux)->address() << endl;
0267         }
0268       }
0269     }
0270   }
0271 
0272   //
0273   // print all results from Extrapolator and Quality Sorter
0274   //
0275   if (level == 1) {
0276     cout << "Results from Extrapolator and Quality Sorter of " << m_sp.id() << " : \n" << endl;
0277 
0278     cout << "             EXT            QSU      " << endl;
0279     cout << "  S E U   11            11           " << endl;
0280     cout << "          109876543210  109876543210 " << endl;
0281     cout << "-------------------------------------" << endl;
0282     for (iter_seu = m_SEUs.begin(); iter_seu != m_SEUs.end(); iter_seu++) {
0283       cout << ((*iter_seu).second)->ext() << "_ " << ((*iter_seu).second)->tsId() << ": "
0284            << ((*iter_seu).second)->exTable() << "  " << ((*iter_seu).second)->qsTable() << endl;
0285     }
0286 
0287     cout << endl;
0288   }
0289 }
0290 
0291 // static
0292 
0293 //
0294 // get station of start and target track segment for a given extrapolation
0295 //
0296 pair<int, int> L1MuDTExtrapolationUnit::which_ext(Extrapolation ext) {
0297   int source = 0;
0298   int target = 0;
0299 
0300   //  assert( ext >= 0 && ext < MAX_EXT );
0301 
0302   switch (ext) {
0303     case EX12: {
0304       source = 1;
0305       target = 2;
0306       break;
0307     }
0308     case EX13: {
0309       source = 1;
0310       target = 3;
0311       break;
0312     }
0313     case EX14: {
0314       source = 1;
0315       target = 4;
0316       break;
0317     }
0318     case EX21: {
0319       source = 1;
0320       target = 2;
0321       break;
0322     }
0323     case EX23: {
0324       source = 2;
0325       target = 3;
0326       break;
0327     }
0328     case EX24: {
0329       source = 2;
0330       target = 4;
0331       break;
0332     }
0333     case EX34: {
0334       source = 3;
0335       target = 4;
0336       break;
0337     }
0338     case EX15: {
0339       source = 1;
0340       target = 3;
0341       break;
0342     }
0343     case EX25: {
0344       source = 2;
0345       target = 3;
0346       break;
0347     }
0348     default: {
0349       source = 1;
0350       target = 2;
0351       break;
0352     }
0353   }
0354 
0355   return pair<int, int>(source, target);
0356 }