Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-07 22:33:32

0001 #include "L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h"
0002 #include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h"
0003 
0004 using namespace std;
0005 using namespace trklet;
0006 
0007 MatchEngineUnit::MatchEngineUnit(bool barrel, unsigned int layerdisk, const TrackletLUT& luttable)
0008     : luttable_(luttable), candmatches_(3) {
0009   idle_ = true;
0010   barrel_ = barrel;
0011   layerdisk_ = layerdisk;
0012   goodpair_ = false;
0013   goodpair__ = false;
0014   havepair_ = false;
0015   havepair__ = false;
0016 }
0017 
0018 void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory,
0019                            unsigned int nrzbins,
0020                            unsigned int rzbin,
0021                            unsigned int phibin,
0022                            int shift,
0023                            int projrinv,
0024                            int projfinerz,
0025                            int projfinephi,
0026                            bool usefirstMinus,
0027                            bool usefirstPlus,
0028                            bool usesecondMinus,
0029                            bool usesecondPlus,
0030                            bool isPSseed,
0031                            Tracklet* proj,
0032                            bool) {
0033   vmstubsmemory_ = vmstubsmemory;
0034   idle_ = false;
0035   nrzbins_ = nrzbins;
0036   rzbin_ = rzbin;
0037   phibin_ = phibin;
0038   shift_ = shift;
0039   istub_ = 0;
0040   iuse_ = 0;
0041   projrinv_ = projrinv;
0042   projfinerz_ = projfinerz;
0043   projfinephi_ = projfinephi;
0044   use_.clear();
0045   if (usefirstMinus) {
0046     use_.emplace_back(0, 0);
0047   }
0048   if (usesecondMinus) {
0049     use_.emplace_back(1, 0);
0050   }
0051   if (usefirstPlus) {
0052     use_.emplace_back(0, 1);
0053   }
0054   if (usesecondPlus) {
0055     use_.emplace_back(1, 1);
0056   }
0057   assert(!use_.empty());
0058   isPSseed_ = isPSseed;
0059   proj_ = proj;
0060 
0061   //Even when you init a new projection you need to process the pipeline
0062   //This should be fixed to be done more cleanly - but require synchronizaton
0063   //with the HLS code
0064   if (goodpair__) {
0065     candmatches_.store(tmppair__);
0066   }
0067 
0068   havepair__ = havepair_;
0069   goodpair__ = goodpair_;
0070   tmppair__ = tmppair_;
0071 
0072   havepair_ = false;
0073   goodpair_ = false;
0074 }
0075 
0076 void MatchEngineUnit::step(bool) {
0077   bool almostfull = candmatches_.nearfull();
0078 
0079   if (goodpair__) {
0080     assert(havepair__);
0081     candmatches_.store(tmppair__);
0082   }
0083 
0084   havepair__ = havepair_;
0085   goodpair__ = goodpair_;
0086   tmppair__ = tmppair_;
0087 
0088   havepair_ = false;
0089   goodpair_ = false;
0090 
0091   if (idle() || almostfull)
0092     return;
0093 
0094   unsigned int slot = (phibin_ + use_[iuse_].second) * nrzbins_ + rzbin_ + use_[iuse_].first;
0095 
0096   int projfinerz = projfinerz_ - (1 << NFINERZBITS) * use_[iuse_].first;
0097   int projfinephi = projfinephi_;
0098   if (use_[iuse_].second == 0) {
0099     if (shift_ == -1) {
0100       projfinephi -= (1 << NFINEPHIBITS);
0101     }
0102   } else {
0103     //When we get here shift_ is either 1 or -1
0104     if (shift_ == 1) {
0105       projfinephi += (1 << NFINEPHIBITS);
0106     }
0107   }
0108 
0109   const VMStubME& vmstub = vmstubsmemory_->getVMStubMEBin(slot, istub_);
0110 
0111   bool isPSmodule = vmstub.isPSmodule();
0112   int stubfinerz = vmstub.finerz().value();
0113   int stubfinephi = vmstub.finephi().value();
0114 
0115   int deltaphi = stubfinephi - projfinephi;
0116 
0117   bool dphicut = (abs(deltaphi) < 3);
0118 
0119   int nbits = isPSmodule ? 3 : 4;
0120 
0121   int diskps = (!barrel_) && isPSmodule;
0122 
0123   unsigned int index = (diskps << (4 + 5)) + (projrinv_ << nbits) + vmstub.bend().value();
0124 
0125   //Check if stub z position consistent
0126   int idrz = stubfinerz - projfinerz;
0127   bool pass;
0128 
0129   if (barrel_) {
0130     if (isPSseed_) {
0131       pass = idrz >= -1 && idrz <= 1;
0132     } else {
0133       pass = idrz >= -5 && idrz <= 5;
0134     }
0135   } else {
0136     if (isPSmodule) {
0137       pass = idrz >= -1 && idrz <= 1;
0138     } else {
0139       pass = idrz >= -3 && idrz <= 3;
0140     }
0141   }
0142 
0143   // Detailed printout for comparison with HLS code
0144   bool print = false;
0145   if (print)
0146     edm::LogVerbatim("Tracklet") << "MEU TrkId stubindex : " << 128 * proj_->TCIndex() + proj_->trackletIndex() << " "
0147                                  << vmstub.stubindex().value() << "   "
0148                                  << ((pass && dphicut) && luttable_.lookup(index)) << " index=" << index
0149                                  << " projrinv bend : " << projrinv_ << " " << vmstub.bend().value()
0150                                  << "  shift_ isPSseed_ :" << shift_ << " " << isPSseed_ << " slot=" << slot;
0151 
0152   //Check if stub bend and proj rinv consistent
0153 
0154   goodpair_ = (pass && dphicut) && luttable_.lookup(index);
0155   havepair_ = true;
0156 
0157   if (havepair_) {
0158     std::pair<Tracklet*, const Stub*> tmppair(proj_, vmstub.stub());
0159     tmppair_ = tmppair;
0160   }
0161 
0162   istub_++;
0163   if (istub_ >= vmstubsmemory_->nStubsBin(slot)) {
0164     iuse_++;
0165     if (iuse_ < use_.size()) {
0166       istub_ = 0;
0167     } else {
0168       idle_ = true;
0169     }
0170   }
0171 }
0172 
0173 void MatchEngineUnit::reset() {
0174   candmatches_.reset();
0175   idle_ = true;
0176   istub_ = 0;
0177   goodpair_ = false;
0178   goodpair__ = false;
0179   havepair_ = false;
0180   havepair__ = false;
0181 }
0182 
0183 int MatchEngineUnit::TCID() const {
0184   if (!empty()) {
0185     return peek().first->TCID();
0186   }
0187 
0188   if (idle_ && !havepair_ && !havepair__) {
0189     return 16383;
0190   }
0191   if (havepair__) {
0192     return tmppair__.first->TCID();
0193   }
0194   if (havepair_) {
0195     return tmppair_.first->TCID();
0196   }
0197   return proj_->TCID();
0198 }