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 }
trklet::Tracklet::TCIndex
int TCIndex() const
Definition: Tracklet.h:210
trklet::VMStubsMEMemory
Definition: VMStubsMEMemory.h:16
Reference_intrackfit_cff.barrel
list barrel
Definition: Reference_intrackfit_cff.py:37
trklet::TrackletLUT::lookup
int lookup(unsigned int index) const
Definition: TrackletLUT.cc:900
trklet::MatchEngineUnit::havepair_
bool havepair_
Definition: MatchEngineUnit.h:95
TrackletLUT.h
trklet::VMStubME::isPSmodule
bool isPSmodule() const
Definition: VMStubME.h:30
trklet::MatchEngineUnit::init
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)
Definition: MatchEngineUnit.cc:18
trklet::VMStubsMEMemory::getVMStubMEBin
const VMStubME & getVMStubMEBin(unsigned int bin, unsigned int i) const
Definition: VMStubsMEMemory.h:35
trklet::TrackletLUT
Definition: TrackletLUT.h:12
trklet::MatchEngineUnit::projrinv_
int projrinv_
Definition: MatchEngineUnit.h:78
cms::cuda::assert
assert(be >=bs)
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
trklet::MatchEngineUnit::peek
std::pair< Tracklet *, const Stub * > peek() const
Definition: MatchEngineUnit.h:47
trklet::VMStubME::bend
const FPGAWord & bend() const
Definition: VMStubME.h:26
trklet::Tracklet
Definition: Tracklet.h:27
trklet::MatchEngineUnit::layerdisk_
unsigned int layerdisk_
Definition: MatchEngineUnit.h:87
trklet::MatchEngineUnit::istub_
unsigned int istub_
Definition: MatchEngineUnit.h:74
trklet::Tracklet::trackletIndex
int trackletIndex() const
Definition: Tracklet.h:206
trklet::MatchEngineUnit::rzbin_
unsigned int rzbin_
Definition: MatchEngineUnit.h:70
trklet::MatchEngineUnit::luttable_
const TrackletLUT & luttable_
Definition: MatchEngineUnit.h:90
trklet::VMStubME::stub
const Stub * stub() const
Definition: VMStubME.h:28
trklet::MatchEngineUnit::goodpair__
bool goodpair__
Definition: MatchEngineUnit.h:94
trklet::NFINEPHIBITS
constexpr unsigned int NFINEPHIBITS
Definition: Settings.h:34
trklet::MatchEngineUnit::candmatches_
CircularBuffer< std::pair< Tracklet *, const Stub * > > candmatches_
Definition: MatchEngineUnit.h:98
trklet::MatchEngineUnit::barrel_
bool barrel_
Definition: MatchEngineUnit.h:77
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:125
trklet::MatchEngineUnit::empty
bool empty() const
Definition: MatchEngineUnit.h:41
trklet::MatchEngineUnit::nrzbins_
unsigned int nrzbins_
Definition: MatchEngineUnit.h:69
amptDefault_cfi.proj
proj
Definition: amptDefault_cfi.py:13
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
trklet::Tracklet::TCID
int TCID() const
Definition: Tracklet.h:212
trklet::MatchEngineUnit::TCID
int TCID() const
Definition: MatchEngineUnit.cc:183
trklet::MatchEngineUnit::proj_
Tracklet * proj_
Definition: MatchEngineUnit.h:83
trklet::MatchEngineUnit::idle_
bool idle_
Definition: MatchEngineUnit.h:85
trklet::VMStubME::stubindex
const FPGAWord & stubindex() const
Definition: VMStubME.h:32
trklet::MatchEngineUnit::vmstubsmemory_
VMStubsMEMemory * vmstubsmemory_
Definition: MatchEngineUnit.h:67
MatchEngineUnit.h
trklet::MatchEngineUnit::step
void step(bool print)
Definition: MatchEngineUnit.cc:76
trklet::MatchEngineUnit::use_
std::vector< std::pair< unsigned int, unsigned int > > use_
Definition: MatchEngineUnit.h:81
trklet
Definition: AllInnerStubsMemory.h:10
trklet::FPGAWord::value
int value() const
Definition: FPGAWord.h:24
trklet::MatchEngineUnit::reset
void reset()
Definition: MatchEngineUnit.cc:173
std
Definition: JetResolutionObject.h:76
trklet::MatchEngineUnit::isPSseed_
bool isPSseed_
Definition: MatchEngineUnit.h:82
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
trklet::NFINERZBITS
constexpr unsigned int NFINERZBITS
Definition: Settings.h:33
trklet::MatchEngineUnit::havepair__
bool havepair__
Definition: MatchEngineUnit.h:95
trklet::MatchEngineUnit::shift_
int shift_
Definition: MatchEngineUnit.h:72
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
trklet::MatchEngineUnit::tmppair_
std::pair< Tracklet *, const Stub * > tmppair_
Definition: MatchEngineUnit.h:93
trklet::MatchEngineUnit::projfinephi_
int projfinephi_
Definition: MatchEngineUnit.h:80
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
trklet::MatchEngineUnit::projfinerz_
int projfinerz_
Definition: MatchEngineUnit.h:79
trklet::MatchEngineUnit::iuse_
unsigned int iuse_
Definition: MatchEngineUnit.h:75
trklet::MatchEngineUnit::phibin_
unsigned int phibin_
Definition: MatchEngineUnit.h:71
trklet::MatchEngineUnit::idle
bool idle() const
Definition: MatchEngineUnit.h:51
trklet::VMStubME::finerz
const FPGAWord & finerz() const
Definition: VMStubME.h:24
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
trklet::VMStubME::finephi
const FPGAWord & finephi() const
Definition: VMStubME.h:23
trklet::VMStubME
Definition: VMStubME.h:15
trklet::VMStubsMEMemory::nStubsBin
unsigned int nStubsBin(unsigned int bin) const
Definition: VMStubsMEMemory.h:30
trklet::MatchEngineUnit::tmppair__
std::pair< Tracklet *, const Stub * > tmppair__
Definition: MatchEngineUnit.h:93
trklet::MatchEngineUnit::goodpair_
bool goodpair_
Definition: MatchEngineUnit.h:94