Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-15 23:40:41

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