Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:56:25

0001 #include "L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h"
0002 #include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h"
0003 #include "L1Trigger/TrackFindingTracklet/interface/Settings.h"
0004 
0005 using namespace std;
0006 using namespace trklet;
0007 
0008 MatchEngineUnit::MatchEngineUnit(const Settings& settings,
0009                                  bool barrel,
0010                                  unsigned int layerdisk,
0011                                  const TrackletLUT& luttable)
0012     : settings_(settings), luttable_(luttable), candmatches_(3) {
0013   idle_ = true;
0014   print_ = false;
0015   imeu_ = -1;
0016   barrel_ = barrel;
0017   layerdisk_ = layerdisk;
0018   good__ = false;
0019   good__t = false;
0020   good___ = false;
0021 }
0022 
0023 void MatchEngineUnit::setAlmostFull() { almostfullsave_ = candmatches_.nearfull(); }
0024 
0025 void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory,
0026                            unsigned int nrzbins,
0027                            unsigned int rzbin,
0028                            unsigned int phibin,
0029                            int shift,
0030                            int projrinv,
0031                            int projfinerz,
0032                            int projfinephi,
0033                            bool usefirstMinus,
0034                            bool usefirstPlus,
0035                            bool usesecondMinus,
0036                            bool usesecondPlus,
0037                            bool isPSseed,
0038                            Tracklet* proj) {
0039   vmstubsmemory_ = vmstubsmemory;
0040   idle_ = false;
0041   nrzbins_ = nrzbins;
0042   rzbin_ = rzbin;
0043   phibin_ = phibin;
0044   shift_ = shift;
0045   istub_ = 0;
0046   iuse_ = 0;
0047   projrinv_ = projrinv;
0048   projfinerz_ = projfinerz;
0049   projfinephi_ = projfinephi;
0050   use_.clear();
0051   if (usefirstMinus) {
0052     use_.emplace_back(0, 0);
0053   }
0054   if (usesecondMinus) {
0055     use_.emplace_back(1, 0);
0056   }
0057   if (usefirstPlus) {
0058     use_.emplace_back(0, 1);
0059   }
0060   if (usesecondPlus) {
0061     use_.emplace_back(1, 1);
0062   }
0063   assert(!use_.empty());
0064   isPSseed_ = isPSseed;
0065   proj_ = proj;
0066 
0067   good__ = false;
0068 }
0069 
0070 void MatchEngineUnit::step() {
0071   good__ = !idle() && !almostfullsave_;
0072 
0073   if (!good__)
0074     return;
0075 
0076   unsigned int slot = (phibin_ + use_[iuse_].second) * nrzbins_ + rzbin_ + use_[iuse_].first;
0077 
0078   projfinerz__ = projfinerz_ - (1 << NFINERZBITS) * use_[iuse_].first;
0079   projfinephi__ = projfinephi_;
0080   if (use_[iuse_].second == 0) {
0081     if (shift_ == -1) {
0082       projfinephi__ -= (1 << NFINEPHIBITS);
0083     }
0084   } else {
0085     //When we get here shift_ is either 1 or -1
0086     if (shift_ == 1) {
0087       projfinephi__ += (1 << NFINEPHIBITS);
0088     }
0089   }
0090 
0091   vmstub__ = vmstubsmemory_->getVMStubMEBin(slot, istub_);
0092 
0093   isPSseed__ = isPSseed_;
0094   projrinv__ = projrinv_;
0095   proj__ = proj_;
0096 
0097   istub_++;
0098   if (istub_ >= vmstubsmemory_->nStubsBin(slot)) {
0099     iuse_++;
0100     if (iuse_ < use_.size()) {
0101       istub_ = 0;
0102     } else {
0103       idle_ = true;
0104     }
0105   }
0106 }
0107 
0108 void MatchEngineUnit::processPipeline() {
0109   if (good___) {
0110     bool isPSmodule = vmstub___.isPSmodule();
0111     int stubfinerz = vmstub___.finerz().value();
0112     int stubfinephi = vmstub___.finephi().value();
0113 
0114     int deltaphi = stubfinephi - projfinephi___;
0115 
0116     constexpr int idphicut = 3;
0117 
0118     bool dphicut = (abs(deltaphi) < idphicut);
0119 
0120     int nbits = isPSmodule ? N_BENDBITS_PS : N_BENDBITS_2S;
0121 
0122     int diskps = (!barrel_) && isPSmodule;
0123 
0124     //here we always use the larger number of bits for the bend
0125     unsigned int index = (diskps << (N_BENDBITS_2S + NRINVBITS)) + (projrinv___ << nbits) + vmstub___.bend().value();
0126 
0127     //Check if stub z position consistent
0128     int idrz = stubfinerz - projfinerz___;
0129     bool pass;
0130 
0131     if (barrel_) {
0132       if (isPSseed___) {
0133         constexpr int drzcut = 1;
0134         pass = std::abs(idrz) <= drzcut;
0135       } else {
0136         constexpr int drzcut = 5;
0137         pass = std::abs(idrz) <= drzcut;
0138       }
0139     } else {
0140       if (isPSmodule) {
0141         constexpr int drzcut = 1;
0142         pass = std::abs(idrz) <= drzcut;
0143       } else {
0144         constexpr int drzcut = 3;
0145         pass = std::abs(idrz) <= drzcut;
0146       }
0147     }
0148 
0149     bool goodpair = (pass && dphicut) && luttable_.lookup(index);
0150 
0151     std::pair<Tracklet*, const Stub*> tmppair(proj___, vmstub___.stub());
0152 
0153     if (goodpair) {
0154       candmatches_.store(tmppair);
0155     }
0156   }
0157 
0158   proj___ = proj__t;
0159   projfinephi___ = projfinephi__t;
0160   projfinerz___ = projfinerz__t;
0161   projrinv___ = projrinv__t;
0162   isPSseed___ = isPSseed__t;
0163   good___ = good__t;
0164   vmstub___ = vmstub__t;
0165 
0166   proj__t = proj__;
0167   projfinephi__t = projfinephi__;
0168   projfinerz__t = projfinerz__;
0169   projrinv__t = projrinv__;
0170   isPSseed__t = isPSseed__;
0171   good__t = good__;
0172   vmstub__t = vmstub__;
0173 }
0174 
0175 void MatchEngineUnit::reset() {
0176   candmatches_.reset();
0177   idle_ = true;
0178   istub_ = 0;
0179   good__ = false;
0180   good__t = false;
0181   good___ = false;
0182 }
0183 
0184 int MatchEngineUnit::TCID() const {
0185   if (!empty()) {
0186     return peek().first->TCID();
0187   }
0188 
0189   if (good___) {
0190     return proj___->TCID();
0191   }
0192 
0193   if (good__t) {
0194     return proj__t->TCID();
0195   }
0196 
0197   if (good__) {
0198     return proj__->TCID();
0199   }
0200 
0201   if (idle_) {
0202     return (1 << (settings_.nbitstrackletindex() + settings_.nbitstcindex())) - 1;
0203   }
0204 
0205   return proj_->TCID();
0206 }