Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-19 23:20:13

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),
0013       isPSseed_(false),
0014       idle_(true),
0015       almostfullsave_(false),
0016       luttable_(luttable),
0017       isPSseed__(false),
0018       isPSseed___(false),
0019       isPSseed____(false),
0020       good__(false),
0021       good___(false),
0022       good____(false),
0023       candmatches_(3),
0024       print_(false) {
0025   imeu_ = -1;
0026   barrel_ = barrel;
0027   layerdisk_ = layerdisk;
0028   ir2smin_ = 0;
0029   if (layerdisk_ >= N_LAYER) {
0030     double rmin2s = (layerdisk_ < N_LAYER + 2) ? settings_.rDSSinner(0) : settings_.rDSSouter(0);
0031     ir2smin_ = (1 << (N_RZBITS + NFINERZBITS)) * (rmin2s - settings_.rmindiskvm()) /
0032                (settings_.rmaxdisk() - settings_.rmindiskvm());
0033   }
0034 }
0035 
0036 void MatchEngineUnit::setAlmostFull() { almostfullsave_ = candmatches_.nearfull(); }
0037 
0038 void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory,
0039                            unsigned int nrzbins,
0040                            unsigned int rzbin,
0041                            unsigned int phibin,
0042                            int shift,
0043                            int projrinv,
0044                            int projfinerz,
0045                            int projfinephi,
0046                            bool usefirstMinus,
0047                            bool usefirstPlus,
0048                            bool usesecondMinus,
0049                            bool usesecondPlus,
0050                            bool isPSseed,
0051                            Tracklet* proj) {
0052   vmstubsmemory_ = vmstubsmemory;
0053   idle_ = false;
0054   nrzbins_ = nrzbins;
0055   rzbin_ = rzbin;
0056   phibin_ = phibin;
0057   shift_ = shift;
0058   istub_ = 0;
0059   iuse_ = 0;
0060   projrinv_ = projrinv;
0061   projfinerz_ = projfinerz;
0062   projfinephi_ = projfinephi;
0063   use_.clear();
0064   if (usefirstMinus) {
0065     use_.emplace_back(0, 0);
0066   }
0067   if (usesecondMinus) {
0068     use_.emplace_back(1, 0);
0069   }
0070   if (usefirstPlus) {
0071     use_.emplace_back(0, 1);
0072   }
0073   if (usesecondPlus) {
0074     use_.emplace_back(1, 1);
0075   }
0076   assert(!use_.empty());
0077   isPSseed_ = isPSseed;
0078   proj_ = proj;
0079 
0080   good__ = false;
0081 }
0082 
0083 void MatchEngineUnit::step() {
0084   good__ = !idle() && !almostfullsave_;
0085 
0086   if (!good__)
0087     return;
0088 
0089   unsigned int slot = (phibin_ + use_[iuse_].second) * nrzbins_ + rzbin_ + use_[iuse_].first;
0090 
0091   projfinerz__ = projfinerz_ - (1 << NFINERZBITS) * use_[iuse_].first;
0092   projfinephi__ = projfinephi_;
0093   if (use_[iuse_].second == 0) {
0094     if (shift_ == -1) {
0095       projfinephi__ -= (1 << NFINEPHIBITS);
0096     }
0097   } else {
0098     //When we get here shift_ is either 1 or -1
0099     if (shift_ == 1) {
0100       projfinephi__ += (1 << NFINEPHIBITS);
0101     }
0102   }
0103 
0104   vmstub__ = vmstubsmemory_->getVMStubMEBin(slot, istub_);
0105   rzbin__ = rzbin_ + use_[iuse_].first;
0106 
0107   isPSseed__ = isPSseed_;
0108   projrinv__ = projrinv_;
0109   proj__ = proj_;
0110 
0111   istub_++;
0112   if (istub_ >= vmstubsmemory_->nStubsBin(slot)) {
0113     iuse_++;
0114     if (iuse_ < use_.size()) {
0115       istub_ = 0;
0116     } else {
0117       idle_ = true;
0118     }
0119   }
0120 }
0121 
0122 void MatchEngineUnit::processPipeline() {
0123   if (good____) {
0124     int stubfinerz = vmstub____.finerz().value();
0125     int stubfinephi = vmstub____.finephi().value();
0126     bool isPSmodule = false;
0127 
0128     if (barrel_) {
0129       isPSmodule = layerdisk_ < N_PSLAYER;
0130     } else {
0131       const int absz = (1 << settings_.MEBinsBits()) - 1;
0132       unsigned int irstub = ((rzbin____ & absz) << NFINERZBITS) + stubfinerz;
0133 
0134       //Verify that ir2smin_ is initialized and check if irstub is less than radius of innermost 2s module
0135       assert(ir2smin_ > 0);
0136       isPSmodule = irstub < ir2smin_;
0137     }
0138     assert(isPSmodule == vmstub____.isPSmodule());
0139 
0140     int deltaphi = stubfinephi - projfinephi____;
0141 
0142     constexpr int idphicut = 3;
0143 
0144     bool dphicut = (abs(deltaphi) < idphicut);
0145 
0146     int nbits = isPSmodule ? N_BENDBITS_PS : N_BENDBITS_2S;
0147 
0148     int diskps = (!barrel_) && isPSmodule;
0149 
0150     //here we always use the larger number of bits for the bend
0151     unsigned int index = (diskps << (N_BENDBITS_2S + NRINVBITS)) + (projrinv____ << nbits) + vmstub____.bend().value();
0152 
0153     //Check if stub z position consistent
0154     int idrz = stubfinerz - projfinerz____;
0155     bool pass;
0156 
0157     if (barrel_) {
0158       if (isPSseed____) {
0159         constexpr int drzcut = 1;
0160         pass = std::abs(idrz) <= drzcut;
0161       } else {
0162         constexpr int drzcut = 5;
0163         pass = std::abs(idrz) <= drzcut;
0164       }
0165     } else {
0166       if (isPSmodule) {
0167         constexpr int drzcut = 1;
0168         pass = std::abs(idrz) <= drzcut;
0169       } else {
0170         constexpr int drzcut = 3;
0171         pass = std::abs(idrz) <= drzcut;
0172       }
0173     }
0174 
0175     bool goodpair = (pass && dphicut) && luttable_.lookup(index);
0176 
0177     std::pair<Tracklet*, const Stub*> tmppair(proj____, vmstub____.stub());
0178 
0179     if (goodpair) {
0180       candmatches_.store(tmppair);
0181     }
0182   }
0183 
0184   proj____ = proj___;
0185   projfinephi____ = projfinephi___;
0186   projfinerz____ = projfinerz___;
0187   projrinv____ = projrinv___;
0188   isPSseed____ = isPSseed___;
0189   good____ = good___;
0190   vmstub____ = vmstub___;
0191   rzbin____ = rzbin___;
0192 
0193   proj___ = proj__;
0194   projfinephi___ = projfinephi__;
0195   projfinerz___ = projfinerz__;
0196   projrinv___ = projrinv__;
0197   isPSseed___ = isPSseed__;
0198   good___ = good__;
0199   vmstub___ = vmstub__;
0200   rzbin___ = rzbin__;
0201 }
0202 
0203 void MatchEngineUnit::reset() {
0204   candmatches_.reset();
0205   idle_ = true;
0206   istub_ = 0;
0207   good__ = false;
0208   good___ = false;
0209   good____ = false;
0210 }
0211 
0212 int MatchEngineUnit::TCID() const {
0213   if (!empty()) {
0214     return peek().first->TCID();
0215   }
0216 
0217   if (good____) {
0218     return proj____->TCID();
0219   }
0220 
0221   if (good___) {
0222     return proj___->TCID();
0223   }
0224 
0225   if (good__) {
0226     return proj__->TCID();
0227   }
0228 
0229   if (idle_) {
0230     return (1 << (settings_.nbitstrackletindex() + settings_.nbitstcindex())) - 1;
0231   }
0232 
0233   return proj_->TCID();
0234 }