CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
trklet::MatchEngine Class Reference

#include <MatchEngine.h>

Inheritance diagram for trklet::MatchEngine:
trklet::ProcessBase

Public Member Functions

void addInput (MemoryBase *memory, std::string input) override
 
void addOutput (MemoryBase *memory, std::string output) override
 
void execute ()
 
 MatchEngine (std::string name, Settings const &settings, Globals *global, unsigned int iSector)
 
 ~MatchEngine () override=default
 
- Public Member Functions inherited from trklet::ProcessBase
unsigned int getISeed (std::string name)
 
std::string const & getName () const
 
unsigned int initLayerDisk (unsigned int pos)
 
void initLayerDisk (unsigned int pos, int &layer, int &disk)
 
void initLayerDisk (unsigned int pos, int &layer, int &disk, int &layerdisk)
 
void initLayerDisksandISeed (unsigned int &layerdisk1, unsigned int &layerdisk2, unsigned int &iSeed)
 
unsigned int nbits (unsigned int power)
 
 ProcessBase (std::string name, Settings const &settings, Globals *global, unsigned int iSector)
 
virtual ~ProcessBase ()=default
 

Private Attributes

CandidateMatchMemorycandmatches_
 
int disk_
 
int layer_
 
std::vector< bool > table2S_
 
std::vector< bool > table_
 
std::vector< bool > tablePS_
 
VMProjectionsMemoryvmprojs_
 
VMStubsMEMemoryvmstubs_
 

Additional Inherited Members

- Protected Attributes inherited from trklet::ProcessBase
Globalsglobals_
 
unsigned int iSector_
 
std::string name_
 
double phimax_
 
double phimin_
 
Settings const & settings_
 

Detailed Description

Definition at line 16 of file MatchEngine.h.

Constructor & Destructor Documentation

◆ MatchEngine()

MatchEngine::MatchEngine ( std::string  name,
Settings const &  settings,
Globals global,
unsigned int  iSector 
)

Definition at line 16 of file MatchEngine.cc.

17  : ProcessBase(name, settings, global, iSector) {
18  layer_ = 0;
19  disk_ = 0;
20  string subname = name.substr(3, 2);
21  if (subname.substr(0, 1) == "L")
22  layer_ = stoi(subname.substr(1, 1));
23  else if (subname.substr(0, 1) == "D")
24  disk_ = stoi(subname.substr(1, 1));
25  else
26  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " " << name << " subname = " << subname << " "
27  << layer_ << " " << disk_;
28 
29  if (layer_ > 0) {
30  unsigned int nbits = 3;
31  if (layer_ >= 4)
32  nbits = 4;
33 
34  for (unsigned int irinv = 0; irinv < 32; irinv++) {
35  double rinv = (irinv - 15.5) * (1 << (settings_.nbitsrinv() - 5)) * settings_.krinvpars();
36 
37  double stripPitch =
39  double projbend = bend(settings_.rmean(layer_ - 1), rinv, stripPitch);
40  for (unsigned int ibend = 0; ibend < (unsigned int)(1 << nbits); ibend++) {
41  double stubbend = benddecode(ibend, layer_ <= 3);
42  bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(layer_ - 1);
43  table_.push_back(pass);
44  }
45  }
46 
47  if (settings_.writeTable()) {
48  ofstream out;
49  char layer = '0' + layer_;
50  string fname = "METable_L";
51  fname += layer;
52  fname += ".tab";
53  out.open(fname.c_str());
54  out << "{" << endl;
55  for (unsigned int i = 0; i < table_.size(); i++) {
56  if (i != 0) {
57  out << "," << endl;
58  }
59  out << table_[i];
60  }
61  out << "};" << endl;
62  out.close();
63  }
64  }
65 
66  if (disk_ > 0) {
67  for (unsigned int iprojbend = 0; iprojbend < 32; iprojbend++) {
68  double projbend = 0.5 * (iprojbend - 15.0);
69  for (unsigned int ibend = 0; ibend < 8; ibend++) {
70  double stubbend = benddecode(ibend, true);
71  bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(disk_ + 5);
72  tablePS_.push_back(pass);
73  }
74  for (unsigned int ibend = 0; ibend < 16; ibend++) {
75  double stubbend = benddecode(ibend, false);
76  bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(disk_ + 5);
77  table2S_.push_back(pass);
78  }
79  }
80  }
81 }

References funct::abs(), trklet::bend(), trklet::Settings::bendcutme(), trklet::benddecode(), disk_, Exception, alignmentValidation::fname, mps_fire::i, createfilelist::int, trklet::Settings::krinvpars(), layer_, Skims_PA_cff::name, trklet::ProcessBase::nbits(), trklet::Settings::nbitsrinv(), MillePedeFileConverter_cfg::out, trklet::Settings::rcrit(), trklet::rinv(), trklet::Settings::rmean(), trklet::ProcessBase::settings_, trklet::Settings::stripPitch(), table2S_, table_, tablePS_, and trklet::Settings::writeTable().

◆ ~MatchEngine()

trklet::MatchEngine::~MatchEngine ( )
overridedefault

Member Function Documentation

◆ addInput()

void MatchEngine::addInput ( MemoryBase memory,
std::string  input 
)
overridevirtual

Implements trklet::ProcessBase.

Definition at line 97 of file MatchEngine.cc.

97  {
98  if (settings_.writetrace()) {
99  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
100  << input;
101  }
102  if (input == "vmstubin") {
103  auto* tmp = dynamic_cast<VMStubsMEMemory*>(memory);
104  assert(tmp != nullptr);
105  vmstubs_ = tmp;
106  return;
107  }
108  if (input == "vmprojin") {
109  auto* tmp = dynamic_cast<VMProjectionsMemory*>(memory);
110  assert(tmp != nullptr);
111  vmprojs_ = tmp;
112  return;
113  }
114  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input;
115 }

References cms::cuda::assert(), Exception, input, trklet::ProcessBase::name_, trklet::ProcessBase::settings_, createJobs::tmp, vmprojs_, vmstubs_, and trklet::Settings::writetrace().

◆ addOutput()

void MatchEngine::addOutput ( MemoryBase memory,
std::string  output 
)
overridevirtual

Implements trklet::ProcessBase.

Definition at line 83 of file MatchEngine.cc.

83  {
84  if (settings_.writetrace()) {
85  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
86  << output;
87  }
88  if (output == "matchout") {
89  auto* tmp = dynamic_cast<CandidateMatchMemory*>(memory);
90  assert(tmp != nullptr);
91  candmatches_ = tmp;
92  return;
93  }
94  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output: " << output;
95 }

References cms::cuda::assert(), candmatches_, Exception, trklet::ProcessBase::name_, convertSQLitetoXML_cfg::output, trklet::ProcessBase::settings_, createJobs::tmp, and trklet::Settings::writetrace().

◆ execute()

void MatchEngine::execute ( void  )

Definition at line 117 of file MatchEngine.cc.

117  {
118  bool barrel = layer_ > 0;
119 
120  unsigned int countall = 0;
121  unsigned int countpass = 0;
122 
123  constexpr unsigned int kNBitsBuffer = 3;
124 
125  int writeindex = 0;
126  int readindex = 0;
127  std::pair<int, int> projbuffer[1 << kNBitsBuffer]; //iproj zbin
128 
129  //The next projection to read, the number of projections and flag if we have more projections to read
130  int iproj = 0;
131  int nproj = vmprojs_->nTracklets();
132  bool moreproj = iproj < nproj;
133 
134  //Projection that is read from the buffer and compared to stubs
135  int rzbin = 0;
136  int projfinerz = 0;
137  int projfinerzadj = 0;
138 
139  int projindex = 0;
140  int projrinv = 0;
141  bool isPSseed = false;
142 
143  //Number of stubs for current zbin and the stub being processed on this clock
144  int nstubs = 0;
145  int istub = 0;
146 
147  //Main processing loops starts here
148  for (unsigned int istep = 0; istep < settings_.maxStep("ME"); istep++) {
149  countall++;
150 
151  int writeindexplus = (writeindex + 1) % (1 << kNBitsBuffer);
152  int writeindexplusplus = (writeindex + 2) % (1 << kNBitsBuffer);
153 
154  //Determine if buffer is full - or near full as a projection
155  //can point to two z bins we might fill two slots in the buffer
156  bool bufferfull = (writeindexplus == readindex) || (writeindexplusplus == readindex);
157 
158  //Determin if buffer is empty
159  bool buffernotempty = (writeindex != readindex);
160 
161  //If we have more projections and the buffer is not full we read
162  //next projection and put in buffer if there are stubs in the
163  //memory the projection points to
164 
165  if ((!moreproj) && (!buffernotempty))
166  break;
167 
168  if (moreproj && (!bufferfull)) {
169  Tracklet* proj = vmprojs_->getTracklet(iproj);
170 
171  int iprojtmp = iproj;
172 
173  iproj++;
174  moreproj = iproj < nproj;
175 
176  unsigned int rzfirst = barrel ? proj->zbin1projvm(layer_) : proj->rbin1projvm(disk_);
177  unsigned int rzlast = rzfirst;
178  bool second = (barrel ? proj->zbin2projvm(layer_) : proj->rbin2projvm(disk_)) == 1;
179  if (second)
180  rzlast += 1;
181 
182  //Check if there are stubs in the memory
183  int nstubfirst = vmstubs_->nStubsBin(rzfirst);
184  int nstublast = vmstubs_->nStubsBin(rzlast);
185  bool savefirst = nstubfirst != 0;
186  bool savelast = second && (nstublast != 0);
187 
188  int writeindextmp = writeindex;
189  int writeindextmpplus = (writeindex + 1) % (1 << kNBitsBuffer);
190 
191  if (savefirst && savelast) {
192  writeindex = writeindexplusplus;
193  } else if (savefirst || savelast) {
194  writeindex = writeindexplus;
195  }
196 
197  if (savefirst) { //TODO for HLS (make code logic simpler)
198  std::pair<int, int> tmp(iprojtmp, rzfirst);
199  projbuffer[writeindextmp] = tmp;
200  }
201  if (savelast) {
202  std::pair<int, int> tmp(iprojtmp, rzlast + 100); //TODO for HLS (fix flagging that this is second bin)
203  if (savefirst) {
204  projbuffer[writeindextmpplus] = tmp;
205  } else {
206  projbuffer[writeindextmp] = tmp;
207  }
208  }
209  }
210 
211  //If the buffer is not empty we have a projection that we need to process.
212 
213  if (buffernotempty) {
214  int istubtmp = istub;
215 
216  //New projection
217  if (istub == 0) {
218  projindex = projbuffer[readindex].first;
219  rzbin = projbuffer[readindex].second;
220  bool second = false;
221  if (rzbin >= 100) {
222  rzbin -= 100;
223  second = true;
224  }
225 
226  Tracklet* proj = vmprojs_->getTracklet(projindex);
227 
228  nstubs = vmstubs_->nStubsBin(rzbin);
229 
230  projfinerz = barrel ? proj->finezvm(layer_) : proj->finervm(disk_);
231 
232  projrinv =
233  barrel
234  ? (16 + (((-2) * proj->fpgaphiprojder(layer_).value()) >> (proj->fpgaphiprojder(layer_).nbits() - 4)))
235  : proj->getBendIndex(disk_).value();
236  assert(projrinv >= 0);
237  if (settings_.extended() && projrinv == 32) {
238  if (settings_.debugTracklet()) {
239  edm::LogVerbatim("Tracklet") << "Extended tracking, projrinv:" << projrinv;
240  }
241  projrinv = 31;
242  }
243  assert(projrinv < 32);
244 
245  isPSseed = proj->PSseed() == 1;
246 
247  //Calculate fine z position
248  if (second) {
249  projfinerzadj = projfinerz - 8;
250  } else {
251  projfinerzadj = projfinerz;
252  }
253  if (nstubs == 1) {
254  istub = 0;
255  readindex = (readindex + 1) % (1 << kNBitsBuffer);
256  } else {
257  istub++;
258  }
259  } else {
260  //Check if last stub, if so, go to next buffer entry
261  if (istub + 1 >= nstubs) {
262  istub = 0;
263  readindex = (readindex + 1) % (1 << kNBitsBuffer);
264  } else {
265  istub++;
266  }
267  }
268 
269  //Read vmstub memory and extract data fields
270  const VMStubME& vmstub = vmstubs_->getVMStubMEBin(rzbin, istubtmp);
271 
272  bool isPSmodule = vmstub.isPSmodule();
273 
274  int stubfinerz = vmstub.finerz().value();
275 
276  int nbits = isPSmodule ? 3 : 4;
277 
278  //TODO - should use finephi information to reduce combinatorics
279 
280  unsigned int index = (projrinv << nbits) + vmstub.bend().value();
281 
282  //Check if stub z position consistent
283  int idrz = stubfinerz - projfinerzadj;
284  bool pass;
285 
286  if (barrel) {
287  if (isPSseed) {
288  pass = idrz >= -2 && idrz <= 2;
289  } else {
290  pass = idrz >= -5 && idrz <= 5;
291  }
292  } else {
293  if (isPSmodule) {
294  pass = idrz >= -1 && idrz <= 1;
295  } else {
296  pass = idrz >= -5 && idrz <= 5;
297  }
298  }
299 
300  //Check if stub bend and proj rinv consistent
301  if (pass) {
302  if (barrel ? table_[index] : (isPSmodule ? tablePS_[index] : table2S_[index])) {
303  Tracklet* proj = vmprojs_->getTracklet(projindex);
304  std::pair<Tracklet*, int> tmp(proj, vmprojs_->getAllProjIndex(projindex));
305  if (settings_.writeMonitorData("Seeds")) {
306  ofstream fout("seeds.txt", ofstream::app);
307  fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << proj->getISeed() << endl;
308  fout.close();
309  }
310  candmatches_->addMatch(tmp, vmstub.stub());
311  countpass++;
312  }
313  }
314  }
315  }
316 
317  if (settings_.writeMonitorData("ME")) {
318  globals_->ofstream("matchengine.txt") << getName() << " " << countall << " " << countpass << endl;
319  }
320 }

References trklet::CandidateMatchMemory::addMatch(), cms::cuda::assert(), Reference_intrackfit_cff::barrel, trklet::VMStubME::bend(), candmatches_, trklet::Settings::debugTracklet(), disk_, trklet::Settings::extended(), trklet::VMStubME::finerz(), groupFilesInBlocks::fout, trklet::VMProjectionsMemory::getAllProjIndex(), trklet::ProcessBase::getName(), trklet::VMProjectionsMemory::getTracklet(), trklet::VMStubsMEMemory::getVMStubMEBin(), trklet::ProcessBase::globals_, trklet::ProcessBase::iSector_, trklet::VMStubME::isPSmodule(), layer_, trklet::Settings::maxStep(), trklet::ProcessBase::name_, trklet::ProcessBase::nbits(), trklet::VMStubsMEMemory::nStubsBin(), trklet::VMProjectionsMemory::nTracklets(), trklet::Globals::ofstream(), amptDefault_cfi::proj, edm::second(), trklet::ProcessBase::settings_, trklet::VMStubME::stub(), table2S_, table_, tablePS_, createJobs::tmp, trklet::FPGAWord::value(), vmprojs_, vmstubs_, and trklet::Settings::writeMonitorData().

Member Data Documentation

◆ candmatches_

CandidateMatchMemory* trklet::MatchEngine::candmatches_
private

Definition at line 31 of file MatchEngine.h.

Referenced by addOutput(), and execute().

◆ disk_

int trklet::MatchEngine::disk_
private

Definition at line 34 of file MatchEngine.h.

Referenced by execute(), and MatchEngine().

◆ layer_

int trklet::MatchEngine::layer_
private

Definition at line 33 of file MatchEngine.h.

Referenced by execute(), and MatchEngine().

◆ table2S_

std::vector<bool> trklet::MatchEngine::table2S_
private

Definition at line 41 of file MatchEngine.h.

Referenced by execute(), and MatchEngine().

◆ table_

std::vector<bool> trklet::MatchEngine::table_
private

Definition at line 37 of file MatchEngine.h.

Referenced by execute(), and MatchEngine().

◆ tablePS_

std::vector<bool> trklet::MatchEngine::tablePS_
private

Definition at line 40 of file MatchEngine.h.

Referenced by execute(), and MatchEngine().

◆ vmprojs_

VMProjectionsMemory* trklet::MatchEngine::vmprojs_
private

Definition at line 29 of file MatchEngine.h.

Referenced by addInput(), and execute().

◆ vmstubs_

VMStubsMEMemory* trklet::MatchEngine::vmstubs_
private

Definition at line 28 of file MatchEngine.h.

Referenced by addInput(), and execute().

trklet::MatchEngine::layer_
int layer_
Definition: MatchEngine.h:33
trklet::MatchEngine::vmprojs_
VMProjectionsMemory * vmprojs_
Definition: MatchEngine.h:29
trklet::MatchEngine::table2S_
std::vector< bool > table2S_
Definition: MatchEngine.h:41
mps_fire.i
i
Definition: mps_fire.py:355
trklet::Settings::writetrace
bool writetrace() const
Definition: Settings.h:145
input
static const std::string input
Definition: EdmProvDump.cc:48
Reference_intrackfit_cff.barrel
list barrel
Definition: Reference_intrackfit_cff.py:37
trklet::VMProjectionsMemory::nTracklets
unsigned int nTracklets() const
Definition: VMProjectionsMemory.h:22
trklet::Settings::krinvpars
double krinvpars() const
Definition: Settings.h:325
trklet::MatchEngine::disk_
int disk_
Definition: MatchEngine.h:34
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
trklet::VMStubME::isPSmodule
bool isPSmodule() const
Definition: VMStubME.h:30
trklet::VMStubsMEMemory::getVMStubMEBin
const VMStubME & getVMStubMEBin(unsigned int bin, unsigned int i) const
Definition: VMStubsMEMemory.h:33
trklet::CandidateMatchMemory::addMatch
void addMatch(std::pair< Tracklet *, int > tracklet, const Stub *stub)
Definition: CandidateMatchMemory.cc:15
cms::cuda::assert
assert(be >=bs)
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
trklet::Settings::rmean
double rmean(unsigned int iLayer) const
Definition: Settings.h:126
trklet::VMStubME::bend
const FPGAWord & bend() const
Definition: VMStubME.h:26
trklet::ProcessBase::nbits
unsigned int nbits(unsigned int power)
Definition: ProcessBase.cc:29
trklet::ProcessBase::settings_
Settings const & settings_
Definition: ProcessBase.h:44
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
trklet::Settings::writeTable
bool writeTable() const
Definition: Settings.h:151
trklet::Tracklet
Definition: Tracklet.h:28
trklet::MatchEngine::table_
std::vector< bool > table_
Definition: MatchEngine.h:37
trklet::VMStubME::stub
const Stub * stub() const
Definition: VMStubME.h:28
trklet::VMProjectionsMemory::getAllProjIndex
int getAllProjIndex(unsigned int i) const
Definition: VMProjectionsMemory.h:25
trklet::Settings::bendcutme
double bendcutme(unsigned int layerdisk) const
Definition: Settings.h:109
amptDefault_cfi.proj
proj
Definition: amptDefault_cfi.py:13
trklet::rinv
double rinv(double phi1, double phi2, double r1, double r2)
Definition: Util.h:167
trklet::Settings::extended
bool extended() const
Definition: Settings.h:205
groupFilesInBlocks.fout
fout
Definition: groupFilesInBlocks.py:162
createfilelist.int
int
Definition: createfilelist.py:10
trklet::MatchEngine::tablePS_
std::vector< bool > tablePS_
Definition: MatchEngine.h:40
edm::LogVerbatim
Definition: MessageLogger.h:297
trklet::Settings::nbitsrinv
int nbitsrinv() const
Definition: Settings.h:275
trklet::FPGAWord::value
int value() const
Definition: FPGAWord.h:24
trklet::Settings::stripPitch
double stripPitch(bool isPSmodule) const
Definition: Settings.h:217
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
trklet::Settings::writeMonitorData
bool writeMonitorData(std::string module) const
Definition: Settings.h:84
trklet::MatchEngine::candmatches_
CandidateMatchMemory * candmatches_
Definition: MatchEngine.h:31
trklet::Globals::ofstream
std::ofstream & ofstream(std::string fname)
Definition: Globals.cc:44
trklet::bend
double bend(double r, double rinv, double stripPitch)
Definition: Util.h:160
Exception
Definition: hltDiff.cc:246
trklet::ProcessBase::getName
std::string const & getName() const
Definition: ProcessBase.h:22
trklet::ProcessBase::name_
std::string name_
Definition: ProcessBase.h:38
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
trklet::ProcessBase::iSector_
unsigned int iSector_
Definition: ProcessBase.h:39
trklet::Settings::debugTracklet
bool debugTracklet() const
Definition: Settings.h:144
trklet::Settings::rcrit
double rcrit() const
Definition: Settings.h:234
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
trklet::Settings::maxStep
unsigned int maxStep(std::string module) const
Definition: Settings.h:91
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
trklet::VMProjectionsMemory::getTracklet
Tracklet * getTracklet(unsigned int i)
Definition: VMProjectionsMemory.h:24
trklet::benddecode
double benddecode(int ibend, bool isPS)
Definition: Util.h:100
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::ProcessBase::globals_
Globals * globals_
Definition: ProcessBase.h:45
trklet::ProcessBase::ProcessBase
ProcessBase(std::string name, Settings const &settings, Globals *global, unsigned int iSector)
Definition: ProcessBase.cc:14
trklet::VMStubME
Definition: VMStubME.h:15
trklet::MatchEngine::vmstubs_
VMStubsMEMemory * vmstubs_
Definition: MatchEngine.h:28
trklet::VMStubsMEMemory::nStubsBin
unsigned int nStubsBin(unsigned int bin) const
Definition: VMStubsMEMemory.h:28
memory
Definition: vlib.h:178