Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:50

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