Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-16 06:15:52

0001 //-------------------------------------------------
0002 //
0003 //   Class: L1MuBMTrackFinder
0004 //
0005 //   Description: L1 barrel Muon Trigger Track Finder
0006 //
0007 //
0008 //
0009 //   Author :
0010 //   N. Neumeister            CERN EP
0011 //   J. Troconiz              UAM Madrid
0012 //   Modifications:
0013 //   G. Flouris               U.Ioannina
0014 //   G. Karathanasis          U. Athens
0015 //--------------------------------------------------
0016 
0017 //-----------------------
0018 // This Class's Header --
0019 //-----------------------
0020 
0021 #include "L1Trigger/L1TMuonBarrel/interface/L1MuBMTrackFinder.h"
0022 
0023 //---------------
0024 // C++ Headers --
0025 //---------------
0026 
0027 #include <iostream>
0028 #include <string>
0029 
0030 //-------------------------------
0031 // Collaborating Class Headers --
0032 //-------------------------------
0033 
0034 #include <DataFormats/Common/interface/Handle.h>
0035 #include <FWCore/Framework/interface/Event.h>
0036 
0037 #include "L1Trigger/L1TMuonBarrel/src/L1MuBMTFConfig.h"
0038 #include "L1Trigger/L1TMuonBarrel/src/L1MuBMSecProcMap.h"
0039 #include "L1Trigger/L1TMuonBarrel/src/L1MuBMSectorProcessor.h"
0040 #include "L1Trigger/L1TMuonBarrel/src/L1MuBMEtaProcessor.h"
0041 #include "L1Trigger/L1TMuonBarrel/src/L1MuBMWedgeSorter.h"
0042 #include "L1Trigger/L1TMuonBarrel/src/L1MuBMMuonSorter.h"
0043 
0044 #include "DataFormats/L1TMuon/interface/BMTF/L1MuBMSecProcId.h"
0045 #include "DataFormats/L1TMuon/interface/RegionalMuonCand.h"
0046 #include "DataFormats/L1TMuon/interface/L1MuBMTrack.h"
0047 #include "DataFormats/L1TMuon/interface/L1MuBMTrackSegPhi.h"
0048 #include "DataFormats/L1TMuon/interface/L1MuBMTrackSegEta.h"
0049 
0050 using namespace std;
0051 
0052 //---------------------------------
0053 //       class L1MuBMTrackFinder
0054 //---------------------------------
0055 
0056 //----------------
0057 // Constructors --
0058 //----------------
0059 //:
0060 L1MuBMTrackFinder::L1MuBMTrackFinder(const edm::ParameterSet& ps, edm::ConsumesCollector&& iC)
0061     : _cache0(144, -9, 8), _cache(36, -9, 8) {
0062   // set configuration parameters
0063   if (not m_config) {
0064     auto temp = std::make_shared<L1MuBMTFConfig>(ps);
0065     std::shared_ptr<L1MuBMTFConfig> empty;
0066     std::atomic_compare_exchange_strong(&m_config, &empty, temp);
0067   }
0068 
0069   if (L1MuBMTFConfig::Debug(1))
0070     cout << endl;
0071   if (L1MuBMTFConfig::Debug(1))
0072     cout << "**** entering L1MuBMTrackFinder ****" << endl;
0073   if (L1MuBMTFConfig::Debug(1))
0074     cout << endl;
0075 
0076   m_spmap = new L1MuBMSecProcMap();
0077   m_epvec.reserve(12);
0078   m_wsvec.reserve(12);
0079   m_ms = nullptr;
0080 
0081   m_DTDigiToken = iC.consumes<L1MuDTChambPhContainer>(L1MuBMTFConfig::getBMDigiInputTag());
0082   m_mbParamsToken = iC.esConsumes();
0083 }
0084 
0085 //--------------
0086 // Destructor --
0087 //--------------
0088 
0089 L1MuBMTrackFinder::~L1MuBMTrackFinder() {
0090   delete m_spmap;
0091 
0092   vector<L1MuBMEtaProcessor*>::iterator it_ep = m_epvec.begin();
0093   while (it_ep != m_epvec.end()) {
0094     delete (*it_ep);
0095     it_ep++;
0096   }
0097   m_epvec.clear();
0098 
0099   vector<L1MuBMWedgeSorter*>::iterator it_ws = m_wsvec.begin();
0100   while (it_ws != m_wsvec.end()) {
0101     delete (*it_ws);
0102     it_ws++;
0103   }
0104   m_wsvec.clear();
0105 
0106   delete m_ms;
0107 }
0108 
0109 //--------------
0110 // Operations --
0111 //--------------
0112 
0113 //
0114 // setup MTTF configuration
0115 //
0116 void L1MuBMTrackFinder::setup(edm::ConsumesCollector&& iC) {
0117   // build the barrel Muon Trigger Track Finder
0118 
0119   if (L1MuBMTFConfig::Debug(1))
0120     cout << endl;
0121   if (L1MuBMTFConfig::Debug(1))
0122     cout << "**** L1MuBMTrackFinder building ****" << endl;
0123   if (L1MuBMTFConfig::Debug(1))
0124     cout << endl;
0125 
0126   // create new sector processors
0127   for (int wh = -3; wh <= 3; wh++) {
0128     if (wh == 0)
0129       continue;
0130     for (int sc = 0; sc < 12; sc++) {
0131       L1MuBMSecProcId tmpspid(wh, sc);
0132       L1MuBMSectorProcessor* sp = new L1MuBMSectorProcessor(*this, tmpspid, std::move(iC));
0133       if (L1MuBMTFConfig::Debug(2))
0134         cout << "creating " << tmpspid << endl;
0135       m_spmap->insert(tmpspid, sp);
0136     }
0137   }
0138 
0139   // create new eta processors and wedge sorters
0140   for (int sc = 0; sc < 12; sc++) {
0141     L1MuBMEtaProcessor* ep = new L1MuBMEtaProcessor(*this, sc, std::move(iC));
0142     if (L1MuBMTFConfig::Debug(2))
0143       cout << "creating Eta Processor " << sc << endl;
0144     m_epvec.push_back(ep);
0145     L1MuBMWedgeSorter* ws = new L1MuBMWedgeSorter(*this, sc);
0146     if (L1MuBMTFConfig::Debug(2))
0147       cout << "creating Wedge Sorter " << sc << endl;
0148     m_wsvec.push_back(ws);
0149   }
0150 
0151   // create new muon sorter
0152   if (L1MuBMTFConfig::Debug(2))
0153     cout << "creating BM Muon Sorter " << endl;
0154   m_ms = new L1MuBMMuonSorter(*this);
0155 }
0156 
0157 //
0158 // run MTTF
0159 //
0160 void L1MuBMTrackFinder::run(const edm::Event& e, const edm::EventSetup& c) {
0161   m_config->setDefaultsES(c.getData(m_mbParamsToken));
0162   int bx_min = L1MuBMTFConfig::getBxMin();
0163   int bx_max = L1MuBMTFConfig::getBxMax();
0164 
0165   //Resize the bx range according to the config file
0166   _cache0.setBXRange(bx_min, bx_max);
0167   _cache.setBXRange(bx_min, bx_max);
0168 
0169   // run the barrel Muon Trigger Track Finder
0170   edm::Handle<L1MuDTChambPhContainer> dttrig;
0171   e.getByToken(m_DTDigiToken, dttrig);
0172   if (dttrig->getContainer()->empty())
0173     return;
0174 
0175   if (L1MuBMTFConfig::Debug(2))
0176     cout << endl;
0177   if (L1MuBMTFConfig::Debug(2))
0178     cout << "**** L1MuBMTrackFinder processing ------****" << endl;
0179   if (L1MuBMTFConfig::Debug(2))
0180     cout << endl;
0181 
0182   for (int bx = bx_min; bx <= bx_max; bx++) {
0183     if (dttrig->bxEmpty(bx))
0184       continue;
0185 
0186     if (L1MuBMTFConfig::Debug(2))
0187       cout << "L1MuBMTrackFinder processing bunch-crossing : " << bx << endl;
0188 
0189     // reset MTTF
0190     reset();
0191 
0192     // run sector processors
0193     L1MuBMSecProcMap::SPmap_iter it_sp = m_spmap->begin();
0194     while (it_sp != m_spmap->end()) {
0195       if (L1MuBMTFConfig::Debug(2))
0196         cout << "running " << (*it_sp).second->id() << endl;
0197       if ((*it_sp).second)
0198         (*it_sp).second->run(bx, e, c);
0199       if (L1MuBMTFConfig::Debug(2) && (*it_sp).second)
0200         (*it_sp).second->print();
0201       it_sp++;
0202     }
0203 
0204     // run eta processors
0205     vector<L1MuBMEtaProcessor*>::iterator it_ep = m_epvec.begin();
0206     while (it_ep != m_epvec.end()) {
0207       if (L1MuBMTFConfig::Debug(2))
0208         cout << "running Eta Processor " << (*it_ep)->id() << endl;
0209       if (*it_ep)
0210         (*it_ep)->run(bx, e, c);
0211       if (L1MuBMTFConfig::Debug(2) && *it_ep)
0212         (*it_ep)->print();
0213       it_ep++;
0214     }
0215 
0216     // read sector processors
0217     it_sp = m_spmap->begin();
0218     while (it_sp != m_spmap->end()) {
0219       if (L1MuBMTFConfig::Debug(2))
0220         cout << "reading " << (*it_sp).second->id() << endl;
0221       for (int number = 0; number < 2; number++) {
0222         const L1MuBMTrack* cand = (*it_sp).second->tracK(number);
0223 
0224         if (cand && !cand->empty()) {
0225           l1t::RegionalMuonCand rmc;
0226 
0227           // max value in LUTs is 117
0228           if (cand->hwEta() > -117 || cand->hwEta() < 117)
0229             rmc.setHwEta(cand->hwEta());
0230           else
0231             rmc.setHwEta(-1000);
0232 
0233           rmc.setHwPt(cand->pt());
0234           int abs_add_1 = setAdd(1, cand->address(1));
0235           int abs_add_2 = setAdd(2, cand->address(2));
0236           int abs_add_3 = setAdd(3, cand->address(3));
0237           int abs_add_4 = setAdd(4, cand->address(4));
0238 
0239           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelSide, cand->spid().wheel() < 0);  // this has to be set!
0240           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelNum,
0241                                  abs(cand->spid().wheel()) - 1);  // this has to be set!
0242           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat1, abs_add_1);
0243           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat2, abs_add_2);
0244           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat3, abs_add_3);
0245           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat4, abs_add_4);
0246           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat1, 0);
0247           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat2, 0);
0248           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat3, 0);
0249           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat4, 0);
0250           rmc.setHwHF(cand->hwHF());
0251 
0252           rmc.setHwPhi(cand->hwPhi());
0253           rmc.setHwSign(cand->hwSign() == 1 ? 0 : 1);
0254           rmc.setHwSignValid(cand->hwSignValid());
0255           rmc.setHwQual(cand->hwQual());
0256           rmc.setTFIdentifiers(cand->spid().sector(), l1t::tftype::bmtf);
0257 
0258           _cache0.push_back(cand->bx(), rmc);
0259           _cache2.insert(std::end(_cache2), std::begin(cand->getTSphi()), std::end(cand->getTSphi()));
0260           _cache3.insert(std::end(_cache3), std::begin(cand->getTSeta()), std::end(cand->getTSeta()));
0261         }
0262       }
0263       it_sp++;
0264     }
0265 
0266     // run wedge sorters
0267     vector<L1MuBMWedgeSorter*>::iterator it_ws = m_wsvec.begin();
0268     while (it_ws != m_wsvec.end()) {
0269       if (L1MuBMTFConfig::Debug(2))
0270         cout << "running Wedge Sorter " << (*it_ws)->id() << endl;
0271       if (*it_ws)
0272         (*it_ws)->run();
0273       if (L1MuBMTFConfig::Debug(2) && *it_ws)
0274         (*it_ws)->print();
0275 
0276       // store found track candidates in container (cache)
0277       if ((*it_ws)->anyMuonCands()) {
0278         const vector<const L1MuBMTrack*>& mttf_cont = (*it_ws)->tracks();
0279 
0280         vector<const L1MuBMTrack*>::const_iterator iter;
0281         for (iter = mttf_cont.begin(); iter != mttf_cont.end(); iter++) {
0282           if (!*iter)
0283             continue;
0284           l1t::RegionalMuonCand rmc;
0285           rmc.setHwPt((*iter)->hwPt());
0286           int abs_add_1 = setAdd(1, (*iter)->address(1));
0287           int abs_add_2 = setAdd(2, (*iter)->address(2));
0288           int abs_add_3 = setAdd(3, (*iter)->address(3));
0289           int abs_add_4 = setAdd(4, (*iter)->address(4));
0290 
0291           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelSide,
0292                                  (*iter)->spid().wheel() < 0);  // this has to be set!
0293           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelNum,
0294                                  abs((*iter)->spid().wheel()) - 1);  // this has to be set!
0295           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat1, abs_add_1);
0296           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat2, abs_add_2);
0297           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat3, abs_add_3);
0298           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat4, abs_add_4);
0299           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat1, 0);
0300           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat2, 0);
0301           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat3, 0);
0302           rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat4, 0);
0303           rmc.setHwHF((*iter)->hwHF());
0304 
0305           rmc.setHwPhi((*iter)->hwPhi());
0306           if ((*iter)->hwEta() > -117 || (*iter)->hwEta() < 117)
0307             //  rmc.setHwEta(eta_map[(*iter)->hwEta()]);
0308             rmc.setHwEta((*iter)->hwEta());
0309           else
0310             rmc.setHwEta(-1000);
0311           rmc.setHwSign((*iter)->hwSign() == 1 ? 0 : 1);
0312           rmc.setHwSignValid((*iter)->hwSignValid());
0313           rmc.setHwQual((*iter)->hwQual());
0314           rmc.setTFIdentifiers((*iter)->spid().sector(), l1t::tftype::bmtf);
0315 
0316           if (*iter) {
0317             _cache.push_back((*iter)->bx(), rmc);
0318             _cache1.push_back(**iter);
0319           }
0320         }
0321       }
0322 
0323       it_ws++;
0324 
0325     }  //end wedge sorting
0326 
0327     /*    // run muon sorter
0328     if ( L1MuBMTFConfig::Debug(2) ) cout << "running BM Muon Sorter" << endl;
0329     if ( m_ms ) m_ms->run();
0330     if ( L1MuBMTFConfig::Debug(2) && m_ms ) m_ms->print();
0331 
0332 
0333     // store found track candidates in container (cache)
0334     if ( m_ms->numberOfTracks() > 0 ) {
0335       const vector<const L1MuBMTrack*>&  mttf_cont = m_ms->tracks();
0336       vector<const L1MuBMTrack*>::const_iterator iter;
0337       for ( iter = mttf_cont.begin(); iter != mttf_cont.end(); iter++ ) {
0338 
0339         l1t::RegionalMuonCand rmc;
0340         rmc.setHwPt((*iter)->hwPt());
0341         int abs_add_1 = setAdd(1,(*iter)->address(1));
0342         int abs_add_2 = setAdd(2,(*iter)->address(2));
0343         int abs_add_3 = setAdd(3,(*iter)->address(3));
0344         int abs_add_4 = setAdd(4,(*iter)->address(4));
0345 
0346         rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelSide, (*iter)->spid().wheel() < 0); // this has to be set!
0347         rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelNum, abs((*iter)->spid().wheel()) - 1); // this has to be set!
0348         rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat1, abs_add_1);
0349         rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat2, abs_add_2);
0350         rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat3, abs_add_3);
0351         rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat4, abs_add_4);
0352         rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat1, 0);
0353         rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat2, 0);
0354         rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat3, 0);
0355         rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat4, 0);
0356 
0357 
0358         rmc.setHwPhi((*iter)->hwPhi());
0359         if((*iter)->hwEta()>-33 || (*iter)->hwEta()<32 )
0360                 rmc.setHwEta(eta_map[(*iter)->hwEta()]);
0361         else
0362             rmc.setHwEta(-1000);
0363         rmc.setHwSign((*iter)->hwSign() == 1 ? 0 : 1);
0364         rmc.setHwSignValid((*iter)->hwSignValid());
0365         rmc.setHwQual((*iter)->hwQual());
0366         rmc.setTFIdentifiers((*iter)->spid().sector(),l1t::tftype::bmtf);
0367 
0368         if ( *iter ){ _cache.push_back((*iter)->bx(), rmc);}
0369      }
0370     }
0371     */
0372 
0373   }  //end of bx loop
0374 }
0375 
0376 //
0377 // reset MTTF
0378 //
0379 void L1MuBMTrackFinder::reset() {
0380   L1MuBMSecProcMap::SPmap_iter it_sp = m_spmap->begin();
0381   while (it_sp != m_spmap->end()) {
0382     if ((*it_sp).second)
0383       (*it_sp).second->reset();
0384     it_sp++;
0385   }
0386 
0387   vector<L1MuBMEtaProcessor*>::iterator it_ep = m_epvec.begin();
0388   while (it_ep != m_epvec.end()) {
0389     if (*it_ep)
0390       (*it_ep)->reset();
0391     it_ep++;
0392   }
0393 
0394   vector<L1MuBMWedgeSorter*>::iterator it_ws = m_wsvec.begin();
0395   while (it_ws != m_wsvec.end()) {
0396     if (*it_ws)
0397       (*it_ws)->reset();
0398     it_ws++;
0399   }
0400 
0401   if (m_ms)
0402     m_ms->reset();
0403 }
0404 
0405 //
0406 // return Sector Processor container
0407 //
0408 const L1MuBMSectorProcessor* L1MuBMTrackFinder::sp(const L1MuBMSecProcId& id) const { return m_spmap->sp(id); }
0409 
0410 //
0411 // return number of muon candidates found by the barrel MTTF
0412 //
0413 int L1MuBMTrackFinder::numberOfTracks() {
0414   int num = 0;
0415   for (int bx = _cache.getFirstBX(); bx < _cache.getLastBX(); ++bx) {
0416     num += _cache.size(bx);
0417   }
0418   return num;
0419 }
0420 
0421 L1MuBMTrackFinder::TFtracks_const_iter L1MuBMTrackFinder::begin(int bx) { return _cache.begin(bx); }
0422 
0423 L1MuBMTrackFinder::TFtracks_const_iter L1MuBMTrackFinder::end(int bx) { return _cache.end(bx); }
0424 
0425 void L1MuBMTrackFinder::clear() {
0426   _cache.clear();
0427   _cache0.clear();
0428   _cache1.clear();
0429   _cache2.clear();
0430   _cache3.clear();
0431 }
0432 
0433 //
0434 // return number of muon candidates found by the barrel MTTF at a given bx
0435 //
0436 int L1MuBMTrackFinder::numberOfTracks(int bx) { return _cache.size(0); }
0437 
0438 //
0439 // Convert Relative to Absolute Track Addresses
0440 //
0441 
0442 int L1MuBMTrackFinder::setAdd(int ust, int rel_add) {
0443   unsigned int uadd = rel_add;
0444 
0445   switch (uadd) {
0446     case 0: {
0447       rel_add = 8;
0448       break;
0449     }
0450     case 1: {
0451       rel_add = 9;
0452       break;
0453     }
0454     case 2: {
0455       rel_add = 0;
0456       break;
0457     }
0458     case 3: {
0459       rel_add = 1;
0460       break;
0461     }
0462     case 8: {
0463       rel_add = 10;
0464       break;
0465     }
0466     case 9: {
0467       rel_add = 11;
0468       break;
0469     }
0470     case 10: {
0471       rel_add = 2;
0472       break;
0473     }
0474     case 11: {
0475       rel_add = 3;
0476       break;
0477     }
0478     case 4: {
0479       rel_add = 12;
0480       break;
0481     }
0482     case 5: {
0483       rel_add = 13;
0484       break;
0485     }
0486     case 6: {
0487       rel_add = 4;
0488       break;
0489     }
0490     case 7: {
0491       rel_add = 5;
0492       break;
0493     }
0494     case 15: {
0495       rel_add = 15;
0496       break;
0497     }
0498     default: {
0499       rel_add = 15;
0500       break;
0501     }
0502   }
0503 
0504   if (ust != 1)
0505     return rel_add;
0506 
0507   switch (uadd) {
0508     case 0: {
0509       rel_add = 2;
0510       break;
0511     }
0512     case 1: {
0513       rel_add = 1;
0514       break;
0515     }
0516     case 15: {
0517       rel_add = 3;
0518       break;
0519     }
0520     default: {
0521       rel_add = 3;
0522       break;
0523     }
0524   }
0525   return rel_add;
0526 }
0527 
0528 // static data members
0529 
0530 std::shared_ptr<L1MuBMTFConfig> L1MuBMTrackFinder::m_config;