CMS 3D CMS Logo

MatchEngineUnit.cc
Go to the documentation of this file.
3 
4 using namespace std;
5 using namespace trklet;
6 
7 MatchEngineUnit::MatchEngineUnit(bool barrel, unsigned int layerdisk, const TrackletLUT& luttable)
8  : luttable_(luttable), candmatches_(3) {
9  idle_ = true;
10  barrel_ = barrel;
11  layerdisk_ = layerdisk;
12  goodpair_ = false;
13  goodpair__ = false;
14  havepair_ = false;
15  havepair__ = false;
16 }
17 
19  unsigned int nrzbins,
20  unsigned int rzbin,
21  unsigned int phibin,
22  int shift,
23  int projrinv,
24  int projfinerz,
25  int projfinephi,
26  bool usefirstMinus,
27  bool usefirstPlus,
28  bool usesecondMinus,
29  bool usesecondPlus,
30  bool isPSseed,
31  Tracklet* proj,
32  bool) {
33  vmstubsmemory_ = vmstubsmemory;
34  idle_ = false;
35  nrzbins_ = nrzbins;
36  rzbin_ = rzbin;
37  phibin_ = phibin;
38  shift_ = shift;
39  istub_ = 0;
40  iuse_ = 0;
41  projrinv_ = projrinv;
42  projfinerz_ = projfinerz;
43  projfinephi_ = projfinephi;
44  use_.clear();
45  if (usefirstMinus) {
46  use_.emplace_back(0, 0);
47  }
48  if (usesecondMinus) {
49  use_.emplace_back(1, 0);
50  }
51  if (usefirstPlus) {
52  use_.emplace_back(0, 1);
53  }
54  if (usesecondPlus) {
55  use_.emplace_back(1, 1);
56  }
57  assert(!use_.empty());
58  isPSseed_ = isPSseed;
59  proj_ = proj;
60 
61  //Even when you init a new projection you need to process the pipeline
62  //This should be fixed to be done more cleanly - but require synchronizaton
63  //with the HLS code
64  if (goodpair__) {
65  candmatches_.store(tmppair__);
66  }
67 
71 
72  havepair_ = false;
73  goodpair_ = false;
74 }
75 
77  bool almostfull = candmatches_.nearfull();
78 
79  if (goodpair__) {
81  candmatches_.store(tmppair__);
82  }
83 
87 
88  havepair_ = false;
89  goodpair_ = false;
90 
91  if (idle() || almostfull)
92  return;
93 
94  unsigned int slot = (phibin_ + use_[iuse_].second) * nrzbins_ + rzbin_ + use_[iuse_].first;
95 
96  int projfinerz = projfinerz_ - (1 << NFINERZBITS) * use_[iuse_].first;
97  int projfinephi = projfinephi_;
98  if (use_[iuse_].second == 0) {
99  if (shift_ == -1) {
100  projfinephi -= (1 << NFINEPHIBITS);
101  }
102  } else {
103  //When we get here shift_ is either 1 or -1
104  if (shift_ == 1) {
105  projfinephi += (1 << NFINEPHIBITS);
106  }
107  }
108 
109  const VMStubME& vmstub = vmstubsmemory_->getVMStubMEBin(slot, istub_);
110 
111  bool isPSmodule = vmstub.isPSmodule();
112  int stubfinerz = vmstub.finerz().value();
113  int stubfinephi = vmstub.finephi().value();
114 
115  int deltaphi = stubfinephi - projfinephi;
116 
117  bool dphicut = (abs(deltaphi) < 3);
118 
119  int nbits = isPSmodule ? 3 : 4;
120 
121  int diskps = (!barrel_) && isPSmodule;
122 
123  unsigned int index = (diskps << (4 + 5)) + (projrinv_ << nbits) + vmstub.bend().value();
124 
125  //Check if stub z position consistent
126  int idrz = stubfinerz - projfinerz;
127  bool pass;
128 
129  if (barrel_) {
130  if (isPSseed_) {
131  pass = idrz >= -1 && idrz <= 1;
132  } else {
133  pass = idrz >= -5 && idrz <= 5;
134  }
135  } else {
136  if (isPSmodule) {
137  pass = idrz >= -1 && idrz <= 1;
138  } else {
139  pass = idrz >= -3 && idrz <= 3;
140  }
141  }
142 
143  // Detailed printout for comparison with HLS code
144  bool print = false;
145  if (print)
146  edm::LogVerbatim("Tracklet") << "MEU TrkId stubindex : " << 128 * proj_->TCIndex() + proj_->trackletIndex() << " "
147  << vmstub.stubindex().value() << " "
148  << ((pass && dphicut) && luttable_.lookup(index)) << " index=" << index
149  << " projrinv bend : " << projrinv_ << " " << vmstub.bend().value()
150  << " shift_ isPSseed_ :" << shift_ << " " << isPSseed_ << " slot=" << slot;
151 
152  //Check if stub bend and proj rinv consistent
153 
154  goodpair_ = (pass && dphicut) && luttable_.lookup(index);
155  havepair_ = true;
156 
157  if (havepair_) {
158  std::pair<Tracklet*, const Stub*> tmppair(proj_, vmstub.stub());
159  tmppair_ = tmppair;
160  }
161 
162  istub_++;
163  if (istub_ >= vmstubsmemory_->nStubsBin(slot)) {
164  iuse_++;
165  if (iuse_ < use_.size()) {
166  istub_ = 0;
167  } else {
168  idle_ = true;
169  }
170  }
171 }
172 
174  candmatches_.reset();
175  idle_ = true;
176  istub_ = 0;
177  goodpair_ = false;
178  goodpair__ = false;
179  havepair_ = false;
180  havepair__ = false;
181 }
182 
184  if (!empty()) {
185  return peek().first->TCID();
186  }
187 
188  if (idle_ && !havepair_ && !havepair__) {
189  return 16383;
190  }
191  if (havepair__) {
192  return tmppair__.first->TCID();
193  }
194  if (havepair_) {
195  return tmppair_.first->TCID();
196  }
197  return proj_->TCID();
198 }
Log< level::Info, true > LogVerbatim
const FPGAWord & bend() const
Definition: VMStubME.h:26
const FPGAWord & finerz() const
Definition: VMStubME.h:24
const Stub * stub() const
Definition: VMStubME.h:28
int lookup(unsigned int index) const
Definition: TrackletLUT.cc:900
assert(be >=bs)
int TCID() const
Definition: Tracklet.h:212
void init(VMStubsMEMemory *vmstubsmemory, unsigned int nrzbin, unsigned int rzbin, unsigned int iphi, int shift, int projrinv, int projfinerz, int projfinephi, bool usefirstMinus, bool usefirstPlus, bool usesecondMinus, bool usesecondPlus, bool isPSseed, Tracklet *proj, bool print)
bool isPSmodule() const
Definition: VMStubME.h:30
int TCIndex() const
Definition: Tracklet.h:210
std::pair< Tracklet *, const Stub * > peek() const
U second(std::pair< T, U > const &p)
CircularBuffer< std::pair< Tracklet *, const Stub * > > candmatches_
int trackletIndex() const
Definition: Tracklet.h:206
const FPGAWord & stubindex() const
Definition: VMStubME.h:32
const TrackletLUT & luttable_
std::pair< Tracklet *, const Stub * > tmppair_
const VMStubME & getVMStubMEBin(unsigned int bin, unsigned int i) const
VMStubsMEMemory * vmstubsmemory_
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int value() const
Definition: FPGAWord.h:24
constexpr unsigned int NFINERZBITS
Definition: Settings.h:33
std::pair< Tracklet *, const Stub * > tmppair__
std::vector< std::pair< unsigned int, unsigned int > > use_
constexpr unsigned int NFINEPHIBITS
Definition: Settings.h:34
const FPGAWord & finephi() const
Definition: VMStubME.h:23
static unsigned int const shift
unsigned int nStubsBin(unsigned int bin) const