CMS 3D CMS Logo

TrackletEngineUnit.cc
Go to the documentation of this file.
4 
5 using namespace std;
6 using namespace trklet;
7 
8 TrackletEngineUnit::TrackletEngineUnit(const Settings* const settings,
9  unsigned int nbitsfinephi,
10  unsigned int layerdisk1,
11  unsigned int layerdisk2,
12  unsigned int iSeed,
13  unsigned int nbitsfinephidiff,
14  unsigned int iAllStub,
15  const TrackletLUT* pttableinnernew,
16  const TrackletLUT* pttableouternew,
17  VMStubsTEMemory* outervmstubs)
18  : settings_(settings), pttableinnernew_(pttableinnernew), pttableouternew_(pttableouternew), candpairs_(3) {
19  idle_ = true;
20  nbitsfinephi_ = nbitsfinephi;
21  layerdisk2_ = layerdisk2;
22  layerdisk1_ = layerdisk1;
23  iSeed_ = iSeed;
24  nbitsfinephidiff_ = nbitsfinephidiff;
25  iAllStub_ = iAllStub;
26  outervmstubs_ = outervmstubs;
27 }
28 
29 void TrackletEngineUnit::init(const TEData& tedata) {
30  tedata_ = tedata;
31  nreg_ = 0;
32  istub_ = 0;
33  idle_ = false;
34  assert(!tedata_.regions_.empty());
35  std::tie(next_, ireg_, nstub_) = tedata_.regions_[0];
36 }
37 
39  idle_ = true;
40  goodpair_ = false;
41  goodpair__ = false;
42  candpairs_.reset();
43 }
44 
45 void TrackletEngineUnit::step(bool, int, int) {
46  if (goodpair__) {
47  candpairs_.store(candpair__);
48  }
49 
52 
53  goodpair_ = false;
54 
55  if (idle_ || nearfull_) {
56  return;
57  }
58 
59  int ibin = tedata_.start_ + next_;
60 
61  int nbins = (1 << NFINERZBITS);
62 
63  assert(istub_ < outervmstubs_->nVMStubsBinned(ireg_ * nbins + ibin));
64 
65  const VMStubTE& outervmstub = outervmstubs_->getVMStubTEBinned(ireg_ * nbins + ibin, istub_);
66  int rzbin = (outervmstub.vmbits().value() & (nbins - 1));
67 
68  FPGAWord iphiouterbin = outervmstub.finephi();
69 
70  assert(iphiouterbin == outervmstub.finephi());
71 
72  //New code to calculate lut value
73  int outerfinephi = iAllStub_ * (1 << (nbitsfinephi_ - settings_->nbitsallstubs(layerdisk2_))) +
74  ireg_ * (1 << settings_->nfinephi(1, iSeed_)) + iphiouterbin.value();
75  int idphi = outerfinephi - tedata_.innerfinephi_;
76 
77  bool inrange = (idphi < (1 << (nbitsfinephidiff_ - 1))) && (idphi >= -(1 << (nbitsfinephidiff_ - 1)));
78 
79  idphi = idphi & ((1 << nbitsfinephidiff_) - 1);
80 
81  unsigned int firstDiskSeed = 4;
82  if (iSeed_ >= firstDiskSeed) { //Also use r-position
83  int ibinMask = 3; //Get two least sign. bits
84  int ir = ((ibin & ibinMask) << 1) + (rzbin >> (NFINERZBITS - 1));
85  int nrbits = 3;
86  idphi = (idphi << nrbits) + ir;
87  }
88 
89  if (next_ != 0)
90  rzbin += (1 << NFINERZBITS);
91 
92  if ((rzbin < tedata_.rzbinfirst_) || (rzbin - tedata_.rzbinfirst_ > tedata_.rzdiffmax_)) {
93  if (settings_->debugTracklet()) {
94  edm::LogVerbatim("Tracklet") << " layer-disk stub pair rejected because rbin cut : " << rzbin << " "
96  }
97  } else {
98  FPGAWord outerbend = outervmstub.bend();
99 
100  int ptinnerindex = (idphi << tedata_.innerbend_.nbits()) + tedata_.innerbend_.value();
101  int ptouterindex = (idphi << outerbend.nbits()) + outerbend.value();
102 
103  if (!(inrange && pttableinnernew_->lookup(ptinnerindex) && pttableouternew_->lookup(ptouterindex))) {
104  if (settings_->debugTracklet()) {
105  edm::LogVerbatim("Tracklet") << " Stub pair rejected because of stub pt cut bends : "
106  << settings_->benddecode(
108  << " "
109  << settings_->benddecode(outerbend.value(), layerdisk2_, outervmstub.isPSmodule());
110  }
111  } else {
112  candpair_ = pair<const Stub*, const Stub*>(tedata_.stub_, outervmstub.stub());
113  goodpair_ = true;
114  }
115  }
116 
117  istub_++;
119  if (istub_ >= nstub_) {
120  istub_ = 0;
121  nreg_++;
122  if (nreg_ >= tedata_.regions_.size()) {
123  nreg_ = 0;
124  idle_ = true;
125  } else {
126  std::tie(next_, ireg_, nstub_) = tedata_.regions_[nreg_];
127  }
128  }
129 }
Log< level::Info, true > LogVerbatim
const VMStubTE & getVMStubTEBinned(unsigned int bin, unsigned int i) const
bool isPSmodule() const
Definition: VMStubTE.h:31
double benddecode(int ibend, int layerdisk, bool isPSmodule) const
Definition: Settings.h:443
const FPGAWord & bend() const
Definition: VMStubTE.h:25
std::pair< const Stub *, const Stub * > candpair__
int lookup(unsigned int index) const
std::pair< const Stub *, const Stub * > candpair_
constexpr unsigned int N_VMSTUBSMAX
Definition: Settings.h:42
assert(be >=bs)
const Stub * stub() const
Definition: VMStubTE.h:29
unsigned int nbitsallstubs(unsigned int layerdisk) const
Definition: Settings.h:115
const TrackletLUT * pttableinnernew_
const FPGAWord & vmbits() const
Definition: VMStubTE.h:27
int value() const
Definition: FPGAWord.h:24
const TrackletLUT * pttableouternew_
constexpr unsigned int NFINERZBITS
Definition: Settings.h:37
const FPGAWord & finephi() const
Definition: VMStubTE.h:23
bool debugTracklet() const
Definition: Settings.h:194
int nbits() const
Definition: FPGAWord.h:25
bool isPSmodule() const
Definition: Stub.h:77
int nfinephi(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:142
const Stub * stub_
VMStubsTEMemory * outervmstubs_
void init(const TEData &tedata)
CircularBuffer< std::pair< const Stub *, const Stub * > > candpairs_
void step(bool print, int istep, int iTE)
std::vector< std::tuple< int, int, int > > regions_