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