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___ = false;
20  good____ = false;
21  ir2smin_ = 0;
22  if (layerdisk_ >= N_LAYER) {
23  double rmin2s = (layerdisk_ < N_LAYER + 2) ? settings_.rDSSinner(0) : settings_.rDSSouter(0);
24  ir2smin_ = (1 << (N_RZBITS + NFINERZBITS)) * (rmin2s - settings_.rmindiskvm()) /
26  }
27 }
28 
30 
32  unsigned int nrzbins,
33  unsigned int rzbin,
34  unsigned int phibin,
35  int shift,
36  int projrinv,
37  int projfinerz,
38  int projfinephi,
39  bool usefirstMinus,
40  bool usefirstPlus,
41  bool usesecondMinus,
42  bool usesecondPlus,
43  bool isPSseed,
44  Tracklet* proj) {
45  vmstubsmemory_ = vmstubsmemory;
46  idle_ = false;
47  nrzbins_ = nrzbins;
48  rzbin_ = rzbin;
49  phibin_ = phibin;
50  shift_ = shift;
51  istub_ = 0;
52  iuse_ = 0;
53  projrinv_ = projrinv;
54  projfinerz_ = projfinerz;
55  projfinephi_ = projfinephi;
56  use_.clear();
57  if (usefirstMinus) {
58  use_.emplace_back(0, 0);
59  }
60  if (usesecondMinus) {
61  use_.emplace_back(1, 0);
62  }
63  if (usefirstPlus) {
64  use_.emplace_back(0, 1);
65  }
66  if (usesecondPlus) {
67  use_.emplace_back(1, 1);
68  }
69  assert(!use_.empty());
70  isPSseed_ = isPSseed;
71  proj_ = proj;
72 
73  good__ = false;
74 }
75 
77  good__ = !idle() && !almostfullsave_;
78 
79  if (!good__)
80  return;
81 
82  unsigned int slot = (phibin_ + use_[iuse_].second) * nrzbins_ + rzbin_ + use_[iuse_].first;
83 
86  if (use_[iuse_].second == 0) {
87  if (shift_ == -1) {
88  projfinephi__ -= (1 << NFINEPHIBITS);
89  }
90  } else {
91  //When we get here shift_ is either 1 or -1
92  if (shift_ == 1) {
93  projfinephi__ += (1 << NFINEPHIBITS);
94  }
95  }
96 
98  rzbin__ = rzbin_ + use_[iuse_].first;
99 
102  proj__ = proj_;
103 
104  istub_++;
105  if (istub_ >= vmstubsmemory_->nStubsBin(slot)) {
106  iuse_++;
107  if (iuse_ < use_.size()) {
108  istub_ = 0;
109  } else {
110  idle_ = true;
111  }
112  }
113 }
114 
116  if (good____) {
117  int stubfinerz = vmstub____.finerz().value();
118  int stubfinephi = vmstub____.finephi().value();
119  bool isPSmodule = false;
120 
121  if (barrel_) {
122  isPSmodule = layerdisk_ < N_PSLAYER;
123  } else {
124  const int absz = (1 << settings_.MEBinsBits()) - 1;
125  unsigned int irstub = ((rzbin____ & absz) << NFINERZBITS) + stubfinerz;
126 
127  //Verify that ir2smin_ is initialized and check if irstub is less than radius of innermost 2s module
128  assert(ir2smin_ > 0);
129  isPSmodule = irstub < ir2smin_;
130  }
131  assert(isPSmodule == vmstub____.isPSmodule());
132 
133  int deltaphi = stubfinephi - projfinephi____;
134 
135  constexpr int idphicut = 3;
136 
137  bool dphicut = (abs(deltaphi) < idphicut);
138 
139  int nbits = isPSmodule ? N_BENDBITS_PS : N_BENDBITS_2S;
140 
141  int diskps = (!barrel_) && isPSmodule;
142 
143  //here we always use the larger number of bits for the bend
144  unsigned int index = (diskps << (nbits + NRINVBITS)) + (projrinv____ << nbits) + vmstub____.bend().value();
145 
146  //Check if stub z position consistent
147  int idrz = stubfinerz - projfinerz____;
148  bool pass;
149 
150  if (barrel_) {
151  if (isPSseed____) {
152  constexpr int drzcut = 1;
153  pass = std::abs(idrz) <= drzcut;
154  } else {
155  constexpr int drzcut = 5;
156  pass = std::abs(idrz) <= drzcut;
157  }
158  } else {
159  if (isPSmodule) {
160  constexpr int drzcut = 1;
161  pass = std::abs(idrz) <= drzcut;
162  } else {
163  constexpr int drzcut = 3;
164  pass = std::abs(idrz) <= drzcut;
165  }
166  }
167 
168  bool goodpair = (pass && dphicut) && luttable_.lookup(index);
169 
170  std::pair<Tracklet*, const Stub*> tmppair(proj____, vmstub____.stub());
171 
172  if (goodpair) {
173  candmatches_.store(tmppair);
174  }
175  }
176 
177  proj____ = proj___;
182  good____ = good___;
185 
186  proj___ = proj__;
191  good___ = good__;
193  rzbin___ = rzbin__;
194 }
195 
197  candmatches_.reset();
198  idle_ = true;
199  istub_ = 0;
200  good__ = false;
201  good___ = false;
202  good____ = false;
203 }
204 
206  if (!empty()) {
207  return peek().first->TCID();
208  }
209 
210  if (good____) {
211  return proj____->TCID();
212  }
213 
214  if (good___) {
215  return proj___->TCID();
216  }
217 
218  if (good__) {
219  return proj__->TCID();
220  }
221 
222  if (idle_) {
223  return (1 << (settings_.nbitstrackletindex() + settings_.nbitstcindex())) - 1;
224  }
225 
226  return proj_->TCID();
227 }
unsigned int MEBinsBits() const
Definition: Settings.h:233
constexpr unsigned int N_RZBITS
Definition: Settings.h:39
const FPGAWord & bend() const
Definition: VMStubME.h:26
const FPGAWord & finerz() const
Definition: VMStubME.h:24
double rDSSinner(unsigned int iBin) const
Definition: Settings.h:183
unsigned int nbitstrackletindex() const
Definition: Settings.h:309
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
double rmindiskvm() const
Definition: Settings.h:355
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_
double rDSSouter(unsigned int iBin) const
Definition: Settings.h:186
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:314
constexpr unsigned int NFINERZBITS
Definition: Settings.h:37
std::vector< std::pair< unsigned int, unsigned int > > use_
constexpr unsigned int N_PSLAYER
Definition: Settings.h:27
double rmaxdisk() const
Definition: Settings.h:134
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
constexpr int N_LAYER
Definition: Settings.h:25