CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MatchProcessor.cc
Go to the documentation of this file.
5 
10 
11 #include <filesystem>
12 
13 using namespace std;
14 using namespace trklet;
15 
16 MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* global)
17  : ProcessBase(name, settings, global),
18  phimatchcuttable_(settings),
19  zmatchcuttable_(settings),
20  rphicutPStable_(settings),
21  rphicut2Stable_(settings),
22  rcutPStable_(settings),
23  rcut2Stable_(settings),
24  fullmatches_(12),
25  rinvbendlut_(settings),
26  luttable_(settings),
27  inputProjBuffer_(3) {
28  phiregion_ = name[8] - 'A';
29 
31 
33 
36 
37  if (barrel_) {
40  } else {
43  }
44 
46 
47  nrbits_ = 5;
48  nphiderbits_ = 6;
49 
50  if (!barrel_) {
53  }
54 
55  nrinv_ = NRINVBITS;
56 
57  unsigned int region = getName()[8] - 'A';
59 
60  if (barrel_) {
61  phimatchcuttable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::barrelphi, region);
62  zmatchcuttable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::barrelz, region);
63  } else {
64  rphicutPStable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::diskPSphi, region);
65  rphicut2Stable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::disk2Sphi, region);
66  rcutPStable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::diskPSr, region);
67  rcut2Stable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::disk2Sr, region);
68  }
69 
70  for (unsigned int i = 0; i < N_DSS_MOD * 2; i++) {
72  (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSinner(i) * settings_.rDSSinner(i)) /
73  settings_.kphi();
75  (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSouter(i) * settings_.rDSSouter(i)) /
76  settings_.kphi();
77  }
78 
82 
83  nMatchEngines_ = 4;
84  for (unsigned int iME = 0; iME < nMatchEngines_; iME++) {
86  matchengines_.push_back(tmpME);
87  }
88 }
89 
91  if (settings_.writetrace()) {
92  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
93  << output;
94  }
95  if (output.find("matchout") != std::string::npos) {
96  auto* tmp = dynamic_cast<FullMatchMemory*>(memory);
97  assert(tmp != nullptr);
98  unsigned int iSeed = getISeed(tmp->getName());
99  assert(iSeed < fullmatches_.size());
100  assert(fullmatches_[iSeed] == nullptr);
101  fullmatches_[iSeed] = tmp;
102  return;
103  }
104  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output: " << output;
105 }
106 
108  if (settings_.writetrace()) {
109  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
110  << input;
111  }
112  if (input == "allstubin") {
113  auto* tmp = dynamic_cast<AllStubsMemory*>(memory);
114  assert(tmp != nullptr);
115  allstubs_ = tmp;
116  return;
117  }
118  if (input == "vmstubin") {
119  auto* tmp = dynamic_cast<VMStubsMEMemory*>(memory);
120  assert(tmp != nullptr);
121  vmstubs_.push_back(tmp); //to allow more than one stub in? vmstubs_=tmp;
122  return;
123  }
124  if (input == "projin") {
125  auto* tmp = dynamic_cast<TrackletProjectionsMemory*>(memory);
126  assert(tmp != nullptr);
127  inputprojs_.push_back(tmp);
128  return;
129  }
130  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input;
131 }
132 
133 void MatchProcessor::execute(unsigned int iSector, double phimin) {
134  assert(vmstubs_.size() == 1);
135 
136  /*
137  The code is organized in three 'steps' corresponding to the PR, ME, and MC functions. The output from
138  the PR step is buffered in a 'circular' buffer, and similarly the ME output is put in a circular buffer.
139 
140  The implementation is done in steps, emulating what can be done in firmware. One each step we do:
141 
142  1) A projection is read and if there is space it is insert into the inputProjBuffer_
143 
144  2) Process next match in the ME - if there is an idle ME the next projection is inserted
145 
146  3) Readout match from ME and send to match calculator
147 
148  */
149 
150  bool print = getName() == "MP_L3PHIC" && iSector == 3;
151  print = false;
152 
153  phimin_ = phimin;
154 
155  Tracklet* oldTracklet = nullptr;
156 
157  unsigned int countme = 0;
158  unsigned int countall = 0;
159  unsigned int countsel = 0;
160  unsigned int countinputproj = 0;
161 
162  unsigned int iprojmem = 0;
163  while (iprojmem < inputprojs_.size() && inputprojs_[iprojmem]->nTracklets() == 0) {
164  iprojmem++;
165  }
166 
167  unsigned int iproj = 0;
168 
169  inputProjBuffer_.reset();
170 
171  for (const auto& inputproj : inputprojs_) {
172  countinputproj += inputproj->nTracklets();
173  }
174 
175  for (auto& matchengine : matchengines_) {
176  matchengine.reset();
177  }
178 
179  ProjectionTemp tmpProj_, tmpProj__;
180  bool good_ = false;
181  bool good__ = false;
182 
183  for (unsigned int istep = 0; istep < settings_.maxStep("MP"); istep++) {
184  bool projBuffNearFull = inputProjBuffer_.nearfull();
185 
186  // This print statement is useful for detailed comparison with the HLS code
187  // It prints out detailed status information for each clock step
188  /*
189  if (print) {
190  cout << "istep = "<<istep<<" projBuff: "<<inputProjBuffer_.rptr()<<" "<<inputProjBuffer_.wptr()<<" "<<projBuffNearFull;
191  unsigned int iMEU = 0;
192  for (auto& matchengine : matchengines_) {
193  cout <<" MEU"<<iMEU<<": "<<matchengine.rptr()<<" "<<matchengine.wptr()
194  <<" "<<matchengine.idle()<<" "<<matchengine.empty()
195  <<" "<<matchengine.have_()<<matchengine.have__()
196  <<" "<<matchengine.TCID();
197  iMEU++;
198  }
199  cout << std::endl;
200  }
201  */
202 
203  bool projdone = false;
204 
205  //Step 3
206  //Check if we have candidate match to process
207 
208  unsigned int iMEbest = 0;
209  int bestTCID = matchengines_[0].TCID();
210  bool meactive = matchengines_[0].active();
211  for (unsigned int iME = 1; iME < nMatchEngines_; iME++) {
212  meactive = meactive || matchengines_[iME].active();
213  int tcid = matchengines_[iME].TCID();
214  if (tcid < bestTCID) {
215  bestTCID = tcid;
216  iMEbest = iME;
217  }
218  }
219 
220  if (!matchengines_[iMEbest].empty()) {
221  std::pair<Tracklet*, const Stub*> candmatch = matchengines_[iMEbest].read();
222 
223  const Stub* fpgastub = candmatch.second;
224  Tracklet* tracklet = candmatch.first;
225 
226  if (oldTracklet != nullptr) {
227  //allow equal here since we can have more than one cadidate match per tracklet projection
228  //cout << "old new : "<<oldTracklet->TCID()<<" "<<tracklet->TCID()<<" "<<iMEbest<<endl;
229  assert(oldTracklet->TCID() <= tracklet->TCID());
230  }
231  oldTracklet = tracklet;
232 
233  bool match = matchCalculator(tracklet, fpgastub, print, istep);
234 
235  if (settings_.debugTracklet() && match) {
236  edm::LogVerbatim("Tracklet") << getName() << " have match";
237  }
238 
239  countall++;
240  if (match)
241  countsel++;
242  }
243 
244  //Step 2
245  //Check if we have ME that can process projection
246 
247  bool addedProjection = false;
248  for (unsigned int iME = 0; iME < nMatchEngines_; iME++) {
249  if (!matchengines_[iME].idle())
250  countme++;
251  //if match engine empty and we have queued projections add to match engine
252  if ((!addedProjection) && matchengines_[iME].idle() && (!inputProjBuffer_.empty())) {
253  ProjectionTemp tmpProj = inputProjBuffer_.read();
254  VMStubsMEMemory* stubmem = vmstubs_[0];
255 
256  if (settings_.debugTracklet()) {
257  edm::LogVerbatim("Tracklet") << getName() << " adding projection to match engine";
258  }
259 
260  int nbins = (1 << N_RZBITS);
261  if (layerdisk_ >= N_LAYER) {
262  nbins *= 2; //twice as many bins in disks (since there are two disks)
263  }
264 
265  matchengines_[iME].init(stubmem,
266  nbins,
267  tmpProj.slot(),
268  tmpProj.iphi(),
269  tmpProj.shift(),
270  tmpProj.projrinv(),
271  tmpProj.projfinerz(),
272  tmpProj.projfinephi(),
273  tmpProj.use(0, 0),
274  tmpProj.use(0, 1),
275  tmpProj.use(1, 0),
276  tmpProj.use(1, 1),
277  tmpProj.isPSseed(),
278  tmpProj.proj(),
279  print && (iME == 0));
280  addedProjection = true;
281  } else {
282  matchengines_[iME].step(print && iME == 0);
283  }
284  }
285 
286  //Step 1
287  //First step here checks if we have more input projections to put into
288  //the input puffer for projections
289 
290  if (good__) {
291  inputProjBuffer_.store(tmpProj__);
292  }
293 
294  good__ = good_;
295  tmpProj__ = tmpProj_;
296 
297  good_ = false;
298 
299  if (istep < settings_.maxStep("MP")) {
300  if (iprojmem < inputprojs_.size()) {
301  TrackletProjectionsMemory* projMem = inputprojs_[iprojmem];
302  if (!projBuffNearFull) {
303  if (settings_.debugTracklet()) {
304  edm::LogVerbatim("Tracklet") << getName() << " have projection in memory : " << projMem->getName();
305  }
306 
307  Tracklet* proj = projMem->getTracklet(iproj);
308 
309  FPGAWord fpgaphi = proj->proj(layerdisk_).fpgaphiproj();
310 
311  unsigned int iphi = (fpgaphi.value() >> (fpgaphi.nbits() - nvmbits_)) & (nvmbins_ - 1);
312 
313  int nextrabits = 2;
314  int overlapbits = nvmbits_ + nextrabits;
315 
316  unsigned int extrabits = fpgaphi.bits(fpgaphi.nbits() - overlapbits, nextrabits);
317 
318  unsigned int ivmPlus = iphi;
319 
320  int shift = 0;
321 
322  if (extrabits == ((1U << nextrabits) - 1) && iphi != ((1U << settings_.nbitsvmme(layerdisk_)) - 1)) {
323  shift = 1;
324  ivmPlus++;
325  }
326  unsigned int ivmMinus = iphi;
327  if (extrabits == 0 && iphi != 0) {
328  shift = -1;
329  ivmMinus--;
330  }
331 
332  int projrinv = -1;
333  if (barrel_) {
334  FPGAWord phider = proj->proj(layerdisk_).fpgaphiprojder();
335  projrinv = (1 << (nrinv_ - 1)) - 1 - (phider.value() >> (phider.nbits() - nrinv_));
336  } else {
337  //The next lines looks up the predicted bend based on:
338  // 1 - r projections
339  // 2 - phi derivative
340  // 3 - the sign - i.e. if track is forward or backward
341 
342  int rindex = (proj->proj(layerdisk_).fpgarzproj().value() >>
343  (proj->proj(layerdisk_).fpgarzproj().nbits() - nrbits_)) &
344  ((1 << nrbits_) - 1);
345 
346  int phiderindex = (proj->proj(layerdisk_).fpgaphiprojder().value() >>
348  ((1 << nphiderbits_) - 1);
349 
350  int signindex = proj->proj(layerdisk_).fpgarzprojder().value() < 0;
351 
352  int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex;
353 
354  projrinv = rinvbendlut_.lookup(bendindex);
355 
356  proj->proj(layerdisk_).setBendIndex(projrinv);
357  }
358  assert(projrinv >= 0);
359 
360  unsigned int slot = proj->proj(layerdisk_).fpgarzbin1projvm().value();
361  bool second = proj->proj(layerdisk_).fpgarzbin2projvm().value();
362 
363  unsigned int projfinephi =
364  (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + NFINEPHIBITS))) & ((1 << NFINEPHIBITS) - 1);
365  int projfinerz = proj->proj(layerdisk_).fpgafinerzvm().value();
366 
367  bool isPSseed = proj->PSseed();
368 
369  int nbins = (1 << N_RZBITS);
370  if (layerdisk_ >= N_LAYER) {
371  nbins *= 2; //twice as many bins in disks (since there are two disks)
372  }
373 
374  VMStubsMEMemory* stubmem = vmstubs_[0];
375  bool usefirstMinus = stubmem->nStubsBin(ivmMinus * nbins + slot) != 0;
376  bool usesecondMinus = (second && (stubmem->nStubsBin(ivmMinus * nbins + slot + 1) != 0));
377  bool usefirstPlus = ivmPlus != ivmMinus && stubmem->nStubsBin(ivmPlus * nbins + slot) != 0;
378  bool usesecondPlus = ivmPlus != ivmMinus && (second && (stubmem->nStubsBin(ivmPlus * nbins + slot + 1) != 0));
379 
380  good_ = usefirstPlus || usesecondPlus || usefirstMinus || usesecondMinus;
381 
382  if (good_) {
383  ProjectionTemp tmpProj(proj,
384  slot,
385  projrinv,
386  projfinerz,
387  projfinephi,
388  ivmMinus,
389  shift,
390  usefirstMinus,
391  usefirstPlus,
392  usesecondMinus,
393  usesecondPlus,
394  isPSseed);
395  tmpProj_ = tmpProj;
396  }
397 
398  iproj++;
399  if (iproj == projMem->nTracklets()) {
400  iproj = 0;
401  do {
402  iprojmem++;
403  } while (iprojmem < inputprojs_.size() && inputprojs_[iprojmem]->nTracklets() == 0);
404  }
405  }
406 
407  } else {
408  projdone = true && !good_ && !good__;
409  }
410  }
411 
412  //
413  // Check if done
414  //
415  //
416  //
417 
418  if ((projdone && !meactive) || (istep == settings_.maxStep("MP") - 1)) {
419  if (settings_.writeMonitorData("MP")) {
420  globals_->ofstream("matchprocessor.txt") << getName() << " " << istep << " " << countall << " " << countsel
421  << " " << countme << " " << countinputproj << endl;
422  }
423  break;
424  }
425  }
426 
427  if (settings_.writeMonitorData("MC")) {
428  globals_->ofstream("matchcalculator.txt") << getName() << " " << countall << " " << countsel << endl;
429  }
430 }
431 
432 bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, bool, unsigned int) {
433  const L1TStub* stub = fpgastub->l1tstub();
434 
435  if (layerdisk_ < N_LAYER) {
436  const Projection& proj = tracklet->proj(layerdisk_);
437  int ir = fpgastub->r().value();
438  int iphi = proj.fpgaphiproj().value();
439  int icorr = (ir * proj.fpgaphiprojder().value()) >> icorrshift_;
440  iphi += icorr;
441 
442  int iz = proj.fpgarzproj().value();
443  int izcor = (ir * proj.fpgarzprojder().value() + (1 << (icorzshift_ - 1))) >> icorzshift_;
444  iz += izcor;
445 
446  int ideltaz = fpgastub->z().value() - iz;
447  int ideltaphi = (fpgastub->phi().value() - iphi) << phishift_;
448 
449  //Floating point calculations
450 
451  double phi = stub->phi();
452  double r = stub->r();
453  double z = stub->z();
454 
455  if (settings_.useapprox()) {
456  double dphi = reco::reduceRange(phi - fpgastub->phiapprox(phimin_, 0.0));
457  assert(std::abs(dphi) < 0.001);
458  phi = fpgastub->phiapprox(phimin_, 0.0);
459  z = fpgastub->zapprox();
460  r = fpgastub->rapprox();
461  }
462 
463  if (phi < 0)
464  phi += 2 * M_PI;
465  phi -= phimin_;
466 
467  double dr = r - settings_.rmean(layerdisk_);
468  assert(std::abs(dr) < settings_.drmax());
469 
470  double dphi = reco::reduceRange(phi - (proj.phiproj() + dr * proj.phiprojder()));
471 
472  double dz = z - (proj.rzproj() + dr * proj.rzprojder());
473 
474  double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dr * proj.phiprojderapprox()));
475 
476  double dzapprox = z - (proj.rzprojapprox() + dr * proj.rzprojderapprox());
477 
478  int seedindex = tracklet->getISeed();
479 
480  assert(phimatchcuttable_.lookup(seedindex) > 0);
481  assert(zmatchcuttable_.lookup(seedindex) > 0);
482 
483  if (settings_.bookHistos()) {
484  bool truthmatch = tracklet->stubtruthmatch(stub);
485 
487  hists->FillLayerResidual(layerdisk_ + 1,
488  seedindex,
489  dphiapprox * settings_.rmean(layerdisk_),
490  ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_),
491  (ideltaz << dzshift_) * settings_.kz(),
492  dz,
493  truthmatch);
494  }
495 
496  if (settings_.writeMonitorData("Residuals")) {
497  double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv());
498 
499  globals_->ofstream("layerresiduals.txt")
500  << layerdisk_ + 1 << " " << seedindex << " " << pt << " "
501  << ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_) << " "
502  << dphiapprox * settings_.rmean(layerdisk_) << " "
503  << phimatchcuttable_.lookup(seedindex) * settings_.kphi1() * settings_.rmean(layerdisk_) << " "
504  << (ideltaz << dzshift_) * settings_.kz() << " " << dz << " "
505  << zmatchcuttable_.lookup(seedindex) * settings_.kz() << endl;
506  }
507 
508  bool imatch = (std::abs(ideltaphi) <= phimatchcuttable_.lookup(seedindex)) &&
509  (std::abs(ideltaz << dzshift_) <= zmatchcuttable_.lookup(seedindex));
510 
511  if (settings_.debugTracklet()) {
512  edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " ideltaphi cut " << ideltaphi << " "
513  << phimatchcuttable_.lookup(seedindex) << " ideltaz<<dzshift cut "
514  << (ideltaz << dzshift_) << " " << zmatchcuttable_.lookup(seedindex);
515  }
516 
517  //This would catch significant consistency problems in the configuration - helps to debug if there are problems.
518  if (std::abs(dphi) > 0.5 * settings_.dphisectorHG() || std::abs(dphiapprox) > 0.5 * settings_.dphisectorHG()) {
519  throw cms::Exception("LogicError") << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox
520  << endl;
521  }
522 
523  if (imatch) {
524  tracklet->addMatch(layerdisk_,
525  ideltaphi,
526  ideltaz,
527  dphi,
528  dz,
529  dphiapprox,
530  dzapprox,
531  (phiregion_ << N_BITSMEMADDRESS) + fpgastub->stubindex().value(),
532  fpgastub);
533 
534  if (settings_.debugTracklet()) {
535  edm::LogVerbatim("Tracklet") << "Accepted full match in layer " << getName() << " " << tracklet;
536  }
537 
538  int iSeed = tracklet->getISeed();
539  assert(fullmatches_[iSeed] != nullptr);
540  fullmatches_[iSeed]->addMatch(tracklet, fpgastub);
541 
542  return true;
543  } else {
544  return false;
545  }
546  } else { //disk matches
547 
548  //check that stubs and projections in same half of detector
549  assert(stub->z() * tracklet->t() > 0.0);
550 
551  int sign = (tracklet->t() > 0.0) ? 1 : -1;
552  int disk = sign * (layerdisk_ - N_LAYER + 1);
553  assert(disk != 0);
554 
555  //Perform integer calculations here
556 
557  int iz = fpgastub->z().value();
558 
559  const Projection& proj = tracklet->proj(layerdisk_);
560 
561  int iphi = proj.fpgaphiproj().value();
562  int iphicorr = (iz * proj.fpgaphiprojder().value()) >> icorrshift_;
563 
564  iphi += iphicorr;
565 
566  int ir = proj.fpgarzproj().value();
567  int ircorr = (iz * proj.fpgarzprojder().value()) >> icorzshift_;
568  ir += ircorr;
569 
570  int ideltaphi = fpgastub->phi().value() - iphi;
571 
572  int irstub = fpgastub->r().value();
573  int ialphafact = 0;
574  if (!stub->isPSmodule()) {
575  assert(irstub < (int)N_DSS_MOD * 2);
576  if (layerdisk_ - N_LAYER <= 1) {
577  ialphafact = ialphafactinner_[irstub];
578  irstub = settings_.rDSSinner(irstub) / settings_.kr();
579  } else {
580  ialphafact = ialphafactouter_[irstub];
581  irstub = settings_.rDSSouter(irstub) / settings_.kr();
582  }
583  }
584 
585  int ideltar = (irstub * settings_.kr()) / settings_.krprojshiftdisk() - ir;
586 
587  if (!stub->isPSmodule()) {
588  int ialpha = fpgastub->alpha().value();
589  int iphialphacor = ((ideltar * ialpha * ialphafact) >> settings_.alphashift());
590  ideltaphi += iphialphacor;
591  }
592 
593  //Perform floating point calculations here
594 
595  double phi = stub->phi();
596  double z = stub->z();
597  double r = stub->r();
598 
599  if (settings_.useapprox()) {
600  double dphi = reco::reduceRange(phi - fpgastub->phiapprox(phimin_, 0.0));
601  assert(std::abs(dphi) < 0.001);
602  phi = fpgastub->phiapprox(phimin_, 0.0);
603  z = fpgastub->zapprox();
604  r = fpgastub->rapprox();
605  }
606 
607  if (phi < 0)
608  phi += 2 * M_PI;
609  phi -= phimin_;
610 
611  double dz = z - sign * settings_.zmean(layerdisk_ - N_LAYER);
612 
613  if (std::abs(dz) > settings_.dzmax()) {
614  edm::LogProblem("Tracklet") << __FILE__ << ":" << __LINE__ << " " << name_ << " " << tracklet->getISeed();
615  edm::LogProblem("Tracklet") << "stub " << stub->z() << " disk " << disk << " " << dz;
616  assert(std::abs(dz) < settings_.dzmax());
617  }
618 
619  double phiproj = proj.phiproj() + dz * proj.phiprojder();
620  double rproj = proj.rzproj() + dz * proj.rzprojder();
621  double deltar = r - rproj;
622 
623  double dr = stub->r() - rproj;
624  double drapprox = stub->r() - (proj.rzprojapprox() + dz * proj.rzprojderapprox());
625 
626  double dphi = reco::reduceRange(phi - phiproj);
627 
628  double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dz * proj.phiprojderapprox()));
629 
630  double drphi = dphi * stub->r();
631  double drphiapprox = dphiapprox * stub->r();
632 
633  if (!stub->isPSmodule()) {
634  double alphanorm = stub->alphanorm();
635  dphi += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r2();
636  ;
637  dphiapprox += drapprox * alphanorm * settings_.half2SmoduleWidth() / stub->r2();
638 
639  drphi += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r();
640  drphiapprox += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r();
641  }
642 
643  int seedindex = tracklet->getISeed();
644 
645  int idrphicut = rphicutPStable_.lookup(seedindex);
646  int idrcut = rcutPStable_.lookup(seedindex);
647  if (!stub->isPSmodule()) {
648  idrphicut = rphicut2Stable_.lookup(seedindex);
649  idrcut = rcut2Stable_.lookup(seedindex);
650  }
651 
652  double drphicut = idrphicut * settings_.kphi() * settings_.kr();
653  double drcut = idrcut * settings_.krprojshiftdisk();
654 
655  if (settings_.writeMonitorData("Residuals")) {
656  double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv());
657 
658  globals_->ofstream("diskresiduals.txt")
659  << layerdisk_ - N_LAYER + 1 << " " << stub->isPSmodule() << " " << tracklet->layer() << " "
660  << abs(tracklet->disk()) << " " << pt << " " << ideltaphi * settings_.kphi() * stub->r() << " " << drphiapprox
661  << " " << drphicut << " " << ideltar * settings_.krprojshiftdisk() << " " << deltar << " " << drcut << " "
662  << endl;
663  }
664 
665  bool match = (std::abs(drphi) < drphicut) && (std::abs(deltar) < drcut);
666  bool imatch = (std::abs(ideltaphi * irstub) < idrphicut) && (std::abs(ideltar) < idrcut);
667 
668  if (settings_.debugTracklet()) {
669  edm::LogVerbatim("Tracklet") << "imatch match disk: " << imatch << " " << match << " " << std::abs(ideltaphi)
670  << " " << drphicut / (settings_.kphi() * stub->r()) << " " << std::abs(ideltar)
671  << " " << drcut / settings_.krprojshiftdisk() << " r = " << stub->r();
672  }
673 
674  if (imatch) {
675  if (settings_.debugTracklet()) {
676  edm::LogVerbatim("Tracklet") << "MatchCalculator found match in disk " << getName();
677  }
678 
679  if (std::abs(dphi) >= third * settings_.dphisectorHG()) {
680  edm::LogPrint("Tracklet") << "dphi " << dphi << " ISeed " << tracklet->getISeed();
681  }
683  assert(std::abs(dphiapprox) < third * settings_.dphisectorHG());
684 
685  tracklet->addMatch(layerdisk_,
686  ideltaphi,
687  ideltar,
688  drphi / stub->r(),
689  dr,
690  drphiapprox / stub->r(),
691  drapprox,
692  (phiregion_ << N_BITSMEMADDRESS) + fpgastub->stubindex().value(),
693  fpgastub);
694 
695  if (settings_.debugTracklet()) {
696  edm::LogVerbatim("Tracklet") << "Accepted full match in disk " << getName() << " " << tracklet;
697  }
698 
699  int iSeed = tracklet->getISeed();
700  assert(fullmatches_[iSeed] != nullptr);
701  fullmatches_[iSeed]->addMatch(tracklet, fpgastub);
702 
703  return true;
704  } else {
705  return false;
706  }
707  }
708 }
double r() const
Definition: L1TStub.h:58
const FPGAWord & stubindex() const
Definition: Stub.h:66
Log< level::Info, true > LogVerbatim
void initBendMatch(unsigned int layerdisk)
Definition: TrackletLUT.cc:443
constexpr unsigned int N_RZBITS
Definition: Settings.h:35
double dphisectorHG() const
Definition: Settings.h:281
double krbarrel() const
Definition: Settings.h:305
double rzproj() const
Definition: Projection.h:84
const FPGAWord & fpgafinerzvm() const
Definition: Projection.h:69
std::string name_
Definition: ProcessBase.h:38
double c() const
Definition: Settings.h:212
void initmatchcut(unsigned int layerdisk, MatchType type, unsigned int region)
Definition: TrackletLUT.cc:13
double r2() const
Definition: L1TStub.h:60
constexpr T reduceRange(T x)
Definition: deltaPhi.h:18
void addInput(MemoryBase *memory, std::string input) override
std::vector< MatchEngineUnit > matchengines_
const FPGAWord & fpgaphiproj() const
Definition: Projection.h:39
const FPGAWord & fpgaphiprojder() const
Definition: Projection.h:49
constexpr unsigned int NRINVBITS
Definition: Settings.h:32
int nbits() const
Definition: FPGAWord.h:25
void initProjectionBend(double k_phider, unsigned int idisk, unsigned int nrbits, unsigned int nphiderbits)
Definition: TrackletLUT.cc:393
double sign(double x)
int getISeed() const
Definition: Tracklet.cc:798
unsigned int nvmme(unsigned int layerdisk) const
Definition: Settings.h:104
double kphi() const
Definition: Settings.h:298
double phi() const
Definition: L1TStub.h:63
Projection & proj(int layerdisk)
Definition: Tracklet.h:87
Settings const & settings_
Definition: ProcessBase.h:40
TrackletLUT phimatchcuttable_
Globals * globals_
Definition: ProcessBase.h:41
double K() const
Definition: imath.h:246
unsigned int nphibitsstub(unsigned int layerdisk) const
Definition: Settings.h:83
double phiapprox(double phimin, double) const
Definition: Stub.cc:177
std::vector< TrackletProjectionsMemory * > inputprojs_
constexpr unsigned int N_DSS_MOD
Definition: Settings.h:27
assert(be >=bs)
bool debugTracklet() const
Definition: Settings.h:182
double half2SmoduleWidth() const
Definition: Settings.h:131
constexpr double third
Definition: Settings.h:42
static std::string const input
Definition: EdmProvDump.cc:47
double rmean(unsigned int iLayer) const
Definition: Settings.h:164
void addMatch(unsigned int layerdisk, int ideltaphi, int ideltarz, double dphi, double drz, double dphiapprox, double drzapprox, int stubid, const trklet::Stub *stubptr)
Definition: Tracklet.cc:295
unsigned int PSseed() const
Definition: Tracklet.h:220
U second(std::pair< T, U > const &p)
unsigned int projrinv() const
std::string const & getName() const
Definition: ProcessBase.h:22
double zmean(unsigned int iDisk) const
Definition: Settings.h:167
double zapprox() const
Definition: Stub.cc:158
std::string const & getName() const
Definition: MemoryBase.h:19
const FPGAWord & fpgarzprojder() const
Definition: Projection.h:54
int value() const
Definition: FPGAWord.h:24
double z() const
Definition: L1TStub.h:57
int ilog2(double factor)
Definition: Util.h:106
double kphiderdisk() const
Definition: Settings.h:394
int nbitsalpha() const
Definition: Settings.h:217
std::vector< FullMatchMemory * > fullmatches_
unsigned int iphi() const
double bfield() const
Definition: Settings.h:253
int TCID() const
Definition: Tracklet.h:212
unsigned int bits(unsigned int lsb, unsigned int nbit) const
Definition: FPGAWord.cc:74
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
IMATH_TrackletCalculator * ITC_L1L2()
Definition: Globals.h:48
unsigned int nallstubs(unsigned int layerdisk) const
Definition: Settings.h:107
unsigned int projfinephi() const
double rDSSouter(unsigned int iBin) const
Definition: Settings.h:174
L1TStub * l1tstub()
Definition: Stub.h:77
CircularBuffer< ProjectionTemp > inputProjBuffer_
unsigned int maxStep(std::string module) const
Definition: Settings.h:116
unsigned int isPSmodule() const
Definition: L1TStub.h:94
Log< level::Warning, true > LogPrint
double t() const
Definition: Tracklet.h:123
double krder() const
Definition: Settings.h:396
unsigned int nzbitsstub(unsigned int layerdisk) const
Definition: Settings.h:82
double kphi1() const
Definition: Settings.h:299
const FPGAWord & fpgarzbin1projvm() const
Definition: Projection.h:59
const FPGAWord & z() const
Definition: Stub.h:61
void initLayerDisk(unsigned int pos, int &layer, int &disk)
Definition: ProcessBase.cc:33
bool use(unsigned int nextrzbin, unsigned int nextiphibin) const
#define M_PI
double dzmax() const
Definition: Settings.h:129
TrackletLUT rphicutPStable_
int lookup(unsigned int index) const
Definition: TrackletLUT.cc:900
bool matchCalculator(Tracklet *tracklet, const Stub *fpgastub, bool print, unsigned int istep)
TrackletLUT rphicut2Stable_
int layer() const
Definition: Tracklet.cc:770
int ialphafactinner_[N_DSS_MOD *2]
const FPGAWord & phi() const
Definition: Stub.h:62
bool stubtruthmatch(const L1TStub *stub)
Definition: Tracklet.cc:138
void addOutput(MemoryBase *memory, std::string output) override
int alphashift() const
Definition: Settings.h:216
double rDSSinner(unsigned int iBin) const
Definition: Settings.h:171
constexpr unsigned int NFINEPHIBITS
Definition: Settings.h:34
double rinv() const
Definition: Tracklet.h:120
unsigned int nbitsallstubs(unsigned int layerdisk) const
Definition: Settings.h:106
const FPGAWord & fpgarzproj() const
Definition: Projection.h:44
double phiprojderapprox() const
Definition: Projection.h:109
list hists
Definition: compare.py:318
unsigned int getISeed(const std::string &name)
Definition: ProcessBase.cc:119
const FPGAWord & alpha() const
Definition: Stub.h:64
double rzprojapprox() const
Definition: Projection.h:104
bool bookHistos() const
Definition: Settings.h:207
void execute(unsigned int iSector, double phimin)
double kzder() const
Definition: Settings.h:395
unsigned int nMatchEngines_
std::ofstream & ofstream(std::string fname)
Definition: Globals.cc:44
double kz() const
Definition: Settings.h:302
static unsigned int const shift
void setBendIndex(int bendindex)
Definition: Projection.h:119
double rapprox() const
Definition: Stub.cc:144
double alphanorm() const
Definition: L1TStub.cc:85
const FPGAWord & r() const
Definition: Stub.h:60
double kphider() const
Definition: Settings.h:393
double phiproj() const
Definition: Projection.h:79
double drmax() const
Definition: Settings.h:128
const FPGAWord & fpgarzbin2projvm() const
Definition: Projection.h:64
HistBase *& histograms()
Definition: Globals.h:38
int disk() const
Definition: Tracklet.cc:779
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
double kr() const
Definition: Settings.h:304
unsigned int nbitsvmme(unsigned int layerdisk) const
Definition: Settings.h:103
Tracklet * proj() const
bool isPSseed() const
double krprojshiftdisk() const
Definition: Settings.h:400
std::vector< VMStubsMEMemory * > vmstubs_
double rzprojderapprox() const
Definition: Projection.h:114
tmp
align.sh
Definition: createJobs.py:716
bool useapprox() const
Definition: Settings.h:234
AllStubsMemory * allstubs_
TrackletLUT zmatchcuttable_
int ialphafactouter_[N_DSS_MOD *2]
double phiprojapprox() const
Definition: Projection.h:99
unsigned int nStubsBin(unsigned int bin) const
constexpr unsigned int N_BITSMEMADDRESS
Definition: Settings.h:39
double phiprojder() const
Definition: Projection.h:89
Log< level::Error, true > LogProblem
virtual void FillLayerResidual(int, int, double, double, double, double, bool)
Definition: HistBase.h:30
bool writeMonitorData(std::string module) const
Definition: Settings.h:109
bool writetrace() const
Definition: Settings.h:183
constexpr int N_LAYER
Definition: Settings.h:21
double rzprojder() const
Definition: Projection.h:94
unsigned int slot() const