Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h"
0002 #include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h"
0003 #include "L1Trigger/TrackFindingTracklet/interface/Settings.h"
0004 
0005 using namespace std;
0006 using namespace trklet;
0007 
0008 TrackletEngineUnit::TrackletEngineUnit(const Settings* const settings,
0009                                        unsigned int nbitsfinephi,
0010                                        unsigned int layerdisk1,
0011                                        unsigned int layerdisk2,
0012                                        unsigned int iSeed,
0013                                        unsigned int nbitsfinephidiff,
0014                                        unsigned int iAllStub,
0015                                        const TrackletLUT* pttableinnernew,
0016                                        const TrackletLUT* pttableouternew,
0017                                        VMStubsTEMemory* outervmstubs)
0018     : settings_(settings), pttableinnernew_(pttableinnernew), pttableouternew_(pttableouternew), candpairs_(3) {
0019   idle_ = true;
0020   nbitsfinephi_ = nbitsfinephi;
0021   layerdisk2_ = layerdisk2;
0022   layerdisk1_ = layerdisk1;
0023   iSeed_ = iSeed;
0024   nbitsfinephidiff_ = nbitsfinephidiff;
0025   iAllStub_ = iAllStub;
0026   outervmstubs_ = outervmstubs;
0027 }
0028 
0029 void TrackletEngineUnit::init(const TEData& tedata) {
0030   tedata_ = tedata;
0031   nreg_ = 0;
0032   istub_ = 0;
0033   idle_ = false;
0034   assert(!tedata_.regions_.empty());
0035   std::tie(next_, ireg_, nstub_) = tedata_.regions_[0];
0036 }
0037 
0038 void TrackletEngineUnit::reset() {
0039   idle_ = true;
0040   goodpair_ = false;
0041   goodpair__ = false;
0042   candpairs_.reset();
0043 }
0044 
0045 void TrackletEngineUnit::step(bool, int, int) {
0046   if (goodpair__) {
0047     candpairs_.store(candpair__);
0048   }
0049 
0050   goodpair__ = goodpair_;
0051   candpair__ = candpair_;
0052 
0053   goodpair_ = false;
0054 
0055   if (idle_ || nearfull_) {
0056     return;
0057   }
0058 
0059   int ibin = tedata_.start_ + next_;
0060 
0061   int nbins = (1 << NFINERZBITS);
0062 
0063   assert(istub_ < outervmstubs_->nVMStubsBinned(ireg_ * nbins + ibin));
0064 
0065   const VMStubTE& outervmstub = outervmstubs_->getVMStubTEBinned(ireg_ * nbins + ibin, istub_);
0066   int rzbin = (outervmstub.vmbits().value() & (nbins - 1));
0067 
0068   FPGAWord iphiouterbin = outervmstub.finephi();
0069 
0070   assert(iphiouterbin == outervmstub.finephi());
0071 
0072   //New code to calculate lut value
0073   int outerfinephi = iAllStub_ * (1 << (nbitsfinephi_ - settings_->nbitsallstubs(layerdisk2_))) +
0074                      ireg_ * (1 << settings_->nfinephi(1, iSeed_)) + iphiouterbin.value();
0075   int idphi = outerfinephi - tedata_.innerfinephi_;
0076 
0077   bool inrange = (idphi < (1 << (nbitsfinephidiff_ - 1))) && (idphi >= -(1 << (nbitsfinephidiff_ - 1)));
0078 
0079   idphi = idphi & ((1 << nbitsfinephidiff_) - 1);
0080 
0081   unsigned int firstDiskSeed = 4;
0082   if (iSeed_ >= firstDiskSeed) {  //Also use r-position
0083     int ibinMask = 3;             //Get two least sign. bits
0084     int ir = ((ibin & ibinMask) << 1) + (rzbin >> (NFINERZBITS - 1));
0085     int nrbits = 3;
0086     idphi = (idphi << nrbits) + ir;
0087   }
0088 
0089   if (next_ != 0)
0090     rzbin += (1 << NFINERZBITS);
0091 
0092   if ((rzbin < tedata_.rzbinfirst_) || (rzbin - tedata_.rzbinfirst_ > tedata_.rzdiffmax_)) {
0093     if (settings_->debugTracklet()) {
0094       edm::LogVerbatim("Tracklet") << " layer-disk stub pair rejected because rbin cut : " << rzbin << " "
0095                                    << tedata_.rzbinfirst_ << " " << tedata_.rzdiffmax_;
0096     }
0097   } else {
0098     FPGAWord outerbend = outervmstub.bend();
0099 
0100     int ptinnerindex = (idphi << tedata_.innerbend_.nbits()) + tedata_.innerbend_.value();
0101     int ptouterindex = (idphi << outerbend.nbits()) + outerbend.value();
0102 
0103     if (!(inrange && pttableinnernew_->lookup(ptinnerindex) && pttableouternew_->lookup(ptouterindex))) {
0104       if (settings_->debugTracklet()) {
0105         edm::LogVerbatim("Tracklet") << " Stub pair rejected because of stub pt cut bends : "
0106                                      << settings_->benddecode(
0107                                             tedata_.innerbend_.value(), layerdisk1_, tedata_.stub_->isPSmodule())
0108                                      << " "
0109                                      << settings_->benddecode(outerbend.value(), layerdisk2_, outervmstub.isPSmodule());
0110       }
0111     } else {
0112       candpair_ = pair<const Stub*, const Stub*>(tedata_.stub_, outervmstub.stub());
0113       goodpair_ = true;
0114     }
0115   }
0116 
0117   istub_++;
0118   assert(nstub_ <= N_VMSTUBSMAX);
0119   if (istub_ >= nstub_) {
0120     istub_ = 0;
0121     nreg_++;
0122     if (nreg_ >= tedata_.regions_.size()) {
0123       nreg_ = 0;
0124       idle_ = true;
0125     } else {
0126       std::tie(next_, ireg_, nstub_) = tedata_.regions_[nreg_];
0127     }
0128   }
0129 }