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