CMS 3D CMS Logo

MatchEngineUnit.cc
Go to the documentation of this file.
4 
5 using namespace std;
6 using namespace trklet;
7 
8 MatchEngineUnit::MatchEngineUnit(const Settings& settings,
9  bool barrel,
10  unsigned int layerdisk,
11  const TrackletLUT& luttable)
12  : settings_(settings), luttable_(luttable), candmatches_(3) {
13  idle_ = true;
14  print_ = false;
15  imeu_ = -1;
16  barrel_ = barrel;
17  layerdisk_ = layerdisk;
18  good__ = false;
19  good__t = false;
20  good___ = false;
21 }
22 
24 
26  unsigned int nrzbins,
27  unsigned int rzbin,
28  unsigned int phibin,
29  int shift,
30  int projrinv,
31  int projfinerz,
32  int projfinephi,
33  bool usefirstMinus,
34  bool usefirstPlus,
35  bool usesecondMinus,
36  bool usesecondPlus,
37  bool isPSseed,
38  Tracklet* proj) {
39  vmstubsmemory_ = vmstubsmemory;
40  idle_ = false;
41  nrzbins_ = nrzbins;
42  rzbin_ = rzbin;
43  phibin_ = phibin;
44  shift_ = shift;
45  istub_ = 0;
46  iuse_ = 0;
47  projrinv_ = projrinv;
48  projfinerz_ = projfinerz;
49  projfinephi_ = projfinephi;
50  use_.clear();
51  if (usefirstMinus) {
52  use_.emplace_back(0, 0);
53  }
54  if (usesecondMinus) {
55  use_.emplace_back(1, 0);
56  }
57  if (usefirstPlus) {
58  use_.emplace_back(0, 1);
59  }
60  if (usesecondPlus) {
61  use_.emplace_back(1, 1);
62  }
63  assert(!use_.empty());
64  isPSseed_ = isPSseed;
65  proj_ = proj;
66 
67  good__ = false;
68 }
69 
71  good__ = !idle() && !almostfullsave_;
72 
73  if (!good__)
74  return;
75 
76  unsigned int slot = (phibin_ + use_[iuse_].second) * nrzbins_ + rzbin_ + use_[iuse_].first;
77 
80  if (use_[iuse_].second == 0) {
81  if (shift_ == -1) {
82  projfinephi__ -= (1 << NFINEPHIBITS);
83  }
84  } else {
85  //When we get here shift_ is either 1 or -1
86  if (shift_ == 1) {
87  projfinephi__ += (1 << NFINEPHIBITS);
88  }
89  }
90 
92 
95  proj__ = proj_;
96 
97  istub_++;
98  if (istub_ >= vmstubsmemory_->nStubsBin(slot)) {
99  iuse_++;
100  if (iuse_ < use_.size()) {
101  istub_ = 0;
102  } else {
103  idle_ = true;
104  }
105  }
106 }
107 
109  if (good___) {
110  bool isPSmodule = vmstub___.isPSmodule();
111  int stubfinerz = vmstub___.finerz().value();
112  int stubfinephi = vmstub___.finephi().value();
113 
114  int deltaphi = stubfinephi - projfinephi___;
115 
116  constexpr int idphicut = 3;
117 
118  bool dphicut = (abs(deltaphi) < idphicut);
119 
120  int nbits = isPSmodule ? N_BENDBITS_PS : N_BENDBITS_2S;
121 
122  int diskps = (!barrel_) && isPSmodule;
123 
124  //here we always use the larger number of bits for the bend
125  unsigned int index = (diskps << (N_BENDBITS_2S + NRINVBITS)) + (projrinv___ << nbits) + vmstub___.bend().value();
126 
127  //Check if stub z position consistent
128  int idrz = stubfinerz - projfinerz___;
129  bool pass;
130 
131  if (barrel_) {
132  if (isPSseed___) {
133  constexpr int drzcut = 1;
134  pass = std::abs(idrz) <= drzcut;
135  } else {
136  constexpr int drzcut = 5;
137  pass = std::abs(idrz) <= drzcut;
138  }
139  } else {
140  if (isPSmodule) {
141  constexpr int drzcut = 1;
142  pass = std::abs(idrz) <= drzcut;
143  } else {
144  constexpr int drzcut = 3;
145  pass = std::abs(idrz) <= drzcut;
146  }
147  }
148 
149  bool goodpair = (pass && dphicut) && luttable_.lookup(index);
150 
151  std::pair<Tracklet*, const Stub*> tmppair(proj___, vmstub___.stub());
152 
153  if (goodpair) {
154  candmatches_.store(tmppair);
155  }
156  }
157 
158  proj___ = proj__t;
163  good___ = good__t;
165 
166  proj__t = proj__;
171  good__t = good__;
173 }
174 
176  candmatches_.reset();
177  idle_ = true;
178  istub_ = 0;
179  good__ = false;
180  good__t = false;
181  good___ = false;
182 }
183 
185  if (!empty()) {
186  return peek().first->TCID();
187  }
188 
189  if (good___) {
190  return proj___->TCID();
191  }
192 
193  if (good__t) {
194  return proj__t->TCID();
195  }
196 
197  if (good__) {
198  return proj__->TCID();
199  }
200 
201  if (idle_) {
202  return (1 << (settings_.nbitstrackletindex() + settings_.nbitstcindex())) - 1;
203  }
204 
205  return proj_->TCID();
206 }
const FPGAWord & bend() const
Definition: VMStubME.h:26
const FPGAWord & finerz() const
Definition: VMStubME.h:24
unsigned int nbitstrackletindex() const
Definition: Settings.h:303
const Stub * stub() const
Definition: VMStubME.h:28
constexpr unsigned int NRINVBITS
Definition: Settings.h:36
constexpr unsigned int N_BENDBITS_2S
Definition: Settings.h:34
int lookup(unsigned int index) const
assert(be >=bs)
int TCID() const
Definition: Tracklet.h:214
bool isPSmodule() const
Definition: VMStubME.h:30
constexpr unsigned int N_BENDBITS_PS
Definition: Settings.h:33
std::pair< Tracklet *, const Stub * > peek() const
const Settings & settings_
U second(std::pair< T, U > const &p)
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)
CircularBuffer< std::pair< Tracklet *, const Stub * > > candmatches_
const TrackletLUT & luttable_
const VMStubME & getVMStubMEBin(unsigned int bin, unsigned int i) const
VMStubsMEMemory * vmstubsmemory_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int value() const
Definition: FPGAWord.h:24
unsigned int nbitstcindex() const
Definition: Settings.h:308
constexpr unsigned int NFINERZBITS
Definition: Settings.h:37
std::vector< std::pair< unsigned int, unsigned int > > use_
constexpr unsigned int NFINEPHIBITS
Definition: Settings.h:38
const FPGAWord & finephi() const
Definition: VMStubME.h:23
static unsigned int const shift
unsigned int nStubsBin(unsigned int bin) const