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 }
21 
23 
25  unsigned int nrzbins,
26  unsigned int rzbin,
27  unsigned int phibin,
28  int shift,
29  int projrinv,
30  int projfinerz,
31  int projfinephi,
32  bool usefirstMinus,
33  bool usefirstPlus,
34  bool usesecondMinus,
35  bool usesecondPlus,
36  bool isPSseed,
37  Tracklet* proj) {
38  vmstubsmemory_ = vmstubsmemory;
39  idle_ = false;
40  nrzbins_ = nrzbins;
41  rzbin_ = rzbin;
42  phibin_ = phibin;
43  shift_ = shift;
44  istub_ = 0;
45  iuse_ = 0;
46  projrinv_ = projrinv;
47  projfinerz_ = projfinerz;
48  projfinephi_ = projfinephi;
49  use_.clear();
50  if (usefirstMinus) {
51  use_.emplace_back(0, 0);
52  }
53  if (usesecondMinus) {
54  use_.emplace_back(1, 0);
55  }
56  if (usefirstPlus) {
57  use_.emplace_back(0, 1);
58  }
59  if (usesecondPlus) {
60  use_.emplace_back(1, 1);
61  }
62  assert(!use_.empty());
63  isPSseed_ = isPSseed;
64  proj_ = proj;
65 
66  good__ = false;
67 }
68 
70  good__ = !idle() && !almostfullsave_;
71 
72  if (!good__)
73  return;
74 
75  unsigned int slot = (phibin_ + use_[iuse_].second) * nrzbins_ + rzbin_ + use_[iuse_].first;
76 
79  if (use_[iuse_].second == 0) {
80  if (shift_ == -1) {
81  projfinephi__ -= (1 << NFINEPHIBITS);
82  }
83  } else {
84  //When we get here shift_ is either 1 or -1
85  if (shift_ == 1) {
86  projfinephi__ += (1 << NFINEPHIBITS);
87  }
88  }
89 
91 
94  proj__ = proj_;
95 
96  istub_++;
97  if (istub_ >= vmstubsmemory_->nStubsBin(slot)) {
98  iuse_++;
99  if (iuse_ < use_.size()) {
100  istub_ = 0;
101  } else {
102  idle_ = true;
103  }
104  }
105 }
106 
108  if (good___) {
109  bool isPSmodule = vmstub___.isPSmodule();
110  int stubfinerz = vmstub___.finerz().value();
111  int stubfinephi = vmstub___.finephi().value();
112 
113  int deltaphi = stubfinephi - projfinephi___;
114 
115  constexpr int idphicut = 3;
116 
117  bool dphicut = (abs(deltaphi) < idphicut);
118 
119  int nbits = isPSmodule ? N_BENDBITS_PS : N_BENDBITS_2S;
120 
121  int diskps = (!barrel_) && isPSmodule;
122 
123  //here we always use the larger number of bits for the bend
124  unsigned int index = (diskps << (N_BENDBITS_2S + NRINVBITS)) + (projrinv___ << nbits) + vmstub___.bend().value();
125 
126  //Check if stub z position consistent
127  int idrz = stubfinerz - projfinerz___;
128  bool pass;
129 
130  if (barrel_) {
131  if (isPSseed___) {
132  constexpr int drzcut = 1;
133  pass = std::abs(idrz) <= drzcut;
134  } else {
135  constexpr int drzcut = 5;
136  pass = std::abs(idrz) <= drzcut;
137  }
138  } else {
139  if (isPSmodule) {
140  constexpr int drzcut = 1;
141  pass = std::abs(idrz) <= drzcut;
142  } else {
143  constexpr int drzcut = 3;
144  pass = std::abs(idrz) <= drzcut;
145  }
146  }
147 
148  bool goodpair = (pass && dphicut) && luttable_.lookup(index);
149 
150  std::pair<Tracklet*, const Stub*> tmppair(proj___, vmstub___.stub());
151 
152  if (goodpair) {
153  candmatches_.store(tmppair);
154  }
155  }
156 
157  proj___ = proj__;
162  good___ = good__;
164 }
165 
167  candmatches_.reset();
168  idle_ = true;
169  istub_ = 0;
170  good__ = false;
171  good___ = false;
172 }
173 
175  if (!empty()) {
176  return peek().first->TCID();
177  }
178 
179  if (good___) {
180  return proj___->TCID();
181  }
182 
183  if (good__) {
184  return proj__->TCID();
185  }
186 
187  if (idle_) {
188  return (1 << (settings_.nbitstrackletindex() + settings_.nbitstcindex())) - 1;
189  }
190 
191  return proj_->TCID();
192 }
const FPGAWord & bend() const
Definition: VMStubME.h:26
const FPGAWord & finerz() const
Definition: VMStubME.h:24
unsigned int nbitstrackletindex() const
Definition: Settings.h:281
const Stub * stub() const
Definition: VMStubME.h:28
constexpr unsigned int NRINVBITS
Definition: Settings.h:32
constexpr unsigned int N_BENDBITS_2S
Definition: Settings.h:30
int lookup(unsigned int index) const
Definition: TrackletLUT.cc:904
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:29
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:286
constexpr unsigned int NFINERZBITS
Definition: Settings.h:33
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