From 7a84cf653569d5d0e639d3b00d346cc7641d9b08 Mon Sep 17 00:00:00 2001 From: Andrew Hart Date: Sun, 21 Feb 2021 18:17:32 -0500 Subject: [PATCH 01/15] PurgeDuplicates test-vectors (11_3_X) (#70) * Various changes for outputting PurgeDuplicates test-vectors. * Removed some magic numbers. * Updated trackfitstr() to be more readable and include more comments. * Removed more magic. --- .../TrackFindingTracklet/interface/Settings.h | 13 + .../TrackFindingTracklet/interface/Tracklet.h | 12 +- .../TrackFindingTracklet/src/FitTrack.cc | 2 + .../TrackFindingTracklet/src/Tracklet.cc | 324 +++++++++--------- .../src/TrackletEventProcessor.cc | 4 - 5 files changed, 193 insertions(+), 162 deletions(-) diff --git a/L1Trigger/TrackFindingTracklet/interface/Settings.h b/L1Trigger/TrackFindingTracklet/interface/Settings.h index e1b70d10fbb16..77fff76c3e941 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Settings.h +++ b/L1Trigger/TrackFindingTracklet/interface/Settings.h @@ -248,6 +248,13 @@ namespace trklet { unsigned int nbitstrackletindex() const { return nbitstrackletindex_; } void setNbitstrackletindex(unsigned int nbitstrackletindex) { nbitstrackletindex_ = nbitstrackletindex; } + unsigned int nbitsitc() const { return nbitsitc_; } + unsigned int nbitsseed() const { return (extended_ ? nbitsseedextended_ : nbitsseed_); } + unsigned int nbitstcindex() const { return nbitsseed() + nbitsitc(); } + void setNbitsitc(unsigned int nbitsitc) { nbitsitc_ = nbitsitc; } + void setNbitsseed(unsigned int nbitsseed) { nbitsseed_ = nbitsseed; } + void setNbitsseedextended(unsigned int nbitsseed) { nbitsseedextended_ = nbitsseed; } + double dphisectorHG() const { return 2 * M_PI / N_SECTOR + 2 * std::max(std::abs(asin(0.5 * rinvmax() * rmean(0)) - asin(0.5 * rinvmax() * rcrit_)), @@ -450,6 +457,12 @@ namespace trklet { unsigned int nbitstrackletindex_{7}; //Bits used to store the tracklet index + unsigned int nbitsitc_{4}; //Bits used to store the iTC, a unique + //identifier assigned to each TC within a sector + unsigned int nbitsseed_{3}; //Bits used to store the seed number + unsigned int nbitsseedextended_{4}; //Bits used to store the seed number + //in the extended project + //Bits used to store track parameter in tracklet int nbitsrinv_{14}; int nbitsphi0_{18}; diff --git a/L1Trigger/TrackFindingTracklet/interface/Tracklet.h b/L1Trigger/TrackFindingTracklet/interface/Tracklet.h index 6137a600b2ac1..870dd822bbbd0 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Tracklet.h +++ b/L1Trigger/TrackFindingTracklet/interface/Tracklet.h @@ -470,7 +470,9 @@ namespace trklet { int hitpattern, const std::vector& l1stubs = std::vector()); - std::string trackfitstr(); + const std::string layerstubstr(const unsigned layer) const; + const std::string diskstubstr(const unsigned disk) const; + std::string trackfitstr() const; Track makeTrack(const std::vector& l1stubs); @@ -499,8 +501,11 @@ namespace trklet { int TCID() const { return TCIndex_ * (1 << settings_.nbitstrackletindex()) + trackletIndex_; } - int getISeed() const; - int getITC() const; + const int getISeed() const; + const int getITC() const; + + void setTrackIndex(int index); + const int trackIndex() const; unsigned int PSseed() const { return ((layer() == 1) || (layer() == 2) || (disk() != 0)) ? 1 : 0; } @@ -527,6 +532,7 @@ namespace trklet { int trackletIndex_; int TCIndex_; + int trackIndex_; //Tracklet track parameters TrackPars fpgapars_; diff --git a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc index 440174026b1ac..bf17095e35a09 100644 --- a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc +++ b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc @@ -996,6 +996,7 @@ void FitTrack::execute() { if (settings_.removalType() == "merge") { trackfit_->addStubList(trackstublist); trackfit_->addStubidsList(stubidslist); + bestTracklet->setTrackIndex(trackfit_->nTracks()); trackfit_->addTrack(bestTracklet); } else if (bestTracklet->fit()) { assert(trackfit_ != nullptr); @@ -1005,6 +1006,7 @@ void FitTrack::execute() { << endl; fout.close(); } + bestTracklet->setTrackIndex(trackfit_->nTracks()); trackfit_->addTrack(bestTracklet); } } diff --git a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc index 8340f44957cb7..a116a646fb23c 100644 --- a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc +++ b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc @@ -276,11 +276,7 @@ std::string Tracklet::trackletprojstr(int layer) const { } tmp.set(trackletIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); FPGAWord tcid; - if (settings_.extended()) { - tcid.set(TCIndex_, 8, true, __LINE__, __FILE__); - } else { - tcid.set(TCIndex_, 7, true, __LINE__, __FILE__); - } + tcid.set(TCIndex_, settings_.nbitstcindex(), true, __LINE__, __FILE__); std::string oss = tcid.str() + "|" + tmp.str() + "|" + layerproj_[layer - 1].fpgaphiproj().str() + "|" + layerproj_[layer - 1].fpgazproj().str() + "|" + layerproj_[layer - 1].fpgaphiprojder().str() + "|" + @@ -296,11 +292,7 @@ std::string Tracklet::trackletprojstrD(int disk) const { } tmp.set(trackletIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); FPGAWord tcid; - if (settings_.extended()) { - tcid.set(TCIndex_, 8, true, __LINE__, __FILE__); - } else { - tcid.set(TCIndex_, 7, true, __LINE__, __FILE__); - } + tcid.set(TCIndex_, settings_.nbitstcindex(), true, __LINE__, __FILE__); std::string oss = tcid.str() + "|" + tmp.str() + "|" + diskproj_[abs(disk) - 1].fpgaphiproj().str() + "|" + diskproj_[abs(disk) - 1].fpgarproj().str() + "|" + diskproj_[abs(disk) - 1].fpgaphiprojder().str() + "|" + diskproj_[abs(disk) - 1].fpgarprojder().str(); @@ -381,13 +373,10 @@ std::string Tracklet::fullmatchstr(int layer) { } tmp.set(trackletIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); FPGAWord tcid; - if (settings_.extended()) { - tcid.set(TCIndex_, 8, true, __LINE__, __FILE__); - } else { - tcid.set(TCIndex_, 7, true, __LINE__, __FILE__); - } + tcid.set(TCIndex_, settings_.nbitstcindex(), true, __LINE__, __FILE__); std::string oss = tcid.str() + "|" + tmp.str() + "|" + layerresid_[layer - 1].fpgastubid().str() + "|" + - layerresid_[layer - 1].fpgaphiresid().str() + "|" + layerresid_[layer - 1].fpgazresid().str(); + layerresid_[layer - 1].stubptr()->r().str() + "|" + layerresid_[layer - 1].fpgaphiresid().str() + + "|" + layerresid_[layer - 1].fpgazresid().str(); return oss; } @@ -400,12 +389,11 @@ std::string Tracklet::fullmatchdiskstr(int disk) { } tmp.set(trackletIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); FPGAWord tcid; - if (settings_.extended()) { - tcid.set(TCIndex_, 8, true, __LINE__, __FILE__); - } else { - tcid.set(TCIndex_, 7, true, __LINE__, __FILE__); - } + tcid.set(TCIndex_, settings_.nbitstcindex(), true, __LINE__, __FILE__); + const FPGAWord& stubr = diskresid_[disk - 1].stubptr()->r(); + const bool isPS = diskresid_[disk - 1].stubptr()->isPSmodule(); std::string oss = tcid.str() + "|" + tmp.str() + "|" + diskresid_[disk - 1].fpgastubid().str() + "|" + + (isPS ? stubr.str() : ("00000000" + stubr.str())) + "|" + diskresid_[disk - 1].fpgaphiresid().str() + "|" + diskresid_[disk - 1].fpgarresid().str(); return oss; } @@ -644,149 +632,168 @@ void Tracklet::setFitPars(double rinvfit, fpgatrack_ = std::make_unique(makeTrack(l1stubs)); } -std::string Tracklet::trackfitstr() { - string stubid0 = "111111111"; - string stubid1 = "111111111"; - string stubid2 = "111111111"; - string stubid3 = "111111111"; +const std::string Tracklet::layerstubstr(const unsigned layer) const { + assert(layer < N_LAYER); - if (isBarrel()) { - if (layer() == 1) { - if (layerresid_[2].valid()) { - stubid0 = layerresid_[2].fpgastubid().str(); - } - if (layerresid_[3].valid()) { - stubid1 = layerresid_[3].fpgastubid().str(); - } - if (layerresid_[4].valid()) { - stubid2 = layerresid_[4].fpgastubid().str(); - } - if (layerresid_[5].valid()) { - stubid3 = layerresid_[5].fpgastubid().str(); - } - if (diskresid_[0].valid()) { - stubid3 = diskresid_[0].fpgastubid().str(); - } - if (diskresid_[1].valid()) { - stubid2 = diskresid_[1].fpgastubid().str(); - } - if (diskresid_[2].valid()) { - stubid1 = diskresid_[2].fpgastubid().str(); - } - if (diskresid_[3].valid()) { - stubid0 = diskresid_[3].fpgastubid().str(); - } + std::stringstream oss(""); + if (!layerresid_[layer].valid()) + oss << "0|0000000|0000000000|0000000|000000000000|000000000"; + else { + if (trackIndex_ < 0 || trackIndex_ > (int)settings_.ntrackletmax()) { + cout << "trackIndex_ = " << trackIndex_ << endl; + assert(0); } + const FPGAWord tmp(trackIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); + oss << "1|"; // valid bit + oss << tmp.str() << "|"; + oss << layerresid_[layer].fpgastubid().str() << "|"; + oss << layerresid_[layer].stubptr()->r().str() << "|"; + oss << layerresid_[layer].fpgaphiresid().str() << "|"; + oss << layerresid_[layer].fpgazresid().str(); + } - if (layer() == 3) { - if (layerresid_[0].valid()) { - stubid0 = layerresid_[0].fpgastubid().str(); - } - if (layerresid_[1].valid()) { - stubid1 = layerresid_[1].fpgastubid().str(); - } - if (layerresid_[4].valid()) { - stubid2 = layerresid_[4].fpgastubid().str(); - } - if (layerresid_[5].valid()) { - stubid3 = layerresid_[5].fpgastubid().str(); - } - if (diskresid_[0].valid()) { - stubid3 = diskresid_[0].fpgastubid().str(); - } - if (diskresid_[1].valid()) { - stubid2 = diskresid_[1].fpgastubid().str(); - } - } + return oss.str(); +} - if (layer() == 5) { - if (layerresid_[0].valid()) { - stubid0 = layerresid_[0].fpgastubid().str(); - } - if (layerresid_[1].valid()) { - stubid1 = layerresid_[1].fpgastubid().str(); - } - if (layerresid_[2].valid()) { - stubid2 = layerresid_[2].fpgastubid().str(); - } - if (layerresid_[3].valid()) { - stubid3 = layerresid_[3].fpgastubid().str(); - } - } - } +const std::string Tracklet::diskstubstr(const unsigned disk) const { + assert(disk < N_DISK); - if (isDisk()) { - if (disk() == 1) { - if (layerresid_[0].valid()) { - stubid0 = layerresid_[0].fpgastubid().str(); - } - if (diskresid_[2].valid()) { - stubid1 = diskresid_[2].fpgastubid().str(); - } - if (diskresid_[3].valid()) { - stubid2 = diskresid_[3].fpgastubid().str(); - } - if (diskresid_[4].valid()) { - stubid3 = diskresid_[4].fpgastubid().str(); - } else if (layerresid_[1].valid()) { - stubid3 = layerresid_[1].fpgastubid().str(); - } + std::stringstream oss(""); + if (!diskresid_[disk].valid()) + oss << "0|0000000|0000000000|000000000000|000000000000|0000000"; + else { + if (trackIndex_ < 0 || trackIndex_ > (int)settings_.ntrackletmax()) { + cout << "trackIndex_ = " << trackIndex_ << endl; + assert(0); } + const FPGAWord tmp(trackIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); + const FPGAWord& stubr = diskresid_[disk].stubptr()->r(); + const bool isPS = diskresid_[disk].stubptr()->isPSmodule(); + oss << "1|"; // valid bit + oss << tmp.str() << "|"; + oss << diskresid_[disk].fpgastubid().str() << "|"; + oss << (isPS ? stubr.str() : ("00000000" + stubr.str())) << "|"; + oss << diskresid_[disk].fpgaphiresid().str() << "|"; + oss << diskresid_[disk].fpgarresid().str(); + } + + return oss.str(); +} - if (disk() == 3) { - if (layerresid_[0].valid()) { - stubid0 = layerresid_[0].fpgastubid().str(); - } - if (diskresid_[0].valid()) { - stubid1 = diskresid_[0].fpgastubid().str(); - } - if (diskresid_[1].valid()) { - stubid2 = diskresid_[1].fpgastubid().str(); - } - if (diskresid_[4].valid()) { - stubid3 = diskresid_[4].fpgastubid().str(); - } else if (layerresid_[1].valid()) { - stubid3 = layerresid_[1].fpgastubid().str(); - } - } - } +std::string Tracklet::trackfitstr() const { + const unsigned maxNHits = 8; + const unsigned nBitsPerHit = 3; + vector stub(maxNHits, "0"); + string hitmap(maxNHits * nBitsPerHit, '0'); - if (isOverlap()) { - if (layer() == 1) { - if (diskresid_[1].valid()) { - stubid0 = diskresid_[1].fpgastubid().str(); - } - if (diskresid_[2].valid()) { - stubid1 = diskresid_[2].fpgastubid().str(); - } - if (diskresid_[3].valid()) { - stubid2 = diskresid_[3].fpgastubid().str(); - } - if (diskresid_[4].valid()) { - stubid3 = diskresid_[4].fpgastubid().str(); - } - } - } + // Assign stub strings for each of the possible projections for each seed. + // The specific layers/disks for a given seed are determined by the wiring. + switch (seedIndex()) { + case 0: // L1L2 + stub[0] = layerstubstr(2); // L3 + stub[1] = layerstubstr(3); // L4 + stub[2] = layerstubstr(4); // L5 + stub[3] = layerstubstr(5); // L6 - std::string oss; - // real Q print out for fitted tracks - if (settings_.writeoutReal()) { - oss = std::to_string((fpgafitpars_.rinv().value()) * settings_.krinvpars()) + " " + - std::to_string((fpgafitpars_.phi0().value()) * settings_.kphi0pars()) + " " + - std::to_string((fpgafitpars_.d0().value()) * settings_.kd0pars()) + " " + - std::to_string((fpgafitpars_.t().value()) * settings_.ktpars()) + " " + - std::to_string((fpgafitpars_.z0().value()) * settings_.kz()) + " " + innerFPGAStub_->phiregionaddressstr() + - " "; + stub[4] = diskstubstr(0); // D1 + stub[5] = diskstubstr(1); // D2 + stub[6] = diskstubstr(2); // D3 + stub[7] = diskstubstr(3); // D4 + + break; + + case 1: // L2L3 + stub[0] = layerstubstr(0); // L1 + stub[1] = layerstubstr(3); // L4 + stub[2] = layerstubstr(4); // L5 + + stub[3] = diskstubstr(0); // D1 + stub[4] = diskstubstr(1); // D2 + stub[5] = diskstubstr(2); // D3 + stub[6] = diskstubstr(3); // D4 + + break; + + case 2: // L3L4 + stub[0] = layerstubstr(0); // L1 + stub[1] = layerstubstr(1); // L2 + stub[2] = layerstubstr(4); // L5 + stub[3] = layerstubstr(5); // L6 + + stub[4] = diskstubstr(0); // D1 + stub[5] = diskstubstr(1); // D2 + + break; + + case 3: // L5L6 + stub[0] = layerstubstr(0); // L1 + stub[1] = layerstubstr(1); // L2 + stub[2] = layerstubstr(2); // L3 + stub[3] = layerstubstr(3); // L4 + + break; + + case 4: // D1D2 + stub[0] = layerstubstr(0); // L1 + stub[1] = layerstubstr(1); // L2 + + stub[2] = diskstubstr(2); // D3 + stub[3] = diskstubstr(3); // D4 + stub[4] = diskstubstr(4); // D5 + + break; + + case 5: // D3D4 + stub[0] = layerstubstr(0); // L1 + + stub[1] = diskstubstr(0); // D1 + stub[2] = diskstubstr(1); // D2 + stub[3] = diskstubstr(4); // D5 + + break; + + case 6: // L1D1 + stub[0] = diskstubstr(1); // D2 + stub[1] = diskstubstr(2); // D3 + stub[2] = diskstubstr(3); // D4 + stub[3] = diskstubstr(4); // D5 + + break; + + case 7: // L2D1 + stub[0] = layerstubstr(0); // L1 + + stub[1] = diskstubstr(1); // D2 + stub[2] = diskstubstr(2); // D3 + stub[3] = diskstubstr(3); // D4 + + break; } + + // Only one hit per layer/disk is allowed currently, so the hit map for a + // given layer/disk is just equal to the valid bit of the corresponding stub + // string, which is the first character. + for (unsigned i = 0; i < maxNHits; i++) + hitmap[i * nBitsPerHit + 2] = stub[i][0]; + + std::string oss(""); //Binary print out if (!settings_.writeoutReal()) { - oss = fpgafitpars_.rinv().str() + "|" + fpgafitpars_.phi0().str() + "|" + fpgafitpars_.d0().str() + "|" + - fpgafitpars_.t().str() + "|" + fpgafitpars_.z0().str() + "|" + innerFPGAStub_->phiregionaddressstr() + "|"; + const FPGAWord tmp(getISeed(), settings_.nbitsseed(), true, __LINE__, __FILE__); + + oss += "1|"; // valid bit + oss += tmp.str() + "|"; + oss += fpgapars_.rinv().str() + "|"; + oss += fpgapars_.phi0().str() + "|"; + oss += fpgapars_.z0().str() + "|"; + oss += fpgapars_.t().str() + "|"; + oss += hitmap; + for (unsigned i = 0; i < maxNHits; i++) + // If a valid stub string was never assigned, then that stub is not + // included in the output. + if (stub[i] != "0") + oss += "|" + stub[i]; } - if (middleFPGAStub_) { - oss += middleFPGAStub_->phiregionaddressstr() + " "; - } - oss += outerFPGAStub_->phiregionaddressstr() + " " + stubid0 + "|" + stubid1 + "|" + stubid2 + "|" + stubid3; return oss; } @@ -846,18 +853,25 @@ void Tracklet::setTrackletIndex(unsigned int index) { assert(index <= settings_.ntrackletmax()); } -int Tracklet::getISeed() const { - int iSeed = TCIndex_ >> 4; +const int Tracklet::getISeed() const { + const int iSeed = TCIndex_ >> settings_.nbitsitc(); assert(iSeed >= 0 && iSeed <= (int)N_SEED); return iSeed; } -int Tracklet::getITC() const { - int iSeed = getISeed(), iTC = TCIndex_ - (iSeed << 4); +const int Tracklet::getITC() const { + const int iSeed = getISeed(), iTC = TCIndex_ - (iSeed << settings_.nbitsitc()); assert(iTC >= 0 && iTC <= 14); return iTC; } +void Tracklet::setTrackIndex(int index) { + trackIndex_ = index; + assert(index <= (int)settings_.ntrackletmax()); +} + +const int Tracklet::trackIndex() const { return trackIndex_; } + unsigned int Tracklet::calcSeedIndex() const { int seedindex = -1; int seedlayer = layer(); diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc index 2e4fc31bd3d7a..77dc376c1e9e0 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc @@ -473,11 +473,9 @@ void TrackletEventProcessor::event(SLHCEvent& ev) { FTTimer_.start(); for (unsigned int k = 0; k < N_SECTOR; k++) { sectors_[k]->executeFT(); -#ifndef USEHYBRID //don't try to print these memories if running hybrid if ((settings_->writeMem() || settings_->writeMonitorData("IFit")) && k == settings_->writememsect()) { sectors_[k]->writeTF(first); } -#endif } FTTimer_.stop(); @@ -485,12 +483,10 @@ void TrackletEventProcessor::event(SLHCEvent& ev) { PDTimer_.start(); for (unsigned int k = 0; k < N_SECTOR; k++) { sectors_[k]->executePD(tracks_); -#ifndef USEHYBRID //don't try to print these memories if running hybrid if (((settings_->writeMem() || settings_->writeMonitorData("IFit")) && k == settings_->writememsect()) || settings_->writeMonitorData("CT")) { sectors_[k]->writeCT(first); } -#endif } PDTimer_.stop(); } From 6e0a37aeaba0477ed500c65073f0bcda3261c1b7 Mon Sep 17 00:00:00 2001 From: Ian Tomalin Date: Sun, 28 Feb 2021 19:52:04 +0000 Subject: [PATCH 02/15] Ian update max step (#71) * Update max steps per TM period to match HLS * Updated MC dataset --- .../TrackFindingTracklet/interface/Settings.h | 18 +++++++++--------- .../test/L1TrackNtupleMaker_cfg.py | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/L1Trigger/TrackFindingTracklet/interface/Settings.h b/L1Trigger/TrackFindingTracklet/interface/Settings.h index 77fff76c3e941..1e045222c4ada 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Settings.h +++ b/L1Trigger/TrackFindingTracklet/interface/Settings.h @@ -624,21 +624,21 @@ namespace trklet { {{0.0, 0.0, 0.0, 0.0, 3.6, 3.4, 3.7, 0.0, 0.0, 0.0, 0.0, 3.0}}}}; //disk 5 // Offset to the maximum number of steps in each processing step: - // Set to 0 (default) means standard trunction + // Set to 0 (default) means standard truncation // Set to large value, e.g. 10000, to disable truncation unsigned int maxstepoffset_{0}; - //Default number of processing steps for one event + //Number of processing steps for one event (108=18TM*240MHz/40MHz) std::unordered_map maxstep_{{"Link", 108}, - {"MC", 107}, - {"ME", 101}, + {"VMR", 108}, + {"TE", 108}, + {"TC", 108}, + {"PR", 108}, + {"ME", 108}, + {"MC", 105}, {"MP", 108}, - {"PR", 107}, - {"TC", 107}, - {"TE", 101}, {"TP", 108}, - {"TRE", 108}, - {"VMR", 101}}; + {"TRE", 108}}; // If set to true this will generate debub printout in text files std::unordered_map writeMonitorData_{{"IL", false}, diff --git a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py index eb7cc7721df8f..aea44217dbdff 100644 --- a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py +++ b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py @@ -71,7 +71,7 @@ #inputMC=getCMSdata(dataName) # Or read specified .root file: - inputMC = ["/store/relval/CMSSW_11_2_0_pre5/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v3_2026D49PU200-v1/20000/FDFA00CE-FA93-0142-B187-99CBD4A43944.root"] + inputMC = ["/store/relval/CMSSW_11_3_0_pre3/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_113X_mcRun4_realistic_v3_2026D49PU200-v1/00000/001edbad-174e-46af-932a-6ce8e04aee1c.root"] else: print "this is not a valid geometry!!!" From 0e55e6278c58510f75a976a3869b10d86774b109 Mon Sep 17 00:00:00 2001 From: cgsavard Date: Tue, 9 Mar 2021 08:15:48 -0700 Subject: [PATCH 03/15] Add beam constraint to extended tracking (#75) * add beam spot constraint flag to save new bcon values * add check on scaled chi2 value after beam constraint * get rid of code duplication * include comment on kalmanAddBeamConstr_ boolean * take out unecessary function --- .../interface/KFTrackletTrack.h | 26 ++++--- .../interface/L1fittedTrack.h | 11 ++- L1Trigger/TrackFindingTMTT/src/KFbase.cc | 10 ++- L1Trigger/TrackFindingTMTT/src/Settings.cc | 1 + .../TrackFindingTracklet/src/HybridFit.cc | 71 ++++++++++--------- 5 files changed, 70 insertions(+), 49 deletions(-) diff --git a/L1Trigger/TrackFindingTMTT/interface/KFTrackletTrack.h b/L1Trigger/TrackFindingTMTT/interface/KFTrackletTrack.h index ae86d424d2df9..293a397b5834f 100644 --- a/L1Trigger/TrackFindingTMTT/interface/KFTrackletTrack.h +++ b/L1Trigger/TrackFindingTMTT/interface/KFTrackletTrack.h @@ -45,7 +45,12 @@ namespace tmtt { unsigned int nHelixParam, unsigned int iPhiSec, unsigned int iEtaReg, - bool accepted = true) + bool accepted = true, + bool done_bcon = false, + float qOverPt_bcon = 0., + float d0_bcon = 0., + float phi0_bcon = 0., + float chi2rphi_bcon = 0.) : l1track3D_(l1track3D), stubs_(stubs), hitPattern_(hitPattern), @@ -56,11 +61,11 @@ namespace tmtt { tanLambda_(tanLambda), chi2rphi_(chi2rphi), chi2rz_(chi2rz), - done_bcon_(false), - qOverPt_bcon_(qOverPt), - d0_bcon_(d0), - phi0_bcon_(phi0), - chi2rphi_bcon_(chi2rphi), + done_bcon_(done_bcon), + qOverPt_bcon_(qOverPt_bcon), + d0_bcon_(d0_bcon), + phi0_bcon_(phi0_bcon), + chi2rphi_bcon_(chi2rphi_bcon), nHelixParam_(nHelixParam), iPhiSec_(iPhiSec), iEtaReg_(iEtaReg), @@ -70,14 +75,6 @@ namespace tmtt { numIterations_(0), accepted_(accepted) {} - //--- Optionally std::set track helix params & chi2 if beam-spot constraint is used (for 5-parameter fit). - void setBeamConstr(float qOverPt_bcon, float phi0_bcon, float chi2rphi_bcon) { - done_bcon_ = true; - qOverPt_bcon_ = qOverPt_bcon; - d0_bcon_ = 0.0, phi0_bcon_ = phi0_bcon; - chi2rphi_bcon_ = chi2rphi_bcon; - } - //--- Set/get additional info about fitted track that is specific to individual track fit algorithms (KF, LR, chi2) //--- and is used for debugging/histogramming purposes. @@ -131,6 +128,7 @@ namespace tmtt { float invPt_bcon() const { return std::abs(qOverPt_bcon_); } float pt_bcon() const { return 1. / (1.0e-6 + this->invPt_bcon()); } float phi0_bcon() const { return phi0_bcon_; } + float d0_bcon() const { return d0_bcon_; } // Phi and z coordinates at which track crosses "chosenR" values used by r-phi HT and rapidity sectors respectively. // (Optionally with beam-spot constraint applied). diff --git a/L1Trigger/TrackFindingTMTT/interface/L1fittedTrack.h b/L1Trigger/TrackFindingTMTT/interface/L1fittedTrack.h index f0373166609d3..834841dd5f9b8 100644 --- a/L1Trigger/TrackFindingTMTT/interface/L1fittedTrack.h +++ b/L1Trigger/TrackFindingTMTT/interface/L1fittedTrack.h @@ -111,11 +111,12 @@ namespace tmtt { ~L1fittedTrack() override = default; //--- Optionally std::set track helix params & chi2 if beam-spot constraint is used (for 5-parameter fit). - void setBeamConstr(float qOverPt_bcon, float phi0_bcon, float chi2rphi_bcon) { + void setBeamConstr(float qOverPt_bcon, float phi0_bcon, float chi2rphi_bcon, bool accepted) { done_bcon_ = true; qOverPt_bcon_ = qOverPt_bcon; d0_bcon_ = 0.0, phi0_bcon_ = phi0_bcon; chi2rphi_bcon_ = chi2rphi_bcon; + accepted_ = accepted; } //--- Set/get additional info about fitted track that is specific to individual track fit algorithms (KF, LR, chi2) @@ -161,7 +162,12 @@ namespace tmtt { nHelixParam(), iPhiSec(), iEtaReg(), - accepted()); + accepted(), + done_bcon(), + qOverPt_bcon(), + d0_bcon(), + phi0_bcon(), + chi2rphi_bcon()); return trk_; } @@ -247,6 +253,7 @@ namespace tmtt { return 1. / (small + this->invPt_bcon()); } float phi0_bcon() const { return phi0_bcon_; } + float d0_bcon() const { return d0_bcon_; } // Phi and z coordinates at which track crosses "chosenR" values used by r-phi HT and rapidity sectors respectively. // (Optionally with beam-spot constraint applied). diff --git a/L1Trigger/TrackFindingTMTT/src/KFbase.cc b/L1Trigger/TrackFindingTMTT/src/KFbase.cc index e6c1875f4227a..aa1aa30825d99 100644 --- a/L1Trigger/TrackFindingTMTT/src/KFbase.cc +++ b/L1Trigger/TrackFindingTMTT/src/KFbase.cc @@ -102,7 +102,15 @@ namespace tmtt { if (nHelixPar_ == 5) { double chi2rphi_bcon = 0.; TVectorD trackPars_bcon = trackParams_BeamConstr(cand, chi2rphi_bcon); - fitTrk.setBeamConstr(trackPars_bcon[QOVERPT], trackPars_bcon[PHI0], chi2rphi_bcon); + + // Check scaled chi2 cut + vector kfLayerVsChiSqCut = settings_->kfLayerVsChiSq5(); + double chi2scaled = chi2rphi_bcon / settings_->kalmanChi2RphiScale() + fitTrk.chi2rz(); + bool accepted = true; + if (chi2scaled > kfLayerVsChiSqCut[cand->nStubLayers()]) + accepted = false; + + fitTrk.setBeamConstr(trackPars_bcon[QOVERPT], trackPars_bcon[PHI0], chi2rphi_bcon, accepted); } } diff --git a/L1Trigger/TrackFindingTMTT/src/Settings.cc b/L1Trigger/TrackFindingTMTT/src/Settings.cc index 0fa32cbd6c11f..aa7c3ad3b162a 100644 --- a/L1Trigger/TrackFindingTMTT/src/Settings.cc +++ b/L1Trigger/TrackFindingTMTT/src/Settings.cc @@ -42,6 +42,7 @@ namespace tmtt { //kalmanDebugLevel_(2), // Good for debugging kalmanMinNumStubs_(4), kalmanMaxNumStubs_(6), + kalmanAddBeamConstr_(false), // Apply post-fit beam-spot constraint to 5-param fit kalmanRemove2PScut_(true), kalmanMaxSkipLayersHard_(1), // On "hard" input tracks kalmanMaxSkipLayersEasy_(2), // On "easy" input tracks diff --git a/L1Trigger/TrackFindingTracklet/src/HybridFit.cc b/L1Trigger/TrackFindingTracklet/src/HybridFit.cc index 5690cfbe8eaa9..9d129fa24db53 100644 --- a/L1Trigger/TrackFindingTracklet/src/HybridFit.cc +++ b/L1Trigger/TrackFindingTracklet/src/HybridFit.cc @@ -195,17 +195,29 @@ void HybridFit::Fit(Tracklet* tracklet, std::vector& trackstublist) << ", phi0 = " << trk.phi0() << ", eta = " << trk.eta() << ", z0 = " << trk.z0() << ", chi2 = " << trk.chi2() << ", accepted = " << trk.accepted(); - // Tracklet wants phi0 with respect to lower edge of sector, not global phi0. - double phi0fit = reco::reduceRange(trk.phi0() - iSector_ * 2 * M_PI / N_SECTOR + 0.5 * settings_.dphisectorHG()); + double d0,chi2rphi,phi0,qoverpt = -999; + if (trk.done_bcon()) { + d0 = trk.d0_bcon(); + chi2rphi = trk.chi2rphi_bcon(); + phi0 = trk.phi0_bcon(); + qoverpt = trk.qOverPt_bcon(); + } else if (!trk.done_bcon()) { + d0 = trk.d0(); + chi2rphi = trk.chi2rphi(); + phi0 = trk.phi0(); + qoverpt = trk.qOverPt(); + } - double rinvfit = 0.01 * settings_.c() * settings_.bfield() * trk.qOverPt(); + // Tracklet wants phi0 with respect to lower edge of sector, not global phi0. + double phi0fit = reco::reduceRange(phi0 - iSector_ * 2 * M_PI / N_SECTOR + 0.5 * settings_.dphisectorHG()); + double rinvfit = 0.01 * settings_.c() * settings_.bfield() * qoverpt; int irinvfit = rinvfit / settings_.krinvpars(); int iphi0fit = phi0fit / settings_.kphi0pars(); int itanlfit = trk.tanLambda() / settings_.ktpars(); int iz0fit = trk.z0() / settings_.kz0pars(); - int id0fit = trk.d0() / settings_.kd0pars(); - int ichi2rphifit = trk.chi2rphi() / 16; + int id0fit = d0 / settings_.kd0pars(); + int ichi2rphifit = chi2rphi / 16; int ichi2rzfit = trk.chi2rz() / 16; const vector& stubsFromFit = trk.stubs(); @@ -216,34 +228,29 @@ void HybridFit::Fit(Tracklet* tracklet, std::vector& trackstublist) l1stubsFromFit.push_back(l1s); } - if (settings_.printDebugKF()) { - edm::LogVerbatim("L1track") << "#stubs before/after KF fit = " << TMTTstubs.size() << "/" - << l1stubsFromFit.size(); - } - tracklet->setFitPars(rinvfit, - phi0fit, - trk.d0(), - trk.tanLambda(), - trk.z0(), - trk.chi2rphi(), - trk.chi2rz(), - rinvfit, - phi0fit, - trk.d0(), - trk.tanLambda(), - trk.z0(), - trk.chi2rphi(), - trk.chi2rz(), - irinvfit, - iphi0fit, - id0fit, - itanlfit, - iz0fit, - ichi2rphifit, - ichi2rzfit, - trk.hitPattern(), - l1stubsFromFit); + phi0fit, + d0, + trk.tanLambda(), + trk.z0(), + chi2rphi, + trk.chi2rz(), + rinvfit, + phi0fit, + d0, + trk.tanLambda(), + trk.z0(), + chi2rphi, + trk.chi2rz(), + irinvfit, + iphi0fit, + id0fit, + itanlfit, + iz0fit, + ichi2rphifit, + ichi2rzfit, + trk.hitPattern(), + l1stubsFromFit); } else { if (settings_.printDebugKF()) { edm::LogVerbatim("L1track") << "FitTrack:KF rejected track"; From c7aaee435e1d095a24670599d80647e4710f4009 Mon Sep 17 00:00:00 2001 From: Louise Skinnari Date: Mon, 12 Apr 2021 00:09:47 +0200 Subject: [PATCH 04/15] DTC_merge2 branch updated to 1130 (#74) * Anders DTC merge with a gazillion manual fixes * propagate buildfile fixes * code formats * fix cherrypick mess up * Remove LayerProjection class * Further cleanup of tracklet projections interface * Correct number of processing steps by changing < to <= * Add missing include of algorithm * Remove extra const * Remove some commented out code * Remove duplicate code * Fix message logger and DTC Stub for consistency with hybrid configuration * Fix problem with writing of input link memories * Create Residual class that will replace LayerResidual and DiskResidual * Remove the use of the class DiskResiduals * Remove unused nMatch and nMatchDisk method of Tracklet * (Re-)Implement the correction to writing the DTC data link file after moving functionality to Sector. * Combine addMatch method for disk and layers into on method * combine the disk and layer match into one method * Remove some redundant poiters to l1tstubs * Pass iSeed to Tracklet * Introduce an InputRouter module. Does not change functionality, but simplifies/unifies the code and makes it similar to the HLS * Cleanup of writing the DTC link files * Change processing order such that all steps in one sector are done and then move to the next sector. This saves memory * Interface updates for CMSSW following change to module processing order * Change in VMRouter to processing PS links before 2S in disks * Cleanup of unused iSector variable in processs and memory modules * Fixes to make the HybridTracks_cfg.py run * Cleanup of hardcoded numbers etc. * Updates to MP to put all regions into one memory slot in the ProjectionTemp * Fix to calculation of irinv for projections - no matches what is done in HLS * Remove now unused file paths for the old cable mapping code * Correct missplaced curly bracket * Fixes for the displaced tracking * Fix to avoid duplicate VMSTE name in D1 for standard configuration * Address comments from Louise S. * Ran scram b code-format * Address comments from Louise S. * Addressing more comments from Louise S. * More fixes to comments * Make running hybrid default (not displaced) * restore buildfile * Add DTC link config to Settings.h * Changes to suppress warning in MatchCalculator when running displaced tracking * Fix typo introduced in code cleanup for MatchProcessor Co-authored-by: Anders Ryd Co-authored-by: Anders --- .../interface/AllInnerStubsMemory.h | 37 + .../interface/AllProjectionsMemory.h | 4 +- .../interface/AllStubsMemory.h | 4 +- .../TrackFindingTracklet/interface/Cabling.h | 39 - .../interface/CandidateMatchMemory.h | 4 +- .../interface/CircularBuffer.h | 10 + .../interface/CleanTrackMemory.h | 4 +- .../TrackFindingTracklet/interface/DTC.h | 46 - .../TrackFindingTracklet/interface/DTCLink.h | 34 - .../interface/DTCLinkMemory.h | 38 + .../interface/DiskResidual.h | 112 -- .../TrackFindingTracklet/interface/FitTrack.h | 6 +- .../interface/FullMatchMemory.h | 4 +- .../interface/InputLinkMemory.h | 8 +- .../interface/InputRouter.h | 39 + .../interface/L1SimTrack.h | 53 + .../TrackFindingTracklet/interface/L1TStub.h | 46 +- .../interface/LayerProjection.h | 163 --- .../interface/MatchCalculator.h | 5 +- .../interface/MatchEngine.h | 8 +- .../interface/MatchEngineUnit.h | 34 +- .../interface/MatchProcessor.h | 24 +- .../interface/MemoryBase.h | 2 +- .../interface/ProcessBase.h | 6 +- .../{DiskProjection.h => Projection.h} | 118 +- .../interface/ProjectionRouter.h | 2 +- .../interface/ProjectionTemp.h | 14 +- .../interface/PurgeDuplicate.h | 4 +- .../interface/{LayerResidual.h => Residual.h} | 45 +- .../interface/SLHCEvent.h | 73 +- .../TrackFindingTracklet/interface/Sector.h | 19 +- .../TrackFindingTracklet/interface/Settings.h | 244 +++- .../TrackFindingTracklet/interface/Stub.h | 28 +- .../interface/StubPairsMemory.h | 4 +- .../interface/StubTripletsMemory.h | 4 +- .../interface/TETableBase.h | 3 +- .../TrackFindingTracklet/interface/Track.h | 8 +- .../interface/TrackFitMemory.h | 4 +- .../TrackFindingTracklet/interface/Tracklet.h | 352 +---- .../interface/TrackletCalculator.h | 4 +- .../interface/TrackletCalculatorBase.h | 5 +- .../interface/TrackletCalculatorDisplaced.h | 8 +- .../interface/TrackletConfigBuilder.h | 273 ++++ .../interface/TrackletEngine.h | 2 +- .../interface/TrackletEngineDisplaced.h | 4 +- .../interface/TrackletEngineUnit.h | 17 +- .../interface/TrackletEventProcessor.h | 14 +- .../interface/TrackletParametersMemory.h | 6 +- .../interface/TrackletProcessor.h | 19 +- .../interface/TrackletProjectionsMemory.h | 4 +- .../interface/TripletEngine.h | 2 +- .../TrackFindingTracklet/interface/Util.h | 254 ++-- .../interface/VMProjectionsMemory.h | 4 +- .../TrackFindingTracklet/interface/VMRouter.h | 6 +- .../interface/VMRouterCM.h | 6 +- .../interface/VMRouterTable.h | 5 +- .../interface/VMStubsMEMemory.h | 4 +- .../interface/VMStubsTEMemory.h | 5 +- .../plugins/BuildFile.xml | 1 + .../plugins/L1FPGATrackProducer.cc | 371 ++--- .../python/Tracklet_cfi.py | 5 +- .../src/AllInnerStubsMemory.cc | 24 + .../src/AllProjectionsMemory.cc | 23 +- .../src/AllStubsMemory.cc | 6 +- L1Trigger/TrackFindingTracklet/src/Cabling.cc | 126 -- .../src/CandidateMatchMemory.cc | 22 +- .../src/CleanTrackMemory.cc | 24 +- L1Trigger/TrackFindingTracklet/src/DTC.cc | 52 - L1Trigger/TrackFindingTracklet/src/DTCLink.cc | 29 - .../TrackFindingTracklet/src/DTCLinkMemory.cc | 71 + .../src/DiskProjection.cc | 94 -- .../TrackFindingTracklet/src/DiskResidual.cc | 47 - .../TrackFindingTracklet/src/FitTrack.cc | 156 +- .../src/FullMatchMemory.cc | 22 +- .../TrackFindingTracklet/src/HybridFit.cc | 2 +- .../src/InputLinkMemory.cc | 84 +- .../TrackFindingTracklet/src/InputRouter.cc | 79 + .../TrackFindingTracklet/src/L1SimTrack.cc | 37 + L1Trigger/TrackFindingTracklet/src/L1TStub.cc | 81 +- .../src/LayerProjection.cc | 103 -- .../TrackFindingTracklet/src/LayerResidual.cc | 42 - .../src/MatchCalculator.cc | 145 +- .../TrackFindingTracklet/src/MatchEngine.cc | 155 +- .../src/MatchEngineUnit.cc | 83 +- .../src/MatchProcessor.cc | 588 ++++---- .../TrackFindingTracklet/src/MemoryBase.cc | 25 +- .../TrackFindingTracklet/src/ProcessBase.cc | 16 +- .../TrackFindingTracklet/src/Projection.cc | 132 ++ .../src/ProjectionRouter.cc | 28 +- .../src/ProjectionRouterBendTable.cc | 2 +- .../src/ProjectionTemp.cc | 18 +- .../src/PurgeDuplicate.cc | 39 +- .../TrackFindingTracklet/src/Residual.cc | 44 + .../TrackFindingTracklet/src/SLHCEvent.cc | 171 +-- L1Trigger/TrackFindingTracklet/src/Sector.cc | 209 +-- L1Trigger/TrackFindingTracklet/src/Stub.cc | 209 +-- .../src/StubPairsMemory.cc | 22 +- .../src/StubTripletsMemory.cc | 22 +- .../TrackFindingTracklet/src/TETableBase.cc | 7 +- L1Trigger/TrackFindingTracklet/src/Track.cc | 2 +- .../TrackFindingTracklet/src/TrackDerTable.cc | 25 +- .../src/TrackFitMemory.cc | 23 +- .../TrackFindingTracklet/src/Tracklet.cc | 363 ++--- .../src/TrackletCalculator.cc | 28 +- .../src/TrackletCalculatorBase.cc | 265 ++-- .../src/TrackletCalculatorDisplaced.cc | 310 ++-- .../src/TrackletConfigBuilder.cc | 1294 +++++++++++++++++ .../src/TrackletEngine.cc | 48 +- .../src/TrackletEngineDisplaced.cc | 46 +- .../src/TrackletEngineUnit.cc | 40 +- .../src/TrackletEventProcessor.cc | 534 +++---- .../src/TrackletParametersMemory.cc | 39 +- .../src/TrackletProcessor.cc | 495 ++++--- .../src/TrackletProjectionsMemory.cc | 29 +- .../TrackFindingTracklet/src/TripletEngine.cc | 31 +- .../src/VMProjectionsMemory.cc | 22 +- .../TrackFindingTracklet/src/VMRouter.cc | 28 +- .../TrackFindingTracklet/src/VMRouterCM.cc | 108 +- .../src/VMRouterPhiCorrTable.cc | 14 +- .../TrackFindingTracklet/src/VMRouterTable.cc | 121 +- .../src/VMStubsMEMemory.cc | 24 +- .../src/VMStubsTEMemory.cc | 38 +- .../test/HybridTracks_cfg.py | 29 +- .../test/L1TrackNtupleMaker_cfg.py | 28 +- L1Trigger/TrackFindingTracklet/test/Makefile | 28 +- L1Trigger/TrackFindingTracklet/test/fpga.cc | 42 +- L1Trigger/TrackerDTC/src/Stub.cc | 10 +- 127 files changed, 5229 insertions(+), 4545 deletions(-) create mode 100644 L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/Cabling.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/DTC.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/DTCLink.h create mode 100644 L1Trigger/TrackFindingTracklet/interface/DTCLinkMemory.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/DiskResidual.h create mode 100644 L1Trigger/TrackFindingTracklet/interface/InputRouter.h create mode 100644 L1Trigger/TrackFindingTracklet/interface/L1SimTrack.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/LayerProjection.h rename L1Trigger/TrackFindingTracklet/interface/{DiskProjection.h => Projection.h} (50%) rename L1Trigger/TrackFindingTracklet/interface/{LayerResidual.h => Residual.h} (61%) create mode 100644 L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h create mode 100644 L1Trigger/TrackFindingTracklet/src/AllInnerStubsMemory.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/Cabling.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/DTC.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/DTCLink.cc create mode 100644 L1Trigger/TrackFindingTracklet/src/DTCLinkMemory.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/DiskProjection.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/DiskResidual.cc create mode 100644 L1Trigger/TrackFindingTracklet/src/InputRouter.cc create mode 100644 L1Trigger/TrackFindingTracklet/src/L1SimTrack.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/LayerProjection.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/LayerResidual.cc create mode 100644 L1Trigger/TrackFindingTracklet/src/Projection.cc create mode 100644 L1Trigger/TrackFindingTracklet/src/Residual.cc create mode 100644 L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc diff --git a/L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h b/L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h new file mode 100644 index 0000000000000..50048e22a96ee --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h @@ -0,0 +1,37 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_AllInnerStubsMemory_h +#define L1Trigger_TrackFindingTracklet_interface_AllInnerStubsMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include +#include +#include + +namespace trklet { + + class Settings; + class Stub; + class L1TStub; + + class AllInnerStubsMemory : public MemoryBase { + public: + AllInnerStubsMemory(std::string name, Settings const& settings); + + ~AllInnerStubsMemory() override = default; + + void addStub(const Stub* stub) { stubs_.push_back(stub); } + + unsigned int nStubs() const { return stubs_.size(); } + + const Stub* getStub(unsigned int i) const { return stubs_[i]; } + + void clean() override { stubs_.clear(); } + + void writeStubs(bool first, unsigned int iSector); + + private: + std::vector stubs_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h b/L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h index f6367108d9ca4..7f84afe390301 100644 --- a/L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h @@ -13,7 +13,7 @@ namespace trklet { class AllProjectionsMemory : public MemoryBase { public: - AllProjectionsMemory(std::string name, Settings const& settings, unsigned int iSector); + AllProjectionsMemory(std::string name, Settings const& settings); ~AllProjectionsMemory() override = default; @@ -25,7 +25,7 @@ namespace trklet { void clean() override { tracklets_.clear(); } - void writeAP(bool first); + void writeAP(bool first, unsigned int iSector); private: std::vector tracklets_; diff --git a/L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h b/L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h index c34601997b069..71254d512e3ac 100644 --- a/L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h @@ -15,7 +15,7 @@ namespace trklet { class AllStubsMemory : public MemoryBase { public: - AllStubsMemory(std::string name, Settings const& settings, unsigned int iSector); + AllStubsMemory(std::string name, Settings const& settings); ~AllStubsMemory() override = default; @@ -27,7 +27,7 @@ namespace trklet { void clean() override { stubs_.clear(); } - void writeStubs(bool first); + void writeStubs(bool first, unsigned int iSector); private: std::vector stubs_; diff --git a/L1Trigger/TrackFindingTracklet/interface/Cabling.h b/L1Trigger/TrackFindingTracklet/interface/Cabling.h deleted file mode 100644 index f835b0d446234..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/Cabling.h +++ /dev/null @@ -1,39 +0,0 @@ -// This class holds a list of stubs that are in a given layer and DCT region -#ifndef L1Trigger_TrackFindingTracklet_interface_Cabling_h -#define L1Trigger_TrackFindingTracklet_interface_Cabling_h - -#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/DTC.h" -#include "L1Trigger/TrackFindingTracklet/interface/DTCLink.h" - -#include -#include - -namespace trklet { - - class Settings; - - class Cabling { - public: - Cabling(std::string dtcconfig, std::string moduleconfig, Settings const& settings); - - ~Cabling() = default; - - const std::string& dtc(int layer, int ladder, int module) const; - - void addphi(const std::string& dtc, double phi, int layer, int module); - - void writephirange() const; - - std::vector DTCs() const; - - private: - Settings const& settings_; - std::vector links_; - std::map dtcranges_; - std::map dtcs_; - std::map > > modules_; - }; - -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h b/L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h index 96358051401c6..8a20813e378d4 100644 --- a/L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h @@ -16,7 +16,7 @@ namespace trklet { class CandidateMatchMemory : public MemoryBase { public: - CandidateMatchMemory(std::string name, Settings const& settings, unsigned int iSector); + CandidateMatchMemory(std::string name, Settings const& settings); ~CandidateMatchMemory() override = default; @@ -28,7 +28,7 @@ namespace trklet { void clean() override { matches_.clear(); } - void writeCM(bool first); + void writeCM(bool first, unsigned int iSector); private: std::vector, const Stub*> > matches_; diff --git a/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h b/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h index 3d0832f56dc5e..e133757bbb70e 100644 --- a/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h +++ b/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h @@ -28,6 +28,11 @@ namespace trklet { //Almost full if writer ptr incremented by 1 or 2 is same as read ptr bool almostfull() const { return (((wptr_ + 1) % size_) == rptr_) || (((wptr_ + 2) % size_) == rptr_); } + //near full if writer ptr incremented by 1, 2, or 3 is same as read ptr + bool nearfull() const { + return (((wptr_ + 1) % size_) == rptr_) || (((wptr_ + 2) % size_) == rptr_) || (((wptr_ + 3) % size_) == rptr_); + } + //Empty buffer is write ptr is same as read ptr bool empty() const { return wptr_ == rptr_; } @@ -47,8 +52,13 @@ namespace trklet { assert(!full()); buffer_[wptr_++] = element; wptr_ = wptr_ % size_; + assert(wptr_ != rptr_); } + unsigned int rptr() const { return rptr_; } + + unsigned int wptr() const { return wptr_; } + private: std::vector buffer_; diff --git a/L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h b/L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h index 41e64bd302f12..d17754d944f4b 100644 --- a/L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h @@ -12,7 +12,7 @@ namespace trklet { class CleanTrackMemory : public MemoryBase { public: - CleanTrackMemory(std::string name, Settings const& settings, unsigned int iSector, double phimin, double phimax); + CleanTrackMemory(std::string name, Settings const& settings, double phimin, double phimax); ~CleanTrackMemory() override = default; @@ -22,7 +22,7 @@ namespace trklet { void clean() override { tracks_.clear(); } - void writeCT(bool first); + void writeCT(bool first, unsigned int iSector); private: double phimin_; diff --git a/L1Trigger/TrackFindingTracklet/interface/DTC.h b/L1Trigger/TrackFindingTracklet/interface/DTC.h deleted file mode 100644 index bbdf38c07636b..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/DTC.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_DTC_h -#define L1Trigger_TrackFindingTracklet_interface_DTC_h - -#include "L1Trigger/TrackFindingTracklet/interface/DTCLink.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" - -namespace trklet { - - class Stub; - class L1TStub; - - class DTC { - public: - DTC(std::string name = ""); - - ~DTC() = default; - - void setName(std::string name); - - void addSec(int sector); - - void addphi(double phi, unsigned int layerdisk); - - void addLink(double phimin, double phimax); - - int addStub(std::pair stub); - - unsigned int nLinks() const { return links_.size(); } - - const DTCLink& link(unsigned int i) const { return links_[i]; } - - void clean(); - - double min(unsigned int i) const { return phimin_[i]; } - double max(unsigned int i) const { return phimax_[i]; } - - private: - std::string name_; - std::vector links_; - std::vector sectors_; - - double phimin_[N_LAYER + N_DISK]; - double phimax_[N_LAYER + N_DISK]; - }; -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/DTCLink.h b/L1Trigger/TrackFindingTracklet/interface/DTCLink.h deleted file mode 100644 index d9f7a0c24bcf5..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/DTCLink.h +++ /dev/null @@ -1,34 +0,0 @@ -// This class holds a list of stubs that are in a given layer and DCT region -#ifndef L1Trigger_TrackFindingTracklet_interface_DTCLink_h -#define L1Trigger_TrackFindingTracklet_interface_DTCLink_h - -#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" -#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" - -namespace trklet { - - class DTCLink { - public: - DTCLink(double phimin, double phimax); - - ~DTCLink() = default; - - void addStub(std::pair stub); - - bool inRange(double phi, bool overlaplayer); - - unsigned int nStubs() const { return stubs_.size(); } - - Stub* getFPGAStub(unsigned int i) const { return stubs_[i].first; } - L1TStub* getL1TStub(unsigned int i) const { return stubs_[i].second; } - std::pair getStub(unsigned int i) const { return stubs_[i]; } - - void clean() { stubs_.clear(); } - - private: - double phimin_; - double phimax_; - std::vector > stubs_; - }; -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/DTCLinkMemory.h b/L1Trigger/TrackFindingTracklet/interface/DTCLinkMemory.h new file mode 100644 index 0000000000000..daab972a6ff0d --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/DTCLinkMemory.h @@ -0,0 +1,38 @@ +// This class holds a list of stubs for an DTC link. +// This modules 'owns' the pointers to the stubs. All subsequent modules that handles stubs uses a pointer to the original stored here. +#ifndef L1Trigger_TrackFindingTracklet_interface_DTCLinkMemory_h +#define L1Trigger_TrackFindingTracklet_interface_DTCLinkMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include + +namespace trklet { + + class Settings; + class Globals; + class Stub; + class L1TStub; + + class DTCLinkMemory : public MemoryBase { + public: + DTCLinkMemory(std::string name, Settings const& settings, double, double); + + ~DTCLinkMemory() override = default; + + void addStub(const L1TStub& al1stub, const Stub& stub); + + unsigned int nStubs() const { return stubs_.size(); } + + Stub* getStub(unsigned int i) { return stubs_[i]; } + + void writeStubs(bool first, unsigned int iSector); + + void clean() override; + + private: + std::vector stubs_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/DiskResidual.h b/L1Trigger/TrackFindingTracklet/interface/DiskResidual.h deleted file mode 100644 index 546410e5a78b7..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/DiskResidual.h +++ /dev/null @@ -1,112 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_DiskResidual_h -#define L1Trigger_TrackFindingTracklet_interface_DiskResidual_h - -#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" - -#include - -namespace trklet { - - class Settings; - class Stub; - - class DiskResidual { - public: - DiskResidual() { valid_ = false; } - - ~DiskResidual() = default; - - void init(Settings const& settings, - int disk, - int iphiresid, - int irresid, - int istubid, - double phiresid, - double rresid, - double phiresidapprox, - double rresidapprox, - double zstub, - double alpha, - FPGAWord ialpha, - const Stub* stubptr); - - bool valid() const { return valid_; } - - const FPGAWord& fpgaphiresid() const { - assert(valid_); - return fpgaphiresid_; - }; - - const FPGAWord& fpgarresid() const { - assert(valid_); - return fpgarresid_; - }; - - const FPGAWord& fpgastubid() const { - assert(valid_); - return fpgastubid_; - }; - - double phiresid() const { - assert(valid_); - return phiresid_; - }; - - double rresid() const { - assert(valid_); - return rresid_; - }; - - double phiresidapprox() const { - assert(valid_); - return phiresidapprox_; - }; - - double rresidapprox() const { - assert(valid_); - return rresidapprox_; - }; - - double zstub() const { - assert(valid_); - return zstub_; - }; - - double alpha() const { - assert(valid_); - return alpha_; - }; - - const FPGAWord& ialpha() const { - assert(valid_); - return ialpha_; - }; - - const Stub* stubptr() const { - assert(valid_); - return stubptr_; - }; - - protected: - bool valid_; - - int disk_; - - FPGAWord fpgaphiresid_; - FPGAWord fpgarresid_; - FPGAWord fpgastubid_; - - double phiresid_; - double rresid_; - - double phiresidapprox_; - double rresidapprox_; - - double zstub_; - double alpha_; - FPGAWord ialpha_; - const Stub* stubptr_; - }; - -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/FitTrack.h b/L1Trigger/TrackFindingTracklet/interface/FitTrack.h index fb897ec1660bd..e72c4cf664132 100644 --- a/L1Trigger/TrackFindingTracklet/interface/FitTrack.h +++ b/L1Trigger/TrackFindingTracklet/interface/FitTrack.h @@ -17,7 +17,7 @@ namespace trklet { class FitTrack : public ProcessBase { public: - FitTrack(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + FitTrack(std::string name, Settings const& settings, Globals* global); ~FitTrack() override = default; @@ -38,7 +38,7 @@ namespace trklet { std::vector orderedMatches(std::vector& fullmatch); - void execute(); + void execute(unsigned int iSector); private: std::vector seedtracklet_; @@ -47,6 +47,8 @@ namespace trklet { std::vector fullmatch3_; std::vector fullmatch4_; + unsigned int iSector_; + TrackFitMemory* trackfit_; }; diff --git a/L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h b/L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h index 10215946939c5..49f60cad58cf3 100644 --- a/L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h @@ -16,7 +16,7 @@ namespace trklet { class FullMatchMemory : public MemoryBase { public: - FullMatchMemory(std::string name, Settings const& settings, unsigned int iSector); + FullMatchMemory(std::string name, Settings const& settings); ~FullMatchMemory() override = default; @@ -30,7 +30,7 @@ namespace trklet { void clean() override { matches_.clear(); } - void writeMC(bool first); + void writeMC(bool first, unsigned int iSector); int layer() const { return layer_; } int disk() const { return disk_; } diff --git a/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h b/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h index 02879946c8eb7..90dae4b7ccf58 100644 --- a/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h @@ -17,24 +17,22 @@ namespace trklet { class InputLinkMemory : public MemoryBase { public: - InputLinkMemory(std::string name, Settings const& settings, unsigned int iSector, double, double); + InputLinkMemory(std::string name, Settings const& settings, double, double); ~InputLinkMemory() override = default; - bool addStub(Settings const& settings, Globals* globals, L1TStub& al1stub, Stub& stub, std::string dtc); + void addStub(Stub* stub); unsigned int nStubs() const { return stubs_.size(); } Stub* getStub(unsigned int i) { return stubs_[i]; } - void writeStubs(bool first); + void writeStubs(bool first, unsigned int iSector); void clean() override; private: std::vector stubs_; - int phiregion_; - unsigned int layerdisk_; }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/InputRouter.h b/L1Trigger/TrackFindingTracklet/interface/InputRouter.h new file mode 100644 index 0000000000000..55551d615ff21 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/InputRouter.h @@ -0,0 +1,39 @@ +// InputRouter: sorts input stubs into layer/disk and phi region +#ifndef L1Trigger_TrackFindingTracklet_interface_InputRouter_h +#define L1Trigger_TrackFindingTracklet_interface_InputRouter_h + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" + +#include +#include +#include + +namespace trklet { + + class Settings; + class Globals; + class MemoryBase; + class DTCLinkMemory; + class InputLinkMemory; + + class InputRouter : public ProcessBase { + public: + InputRouter(std::string name, Settings const& settings, Globals* global); + + ~InputRouter() override = default; + + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(); + + private: + //The input stub memories + DTCLinkMemory* dtcstubs_; + + //The all stub memories - the ints are layerdisk and phiregion + std::vector, InputLinkMemory*> > irstubs_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/L1SimTrack.h b/L1Trigger/TrackFindingTracklet/interface/L1SimTrack.h new file mode 100644 index 0000000000000..eddda2dbc1171 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/L1SimTrack.h @@ -0,0 +1,53 @@ +// Stores MC truth information, pt, eta, phi, vx, vy, vz, as well as particle type and track id +#ifndef L1Trigger_TrackFindingTracklet_interface_L1SimTrack_h +#define L1Trigger_TrackFindingTracklet_interface_L1SimTrack_h + +#include +#include +#include +#include +#include +#include + +namespace trklet { + + class L1SimTrack { + public: + L1SimTrack(); + L1SimTrack(int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz); + ~L1SimTrack() = default; + + void write(std::ofstream& out); + void write(std::ostream& out); + + int eventid() const { return eventid_; } + int trackid() const { return trackid_; } + int type() const { return type_; } + double pt() const { return pt_; } + double eta() const { return eta_; } + double phi() const { return phi_; } + double vx() const { return vx_; } + double vy() const { return vy_; } + double vz() const { return vz_; } + double dxy() const { return -vx() * sin(phi()) + vy() * cos(phi()); } + double d0() const { return -dxy(); } + int charge() const { + if (type_ == 11 || type_ == 13 || type_ == -211 || type_ == -321 || type_ == -2212) + return -1; + return 1; + } + + private: + int eventid_; + int trackid_; + int type_; + double pt_; + double eta_; + double phi_; + double vx_; + double vy_; + double vz_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/L1TStub.h b/L1Trigger/TrackFindingTracklet/interface/L1TStub.h index 2010d1eae1bb6..95a85bdaf4f1a 100644 --- a/L1Trigger/TrackFindingTracklet/interface/L1TStub.h +++ b/L1Trigger/TrackFindingTracklet/interface/L1TStub.h @@ -1,6 +1,8 @@ #ifndef L1Trigger_TrackFindingTracklet_interface_L1TStub_h #define L1Trigger_TrackFindingTracklet_interface_L1TStub_h +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + #include #include #include @@ -12,28 +14,23 @@ namespace trklet { class L1TStub { public: L1TStub(); - L1TStub(int eventid, - std::vector tps, - int iphi, - int iz, - int layer, - int ladder, - int module, - int strip, + + L1TStub(std::string DTClink, + int region, + int layerdisk, + std::string stubword, + int isPSmodule, + int isFlipped, double x, double y, double z, - double sigmax, - double sigmaz, - double pt, double bend, - int isPSmodule, - int isFlipped); + double strip, + std::vector tps); ~L1TStub() = default; void write(std::ofstream& out); - void write(std::ostream& out); double diphi(); @@ -43,10 +40,14 @@ namespace trklet { unsigned int layer() const { return layer_; } int disk() const { + if (layerdisk_ < N_LAYER) { + return 0; + } + int disk = layerdisk_ - N_LAYER + 1; if (z_ < 0.0) { - return -module_; + return -disk; } - return module_; + return disk; } unsigned int ladder() const { return ladder_; } unsigned int module() const { return module_; } @@ -96,8 +97,21 @@ namespace trklet { bool isTilted() const; bool tpmatch(int tp) const; + bool tpmatch2(int tp) const; + + const std::string& DTClink() const { return DTClink_; } + + int layerdisk() const { return layerdisk_; } + + int region() const { return region_; } + + const std::string& stubword() const { return stubword_; } private: + int layerdisk_; + std::string DTClink_; + int region_; + std::string stubword_; int eventid_; std::vector tps_; unsigned int iphi_; diff --git a/L1Trigger/TrackFindingTracklet/interface/LayerProjection.h b/L1Trigger/TrackFindingTracklet/interface/LayerProjection.h deleted file mode 100644 index b31854c5adcd2..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/LayerProjection.h +++ /dev/null @@ -1,163 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_LayerProjection_h -#define L1Trigger_TrackFindingTracklet_interface_LayerProjection_h - -#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" - -namespace trklet { - - class Settings; - - class LayerProjection { - public: - LayerProjection() { valid_ = false; } - - ~LayerProjection() = default; - - void init(Settings const& settings, - int projlayer, - double rproj, - int iphiproj, - int izproj, - int iphider, - int izder, - double phiproj, - double zproj, - double phiprojder, - double zprojder, - double phiprojapprox, - double zprojapprox, - double phiprojderapprox, - double zprojderapprox, - bool isPSseed = false); - - bool valid() const { return valid_; } - - int projlayer() const { - assert(valid_); - return projlayer_; - }; - - double rproj() const { - assert(valid_); - return rproj_; - }; - - const FPGAWord& fpgaphiproj() const { - assert(valid_); - return fpgaphiproj_; - }; - - const FPGAWord& fpgazproj() const { - assert(valid_); - return fpgazproj_; - }; - - const FPGAWord& fpgaphiprojder() const { - assert(valid_); - return fpgaphiprojder_; - }; - - const FPGAWord& fpgazprojder() const { - assert(valid_); - return fpgazprojder_; - }; - - const FPGAWord& fpgaphiprojvm() const { - assert(valid_); - return fpgaphiprojvm_; - }; - - const FPGAWord& fpgazbin1projvm() const { - assert(valid_); - return fpgazbin1projvm_; - }; - - const FPGAWord& fpgazbin2projvm() const { - assert(valid_); - return fpgazbin2projvm_; - }; - - const FPGAWord& fpgafinezvm() const { - assert(valid_); - return fpgafinezvm_; - }; - - const FPGAWord& fpgazprojvm() const { - assert(valid_); - return fpgazprojvm_; - }; - - double phiproj() const { - assert(valid_); - return phiproj_; - }; - - double zproj() const { - assert(valid_); - return zproj_; - }; - - double phiprojder() const { - assert(valid_); - return phiprojder_; - }; - - double zprojder() const { - assert(valid_); - return zprojder_; - }; - - double phiprojapprox() const { - assert(valid_); - return phiprojapprox_; - }; - - double zprojapprox() const { - assert(valid_); - return zprojapprox_; - }; - - double phiprojderapprox() const { - assert(valid_); - return phiprojderapprox_; - }; - - double zprojderapprox() const { - assert(valid_); - return zprojderapprox_; - }; - - protected: - bool valid_; - - int projlayer_; - - double rproj_; - - FPGAWord fpgaphiproj_; - FPGAWord fpgazproj_; - FPGAWord fpgaphiprojder_; - FPGAWord fpgazprojder_; - - FPGAWord fpgaphiprojvm_; - FPGAWord fpgazprojvm_; - - FPGAWord fpgazbin1projvm_; - FPGAWord fpgazbin2projvm_; - FPGAWord fpgafinezvm_; - - double phiproj_; - double zproj_; - double phiprojder_; - double zprojder_; - - double zbin1_; - double zbin2_; - - double phiprojapprox_; - double zprojapprox_; - double phiprojderapprox_; - double zprojderapprox_; - }; -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h b/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h index 16d95f9d85f33..2a4051e98cb55 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h @@ -20,14 +20,14 @@ namespace trklet { class MatchCalculator : public ProcessBase { public: - MatchCalculator(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + MatchCalculator(std::string name, Settings const& settings, Globals* global); ~MatchCalculator() override = default; void addOutput(MemoryBase* memory, std::string output) override; void addInput(MemoryBase* memory, std::string input) override; - void execute(); + void execute(double phioffset); std::vector, const Stub*> > mergeMatches( std::vector& candmatch); @@ -40,7 +40,6 @@ namespace trklet { int icorrshift_; int icorzshift_; int phi0shift_; - double phioffset_; unsigned int phimatchcut_[N_SEED]; unsigned int zmatchcut_[N_SEED]; diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h b/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h index 4d935e87322c1..db0ba984a85a5 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h @@ -15,7 +15,7 @@ namespace trklet { class MatchEngine : public ProcessBase { public: - MatchEngine(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + MatchEngine(std::string name, Settings const& settings, Globals* global); ~MatchEngine() override = default; @@ -30,13 +30,15 @@ namespace trklet { CandidateMatchMemory* candmatches_; - int layer_; - int disk_; + unsigned int layerdisk_; bool barrel_; int nvm_; int nvmbits_; + unsigned int nfinephibits_; //number of fine phi bits in phi VM bin + unsigned int nrinv_; //number of bits for rinv in stub bend LUT + //used in the layers std::vector table_; diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h index cb84945be1865..f61a4a659ee7c 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h @@ -17,16 +17,22 @@ namespace trklet { class MatchEngineUnit { public: - MatchEngineUnit(bool barrel, std::vector table, std::vector tablePS, std::vector table2S); + MatchEngineUnit(bool barrel, unsigned int layerdisk, std::vector table); ~MatchEngineUnit() = default; void init(VMStubsMEMemory* vmstubsmemory, - unsigned int slot, + unsigned int nrzbin, + unsigned int rzbin, + unsigned int iphi, + int shift, int projrinv, int projfinerz, int projfinephi, - bool usesecond, + bool usefirstMinus, + bool usefirstPlus, + bool usesecondMinus, + bool usesecondPlus, bool isPSseed, Tracklet* proj); @@ -42,34 +48,36 @@ namespace trklet { void reset(); - void step(); + void step(bool print); private: VMStubsMEMemory* vmstubsmemory_; - //unsigned int memory slot - unsigned int slot_; + unsigned int nrzbins_; + unsigned int rzbin_; + unsigned int phibin_; + int shift_; + unsigned int istub_; + unsigned int iuse_; bool barrel_; int projrinv_; int projfinerz_; int projfinephi_; - bool usesecond_; + std::vector> use_; bool isPSseed_; Tracklet* proj_; bool idle_; - //used in the layers - std::vector table_; + unsigned int layerdisk_; - //used in the disks - std::vector tablePS_; - std::vector table2S_; + //used for bend consistency with rinv + std::vector table_; //save the candidate matches - CircularBuffer > candmatches_; + CircularBuffer> candmatches_; }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h b/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h index 5758957ec555b..cbda531d96186 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h @@ -23,20 +23,18 @@ namespace trklet { class MatchProcessor : public ProcessBase { public: - MatchProcessor(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + MatchProcessor(std::string name, Settings const& settings, Globals* global); ~MatchProcessor() override = default; void addOutput(MemoryBase* memory, std::string output) override; void addInput(MemoryBase* memory, std::string input) override; - void execute(); + void execute(unsigned int iSector, double phimin); - bool matchCalculator(Tracklet* tracklet, const Stub* fpgastub); + bool matchCalculator(Tracklet* tracklet, const Stub* fpgastub, bool print, unsigned int istep); private: - int layer_; - int disk_; unsigned int layerdisk_; bool barrel_; @@ -45,13 +43,12 @@ namespace trklet { int nvm_; //VMs in sector int nvmbits_; //# of bits for VMs in sector int nvmbins_; //VMs in in phi region + int nrinv_; //# of bits for rinv - int fact_; + int dzshift_; int icorrshift_; int icorzshift_; - int phi0shift_; - - double phioffset_; + int phishift_; unsigned int phimatchcut_[N_SEED]; unsigned int zmatchcut_[N_SEED]; @@ -61,9 +58,6 @@ namespace trklet { unsigned int rcutPS_[N_SEED]; unsigned int rcut2S_[N_SEED]; - double phifact_; - double rzfact_; - int nrbits_; int nphiderbits_; @@ -77,12 +71,10 @@ namespace trklet { //Memory for the full matches std::vector fullmatches_; - //used in the layers + //used for bend consistency with rinv std::vector table_; - //used in the disks - std::vector tablePS_; - std::vector table2S_; + double phimin_; unsigned int nMatchEngines_; std::vector matchengines_; diff --git a/L1Trigger/TrackFindingTracklet/interface/MemoryBase.h b/L1Trigger/TrackFindingTracklet/interface/MemoryBase.h index 2c92d3606d5c7..ca0280bff8911 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MemoryBase.h +++ b/L1Trigger/TrackFindingTracklet/interface/MemoryBase.h @@ -12,7 +12,7 @@ namespace trklet { class MemoryBase { public: - MemoryBase(std::string name, Settings const& settings, unsigned int iSector); + MemoryBase(std::string name, Settings const& settings); virtual ~MemoryBase() = default; diff --git a/L1Trigger/TrackFindingTracklet/interface/ProcessBase.h b/L1Trigger/TrackFindingTracklet/interface/ProcessBase.h index 4033b6ca025cf..35fe4015c5e92 100644 --- a/L1Trigger/TrackFindingTracklet/interface/ProcessBase.h +++ b/L1Trigger/TrackFindingTracklet/interface/ProcessBase.h @@ -11,7 +11,7 @@ namespace trklet { class ProcessBase { public: - ProcessBase(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + ProcessBase(std::string name, Settings const& settings, Globals* global); virtual ~ProcessBase() = default; @@ -36,10 +36,6 @@ namespace trklet { protected: std::string name_; - unsigned int iSector_; - - double phimin_; - double phimax_; Settings const& settings_; Globals* globals_; diff --git a/L1Trigger/TrackFindingTracklet/interface/DiskProjection.h b/L1Trigger/TrackFindingTracklet/interface/Projection.h similarity index 50% rename from L1Trigger/TrackFindingTracklet/interface/DiskProjection.h rename to L1Trigger/TrackFindingTracklet/interface/Projection.h index 83784c5ea042b..80739c56672d5 100644 --- a/L1Trigger/TrackFindingTracklet/interface/DiskProjection.h +++ b/L1Trigger/TrackFindingTracklet/interface/Projection.h @@ -1,46 +1,39 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_DiskProjection_h -#define L1Trigger_TrackFindingTracklet_interface_DiskProjection_h +#ifndef L1Trigger_TrackFindingTracklet_interface_Projection_h +#define L1Trigger_TrackFindingTracklet_interface_Projection_h #include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" -#include - namespace trklet { class Settings; - class DiskProjection { + class Projection { public: - DiskProjection() { valid_ = false; } + Projection() { valid_ = false; } - ~DiskProjection() = default; + ~Projection() = default; void init(Settings const& settings, - int projdisk, - double zproj, + unsigned int layerdisk, int iphiproj, - int irproj, + int irzproj, int iphider, - int irder, + int irzder, double phiproj, - double rproj, + double rzproj, double phiprojder, - double rprojder, + double rzprojder, double phiprojapprox, - double rprojapprox, + double rzprojapprox, double phiprojderapprox, - double rprojderapprox); + double rzprojderapprox, + bool isPSseed); bool valid() const { return valid_; } - int projdisk() const { + unsigned int layerdisk() const { assert(valid_); - return projdisk_; - }; - - double zproj() const { - assert(valid_); - return zproj_; + return layerdisk_; }; const FPGAWord& fpgaphiproj() const { @@ -48,9 +41,9 @@ namespace trklet { return fpgaphiproj_; }; - const FPGAWord& fpgarproj() const { + const FPGAWord& fpgarzproj() const { assert(valid_); - return fpgarproj_; + return fpgarzproj_; }; const FPGAWord& fpgaphiprojder() const { @@ -58,44 +51,39 @@ namespace trklet { return fpgaphiprojder_; }; - const FPGAWord& fpgarprojder() const { + const FPGAWord& fpgarzprojder() const { assert(valid_); - return fpgarprojder_; + return fpgarzprojder_; }; - const FPGAWord& fpgaphiprojvm() const { + const FPGAWord& fpgarzbin1projvm() const { assert(valid_); - return fpgaphiprojvm_; + return fpgarzbin1projvm_; }; - const FPGAWord& fpgarprojvm() const { + const FPGAWord& fpgarzbin2projvm() const { assert(valid_); - return fpgarprojvm_; - }; - - double phiproj() const { - assert(valid_); - return phiproj_; + return fpgarzbin2projvm_; }; - const FPGAWord& fpgarbin1projvm() const { + const FPGAWord& fpgafinerzvm() const { assert(valid_); - return fpgarbin1projvm_; + return fpgafinerzvm_; }; - const FPGAWord& fpgarbin2projvm() const { + const FPGAWord& fpgafinephivm() const { assert(valid_); - return fpgarbin2projvm_; + return fpgafinephivm_; }; - const FPGAWord& fpgafinervm() const { + double phiproj() const { assert(valid_); - return fpgafinervm_; + return phiproj_; }; - double rproj() const { + double rzproj() const { assert(valid_); - return rproj_; + return rzproj_; }; double phiprojder() const { @@ -103,9 +91,9 @@ namespace trklet { return phiprojder_; }; - double rprojder() const { + double rzprojder() const { assert(valid_); - return rprojder_; + return rzprojder_; }; double phiprojapprox() const { @@ -113,9 +101,9 @@ namespace trklet { return phiprojapprox_; }; - double rprojapprox() const { + double rzprojapprox() const { assert(valid_); - return rprojapprox_; + return rzprojapprox_; }; double phiprojderapprox() const { @@ -123,9 +111,9 @@ namespace trklet { return phiprojderapprox_; }; - double rprojderapprox() const { + double rzprojderapprox() const { assert(valid_); - return rprojderapprox_; + return rzprojderapprox_; }; void setBendIndex(int bendindex) { fpgabendindex_.set(bendindex, 5, true, __LINE__, __FILE__); } @@ -135,34 +123,30 @@ namespace trklet { protected: bool valid_; - int projdisk_; - - double zproj_; + unsigned int layerdisk_; FPGAWord fpgaphiproj_; - FPGAWord fpgarproj_; + FPGAWord fpgarzproj_; FPGAWord fpgaphiprojder_; - FPGAWord fpgarprojder_; + FPGAWord fpgarzprojder_; - FPGAWord fpgaphiprojvm_; - FPGAWord fpgarprojvm_; - - FPGAWord fpgarbin1projvm_; - FPGAWord fpgarbin2projvm_; - FPGAWord fpgafinervm_; - - FPGAWord fpgabendindex_; + FPGAWord fpgarzbin1projvm_; + FPGAWord fpgarzbin2projvm_; + FPGAWord fpgafinerzvm_; + FPGAWord fpgafinephivm_; double phiproj_; - double rproj_; + double rzproj_; double phiprojder_; - double rprojder_; + double rzprojder_; double phiprojapprox_; - double rprojapprox_; + double rzprojapprox_; double phiprojderapprox_; - double rprojderapprox_; - }; + double rzprojderapprox_; + //used by projections to disks + FPGAWord fpgabendindex_; + }; }; // namespace trklet #endif diff --git a/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h b/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h index 2559a22a96fbf..7b898f1b2e7a4 100644 --- a/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h +++ b/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h @@ -15,7 +15,7 @@ namespace trklet { class ProjectionRouter : public ProcessBase { public: - ProjectionRouter(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + ProjectionRouter(std::string name, Settings const& settings, Globals* global); ~ProjectionRouter() override = default; diff --git a/L1Trigger/TrackFindingTracklet/interface/ProjectionTemp.h b/L1Trigger/TrackFindingTracklet/interface/ProjectionTemp.h index 4b8a445146d96..e34786d37587e 100644 --- a/L1Trigger/TrackFindingTracklet/interface/ProjectionTemp.h +++ b/L1Trigger/TrackFindingTracklet/interface/ProjectionTemp.h @@ -14,7 +14,11 @@ namespace trklet { int projfinerz, unsigned int projfinephi, unsigned int iphi, - bool usesecond, + int shift, + bool usefirstMinus, + bool usefirstPlus, + bool usesecondMinus, + bool usesecondPlus, bool isPSseed); ProjectionTemp(); @@ -27,7 +31,8 @@ namespace trklet { int projfinerz() const { return projfinerz_; } unsigned int projfinephi() const { return projfinephi_; } unsigned int iphi() const { return iphi_; } - bool usesecond() const { return usesecond_; } + int shift() const { return shift_; } + bool use(unsigned int nextrzbin, unsigned int nextiphibin) const { return use_[nextrzbin][nextiphibin]; } bool isPSseed() const { return isPSseed_; } private: @@ -37,7 +42,10 @@ namespace trklet { unsigned int projfinerz_; unsigned int projfinephi_; unsigned int iphi_; - bool usesecond_; + int shift_; + //Projection may use two bins in rz and phi if the projection is near a boundary + //The use_[rz][phi] array indicates which bins are used. + bool use_[2][2]; bool isPSseed_; }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h b/L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h index 833c41e30a7b4..6600a3de15d98 100644 --- a/L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h +++ b/L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h @@ -19,14 +19,14 @@ namespace trklet { class PurgeDuplicate : public ProcessBase { public: - PurgeDuplicate(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + PurgeDuplicate(std::string name, Settings const& settings, Globals* global); ~PurgeDuplicate() override = default; void addOutput(MemoryBase* memory, std::string output) override; void addInput(MemoryBase* memory, std::string input) override; - void execute(std::vector& outputtracks_); + void execute(std::vector& outputtracks_, unsigned int iSector); private: double getPhiRes(Tracklet* curTracklet, const Stub* curStub); diff --git a/L1Trigger/TrackFindingTracklet/interface/LayerResidual.h b/L1Trigger/TrackFindingTracklet/interface/Residual.h similarity index 61% rename from L1Trigger/TrackFindingTracklet/interface/LayerResidual.h rename to L1Trigger/TrackFindingTracklet/interface/Residual.h index 1c2cf303ae479..8eb934bee4d92 100644 --- a/L1Trigger/TrackFindingTracklet/interface/LayerResidual.h +++ b/L1Trigger/TrackFindingTracklet/interface/Residual.h @@ -1,5 +1,5 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_LayerResidual_h -#define L1Trigger_TrackFindingTracklet_interface_LayerResidual_h +#ifndef L1Trigger_TrackFindingTracklet_interface_Residual_h +#define L1Trigger_TrackFindingTracklet_interface_Residual_h #include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" @@ -10,22 +10,21 @@ namespace trklet { class Settings; class Stub; - class LayerResidual { + class Residual { public: - LayerResidual() { valid_ = false; } + Residual() { valid_ = false; } - ~LayerResidual() = default; + ~Residual() = default; void init(Settings const& settings, - int layer, + unsigned int layerdisk, int iphiresid, - int izresid, + int irzresid, int istubid, double phiresid, - double zresid, + double rzresid, double phiresidapprox, - double zresidapprox, - double rstub, + double rzresidapprox, const Stub* stubptr); bool valid() const { return valid_; } @@ -35,9 +34,9 @@ namespace trklet { return fpgaphiresid_; }; - const FPGAWord& fpgazresid() const { + const FPGAWord& fpgarzresid() const { assert(valid_); - return fpgazresid_; + return fpgarzresid_; }; const FPGAWord& fpgastubid() const { @@ -50,9 +49,9 @@ namespace trklet { return phiresid_; }; - double zresid() const { + double rzresid() const { assert(valid_); - return zresid_; + return rzresid_; }; double phiresidapprox() const { @@ -60,16 +59,11 @@ namespace trklet { return phiresidapprox_; }; - double zresidapprox() const { + double rzresidapprox() const { assert(valid_); - return zresidapprox_; + return rzresidapprox_; }; - double rstub() const { - assert(valid_); - return rstub_; - } - const Stub* stubptr() const { assert(valid_); return stubptr_; @@ -78,19 +72,18 @@ namespace trklet { protected: bool valid_; - int layer_; + unsigned int layerdisk_; FPGAWord fpgaphiresid_; - FPGAWord fpgazresid_; + FPGAWord fpgarzresid_; FPGAWord fpgastubid_; double phiresid_; - double zresid_; + double rzresid_; double phiresidapprox_; - double zresidapprox_; + double rzresidapprox_; - double rstub_; const Stub* stubptr_; }; diff --git a/L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h b/L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h index 0ef6024854059..74dfc0d22d3fd 100644 --- a/L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h +++ b/L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h @@ -10,47 +10,10 @@ #include #include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1SimTrack.h" namespace trklet { - class L1SimTrack { - public: - L1SimTrack(); - L1SimTrack(int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz); - ~L1SimTrack() = default; - - void write(std::ofstream& out); - void write(std::ostream& out); - - int eventid() const { return eventid_; } - int trackid() const { return trackid_; } - int type() const { return type_; } - double pt() const { return pt_; } - double eta() const { return eta_; } - double phi() const { return phi_; } - double vx() const { return vx_; } - double vy() const { return vy_; } - double vz() const { return vz_; } - double dxy() const { return -vx() * sin(phi()) + vy() * cos(phi()); } - double d0() const { return -dxy(); } - int charge() const { - if (type_ == 11 || type_ == 13 || type_ == -211 || type_ == -321 || type_ == -2212) - return -1; - return 1; - } - - private: - int eventid_; - int trackid_; - int type_; - double pt_; - double eta_; - double phi_; - double vx_; - double vy_; - double vz_; - }; - class SLHCEvent { public: SLHCEvent() { @@ -60,32 +23,32 @@ namespace trklet { SLHCEvent(std::istream& in); ~SLHCEvent() = default; - void setIPx(double x) { x_offset_ = x; } - void setIPy(double y) { y_offset_ = y; } - void setEventNum(int eventnum) { eventnum_ = eventnum; } void addL1SimTrack( int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz); - bool addStub(int layer, - int ladder, - int module, - int strip, - int eventid, - std::vector tps, - double pt, - double bend, + bool addStub(std::string DTClink, + int region, + int layerdisk, + std::string stubword, + int isPSmodule, + int isFlipped, double x, double y, double z, - int isPSmodule, - int isFlipped); + double bend, + double strip, + std::vector tps); const L1TStub& lastStub() const { return stubs_.back(); } + void setIP(double x, double y) { + ipx_ = x; + ipy_ = y; + } + void write(std::ofstream& out); - void write(std::ostream& out); unsigned int layersHit(int tpid, int& nlayers, int& ndisks); @@ -99,15 +62,11 @@ namespace trklet { int eventnum() const { return eventnum_; } - int getSimtrackFromSimtrackid(int simtrackid, int eventid = 0) const; - private: int eventnum_; std::vector simtracks_; std::vector stubs_; - - double x_offset_{0.0}; - double y_offset_{0.0}; + double ipx_, ipy_; }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/Sector.h b/L1Trigger/TrackFindingTracklet/interface/Sector.h index fdddb08af0055..ab3d67bdb39e7 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Sector.h +++ b/L1Trigger/TrackFindingTracklet/interface/Sector.h @@ -11,6 +11,7 @@ #include #include #include +#include namespace trklet { @@ -23,8 +24,10 @@ namespace trklet { class Stub; //Memory modules + class DTCLinkMemory; class InputLinkMemory; class AllStubsMemory; + class AllInnerStubsMemory; class VMStubsTEMemory; class VMStubsMEMemory; class StubPairsMemory; @@ -39,6 +42,7 @@ namespace trklet { class CleanTrackMemory; //Processing modules + class InputRouter; class VMRouter; class VMRouterCM; class TrackletEngine; @@ -56,10 +60,13 @@ namespace trklet { class Sector { public: - Sector(unsigned int i, Settings const& settings, Globals* globals); + Sector(Settings const& settings, Globals* globals); ~Sector(); + //Set the sector + void setSector(unsigned int isector); + bool addStub(L1TStub stub, std::string dtc); //TODO - should be pointer or string // Creates all required memory modules based on wiring map (args: module type, module instance) @@ -75,10 +82,12 @@ namespace trklet { ProcessBase* getProc(std::string procName); MemoryBase* getMem(std::string memName); - void writeInputStubs(bool first); + void writeDTCStubs(bool first); + void writeIRStubs(bool first); void writeVMSTE(bool first); void writeVMSME(bool first); void writeAS(bool first); + void writeAIS(bool first); void writeSP(bool first); void writeST(bool first); void writeTPAR(bool first); @@ -93,6 +102,7 @@ namespace trklet { void clean(); // execute the different tracklet processing modules + void executeIR(); void executeVMR(); void executeTE(); void executeTED(); @@ -105,7 +115,7 @@ namespace trklet { void executeMC(); void executeMP(); void executeFT(); - void executePD(std::vector& tracks); + void executePD(std::vector& tracks); std::vector getAllTracklets() const; std::vector getStubs() const; @@ -137,8 +147,10 @@ namespace trklet { std::map Memories_; std::vector MemoriesV_; + std::vector > DL_; std::vector > IL_; std::vector > AS_; + std::vector > AIS_; std::vector > VMSTE_; std::vector > VMSME_; std::vector > SP_; @@ -153,6 +165,7 @@ namespace trklet { std::vector > CT_; std::map Processes_; + std::vector > IR_; std::vector > VMR_; std::vector > VMRCM_; std::vector > TE_; diff --git a/L1Trigger/TrackFindingTracklet/interface/Settings.h b/L1Trigger/TrackFindingTracklet/interface/Settings.h index 1e045222c4ada..0759b7ebcf279 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Settings.h +++ b/L1Trigger/TrackFindingTracklet/interface/Settings.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" @@ -16,18 +18,33 @@ namespace trklet { constexpr unsigned int N_SECTOR = 9; // # of phi sectors for L1TK processing - constexpr int N_LAYER = 6; // # of barrel layers assumed - constexpr int N_DISK = 5; // # of endcap disks assumed - constexpr unsigned int N_PSLAYER = 3; // # of barrel PS layers assumed - constexpr unsigned int N_SEED = 12; // # of tracklet+triplet seeds + constexpr int N_LAYER = 6; // # of barrel layers assumed + constexpr int N_DISK = 5; // # of endcap disks assumed + constexpr unsigned int N_PSLAYER = 3; // # of barrel PS layers assumed + constexpr unsigned int N_SEED = 12; // # of tracklet+triplet seeds + constexpr unsigned int N_SEED_PROMPT = 8; // # of tracklet (prompt) seeds constexpr unsigned int N_DSS_MOD = 5; // # of rings with 2S modules per disk - constexpr unsigned int NRINVBITS = 5; //number of bit for rinv in bend match table - constexpr unsigned int NFINERZBITS = 3; //number of bit for r or z within a r/z bin + constexpr unsigned int N_BENDBITS_PS = 3; // Number of bend bits for PS modules + constexpr unsigned int N_BENDBITS_2S = 4; // Number of bend bits for 2S modules + + constexpr unsigned int NRINVBITS = 5; //number of bit for rinv in bend match table + constexpr unsigned int NFINERZBITS = 3; //number of bit for r or z within a r/z bin + constexpr unsigned int NFINEPHIBITS = 3; //number of bits for phi within a vm bin + constexpr unsigned int N_RZBITS = 3; //number of bit for the r/z bins + + constexpr unsigned int N_VMSTUBSMAX = 15; // maximum number of stubs in VM bin + constexpr unsigned int N_BITSMEMADDRESS = 7; // Number of bits for address in memories constexpr double sixth = 1.0 / 6.0; //Commonly used factor + constexpr double third = 1.0 / 3.0; //Commonly used factor + constexpr double VMROUTERCUTZL2 = 50.0; //Min L2 z for inner allstub + constexpr double VMROUTERCUTZL1L3L5 = 95.0; //Max z for inner barrel layers + constexpr double VMROUTERCUTZL1 = 70.0; //Max z for L1 barrel seeding + constexpr double VMROUTERCUTRD1D3 = 55.0; //Max r for disk seeds + class Settings { public: Settings() { @@ -42,9 +59,6 @@ namespace trklet { ~Settings() = default; // processing & memory modules, wiring, etc. - std::string DTCLinkFile() const { return DTCLinkFile_; } - std::string const& moduleCablingFile() const { return moduleCablingFile_; } - std::string const& DTCLinkLayerDiskFile() const { return DTCLinkLayerDiskFile_; } std::string const& fitPatternFile() const { return fitPatternFile_; } std::string const& processingModulesFile() const { return processingModulesFile_; } std::string const& memoryModulesFile() const { return memoryModulesFile_; } @@ -52,11 +66,6 @@ namespace trklet { std::string const& tableTEDFile() const { return tableTEDFile_; } std::string const& tableTREFile() const { return tableTREFile_; } - void setDTCLinkFile(std::string DTCLinkFileName) { DTCLinkFile_ = DTCLinkFileName; } - void setModuleCablingFile(std::string moduleCablingFileName) { moduleCablingFile_ = moduleCablingFileName; } - void setDTCLinkLayerDiskFile(std::string DTCLinkLayerDiskFileName) { - DTCLinkLayerDiskFile_ = DTCLinkLayerDiskFileName; - } void setFitPatternFile(std::string fitPatternFileName) { fitPatternFile_ = fitPatternFileName; } void setProcessingModulesFile(std::string processingModulesFileName) { processingModulesFile_ = processingModulesFileName; @@ -117,8 +126,6 @@ namespace trklet { double half2SmoduleWidth() const { return half2SmoduleWidth_; } - double bendcutte(unsigned int inner, unsigned int iSeed) const { return bendcutte_[inner][iSeed]; } - double bendcutme(unsigned int layerdisk) const { return bendcutme_[layerdisk]; } int nfinephi(unsigned int inner, unsigned int iSeed) const { return nfinephi_[inner][iSeed]; } double nphireg(unsigned int inner, unsigned int iSeed) const { if (combined_) { @@ -131,6 +138,16 @@ namespace trklet { return lutwidthtabextended_[inner][iSeed]; } + unsigned int seedlayers(int inner, int seed) const { + int layerdisk = seedlayers_[seed][inner]; + assert(layerdisk >= 0); + return layerdisk; + } + + unsigned int teunits(unsigned int iSeed) const { return teunits_[iSeed]; } + + unsigned int NTC(int seed) const { return ntc_[seed]; } + unsigned int projlayers(unsigned int iSeed, unsigned int i) const { return projlayers_[iSeed][i]; } unsigned int projdisks(unsigned int iSeed, unsigned int i) const { return projdisks_[iSeed][i]; } double rphimatchcut(unsigned int iSeed, unsigned int ilayer) const { return rphimatchcut_[ilayer][iSeed]; } @@ -166,8 +183,10 @@ namespace trklet { bool writeMem() const { return writeMem_; } bool writeTable() const { return writeTable_; } - std::string const& memPath() const { return memPath_; } - std::string const& tablePath() const { return tablePath_; } + bool writeConfig() const { return writeConfig_; } + + std::string memPath() const { return memPath_; } + std::string tablePath() const { return tablePath_; } bool writeVerilog() const { return writeVerilog_; } bool writeHLS() const { return writeHLS_; } @@ -256,9 +275,10 @@ namespace trklet { void setNbitsseedextended(unsigned int nbitsseed) { nbitsseedextended_ = nbitsseed; } double dphisectorHG() const { - return 2 * M_PI / N_SECTOR + - 2 * std::max(std::abs(asin(0.5 * rinvmax() * rmean(0)) - asin(0.5 * rinvmax() * rcrit_)), - std::abs(asin(0.5 * rinvmax() * rmean(5)) - asin(0.5 * rinvmax() * rcrit_))); + //These values are used in the DTC emulation code. + double rsectmin = 21.8; + double rsectmax = 112.7; + return 2 * M_PI / N_SECTOR + rinvmax() * std::max(rcrit_ - rsectmin, rsectmax - rcrit_); } double rcrit() const { return rcrit_; } @@ -272,10 +292,13 @@ namespace trklet { double phicritmaxmc() const { return phicritmax() + dphicritmc_; } double kphi() const { return dphisectorHG() / (1 << nphibitsstub(0)); } - double kphi1() const { return dphisectorHG() / (1 << nphibitsstub(5)); } + double kphi1() const { return dphisectorHG() / (1 << nphibitsstub(N_LAYER - 1)); } + double kphi(unsigned int layerdisk) const { return dphisectorHG() / (1 << nphibitsstub(layerdisk)); } - double kz() const { return 2 * zlength_ / (1 << nzbitsstub_[0]); } - double kr() const { return rmaxdisk_ / (1 << nrbitsstub_[6]); } + double kz() const { return 2.0 * zlength_ / (1 << nzbitsstub_[0]); } + double kz(unsigned int layerdisk) const { return 2.0 * zlength_ / (1 << nzbitsstub_[layerdisk]); } + double kr() const { return rmaxdisk_ / (1 << nrbitsstub_[N_LAYER]); } + double krbarrel() const { return 2.0 * drmax() / (1 << nrbitsstub_[0]); } double maxrinv() const { return maxrinv_; } double maxd0() const { return maxd0_; } @@ -363,17 +386,48 @@ namespace trklet { double kz0pars() const { return kz(); } double kd0pars() const { return kd0(); } - double kphider() const { return krinvpars() / (1 << phiderbitshift_); } - double kzder() const { return ktpars() / (1 << zderbitshift_); } + double kphider() const { return kphi() / kr() / 256; } + double kphiderdisk() const { return kphi() / kr() / 128; } + double kzder() const { return 1.0 / 64; } + double krder() const { return 1.0 / 128; } //This is a 'historical accident' and should be fixed so that we don't //have the factor if 2 double krprojshiftdisk() const { return 2 * kr(); } + double benddecode(int ibend, int layerdisk, bool isPSmodule) const { + if (layerdisk >= N_LAYER && (!isPSmodule)) + layerdisk += (N_LAYER - 1); + double bend = benddecode_[layerdisk][ibend]; + assert(bend < 99.0); + return bend; + } + + double bendcut(int ibend, int layerdisk, bool isPSmodule) const { + if (layerdisk >= N_LAYER && (!isPSmodule)) + layerdisk += (N_LAYER - 1); + double bendcut = bendcut_[layerdisk][ibend]; + if (bendcut <= 0.0) + std::cout << "bendcut : " << layerdisk << " " << ibend << " " << isPSmodule << std::endl; + assert(bendcut > 0.0); + return bendcut; + } + + const std::vector& dtcLayers(const std::string& dtcName) const { + auto iter=dtclayers_.find(dtcName); + assert(iter!=dtclayers_.end()); + return iter->second; + } + + double bendcutte(int ibend, int layerdisk, bool isPSmodule) const { return bendcut(ibend, layerdisk, isPSmodule); } + + double bendcutme(int ibend, int layerdisk, bool isPSmodule) const { + //FIXME temporary fix until phiprojderdisk bits adjusted. But requires coordinatin with HLS + double fact = (layerdisk < N_LAYER) ? 1.0 : 1.8; + return fact * bendcut(ibend, layerdisk, isPSmodule); + } + private: - std::string DTCLinkFile_; - std::string moduleCablingFile_; - std::string DTCLinkLayerDiskFile_; std::string fitPatternFile_; std::string processingModulesFile_; std::string memoryModulesFile_; @@ -419,11 +473,18 @@ namespace trklet { {{3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2}}, {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1}}}}; - std::array, 2> bendcutte_{ - {{{1.25, 1.25, 1.25, 1.25, 1.25, 1.25, 1.25, 1.25}}, //inner (2 = #stubs/tracklet) - {{1.25, 1.25, 1.25, 1.25, 1.25, 1.25, 1.25, 1.25}}}}; //outer - - std::array bendcutme_{{2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.5, 1.5, 1.5, 1.5, 1.5}}; + std::map > dtclayers_{{"PS10G_1", {0, 6, 8, 10}}, + {"PS10G_2", {0, 7, 9}}, + {"PS10G_3", {1, 7}}, + {"PS10G_4", {6, 8, 10}}, + {"PS_1", {2, 7}}, + {"PS_2", {2, 9}}, + {"2S_1", {3, 4}}, + {"2S_2", {4}}, + {"2S_3", {5}}, + {"2S_4", {5, 8}}, + {"2S_5", {6, 9}}, + {"2S_6", {7, 10}}}; double rmindiskvm_{22.5}; double rmaxdiskvm_{67.0}; @@ -513,6 +574,8 @@ namespace trklet { int chisqphifactbits_{14}; int chisqzfactbits_{14}; + std::array teunits_{{5, 2, 5, 3, 3, 2, 3, 2, 0, 0, 0, 0}}; //teunits used by seed + std::array vmrlutzbits_{ {7, 7, 7, 7, 7, 7, 3, 3, 3, 3, 3}}; // zbits used by LUT in VMR std::array vmrlutrbits_{ @@ -545,6 +608,23 @@ namespace trklet { {{6, 6, 6, 6, 10, 10, 10, 10, 0, 0, 6, 0}}, {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6}}}}; + //layers/disks used by each seed + std::array, N_SEED> seedlayers_{{{{0, 1, -1}}, //L1L2 + {{1, 2, -1}}, //1 L2L3 + {{2, 3, -1}}, //2 L3L4 + {{4, 5, -1}}, //3 L5L6 + {{6, 7, -1}}, //4 D1D2 + {{8, 9, -1}}, //5 D3D4 + {{0, 6, -1}}, //6 L1D1 + {{1, 6, -1}}, //7 L2D1 + {{2, 3, 1}}, //8 L2L3L4 + {{4, 5, 3}}, //9 L4L5L6 + {{1, 2, 6}}, //10 L2L3D1 + {{6, 7, 1}}}}; //11 D1D2L2 + + //Number of tracklet calculators for the prompt seeding combinations + std::array ntc_{{12, 4, 4, 4, 4, 4, 8, 4, 0, 0, 0, 0}}; + //projection layers by seed index. For each seeding index (row) the list of layers that we consider projections to std::array, N_SEED> projlayers_{{{{3, 4, 5, 6}}, //0 L1L2 {{1, 4, 5, 6}}, //1 L2L3 @@ -568,7 +648,7 @@ namespace trklet { {{1, 2, 5}}, //5 D3D4 {{2, 3, 4, 5}}, //6 L1D1 {{2, 3, 4}}, //7 L2D1 - {{1, 2}}, //8 L2L3L4 + {{1, 2, 3}}, //8 L2L3L4 {{}}, //9 L4L5L6 {{2, 3, 4}}, //10 L2L3D1 {{3, 4}}}}; //11 D1D2L2 @@ -623,14 +703,53 @@ namespace trklet { {{3.6, 3.8, 0.0, 0.0, 3.6, 0.0, 3.5, 3.8, 0.0, 0.0, 3.0, 3.0}}, //disk 4 {{0.0, 0.0, 0.0, 0.0, 3.6, 3.4, 3.7, 0.0, 0.0, 0.0, 0.0, 3.0}}}}; //disk 5 + //returns the mean bend (in strips at a 1.8cm separation) for bendcode + std::array, 16> benddecode_{ + {{{0.0, 0.5, 0.7, 0.8, 89.9, -1.0, -0.9, -0.8, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //L1 PS + {{0.0, 0.7, 1.0, 1.5, 89.9, -1.5, -1.0, -0.7, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //L2 PS + {{0.0, 1.0, 1.8, 2.2, 89.9, -2.2, -1.8, -1.0, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //L3 PS + {{0.0, 0.7, 1.2, 1.8, 2.1, 2.6, 3.2, 3.5, 89.9, -3.5, -3.2, -2.6, -2.1, -1.8, -1.2, -0.7}}, //L4 2S + {{0.0, 0.8, 1.2, 1.8, 2.2, 3.2, 4.1, 4.4, 89.9, -4.4, -4.1, -3.2, -2.2, -1.8, -1.2, -0.8}}, //L5 2S + {{0.0, 0.9, 1.8, 2.8, 3.8, 4.5, 5.3, 5.9, 89.9, -5.9, -5.3, -4.5, -3.8, -2.8, -1.8, -0.9}}, //L6 2S + {{0.0, 0.8, 1.2, 2.0, 89.9, -2.0, -1.2, -0.8, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //D1 PS + {{0.0, 1.5, 1.8, 2.4, 89.9, -2.4, -1.8, -1.4, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //D2 PS + {{0.0, 1.7, 2.0, 2.2, 89.9, -2.2, -2.0, -1.7, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //D3 PS + {{0.0, 1.8, 2.0, 2.4, 89.9, -2.4, -2.0, -1.8, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //D4 PS + {{0.0, 2.0, 2.2, 2.4, 89.9, -2.4, -2.0, -1.8, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //D5 PS + {{0.0, 1.8, 2.3, 2.5, 3.0, 3.9, 4.5, 5.2, 89.9, -5.2, -4.5, -3.9, -3.0, -2.5, -2.3, -1.8}}, //D1 2S + {{0.0, 2.0, 2.4, 2.9, 3.2, 4.0, 4.8, 5.2, 89.9, -5.2, -4.8, -4.0, -3.2, -2.9, -2.4, -2.0}}, //D2 2S + {{0.0, 2.0, 2.4, 2.7, 3.6, 3.7, 4.4, 4.6, 89.9, -4.6, -4.4, -3.7, -3.6, -2.7, -2.4, -2.0}}, //D3 2S + {{0.0, 2.0, 2.6, 3.2, 3.8, 4.0, 4.4, 4.4, 89.9, -4.4, -4.4, -4.0, -3.8, -3.2, -2.6, -2.0}}, //D4 2S + {{0.0, 2.0, 3.2, 3.4, 3.9, 3.9, 4.4, 4.4, 89.9, -4.4, -4.4, -3.9, -3.9, -3.4, -3.2, -2.0}}}}; //D5 2S + + //returns the bend 'cut' (in strips at a 1.8cm separation) for bendcode + std::array, 16> bendcut_{ + {{{1.5, 1.2, 0.8, 0.8, 99.9, 0.8, 0.8, 1.2, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //L1 PS + {{1.5, 1.3, 1.0, 1.0, 99.9, 1.0, 1.0, 1.3, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //L2 PS + {{1.6, 1.5, 1.0, 1.0, 99.9, 1.0, 1.0, 1.5, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //L3 PS + {{1.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 99.9, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}}, //L4 2S + {{1.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 99.9, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}}, //L5 2S + {{1.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 99.9, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}}, //L6 2S + {{1.8, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //D1 PS + {{1.8, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //D2 PS + {{1.8, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //D3 PS + {{2.2, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //D4 PS + {{2.2, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //D5 PS + {{2.0, 1.2, 1.2, 1.2, 1.5, 1.5, 1.5, 1.5, 99.9, 1.5, 1.5, 1.5, 1.5, 1.2, 1.2, 1.2}}, //D1 2S + {{2.0, 1.2, 1.2, 1.2, 1.5, 1.5, 1.5, 1.5, 99.9, 1.5, 1.5, 1.5, 1.5, 1.2, 1.2, 1.2}}, //D2 2S + {{2.2, 1.5, 1.5, 1.5, 2.0, 2.0, 2.0, 2.0, 99.9, 2.0, 2.0, 2.0, 2.0, 1.5, 1.5, 1.5}}, //D3 2S + {{2.5, 1.5, 1.5, 2.0, 2.0, 2.0, 2.0, 2.0, 99.9, 2.0, 2.0, 2.0, 2.0, 2.0, 1.5, 1.5}}, //D4 2S + {{2.5, 1.5, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 99.9, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.5}}}}; //D5 2S + // Offset to the maximum number of steps in each processing step: // Set to 0 (default) means standard truncation // Set to large value, e.g. 10000, to disable truncation unsigned int maxstepoffset_{0}; //Number of processing steps for one event (108=18TM*240MHz/40MHz) - std::unordered_map maxstep_{{"Link", 108}, - {"VMR", 108}, + std::unordered_map maxstep_{{"IR", 168}, //IR will run at a higher clock speed to handle + //input links running at 25 Gbits/s + {"VMR", 108}, {"TE", 108}, {"TC", 108}, {"PR", 108}, @@ -641,37 +760,21 @@ namespace trklet { {"TRE", 108}}; // If set to true this will generate debub printout in text files - std::unordered_map writeMonitorData_{{"IL", false}, - {"TE", false}, - {"CT", false}, - {"HitPattern", false}, - {"ChiSq", false}, - {"Seeds", false}, - {"FT", false}, - {"Residuals", false}, - {"MC", false}, - {"MP", false}, - {"ME", false}, - {"AP", false}, - {"VMP", false}, - {"NMatches", false}, - {"TrackProjOcc", false}, - {"TC", false}, - {"Pars", false}, - {"TPars", false}, - {"TPD", false}, - {"TrackletPars", false}, - {"TED", false}, - {"TP", false}, - {"TRE", false}, - {"VMR", false}, - {"StubsLayer", false}, - {"StubsLayerSector", false}, - {"HitEff", false}, - {"MatchEff", false}, - {"Cabling", false}, - {"IFit", false}, - {"AS", false}}; + std::unordered_map writeMonitorData_{{"IL", false}, {"TE", false}, + {"CT", false}, {"HitPattern", false}, + {"ChiSq", false}, {"Seeds", false}, + {"FT", false}, {"Residuals", false}, + {"StubBend", false}, {"MC", false}, + {"MP", false}, {"ME", false}, + {"AP", false}, {"VMP", false}, + {"TrackProjOcc", false}, {"TC", false}, + {"Pars", false}, {"TPars", false}, + {"TPD", false}, {"TrackletPars", false}, + {"TED", false}, {"TP", false}, + {"TRE", false}, {"VMR", false}, + {"StubsLayer", false}, {"StubsLayerSector", false}, + {"HitEff", false}, {"MatchEff", false}, + {"IFit", false}, {"AS", false}}; std::array rDSSinner_mod_{{68.9391, 78.7750, 85.4550, 96.3150, 102.3160}}; std::array rDSSouter_mod_{{66.4903, 76.7750, 84.4562, 94.9920, 102.3160}}; @@ -688,8 +791,9 @@ namespace trklet { bool warnNoDer_{false}; //If true will print out warnings about missing track fit derivatives //--- These used to create files needed by HLS code. - bool writeMem_{false}; //If true will print out content of memories (between algo steps) to files - bool writeTable_{false}; //If true will print out content of LUTs to files + bool writeMem_{false}; //If true will print out content of memories (between algo steps) to files + bool writeTable_{false}; //If true will print out content of LUTs to files + bool writeConfig_{false}; //If true will print out the autogenerated configuration as files std::string memPath_{"../data/MemPrints/"}; //path for writing memories std::string tablePath_{"../data/LUTs/"}; //path for writing LUTs diff --git a/L1Trigger/TrackFindingTracklet/interface/Stub.h b/L1Trigger/TrackFindingTracklet/interface/Stub.h index 8b5536d270d84..90c8f7f1dbd80 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Stub.h +++ b/L1Trigger/TrackFindingTracklet/interface/Stub.h @@ -13,11 +13,13 @@ namespace trklet { + class Globals; + class Stub { public: Stub(Settings const& settings); - Stub(L1TStub& stub, Settings const& settings, double phiminsec, double phimaxsec); + Stub(L1TStub& stub, Settings const& settings, Globals& globals); ~Stub() = default; @@ -30,13 +32,22 @@ namespace trklet { if (isPSmodule()) { return r_.str() + "|" + z_.str() + "|" + phi_.str() + "|" + bend_.str(); } else { - return "000" + r_.str() + "|" + z_.str() + "|" + phi_.str() + "|" + alphanew_.str() + "|" + bend_.str(); + return "000" + r_.str() + "|" + z_.str() + "|" + phi_.str() + "|" + alpha_.str() + "|" + bend_.str(); } } } std::string strbare() const { return bend_.str() + r_.str() + z_.str() + phi_.str(); } + std::string strinner() const { + unsigned int nbitsfinephi = 8; + FPGAWord finephi( + phicorr_.bits(phicorr_.nbits() - nbitsfinephi, nbitsfinephi), nbitsfinephi, true, __LINE__, __FILE__); + return str() + "|" + stubindex_.str() + "|" + finephi.str(); + } + + FPGAWord allStubIndex() const { return stubindex_; } + unsigned int phiregionaddress() const; std::string phiregionaddressstr() const; @@ -50,17 +61,14 @@ namespace trklet { const FPGAWord& z() const { return z_; } const FPGAWord& phi() const { return phi_; } const FPGAWord& phicorr() const { return phicorr_; } - const FPGAWord& alphanew() const { return alphanew_; } + const FPGAWord& alpha() const { return alpha_; } const FPGAWord& stubindex() const { return stubindex_; } const FPGAWord& layer() const { return layer_; } const FPGAWord& disk() const { return disk_; } unsigned int layerdisk() const; - bool isBarrel() const { return layer_.value() != -1; } - bool isDisk() const { return disk_.value() != 0; } - - bool isPSmodule() const { return isBarrel() ? (layer_.value() < (int)N_PSLAYER) : (r_.value() > 10); } + bool isPSmodule() const { return (layerdisk_ < N_LAYER) ? (layerdisk_ < N_PSLAYER) : (r_.value() > 10); } double rapprox() const; double zapprox() const; @@ -70,13 +78,17 @@ namespace trklet { const L1TStub* l1tstub() const { return l1tstub_; } void setl1tstub(L1TStub* l1tstub) { l1tstub_ = l1tstub; } + bool isBarrel() const { return layerdisk_ < N_LAYER; } + private: + unsigned int layerdisk_; + FPGAWord layer_; FPGAWord disk_; FPGAWord r_; FPGAWord z_; FPGAWord phi_; - FPGAWord alphanew_; + FPGAWord alpha_; FPGAWord bend_; diff --git a/L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h b/L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h index cc219691a61ff..9f87f84ee490f 100644 --- a/L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h @@ -12,7 +12,7 @@ namespace trklet { class StubPairsMemory : public MemoryBase { public: - StubPairsMemory(std::string name, Settings const& settings, unsigned int iSector); + StubPairsMemory(std::string name, Settings const& settings); ~StubPairsMemory() override = default; @@ -39,7 +39,7 @@ namespace trklet { tedNames_.clear(); } - void writeSP(bool first); + void writeSP(bool first, unsigned int iSector); private: std::vector > stubs_; diff --git a/L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h b/L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h index ecb2163251a38..00e94404feadd 100644 --- a/L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h @@ -13,7 +13,7 @@ namespace trklet { class StubTripletsMemory : public MemoryBase { public: - StubTripletsMemory(std::string name, Settings const& settings, unsigned int iSector); + StubTripletsMemory(std::string name, Settings const& settings); ~StubTripletsMemory() override = default; @@ -35,7 +35,7 @@ namespace trklet { stubs3_.clear(); } - void writeST(bool first); + void writeST(bool first, unsigned int iSector); private: std::vector stubs1_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TETableBase.h b/L1Trigger/TrackFindingTracklet/interface/TETableBase.h index 754ac6345c4c4..c12a818eb35f7 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TETableBase.h +++ b/L1Trigger/TrackFindingTracklet/interface/TETableBase.h @@ -2,6 +2,7 @@ #define L1Trigger_TrackFindingTracklet_interface_TETableBase_h #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" #include #include @@ -21,7 +22,7 @@ namespace trklet { virtual void lookup(int, int) {} - void writeVMTable(std::string name, bool positive = true); + void writeVMTable(const std::string& dir, const std::string& name, bool positive = true); protected: Settings const& settings_; diff --git a/L1Trigger/TrackFindingTracklet/interface/Track.h b/L1Trigger/TrackFindingTracklet/interface/Track.h index cbf27a81c3f63..bd95a2a6cc43c 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Track.h +++ b/L1Trigger/TrackFindingTracklet/interface/Track.h @@ -24,7 +24,7 @@ namespace trklet { double chisqrz, int hitpattern, std::map stubID, - const std::vector& l1stub, + const std::vector& l1stub, int seed); ~Track() = default; @@ -39,7 +39,7 @@ namespace trklet { int ichisq() const { return ichisqrphi_ + ichisqrz_; } const std::map& stubID() const { return stubID_; } - const std::vector& stubs() const { return l1stub_; } + const std::vector& stubs() const { return l1stub_; } //These are not used? Should be removed? const std::vector>& stubIDpremerge() const { return stubIDpremerge_; } @@ -69,7 +69,7 @@ namespace trklet { int nPSstubs() const { int npsstubs = 0; for (auto istub : l1stub_) { - if (istub->layer() < N_PSLAYER) + if (istub.layer() < N_PSLAYER) npsstubs++; } return npsstubs; @@ -88,7 +88,7 @@ namespace trklet { std::vector> stubIDpremerge_; std::vector> stubIDprefit_; std::map stubID_; - std::vector l1stub_; + std::vector l1stub_; unsigned int nstubs_; int seed_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h b/L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h index 6775080971f1a..f8c9335abd8fa 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h @@ -14,7 +14,7 @@ namespace trklet { class TrackFitMemory : public MemoryBase { public: - TrackFitMemory(std::string name, Settings const& settings, unsigned int iSector, double phimin, double phimax); + TrackFitMemory(std::string name, Settings const& settings, double phimin, double phimax); ~TrackFitMemory() override = default; @@ -36,7 +36,7 @@ namespace trklet { stubidslists_.clear(); } - void writeTF(bool first); + void writeTF(bool first, unsigned int iSector); private: double phimin_; diff --git a/L1Trigger/TrackFindingTracklet/interface/Tracklet.h b/L1Trigger/TrackFindingTracklet/interface/Tracklet.h index 870dd822bbbd0..30e1ae3900ec3 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Tracklet.h +++ b/L1Trigger/TrackFindingTracklet/interface/Tracklet.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" @@ -13,10 +14,8 @@ #include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" #include "L1Trigger/TrackFindingTracklet/interface/Track.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackPars.h" -#include "L1Trigger/TrackFindingTracklet/interface/LayerProjection.h" -#include "L1Trigger/TrackFindingTracklet/interface/DiskProjection.h" -#include "L1Trigger/TrackFindingTracklet/interface/LayerResidual.h" -#include "L1Trigger/TrackFindingTracklet/interface/DiskResidual.h" +#include "L1Trigger/TrackFindingTracklet/interface/Projection.h" +#include "L1Trigger/TrackFindingTracklet/interface/Residual.h" #include "L1Trigger/TrackFindingTracklet/interface/Util.h" namespace trklet { @@ -28,9 +27,7 @@ namespace trklet { class Tracklet { public: Tracklet(Settings const& settings, - const L1TStub* innerStub, - const L1TStub* middleStub, - const L1TStub* outerStub, + unsigned int iSeed, const Stub* innerFPGAStub, const Stub* middleFPGAStub, const Stub* outerFPGAStub, @@ -49,8 +46,7 @@ namespace trklet { int id0, int iz0, int it, - LayerProjection layerprojs[N_PROJ], - DiskProjection diskprojs[N_PROJ], + Projection projs[N_LAYER + N_DISK], bool disk, bool overlap = false); @@ -62,13 +58,10 @@ namespace trklet { bool stubtruthmatch(const L1TStub* stub); - const L1TStub* innerStub() { return innerStub_; } const Stub* innerFPGAStub() { return innerFPGAStub_; } - const L1TStub* middleStub() { return middleStub_; } const Stub* middleFPGAStub() { return middleFPGAStub_; } - const L1TStub* outerStub() { return outerStub_; } const Stub* outerFPGAStub() { return outerFPGAStub_; } std::string addressstr(); @@ -86,320 +79,38 @@ namespace trklet { std::string trackletprojstrlayer(int layer) const { return trackletprojstr(layer); } std::string trackletprojstrdisk(int disk) const { return trackletprojstrD(disk); } - bool validProj(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].valid(); + bool validProj(int layerdisk) const { + assert(layerdisk >= 0 && layerdisk < N_LAYER + N_DISK); + return proj_[layerdisk].valid(); } - const FPGAWord& fpgaphiprojder(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgaphiprojder(); + Projection& proj(int layerdisk) { + assert(validProj(layerdisk)); + return proj_[layerdisk]; } - const FPGAWord& fpgazproj(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgazproj(); - } - - const FPGAWord& fpgaphiproj(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgaphiproj(); - } - - const FPGAWord& fpgazprojder(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgazprojder(); - } - - int zbin1projvm(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgazbin1projvm().value(); - } - - int zbin2projvm(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgazbin2projvm().value(); - } - - int finezvm(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgafinezvm().value(); - } - - int rbin1projvm(int disk) const { - assert(disk > 0 && disk <= N_DISK); - return diskproj_[disk - 1].fpgarbin1projvm().value(); - } - - int rbin2projvm(int disk) const { - assert(disk > 0 && disk <= N_DISK); - return diskproj_[disk - 1].fpgarbin2projvm().value(); - } - - int finervm(int disk) const { - assert(disk > 0 && disk <= N_DISK); - return diskproj_[disk - 1].fpgafinervm().value(); - } - - int phiprojvm(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgaphiprojvm().value(); - } - - int zprojvm(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgazprojvm().value(); - } - - double phiproj(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].phiproj(); - } - - double phiprojder(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].phiprojder(); - } - - double zproj(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].zproj(); - } - - double zprojder(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].zprojder(); - } - - double zprojapprox(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].zprojapprox(); - } - - double zprojderapprox(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].zprojderapprox(); - } - - double phiprojapprox(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].phiprojapprox(); - } - - double phiprojderapprox(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].phiprojderapprox(); - } - - double rproj(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].rproj(); - } - - double rstub(int layer) { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].rstub(); - } - - //Disks residuals - - bool validProjDisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].valid(); - } - - const FPGAWord& fpgaphiresiddisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].fpgaphiresid(); - } - - const FPGAWord& fpgarresiddisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].fpgarresid(); - } - - double phiresiddisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].phiresid(); - } - - double rresiddisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].rresid(); - } - - double phiresidapproxdisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].phiresidapprox(); - } - - double rresidapproxdisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].rresidapprox(); - } - - double zstubdisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].zstub(); - } - - void setBendIndex(int bendIndex, int disk) { - assert(abs(disk) <= N_DISK); - diskproj_[abs(disk) - 1].setBendIndex(bendIndex); - } - - const FPGAWord& getBendIndex(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].getBendIndex(); - } - - double alphadisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].alpha(); - } - - const FPGAWord& ialphadisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].ialpha(); - } - - const FPGAWord& fpgaphiprojdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].fpgaphiproj(); - } - - const FPGAWord& fpgaphiprojderdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].fpgaphiprojder(); - } - - const FPGAWord& fpgarprojdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].fpgarproj(); - } - - const FPGAWord& fpgarprojderdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].fpgarprojder(); - } - - double phiprojapproxdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].phiprojapprox(); - } - - double phiprojderapproxdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].phiprojderapprox(); - } - - double rprojapproxdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].rprojapprox(); - } - - double rprojderapproxdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].rprojderapprox(); - } - - double phiprojdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].phiproj(); - } - - double phiprojderdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].phiprojder(); - } - - double rprojdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].rproj(); - } - - double rprojderdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].rprojder(); - } - - bool matchdisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].valid(); - } - - void addMatch(int layer, + void addMatch(unsigned int layerdisk, int ideltaphi, - int ideltaz, + int ideltarz, double dphi, - double dz, + double drz, double dphiapprox, - double dzapprox, + double drzapprox, int stubid, - double rstub, const trklet::Stub* stubptr); - void addMatchDisk(int disk, - int ideltaphi, - int ideltar, - double dphi, - double dr, - double dphiapprox, - double drapprox, - double alpha, - int stubid, - double zstub, - const trklet::Stub* stubptr); - - int nMatches(); - int nMatchesDisk(); - - bool match(int layer) { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].valid(); - } - std::string fullmatchstr(int layer); std::string fullmatchdiskstr(int disk); - bool validResid(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].valid(); + bool match(unsigned int layerdisk) { + assert(layerdisk < N_LAYER + N_DISK); + return resid_[layerdisk].valid(); } - const trklet::Stub* stubptr(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].stubptr(); - } - - double phiresid(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].phiresid(); - } - - double phiresidapprox(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].phiresidapprox(); - } - - double zresid(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].zresid(); - } - - double zresidapprox(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].zresidapprox(); - } - - const FPGAWord& fpgaphiresid(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].fpgaphiresid(); - } - - const FPGAWord& fpgazresid(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].fpgazresid(); + const Residual& resid(unsigned int layerdisk) { + assert(layerdisk < N_LAYER + N_DISK); + assert(resid_[layerdisk].valid()); + return resid_[layerdisk]; } std::vector getL1Stubs(); @@ -485,7 +196,6 @@ namespace trklet { int layer() const; int disk() const; - int disk2() const; bool isBarrel() const { return barrel_; } bool isOverlap() const { return overlap_; } @@ -501,18 +211,16 @@ namespace trklet { int TCID() const { return TCIndex_ * (1 << settings_.nbitstrackletindex()) + trackletIndex_; } - const int getISeed() const; - const int getITC() const; + int getISeed() const; + int getITC() const; void setTrackIndex(int index); - const int trackIndex() const; + int trackIndex() const; unsigned int PSseed() const { return ((layer() == 1) || (layer() == 2) || (disk() != 0)) ? 1 : 0; } unsigned int seedIndex() const { return seedIndex_; } - unsigned int calcSeedIndex() const; - private: unsigned int seedIndex_; @@ -526,10 +234,6 @@ namespace trklet { const Stub* middleFPGAStub_; const Stub* outerFPGAStub_; - const L1TStub* innerStub_; - const L1TStub* middleStub_; - const L1TStub* outerStub_; - int trackletIndex_; int TCIndex_; int trackIndex_; @@ -561,11 +265,9 @@ namespace trklet { std::unique_ptr fpgatrack_; - LayerProjection layerproj_[N_LAYER]; - DiskProjection diskproj_[N_DISK]; + Projection proj_[N_LAYER + N_DISK]; - LayerResidual layerresid_[N_LAYER]; - DiskResidual diskresid_[N_DISK]; + Residual resid_[N_LAYER + N_DISK]; Settings const& settings_; }; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h index 16d65ae9518b8..a271bab238d69 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h @@ -19,7 +19,7 @@ namespace trklet { class TrackletCalculator : public TrackletCalculatorBase { public: - TrackletCalculator(std::string name, Settings const& settings, Globals* globals, unsigned int iSector); + TrackletCalculator(std::string name, Settings const& settings, Globals* globals); ~TrackletCalculator() override = default; @@ -27,7 +27,7 @@ namespace trklet { void addOutput(MemoryBase* memory, std::string output) override; void addInput(MemoryBase* memory, std::string input) override; - void execute(); + void execute(unsigned int iSector, double phimin, double phimax); private: int iTC_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h index e58c5eb340adb..4638b07f5e5a9 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h @@ -17,7 +17,7 @@ namespace trklet { class TrackletCalculatorBase : public ProcessBase { public: - TrackletCalculatorBase(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + TrackletCalculatorBase(std::string name, Settings const& settings, Globals* global); ~TrackletCalculatorBase() override = default; @@ -131,6 +131,9 @@ namespace trklet { int TCIndex_; + unsigned int iSector_; + double phimin_, phimax_; + TrackletParametersMemory* trackletpars_; //First index is layer/disk second is phi region diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorDisplaced.h b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorDisplaced.h index 541d7043dfc60..9bc51a81d34c8 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorDisplaced.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorDisplaced.h @@ -19,7 +19,7 @@ namespace trklet { class TrackletCalculatorDisplaced : public ProcessBase { public: - TrackletCalculatorDisplaced(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + TrackletCalculatorDisplaced(std::string name, Settings const& settings, Globals* global); ~TrackletCalculatorDisplaced() override = default; @@ -28,7 +28,7 @@ namespace trklet { void addOutput(MemoryBase* memory, std::string output) override; void addInput(MemoryBase* memory, std::string input) override; - void execute(); + void execute(unsigned int iSector, double phimin, double phimax); void addDiskProj(Tracklet* tracklet, int disk); bool addLayerProj(Tracklet* tracklet, int layer); @@ -159,12 +159,16 @@ namespace trklet { int TCIndex_; int layer_; int disk_; + unsigned int iSeed_; double rproj_[N_LAYER - 2]; int lproj_[N_LAYER - 2]; double zproj_[N_DISK - 2]; int dproj_[N_DISK - 2]; double rzmeanInv_[N_DISK - 2]; + unsigned int iSector_; + double phimin_, phimax_; + std::vector toR_; std::vector toZ_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h b/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h new file mode 100644 index 0000000000000..f1734c35f2cd3 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h @@ -0,0 +1,273 @@ +// +// Class to build the configuration for the tracklet based track finding +// +// +// +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletConfigBuilder_h +#define L1Trigger_TrackFindingTracklet_interface_TrackletConfigBuilder_h + +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +#include +#include +#include +#include +#include +#include + +namespace trklet { + + class TrackletConfigBuilder { + public: + //Builds the configuration for the tracklet based track finding + TrackletConfigBuilder(const Settings& settings); + + //This method writes out the configuration as files + void writeAll(std::ostream& wires, std::ostream& memories, std::ostream& modules); + + private: + // + // Method to initialize the regions and VM in each layer + // + void initGeom(); + + // + // Builds the list of TE for each seeding combination + // + void buildTE(); + + // + // Builds the lists of TC for each seeding combination + // + void buildTC(); + + // + // Finds the projections needed for each seeding combination + // + void buildProjections(); + + // + // Helper function to determine if a pair of VM memories form valid TE + // + bool validTEPair(unsigned int iseed, unsigned int iTE1, unsigned int iTE2); + + // + // Helper fcn. to get the layers/disks for a seed + // + std::pair seedLayers(unsigned int iSeed); + + // + // Helper fcn to get the radii of the two layers in a seed + // + std::pair seedRadii(unsigned int iseed); + + // + // Helper fcn to return the phi range of a projection of a tracklet from a TC + // + std::pair seedPhiRange(double rproj, unsigned int iSeed, unsigned int iTC); + + // + // Helper function to calculate the phi position of a seed at radius r that is formed + // by two stubs at (r1,phi1) and (r2, phi2) + // + double phi(double r1, double phi1, double r2, double phi2, double r); + + // + // Helper function to calculate rinv for two stubs at (r1,phi1) and (r2,phi2) + // + double rinv(double r1, double phi1, double r2, double phi2); + + // + // The next group of fcn formats a string to write out names of different + // memories and processing modules + // + + //Seed string, eg. L1L2 + std::string iSeedStr(unsigned int iSeed); + + //Return unsigned as string + std::string numStr(unsigned int i); + + //Retunr iTC as string - ie A, B, C, etc + std::string iTCStr(unsigned int iTC); + + //The region string A, B, C etc for layers and disks; X, Y, Z etc for overlap + std::string iRegStr(unsigned int iReg, unsigned int iSeed); + + //TC Name + std::string TCName(unsigned int iSeed, unsigned int iTC); + + //Name of layer or disk, e.g. L1 or D1 + std::string LayerName(unsigned int ilayer); + + //Tracklet projection name + std::string TPROJName(unsigned int iSeed, unsigned int iTC, unsigned int ilayer, unsigned int ireg); + + //Projection router name + std::string PRName(unsigned int ilayer, unsigned int ireg); + + //StubPair Name + std::string SPName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int iseed); + + //StubPaur displaced name + std::string SPDName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int l3, + unsigned int ireg3, + unsigned int ivm3, + unsigned int iseed); + + //Stub Triplet name + std::string STName(unsigned int l1, + unsigned int ireg1, + unsigned int l2, + unsigned int ireg2, + unsigned int l3, + unsigned int ireg3, + unsigned int iseed, + unsigned int count); + + //TrackletEngine name + std::string TEName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int iseed); + + //Triplet engine name + std::string TREName(unsigned int l1, + unsigned int ireg1, + unsigned int l2, + unsigned int ireg2, + unsigned int iseed, + unsigned int count); + + //TrackletEngine displaced name + std::string TEDName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int iseed); + + //Tracklet parameter memory name + std::string TParName(unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc); + + //TrackletCalculator displaced name + std::string TCDName(unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc); + + //TrackletProjection name + std::string TPROJName(unsigned int l1, + unsigned int l2, + unsigned int l3, + unsigned int itc, + unsigned int projlay, + unsigned int projreg); + + //FitTrack module name + std::string FTName(unsigned int l1, unsigned int l2, unsigned int l3); + + //TrackletCalculator name + std::string TCNAme(unsigned int iseed, unsigned int iTC); + + // + // This group of methods are used to print out the configuration as a file + // + void writeProjectionMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeSPMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeSPDMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeAPMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeCMMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeVMPROJMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeFMMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeASMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeVMSMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeTPARMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeTFMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeCTMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeILMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + // + // Store constants extracted from Settings + // + unsigned int NSector_; //Number of sectors + double rcrit_; //critical radius that defines the sector + + bool combinedmodules_; //if true write configuration for combined modules + + bool extended_; //if true write configuration for extended configuration + + double rinvmax_; //Max value for valid rinv + double rmaxdisk_; //Maximim disk radius + double zlength_; //Maximim (abslute) z-positon in barrel + double rmean_[N_LAYER]; //Mean layer radius + double zmean_[N_DISK]; //Mean disk z-position + + double dphisectorHG_; //Full sector width + + unsigned int NTC_[N_SEED_PROMPT]; //Number of TC per seeding combination + + unsigned int NRegions_[N_LAYER + N_DISK]; //Regions (all stubs memories 6 layers +5 disks + unsigned int NVMME_[N_LAYER + N_DISK]; //Number of MEs (all stubs memories 6 layers +5 disks + std::pair NVMTE_[N_SEED_PROMPT]; //number of TEs for each seeding combination + + //Min and max phi for a phi region (e.g. all stubs) + std::vector > allStubs_[N_LAYER + N_DISK]; + + //Min and max phi for VM bin + std::vector > VMStubsME_[N_LAYER + N_DISK]; + + //Phi ranges for the stubs in the VM bins used in the pair in th TE + std::pair >, std::vector > > + VMStubsTE_[N_SEED_PROMPT]; + + //List of the TEs and the VM bins for each TE + std::vector > TE_[N_SEED_PROMPT]; + + //The TCs for each seeding combination + std::vector > TC_[N_SEED_PROMPT]; + + //The projections to each layer/disk from a seed and TC + std::vector > > projections_[N_LAYER + N_DISK]; + + //Which matches are used for each seeding layer + // L1 L2 L3 L4 L5 L6 D1 D2 D3 D4 D5 + int matchport_[N_SEED_PROMPT][N_LAYER + N_DISK] = {{-1, -1, 1, 2, 3, 4, 4, 3, 2, 1, -1}, //L1L2 + {1, -1, -1, 2, 3, -1, 4, 3, 2, 1, -1}, //L2L3 + {1, 2, -1, -1, 3, 4, 4, 3, -1, -1, -1}, //L3L4 + {1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1}, //L5L6 + {1, 2, -1, -1, -1, -1, -1, -1, 2, 3, 4}, //D1D2 + {1, -1, -1, -1, -1, -1, 2, 3, -1, -1, 4}, //D3D4 + {-1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 4}, //L1D1 + {1, -1, -1, -1, -1, -1, -1, 2, 3, 4, -1}}; //L2D1 + + //Settings + const Settings& settings_; + }; +} // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h index a6fd3f9492fe2..e827185374716 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h @@ -16,7 +16,7 @@ namespace trklet { class TrackletEngine : public ProcessBase { public: - TrackletEngine(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + TrackletEngine(std::string name, Settings const& settings, Globals* global); ~TrackletEngine() override = default; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h index 79eadb944b67e..91ea9e6ad4ee8 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h @@ -19,7 +19,7 @@ namespace trklet { class TrackletEngineDisplaced : public ProcessBase { public: - TrackletEngineDisplaced(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + TrackletEngineDisplaced(std::string name, Settings const& settings, Globals* global); ~TrackletEngineDisplaced() override; @@ -30,7 +30,7 @@ namespace trklet { void readTables(); - const short memNameToIndex(const std::string& name); + short memNameToIndex(const std::string& name); private: int layer1_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h index 120e8891e9c2e..dd12be6851287 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h @@ -28,6 +28,7 @@ namespace trklet { public: TrackletEngineUnit(const Settings* const settings, unsigned int nbitsfinephi, + unsigned int layerdisk1, unsigned int layerdisk2, unsigned int iSeed, unsigned int nbitsfinephiediff, @@ -48,19 +49,28 @@ namespace trklet { bool idle() const { return idle_; } + void setNearFull() { nearfull_ = candpairs_.nearfull(); } + void reset(); - void step(); + void step(bool print, int istep, int iTE); + + int rptr() const { return candpairs_.rptr(); } + + int wptr() const { return candpairs_.wptr(); } + + const Stub* innerStub() const { return tedata_.stub_; } private: VMStubsTEMemory* outervmstubs_; TEData tedata_; const Settings* settings_; unsigned int nbitsfinephi_; + unsigned int layerdisk1_; unsigned int layerdisk2_; unsigned int iSeed_; unsigned int nbitsfinephidiff_; - + bool nearfull_; //initialized at start of each processing step unsigned int iAllStub_; //unsigned int memory slot @@ -75,6 +85,9 @@ namespace trklet { std::vector pttableinner_; std::vector pttableouter_; + std::pair candpair_, candpair__; + bool goodpair_, goodpair__; + //save the candidate matches CircularBuffer > candpairs_; }; // TrackletEngineUnit diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h index e46685eaf563c..114b2f0e32dc5 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h @@ -17,7 +17,6 @@ namespace trklet { class Sector; class HistBase; class Track; - class Cabling; class TrackletEventProcessor { public: @@ -31,23 +30,24 @@ namespace trklet { void printSummary(); - std::vector& tracks() { return tracks_; } + const std::vector& tracks() const { return tracks_; } private: + void configure(std::istream& inwire, std::istream& inmem, std::istream& inproc); + const Settings* settings_{nullptr}; std::unique_ptr globals_; - std::vector > sectors_; + std::unique_ptr sector_; HistBase* histbase_{}; int eventnum_ = {0}; - std::unique_ptr cabling_; - Timer cleanTimer_; Timer addStubTimer_; + Timer InputRouterTimer_; Timer VMRouterTimer_; Timer TETimer_; Timer TEDTimer_; @@ -62,9 +62,7 @@ namespace trklet { Timer FTTimer_; Timer PDTimer_; - std::vector tracks_; - - std::map > dtclayerdisk_; + std::vector tracks_; }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h b/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h index 088f937dcbc4c..7a81bececba65 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h @@ -16,7 +16,7 @@ namespace trklet { class TrackletParametersMemory : public MemoryBase { public: - TrackletParametersMemory(std::string name, Settings const &settings, unsigned int iSector); + TrackletParametersMemory(std::string name, Settings const &settings); ~TrackletParametersMemory() override = default; @@ -28,9 +28,7 @@ namespace trklet { void clean() override; - void writeMatches(Globals *globals, int &matchesL1, int &matchesL3, int &matchesL5); - - void writeTPAR(bool first); + void writeTPAR(bool first, unsigned int iSector); private: std::vector tracklets_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h b/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h index d740b26b8ff35..c32a718681fc1 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h @@ -18,11 +18,12 @@ namespace trklet { class Globals; class MemoryBase; class AllStubsMemory; + class AllInnerStubsMemory; class VMStubsTEMemory; class TrackletProcessor : public TrackletCalculatorBase { public: - TrackletProcessor(std::string name, Settings const& settings, Globals* globals, unsigned int iSector); + TrackletProcessor(std::string name, Settings const& settings, Globals* globals); ~TrackletProcessor() override = default; @@ -32,7 +33,7 @@ namespace trklet { void addInput(MemoryBase* memory, std::string input) override; - void execute(); + void execute(unsigned int iSector, double phimin, double phimax); void writeTETable(); @@ -42,18 +43,16 @@ namespace trklet { int iTC_; int iAllStub_; + unsigned int maxStep_; + VMStubsTEMemory* outervmstubs_; - // The use of a std::tuple here is awkward and should be fixed. This code is slotted for a significant - // overhaul to allign with the HLS implementation. At that point the use fo the tuple should be - // eliminated - // istub imem start imem end imem - std::vector, unsigned int, unsigned int, unsigned int, unsigned int> > - tedatabuffers_; + // istub imem start imem end imem + std::tuple, unsigned int, unsigned int, unsigned int, unsigned int> tebuffer_; std::vector teunits_; - std::vector innerallstubs_; + std::vector innerallstubs_; std::vector outerallstubs_; std::map > pttableinner_; @@ -62,7 +61,7 @@ namespace trklet { std::vector pttableinnernew_; std::vector pttableouternew_; - std::vector > useregion_; + std::vector useregion_; int nbitsfinephi_; int nbitsfinephidiff_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h b/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h index 3d376d3b98dcc..4a936c7c4f950 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h @@ -14,7 +14,7 @@ namespace trklet { class TrackletProjectionsMemory : public MemoryBase { public: - TrackletProjectionsMemory(std::string name, Settings const& settings, unsigned int iSector); + TrackletProjectionsMemory(std::string name, Settings const& settings); ~TrackletProjectionsMemory() override = default; @@ -26,7 +26,7 @@ namespace trklet { void clean() override; - void writeTPROJ(bool first); + void writeTPROJ(bool first, unsigned int iSector); int layer() const { return layer_; } int disk() const { return disk_; } diff --git a/L1Trigger/TrackFindingTracklet/interface/TripletEngine.h b/L1Trigger/TrackFindingTracklet/interface/TripletEngine.h index 1652262c1808a..ad5840af13a0e 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TripletEngine.h +++ b/L1Trigger/TrackFindingTracklet/interface/TripletEngine.h @@ -17,7 +17,7 @@ namespace trklet { class TripletEngine : public ProcessBase { public: - TripletEngine(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + TripletEngine(std::string name, Settings const& settings, Globals* global); ~TripletEngine() override; diff --git a/L1Trigger/TrackFindingTracklet/interface/Util.h b/L1Trigger/TrackFindingTracklet/interface/Util.h index 818b548880d98..41ed3a8e25390 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Util.h +++ b/L1Trigger/TrackFindingTracklet/interface/Util.h @@ -2,9 +2,13 @@ #define L1Trigger_TrackFindingTracklet_interface_Util_h #include +#include #include #include +#include #include +#include +#include #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" @@ -35,150 +39,142 @@ namespace trklet { return str; } - //Should be optimized by layer - now first implementation to make sure it works OK - inline int bendencode(double bend, bool isPS) { - int ibend = 2.0 * bend; + inline double bendstrip(double r, double rinv, double stripPitch) { + constexpr double dr = 0.18; + double delta = r * dr * 0.5 * rinv; + double bend = delta / stripPitch; + return bend; + } - assert(std::abs(ibend - 2.0 * bend) < 0.1); + inline double rinv(double phi1, double phi2, double r1, double r2) { + if (r2 <= r1) { //FIXME can not form tracklet should not call function with r2<=r1 + return 20.0; + } - if (isPS) { - if (ibend == 0 || ibend == 1) - return 0; - if (ibend == 2 || ibend == 3) - return 1; - if (ibend == 4 || ibend == 5) - return 2; - if (ibend >= 6) - return 3; - if (ibend == -1 || ibend == -2) - return 4; - if (ibend == -3 || ibend == -4) - return 5; - if (ibend == -5 || ibend == -6) - return 6; - if (ibend <= -7) - return 7; - - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ - << " Unknown bendencode for PS module for bend = " << bend - << " ibend = " << ibend; + double dphi = phi2 - phi1; + double dr = r2 - r1; + + return 2.0 * sin(dphi) / dr / sqrt(1.0 + 2 * r1 * r2 * (1.0 - cos(dphi)) / (dr * dr)); + } + + inline std::string convertHexToBin(const std::string& stubwordhex) { + std::string stubwordbin = ""; + + for (char word : stubwordhex) { + std::string hexword = ""; + if (word == '0') + hexword = "0000"; + if (word == '1') + hexword = "0001"; + if (word == '2') + hexword = "0010"; + if (word == '3') + hexword = "0011"; + if (word == '4') + hexword = "0100"; + if (word == '5') + hexword = "0101"; + if (word == '6') + hexword = "0110"; + if (word == '7') + hexword = "0111"; + if (word == '8') + hexword = "1000"; + if (word == '9') + hexword = "1001"; + if (word == 'A') + hexword = "1010"; + if (word == 'B') + hexword = "1011"; + if (word == 'C') + hexword = "1100"; + if (word == 'D') + hexword = "1101"; + if (word == 'E') + hexword = "1110"; + if (word == 'F') + hexword = "1111"; + if (hexword == "") { + throw cms::Exception("Inconsistency") + << __FILE__ << " " << __LINE__ << " hex string format invalid: " << stubwordhex; + } + stubwordbin += hexword; } + return stubwordbin; + } - if (ibend == 0 || ibend == 1) - return 0; - if (ibend == 2 || ibend == 3) - return 1; - if (ibend == 4 || ibend == 5) - return 2; - if (ibend == 6 || ibend == 7) - return 3; - if (ibend == 8 || ibend == 9) - return 4; - if (ibend == 10 || ibend == 11) - return 5; - if (ibend == 12 || ibend == 13) - return 6; - if (ibend >= 14) - return 7; - if (ibend == -1 || ibend == -2) - return 8; - if (ibend == -3 || ibend == -4) - return 9; - if (ibend == -5 || ibend == -6) - return 10; - if (ibend == -7 || ibend == -8) - return 11; - if (ibend == -9 || ibend == -10) - return 12; - if (ibend == -11 || ibend == -12) - return 13; - if (ibend == -13 || ibend == -14) - return 14; - if (ibend <= -15) - return 15; - - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ - << " Unknown bendencode for 2S module for bend = " << bend - << " ibend = " << ibend; + inline int ilog2(double factor) { + double power = log(factor) / log(2); + int ipower = round(power); + assert(std::abs(power - ipower) < 0.1); + return ipower; } - //Should be optimized by layer - now first implementation to make sure it works OK - inline double benddecode(int ibend, bool isPS) { - if (isPS) { - if (ibend == 0) - return 0.25; - if (ibend == 1) - return 1.25; - if (ibend == 2) - return 2.25; - if (ibend == 3) - return 3.25; - if (ibend == 4) - return -0.75; - if (ibend == 5) - return -1.75; - if (ibend == 6) - return -2.75; - if (ibend == 7) - return -3.75; - - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ - << " Unknown benddecode for PS module for ibend = " << ibend; + /****************************************************************************** + * Checks to see if a directory exists. Note: This method only checks the + * existence of the full path AND if path leaf is a dir. + * + * @return 1 if dir exists AND is a dir, + * 0 if dir does not exist OR exists but not a dir, + * -1 if an error occurred (errno is also set) + *****************************************************************************/ + inline int dirExists(const std::string& path) { + struct stat info; + + int statRC = stat(path.c_str(), &info); + if (statRC != 0) { + if (errno == ENOENT) { + return 0; + } // something along the path does not exist + if (errno == ENOTDIR) { + return 0; + } // something in path prefix is not a dir + return -1; } - if (ibend == 0) - return 0.25; - if (ibend == 1) - return 1.25; - if (ibend == 2) - return 2.25; - if (ibend == 3) - return 3.25; - if (ibend == 4) - return 4.25; - if (ibend == 5) - return 5.25; - if (ibend == 6) - return 6.25; - if (ibend == 7) - return 7.25; - if (ibend == 8) - return -0.75; - if (ibend == 9) - return -1.75; - if (ibend == 10) - return -2.75; - if (ibend == 11) - return -3.75; - if (ibend == 12) - return -4.75; - if (ibend == 13) - return -5.75; - if (ibend == 14) - return -6.75; - if (ibend == 15) - return -7.75; - - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ - << " Unknown benddecode for 2S module for ibend = " << ibend; + return (info.st_mode & S_IFDIR) ? 1 : 0; } - inline double bend(double r, double rinv, double stripPitch) { - constexpr double dr = 0.18; - double delta = r * dr * 0.5 * rinv; - double bend = -delta / stripPitch; - return bend; + //Open file - create directory if not existent. + inline std::ofstream openfile(const std::string& dir, const std::string& fname, const char* file, int line) { + if (dirExists(dir) != 1) { + std::cout << "Creating directory : " << dir << std::endl; + int fail = system((std::string("mkdir -p ") + dir).c_str()); + if (fail) { + throw cms::Exception("BadDir") << file << " " << line << " could not create directory " << dir; + } + } + + std::ofstream out(dir + "/" + fname); + + if (out.fail()) { + throw cms::Exception("BadFile") << file << " " << line << " could not create file " << fname << " in " << dir; + } + + return out; } - inline double rinv(double phi1, double phi2, double r1, double r2) { - if (r2 <= r1) { //can not form tracklet - return 20.0; + //Open file - create directory if not existent. + //If first==true open file in create mode, if first==false open in append mode + inline void openfile( + std::ofstream& out, bool first, const std::string& dir, const std::string& fname, const char* file, int line) { + if (dirExists(dir) != 1) { + std::cout << "Creating directory : " << dir << std::endl; + int fail = system((std::string("mkdir -p ") + dir).c_str()); + if (fail) { + throw cms::Exception("BadDir") << file << " " << line << " could not create directory " << dir; + } } - double dphi = phi2 - phi1; - double dr = r2 - r1; + if (first) { + out.open(fname); + } else { + out.open(fname, std::ofstream::app); + } - return 2.0 * sin(dphi) / dr / sqrt(1.0 + 2 * r1 * r2 * (1.0 - cos(dphi)) / (dr * dr)); + if (out.fail()) { + throw cms::Exception("BadFile") << file << " " << line << " could not create file " << fname << " in " << dir; + } } }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h b/L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h index 1b3e37aba7184..47f15743dc6c8 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h @@ -13,7 +13,7 @@ namespace trklet { class VMProjectionsMemory : public MemoryBase { public: - VMProjectionsMemory(std::string name, Settings const& settings, unsigned int iSector); + VMProjectionsMemory(std::string name, Settings const& settings); ~VMProjectionsMemory() override = default; @@ -24,7 +24,7 @@ namespace trklet { Tracklet* getTracklet(unsigned int i) { return tracklets_[i].first; } int getAllProjIndex(unsigned int i) const { return tracklets_[i].second; } - void writeVMPROJ(bool first); + void writeVMPROJ(bool first, unsigned int iSector); void clean() override { tracklets_.clear(); } diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouter.h b/L1Trigger/TrackFindingTracklet/interface/VMRouter.h index 5e93482182cfe..52811501ac88e 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouter.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouter.h @@ -34,7 +34,7 @@ namespace trklet { class VMRouter : public ProcessBase { public: - VMRouter(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + VMRouter(std::string name, Settings const& settings, Globals* global); ~VMRouter() override = default; @@ -57,8 +57,8 @@ namespace trklet { VMRouterTable vmrtable_; - //The input stub memories - std::vector stubinputs_; + //The input stub memories the two tmp inputs are used to build the order needed in HLS + std::vector stubinputs_, stubinputtmp_, stubinputdisk2stmp_; //The all stub memories std::vector allstubs_; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h b/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h index a360351aafe84..3322ea12019aa 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h @@ -17,6 +17,7 @@ namespace trklet { class MemoryBase; class InputLinkMemory; class AllStubsMemory; + class AllInnerStubsMemory; class VMStubsMEMemory; class VMStubsTEMemory; @@ -30,7 +31,7 @@ namespace trklet { class VMRouterCM : public ProcessBase { public: - VMRouterCM(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + VMRouterCM(std::string name, Settings const& settings, Globals* global); ~VMRouterCM() override = default; @@ -59,7 +60,8 @@ namespace trklet { std::vector stubinputs_; //The all stub memories - std::vector > allstubs_; + std::vector allstubs_; + std::vector > allinnerstubs_; //The VM stubs memories used by the MEs std::vector vmstubsMEPHI_; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h b/L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h index 08a1ecd198fe2..b376c5d712c79 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h @@ -20,7 +20,7 @@ namespace trklet { ~VMRouterTable() = default; - void init(unsigned int layerdisk, std::string const& name); + void init(unsigned int layerdisk, std::string const& name = ""); // negative return means that seed can not be formed int getLookup(unsigned int layerdisk, double z, double r, int iseed = -1); @@ -30,7 +30,8 @@ namespace trklet { int lookupinner(int zbin, int rbin); int lookupinneroverlap(int zbin, int rbin); int lookupinnerThird(int zbin, int rbin); - void writeVMTable(std::string const& name, std::vector const& table); + + void writeVMTable(std::string const& dir, std::string const& name, std::vector const& table); private: Settings const& settings_; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h b/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h index 8c231f2909352..ee85a668da883 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h @@ -15,7 +15,7 @@ namespace trklet { class VMStubsMEMemory : public MemoryBase { public: - VMStubsMEMemory(std::string name, Settings const& settings, unsigned int iSector); + VMStubsMEMemory(std::string name, Settings const& settings); ~VMStubsMEMemory() override = default; @@ -50,7 +50,7 @@ namespace trklet { } } - void writeStubs(bool first); + void writeStubs(bool first, unsigned int iSector); private: std::vector > binnedstubs_; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h b/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h index b494573c7de79..e77d22ba3cb02 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h @@ -15,7 +15,7 @@ namespace trklet { class VMStubsTEMemory : public MemoryBase { public: - VMStubsTEMemory(std::string name, Settings const& settings, unsigned int iSector); + VMStubsTEMemory(std::string name, Settings const& settings); ~VMStubsTEMemory() override = default; @@ -37,7 +37,7 @@ namespace trklet { void clean() override; - void writeStubs(bool first); + void writeStubs(bool first, unsigned int iSector); int phibin() const { return phibin_; } @@ -59,6 +59,7 @@ namespace trklet { private: int layer_; int disk_; + int layerdisk_; int phibin_; VMStubsTEMemory* other_; bool overlap_; diff --git a/L1Trigger/TrackFindingTracklet/plugins/BuildFile.xml b/L1Trigger/TrackFindingTracklet/plugins/BuildFile.xml index df534e5516622..c9303f449c53b 100644 --- a/L1Trigger/TrackFindingTracklet/plugins/BuildFile.xml +++ b/L1Trigger/TrackFindingTracklet/plugins/BuildFile.xml @@ -4,6 +4,7 @@ + diff --git a/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc b/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc index aa6b5f30f9860..ad83e1ec15f16 100644 --- a/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc +++ b/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc @@ -40,7 +40,6 @@ #include "SimDataFormats/Vertex/interface/SimVertex.h" #include "SimDataFormats/Vertex/interface/SimVertexContainer.h" #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" -#include "SimDataFormats/TrackingAnalysis/interface/TrackingVertex.h" #include "SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h" #include "SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h" // @@ -52,6 +51,8 @@ #include "DataFormats/L1TrackTrigger/interface/TTTrack.h" #include "DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h" #include "DataFormats/L1TrackTrigger/interface/TTTypes.h" +#include "DataFormats/L1TrackTrigger/interface/TTDTC.h" +#include "L1Trigger/TrackerDTC/interface/Setup.h" // #include "DataFormats/HepMCCandidate/interface/GenParticle.h" #include "DataFormats/Candidate/interface/Candidate.h" @@ -80,7 +81,6 @@ // Tracklet emulation #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" #include "L1Trigger/TrackFindingTracklet/interface/Sector.h" -#include "L1Trigger/TrackFindingTracklet/interface/Cabling.h" #include "L1Trigger/TrackFindingTracklet/interface/Track.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h" @@ -118,14 +118,14 @@ using namespace std; // between different types of stubs struct L1TStubCompare { public: - bool operator()(const trklet::L1TStub& x, const trklet::L1TStub& y) const { - if (x.x() != y.x()) - return (y.x() > x.x()); + bool operator()(const trklet::L1TStub& a, const trklet::L1TStub& b) const { + if (a.x() != b.x()) + return (b.x() > a.x()); else { - if (x.y() != y.y()) - return (y.y() > x.y()); + if (a.y() != b.y()) + return (b.y() > a.y()); else - return (x.z() > y.z()); + return (a.z() > b.z()); } } }; @@ -150,18 +150,12 @@ class L1FPGATrackProducer : public edm::one::EDProducer { edm::FileInPath processingModulesFile; edm::FileInPath wiresFile; - edm::FileInPath DTCLinkFile; - edm::FileInPath moduleCablingFile; - edm::FileInPath DTCLinkLayerDiskFile; - edm::FileInPath tableTEDFile; edm::FileInPath tableTREFile; string asciiEventOutName_; std::ofstream asciiEventOut_; - string geometryType_; - // settings containing various constants for the tracklet processing trklet::Settings settings; @@ -182,17 +176,18 @@ class L1FPGATrackProducer : public edm::one::EDProducer { edm::InputTag MCTruthClusterInputTag; edm::InputTag MCTruthStubInputTag; edm::InputTag TrackingParticleInputTag; - edm::InputTag TrackingVertexInputTag; - edm::InputTag ttStubSrc_; - edm::InputTag bsSrc_; - const edm::EDGetTokenT>> ttStubToken_; const edm::EDGetTokenT bsToken_; edm::EDGetTokenT> ttClusterMCTruthToken_; - edm::EDGetTokenT> ttStubMCTruthToken_; edm::EDGetTokenT> TrackingParticleToken_; - edm::EDGetTokenT> TrackingVertexToken_; + edm::EDGetTokenT tokenDTC_; + + // helper class to store DTC configuration + trackerDTC::Setup setup_; + + // Setup token + edm::ESGetToken esGetToken_; /// ///////////////// /// /// MANDATORY METHODS /// @@ -212,18 +207,11 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig) : edm::InputTag()), TrackingParticleInputTag(readMoreMcTruth_ ? iConfig.getParameter("TrackingParticleInputTag") : edm::InputTag()), - TrackingVertexInputTag(readMoreMcTruth_ ? iConfig.getParameter("TrackingVertexInputTag") - : edm::InputTag()), - ttStubSrc_(config.getParameter("TTStubSource")), - bsSrc_(config.getParameter("BeamSpotSource")), - - ttStubToken_(consumes>>(ttStubSrc_)), - bsToken_(consumes(bsSrc_)) { + bsToken_(consumes(config.getParameter("BeamSpotSource"))), + tokenDTC_(consumes(edm::InputTag(iConfig.getParameter("InputTagTTDTC")))) { if (readMoreMcTruth_) { ttClusterMCTruthToken_ = consumes>(MCTruthClusterInputTag); - ttStubMCTruthToken_ = consumes>(MCTruthStubInputTag); TrackingParticleToken_ = consumes>(TrackingParticleInputTag); - TrackingVertexToken_ = consumes>(TrackingVertexInputTag); } produces>>("Level1TTTracks").setBranchAlias("Level1TTTracks"); @@ -235,10 +223,6 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig) memoryModulesFile = iConfig.getParameter("memoryModulesFile"); wiresFile = iConfig.getParameter("wiresFile"); - DTCLinkFile = iConfig.getParameter("DTCLinkFile"); - moduleCablingFile = iConfig.getParameter("moduleCablingFile"); - DTCLinkLayerDiskFile = iConfig.getParameter("DTCLinkLayerDiskFile"); - extended_ = iConfig.getParameter("Extended"); nHelixPar_ = iConfig.getParameter("Hnpar"); @@ -247,6 +231,9 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig) tableTREFile = iConfig.getParameter("tableTREFile"); } + // book ES product + esGetToken_ = esConsumes(); + // -------------------------------------------------------------------------------- // set options in Settings based on inputs from configuration files // -------------------------------------------------------------------------------- @@ -254,9 +241,6 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig) settings.setExtended(extended_); settings.setNHelixPar(nHelixPar_); - settings.setDTCLinkFile(DTCLinkFile.fullPath()); - settings.setModuleCablingFile(moduleCablingFile.fullPath()); - settings.setDTCLinkLayerDiskFile(DTCLinkLayerDiskFile.fullPath()); settings.setFitPatternFile(fitPatternFile.fullPath()); settings.setProcessingModulesFile(processingModulesFile.fullPath()); settings.setMemoryModulesFile(memoryModulesFile.fullPath()); @@ -278,10 +262,7 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig) } if (settings.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "cabling DTC links : " << DTCLinkFile.fullPath() - << "\n module cabling : " << moduleCablingFile.fullPath() - << "\n DTC link layer disk : " << DTCLinkLayerDiskFile.fullPath() - << "\n fit pattern : " << fitPatternFile.fullPath() + edm::LogVerbatim("Tracklet") << "fit pattern : " << fitPatternFile.fullPath() << "\n process modules : " << processingModulesFile.fullPath() << "\n memory modules : " << memoryModulesFile.fullPath() << "\n wires : " << wiresFile.fullPath(); @@ -320,6 +301,8 @@ void L1FPGATrackProducer::beginRun(const edm::Run& run, const edm::EventSetup& i double mMagneticFieldStrength = theMagneticField->inTesla(GlobalPoint(0, 0, 0)).z(); settings.setBfield(mMagneticFieldStrength); + setup_ = iSetup.getData(esGetToken_); + // initialize the tracklet event processing (this sets all the processing & memory modules, wiring, etc) eventProcessor.init(settings); } @@ -357,16 +340,12 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe eventnum++; trklet::SLHCEvent ev; ev.setEventNum(eventnum); - ev.setIPx(bsPosition.x()); - ev.setIPy(bsPosition.y()); + ev.setIP(bsPosition.x(), bsPosition.y()); // tracking particles edm::Handle> TrackingParticleHandle; - edm::Handle> TrackingVertexHandle; if (readMoreMcTruth_) iEvent.getByToken(TrackingParticleToken_, TrackingParticleHandle); - if (readMoreMcTruth_) - iEvent.getByToken(TrackingVertexToken_, TrackingVertexHandle); // tracker topology const TrackerTopology* const tTopo = tTopoHandle.product(); @@ -374,18 +353,16 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe //////////////////////// // GET THE PRIMITIVES // - edm::Handle>> Phase2TrackerDigiTTStubHandle; - iEvent.getByToken(ttStubToken_, Phase2TrackerDigiTTStubHandle); + edm::Handle handleDTC; + iEvent.getByToken(tokenDTC_, handleDTC); // must be defined for code to compile, even if it's not used unless readMoreMcTruth_ is true map, int> translateTP; // MC truth association maps edm::Handle> MCTruthTTClusterHandle; - edm::Handle> MCTruthTTStubHandle; if (readMoreMcTruth_) { iEvent.getByToken(ttClusterMCTruthToken_, MCTruthTTClusterHandle); - iEvent.getByToken(ttStubMCTruthToken_, MCTruthTTStubHandle); //////////////////////////////////////////////// /// LOOP OVER TRACKING PARTICLES & GET SIMTRACKS @@ -427,57 +404,110 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe } // end if (readMoreMcTruth_) - //////////////////////////////// - /// COLLECT STUB INFORMATION /// - //////////////////////////////// + ///////////////////////////////// + /// READ DTC STUB INFORMATION /// + ///////////////////////////////// - bool firstPS = true; - bool first2S = true; + // Process stubs in each region and channel within that region + for (const int& region : handleDTC->tfpRegions()) { + for (const int& channel : handleDTC->tfpChannels()) { + // Get the DTC name form the channel - for (const auto& gd : theTrackerGeom->dets()) { - DetId detid = (*gd).geographicalId(); - if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID) - continue; // only run on OT - if (!tTopo->isLower(detid)) - continue; // loop on the stacks: choose the lower arbitrarily - DetId stackDetid = tTopo->stack(detid); // Stub module detid + static string dtcbasenames[12] = { + "PS10G_1", "PS10G_2", "PS10G_3", "PS10G_4", "PS_1", "PS_2", "2S_1", "2S_2", "2S_3", "2S_4", "2S_5", "2S_6"}; - if (Phase2TrackerDigiTTStubHandle->find(stackDetid) == Phase2TrackerDigiTTStubHandle->end()) - continue; + string dtcname = dtcbasenames[channel % 12]; - // Get the DetSets of the Clusters - edmNew::DetSet> stubs = (*Phase2TrackerDigiTTStubHandle)[stackDetid]; - const GeomDetUnit* det0 = theTrackerGeom->idToDetUnit(detid); - const auto* theGeomDet = dynamic_cast(det0); - const PixelTopology* topol = dynamic_cast(&(theGeomDet->specificTopology())); + if (channel % 24 >= 12) + dtcname = "neg" + dtcname; - bool isPSmodule = theTrackerGeom->getDetectorType(detid) == TrackerGeometry::ModuleType::Ph2PSP; + dtcname += (channel < 24) ? "_A" : "_B"; - // set constants that are common for all modules/stubs of a given type (PS vs 2S) - if (isPSmodule && firstPS) { - settings.setNStrips_PS(topol->nrows()); - settings.setStripPitch_PS(topol->pitch().first); - settings.setStripLength_PS(topol->pitch().second); - firstPS = false; - } - if (!isPSmodule && first2S) { - settings.setNStrips_2S(topol->nrows()); - settings.setStripPitch_2S(topol->pitch().first); - settings.setStripLength_2S(topol->pitch().second); - first2S = false; - } + // Get the stubs from the DTC + const TTDTC::Stream& streamFromDTC{handleDTC->stream(region, channel)}; - // loop over stubs - for (auto stubIter = stubs.begin(); stubIter != stubs.end(); ++stubIter) { - edm::Ref>, TTStub> tempStubPtr = - edmNew::makeRefTo(Phase2TrackerDigiTTStubHandle, stubIter); + // Prepare the DTC stubs for the IR + for (size_t stubIndex = 0; stubIndex < streamFromDTC.size(); ++stubIndex) { + const TTDTC::Frame& stub{streamFromDTC[stubIndex]}; - vector assocTPs; + if (stub.first.isNull()) { + continue; + } + + const GlobalPoint& ttPos = setup_.stubPos(stub.first); + + //Get the 2 bits for the layercode + string layerword = stub.second.to_string().substr(61, 2); + unsigned int layercode = 2 * (layerword[0] - '0') + layerword[1] - '0'; + assert(layercode < 4); + + //translation from the two bit layercode to the layer/disk number of each of the + //12 channels (dtcs) + static int layerdisktab[12][4] = {{0, 6, 8, 10}, + {0, 7, 9, -1}, + {1, 7, -1, -1}, + {6, 8, 10, -1}, + {2, 7, -1, -1}, + {2, 9, -1, -1}, + {3, 4, -1, -1}, + {4, -1, -1, -1}, + {5, -1, -1, -1}, + {5, 8, -1, -1}, + {6, 9, -1, -1}, + {7, 10, -1, -1}}; + + int layerdisk = layerdisktab[channel % 12][layercode]; + assert(layerdisk != -1); + + //Get the 36 bit word - skip the lowest 3 buts (status and layer code) + constexpr int DTCLinkWordSize = 64; + constexpr int StubWordSize = 36; + constexpr int LayerandStatusCodeSize = 3; + string stubword = stub.second.to_string().substr(DTCLinkWordSize - StubWordSize - LayerandStatusCodeSize, StubWordSize); + string stubwordhex = ""; + + //Loop over the 9 words in the 36 bit stub word + for (unsigned int i = 0; i < 9; i++) { + bitset<4> bits(stubword.substr(i * 4, 4)); + ulong val = bits.to_ulong(); + stubwordhex += ((val < 10) ? ('0' + val) : ('A' + val - 10)); + } + + /// Get the Inner and Outer TTCluster + edm::Ref>, TTCluster> + innerCluster = stub.first->clusterRef(0); + edm::Ref>, TTCluster> + outerCluster = stub.first->clusterRef(1); + + // ----------------------------------------------------- + // check module orientation, if flipped, need to store that information for track fit + // ----------------------------------------------------- + + const DetId innerDetId = innerCluster->getDetId(); + const GeomDetUnit* det_inner = theTrackerGeom->idToDetUnit(innerDetId); + const auto* theGeomDet_inner = dynamic_cast(det_inner); + const PixelTopology* topol_inner = dynamic_cast(&(theGeomDet_inner->specificTopology())); + + MeasurementPoint coords_inner = innerCluster->findAverageLocalCoordinatesCentered(); + LocalPoint clustlp_inner = topol_inner->localPosition(coords_inner); + GlobalPoint posStub_inner = theGeomDet_inner->surface().toGlobal(clustlp_inner); + + const DetId outerDetId = outerCluster->getDetId(); + const GeomDetUnit* det_outer = theTrackerGeom->idToDetUnit(outerDetId); + const auto* theGeomDet_outer = dynamic_cast(det_outer); + const PixelTopology* topol_outer = dynamic_cast(&(theGeomDet_outer->specificTopology())); + + MeasurementPoint coords_outer = outerCluster->findAverageLocalCoordinatesCentered(); + LocalPoint clustlp_outer = topol_outer->localPosition(coords_outer); + GlobalPoint posStub_outer = theGeomDet_outer->surface().toGlobal(clustlp_outer); + + bool isFlipped = (posStub_outer.mag() < posStub_inner.mag()); + + vector assocTPs; - if (readMoreMcTruth_) { for (unsigned int iClus = 0; iClus <= 1; iClus++) { // Loop over both clusters that make up stub. - const TTClusterRef& ttClusterRef = tempStubPtr->clusterRef(iClus); + const TTClusterRef& ttClusterRef = stub.first->clusterRef(iClus); // Now identify all TP's contributing to either cluster in stub. vector> vecTpPtr = MCTruthTTClusterHandle->findTrackingParticlePtrs(ttClusterRef); @@ -495,128 +525,27 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe } } } - } // end if (readMoreMcTruth_) - - MeasurementPoint coords = tempStubPtr->clusterRef(0)->findAverageLocalCoordinatesCentered(); - LocalPoint clustlp = topol->localPosition(coords); - GlobalPoint posStub = theGeomDet->surface().toGlobal(clustlp); - int eventID = -1; - - if (readMoreMcTruth_) { - edm::Ptr my_tp = MCTruthTTStubHandle->findTrackingParticlePtr(tempStubPtr); - } - - int layer = -999999; - int ladder = -999999; - int module = -999999; - - int strip = 460; - - if (detid.subdetId() == StripSubdetector::TOB) { - layer = static_cast(tTopo->layer(detid)); - module = static_cast(tTopo->module(detid)); - ladder = static_cast(tTopo->tobRod(detid)); - - // https://github.com/cms-sw/cmssw/tree/master/Geometry/TrackerNumberingBuilder - // tobSide = 1: ring- (tilted) - // tobSide = 2: ring+ (tilted) - // tobSide = 3: barrel (flat) - enum TypeBarrel { nonBarrel = 0, tiltedMinus = 1, tiltedPlus = 2, flat = 3 }; - const TypeBarrel type = static_cast(tTopo->tobSide(detid)); - - // modules in the flat part of barrel are mounted on planks, while modules in tilted part are on rings - // below, "module" is the module number in the z direction (from minus z to positive), - // while "ladder" is the module number in the phi direction - - if (layer > 0 && layer <= (int)trklet::N_PSLAYER) { - if (type == tiltedMinus) { - module = static_cast(tTopo->tobRod(detid)); - ladder = static_cast(tTopo->module(detid)); - } - if (type == tiltedPlus) { - module = - trklet::N_TILTED_RINGS + trklet::N_MOD_PLANK.at(layer - 1) + static_cast(tTopo->tobRod(detid)); - ladder = static_cast(tTopo->module(detid)); - } - if (type == flat) { - module = trklet::N_TILTED_RINGS + static_cast(tTopo->module(detid)); - } + double stubbend = stub.first->bendFE(); //stub.first->rawBend() + if (ttPos.z() < -120) { + stubbend = -stubbend; } - } else if (detid.subdetId() == StripSubdetector::TID) { - layer = 1000 + static_cast(tTopo->tidRing(detid)); - ladder = static_cast(tTopo->module(detid)); - module = static_cast(tTopo->tidWheel(detid)); - } - /// Get the Inner and Outer TTCluster - edm::Ref>, TTCluster> innerCluster = - tempStubPtr->clusterRef(0); - edm::Ref>, TTCluster> outerCluster = - tempStubPtr->clusterRef(1); - - std::vector irphi; - std::vector innerrows = innerCluster->getRows(); - irphi.reserve(innerrows.size()); - for (int innerrow : innerrows) { - irphi.push_back(innerrow); - } - std::vector outerrows = outerCluster->getRows(); - for (int outerrow : outerrows) { - irphi.push_back(outerrow); - } - - // ----------------------------------------------------- - // check module orientation, if flipped, need to store that information for track fit - // ----------------------------------------------------- - - const DetId innerDetId = innerCluster->getDetId(); - const GeomDetUnit* det_inner = theTrackerGeom->idToDetUnit(innerDetId); - const auto* theGeomDet_inner = dynamic_cast(det_inner); - const PixelTopology* topol_inner = dynamic_cast(&(theGeomDet_inner->specificTopology())); - - MeasurementPoint coords_inner = innerCluster->findAverageLocalCoordinatesCentered(); - LocalPoint clustlp_inner = topol_inner->localPosition(coords_inner); - GlobalPoint posStub_inner = theGeomDet_inner->surface().toGlobal(clustlp_inner); - - const DetId outerDetId = outerCluster->getDetId(); - const GeomDetUnit* det_outer = theTrackerGeom->idToDetUnit(outerDetId); - const auto* theGeomDet_outer = dynamic_cast(det_outer); - const PixelTopology* topol_outer = dynamic_cast(&(theGeomDet_outer->specificTopology())); + ev.addStub(dtcname, + region, + layerdisk, + stubwordhex, + setup_.psModule(setup_.dtcId(region, channel)), + isFlipped, + ttPos.x(), + ttPos.y(), + ttPos.z(), + stubbend, + stub.first->innerClusterPosition(), + assocTPs); - MeasurementPoint coords_outer = outerCluster->findAverageLocalCoordinatesCentered(); - LocalPoint clustlp_outer = topol_outer->localPosition(coords_outer); - GlobalPoint posStub_outer = theGeomDet_outer->surface().toGlobal(clustlp_outer); - - bool isFlipped = (posStub_outer.mag() < posStub_inner.mag()); - - // ----------------------------------------------------- - // correct sign for stubs in negative endcap - float stub_bend = tempStubPtr->bendFE(); - float stub_pt = -1; - if (layer > 999 && posStub.z() < 0.0) { - stub_bend = -stub_bend; - } - if (!irphi.empty()) { - strip = irphi[0]; - } - - //if module FE inefficiencies are calculated, a stub is thrown out if rawBend > 100 - if ((tempStubPtr->rawBend() < 100.) && (ev.addStub(layer, - ladder, - module, - strip, - eventID, - assocTPs, - stub_pt, - stub_bend, - posStub.x(), - posStub.y(), - posStub.z(), - isPSmodule, - isFlipped))) { const trklet::L1TStub& lastStub = ev.lastStub(); - stubMap[lastStub] = tempStubPtr; + stubMap[lastStub] = stub.first; } } } @@ -628,9 +557,7 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe ev.write(asciiEventOut_); } - std::vector& tracks = eventProcessor.tracks(); - - trklet::L1SimTrack simtrk(0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + const std::vector& tracks = eventProcessor.tracks(); // this performs the actual tracklet event processing eventProcessor.event(ev); @@ -638,20 +565,20 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe int ntracks = 0; for (auto track : tracks) { - if (track->duplicate()) + if (track.duplicate()) continue; ntracks++; // this is where we create the TTTrack object - double tmp_rinv = track->rinv(settings); - double tmp_phi = track->phi0(settings); - double tmp_tanL = track->tanL(settings); - double tmp_z0 = track->z0(settings); - double tmp_d0 = track->d0(settings); - double tmp_chi2rphi = track->chisqrphi(); - double tmp_chi2rz = track->chisqrz(); - unsigned int tmp_hit = track->hitpattern(); + double tmp_rinv = track.rinv(settings); + double tmp_phi = track.phi0(settings); + double tmp_tanL = track.tanL(settings); + double tmp_z0 = track.z0(settings); + double tmp_d0 = track.d0(settings); + double tmp_chi2rphi = track.chisqrphi(); + double tmp_chi2rz = track.chisqrz(); + unsigned int tmp_hit = track.hitpattern(); TTTrack aTrack(tmp_rinv, tmp_phi, @@ -667,18 +594,18 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe settings.nHelixPar(), settings.bfield()); - unsigned int trksector = track->sector(); - unsigned int trkseed = (unsigned int)abs(track->seed()); + unsigned int trksector = track.sector(); + unsigned int trkseed = (unsigned int)abs(track.seed()); aTrack.setPhiSector(trksector); aTrack.setTrackSeedType(trkseed); - const vector& stubptrs = track->stubs(); + const vector& stubptrs = track.stubs(); vector stubs; stubs.reserve(stubptrs.size()); for (auto stubptr : stubptrs) { - stubs.push_back(*stubptr); + stubs.push_back(stubptr); } stubMapType::const_iterator it; diff --git a/L1Trigger/TrackFindingTracklet/python/Tracklet_cfi.py b/L1Trigger/TrackFindingTracklet/python/Tracklet_cfi.py index cab518307ffb2..0ca90046d6e93 100644 --- a/L1Trigger/TrackFindingTracklet/python/Tracklet_cfi.py +++ b/L1Trigger/TrackFindingTracklet/python/Tracklet_cfi.py @@ -3,11 +3,11 @@ TTTracksFromTrackletEmulation = cms.EDProducer("L1FPGATrackProducer", TTStubSource = cms.InputTag("TTStubsFromPhase2TrackerDigis","StubAccepted"), + InputTagTTDTC = cms.InputTag ( "TrackerDTCProducer", "StubAccepted" ), readMoreMcTruth = cms.bool(True), MCTruthClusterInputTag = cms.InputTag("TTClusterAssociatorFromPixelDigis", "ClusterAccepted"), MCTruthStubInputTag = cms.InputTag("TTStubAssociatorFromPixelDigis", "StubAccepted"), TrackingParticleInputTag = cms.InputTag("mix", "MergedTrackTruth"), - TrackingVertexInputTag = cms.InputTag("mix", "MergedTrackTruth"), BeamSpotSource = cms.InputTag("offlineBeamSpot"), asciiFileName = cms.untracked.string(""), # (if running on CRAB use "../../fitpattern.txt" etc instead) @@ -17,9 +17,6 @@ memoryModulesFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/memorymodules_hourglass.dat'), processingModulesFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/processingmodules_hourglass.dat'), wiresFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/wires_hourglass.dat'), - DTCLinkFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/calcNumDTCLinks.txt'), - DTCLinkLayerDiskFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/dtclinklayerdisk.dat'), - moduleCablingFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/modules_T5v3_27SP_nonant_tracklet.dat'), # Quality Flag and Quality params TrackQuality =cms.bool(True), TrackQualityPSet = cms.PSet(TrackQualityParams) diff --git a/L1Trigger/TrackFindingTracklet/src/AllInnerStubsMemory.cc b/L1Trigger/TrackFindingTracklet/src/AllInnerStubsMemory.cc new file mode 100644 index 0000000000000..5ee9e5b1cda63 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/AllInnerStubsMemory.cc @@ -0,0 +1,24 @@ +#include "L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include + +using namespace std; +using namespace trklet; + +AllInnerStubsMemory::AllInnerStubsMemory(string name, Settings const& settings) : MemoryBase(name, settings) {} + +void AllInnerStubsMemory::writeStubs(bool first, unsigned int iSector) { + iSector_ = iSector; + const string dirS = settings_.memPath() + "Stubs/"; + openFile(first, dirS, "AllInnerStubs_"); + + for (unsigned int j = 0; j < stubs_.size(); j++) { + string stub = stubs_[j]->strinner(); + out_ << "0x"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + out_ << " " << stub << " " << hexFormat(stub) << endl; + } + out_.close(); +} diff --git a/L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc b/L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc index 2aef2b74ef8ca..d15cb03d753de 100644 --- a/L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc @@ -1,6 +1,7 @@ #include "L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include @@ -9,33 +10,19 @@ using namespace trklet; using namespace std; -AllProjectionsMemory::AllProjectionsMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) { +AllProjectionsMemory::AllProjectionsMemory(string name, Settings const& settings) : MemoryBase(name, settings) { initLayerDisk(3, layer_, disk_); } -void AllProjectionsMemory::writeAP(bool first) { +void AllProjectionsMemory::writeAP(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirTP = settings_.memPath() + "TrackletProjections/"; std::ostringstream oss; oss << dirTP << "AllProj_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirTP)) { - int fail = system((string("mkdir -p ") + dirTP).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirTP; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirTP, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/AllStubsMemory.cc b/L1Trigger/TrackFindingTracklet/src/AllStubsMemory.cc index 315b7f668fbc9..db3993fdd74c5 100644 --- a/L1Trigger/TrackFindingTracklet/src/AllStubsMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/AllStubsMemory.cc @@ -6,10 +6,10 @@ using namespace std; using namespace trklet; -AllStubsMemory::AllStubsMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) {} +AllStubsMemory::AllStubsMemory(string name, Settings const& settings) : MemoryBase(name, settings) {} -void AllStubsMemory::writeStubs(bool first) { +void AllStubsMemory::writeStubs(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirS = settings_.memPath() + "Stubs/"; openFile(first, dirS, "AllStubs_"); diff --git a/L1Trigger/TrackFindingTracklet/src/Cabling.cc b/L1Trigger/TrackFindingTracklet/src/Cabling.cc deleted file mode 100644 index c0b48b3e494ad..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/Cabling.cc +++ /dev/null @@ -1,126 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/Cabling.h" -#include "L1Trigger/TrackFindingTracklet/interface/DTCLink.h" -#include "L1Trigger/TrackFindingTracklet/interface/DTC.h" -#include "L1Trigger/TrackFindingTracklet/interface/Util.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/Exception.h" -#include "DataFormats/Math/interface/deltaPhi.h" - -using namespace std; -using namespace trklet; - -Cabling::Cabling(string dtcconfig, string moduleconfig, Settings const& settings) : settings_(settings) { - ifstream indtc(dtcconfig.c_str()); - assert(indtc.good()); - - string dtc; - int isec; - - while (indtc.good()) { - indtc >> dtc >> isec; - - if (!indtc.good()) - continue; - - if (dtcs_.find(dtc) == dtcs_.end()) { - dtcs_[dtc].setName(dtc); - } - - dtcs_[dtc].addSec(isec); - - string dtcbase = dtc.substr(2, dtc.size() - 2); - if (dtc[0] == 'n') { - dtcbase = "neg_" + dtc.substr(6, dtc.size() - 6); - } - if (dtcranges_.find(dtcbase) == dtcranges_.end()) { - dtcranges_[dtcbase].setName(dtcbase); - } - } - - ifstream inmodules(moduleconfig.c_str()); - - int layer, ladder, module; - - while (inmodules.good()) { - inmodules >> layer >> ladder >> module >> dtc; - - // in the cabling module map, module# 300+ is flat part of barrel, 200-299 is tilted z-, 100-199 is tilted z+ - if (module > 300) { - if (layer > 0 && layer <= (int)N_PSLAYER) { - module = (module - 300) + N_TILTED_RINGS; - } else if (layer > (int)N_PSLAYER) { - module = (module - 300); - } - } - if (module > 200) { - module = (module - 200); - } - if ((module > 100) && (layer > 0 && layer <= (int)N_PSLAYER)) { - module = (module - 100) + N_TILTED_RINGS + N_MOD_PLANK.at(layer - 1); - } - if (!inmodules.good()) - break; - modules_[layer][ladder][module] = dtc; - } -} - -const string& Cabling::dtc(int layer, int ladder, int module) const { - auto it1 = modules_.find(layer); - assert(it1 != modules_.end()); - auto it2 = it1->second.find(ladder); - assert(it2 != it1->second.end()); - auto it3 = it2->second.find(module); - if (it3 == it2->second.end()) { - throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << "Could not find stub " << layer << " " - << ladder << " " << module; - } - return it3->second; -} - -void Cabling::addphi(const string& dtc, double phi, int layer, int module) { - unsigned int layerdisk = layer - 1; - - if (layer > 1000) - layerdisk = module + N_DISK; - - assert(layerdisk < N_LAYER + N_DISK); - - int isec = dtc[0] - '0'; - - string dtcbase = dtc.substr(2, dtc.size() - 2); - if (dtc[0] == 'n') { - dtcbase = "neg_" + dtc.substr(6, dtc.size() - 6); - isec = dtc[4] - '0'; - } - - double phisec = reco::reduceRange(phi - isec * settings_.dphisector()); - - assert(dtcranges_.find(dtcbase) != dtcranges_.end()); - - dtcranges_[dtcbase].addphi(phisec, layerdisk); -} - -void Cabling::writephirange() const { - ofstream out("dtcphirange.txt"); - - for (auto&& it : dtcranges_) { - for (unsigned int i = 0; i < N_LAYER + N_DISK; i++) { - double min = it.second.min(i); - double max = it.second.max(i); - if (min < max) { - out << it.first << " " << i + 1 << " " << min << " " << max << endl; - } - } - } -} - -std::vector Cabling::DTCs() const { - std::vector tmp; - - for (const auto& it : dtcs_) { - tmp.push_back(it.first); - } - - return tmp; -} diff --git a/L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc b/L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc index 41b0326f7e5f0..06092b28350ed 100644 --- a/L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc @@ -11,8 +11,7 @@ using namespace std; using namespace trklet; -CandidateMatchMemory::CandidateMatchMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) {} +CandidateMatchMemory::CandidateMatchMemory(string name, Settings const& settings) : MemoryBase(name, settings) {} void CandidateMatchMemory::addMatch(std::pair tracklet, const Stub* stub) { std::pair, const Stub*> tmp(tracklet, stub); @@ -28,7 +27,8 @@ void CandidateMatchMemory::addMatch(std::pair tracklet, const St matches_.push_back(tmp); } -void CandidateMatchMemory::writeCM(bool first) { +void CandidateMatchMemory::writeCM(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirM = settings_.memPath() + "Matches/"; std::ostringstream oss; @@ -36,21 +36,7 @@ void CandidateMatchMemory::writeCM(bool first) { << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirM)) { - int fail = system((string("mkdir -p ") + dirM).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirM; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirM, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/CleanTrackMemory.cc b/L1Trigger/TrackFindingTracklet/src/CleanTrackMemory.cc index 9c90b757e7225..b5adf1859e29c 100644 --- a/L1Trigger/TrackFindingTracklet/src/CleanTrackMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/CleanTrackMemory.cc @@ -7,35 +7,21 @@ using namespace std; using namespace trklet; -CleanTrackMemory::CleanTrackMemory( - string name, Settings const& settings, unsigned int iSector, double phimin, double phimax) - : MemoryBase(name, settings, iSector) { +CleanTrackMemory::CleanTrackMemory(string name, Settings const& settings, double phimin, double phimax) + : MemoryBase(name, settings) { phimin_ = phimin; phimax_ = phimax; } -void CleanTrackMemory::writeCT(bool first) { +void CleanTrackMemory::writeCT(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirCT = settings_.memPath() + "CleanTrack/"; std::ostringstream oss; oss << dirCT << "CleanTrack_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirCT)) { - int fail = system((string("mkdir -p ") + dirCT).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirCT; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirCT, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/DTC.cc b/L1Trigger/TrackFindingTracklet/src/DTC.cc deleted file mode 100644 index 6fb97d524565e..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/DTC.cc +++ /dev/null @@ -1,52 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/DTC.h" -#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" -#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" - -#include "DataFormats/Math/interface/deltaPhi.h" - -using namespace std; -using namespace trklet; - -DTC::DTC(string name) { - name_ = name; - for (unsigned int i = 0; i < N_LAYER + N_DISK; i++) { - phimin_[i] = 10.0; - phimax_[i] = -10.0; - } -} - -void DTC::setName(string name) { name_ = name; } - -void DTC::addSec(int sector) { sectors_.push_back(sector); } - -void DTC::addphi(double phi, unsigned int layerdisk) { - assert(layerdisk < N_LAYER + N_DISK); - if (phi < phimin_[layerdisk]) - phimin_[layerdisk] = phi; - if (phi > phimax_[layerdisk]) - phimax_[layerdisk] = phi; -} - -void DTC::addLink(double phimin, double phimax) { - DTCLink link(phimin, phimax); - links_.push_back(link); -} - -int DTC::addStub(std::pair stub) { - double phi = reco::reduceRange(stub.second->phi()); - bool overlaplayer = ((stub.second->layer() + 1) % 2 == 0); - int added = 0; - for (auto& link : links_) { - if (link.inRange(phi, overlaplayer)) { - added++; - link.addStub(stub); - } - } - return added; -} - -void DTC::clean() { - for (auto& link : links_) { - link.clean(); - } -} diff --git a/L1Trigger/TrackFindingTracklet/src/DTCLink.cc b/L1Trigger/TrackFindingTracklet/src/DTCLink.cc deleted file mode 100644 index 8b5c59c671fd2..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/DTCLink.cc +++ /dev/null @@ -1,29 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/DTCLink.h" - -using namespace std; -using namespace trklet; - -DTCLink::DTCLink(double phimin, double phimax) { - if (phimin > M_PI) { - phimin -= 2 * M_PI; - phimax -= 2 * M_PI; - } - assert(phimax > phimin); - phimin_ = phimin; - phimax_ = phimax; -} - -void DTCLink::addStub(std::pair stub) { stubs_.push_back(stub); } - -bool DTCLink::inRange(double phi, bool overlaplayer) { - double phimax = phimax_; - double phimin = phimin_; - if (overlaplayer) { - double dphi = phimax - phimin; - assert(dphi > 0.0); - assert(dphi < M_PI); - phimin -= dphi / 6.0; - phimax += dphi / 6.0; - } - return (phi < phimax && phi > phimin) || (phi + 2 * M_PI < phimax && phi + 2 * M_PI > phimin); -} diff --git a/L1Trigger/TrackFindingTracklet/src/DTCLinkMemory.cc b/L1Trigger/TrackFindingTracklet/src/DTCLinkMemory.cc new file mode 100644 index 0000000000000..d80531fa86687 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/DTCLinkMemory.cc @@ -0,0 +1,71 @@ +#include "L1Trigger/TrackFindingTracklet/interface/DTCLinkMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" + +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" + +#include +#include +#include +#include + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace trklet; +using namespace std; + +DTCLinkMemory::DTCLinkMemory(string name, Settings const& settings, double, double) : MemoryBase(name, settings) {} + +void DTCLinkMemory::addStub(const L1TStub& al1stub, const Stub& stub) { + //Make new objects owned by the dtclink memory and save in list of stubs + if (stubs_.size() < settings_.maxStep("IR")) { + Stub* stubptr = new Stub(stub); + stubptr->setl1tstub(new L1TStub(al1stub)); + + stubs_.emplace_back(stubptr); + } +} + +void DTCLinkMemory::writeStubs(bool first, unsigned int iSector) { + iSector_ = iSector; + + const string dirIS = settings_.memPath() + "InputStubs/"; + openFile(first, dirIS, "Link_"); + + for (unsigned int j = 0; j < stubs_.size(); j++) { + string dtcname = stubs_[j]->l1tstub()->DTClink(); + int layerdisk = stubs_[j]->l1tstub()->layerdisk(); + + //If the string starts with 'neg' skip the first three character + int start = dtcname.substr(0, 3) == "neg" ? 3 : 0; + + //For the dtcbase name remove the leading 'neg' if in the name and the trailing '_A' or '_B' + string dtcbase = dtcname.substr(start, dtcname.size() - 2 - start); + + const vector& layers = settings_.dtcLayers(dtcbase); + + int lcode = -1; + for (unsigned int index = 0; index < layers.size(); index++) { + if (layerdisk == layers[index]) { + lcode = index; + } + } + assert(lcode != -1); + + FPGAWord ldcode(lcode, 2, true); + + string stub = stubs_[j]->str() + "|" + ldcode.str() + "|1"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + out_ << " " << stub << " " << trklet::hexFormat(stub) << endl; + } + out_.close(); +} + +void DTCLinkMemory::clean() { + for (auto& stub : stubs_) { + delete stub->l1tstub(); + delete stub; + } + stubs_.clear(); +} diff --git a/L1Trigger/TrackFindingTracklet/src/DiskProjection.cc b/L1Trigger/TrackFindingTracklet/src/DiskProjection.cc deleted file mode 100644 index 4fa054be39805..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/DiskProjection.cc +++ /dev/null @@ -1,94 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/DiskProjection.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -#include -#include - -using namespace std; -using namespace trklet; - -void DiskProjection::init(Settings const& settings, - int projdisk, - double zproj, - int iphiproj, - int irproj, - int iphider, - int irder, - double phiproj, - double rproj, - double phiprojder, - double rprojder, - double phiprojapprox, - double rprojapprox, - double phiprojderapprox, - double rprojderapprox) { - assert(abs(projdisk) >= 0); - assert(abs(projdisk) <= N_DISK); - - valid_ = true; - - zproj_ = zproj; - - projdisk_ = projdisk; - - assert(iphiproj >= 0); - - fpgaphiproj_.set(iphiproj, settings.nphibitsstub(0), true, __LINE__, __FILE__); - int iphivm = (iphiproj >> (settings.nphibitsstub(0) - 5)) & 0x7; - if ((abs(projdisk_) % 2) == 1) { - iphivm ^= 4; - } - fpgaphiprojvm_.set(iphivm, 3, true, __LINE__, __FILE__); - fpgarproj_.set(irproj, settings.nrbitsstub(6), false, __LINE__, __FILE__); - int irvm = irproj >> (13 - 7) & 0xf; - fpgarprojvm_.set(irvm, 4, true, __LINE__, __FILE__); - fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL123(), false, __LINE__, __FILE__); - fpgarprojder_.set(irder, settings.nrbitsprojderdisk(), false, __LINE__, __FILE__); - - //TODO the -3 and +3 should be evaluated and efficiency for matching hits checked. - //This code should be migrated in the ProjectionRouter - int rbin1 = 8.0 * (irproj * settings.krprojshiftdisk() - 3 - settings.rmindiskvm()) / - (settings.rmaxdisk() - settings.rmindiskvm()); - int rbin2 = 8.0 * (irproj * settings.krprojshiftdisk() + 3 - settings.rmindiskvm()) / - (settings.rmaxdisk() - settings.rmindiskvm()); - - if (irproj * settings.krprojshiftdisk() < 20.0) { - edm::LogPrint("Tracklet") << " WARNING : irproj = " << irproj << " " << irproj * settings.krprojshiftdisk() << " " - << projdisk_; - } - - if (rbin1 < 0) - rbin1 = 0; - rbin2 = clamp(rbin2, 0, 7); - - assert(rbin1 <= rbin2); - assert(rbin2 - rbin1 <= 1); - - int finer = 64 * - ((irproj * settings.krprojshiftdisk() - settings.rmindiskvm()) - - rbin1 * (settings.rmaxdisk() - settings.rmindiskvm()) / 8.0) / - (settings.rmaxdisk() - settings.rmindiskvm()); - - finer = clamp(finer, 0, 15); - - int diff = rbin1 != rbin2; - if (irder < 0) - rbin1 += 8; - - fpgarbin1projvm_.set(rbin1, 4, true, __LINE__, __FILE__); // first r bin - fpgarbin2projvm_.set(diff, 1, true, __LINE__, __FILE__); // need to check adjacent r bin - - fpgafinervm_.set(finer, 4, true, __LINE__, __FILE__); // fine r postions starting at rbin1 - - phiproj_ = phiproj; - rproj_ = rproj; - phiprojder_ = phiprojder; - rprojder_ = rprojder; - - phiprojapprox_ = phiprojapprox; - rprojapprox_ = rprojapprox; - phiprojderapprox_ = phiprojderapprox; - rprojderapprox_ = rprojderapprox; -} diff --git a/L1Trigger/TrackFindingTracklet/src/DiskResidual.cc b/L1Trigger/TrackFindingTracklet/src/DiskResidual.cc deleted file mode 100644 index 99213f18b9848..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/DiskResidual.cc +++ /dev/null @@ -1,47 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/DiskResidual.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" - -using namespace std; -using namespace trklet; - -void DiskResidual::init(Settings const& settings, - int disk, - int iphiresid, - int irresid, - int istubid, - double phiresid, - double rresid, - double phiresidapprox, - double rresidapprox, - double zstub, - double alpha, - FPGAWord ialpha, - const Stub* stubptr) { - assert(abs(disk) > 0); - assert(abs(disk) <= N_DISK); - - if (valid_ && (std::abs(iphiresid) > std::abs(fpgaphiresid_.value()))) - return; - - valid_ = true; - - disk_ = disk; - - fpgaphiresid_.set(iphiresid, settings.phiresidbits(), false, __LINE__, __FILE__); - fpgarresid_.set(irresid, settings.rresidbits(), false, __LINE__, __FILE__); - assert(istubid >= 0); - unsigned int nbitsstubid = 10; - fpgastubid_.set(istubid, nbitsstubid, true, __LINE__, __FILE__); - assert(!fpgaphiresid_.atExtreme()); - - phiresid_ = phiresid; - rresid_ = rresid; - - phiresidapprox_ = phiresidapprox; - rresidapprox_ = rresidapprox; - - zstub_ = zstub; - alpha_ = alpha; - ialpha_ = ialpha; - stubptr_ = stubptr; -} diff --git a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc index bf17095e35a09..20bf5e741e2b6 100644 --- a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc +++ b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc @@ -11,8 +11,8 @@ using namespace std; using namespace trklet; -FitTrack::FitTrack(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector), trackfit_(nullptr) {} +FitTrack::FitTrack(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global), trackfit_(nullptr) {} void FitTrack::addOutput(MemoryBase* memory, string output) { if (settings_.writetrace()) { @@ -200,15 +200,16 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: layers[nlayers++] = l; continue; } - if (tracklet->match(l)) { + if (tracklet->match(l - 1)) { + const Residual& resid = tracklet->resid(l - 1); lmatches.set(N_LAYER - l); layermask |= (1 << (N_LAYER - l)); - phiresid[nlayers] = tracklet->phiresidapprox(l); - zresid[nlayers] = tracklet->zresidapprox(l); - phiresidexact[nlayers] = tracklet->phiresid(l); - zresidexact[nlayers] = tracklet->zresid(l); - iphiresid[nlayers] = tracklet->fpgaphiresid(l).value(); - izresid[nlayers] = tracklet->fpgazresid(l).value(); + phiresid[nlayers] = resid.phiresidapprox(); + zresid[nlayers] = resid.rzresidapprox(); + phiresidexact[nlayers] = resid.phiresid(); + zresidexact[nlayers] = resid.rzresid(); + iphiresid[nlayers] = resid.fpgaphiresid().value(); + izresid[nlayers] = resid.fpgarzresid().value(); layers[nlayers++] = l; } @@ -223,13 +224,15 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: if (ndisks + nlayers >= N_FITSTUB) continue; - if (tracklet->matchdisk(d)) { - if (std::abs(tracklet->alphadisk(d)) < 1e-20) { + if (tracklet->match(N_LAYER + d - 1)) { + const Residual& resid = tracklet->resid(N_LAYER + d - 1); + double pitch = settings_.stripPitch(resid.stubptr()->l1tstub()->isPSmodule()); + if (std::abs(resid.stubptr()->l1tstub()->alpha(pitch)) < 1e-20) { dmatches.set(2 * d - 1); diskmask |= (1 << (2 * (N_DISK - d) + 1)); } else { - int ialpha = tracklet->ialphadisk(d).value(); - int nalpha = tracklet->ialphadisk(d).nbits(); + int ialpha = resid.stubptr()->alpha().value(); + int nalpha = resid.stubptr()->alpha().nbits(); nalpha = nalpha - settings_.alphaBitsTable(); ialpha = (1 << (settings_.alphaBitsTable() - 1)) + (ialpha >> nalpha); @@ -239,13 +242,13 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: diskmask |= (1 << (2 * (N_DISK - d))); mult = mult << settings_.alphaBitsTable(); } - alpha[ndisks] = tracklet->alphadisk(d); - phiresid[nlayers + ndisks] = tracklet->phiresidapproxdisk(d); - zresid[nlayers + ndisks] = tracklet->rresidapproxdisk(d); - phiresidexact[nlayers + ndisks] = tracklet->phiresiddisk(d); - zresidexact[nlayers + ndisks] = tracklet->rresiddisk(d); - iphiresid[nlayers + ndisks] = tracklet->fpgaphiresiddisk(d).value(); - izresid[nlayers + ndisks] = tracklet->fpgarresiddisk(d).value(); + alpha[ndisks] = resid.stubptr()->l1tstub()->alpha(pitch); + phiresid[nlayers + ndisks] = resid.phiresidapprox(); + zresid[nlayers + ndisks] = resid.rzresidapprox(); + phiresidexact[nlayers + ndisks] = resid.phiresid(); + zresidexact[nlayers + ndisks] = resid.rzresid(); + iphiresid[nlayers + ndisks] = resid.fpgaphiresid().value(); + izresid[nlayers + ndisks] = resid.fpgarzresid().value(); disks[ndisks++] = d; } @@ -261,17 +264,17 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: if (tracklet->isDisk()) { for (unsigned int l = 1; l <= 2; l++) { - if (tracklet->match(l)) { + if (tracklet->match(l - 1)) { lmatches.set(N_LAYER - l); layermask |= (1 << (N_LAYER - l)); - - phiresid[nlayers] = tracklet->phiresidapprox(l); - zresid[nlayers] = tracklet->zresidapprox(l); - phiresidexact[nlayers] = tracklet->phiresid(l); - zresidexact[nlayers] = tracklet->zresid(l); - iphiresid[nlayers] = tracklet->fpgaphiresid(l).value(); - izresid[nlayers] = tracklet->fpgazresid(l).value(); + const Residual& resid = tracklet->resid(l - 1); + phiresid[nlayers] = resid.phiresidapprox(); + zresid[nlayers] = resid.rzresidapprox(); + phiresidexact[nlayers] = resid.phiresid(); + zresidexact[nlayers] = resid.rzresid(); + iphiresid[nlayers] = resid.fpgaphiresid().value(); + izresid[nlayers] = resid.fpgarzresid().value(); layers[nlayers++] = l; } @@ -296,13 +299,15 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: if (ndisks + nlayers >= N_FITSTUB) continue; - if (tracklet->matchdisk(d)) { - if (std::abs(tracklet->alphadisk(d)) < 1e-20) { + if (tracklet->match(N_LAYER + abs(d) - 1)) { + const Residual& resid = tracklet->resid(N_LAYER + abs(d) - 1); + double pitch = settings_.stripPitch(resid.stubptr()->l1tstub()->isPSmodule()); + if (std::abs(resid.stubptr()->l1tstub()->alpha(pitch)) < 1e-20) { dmatches.set(2 * d1 - 1); diskmask |= (1 << (2 * (N_DISK - d1) + 1)); } else { - int ialpha = tracklet->ialphadisk(d).value(); - int nalpha = tracklet->ialphadisk(d).nbits(); + int ialpha = resid.stubptr()->alpha().value(); + int nalpha = resid.stubptr()->alpha().nbits(); nalpha = nalpha - settings_.alphaBitsTable(); ialpha = (1 << (settings_.alphaBitsTable() - 1)) + (ialpha >> nalpha); @@ -313,15 +318,15 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: mult = mult << settings_.alphaBitsTable(); } - alpha[ndisks] = tracklet->alphadisk(d); - assert(std::abs(tracklet->phiresidapproxdisk(d)) < 0.2); - phiresid[nlayers + ndisks] = tracklet->phiresidapproxdisk(d); - zresid[nlayers + ndisks] = tracklet->rresidapproxdisk(d); - assert(std::abs(tracklet->phiresiddisk(d)) < 0.2); - phiresidexact[nlayers + ndisks] = tracklet->phiresiddisk(d); - zresidexact[nlayers + ndisks] = tracklet->rresiddisk(d); - iphiresid[nlayers + ndisks] = tracklet->fpgaphiresiddisk(d).value(); - izresid[nlayers + ndisks] = tracklet->fpgarresiddisk(d).value(); + alpha[ndisks] = resid.stubptr()->l1tstub()->alpha(pitch); + assert(std::abs(resid.phiresidapprox()) < 0.2); + phiresid[nlayers + ndisks] = resid.phiresidapprox(); + zresid[nlayers + ndisks] = resid.rzresidapprox(); + assert(std::abs(resid.phiresid()) < 0.2); + phiresidexact[nlayers + ndisks] = resid.phiresid(); + zresidexact[nlayers + ndisks] = resid.rzresid(); + iphiresid[nlayers + ndisks] = resid.fpgaphiresid().value(); + izresid[nlayers + ndisks] = resid.fpgarzresid().value(); disks[ndisks++] = d; } @@ -336,17 +341,18 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: layers[nlayers++] = l; continue; } - if (tracklet->match(l)) { + if (tracklet->match(l - 1)) { lmatches.set(N_LAYER - l); layermask |= (1 << (N_LAYER - l)); - assert(std::abs(tracklet->phiresidapprox(l)) < 0.2); - phiresid[nlayers] = tracklet->phiresidapprox(l); - zresid[nlayers] = tracklet->zresidapprox(l); - assert(std::abs(tracklet->phiresid(l)) < 0.2); - phiresidexact[nlayers] = tracklet->phiresid(l); - zresidexact[nlayers] = tracklet->zresid(l); - iphiresid[nlayers] = tracklet->fpgaphiresid(l).value(); - izresid[nlayers] = tracklet->fpgazresid(l).value(); + const Residual& resid = tracklet->resid(l - 1); + assert(std::abs(resid.phiresidapprox()) < 0.2); + phiresid[nlayers] = resid.phiresidapprox(); + zresid[nlayers] = resid.rzresidapprox(); + assert(std::abs(resid.phiresid()) < 0.2); + phiresidexact[nlayers] = resid.phiresid(); + zresidexact[nlayers] = resid.rzresid(); + iphiresid[nlayers] = resid.fpgaphiresid().value(); + izresid[nlayers] = resid.fpgarzresid().value(); layers[nlayers++] = l; } @@ -368,15 +374,17 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: if (ndisks + nlayers >= N_FITSTUB) continue; - if (tracklet->matchdisk(d)) { - if (std::abs(tracklet->alphadisk(d)) < 1e-20) { + if (tracklet->match(N_LAYER + abs(d) - 1)) { + const Residual& resid = tracklet->resid(N_LAYER + abs(d) - 1); + double pitch = settings_.stripPitch(resid.stubptr()->l1tstub()->isPSmodule()); + if (std::abs(resid.stubptr()->l1tstub()->alpha(pitch)) < 1e-20) { dmatches.set(2 * (N_DISK - d1)); diskmask |= (1 << (2 * (N_DISK - d1) + 1)); FPGAWord tmp; tmp.set(diskmask, 10); } else { - int ialpha = tracklet->ialphadisk(d).value(); - int nalpha = tracklet->ialphadisk(d).nbits(); + int ialpha = resid.stubptr()->alpha().value(); + int nalpha = resid.stubptr()->alpha().nbits(); nalpha = nalpha - settings_.alphaBitsTable(); ialpha = (1 << (settings_.alphaBitsTable() - 1)) + (ialpha >> nalpha); @@ -389,15 +397,15 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: mult = mult << settings_.alphaBitsTable(); } - alpha[ndisks] = tracklet->alphadisk(d); - assert(std::abs(tracklet->phiresidapproxdisk(d)) < 0.2); - phiresid[nlayers + ndisks] = tracklet->phiresidapproxdisk(d); - zresid[nlayers + ndisks] = tracklet->rresidapproxdisk(d); - assert(std::abs(tracklet->phiresiddisk(d)) < 0.2); - phiresidexact[nlayers + ndisks] = tracklet->phiresiddisk(d); - zresidexact[nlayers + ndisks] = tracklet->rresiddisk(d); - iphiresid[nlayers + ndisks] = tracklet->fpgaphiresiddisk(d).value(); - izresid[nlayers + ndisks] = tracklet->fpgarresiddisk(d).value(); + alpha[ndisks] = resid.stubptr()->l1tstub()->alpha(pitch); + assert(std::abs(resid.phiresidapprox()) < 0.2); + phiresid[nlayers + ndisks] = resid.phiresidapprox(); + zresid[nlayers + ndisks] = resid.rzresidapprox(); + assert(std::abs(resid.phiresid()) < 0.2); + phiresidexact[nlayers + ndisks] = resid.phiresid(); + zresidexact[nlayers + ndisks] = resid.rzresid(); + iphiresid[nlayers + ndisks] = resid.fpgaphiresid().value(); + izresid[nlayers + ndisks] = resid.fpgarzresid().value(); disks[ndisks++] = d; } @@ -448,16 +456,16 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: r[i] = settings_.rmean(layers[i] - 1); if (layers[i] == tracklet->layer()) { if (tracklet->isOverlap()) { - realrstub[i] = tracklet->outerStub()->r(); + realrstub[i] = tracklet->outerFPGAStub()->l1tstub()->r(); } else { - realrstub[i] = tracklet->innerStub()->r(); + realrstub[i] = tracklet->innerFPGAStub()->l1tstub()->r(); } } if (layers[i] == tracklet->layer() + 1) { - realrstub[i] = tracklet->outerStub()->r(); + realrstub[i] = tracklet->outerFPGAStub()->l1tstub()->r(); } - if (tracklet->validResid(layers[i]) && layers[i] < 4) { - const Stub* stubptr = tracklet->stubptr(layers[i]); + if (tracklet->match(layers[i] - 1) && layers[i] < 4) { + const Stub* stubptr = tracklet->resid(layers[i] - 1).stubptr(); realrstub[i] = stubptr->l1tstub()->r(); assert(std::abs(realrstub[i] - r[i]) < 5.0); } @@ -859,19 +867,21 @@ std::vector FitTrack::orderedMatches(vector& fullma return tmp; } -void FitTrack::execute() { +void FitTrack::execute(unsigned int iSector) { // merge const std::vector& matches1 = orderedMatches(fullmatch1_); const std::vector& matches2 = orderedMatches(fullmatch2_); const std::vector& matches3 = orderedMatches(fullmatch3_); const std::vector& matches4 = orderedMatches(fullmatch4_); + iSector_ = iSector; + if (settings_.debugTracklet() && (matches1.size() + matches2.size() + matches3.size() + matches4.size()) > 0) { for (auto& imatch : fullmatch1_) { edm::LogVerbatim("Tracklet") << imatch->getName() << " " << imatch->nMatches(); } - edm::LogVerbatim("Tracklet") << getName() << "[" << iSector_ << "] matches : " << matches1.size() << " " - << matches2.size() << " " << matches3.size() << " " << matches4.size(); + edm::LogVerbatim("Tracklet") << getName() << " matches : " << matches1.size() << " " << matches2.size() << " " + << matches3.size() << " " << matches4.size(); } unsigned int indexArray[4]; @@ -1002,8 +1012,8 @@ void FitTrack::execute() { assert(trackfit_ != nullptr); if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << bestTracklet->getISeed() - << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" + << " " << bestTracklet->getISeed() << endl; fout.close(); } bestTracklet->setTrackIndex(trackfit_->nTracks()); diff --git a/L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc b/L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc index 1f43b6a1f0439..f4bf27d54e5e1 100644 --- a/L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc @@ -9,8 +9,7 @@ using namespace std; using namespace trklet; -FullMatchMemory::FullMatchMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) { +FullMatchMemory::FullMatchMemory(string name, Settings const& settings) : MemoryBase(name, settings) { size_t pos = find_nth(name, 0, "_", 1); assert(pos != string::npos); initLayerDisk(pos + 1, layer_, disk_); @@ -39,28 +38,15 @@ void FullMatchMemory::addMatch(Tracklet* tracklet, const Stub* stub) { matches_.push_back(tmp); } -void FullMatchMemory::writeMC(bool first) { +void FullMatchMemory::writeMC(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirM = settings_.memPath() + "Matches/"; std::ostringstream oss; oss << dirM << "FullMatches_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirM)) { - int fail = system((string("mkdir -p ") + dirM).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirM; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirM, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/HybridFit.cc b/L1Trigger/TrackFindingTracklet/src/HybridFit.cc index 9d129fa24db53..82b6233e31c14 100644 --- a/L1Trigger/TrackFindingTracklet/src/HybridFit.cc +++ b/L1Trigger/TrackFindingTracklet/src/HybridFit.cc @@ -75,7 +75,7 @@ void HybridFit::Fit(Tracklet* tracklet, std::vector& trackstublist) double alpha = L1stubptr->alpha(settings_.stripPitch(psmodule)); bool isTilted = L1stubptr->isTilted(); - bool isBarrel = trackstublist[k]->isBarrel(); + bool isBarrel = trackstublist[k]->layerdisk() < N_LAYER; int kflayer; if (isBarrel) { // Barrel-specific diff --git a/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc b/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc index ddfd115a53fcf..92affaed962c9 100644 --- a/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc @@ -1,7 +1,7 @@ #include "L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" #include "L1Trigger/TrackFindingTracklet/interface/Stub.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h" + #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" #include @@ -14,78 +14,12 @@ using namespace trklet; using namespace std; -InputLinkMemory::InputLinkMemory(string name, Settings const& settings, unsigned int iSector, double, double) - : MemoryBase(name, settings, iSector) { - string subname = name.substr(5, 7); - phiregion_ = subname[3] - 'A'; - assert(phiregion_ >= 0 && phiregion_ < 8); - - layerdisk_ = initLayerDisk(3); -} - -bool InputLinkMemory::addStub( - Settings const& settings, Globals* globals, L1TStub& al1stub, Stub& stub, string dtc = "") { - if (layerdisk_ < N_LAYER && globals->phiCorr(layerdisk_) == nullptr) { - globals->phiCorr(layerdisk_) = new VMRouterPhiCorrTable(settings); - int nbits = 3; - if (layerdisk_ >= N_PSLAYER) - nbits = 4; - globals->phiCorr(layerdisk_)->init(layerdisk_ + 1, nbits, 3); - } - - unsigned int stublayerdisk = stub.layerdisk(); - assert(stublayerdisk < 11); - - if (stublayerdisk != layerdisk_) - return false; - - if (layerdisk_ < N_LAYER) { - FPGAWord r = stub.r(); - int bendbin = stub.bend().value(); - int rbin = (r.value() + (1 << (r.nbits() - 1))) >> (r.nbits() - 3); - const VMRouterPhiCorrTable& phiCorrTable = *globals->phiCorr(layerdisk_); - int iphicorr = phiCorrTable.getphiCorrValue(bendbin, rbin); - stub.setPhiCorr(iphicorr); - } - - FPGAWord iphi = stub.phicorr(); - unsigned int nallbits = settings_.nbitsallstubs(layerdisk_); - int phibin = iphi.bits(iphi.nbits() - nallbits, nallbits); - int iphivmRaw = iphi.bits(iphi.nbits() - 5, 5); - - if (phibin != phiregion_) - return false; +InputLinkMemory::InputLinkMemory(string name, Settings const& settings, double, double) : MemoryBase(name, settings) {} - if (getName().substr(10, dtc.size()) != dtc) - return false; +void InputLinkMemory::addStub(Stub* stub) { stubs_.push_back(stub); } - string half = getName().substr(getName().size() - 3, 3); - if (half[1] != 'n') { - half = getName().substr(getName().size() - 1, 1); - } - - assert(half[0] == 'A' || half[0] == 'B'); - - if (half[0] == 'B' && iphivmRaw <= 15) - return false; - if (half[0] == 'A' && iphivmRaw > 15) - return false; - - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Will add stub in " << getName() << " " - << "iphiwmRaw = " << iphivmRaw << " phi=" << al1stub.phi() << " z=" << al1stub.z() - << " r=" << al1stub.r(); - } - if (stubs_.size() < settings_.maxStep("Link")) { - Stub* stubptr = new Stub(stub); - stubptr->setl1tstub(new L1TStub(al1stub)); - - stubs_.emplace_back(stubptr); - } - return true; -} - -void InputLinkMemory::writeStubs(bool first) { +void InputLinkMemory::writeStubs(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirIS = settings_.memPath() + "InputStubs/"; openFile(first, dirIS, "InputStubs_"); @@ -98,10 +32,4 @@ void InputLinkMemory::writeStubs(bool first) { out_.close(); } -void InputLinkMemory::clean() { - for (auto& stub : stubs_) { - delete stub->l1tstub(); - delete stub; - } - stubs_.clear(); -} +void InputLinkMemory::clean() { stubs_.clear(); } diff --git a/L1Trigger/TrackFindingTracklet/src/InputRouter.cc b/L1Trigger/TrackFindingTracklet/src/InputRouter.cc new file mode 100644 index 0000000000000..2ee8e965a90c1 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/InputRouter.cc @@ -0,0 +1,79 @@ +#include "L1Trigger/TrackFindingTracklet/interface/InputRouter.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/DTCLinkMemory.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +using namespace std; +using namespace trklet; + +InputRouter::InputRouter(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) {} + +void InputRouter::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + + if (output == "stubout") { + InputLinkMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + unsigned int layerdisk = tmp->getName()[4] - '1'; + if (tmp->getName()[3] == 'D') { + layerdisk += N_LAYER; + } + assert(layerdisk < N_LAYER + N_DISK); + unsigned int phireg = tmp->getName()[8] - 'A'; + std::pair layerphireg(layerdisk, phireg); + irstubs_.emplace_back(layerphireg, tmp); + return; + } + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; +} + +void InputRouter::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + if (input == "stubin") { + dtcstubs_ = dynamic_cast(memory); + assert(dtcstubs_ != nullptr); + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; +} + +void InputRouter::execute() { + for (unsigned int i = 0; i < settings_.maxStep("IR"); i++) { + if (i >= dtcstubs_->nStubs()) { + break; + } + + Stub* stub = dtcstubs_->getStub(i); + + unsigned int layerdisk = stub->l1tstub()->layerdisk(); + + FPGAWord iphi = stub->phicorr(); + unsigned int iphipos = iphi.value() >> (iphi.nbits() - settings_.nbitsallstubs(layerdisk)); + + std::pair layerphireg(layerdisk, iphipos); + + //Fill inner allstubs memories - in HLS this is the same write to multiple memories + int iadd = 0; + for (auto& irstubmem : irstubs_) { + if (layerphireg == irstubmem.first) { + irstubmem.second->addStub(stub); + iadd++; + } + } + assert(iadd == 1); + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/L1SimTrack.cc b/L1Trigger/TrackFindingTracklet/src/L1SimTrack.cc new file mode 100644 index 0000000000000..e0744ff66763c --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/L1SimTrack.cc @@ -0,0 +1,37 @@ +#include "L1Trigger/TrackFindingTracklet/interface/L1SimTrack.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace std; +using namespace trklet; + +L1SimTrack::L1SimTrack() { + eventid_ = -1; + trackid_ = -1; +} + +L1SimTrack::L1SimTrack( + int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz) { + eventid_ = eventid; + trackid_ = trackid; + type_ = type; + pt_ = pt; + eta_ = eta; + phi_ = phi; + vx_ = vx; + vy_ = vy; + vz_ = vz; +} + +void L1SimTrack::write(ofstream& out) { + if (pt_ > -2.0) { + out << "SimTrack: " << eventid_ << "\t" << trackid_ << "\t" << type_ << "\t" << pt_ << "\t" << eta_ << "\t" << phi_ + << "\t" << vx_ << "\t" << vy_ << "\t" << vz_ << "\t" << endl; + } +} + +void L1SimTrack::write(ostream& out) { + if (pt_ > -2) { + out << "SimTrack: " << eventid_ << "\t" << trackid_ << "\t" << type_ << "\t" << pt_ << "\t" << eta_ << "\t" << phi_ + << "\t" << vx_ << "\t" << vy_ << "\t" << vz_ << "\t" << endl; + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/L1TStub.cc b/L1Trigger/TrackFindingTracklet/src/L1TStub.cc index 1ae8497e75396..d7cc37d26b863 100644 --- a/L1Trigger/TrackFindingTracklet/src/L1TStub.cc +++ b/L1Trigger/TrackFindingTracklet/src/L1TStub.cc @@ -1,42 +1,46 @@ #include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" using namespace std; using namespace trklet; L1TStub::L1TStub() {} -L1TStub::L1TStub(int eventid, - vector tps, - int iphi, - int iz, - int layer, - int ladder, - int module, - int strip, +L1TStub::L1TStub(std::string DTClink, + int region, + int layerdisk, + std::string stubword, + int isPSmodule, + int isFlipped, double x, double y, double z, - double sigmax, - double sigmaz, - double pt, double bend, - int isPSmodule, - int isFlipped) { - eventid_ = eventid; + double strip, + std::vector tps) { + DTClink_ = DTClink; + layerdisk_ = layerdisk; + region_ = region; + stubword_ = stubword; + eventid_ = -1; tps_ = tps; - iphi_ = iphi; - iz_ = iz; - layer_ = layer; - ladder_ = ladder; - module_ = module; + iphi_ = -1; + iz_ = -1; + layer_ = layerdisk; + if (layerdisk >= N_LAYER) { + layer_ = 1000 + layerdisk - N_LAYER + 1; + if (z < 0.0) + layer_ += 1000; + } + + ladder_ = -1; + module_ = -1; strip_ = strip; x_ = x; y_ = y; z_ = z; - sigmax_ = sigmax; - sigmaz_ = sigmaz; - pt_ = pt; + sigmax_ = -1.0; + sigmaz_ = -1.0; + pt_ = -1.0; bend_ = bend; isPSmodule_ = isPSmodule; isFlipped_ = isFlipped; @@ -45,18 +49,8 @@ L1TStub::L1TStub(int eventid, } void L1TStub::write(ofstream& out) { - out << "Stub: " << layer_ + 1 << "\t" << ladder_ << "\t" << module_ << "\t" << strip_ << "\t" << eventid_ << "\t" - << pt_ << "\t" << x_ << "\t" << y_ << "\t" << z_ << "\t" << bend_ << "\t" << isPSmodule_ << "\t" << isFlipped_ - << "\t" << tps_.size() << " \t"; - for (int itp : tps_) { - out << itp << " \t"; - } - out << endl; -} - -void L1TStub::write(ostream& out) { - out << "Stub: " << layer_ + 1 << "\t" << ladder_ << "\t" << module_ << "\t" << strip_ << "\t" << eventid_ << "\t" - << pt_ << "\t" << x_ << "\t" << y_ << "\t" << z_ << "\t" << bend_ << "\t" << isPSmodule_ << "\t" << isFlipped_ + out << "Stub: " << DTClink_ << "\t" << region_ << "\t" << layerdisk_ << "\t" << stubword_ << "\t" << isPSmodule_ + << "\t" << isFlipped_ << "\t" << x_ << "\t" << y_ << "\t" << z_ << "\t" << bend_ << "\t" << strip_ << "\t" << "\t" << tps_.size() << " \t"; for (int itp : tps_) { out << itp << " \t"; @@ -107,13 +101,28 @@ void L1TStub::setXY(double x, double y) { bool L1TStub::tpmatch(int tp) const { for (int itp : tps_) { - if (tp == itp) + if (tp == std::abs(itp)) return true; } return false; } +bool L1TStub::tpmatch2(int tp) const { + bool match1 = false; + bool match2 = false; + for (int itp : tps_) { + if (tp == itp) { + match1 = true; + } + if (tp == -itp) { + match2 = true; + } + } + + return match1 && match2; +} + bool L1TStub::isTilted() const { //here layer_ runs 0-5 for barrel, >1000 for disk //disk modules and outer barrel modules are not tilted by construction diff --git a/L1Trigger/TrackFindingTracklet/src/LayerProjection.cc b/L1Trigger/TrackFindingTracklet/src/LayerProjection.cc deleted file mode 100644 index 83cb116eacb6a..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/LayerProjection.cc +++ /dev/null @@ -1,103 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/LayerProjection.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -using namespace std; -using namespace trklet; - -void LayerProjection::init(Settings const& settings, - int projlayer, - double rproj, - int iphiproj, - int izproj, - int iphider, - int izder, - double phiproj, - double zproj, - double phiprojder, - double zprojder, - double phiprojapprox, - double zprojapprox, - double phiprojderapprox, - double zprojderapprox, - bool isPSseed) { - assert(projlayer > 0); - assert(projlayer <= N_LAYER); - - valid_ = true; - - rproj_ = rproj; - - projlayer_ = projlayer; - - assert(iphiproj >= 0); - - if (rproj < settings.rPS2S()) { - fpgaphiproj_.set(iphiproj, settings.nphibitsstub(0), true, __LINE__, __FILE__); - int iphivm = (iphiproj >> (settings.nphibitsstub(0) - 5)) & 0x7; - if ((projlayer_ % 2) == 1) { - iphivm ^= 4; - } - fpgaphiprojvm_.set(iphivm, 3, true, __LINE__, __FILE__); - fpgazproj_.set(izproj, settings.nzbitsstub(0), false, __LINE__, __FILE__); - int izvm = izproj >> (12 - 7) & 0xf; - fpgazprojvm_.set(izvm, 4, true, __LINE__, __FILE__); - fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL123(), false, __LINE__, __FILE__); - fpgazprojder_.set(izder, settings.nbitszprojderL123(), false, __LINE__, __FILE__); - } else { - fpgaphiproj_.set(iphiproj, settings.nphibitsstub(5), true, __LINE__, __FILE__); - int iphivm = (iphiproj >> (settings.nphibitsstub(5) - 5)) & 0x7; - if ((projlayer_ % 2) == 1) { - iphivm ^= 4; - } - fpgaphiprojvm_.set(iphivm, 3, true, __LINE__, __FILE__); - fpgazproj_.set(izproj, settings.nzbitsstub(5), false, __LINE__, __FILE__); - int izvm = izproj >> (8 - 7) & 0xf; - fpgazprojvm_.set(izvm, 4, true, __LINE__, __FILE__); - fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL456(), false, __LINE__, __FILE__); - fpgazprojder_.set(izder, settings.nbitszprojderL456(), false, __LINE__, __FILE__); - } - - ////Separate the vm projections into zbins - ////This determines the central bin: - ////int zbin=4+(zproj.value()>>(zproj.nbits()-3)); - ////But we need some range (particularly for L5L6 seed projecting to L1-L3): - int offset = 4; - if (isPSseed) { - offset = 1; - } - unsigned int zbin1 = (1 << (settings.MEBinsBits() - 1)) + - (((fpgazproj_.value() >> (fpgazproj_.nbits() - settings.MEBinsBits() - 3)) - offset) >> 3); - unsigned int zbin2 = (1 << (settings.MEBinsBits() - 1)) + - (((fpgazproj_.value() >> (fpgazproj_.nbits() - settings.MEBinsBits() - 3)) + offset) >> 3); - if (zbin1 >= settings.MEBins()) { - zbin1 = 0; //note that zbin1 is unsigned - } - if (zbin2 >= settings.MEBins()) - zbin2 = settings.MEBins() - 1; - assert(zbin1 <= zbin2); - assert(zbin2 - zbin1 <= 1); - fpgazbin1projvm_.set(zbin1, settings.MEBinsBits(), true, __LINE__, __FILE__); // first z bin - if (zbin1 == zbin2) - fpgazbin2projvm_.set(0, 1, true, __LINE__, __FILE__); // don't need to check adjacent z bin - else - fpgazbin2projvm_.set(1, 1, true, __LINE__, __FILE__); // do need to check next z bin - - //fine vm z bits. Use 4 bits for fine position. starting at zbin 1 - int finez = ((1 << (settings.MEBinsBits() + 2)) + - (fpgazproj_.value() >> (fpgazproj_.nbits() - (settings.MEBinsBits() + 3)))) - - (zbin1 << 3); - - fpgafinezvm_.set(finez, 4, true, __LINE__, __FILE__); // fine z postions starting at zbin1 //FIXME using 3 bits - - phiproj_ = phiproj; - zproj_ = zproj; - phiprojder_ = phiprojder; - zprojder_ = zprojder; - - phiprojapprox_ = phiprojapprox; - zprojapprox_ = zprojapprox; - phiprojderapprox_ = phiprojderapprox; - zprojderapprox_ = zprojderapprox; -} diff --git a/L1Trigger/TrackFindingTracklet/src/LayerResidual.cc b/L1Trigger/TrackFindingTracklet/src/LayerResidual.cc deleted file mode 100644 index b9483e5135881..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/LayerResidual.cc +++ /dev/null @@ -1,42 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/LayerResidual.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" - -using namespace std; -using namespace trklet; - -void LayerResidual::init(Settings const& settings, - int layer, - int iphiresid, - int izresid, - int istubid, - double phiresid, - double zresid, - double phiresidapprox, - double zresidapprox, - double rstub, - const Stub* stubptr) { - assert(layer > 0); - assert(layer <= N_LAYER); - - if (valid_ && (std::abs(iphiresid) > std::abs(fpgaphiresid_.value()))) - return; - - valid_ = true; - - layer_ = layer; - - fpgaphiresid_.set(iphiresid, settings.phiresidbits(), false, __LINE__, __FILE__); - fpgazresid_.set(izresid, settings.zresidbits(), false, __LINE__, __FILE__); - int nbitsid = 10; - fpgastubid_.set(istubid, nbitsid, true, __LINE__, __FILE__); - assert(!fpgaphiresid_.atExtreme()); - - phiresid_ = phiresid; - zresid_ = zresid; - - phiresidapprox_ = phiresidapprox; - zresidapprox_ = zresidapprox; - - rstub_ = rstub; - stubptr_ = stubptr; -} diff --git a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc index be1fdd992fea2..86549eac723bf 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc @@ -18,10 +18,8 @@ using namespace std; using namespace trklet; -MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector) { - phioffset_ = phimin_; - +MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) { phiregion_ = name[8] - 'A'; layerdisk_ = initLayerDisk(3); @@ -58,18 +56,8 @@ MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* } } - if (iSector_ == 0 && layerdisk_ < N_LAYER && settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } - - const string filephicut = settings_.tablePath() + getName() + "_phicut.tab"; - ofstream outphicut(filephicut); - if (outphicut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << filephicut; + if (layerdisk_ < N_LAYER && settings_.writeTable()) { + ofstream outphicut = openfile(settings_.tablePath(), getName() + "_phicut.tab", __FILE__, __LINE__); outphicut << "{" << endl; for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { @@ -95,18 +83,9 @@ MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* outzcut.close(); } - if (iSector_ == 0 && layerdisk_ >= N_LAYER && settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } + if (layerdisk_ >= N_LAYER && settings_.writeTable()) { + ofstream outPSphicut = openfile(settings_.tablePath(), getName() + "_PSphicut.tab", __FILE__, __LINE__); - const string filePSphicut = settings_.tablePath() + getName() + "_PSphicut.tab"; - ofstream outPSphicut(filePSphicut); - if (outPSphicut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << filePSphicut; outPSphicut << "{" << endl; for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { if (seedindex != 0) @@ -116,10 +95,8 @@ MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* outPSphicut << endl << "};" << endl; outPSphicut.close(); - const string file2Sphicut = settings_.tablePath() + getName() + "_2Sphicut.tab"; - ofstream out2Sphicut(file2Sphicut); - if (out2Sphicut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << file2Sphicut; + ofstream out2Sphicut = openfile(settings_.tablePath(), getName() + "_2Sphicut.tab", __FILE__, __LINE__); + out2Sphicut << "{" << endl; for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { if (seedindex != 0) @@ -207,7 +184,7 @@ void MatchCalculator::addInput(MemoryBase* memory, string input) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input " << input; } -void MatchCalculator::execute() { +void MatchCalculator::execute(double phioffset) { unsigned int countall = 0; unsigned int countsel = 0; @@ -236,13 +213,15 @@ void MatchCalculator::execute() { if (layerdisk_ < N_LAYER) { //Integer calculation + const Projection& proj = tracklet->proj(layerdisk_); + int ir = fpgastub->r().value(); - int iphi = tracklet->fpgaphiproj(layerdisk_ + 1).value(); - int icorr = (ir * tracklet->fpgaphiprojder(layerdisk_ + 1).value()) >> icorrshift_; + int iphi = proj.fpgaphiproj().value(); + int icorr = (ir * proj.fpgaphiprojder().value()) >> icorrshift_; iphi += icorr; - int iz = tracklet->fpgazproj(layerdisk_ + 1).value(); - int izcor = (ir * tracklet->fpgazprojder(layerdisk_ + 1).value() + (1 << (icorzshift_ - 1))) >> icorzshift_; + int iz = proj.fpgarzproj().value(); + int izcor = (ir * proj.fpgarzprojder().value() + (1 << (icorzshift_ - 1))) >> icorzshift_; iz += izcor; int ideltaz = fpgastub->z().value() - iz; @@ -250,7 +229,7 @@ void MatchCalculator::execute() { //Floating point calculations - double phi = stub->phi() - phioffset_; + double phi = stub->phi() - phioffset; double r = stub->r(); double z = stub->z(); @@ -265,18 +244,16 @@ void MatchCalculator::execute() { if (phi < 0) phi += 2 * M_PI; - double dr = r - tracklet->rproj(layerdisk_ + 1); + double dr = r - settings_.rmean(layerdisk_); assert(std::abs(dr) < settings_.drmax()); - double dphi = - reco::reduceRange(phi - (tracklet->phiproj(layerdisk_ + 1) + dr * tracklet->phiprojder(layerdisk_ + 1))); + double dphi = reco::reduceRange(phi - (proj.phiproj() + dr * proj.phiprojder())); - double dz = z - (tracklet->zproj(layerdisk_ + 1) + dr * tracklet->zprojder(layerdisk_ + 1)); + double dz = z - (proj.rzproj() + dr * proj.rzprojder()); - double dphiapprox = reco::reduceRange( - phi - (tracklet->phiprojapprox(layerdisk_ + 1) + dr * tracklet->phiprojderapprox(layerdisk_ + 1))); + double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dr * proj.phiprojderapprox())); - double dzapprox = z - (tracklet->zprojapprox(layerdisk_ + 1) + dr * tracklet->zprojderapprox(layerdisk_ + 1)); + double dzapprox = z - (proj.rzprojapprox() + dr * proj.rzprojderapprox()); int seedindex = tracklet->getISeed(); @@ -296,9 +273,21 @@ void MatchCalculator::execute() { truthmatch); } - if (std::abs(dphi) > 0.2 || std::abs(dphiapprox) > 0.2) { - edm::LogProblem("Tracklet") << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox - << endl; + //This would catch significant consistency problems in the configuration - helps to debug if there are problems. + if (std::abs(dphi) > 0.5 * settings_.dphisectorHG() || std::abs(dphiapprox) > 0.5 * settings_.dphisectorHG()) { + throw cms::Exception("LogicError") + << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox << endl; + } + + if (settings_.writeMonitorData("Residuals")) { + double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv()); + + globals_->ofstream("layerresiduals.txt") + << layerdisk_ + 1 << " " << seedindex << " " << pt << " " + << ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_) << " " + << dphiapprox * settings_.rmean(layerdisk_) << " " + << phimatchcut_[seedindex] * settings_.kphi1() * settings_.rmean(layerdisk_) << " " + << ideltaz * fact_ * settings_.kz() << " " << dz << " " << zmatchcut_[seedindex] * settings_.kz() << endl; } bool imatch = false; @@ -326,7 +315,7 @@ void MatchCalculator::execute() { if (imatch) { countsel++; - tracklet->addMatch(layerdisk_ + 1, + tracklet->addMatch(layerdisk_, ideltaphi, ideltaz, dphi, @@ -334,12 +323,10 @@ void MatchCalculator::execute() { dphiapprox, dzapprox, (phiregion_ << 7) + fpgastub->stubindex().value(), - stub->r(), mergedMatches[j].second); if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Accepted full match in layer " << getName() << " " << tracklet << " " - << iSector_; + edm::LogVerbatim("Tracklet") << "Accepted full match in layer " << getName() << " " << tracklet; } fullMatches_[seedindex]->addMatch(tracklet, mergedMatches[j].second); @@ -355,20 +342,22 @@ void MatchCalculator::execute() { //Perform integer calculations here + const Projection& proj = tracklet->proj(layerdisk_); + int iz = fpgastub->z().value(); - int iphi = tracklet->fpgaphiprojdisk(disk).value(); + int iphi = proj.fpgaphiproj().value(); //TODO - need to express interms of constants int shifttmp = 6; - int iphicorr = (iz * tracklet->fpgaphiprojderdisk(disk).value()) >> shifttmp; + int iphicorr = (iz * proj.fpgaphiprojder().value()) >> shifttmp; iphi += iphicorr; - int ir = tracklet->fpgarprojdisk(disk).value(); + int ir = proj.fpgarzproj().value(); //TODO - need to express interms of constants int shifttmp2 = 7; - int ircorr = (iz * tracklet->fpgarprojderdisk(disk).value()) >> shifttmp2; + int ircorr = (iz * proj.fpgarzprojder().value()) >> shifttmp2; ir += ircorr; @@ -391,14 +380,14 @@ void MatchCalculator::execute() { int ideltar = (irstub >> 1) - ir; if (!stub->isPSmodule()) { - int ialphanew = fpgastub->alphanew().value(); - int iphialphacor = ((ideltar * ialphanew * ialphafact) >> settings_.alphashift()); + int ialpha = fpgastub->alpha().value(); + int iphialphacor = ((ideltar * ialpha * ialphafact) >> settings_.alphashift()); ideltaphi += iphialphacor; } //Perform floating point calculations here - double phi = stub->phi() - phioffset_; + double phi = stub->phi() - phioffset; double z = stub->z(); double r = stub->r(); @@ -416,14 +405,13 @@ void MatchCalculator::execute() { double dz = z - sign * settings_.zmean(layerdisk_ - N_LAYER); if (std::abs(dz) > settings_.dzmax()) { - throw cms::Exception("LogicError") - << __FILE__ << " " << __LINE__ << " " << name_ << "_" << iSector_ << " " << tracklet->getISeed() - << "\n stub " << stub->z() << " disk " << disk << " " << dz; + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " " << name_ << " " << tracklet->getISeed() + << "\n stub " << stub->z() << " disk " << disk << " " << dz; } - double phiproj = tracklet->phiprojdisk(disk) + dz * tracklet->phiprojderdisk(disk); + double phiproj = proj.phiproj() + dz * proj.phiprojder(); - double rproj = tracklet->rprojdisk(disk) + dz * tracklet->rprojderdisk(disk); + double rproj = proj.rzproj() + dz * proj.rzprojder(); double deltar = r - rproj; @@ -431,10 +419,9 @@ void MatchCalculator::execute() { double dphi = reco::reduceRange(phi - phiproj); - double dphiapprox = - reco::reduceRange(phi - (tracklet->phiprojapproxdisk(disk) + dz * tracklet->phiprojderapproxdisk(disk))); + double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dz * proj.phiprojderapprox())); - double drapprox = stub->r() - (tracklet->rprojapproxdisk(disk) + dz * tracklet->rprojderapproxdisk(disk)); + double drapprox = stub->r() - (proj.rzprojapprox() + dz * proj.rzprojderapprox()); double drphi = dphi * stub->r(); double drphiapprox = dphiapprox * stub->r(); @@ -461,7 +448,7 @@ void MatchCalculator::execute() { double drcut = idrcut * settings_.krprojshiftdisk(); bool match, imatch; - if (std::abs(dphi) < 0.25 && std::abs(dphiapprox) < 0.25) { //Changed the Asserts into if statements + if (std::abs(dphi) < third*settings_.dphisectorHG() && std::abs(dphiapprox) < third*settings_.dphisectorHG()) { //1/3 of sector size to catch errors if (settings_.writeMonitorData("Residuals")) { double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv()); @@ -493,20 +480,18 @@ void MatchCalculator::execute() { edm::LogVerbatim("Tracklet") << "MatchCalculator found match in disk " << getName(); } - tracklet->addMatchDisk(disk, - ideltaphi, - ideltar, - drphi / stub->r(), - dr, - drphiapprox / stub->r(), - drapprox, - stub->alpha(settings_.stripPitch(stub->isPSmodule())), - (phiregion_ << 7) + fpgastub->stubindex().value(), - stub->z(), - fpgastub); + tracklet->addMatch(layerdisk_, + ideltaphi, + ideltar, + drphi / stub->r(), + dr, + drphiapprox / stub->r(), + drapprox, + (phiregion_ << 7) + fpgastub->stubindex().value(), + fpgastub); + if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Accepted full match in disk " << getName() << " " << tracklet << " " - << iSector_; + edm::LogVerbatim("Tracklet") << "Accepted full match in disk " << getName() << " " << tracklet; } fullMatches_[seedindex]->addMatch(tracklet, mergedMatches[j].second); diff --git a/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc b/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc index 0e528803e2747..2668c2e646761 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc @@ -15,64 +15,44 @@ using namespace std; using namespace trklet; -MatchEngine::MatchEngine(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector) { - layer_ = 0; - disk_ = 0; - string subname = name.substr(3, 2); - if (subname.substr(0, 1) == "L") - layer_ = stoi(subname.substr(1, 1)); - else if (subname.substr(0, 1) == "D") - disk_ = stoi(subname.substr(1, 1)); - else - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " " << name << " subname = " << subname << " " - << layer_ << " " << disk_; - - barrel_ = layer_ > 0; - - nvm_ = barrel_ ? settings_.nvmme(layer_ - 1) * settings_.nallstubs(layer_ - 1) - : settings_.nvmme(disk_ + N_LAYER - 1) * settings_.nallstubs(disk_ + N_LAYER - 1); - - if (nvm_ == 32) - nvmbits_ = 5; - else if (nvm_ == 16) - nvmbits_ = 4; - - if (layer_ > 0) { - unsigned int nbits = 3; - if (layer_ >= 4) - nbits = 4; - - for (unsigned int irinv = 0; irinv < 32; irinv++) { - double rinv = (irinv - 15.5) * (1 << (settings_.nbitsrinv() - 5)) * settings_.krinvpars(); - - double stripPitch = - (settings_.rmean(layer_ - 1) < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); - double projbend = bend(settings_.rmean(layer_ - 1), rinv, stripPitch); - for (unsigned int ibend = 0; ibend < (unsigned int)(1 << nbits); ibend++) { - double stubbend = benddecode(ibend, layer_ <= 3); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(layer_ - 1); +MatchEngine::MatchEngine(string name, Settings const& settings, Globals* global) : ProcessBase(name, settings, global) { + layerdisk_ = initLayerDisk(3); + + barrel_ = layerdisk_ < N_LAYER; + + nvm_ = settings_.nvmme(layerdisk_) * settings_.nallstubs(layerdisk_); + + nvmbits_ = settings_.nbitsvmme(layerdisk_) + settings_.nbitsallstubs(layerdisk_); + + nrinv_ = NRINVBITS; + double rinvhalf = 0.5 * ((1 << nrinv_) - 1); + + nfinephibits_ = 3; + + if (barrel_) { + bool isPSmodule = layerdisk_ < N_PSLAYER; + + unsigned int nbits = isPSmodule ? N_BENDBITS_PS : N_BENDBITS_2S; + + for (unsigned int irinv = 0; irinv < (1u << nrinv_); irinv++) { + double rinv = (irinv - rinvhalf) * (1 << (settings_.nbitsrinv() - nrinv_)) * settings_.krinvpars(); + + double stripPitch = settings_.stripPitch(isPSmodule); + double projbend = bendstrip(settings_.rmean(layerdisk_), rinv, stripPitch); + for (unsigned int ibend = 0; ibend < (1u << nbits); ibend++) { + double stubbend = settings_.benddecode(ibend, layerdisk_, isPSmodule); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, isPSmodule); table_.push_back(pass); } } if (settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } - - char layer = '0' + layer_; + char layer = '1' + layerdisk_; string fname = "METable_L"; fname += layer; fname += ".tab"; - const string full_fname = settings_.tablePath() + fname; - ofstream out(full_fname); - if (out.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << full_fname; + ofstream out = openfile(settings_.tablePath(), fname, __FILE__, __LINE__); out << "{" << endl; for (unsigned int i = 0; i < table_.size(); i++) { @@ -86,17 +66,17 @@ MatchEngine::MatchEngine(string name, Settings const& settings, Globals* global, } } - if (disk_ > 0) { - for (unsigned int iprojbend = 0; iprojbend < 32; iprojbend++) { - double projbend = 0.5 * (iprojbend - 15.0); - for (unsigned int ibend = 0; ibend < 8; ibend++) { - double stubbend = benddecode(ibend, true); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(disk_ + 5); + if (layerdisk_ >= N_LAYER) { + for (unsigned int iprojbend = 0; iprojbend < (1u << nrinv_); iprojbend++) { + double projbend = 0.5 * (iprojbend - rinvhalf); + for (unsigned int ibend = 0; ibend < (1 << N_BENDBITS_PS); ibend++) { + double stubbend = settings_.benddecode(ibend, layerdisk_, true); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, true); tablePS_.push_back(pass); } - for (unsigned int ibend = 0; ibend < 16; ibend++) { - double stubbend = benddecode(ibend, false); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(disk_ + 5); + for (unsigned int ibend = 0; ibend < (1 << N_BENDBITS_2S); ibend++) { + double stubbend = settings_.benddecode(ibend, layerdisk_, false); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, false); table2S_.push_back(pass); } } @@ -141,6 +121,9 @@ void MatchEngine::execute() { unsigned int countall = 0; unsigned int countpass = 0; + bool print = (getName() == "ME_L3PHIC20"); + print = false; + constexpr unsigned int kNBitsBuffer = 3; int writeindex = 0; @@ -195,9 +178,11 @@ void MatchEngine::execute() { iproj++; moreproj = iproj < nproj; - unsigned int rzfirst = barrel_ ? proj->zbin1projvm(layer_) : proj->rbin1projvm(disk_); + unsigned int rzfirst = proj->proj(layerdisk_).fpgarzbin1projvm().value(); unsigned int rzlast = rzfirst; - bool second = (barrel_ ? proj->zbin2projvm(layer_) : proj->rbin2projvm(disk_)) == 1; + + bool second = proj->proj(layerdisk_).fpgarzbin2projvm().value(); + if (second) rzlast += 1; @@ -247,31 +232,31 @@ void MatchEngine::execute() { Tracklet* proj = vmprojs_->getTracklet(projindex); - FPGAWord fpgaphi = barrel_ ? proj->fpgaphiproj(layer_) : proj->fpgaphiprojdisk(disk_); - projfinephi = (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + 3))) & 7; + FPGAWord fpgafinephi = proj->proj(layerdisk_).fpgafinephivm(); + + projfinephi = fpgafinephi.value(); nstubs = vmstubs_->nStubsBin(rzbin); - projfinerz = barrel_ ? proj->finezvm(layer_) : proj->finervm(disk_); + projfinerz = proj->proj(layerdisk_).fpgafinerzvm().value(); - projrinv = - barrel_ - ? (16 + (((-2) * proj->fpgaphiprojder(layer_).value()) >> (proj->fpgaphiprojder(layer_).nbits() - 4))) - : proj->getBendIndex(disk_).value(); + projrinv = barrel_ ? ((1 << (nrinv_ - 1)) + ((-2 * proj->proj(layerdisk_).fpgaphiprojder().value()) >> + (proj->proj(layerdisk_).fpgaphiprojder().nbits() - (nrinv_ - 1)))) + : proj->proj(layerdisk_).getBendIndex().value(); assert(projrinv >= 0); - if (settings_.extended() && projrinv == 32) { + if (settings_.extended() && projrinv == (1 << nrinv_)) { if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "Extended tracking, projrinv:" << projrinv; } - projrinv = 31; + projrinv = (1 << nrinv_) - 1; } - assert(projrinv < 32); + assert(projrinv < (1 << nrinv_)); - isPSseed = proj->PSseed() == 1; + isPSseed = proj->PSseed(); //Calculate fine z position if (second) { - projfinerzadj = projfinerz - 8; + projfinerzadj = projfinerz - (1 << NFINERZBITS); } else { projfinerzadj = projfinerz; } @@ -298,11 +283,13 @@ void MatchEngine::execute() { int stubfinerz = vmstub.finerz().value(); - int nbits = isPSmodule ? 3 : 4; + int nbits = isPSmodule ? N_BENDBITS_PS : N_BENDBITS_2S; int deltaphi = projfinephi - vmstub.finephi().value(); - bool passphi = (abs(deltaphi) < 3) || (abs(deltaphi) > 5); + constexpr int mindeltaphicut = 3; + constexpr int maxdeltaphicut = 5; + bool passphi = (std::abs(deltaphi) < mindeltaphicut) || (std::abs(deltaphi) > maxdeltaphicut); unsigned int index = (projrinv << nbits) + vmstub.bend().value(); @@ -312,18 +299,28 @@ void MatchEngine::execute() { if (barrel_) { if (isPSseed) { - passz = idrz >= -2 && idrz <= 2; + constexpr int drzcut = 1; + passz = std::abs(idrz) <= drzcut; } else { - passz = idrz >= -5 && idrz <= 5; + constexpr int drzcut = 5; + passz = std::abs(idrz) <= drzcut; } } else { if (isPSmodule) { - passz = idrz >= -1 && idrz <= 1; + constexpr int drzcut = 1; + passz = std::abs(idrz) <= drzcut; } else { - passz = idrz >= -5 && idrz <= 5; + constexpr int drzcut = 3; + passz = std::abs(idrz) <= drzcut; } } + if (print) { + cout << "istep index : " << istep << " " << index << " " << vmstub.bend().value() + << " rzbin istubtmp : " << rzbin << " " << istubtmp << " dz " << stubfinerz << " " << projfinerzadj + << " dphi: " << deltaphi << endl; + } + //Check if stub bend and proj rinv consistent if (passz && passphi) { if (barrel_ ? table_[index] : (isPSmodule ? tablePS_[index] : table2S_[index])) { @@ -331,7 +328,7 @@ void MatchEngine::execute() { std::pair tmp(proj, vmprojs_->getAllProjIndex(projindex)); if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << proj->getISeed() << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << proj->getISeed() << endl; fout.close(); } candmatches_->addMatch(tmp, vmstub.stub()); diff --git a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc index 47d621adcaec6..6bea2f165c795 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc @@ -3,56 +3,93 @@ using namespace std; using namespace trklet; -MatchEngineUnit::MatchEngineUnit(bool barrel, vector table, vector tablePS, vector table2S) - : candmatches_(5) { +MatchEngineUnit::MatchEngineUnit(bool barrel, unsigned int layerdisk, vector table) : candmatches_(5) { idle_ = true; barrel_ = barrel; table_ = table; - tablePS_ = tablePS; - table2S_ = table2S; - slot_ = 1; //This makes it idle until initialized + layerdisk_ = layerdisk; } void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory, - unsigned int slot, + unsigned int nrzbins, + unsigned int rzbin, + unsigned int phibin, + int shift, int projrinv, int projfinerz, int projfinephi, - bool usesecond, + bool usefirstMinus, + bool usefirstPlus, + bool usesecondMinus, + bool usesecondPlus, bool isPSseed, Tracklet* proj) { vmstubsmemory_ = vmstubsmemory; idle_ = false; - slot_ = slot; + nrzbins_ = nrzbins; + rzbin_ = rzbin; + phibin_ = phibin; + shift_ = shift; istub_ = 0; + iuse_ = 0; projrinv_ = projrinv; projfinerz_ = projfinerz; projfinephi_ = projfinephi; - usesecond_ = usesecond; + use_.clear(); + if (usefirstMinus) { + use_.emplace_back(0, 0); + } + if (usefirstPlus) { + use_.emplace_back(0, 1); + } + if (usesecondMinus) { + use_.emplace_back(1, 0); + } + if (usesecondPlus) { + use_.emplace_back(1, 1); + } + assert(use_.size() != 0); isPSseed_ = isPSseed; proj_ = proj; } -void MatchEngineUnit::step() { +void MatchEngineUnit::step(bool print) { if (idle() || candmatches_.almostfull()) return; - const VMStubME& vmstub = vmstubsmemory_->getVMStubMEBin(slot_, istub_); + unsigned int slot = (phibin_ + use_[iuse_].second) * nrzbins_ + rzbin_ + use_[iuse_].first; + + int projfinerz = projfinerz_ - (1 << NFINERZBITS) * use_[iuse_].first; + int projfinephi = projfinephi_; + if (use_[iuse_].second == 0) { + if (shift_ == -1) { + projfinephi -= (1 << NFINEPHIBITS); + } + } else { + //When we get here shift_ is either 1 or -1 + if (shift_ == 1) { + projfinephi += (1 << NFINEPHIBITS); + } + } + + const VMStubME& vmstub = vmstubsmemory_->getVMStubMEBin(slot, istub_); bool isPSmodule = vmstub.isPSmodule(); int stubfinerz = vmstub.finerz().value(); int stubfinephi = vmstub.finephi().value(); - int deltaphi = stubfinephi - projfinephi_; + int deltaphi = stubfinephi - projfinephi; - bool dphicut = (abs(deltaphi) < 3) || (abs(deltaphi) > 5); //TODO - need better implementations + bool dphicut = (abs(deltaphi) < 3); int nbits = isPSmodule ? 3 : 4; - unsigned int index = (projrinv_ << nbits) + vmstub.bend().value(); + int diskps = (!barrel_) && isPSmodule; + + unsigned int index = (diskps << (4 + 5)) + (projrinv_ << nbits) + vmstub.bend().value(); //Check if stub z position consistent - int idrz = stubfinerz - projfinerz_; + int idrz = stubfinerz - projfinerz; bool pass; if (barrel_) { @@ -69,19 +106,23 @@ void MatchEngineUnit::step() { } } + if (print) + cout << "MEU TrkId stubindex : " << 128 * proj_->TCIndex() + proj_->trackletIndex() << " " + << vmstub.stubindex().value() << " " << ((pass && dphicut) && table_[index]) << " index=" << index + << " projrinv bend : " << projrinv_ << " " << vmstub.bend().value() << " shift_ isPSseed_ :" << shift_ << " " + << isPSseed_ << " slot=" << slot << endl; + //Check if stub bend and proj rinv consistent - if ((pass && dphicut) && (barrel_ ? table_[index] : (isPSmodule ? tablePS_[index] : table2S_[index]))) { + if ((pass && dphicut) && table_[index]) { std::pair tmp(proj_, vmstub.stub()); candmatches_.store(tmp); } istub_++; - if (istub_ >= vmstubsmemory_->nStubsBin(slot_)) { - if (usesecond_) { - usesecond_ = false; + if (istub_ >= vmstubsmemory_->nStubsBin(slot)) { + iuse_++; + if (iuse_ < use_.size()) { istub_ = 0; - slot_++; - projfinerz_ -= (1 << NFINERZBITS); } else { idle_ = true; } diff --git a/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc b/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc index 2a977a963cc00..b2f7722a5b1d5 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc @@ -13,66 +13,46 @@ using namespace std; using namespace trklet; -MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector), fullmatches_(12), inputProjBuffer_(3) { - phioffset_ = phimin_; - +MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global), fullmatches_(12), inputProjBuffer_(3) { phiregion_ = name[8] - 'A'; - initLayerDisk(3, layer_, disk_); layerdisk_ = initLayerDisk(3); - //TODO should sort out constants here - icorrshift_ = 7; + barrel_ = layerdisk_ < N_LAYER; + + phishift_ = settings_.nphibitsstub(N_LAYER - 1) - settings_.nphibitsstub(layerdisk_); + dzshift_ = settings_.nzbitsstub(0) - settings_.nzbitsstub(layerdisk_); - if (layer_ <= 3) { - icorzshift_ = -1 - settings_.PS_zderL_shift(); + if (barrel_) { + icorrshift_ = ilog2(settings_.kphi(layerdisk_) / (settings_.krbarrel() * settings_.kphider())); + icorzshift_ = ilog2(settings_.kz(layerdisk_) / (settings_.krbarrel() * settings_.kzder())); } else { - icorzshift_ = -1 - settings_.SS_zderL_shift(); - } - phi0shift_ = 3; - fact_ = 1; - if (layer_ >= 4) { - fact_ = (1 << (settings_.nzbitsstub(0) - settings_.nzbitsstub(5))); - icorrshift_ -= (10 - settings_.nrbitsstub(layer_ - 1)); - icorzshift_ += (settings_.nzbitsstub(0) - settings_.nzbitsstub(5) + settings_.nrbitsstub(layer_ - 1) - - settings_.nrbitsstub(0)); - phi0shift_ = 0; + icorrshift_ = ilog2(settings_.kphi(layerdisk_) / (settings_.kz() * settings_.kphiderdisk())); + icorzshift_ = ilog2(settings_.krprojshiftdisk() / (settings_.kz() * settings_.krder())); } nrbits_ = 5; nphiderbits_ = 6; - //to adjust globaly the phi and rz matching cuts - phifact_ = 1.0; - rzfact_ = 1.0; + nrinv_ = NRINVBITS; + double rinvhalf = 0.5 * ((1 << nrinv_) - 1); for (unsigned int iSeed = 0; iSeed < 12; iSeed++) { - if (layer_ > 0) { + if (layerdisk_ < N_LAYER) { phimatchcut_[iSeed] = - settings_.rphimatchcut(iSeed, layer_ - 1) / (settings_.kphi1() * settings_.rmean(layer_ - 1)); - zmatchcut_[iSeed] = settings_.zmatchcut(iSeed, layer_ - 1) / settings_.kz(); - } - if (disk_ != 0) { - rphicutPS_[iSeed] = settings_.rphicutPS(iSeed, abs(disk_) - 1) / (settings_.kphi() * settings_.kr()); - rphicut2S_[iSeed] = settings_.rphicut2S(iSeed, abs(disk_) - 1) / (settings_.kphi() * settings_.kr()); - rcut2S_[iSeed] = settings_.rcut2S(iSeed, abs(disk_) - 1) / settings_.krprojshiftdisk(); - rcutPS_[iSeed] = settings_.rcutPS(iSeed, abs(disk_) - 1) / settings_.krprojshiftdisk(); + settings_.rphimatchcut(iSeed, layerdisk_) / (settings_.kphi1() * settings_.rmean(layerdisk_)); + zmatchcut_[iSeed] = settings_.zmatchcut(iSeed, layerdisk_) / settings_.kz(); + } else { + rphicutPS_[iSeed] = settings_.rphicutPS(iSeed, layerdisk_ - N_LAYER) / (settings_.kphi() * settings_.kr()); + rphicut2S_[iSeed] = settings_.rphicut2S(iSeed, layerdisk_ - N_LAYER) / (settings_.kphi() * settings_.kr()); + rcut2S_[iSeed] = settings_.rcut2S(iSeed, layerdisk_ - N_LAYER) / settings_.krprojshiftdisk(); + rcutPS_[iSeed] = settings_.rcutPS(iSeed, layerdisk_ - N_LAYER) / settings_.krprojshiftdisk(); } } - if (iSector_ == 0 && layer_ > 0 && settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } - - const string filephicut = settings_.tablePath() + getName() + "_phicut.tab"; - ofstream outphicut(filephicut); - if (outphicut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << filephicut; + if (barrel_ && settings_.writeTable()) { + ofstream outphicut = openfile(settings_.tablePath(), getName() + "_phicut.tab", __FILE__, __LINE__); outphicut << "{" << endl; for (unsigned int seedindex = 0; seedindex < 12; seedindex++) { @@ -83,10 +63,7 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g outphicut << endl << "};" << endl; outphicut.close(); - const string filezcut = settings_.tablePath() + getName() + "_zcut.tab"; - ofstream outzcut(filezcut); - if (outzcut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << filezcut; + ofstream outzcut = openfile(settings_.tablePath(), getName() + "_zcut.tab", __FILE__, __LINE__); outzcut << "{" << endl; for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { @@ -98,66 +75,55 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g outzcut.close(); } - if (layer_ > 0) { - unsigned int nbits = 3; - if (layer_ >= 4) - nbits = 4; + if (barrel_) { + unsigned int nbits = (layerdisk_ < N_PSLAYER) ? N_BENDBITS_PS : N_BENDBITS_2S; - for (unsigned int irinv = 0; irinv < 32; irinv++) { - double rinv = (irinv - 15.5) * (1 << (settings_.nbitsrinv() - 5)) * settings_.krinvpars(); - double stripPitch = - (settings_.rmean(layer_ - 1) < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); - double projbend = bend(settings_.rmean(layer_ - 1), rinv, stripPitch); + for (unsigned int irinv = 0; irinv < (1u << nrinv_); irinv++) { + double rinv = (irinv - rinvhalf) * (1 << (settings_.nbitsrinv() - nrinv_)) * settings_.krinvpars(); + double stripPitch = settings_.stripPitch(layerdisk_ < N_PSLAYER); + double projbend = bendstrip(settings_.rmean(layerdisk_), rinv, stripPitch); for (unsigned int ibend = 0; ibend < (unsigned int)(1 << nbits); ibend++) { - double stubbend = benddecode(ibend, layer_ <= (int)N_PSLAYER); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(layer_ - 1); + double stubbend = settings_.benddecode(ibend, layerdisk_, layerdisk_ < (int)N_PSLAYER); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, layerdisk_ < (int)N_PSLAYER); table_.push_back(pass); } } - - if (settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); + } else { + constexpr int nprojbends = 1 << NRINVBITS; + constexpr int npsbends = 1 << N_BENDBITS_PS; + constexpr int n2sbends = 1 << N_BENDBITS_2S; + table_.resize(nprojbends * n2sbends * 2, false); //Factor of 2 is to have both 2s and ps bends in same table + for (unsigned int iprojbend = 0; iprojbend < nprojbends; iprojbend++) { + double projbend = 0.5 * (iprojbend - rinvhalf); + for (unsigned int ibend = 0; ibend < npsbends; ibend++) { + double stubbend = settings_.benddecode(ibend, layerdisk_, true); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, true); + table_[nprojbends*n2sbends + npsbends * iprojbend + ibend] = pass; } - - char layer = '0' + layer_; - string fname = "METable_L"; - fname += layer; - fname += ".tab"; - const string full_fname = settings_.tablePath() + fname; - ofstream out(full_fname); - if (out.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << full_fname; - - out << "{" << endl; - for (unsigned int i = 0; i < table_.size(); i++) { - if (i != 0) { - out << "," << endl; - } - out << table_[i]; + for (unsigned int ibend = 0; ibend < n2sbends; ibend++) { + double stubbend = settings_.benddecode(ibend, layerdisk_, false); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, false); + table_[n2sbends * iprojbend + ibend] = pass; } - out << "};" << endl; - out.close(); } } - if (disk_ > 0) { - for (unsigned int iprojbend = 0; iprojbend < 32; iprojbend++) { - double projbend = 0.5 * (iprojbend - 15.0); - for (unsigned int ibend = 0; ibend < 8; ibend++) { - double stubbend = benddecode(ibend, true); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(disk_ + 5); - tablePS_.push_back(pass); - } - for (unsigned int ibend = 0; ibend < 16; ibend++) { - double stubbend = benddecode(ibend, false); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(disk_ + 5); - table2S_.push_back(pass); + if (settings_.writeTable()) { + char layerdisk = barrel_ ? '0' + layerdisk_ + 1 : '0' + layerdisk_ - N_LAYER + 1; + string fname = barrel_ ? "METable_L" : "METable_D"; + fname += layerdisk; + fname += ".tab"; + + ofstream out = openfile(settings_.tablePath(), fname, __FILE__, __LINE__); + out << "{" << endl; + for (unsigned int i = 0; i < table_.size(); i++) { + if (i != 0) { + out << "," << endl; } + out << table_[i]; } + out << "};" << endl; + out.close(); } for (unsigned int i = 0; i < N_DSS_MOD * 2; i++) { @@ -169,23 +135,21 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g settings_.kphi(); } - barrel_ = layer_ > 0; - - nvm_ = barrel_ ? settings_.nvmme(layer_ - 1) * settings_.nallstubs(layer_ - 1) - : settings_.nvmme(disk_ + 5) * settings_.nallstubs(disk_ + 5); - nvmbins_ = barrel_ ? settings_.nvmme(layer_ - 1) : settings_.nvmme(disk_ + 5); - - if (nvm_ == 32) - nvmbits_ = 5; - if (nvm_ == 16) - nvmbits_ = 4; - assert(nvmbits_ != -1); + nvm_ = settings_.nvmme(layerdisk_) * settings_.nallstubs(layerdisk_); + nvmbins_ = settings_.nvmme(layerdisk_); + nvmbits_ = settings_.nbitsvmme(layerdisk_) + settings_.nbitsallstubs(layerdisk_); nMatchEngines_ = 4; for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { - MatchEngineUnit tmpME(barrel_, table_, tablePS_, table2S_); + MatchEngineUnit tmpME(barrel_, layerdisk_, table_); matchengines_.push_back(tmpME); } + + if (globals_->projectionRouterBendTable() == nullptr) { + auto* bendTablePtr = new ProjectionRouterBendTable(); + bendTablePtr->init(settings_, globals_, nrbits_, nphiderbits_); + globals_->projectionRouterBendTable() = bendTablePtr; + } } void MatchProcessor::addOutput(MemoryBase* memory, string output) { @@ -231,15 +195,9 @@ void MatchProcessor::addInput(MemoryBase* memory, string input) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input; } -void MatchProcessor::execute() { +void MatchProcessor::execute(unsigned int iSector, double phimin) { assert(vmstubs_.size() == 1); - if (globals_->projectionRouterBendTable() == nullptr) { // move to constructor?! - auto* bendTablePtr = new ProjectionRouterBendTable(); - bendTablePtr->init(settings_, globals_, nrbits_, nphiderbits_); - globals_->projectionRouterBendTable() = bendTablePtr; - } - /* The code is organized in three 'steps' corresponding to the PR, ME, and MC functions. The output from the PR step is buffered in a 'circular' buffer, and similarly the ME output is put in a circular buffer. @@ -254,6 +212,11 @@ void MatchProcessor::execute() { */ + bool print = getName() == "MP_L3PHIC" && iSector == 3; + print = false; + + phimin_ = phimin; + Tracklet* oldTracklet = nullptr; unsigned int countme = 0; @@ -266,18 +229,15 @@ void MatchProcessor::execute() { inputProjBuffer_.reset(); - for (unsigned int i = 0; i < inputprojs_.size(); i++) { - countinputproj += inputprojs_[i]->nTracklets(); + for (const auto& inputproj : inputprojs_) { + countinputproj += inputproj->nTracklets(); } - for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { - matchengines_[iME].reset(); + for (auto& matchengine : matchengines_) { + matchengine.reset(); } - unsigned int step2delay = 0; - unsigned int step3delay = 0; - - for (unsigned int istep = 0; istep < settings_.maxStep("MP") + step3delay; istep++) { + for (unsigned int istep = 0; istep < settings_.maxStep("MP"); istep++) { bool projdone = false; bool medone = true; //Step 1 @@ -296,60 +256,96 @@ void MatchProcessor::execute() { } Tracklet* proj = projMem->getTracklet(iproj); - FPGAWord fpgaphi = barrel_ ? proj->fpgaphiproj(layer_) : proj->fpgaphiprojdisk(disk_); - int iphi = (fpgaphi.value() >> (fpgaphi.nbits() - nvmbits_)) & (nvmbins_ - 1); + FPGAWord fpgaphi = proj->proj(layerdisk_).fpgaphiproj(); + + unsigned int iphi = (fpgaphi.value() >> (fpgaphi.nbits() - nvmbits_)) & (nvmbins_ - 1); + + int nextrabits = 2; + int overlapbits = nvmbits_ + nextrabits; + + unsigned int extrabits = fpgaphi.bits(fpgaphi.nbits() - overlapbits, nextrabits); + + unsigned int ivmPlus = iphi; + + int shift = 0; + + if (extrabits == ((1U << nextrabits) - 1) && iphi != ((1U << settings_.nbitsvmme(layerdisk_)) - 1)) { + shift = 1; + ivmPlus++; + } + unsigned int ivmMinus = iphi; + if (extrabits == 0 && iphi != 0) { + shift = -1; + ivmMinus--; + } int projrinv = -1; if (barrel_) { - projrinv = (1 << (NRINVBITS - 1)) + (proj->fpgarinv().value() >> (proj->fpgarinv().nbits() - NRINVBITS)); + FPGAWord phider = proj->proj(layerdisk_).fpgaphiprojder(); + projrinv = (1 << (nrinv_ - 1)) - 1 - (phider.value() >> (phider.nbits() - nrinv_)); } else { //The next lines looks up the predicted bend based on: // 1 - r projections // 2 - phi derivative // 3 - the sign - i.e. if track is forward or backward - int rindex = (proj->fpgarprojdisk(disk_).value() >> (proj->fpgarprojdisk(disk_).nbits() - nrbits_)) & + + int rindex = (proj->proj(layerdisk_).fpgarzproj().value() >> + (proj->proj(layerdisk_).fpgarzproj().nbits() - nrbits_)) & ((1 << nrbits_) - 1); - int phiderindex = (proj->fpgaphiprojderdisk(disk_).value() >> - (proj->fpgaphiprojderdisk(disk_).nbits() - nphiderbits_)) & + int phiderindex = (proj->proj(layerdisk_).fpgaphiprojder().value() >> + (proj->proj(layerdisk_).fpgaphiprojder().nbits() - nphiderbits_)) & ((1 << nphiderbits_) - 1); - int signindex = (proj->fpgarprojderdisk(disk_).value() < 0); + int signindex = proj->proj(layerdisk_).fpgarzprojder().value() < 0; int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; - projrinv = globals_->projectionRouterBendTable()->bendLoookup(abs(disk_) - 1, bendindex); + projrinv = globals_->projectionRouterBendTable()->bendLoookup(layerdisk_ - N_LAYER, bendindex); - proj->setBendIndex(projrinv, disk_); + proj->proj(layerdisk_).setBendIndex(projrinv); } assert(projrinv >= 0); - unsigned int slot = barrel_ ? proj->zbin1projvm(layer_) : proj->rbin1projvm(disk_); - bool second = (barrel_ ? proj->zbin2projvm(layer_) : proj->rbin2projvm(disk_)); + unsigned int slot = proj->proj(layerdisk_).fpgarzbin1projvm().value(); + bool second = proj->proj(layerdisk_).fpgarzbin2projvm().value(); - int nfinephi = 3; - unsigned int projfinephi = - (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + nfinephi))) & ((1 << nfinephi) - 1); - int projfinerz = barrel_ ? proj->finezvm(layer_) : proj->finervm(disk_); + unsigned int projfinephi = (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + NFINEPHIBITS))) & ((1<proj(layerdisk_).fpgafinerzvm().value(); - bool isPSseed = proj->PSseed() == 1; + bool isPSseed = proj->PSseed(); - int nbins = 8; - if (layerdisk_ >= 6) - nbins = 16; + int nbins = (1 << N_RZBITS); + if (layerdisk_ >= N_LAYER) { + nbins*=2; //twice as many bins in disks (since there are two disks) + } VMStubsMEMemory* stubmem = vmstubs_[0]; - bool usefirst = stubmem->nStubsBin(iphi * nbins + slot) != 0; - bool usesecond = (second && (stubmem->nStubsBin(iphi * nbins + slot + 1) != 0)); - - if (usefirst) { - ProjectionTemp tmpProj(proj, slot, projrinv, projfinerz, projfinephi, iphi, usesecond, isPSseed); - inputProjBuffer_.store(tmpProj); - } else if (usesecond) { - ProjectionTemp tmpProj(proj, slot + 1, projrinv, projfinerz - 8, projfinephi, iphi, false, isPSseed); + bool usefirstMinus = stubmem->nStubsBin(ivmMinus * nbins + slot) != 0; + bool usesecondMinus = (second && (stubmem->nStubsBin(ivmMinus * nbins + slot + 1) != 0)); + bool usefirstPlus = ivmPlus != ivmMinus && stubmem->nStubsBin(ivmPlus * nbins + slot) != 0; + bool usesecondPlus = + ivmPlus != ivmMinus && (second && (stubmem->nStubsBin(ivmPlus * nbins + slot + 1) != 0)); + + bool useProj = usefirstPlus || usesecondPlus || usefirstMinus || usesecondMinus; + + if (useProj) { + ProjectionTemp tmpProj(proj, + slot, + projrinv, + projfinerz, + projfinephi, + ivmMinus, + shift, + usefirstMinus, + usefirstPlus, + usesecondMinus, + usesecondPlus, + isPSseed); inputProjBuffer_.store(tmpProj); } + iproj++; if (iproj == projMem->nTracklets()) { iproj = 0; @@ -365,84 +361,90 @@ void MatchProcessor::execute() { //Step 2 //Check if we have ME that can process projection - if (istep >= step2delay && istep < settings_.maxStep("MP") + step2delay) { - bool addedProjection = false; - for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { - if (!matchengines_[iME].idle()) - countme++; - matchengines_[iME].step(); - //if match engine empty and we have queued projections add to match engine - if ((!addedProjection) && matchengines_[iME].idle() && (!inputProjBuffer_.empty())) { - ProjectionTemp tmpProj = inputProjBuffer_.read(); - VMStubsMEMemory* stubmem = vmstubs_[0]; - - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << getName() << " adding projection to match engine"; - } - - int nbins = 8; - if (layerdisk_ >= 6) - nbins = 16; - - matchengines_[iME].init(stubmem, - tmpProj.iphi() * nbins + tmpProj.slot(), - tmpProj.projrinv(), - tmpProj.projfinerz(), - tmpProj.projfinephi(), - tmpProj.usesecond(), - tmpProj.isPSseed(), - tmpProj.proj()); - addedProjection = true; + bool addedProjection = false; + for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { + if (!matchengines_[iME].idle()) + countme++; + matchengines_[iME].step(print); + //if match engine empty and we have queued projections add to match engine + if ((!addedProjection) && matchengines_[iME].idle() && (!inputProjBuffer_.empty())) { + ProjectionTemp tmpProj = inputProjBuffer_.read(); + VMStubsMEMemory* stubmem = vmstubs_[0]; + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " adding projection to match engine"; } + + int nbins = (1 << N_RZBITS); + if (layerdisk_ >= N_LAYER) { + nbins*=2; //twice as many bins in disks (since there are two disks) + } + + matchengines_[iME].init(stubmem, + nbins, + tmpProj.slot(), + tmpProj.iphi(), + tmpProj.shift(), + tmpProj.projrinv(), + tmpProj.projfinerz(), + tmpProj.projfinephi(), + tmpProj.use(0, 0), + tmpProj.use(0, 1), + tmpProj.use(1, 0), + tmpProj.use(1, 1), + tmpProj.isPSseed(), + tmpProj.proj()); + addedProjection = true; } } //Step 3 //Check if we have candidate match to process - if (istep >= step3delay) { - unsigned int iMEbest = nMatchEngines_; - int bestTCID = -1; - bool bestInPipeline = false; - for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { - bool empty = matchengines_[iME].empty(); - medone = medone && (empty && matchengines_[iME].idle()); - if (empty && matchengines_[iME].idle()) - continue; - int currentTCID = empty ? matchengines_[iME].currentProj()->TCID() : matchengines_[iME].peek().first->TCID(); - if ((iMEbest == nMatchEngines_) || (currentTCID < bestTCID)) { - iMEbest = iME; - bestTCID = currentTCID; - bestInPipeline = empty; - } + unsigned int iMEbest = nMatchEngines_; + int bestTCID = -1; + bool bestInPipeline = false; + for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { + bool empty = matchengines_[iME].empty(); + medone = medone && (empty && matchengines_[iME].idle()); + if (empty && matchengines_[iME].idle()) + continue; + int currentTCID = empty ? matchengines_[iME].currentProj()->TCID() : matchengines_[iME].peek().first->TCID(); + if ((iMEbest == nMatchEngines_) || (currentTCID < bestTCID)) { + iMEbest = iME; + bestTCID = currentTCID; + bestInPipeline = empty; } + } - if (iMEbest != nMatchEngines_ && (!bestInPipeline)) { - const std::pair& candmatch = matchengines_[iMEbest].read(); - - const Stub* fpgastub = candmatch.second; - Tracklet* tracklet = candmatch.first; + if (iMEbest != nMatchEngines_ && (!bestInPipeline)) { + std::pair candmatch = matchengines_[iMEbest].read(); - if (oldTracklet != nullptr) { - //allow equal here since we can have more than one cadidate match per tracklet projection - assert(oldTracklet->TCID() <= tracklet->TCID()); - } - oldTracklet = tracklet; + const Stub* fpgastub = candmatch.second; + Tracklet* tracklet = candmatch.first; - bool match = matchCalculator(tracklet, fpgastub); + if (oldTracklet != nullptr) { + //allow equal here since we can have more than one cadidate match per tracklet projection + assert(oldTracklet->TCID() <= tracklet->TCID()); + } + oldTracklet = tracklet; - if (settings_.debugTracklet() && match) { - edm::LogVerbatim("Tracklet") << getName() << " have match"; - } + bool match = matchCalculator(tracklet, fpgastub, print, istep); - countall++; - if (match) - countsel++; + if (settings_.debugTracklet() && match) { + edm::LogVerbatim("Tracklet") << getName() << " have match"; } + + countall++; + if (match) + countsel++; } - if ((projdone && medone) || (istep == settings_.maxStep("MP") + step3delay - 1)) { - globals_->ofstream("matchprocessor.txt") << getName() << " " << istep << " " << countall << " " << countsel << " " - << countme << " " << countinputproj << endl; + + if ((projdone && medone) || (istep == settings_.maxStep("MP") - 1)) { + if (settings_.writeMonitorData("MP")) { + globals_->ofstream("matchprocessor.txt") << getName() << " " << istep << " " << countall << " " << countsel + << " " << countme << " " << countinputproj << endl; + } break; } } @@ -452,21 +454,22 @@ void MatchProcessor::execute() { } } -bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { +bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, bool, unsigned int) { const L1TStub* stub = fpgastub->l1tstub(); - if (layer_ != 0) { + if (layerdisk_ < N_LAYER) { + const Projection& proj = tracklet->proj(layerdisk_); int ir = fpgastub->r().value(); - int iphi = tracklet->fpgaphiproj(layer_).value(); - int icorr = (ir * tracklet->fpgaphiprojder(layer_).value()) >> icorrshift_; + int iphi = proj.fpgaphiproj().value(); + int icorr = (ir * proj.fpgaphiprojder().value()) >> icorrshift_; iphi += icorr; - int iz = tracklet->fpgazproj(layer_).value(); - int izcor = (ir * tracklet->fpgazprojder(layer_).value() + (1 << (icorzshift_ - 1))) >> icorzshift_; + int iz = proj.fpgarzproj().value(); + int izcor = (ir * proj.fpgarzprojder().value() + (1 << (icorzshift_ - 1))) >> icorzshift_; iz += izcor; int ideltaz = fpgastub->z().value() - iz; - int ideltaphi = (fpgastub->phi().value() << phi0shift_) - (iphi << (settings_.phi0bitshift() - 1 + phi0shift_)); + int ideltaphi = (fpgastub->phi().value() - iphi) << phishift_; //Floating point calculations @@ -475,28 +478,27 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { double z = stub->z(); if (settings_.useapprox()) { - double dphi = reco::reduceRange(phi - fpgastub->phiapprox(phimin_, phimax_)); + double dphi = reco::reduceRange(phi - fpgastub->phiapprox(phimin_, 0.0)); assert(std::abs(dphi) < 0.001); - phi = fpgastub->phiapprox(phimin_, phimax_); + phi = fpgastub->phiapprox(phimin_, 0.0); z = fpgastub->zapprox(); r = fpgastub->rapprox(); } if (phi < 0) phi += 2 * M_PI; - phi -= phioffset_; + phi -= phimin_; - double dr = r - tracklet->rproj(layer_); + double dr = r - settings_.rmean(layerdisk_); assert(std::abs(dr) < settings_.drmax()); - double dphi = reco::reduceRange(phi - (tracklet->phiproj(layer_) + dr * tracklet->phiprojder(layer_))); + double dphi = reco::reduceRange(phi - (proj.phiproj() + dr * proj.phiprojder())); - double dz = z - (tracklet->zproj(layer_) + dr * tracklet->zprojder(layer_)); + double dz = z - (proj.rzproj() + dr * proj.rzprojder()); - double dphiapprox = - reco::reduceRange(phi - (tracklet->phiprojapprox(layer_) + dr * tracklet->phiprojderapprox(layer_))); + double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dr * proj.phiprojderapprox())); - double dzapprox = z - (tracklet->zprojapprox(layer_) + dr * tracklet->zprojderapprox(layer_)); + double dzapprox = z - (proj.rzprojapprox() + dr * proj.rzprojderapprox()); int seedindex = tracklet->getISeed(); @@ -507,11 +509,11 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { bool truthmatch = tracklet->stubtruthmatch(stub); HistBase* hists = globals_->histograms(); - hists->FillLayerResidual(layer_, + hists->FillLayerResidual(layerdisk_ + 1, seedindex, - dphiapprox * settings_.rmean(layer_ - 1), - ideltaphi * settings_.kphi1() * settings_.rmean(layer_ - 1), - ideltaz * fact_ * settings_.kz(), + dphiapprox * settings_.rmean(layerdisk_), + ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_), + (ideltaz << dzshift_) * settings_.kz(), dz, truthmatch); } @@ -520,44 +522,42 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv()); globals_->ofstream("layerresiduals.txt") - << layer_ << " " << seedindex << " " << pt << " " - << ideltaphi * settings_.kphi1() * settings_.rmean(layer_ - 1) << " " - << dphiapprox * settings_.rmean(layer_ - 1) << " " - << phimatchcut_[seedindex] * settings_.kphi1() * settings_.rmean(layer_ - 1) << " " - << ideltaz * fact_ * settings_.kz() << " " << dz << " " << zmatchcut_[seedindex] * settings_.kz() << endl; + << layerdisk_ + 1 << " " << seedindex << " " << pt << " " + << ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_) << " " + << dphiapprox * settings_.rmean(layerdisk_) << " " + << phimatchcut_[seedindex] * settings_.kphi1() * settings_.rmean(layerdisk_) << " " + << (ideltaz << dzshift_) * settings_.kz() << " " << dz << " " << zmatchcut_[seedindex] * settings_.kz() + << endl; } - bool imatch = (std::abs(ideltaphi) <= phifact_ * phimatchcut_[seedindex]) && - (std::abs(ideltaz * fact_) <= rzfact_ * zmatchcut_[seedindex]); + bool imatch = ((unsigned int)std::abs(ideltaphi) <= phimatchcut_[seedindex]) && + ((unsigned int)std::abs(ideltaz << dzshift_) <= zmatchcut_[seedindex]); if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " ideltaphi cut " << ideltaphi << " " - << phimatchcut_[seedindex] << " ideltaz*fact cut " << ideltaz * fact_ << " " - << zmatchcut_[seedindex]; + << phimatchcut_[seedindex] << " ideltaz< 0.2 || std::abs(dphiapprox) > 0.2) { - edm::LogPrint("Tracklet") << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox; + //This would catch significant consistency problems in the configuration - helps to debug if there are problems. + if (std::abs(dphi) > 0.5 * settings_.dphisectorHG() || std::abs(dphiapprox) > 0.5 * settings_.dphisectorHG()) { + throw cms::Exception("LogicError") << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox + << endl; } - assert(std::abs(dphi) < 0.2); - assert(std::abs(dphiapprox) < 0.2); - if (imatch) { - tracklet->addMatch(layer_, + tracklet->addMatch(layerdisk_, ideltaphi, ideltaz, dphi, dz, dphiapprox, dzapprox, - (phiregion_ << 7) + fpgastub->stubindex().value(), - stub->r(), + (phiregion_ << N_BITSMEMADDRESS) + fpgastub->stubindex().value(), fpgastub); if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Accepted full match in layer " << getName() << " " << tracklet << " " - << iSector_; + edm::LogVerbatim("Tracklet") << "Accepted full match in layer " << getName() << " " << tracklet; } int iSeed = tracklet->getISeed(); @@ -574,35 +574,31 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { assert(stub->z() * tracklet->t() > 0.0); int sign = (tracklet->t() > 0.0) ? 1 : -1; - int disk = sign * disk_; + int disk = sign * (layerdisk_ - N_LAYER + 1); assert(disk != 0); //Perform integer calculations here int iz = fpgastub->z().value(); - int iphi = tracklet->fpgaphiprojdisk(disk).value(); - int shifttmp = 6; //TODO - express in terms of constants - assert(shifttmp >= 0); - int iphicorr = (iz * tracklet->fpgaphiprojderdisk(disk).value()) >> shifttmp; + const Projection& proj = tracklet->proj(layerdisk_); - iphi += iphicorr; + int iphi = proj.fpgaphiproj().value(); + int iphicorr = (iz * proj.fpgaphiprojder().value()) >> icorrshift_; - int ir = tracklet->fpgarprojdisk(disk).value(); - - int shifttmp2 = 7; //TODO - express in terms of constants - assert(shifttmp2 >= 0); - int ircorr = (iz * tracklet->fpgarprojderdisk(disk).value()) >> shifttmp2; + iphi += iphicorr; + int ir = proj.fpgarzproj().value(); + int ircorr = (iz * proj.fpgarzprojder().value()) >> icorzshift_; ir += ircorr; - int ideltaphi = fpgastub->phi().value() * settings_.kphi() / settings_.kphi() - iphi; + int ideltaphi = fpgastub->phi().value() - iphi; int irstub = fpgastub->r().value(); int ialphafact = 0; if (!stub->isPSmodule()) { assert(irstub < (int)N_DSS_MOD * 2); - if (disk_ <= 2) { + if (layerdisk_ - N_LAYER <= 1) { ialphafact = ialphafactinner_[irstub]; irstub = settings_.rDSSinner(irstub) / settings_.kr(); } else { @@ -614,8 +610,8 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { int ideltar = (irstub * settings_.kr()) / settings_.krprojshiftdisk() - ir; if (!stub->isPSmodule()) { - int ialphanew = fpgastub->alphanew().value(); - int iphialphacor = ((ideltar * ialphanew * ialphafact) >> settings_.alphashift()); + int ialpha = fpgastub->alpha().value(); + int iphialphacor = ((ideltar * ialpha * ialphafact) >> settings_.alphashift()); ideltaphi += iphialphacor; } @@ -626,36 +622,35 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { double r = stub->r(); if (settings_.useapprox()) { - double dphi = reco::reduceRange(phi - fpgastub->phiapprox(phimin_, phimax_)); + double dphi = reco::reduceRange(phi - fpgastub->phiapprox(phimin_, 0.0)); assert(std::abs(dphi) < 0.001); - phi = fpgastub->phiapprox(phimin_, phimax_); + phi = fpgastub->phiapprox(phimin_, 0.0); z = fpgastub->zapprox(); r = fpgastub->rapprox(); } if (phi < 0) phi += 2 * M_PI; - phi -= phioffset_; + phi -= phimin_; - double dz = z - sign * settings_.zmean(disk_ - 1); + double dz = z - sign * settings_.zmean(layerdisk_ - N_LAYER); if (std::abs(dz) > settings_.dzmax()) { - edm::LogProblem("Tracklet") << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " - << tracklet->getISeed(); + edm::LogProblem("Tracklet") << __FILE__ << ":" << __LINE__ << " " << name_ << " " << tracklet->getISeed(); edm::LogProblem("Tracklet") << "stub " << stub->z() << " disk " << disk << " " << dz; assert(std::abs(dz) < settings_.dzmax()); } - double phiproj = tracklet->phiprojdisk(disk) + dz * tracklet->phiprojderdisk(disk); - double rproj = tracklet->rprojdisk(disk) + dz * tracklet->rprojderdisk(disk); + double phiproj = proj.phiproj() + dz * proj.phiprojder(); + double rproj = proj.rzproj() + dz * proj.rzprojder(); double deltar = r - rproj; double dr = stub->r() - rproj; - double drapprox = stub->r() - (tracklet->rprojapproxdisk(disk) + dz * tracklet->rprojderapproxdisk(disk)); + double drapprox = stub->r() - (proj.rzprojapprox() + dz * proj.rzprojderapprox()); double dphi = reco::reduceRange(phi - phiproj); - double dphiapprox = - reco::reduceRange(phi - (tracklet->phiprojapproxdisk(disk) + dz * tracklet->phiprojderapproxdisk(disk))); + + double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dz * proj.phiprojderapprox())); double drphi = dphi * stub->r(); double drphiapprox = dphiapprox * stub->r(); @@ -686,9 +681,10 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv()); globals_->ofstream("diskresiduals.txt") - << disk_ << " " << stub->isPSmodule() << " " << tracklet->layer() << " " << abs(tracklet->disk()) << " " << pt - << " " << ideltaphi * settings_.kphi() * stub->r() << " " << drphiapprox << " " << drphicut << " " - << ideltar * settings_.krprojshiftdisk() << " " << deltar << " " << drcut << " " << endl; + << layerdisk_ - N_LAYER + 1 << " " << stub->isPSmodule() << " " << tracklet->layer() << " " + << abs(tracklet->disk()) << " " << pt << " " << ideltaphi * settings_.kphi() * stub->r() << " " << drphiapprox + << " " << drphicut << " " << ideltar * settings_.krprojshiftdisk() << " " << deltar << " " << drcut << " " + << endl; } bool match = (std::abs(drphi) < drphicut) && (std::abs(deltar) < drcut); @@ -705,26 +701,24 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { edm::LogVerbatim("Tracklet") << "MatchCalculator found match in disk " << getName(); } - if (std::abs(dphi) >= 0.25) { + if (std::abs(dphi) >= third*settings_.dphisectorHG()) { edm::LogPrint("Tracklet") << "dphi " << dphi << " ISeed " << tracklet->getISeed(); } - assert(std::abs(dphi) < 0.25); - assert(std::abs(dphiapprox) < 0.25); - - tracklet->addMatchDisk(disk, - ideltaphi, - ideltar, - drphi / stub->r(), - dr, - drphiapprox / stub->r(), - drapprox, - stub->alpha(settings_.stripPitch(stub->isPSmodule())), - (phiregion_ << 7) + fpgastub->stubindex().value(), - stub->z(), - fpgastub); + assert(std::abs(dphi) < third*settings_.dphisectorHG()); + assert(std::abs(dphiapprox) < third*settings_.dphisectorHG()); + + tracklet->addMatch(layerdisk_, + ideltaphi, + ideltar, + drphi / stub->r(), + dr, + drphiapprox / stub->r(), + drapprox, + (phiregion_ << N_BITSMEMADDRESS) + fpgastub->stubindex().value(), + fpgastub); + if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Accepted full match in disk " << getName() << " " << tracklet << " " - << iSector_; + edm::LogVerbatim("Tracklet") << "Accepted full match in disk " << getName() << " " << tracklet; } int iSeed = tracklet->getISeed(); diff --git a/L1Trigger/TrackFindingTracklet/src/MemoryBase.cc b/L1Trigger/TrackFindingTracklet/src/MemoryBase.cc index e7c0ee7b241ec..580dae3a8df7f 100644 --- a/L1Trigger/TrackFindingTracklet/src/MemoryBase.cc +++ b/L1Trigger/TrackFindingTracklet/src/MemoryBase.cc @@ -1,4 +1,5 @@ #include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" @@ -9,8 +10,8 @@ using namespace trklet; using namespace std; -MemoryBase::MemoryBase(string name, Settings const& settings, unsigned int iSector) : name_(name), settings_(settings) { - iSector_ = iSector; +MemoryBase::MemoryBase(string name, Settings const& settings) : name_(name), settings_(settings) { + iSector_ = 0; bx_ = 0; event_ = 0; } @@ -71,14 +72,7 @@ void MemoryBase::findAndReplaceAll(std::string& data, std::string toSearch, std: } void MemoryBase::openFile(bool first, std::string dirName, std::string filebase) { - if (not std::filesystem::exists(dirName)) { - int fail = system((string("mkdir -p ") + dirName).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirName; - } - - std::string fname = dirName + filebase; - fname += getName(); + std::string fname = filebase + getName(); findAndReplaceAll(fname, "PHIa", "PHIaa"); findAndReplaceAll(fname, "PHIb", "PHIbb"); @@ -96,16 +90,7 @@ void MemoryBase::openFile(bool first, std::string dirName, std::string filebase) fname += std::to_string(iSector_ + 1); fname += ".dat"; - if (first) { - bx_ = 0; - event_ = 1; - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else { - out_.open(fname, std::ofstream::app); - } + openfile(out_, first, dirName, dirName + fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc b/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc index b0a478f962424..20fb0b1082ce9 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc @@ -11,20 +11,8 @@ using namespace trklet; using namespace std; -ProcessBase::ProcessBase(string name, Settings const& settings, Globals* global, unsigned int iSector) - : name_(name), settings_(settings), globals_(global) { - iSector_ = iSector; - double dphi = 2 * M_PI / N_SECTOR; - double dphiHG = 0.5 * settings_.dphisectorHG() - M_PI / N_SECTOR; - phimin_ = iSector_ * dphi - dphiHG; - phimax_ = phimin_ + dphi + 2 * dphiHG; - phimin_ -= M_PI / N_SECTOR; - phimax_ -= M_PI / N_SECTOR; - if (phimin_ > M_PI) { - phimin_ -= 2 * M_PI; - phimax_ -= 2 * M_PI; - } -} +ProcessBase::ProcessBase(string name, Settings const& settings, Globals* global) + : name_(name), settings_(settings), globals_(global) {} unsigned int ProcessBase::nbits(unsigned int power) { if (power == 2) diff --git a/L1Trigger/TrackFindingTracklet/src/Projection.cc b/L1Trigger/TrackFindingTracklet/src/Projection.cc new file mode 100644 index 0000000000000..2f08e1a5348a2 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/Projection.cc @@ -0,0 +1,132 @@ + +#include "L1Trigger/TrackFindingTracklet/interface/Projection.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include + +using namespace std; +using namespace trklet; + +void Projection::init(Settings const& settings, + unsigned int layerdisk, + int iphiproj, + int irzproj, + int iphider, + int irzder, + double phiproj, + double rzproj, + double phiprojder, + double rzprojder, + double phiprojapprox, + double rzprojapprox, + double phiprojderapprox, + double rzprojderapprox, + bool isPSseed) { + assert(layerdisk < N_LAYER + N_DISK); + + valid_ = true; + + fpgaphiproj_.set(iphiproj, settings.nphibitsstub(layerdisk), true, __LINE__, __FILE__); + + if (layerdisk < N_LAYER) { + fpgarzproj_.set(irzproj, settings.nzbitsstub(layerdisk), false, __LINE__, __FILE__); + } else { + fpgarzproj_.set(irzproj, settings.nrbitsstub(layerdisk), false, __LINE__, __FILE__); + } + + if (layerdisk < N_LAYER) { + if (layerdisk < N_PSLAYER) { + fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL123(), false, __LINE__, __FILE__); + fpgarzprojder_.set(irzder, settings.nbitszprojderL123(), false, __LINE__, __FILE__); + } else { + fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL456(), false, __LINE__, __FILE__); + fpgarzprojder_.set(irzder, settings.nbitszprojderL456(), false, __LINE__, __FILE__); + } + } else { + fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL123(), false, __LINE__, __FILE__); + fpgarzprojder_.set(irzder, settings.nrbitsprojderdisk(), false, __LINE__, __FILE__); + } + + if (layerdisk < N_LAYER) { + ////Separate the vm projections into zbins + ////This determines the central bin: + ////int zbin=4+(zproj.value()>>(zproj.nbits()-3)); + ////But we need some range (particularly for L5L6 seed projecting to L1-L3): + int offset = isPSseed ? 1 : 4; + + int ztemp = fpgarzproj_.value() >> (fpgarzproj_.nbits() - settings.MEBinsBits() - NFINERZBITS); + unsigned int zbin1 = (1 << (settings.MEBinsBits() - 1)) + ((ztemp - offset) >> NFINERZBITS); + unsigned int zbin2 = (1 << (settings.MEBinsBits() - 1)) + ((ztemp + offset) >> NFINERZBITS); + + if (zbin1 >= settings.MEBins()) { + zbin1 = 0; //note that zbin1 is unsigned + } + if (zbin2 >= settings.MEBins()) { + zbin2 = settings.MEBins() - 1; + } + + assert(zbin1 <= zbin2); + assert(zbin2 - zbin1 <= 1); + + fpgarzbin1projvm_.set(zbin1, settings.MEBinsBits(), true, __LINE__, __FILE__); // first z bin + + int nextbin = zbin1 != zbin2; + fpgarzbin2projvm_.set(nextbin, 1, true, __LINE__, __FILE__); // need to check adjacent z bin? + + //fine vm z bits. Use 4 bits for fine position. starting at zbin 1 + int finez = ((1 << (settings.MEBinsBits() + NFINERZBITS - 1)) + ztemp) - (zbin1 << NFINERZBITS); + + fpgafinerzvm_.set(finez, NFINERZBITS + 1, true, __LINE__, __FILE__); // fine z postions starting at zbin1 + + } else { + //TODO the -3 and +3 should be evaluated and efficiency for matching hits checked. + //This code should be migrated in the ProjectionRouter + double roffset = 3.0; + int rbin1 = 8.0 * (irzproj * settings.krprojshiftdisk() - roffset - settings.rmindiskvm()) / + (settings.rmaxdisk() - settings.rmindiskvm()); + int rbin2 = 8.0 * (irzproj * settings.krprojshiftdisk() + roffset - settings.rmindiskvm()) / + (settings.rmaxdisk() - settings.rmindiskvm()); + + if (rbin1 < 0) { + rbin1 = 0; + } + rbin2 = clamp(rbin2, 0, 7); + + assert(rbin1 <= rbin2); + assert(rbin2 - rbin1 <= 1); + + int finer = 64 * + ((irzproj * settings.krprojshiftdisk() - settings.rmindiskvm()) - + rbin1 * (settings.rmaxdisk() - settings.rmindiskvm()) / 8.0) / + (settings.rmaxdisk() - settings.rmindiskvm()); + + finer = clamp(finer, 0, 15); + + int diff = rbin1 != rbin2; + if (irzder < 0) + rbin1 += 8; + + fpgarzbin1projvm_.set(rbin1, 4, true, __LINE__, __FILE__); // first r bin + fpgarzbin2projvm_.set(diff, 1, true, __LINE__, __FILE__); // need to check adjacent r bin + + fpgafinerzvm_.set(finer, 4, true, __LINE__, __FILE__); // fine r postions starting at rbin1 + } + + //fine phi bits + int projfinephi = + (fpgaphiproj_.value() >> + (fpgaphiproj_.nbits() - (settings.nbitsallstubs(layerdisk) + settings.nbitsvmme(layerdisk) + NFINEPHIBITS))) & + ((1 << NFINEPHIBITS) - 1); + fpgafinephivm_.set(projfinephi, NFINEPHIBITS, true, __LINE__, __FILE__); // fine phi postions + + phiproj_ = phiproj; + rzproj_ = rzproj; + phiprojder_ = phiprojder; + rzprojder_ = rzprojder; + + phiprojapprox_ = phiprojapprox; + rzprojapprox_ = rzprojapprox; + phiprojderapprox_ = phiprojderapprox; + rzprojderapprox_ = rzprojderapprox; +} diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc index 06856031b1e1d..711b0972bf715 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc @@ -10,8 +10,8 @@ using namespace std; using namespace trklet; -ProjectionRouter::ProjectionRouter(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector) { +ProjectionRouter::ProjectionRouter(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) { layerdisk_ = initLayerDisk(3); vmprojs_.resize(settings_.nvmme(layerdisk_), nullptr); @@ -81,7 +81,7 @@ void ProjectionRouter::execute() { for (auto& iproj : inputproj_) { for (unsigned int i = 0; i < iproj->nTracklets(); i++) { - if (allprojcount > settings_.maxStep("PR")) + if (allprojcount >= settings_.maxStep("PR")) continue; Tracklet* tracklet = iproj->getTracklet(i); @@ -89,29 +89,30 @@ void ProjectionRouter::execute() { FPGAWord fpgaphi; if (layerdisk_ < N_LAYER) { - fpgaphi = tracklet->fpgaphiproj(layerdisk_ + 1); + fpgaphi = tracklet->proj(layerdisk_).fpgaphiproj(); } else { int disk = layerdisk_ - (N_LAYER - 1); - fpgaphi = tracklet->fpgaphiprojdisk(disk); + + Projection& proj = tracklet->proj(layerdisk_); + fpgaphi = proj.fpgaphiproj(); //The next lines looks up the predicted bend based on: // 1 - r projections // 2 - phi derivative // 3 - the sign - i.e. if track is forward or backward - int rindex = (tracklet->fpgarprojdisk(disk).value() >> (tracklet->fpgarprojdisk(disk).nbits() - nrbits_)) & - ((1 << nrbits_) - 1); - int phiderindex = (tracklet->fpgaphiprojderdisk(disk).value() >> - (tracklet->fpgaphiprojderdisk(disk).nbits() - nphiderbits_)) & + int rindex = (proj.fpgarzproj().value() >> (proj.fpgarzproj().nbits() - nrbits_)) & ((1 << nrbits_) - 1); + + int phiderindex = (proj.fpgaphiprojder().value() >> (proj.fpgaphiprojder().nbits() - nphiderbits_)) & ((1 << nphiderbits_) - 1); - int signindex = (tracklet->fpgarprojderdisk(disk).value() < 0); + int signindex = (proj.fpgarzprojder().value() < 0); int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; int ibendproj = globals_->projectionRouterBendTable()->bendLoookup(disk - 1, bendindex); - tracklet->setBendIndex(ibendproj, disk); + proj.setBendIndex(ibendproj); } unsigned int iphivm = @@ -129,6 +130,11 @@ void ProjectionRouter::execute() { vmprojs_[iphivm]->addTracklet(tracklet, allprojcount); + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " projection to " << vmprojs_[iphivm]->getName() << " iphivm " + << iphivm; + } + allprojcount++; } } diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc index 6ddbcc3628cf2..78de56f0076db 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc @@ -36,7 +36,7 @@ void ProjectionRouterBendTable::init(Settings const& settings, double rinv = -phider * (2.0 * t); double stripPitch = (rproj < settings.rcrit()) ? settings.stripPitch(true) : settings.stripPitch(false); - double bendproj = 0.5 * bend(rproj, rinv, stripPitch); + double bendproj = bendstrip(rproj, rinv, stripPitch); int ibendproj = 2.0 * bendproj + 15.5; if (ibendproj < 0) diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionTemp.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionTemp.cc index e8f902f1dd27d..f43b6fd2056c6 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProjectionTemp.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProjectionTemp.cc @@ -9,7 +9,11 @@ ProjectionTemp::ProjectionTemp(Tracklet* proj, int projfinerz, unsigned int projfinephi, unsigned int iphi, - bool usesecond, + int shift, + bool usefirstMinus, + bool usefirstPlus, + bool usesecondMinus, + bool usesecondPlus, bool isPSseed) { proj_ = proj; slot_ = slot; @@ -17,7 +21,11 @@ ProjectionTemp::ProjectionTemp(Tracklet* proj, projfinerz_ = projfinerz; projfinephi_ = projfinephi; iphi_ = iphi; - usesecond_ = usesecond; + shift_ = shift; + use_[0][0] = usefirstMinus; + use_[0][1] = usefirstPlus; + use_[1][0] = usesecondMinus; + use_[1][1] = usesecondPlus; isPSseed_ = isPSseed; } @@ -28,6 +36,10 @@ ProjectionTemp::ProjectionTemp() { projfinerz_ = 0; projfinephi_ = 0; iphi_ = 0; - usesecond_ = false; + shift_ = 0; + use_[0][0] = false; + use_[0][1] = false; + use_[1][0] = false; + use_[1][1] = false; isPSseed_ = false; } diff --git a/L1Trigger/TrackFindingTracklet/src/PurgeDuplicate.cc b/L1Trigger/TrackFindingTracklet/src/PurgeDuplicate.cc index 8c3e3f76ae02f..c334a7c488b01 100644 --- a/L1Trigger/TrackFindingTracklet/src/PurgeDuplicate.cc +++ b/L1Trigger/TrackFindingTracklet/src/PurgeDuplicate.cc @@ -22,8 +22,8 @@ using namespace std; using namespace trklet; -PurgeDuplicate::PurgeDuplicate(std::string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector) {} +PurgeDuplicate::PurgeDuplicate(std::string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) {} void PurgeDuplicate::addOutput(MemoryBase* memory, std::string output) { if (settings_.writetrace()) { @@ -78,7 +78,7 @@ void PurgeDuplicate::addInput(MemoryBase* memory, std::string input) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input; } -void PurgeDuplicate::execute(std::vector& outputtracks_) { +void PurgeDuplicate::execute(std::vector& outputtracks_, unsigned int iSector) { inputtracklets_.clear(); inputtracks_.clear(); @@ -92,7 +92,7 @@ void PurgeDuplicate::execute(std::vector& outputtracks_) { continue; for (unsigned int j = 0; j < inputtrackfit->nTracks(); j++) { Track* aTrack = inputtrackfit->getTrack(j)->getTrack(); - aTrack->setSector(iSector_); + aTrack->setSector(iSector); inputtracks_.push_back(aTrack); } } @@ -326,14 +326,14 @@ void PurgeDuplicate::execute(std::vector& outputtracks_) { Tracklet* tracklet = inputtracklets_[itrk]; std::vector trackstublist = inputstublists_[itrk]; - HybridFit hybridFitter(iSector_, settings_, globals_); + HybridFit hybridFitter(iSector, settings_, globals_); hybridFitter.Fit(tracklet, trackstublist); // If the track was accepted (and thus fit), add to output if (tracklet->fit()) { // Add track to output if it wasn't merged into another Track* outtrack = tracklet->getTrack(); - outtrack->setSector(iSector_); + outtrack->setSector(iSector); if (trackInfo[itrk].second == true) outtrack->setDuplicate(true); else @@ -342,7 +342,7 @@ void PurgeDuplicate::execute(std::vector& outputtracks_) { // Add all tracks to standalone root file output outtrack->setStubIDpremerge(inputstubidslists_[itrk]); outtrack->setStubIDprefit(mergedstubidslists_[itrk]); - outputtracks_.push_back(outtrack); + outputtracks_.push_back(*outtrack); } } } @@ -362,7 +362,7 @@ void PurgeDuplicate::execute(std::vector& outputtracks_) { if (inputtracks_[itrk]->duplicate()) edm::LogPrint("Tracklet") << "WARNING: Track already tagged as duplicate!!"; - double phiBin = (inputtracks_[itrk]->phi0(settings_) - 2 * M_PI / 27 * iSector_) / (2 * M_PI / 9 / 50) + 9; + double phiBin = (inputtracks_[itrk]->phi0(settings_) - 2 * M_PI / 27 * iSector) / (2 * M_PI / 9 / 50) + 9; phiBin = std::max(phiBin, 0.); phiBin = std::min(phiBin, 34.); @@ -374,7 +374,7 @@ void PurgeDuplicate::execute(std::vector& outputtracks_) { inputtracks_[itrk]->setDuplicate(true); grid[(int)phiBin][(int)ptBin] = true; - double phiTest = inputtracks_[itrk]->phi0(settings_) - 2 * M_PI / 27 * iSector_; + double phiTest = inputtracks_[itrk]->phi0(settings_) - 2 * M_PI / 27 * iSector; if (phiTest < -2 * M_PI / 27) edm::LogVerbatim("Tracklet") << "track phi too small!"; if (phiTest > 2 * 2 * M_PI / 27) @@ -463,14 +463,14 @@ void PurgeDuplicate::execute(std::vector& outputtracks_) { if (inputtrackfits_[i]->getTrack(j)->getTrack()->duplicate() == 0) { if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector << " " << inputtrackfits_[i]->getTrack(j)->getISeed() << endl; fout.close(); } outputtracklets_[i]->addTrack(inputtrackfits_[i]->getTrack(j)); } //For root file: - outputtracks_.push_back(inputtrackfits_[i]->getTrack(j)->getTrack()); + outputtracks_.push_back(*inputtrackfits_[i]->getTrack(j)->getTrack()); } } } @@ -483,8 +483,14 @@ double PurgeDuplicate::getPhiRes(Tracklet* curTracklet, const Stub* curStub) { // Get phi position of stub stubphi = curStub->l1tstub()->phi(); // Get region that the stub is in (Layer 1->6, Disk 1->5) - int Layer = curStub->layer().value() + 1; - int Disk = curStub->disk().value(); + int Layer = curStub->layerdisk() + 1; + if (Layer > N_LAYER) { + Layer = 0; + } + int Disk = curStub->layerdisk() - (N_LAYER - 1); + if (Disk < 0) { + Disk = 0; + } // Get phi projection of tracklet int seedindex = curTracklet->seedIndex(); // If this stub is a seed stub, set projection=phi, so that res=0 @@ -499,13 +505,8 @@ double PurgeDuplicate::getPhiRes(Tracklet* curTracklet, const Stub* curStub) { (seedindex == 11 && (Layer == 2 || abs(Disk) == 1 || abs(Disk) == 2))) { phiproj = stubphi; // Otherwise, get projection of tracklet - } else if (Layer != 0) { - phiproj = curTracklet->phiproj(Layer); - } else if (Disk != 0) { - phiproj = curTracklet->phiprojdisk(Disk); } else { - throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Layer: " << Layer << " -- Disk: " << Disk - << " Stub is not layer or disk in getPhiRes"; + phiproj = curTracklet->proj(curStub->layerdisk()).phiproj(); } // Calculate residual phires = std::abs(stubphi - phiproj); diff --git a/L1Trigger/TrackFindingTracklet/src/Residual.cc b/L1Trigger/TrackFindingTracklet/src/Residual.cc new file mode 100644 index 0000000000000..1507d73bc4e6b --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/Residual.cc @@ -0,0 +1,44 @@ +#include "L1Trigger/TrackFindingTracklet/interface/Residual.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +using namespace std; +using namespace trklet; + +void Residual::init(Settings const& settings, + unsigned int layerdisk, + int iphiresid, + int irzresid, + int istubid, + double phiresid, + double rzresid, + double phiresidapprox, + double rzresidapprox, + const Stub* stubptr) { + assert(layerdisk < N_LAYER + N_DISK); + + if (valid_ && (std::abs(iphiresid) > std::abs(fpgaphiresid_.value()))) + return; + + valid_ = true; + + layerdisk_ = layerdisk; + + fpgaphiresid_.set(iphiresid, settings.phiresidbits(), false, __LINE__, __FILE__); + if (layerdisk < N_LAYER) { + fpgarzresid_.set(irzresid, settings.zresidbits(), false, __LINE__, __FILE__); + } else { + fpgarzresid_.set(irzresid, settings.rresidbits(), false, __LINE__, __FILE__); + } + + int nbitsid = 10; + fpgastubid_.set(istubid, nbitsid, true, __LINE__, __FILE__); + assert(!fpgaphiresid_.atExtreme()); + + phiresid_ = phiresid; + rzresid_ = rzresid; + + phiresidapprox_ = phiresidapprox; + rzresidapprox_ = rzresidapprox; + + stubptr_ = stubptr; +} diff --git a/L1Trigger/TrackFindingTracklet/src/SLHCEvent.cc b/L1Trigger/TrackFindingTracklet/src/SLHCEvent.cc index 966bc40bca0e6..4ea8f49d3f953 100644 --- a/L1Trigger/TrackFindingTracklet/src/SLHCEvent.cc +++ b/L1Trigger/TrackFindingTracklet/src/SLHCEvent.cc @@ -1,73 +1,28 @@ #include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h" - #include "FWCore/MessageLogger/interface/MessageLogger.h" using namespace std; using namespace trklet; -L1SimTrack::L1SimTrack() { - eventid_ = -1; - trackid_ = -1; -} - -L1SimTrack::L1SimTrack( - int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz) { - eventid_ = eventid; - trackid_ = trackid; - type_ = type; - pt_ = pt; - eta_ = eta; - phi_ = phi; - vx_ = vx; - vy_ = vy; - vz_ = vz; -} - -void L1SimTrack::write(ofstream& out) { - if (pt_ > -2.0) { - out << "SimTrack: " << eventid_ << "\t" << trackid_ << "\t" << type_ << "\t" << pt_ << "\t" << eta_ << "\t" << phi_ - << "\t" << vx_ << "\t" << vy_ << "\t" << vz_ << "\t" << endl; - } -} - -void L1SimTrack::write(ostream& out) { - if (pt_ > -2) { - out << "SimTrack: " << eventid_ << "\t" << trackid_ << "\t" << type_ << "\t" << pt_ << "\t" << eta_ << "\t" << phi_ - << "\t" << vx_ << "\t" << vy_ << "\t" << vz_ << "\t" << endl; - } -} - void SLHCEvent::addL1SimTrack( int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz) { - vx -= x_offset_; - vy -= y_offset_; L1SimTrack simtrack(eventid, trackid, type, pt, eta, phi, vx, vy, vz); simtracks_.push_back(simtrack); } -bool SLHCEvent::addStub(int layer, - int ladder, - int module, - int strip, - int eventid, - vector tps, - double pt, - double bend, +bool SLHCEvent::addStub(string DTClink, + int region, + int layerdisk, + string stubword, + int isPSmodule, + int isFlipped, double x, double y, double z, - int isPSmodule, - int isFlipped) { - if (layer > 999 && layer < 1999 && z < 0.0) { - layer += 1000; - } - - layer--; - x -= x_offset_; - y -= y_offset_; - - L1TStub stub( - eventid, tps, -1, -1, layer, ladder, module, strip, x, y, z, -1.0, -1.0, pt, bend, isPSmodule, isFlipped); + double bend, + double strip, + vector tps) { + L1TStub stub(DTClink, region, layerdisk, stubword, isPSmodule, isFlipped, x, y, z, bend, strip, tps); stubs_.push_back(stub); return true; @@ -76,13 +31,6 @@ bool SLHCEvent::addStub(int layer, SLHCEvent::SLHCEvent(istream& in) { string tmp; in >> tmp; - while (tmp == "Map:") { - in >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp; - in >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp; - } - if (tmp == "EndMap") { - in >> tmp; - } if (tmp != "Event:") { edm::LogVerbatim("Tracklet") << "Expected to read 'Event:' but found:" << tmp; if (tmp.empty()) { @@ -105,67 +53,44 @@ SLHCEvent::SLHCEvent(istream& in) { int eventid; int trackid; int type; - string pt_str; - string eta_str; - string phi_str; - string vx_str; - string vy_str; - string vz_str; double pt; double eta; double phi; double vx; double vy; double vz; - in >> eventid >> trackid >> type >> pt_str >> eta_str >> phi_str >> vx_str >> vy_str >> vz_str; - pt = strtod(pt_str.c_str(), nullptr); - eta = strtod(eta_str.c_str(), nullptr); - phi = strtod(phi_str.c_str(), nullptr); - vx = strtod(vx_str.c_str(), nullptr); - vy = strtod(vy_str.c_str(), nullptr); - vz = strtod(vz_str.c_str(), nullptr); - vx -= x_offset_; - vy -= y_offset_; + in >> eventid >> trackid >> type >> pt >> eta >> phi >> vx >> vy >> vz; L1SimTrack simtrack(eventid, trackid, type, pt, eta, phi, vx, vy, vz); simtracks_.push_back(simtrack); in >> tmp; } - int oldlayer = 0; - int oldladder = 0; - int oldmodule = 0; - int oldcbc = -1; - int count = 1; - double oldz = -1000.0; - //read stubs in >> tmp; - while (tmp != "StubEnd") { + while (tmp != "Stubend") { if (!in.good()) { - edm::LogVerbatim("Tracklet") << "File not good"; + edm::LogVerbatim("Tracklet") << "File not good (SLHCEvent)"; abort(); }; - if (!(tmp == "Stub:" || tmp == "StubEnd")) { + if (!(tmp == "Stub:" || tmp == "Stubend")) { edm::LogVerbatim("Tracklet") << "Expected to read 'Stub:' or 'StubEnd' but found:" << tmp; abort(); } - int layer; - int ladder; - int module; - int eventid; - vector tps; - int strip; - double pt; + string DTClink; + int region; + int layerdisk; + string stubword; + int isPSmodule; + int isFlipped; double x; double y; double z; double bend; - int isPSmodule; - int isFlipped; - + double strip; unsigned int ntps; + vector tps; - in >> layer >> ladder >> module >> strip >> eventid >> pt >> x >> y >> z >> bend >> isPSmodule >> isFlipped >> ntps; + in >> DTClink >> region >> layerdisk >> stubword >> isPSmodule >> isFlipped >> x >> y >> z >> bend >> strip >> ntps; for (unsigned int itps = 0; itps < ntps; itps++) { int tp; @@ -173,36 +98,14 @@ SLHCEvent::SLHCEvent(istream& in) { tps.push_back(tp); } - if (layer > 999 && layer < 1999 && z < 0.0) { //negative disk - layer += 1000; - } - - int cbc = strip / 126; - if (layer > 3 && layer == oldlayer && ladder == oldladder && module == oldmodule && cbc == oldcbc && - std::abs(oldz - z) < 1.0) { - count++; - } else { - oldlayer = layer; - oldladder = ladder; - oldmodule = module; - oldcbc = cbc; - oldz = z; - count = 1; - } - - layer--; - x -= x_offset_; - y -= y_offset_; - - L1TStub stub( - eventid, tps, -1, -1, layer, ladder, module, strip, x, y, z, -1.0, -1.0, pt, bend, isPSmodule, isFlipped); + L1TStub stub(DTClink, region, layerdisk, stubword, isPSmodule, isFlipped, x, y, z, bend, strip, tps); in >> tmp; double t = std::abs(stub.z()) / stub.r(); double eta = asinh(t); - if (std::abs(eta) < 2.6 && count <= 100) { + if (std::abs(eta) < 2.6) { stubs_.push_back(stub); } } @@ -219,21 +122,7 @@ void SLHCEvent::write(ofstream& out) { for (auto& stub : stubs_) { stub.write(out); } - out << "StubEnd" << endl; -} - -void SLHCEvent::write(ostream& out) { - out << "Event: " << eventnum_ << endl; - - for (auto& simtrack : simtracks_) { - simtrack.write(out); - } - out << "SimTrackEnd" << endl; - - for (auto& stub : stubs_) { - stub.write(out); - } - out << "StubEnd" << endl; + out << "Stubend" << endl; } unsigned int SLHCEvent::layersHit(int tpid, int& nlayers, int& ndisks) { @@ -283,11 +172,3 @@ unsigned int SLHCEvent::layersHit(int tpid, int& nlayers, int& ndisks) { return l1 + 2 * l2 + 4 * l3 + 8 * l4 + 16 * l5 + 32 * l6 + 64 * d1 + 128 * d2 + 256 * d3 + 512 * d4 + 1024 * d5; } - -int SLHCEvent::getSimtrackFromSimtrackid(int simtrackid, int eventid) const { - for (unsigned int i = 0; i < simtracks_.size(); i++) { - if (simtracks_[i].trackid() == simtrackid && simtracks_[i].eventid() == eventid) - return i; - } - return -1; -} diff --git a/L1Trigger/TrackFindingTracklet/src/Sector.cc b/L1Trigger/TrackFindingTracklet/src/Sector.cc index 9ecef0c857f3e..c0d874d16d8de 100644 --- a/L1Trigger/TrackFindingTracklet/src/Sector.cc +++ b/L1Trigger/TrackFindingTracklet/src/Sector.cc @@ -3,8 +3,10 @@ #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/DTCLinkMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" @@ -18,6 +20,7 @@ #include "L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/InputRouter.h" #include "L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h" #include "L1Trigger/TrackFindingTracklet/interface/VMRouter.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h" @@ -37,12 +40,18 @@ #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" #include "DataFormats/Math/interface/deltaPhi.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h" using namespace std; using namespace trklet; -Sector::Sector(unsigned int i, Settings const& settings, Globals* globals) : settings_(settings), globals_(globals) { - isector_ = i; +Sector::Sector(Settings const& settings, Globals* globals) : isector_(-1), settings_(settings), globals_(globals) {} + +Sector::~Sector() = default; + +void Sector::setSector(unsigned int isector) { + assert(isector < N_SECTOR); + isector_ = isector; double dphi = 2 * M_PI / N_SECTOR; double dphiHG = 0.5 * settings_.dphisectorHG() - M_PI / N_SECTOR; phimin_ = isector_ * dphi - dphiHG; @@ -51,75 +60,81 @@ Sector::Sector(unsigned int i, Settings const& settings, Globals* globals) : set phimax_ -= M_PI / N_SECTOR; phimin_ = reco::reduceRange(phimin_); phimax_ = reco::reduceRange(phimax_); - if (phimin_ > phimax_) + if (phimin_ > phimax_) { phimin_ -= 2 * M_PI; -} - -Sector::~Sector() { - for (auto& mem : MemoriesV_) { - mem->clean(); } } bool Sector::addStub(L1TStub stub, string dtc) { - bool add = false; + unsigned int layerdisk = stub.layerdisk(); - double phi = stub.phi(); - double dphi = 0.5 * settings_.dphisectorHG() - M_PI / N_SECTOR; + if (layerdisk < N_LAYER && globals_->phiCorr(layerdisk) == nullptr) { + globals_->phiCorr(layerdisk) = new VMRouterPhiCorrTable(settings_); - std::map >& ILindex = globals_->ILindex(); - std::vector& tmp = ILindex[dtc]; - if (tmp.empty()) { - for (unsigned int i = 0; i < IL_.size(); i++) { - if (IL_[i]->getName().find("_" + dtc) != string::npos) { - tmp.push_back(i); - } - } + int nbits = 3; + if (layerdisk >= N_PSLAYER) + nbits = 4; + globals_->phiCorr(layerdisk)->init(layerdisk + 1, nbits, 3); } - if (((phi > phimin_ - dphi) && (phi < phimax_ + dphi)) || - ((phi > 2 * M_PI + phimin_ - dphi) && (phi < 2 * M_PI + phimax_ + dphi))) { - Stub fpgastub(stub, settings_, phimin_, phimax_); - std::vector& tmp = ILindex[dtc]; - assert(!tmp.empty()); - for (int i : tmp) { - if (IL_[i]->addStub(settings_, globals_, stub, fpgastub, dtc)) - add = true; - } + Stub fpgastub(stub, settings_, *globals_); + + if (layerdisk < N_LAYER) { + FPGAWord r = fpgastub.r(); + int bendbin = fpgastub.bend().value(); + int rbin = (r.value() + (1 << (r.nbits() - 1))) >> (r.nbits() - 3); + const VMRouterPhiCorrTable& phiCorrTable = *globals_->phiCorr(layerdisk); + int iphicorr = phiCorrTable.getphiCorrValue(bendbin, rbin); + fpgastub.setPhiCorr(iphicorr); + } + + int nadd = 0; + for (unsigned int i = 0; i < DL_.size(); i++) { + const string& name = DL_[i]->getName(); + if (name.find("_" + dtc) == string::npos) + continue; + DL_[i]->addStub(stub, fpgastub); + nadd++; } - return add; + assert(nadd == 1); + + return true; } void Sector::addMem(string memType, string memName) { - if (memType == "InputLink:") { - addMemToVec(IL_, memName, settings_, isector_, phimin_, phimax_); + if (memType == "DTCLink:") { + addMemToVec(DL_, memName, settings_, phimin_, phimax_); + } else if (memType == "InputLink:") { + addMemToVec(IL_, memName, settings_, phimin_, phimax_); } else if (memType == "AllStubs:") { - addMemToVec(AS_, memName, settings_, isector_); + addMemToVec(AS_, memName, settings_); + } else if (memType == "AllInnerStubs:") { + addMemToVec(AIS_, memName, settings_); } else if (memType == "VMStubsTE:") { - addMemToVec(VMSTE_, memName, settings_, isector_); + addMemToVec(VMSTE_, memName, settings_); } else if (memType == "VMStubsME:") { - addMemToVec(VMSME_, memName, settings_, isector_); + addMemToVec(VMSME_, memName, settings_); } else if (memType == "StubPairs:" || memType == "StubPairsDisplaced:") { - addMemToVec(SP_, memName, settings_, isector_); + addMemToVec(SP_, memName, settings_); } else if (memType == "StubTriplets:") { - addMemToVec(ST_, memName, settings_, isector_); + addMemToVec(ST_, memName, settings_); } else if (memType == "TrackletParameters:") { - addMemToVec(TPAR_, memName, settings_, isector_); + addMemToVec(TPAR_, memName, settings_); } else if (memType == "TrackletProjections:") { - addMemToVec(TPROJ_, memName, settings_, isector_); + addMemToVec(TPROJ_, memName, settings_); } else if (memType == "AllProj:") { - addMemToVec(AP_, memName, settings_, isector_); + addMemToVec(AP_, memName, settings_); } else if (memType == "VMProjections:") { - addMemToVec(VMPROJ_, memName, settings_, isector_); + addMemToVec(VMPROJ_, memName, settings_); } else if (memType == "CandidateMatch:") { - addMemToVec(CM_, memName, settings_, isector_); + addMemToVec(CM_, memName, settings_); } else if (memType == "FullMatch:") { - addMemToVec(FM_, memName, settings_, isector_); + addMemToVec(FM_, memName, settings_); } else if (memType == "TrackFit:") { - addMemToVec(TF_, memName, settings_, isector_, phimin_, phimax_); + addMemToVec(TF_, memName, settings_, phimin_, phimax_); } else if (memType == "CleanTrack:") { - addMemToVec(CT_, memName, settings_, isector_, phimin_, phimax_); + addMemToVec(CT_, memName, settings_, phimin_, phimax_); } else { edm::LogPrint("Tracklet") << "Don't know of memory type: " << memType; exit(0); @@ -127,35 +142,37 @@ void Sector::addMem(string memType, string memName) { } void Sector::addProc(string procType, string procName) { - if (procType == "VMRouter:") { - addProcToVec(VMR_, procName, settings_, globals_, isector_); + if (procType == "InputRouter:") { + addProcToVec(IR_, procName, settings_, globals_); + } else if (procType == "VMRouter:") { + addProcToVec(VMR_, procName, settings_, globals_); } else if (procType == "VMRouterCM:") { - addProcToVec(VMRCM_, procName, settings_, globals_, isector_); + addProcToVec(VMRCM_, procName, settings_, globals_); } else if (procType == "TrackletEngine:") { - addProcToVec(TE_, procName, settings_, globals_, isector_); + addProcToVec(TE_, procName, settings_, globals_); } else if (procType == "TrackletEngineDisplaced:") { - addProcToVec(TED_, procName, settings_, globals_, isector_); + addProcToVec(TED_, procName, settings_, globals_); } else if (procType == "TripletEngine:") { - addProcToVec(TRE_, procName, settings_, globals_, isector_); + addProcToVec(TRE_, procName, settings_, globals_); } else if (procType == "TrackletCalculator:") { - addProcToVec(TC_, procName, settings_, globals_, isector_); + addProcToVec(TC_, procName, settings_, globals_); } else if (procType == "TrackletProcessor:") { - addProcToVec(TP_, procName, settings_, globals_, isector_); + addProcToVec(TP_, procName, settings_, globals_); } else if (procType == "TrackletCalculatorDisplaced:") { - addProcToVec(TCD_, procName, settings_, globals_, isector_); + addProcToVec(TCD_, procName, settings_, globals_); } else if (procType == "ProjectionRouter:") { - addProcToVec(PR_, procName, settings_, globals_, isector_); + addProcToVec(PR_, procName, settings_, globals_); } else if (procType == "MatchEngine:") { - addProcToVec(ME_, procName, settings_, globals_, isector_); + addProcToVec(ME_, procName, settings_, globals_); } else if (procType == "MatchCalculator:" || procType == "DiskMatchCalculator:") { //TODO should not be used in configurations - addProcToVec(MC_, procName, settings_, globals_, isector_); + addProcToVec(MC_, procName, settings_, globals_); } else if (procType == "MatchProcessor:") { - addProcToVec(MP_, procName, settings_, globals_, isector_); + addProcToVec(MP_, procName, settings_, globals_); } else if (procType == "FitTrack:") { - addProcToVec(FT_, procName, settings_, globals_, isector_); + addProcToVec(FT_, procName, settings_, globals_); } else if (procType == "PurgeDuplicate:") { - addProcToVec(PD_, procName, settings_, globals_, isector_); + addProcToVec(PD_, procName, settings_, globals_); } else { edm::LogPrint("Tracklet") << "Don't know of processing type: " << procType; exit(0); @@ -206,106 +223,114 @@ MemoryBase* Sector::getMem(string memName) { return nullptr; } -void Sector::writeInputStubs(bool first) { +void Sector::writeDTCStubs(bool first) { + for (auto& i : DL_) { + i->writeStubs(first, isector_); + } +} + +void Sector::writeIRStubs(bool first) { for (auto& i : IL_) { - i->writeStubs(first); + i->writeStubs(first, isector_); } } void Sector::writeVMSTE(bool first) { for (auto& i : VMSTE_) { - i->writeStubs(first); + i->writeStubs(first, isector_); } } void Sector::writeVMSME(bool first) { for (auto& i : VMSME_) { - i->writeStubs(first); + i->writeStubs(first, isector_); } } void Sector::writeAS(bool first) { for (auto& i : AS_) { - i->writeStubs(first); + i->writeStubs(first, isector_); + } +} + +void Sector::writeAIS(bool first) { + for (auto& i : AIS_) { + i->writeStubs(first, isector_); } } void Sector::writeSP(bool first) { for (auto& i : SP_) { - i->writeSP(first); + i->writeSP(first, isector_); } } void Sector::writeST(bool first) { for (auto& i : ST_) { - i->writeST(first); + i->writeST(first, isector_); } } void Sector::writeTPAR(bool first) { for (auto& i : TPAR_) { - i->writeTPAR(first); + i->writeTPAR(first, isector_); } } void Sector::writeTPROJ(bool first) { for (auto& i : TPROJ_) { - i->writeTPROJ(first); + i->writeTPROJ(first, isector_); } } void Sector::writeAP(bool first) { for (auto& i : AP_) { - i->writeAP(first); + i->writeAP(first, isector_); } } void Sector::writeVMPROJ(bool first) { for (auto& i : VMPROJ_) { - i->writeVMPROJ(first); + i->writeVMPROJ(first, isector_); } } void Sector::writeCM(bool first) { for (auto& i : CM_) { - i->writeCM(first); + i->writeCM(first, isector_); } } void Sector::writeMC(bool first) { for (auto& i : FM_) { - i->writeMC(first); + i->writeMC(first, isector_); } } void Sector::writeTF(bool first) { for (auto& i : TF_) { - i->writeTF(first); + i->writeTF(first, isector_); } } void Sector::writeCT(bool first) { for (auto& i : CT_) { - i->writeCT(first); + i->writeCT(first, isector_); } } void Sector::clean() { - if (settings_.writeMonitorData("NMatches")) { - int matchesL1 = 0; - int matchesL3 = 0; - int matchesL5 = 0; - for (auto& i : TPAR_) { - i->writeMatches(globals_, matchesL1, matchesL3, matchesL5); - } - globals_->ofstream("nmatchessector.txt") << matchesL1 << " " << matchesL3 << " " << matchesL5 << endl; - } - for (auto& mem : MemoriesV_) { mem->clean(); } } +void Sector::executeIR() { + for (auto& i : IR_) { + i->execute(); + } +} + void Sector::executeVMR() { if (settings_.writeMonitorData("IL")) { ofstream& out = globals_->ofstream("inputlink.txt"); @@ -341,13 +366,13 @@ void Sector::executeTRE() { void Sector::executeTP() { for (auto& i : TP_) { - i->execute(); + i->execute(isector_, phimin_, phimax_); } } void Sector::executeTC() { for (auto& i : TC_) { - i->execute(); + i->execute(isector_, phimin_, phimax_); } if (settings_.writeMonitorData("TrackProjOcc")) { @@ -360,7 +385,7 @@ void Sector::executeTC() { void Sector::executeTCD() { for (auto& i : TCD_) { - i->execute(); + i->execute(isector_, phimin_, phimax_); } } @@ -378,25 +403,25 @@ void Sector::executeME() { void Sector::executeMC() { for (auto& i : MC_) { - i->execute(); + i->execute(phimin_); } } void Sector::executeMP() { for (auto& i : MP_) { - i->execute(); + i->execute(isector_, phimin_); } } void Sector::executeFT() { for (auto& i : FT_) { - i->execute(); + i->execute(isector_); } } -void Sector::executePD(std::vector& tracks) { +void Sector::executePD(std::vector& tracks) { for (auto& i : PD_) { - i->execute(tracks); + i->execute(tracks, isector_); } } diff --git a/L1Trigger/TrackFindingTracklet/src/Stub.cc b/L1Trigger/TrackFindingTracklet/src/Stub.cc index 449b17fe79238..fe7595a7dd784 100644 --- a/L1Trigger/TrackFindingTracklet/src/Stub.cc +++ b/L1Trigger/TrackFindingTracklet/src/Stub.cc @@ -1,171 +1,110 @@ #include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" #include "DataFormats/Math/interface/deltaPhi.h" #include +#include using namespace std; using namespace trklet; Stub::Stub(Settings const& settings) : settings_(settings) {} -Stub::Stub(L1TStub& stub, Settings const& settings, double phiminsec, double phimaxsec) : settings_(settings) { - double r = stub.r(); - double z = stub.z(); - double sbend = stub.bend(); +Stub::Stub(L1TStub& stub, Settings const& settings, Globals& globals) : settings_(settings) { + const string& stubwordhex = stub.stubword(); - l1tstub_ = &stub; - - int bendbits = 4; - if (stub.isPSmodule()) - bendbits = 3; + const string stubwordbin = convertHexToBin(stubwordhex); - int ibend = bendencode(sbend, stub.isPSmodule()); + layerdisk_ = stub.layerdisk(); - bend_.set(ibend, bendbits, true, __LINE__, __FILE__); - - int layer = stub.layer() + 1; + int nbendbits = 4; + if (stub.isPSmodule()) + nbendbits = 3; - // hold the real values from L1Stub - double stubphi = stub.phi(); + int nalphabits = 0; - if (layer < 999) { - disk_.set(0, 4, false, __LINE__, __FILE__); + int nrbits = settings_.nrbitsstub(layerdisk_); + int nzbits = settings_.nzbitsstub(layerdisk_); + int nphibits = settings_.nphibitsstub(layerdisk_); - assert(layer > 0 && layer <= N_LAYER); - double rmin = settings_.rmean(layer - 1) - settings_.drmax(); - double rmax = settings_.rmean(layer - 1) + settings_.drmax(); + if (layerdisk_ >= N_LAYER && !stub.isPSmodule()) { + nalphabits = settings.nbitsalpha(); + nrbits = 7; + } - if (r < rmin || r > rmax) { - edm::LogProblem("Tracklet") << "Error r, rmin, rmeas, rmax :" << r << " " << rmin << " " << 0.5 * (rmin + rmax) - << " " << rmax; - } + int layer = stub.layer() + 1; - int irbits = settings_.nrbitsstub(layer - 1); + assert(nbendbits + nalphabits + nrbits + nzbits + nphibits == 36); - int ir = lround((1 << irbits) * ((r - settings_.rmean(layer - 1)) / (rmax - rmin))); + bitset<32> rbits(stubwordbin.substr(0, nrbits)); + bitset<32> zbits(stubwordbin.substr(nrbits, nzbits)); + bitset<32> phibits(stubwordbin.substr(nrbits + nzbits, nphibits)); + bitset<32> alphabits(stubwordbin.substr(nphibits + nzbits + nrbits, nalphabits)); + bitset<32> bendbits(stubwordbin.substr(nphibits + nzbits + nrbits + nalphabits, nbendbits)); - double zmin = -settings_.zlength(); - double zmax = settings_.zlength(); + int newbend = bendbits.to_ulong(); - if (z < zmin || z > zmax) { - edm::LogProblem("Tracklet") << "Error z, zmin, zmax :" << z << " " << zmin << " " << zmax; - } + int newr = rbits.to_ulong(); + if (layerdisk_ < N_LAYER) { + if (newr >= (1 << (nrbits - 1))) + newr = newr - (1 << nrbits); + } - int izbits = settings_.nzbitsstub(layer - 1); + int newz = zbits.to_ulong(); + if (newz >= (1 << (nzbits - 1))) + newz = newz - (1 << nzbits); - int iz = lround((1 << izbits) * z / (zmax - zmin)); + int newphi = phibits.to_ulong(); - if (z < zmin || z > zmax) { - edm::LogProblem("Tracklet") << "Error z, zmin, zmax :" << z << " " << zmin << " " << zmax; - } + int newalpha = alphabits.to_ulong(); + if (newalpha >= (1 << (nalphabits - 1))) + newalpha = newalpha - (1 << nalphabits); - assert(phimaxsec - phiminsec > 0.0); + l1tstub_ = &stub; - if (stubphi < phiminsec - (phimaxsec - phiminsec) / 6.0) { - stubphi += 2 * M_PI; + bend_.set(newbend, nbendbits, true, __LINE__, __FILE__); + + phi_.set(newphi, nphibits, true, __LINE__, __FILE__); + phicorr_.set(newphi, nphibits, true, __LINE__, __FILE__); + bool pos = false; + if (layerdisk_ > 5) { + pos = true; + int disk = layerdisk_ - 5; + if (stub.z() < 0.0) + disk = -disk; + disk_.set(disk, 4, false, __LINE__, __FILE__); + if (!stub.isPSmodule()) { + alpha_.set(newalpha, nalphabits, false, __LINE__, __FILE__); + nrbits = 4; } - assert((phimaxsec - phiminsec) > 0.0); - - int iphibits = settings_.nphibitsstub(layer - 1); - - double deltaphi = reco::reduceRange(stubphi - phiminsec); - - int iphi = (1 << iphibits) * deltaphi / (phimaxsec - phiminsec); - - layer_.set(layer - 1, 3, true, __LINE__, __FILE__); - r_.set(ir, irbits, false, __LINE__, __FILE__); - z_.set(iz, izbits, false, __LINE__, __FILE__); - phi_.set(iphi, iphibits, true, __LINE__, __FILE__); - - phicorr_.set(iphi, iphibits, true, __LINE__, __FILE__); - } else { - // Here we handle the hits on disks. - - int disk = stub.module(); - assert(disk > 0 && disk <= N_DISK); - int sign = 1; - if (z < 0.0) - sign = -1; - - double zmin = sign * (settings_.zmean(disk - 1) - sign * settings_.dzmax()); - double zmax = sign * (settings_.zmean(disk - 1) + sign * settings_.dzmax()); - - if ((z > zmax) || (z < zmin)) { - edm::LogProblem("Tracklet") << "Error disk z, zmax, zmin: " << z << " " << zmax << " " << zmin; - } - - int iz = - (1 << settings.nzbitsstub(disk + N_DISK)) * ((z - sign * settings_.zmean(disk - 1)) / std::abs(zmax - zmin)); - - assert(phimaxsec - phiminsec > 0.0); - if (stubphi < phiminsec - (phimaxsec - phiminsec) / 6.0) { - stubphi += 2 * M_PI; - } - - assert(phimaxsec - phiminsec > 0.0); - if (stubphi < phiminsec - (phimaxsec - phiminsec) / 6.0) { - stubphi += 2 * M_PI; - } - - int iphibits = settings_.nphibitsstub(disk + 5); - - double deltaphi = reco::reduceRange(stubphi - phiminsec); - - int iphi = (1 << iphibits) * deltaphi / (phimaxsec - phiminsec); - - double rmin = 0; - double rmax = settings_.rmaxdisk(); - - if (r < rmin || r > rmax) { - edm::LogProblem("Tracklet") << "Error disk r, rmin, rmax :" << r << " " << rmin << " " << rmax; - } - - int ir = (1 << settings_.nrbitsstub(disk + 5)) * (r - rmin) / (rmax - rmin); - - int irSS = -1; - if (!stub.isPSmodule()) { - for (unsigned int i = 0; i < N_DSS_MOD * 2; ++i) { - if (disk <= 2) { - if (std::abs(r - settings_.rDSSinner(i)) < 0.2) { - irSS = i; - break; - } - } else { - if (std::abs(r - settings_.rDSSouter(i)) < 0.2) { - irSS = i; - break; - } - } - } - if (irSS < 0) { - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " didn't find rDSS value! r = " << r - << " Check that correct geometry is used!"; + disk_.set(0, 4, false, __LINE__, __FILE__); + layer_.set(layer - 1, 3, true, __LINE__, __FILE__); + } + r_.set(newr, nrbits, pos, __LINE__, __FILE__); + z_.set(newz, nzbits, false, __LINE__, __FILE__); + + if (settings.writeMonitorData("StubBend")) { + unsigned int nsimtrks = globals.event()->nsimtracks(); + + for (unsigned int isimtrk = 0; isimtrk < nsimtrks; isimtrk++) { + const L1SimTrack& simtrk = globals.event()->simtrack(isimtrk); + if (stub.tpmatch2(simtrk.trackid())) { + double dr = 0.18; + double rinv = simtrk.charge() * 0.01 * settings_.c() * settings_.bfield() / simtrk.pt(); + double pitch = settings_.stripPitch(stub.isPSmodule()); + double bend = stub.r() * dr * 0.5 * rinv / pitch; + + globals.ofstream("stubbend.dat") << layerdisk_ << " " << stub.isPSmodule() << " " + << simtrk.pt() * simtrk.charge() << " " << bend << " " << newbend << " " + << settings.benddecode(newbend, layerdisk_, stub.isPSmodule()) << " " + << settings.bendcut(newbend, layerdisk_, stub.isPSmodule()) << endl; } } - if (irSS < 0) { - //PS modules - r_.set(ir, settings_.nrbitsstub(disk + N_DISK), true, __LINE__, __FILE__); - } else { - //SS modules - r_.set(irSS, 4, true, __LINE__, __FILE__); // in case of SS modules, store index, not r itself - } - - z_.set(iz, settings.nzbitsstub(disk + 5), false, __LINE__, __FILE__); - phi_.set(iphi, iphibits, true, __LINE__, __FILE__); - phicorr_.set(iphi, iphibits, true, __LINE__, __FILE__); - - disk_.set(sign * disk, 4, false, __LINE__, __FILE__); - - double alphanorm = stub.alphanorm(); - assert(std::abs(alphanorm) < 1.0); - int ialphanew = alphanorm * (1 << (settings.nbitsalpha() - 1)); - assert(ialphanew < (1 << (settings.nbitsalpha() - 1))); - assert(ialphanew >= -(1 << (settings.nbitsalpha() - 1))); - alphanew_.set(ialphanew, settings.nbitsalpha(), false, __LINE__, __FILE__); } } diff --git a/L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc b/L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc index 4e882c62789c8..40d81f17e3147 100644 --- a/L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc @@ -6,31 +6,17 @@ using namespace std; using namespace trklet; -StubPairsMemory::StubPairsMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) {} +StubPairsMemory::StubPairsMemory(string name, Settings const& settings) : MemoryBase(name, settings) {} -void StubPairsMemory::writeSP(bool first) { +void StubPairsMemory::writeSP(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirSP = settings_.memPath() + "StubPairs/"; std::ostringstream oss; oss << dirSP << "StubPairs_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirSP)) { - int fail = system((string("mkdir -p ") + dirSP).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirSP; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirSP, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/StubTripletsMemory.cc b/L1Trigger/TrackFindingTracklet/src/StubTripletsMemory.cc index cd6f8dcbb1cf1..73a63404b83c5 100644 --- a/L1Trigger/TrackFindingTracklet/src/StubTripletsMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/StubTripletsMemory.cc @@ -7,31 +7,17 @@ using namespace std; using namespace trklet; -StubTripletsMemory::StubTripletsMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) {} +StubTripletsMemory::StubTripletsMemory(string name, Settings const& settings) : MemoryBase(name, settings) {} -void StubTripletsMemory::writeST(bool first) { +void StubTripletsMemory::writeST(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirSP = settings_.memPath() + "StubPairs/"; std::ostringstream oss; oss << dirSP << "StubTriplets_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirSP)) { - int fail = system((string("mkdir -p ") + dirSP).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirSP; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirSP, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/TETableBase.cc b/L1Trigger/TrackFindingTracklet/src/TETableBase.cc index 6ece1f83d3b35..6e701edf0ee15 100644 --- a/L1Trigger/TrackFindingTracklet/src/TETableBase.cc +++ b/L1Trigger/TrackFindingTracklet/src/TETableBase.cc @@ -1,16 +1,15 @@ #include "L1Trigger/TrackFindingTracklet/interface/TETableBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" using namespace std; using namespace trklet; TETableBase::TETableBase(Settings const& settings) : settings_(settings) {} -void TETableBase::writeVMTable(std::string name, bool positive) { +void TETableBase::writeVMTable(const std::string& dir, const std::string& name, bool positive) { // Write LUT table. - ofstream out(name); - if (out.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << name; + ofstream out = openfile(dir, name, __FILE__, __LINE__); out << "{" << endl; for (unsigned int i = 0; i < table_.size(); i++) { diff --git a/L1Trigger/TrackFindingTracklet/src/Track.cc b/L1Trigger/TrackFindingTracklet/src/Track.cc index 58e1469936aae..61cb8d1521704 100644 --- a/L1Trigger/TrackFindingTracklet/src/Track.cc +++ b/L1Trigger/TrackFindingTracklet/src/Track.cc @@ -14,7 +14,7 @@ Track::Track(TrackPars ipars, double chisqrz, int hitpattern, std::map stubID, - const std::vector& l1stub, + const std::vector& l1stub, int seed) { ipars_ = ipars; ichisqrphi_ = ichisqrphi; diff --git a/L1Trigger/TrackFindingTracklet/src/TrackDerTable.cc b/L1Trigger/TrackFindingTracklet/src/TrackDerTable.cc index 03cac8804cbd3..3b39c761a80e7 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackDerTable.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackDerTable.cc @@ -1,11 +1,10 @@ #include "L1Trigger/TrackFindingTracklet/interface/TrackDerTable.h" #include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" -#include - using namespace std; using namespace trklet; @@ -359,17 +358,7 @@ void TrackDerTable::fillTable() { } if (settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } - - const string fnameL = settings_.tablePath() + "FitDerTableNew_LayerMem.tab"; - ofstream outL(fnameL); - if (outL.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fnameL; + ofstream outL = openfile(settings_.tablePath(), "FitDerTableNew_LayerMem.tab", __FILE__, __LINE__); int nbits = 6; for (unsigned int i = 0; i < LayerMem_.size(); i++) { @@ -382,10 +371,7 @@ void TrackDerTable::fillTable() { } outL.close(); - const string fnameD = settings_.tablePath() + "FitDerTableNew_DiskMem.tab"; - ofstream outD(fnameD); - if (outD.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fnameD; + ofstream outD = openfile(settings_.tablePath(), "FitDerTableNew_DiskMem.tab", __FILE__, __LINE__); nbits = 7; for (int tmp1 : DiskMem_) { @@ -397,10 +383,7 @@ void TrackDerTable::fillTable() { } outD.close(); - const string fnameLD = settings_.tablePath() + "FitDerTableNew_LayerDiskMem.tab"; - ofstream outLD(fnameLD); - if (outLD.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fnameLD; + ofstream outLD = openfile(settings_.tablePath(), "FitDerTableNew_LayerDiskMem.tab", __FILE__, __LINE__); nbits = 15; for (int tmp1 : LayerDiskMem_) { diff --git a/L1Trigger/TrackFindingTracklet/src/TrackFitMemory.cc b/L1Trigger/TrackFindingTracklet/src/TrackFitMemory.cc index 63505b224f8a1..55e95adadf29d 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackFitMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackFitMemory.cc @@ -7,34 +7,21 @@ using namespace std; using namespace trklet; -TrackFitMemory::TrackFitMemory(string name, Settings const& settings, unsigned int iSector, double phimin, double phimax) - : MemoryBase(name, settings, iSector) { +TrackFitMemory::TrackFitMemory(string name, Settings const& settings, double phimin, double phimax) + : MemoryBase(name, settings) { phimin_ = phimin; phimax_ = phimax; } -void TrackFitMemory::writeTF(bool first) { +void TrackFitMemory::writeTF(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirFT = settings_.memPath() + "FitTrack/"; std::ostringstream oss; oss << dirFT << "TrackFit_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirFT)) { - int fail = system((string("mkdir -p ") + dirFT).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirFT; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirFT, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc index a116a646fb23c..bc7ba9f5d1f1a 100644 --- a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc +++ b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc @@ -14,9 +14,7 @@ using namespace std; using namespace trklet; Tracklet::Tracklet(Settings const& settings, - const L1TStub* innerStub, - const L1TStub* middleStub, - const L1TStub* outerStub, + unsigned int iSeed, const Stub* innerFPGAStub, const Stub* middleFPGAStub, const Stub* outerFPGAStub, @@ -35,11 +33,12 @@ Tracklet::Tracklet(Settings const& settings, int id0, int iz0, int it, - LayerProjection layerprojs[N_PROJ], - DiskProjection diskprojs[N_PROJ], + Projection projs[N_LAYER + N_DISK], bool disk, bool overlap) : settings_(settings) { + seedIndex_ = iSeed; + overlap_ = overlap; disk_ = disk; assert(!(disk && overlap)); @@ -51,12 +50,9 @@ Tracklet::Tracklet(Settings const& settings, assert(disk_ || barrel_ || overlap_); - if (barrel_ && middleStub == nullptr) - assert(innerStub->layer() < N_LAYER); + if (barrel_ && middleFPGAStub == nullptr) + assert(innerFPGAStub->l1tstub()->layer() < N_LAYER); - innerStub_ = innerStub; - middleStub_ = middleStub; - outerStub_ = outerStub; innerFPGAStub_ = innerFPGAStub; middleFPGAStub_ = middleFPGAStub; outerFPGAStub_ = outerFPGAStub; @@ -73,15 +69,6 @@ Tracklet::Tracklet(Settings const& settings, fpgatrack_ = nullptr; - if (innerStub_) - assert(innerStub_->layer() < N_LAYER || innerStub_->disk() < N_DISK); - if (middleStub_) - assert(middleStub_->layer() < N_LAYER || middleStub_->disk() < N_DISK); - if (outerStub_) - assert(outerStub_->layer() < N_LAYER || outerStub_->disk() < N_DISK); - - seedIndex_ = calcSeedIndex(); - triplet_ = (seedIndex_ >= 8); //fill projection layers @@ -98,19 +85,19 @@ Tracklet::Tracklet(Settings const& settings, for (unsigned int i = 0; i < N_LAYER - 2; i++) { if (projlayer_[i] == 0) continue; - if (!layerprojs[i].valid()) + if (!projs[projlayer_[i] - 1].valid()) continue; - layerproj_[projlayer_[i] - 1] = layerprojs[i]; + proj_[projlayer_[i] - 1] = projs[projlayer_[i] - 1]; } //Now handle projections to the disks for (unsigned int i = 0; i < N_DISK; i++) { if (projdisk_[i] == 0) continue; - if (!diskprojs[i].valid()) + if (!projs[N_LAYER + projdisk_[i] - 1].valid()) continue; - diskproj_[projdisk_[i] - 1] = diskprojs[i]; + proj_[N_LAYER + projdisk_[i] - 1] = projs[N_LAYER + projdisk_[i] - 1]; } ichisqrphifit_.set(-1, 8, false); @@ -123,7 +110,7 @@ int Tracklet::tpseed() { set tpsetstubinner; set tpsetstubouter; - vector tps = innerStub_->tps(); + vector tps = innerFPGAStub_->l1tstub()->tps(); for (auto tp : tps) { if (tp != 0) { tpsetstubinner.insert(tp); @@ -131,7 +118,7 @@ int Tracklet::tpseed() { } } - tps = outerStub_->tps(); + tps = outerFPGAStub_->l1tstub()->tps(); for (auto tp : tps) { if (tp != 0) { tpsetstubouter.insert(tp); @@ -161,14 +148,14 @@ bool Tracklet::stubtruthmatch(const L1TStub* stub) { tpset.insert(abs(tp)); } } - tps = innerStub_->tps(); + tps = innerFPGAStub_->l1tstub()->tps(); for (auto tp : tps) { if (tp != 0) { tpsetstubinner.insert(tp); tpset.insert(abs(tp)); } } - tps = outerStub_->tps(); + tps = outerFPGAStub_->l1tstub()->tps(); for (auto tp : tps) { if (tp != 0) { tpsetstubouter.insert(tp); @@ -232,8 +219,8 @@ std::string Tracklet::vmstrlayer(int layer, unsigned int allstubindex) { //int irinvvm=16+(fpgarinv().value()>>(fpgarinv().nbits()-5)); // rinv is not directly available in the TrackletProjection. // can be inferred from phi derivative: rinv = - phider * 2 - int tmp_irinv = layerproj_[layer - 1].fpgaphiprojder().value() * (-2); - int nbits_irinv = layerproj_[layer - 1].fpgaphiprojder().nbits() + 1; + int tmp_irinv = proj_[layer - 1].fpgaphiprojder().value() * (-2); + int nbits_irinv = proj_[layer - 1].fpgaphiprojder().nbits() + 1; // irinv in VMProjection: // top 5 bits of rinv and shifted to be positive @@ -248,9 +235,9 @@ std::string Tracklet::vmstrlayer(int layer, unsigned int allstubindex) { assert(irinvvm < 32); FPGAWord tmp; tmp.set(irinvvm, 5, true, __LINE__, __FILE__); - std::string oss = index.str() + "|" + layerproj_[layer - 1].fpgazbin1projvm().str() + "|" + - layerproj_[layer - 1].fpgazbin2projvm().str() + "|" + layerproj_[layer - 1].fpgafinezvm().str() + - "|" + tmp.str() + "|" + std::to_string(PSseed()); + std::string oss = index.str() + "|" + proj_[layer - 1].fpgarzbin1projvm().str() + "|" + + proj_[layer - 1].fpgarzbin2projvm().str() + "|" + proj_[layer - 1].fpgafinerzvm().str() + "|" + + proj_[layer - 1].fpgafinephivm().str() + "|" + tmp.str() + "|" + std::to_string(PSseed()); return oss; } @@ -262,9 +249,10 @@ std::string Tracklet::vmstrdisk(int disk, unsigned int allstubindex) { } else { index.set(allstubindex, 7, true, __LINE__, __FILE__); } - std::string oss = index.str() + "|" + diskproj_[disk - 1].fpgarbin1projvm().str() + "|" + - diskproj_[disk - 1].fpgarbin2projvm().str() + "|" + diskproj_[disk - 1].fpgafinervm().str() + "|" + - diskproj_[disk - 1].getBendIndex().str(); + std::string oss = + index.str() + "|" + proj_[N_LAYER + disk - 1].fpgarzbin1projvm().str() + "|" + + proj_[N_LAYER + disk - 1].fpgarzbin2projvm().str() + "|" + proj_[N_LAYER + disk - 1].fpgafinerzvm().str() + "|" + + proj_[N_LAYER + disk - 1].fpgafinephivm().str() + "|" + proj_[N_LAYER + disk - 1].getBendIndex().str(); return oss; } @@ -278,9 +266,9 @@ std::string Tracklet::trackletprojstr(int layer) const { FPGAWord tcid; tcid.set(TCIndex_, settings_.nbitstcindex(), true, __LINE__, __FILE__); - std::string oss = tcid.str() + "|" + tmp.str() + "|" + layerproj_[layer - 1].fpgaphiproj().str() + "|" + - layerproj_[layer - 1].fpgazproj().str() + "|" + layerproj_[layer - 1].fpgaphiprojder().str() + "|" + - layerproj_[layer - 1].fpgazprojder().str(); + std::string oss = tcid.str() + "|" + tmp.str() + "|" + proj_[layer - 1].fpgaphiproj().str() + "|" + + proj_[layer - 1].fpgarzproj().str() + "|" + proj_[layer - 1].fpgaphiprojder().str() + "|" + + proj_[layer - 1].fpgarzprojder().str(); return oss; } @@ -292,76 +280,29 @@ std::string Tracklet::trackletprojstrD(int disk) const { } tmp.set(trackletIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); FPGAWord tcid; - tcid.set(TCIndex_, settings_.nbitstcindex(), true, __LINE__, __FILE__); - std::string oss = tcid.str() + "|" + tmp.str() + "|" + diskproj_[abs(disk) - 1].fpgaphiproj().str() + "|" + - diskproj_[abs(disk) - 1].fpgarproj().str() + "|" + diskproj_[abs(disk) - 1].fpgaphiprojder().str() + - "|" + diskproj_[abs(disk) - 1].fpgarprojder().str(); + if (settings_.extended()) { + tcid.set(TCIndex_, 8, true, __LINE__, __FILE__); + } else { + tcid.set(TCIndex_, 7, true, __LINE__, __FILE__); + } + std::string oss = tcid.str() + "|" + tmp.str() + "|" + proj_[N_LAYER + abs(disk) - 1].fpgaphiproj().str() + "|" + + proj_[N_LAYER + abs(disk) - 1].fpgarzproj().str() + "|" + + proj_[N_LAYER + abs(disk) - 1].fpgaphiprojder().str() + "|" + + proj_[N_LAYER + abs(disk) - 1].fpgarzprojder().str(); return oss; } -void Tracklet::addMatch(int layer, +void Tracklet::addMatch(unsigned int layerdisk, int ideltaphi, - int ideltaz, + int ideltarz, double dphi, - double dz, + double drz, double dphiapprox, - double dzapprox, + double drzapprox, int stubid, - double rstub, const trklet::Stub* stubptr) { - assert(layer > 0 && layer <= N_LAYER); - layerresid_[layer - 1].init( - settings_, layer, ideltaphi, ideltaz, stubid, dphi, dz, dphiapprox, dzapprox, rstub, stubptr); -} - -void Tracklet::addMatchDisk(int disk, - int ideltaphi, - int ideltar, - double dphi, - double dr, - double dphiapprox, - double drapprox, - double alpha, - int stubid, - double zstub, - const trklet::Stub* stubptr) { - assert(abs(disk) <= N_DISK); - diskresid_[abs(disk) - 1].init(settings_, - disk, - ideltaphi, - ideltar, - stubid, - dphi, - dr, - dphiapprox, - drapprox, - zstub, - alpha, - stubptr->alphanew(), - stubptr); -} - -int Tracklet::nMatches() { - int nmatches = 0; - - for (const auto& ilayerresid : layerresid_) { - if (ilayerresid.valid()) { - nmatches++; - } - } - - return nmatches; -} - -int Tracklet::nMatchesDisk() { - int nmatches = 0; - - for (const auto& idiskresid : diskresid_) { - if (idiskresid.valid()) { - nmatches++; - } - } - return nmatches; + assert(layerdisk < N_LAYER + N_DISK); + resid_[layerdisk].init(settings_, layerdisk, ideltaphi, ideltarz, stubid, dphi, drz, dphiapprox, drzapprox, stubptr); } std::string Tracklet::fullmatchstr(int layer) { @@ -374,9 +315,9 @@ std::string Tracklet::fullmatchstr(int layer) { tmp.set(trackletIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); FPGAWord tcid; tcid.set(TCIndex_, settings_.nbitstcindex(), true, __LINE__, __FILE__); - std::string oss = tcid.str() + "|" + tmp.str() + "|" + layerresid_[layer - 1].fpgastubid().str() + "|" + - layerresid_[layer - 1].stubptr()->r().str() + "|" + layerresid_[layer - 1].fpgaphiresid().str() + - "|" + layerresid_[layer - 1].fpgazresid().str(); + std::string oss = tcid.str() + "|" + tmp.str() + "|" + resid_[layer - 1].fpgastubid().str() + "|" + + resid_[layer - 1].stubptr()->r().str() + "|" + resid_[layer - 1].fpgaphiresid().str() + "|" + + resid_[layer - 1].fpgarzresid().str(); return oss; } @@ -390,32 +331,28 @@ std::string Tracklet::fullmatchdiskstr(int disk) { tmp.set(trackletIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); FPGAWord tcid; tcid.set(TCIndex_, settings_.nbitstcindex(), true, __LINE__, __FILE__); - const FPGAWord& stubr = diskresid_[disk - 1].stubptr()->r(); - const bool isPS = diskresid_[disk - 1].stubptr()->isPSmodule(); - std::string oss = tcid.str() + "|" + tmp.str() + "|" + diskresid_[disk - 1].fpgastubid().str() + "|" + + const FPGAWord& stubr = resid_[N_LAYER + disk - 1].stubptr()->r(); + const bool isPS = resid_[N_LAYER + disk - 1].stubptr()->isPSmodule(); + std::string oss = tcid.str() + "|" + tmp.str() + "|" + resid_[N_LAYER + disk - 1].fpgastubid().str() + "|" + (isPS ? stubr.str() : ("00000000" + stubr.str())) + "|" + - diskresid_[disk - 1].fpgaphiresid().str() + "|" + diskresid_[disk - 1].fpgarresid().str(); + resid_[N_LAYER + disk - 1].fpgaphiresid().str() + "|" + + resid_[N_LAYER + disk - 1].fpgarzresid().str(); return oss; } std::vector Tracklet::getL1Stubs() { std::vector tmp; - if (innerStub_) - tmp.push_back(innerStub_); - if (middleStub_) - tmp.push_back(middleStub_); - if (outerStub_) - tmp.push_back(outerStub_); - - for (const auto& ilayerresid : layerresid_) { - if (ilayerresid.valid()) - tmp.push_back(ilayerresid.stubptr()->l1tstub()); - } + if (innerFPGAStub_) + tmp.push_back(innerFPGAStub_->l1tstub()); + if (middleFPGAStub_) + tmp.push_back(middleFPGAStub_->l1tstub()); + if (outerFPGAStub_) + tmp.push_back(outerFPGAStub_->l1tstub()); - for (const auto& idiskresid : diskresid_) { - if (idiskresid.valid()) - tmp.push_back(idiskresid.stubptr()->l1tstub()); + for (const auto& iresid : resid_) { + if (iresid.valid()) + tmp.push_back(iresid.stubptr()->l1tstub()); } return tmp; @@ -429,37 +366,37 @@ std::map Tracklet::getStubIDs() { // E.g. An L3L4 track has 0=L1, 1=L2, 2=L4, 3=L5 for the barrels (for proj*_[i]) if (innerFPGAStub_) - assert(innerFPGAStub_->stubindex().nbits() == 7); + assert(innerFPGAStub_->stubindex().nbits() == N_BITSMEMADDRESS); if (middleFPGAStub_) - assert(middleFPGAStub_->stubindex().nbits() == 7); + assert(middleFPGAStub_->stubindex().nbits() == N_BITSMEMADDRESS); if (outerFPGAStub_) - assert(outerFPGAStub_->stubindex().nbits() == 7); + assert(outerFPGAStub_->stubindex().nbits() == N_BITSMEMADDRESS); if (barrel_) { for (int i = 0; i < N_LAYER; i++) { //check barrel - if (layerresid_[i].valid()) { + if (resid_[i].valid()) { // two extra bits to indicate if the matched stub is local or from neighbor int location = 1; // local - location <<= layerresid_[i].fpgastubid().nbits(); + location <<= resid_[i].fpgastubid().nbits(); - stubIDs[1 + i] = layerresid_[i].fpgastubid().value() + location; + stubIDs[1 + i] = resid_[i].fpgastubid().value() + location; } //check disk if (i >= N_DISK) continue; //i=[0..4] for disks - if (diskresid_[i].valid()) { - if (i == 3 && layerresid_[0].valid() && innerFPGAStub_->layer().value() == 1) + if (resid_[N_LAYER + i].valid()) { + if (i == 3 && resid_[0].valid() && innerFPGAStub_->layer().value() == 1) continue; // Don't add D4 if track has L1 stub // two extra bits to indicate if the matched stub is local or from neighbor int location = 1; // local - location <<= diskresid_[i].fpgastubid().nbits(); + location <<= resid_[N_LAYER + i].fpgastubid().nbits(); if (itfit().value() < 0) { - stubIDs[-11 - i] = diskresid_[i].fpgastubid().value() + location; + stubIDs[-(N_LAYER + N_DISK) - i] = resid_[N_LAYER + i].fpgastubid().value() + location; } else { - stubIDs[11 + i] = diskresid_[i].fpgastubid().value() + location; + stubIDs[N_LAYER + N_DISK + i] = resid_[N_LAYER + i].fpgastubid().value() + location; } } } @@ -475,26 +412,26 @@ std::map Tracklet::getStubIDs() { } else if (disk_) { for (int i = 0; i < N_DISK; i++) { //check barrel - if (layerresid_[i].valid()) { + if (resid_[i].valid()) { // two extra bits to indicate if the matched stub is local or from neighbor int location = 1; // local - location <<= layerresid_[i].fpgastubid().nbits(); + location <<= resid_[i].fpgastubid().nbits(); - stubIDs[1 + i] = layerresid_[i].fpgastubid().value() + location; + stubIDs[1 + i] = resid_[i].fpgastubid().value() + location; } //check disks - if (i == 4 && layerresid_[1].valid()) + if (i == 4 && resid_[1].valid()) continue; // Don't add D5 if track has L2 stub - if (diskresid_[i].valid()) { + if (resid_[N_LAYER + i].valid()) { // two extra bits to indicate if the matched stub is local or from neighbor int location = 1; // local - location <<= diskresid_[i].fpgastubid().nbits(); + location <<= resid_[N_LAYER + i].fpgastubid().nbits(); - if (innerStub_->disk() < 0) { - stubIDs[-11 - i] = diskresid_[i].fpgastubid().value() + location; + if (innerFPGAStub_->l1tstub()->disk() < 0) { + stubIDs[-11 - i] = resid_[N_LAYER + i].fpgastubid().value() + location; } else { - stubIDs[11 + i] = diskresid_[i].fpgastubid().value() + location; + stubIDs[11 + i] = resid_[N_LAYER + i].fpgastubid().value() + location; } } } @@ -519,28 +456,28 @@ std::map Tracklet::getStubIDs() { } else if (overlap_) { for (int i = 0; i < N_DISK; i++) { //check barrel - if (layerresid_[i].valid()) { + if (resid_[i].valid()) { // two extra bits to indicate if the matched stub is local or from neighbor int location = 1; // local - location <<= layerresid_[i].fpgastubid().nbits(); + location <<= resid_[i].fpgastubid().nbits(); - stubIDs[1 + i] = layerresid_[i].fpgastubid().value() + location; + stubIDs[1 + i] = resid_[i].fpgastubid().value() + location; } //check disks - if (diskresid_[i].valid()) { + if (resid_[N_LAYER + i].valid()) { // two extra bits to indicate if the matched stub is local or from neighbor int location = 1; // local - location <<= diskresid_[i].fpgastubid().nbits(); + location <<= resid_[N_LAYER + i].fpgastubid().nbits(); - if (innerStub_->disk() < 0) { // if negative overlap - if (innerFPGAStub_->layer().value() != 2 || !layerresid_[0].valid() || + if (innerFPGAStub_->l1tstub()->disk() < 0) { // if negative overlap + if (innerFPGAStub_->layer().value() != 2 || !resid_[0].valid() || i != 3) { // Don't add D4 if this is an L3L2 track with an L1 stub - stubIDs[-11 - i] = diskresid_[i].fpgastubid().value() + location; + stubIDs[-11 - i] = resid_[N_LAYER + i].fpgastubid().value() + location; } } else { - if (innerFPGAStub_->layer().value() != 2 || !layerresid_[0].valid() || i != 3) { - stubIDs[11 + i] = diskresid_[i].fpgastubid().value() + location; + if (innerFPGAStub_->layer().value() != 2 || !resid_[0].valid() || i != 3) { + stubIDs[11 + i] = resid_[N_LAYER + i].fpgastubid().value() + location; } } } @@ -636,7 +573,7 @@ const std::string Tracklet::layerstubstr(const unsigned layer) const { assert(layer < N_LAYER); std::stringstream oss(""); - if (!layerresid_[layer].valid()) + if (!resid_[layer].valid()) oss << "0|0000000|0000000000|0000000|000000000000|000000000"; else { if (trackIndex_ < 0 || trackIndex_ > (int)settings_.ntrackletmax()) { @@ -646,10 +583,10 @@ const std::string Tracklet::layerstubstr(const unsigned layer) const { const FPGAWord tmp(trackIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); oss << "1|"; // valid bit oss << tmp.str() << "|"; - oss << layerresid_[layer].fpgastubid().str() << "|"; - oss << layerresid_[layer].stubptr()->r().str() << "|"; - oss << layerresid_[layer].fpgaphiresid().str() << "|"; - oss << layerresid_[layer].fpgazresid().str(); + oss << resid_[layer].fpgastubid().str() << "|"; + oss << resid_[layer].stubptr()->r().str() << "|"; + oss << resid_[layer].fpgaphiresid().str() << "|"; + oss << resid_[layer].fpgarzresid().str(); } return oss.str(); @@ -659,7 +596,7 @@ const std::string Tracklet::diskstubstr(const unsigned disk) const { assert(disk < N_DISK); std::stringstream oss(""); - if (!diskresid_[disk].valid()) + if (!resid_[N_LAYER + disk].valid()) oss << "0|0000000|0000000000|000000000000|000000000000|0000000"; else { if (trackIndex_ < 0 || trackIndex_ > (int)settings_.ntrackletmax()) { @@ -667,14 +604,14 @@ const std::string Tracklet::diskstubstr(const unsigned disk) const { assert(0); } const FPGAWord tmp(trackIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); - const FPGAWord& stubr = diskresid_[disk].stubptr()->r(); - const bool isPS = diskresid_[disk].stubptr()->isPSmodule(); + const FPGAWord& stubr = resid_[N_LAYER + disk].stubptr()->r(); + const bool isPS = resid_[N_LAYER + disk].stubptr()->isPSmodule(); oss << "1|"; // valid bit oss << tmp.str() << "|"; - oss << diskresid_[disk].fpgastubid().str() << "|"; + oss << resid_[N_LAYER + disk].fpgastubid().str() << "|"; oss << (isPS ? stubr.str() : ("00000000" + stubr.str())) << "|"; - oss << diskresid_[disk].fpgaphiresid().str() << "|"; - oss << diskresid_[disk].fpgarresid().str(); + oss << resid_[N_LAYER + disk].fpgaphiresid().str() << "|"; + oss << resid_[N_LAYER + disk].fpgarzresid().str(); } return oss.str(); @@ -807,31 +744,42 @@ Track Tracklet::makeTrack(const vector& l1stubs) { fpgafitpars_.t().value(), fpgafitpars_.z0().value()); - Track tmpTrack( - ipars, - ichisqrphifit_.value(), - ichisqrzfit_.value(), - chisqrphifit_, - chisqrzfit_, - hitpattern_, - getStubIDs(), - (l1stubs.empty()) ? getL1Stubs() : l1stubs, // If fitter produced no stub list, take it from original tracklet. - getISeed()); + // If fitter produced no stub list, take it from original tracklet. + vector tmp = l1stubs.empty() ? getL1Stubs() : l1stubs; + + vector tmp2; + + for (auto stub : tmp) { + tmp2.push_back(*stub); + } + + Track tmpTrack(ipars, + ichisqrphifit_.value(), + ichisqrzfit_.value(), + chisqrphifit_, + chisqrzfit_, + hitpattern_, + getStubIDs(), + tmp2, + getISeed()); return tmpTrack; } int Tracklet::layer() const { - int l1 = (innerFPGAStub_ && innerFPGAStub_->isBarrel()) ? innerStub_->layer() + 1 : 999, - l2 = (middleFPGAStub_ && middleFPGAStub_->isBarrel()) ? middleStub_->layer() + 1 : 999, - l3 = (outerFPGAStub_ && outerFPGAStub_->isBarrel()) ? outerStub_->layer() + 1 : 999, l = min(min(l1, l2), l3); + int l1 = (innerFPGAStub_ && innerFPGAStub_->layerdisk() < N_LAYER) ? innerFPGAStub_->l1tstub()->layerdisk() + 1 : 999, + l2 = (middleFPGAStub_ && middleFPGAStub_->layerdisk() < N_LAYER) ? middleFPGAStub_->l1tstub()->layerdisk() + 1 + : 999, + l3 = (outerFPGAStub_ && outerFPGAStub_->layerdisk() < N_LAYER) ? outerFPGAStub_->l1tstub()->layerdisk() + 1 : 999, + l = min(min(l1, l2), l3); return (l < 999 ? l : 0); } int Tracklet::disk() const { - int d1 = (innerFPGAStub_ && innerFPGAStub_->isDisk()) ? innerStub_->disk() : 999, - d2 = (middleFPGAStub_ && middleFPGAStub_->isDisk()) ? middleStub_->disk() : 999, - d3 = (outerFPGAStub_ && outerFPGAStub_->isDisk()) ? outerStub_->disk() : 999, d = 999; + int d1 = (innerFPGAStub_ && (innerFPGAStub_->layerdisk() >= N_LAYER)) ? innerFPGAStub_->l1tstub()->disk() : 999, + d2 = (middleFPGAStub_ && (middleFPGAStub_->layerdisk() >= N_LAYER)) ? middleFPGAStub_->l1tstub()->disk() : 999, + d3 = (outerFPGAStub_ && (outerFPGAStub_->layerdisk() >= N_LAYER)) ? outerFPGAStub_->l1tstub()->disk() : 999, + d = 999; if (abs(d1) < min(abs(d2), abs(d3))) d = d1; if (abs(d2) < min(abs(d1), abs(d3))) @@ -841,25 +789,18 @@ int Tracklet::disk() const { return (d < 999 ? d : 0); } -int Tracklet::disk2() const { - if (innerStub_->disk() > 0) { - return innerStub_->disk() + 1; - } - return innerStub_->disk() - 1; -} - void Tracklet::setTrackletIndex(unsigned int index) { trackletIndex_ = index; assert(index <= settings_.ntrackletmax()); } -const int Tracklet::getISeed() const { +int Tracklet::getISeed() const { const int iSeed = TCIndex_ >> settings_.nbitsitc(); assert(iSeed >= 0 && iSeed <= (int)N_SEED); return iSeed; } -const int Tracklet::getITC() const { +int Tracklet::getITC() const { const int iSeed = getISeed(), iTC = TCIndex_ - (iSeed << settings_.nbitsitc()); assert(iTC >= 0 && iTC <= 14); return iTC; @@ -870,50 +811,4 @@ void Tracklet::setTrackIndex(int index) { assert(index <= (int)settings_.ntrackletmax()); } -const int Tracklet::trackIndex() const { return trackIndex_; } - -unsigned int Tracklet::calcSeedIndex() const { - int seedindex = -1; - int seedlayer = layer(); - int seeddisk = disk(); - - if (seedlayer == 1 && seeddisk == 0) - seedindex = 0; //L1L2 - if (seedlayer == 3 && seeddisk == 0) - seedindex = 2; //L3L4 - if (seedlayer == 5 && seeddisk == 0) - seedindex = 3; //L5L6 - if (seedlayer == 0 && abs(seeddisk) == 1) - seedindex = 4; //D1D2 - if (seedlayer == 0 && abs(seeddisk) == 3) - seedindex = 5; //D3D4 - if (seedlayer == 1 && abs(seeddisk) == 1) - seedindex = 6; //L1D1 - if (seedlayer == 2 && abs(seeddisk) == 1) - seedindex = 7; //L2D1 - if (seedlayer == 2 && abs(seeddisk) == 0) - seedindex = 1; //L2L3 - if (middleFPGAStub_ && seedlayer == 2 && seeddisk == 0) - seedindex = 8; // L3L4L2 - if (middleFPGAStub_ && seedlayer == 4 && seeddisk == 0) - seedindex = 9; // L5L6L4 - assert(innerFPGAStub_ != nullptr); - assert(outerFPGAStub_ != nullptr); - if (middleFPGAStub_ && seedlayer == 2 && abs(seeddisk) == 1) { - int l1 = (innerFPGAStub_ && innerFPGAStub_->isBarrel()) ? innerStub_->layer() + 1 : 999, - l2 = (middleFPGAStub_ && middleFPGAStub_->isBarrel()) ? middleStub_->layer() + 1 : 999, - l3 = (outerFPGAStub_ && outerFPGAStub_->isBarrel()) ? outerStub_->layer() + 1 : 999; - if (l1 + l2 + l3 < 1998) { // If two stubs are layer stubs - seedindex = 10; // L2L3D1 - } else { - seedindex = 11; // D1D2L2 - } - } - - if (seedindex < 0) { - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " seedlayer abs(seeddisk) : " << seedlayer - << " " << abs(seeddisk); - } - - return seedindex; -} +int Tracklet::trackIndex() const { return trackIndex_; } diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc b/L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc index edf75772c4758..2ad45e30c6717 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc @@ -14,8 +14,8 @@ using namespace std; using namespace trklet; -TrackletCalculator::TrackletCalculator(string name, Settings const& settings, Globals* globals, unsigned int iSector) - : TrackletCalculatorBase(name, settings, globals, iSector) { +TrackletCalculator::TrackletCalculator(string name, Settings const& settings, Globals* globals) + : TrackletCalculatorBase(name, settings, globals) { for (unsigned int ilayer = 0; ilayer < N_LAYER; ilayer++) { vector tmp(settings.nallstubs(ilayer), nullptr); trackletprojlayers_.push_back(tmp); @@ -43,7 +43,7 @@ TrackletCalculator::TrackletCalculator(string name, Settings const& settings, Gl } // write the drinv and invt inverse tables - if ((settings_.writeInvTable() || settings_.writeHLSInvTable()) && iTC_ == 0 && iSector_ == 0) { + if ((settings_.writeInvTable() || settings_.writeHLSInvTable() || settings_.writeTable()) && iTC_ == 0) { void (*writeLUT)(const VarInv&, const string&) = nullptr; if (settings.writeInvTable()) { // Verilog version writeLUT = [](const VarInv& x, const string& basename) -> void { @@ -61,7 +61,7 @@ TrackletCalculator::TrackletCalculator(string name, Settings const& settings, Gl // write the firmware design for the calculation of the tracklet parameters // and projections - if ((settings_.writeVerilog() || settings_.writeHLS()) && iTC_ == 0 && iSector_ == 0) { + if ((settings_.writeVerilog() || settings_.writeHLS()) && iTC_ == 0) { void (*writeDesign)(const vector&, const string&) = nullptr; if (settings.writeVerilog()) { // Verilog version writeDesign = [](const vector& v, const string& basename) -> void { @@ -151,10 +151,18 @@ void TrackletCalculator::addInput(MemoryBase* memory, string input) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find intput : " << input; } -void TrackletCalculator::execute() { +void TrackletCalculator::execute(unsigned int iSector, double phimin, double phimax) { unsigned int countall = 0; unsigned int countsel = 0; + phimin_ = phimin; + phimax_ = phimax; + iSector_ = iSector; + + //Helpfull to have for debugging the HLS code - will keep here for now. + //bool print = (iSector == 3) && (getName() == "TC_L1L2G"); + //print = false; + for (auto& stubpair : stubpairs_) { if (trackletpars_->nTracklets() >= settings_.ntrackletmax()) { edm::LogVerbatim("Tracklet") << "Will break on too many tracklets in " << getName(); @@ -169,11 +177,11 @@ void TrackletCalculator::execute() { const L1TStub* outerStub = outerFPGAStub->l1tstub(); if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "TrackletCalculator execute " << getName() << "[" << iSector_ << "]"; + edm::LogVerbatim("Tracklet") << "TrackletCalculator execute " << getName() << "[" << iSector << "]"; } - if (innerFPGAStub->isBarrel() && (getName() != "TC_D1L2A" && getName() != "TC_D1L2B")) { - if (outerFPGAStub->isDisk()) { + if (innerFPGAStub->layerdisk() < N_LAYER && (getName() != "TC_D1L2A" && getName() != "TC_D1L2B")) { + if (outerFPGAStub->layerdisk() >= N_LAYER) { //overlap seeding bool accept = overlapSeeding(outerFPGAStub, outerStub, innerFPGAStub, innerStub); if (accept) @@ -185,12 +193,12 @@ void TrackletCalculator::execute() { countsel++; } } else { - if (outerFPGAStub->isDisk()) { + if (outerFPGAStub->layerdisk() >= N_LAYER) { //disk+disk seeding bool accept = diskSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); if (accept) countsel++; - } else if (innerFPGAStub->isDisk()) { + } else if (innerFPGAStub->layerdisk() >= N_LAYER) { //layer+disk seeding bool accept = overlapSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); if (accept) diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc index 86299e4ce3293..24e397c30d433 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc @@ -14,11 +14,8 @@ using namespace std; using namespace trklet; -TrackletCalculatorBase::TrackletCalculatorBase(string name, - Settings const& settings, - Globals* global, - unsigned int iSector) - : ProcessBase(name, settings, global, iSector) {} +TrackletCalculatorBase::TrackletCalculatorBase(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) {} void TrackletCalculatorBase::exacttracklet(double r1, double z1, @@ -211,27 +208,29 @@ void TrackletCalculatorBase::exactprojdisk(double zproj, } void TrackletCalculatorBase::addDiskProj(Tracklet* tracklet, int disk) { - FPGAWord fpgar = tracklet->fpgarprojdisk(disk); + disk = std::abs(disk); + + FPGAWord fpgar = tracklet->proj(N_LAYER + disk - 1).fpgarzproj(); if (fpgar.value() * settings_.krprojshiftdisk() < settings_.rmindiskvm()) return; if (fpgar.value() * settings_.krprojshiftdisk() > settings_.rmaxdisk()) return; - FPGAWord fpgaphi = tracklet->fpgaphiprojdisk(disk); + FPGAWord fpgaphi = tracklet->proj(N_LAYER + disk - 1).fpgaphiproj(); int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5); - int iphi = iphivmRaw / (32 / settings_.nallstubs(abs(disk) + N_DISK)); + int iphi = iphivmRaw / (32 / settings_.nallstubs(disk + N_LAYER - 1)); - addProjectionDisk(disk, iphi, trackletprojdisks_[abs(disk) - 1][iphi], tracklet); + addProjectionDisk(disk, iphi, trackletprojdisks_[disk - 1][iphi], tracklet); } bool TrackletCalculatorBase::addLayerProj(Tracklet* tracklet, int layer) { assert(layer > 0); - FPGAWord fpgaz = tracklet->fpgazproj(layer); - FPGAWord fpgaphi = tracklet->fpgaphiproj(layer); + FPGAWord fpgaz = tracklet->proj(layer - 1).fpgarzproj(); + FPGAWord fpgaphi = tracklet->proj(layer - 1).fpgaphiproj(); if (fpgaphi.atExtreme()) edm::LogProblem("Tracklet") << "at extreme! " << fpgaphi.value(); @@ -333,12 +332,12 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, const Stub* outerFPGAStub, const L1TStub* outerStub) { if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "TrackletCalculator " << getName() + edm::LogVerbatim("Tracklet") << "TrackletCalculatorBase " << getName() << " trying stub pair in layer (inner outer): " << innerFPGAStub->layer().value() << " " << outerFPGAStub->layer().value(); } - assert(outerFPGAStub->isBarrel()); + assert(outerFPGAStub->layerdisk() < N_LAYER); assert(layerdisk1_ == (unsigned int)innerFPGAStub->layer().value()); assert(layerdisk1_ < N_LAYER && layerdisk2_ < N_LAYER); @@ -483,8 +482,7 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, //now binary int irinv, iphi0, it, iz0; - LayerProjection layerprojs[N_LAYER - 2]; - DiskProjection diskprojs[N_DISK]; + Projection projs[N_LAYER + N_DISK]; int iphiproj[N_LAYER - 2], izproj[N_LAYER - 2]; int iphiprojdisk[N_DISK], irprojdisk[N_DISK]; @@ -561,11 +559,18 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, izproj[3] = ITC->zL_3_final.ival(); if (!goodTrackPars(ITC->rinv_final.local_passes(), ITC->z0_final.local_passes())) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " Failed rinv or z0 cut"; + } return false; } - if (!inSector(iphi0, irinv, phi0approx, rinvapprox)) + if (!inSector(iphi0, irinv, phi0approx, rinvapprox)) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " Failed in sector check"; + } return false; + } for (unsigned int i = 0; i < N_LAYER - 2; ++i) { //reject projection if z is out of range @@ -587,22 +592,21 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, izproj[i] >>= (settings_.nzbitsstub(0) - settings_.nzbitsstub(5)); } - layerprojs[i].init(settings_, - settings_.projlayers(iSeed_, i), - settings_.rmean(settings_.projlayers(iSeed_, i) - 1), - iphiproj[i], - izproj[i], - ITC->der_phiL_final.ival(), - ITC->der_zL_final.ival(), - phiproj[i], - zproj[i], - phider[i], - zder[i], - phiprojapprox[i], - zprojapprox[i], - ITC->der_phiL_final.fval(), - ITC->der_zL_final.fval(), - !(iSeed_ == 1 || iSeed_ == 2)); + projs[settings_.projlayers(iSeed_, i) - 1].init(settings_, + settings_.projlayers(iSeed_, i) - 1, + iphiproj[i], + izproj[i], + ITC->der_phiL_final.ival(), + ITC->der_zL_final.ival(), + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + ITC->der_phiL_final.fval(), + ITC->der_zL_final.fval(), + !(iSeed_ == 2 || iSeed_ == 3)); } iphiprojdisk[0] = ITC->phiD_0_final.ival(); @@ -628,21 +632,21 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, irprojdisk[i] > settings_.rmaxdisk() / ITC->rD_0_final.K()) continue; - diskprojs[i].init(settings_, - i + 1, - settings_.zmean(i), - iphiprojdisk[i], - irprojdisk[i], - ITC->der_phiD_final.ival(), - ITC->der_rD_final.ival(), - phiprojdisk[i], - rprojdisk[i], - phiderdisk[i], - rderdisk[i], - phiprojdiskapprox[i], - rprojdiskapprox[i], - ITC->der_phiD_final.fval(), - ITC->der_rD_final.fval()); + projs[i + N_LAYER].init(settings_, + i + N_LAYER, + iphiprojdisk[i], + irprojdisk[i], + ITC->der_phiD_final.ival(), + ITC->der_rD_final.ival(), + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + ITC->der_phiD_final.fval(), + ITC->der_rD_final.fval(), + !(iSeed_ == 2 || iSeed_ == 3)); } } @@ -654,9 +658,7 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, } Tracklet* tracklet = new Tracklet(settings_, - innerStub, - nullptr, - outerStub, + iSeed_, innerFPGAStub, nullptr, outerFPGAStub, @@ -675,8 +677,7 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, 0, iz0, it, - layerprojs, - diskprojs, + projs, false); if (settings_.debugTracklet()) { @@ -719,7 +720,7 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, for (unsigned int j = 0; j < N_LAYER - 2; j++) { int lproj = settings_.projlayers(iSeed_, j); bool added = false; - if (tracklet->validProj(lproj)) { + if (tracklet->validProj(lproj - 1)) { added = addLayerProj(tracklet, lproj); if (added && lproj == 3) addL3 = true; @@ -744,7 +745,7 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, continue; if (it < 0) disk = -disk; - if (tracklet->validProjDisk(abs(disk))) { + if (tracklet->validProj(N_LAYER + abs(disk) - 1)) { addDiskProj(tracklet, disk); } } @@ -970,8 +971,7 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, if (!inSector(iphi0, irinv, phi0approx, rinvapprox)) return false; - LayerProjection layerprojs[N_LAYER - 2]; - DiskProjection diskprojs[N_DISK - 2]; + Projection projs[N_LAYER + N_DISK]; for (unsigned int i = 0; i < N_DISK - 2; ++i) { //Check is outside z range @@ -989,22 +989,21 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, //shift bits - allways in PS modules for disk seeding iphiproj[i] >>= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); - layerprojs[i].init(settings_, - i + 1, - settings_.rmean(i), - iphiproj[i], - izproj[i], - ITC->der_phiL_final.ival(), - ITC->der_zL_final.ival(), - phiproj[i], - zproj[i], - phider[i], - zder[i], - phiprojapprox[i], - zprojapprox[i], - ITC->der_phiL_final.fval(), - ITC->der_zL_final.fval(), - true); + projs[i].init(settings_, + i, + iphiproj[i], + izproj[i], + ITC->der_phiL_final.ival(), + ITC->der_zL_final.ival(), + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + ITC->der_phiL_final.fval(), + ITC->der_zL_final.fval(), + true); } iphiprojdisk[0] = ITC->phiD_0_final.ival(); @@ -1026,21 +1025,21 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, if (irprojdisk[i] <= 0 || irprojdisk[i] > settings_.rmaxdisk() / ITC->rD_0_final.K()) continue; - diskprojs[i].init(settings_, - i + 1, - settings_.zmean(settings_.projdisks(iSeed_, i) - 1), - iphiprojdisk[i], - irprojdisk[i], - ITC->der_phiD_final.ival(), - ITC->der_rD_final.ival(), - phiprojdisk[i], - rprojdisk[i], - phiderdisk[i], - rderdisk[i], - phiprojdiskapprox[i], - rprojdiskapprox[i], - ITC->der_phiD_final.fval(), - ITC->der_rD_final.fval()); + projs[settings_.projdisks(iSeed_, i) + N_LAYER - 1].init(settings_, + settings_.projdisks(iSeed_, i) + N_LAYER - 1, + iphiprojdisk[i], + irprojdisk[i], + ITC->der_phiD_final.ival(), + ITC->der_rD_final.ival(), + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + ITC->der_phiD_final.fval(), + ITC->der_rD_final.fval(), + true); } if (settings_.writeMonitorData("TPars")) { @@ -1052,9 +1051,7 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, } Tracklet* tracklet = new Tracklet(settings_, - innerStub, - nullptr, - outerStub, + iSeed_, innerFPGAStub, nullptr, outerFPGAStub, @@ -1073,8 +1070,7 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, 0, iz0, it, - layerprojs, - diskprojs, + projs, true); if (settings_.debugTracklet()) { @@ -1091,16 +1087,16 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, } trackletpars_->addTracklet(tracklet); - if (tracklet->validProj(1)) { + if (tracklet->validProj(0)) { addLayerProj(tracklet, 1); } - if (tracklet->validProj(2)) { + if (tracklet->validProj(1)) { addLayerProj(tracklet, 2); } for (unsigned int j = 0; j < N_DISK - 2; j++) { - if (tracklet->validProjDisk(sign * settings_.projdisks(iSeed_, j))) { + if (tracklet->validProj(N_LAYER + settings_.projdisks(iSeed_, j) - 1)) { addDiskProj(tracklet, sign * settings_.projdisks(iSeed_, j)); } } @@ -1113,9 +1109,9 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, const Stub* outerFPGAStub, const L1TStub* outerStub) { //Deal with overlap stubs here - assert(outerFPGAStub->isBarrel()); + assert(outerFPGAStub->layerdisk() < N_LAYER); - assert(innerFPGAStub->isDisk()); + assert(innerFPGAStub->layerdisk() >= N_LAYER); int disk = innerFPGAStub->disk().value(); @@ -1344,8 +1340,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, if (!inSector(iphi0, irinv, phi0approx, rinvapprox)) return false; - LayerProjection layerprojs[N_LAYER - 2]; - DiskProjection diskprojs[N_DISK]; + Projection projs[N_LAYER + N_DISK]; for (unsigned int i = 0; i < N_DISK - 2; ++i) { //check that zproj is in range @@ -1363,22 +1358,21 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, //adjust bits for PS modules (no 2S modules in overlap seeds) iphiproj[i] >>= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); - layerprojs[i].init(settings_, - i + 1, - settings_.rmean(i), - iphiproj[i], - izproj[i], - ITC->der_phiL_final.ival(), - ITC->der_zL_final.ival(), - phiproj[i], - zproj[i], - phider[i], - zder[i], - phiprojapprox[i], - zprojapprox[i], - ITC->der_phiL_final.fval(), - ITC->der_zL_final.fval(), - true); + projs[i].init(settings_, + i, + iphiproj[i], + izproj[i], + ITC->der_phiL_final.ival(), + ITC->der_zL_final.ival(), + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + ITC->der_phiL_final.fval(), + ITC->der_zL_final.fval(), + true); } for (int i = 0; i < 4; ++i) { @@ -1392,21 +1386,21 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, if (irprojdisk[i] <= 0 || irprojdisk[i] > settings_.rmaxdisk() / ITC->rD_0_final.K()) continue; - diskprojs[i].init(settings_, - i + 1, - settings_.zmean(i), - iphiprojdisk[i], - irprojdisk[i], - ITC->der_phiD_final.ival(), - ITC->der_rD_final.ival(), - phiprojdisk[i], - rprojdisk[i], - phiderdisk[i], - rderdisk[i], - phiprojdiskapprox[i], - rprojdiskapprox[i], - ITC->der_phiD_final.fval(), - ITC->der_rD_final.fval()); + projs[N_LAYER + i + 1].init(settings_, + N_LAYER + i + 1, + iphiprojdisk[i], + irprojdisk[i], + ITC->der_phiD_final.ival(), + ITC->der_rD_final.ival(), + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + ITC->der_phiD_final.fval(), + ITC->der_rD_final.fval(), + true); } if (settings_.writeMonitorData("TPars")) { @@ -1417,9 +1411,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, } Tracklet* tracklet = new Tracklet(settings_, - innerStub, - nullptr, - outerStub, + iSeed_, innerFPGAStub, nullptr, outerFPGAStub, @@ -1438,8 +1430,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, 0, iz0, it, - layerprojs, - diskprojs, + projs, false, true); @@ -1460,7 +1451,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, int layer = outerFPGAStub->layer().value() + 1; if (layer == 2) { - if (tracklet->validProj(1)) { + if (tracklet->validProj(0)) { addLayerProj(tracklet, 1); } } @@ -1468,7 +1459,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, for (unsigned int disk = 2; disk < 6; disk++) { if (layer == 2 && disk == 5) continue; - if (tracklet->validProjDisk(disk)) { + if (tracklet->validProj(N_LAYER + disk - 1)) { addDiskProj(tracklet, disk); } } diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc index 5c99dfd6238a4..56fd768ef6163 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc @@ -13,11 +13,8 @@ using namespace std; using namespace trklet; -TrackletCalculatorDisplaced::TrackletCalculatorDisplaced(string name, - Settings const& settings, - Globals* global, - unsigned int iSector) - : ProcessBase(name, settings, global, iSector) { +TrackletCalculatorDisplaced::TrackletCalculatorDisplaced(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) { for (unsigned int ilayer = 0; ilayer < N_LAYER; ilayer++) { vector tmp(settings.nallstubs(ilayer), nullptr); trackletprojlayers_.push_back(tmp); @@ -38,22 +35,22 @@ TrackletCalculatorDisplaced::TrackletCalculatorDisplaced(string name, disk_ = name1[4] - '0'; // set TC index - int iSeed = -1; + iSeed_ = 0; int iTC = name1[9] - 'A'; if (name1.substr(3, 6) == "L3L4L2") - iSeed = 8; + iSeed_ = 8; else if (name1.substr(3, 6) == "L5L6L4") - iSeed = 9; + iSeed_ = 9; else if (name1.substr(3, 6) == "L2L3D1") - iSeed = 10; + iSeed_ = 10; else if (name1.substr(3, 6) == "D1D2L2") - iSeed = 11; + iSeed_ = 11; - assert(iSeed != -1); + assert(iSeed_ != 0); - TCIndex_ = (iSeed << 4) + iTC; + TCIndex_ = (iSeed_ << 4) + iTC; assert(TCIndex_ >= 128 && TCIndex_ < 191); assert((layer_ != 0) || (disk_ != 0)); @@ -61,7 +58,7 @@ TrackletCalculatorDisplaced::TrackletCalculatorDisplaced(string name, toR_.clear(); toZ_.clear(); - if (iSeed == 8 || iSeed == 9) { + if (iSeed_ == 8 || iSeed_ == 9) { if (layer_ == 3) { rzmeanInv_[0] = 1.0 / settings_.rmean(2 - 1); rzmeanInv_[1] = 1.0 / settings_.rmean(3 - 1); @@ -100,7 +97,7 @@ TrackletCalculatorDisplaced::TrackletCalculatorDisplaced(string name, toR_.push_back(rproj_[i]); } - if (iSeed == 10 || iSeed == 11) { + if (iSeed_ == 10 || iSeed_ == 11) { if (layer_ == 2) { rzmeanInv_[0] = 1.0 / settings_.rmean(2 - 1); rzmeanInv_[1] = 1.0 / settings_.rmean(3 - 1); @@ -151,6 +148,7 @@ void TrackletCalculatorDisplaced::addOutput(MemoryBase* memory, string output) { edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " << output; } + if (output == "trackpar") { auto* tmp = dynamic_cast(memory); assert(tmp != nullptr); @@ -193,6 +191,7 @@ void TrackletCalculatorDisplaced::addInput(MemoryBase* memory, string input) { edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " << input; } + if (input == "thirdallstubin") { auto* tmp = dynamic_cast(memory); assert(tmp != nullptr); @@ -220,10 +219,14 @@ void TrackletCalculatorDisplaced::addInput(MemoryBase* memory, string input) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; } -void TrackletCalculatorDisplaced::execute() { +void TrackletCalculatorDisplaced::execute(unsigned int iSector, double phimin, double phimax) { unsigned int countall = 0; unsigned int countsel = 0; + phimin_ = phimin; + phimax_ = phimax; + iSector_ = iSector; + for (auto& stubtriplet : stubtriplets_) { if (trackletpars_->nTracklets() >= settings_.ntrackletmax()) { edm::LogVerbatim("Tracklet") << "Will break on too many tracklets in " << getName(); @@ -244,20 +247,24 @@ void TrackletCalculatorDisplaced::execute() { if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced execute " << getName() << "[" << iSector_ << "]"; - if (innerFPGAStub->isBarrel() && middleFPGAStub->isBarrel() && outerFPGAStub->isBarrel()) { + if (innerFPGAStub->layerdisk() < N_LAYER && middleFPGAStub->layerdisk() < N_LAYER && + outerFPGAStub->layerdisk() < N_LAYER) { //barrel+barrel seeding bool accept = LLLSeeding(innerFPGAStub, innerStub, middleFPGAStub, middleStub, outerFPGAStub, outerStub); if (accept) countsel++; - } else if (innerFPGAStub->isDisk() && middleFPGAStub->isDisk() && outerFPGAStub->isDisk()) { + } else if (innerFPGAStub->layerdisk() >= N_LAYER && middleFPGAStub->layerdisk() >= N_LAYER && + outerFPGAStub->layerdisk() >= N_LAYER) { throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!"; } else { //layer+disk seeding - if (innerFPGAStub->isBarrel() && middleFPGAStub->isDisk() && outerFPGAStub->isDisk()) { //D1D2L2 + if (innerFPGAStub->layerdisk() < N_LAYER && middleFPGAStub->layerdisk() >= N_LAYER && + outerFPGAStub->layerdisk() >= N_LAYER) { //D1D2L2 bool accept = DDLSeeding(innerFPGAStub, innerStub, middleFPGAStub, middleStub, outerFPGAStub, outerStub); if (accept) countsel++; - } else if (innerFPGAStub->isDisk() && middleFPGAStub->isBarrel() && outerFPGAStub->isBarrel()) { //L2L3D1 + } else if (innerFPGAStub->layerdisk() >= N_LAYER && middleFPGAStub->layerdisk() < N_LAYER && + outerFPGAStub->layerdisk() < N_LAYER) { //L2L3D1 bool accept = LLDSeeding(innerFPGAStub, innerStub, middleFPGAStub, middleStub, outerFPGAStub, outerStub); if (accept) countsel++; @@ -292,26 +299,27 @@ void TrackletCalculatorDisplaced::execute() { } void TrackletCalculatorDisplaced::addDiskProj(Tracklet* tracklet, int disk) { - FPGAWord fpgar = tracklet->fpgarprojdisk(disk); + disk = std::abs(disk); + FPGAWord fpgar = tracklet->proj(N_LAYER + disk - 1).fpgarzproj(); if (fpgar.value() * settings_.krprojshiftdisk() < settings_.rmindiskvm()) return; if (fpgar.value() * settings_.krprojshiftdisk() > settings_.rmaxdisk()) return; - FPGAWord fpgaphi = tracklet->fpgaphiprojdisk(disk); + FPGAWord fpgaphi = tracklet->proj(N_LAYER + disk - 1).fpgaphiproj(); int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5); - int iphi = iphivmRaw / (32 / settings_.nallstubs(abs(disk) + N_DISK)); + int iphi = iphivmRaw / (32 / settings_.nallstubs(disk + N_LAYER - 1)); - addProjectionDisk(disk, iphi, trackletprojdisks_[abs(disk) - 1][iphi], tracklet); + addProjectionDisk(disk, iphi, trackletprojdisks_[disk - 1][iphi], tracklet); } bool TrackletCalculatorDisplaced::addLayerProj(Tracklet* tracklet, int layer) { assert(layer > 0); - FPGAWord fpgaz = tracklet->fpgazproj(layer); - FPGAWord fpgaphi = tracklet->fpgaphiproj(layer); + FPGAWord fpgaz = tracklet->proj(layer - 1).fpgarzproj(); + FPGAWord fpgaphi = tracklet->proj(layer - 1).fpgaphiproj(); if (fpgaz.atExtreme()) return false; @@ -372,7 +380,7 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, << " trying stub triplet in layer (L L L): " << innerFPGAStub->layer().value() << " " << middleFPGAStub->layer().value() << " " << outerFPGAStub->layer().value(); - assert(outerFPGAStub->isBarrel()); + assert(outerFPGAStub->layerdisk() < N_LAYER); double r1 = innerStub->r(); double z1 = innerStub->z(); @@ -393,8 +401,7 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, double rinv, phi0, d0, t, z0; - LayerProjection layerprojs[N_LAYER - 2]; - DiskProjection diskprojs[N_DISK]; + Projection projs[N_LAYER + N_DISK]; double phiproj[N_LAYER - 2], zproj[N_LAYER - 2], phider[N_LAYER - 2], zder[N_LAYER - 2]; double phiprojdisk[N_DISK], rprojdisk[N_DISK], phiderdisk[N_DISK], rderdisk[N_DISK]; @@ -580,8 +587,9 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, success = false; } - if (!success) + if (!success) { return false; + } double phicritapprox = phi0approx - asin(0.5 * settings_.rcrit() * rinvapprox); int phicrit = iphi0 - 2 * irinv; @@ -598,11 +606,13 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, "but not approximate, phicritapprox: " << phicritapprox; if (settings_.usephicritapprox()) { - if (!keepapprox) + if (!keepapprox) { return false; + } } else { - if (!keep) + if (!keep) { return false; + } } for (unsigned int i = 0; i < toR_.size(); ++i) { @@ -649,21 +659,21 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, } } - layerprojs[i].init(settings_, - lproj_[i], - rproj_[i], - iphiproj[i], - izproj[i], - iphider[i], - izder[i], - phiproj[i], - zproj[i], - phider[i], - zder[i], - phiprojapprox[i], - zprojapprox[i], - phiderapprox[i], - zderapprox[i]); + projs[lproj_[i] - 1].init(settings_, + lproj_[i] - 1, + iphiproj[i], + izproj[i], + iphider[i], + izder[i], + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + phiderapprox[i], + zderapprox[i], + false); } if (std::abs(it * kt) > 1.0) { @@ -684,21 +694,21 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, if (rprojdiskapprox[i] < settings_.rmindisk() || rprojdiskapprox[i] > settings_.rmaxdisk()) continue; - diskprojs[i].init(settings_, - i + 1, - rproj_[i], - iphiprojdisk[i], - irprojdisk[i], - iphiderdisk[i], - irderdisk[i], - phiprojdisk[i], - rprojdisk[i], - phiderdisk[i], - rderdisk[i], - phiprojdiskapprox[i], - rprojdiskapprox[i], - phiderdisk[i], - rderdisk[i]); + projs[N_LAYER + i].init(settings_, + N_LAYER + i, + iphiprojdisk[i], + irprojdisk[i], + iphiderdisk[i], + irderdisk[i], + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + phiderdisk[i], + rderdisk[i], + false); } } @@ -709,9 +719,7 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, } Tracklet* tracklet = new Tracklet(settings_, - innerStub, - middleStub, - outerStub, + iSeed_, innerFPGAStub, middleFPGAStub, outerFPGAStub, @@ -730,8 +738,7 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, id0, iz0, it, - layerprojs, - diskprojs, + projs, false); if (settings_.debugTracklet()) @@ -752,9 +759,10 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, bool addL6 = false; for (unsigned int j = 0; j < toR_.size(); j++) { bool added = false; + if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "adding layer projection " << j << "/" << toR_.size() << " " << lproj_[j]; - if (tracklet->validProj(lproj_[j])) { + if (tracklet->validProj(lproj_[j] - 1)) { added = addLayerProj(tracklet, lproj_[j]); if (added && lproj_[j] == 5) addL5 = true; @@ -775,7 +783,7 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, disk = -disk; if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "adding disk projection " << j << "/" << toZ_.size() << " " << disk; - if (tracklet->validProjDisk(abs(disk))) { + if (tracklet->validProj(N_LAYER + abs(disk) - 1)) { addDiskProj(tracklet, disk); } } @@ -1020,8 +1028,7 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, return false; } - LayerProjection layerprojs[N_LAYER - 2]; - DiskProjection diskprojs[N_DISK]; + Projection projs[N_LAYER + N_DISK]; for (unsigned int i = 0; i < toR_.size(); ++i) { iphiproj[i] = phiprojapprox[i] / kphiproj; @@ -1060,21 +1067,21 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, iphider[i] = (1 << (settings_.nbitsphiprojderL456() - 1)) - 1; } - layerprojs[i].init(settings_, - lproj_[i], - rproj_[i], - iphiproj[i], - izproj[i], - iphider[i], - izder[i], - phiproj[i], - zproj[i], - phider[i], - zder[i], - phiprojapprox[i], - zprojapprox[i], - phiderapprox[i], - zderapprox[i]); + projs[lproj_[i] - 1].init(settings_, + lproj_[i] - 1, + iphiproj[i], + izproj[i], + iphider[i], + izder[i], + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + phiderapprox[i], + zderapprox[i], + false); } if (std::abs(it * kt) > 1.0) { @@ -1093,21 +1100,21 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, if (irprojdisk[i] < settings_.rmindisk() / krprojdisk || irprojdisk[i] > settings_.rmaxdisk() / krprojdisk) continue; - diskprojs[i].init(settings_, - i + 1, - rproj_[i], - iphiprojdisk[i], - irprojdisk[i], - iphiderdisk[i], - irderdisk[i], - phiprojdisk[i], - rprojdisk[i], - phiderdisk[i], - rderdisk[i], - phiprojdiskapprox[i], - rprojdiskapprox[i], - phiderdisk[i], - rderdisk[i]); + projs[N_LAYER + i + 2].init(settings_, + N_LAYER + i + 2, + iphiprojdisk[i], + irprojdisk[i], + iphiderdisk[i], + irderdisk[i], + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + phiderdisk[i], + rderdisk[i], + false); } } @@ -1118,9 +1125,7 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, } Tracklet* tracklet = new Tracklet(settings_, - innerStub, - middleStub, - outerStub, + iSeed_, innerFPGAStub, middleFPGAStub, outerFPGAStub, @@ -1139,8 +1144,7 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, id0, iz0, it, - layerprojs, - diskprojs, + projs, true); if (settings_.debugTracklet()) @@ -1160,8 +1164,8 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, for (unsigned int j = 0; j < toR_.size(); j++) { if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "adding layer projection " << j << "/" << toR_.size() << " " << lproj_[j] << " " - << tracklet->validProj(lproj_[j]); - if (tracklet->validProj(lproj_[j])) { + << tracklet->validProj(lproj_[j] - 1); + if (tracklet->validProj(lproj_[j] - 1)) { addLayerProj(tracklet, lproj_[j]); } } @@ -1174,8 +1178,8 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, disk = -disk; if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "adding disk projection " << j << "/" << toZ_.size() << " " << disk << " " - << tracklet->validProjDisk(abs(disk)); - if (tracklet->validProjDisk(abs(disk))) { + << tracklet->validProj(N_LAYER + abs(disk) - 1); + if (tracklet->validProj(N_LAYER + abs(disk) - 1)) { addDiskProj(tracklet, disk); } } @@ -1420,8 +1424,7 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, return false; } - LayerProjection layerprojs[N_LAYER - 2]; - DiskProjection diskprojs[N_DISK]; + Projection projs[N_LAYER + N_DISK]; for (unsigned int i = 0; i < toR_.size(); ++i) { iphiproj[i] = phiprojapprox[i] / kphiproj; @@ -1459,21 +1462,21 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, iphider[i] = (1 << (settings_.nbitsphiprojderL456() - 1)) - 1; } - layerprojs[i].init(settings_, - lproj_[i], - rproj_[i], - iphiproj[i], - izproj[i], - iphider[i], - izder[i], - phiproj[i], - zproj[i], - phider[i], - zder[i], - phiprojapprox[i], - zprojapprox[i], - phiderapprox[i], - zderapprox[i]); + projs[lproj_[i] - 1].init(settings_, + lproj_[i] - 1, + iphiproj[i], + izproj[i], + iphider[i], + izder[i], + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + phiderapprox[i], + zderapprox[i], + false); } if (std::abs(it * kt) > 1.0) { @@ -1494,21 +1497,21 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, if (irprojdisk[i] < settings_.rmindisk() / krprojdisk || irprojdisk[i] > settings_.rmaxdisk() / krprojdisk) continue; - diskprojs[i].init(settings_, - i + 1, - rproj_[i], - iphiprojdisk[i], - irprojdisk[i], - iphiderdisk[i], - irderdisk[i], - phiprojdisk[i], - rprojdisk[i], - phiderdisk[i], - rderdisk[i], - phiprojdiskapprox[i], - rprojdiskapprox[i], - phiderdisk[i], - rderdisk[i]); + projs[N_LAYER + i + 1].init(settings_, + N_LAYER + i + 1, + iphiprojdisk[i], + irprojdisk[i], + iphiderdisk[i], + irderdisk[i], + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + phiderdisk[i], + rderdisk[i], + false); } } @@ -1519,9 +1522,7 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, } Tracklet* tracklet = new Tracklet(settings_, - innerStub, - middleStub, - outerStub, + iSeed_, innerFPGAStub, middleFPGAStub, outerFPGAStub, @@ -1540,8 +1541,7 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, id0, iz0, it, - layerprojs, - diskprojs, + projs, false); if (settings_.debugTracklet()) @@ -1561,7 +1561,7 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, for (unsigned int j = 0; j < toR_.size(); j++) { if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "adding layer projection " << j << "/" << toR_.size() << " " << lproj_[j]; - if (tracklet->validProj(lproj_[j])) { + if (tracklet->validProj(lproj_[j] - 1)) { addLayerProj(tracklet, lproj_[j]); } } @@ -1574,7 +1574,7 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, disk = -disk; if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "adding disk projection " << j << "/" << toZ_.size() << " " << disk; - if (tracklet->validProjDisk(abs(disk))) { + if (tracklet->validProj(N_LAYER + abs(disk) - 1)) { addDiskProj(tracklet, disk); } } @@ -1679,8 +1679,18 @@ void TrackletCalculatorDisplaced::exacttracklet(double r1, double y2 = r2 * sin(phi2); double y3 = r3 * sin(phi3); - double k1 = -(x2 - x1) / (y2 - y1); - double k2 = -(x3 - x2) / (y3 - y2); + double dy21 = y2 - y1; + double dy32 = y3 - y2; + + //Hack to protect against dividing by zero + //code should be rewritten to avoid this + if (dy21 == 0.0) + dy21 = 1e-9; + if (dy32 == 0.0) + dy32 = 1e-9; + + double k1 = -(x2 - x1) / dy21; + double k2 = -(x3 - x2) / dy32; double b1 = 0.5 * (y2 + y1) - 0.5 * (x1 + x2) * k1; double b2 = 0.5 * (y3 + y2) - 0.5 * (x2 + x3) * k2; //their intersection gives the center of the circle diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc b/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc new file mode 100644 index 0000000000000..cfed9abbcaebb --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc @@ -0,0 +1,1294 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +using namespace std; +using namespace trklet; + +TrackletConfigBuilder::TrackletConfigBuilder(const Settings& settings) : settings_(settings) { + NSector_ = N_SECTOR; + rcrit_ = settings.rcrit(); + + combinedmodules_ = settings.combined(); + + extended_ = settings.extended(); + + rinvmax_ = settings.rinvmax(); + + rmaxdisk_ = settings.rmaxdisk(); + zlength_ = settings.zlength(); + + for (int i = 0; i < N_LAYER; i++) { + rmean_[i] = settings.rmean(i); + } + + for (int i = 0; i < N_DISK; i++) { + zmean_[i] = settings.zmean(i); + } + + dphisectorHG_ = settings.dphisectorHG(); + + for (int layerdisk = 0; layerdisk < N_LAYER + N_DISK; layerdisk++) { + NRegions_[layerdisk] = settings.nallstubs(layerdisk); + NVMME_[layerdisk] = settings.nvmme(layerdisk); + } + + for (unsigned int iseed = 0; iseed < N_SEED_PROMPT; iseed++) { + NVMTE_[iseed] = std::pair(settings.nvmte(0, iseed), settings.nvmte(1, iseed)); + NTC_[iseed] = settings.NTC(iseed); + } + + initGeom(); + + buildTE(); + + buildTC(); + + buildProjections(); +} + +std::pair TrackletConfigBuilder::seedLayers(unsigned int iSeed) { + return std::pair(settings_.seedlayers(0, iSeed), settings_.seedlayers(1, iSeed)); +} + +void TrackletConfigBuilder::initGeom() { + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + double dphi = dphisectorHG_ / NRegions_[ilayer]; + for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { + std::vector > emptyVec; + projections_[ilayer].push_back(emptyVec); + double phimin = dphi * iReg; + double phimax = phimin + dphi; + std::pair tmp(phimin, phimax); + allStubs_[ilayer].push_back(tmp); + double dphiVM = dphi / NVMME_[ilayer]; + for (unsigned int iVM = 0; iVM < NVMME_[ilayer]; iVM++) { + double phivmmin = phimin + iVM * dphiVM; + double phivmmax = phivmmin + dphiVM; + std::pair tmp(phivmmin, phivmmax); + VMStubsME_[ilayer].push_back(tmp); + } + } + } + for (unsigned int iseed = 0; iseed < N_SEED_PROMPT; iseed++) { + unsigned int l1 = seedLayers(iseed).first; + unsigned int l2 = seedLayers(iseed).second; + unsigned int nVM1 = NVMTE_[iseed].first; + unsigned int nVM2 = NVMTE_[iseed].second; + double dphiVM = dphisectorHG_ / (nVM1 * NRegions_[l1]); + for (unsigned int iVM = 0; iVM < nVM1 * NRegions_[l1]; iVM++) { + double phivmmin = iVM * dphiVM; + double phivmmax = phivmmin + dphiVM; + std::pair tmp(phivmmin, phivmmax); + VMStubsTE_[iseed].first.push_back(tmp); + } + dphiVM = dphisectorHG_ / (nVM2 * NRegions_[l2]); + for (unsigned int iVM = 0; iVM < nVM2 * NRegions_[l2]; iVM++) { + double phivmmin = iVM * dphiVM; + double phivmmax = phivmmin + dphiVM; + std::pair tmp(phivmmin, phivmmax); + VMStubsTE_[iseed].second.push_back(tmp); + } + } +} + +std::pair TrackletConfigBuilder::seedRadii(unsigned int iseed) { + std::pair seedlayers = seedLayers(iseed); + + unsigned int l1 = seedlayers.first; + unsigned int l2 = seedlayers.second; + + double r1, r2; + + if (iseed < 4) { //barrel seeding + r1 = rmean_[l1]; + r2 = rmean_[l2]; + } else if (iseed < 6) { //disk seeding + r1 = rmean_[0] + 40.0; //Somwwhat of a hack - but allows finding all the regions + //when projecting to L1 + r2 = r1 * zmean_[l2 - 6] / zmean_[l1 - 6]; + } else { //overlap seeding + r1 = rmean_[l1]; + r2 = r1 * zmean_[l2 - 6] / zlength_; + } + + return std::pair(r1, r2); +} + +bool TrackletConfigBuilder::validTEPair(unsigned int iseed, unsigned int iTE1, unsigned int iTE2) { + double rinvmin = 999.9; + double rinvmax = -999.9; + + double phi1[2] = {VMStubsTE_[iseed].first[iTE1].first, VMStubsTE_[iseed].first[iTE1].second}; + double phi2[2] = {VMStubsTE_[iseed].second[iTE2].first, VMStubsTE_[iseed].second[iTE2].second}; + + std::pair seedradii = seedRadii(iseed); + + for (unsigned int i1 = 0; i1 < 2; i1++) { + for (unsigned int i2 = 0; i2 < 2; i2++) { + double arinv = rinv(seedradii.first, phi1[i1], seedradii.second, phi2[i2]); + if (arinv < rinvmin) + rinvmin = arinv; + if (arinv > rinvmax) + rinvmax = arinv; + } + } + + if (rinvmin > rinvmax_) + return false; + if (rinvmax < -rinvmax_) + return false; + + return true; +} + +void TrackletConfigBuilder::buildTE() { + for (unsigned int iseed = 0; iseed < N_SEED_PROMPT; iseed++) { + for (unsigned int i1 = 0; i1 < VMStubsTE_[iseed].first.size(); i1++) { + for (unsigned int i2 = 0; i2 < VMStubsTE_[iseed].second.size(); i2++) { + if (validTEPair(iseed, i1, i2)) { + std::pair tmp(i1, i2); + TE_[iseed].push_back(tmp); + } + } + } + } +} + +void TrackletConfigBuilder::buildTC() { + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + unsigned int nTC = NTC_[iSeed]; + std::vector >& TEs = TE_[iSeed]; + std::vector >& TCs = TC_[iSeed]; + + //Very naive method to group TEs in TC + + double invnTC = nTC * (1.0 / TEs.size()); + + for (unsigned int iTE = 0; iTE < TEs.size(); iTE++) { + int iTC = invnTC * iTE; + assert(iTC < (int)nTC); + if (iTC >= (int)TCs.size()) { + std::vector tmp; + tmp.push_back(iTE); + TCs.push_back(tmp); + } else { + TCs[iTC].push_back(iTE); + } + } + } +} + +std::pair TrackletConfigBuilder::seedPhiRange(double rproj, unsigned int iSeed, unsigned int iTC) { + std::vector >& TCs = TC_[iSeed]; + + std::pair seedradii = seedRadii(iSeed); + + double phimin = 999.0; + double phimax = -999.0; + for (unsigned int iTE = 0; iTE < TCs[iTC].size(); iTE++) { + unsigned int theTE = TCs[iTC][iTE]; + unsigned int l1TE = TE_[iSeed][theTE].first; + unsigned int l2TE = TE_[iSeed][theTE].second; + double phi1[2] = {VMStubsTE_[iSeed].first[l1TE].first, VMStubsTE_[iSeed].first[l1TE].second}; + double phi2[2] = {VMStubsTE_[iSeed].second[l2TE].first, VMStubsTE_[iSeed].second[l2TE].second}; + for (unsigned int i1 = 0; i1 < 2; i1++) { + for (unsigned int i2 = 0; i2 < 2; i2++) { + double aphi = phi(seedradii.first, phi1[i1], seedradii.second, phi2[i2], rproj); + if (aphi < phimin) + phimin = aphi; + if (aphi > phimax) + phimax = aphi; + } + } + } + return std::pair(phimin, phimax); +} + +void TrackletConfigBuilder::buildProjections() { + for (unsigned int iseed = 0; iseed < N_SEED_PROMPT; iseed++) { + std::vector >& TCs = TC_[iseed]; + + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + if (matchport_[iseed][ilayer] == -1) + continue; + for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { + for (unsigned int iTC = 0; iTC < TCs.size(); iTC++) { + double rproj = rmaxdisk_; + if (ilayer < 6) + rproj = rmean_[ilayer]; + std::pair phiRange = seedPhiRange(rproj, iseed, iTC); + if (phiRange.first < allStubs_[ilayer][iReg].second && phiRange.second > allStubs_[ilayer][iReg].first) { + std::pair tmp(iseed, iTC); //seedindex and TC + projections_[ilayer][iReg].push_back(tmp); + } + } + } + } + } +} + +double TrackletConfigBuilder::phi(double r1, double phi1, double r2, double phi2, double r) { + double rhoinv = rinv(r1, phi1, r2, phi2); + if (fabs(rhoinv) > rinvmax_) { + rhoinv = rinvmax_ * rhoinv / fabs(rhoinv); + } + return phi1 + asin(0.5 * r * rhoinv) - asin(0.5 * r1 * rhoinv); +} + +double TrackletConfigBuilder::rinv(double r1, double phi1, double r2, double phi2) { + double deltaphi = phi1 - phi2; + return 2 * sin(deltaphi) / sqrt(r2 * r2 + r1 * r1 - 2 * r1 * r2 * cos(deltaphi)); +} + +std::string TrackletConfigBuilder::iSeedStr(unsigned int iSeed) { + static std::string name[8] = {"L1L2", "L2L3", "L3L4", "L5L6", "D1D2", "D3D4", "L1D1", "L2D1"}; + + assert(iSeed < 8); + return name[iSeed]; +} + +std::string TrackletConfigBuilder::numStr(unsigned int i) { + static std::string num[32] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", + "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", + "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"}; + assert(i < 32); + return num[i]; +} + +std::string TrackletConfigBuilder::iTCStr(unsigned int iTC) { + static std::string name[12] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}; + + assert(iTC < 12); + return name[iTC]; +} + +std::string TrackletConfigBuilder::iRegStr(unsigned int iReg, unsigned int iSeed) { + static std::string name[8] = {"A", "B", "C", "D", "E", "F", "G", "H"}; + + static std::string nameOverlap[8] = {"X", "Y", "Z", "W", "Q", "R", "S", "T"}; + + static std::string nameL2L3[4] = {"I", "J", "K", "L"}; + + if (iSeed == 1) { + assert(iReg < 4); + return nameL2L3[iReg]; + } + if (iSeed == 6 || iSeed == 7) { + assert(iReg < 8); + return nameOverlap[iReg]; + } + assert(iReg < 8); + return name[iReg]; +} + +std::string TrackletConfigBuilder::TCName(unsigned int iSeed, unsigned int iTC) { + if (combinedmodules_) { + return "TP_" + iSeedStr(iSeed) + iTCStr(iTC); + } else { + return "TC_" + iSeedStr(iSeed) + iTCStr(iTC); + } +} + +std::string TrackletConfigBuilder::LayerName(unsigned int ilayer) { + return ilayer < 6 ? ("L" + numStr(ilayer)) : ("D" + numStr(ilayer - 6)); +} + +std::string TrackletConfigBuilder::TPROJName(unsigned int iSeed, + unsigned int iTC, + unsigned int ilayer, + unsigned int ireg) { + return "TPROJ_" + iSeedStr(iSeed) + iTCStr(iTC) + "_" + LayerName(ilayer) + "PHI" + iTCStr(ireg); +} + +std::string TrackletConfigBuilder::PRName(unsigned int ilayer, unsigned int ireg) { + if (combinedmodules_) { + return "MP_" + LayerName(ilayer) + "PHI" + iTCStr(ireg); + } else { + return "PR_" + LayerName(ilayer) + "PHI" + iTCStr(ireg); + } +} + +void TrackletConfigBuilder::writeProjectionMemories(std::ostream& os, std::ostream& memories, std::ostream&) { + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (unsigned int ireg = 0; ireg < projections_[ilayer].size(); ireg++) { + for (unsigned int imem = 0; imem < projections_[ilayer][ireg].size(); imem++) { + unsigned int iSeed = projections_[ilayer][ireg][imem].first; + unsigned int iTC = projections_[ilayer][ireg][imem].second; + + memories << "TrackletProjections: " + TPROJName(iSeed, iTC, ilayer, ireg) + " [54]" << std::endl; + + os << TPROJName(iSeed, iTC, ilayer, ireg) << " input=> " << TCName(iSeed, iTC) << ".projout" + << LayerName(ilayer) << "PHI" << iTCStr(ireg) << " output=> " << PRName(ilayer, ireg) << ".projin" + << std::endl; + } + } + } +} + +std::string TrackletConfigBuilder::SPName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int iseed) { + return "SP_" + LayerName(l1) + "PHI" + iRegStr(ireg1, iseed) + numStr(ivm1) + "_" + LayerName(l2) + "PHI" + + iRegStr(ireg2, iseed) + numStr(ivm2); +} + +std::string TrackletConfigBuilder::SPDName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int l3, + unsigned int ireg3, + unsigned int ivm3, + unsigned int iseed) { + return "SPD_" + LayerName(l1) + "PHI" + iRegStr(ireg1, iseed) + numStr(ivm1) + "_" + LayerName(l2) + "PHI" + + iRegStr(ireg2, iseed) + numStr(ivm2) + "_" + LayerName(l3) + "PHI" + iRegStr(ireg3, iseed) + numStr(ivm3); +} + +std::string TrackletConfigBuilder::TEName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int iseed) { + return "TE_" + LayerName(l1) + "PHI" + iRegStr(ireg1, iseed) + numStr(ivm1) + "_" + LayerName(l2) + "PHI" + + iRegStr(ireg2, iseed) + numStr(ivm2); +} + +std::string TrackletConfigBuilder::TEDName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int iseed) { + return "TED_" + LayerName(l1) + "PHI" + iRegStr(ireg1, iseed) + numStr(ivm1) + "_" + LayerName(l2) + "PHI" + + iRegStr(ireg2, iseed) + numStr(ivm2); +} + +std::string TrackletConfigBuilder::TParName(unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc) { + return "TPAR_" + LayerName(l1) + LayerName(l2) + LayerName(l3) + iTCStr(itc); +} + +std::string TrackletConfigBuilder::TCDName(unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc) { + return "TCD_" + LayerName(l1) + LayerName(l2) + LayerName(l3) + iTCStr(itc); +} + +std::string TrackletConfigBuilder::TPROJName( + unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc, unsigned int projlayer, unsigned int projreg) { + return "TPROJ_" + LayerName(l1) + LayerName(l2) + LayerName(l3) + iTCStr(itc) + "_" + LayerName(projlayer) + "PHI" + + iTCStr(projreg); +} + +std::string TrackletConfigBuilder::FTName(unsigned int l1, unsigned int l2, unsigned int l3) { + return "FT_" + LayerName(l1) + LayerName(l2) + LayerName(l3); +} + +std::string TrackletConfigBuilder::TREName( + unsigned int l1, unsigned int ireg1, unsigned int l2, unsigned int ireg2, unsigned int iseed, unsigned int count) { + return "TRE_" + LayerName(l1) + iRegStr(ireg1, iseed) + LayerName(l2) + iRegStr(ireg2, iseed) + "_" + numStr(count); +} + +std::string TrackletConfigBuilder::STName(unsigned int l1, + unsigned int ireg1, + unsigned int l2, + unsigned int ireg2, + unsigned int l3, + unsigned int ireg3, + unsigned int iseed, + unsigned int count) { + return "ST_" + LayerName(l1) + iRegStr(ireg1, iseed) + LayerName(l2) + iRegStr(ireg2, iseed) + "_" + LayerName(l3) + + iRegStr(ireg3, iseed) + "_" + numStr(count); +} + +std::string TrackletConfigBuilder::TCNAme(unsigned int iseed, unsigned int iTC) { + return "TC_" + iSeedStr(iseed) + iTCStr(iTC); +} + +void TrackletConfigBuilder::writeSPMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { + if (combinedmodules_) + return; + + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) { + for (unsigned int iTE = 0; iTE < TC_[iSeed][iTC].size(); iTE++) { + unsigned int theTE = TC_[iSeed][iTC][iTE]; + + unsigned int TE1 = TE_[iSeed][theTE].first; + unsigned int TE2 = TE_[iSeed][theTE].second; + + unsigned int l1 = seedLayers(iSeed).first; + unsigned int l2 = seedLayers(iSeed).second; + + memories << "StubPairs: " + << SPName(l1, TE1 / NVMTE_[iSeed].first, TE1, l2, TE2 / NVMTE_[iSeed].second, TE2, iSeed) << " [12]" + << std::endl; + modules << "TrackletEngine: " + << TEName(l1, TE1 / NVMTE_[iSeed].first, TE1, l2, TE2 / NVMTE_[iSeed].second, TE2, iSeed) << std::endl; + + os << SPName(l1, TE1 / NVMTE_[iSeed].first, TE1, l2, TE2 / NVMTE_[iSeed].second, TE2, iSeed) << " input=> " + << TEName(l1, TE1 / NVMTE_[iSeed].first, TE1, l2, TE2 / NVMTE_[iSeed].second, TE2, iSeed) + << ".stubpairout output=> " << TCNAme(iSeed, iTC) << ".stubpairin" << std::endl; + } + } + } +} + +void TrackletConfigBuilder::writeSPDMemories(std::ostream& wires, std::ostream& memories, std::ostream& modules) { + if (!extended_) + return; + + vector stubTriplets[N_SEED]; + + for (unsigned int iSeed = N_SEED_PROMPT; iSeed < N_SEED; iSeed++) { + int layerdisk1 = settings_.seedlayers(0, iSeed); + int layerdisk2 = settings_.seedlayers(1, iSeed); + int layerdisk3 = settings_.seedlayers(2, iSeed); + + unsigned int nallstub1 = settings_.nallstubs(layerdisk1); + unsigned int nallstub2 = settings_.nallstubs(layerdisk2); + unsigned int nallstub3 = settings_.nallstubs(layerdisk3); + + unsigned int nvm1 = settings_.nvmte(0, iSeed); + unsigned int nvm2 = settings_.nvmte(1, iSeed); + unsigned int nvm3 = settings_.nvmte(2, iSeed); + + int count = 0; + for (unsigned int ireg1 = 0; ireg1 < nallstub1; ireg1++) { + for (unsigned int ireg2 = 0; ireg2 < nallstub2; ireg2++) { + for (unsigned int ireg3 = 0; ireg3 < nallstub3; ireg3++) { + count++; + memories << "StubTriplets: " << STName(layerdisk1, ireg1, layerdisk2, ireg2, layerdisk3, ireg3, iSeed, count) + << " [18]" << std::endl; + stubTriplets[iSeed].push_back(STName(layerdisk1, ireg1, layerdisk2, ireg2, layerdisk3, ireg3, iSeed, count)); + } + } + } + + for (unsigned int ireg1 = 0; ireg1 < nallstub1; ireg1++) { + for (unsigned int ivm1 = 0; ivm1 < nvm1; ivm1++) { + for (unsigned int ireg2 = 0; ireg2 < nallstub2; ireg2++) { + for (unsigned int ivm2 = 0; ivm2 < nvm2; ivm2++) { + int count = 0; + + modules << "TrackletEngineDisplaced: " + << TEDName(layerdisk1, ireg1, ireg1 * nvm1 + ivm1, layerdisk2, ireg2, ireg2 * nvm2 + ivm2, iSeed) + << std::endl; + + for (unsigned int ireg3 = 0; ireg3 < nallstub3; ireg3++) { + for (unsigned int ivm3 = 0; ivm3 < nvm3; ivm3++) { + count++; + + memories << "StubPairsDisplaced: " + << SPDName(layerdisk1, + ireg1, + ireg1 * nvm1 + ivm1, + layerdisk2, + ireg2, + ireg2 * nvm2 + ivm2, + layerdisk3, + ireg3, + ireg3 * nvm3 + ivm3, + iSeed) + << " [12]" << std::endl; + + modules << "TripletEngine: " << TREName(layerdisk1, ireg1, layerdisk2, ireg2, iSeed, count) + << std::endl; + + wires << SPDName(layerdisk1, + ireg1, + ireg1 * nvm1 + ivm1, + layerdisk2, + ireg2, + ireg2 * nvm2 + ivm2, + layerdisk3, + ireg3, + ireg3 * nvm3 + ivm3, + iSeed) + << " input=> " + << TEDName(layerdisk1, ireg1, ireg1 * nvm1 + ivm1, layerdisk2, ireg2, ireg2 * nvm2 + ivm2, iSeed) + << ".stubpairout output=> " << TREName(layerdisk1, ireg1, layerdisk2, ireg2, iSeed, count) + << ".stubpair" + << "1" + << "in" << std::endl; + } + } + } + } + } + } + + unsigned int nTC = 10; + for (unsigned int itc = 0; itc < nTC; itc++) { + for (int iproj = 0; iproj < 4; iproj++) { + int ilay = settings_.projlayers(iSeed, iproj); + if (ilay > 0) { + unsigned int nallstub = settings_.nallstubs(ilay - 1); + for (unsigned int ireg = 0; ireg < nallstub; ireg++) { + memories << "TrackletProjections: " << TPROJName(layerdisk1, layerdisk2, layerdisk3, itc, ilay - 1, ireg) + << " [54]" << std::endl; + } + } + + int idisk = settings_.projdisks(iSeed, iproj); + if (idisk > 0) { + unsigned int nallstub = settings_.nallstubs(idisk + 5); + for (unsigned int ireg = 0; ireg < nallstub; ireg++) { + memories << "TrackletProjections: " << TPROJName(layerdisk1, layerdisk2, layerdisk3, itc, idisk + 5, ireg) + << " [54]" << std::endl; + + wires << TPROJName(layerdisk1, layerdisk2, layerdisk3, itc, idisk + 5, ireg) << " input=> " + << TCDName(layerdisk1, layerdisk2, layerdisk3, itc) << ".projout" << LayerName(idisk + 1) << "PHI" + << iTCStr(ireg) << " output=> " + << "PR_" << LayerName(idisk + 1) << "PHI" << iTCStr(ireg) << ".projin" << std::endl; + } + } + } + + memories << "TrackletParameters: " << TParName(layerdisk1, layerdisk2, layerdisk3, itc) << " [56]" << std::endl; + + modules << "TrackletCalculatorDisplaced: " << TCDName(layerdisk1, layerdisk2, layerdisk3, itc) << std::endl; + } + + unsigned int nST = stubTriplets[iSeed].size(); + for (unsigned int iST = 0; iST < nST; iST++) { + unsigned int iTC = (iST * nTC) / nST; + assert(iTC < nTC); + string stname = stubTriplets[iSeed][iST]; + string trename = "TRE_" + stname.substr(3, 6) + "_"; + unsigned int stlen = stname.size(); + if (stname[stlen - 2] == '_') + trename += stname.substr(stlen - 1, 1); + if (stname[stlen - 3] == '_') + trename += stname.substr(stlen - 2, 2); + wires << stname << " input=> " << trename << ".stubtripout output=> " + << TCDName(layerdisk1, layerdisk2, layerdisk3, iTC) << ".stubtriplet" << ((iST * nTC) % nST) << "in" + << std::endl; + } + + modules << "FitTrack: " << FTName(layerdisk1, layerdisk2, layerdisk3) << std::endl; + } +} + +void TrackletConfigBuilder::writeAPMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { + if (combinedmodules_) + return; + + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { + memories << "AllProj: AP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " [56]" << std::endl; + modules << "ProjectionRouter: PR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; + + os << "AP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " input=> PR_" << LayerName(ilayer) << "PHI" + << iTCStr(iReg) << ".allprojout output=> MC_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allprojin" + << std::endl; + } + } +} + +void TrackletConfigBuilder::writeCMMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { + if (combinedmodules_) + return; + + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (unsigned int iME = 0; iME < NVMME_[ilayer] * NRegions_[ilayer]; iME++) { + memories << "CandidateMatch: CM_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 + << " [12]" << std::endl; + modules << "MatchEngine: ME_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 + << std::endl; + + os << "CM_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << " input=> ME_" + << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << ".matchout output=> MC_" + << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << ".matchin" << std::endl; + } + } +} + +void TrackletConfigBuilder::writeVMPROJMemories(std::ostream& os, std::ostream& memories, std::ostream&) { + if (combinedmodules_) + return; + + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (unsigned int iME = 0; iME < NVMME_[ilayer] * NRegions_[ilayer]; iME++) { + memories << "VMProjections: VMPROJ_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 + << " [13]" << std::endl; + + os << "VMPROJ_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << " input=> PR_" + << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << ".vmprojout" + << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << " output=> ME_" << LayerName(ilayer) << "PHI" + << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << ".vmprojin" << std::endl; + } + } +} + +void TrackletConfigBuilder::writeFMMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { + if (combinedmodules_) { + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { + modules << "MatchProcessor: MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + if (matchport_[iSeed][ilayer] == -1) + continue; + memories << "FullMatch: FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) + << " [36]" << std::endl; + os << "FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " input=> MP_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".matchout1 output=> FT_" << iSeedStr(iSeed) + << ".fullmatch" << matchport_[iSeed][ilayer] << "in" << iReg + 1 << std::endl; + } + } + } + } else { + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { + modules << "MatchCalculator: MC_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + if (matchport_[iSeed][ilayer] == -1) + continue; + memories << "FullMatch: FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) + << " [36]" << std::endl; + os << "FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " input=> MC_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".matchout1 output=> FT_" << iSeedStr(iSeed) + << ".fullmatch" << matchport_[iSeed][ilayer] << "in" << iReg + 1 << std::endl; + } + } + } + } +} + +void TrackletConfigBuilder::writeASMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { + if (combinedmodules_) { + //First write AS memories used by MatchProcessor + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { + memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" + << " [42]" << std::endl; + if (combinedmodules_) { + modules << "VMRouterCM: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; + } else { + modules << "VMRouter: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; + } + os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" + << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MP_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubin" << std::endl; + } + } + + //Next write AS memories used by TrackletProcessor + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (int iReg = 0; iReg < (int)NRegions_[ilayer]; iReg++) { + unsigned int nmem = 1; + + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + unsigned int l1 = seedLayers(iSeed).first; + unsigned int l2 = seedLayers(iSeed).second; + + if (ilayer != l1 && ilayer != l2) + continue; + + bool inner = ilayer == l1; + + for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) { + int nTCReg = TC_[iSeed].size() / NRegions_[l2]; + + int iTCReg = iTC / nTCReg; + + int jTCReg = iTC % nTCReg; + + if (ilayer == l2) { + if (iTCReg != iReg) + continue; + } + + string ext = ""; + + if (ilayer == l1) { + int ratio = NRegions_[l1] / NRegions_[l2]; + int min = iTCReg * ratio - 1 + jTCReg; + int max = (iTCReg + 1) * ratio - (nTCReg - jTCReg - 1); + if ((int)iReg < min || (int)iReg > max) + continue; + + if (max - min >= 2) { + ext = "M"; + if (iReg == min) + ext = "R"; + if (iReg == max) + ext = "L"; + } + + if (max - min == 1) { + if (nTCReg == 2) { + assert(0); + if (jTCReg == 0) { + if (iReg == min) + ext = "R"; + if (iReg == max) + ext = "B"; + } + if (jTCReg == 1) { + if (iReg == min) + ext = "A"; + if (iReg == max) + ext = "L"; + } + } + if (nTCReg == 3) { + if (jTCReg == 0) { + if (iReg == min) + ext = "A"; + if (iReg == max) + ext = "F"; + } + if (jTCReg == 1) { + if (iReg == min) + ext = "E"; + if (iReg == max) + ext = "D"; + } + if (jTCReg == 2) { + if (iReg == min) + ext = "C"; + if (iReg == max) + ext = "B"; + } + } + } + assert(ext != ""); + } + + if (ext == "") { + ext = "_" + iTCStr(iTC); + } + + if (iSeed < 4) { //Barrel seeding + ext = "_B" + ext; + } else if (iSeed > 5) { + ext = "_O" + ext; + } else { + ext = "_D" + ext; + } + + nmem++; + if (inner) { + memories << "AllInnerStubs: "; + } else { + memories << "AllStubs: "; + } + memories << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ext << " [42]" << std::endl; + os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ext << " input=> VMR_" << LayerName(ilayer) + << "PHI" << iTCStr(iReg) << ".all" << (inner ? "inner" : "") << "stubout output=> TP_" << iSeedStr(iSeed) + << iTCStr(iTC); + if (inner) { + os << ".innerallstubin" << std::endl; + } else { + os << ".outerallstubin" << std::endl; + } + } + } + } + } + } else { + //First write AS memories used by MatchCalculator + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { + memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" + << " [42]" << std::endl; + if (combinedmodules_) { + modules << "VMRouterCM: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; + } else { + modules << "VMRouter: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; + } + os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" + << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MC_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubin" << std::endl; + } + } + + //Next write AS memories used by TrackletCalculator + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { + unsigned int nmem = 1; + + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + unsigned int l1 = seedLayers(iSeed).first; + unsigned int l2 = seedLayers(iSeed).second; + + if (ilayer != l1 && ilayer != l2) + continue; + + for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) { + bool used = false; + for (unsigned int iTE = 0; iTE < TC_[iSeed][iTC].size(); iTE++) { + unsigned int theTE = TC_[iSeed][iTC][iTE]; + + unsigned int TE1 = TE_[iSeed][theTE].first; + unsigned int TE2 = TE_[iSeed][theTE].second; + + if (l1 == ilayer && iReg == TE1 / NVMTE_[iSeed].first) + used = true; + if (l2 == ilayer && iReg == TE2 / NVMTE_[iSeed].second) + used = true; + } + + if (used) { + nmem++; + memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n" << nmem << " [42]" + << std::endl; + os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n" << nmem << " input=> VMR_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> TC_" << iSeedStr(iSeed) + << iTCStr(iTC); + if (ilayer == l1) { + os << ".innerallstubin" << std::endl; + } else { + os << ".outerallstubin" << std::endl; + } + } + } + } + } + } + } +} + +void TrackletConfigBuilder::writeVMSMemories(std::ostream& os, std::ostream& memories, std::ostream&) { + if (combinedmodules_) { + //First write VMS memories used by MatchProcessor + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { + memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1 [18]" << std::endl; + os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" + << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutPHI" << iTCStr(iReg) + << " output=> MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubin" << std::endl; + } + } + + //Next write VMS memories used by TrackletProcessor + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + //FIXME - code could be cleaner + unsigned int l1 = seedLayers(iSeed).first; + unsigned int l2 = seedLayers(iSeed).second; + + unsigned int ilayer = seedLayers(iSeed).second; + + //for(unsigned int iReg=0;iReg VMR_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubout_seed_" << iSeed << " output=> TP_" + << LayerName(l1) << LayerName(l2) << iTCStr(iReg * nTCReg + iTC) << ".outervmstubin" << std::endl; + } + } + } + } else { + //First write VMS memories used by MatchEngine + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (unsigned int iVMME = 0; iVMME < NVMME_[ilayer] * NRegions_[ilayer]; iVMME++) { + unsigned int iReg = iVMME / NVMME_[ilayer]; + memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << iVMME + 1 << "n1 [18]" + << std::endl; + os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << iVMME + 1 << "n1" + << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutPHI" << iTCStr(iReg) + << iVMME + 1 << " output=> ME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << iVMME + 1 << ".vmstubin" + << std::endl; + } + } + + //Next write VMS memories used by MatchCalculator + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + for (unsigned int innerouterseed = 0; innerouterseed < 2; innerouterseed++) { + //FIXME - code could be cleaner + unsigned int l1 = seedLayers(iSeed).first; + unsigned int l2 = seedLayers(iSeed).second; + + unsigned int NVMTE1 = NVMTE_[iSeed].first; + unsigned int NVMTE2 = NVMTE_[iSeed].second; + + unsigned int ilayer = seedLayers(iSeed).first; + unsigned int NVMTE = NVMTE_[iSeed].first; + if (innerouterseed == 1) { + ilayer = seedLayers(iSeed).second; + NVMTE = NVMTE_[iSeed].second; + } + + for (unsigned int iVMTE = 0; iVMTE < NVMTE * NRegions_[ilayer]; iVMTE++) { + unsigned int iReg = iVMTE / NVMTE; + + unsigned int nmem = 0; + + if (iSeed == 7) { + nmem = 4; + } + + for (unsigned int iTE = 0; iTE < TE_[iSeed].size(); iTE++) { + unsigned int TE1 = TE_[iSeed][iTE].first; + unsigned int TE2 = TE_[iSeed][iTE].second; + + bool used = false; + + if (innerouterseed == 0 && iVMTE == TE1) + used = true; + if (innerouterseed == 1 && iVMTE == TE2) + used = true; + + if (!used) + continue; + nmem++; + memories << "VMStubsTE: VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << iVMTE + 1 << "n" + << nmem << " [18]" << std::endl; + os << "VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << iVMTE + 1 << "n" << nmem + << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutPHI" << iTCStr(iReg) + << iVMTE + 1 << " output=> TE_" << LayerName(l1) << "PHI" << iRegStr(TE1 / NVMTE1, iSeed) << TE1 + 1 + << "_" << LayerName(l2) << "PHI" << iRegStr(TE2 / NVMTE2, iSeed) << TE2 + 1; + if (innerouterseed == 0) { + os << ".innervmstubin" << std::endl; + } else { + os << ".outervmstubin" << std::endl; + } + } + } + } + } + } +} + +void TrackletConfigBuilder::writeTPARMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { + if (combinedmodules_) { + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + for (unsigned int iTP = 0; iTP < TC_[iSeed].size(); iTP++) { + memories << "TrackletParameters: TPAR_" << iSeedStr(iSeed) << iTCStr(iTP) << " [56]" << std::endl; + modules << "TrackletProcessor: TP_" << iSeedStr(iSeed) << iTCStr(iTP) << std::endl; + os << "TPAR_" << iSeedStr(iSeed) << iTCStr(iTP) << " input=> TP_" << iSeedStr(iSeed) << iTCStr(iTP) + << ".trackpar output=> FT_" << iSeedStr(iSeed) << ".tparin" << std::endl; + } + } + } else { + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) { + memories << "TrackletParameters: TPAR_" << iSeedStr(iSeed) << iTCStr(iTC) << " [56]" << std::endl; + modules << "TrackletCalculator: TC_" << iSeedStr(iSeed) << iTCStr(iTC) << std::endl; + os << "TPAR_" << iSeedStr(iSeed) << iTCStr(iTC) << " input=> TC_" << iSeedStr(iSeed) << iTCStr(iTC) + << ".trackpar output=> FT_" << iSeedStr(iSeed) << ".tparin" << std::endl; + } + } + } +} + +void TrackletConfigBuilder::writeTFMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + memories << "TrackFit: TF_" << iSeedStr(iSeed) << " [126]" << std::endl; + modules << "FitTrack: FT_" << iSeedStr(iSeed) << std::endl; + os << "TF_" << iSeedStr(iSeed) << " input=> FT_" << iSeedStr(iSeed) << ".trackout output=> PD.trackin" << std::endl; + } +} + +void TrackletConfigBuilder::writeCTMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { + modules << "PurgeDuplicate: PD" << std::endl; + + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + memories << "CleanTrack: CT_" << iSeedStr(iSeed) << " [126]" << std::endl; + os << "CT_" << iSeedStr(iSeed) << " input=> PD.trackout output=>" << std::endl; + } +} + +void TrackletConfigBuilder::writeILMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { + //FIXME these should not be hardcoded - but for now wanted to avoid reading file + string dtcname[52]; + unsigned int layerdisk[52]; + double phimin[52]; + double phimax[52]; + + dtcname[0] = "PS10G_1"; + layerdisk[0] = 0; + phimin[0] = 0.304273; + phimax[0] = 0.742925; + dtcname[1] = "PS10G_1"; + layerdisk[1] = 6; + phimin[1] = -0.185672; + phimax[1] = 0.883803; + dtcname[2] = "PS10G_1"; + layerdisk[2] = 8; + phimin[2] = -0.132414; + phimax[2] = 0.830545; + dtcname[3] = "PS10G_1"; + layerdisk[3] = 10; + phimin[3] = -0.132414; + phimax[3] = 0.830545; + dtcname[4] = "PS10G_2"; + layerdisk[4] = 0; + phimin[4] = -0.0133719; + phimax[4] = 0.715599; + dtcname[5] = "PS10G_2"; + layerdisk[5] = 7; + phimin[5] = -0.110089; + phimax[5] = 0.808221; + dtcname[6] = "PS10G_2"; + layerdisk[6] = 9; + phimin[6] = -0.132414; + phimax[6] = 0.830545; + dtcname[7] = "PS10G_3"; + layerdisk[7] = 1; + phimin[7] = -0.11381; + phimax[7] = 0.822812; + dtcname[8] = "PS10G_3"; + layerdisk[8] = 7; + phimin[8] = -0.185672; + phimax[8] = 0.883803; + dtcname[9] = "PS10G_4"; + layerdisk[9] = 6; + phimin[9] = -0.0823971; + phimax[9] = 0.780529; + dtcname[10] = "PS10G_4"; + layerdisk[10] = 8; + phimin[10] = -0.0963091; + phimax[10] = 0.794441; + dtcname[11] = "PS10G_4"; + layerdisk[11] = 10; + phimin[11] = -0.0963091; + phimax[11] = 0.794441; + dtcname[12] = "PS_1"; + layerdisk[12] = 2; + phimin[12] = 0.0827748; + phimax[12] = 0.615357; + dtcname[13] = "PS_1"; + layerdisk[13] = 7; + phimin[13] = -0.0823971; + phimax[13] = 0.780529; + dtcname[14] = "PS_2"; + layerdisk[14] = 2; + phimin[14] = -0.0917521; + phimax[14] = 0.614191; + dtcname[15] = "PS_2"; + layerdisk[15] = 9; + phimin[15] = -0.0963091; + phimax[15] = 0.794441; + dtcname[16] = "2S_1"; + layerdisk[16] = 3; + phimin[16] = -0.0246209; + phimax[16] = 0.763311; + dtcname[17] = "2S_1"; + layerdisk[17] = 4; + phimin[17] = 0.261875; + phimax[17] = 0.403311; + dtcname[18] = "2S_2"; + layerdisk[18] = 4; + phimin[18] = -0.0542445; + phimax[18] = 0.715509; + dtcname[19] = "2S_3"; + layerdisk[19] = 5; + phimin[19] = 0.0410126; + phimax[19] = 0.730605; + dtcname[20] = "2S_4"; + layerdisk[20] = 5; + phimin[20] = -0.0428961; + phimax[20] = 0.693862; + dtcname[21] = "2S_4"; + layerdisk[21] = 8; + phimin[21] = -0.0676705; + phimax[21] = 0.765802; + dtcname[22] = "2S_5"; + layerdisk[22] = 6; + phimin[22] = -0.0648206; + phimax[22] = 0.762952; + dtcname[23] = "2S_5"; + layerdisk[23] = 9; + phimin[23] = -0.0676705; + phimax[23] = 0.765802; + dtcname[24] = "2S_6"; + layerdisk[24] = 7; + phimin[24] = -0.0648206; + phimax[24] = 0.762952; + dtcname[25] = "2S_6"; + layerdisk[25] = 10; + phimin[25] = -0.0676705; + phimax[25] = 0.765802; + dtcname[26] = "negPS10G_1"; + layerdisk[26] = 0; + phimin[26] = -0.023281; + phimax[26] = 0.372347; + dtcname[27] = "negPS10G_1"; + layerdisk[27] = 6; + phimin[27] = -0.185672; + phimax[27] = 0.883803; + dtcname[28] = "negPS10G_1"; + layerdisk[28] = 8; + phimin[28] = -0.132414; + phimax[28] = 0.830545; + dtcname[29] = "negPS10G_1"; + layerdisk[29] = 10; + phimin[29] = -0.132414; + phimax[29] = 0.830545; + dtcname[30] = "negPS10G_2"; + layerdisk[30] = 0; + phimin[30] = -0.0133719; + phimax[30] = 0.715599; + dtcname[31] = "negPS10G_2"; + layerdisk[31] = 7; + phimin[31] = -0.110089; + phimax[31] = 0.808221; + dtcname[32] = "negPS10G_2"; + layerdisk[32] = 9; + phimin[32] = -0.132414; + phimax[32] = 0.830545; + dtcname[33] = "negPS10G_3"; + layerdisk[33] = 1; + phimin[33] = -0.115834; + phimax[33] = 0.813823; + dtcname[34] = "negPS10G_3"; + layerdisk[34] = 7; + phimin[34] = -0.185672; + phimax[34] = 0.883803; + dtcname[35] = "negPS10G_4"; + layerdisk[35] = 6; + phimin[35] = -0.0823971; + phimax[35] = 0.780529; + dtcname[36] = "negPS10G_4"; + layerdisk[36] = 8; + phimin[36] = -0.0963091; + phimax[36] = 0.794441; + dtcname[37] = "negPS10G_4"; + layerdisk[37] = 10; + phimin[37] = -0.0963091; + phimax[37] = 0.794441; + dtcname[38] = "negPS_1"; + layerdisk[38] = 2; + phimin[38] = -0.0961318; + phimax[38] = 0.445198; + dtcname[39] = "negPS_1"; + layerdisk[39] = 7; + phimin[39] = -0.0823971; + phimax[39] = 0.780529; + dtcname[40] = "negPS_2"; + layerdisk[40] = 2; + phimin[40] = -0.0917521; + phimax[40] = 0.614191; + dtcname[41] = "negPS_2"; + layerdisk[41] = 9; + phimin[41] = -0.0963091; + phimax[41] = 0.794441; + dtcname[42] = "neg2S_1"; + layerdisk[42] = 3; + phimin[42] = -0.0246209; + phimax[42] = 0.763311; + dtcname[43] = "neg2S_1"; + layerdisk[43] = 4; + phimin[43] = 0.261875; + phimax[43] = 0.403311; + dtcname[44] = "neg2S_2"; + layerdisk[44] = 4; + phimin[44] = -0.0542445; + phimax[44] = 0.715509; + dtcname[45] = "neg2S_3"; + layerdisk[45] = 5; + phimin[45] = 0.0410126; + phimax[45] = 0.730605; + dtcname[46] = "neg2S_4"; + layerdisk[46] = 5; + phimin[46] = -0.0428961; + phimax[46] = 0.693862; + dtcname[47] = "neg2S_4"; + layerdisk[47] = 8; + phimin[47] = -0.06767; + phimax[47] = 0.765802; + dtcname[48] = "neg2S_5"; + layerdisk[48] = 6; + phimin[48] = -0.0648201; + phimax[48] = 0.762952; + dtcname[49] = "neg2S_5"; + layerdisk[49] = 9; + phimin[49] = -0.06767; + phimax[49] = 0.765802; + dtcname[50] = "neg2S_6"; + layerdisk[50] = 7; + phimin[50] = -0.0648201; + phimax[50] = 0.762952; + dtcname[51] = "neg2S_6"; + layerdisk[51] = 10; + phimin[51] = -0.06767; + phimax[51] = 0.765802; + + double dphi = 0.5 * dphisectorHG_ - M_PI / NSector_; + + string olddtc = ""; + for (unsigned int i = 0; i < 52; i++) { + if (olddtc != dtcname[i]) { + modules << "InputRouter: IR_" << dtcname[i] << "_A" << std::endl; + modules << "InputRouter: IR_" << dtcname[i] << "_B" << std::endl; + memories << "DTCLink: DL_" << dtcname[i] << "_A [36]" << std::endl; + memories << "DTCLink: DL_" << dtcname[i] << "_B [36]" << std::endl; + os << "DL_" << dtcname[i] << "_A" + << " input=> output=> IR_" << dtcname[i] << "_A.stubin" << std::endl; + os << "DL_" << dtcname[i] << "_B" + << " input=> output=> IR_" << dtcname[i] << "_B.stubin" << std::endl; + } + olddtc = dtcname[i]; + } + + for (unsigned int i = 0; i < 52; i++) { + double phimintmp = phimin[i] + dphi; + double phimaxtmp = phimax[i] + dphi; + + for (unsigned int iReg = 0; iReg < NRegions_[layerdisk[i]]; iReg++) { + if (allStubs_[layerdisk[i]][iReg].first > phimaxtmp && allStubs_[layerdisk[i]][iReg].second < phimintmp) + continue; + + if (allStubs_[layerdisk[i]][iReg].second < phimaxtmp) { + memories << "InputLink: IL_" << LayerName(layerdisk[i]) << "PHI" << iTCStr(iReg) << "_" << dtcname[i] << "_A" + << " [36]" << std::endl; + os << "IL_" << LayerName(layerdisk[i]) << "PHI" << iTCStr(iReg) << "_" << dtcname[i] << "_A" + << " input=> IR_" << dtcname[i] << "_A.stubout output=> VMR_" << LayerName(layerdisk[i]) << "PHI" + << iTCStr(iReg) << ".stubin" << std::endl; + } + + if (allStubs_[layerdisk[i]][iReg].first > phimintmp) { + memories << "InputLink: IL_" << LayerName(layerdisk[i]) << "PHI" << iTCStr(iReg) << "_" << dtcname[i] << "_B" + << " [36]" << std::endl; + os << "IL_" << LayerName(layerdisk[i]) << "PHI" << iTCStr(iReg) << "_" << dtcname[i] << "_B" + << " input=> IR_" << dtcname[i] << "_B.stubout output=> VMR_" << LayerName(layerdisk[i]) << "PHI" + << iTCStr(iReg) << ".stubin" << std::endl; + } + } + } +} + +void TrackletConfigBuilder::writeAll(std::ostream& wires, std::ostream& memories, std::ostream& modules) { + writeILMemories(wires, memories, modules); + writeASMemories(wires, memories, modules); + writeVMSMemories(wires, memories, modules); + writeSPMemories(wires, memories, modules); + writeSPDMemories(wires, memories, modules); + writeProjectionMemories(wires, memories, modules); + writeTPARMemories(wires, memories, modules); + writeVMPROJMemories(wires, memories, modules); + writeAPMemories(wires, memories, modules); + writeCMMemories(wires, memories, modules); + writeFMMemories(wires, memories, modules); + writeTFMemories(wires, memories, modules); + writeCTMemories(wires, memories, modules); +} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc index 3119888246b09..42f5d49cc2947 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc @@ -13,8 +13,8 @@ using namespace trklet; using namespace std; -TrackletEngine::TrackletEngine(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector) { +TrackletEngine::TrackletEngine(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) { stubpairs_ = nullptr; innervmstubs_ = nullptr; outervmstubs_ = nullptr; @@ -122,8 +122,11 @@ void TrackletEngine::execute() { if (!(pttableinner_[ptinnerindex] && pttableouter_[ptouterindex])) { if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " - << benddecode(innervmstub.bend().value(), innervmstub.isPSmodule()) << " " - << benddecode(outervmstub.bend().value(), outervmstub.isPSmodule()); + << settings_.benddecode( + innervmstub.bend().value(), layerdisk1_, innervmstub.isPSmodule()) + << " " + << settings_.benddecode( + outervmstub.bend().value(), layerdisk2_, outervmstub.isPSmodule()); } continue; } @@ -212,13 +215,13 @@ void TrackletEngine::setVMPhiBin() { } else { rinner = settings_.rmean(layerdisk1_); } - double rinv1 = rinv(phiinner[i1], phiouter[i2], rinner, router[i3]); + double rinv1 = -rinv(phiinner[i1], phiouter[i2], rinner, router[i3]); double pitchinner = (rinner < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); double pitchouter = (router[i3] < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); - double abendinner = -bend(rinner, rinv1, pitchinner); - double abendouter = -bend(router[i3], rinv1, pitchouter); + double abendinner = bendstrip(rinner, rinv1, pitchinner); + double abendouter = bendstrip(router[i3], rinv1, pitchouter); if (abendinner < bendinnermin) bendinnermin = abendinner; if (abendinner > bendinnermax) @@ -237,20 +240,20 @@ void TrackletEngine::setVMPhiBin() { bool passptcut = rinvmin < settings_.rinvcutte(); for (int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) { - double bend = benddecode(ibend, nbendbitsinner == 3); + double bend = settings_.benddecode(ibend, layerdisk1_, nbendbitsinner == 3); - bool passinner = bend - bendinnermin > -settings_.bendcutte(0, iSeed_) && - bend - bendinnermax < settings_.bendcutte(0, iSeed_); + bool passinner = bend > bendinnermin - settings_.bendcutte(ibend, layerdisk1_, nbendbitsinner == 3) && + bend < bendinnermax + settings_.bendcutte(ibend, layerdisk1_, nbendbitsinner == 3); if (passinner) vmbendinner[ibend] = true; pttableinner_.push_back(passinner && passptcut); } for (int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) { - double bend = benddecode(ibend, nbendbitsouter == 3); + double bend = settings_.benddecode(ibend, layerdisk2_, nbendbitsouter == 3); - bool passouter = bend - bendoutermin > -settings_.bendcutte(1, iSeed_) && - bend - bendoutermax < settings_.bendcutte(1, iSeed_); + bool passouter = bend > bendoutermin - settings_.bendcutte(ibend, layerdisk2_, nbendbitsouter == 3) && + bend < bendoutermax + settings_.bendcutte(ibend, layerdisk2_, nbendbitsouter == 3); if (passouter) vmbendouter[ibend] = true; pttableouter_.push_back(passouter && passptcut); @@ -262,22 +265,12 @@ void TrackletEngine::setVMPhiBin() { innervmstubs_->setbendtable(vmbendinner); outervmstubs_->setbendtable(vmbendouter); - if (iSector_ == 0 && settings_.writeTable()) + if (settings_.writeTable()) writeTETable(); } void TrackletEngine::writeTETable() { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } - - const string fnameI = settings_.tablePath() + getName() + "_stubptinnercut.tab"; - ofstream outstubptinnercut(fnameI); - if (outstubptinnercut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fnameI; + ofstream outstubptinnercut = openfile(settings_.tablePath(), getName() + "_stubptinnercut.tab", __FILE__, __LINE__); outstubptinnercut << "{" << endl; for (unsigned int i = 0; i < pttableinner_.size(); i++) { @@ -288,10 +281,7 @@ void TrackletEngine::writeTETable() { outstubptinnercut << endl << "};" << endl; outstubptinnercut.close(); - const string fnameO = settings_.tablePath() + getName() + "_stubptoutercut.tab"; - ofstream outstubptoutercut(fnameO); - if (outstubptoutercut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fnameI; + ofstream outstubptoutercut = openfile(settings_.tablePath(), getName() + "_stubptoutercut.tab", __FILE__, __LINE__); outstubptoutercut << "{" << endl; for (unsigned int i = 0; i < pttableouter_.size(); i++) { diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc index 201b0b9b99723..927cd2b43505a 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc @@ -12,11 +12,8 @@ using namespace std; using namespace trklet; -TrackletEngineDisplaced::TrackletEngineDisplaced(string name, - Settings const& settings, - Globals* global, - unsigned int iSector) - : ProcessBase(name, settings, global, iSector) { +TrackletEngineDisplaced::TrackletEngineDisplaced(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) { stubpairs_.clear(); firstvmstubs_.clear(); secondvmstubs_ = nullptr; @@ -174,21 +171,24 @@ void TrackletEngineDisplaced::execute() { if ((settings_.enableTripletTables() && !settings_.writeTripletTables()) && (index >= table_.size() || table_.at(index).empty())) { if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " - << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " " - << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()); + edm::LogVerbatim("Tracklet") + << "Stub pair rejected because of stub pt cut bends : " + << settings_.benddecode(firstvmstub.bend().value(), layer1_ - 1, firstvmstub.isPSmodule()) << " " + << settings_.benddecode(secondvmstub.bend().value(), layer2_ - 1, secondvmstub.isPSmodule()); } - continue; + + //FIXME temporarily commented out until stub bend table fixed + //if (!settings_.writeTripletTables()) + // continue; } if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName(); for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) { - if ((!settings_.enableTripletTables() || settings_.writeTripletTables()) || - (index < table_.size() && table_.at(index).count(isp))) { + if (!settings_.enableTripletTables() || settings_.writeTripletTables() || table_.at(index).count(isp)) { if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; fout.close(); } stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName()); @@ -254,9 +254,10 @@ void TrackletEngineDisplaced::execute() { if ((settings_.enableTripletTables() && !settings_.writeTripletTables()) && (index >= table_.size() || table_.at(index).empty())) { if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " - << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " " - << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()); + edm::LogVerbatim("Tracklet") + << "Stub pair rejected because of stub pt cut bends : " + << settings_.benddecode(firstvmstub.bend().value(), layer1_ - 1, firstvmstub.isPSmodule()) << " " + << settings_.benddecode(secondvmstub.bend().value(), layer2_ - 1, secondvmstub.isPSmodule()); } continue; } @@ -268,7 +269,7 @@ void TrackletEngineDisplaced::execute() { (index < table_.size() && table_.at(index).count(isp))) { if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; fout.close(); } stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName()); @@ -281,7 +282,7 @@ void TrackletEngineDisplaced::execute() { } else if (disk1_ == 1 && disk2_ == 2) { if (settings_.debugTracklet()) - edm::LogVerbatim("Tracklet") << getName() << "[" << iSector_ << "] Disk-disk pair"; + edm::LogVerbatim("Tracklet") << getName() << " Disk-disk pair"; int lookupbits = firstvmstub.vmbits().value() & 511; bool negdisk = firstvmstub.stub()->disk().value() < 0; @@ -334,9 +335,10 @@ void TrackletEngineDisplaced::execute() { if ((settings_.enableTripletTables() && !settings_.writeTripletTables()) && (index >= table_.size() || table_.at(index).empty())) { if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " - << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " " - << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()); + edm::LogVerbatim("Tracklet") + << "Stub pair rejected because of stub pt cut bends : " + << settings_.benddecode(firstvmstub.bend().value(), disk1_ + 5, firstvmstub.isPSmodule()) << " " + << settings_.benddecode(secondvmstub.bend().value(), disk2_ + 5, secondvmstub.isPSmodule()); } continue; } @@ -349,7 +351,7 @@ void TrackletEngineDisplaced::execute() { (index < table_.size() && table_.at(index).count(isp))) { if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; fout.close(); } stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName()); @@ -412,7 +414,7 @@ void TrackletEngineDisplaced::readTables() { fin.close(); } -const short TrackletEngineDisplaced::memNameToIndex(const string& name) { +short TrackletEngineDisplaced::memNameToIndex(const string& name) { for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) if (stubpairs_.at(isp)->getName() == name) return isp; diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc index 10bc49cad08a9..291d47b7ad5cc 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc @@ -7,6 +7,7 @@ using namespace trklet; TrackletEngineUnit::TrackletEngineUnit(const Settings* const settings, unsigned int nbitsfinephi, + unsigned int layerdisk1, unsigned int layerdisk2, unsigned int iSeed, unsigned int nbitsfinephidiff, @@ -14,10 +15,11 @@ TrackletEngineUnit::TrackletEngineUnit(const Settings* const settings, std::vector const& pttableinner, std::vector const& pttableouter, VMStubsTEMemory* outervmstubs) - : settings_(settings), candpairs_(5) { + : settings_(settings), candpairs_(3) { idle_ = true; nbitsfinephi_ = nbitsfinephi; layerdisk2_ = layerdisk2; + layerdisk1_ = layerdisk1; iSeed_ = iSeed; nbitsfinephidiff_ = nbitsfinephidiff; iAllStub_ = iAllStub; @@ -31,18 +33,31 @@ void TrackletEngineUnit::init(const TEData& tedata) { nreg_ = 0; istub_ = 0; idle_ = false; - assert(!tedata_.regions_.empty()); + assert(tedata_.regions_.size() > 0); std::tie(next_, ireg_, nstub_) = tedata_.regions_[0]; } void TrackletEngineUnit::reset() { idle_ = true; + goodpair_ = false; + goodpair__ = false; candpairs_.reset(); } -void TrackletEngineUnit::step() { - if (candpairs_.full()) +void TrackletEngineUnit::step(bool, int, int) { + + if (goodpair__) { + candpairs_.store(candpair__); + } + + goodpair__ = goodpair_; + candpair__ = candpair_; + + goodpair_ = false; + + if (idle_ || nearfull_) { return; + } int ibin = tedata_.start_ + next_; @@ -61,9 +76,10 @@ void TrackletEngineUnit::step() { int outerfinephi = iAllStub_ * (1 << (nbitsfinephi_ - settings_->nbitsallstubs(layerdisk2_))) + ireg_ * (1 << settings_->nfinephi(1, iSeed_)) + iphiouterbin.value(); int idphi = outerfinephi - tedata_.innerfinephi_; + bool inrange = (idphi < (1 << (nbitsfinephidiff_ - 1))) && (idphi >= -(1 << (nbitsfinephidiff_ - 1))); - if (idphi < 0) - idphi = idphi + (1 << nbitsfinephidiff_); + + idphi = idphi & ((1 << nbitsfinephidiff_) - 1); unsigned int firstDiskSeed = 4; if (iSeed_ >= firstDiskSeed) { //Also use r-position @@ -75,6 +91,7 @@ void TrackletEngineUnit::step() { if (next_ != 0) rzbin += (1 << NFINERZBITS); + if ((rzbin < tedata_.rzbinfirst_) || (rzbin - tedata_.rzbinfirst_ > tedata_.rzdiffmax_)) { if (settings_->debugTracklet()) { edm::LogVerbatim("Tracklet") << " layer-disk stub pair rejected because rbin cut : " << rzbin << " " @@ -89,14 +106,19 @@ void TrackletEngineUnit::step() { if (!(inrange && pttableinner_[ptinnerindex] && pttableouter_[ptouterindex])) { if (settings_->debugTracklet()) { edm::LogVerbatim("Tracklet") << " Stub pair rejected because of stub pt cut bends : " - << benddecode(tedata_.innerbend_.value(), tedata_.stub_->isPSmodule()) << " " - << benddecode(outerbend.value(), outervmstub.isPSmodule()); + << settings_->benddecode( + tedata_.innerbend_.value(), layerdisk1_, tedata_.stub_->isPSmodule()) + << " " + << settings_->benddecode(outerbend.value(), layerdisk2_, outervmstub.isPSmodule()); } } else { - candpairs_.store(pair(tedata_.stub_, outervmstub.stub())); + candpair_ = pair(tedata_.stub_, outervmstub.stub()); + goodpair_ = true; } } + istub_++; + assert(nstub_ <= N_VMSTUBSMAX); if (istub_ >= nstub_) { istub_ = 0; nreg_++; diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc index 77dc376c1e9e0..19286102bbaf3 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc @@ -1,11 +1,12 @@ #include "L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h" +#include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h" #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" #include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h" #include "L1Trigger/TrackFindingTracklet/interface/Sector.h" #include "L1Trigger/TrackFindingTracklet/interface/HistBase.h" #include "L1Trigger/TrackFindingTracklet/interface/Track.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h" #include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" -#include "L1Trigger/TrackFindingTracklet/interface/Cabling.h" #include "DataFormats/Math/interface/deltaPhi.h" @@ -41,6 +42,12 @@ void TrackletEventProcessor::init(Settings const& theSettings) { throw cms::Exception("Inconsistency") << "t conversion parameter inconsistency\n"; } + if (settings_->kphider() != globals_->ITC_L1L2()->der_phiL_final.K()) { + throw cms::Exception("Inconsistency") + << "t conversion parameter inconsistency:" << settings_->kphider() / globals_->ITC_L1L2()->der_phiL_final.K() + << "\n"; + } + if (settings_->debugTracklet()) { edm::LogVerbatim("Tracklet") << "========================================================= \n" << "Conversion factors for global coordinates: \n" @@ -71,21 +78,47 @@ void TrackletEventProcessor::init(Settings const& theSettings) { globals_->histograms() = histbase_; } - // create the sector processors (1 sector processor = 1 board) - sectors_.resize(N_SECTOR); + sector_ = make_unique(*settings_, globals_.get()); + + if (settings_->extended()) { + ifstream inmem(settings_->memoryModulesFile().c_str()); + assert(inmem.good()); + + ifstream inproc(settings_->processingModulesFile().c_str()); + assert(inproc.good()); + + ifstream inwire(settings_->wiresFile().c_str()); + assert(inwire.good()); + + configure(inwire, inmem, inproc); + + } else { + TrackletConfigBuilder config(*settings_); + + //Write configurations to file. + if (settings_->writeConfig()) { + std::ofstream wires = openfile(settings_->tablePath(), "wires.dat", __FILE__, __LINE__); + std::ofstream memorymodules = openfile(settings_->tablePath(), "memorymodules.dat", __FILE__, __LINE__); + std::ofstream processingmodules = openfile(settings_->tablePath(), "processingmodules.dat", __FILE__, __LINE__); + + config.writeAll(wires, memorymodules, processingmodules); + } - for (unsigned int i = 0; i < N_SECTOR; i++) { - sectors_[i] = make_unique(i, *settings_, globals_.get()); + std::stringstream wires; + std::stringstream memorymodules; + std::stringstream processingmodules; + + config.writeAll(wires, memorymodules, processingmodules); + configure(wires, memorymodules, processingmodules); } +} +void TrackletEventProcessor::configure(istream& inwire, istream& inmem, istream& inproc) { // get the memory modules if (settings_->debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Will read memory modules file"; + edm::LogVerbatim("Tracklet") << "Will read memory modules"; } - ifstream inmem(settings_->memoryModulesFile().c_str()); - assert(inmem.good()); - while (inmem.good()) { string memType, memName, size; inmem >> memType >> memName >> size; @@ -94,19 +127,14 @@ void TrackletEventProcessor::init(Settings const& theSettings) { if (settings_->writetrace()) { edm::LogVerbatim("Tracklet") << "Read memory: " << memType << " " << memName; } - for (auto& sector : sectors_) { - sector->addMem(memType, memName); - } + sector_->addMem(memType, memName); } // get the processing modules if (settings_->debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Will read processing modules file"; + edm::LogVerbatim("Tracklet") << "Will read processing modules"; } - ifstream inproc(settings_->processingModulesFile().c_str()); - assert(inproc.good()); - while (inproc.good()) { string procType, procName; inproc >> procType >> procName; @@ -115,9 +143,7 @@ void TrackletEventProcessor::init(Settings const& theSettings) { if (settings_->writetrace()) { edm::LogVerbatim("Tracklet") << "Read process: " << procType << " " << procName; } - for (auto& sector : sectors_) { - sector->addProc(procType, procName); - } + sector_->addProc(procType, procName); } // get the wiring information @@ -125,9 +151,6 @@ void TrackletEventProcessor::init(Settings const& theSettings) { edm::LogVerbatim("Tracklet") << "Will read wiring information"; } - ifstream inwire(settings_->wiresFile().c_str()); - assert(inwire.good()); - while (inwire.good()) { string line; getline(inwire, line); @@ -146,29 +169,8 @@ void TrackletEventProcessor::init(Settings const& theSettings) { ss >> tmp2 >> procout; } - for (auto& sector : sectors_) { - sector->addWire(mem, procin, procout); - } - } - - // get the DTC/cabling information - ifstream indtc(settings_->DTCLinkLayerDiskFile()); - assert(indtc.good()); - string dtc; - indtc >> dtc; - while (indtc.good()) { - vector tmp; - dtclayerdisk_[dtc] = tmp; - int layerdisk; - indtc >> layerdisk; - while (layerdisk > 0) { - dtclayerdisk_[dtc].push_back(layerdisk); - indtc >> layerdisk; - } - indtc >> dtc; + sector_->addWire(mem, procin, procout); } - - cabling_ = make_unique(settings_->DTCLinkFile(), settings_->moduleCablingFile(), *settings_); } void TrackletEventProcessor::event(SLHCEvent& ev) { @@ -179,323 +181,207 @@ void TrackletEventProcessor::event(SLHCEvent& ev) { eventnum_++; bool first = (eventnum_ == 1); - cleanTimer_.start(); for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->clean(); - } - cleanTimer_.stop(); - - addStubTimer_.start(); + sector_->setSector(k); - for (int j = 0; j < ev.nstubs(); j++) { - L1TStub stub = ev.stub(j); + cleanTimer_.start(); + sector_->clean(); + cleanTimer_.stop(); - int layer = stub.layer() + 1; - int ladder = stub.ladder(); - int module = stub.module(); + addStubTimer_.start(); - string dtc = cabling_->dtc(layer, ladder, module); - string dtcbase = dtc.substr(2, dtc.size() - 2); - if (dtc[0] == 'n') { - dtcbase = dtc.substr(0, 4) + dtc.substr(6, dtc.size() - 6); - } + vector layerstubs(N_LAYER + N_DISK, 0); + vector layerstubssector(N_SECTOR * (N_LAYER + N_DISK), 0); - cabling_->addphi(dtc, stub.phi(), layer, module); + for (int j = 0; j < ev.nstubs(); j++) { + L1TStub stub = ev.stub(j); + unsigned int isector = stub.region(); + if (isector != k) { + continue; + } - double phi = angle0to2pi::make0To2pi(stub.phi() + 0.5 * settings_->dphisectorHG()); + string dtc = stub.DTClink(); - unsigned int isector = N_SECTOR * phi / (2 * M_PI); + layerstubs[stub.layerdisk()]++; + layerstubssector[isector * (N_LAYER + N_DISK) + stub.layerdisk()]++; - for (unsigned int k = 0; k < N_SECTOR; k++) { - int diff = k - isector; - if (diff > (int)N_SECTOR / 2) - diff -= (int)N_SECTOR; - if (diff < (-1) * (int)N_SECTOR / 2) - diff += (int)N_SECTOR; - if (abs(diff) > 1) - continue; - double phiminsect = - k * 2 * M_PI / N_SECTOR - 0.5 * (settings_->dphisectorHG() - 2 * M_PI / N_SECTOR) - M_PI / N_SECTOR; - double dphi = stub.phi() - phiminsect; - if (dphi > M_PI) - dphi -= 2 * M_PI; - while (dphi < 0.0) - dphi += 2 * M_PI; - if (dphi > settings_->dphisectorHG()) - continue; - bool add = sectors_[k]->addStub(stub, dtcbase); - - static std::map dtcstubs; - - if (settings_->writeMem()) { - vector dtcs = cabling_->DTCs(); - for (const auto& dtc : dtcs) { - string dtcbase = dtc.substr(2, dtc.size() - 2); - if (dtc[0] == 'n') { - dtcbase = dtc.substr(0, 4) + dtc.substr(6, dtc.size() - 6); - } - - const string dirIS = settings_->memPath() + "InputStubs/"; - string fname = dirIS + "Link_"; - fname += dtcbase; - if (dtcstubs.find(dtcbase + "A") != dtcstubs.end()) - continue; - fname += "_A.dat"; - - if (not std::filesystem::exists(dirIS)) { - int fail = system((string("mkdir -p ") + dirIS).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirIS; - } - - ofstream* out = new ofstream; - out->open(fname); - if (out->fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - dtcstubs[dtcbase + "A"] = out; - - fname = dirIS + "Link_"; - fname += dtcbase; - if (dtcstubs.find(dtcbase + "B") != dtcstubs.end()) - continue; - fname += "_B.dat"; - out = new ofstream; - out->open(fname); - if (out->fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - dtcstubs[dtcbase + "B"] = out; - } + sector_->addStub(stub, dtc); + } - static int oldevent = -1; - if (eventnum_ != oldevent) { - oldevent = eventnum_; - for (auto& dtcstub : dtcstubs) { - FPGAWord tmp; - tmp.set(eventnum_ % 8, 3); - (*(dtcstub.second)) << "BX " << tmp.str() << " Event : " << eventnum_ + 1 << endl; - } - } + if (settings_->writeMonitorData("StubsLayerSector")) { + for (unsigned int index = 0; index < layerstubssector.size(); index++) { + int layerdisk = index % (N_LAYER + N_DISK); + int sector = index / (N_LAYER + N_DISK); + globals_->ofstream("stubslayersector.txt") + << layerdisk << " " << sector << " " << layerstubssector[index] << endl; } + } - if (add && settings_->writeMem() && k == settings_->writememsect()) { - Stub fpgastub(stub, *settings_, sectors_[k]->phimin(), sectors_[k]->phimax()); - FPGAWord phi = fpgastub.phi(); - int topbit = phi.value() >> (phi.nbits() - 1); - std::vector tmp = dtclayerdisk_[dtcbase]; - int layerdisk = stub.layer() + 1; - if (layerdisk > 999) { - layerdisk = 10 + abs(stub.disk()); - } - int layerdiskcode = -1; - for (unsigned int i = 0; i < tmp.size(); i++) { - if (tmp[i] == layerdisk) - layerdiskcode = i; - } - if (layerdiskcode == -1) { - edm::LogVerbatim("Tracklet") << "dtcbase layerdisk layer disk : " << dtcbase << " " << layerdisk << " " - << stub.layer() + 1 << " " << stub.disk(); - } - assert(layerdiskcode >= 0); - assert(layerdiskcode < 4); - FPGAWord ldcode; - ldcode.set(layerdiskcode, 2); - string dataword = fpgastub.str() + "|" + ldcode.str() + "|1"; - if (topbit == 0) { - (*dtcstubs[dtcbase + "A"]) << dataword << " " << trklet::hexFormat(dataword) << endl; - } else { - (*dtcstubs[dtcbase + "B"]) << dataword << " " << trklet::hexFormat(dataword) << endl; - } + if (settings_->writeMonitorData("StubsLayer")) { + for (unsigned int layerdisk = 0; layerdisk < layerstubs.size(); layerdisk++) { + globals_->ofstream("stubslayer.txt") << layerdisk << " " << layerstubs[layerdisk] << endl; } } - } - addStubTimer_.stop(); + addStubTimer_.stop(); - // ---------------------------------------------------------------------------------------- - // Now start the tracklet processing + // ---------------------------------------------------------------------------------------- + // Now start the tracklet processing - // VM router - VMRouterTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeVMR(); + // VM router + InputRouterTimer_.start(); + sector_->executeIR(); if (settings_->writeMem() && k == settings_->writememsect()) { - sectors_[k]->writeInputStubs(first); - sectors_[k]->writeVMSTE(first); - sectors_[k]->writeVMSME(first); - sectors_[k]->writeAS(first); + sector_->writeDTCStubs(first); + sector_->writeIRStubs(first); } - } - VMRouterTimer_.stop(); + InputRouterTimer_.stop(); - // tracklet engine - TETimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeTE(); - } - TETimer_.stop(); + VMRouterTimer_.start(); + sector_->executeVMR(); + if (settings_->writeMem() && k == settings_->writememsect()) { + sector_->writeVMSTE(first); + sector_->writeVMSME(first); + sector_->writeAS(first); + sector_->writeAIS(first); + } + VMRouterTimer_.stop(); - // tracklet engine displaced - TEDTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeTED(); - } - TEDTimer_.stop(); + // tracklet engine + TETimer_.start(); + sector_->executeTE(); + TETimer_.stop(); - // triplet engine - TRETimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeTRE(); + // tracklet engine displaced + TEDTimer_.start(); + sector_->executeTED(); + TEDTimer_.stop(); + + // triplet engine + TRETimer_.start(); + sector_->executeTRE(); if (settings_->writeMem() && k == settings_->writememsect()) { - sectors_[k]->writeST(first); + sector_->writeST(first); } - } - TRETimer_.stop(); + TRETimer_.stop(); - // tracklet processor (alternative implementation to TE+TC) - TPTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeTP(); - } - TPTimer_.stop(); + // tracklet processor (alternative implementation to TE+TC) + TPTimer_.start(); + sector_->executeTP(); + TPTimer_.stop(); - for (unsigned int k = 0; k < N_SECTOR; k++) { if (settings_->writeMem() && k == settings_->writememsect()) { - sectors_[k]->writeSP(first); + sector_->writeSP(first); } - } - // tracklet calculator - TCTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeTC(); - } - TCTimer_.stop(); + // tracklet calculator + TCTimer_.start(); + sector_->executeTC(); + TCTimer_.stop(); - int nTP = globals_->event()->nsimtracks(); - for (int iTP = 0; iTP < nTP; iTP++) { - L1SimTrack simtrk = globals_->event()->simtrack(iTP); - if (simtrk.pt() < 2.0) - continue; - if (std::abs(simtrk.vz()) > 15.0) - continue; - if (hypot(simtrk.vx(), simtrk.vy()) > 0.1) - continue; - bool electron = (abs(simtrk.type()) == 11); - bool muon = (abs(simtrk.type()) == 13); - bool pion = (abs(simtrk.type()) == 211); - bool kaon = (abs(simtrk.type()) == 321); - bool proton = (abs(simtrk.type()) == 2212); - if (!(electron || muon || pion || kaon || proton)) - continue; - int nlayers = 0; - int ndisks = 0; - int simtrackid = simtrk.trackid(); - unsigned int hitmask = ev.layersHit(simtrackid, nlayers, ndisks); - if (nlayers + ndisks < 4) - continue; + int nTP = globals_->event()->nsimtracks(); + for (int iTP = 0; iTP < nTP; iTP++) { + L1SimTrack simtrk = globals_->event()->simtrack(iTP); + if (simtrk.pt() < 2.0) + continue; + if (std::abs(simtrk.vz()) > 15.0) + continue; + if (hypot(simtrk.vx(), simtrk.vy()) > 0.1) + continue; + bool electron = (abs(simtrk.type()) == 11); + bool muon = (abs(simtrk.type()) == 13); + bool pion = (abs(simtrk.type()) == 211); + bool kaon = (abs(simtrk.type()) == 321); + bool proton = (abs(simtrk.type()) == 2212); + if (!(electron || muon || pion || kaon || proton)) + continue; + int nlayers = 0; + int ndisks = 0; + int simtrackid = simtrk.trackid(); + unsigned int hitmask = ev.layersHit(simtrackid, nlayers, ndisks); + if (nlayers + ndisks < 4) + continue; - if (settings_->writeMonitorData("HitEff")) { - static ofstream outhit("hiteff.txt"); - outhit << simtrk.eta() << " " << (hitmask & 1) << " " << (hitmask & 2) << " " << (hitmask & 4) << " " - << (hitmask & 8) << " " << (hitmask & 16) << " " << (hitmask & 32) << " " << (hitmask & 64) << " " - << (hitmask & 128) << " " << (hitmask & 256) << " " << (hitmask & 512) << " " << (hitmask & 1024) << endl; - } + if (settings_->writeMonitorData("HitEff")) { + static ofstream outhit("hiteff.txt"); + outhit << simtrk.eta() << " " << (hitmask & 1) << " " << (hitmask & 2) << " " << (hitmask & 4) << " " + << (hitmask & 8) << " " << (hitmask & 16) << " " << (hitmask & 32) << " " << (hitmask & 64) << " " + << (hitmask & 128) << " " << (hitmask & 256) << " " << (hitmask & 512) << " " << (hitmask & 1024) + << endl; + } - std::unordered_set matchseed; - for (unsigned int k = 0; k < N_SECTOR; k++) { - std::unordered_set matchseedtmp = sectors_[k]->seedMatch(iTP); + std::unordered_set matchseed; + std::unordered_set matchseedtmp = sector_->seedMatch(iTP); matchseed.insert(matchseedtmp.begin(), matchseedtmp.end()); - } - if (settings_->bookHistos()) { - for (int iseed = 0; iseed < 8; iseed++) { - bool eff = matchseed.find(iseed) != matchseed.end(); - globals_->histograms()->fillSeedEff(iseed, simtrk.eta(), eff); + if (settings_->bookHistos()) { + for (int iseed = 0; iseed < 8; iseed++) { + bool eff = matchseed.find(iseed) != matchseed.end(); + globals_->histograms()->fillSeedEff(iseed, simtrk.eta(), eff); + } } } - } - // tracklet calculator displaced - TCDTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeTCD(); - } - TCDTimer_.stop(); + // tracklet calculator displaced + TCDTimer_.start(); + sector_->executeTCD(); + TCDTimer_.stop(); - for (unsigned int k = 0; k < N_SECTOR; k++) { if (settings_->writeMem() && k == settings_->writememsect()) { - sectors_[k]->writeTPAR(first); - sectors_[k]->writeTPROJ(first); + sector_->writeTPAR(first); + sector_->writeTPROJ(first); } - } - // projection router - PRTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executePR(); + // projection router + PRTimer_.start(); + sector_->executePR(); if (settings_->writeMem() && k == settings_->writememsect()) { - sectors_[k]->writeVMPROJ(first); - sectors_[k]->writeAP(first); + sector_->writeVMPROJ(first); + sector_->writeAP(first); } - } - PRTimer_.stop(); + PRTimer_.stop(); - // match engine - METimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeME(); + // match engine + METimer_.start(); + sector_->executeME(); if (settings_->writeMem() && k == settings_->writememsect()) { - sectors_[k]->writeCM(first); + sector_->writeCM(first); } - } - METimer_.stop(); + METimer_.stop(); - // match calculator - MCTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeMC(); - } - MCTimer_.stop(); + // match calculator + MCTimer_.start(); + sector_->executeMC(); + MCTimer_.stop(); - // match processor (alternative to ME+MC) - MPTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeMP(); - } - MPTimer_.stop(); + // match processor (alternative to ME+MC) + MPTimer_.start(); + sector_->executeMP(); + MPTimer_.stop(); - for (unsigned int k = 0; k < N_SECTOR; k++) { if (settings_->writeMem() && k == settings_->writememsect()) { - sectors_[k]->writeMC(first); + sector_->writeMC(first); } - } - // fit track - FTTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeFT(); + // fit track + FTTimer_.start(); + sector_->executeFT(); if ((settings_->writeMem() || settings_->writeMonitorData("IFit")) && k == settings_->writememsect()) { - sectors_[k]->writeTF(first); + sector_->writeTF(first); } - } - FTTimer_.stop(); + FTTimer_.stop(); - // purge duplicate - PDTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executePD(tracks_); + // purge duplicate + PDTimer_.start(); + sector_->executePD(tracks_); if (((settings_->writeMem() || settings_->writeMonitorData("IFit")) && k == settings_->writememsect()) || settings_->writeMonitorData("CT")) { - sectors_[k]->writeCT(first); + sector_->writeCT(first); } + PDTimer_.stop(); } - PDTimer_.stop(); } void TrackletEventProcessor::printSummary() { - if (settings_->writeMonitorData("Cabling")) { - cabling_->writephirange(); - } - if (settings_->bookHistos()) { globals_->histograms()->close(); } @@ -508,6 +394,9 @@ void TrackletEventProcessor::printSummary() { << "Add Stubs " << setw(10) << addStubTimer_.ntimes() << setw(20) << setprecision(3) << addStubTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << addStubTimer_.tottime() << "\n" + << "InputRouter " << setw(10) << InputRouterTimer_.ntimes() << setw(20) + << setprecision(3) << InputRouterTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << InputRouterTimer_.tottime() << "\n" << "VMRouter " << setw(10) << VMRouterTimer_.ntimes() << setw(20) << setprecision(3) << VMRouterTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << VMRouterTimer_.tottime(); @@ -519,23 +408,32 @@ void TrackletEventProcessor::printSummary() { << setprecision(3) << MPTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << MPTimer_.tottime(); } else { - edm::LogVerbatim("Tracklet") - << "TrackletEngine " << setw(10) << TETimer_.ntimes() << setw(20) << setprecision(3) - << TETimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << TETimer_.tottime() << "\n" - << "TrackletEngineDisplaced" << setw(10) << TEDTimer_.ntimes() << setw(20) << setprecision(3) - << TEDTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << TEDTimer_.tottime() << "\n" - << "TripletEngine " << setw(10) << TRETimer_.ntimes() << setw(20) << setprecision(3) - << TRETimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << TRETimer_.tottime() << "\n" - << "TrackletCalculator " << setw(10) << TCTimer_.ntimes() << setw(20) << setprecision(3) - << TCTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << TCTimer_.tottime() << "\n" - << "TrackletCalculatorDisplaced" << setw(10) << TCDTimer_.ntimes() << setw(20) << setprecision(3) - << TCDTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << TCDTimer_.tottime() << "\n" - << "ProjectionRouter " << setw(10) << PRTimer_.ntimes() << setw(20) << setprecision(3) - << PRTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << PRTimer_.tottime() << "\n" - << "MatchEngine " << setw(10) << METimer_.ntimes() << setw(20) << setprecision(3) - << METimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << METimer_.tottime() << "\n" - << "MatchCalculator " << setw(10) << MCTimer_.ntimes() << setw(20) << setprecision(3) - << MCTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << MCTimer_.tottime(); + edm::LogVerbatim("Tracklet") << "TrackletEngine " << setw(10) << TETimer_.ntimes() << setw(20) + << setprecision(3) << TETimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << TETimer_.tottime(); + if (settings_->extended()) { + edm::LogVerbatim("Tracklet") << "TrackletEngineDisplaced" << setw(10) << TEDTimer_.ntimes() << setw(20) + << setprecision(3) << TEDTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << TEDTimer_.tottime() << "\n" + << "TripletEngine " << setw(10) << TRETimer_.ntimes() << setw(20) + << setprecision(3) << TRETimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << TRETimer_.tottime() << "\n" + << "TrackletCalculatorDisplaced" << setw(10) << TCDTimer_.ntimes() << setw(20) + << setprecision(3) << TCDTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << TCDTimer_.tottime(); + } + edm::LogVerbatim("Tracklet") << "TrackletCalculator " << setw(10) << TCTimer_.ntimes() << setw(20) + << setprecision(3) << TCTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << TCTimer_.tottime() << "\n" + << "ProjectionRouter " << setw(10) << PRTimer_.ntimes() << setw(20) + << setprecision(3) << PRTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << PRTimer_.tottime() << "\n" + << "MatchEngine " << setw(10) << METimer_.ntimes() << setw(20) + << setprecision(3) << METimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << METimer_.tottime() << "\n" + << "MatchCalculator " << setw(10) << MCTimer_.ntimes() << setw(20) + << setprecision(3) << MCTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << MCTimer_.tottime(); } edm::LogVerbatim("Tracklet") << "FitTrack " << setw(10) << FTTimer_.ntimes() << setw(20) << setprecision(3) << FTTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc b/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc index dbba44f2b361a..7667f26038a97 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc @@ -8,8 +8,8 @@ using namespace std; using namespace trklet; -TrackletParametersMemory::TrackletParametersMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) {} +TrackletParametersMemory::TrackletParametersMemory(string name, Settings const& settings) + : MemoryBase(name, settings) {} void TrackletParametersMemory::clean() { for (auto& tracklet : tracklets_) { @@ -18,23 +18,8 @@ void TrackletParametersMemory::clean() { tracklets_.clear(); } -void TrackletParametersMemory::writeMatches(Globals* globals, int& matchesL1, int& matchesL3, int& matchesL5) { - ofstream& out = globals->ofstream("nmatches.txt"); - for (auto& tracklet : tracklets_) { - if ((tracklet->nMatches() + tracklet->nMatchesDisk()) > 0) { - if (tracklet->layer() == 1) - matchesL1++; - if (tracklet->layer() == 3) - matchesL3++; - if (tracklet->layer() == 5) - matchesL5++; - } - out << tracklet->layer() << " " << tracklet->disk() << " " << tracklet->nMatches() << " " - << tracklet->nMatchesDisk() << endl; - } -} - -void TrackletParametersMemory::writeTPAR(bool first) { +void TrackletParametersMemory::writeTPAR(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirTP = settings_.memPath() + "TrackletParameters/"; std::ostringstream oss; @@ -42,21 +27,7 @@ void TrackletParametersMemory::writeTPAR(bool first) { << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirTP)) { - int fail = system((string("mkdir -p ") + dirTP).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirTP; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirTP, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc index de95f8c19bedf..ee937c120033f 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc @@ -1,8 +1,8 @@ - #include "L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h" #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" #include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/Util.h" #include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" @@ -16,8 +16,10 @@ using namespace std; using namespace trklet; -TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Globals* globals, unsigned int iSector) - : TrackletCalculatorBase(name, settings, globals, iSector), vmrtable_(settings) { +TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Globals* globals) + : TrackletCalculatorBase(name, settings, globals), + tebuffer_(CircularBuffer(3), 0, 0, 0, 0), + vmrtable_(settings) { iAllStub_ = -1; for (unsigned int ilayer = 0; ilayer < N_LAYER; ilayer++) { @@ -37,9 +39,9 @@ TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Glob nbitszfinebintable_ = settings_.vmrlutzbits(layerdisk1_); nbitsrfinebintable_ = settings_.vmrlutrbits(layerdisk1_); - vmrtable_.init(layerdisk1_, getName()); + vmrtable_.init(layerdisk1_); - nbitsrzbin_ = NFINERZBITS; + nbitsrzbin_ = N_RZBITS; if (iSeed_ == 4 || iSeed_ == 5) nbitsrzbin_ = 2; @@ -52,6 +54,8 @@ TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Glob TCIndex_ = (iSeed_ << 4) + iTC_; assert(TCIndex_ >= 0 && TCIndex_ <= (int)settings_.ntrackletmax()); + + maxStep_ = settings_.maxStep("TP"); } void TrackletProcessor::addOutputProjection(TrackletProjectionsMemory*& outputProj, MemoryBase* memory) { @@ -128,6 +132,7 @@ void TrackletProcessor::addInput(MemoryBase* memory, string input) { TrackletEngineUnit teunit(&settings_, nbitsfinephi_, + layerdisk1_, layerdisk2_, iSeed_, nbitsfinephidiff_, @@ -135,13 +140,14 @@ void TrackletProcessor::addInput(MemoryBase* memory, string input) { pttableinnernew_, pttableouternew_, outervmstubs_); - teunits_.resize(6, teunit); + + teunits_.resize(settings_.teunits(iSeed_), teunit); return; } if (input == "innerallstubin") { - auto* tmp = dynamic_cast(memory); + auto* tmp = dynamic_cast(memory); assert(tmp != nullptr); if (innerallstubs_.size() == 2) { //FIXME this should be done with better logic with reading the input stubs innerallstubs_.insert(innerallstubs_.begin(), tmp); @@ -150,13 +156,8 @@ void TrackletProcessor::addInput(MemoryBase* memory, string input) { } //FIXME should be done once after all inputs are added - tedatabuffers_.clear(); - CircularBuffer tedatabuffertmp(5); - tedatabuffertmp.reset(); - - tedatabuffers_.emplace_back(tedatabuffertmp, 0, 0, 0, (innerallstubs_.size() + 1) / 2); - tedatabuffers_.emplace_back( - tedatabuffertmp, 0, (innerallstubs_.size() + 1) / 2, (innerallstubs_.size() + 1) / 2, innerallstubs_.size()); + tebuffer_ = tuple, unsigned int, unsigned int, unsigned int, unsigned int>( + CircularBuffer(3), 0, 0, 0, innerallstubs_.size()); return; } @@ -169,10 +170,20 @@ void TrackletProcessor::addInput(MemoryBase* memory, string input) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; } -void TrackletProcessor::execute() { +void TrackletProcessor::execute(unsigned int iSector, double phimin, double phimax) { + bool print = (iSector == 3) && (getName() == "TP_L1L2D"); + print = false; + + phimin_ = phimin; + phimax_ = phimax; + iSector_ = iSector; + if (!settings_.useSeed(iSeed_)) return; + //Not most elegant solution; but works + int donecount = 0; + //Consistency checks assert(iAllStub_ >= 0); assert(iAllStub_ < (int)settings_.nallstubs(layerdisk2_)); @@ -191,152 +202,58 @@ void TrackletProcessor::execute() { //Actual implemenation starts here - //Reset the tebuffers - for (auto& tebuffer : tedatabuffers_) { - std::get<0>(tebuffer).reset(); - std::get<1>(tebuffer) = 0; - std::get<2>(tebuffer) = std::get<3>(tebuffer); - } + //Reset the tebuffer + std::get<0>(tebuffer_).reset(); + std::get<1>(tebuffer_) = 0; + std::get<2>(tebuffer_) = std::get<3>(tebuffer_); //Reset the teunits for (auto& teunit : teunits_) { teunit.reset(); } - for (unsigned int istep = 0; istep < settings_.maxStep("TP"); istep++) { - for (auto& tebuffer : tedatabuffers_) { - CircularBuffer& tedatabuffer = std::get<0>(tebuffer); - unsigned int& istub = std::get<1>(tebuffer); - unsigned int& imem = std::get<2>(tebuffer); - unsigned int imemend = std::get<4>(tebuffer); - - if ((!tedatabuffer.full()) && imem < imemend && istub < innerallstubs_[imem]->nStubs()) { - ninnerstubs++; - - const Stub* stub = innerallstubs_[imem]->getStub(istub); - - bool negdisk = (stub->disk().value() < 0); //FIXME stub needs to contain bit for +/- z disk - - FPGAWord phicorr = stub->phicorr(); - int innerfinephi = phicorr.bits(phicorr.nbits() - nbitsfinephi_, nbitsfinephi_); - FPGAWord innerbend = stub->bend(); - - //Take the top nbitszfinebintable_ bits of the z coordinate - int indexz = - (((1 << (stub->z().nbits() - 1)) + stub->z().value()) >> (stub->z().nbits() - nbitszfinebintable_)); - int indexr = -1; - if (layerdisk1_ > (N_LAYER - 1)) { - if (negdisk) { - indexz = (1 << nbitszfinebintable_) - indexz; - } - indexr = stub->r().value(); - if (stub->isPSmodule()) { - indexr = stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_); - } - } else { - //Take the top nbitsfinebintable_ bits of the z coordinate - indexr = (((1 << (stub->r().nbits() - 1)) + stub->r().value()) >> (stub->r().nbits() - nbitsrfinebintable_)); - } - - int lutval = -1; - if (iSeed_ < 6) { //FIXME should only be one table... - lutval = vmrtable_.lookupinner(indexz, indexr); - } else { - lutval = vmrtable_.lookupinneroverlap(indexz, indexr); - } - - if (lutval != -1) { - unsigned int lutwidth = settings_.lutwidthtab(0, iSeed_); - FPGAWord lookupbits(lutval, lutwidth, true, __LINE__, __FILE__); - - int rzfinebinfirst = lookupbits.bits(0, 3); //finephi - int next = lookupbits.bits(3, 1); //next r/z bin - int start = lookupbits.bits(4, nbitsrzbin_); - int rzdiffmax = lookupbits.bits(lookupbits.nbits() - 3, 3); - - if ((iSeed_ == 4 || iSeed_ == 5) && negdisk) { //TODO - need to store negative disk - start += 4; - } - int last = start + next; - - int nbins = 8; - - unsigned int useregindex = (innerfinephi << innerbend.nbits()) + innerbend.value(); - if (iSeed_ >= 4) { - //FIXME If the lookupbits were rationally organized this would be much simpler - int ir = ((start & 3) << 1) + (rzfinebinfirst >> 2); - useregindex = (useregindex << 3) + ir; - } - - assert(useregindex < useregion_.size()); - vector usereg = useregion_[useregindex]; - - TEData tedata; - tedata.stub_ = stub; - tedata.rzbinfirst_ = rzfinebinfirst; - tedata.start_ = start; - tedata.innerfinephi_ = innerfinephi; - tedata.rzdiffmax_ = rzdiffmax; - tedata.innerbend_ = innerbend; - - for (unsigned int ireg = 0; ireg < settings_.nvmte(1, iSeed_); ireg++) { - assert(ireg < usereg.size()); - if (!usereg[ireg]) - continue; - - for (int ibin = start; ibin <= last; ibin++) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << getName() << " looking for matching stub in bin " << ibin << " with " - << outervmstubs_->nVMStubsBinned(ireg * nbins + ibin) << " stubs"; - } - assert(ireg * nbins + ibin < outervmstubs_->nBin()); - int nstubs = outervmstubs_->nVMStubsBinned(ireg * nbins + ibin); - if (nstubs > 0) { - tedata.regions_.emplace_back(tuple(ibin - start, ireg, nstubs)); - countteall += nstubs; - } - } - } - - if (!tedata.regions_.empty()) { - ntedata++; - //cout << getName() << " adding TE data" << endl; - tedatabuffer.store(tedata); - } - } - istub++; - if (istub >= innerallstubs_[imem]->nStubs()) { - istub = 0; - imem++; - } + TEData tedata; + TEData tedata__; + TEData tedata___; + bool goodtedata = false; + bool goodtedata__ = false; + bool goodtedata___ = false; + + bool tebuffernearfull; + + for (unsigned int istep = 0; istep < maxStep_; istep++) { + if (print) { + CircularBuffer& tedatabuffer = std::get<0>(tebuffer_); + unsigned int& istub = std::get<1>(tebuffer_); + unsigned int& imem = std::get<2>(tebuffer_); + cout << "istep=" << istep << " TEBuffer: " << istub << " " << imem << " " << tedatabuffer.rptr() << " " + << tedatabuffer.wptr(); + int k = -1; + for (auto& teunit : teunits_) { + k++; + cout << " [" << k << " " << teunit.rptr() << " " << teunit.wptr() << " " << teunit.idle() << "]"; } + cout << endl; } - bool tedatabuffersdone = true; - for (auto& tebuffer : tedatabuffers_) { - CircularBuffer& tedatabuffer = std::get<0>(tebuffer); - tedatabuffersdone &= tedatabuffer.empty(); //buffer empty - tedatabuffersdone &= (std::get<2>(tebuffer) == std::get<4>(tebuffer)); //buffer processed all stubs - if (!tedatabuffer.empty()) { - for (auto& teunit : teunits_) { - if (teunit.empty() && teunit.idle()) { - teunit.init(tedatabuffer.read()); - break; - } - } - } - } + CircularBuffer& tedatabuffer = std::get<0>(tebuffer_); + tebuffernearfull = tedatabuffer.nearfull(); + + // + // First block here checks if there is a teunit with data that should should be used + // to calculate the tracklet parameters + // - bool teunitsdone = true; TrackletEngineUnit* teunitptr = nullptr; + + int iTE = 0; + int icount = -1; for (auto& teunit : teunits_) { - if (!teunit.idle()) { - teunit.step(); - teunitsdone = false; - } + teunit.setNearFull(); + icount++; if (!teunit.empty()) { teunitptr = &teunit; - teunitsdone = false; + iTE = icount; } } @@ -362,6 +279,8 @@ void TrackletProcessor::execute() { bool accept = false; if (iSeed_ < 4) { + if (print) + cout << "istep=" << istep << " TEUnit read iTE=" << iTE << endl; accept = barrelSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); } else if (iSeed_ < 6) { accept = diskSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); @@ -374,6 +293,7 @@ void TrackletProcessor::execute() { if (trackletpars_->nTracklets() >= settings_.ntrackletmax()) { edm::LogVerbatim("Tracklet") << "Will break on number of tracklets in " << getName(); + assert(0); break; } @@ -382,43 +302,198 @@ void TrackletProcessor::execute() { } } - if (settings_.writeMonitorData("TP")) { - globals_->ofstream("trackletprocessor.txt") << getName() << " " << ninnerstubs //# inner stubs - << " " << outervmstubs_->nVMStubs() //# outer stubs - << " " << countteall //# pairs tried in TE - << " " << stubpairs //# stubs pairs - << " " << countsel //# tracklets found - << endl; + // + // The second block fills the teunit if data in buffer and process TEUnit step + // + // + + bool notemptytebuffer = !tedatabuffer.empty(); + + int ite = -1; + for (auto& teunit : teunits_) { + ite++; + if (teunit.idle()) { + if (notemptytebuffer) { + teunit.init(std::get<0>(tebuffer_).read()); + if (print) + std::cout << "istep=" << istep << " TEUnit init iTE inner : " << ite << " " + << teunit.innerStub()->allStubIndex().value() << std::endl; + notemptytebuffer = false; //prevent initialzing another TE unit + } + } + teunit.step(print, istep, ite); } - if (teunitsdone && tedatabuffersdone) { + // + // The third block here checks if we have input stubs to process + // + // + + if (goodtedata___) + tedatabuffer.store(tedata___); + + goodtedata = false; + + unsigned int& istub = std::get<1>(tebuffer_); + unsigned int& imem = std::get<2>(tebuffer_); + unsigned int imemend = std::get<4>(tebuffer_); + + if ((!tebuffernearfull) && imem < imemend && istub < innerallstubs_[imem]->nStubs()) { + ninnerstubs++; + + const Stub* stub = innerallstubs_[imem]->getStub(istub); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " Have stub in " << innerallstubs_[imem]->getName(); + } + + bool negdisk = (stub->disk().value() < 0); //FIXME stub needs to contain bit for +/- z disk + + FPGAWord phicorr = stub->phicorr(); + int innerfinephi = phicorr.bits(phicorr.nbits() - nbitsfinephi_, nbitsfinephi_); + FPGAWord innerbend = stub->bend(); + + //Take the top nbitszfinebintable_ bits of the z coordinate + int indexz = (stub->z().value() >> (stub->z().nbits() - nbitszfinebintable_)) & ((1 << nbitszfinebintable_) - 1); + int indexr = -1; + if (layerdisk1_ > (N_LAYER - 1)) { + if (negdisk) { + indexz = ((1 << nbitszfinebintable_) - 1) - indexz; + } + indexr = stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_); + } else { //Take the top nbitsfinebintable_ bits of the z coordinate + indexr = (stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_)) & ((1 << nbitsrfinebintable_) - 1); + } + + int lutval = -1; + if (iSeed_ < 6) { //FIXME should only be one table - but will need coordination with HLS code. + lutval = vmrtable_.lookupinner(indexz, indexr); + } else { + lutval = vmrtable_.lookupinneroverlap(indexz, indexr); + } + + if (lutval != -1) { + unsigned int lutwidth = settings_.lutwidthtab(0, iSeed_); + FPGAWord lookupbits(lutval, lutwidth, true, __LINE__, __FILE__); + + int rzfinebinfirst = lookupbits.bits(0, NFINERZBITS); //finerz + int next = lookupbits.bits(NFINERZBITS, 1); //use next r/z bin + int start = lookupbits.bits(NFINERZBITS + 1, nbitsrzbin_); //rz bin + int rzdiffmax = lookupbits.bits(NFINERZBITS + 1 + nbitsrzbin_, NFINERZBITS); + + if ((iSeed_ == 4 || iSeed_ == 5) && negdisk) { //TODO - need to store negative disk + start += (1 << nbitsrzbin_); + } + int last = start + next; + + int nbins = (1 << N_RZBITS); + + unsigned int useregindex = (innerfinephi << innerbend.nbits()) + innerbend.value(); + if (iSeed_ >= 4) { + //FIXME If the lookupbits were rationally organized this would be much simpler + unsigned int nrbits = 3; + int ir = ((start & ((1 << (nrbits - 1)) - 1)) << 1) + (rzfinebinfirst >> (NFINERZBITS - 1)); + useregindex = (useregindex << nrbits) + ir; + } + + assert(useregindex < useregion_.size()); + unsigned int usereg = useregion_[useregindex]; + + tedata.regions_.clear(); + tedata.stub_ = stub; + tedata.rzbinfirst_ = rzfinebinfirst; + tedata.start_ = start; + tedata.innerfinephi_ = innerfinephi; + tedata.rzdiffmax_ = rzdiffmax; + tedata.innerbend_ = innerbend; + + std::string mask = ""; + + for (int ibin = start; ibin <= last; ibin++) { + for (unsigned int ireg = 0; ireg < settings_.nvmte(1, iSeed_); ireg++) { + if (!(usereg & (1 << ireg))) { + mask = "0" + mask; + continue; + } + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " looking for matching stub in bin " << ibin << " with " + << outervmstubs_->nVMStubsBinned(ireg * nbins + ibin) << " stubs"; + } + assert(ireg * nbins + ibin < outervmstubs_->nBin()); + int nstubs = outervmstubs_->nVMStubsBinned(ireg * nbins + ibin); + + if (print) + cout << "Add to TEBuffer stub ibin ireg nstubs: " << stub->allStubIndex().value() << " " << ibin << " " + << ireg << " " << nstubs << endl; + + if (nstubs > 0) { + mask = "1" + mask; + tedata.regions_.emplace_back(tuple(ibin - start, ireg, nstubs)); + countteall += nstubs; + } else { + mask = "0" + mask; + } + } + } + + if (tedata.regions_.size() > 0) { + ntedata++; + goodtedata = true; + } + } + istub++; + if (istub >= innerallstubs_[imem]->nStubs()) { + istub = 0; + imem++; + } + } else if ((!tebuffernearfull) && imem < imemend && istub == 0) { + imem++; + } + + goodtedata___ = goodtedata__; + goodtedata__ = goodtedata; + + tedata___ = tedata__; + tedata__ = tedata; + + // + // stop looping over istep if done + // + + bool done = true; + + if (imem < imemend || (!tedatabuffer.empty())) { + done = false; + } + + for (auto& teunit : teunits_) { + if (!(teunit.idle() && teunit.empty())) + done = false; + } + + if (done) { + donecount++; + } + + //FIXME This should be done cleaner... Not too hard, but need to check fully the TEBuffer and TEUnit buffer. + if (donecount > 4) { break; } } -} -void TrackletProcessor::writeTETable() { - ofstream outstubptinnercut; - outstubptinnercut.open(getName() + "_stubptinnercut.tab"); - outstubptinnercut << "{" << endl; - // the below is outcommented as the writing of these tables are currently not implemented, to be adressed - //for(unsigned int i=0;iofstream("trackletprocessor.txt") << getName() << " " << ninnerstubs //# inner stubs + << " " << outervmstubs_->nVMStubs() //# outer stubs + << " " << countteall //# pairs tried in TE + << " " << stubpairs //# stubs pairs + << " " << countsel //# tracklets found + << endl; + } } void TrackletProcessor::buildLUT() { @@ -437,7 +512,8 @@ void TrackletProcessor::buildLUT() { if (iSeed_ > 5) { if (iSeed_ == 6) { rmax = settings_.rmaxdiskl1overlapvm(); - } else if (iSeed_ == 7) { + } + if (iSeed_ == 7) { rmax = settings_.rmaxdiskvm(); } rmin = settings_.rmean(layerdisk1_); @@ -508,12 +584,12 @@ void TrackletProcessor::buildLUT() { } else { rinner = settings_.rmean(layerdisk1_); } - double rinv1 = rinv(0.0, dphi[i2], rinner, router[i3]); + double rinv1 = rinv(0.0, -dphi[i2], rinner, router[i3]); double pitchinner = (rinner < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); double pitchouter = (router[i3] < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); - double abendinner = -bend(rinner, rinv1, pitchinner); - double abendouter = -bend(router[i3], rinv1, pitchouter); + double abendinner = bendstrip(rinner, rinv1, pitchinner); + double abendouter = bendstrip(router[i3], rinv1, pitchouter); if (abendinner < bendinnermin) bendinnermin = abendinner; if (abendinner > bendinnermax) @@ -531,18 +607,18 @@ void TrackletProcessor::buildLUT() { bool passptcut = rinvmin < settings_.rinvcutte(); for (int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) { - double bend = benddecode(ibend, nbendbitsinner == 3); + double bend = settings_.benddecode(ibend, layerdisk1_, nbendbitsinner == 3); - bool passinner = bend - bendinnermin > -settings_.bendcutte(0, iSeed_) && - bend - bendinnermax < settings_.bendcutte(0, iSeed_); + bool passinner = bend <= bendinnermax + settings_.bendcutte(ibend, layerdisk1_, nbendbitsinner == 3) && + bend >= bendinnermin - settings_.bendcutte(ibend, layerdisk1_, nbendbitsinner == 3); pttableinnernew_.push_back(passinner && passptcut); } for (int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) { - double bend = benddecode(ibend, nbendbitsouter == 3); + double bend = settings_.benddecode(ibend, layerdisk2_, nbendbitsouter == 3); - bool passouter = bend - bendoutermin > -settings_.bendcutte(1, iSeed_) && - bend - bendoutermax < settings_.bendcutte(1, iSeed_); + bool passouter = bend <= bendoutermax + settings_.bendcutte(ibend, layerdisk2_, nbendbitsouter == 3) && + bend >= bendoutermin - settings_.bendcutte(ibend, layerdisk2_, nbendbitsouter == 3); pttableouternew_.push_back(passouter && passptcut); } } @@ -558,7 +634,7 @@ void TrackletProcessor::buildLUT() { for (int innerbend = 0; innerbend < (1 << nbendbitsinner); innerbend++) { for (int ir = 0; ir < (1 << nirbits); ir++) { int nreg = 0; - vector usereg; + unsigned int usereg = 0; for (unsigned int ireg = 0; ireg < settings_.nvmte(1, iSeed_); ireg++) { bool match = false; for (int ifinephiouter = 0; ifinephiouter < (1 << settings_.nfinephi(1, iSeed_)); ifinephiouter++) { @@ -576,7 +652,9 @@ void TrackletProcessor::buildLUT() { } if (match && ir < 3) nreg++; - usereg.push_back(match); + if (match) { + usereg = usereg | (1 << ireg); + } } useregion_.push_back(usereg); @@ -585,4 +663,41 @@ void TrackletProcessor::buildLUT() { } } } + + if (settings_.writeTable()) { + ofstream out; + out.open(settings_.tablePath() + getName() + "_usereg.tab"); + + out << "{" << endl; + for (unsigned int i = 0; i < useregion_.size(); i++) { + if (i != 0) { + out << "," << endl; + } + out << useregion_[i]; + } + out << endl << "};" << endl; + out.close(); + + ofstream outstubptinnercut; + outstubptinnercut.open(settings_.tablePath() + getName() + "_stubptinnercut.tab"); + outstubptinnercut << "{" << endl; + for (unsigned int i = 0; i < pttableinnernew_.size(); i++) { + if (i != 0) + outstubptinnercut << "," << endl; + outstubptinnercut << pttableinnernew_[i]; + } + outstubptinnercut << endl << "};" << endl; + outstubptinnercut.close(); + + ofstream outstubptoutercut; + outstubptoutercut.open(settings_.tablePath() + getName() + "_stubptoutercut.tab"); + outstubptoutercut << "{" << endl; + for (unsigned int i = 0; i < pttableouternew_.size(); i++) { + if (i != 0) + outstubptoutercut << "," << endl; + outstubptoutercut << pttableouternew_[i]; + } + outstubptoutercut << endl << "};" << endl; + outstubptoutercut.close(); + } } diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc b/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc index 50080813e2438..b1861fdc64dab 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc @@ -7,8 +7,8 @@ using namespace std; using namespace trklet; -TrackletProjectionsMemory::TrackletProjectionsMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) { +TrackletProjectionsMemory::TrackletProjectionsMemory(string name, Settings const& settings) + : MemoryBase(name, settings) { size_t pos = find_nth(name, 0, "_", 1); assert(pos != string::npos); initLayerDisk(pos + 1, layer_, disk_); @@ -16,11 +16,11 @@ TrackletProjectionsMemory::TrackletProjectionsMemory(string name, Settings const void TrackletProjectionsMemory::addProj(Tracklet* tracklet) { if (layer_ != 0 && disk_ == 0) - assert(tracklet->validProj(layer_)); + assert(tracklet->validProj(layer_ - 1)); if (layer_ == 0 && disk_ != 0) - assert(tracklet->validProjDisk(disk_)); + assert(tracklet->validProj(N_LAYER + abs(disk_) - 1)); if (layer_ != 0 && disk_ != 0) - assert(tracklet->validProj(layer_) || tracklet->validProjDisk(disk_)); + assert(tracklet->validProj(layer_ - 1) || tracklet->validProj(N_LAYER + abs(disk_) - 1)); for (auto& itracklet : tracklets_) { if (itracklet == tracklet) { @@ -34,31 +34,22 @@ void TrackletProjectionsMemory::addProj(Tracklet* tracklet) { void TrackletProjectionsMemory::clean() { tracklets_.clear(); } -void TrackletProjectionsMemory::writeTPROJ(bool first) { +void TrackletProjectionsMemory::writeTPROJ(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirTP = settings_.memPath() + "TrackletProjections/"; - if (not std::filesystem::exists(dirTP)) { - int fail = system((string("mkdir -p ") + dirTP).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirTP; - } std::ostringstream oss; oss << dirTP << "TrackletProjections_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - out_.open(fname); - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirTP, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; for (unsigned int j = 0; j < tracklets_.size(); j++) { - string proj = (layer_ > 0 && tracklets_[j]->validProj(layer_)) ? tracklets_[j]->trackletprojstrlayer(layer_) - : tracklets_[j]->trackletprojstrdisk(disk_); + string proj = (layer_ > 0 && tracklets_[j]->validProj(layer_ - 1)) ? tracklets_[j]->trackletprojstrlayer(layer_) + : tracklets_[j]->trackletprojstrdisk(disk_); out_ << "0x"; out_ << std::setfill('0') << std::setw(2); out_ << hex << j << dec; diff --git a/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc b/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc index a7ef1821f3273..e08cd039b9e24 100644 --- a/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc +++ b/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc @@ -10,8 +10,8 @@ using namespace std; using namespace trklet; -TripletEngine::TripletEngine(string name, Settings const &settings, Globals *global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector) { +TripletEngine::TripletEngine(string name, Settings const &settings, Globals *global) + : ProcessBase(name, settings, global) { stubpairs_.clear(); thirdvmstubs_.clear(); layer1_ = 0; @@ -207,10 +207,13 @@ void TripletEngine::execute() { if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " - << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()) << " " - << benddecode(thirdvmstub.bend().value(), thirdvmstub.isPSmodule()); + << settings_.benddecode(secondvmstub.bend().value(), layer2_ - 1, secondvmstub.isPSmodule()) + << " " << settings_.benddecode(thirdvmstub.bend().value(), layer3_ - 1, thirdvmstub.isPSmodule()); } - continue; + + //FIXME temporarily commented out until bend table fixed + //if (!settings_.writeTripletTables()) + // continue; } if (settings_.writeTripletTables()) { if (index >= table_.size()) @@ -230,7 +233,7 @@ void TripletEngine::execute() { edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName(); if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; fout.close(); } stubtriplets_->addStubs(thirdvmstub.stub(), @@ -290,8 +293,8 @@ void TripletEngine::execute() { if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "Stub triplet rejected because of stub pt cut bends : " - << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()) << " " - << benddecode(thirdvmstub.bend().value(), thirdvmstub.isPSmodule()); + << settings_.benddecode(secondvmstub.bend().value(), disk2_ + 5, secondvmstub.isPSmodule()) << " " + << settings_.benddecode(thirdvmstub.bend().value(), layer3_ - 1, thirdvmstub.isPSmodule()); } continue; } @@ -313,7 +316,7 @@ void TripletEngine::execute() { edm::LogVerbatim("Tracklet") << "Adding layer-disk pair in " << getName(); if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; fout.close(); } stubtriplets_->addStubs(thirdvmstub.stub(), @@ -374,8 +377,8 @@ void TripletEngine::execute() { if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " - << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()) << " " - << benddecode(thirdvmstub.bend().value(), thirdvmstub.isPSmodule()); + << settings_.benddecode(secondvmstub.bend().value(), layer2_ - 1, secondvmstub.isPSmodule()) + << " " << settings_.benddecode(thirdvmstub.bend().value(), disk3_ + 5, thirdvmstub.isPSmodule()); } continue; } @@ -397,7 +400,7 @@ void TripletEngine::execute() { edm::LogVerbatim("Tracklet") << "Adding layer-disk pair in " << getName(); if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; fout.close(); } stubtriplets_->addStubs(thirdvmstub.stub(), @@ -460,7 +463,7 @@ void TripletEngine::writeTables() { ofstream fout; stringstream tableName; - tableName << "table/table_" << name_ << "_" << iSector_ << ".txt"; + tableName << "table/table_" << name_ << ".txt"; fout.open(tableName.str(), ofstream::out); for (const auto &entry : table_) @@ -469,7 +472,7 @@ void TripletEngine::writeTables() { for (const auto &tedName : spTable_) { tableName.str(""); - tableName << "table/table_" << tedName.first << "_" << name_ << "_" << iSector_ << ".txt"; + tableName << "table/table_" << tedName.first << "_" << name_ << ".txt"; fout.open(tableName.str(), ofstream::out); for (const auto &entry : tedName.second) { diff --git a/L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc index 9ff195063fb54..3541d9ce522f6 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc @@ -7,8 +7,7 @@ using namespace std; using namespace trklet; -VMProjectionsMemory::VMProjectionsMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) { +VMProjectionsMemory::VMProjectionsMemory(string name, Settings const& settings) : MemoryBase(name, settings) { initLayerDisk(7, layer_, disk_); } @@ -21,7 +20,8 @@ void VMProjectionsMemory::addTracklet(Tracklet* tracklet, unsigned int allprojin tracklets_.push_back(tmp); } -void VMProjectionsMemory::writeVMPROJ(bool first) { +void VMProjectionsMemory::writeVMPROJ(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirVM = settings_.memPath() + "VMProjections/"; std::ostringstream oss; @@ -34,21 +34,7 @@ void VMProjectionsMemory::writeVMPROJ(bool first) { oss << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirVM)) { - int fail = system((string("mkdir -p ") + dirVM).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirVM; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirVM, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc index dd3015ea1e75f..484bd3ad549fe 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc @@ -13,8 +13,8 @@ using namespace std; using namespace trklet; -VMRouter::VMRouter(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector), vmrtable_(settings) { +VMRouter::VMRouter(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global), vmrtable_(settings) { layerdisk_ = initLayerDisk(4); vmstubsMEPHI_.resize(settings_.nvmme(layerdisk_), nullptr); @@ -22,7 +22,7 @@ VMRouter::VMRouter(string name, Settings const& settings, Globals* global, unsig overlapbits_ = 7; nextrabits_ = overlapbits_ - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_)); - vmrtable_.init(layerdisk_, getName()); + vmrtable_.init(layerdisk_, name); nbitszfinebintable_ = settings_.vmrlutzbits(layerdisk_); nbitsrfinebintable_ = settings_.vmrlutrbits(layerdisk_); @@ -136,7 +136,17 @@ void VMRouter::addInput(MemoryBase* memory, string input) { InputLinkMemory* tmp1 = dynamic_cast(memory); assert(tmp1 != nullptr); if (tmp1 != nullptr) { - stubinputs_.push_back(tmp1); + if (layerdisk_ > N_LAYER && tmp1->getName().find("2S_") != string::npos) { + stubinputdisk2stmp_.push_back(tmp1); + } else { + stubinputtmp_.push_back(tmp1); + } + } + //This gymnastic is done to ensure that in the disks the PS stubs are processed before + //the 2S stubs. This is needed by the current HLS implemenation of the VM router. + stubinputs_ = stubinputtmp_; + for (auto& mem : stubinputdisk2stmp_) { + stubinputs_.push_back(mem); } return; } @@ -149,7 +159,7 @@ void VMRouter::execute() { //Loop over the input stubs for (auto& stubinput : stubinputs_) { for (unsigned int i = 0; i < stubinput->nStubs(); i++) { - if (allStubCounter > settings_.maxStep("VMR")) + if (allStubCounter >= settings_.maxStep("VMR")) continue; if (allStubCounter > 127) continue; @@ -235,10 +245,18 @@ void VMRouter::execute() { assert(vmstubsMEPHI_[ivmPlus] != nullptr); vmstubsMEPHI_[ivmPlus]->addStub(vmstub, vmbin); + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << vmstubsMEPHI_[ivmPlus]->getName() + << " ivmPlus" << ivmPlus << " bin=" << vmbin; + } if (ivmMinus != ivmPlus) { assert(vmstubsMEPHI_[ivmMinus] != nullptr); vmstubsMEPHI_[ivmMinus]->addStub(vmstub, vmbin); + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << vmstubsMEPHI_[ivmMinus]->getName() + << " ivmMinus" << ivmMinus << " bin=" << vmbin; + } } //Fill the TE VM memories diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc b/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc index f6ce34e3badc6..b2025b7d0067f 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc @@ -4,6 +4,7 @@ #include "L1Trigger/TrackFindingTracklet/interface/VMStubTE.h" #include "L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" @@ -13,8 +14,8 @@ using namespace std; using namespace trklet; -VMRouterCM::VMRouterCM(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector), vmrtable_(settings) { +VMRouterCM::VMRouterCM(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global), vmrtable_(settings) { layerdisk_ = initLayerDisk(4); vmstubsMEPHI_.resize(1, nullptr); @@ -22,7 +23,7 @@ VMRouterCM::VMRouterCM(string name, Settings const& settings, Globals* global, u overlapbits_ = 7; nextrabits_ = overlapbits_ - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_)); - vmrtable_.init(layerdisk_, getName()); + vmrtable_.init(layerdisk_); nbitszfinebintable_ = settings_.vmrlutzbits(layerdisk_); nbitsrfinebintable_ = settings_.vmrlutrbits(layerdisk_); @@ -36,14 +37,17 @@ void VMRouterCM::addOutput(MemoryBase* memory, string output) { << output; } + if (output == "allinnerstubout") { + AllInnerStubsMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + char memtype = memory->getName().back(); + allinnerstubs_.emplace_back(memtype, tmp); + return; + } + if (output.substr(0, 10) == "allstubout") { AllStubsMemory* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - char memtype = 0; - if (output.size() > 10) { - memtype = output[11]; - } - allstubs_.emplace_back(memtype, tmp); + allstubs_.push_back(tmp); return; } @@ -139,16 +143,67 @@ void VMRouterCM::execute() { allStubCounter++; + for (auto& allstub : allstubs_) { + allstub->addStub(stub); + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << allstub->getName(); + } + } + FPGAWord iphi = stub->phicorr(); unsigned int iphipos = iphi.bits(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + 3), 3); - //Fill allstubs memories - in HLS this is the same write to multiple memories - for (auto& allstub : allstubs_) { + unsigned int phicutmax = 4; + unsigned int phicutmin = 4; + + if (layerdisk_ != 0) { + phicutmax = 6; + phicutmin = 2; + } + + //Fill inner allstubs memories - in HLS this is the same write to multiple memories + for (auto& allstub : allinnerstubs_) { char memtype = allstub.first; - if ((memtype == 'R' && iphipos < 5) || (memtype == 'L' && iphipos >= 3) || (memtype == 'A' && iphipos < 4) || - (memtype == 'B' && iphipos >= 4) || (memtype == 'E' && iphipos >= 4) || (memtype == 'F' && iphipos < 4) || - (memtype == 'C' && iphipos >= 4) || (memtype == 'D' && iphipos < 4)) + if (memtype == 'R' && iphipos < phicutmax) + continue; + if (memtype == 'L' && iphipos >= phicutmin) + continue; + if (memtype == 'A' && iphipos < 4) + continue; + if (memtype == 'B' && iphipos >= 4) + continue; + if (memtype == 'E' && iphipos >= 4) continue; + if (memtype == 'F' && iphipos < 4) + continue; + if (memtype == 'C' && iphipos >= 4) + continue; + if (memtype == 'D' && iphipos < 4) + continue; + + int absz = std::abs(stub->z().value()); + if (layerdisk_ == 1 && absz < VMROUTERCUTZL2 / settings_.kz(layerdisk_)) + continue; + if ((layerdisk_ == 2 || layerdisk_ == 4) && absz > VMROUTERCUTZL1L3L5 / settings_.kz(layerdisk_)) + continue; + if ((layerdisk_ == 6 || layerdisk_ == 8) && stub->r().value() > VMROUTERCUTRD1D3 / settings_.kr()) + continue; + if ((layerdisk_ == 6 || layerdisk_ == 8) && stub->r().value() < 2 * int(N_DSS_MOD)) + continue; + if (layerdisk_ == 0) { + if (memtype == 'M' || memtype == 'R' || memtype == 'L') { + if (absz < VMROUTERCUTZL1 / settings_.kz(layerdisk_)) + continue; + } else { + if (absz > VMROUTERCUTZL1L3L5 / settings_.kz(layerdisk_)) + continue; + } + } + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << allstub.second->getName(); + } + allstub.second->addStub(stub); } @@ -156,24 +211,15 @@ void VMRouterCM::execute() { unsigned int ivm = iphi.bits(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_)), settings_.nbitsvmme(layerdisk_)); - unsigned int extrabits = iphi.bits(iphi.nbits() - overlapbits_, nextrabits_); - - unsigned int ivmPlus = ivm; - - if (extrabits == ((1U << nextrabits_) - 1) && ivm != ((1U << settings_.nbitsvmme(layerdisk_)) - 1)) - ivmPlus++; - unsigned int ivmMinus = ivm; - if (extrabits == 0 && ivm != 0) - ivmMinus--; //Calculate the z and r position for the vmstub //Take the top nbitszfinebintable_ bits of the z coordinate - int indexz = (((1 << (stub->z().nbits() - 1)) + stub->z().value()) >> (stub->z().nbits() - nbitszfinebintable_)); + int indexz = (stub->z().value() >> (stub->z().nbits() - nbitszfinebintable_)) & ((1 << nbitszfinebintable_) - 1); int indexr = -1; if (layerdisk_ > (N_LAYER - 1)) { if (negdisk) { - indexz = (1 << nbitszfinebintable_) - indexz; + indexz = ((1 << nbitszfinebintable_) - 1) - indexz; } indexr = stub->r().value(); if (stub->isPSmodule()) { @@ -181,7 +227,7 @@ void VMRouterCM::execute() { } } else { //Take the top nbitsfinebintable_ bits of the z coordinate. The & is to handle the negative z values. - indexr = (((1 << (stub->r().nbits() - 1)) + stub->r().value()) >> (stub->r().nbits() - nbitsrfinebintable_)); + indexr = (stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_)) & ((1 << nbitsrfinebintable_) - 1); } assert(indexz >= 0); @@ -211,11 +257,8 @@ void VMRouterCM::execute() { allStubIndex); assert(vmstubsMEPHI_[0] != nullptr); - vmstubsMEPHI_[0]->addStub(vmstub, ivmPlus * nvmmebins_ + vmbin); - if (ivmMinus != ivmPlus) { - vmstubsMEPHI_[0]->addStub(vmstub, ivmMinus * nvmmebins_ + vmbin); - } + vmstubsMEPHI_[0]->addStub(vmstub, ivm * nvmmebins_ + vmbin); //Fill the TE VM memories if (layerdisk_ >= 6 && (!stub->isPSmodule())) @@ -231,9 +274,10 @@ void VMRouterCM::execute() { lutval = melut; } else { lutval = vmrtable_.lookupdisk(indexz, indexr); + if (lutval == 0) { + continue; + } } - if (lutval == -1) - continue; assert(lutval >= 0); diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouterPhiCorrTable.cc b/L1Trigger/TrackFindingTracklet/src/VMRouterPhiCorrTable.cc index 257843cd5c49b..84cb75dac4e14 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouterPhiCorrTable.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouterPhiCorrTable.cc @@ -33,25 +33,19 @@ void VMRouterPhiCorrTable::init(int layer, int bendbits, int rbits) { } if (settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } - - writeVMTable(settings_.tablePath() + "VMPhiCorrL" + std::to_string(layer_) + ".tab", false); + writeVMTable(settings_.tablePath(), "VMPhiCorrL" + std::to_string(layer_) + ".tab", false); } } int VMRouterPhiCorrTable::getphiCorrValue(int ibend, int irbin) const { - double bend = trklet::benddecode(ibend, layer_ <= (int)N_PSLAYER); + assert(layer_ > 0.0 && layer_ <= (int)N_LAYER); + double bend = -settings_.benddecode(ibend, layer_ - 1, layer_ <= (int)N_PSLAYER); //for the rbin - calculate the distance to the nominal layer radius double Delta = (irbin + 0.5) * dr_ - settings_.drmax(); //calculate the phi correction - this is a somewhat approximate formula - double dphi = (Delta / 0.18) * (bend * settings_.stripPitch(false)) / rmean_; + double dphi = (Delta / 0.18) * (bend * settings_.stripPitch(layer_ <= (int)N_PSLAYER)) / rmean_; int idphi = 0; diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc b/L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc index 3605f8aadbae0..1853a01f71f6b 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc @@ -1,6 +1,7 @@ // VMRouterTable: Lookup table used by the VMRouter to route stubs and provide information about which VMStubs are needed by the TrackletEngine #include "L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h" #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" #include #include @@ -43,6 +44,23 @@ void VMRouterTable::init(unsigned int layerdisk, std::string const& name) { double r = rmin_ + (irbin + 0.5) * dr_; double z = zmin_ + (izbin + 0.5) * dz_; + if (settings_.combined()) { + int iznew = izbin - (1 << (zbits_ - 1)); + if (iznew < 0) + iznew += (1 << zbits_); + assert(iznew >= 0); + assert(iznew < (1 << zbits_)); + z = zmin_ + (iznew + 0.5) * dz_; + if (layerdisk < N_LAYER) { + int irnew = irbin - (1 << (rbits_ - 1)); + if (irnew < 0) + irnew += (1 << rbits_); + assert(irnew >= 0); + assert(irnew < (1 << rbits_)); + r = rmin_ + (irnew + 0.5) * dr_; + } + } + if (layerdisk > (N_LAYER - 1) && irbin < 10) //special case for the tabulated radii in 2S disks r = (layerdisk <= 7) ? settings_.rDSSinner(irbin) : settings_.rDSSouter(irbin); @@ -63,10 +81,11 @@ void VMRouterTable::init(unsigned int layerdisk, std::string const& name) { if (layerdisk >= N_LAYER) { double rproj = r * settings_.zmean(layerdisk - N_LAYER) / z; bin = 0.5 * NBINS * (rproj - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm()); + //bin value of zero indicates that stub is out of range if (bin < 0) bin = 0; if (bin >= NBINS / 2) - bin = NBINS / 2 - 1; + bin = 0; vmrtabletedisk_.push_back(bin); } @@ -101,39 +120,69 @@ void VMRouterTable::init(unsigned int layerdisk, std::string const& name) { } if (settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } + if (!settings_.combined()) { + // write finebin tables + writeVMTable(settings_.tablePath(), name + "_finebin.tab", vmrtable_); + // write barrel seed teinner tables (L1L2, L2L3, L3L4, L5L6) + if (layerdisk == 0 || layerdisk == 1 || layerdisk == 2 || layerdisk == 4) { + std::string fnamesuffix = "L" + to_string(layerdisk + 1) + "L" + std::to_string(layerdisk + 2); + writeVMTable(settings_.tablePath(), "VMTableInner" + fnamesuffix + ".tab", vmrtableteinner_); + } + // write disk seed teinner tables (D1D2, D3D4) + if (layerdisk == 6 || layerdisk == 8) { + std::string fnamesuffix = "D" + to_string(layerdisk - N_LAYER + 1) + "D" + to_string(layerdisk - N_LAYER + 2); + writeVMTable(settings_.tablePath(), "VMTableInner" + fnamesuffix + ".tab", vmrtableteinner_); + } + // write overlap seed teinner tables (L1D1, L2D1) + if (layerdisk == 0 || layerdisk == 1) { + std::string fnamesuffix = "L" + to_string(layerdisk + 1) + "D1"; + writeVMTable(settings_.tablePath(), "VMTableInner" + fnamesuffix + ".tab", vmrtableteinneroverlap_); + } + // write barrel teouter tables (L2, L3, L4, L6, same as finebin tables) + if (layerdisk == 1 || layerdisk == 2 || layerdisk == 3 || layerdisk == 5) { + std::string fnamesuffix = "L" + to_string(layerdisk + 1); + writeVMTable(settings_.tablePath(), "VMTableOuter" + fnamesuffix + ".tab", vmrtable_); + } + // write disk teouter tables (D1, D2, D4) + if (layerdisk == 6 || layerdisk == 7 || layerdisk == 9) { + std::string fnamesuffix = "D" + to_string(layerdisk - N_LAYER + 1); + writeVMTable(settings_.tablePath(), "VMTableOuter" + fnamesuffix + ".tab", vmrtabletedisk_); + } + } else { + std::string fname = "VMRME_"; + if (layerdisk < 6) { + fname += "L" + std::to_string(layerdisk + 1) + ".tab"; + } else { + fname += "D" + std::to_string(layerdisk - 5) + ".tab"; + } + writeVMTable(settings_.tablePath(), fname, vmrtable_); - // write finebin tables - writeVMTable(settings_.tablePath() + name + "_finebin.tab", vmrtable_); - // write barrel seed teinner tables (L1L2, L2L3, L3L4, L5L6) - if (layerdisk == 0 || layerdisk == 1 || layerdisk == 2 || layerdisk == 4) { - std::string fnamesuffix = "L" + to_string(layerdisk + 1) + "L" + std::to_string(layerdisk + 2); - writeVMTable(settings_.tablePath() + "VMTableInner" + fnamesuffix + ".tab", vmrtableteinner_); - } - // write disk seed teinner tables (D1D2, D3D4) - if (layerdisk == 6 || layerdisk == 8) { - std::string fnamesuffix = "D" + to_string(layerdisk - N_LAYER + 1) + "D" + to_string(layerdisk - N_LAYER + 2); - writeVMTable(settings_.tablePath() + "VMTableInner" + fnamesuffix + ".tab", vmrtableteinner_); - } - // write overlap seed teinner tables (L1D1, L2D1) - if (layerdisk == 0 || layerdisk == 1) { - std::string fnamesuffix = "L" + to_string(layerdisk + 1) + "D1"; - writeVMTable(settings_.tablePath() + "VMTableInner" + fnamesuffix + ".tab", vmrtableteinneroverlap_); - } - // write barrel teouter tables (L2, L3, L4, L6, same as finebin tables) - if (layerdisk == 1 || layerdisk == 2 || layerdisk == 3 || layerdisk == 5) { - std::string fnamesuffix = "L" + to_string(layerdisk + 1); - writeVMTable(settings_.tablePath() + "VMTableOuter" + fnamesuffix + ".tab", vmrtable_); - } - // write disk teouter tables (D1, D2, D4) - if (layerdisk == 6 || layerdisk == 7 || layerdisk == 9) { - std::string fnamesuffix = "D" + to_string(layerdisk - N_LAYER + 1); - writeVMTable(settings_.tablePath() + "VMTableOuter" + fnamesuffix + ".tab", vmrtabletedisk_); + if (layerdisk == 6 || layerdisk == 7 || layerdisk == 9) { + std::string fname = "VMRTE_D" + to_string(layerdisk - N_LAYER + 1) + ".tab"; + writeVMTable(settings_.tablePath(), fname, vmrtabletedisk_); + } + + if (vmrtableteinner_.size() > 0) { + ofstream out; + if (layerdisk < 6) { + out.open(settings_.tablePath() + "TP_L" + std::to_string(layerdisk + 1) + ".tab"); + } else { + out.open(settings_.tablePath() + "TP_D" + std::to_string(layerdisk - 5) + ".tab"); + } + out << "{" << endl; + for (unsigned int i = 0; i < vmrtableteinner_.size(); i++) { + if (i != 0) { + out << "," << endl; + } + if (vmrtableteinner_[i] == -1) { + out << 1023; + } else { + out << vmrtableteinner_[i]; + } + } + out << endl << "};" << endl; + out.close(); + } } } } @@ -325,10 +374,8 @@ int VMRouterTable::lookupinnerThird(int zbin, int rbin) { return vmrtableteinnerThird_[index]; } -void VMRouterTable::writeVMTable(std::string const& name, std::vector const& table) { - ofstream out(name); - if (out.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << name; +void VMRouterTable::writeVMTable(std::string const& dir, std::string const& name, std::vector const& table) { + ofstream out = openfile(dir, name, __FILE__, __LINE__); out << "{" << endl; for (unsigned int i = 0; i < table.size(); i++) { diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc index 275a73aca4213..9ac11723a6fcf 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc @@ -6,8 +6,7 @@ using namespace std; using namespace trklet; -VMStubsMEMemory::VMStubsMEMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) { +VMStubsMEMemory::VMStubsMEMemory(string name, Settings const& settings) : MemoryBase(name, settings) { unsigned int layerdisk = initLayerDisk(6); if (layerdisk < N_LAYER) { binnedstubs_.resize(settings_.NLONGVMBINS()); @@ -17,7 +16,8 @@ VMStubsMEMemory::VMStubsMEMemory(string name, Settings const& settings, unsigned } } -void VMStubsMEMemory::writeStubs(bool first) { +void VMStubsMEMemory::writeStubs(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirVM = settings_.memPath() + "VMStubsME/"; std::ostringstream oss; @@ -30,21 +30,7 @@ void VMStubsMEMemory::writeStubs(bool first) { oss << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirVM)) { - int fail = system((string("mkdir -p ") + dirVM).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirVM; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirVM, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; @@ -53,6 +39,8 @@ void VMStubsMEMemory::writeStubs(bool first) { string stub = binnedstubs_[i][j].stubindex().str(); stub += "|" + binnedstubs_[i][j].bend().str(); + FPGAWord finephipos = binnedstubs_[i][j].finephi(); + stub += "|" + finephipos.str(); FPGAWord finepos = binnedstubs_[i][j].finerz(); stub += "|" + finepos.str(); out_ << hex << i << " " << j << dec << " " << stub << " " << trklet::hexFormat(stub) << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc index be05d40c9536a..47c70a825d5b4 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc @@ -6,11 +6,12 @@ using namespace std; using namespace trklet; -VMStubsTEMemory::VMStubsTEMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) { +VMStubsTEMemory::VMStubsTEMemory(string name, Settings const& settings) : MemoryBase(name, settings) { //set the layer or disk that the memory is in initLayerDisk(6, layer_, disk_); + layerdisk_ = initLayerDisk(6); + //Pointer to other VMStub memory for creating stub pairs other_ = nullptr; @@ -71,8 +72,10 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub, int bin) { if (negdisk) bin += 4; assert(bin < (int)stubsbinnedvm_.size()); - stubsbinnedvm_[bin].push_back(vmstub); - stubsvm_.push_back(vmstub); + if (stubsbinnedvm_[bin].size() < N_VMSTUBSMAX) { + stubsbinnedvm_[bin].push_back(vmstub); + stubsvm_.push_back(vmstub); + } return true; } @@ -81,7 +84,7 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub, int bin) { if (!pass) { if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << getName() << " Stub failed bend cut. bend = " - << benddecode(vmstub.bend().value(), vmstub.isPSmodule()); + << settings_.benddecode(vmstub.bend().value(), layerdisk_, vmstub.isPSmodule()); return false; } @@ -103,7 +106,7 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub, int bin) { stubsbinnedvm_[bin].push_back(vmstub); } } else { - if (vmstub.stub()->isBarrel()) { + if (vmstub.stub()->layerdisk() < N_LAYER) { if (!isinner_) { if (stubsbinnedvm_[bin].size() >= settings_.maxStubsPerBin()) return false; @@ -143,7 +146,7 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub) { if (!pass) { if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << getName() << " Stub failed bend cut. bend = " - << benddecode(vmstub.bend().value(), vmstub.isPSmodule()); + << settings_.benddecode(vmstub.bend().value(), layerdisk_, vmstub.isPSmodule()); return false; } @@ -162,7 +165,7 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub) { } } } else { - if (vmstub.stub()->isBarrel()) { + if (vmstub.stub()->layerdisk() < N_LAYER) { if (!isinner_) { stubsbinnedvm_[bin].push_back(vmstub); } @@ -214,7 +217,8 @@ void VMStubsTEMemory::clean() { } } -void VMStubsTEMemory::writeStubs(bool first) { +void VMStubsTEMemory::writeStubs(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirVM = settings_.memPath() + "VMStubsTE/"; openFile(first, dirVM, "VMStubs_"); @@ -227,7 +231,7 @@ void VMStubsTEMemory::writeStubs(bool first) { out_ << " " << stub << " " << trklet::hexFormat(stub) << endl; } } else { // outer VM for TE purpose - for (unsigned int i = 0; i < settings_.NLONGVMBINS(); i++) { + for (unsigned int i = 0; i < stubsbinnedvm_.size(); i++) { for (unsigned int j = 0; j < stubsbinnedvm_[i].size(); j++) { string stub = stubsbinnedvm_[i][j].str(); out_ << hex << i << " " << j << dec << " " << stub << " " << trklet::hexFormat(stub) << endl; @@ -273,22 +277,12 @@ void VMStubsTEMemory::setbendtable(std::vector vmbendtable) { vmbendtable_[i] = vmbendtable[i]; } - if (iSector_ == 0 && settings_.writeTable()) + if (settings_.writeTable()) writeVMBendTable(); } void VMStubsTEMemory::writeVMBendTable() { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } - - const string fname = settings_.tablePath() + getName() + "_vmbendcut.tab"; - ofstream outvmbendcut(fname); - if (outvmbendcut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; + ofstream outvmbendcut = openfile(settings_.tablePath(), getName() + "_vmbendcut.tab", __FILE__, __LINE__); outvmbendcut << "{" << endl; unsigned int vmbendtableSize = vmbendtable_.size(); diff --git a/L1Trigger/TrackFindingTracklet/test/HybridTracks_cfg.py b/L1Trigger/TrackFindingTracklet/test/HybridTracks_cfg.py index 7b355253cc4e5..357f01cf38584 100644 --- a/L1Trigger/TrackFindingTracklet/test/HybridTracks_cfg.py +++ b/L1Trigger/TrackFindingTracklet/test/HybridTracks_cfg.py @@ -18,6 +18,11 @@ from Configuration.AlCa.GlobalTag import GlobalTag process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:upgradePLS3', '') +############################################################ +# L1 tracking: remake stubs? +############################################################ +process.load('L1Trigger.TrackTrigger.TrackTrigger_cff') + # ---------------------------------------------------------------------------------- # input @@ -27,8 +32,6 @@ ) process.source = cms.Source("PoolSource", fileNames = Source_Files) - -# ---------------------------------------------------------------------------------- # L1 tracking => hybrid emulation process.load("L1Trigger.TrackFindingTracklet.L1HybridEmulationTracks_cff") @@ -44,6 +47,26 @@ #process.TTTracksEmulation = cms.Path(process.L1PromptExtendedHybridTracks) #process.TTTracksEmulationWithTruth = cms.Path(process.L1PromptExtendedHybridTracksWithAssociators) +# ----------------------------------------------------------------------------------- +# DTC Emulations +process.load( 'L1Trigger.TrackerDTC.ProducerED_cff' ) +process.load( 'L1Trigger.TrackerDTC.ProducerES_cff' ) + +#--- Load code that produces DTCStubs + +# load Track Trigger Configuration +process.load( 'L1Trigger.TrackerDTC.ProducerES_cff' ) +# load code that produces DTCStubs +process.load( 'L1Trigger.TrackerDTC.ProducerED_cff' ) +# load code that analyzes DTCStubs +process.load( 'L1Trigger.TrackerDTC.Analyzer_cff' ) + +process.dtc = cms.Path( process.TrackerDTCProducer ) + + + +# ---------------------------------------------------------------------------------- + # ---------------------------------------------------------------------------------- # output module @@ -58,5 +81,5 @@ #process.schedule = cms.Schedule(process.TTTracksEmulation,process.FEVToutput_step) -process.schedule = cms.Schedule(process.TTTracksEmulationWithTruth,process.FEVToutput_step) +process.schedule = cms.Schedule(process.dtc,process.TTTracksEmulationWithTruth,process.FEVToutput_step) diff --git a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py index aea44217dbdff..494fdfc7e4470 100644 --- a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py +++ b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py @@ -28,8 +28,8 @@ process.load('Configuration.StandardSequences.MagneticField_cff') process.load('FWCore.MessageService.MessageLogger_cfi') -process.MessageLogger.L1track=dict() -process.MessageLogger.Tracklet = cms.untracked.PSet(limit = cms.untracked.int32(-1)) +process.MessageLogger.L1track = dict(limit = -1) +process.MessageLogger.Tracklet = dict(limit = -1) if GEOMETRY == "D49": print "using geometry " + GEOMETRY + " (tilted)" @@ -72,6 +72,8 @@ # Or read specified .root file: inputMC = ["/store/relval/CMSSW_11_3_0_pre3/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_113X_mcRun4_realistic_v3_2026D49PU200-v1/00000/001edbad-174e-46af-932a-6ce8e04aee1c.root"] + #inputMC = ["/store/relval/CMSSW_11_2_0_pre8/RelValSingleMuPt10/GEN-SIM-RECO/112X_mcRun4_realistic_v3_2026D49noPU-v1/00000/007d817e-9c59-4dec-959b-0f227942cdf0.root"] + #inputMC = ["/store/relval/CMSSW_11_3_0_pre3/RelValSingleMuPt10/GEN-SIM-DIGI-RAW/113X_mcRun4_realistic_v3_2026D49noPU-v1/00000/04514913-efc7-49fc-8df4-90efe43ca047.root"] else: print "this is not a valid geometry!!!" @@ -86,7 +88,7 @@ # L1 tracking: remake stubs? ############################################################ -#process.load('L1Trigger.TrackTrigger.TrackTrigger_cff') +process.load('L1Trigger.TrackTrigger.TrackTrigger_cff') #from L1Trigger.TrackTrigger.TTStubAlgorithmRegister_cfi import * #process.load("SimTracker.TrackTriggerAssociation.TrackTriggerAssociator_cff") @@ -96,6 +98,7 @@ #process.TTClusterStub = cms.Path(process.TrackTriggerClustersStubs) #process.TTClusterStubTruth = cms.Path(process.TrackTriggerAssociatorClustersStubs) + ############################################################ # L1 tracking ############################################################ @@ -189,6 +192,23 @@ process.ana = cms.Path(process.L1TrackNtuple) +process.load( 'L1Trigger.TrackerDTC.ProducerED_cff' ) +process.load( 'L1Trigger.TrackerDTC.ProducerES_cff' ) + +#--- Load code that produces DTCStubs +# load Track Trigger Configuration +process.load( 'L1Trigger.TrackerDTC.ProducerES_cff' ) +# load code that produces DTCStubs +process.load( 'L1Trigger.TrackerDTC.ProducerED_cff' ) +# load code that analyzes DTCStubs +process.load( 'L1Trigger.TrackerDTC.Analyzer_cff' ) +#process.TrackTriggerSetup.FrontEnd.BendCut=5.0 +#process.TrackTriggerSetup.Hybrid.MinPt=1.0 +process.dtc = cms.Path( process.TrackerDTCProducer )#* process.TrackerDTCAnalyzer ) + + + + # use this if you want to re-run the stub making # process.schedule = cms.Schedule(process.TTClusterStub,process.TTClusterStubTruth,process.TTTracksEmulationWithTruth,process.ana) @@ -196,7 +216,7 @@ # process.schedule = cms.Schedule(process.TTClusterStubTruth,process.TTTracksEmulationWithTruth,process.ana) # use this to only run tracking + track associator -process.schedule = cms.Schedule(process.TTTracksEmulationWithTruth,process.ana) +process.schedule = cms.Schedule(process.dtc,process.TTTracksEmulationWithTruth,process.ana) ############################################################ diff --git a/L1Trigger/TrackFindingTracklet/test/Makefile b/L1Trigger/TrackFindingTracklet/test/Makefile index 263ae484f31ac..0288bbb14082e 100644 --- a/L1Trigger/TrackFindingTracklet/test/Makefile +++ b/L1Trigger/TrackFindingTracklet/test/Makefile @@ -57,6 +57,7 @@ $(shell touch dummyIncl/ctime) $(shell touch dummyIncl/cstdlib) $(shell touch dummyIncl/cmath) $(shell touch dummyIncl/exception) +$(shell touch dummyIncl/filesystem) $(shell touch dummyIncl/fstream) $(shell touch dummyIncl/iomanip) $(shell touch dummyIncl/iostream) @@ -66,6 +67,7 @@ $(shell touch dummyIncl/memory) $(shell touch dummyIncl/set) $(shell touch dummyIncl/sstream) $(shell touch dummyIncl/string) +$(shell touch dummyIncl/tuple) $(shell touch dummyIncl/vector) $(shell touch dummyIncl/unordered_map) $(shell touch dummyIncl/unordered_set) @@ -73,6 +75,8 @@ $(shell touch dummyIncl/utility) $(shell touch dummyIncl/algorithm) $(shell touch dummyIncl/ext/hash_set) $(shell touch dummyIncl/sys/time.h) +$(shell touch dummyIncl/sys/stat.h) +$(shell touch dummyIncl/sys/types.h) $(shell touch dummyIncl/ctime) $(shell touch dummyIncl/chrono) endif @@ -165,10 +169,23 @@ $(shell echo " while (phi > M_PI) { phi -= 2 * M_PI; }" >> DataFormats/Math/i $(shell echo " return phi; } " >> DataFormats/Math/interface/deltaPhi.h) $(shell echo "};" >> DataFormats/Math/interface/deltaPhi.h) $(shell echo "namespace angle0to2pi {" >> DataFormats/Math/interface/deltaPhi.h) -$(shell echo " inline double make0To2pi(double phi) { assert(std::abs(phi) < 100.0); " >> DataFormats/Math/interface/deltaPhi.h) -$(shell echo " while (phi < 0.0) { phi += 2 * M_PI; }" >> DataFormats/Math/interface/deltaPhi.h) -$(shell echo " while (phi > 2 * M_PI) { phi -= 2 * M_PI; }" >> DataFormats/Math/interface/deltaPhi.h) -$(shell echo " return phi; } " >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " template " >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " inline constexpr valType make0To2pi(valType angle) {" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " constexpr valType twoPi = 2*M_PI;" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " constexpr valType oneOverTwoPi = 1. / twoPi;" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " constexpr valType epsilon = 1.e-13;" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " if ((std::abs(angle) <= epsilon) || (std::abs(twoPi - std::abs(angle)) <= epsilon))" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " return (0.);" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " if (std::abs(angle) > twoPi) { " >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " valType nFac = trunc(angle * oneOverTwoPi);" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " angle -= (nFac * twoPi);" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " if (std::abs(angle) <= epsilon)" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " return (0.);" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " } " >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " if (angle < 0.)" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " angle += twoPi;" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " return (angle);" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " }" >> DataFormats/Math/interface/deltaPhi.h) $(shell echo "};" >> DataFormats/Math/interface/deltaPhi.h) $(shell echo "#endif" >> DataFormats/Math/interface/deltaPhi.h) endif @@ -188,13 +205,14 @@ CXXFLAGS += -std=c++17 #fix, otherwise ROOT cflags overrule c++11 LIBS = -lHtml - ifneq ($(CMSSW_BASE),) ROOTFIT_INCLUDE := $(shell cd $(CMSSW_BASE); scram tool info roofitcore | grep INCLUDE= | sed 's|INCLUDE=||') ROOTFIT_LIBDIR := $(shell cd $(CMSSW_BASE); scram tool info roofitcore | grep LIBDIR= | sed 's|LIBDIR=||') CINTINCLUDES := -I$(ROOTFIT_INCLUDE) +ifneq ($(ROOTFIT_INCLUDE),) CXXFLAGS += -I$(ROOTFIT_INCLUDE) +endif LDFLAGS += -L$(ROOTFIT_LIBDIR) endif diff --git a/L1Trigger/TrackFindingTracklet/test/fpga.cc b/L1Trigger/TrackFindingTracklet/test/fpga.cc index b9c1786f4549f..69736de2f3adf 100644 --- a/L1Trigger/TrackFindingTracklet/test/fpga.cc +++ b/L1Trigger/TrackFindingTracklet/test/fpga.cc @@ -54,9 +54,6 @@ int main(const int argc, const char **argv) { // --------------------------------------------------------- // these are options that are read from python configuration files for the CMSSW running, set manually for the standalone version - settings.setDTCLinkFile("../data/calcNumDTCLinks.txt"); - settings.setModuleCablingFile("../data/modules_T5v3_27SP_nonant_tracklet.dat"); - settings.setDTCLinkLayerDiskFile("../data/dtclinklayerdisk.dat"); settings.setFitPatternFile("../data/fitpattern.txt"); settings.setProcessingModulesFile("../data/processingmodules_" + settings.geomext() + ".dat"); settings.setMemoryModulesFile("../data/memorymodules_" + settings.geomext() + ".dat"); @@ -67,10 +64,6 @@ int main(const int argc, const char **argv) { settings.setTableTREFile("../data/table_TRE/table_TRE_Dummy.txt"); } - edm::LogVerbatim("Tracklet") << "cabling DTC links : " << settings.DTCLinkFile(); - edm::LogVerbatim("Tracklet") << "module cabling : " << settings.moduleCablingFile(); - edm::LogVerbatim("Tracklet") << "DTC link layer disk : " << settings.DTCLinkLayerDiskFile(); - edm::LogVerbatim("Tracklet") << "fit pattern : " << settings.fitPatternFile(); edm::LogVerbatim("Tracklet") << "process modules : " << settings.processingModulesFile(); edm::LogVerbatim("Tracklet") << "memory modules : " << settings.memoryModulesFile(); @@ -116,7 +109,8 @@ int main(const int argc, const char **argv) { for (int eventnum = 0; eventnum < nevents && !in->eof(); eventnum++) { SLHCEvent ev(*in); - L1SimTrack simtrk; + //auto simtrk = ev.simtrack(0); + //if (std::abs(std::abs(simtrk.eta())-1.3)>0.1) continue; // ----------------------------------------------------------------- // setup ROOT Tree and Add Monte Carlo tracks to the ROOT-Tree Event @@ -216,7 +210,7 @@ int main(const int argc, const char **argv) { eventProcessor.event(ev); - std::vector &tracks = eventProcessor.tracks(); + const std::vector &tracks = eventProcessor.tracks(); // --------------------------------------------------------- // Block for producing ROOT-Tree @@ -253,23 +247,23 @@ int main(const int argc, const char **argv) { if (nlayers + ndisks < 4) continue; nsim++; - for (int seed = -1; seed < 8; seed++) { + for (int seed = -1; seed < 12; seed++) { bool eff = false; bool effloose = false; int itrackmatch = -1; for (unsigned int itrack = 0; itrack < tracks.size(); itrack++) { - const std::vector &stubs = tracks[itrack]->stubs(); + const std::vector &stubs = tracks[itrack].stubs(); if (seed == -1) { - if (tracks[itrack]->duplicate()) + if (tracks[itrack].duplicate()) continue; } else { - if (seed != tracks[itrack]->seed()) + if (seed != tracks[itrack].seed()) continue; } unsigned int nmatch = 0; for (auto stub : stubs) { - if (stub->tpmatch(simtrackid)) { + if (stub.tpmatch(simtrackid)) { nmatch++; } } @@ -295,14 +289,14 @@ int main(const int argc, const char **argv) { } if (itrackmatch >= 0) { - dpt = tracks[itrackmatch]->pt(settings) - q * simtrack.pt(); - dphi = tracks[itrackmatch]->phi0(settings) - simtrack.phi(); + dpt = tracks[itrackmatch].pt(settings) - q * simtrack.pt(); + dphi = tracks[itrackmatch].phi0(settings) - simtrack.phi(); if (dphi > M_PI) dphi -= 2 * M_PI; if (dphi < -M_PI) dphi += 2 * M_PI; - deta = tracks[itrackmatch]->eta(settings) - simtrack.eta(); - dz0 = tracks[itrackmatch]->z0(settings) - simtrack.vz(); + deta = tracks[itrackmatch].eta(settings) - simtrack.eta(); + dz0 = tracks[itrackmatch].z0(settings) - simtrack.vz(); } out << eventnum << " " << simeventid << " " << seed << " " << simtrackid << " " << simtrack.type() << " " @@ -314,18 +308,20 @@ int main(const int argc, const char **argv) { } int ntrack = 0; + int i = 0; for (auto &track : tracks) { + i++; if (settings.writeMonitorData("Pars")) { - outpars << track->duplicate() << " " << track->eta(settings) << " " << track->phi0(settings) << " " - << track->z0(settings) << " " << angle0to2pi::make0To2pi(track->phi0(settings)) / (2 * M_PI / N_SECTOR) - << " " << track->rinv(settings); + outpars << track.duplicate() << " " << track.eta(settings) << " " << track.phi0(settings) << " " + << track.z0(settings) << " " << angle0to2pi::make0To2pi(track.phi0(settings)) / (2 * M_PI / N_SECTOR) + << " " << track.rinv(settings); } - if (!track->duplicate()) { + if (!track.duplicate()) { ntrack++; } } - edm::LogVerbatim("Tracklet") << "Number of found tracks : " << tracks.size() << " unique " << ntrack; + edm::LogVerbatim("Tracklet") << "Number of found tracks : " << tracks.size() << " unique " << ntrack << " "; } eventProcessor.printSummary(); diff --git a/L1Trigger/TrackerDTC/src/Stub.cc b/L1Trigger/TrackerDTC/src/Stub.cc index 73b23f4a7be38..5647a6a74027d 100644 --- a/L1Trigger/TrackerDTC/src/Stub.cc +++ b/L1Trigger/TrackerDTC/src/Stub.cc @@ -131,9 +131,9 @@ namespace trackerDTC { // encode bend const vector& encodingBend = setup.encodingBend(sm->windowSize(), sm->psModule()); - const auto pos = find(encodingBend.begin(), encodingBend.end(), abs(bend_)); + const auto pos = find(encodingBend.begin(), encodingBend.end(), abs(ttStubRef->bendBE())); const int uBend = distance(encodingBend.begin(), pos); - bend_ = pow(-1, signbit(bend_)) * (uBend - (int)encodingBend.size() / 2); + bend_ = pow(-1, signbit(bend_)) * uBend; } // returns bit accurate representation of Stub @@ -149,7 +149,9 @@ namespace trackerDTC { TTDTC::BV Stub::formatHybrid(int region) const { const SensorModule::Type type = sm_->type(); // stub phi w.r.t. processing region centre in rad - const double phi = phi_ - (region - .5) * setup_->baseRegion(); + const double phi = phi_ - (region - .5) * setup_->baseRegion() + + 0.5 * setup_->hybridBasePhi(type) * (1 << setup_->hybridWidthPhi(type)); + // convert stub variables into bit vectors const TTBV hwR(r_, setup_->hybridBaseR(type), setup_->hybridWidthR(type), true); const TTBV hwPhi(phi, setup_->hybridBasePhi(type), setup_->hybridWidthPhi(type), true); @@ -235,4 +237,4 @@ namespace trackerDTC { hwLayer.str()); } -} // namespace trackerDTC \ No newline at end of file +} // namespace trackerDTC From 208d3d41253ed5b83e30117a3546b5c0ab9c3851 Mon Sep 17 00:00:00 2001 From: aryd Date: Mon, 3 May 2021 07:10:15 -0400 Subject: [PATCH 05/15] Minor corrections to pin names and removal of duplicate code (#78) * Fix to compiler warning and removal of hardoded value in MatchCalculator * Updates to fix names of pins to make unique Co-authored-by: Anders Ryd --- .../TrackFindingTracklet/src/MatchCalculator.cc | 17 ++--------------- .../src/TrackletConfigBuilder.cc | 13 +++++++++---- .../TrackFindingTracklet/src/TripletEngine.cc | 2 +- L1Trigger/TrackFindingTracklet/src/VMRouter.cc | 3 ++- L1Trigger/TrackFindingTracklet/src/imath.cc | 4 ++-- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc index 86549eac723bf..f9b363ced8a2a 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc @@ -290,22 +290,9 @@ void MatchCalculator::execute(double phioffset) { << ideltaz * fact_ * settings_.kz() << " " << dz << " " << zmatchcut_[seedindex] * settings_.kz() << endl; } - bool imatch = false; - if (std::abs(dphi) < 0.2 && std::abs(dphiapprox) < 0.2) { //Changed the Asserts into if statements - if (settings_.writeMonitorData("Residuals")) { - double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv()); + bool imatch = (std::abs(ideltaphi) <= (int)phimatchcut_[seedindex]) && + (std::abs(ideltaz * fact_) <= (int)zmatchcut_[seedindex]); - globals_->ofstream("layerresiduals.txt") - << layerdisk_ + 1 << " " << seedindex << " " << pt << " " - << ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_) << " " - << dphiapprox * settings_.rmean(layerdisk_) << " " - << phimatchcut_[seedindex] * settings_.kphi1() * settings_.rmean(layerdisk_) << " " - << ideltaz * fact_ * settings_.kz() << " " << dz << " " << zmatchcut_[seedindex] * settings_.kz() << endl; - } - - imatch = (std::abs(ideltaphi) <= (int)phimatchcut_[seedindex]) && - (std::abs(ideltaz * fact_) <= (int)zmatchcut_[seedindex]); - } if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " ideltaphi cut " << ideltaphi << " " << phimatchcut_[seedindex] << " ideltaz*fact cut " << ideltaz * fact_ << " " diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc b/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc index cfed9abbcaebb..8984e574c3ebe 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc @@ -772,7 +772,7 @@ void TrackletConfigBuilder::writeASMemories(std::ostream& os, std::ostream& memo } if (ext == "") { - ext = "_" + iTCStr(iTC); + ext = "_" + LayerName(l1)+iTCStr(iTC); } if (iSeed < 4) { //Barrel seeding @@ -914,13 +914,13 @@ void TrackletConfigBuilder::writeVMSMemories(std::ostream& os, std::ostream& mem memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << iVMME + 1 << "n1 [18]" << std::endl; os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << iVMME + 1 << "n1" - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutPHI" << iTCStr(iReg) + << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutMEPHI" << iTCStr(iReg) << iVMME + 1 << " output=> ME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << iVMME + 1 << ".vmstubin" << std::endl; } } - //Next write VMS memories used by MatchCalculator + //Next write VMS memories used by TrackletEngine for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { for (unsigned int innerouterseed = 0; innerouterseed < 2; innerouterseed++) { //FIXME - code could be cleaner @@ -959,11 +959,16 @@ void TrackletConfigBuilder::writeVMSMemories(std::ostream& os, std::ostream& mem if (!used) continue; + + string inorout = "I"; + if (innerouterseed == 1 ) + inorout = "O"; + nmem++; memories << "VMStubsTE: VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << iVMTE + 1 << "n" << nmem << " [18]" << std::endl; os << "VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << iVMTE + 1 << "n" << nmem - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutPHI" << iTCStr(iReg) + << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutTE"< TE_" << LayerName(l1) << "PHI" << iRegStr(TE1 / NVMTE1, iSeed) << TE1 + 1 << "_" << LayerName(l2) << "PHI" << iRegStr(TE2 / NVMTE2, iSeed) << TE2 + 1; if (innerouterseed == 0) { diff --git a/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc b/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc index e08cd039b9e24..ce4a68a4fa6a2 100644 --- a/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc +++ b/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc @@ -466,7 +466,7 @@ void TripletEngine::writeTables() { tableName << "table/table_" << name_ << ".txt"; fout.open(tableName.str(), ofstream::out); - for (const auto &entry : table_) + for (const auto entry : table_) fout << entry << endl; fout.close(); diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc index 484bd3ad549fe..a64d06c28fb36 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc @@ -41,7 +41,8 @@ void VMRouter::addOutput(MemoryBase* memory, string output) { return; } - if (output.substr(0, 12) == "vmstuboutPHI") { + if (output.substr(0, 12) == "vmstuboutPHI" || output.substr(0, 14) == "vmstuboutMEPHI" || + output.substr(0, 15) == "vmstuboutTEIPHI" ||output.substr(0, 15) == "vmstuboutTEOPHI" ) { char seedtype = memory->getName().substr(11, 1)[0]; unsigned int pos = 12; int vmbin = memory->getName().substr(pos, 1)[0] - '0'; diff --git a/L1Trigger/TrackFindingTracklet/src/imath.cc b/L1Trigger/TrackFindingTracklet/src/imath.cc index a5498f6fa3959..3f5ce5dd37ebd 100644 --- a/L1Trigger/TrackFindingTracklet/src/imath.cc +++ b/L1Trigger/TrackFindingTracklet/src/imath.cc @@ -420,13 +420,13 @@ bool VarFlag::passes() { bool passes = true; for (const auto &cut_var : passes0) { bool local_passes = false; - for (const auto &pass : cut_var.second) + for (const auto pass : cut_var.second) local_passes = local_passes || pass; passes = passes && local_passes; } for (const auto &cut_var : passes1) { bool local_passes = false; - for (const auto &pass : cut_var.second) + for (const auto pass : cut_var.second) local_passes = local_passes || pass; passes = passes && local_passes; } From f17f4b6b0027f6cf90b90b0766e81261bdfe3110 Mon Sep 17 00:00:00 2001 From: aryd Date: Thu, 6 May 2021 10:44:22 -0400 Subject: [PATCH 06/15] Cleanup of LUTs (#79) * Fix to compiler warning and removal of hardoded value in MatchCalculator * Updates to fix names of pins to make unique * Migrate to new format of table for phi correction memory * Remove unused TETableBase class * Cleanup of VMRouterTable * Cleanup of LUT for bend consistency * Cleanup of LUT used in MEU for bend consistency * Cleanup code for disk bend table * cleanup of code to generate table used by TE * Cleanup of TP LUTs * Cleanup of LUTs for MatchCalculator cuts * Fix names of new LUT when writing to files * Cleanup of writing LUTs for the combined modules * Add code to write projection bend table for disk projections * More cleanup to remove hard coded layer and seed numbers * Cleanup of hardcoded numbers * Remove few more hardcoded constants: * Some further cleanup based on comments from Louise S. Co-authored-by: Anders Ryd Co-authored-by: Louise Skinnari --- .../TrackFindingTracklet/interface/Globals.h | 12 +- .../interface/InputLinkMemory.h | 2 - .../interface/MatchCalculator.h | 16 +- .../interface/MatchEngine.h | 13 +- .../interface/MatchEngineUnit.h | 10 +- .../interface/MatchProcessor.h | 22 +- .../interface/ProjectionRouter.h | 5 +- .../interface/ProjectionRouterBendTable.h | 31 - .../TrackFindingTracklet/interface/Settings.h | 6 +- .../interface/TETableBase.h | 34 - .../interface/TrackletConfigBuilder.h | 58 +- .../interface/TrackletEngine.h | 7 +- .../interface/TrackletEngineUnit.h | 9 +- .../interface/TrackletLUT.h | 81 ++ .../interface/TrackletProcessor.h | 20 +- .../TrackFindingTracklet/interface/VMRouter.h | 8 +- .../interface/VMRouterCM.h | 5 +- .../interface/VMRouterPhiCorrTable.h | 44 - .../interface/VMRouterTable.h | 62 -- .../interface/VMStubsTEMemory.h | 15 +- .../TrackFindingTracklet/src/FitTrack.cc | 2 +- L1Trigger/TrackFindingTracklet/src/Globals.cc | 2 +- .../src/InputLinkMemory.cc | 2 - .../src/MatchCalculator.cc | 130 +-- .../TrackFindingTracklet/src/MatchEngine.cc | 67 +- .../src/MatchEngineUnit.cc | 8 +- .../src/MatchProcessor.cc | 141 +-- .../TrackFindingTracklet/src/ProcessBase.cc | 46 +- .../src/ProjectionRouter.cc | 17 +- .../src/ProjectionRouterBendTable.cc | 54 - L1Trigger/TrackFindingTracklet/src/Sector.cc | 14 +- L1Trigger/TrackFindingTracklet/src/Stub.cc | 20 +- .../TrackFindingTracklet/src/TETableBase.cc | 33 - .../src/TrackletCalculatorBase.cc | 4 +- .../src/TrackletConfigBuilder.cc | 8 +- .../src/TrackletEngine.cc | 163 +-- .../src/TrackletEngineUnit.cc | 12 +- .../TrackFindingTracklet/src/TrackletLUT.cc | 945 ++++++++++++++++++ .../src/TrackletProcessor.cc | 302 ++---- .../TrackFindingTracklet/src/VMRouter.cc | 90 +- .../TrackFindingTracklet/src/VMRouterCM.cc | 45 +- .../src/VMRouterPhiCorrTable.cc | 65 -- .../TrackFindingTracklet/src/VMRouterTable.cc | 390 -------- .../src/VMStubsTEMemory.cc | 41 +- 44 files changed, 1449 insertions(+), 1612 deletions(-) delete mode 100644 L1Trigger/TrackFindingTracklet/interface/ProjectionRouterBendTable.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/TETableBase.h create mode 100644 L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h delete mode 100644 L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/TETableBase.cc create mode 100644 L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/VMRouterPhiCorrTable.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc diff --git a/L1Trigger/TrackFindingTracklet/interface/Globals.h b/L1Trigger/TrackFindingTracklet/interface/Globals.h index cbe4eb2b4c4c9..e33b6600e9ac7 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Globals.h +++ b/L1Trigger/TrackFindingTracklet/interface/Globals.h @@ -17,13 +17,11 @@ namespace trklet { - class TETableBase; class TrackDerTable; - class ProjectionRouterBendTable; class SLHCEvent; class HistBase; class Settings; - class VMRouterPhiCorrTable; + class TrackletLUT; struct imathGlobals; class IMATH_TrackletCalculator; class IMATH_TrackletCalculatorDisk; @@ -41,9 +39,7 @@ namespace trklet { TrackDerTable*& trackDerTable() { return trackDerTable_; } - VMRouterPhiCorrTable*& phiCorr(unsigned int layer) { return thePhiCorr_[layer]; } - - ProjectionRouterBendTable*& projectionRouterBendTable() { return projectionRouterBendTable_; } + TrackletLUT*& phiCorr(unsigned int layer) { return thePhiCorr_[layer]; } std::map >& ILindex() { return ILindex_; } @@ -98,14 +94,12 @@ namespace trklet { TrackDerTable* trackDerTable_{nullptr}; - ProjectionRouterBendTable* projectionRouterBendTable_{nullptr}; - #ifdef USEHYBRID std::unique_ptr tmttSettings_; std::unique_ptr tmttKFParamsComb_; #endif - std::array thePhiCorr_{{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}}; + std::array thePhiCorr_{{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}}; std::map > ILindex_; diff --git a/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h b/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h index 90dae4b7ccf58..1972f58de1828 100644 --- a/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h @@ -12,8 +12,6 @@ namespace trklet { class Settings; class Globals; class Stub; - class L1TStub; - class VMRouterPhiCorrTable; class InputLinkMemory : public MemoryBase { public: diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h b/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h index 2a4051e98cb55..e2ce9a3a24f3b 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h @@ -3,6 +3,7 @@ #include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" #include #include @@ -41,13 +42,14 @@ namespace trklet { int icorzshift_; int phi0shift_; - unsigned int phimatchcut_[N_SEED]; - unsigned int zmatchcut_[N_SEED]; - unsigned int rphicutPS_[N_SEED]; - unsigned int rphicut2S_[N_SEED]; - unsigned int rcutPS_[N_SEED]; - unsigned int rcut2S_[N_SEED]; - + TrackletLUT phimatchcuttable_; + TrackletLUT zmatchcuttable_; + + TrackletLUT rphicutPStable_; + TrackletLUT rphicut2Stable_; + TrackletLUT rcutPStable_; + TrackletLUT rcut2Stable_; + int ialphafactinner_[N_DSS_MOD * 2]; int ialphafactouter_[N_DSS_MOD * 2]; diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h b/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h index db0ba984a85a5..6c6ccac14643b 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h @@ -2,6 +2,7 @@ #define L1Trigger_TrackFindingTracklet_interface_MatchEngine_h #include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" #include namespace trklet { @@ -33,18 +34,12 @@ namespace trklet { unsigned int layerdisk_; bool barrel_; - int nvm_; - int nvmbits_; - unsigned int nfinephibits_; //number of fine phi bits in phi VM bin unsigned int nrinv_; //number of bits for rinv in stub bend LUT - //used in the layers - std::vector table_; - - //used in the disks - std::vector tablePS_; - std::vector table2S_; + //LUT for bend consistency + TrackletLUT luttable_; + }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h index f61a4a659ee7c..7dfaa3503736e 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h @@ -14,10 +14,11 @@ namespace trklet { class Settings; class Stub; class L1TStub; - + class TrackletLUT; + class MatchEngineUnit { public: - MatchEngineUnit(bool barrel, unsigned int layerdisk, std::vector table); + MatchEngineUnit(bool barrel, unsigned int layerdisk, const TrackletLUT& luttable); ~MatchEngineUnit() = default; @@ -72,9 +73,10 @@ namespace trklet { bool idle_; unsigned int layerdisk_; + + //LUT for bend consistency with rinv + const TrackletLUT& luttable_; - //used for bend consistency with rinv - std::vector table_; //save the candidate matches CircularBuffer> candmatches_; diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h b/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h index cbda531d96186..1a2c1a26cd834 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h @@ -9,6 +9,7 @@ #include "L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" #include @@ -50,14 +51,14 @@ namespace trklet { int icorzshift_; int phishift_; - unsigned int phimatchcut_[N_SEED]; - unsigned int zmatchcut_[N_SEED]; - - unsigned int rphicutPS_[N_SEED]; - unsigned int rphicut2S_[N_SEED]; - unsigned int rcutPS_[N_SEED]; - unsigned int rcut2S_[N_SEED]; + TrackletLUT phimatchcuttable_; + TrackletLUT zmatchcuttable_; + TrackletLUT rphicutPStable_; + TrackletLUT rphicut2Stable_; + TrackletLUT rcutPStable_; + TrackletLUT rcut2Stable_; + int nrbits_; int nphiderbits_; @@ -71,9 +72,12 @@ namespace trklet { //Memory for the full matches std::vector fullmatches_; - //used for bend consistency with rinv - std::vector table_; + //disk projectionrinv table + TrackletLUT rinvbendlut_; + //LUT for bend consistency + TrackletLUT luttable_; + double phimin_; unsigned int nMatchEngines_; diff --git a/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h b/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h index 7b898f1b2e7a4..4f59d4fb1a342 100644 --- a/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h +++ b/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h @@ -2,7 +2,7 @@ #define L1Trigger_TrackFindingTracklet_interface_ProjectionRouter_h #include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/ProjectionRouterBendTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h" @@ -29,6 +29,9 @@ namespace trklet { int nrbits_; int nphiderbits_; + + //disk projectionrinv table + TrackletLUT rinvbendlut_; std::vector inputproj_; diff --git a/L1Trigger/TrackFindingTracklet/interface/ProjectionRouterBendTable.h b/L1Trigger/TrackFindingTracklet/interface/ProjectionRouterBendTable.h deleted file mode 100644 index 0cd798d758d08..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/ProjectionRouterBendTable.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_ProjectionRouterBendTable_h -#define L1Trigger_TrackFindingTracklet_interface_ProjectionRouterBendTable_h - -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" - -#include -#include -#include -#include -#include - -namespace trklet { - - class Globals; - - class ProjectionRouterBendTable { - public: - ProjectionRouterBendTable() {} - - ~ProjectionRouterBendTable() = default; - - void init(Settings const& settings, Globals* globals, unsigned int nrbits, unsigned int nphiderbits); - - int bendLoookup(int diskindex, int bendindex); - - private: - std::vector bendtable_[N_DISK]; - }; - -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/Settings.h b/L1Trigger/TrackFindingTracklet/interface/Settings.h index 0759b7ebcf279..f241b00744481 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Settings.h +++ b/L1Trigger/TrackFindingTracklet/interface/Settings.h @@ -33,6 +33,7 @@ namespace trklet { constexpr unsigned int NFINERZBITS = 3; //number of bit for r or z within a r/z bin constexpr unsigned int NFINEPHIBITS = 3; //number of bits for phi within a vm bin constexpr unsigned int N_RZBITS = 3; //number of bit for the r/z bins + constexpr unsigned int N_PHIBITS = 3; //number of bit for the phi bins constexpr unsigned int N_VMSTUBSMAX = 15; // maximum number of stubs in VM bin constexpr unsigned int N_BITSMEMADDRESS = 7; // Number of bits for address in memories @@ -44,7 +45,10 @@ namespace trklet { constexpr double VMROUTERCUTZL1L3L5 = 95.0; //Max z for inner barrel layers constexpr double VMROUTERCUTZL1 = 70.0; //Max z for L1 barrel seeding constexpr double VMROUTERCUTRD1D3 = 55.0; //Max r for disk seeds - + + enum Seed { L1L2 = 0, L2L3, L3L4, L5L6, D1D2, D3D4, L1D1, L2D1, L2L3L4, L4L5L6, L2L3D1, D1D2L2 }; + enum LayerDisk { L1 = 0, L2, L3, L4, L5, L6, D1, D2, D3, D4, D5 }; + class Settings { public: Settings() { diff --git a/L1Trigger/TrackFindingTracklet/interface/TETableBase.h b/L1Trigger/TrackFindingTracklet/interface/TETableBase.h deleted file mode 100644 index c12a818eb35f7..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/TETableBase.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_TETableBase_h -#define L1Trigger_TrackFindingTracklet_interface_TETableBase_h - -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" -#include "L1Trigger/TrackFindingTracklet/interface/Util.h" - -#include -#include -#include -#include -#include - -namespace trklet { - - class Settings; - - class TETableBase { - public: - TETableBase(Settings const& settings); - - virtual ~TETableBase() = default; - - virtual void lookup(int, int) {} - - void writeVMTable(const std::string& dir, const std::string& name, bool positive = true); - - protected: - Settings const& settings_; - std::vector table_; - int nbits_; - }; - -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h b/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h index f1734c35f2cd3..24894a51a11a4 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h @@ -25,6 +25,36 @@ namespace trklet { //This method writes out the configuration as files void writeAll(std::ostream& wires, std::ostream& memories, std::ostream& modules); + // + // The next group of fcn formats a string to write out names of different + // memories and processing modules + // + + //Seed string, eg. L1L2 + std::string iSeedStr(unsigned int iSeed); + + //Return unsigned as string + static std::string numStr(unsigned int i); + + //Retunr iTC as string - ie A, B, C, etc + std::string iTCStr(unsigned int iTC); + + //The region string A, B, C etc for layers and disks; X, Y, Z etc for overlap + std::string iRegStr(unsigned int iReg, unsigned int iSeed); + + //TC Name + std::string TCName(unsigned int iSeed, unsigned int iTC); + + //Name of layer or disk, e.g. L1 or D1 + static std::string LayerName(unsigned int ilayer); + + //Tracklet projection name + std::string TPROJName(unsigned int iSeed, unsigned int iTC, unsigned int ilayer, unsigned int ireg); + + //Projection router name + std::string PRName(unsigned int ilayer, unsigned int ireg); + + private: // // Method to initialize the regions and VM in each layer @@ -77,34 +107,6 @@ namespace trklet { // double rinv(double r1, double phi1, double r2, double phi2); - // - // The next group of fcn formats a string to write out names of different - // memories and processing modules - // - - //Seed string, eg. L1L2 - std::string iSeedStr(unsigned int iSeed); - - //Return unsigned as string - std::string numStr(unsigned int i); - - //Retunr iTC as string - ie A, B, C, etc - std::string iTCStr(unsigned int iTC); - - //The region string A, B, C etc for layers and disks; X, Y, Z etc for overlap - std::string iRegStr(unsigned int iReg, unsigned int iSeed); - - //TC Name - std::string TCName(unsigned int iSeed, unsigned int iTC); - - //Name of layer or disk, e.g. L1 or D1 - std::string LayerName(unsigned int ilayer); - - //Tracklet projection name - std::string TPROJName(unsigned int iSeed, unsigned int iTC, unsigned int ilayer, unsigned int ireg); - - //Projection router name - std::string PRName(unsigned int ilayer, unsigned int ireg); //StubPair Name std::string SPName(unsigned int l1, diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h index e827185374716..054f66bca1b47 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h @@ -2,6 +2,7 @@ #define L1Trigger_TrackFindingTracklet_interface_TrackletEngine_h #include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" #include #include @@ -27,8 +28,6 @@ namespace trklet { void setVMPhiBin(); - void writeTETable(); - private: //Which seed type and which layer/disk is used unsigned int iSeed_; @@ -43,8 +42,8 @@ namespace trklet { StubPairsMemory* stubpairs_; //The stub pt (bend) lookup table for the inner and outer stub - std::vector pttableinner_; - std::vector pttableouter_; + TrackletLUT innerptlut_; + TrackletLUT outerptlut_; //Number of phi bits used in the lookup table unsigned int innerphibits_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h index dd12be6851287..b8a77cf6734fb 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h @@ -3,6 +3,7 @@ #include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" #include #include @@ -33,8 +34,8 @@ namespace trklet { unsigned int iSeed, unsigned int nbitsfinephiediff, unsigned int iAllStub, - std::vector const& pttableinner, - std::vector const& pttableouter, + const TrackletLUT& pttableinnernew, + const TrackletLUT& pttableouternew, VMStubsTEMemory* outervmstubs); ~TrackletEngineUnit() = default; @@ -82,8 +83,8 @@ namespace trklet { bool idle_; - std::vector pttableinner_; - std::vector pttableouter_; + const TrackletLUT& pttableinnernew_; + const TrackletLUT& pttableouternew_; std::pair candpair_, candpair__; bool goodpair_, goodpair__; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h b/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h new file mode 100644 index 0000000000000..7e7392d372e3a --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h @@ -0,0 +1,81 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletLUT_h +#define L1Trigger_TrackFindingTracklet_interface_TrackletLUT_h + +#include +#include +#include + +namespace trklet { + + class Settings; + + class TrackletLUT { + public: + + TrackletLUT(const Settings& settings); + + TrackletLUT& operator=(const TrackletLUT& other) { + + name_ = other.name_; + table_ = other.table_; + nbits_ = other.nbits_; + positive_ = other.positive_; + + return *this; + } + + ~TrackletLUT() = default; + + enum MatchType { barrelphi, barrelz, disk2Sphi, disk2Sr, diskPSphi, diskPSr }; + + //region only used for name - should be removed + void initmatchcut(unsigned int layerdisk, MatchType type, unsigned int region); + + void initTPlut(bool fillInner, unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, + unsigned int nbitsfinephidiff, unsigned int iTP); + + void initTPregionlut(unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, + unsigned int iAllStub, unsigned int nbitsfinephidiff, unsigned int nbitsfinephi, + const TrackletLUT& tplutinner, unsigned int iTP); + + void initteptlut(bool fillInner, bool fillTEMem, unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, + unsigned int innerphibits, unsigned int outerphibits, + double innerphimin, double innerphimax, double outerphimin, double outerphimax, + const std::string& innermem, const std::string& outermem); + + + void initProjectionBend(double k_phider, unsigned int idisk, unsigned int nrbits, unsigned int nphiderbits); + + void initBendMatch(unsigned int layerdisk); + + enum VMRTableType { me, disk, inner, inneroverlap, innerthird }; + + //region only used for name - should be removed + void initVMRTable(unsigned int layerdisk, VMRTableType type, int region=-1); + + void initPhiCorrTable(unsigned int layerdisk, unsigned int rbits); + + void writeTable() const; + + int lookup(unsigned int index) const; + + private: + + int getphiCorrValue(unsigned int layerdisk, unsigned int ibend, unsigned int irbin, + double rmean, double dr, double drmax) const; + + int getVMRLookup(unsigned int layerdisk, double z, double r, double dz, double dr, int iseed = -1) const; + + const Settings& settings_; + + std::string name_; + + std::vector table_; + + unsigned int nbits_; + + bool positive_; + + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h b/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h index c32a718681fc1..fd9fd6da8f03a 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h @@ -4,7 +4,7 @@ #define L1Trigger_TrackFindingTracklet_interface_TrackletProcessor_h #include "L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" #include "L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h" @@ -35,10 +35,6 @@ namespace trklet { void execute(unsigned int iSector, double phimin, double phimax); - void writeTETable(); - - void buildLUT(); - private: int iTC_; int iAllStub_; @@ -55,13 +51,9 @@ namespace trklet { std::vector innerallstubs_; std::vector outerallstubs_; - std::map > pttableinner_; - std::map > pttableouter_; - - std::vector pttableinnernew_; - std::vector pttableouternew_; - - std::vector useregion_; + TrackletLUT pttableinner_; + TrackletLUT pttableouter_; + TrackletLUT useregiontable_; int nbitsfinephi_; int nbitsfinephidiff_; @@ -74,7 +66,9 @@ namespace trklet { unsigned int nbitsrzbin_; - VMRouterTable vmrtable_; + TrackletLUT innerTable_; //projection to next layer/disk + TrackletLUT innerOverlapTable_; //projection to disk from layer + }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouter.h b/L1Trigger/TrackFindingTracklet/interface/VMRouter.h index 52811501ac88e..ab1390490286f 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouter.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouter.h @@ -4,7 +4,7 @@ #include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" #include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" #include #include @@ -55,7 +55,11 @@ namespace trklet { int nbitszfinebintable_; int nbitsrfinebintable_; - VMRouterTable vmrtable_; + TrackletLUT meTable_; //used for ME and outer TE barrel + TrackletLUT diskTable_; //outer disk used by D1, D2, and D4 + TrackletLUT innerTable_; //projection to next layer/disk + TrackletLUT innerOverlapTable_; //projection to disk from layer + TrackletLUT innerThirdTable_; //projection to disk1 for extended - iseed=10 //The input stub memories the two tmp inputs are used to build the order needed in HLS std::vector stubinputs_, stubinputtmp_, stubinputdisk2stmp_; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h b/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h index 3322ea12019aa..6d31e5f1d5d9c 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h @@ -4,7 +4,7 @@ #include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" #include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" #include #include @@ -54,7 +54,8 @@ namespace trklet { unsigned int nvmmebins_; //number of long z/r bins in VM - VMRouterTable vmrtable_; + TrackletLUT meTable_; //used for ME and outer TE barrel + TrackletLUT diskTable_; //outer disk used by D1, D2, and D4 //The input stub memories std::vector stubinputs_; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h b/L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h deleted file mode 100644 index ec1907230e6b0..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_VMRouterPhiCorrTable_h -#define L1Trigger_TrackFindingTracklet_interface_VMRouterPhiCorrTable_h - -#include "L1Trigger/TrackFindingTracklet/interface/TETableBase.h" - -#include -#include -#include -#include -#include - -namespace trklet { - - class Settings; - - class VMRouterPhiCorrTable : public TETableBase { - public: - VMRouterPhiCorrTable(Settings const& settings); - - ~VMRouterPhiCorrTable() override = default; - - void init(int layer, int bendbits, int rbits); - - int getphiCorrValue(int ibend, int irbin) const; - - int lookupPhiCorr(int ibend, int rbin); - - private: - double rmean_; - double rmin_; - double rmax_; - - double dr_; - - int bendbits_; - int rbits_; - - int bendbins_; - int rbins_; - - int layer_; - }; -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h b/L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h deleted file mode 100644 index b376c5d712c79..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_VMRouterTable_h -#define L1Trigger_TrackFindingTracklet_interface_VMRouterTable_h - -#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" - -#include -#include -#include -#include -#include - -namespace trklet { - - class Settings; - - class VMRouterTable { - public: - VMRouterTable(Settings const& settings); - VMRouterTable(Settings const& settings, unsigned int layerdisk, std::string const& name); - - ~VMRouterTable() = default; - - void init(unsigned int layerdisk, std::string const& name = ""); - - // negative return means that seed can not be formed - int getLookup(unsigned int layerdisk, double z, double r, int iseed = -1); - - int lookup(int zbin, int rbin); - int lookupdisk(int zbin, int rbin); - int lookupinner(int zbin, int rbin); - int lookupinneroverlap(int zbin, int rbin); - int lookupinnerThird(int zbin, int rbin); - - void writeVMTable(std::string const& dir, std::string const& name, std::vector const& table); - - private: - Settings const& settings_; - - double rmin_; - double rmax_; - - double zmin_; - double zmax_; - - double dr_; - double dz_; - - int zbits_; - int rbits_; - - int zbins_; - int rbins_; - - //int layer_; - std::vector vmrtable_; //used for ME and outer TE - std::vector vmrtabletedisk_; //outer disk used by D1, D2, and D4 - std::vector vmrtableteinner_; //projection to next layer/disk - std::vector vmrtableteinneroverlap_; //projection to disk - std::vector vmrtableteinnerThird_; //projection to disk1 for extended - iseed=10 - }; -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h b/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h index e77d22ba3cb02..e487b37458d25 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h @@ -2,6 +2,7 @@ #define L1Trigger_TrackFindingTracklet_interface_VMStubsTEMemory_h #include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" #include "L1Trigger/TrackFindingTracklet/interface/VMStubTE.h" #include @@ -12,6 +13,7 @@ namespace trklet { class Settings; class Stub; class L1TStub; + class TrackletLUT; class VMStubsTEMemory : public MemoryBase { public: @@ -47,14 +49,7 @@ namespace trklet { VMStubsTEMemory* other() { return other_; } - void setbendtable(std::vector vmbendtable); - - bool passbend(unsigned int ibend) const { - assert(ibend < vmbendtable_.size()); - return vmbendtable_[ibend]; - } - - void writeVMBendTable(); + void setbendtable(const TrackletLUT& bendtable); private: int layer_; @@ -67,8 +62,8 @@ namespace trklet { bool extended_; // for the L2L3->D1 and D1D2->L2 bool isinner_; // is inner layer/disk for TE purpose - std::vector vmbendtable_; - + TrackletLUT bendtable_; + std::vector stubsvm_; std::vector > stubsbinnedvm_; }; diff --git a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc index 20bf5e741e2b6..82b877da25947 100644 --- a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc +++ b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc @@ -989,7 +989,7 @@ void FitTrack::execute(unsigned int iSector) { std::vector trackstublist; std::vector> stubidslist; - if ((bestTracklet->getISeed() >= 8 && nMatchesUniq >= 1) || + if ((bestTracklet->getISeed() >= (int)N_SEED_PROMPT && nMatchesUniq >= 1) || nMatchesUniq >= 2) { //For seeds index >=8 (triplet seeds), there are three stubs associated from start. countFit++; diff --git a/L1Trigger/TrackFindingTracklet/src/Globals.cc b/L1Trigger/TrackFindingTracklet/src/Globals.cc index da35939f46014..0581f6f8f8bc1 100644 --- a/L1Trigger/TrackFindingTracklet/src/Globals.cc +++ b/L1Trigger/TrackFindingTracklet/src/Globals.cc @@ -5,7 +5,7 @@ #include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" #include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorDisk.h" #include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorOverlap.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" #include "L1Trigger/TrackFindingTracklet/interface/HistBase.h" using namespace std; diff --git a/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc b/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc index 92affaed962c9..d9bcb6589d513 100644 --- a/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc @@ -1,7 +1,5 @@ #include "L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" #include "L1Trigger/TrackFindingTracklet/interface/Stub.h" - #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" #include diff --git a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc index f9b363ced8a2a..b9891452f3283 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc @@ -19,7 +19,10 @@ using namespace std; using namespace trklet; MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global) { + : ProcessBase(name, settings, global), phimatchcuttable_(settings), zmatchcuttable_(settings), + rphicutPStable_(settings), rphicut2Stable_(settings), + rcutPStable_(settings), rcut2Stable_(settings) { + phiregion_ = name[8] - 'A'; layerdisk_ = initLayerDisk(3); @@ -43,96 +46,19 @@ MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* phi0shift_ = 0; } - for (unsigned int iSeed = 0; iSeed < N_SEED; iSeed++) { - if (layerdisk_ < N_LAYER) { - phimatchcut_[iSeed] = - settings_.rphimatchcut(iSeed, layerdisk_) / (settings_.kphi1() * settings_.rmean(layerdisk_)); - zmatchcut_[iSeed] = settings_.zmatchcut(iSeed, layerdisk_) / settings_.kz(); - } else { - rphicutPS_[iSeed] = settings_.rphicutPS(iSeed, layerdisk_ - N_LAYER) / (settings_.kphi() * settings_.kr()); - rphicut2S_[iSeed] = settings_.rphicut2S(iSeed, layerdisk_ - N_LAYER) / (settings_.kphi() * settings_.kr()); - rcut2S_[iSeed] = settings_.rcut2S(iSeed, layerdisk_ - N_LAYER) / settings_.krprojshiftdisk(); - rcutPS_[iSeed] = settings_.rcutPS(iSeed, layerdisk_ - N_LAYER) / settings_.krprojshiftdisk(); - } - } - - if (layerdisk_ < N_LAYER && settings_.writeTable()) { - ofstream outphicut = openfile(settings_.tablePath(), getName() + "_phicut.tab", __FILE__, __LINE__); - - outphicut << "{" << endl; - for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { - if (seedindex != 0) - outphicut << "," << endl; - outphicut << phimatchcut_[seedindex]; - } - outphicut << endl << "};" << endl; - outphicut.close(); - - const string filezcut = settings_.tablePath() + getName() + "_zcut.tab"; - ofstream outzcut(filezcut); - if (outzcut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << filezcut; - - outzcut << "{" << endl; - for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { - if (seedindex != 0) - outzcut << "," << endl; - outzcut << zmatchcut_[seedindex]; - } - outzcut << endl << "};" << endl; - outzcut.close(); - } - - if (layerdisk_ >= N_LAYER && settings_.writeTable()) { - ofstream outPSphicut = openfile(settings_.tablePath(), getName() + "_PSphicut.tab", __FILE__, __LINE__); - - outPSphicut << "{" << endl; - for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { - if (seedindex != 0) - outPSphicut << "," << endl; - outPSphicut << rphicutPS_[seedindex]; - } - outPSphicut << endl << "};" << endl; - outPSphicut.close(); - - ofstream out2Sphicut = openfile(settings_.tablePath(), getName() + "_2Sphicut.tab", __FILE__, __LINE__); - - out2Sphicut << "{" << endl; - for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { - if (seedindex != 0) - out2Sphicut << "," << endl; - out2Sphicut << rphicut2S_[seedindex]; - } - out2Sphicut << endl << "};" << endl; - out2Sphicut.close(); - - const string filePSrcut = settings_.tablePath() + getName() + "_PSrcut.tab"; - ofstream outPSrcut(filePSrcut); - if (outPSrcut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << filePSrcut; - outPSrcut << "{" << endl; - for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { - if (seedindex != 0) - outPSrcut << "," << endl; - outPSrcut << rcutPS_[seedindex]; - } - outPSrcut << endl << "};" << endl; - outPSrcut.close(); - - const string file2Srcut = settings_.tablePath() + getName() + "_2Srcut.tab"; - ofstream out2Srcut(file2Srcut); - if (out2Srcut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << file2Srcut; - out2Srcut << "{" << endl; - for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { - if (seedindex != 0) - out2Srcut << "," << endl; - out2Srcut << rcut2S_[seedindex]; - } - out2Srcut << endl << "};" << endl; - out2Srcut.close(); + unsigned int region = getName()[8]-'A'; + assert(region < settings_.nallstubs(layerdisk_)); + + if (layerdisk_ < N_LAYER) { + phimatchcuttable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::barrelphi, region); + zmatchcuttable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::barrelz, region); + } else { + rphicutPStable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::diskPSphi, region); + rphicut2Stable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::disk2Sphi, region); + rcutPStable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::diskPSr, region); + rcut2Stable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::disk2Sr, region); } - + for (unsigned int i = 0; i < N_DSS_MOD * 2; i++) { ialphafactinner_[i] = (1 << settings_.alphashift()) * settings_.krprojshiftdisk() * settings_.half2SmoduleWidth() / (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSinner(i) * settings_.rDSSinner(i)) / @@ -257,8 +183,8 @@ void MatchCalculator::execute(double phioffset) { int seedindex = tracklet->getISeed(); - assert(phimatchcut_[seedindex] > 0); - assert(zmatchcut_[seedindex] > 0); + assert(phimatchcuttable_.lookup(seedindex) > 0); + assert(zmatchcuttable_.lookup(seedindex) > 0); if (settings_.bookHistos()) { bool truthmatch = tracklet->stubtruthmatch(stub); @@ -286,17 +212,17 @@ void MatchCalculator::execute(double phioffset) { << layerdisk_ + 1 << " " << seedindex << " " << pt << " " << ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_) << " " << dphiapprox * settings_.rmean(layerdisk_) << " " - << phimatchcut_[seedindex] * settings_.kphi1() * settings_.rmean(layerdisk_) << " " - << ideltaz * fact_ * settings_.kz() << " " << dz << " " << zmatchcut_[seedindex] * settings_.kz() << endl; + << phimatchcuttable_.lookup(seedindex) * settings_.kphi1() * settings_.rmean(layerdisk_) << " " + << ideltaz * fact_ * settings_.kz() << " " << dz << " " << zmatchcuttable_.lookup(seedindex) * settings_.kz() << endl; } - bool imatch = (std::abs(ideltaphi) <= (int)phimatchcut_[seedindex]) && - (std::abs(ideltaz * fact_) <= (int)zmatchcut_[seedindex]); + bool imatch = (std::abs(ideltaphi) <= (int)phimatchcuttable_.lookup(seedindex)) && + (std::abs(ideltaz * fact_) <= (int)zmatchcuttable_.lookup(seedindex)); if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " ideltaphi cut " << ideltaphi << " " - << phimatchcut_[seedindex] << " ideltaz*fact cut " << ideltaz * fact_ << " " - << zmatchcut_[seedindex]; + << phimatchcuttable_.lookup(seedindex) << " ideltaz*fact cut " << ideltaz * fact_ << " " + << zmatchcuttable_.lookup(seedindex); } if (imatch) { @@ -424,11 +350,11 @@ void MatchCalculator::execute(double phioffset) { int seedindex = tracklet->getISeed(); - int idrphicut = rphicutPS_[seedindex]; - int idrcut = rcutPS_[seedindex]; + int idrphicut = rphicutPStable_.lookup(seedindex); + int idrcut = rcutPStable_.lookup(seedindex); if (!stub->isPSmodule()) { - idrphicut = rphicut2S_[seedindex]; - idrcut = rcut2S_[seedindex]; + idrphicut = rphicut2Stable_.lookup(seedindex); + idrcut = rcut2Stable_.lookup(seedindex); } double drphicut = idrphicut * settings_.kphi() * settings_.kr(); diff --git a/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc b/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc index 2668c2e646761..de08e2cb88a91 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc @@ -15,72 +15,16 @@ using namespace std; using namespace trklet; -MatchEngine::MatchEngine(string name, Settings const& settings, Globals* global) : ProcessBase(name, settings, global) { +MatchEngine::MatchEngine(string name, Settings const& settings, Globals* global) : ProcessBase(name, settings, global), + luttable_(settings) { layerdisk_ = initLayerDisk(3); barrel_ = layerdisk_ < N_LAYER; - nvm_ = settings_.nvmme(layerdisk_) * settings_.nallstubs(layerdisk_); - - nvmbits_ = settings_.nbitsvmme(layerdisk_) + settings_.nbitsallstubs(layerdisk_); + luttable_.initBendMatch(layerdisk_); nrinv_ = NRINVBITS; - double rinvhalf = 0.5 * ((1 << nrinv_) - 1); - - nfinephibits_ = 3; - - if (barrel_) { - bool isPSmodule = layerdisk_ < N_PSLAYER; - - unsigned int nbits = isPSmodule ? N_BENDBITS_PS : N_BENDBITS_2S; - - for (unsigned int irinv = 0; irinv < (1u << nrinv_); irinv++) { - double rinv = (irinv - rinvhalf) * (1 << (settings_.nbitsrinv() - nrinv_)) * settings_.krinvpars(); - - double stripPitch = settings_.stripPitch(isPSmodule); - double projbend = bendstrip(settings_.rmean(layerdisk_), rinv, stripPitch); - for (unsigned int ibend = 0; ibend < (1u << nbits); ibend++) { - double stubbend = settings_.benddecode(ibend, layerdisk_, isPSmodule); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, isPSmodule); - table_.push_back(pass); - } - } - - if (settings_.writeTable()) { - char layer = '1' + layerdisk_; - string fname = "METable_L"; - fname += layer; - fname += ".tab"; - - ofstream out = openfile(settings_.tablePath(), fname, __FILE__, __LINE__); - out << "{" << endl; - for (unsigned int i = 0; i < table_.size(); i++) { - if (i != 0) { - out << "," << endl; - } - out << table_[i]; - } - out << "};" << endl; - out.close(); - } - } - - if (layerdisk_ >= N_LAYER) { - for (unsigned int iprojbend = 0; iprojbend < (1u << nrinv_); iprojbend++) { - double projbend = 0.5 * (iprojbend - rinvhalf); - for (unsigned int ibend = 0; ibend < (1 << N_BENDBITS_PS); ibend++) { - double stubbend = settings_.benddecode(ibend, layerdisk_, true); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, true); - tablePS_.push_back(pass); - } - for (unsigned int ibend = 0; ibend < (1 << N_BENDBITS_2S); ibend++) { - double stubbend = settings_.benddecode(ibend, layerdisk_, false); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, false); - table2S_.push_back(pass); - } - } - } } void MatchEngine::addOutput(MemoryBase* memory, string output) { @@ -292,6 +236,9 @@ void MatchEngine::execute() { bool passphi = (std::abs(deltaphi) < mindeltaphicut) || (std::abs(deltaphi) > maxdeltaphicut); unsigned int index = (projrinv << nbits) + vmstub.bend().value(); + if (!barrel_&&isPSmodule) { + index += (1 << (nrinv_ + N_BENDBITS_2S)); + } //Check if stub z position consistent int idrz = stubfinerz - projfinerzadj; @@ -323,7 +270,7 @@ void MatchEngine::execute() { //Check if stub bend and proj rinv consistent if (passz && passphi) { - if (barrel_ ? table_[index] : (isPSmodule ? tablePS_[index] : table2S_[index])) { + if (luttable_.lookup(index)) { Tracklet* proj = vmprojs_->getTracklet(projindex); std::pair tmp(proj, vmprojs_->getAllProjIndex(projindex)); if (settings_.writeMonitorData("Seeds")) { diff --git a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc index 6bea2f165c795..2b89f436be2fc 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc @@ -1,12 +1,12 @@ #include "L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" using namespace std; using namespace trklet; -MatchEngineUnit::MatchEngineUnit(bool barrel, unsigned int layerdisk, vector table) : candmatches_(5) { +MatchEngineUnit::MatchEngineUnit(bool barrel, unsigned int layerdisk, const TrackletLUT& luttable) : luttable_(luttable), candmatches_(5) { idle_ = true; barrel_ = barrel; - table_ = table; layerdisk_ = layerdisk; } @@ -108,12 +108,12 @@ void MatchEngineUnit::step(bool print) { if (print) cout << "MEU TrkId stubindex : " << 128 * proj_->TCIndex() + proj_->trackletIndex() << " " - << vmstub.stubindex().value() << " " << ((pass && dphicut) && table_[index]) << " index=" << index + << vmstub.stubindex().value() << " " << ((pass && dphicut) && luttable_.lookup(index)) << " index=" << index << " projrinv bend : " << projrinv_ << " " << vmstub.bend().value() << " shift_ isPSseed_ :" << shift_ << " " << isPSseed_ << " slot=" << slot << endl; //Check if stub bend and proj rinv consistent - if ((pass && dphicut) && table_[index]) { + if ((pass && dphicut) && luttable_.lookup(index)) { std::pair tmp(proj_, vmstub.stub()); candmatches_.store(tmp); } diff --git a/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc b/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc index b2f7722a5b1d5..4eca2ff1c4569 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc @@ -1,12 +1,12 @@ #include "L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h" #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" #include "L1Trigger/TrackFindingTracklet/interface/Util.h" -#include "L1Trigger/TrackFindingTracklet/interface/ProjectionRouterBendTable.h" #include "L1Trigger/TrackFindingTracklet/interface/HistBase.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" #include "DataFormats/Math/interface/deltaPhi.h" +#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" #include @@ -14,7 +14,11 @@ using namespace std; using namespace trklet; MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global), fullmatches_(12), inputProjBuffer_(3) { + : ProcessBase(name, settings, global), + phimatchcuttable_(settings), zmatchcuttable_(settings), rphicutPStable_(settings), + rphicut2Stable_(settings), rcutPStable_(settings), rcut2Stable_(settings), + fullmatches_(12), rinvbendlut_(settings), luttable_(settings), inputProjBuffer_(3) { + phiregion_ = name[8] - 'A'; layerdisk_ = initLayerDisk(3); @@ -32,100 +36,30 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g icorzshift_ = ilog2(settings_.krprojshiftdisk() / (settings_.kz() * settings_.krder())); } + luttable_.initBendMatch(layerdisk_); + nrbits_ = 5; nphiderbits_ = 6; - nrinv_ = NRINVBITS; - double rinvhalf = 0.5 * ((1 << nrinv_) - 1); - - for (unsigned int iSeed = 0; iSeed < 12; iSeed++) { - if (layerdisk_ < N_LAYER) { - phimatchcut_[iSeed] = - settings_.rphimatchcut(iSeed, layerdisk_) / (settings_.kphi1() * settings_.rmean(layerdisk_)); - zmatchcut_[iSeed] = settings_.zmatchcut(iSeed, layerdisk_) / settings_.kz(); - } else { - rphicutPS_[iSeed] = settings_.rphicutPS(iSeed, layerdisk_ - N_LAYER) / (settings_.kphi() * settings_.kr()); - rphicut2S_[iSeed] = settings_.rphicut2S(iSeed, layerdisk_ - N_LAYER) / (settings_.kphi() * settings_.kr()); - rcut2S_[iSeed] = settings_.rcut2S(iSeed, layerdisk_ - N_LAYER) / settings_.krprojshiftdisk(); - rcutPS_[iSeed] = settings_.rcutPS(iSeed, layerdisk_ - N_LAYER) / settings_.krprojshiftdisk(); - } + if (!barrel_) { + rinvbendlut_.initProjectionBend(global->ITC_L1L2()->der_phiD_final.K(), layerdisk_-N_LAYER, nrbits_, nphiderbits_); } - if (barrel_ && settings_.writeTable()) { - ofstream outphicut = openfile(settings_.tablePath(), getName() + "_phicut.tab", __FILE__, __LINE__); - - outphicut << "{" << endl; - for (unsigned int seedindex = 0; seedindex < 12; seedindex++) { - if (seedindex != 0) - outphicut << "," << endl; - outphicut << phimatchcut_[seedindex]; - } - outphicut << endl << "};" << endl; - outphicut.close(); - - ofstream outzcut = openfile(settings_.tablePath(), getName() + "_zcut.tab", __FILE__, __LINE__); + nrinv_ = NRINVBITS; - outzcut << "{" << endl; - for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { - if (seedindex != 0) - outzcut << "," << endl; - outzcut << zmatchcut_[seedindex]; - } - outzcut << endl << "};" << endl; - outzcut.close(); - } + unsigned int region = getName()[8]-'A'; + assert(region < settings_.nallstubs(layerdisk_)); if (barrel_) { - unsigned int nbits = (layerdisk_ < N_PSLAYER) ? N_BENDBITS_PS : N_BENDBITS_2S; - - for (unsigned int irinv = 0; irinv < (1u << nrinv_); irinv++) { - double rinv = (irinv - rinvhalf) * (1 << (settings_.nbitsrinv() - nrinv_)) * settings_.krinvpars(); - double stripPitch = settings_.stripPitch(layerdisk_ < N_PSLAYER); - double projbend = bendstrip(settings_.rmean(layerdisk_), rinv, stripPitch); - for (unsigned int ibend = 0; ibend < (unsigned int)(1 << nbits); ibend++) { - double stubbend = settings_.benddecode(ibend, layerdisk_, layerdisk_ < (int)N_PSLAYER); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, layerdisk_ < (int)N_PSLAYER); - table_.push_back(pass); - } - } + phimatchcuttable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::barrelphi, region); + zmatchcuttable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::barrelz, region); } else { - constexpr int nprojbends = 1 << NRINVBITS; - constexpr int npsbends = 1 << N_BENDBITS_PS; - constexpr int n2sbends = 1 << N_BENDBITS_2S; - table_.resize(nprojbends * n2sbends * 2, false); //Factor of 2 is to have both 2s and ps bends in same table - for (unsigned int iprojbend = 0; iprojbend < nprojbends; iprojbend++) { - double projbend = 0.5 * (iprojbend - rinvhalf); - for (unsigned int ibend = 0; ibend < npsbends; ibend++) { - double stubbend = settings_.benddecode(ibend, layerdisk_, true); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, true); - table_[nprojbends*n2sbends + npsbends * iprojbend + ibend] = pass; - } - for (unsigned int ibend = 0; ibend < n2sbends; ibend++) { - double stubbend = settings_.benddecode(ibend, layerdisk_, false); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, false); - table_[n2sbends * iprojbend + ibend] = pass; - } - } + rphicutPStable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::diskPSphi, region); + rphicut2Stable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::disk2Sphi, region); + rcutPStable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::diskPSr, region); + rcut2Stable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::disk2Sr, region); } - - if (settings_.writeTable()) { - char layerdisk = barrel_ ? '0' + layerdisk_ + 1 : '0' + layerdisk_ - N_LAYER + 1; - string fname = barrel_ ? "METable_L" : "METable_D"; - fname += layerdisk; - fname += ".tab"; - - ofstream out = openfile(settings_.tablePath(), fname, __FILE__, __LINE__); - out << "{" << endl; - for (unsigned int i = 0; i < table_.size(); i++) { - if (i != 0) { - out << "," << endl; - } - out << table_[i]; - } - out << "};" << endl; - out.close(); - } - + for (unsigned int i = 0; i < N_DSS_MOD * 2; i++) { ialphafactinner_[i] = (1 << settings_.alphashift()) * settings_.krprojshiftdisk() * settings_.half2SmoduleWidth() / (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSinner(i) * settings_.rDSSinner(i)) / @@ -141,15 +75,10 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g nMatchEngines_ = 4; for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { - MatchEngineUnit tmpME(barrel_, layerdisk_, table_); + MatchEngineUnit tmpME(barrel_, layerdisk_, luttable_); matchengines_.push_back(tmpME); } - if (globals_->projectionRouterBendTable() == nullptr) { - auto* bendTablePtr = new ProjectionRouterBendTable(); - bendTablePtr->init(settings_, globals_, nrbits_, nphiderbits_); - globals_->projectionRouterBendTable() = bendTablePtr; - } } void MatchProcessor::addOutput(MemoryBase* memory, string output) { @@ -302,8 +231,8 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; - projrinv = globals_->projectionRouterBendTable()->bendLoookup(layerdisk_ - N_LAYER, bendindex); - + projrinv = rinvbendlut_.lookup(bendindex); + proj->proj(layerdisk_).setBendIndex(projrinv); } assert(projrinv >= 0); @@ -502,8 +431,8 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b int seedindex = tracklet->getISeed(); - assert(phimatchcut_[seedindex] > 0); - assert(zmatchcut_[seedindex] > 0); + assert(phimatchcuttable_.lookup(seedindex) > 0); + assert(zmatchcuttable_.lookup(seedindex) > 0); if (settings_.bookHistos()) { bool truthmatch = tracklet->stubtruthmatch(stub); @@ -525,18 +454,18 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b << layerdisk_ + 1 << " " << seedindex << " " << pt << " " << ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_) << " " << dphiapprox * settings_.rmean(layerdisk_) << " " - << phimatchcut_[seedindex] * settings_.kphi1() * settings_.rmean(layerdisk_) << " " - << (ideltaz << dzshift_) * settings_.kz() << " " << dz << " " << zmatchcut_[seedindex] * settings_.kz() + << phimatchcuttable_.lookup(seedindex) * settings_.kphi1() * settings_.rmean(layerdisk_) << " " + << (ideltaz << dzshift_) * settings_.kz() << " " << dz << " " << zmatchcuttable_.lookup(seedindex) * settings_.kz() << endl; } - bool imatch = ((unsigned int)std::abs(ideltaphi) <= phimatchcut_[seedindex]) && - ((unsigned int)std::abs(ideltaz << dzshift_) <= zmatchcut_[seedindex]); + bool imatch = (std::abs(ideltaphi) <= phimatchcuttable_.lookup(seedindex)) && + (std::abs(ideltaz << dzshift_) <= zmatchcuttable_.lookup(seedindex)); if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " ideltaphi cut " << ideltaphi << " " - << phimatchcut_[seedindex] << " ideltaz<getISeed(); - int idrphicut = rphicutPS_[seedindex]; - int idrcut = rcutPS_[seedindex]; + int idrphicut = rphicutPStable_.lookup(seedindex); + int idrcut = rcutPStable_.lookup(seedindex); if (!stub->isPSmodule()) { - idrphicut = rphicut2S_[seedindex]; - idrcut = rcut2S_[seedindex]; + idrphicut = rphicut2Stable_.lookup(seedindex); + idrcut = rcut2Stable_.lookup(seedindex); } double drphicut = idrphicut * settings_.kphi() * settings_.kr(); diff --git a/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc b/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc index 20fb0b1082ce9..9194bffc91544 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc @@ -48,7 +48,7 @@ void ProcessBase::initLayerDisk(unsigned int pos, int& layer, int& disk, int& la layerdisk = layer - 1; if (disk > 0) - layerdisk = N_DISK + disk; + layerdisk = N_LAYER + disk - 1; } unsigned int ProcessBase::initLayerDisk(unsigned int pos) { @@ -56,7 +56,7 @@ unsigned int ProcessBase::initLayerDisk(unsigned int pos) { initLayerDisk(pos, layer, disk); if (disk > 0) - return N_DISK + disk; + return N_LAYER + disk - 1; return layer - 1; } @@ -68,16 +68,16 @@ void ProcessBase::initLayerDisksandISeed(unsigned int& layerdisk1, unsigned int& if (name_[3] == 'L') { layerdisk1 = name_[4] - '1'; } else if (name_[3] == 'D') { - layerdisk1 = 6 + name_[4] - '1'; + layerdisk1 = N_LAYER + name_[4] - '1'; } if (name_[11] == 'L') { layerdisk2 = name_[12] - '1'; } else if (name_[11] == 'D') { - layerdisk2 = 6 + name_[12] - '1'; + layerdisk2 = N_LAYER + name_[12] - '1'; } else if (name_[12] == 'L') { layerdisk2 = name_[13] - '1'; } else if (name_[12] == 'D') { - layerdisk2 = 6 + name_[13] - '1'; + layerdisk2 = N_LAYER + name_[13] - '1'; } } @@ -85,31 +85,31 @@ void ProcessBase::initLayerDisksandISeed(unsigned int& layerdisk1, unsigned int& if (name_[3] == 'L') { layerdisk1 = name_[4] - '1'; } else if (name_[3] == 'D') { - layerdisk1 = 6 + name_[4] - '1'; + layerdisk1 = N_LAYER + name_[4] - '1'; } if (name_[5] == 'L') { layerdisk2 = name_[6] - '1'; } else if (name_[5] == 'D') { - layerdisk2 = 6 + name_[6] - '1'; + layerdisk2 = N_LAYER + name_[6] - '1'; } } - if (layerdisk1 == 0 && layerdisk2 == 1) - iSeed = 0; - else if (layerdisk1 == 1 && layerdisk2 == 2) - iSeed = 1; - else if (layerdisk1 == 2 && layerdisk2 == 3) - iSeed = 2; - else if (layerdisk1 == 4 && layerdisk2 == 5) - iSeed = 3; - else if (layerdisk1 == 6 && layerdisk2 == 7) - iSeed = 4; - else if (layerdisk1 == 8 && layerdisk2 == 9) - iSeed = 5; - else if (layerdisk1 == 0 && layerdisk2 == 6) - iSeed = 6; - else if (layerdisk1 == 1 && layerdisk2 == 6) - iSeed = 7; + if (layerdisk1 == LayerDisk::L1 && layerdisk2 == LayerDisk::L2) + iSeed = Seed::L1L2; + else if (layerdisk1 == LayerDisk::L2 && layerdisk2 == LayerDisk::L3) + iSeed = Seed::L2L3; + else if (layerdisk1 == LayerDisk::L3 && layerdisk2 == LayerDisk::L4) + iSeed = Seed::L3L4; + else if (layerdisk1 == LayerDisk::L5 && layerdisk2 == LayerDisk::L6) + iSeed = Seed::L5L6; + else if (layerdisk1 == LayerDisk::D1 && layerdisk2 == LayerDisk::D2) + iSeed = Seed::D1D2; + else if (layerdisk1 == LayerDisk::D3 && layerdisk2 == LayerDisk::D4) + iSeed = Seed::D3D4; + else if (layerdisk1 == LayerDisk::L1 && layerdisk2 == LayerDisk::D1) + iSeed = Seed::L1D1; + else if (layerdisk1 == LayerDisk::L2 && layerdisk2 == LayerDisk::D1) + iSeed = Seed::L2D1; else { throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " layerdisk1 " << layerdisk1 << " layerdisk2 " << layerdisk2; diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc index 711b0972bf715..ca0aea33c6e5c 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc @@ -3,6 +3,8 @@ #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" #include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" #include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" +#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" + #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" @@ -11,13 +13,18 @@ using namespace std; using namespace trklet; ProjectionRouter::ProjectionRouter(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global) { + : ProcessBase(name, settings, global), rinvbendlut_(settings) { layerdisk_ = initLayerDisk(3); vmprojs_.resize(settings_.nvmme(layerdisk_), nullptr); nrbits_ = 5; nphiderbits_ = 6; + + if (layerdisk_ >= N_LAYER) { + rinvbendlut_.initProjectionBend(global->ITC_L1L2()->der_phiD_final.K(), layerdisk_-N_LAYER, nrbits_, nphiderbits_); + } + } void ProjectionRouter::addOutput(MemoryBase* memory, string output) { @@ -67,11 +74,6 @@ void ProjectionRouter::addInput(MemoryBase* memory, string input) { } void ProjectionRouter::execute() { - if (globals_->projectionRouterBendTable() == nullptr) { - auto* bendTablePtr = new ProjectionRouterBendTable(); - bendTablePtr->init(settings_, globals_, nrbits_, nphiderbits_); - globals_->projectionRouterBendTable() = bendTablePtr; - } unsigned int allprojcount = 0; @@ -91,7 +93,6 @@ void ProjectionRouter::execute() { if (layerdisk_ < N_LAYER) { fpgaphi = tracklet->proj(layerdisk_).fpgaphiproj(); } else { - int disk = layerdisk_ - (N_LAYER - 1); Projection& proj = tracklet->proj(layerdisk_); fpgaphi = proj.fpgaphiproj(); @@ -110,7 +111,7 @@ void ProjectionRouter::execute() { int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; - int ibendproj = globals_->projectionRouterBendTable()->bendLoookup(disk - 1, bendindex); + int ibendproj = rinvbendlut_.lookup(bendindex); proj.setBendIndex(ibendproj); } diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc deleted file mode 100644 index 78de56f0076db..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc +++ /dev/null @@ -1,54 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/ProjectionRouterBendTable.h" -#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" -#include "L1Trigger/TrackFindingTracklet/interface/Util.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" - -using namespace trklet; - -void ProjectionRouterBendTable::init(Settings const& settings, - Globals* globals, - unsigned int nrbits, - unsigned int nphiderbits) { - for (unsigned int idisk = 0; idisk < N_DISK; idisk++) { - unsigned int nsignbins = 2; - unsigned int nrbins = 1 << (nrbits); - unsigned int nphiderbins = 1 << (nphiderbits); - - for (unsigned int isignbin = 0; isignbin < nsignbins; isignbin++) { - for (unsigned int irbin = 0; irbin < nrbins; irbin++) { - int ir = irbin; - if (ir > (1 << (nrbits - 1))) - ir -= (1 << nrbits); - ir = ir << (settings.nrbitsstub(N_LAYER) - nrbits); - for (unsigned int iphiderbin = 0; iphiderbin < nphiderbins; iphiderbin++) { - int iphider = iphiderbin; - if (iphider > (1 << (nphiderbits - 1))) - iphider -= (1 << nphiderbits); - iphider = iphider << (settings.nbitsphiprojderL123() - nphiderbits); - - double rproj = ir * settings.krprojshiftdisk(); - double phider = iphider * globals->ITC_L1L2()->der_phiD_final.K(); - double t = settings.zmean(idisk) / rproj; - - if (isignbin) - t = -t; - - double rinv = -phider * (2.0 * t); - - double stripPitch = (rproj < settings.rcrit()) ? settings.stripPitch(true) : settings.stripPitch(false); - double bendproj = bendstrip(rproj, rinv, stripPitch); - - int ibendproj = 2.0 * bendproj + 15.5; - if (ibendproj < 0) - ibendproj = 0; - if (ibendproj > 31) - ibendproj = 31; - - bendtable_[idisk].push_back(ibendproj); - } - } - } - } -} - -int ProjectionRouterBendTable::bendLoookup(int diskindex, int bendindex) { return bendtable_[diskindex][bendindex]; } diff --git a/L1Trigger/TrackFindingTracklet/src/Sector.cc b/L1Trigger/TrackFindingTracklet/src/Sector.cc index c0d874d16d8de..6127d60c87670 100644 --- a/L1Trigger/TrackFindingTracklet/src/Sector.cc +++ b/L1Trigger/TrackFindingTracklet/src/Sector.cc @@ -40,7 +40,7 @@ #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" #include "DataFormats/Math/interface/deltaPhi.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" using namespace std; using namespace trklet; @@ -69,12 +69,8 @@ bool Sector::addStub(L1TStub stub, string dtc) { unsigned int layerdisk = stub.layerdisk(); if (layerdisk < N_LAYER && globals_->phiCorr(layerdisk) == nullptr) { - globals_->phiCorr(layerdisk) = new VMRouterPhiCorrTable(settings_); - - int nbits = 3; - if (layerdisk >= N_PSLAYER) - nbits = 4; - globals_->phiCorr(layerdisk)->init(layerdisk + 1, nbits, 3); + globals_->phiCorr(layerdisk) = new TrackletLUT(settings_); + globals_->phiCorr(layerdisk)->initPhiCorrTable(layerdisk, 3); } Stub fpgastub(stub, settings_, *globals_); @@ -83,8 +79,8 @@ bool Sector::addStub(L1TStub stub, string dtc) { FPGAWord r = fpgastub.r(); int bendbin = fpgastub.bend().value(); int rbin = (r.value() + (1 << (r.nbits() - 1))) >> (r.nbits() - 3); - const VMRouterPhiCorrTable& phiCorrTable = *globals_->phiCorr(layerdisk); - int iphicorr = phiCorrTable.getphiCorrValue(bendbin, rbin); + const TrackletLUT& phiCorrTable = *globals_->phiCorr(layerdisk); + int iphicorr = phiCorrTable.lookup(bendbin*(1<<3)+rbin); fpgastub.setPhiCorr(iphicorr); } diff --git a/L1Trigger/TrackFindingTracklet/src/Stub.cc b/L1Trigger/TrackFindingTracklet/src/Stub.cc index fe7595a7dd784..8359d17894966 100644 --- a/L1Trigger/TrackFindingTracklet/src/Stub.cc +++ b/L1Trigger/TrackFindingTracklet/src/Stub.cc @@ -21,9 +21,7 @@ Stub::Stub(L1TStub& stub, Settings const& settings, Globals& globals) : settings layerdisk_ = stub.layerdisk(); - int nbendbits = 4; - if (stub.isPSmodule()) - nbendbits = 3; + int nbendbits = stub.isPSmodule() ? N_BENDBITS_PS : N_BENDBITS_2S; int nalphabits = 0; @@ -36,8 +34,6 @@ Stub::Stub(L1TStub& stub, Settings const& settings, Globals& globals) : settings nrbits = 7; } - int layer = stub.layer() + 1; - assert(nbendbits + nalphabits + nrbits + nzbits + nphibits == 36); bitset<32> rbits(stubwordbin.substr(0, nrbits)); @@ -71,9 +67,9 @@ Stub::Stub(L1TStub& stub, Settings const& settings, Globals& globals) : settings phi_.set(newphi, nphibits, true, __LINE__, __FILE__); phicorr_.set(newphi, nphibits, true, __LINE__, __FILE__); bool pos = false; - if (layerdisk_ > 5) { + if (layerdisk_ >= N_LAYER) { pos = true; - int disk = layerdisk_ - 5; + int disk = layerdisk_ - N_LAYER + 1; if (stub.z() < 0.0) disk = -disk; disk_.set(disk, 4, false, __LINE__, __FILE__); @@ -83,7 +79,7 @@ Stub::Stub(L1TStub& stub, Settings const& settings, Globals& globals) : settings } } else { disk_.set(0, 4, false, __LINE__, __FILE__); - layer_.set(layer - 1, 3, true, __LINE__, __FILE__); + layer_.set(layerdisk_, 3, true, __LINE__, __FILE__); } r_.set(newr, nrbits, pos, __LINE__, __FILE__); z_.set(newz, nzbits, false, __LINE__, __FILE__); @@ -125,13 +121,13 @@ std::string Stub::phiregionaddressstr() const { } void Stub::setAllStubIndex(int nstub) { - if (nstub >= (1 << 7)) { + if (nstub >= (1 << N_BITSMEMADDRESS)) { if (settings_.debugTracklet()) edm::LogPrint("Tracklet") << "Warning too large stubindex!"; - nstub = (1 << 7) - 1; + nstub = (1 << N_BITSMEMADDRESS) - 1; } - stubindex_.set(nstub, 7); + stubindex_.set(nstub, N_BITSMEMADDRESS); } void Stub::setPhiCorr(int phiCorr) { @@ -188,6 +184,6 @@ double Stub::phiapprox(double phimin, double) const { unsigned int Stub::layerdisk() const { if (layer_.value() == -1) - return 5 + abs(disk_.value()); + return N_LAYER - 1 + abs(disk_.value()); return layer_.value(); } diff --git a/L1Trigger/TrackFindingTracklet/src/TETableBase.cc b/L1Trigger/TrackFindingTracklet/src/TETableBase.cc deleted file mode 100644 index 6e701edf0ee15..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/TETableBase.cc +++ /dev/null @@ -1,33 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/TETableBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/Util.h" - -using namespace std; -using namespace trklet; - -TETableBase::TETableBase(Settings const& settings) : settings_(settings) {} - -void TETableBase::writeVMTable(const std::string& dir, const std::string& name, bool positive) { - // Write LUT table. - - ofstream out = openfile(dir, name, __FILE__, __LINE__); - - out << "{" << endl; - for (unsigned int i = 0; i < table_.size(); i++) { - if (i != 0) { - out << "," << endl; - } - - assert(nbits_ > 0); - - int itable = table_[i]; - if (positive) { - if (table_[i] < 0) { - itable = (1 << nbits_) - 1; - } - } - - out << itable; - } - out << endl << "};" << endl; - out.close(); -} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc index 24e397c30d433..7169ab6f52c47 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc @@ -270,10 +270,10 @@ void TrackletCalculatorBase::addProjectionDisk(int disk, int iphi, TrackletProjectionsMemory* trackletprojs, Tracklet* tracklet) { - if (iSeed_ == 2 && abs(disk) == 4) + if (iSeed_ == Seed::L3L4 && abs(disk) == 4) return; //L3L4 projections to D3 are not used. Should be in configuration if (trackletprojs == nullptr) { - if (iSeed_ == 2 && abs(disk) == 3) + if (iSeed_ == Seed::L3L4 && abs(disk) == 3) return; //L3L4 projections to D3 are not used. if (settings_.warnNoMem()) { edm::LogVerbatim("Tracklet") << "No projection memory exists in " << getName() << " for disk = " << abs(disk) diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc b/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc index 8984e574c3ebe..2cf5d706aae4e 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc @@ -278,11 +278,11 @@ std::string TrackletConfigBuilder::iRegStr(unsigned int iReg, unsigned int iSeed static std::string nameL2L3[4] = {"I", "J", "K", "L"}; - if (iSeed == 1) { + if (iSeed == Seed::L2L3) { assert(iReg < 4); return nameL2L3[iReg]; } - if (iSeed == 6 || iSeed == 7) { + if (iSeed == Seed::L1D1 || iSeed == Seed::L2D1) { assert(iReg < 8); return nameOverlap[iReg]; } @@ -892,7 +892,7 @@ void TrackletConfigBuilder::writeVMSMemories(std::ostream& os, std::ostream& mem for (unsigned int iReg = 0; iReg < NRegions_[l2]; iReg++) { unsigned int nmem = 0; //Hack since we use same module twice - if (iSeed == 7) { + if (iSeed == Seed::L2D1) { nmem = 2; } @@ -942,7 +942,7 @@ void TrackletConfigBuilder::writeVMSMemories(std::ostream& os, std::ostream& mem unsigned int nmem = 0; - if (iSeed == 7) { + if (iSeed == Seed::L2D1) { nmem = 4; } diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc index 42f5d49cc2947..e4d71c40de799 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc @@ -14,7 +14,7 @@ using namespace trklet; using namespace std; TrackletEngine::TrackletEngine(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global) { + : ProcessBase(name, settings, global), innerptlut_(settings), outerptlut_(settings) { stubpairs_ = nullptr; innervmstubs_ = nullptr; outervmstubs_ = nullptr; @@ -119,7 +119,7 @@ void TrackletEngine::execute() { int ptinnerindex = (index << innerbend.nbits()) + innerbend.value(); int ptouterindex = (index << outerbend.nbits()) + outerbend.value(); - if (!(pttableinner_[ptinnerindex] && pttableouter_[ptouterindex])) { + if (!(innerptlut_.lookup(ptinnerindex) && outerptlut_.lookup(ptouterindex))) { if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " << settings_.benddecode( @@ -152,143 +152,40 @@ void TrackletEngine::setVMPhiBin() { innervmstubs_->setother(outervmstubs_); outervmstubs_->setother(innervmstubs_); - int outerrbits = 3; - if (iSeed_ < 4) { - outerrbits = 0; - } - - int outerrbins = (1 << outerrbits); - int innerphibins = (1 << innerphibits_); - int outerphibins = (1 << outerphibits_); - double innerphimin, innerphimax; innervmstubs_->getPhiRange(innerphimin, innerphimax, iSeed_, 0); double outerphimin, outerphimax; outervmstubs_->getPhiRange(outerphimin, outerphimax, iSeed_, 1); - double phiinner[2]; - double phiouter[2]; - double router[2]; - - unsigned int nbendbitsinner = 3; - unsigned int nbendbitsouter = 3; - if (iSeed_ == 2) { - nbendbitsouter = 4; - } - if (iSeed_ == 3) { - nbendbitsinner = 4; - nbendbitsouter = 4; - } - - std::vector vmbendinner((1 << nbendbitsinner), false); - std::vector vmbendouter((1 << nbendbitsouter), false); - - for (int iphiinnerbin = 0; iphiinnerbin < innerphibins; iphiinnerbin++) { - phiinner[0] = innerphimin + iphiinnerbin * (innerphimax - innerphimin) / innerphibins; - phiinner[1] = innerphimin + (iphiinnerbin + 1) * (innerphimax - innerphimin) / innerphibins; - for (int iphiouterbin = 0; iphiouterbin < outerphibins; iphiouterbin++) { - phiouter[0] = outerphimin + iphiouterbin * (outerphimax - outerphimin) / outerphibins; - phiouter[1] = outerphimin + (iphiouterbin + 1) * (outerphimax - outerphimin) / outerphibins; - for (int irouterbin = 0; irouterbin < outerrbins; irouterbin++) { - if (iSeed_ >= 4) { - router[0] = - settings_.rmindiskvm() + irouterbin * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins; - router[1] = settings_.rmindiskvm() + - (irouterbin + 1) * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins; - } else { - router[0] = settings_.rmean(layerdisk2_); - router[1] = settings_.rmean(layerdisk2_); - } - - double bendinnermin = 20.0; - double bendinnermax = -20.0; - double bendoutermin = 20.0; - double bendoutermax = -20.0; - double rinvmin = 1.0; - for (int i1 = 0; i1 < 2; i1++) { - for (int i2 = 0; i2 < 2; i2++) { - for (int i3 = 0; i3 < 2; i3++) { - double rinner = 0.0; - if (iSeed_ == 4 || iSeed_ == 5) { - rinner = router[i3] * settings_.zmean(layerdisk1_ - N_LAYER) / settings_.zmean(layerdisk2_ - N_LAYER); - } else { - rinner = settings_.rmean(layerdisk1_); - } - double rinv1 = -rinv(phiinner[i1], phiouter[i2], rinner, router[i3]); - double pitchinner = - (rinner < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); - double pitchouter = - (router[i3] < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); - double abendinner = bendstrip(rinner, rinv1, pitchinner); - double abendouter = bendstrip(router[i3], rinv1, pitchouter); - if (abendinner < bendinnermin) - bendinnermin = abendinner; - if (abendinner > bendinnermax) - bendinnermax = abendinner; - if (abendouter < bendoutermin) - bendoutermin = abendouter; - if (abendouter > bendoutermax) - bendoutermax = abendouter; - if (std::abs(rinv1) < rinvmin) { - rinvmin = std::abs(rinv1); - } - } - } - } - - bool passptcut = rinvmin < settings_.rinvcutte(); - - for (int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) { - double bend = settings_.benddecode(ibend, layerdisk1_, nbendbitsinner == 3); - - bool passinner = bend > bendinnermin - settings_.bendcutte(ibend, layerdisk1_, nbendbitsinner == 3) && - bend < bendinnermax + settings_.bendcutte(ibend, layerdisk1_, nbendbitsinner == 3); - if (passinner) - vmbendinner[ibend] = true; - pttableinner_.push_back(passinner && passptcut); - } - - for (int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) { - double bend = settings_.benddecode(ibend, layerdisk2_, nbendbitsouter == 3); - - bool passouter = bend > bendoutermin - settings_.bendcutte(ibend, layerdisk2_, nbendbitsouter == 3) && - bend < bendoutermax + settings_.bendcutte(ibend, layerdisk2_, nbendbitsouter == 3); - if (passouter) - vmbendouter[ibend] = true; - pttableouter_.push_back(passouter && passptcut); - } - } - } - } + string innermem = innervmstubs_->getName().substr(6); + string outermem = outervmstubs_->getName().substr(6); + + innerptlut_.initteptlut(true, false, iSeed_, layerdisk1_, layerdisk2_, + innerphibits_, outerphibits_, + innerphimin, innerphimax, outerphimin, outerphimax, + innermem, outermem); + + outerptlut_.initteptlut(false, false, iSeed_, layerdisk1_, layerdisk2_, + innerphibits_, outerphibits_, + innerphimin, innerphimax, outerphimin, outerphimax, + innermem, outermem); + + TrackletLUT innertememlut(settings_); + TrackletLUT outertememlut(settings_); + + innertememlut.initteptlut(true, true, iSeed_, layerdisk1_, layerdisk2_, + innerphibits_, outerphibits_, + innerphimin, innerphimax, outerphimin, outerphimax, + innermem, outermem); + + outertememlut.initteptlut(false, true, iSeed_, layerdisk1_, layerdisk2_, + innerphibits_, outerphibits_, + innerphimin, innerphimax, outerphimin, outerphimax, + innermem, outermem); + + innervmstubs_->setbendtable(innertememlut); + outervmstubs_->setbendtable(outertememlut); - innervmstubs_->setbendtable(vmbendinner); - outervmstubs_->setbendtable(vmbendouter); - - if (settings_.writeTable()) - writeTETable(); } -void TrackletEngine::writeTETable() { - ofstream outstubptinnercut = openfile(settings_.tablePath(), getName() + "_stubptinnercut.tab", __FILE__, __LINE__); - - outstubptinnercut << "{" << endl; - for (unsigned int i = 0; i < pttableinner_.size(); i++) { - if (i != 0) - outstubptinnercut << "," << endl; - outstubptinnercut << pttableinner_[i]; - } - outstubptinnercut << endl << "};" << endl; - outstubptinnercut.close(); - - ofstream outstubptoutercut = openfile(settings_.tablePath(), getName() + "_stubptoutercut.tab", __FILE__, __LINE__); - - outstubptoutercut << "{" << endl; - for (unsigned int i = 0; i < pttableouter_.size(); i++) { - if (i != 0) - outstubptoutercut << "," << endl; - outstubptoutercut << pttableouter_[i]; - } - outstubptoutercut << endl << "};" << endl; - outstubptoutercut.close(); -} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc index 291d47b7ad5cc..9aa2fc61efd14 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc @@ -12,10 +12,10 @@ TrackletEngineUnit::TrackletEngineUnit(const Settings* const settings, unsigned int iSeed, unsigned int nbitsfinephidiff, unsigned int iAllStub, - std::vector const& pttableinner, - std::vector const& pttableouter, + const TrackletLUT& pttableinnernew, + const TrackletLUT& pttableouternew, VMStubsTEMemory* outervmstubs) - : settings_(settings), candpairs_(3) { +: settings_(settings), pttableinnernew_(pttableinnernew), pttableouternew_(pttableouternew), candpairs_(3) { idle_ = true; nbitsfinephi_ = nbitsfinephi; layerdisk2_ = layerdisk2; @@ -23,8 +23,6 @@ TrackletEngineUnit::TrackletEngineUnit(const Settings* const settings, iSeed_ = iSeed; nbitsfinephidiff_ = nbitsfinephidiff; iAllStub_ = iAllStub; - pttableinner_ = pttableinner; - pttableouter_ = pttableouter; outervmstubs_ = outervmstubs; } @@ -102,8 +100,8 @@ void TrackletEngineUnit::step(bool, int, int) { int ptinnerindex = (idphi << tedata_.innerbend_.nbits()) + tedata_.innerbend_.value(); int ptouterindex = (idphi << outerbend.nbits()) + outerbend.value(); - - if (!(inrange && pttableinner_[ptinnerindex] && pttableouter_[ptouterindex])) { + + if (!(inrange && pttableinnernew_.lookup(ptinnerindex) && pttableouternew_.lookup(ptouterindex))) { if (settings_->debugTracklet()) { edm::LogVerbatim("Tracklet") << " Stub pair rejected because of stub pt cut bends : " << settings_->benddecode( diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc b/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc new file mode 100644 index 0000000000000..bb48a551f1f4d --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc @@ -0,0 +1,945 @@ +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h" + +#include + +using namespace std; +using namespace trklet; + +TrackletLUT::TrackletLUT(const Settings& settings) : settings_(settings) {} + +void TrackletLUT::initmatchcut(unsigned int layerdisk, MatchType type, unsigned int region) { + + char cregion = 'A'+region; + + for (unsigned int iSeed = 0; iSeed < 12; iSeed++) { + if (type==barrelphi) { + table_.push_back(settings_.rphimatchcut(iSeed, layerdisk) / (settings_.kphi1() * settings_.rmean(layerdisk))); + } + if (type==barrelz) { + table_.push_back(settings_.zmatchcut(iSeed, layerdisk) / settings_.kz()); + } + if (type==diskPSphi) { + table_.push_back(settings_.rphicutPS(iSeed, layerdisk - N_LAYER) / (settings_.kphi() * settings_.kr())); + } + if (type==disk2Sphi) { + table_.push_back(settings_.rphicut2S(iSeed, layerdisk - N_LAYER) / (settings_.kphi() * settings_.kr())); + } + if (type==disk2Sr) { + table_.push_back(settings_.rcut2S(iSeed, layerdisk - N_LAYER) / settings_.krprojshiftdisk()); + } + if (type==diskPSr) { + table_.push_back(settings_.rcutPS(iSeed, layerdisk - N_LAYER) / settings_.krprojshiftdisk()); + } + } + + name_ = settings_.combined() ? "MP_" : "MC_"; + + if (type==barrelphi) { + name_ += TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_phicut.tab"; + } + if (type==barrelz) { + name_ += TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_zcut.tab"; + } + if (type==diskPSphi) { + name_ += TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_PSphicut.tab"; + } + if (type==disk2Sphi) { + name_ += TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_2Sphicut.tab"; + } + if (type==disk2Sr) { + name_ += TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_2Srcut.tab"; + } + if (type==diskPSr) { + name_ += TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_PSrcut.tab"; + } + + positive_ = false; + + writeTable(); + +} + + +void TrackletLUT::initTPlut(bool fillInner, unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, + unsigned int nbitsfinephidiff, unsigned int iTP) { + + //number of fine phi bins in sector + int nfinephibins = + settings_.nallstubs(layerdisk2) * settings_.nvmte(1, iSeed) * (1 << settings_.nfinephi(1, iSeed)); + double dfinephi = settings_.dphisectorHG() / nfinephibins; + + double rmin = -1.0; + double rmax = -1.0; + + int outerrbits = 3; + + if (iSeed == Seed::L1L2 || iSeed == Seed::L2L3 ||iSeed == Seed::L3L4 || iSeed == Seed::L5L6 ) { + outerrbits = 0; + rmin = settings_.rmean(layerdisk1); + rmax = settings_.rmean(layerdisk2); + } else { + if (iSeed == Seed::L1D1) { + rmax = settings_.rmaxdiskl1overlapvm(); + rmin = settings_.rmean(layerdisk1); + } else if (iSeed == Seed::L2D1) { + rmax = settings_.rmaxdiskvm(); + rmin = settings_.rmean(layerdisk1); + } else { + rmax = settings_.rmaxdiskvm(); + rmin = rmax * settings_.zmean(layerdisk2 - N_LAYER - 1) / settings_.zmean(layerdisk2 - N_LAYER); + } + } + + int outerrbins = (1 << outerrbits); + + double dphi[2]; + double router[2]; + + unsigned int nbendbitsinner = 3; + unsigned int nbendbitsouter = 3; + if (iSeed == Seed::L3L4) { + nbendbitsouter = 4; + } else if (iSeed == Seed::L5L6) { + nbendbitsinner = 4; + nbendbitsouter = 4; + } + + int nbinsfinephidiff = (1 << nbitsfinephidiff); + + for (int iphibin = 0; iphibin < nbinsfinephidiff; iphibin++) { + int iphidiff = iphibin; + if (iphibin >= nbinsfinephidiff / 2) { + iphidiff = iphibin - nbinsfinephidiff; + } + //min and max dphi + dphi[0] = (iphidiff - 1.5) * dfinephi; + dphi[1] = (iphidiff + 1.5) * dfinephi; + for (int irouterbin = 0; irouterbin < outerrbins; irouterbin++) { + if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4 ||iSeed == Seed::L1D1 || iSeed == Seed::L2D1 ) { + router[0] = + settings_.rmindiskvm() + irouterbin * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins; + router[1] = + settings_.rmindiskvm() + (irouterbin + 1) * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins; + } else { + router[0] = settings_.rmean(layerdisk2); + router[1] = settings_.rmean(layerdisk2); + } + + double bendinnermin = 20.0; + double bendinnermax = -20.0; + double bendoutermin = 20.0; + double bendoutermax = -20.0; + double rinvmin = 1.0; + for (int i2 = 0; i2 < 2; i2++) { + for (int i3 = 0; i3 < 2; i3++) { + double rinner = 0.0; + if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4) { + rinner = router[i3] * settings_.zmean(layerdisk1 - N_LAYER) / settings_.zmean(layerdisk2 - N_LAYER); + } else { + rinner = settings_.rmean(layerdisk1); + } + double rinv1 = rinv(0.0, -dphi[i2], rinner, router[i3]); + double pitchinner = (rinner < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double pitchouter = + (router[i3] < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double abendinner = bendstrip(rinner, rinv1, pitchinner); + double abendouter = bendstrip(router[i3], rinv1, pitchouter); + if (abendinner < bendinnermin) + bendinnermin = abendinner; + if (abendinner > bendinnermax) + bendinnermax = abendinner; + if (abendouter < bendoutermin) + bendoutermin = abendouter; + if (abendouter > bendoutermax) + bendoutermax = abendouter; + if (std::abs(rinv1) < rinvmin) { + rinvmin = std::abs(rinv1); + } + } + } + + bool passptcut = rinvmin < settings_.rinvcutte(); + + if (fillInner) { + for (int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) { + double bend = settings_.benddecode(ibend, layerdisk1, nbendbitsinner == 3); + + bool passinner = bend <= bendinnermax + settings_.bendcutte(ibend, layerdisk1, nbendbitsinner == 3) && + bend >= bendinnermin - settings_.bendcutte(ibend, layerdisk1, nbendbitsinner == 3); + table_.push_back(passinner && passptcut); + } + } else { + for (int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) { + double bend = settings_.benddecode(ibend, layerdisk2, nbendbitsouter == 3); + + bool passouter = bend <= bendoutermax + settings_.bendcutte(ibend, layerdisk2, nbendbitsouter == 3) && + bend >= bendoutermin - settings_.bendcutte(ibend, layerdisk2, nbendbitsouter == 3); + table_.push_back(passouter && passptcut); + } + } + } + } + + positive_ = false; + char cTP='A'+iTP; + + name_="TP_"+TrackletConfigBuilder::LayerName(layerdisk1)+TrackletConfigBuilder::LayerName(layerdisk2)+cTP; + + if (fillInner) { + name_+="_stubptinnercut.tab"; + } else { + name_+="_stubptoutercut.tab"; + } + + writeTable(); + +} + + +void TrackletLUT::initTPregionlut(unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, + unsigned int iAllStub, unsigned int nbitsfinephidiff, unsigned int nbitsfinephi, + const TrackletLUT& tplutinner, unsigned int iTP) { + + int nirbits = 0; + if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4 ||iSeed == Seed::L1D1 || iSeed == Seed::L2D1 ) { + nirbits = 3; + } + + unsigned int nbendbitsinner = 3; + unsigned int nbendbitsouter = 3; + if (iSeed == Seed::L3L4) { + nbendbitsouter = 4; + } else if (iSeed == Seed::L5L6) { + nbendbitsinner = 4; + nbendbitsouter = 4; + } + + for (int innerfinephi = 0; innerfinephi < (1 << nbitsfinephi); innerfinephi++) { + for (int innerbend = 0; innerbend < (1 << nbendbitsinner); innerbend++) { + for (int ir = 0; ir < (1 << nirbits); ir++) { + unsigned int usereg = 0; + for (unsigned int ireg = 0; ireg < settings_.nvmte(1, iSeed); ireg++) { + bool match = false; + for (int ifinephiouter = 0; ifinephiouter < (1 << settings_.nfinephi(1, iSeed)); ifinephiouter++) { + int outerfinephi = iAllStub * (1 << (nbitsfinephi - settings_.nbitsallstubs(layerdisk2))) + + ireg * (1 << settings_.nfinephi(1, iSeed)) + ifinephiouter; + int idphi = outerfinephi - innerfinephi; + bool inrange = (idphi < (1 << (nbitsfinephidiff - 1))) && (idphi >= -(1 << (nbitsfinephidiff - 1))); + if (idphi < 0) + idphi = idphi + (1 << nbitsfinephidiff); + int idphi1 = idphi; + if (iSeed >= 4) + idphi1 = (idphi << 3) + ir; + int ptinnerindexnew = (idphi1 << nbendbitsinner) + innerbend; + match = match || (inrange && tplutinner.lookup(ptinnerindexnew)); + } + if (match) { + usereg = usereg | (1 << ireg); + } + } + + table_.push_back(usereg); + + } + } + } + + positive_ = false; + char cTP='A'+iTP; + + name_="TP_"+TrackletConfigBuilder::LayerName(layerdisk1)+TrackletConfigBuilder::LayerName(layerdisk2)+cTP+"_usereg.tab"; + + writeTable(); + +} + +void TrackletLUT::initteptlut(bool fillInner, bool fillTEMem, unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, + unsigned int innerphibits, unsigned int outerphibits, + double innerphimin, double innerphimax, double outerphimin, double outerphimax, + const std::string& innermem, const std::string& outermem) { + + int outerrbits = 0; + if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4 ||iSeed == Seed::L1D1 || iSeed == Seed::L2D1 ) { + outerrbits = 3; + } + + int outerrbins = (1 << outerrbits); + int innerphibins = (1 << innerphibits); + int outerphibins = (1 << outerphibits); + + double phiinner[2]; + double phiouter[2]; + double router[2]; + + unsigned int nbendbitsinner = 3; + unsigned int nbendbitsouter = 3; + if (iSeed == Seed::L3L4) { + nbendbitsouter = 4; + } + if (iSeed == Seed::L5L6) { + nbendbitsinner = 4; + nbendbitsouter = 4; + } + + if (fillTEMem) { + if (fillInner) { + table_.resize((1 << nbendbitsinner), false); + } else { + table_.resize((1 << nbendbitsouter), false); + } + } + + for (int iphiinnerbin = 0; iphiinnerbin < innerphibins; iphiinnerbin++) { + phiinner[0] = innerphimin + iphiinnerbin * (innerphimax - innerphimin) / innerphibins; + phiinner[1] = innerphimin + (iphiinnerbin + 1) * (innerphimax - innerphimin) / innerphibins; + for (int iphiouterbin = 0; iphiouterbin < outerphibins; iphiouterbin++) { + phiouter[0] = outerphimin + iphiouterbin * (outerphimax - outerphimin) / outerphibins; + phiouter[1] = outerphimin + (iphiouterbin + 1) * (outerphimax - outerphimin) / outerphibins; + for (int irouterbin = 0; irouterbin < outerrbins; irouterbin++) { + if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4 ||iSeed == Seed::L1D1 || iSeed == Seed::L2D1 ) { + router[0] = + settings_.rmindiskvm() + irouterbin * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins; + router[1] = settings_.rmindiskvm() + + (irouterbin + 1) * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins; + } else { + router[0] = settings_.rmean(layerdisk2); + router[1] = settings_.rmean(layerdisk2); + } + + double bendinnermin = 20.0; + double bendinnermax = -20.0; + double bendoutermin = 20.0; + double bendoutermax = -20.0; + double rinvmin = 1.0; + for (int i1 = 0; i1 < 2; i1++) { + for (int i2 = 0; i2 < 2; i2++) { + for (int i3 = 0; i3 < 2; i3++) { + double rinner = 0.0; + if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4) { + rinner = router[i3] * settings_.zmean(layerdisk1 - N_LAYER) / settings_.zmean(layerdisk2 - N_LAYER); + } else { + rinner = settings_.rmean(layerdisk1); + } + double rinv1 = -rinv(phiinner[i1], phiouter[i2], rinner, router[i3]); + double pitchinner = + (rinner < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double pitchouter = + (router[i3] < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double abendinner = bendstrip(rinner, rinv1, pitchinner); + double abendouter = bendstrip(router[i3], rinv1, pitchouter); + if (abendinner < bendinnermin) + bendinnermin = abendinner; + if (abendinner > bendinnermax) + bendinnermax = abendinner; + if (abendouter < bendoutermin) + bendoutermin = abendouter; + if (abendouter > bendoutermax) + bendoutermax = abendouter; + if (std::abs(rinv1) < rinvmin) { + rinvmin = std::abs(rinv1); + } + } + } + } + + bool passptcut = rinvmin < settings_.rinvcutte(); + + if (fillInner) { + for (int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) { + double bend = settings_.benddecode(ibend, layerdisk1, nbendbitsinner == 3); + + bool passinner = bend > bendinnermin - settings_.bendcutte(ibend, layerdisk1, nbendbitsinner == 3) && + bend < bendinnermax + settings_.bendcutte(ibend, layerdisk1, nbendbitsinner == 3); + + if (fillTEMem) { + if (passinner) { + table_[ibend] = 1; + } + } else { + table_.push_back(passinner && passptcut); + } + } + } else { + for (int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) { + double bend = settings_.benddecode(ibend, layerdisk2, nbendbitsouter == 3); + + bool passouter = bend > bendoutermin - settings_.bendcutte(ibend, layerdisk2, nbendbitsouter == 3) && + bend < bendoutermax + settings_.bendcutte(ibend, layerdisk2, nbendbitsouter == 3); + if (fillTEMem) { + if (passouter) { + table_[ibend] = 1; + } + } else { + table_.push_back(passouter && passptcut); + } + } + } + } + } + } + + positive_ = false; + + if (fillTEMem) { + if (fillInner) { + name_ = "VMSTE_"+innermem+"_vmbendcut.tab"; + } else { + name_ = "VMSTE_"+outermem+"_vmbendcut.tab"; + } + } else { + name_ = "TE_"+innermem.substr(0,innermem.size()-2)+"_"+outermem.substr(0,outermem.size()-2); + if (fillInner) { + name_+="_stubptinnercut.tab"; + } else { + name_+="_stubptoutercut.tab"; + } + } + + + writeTable(); + +} + + +void TrackletLUT::initProjectionBend(double k_phider, + unsigned int idisk, + unsigned int nrbits, + unsigned int nphiderbits) { + + unsigned int nsignbins = 2; + unsigned int nrbins = 1 << (nrbits); + unsigned int nphiderbins = 1 << (nphiderbits); + + for (unsigned int isignbin = 0; isignbin < nsignbins; isignbin++) { + for (unsigned int irbin = 0; irbin < nrbins; irbin++) { + int ir = irbin; + if (ir > (1 << (nrbits - 1))) + ir -= (1 << nrbits); + ir = ir << (settings_.nrbitsstub(N_LAYER) - nrbits); + for (unsigned int iphiderbin = 0; iphiderbin < nphiderbins; iphiderbin++) { + int iphider = iphiderbin; + if (iphider > (1 << (nphiderbits - 1))) + iphider -= (1 << nphiderbits); + iphider = iphider << (settings_.nbitsphiprojderL123() - nphiderbits); + + double rproj = ir * settings_.krprojshiftdisk(); + double phider = iphider * k_phider; + double t = settings_.zmean(idisk) / rproj; + + if (isignbin) + t = -t; + + double rinv = -phider * (2.0 * t); + + double stripPitch = (rproj < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double bendproj = bendstrip(rproj, rinv, stripPitch); + + int ibendproj = 2.0 * bendproj + 15.5; + if (ibendproj < 0) + ibendproj = 0; + if (ibendproj > 31) + ibendproj = 31; + + table_.push_back(ibendproj); + } + } + } + + positive_ = false; + name_ = settings_.combined() ? "MP_" : "PR_"; + name_ += "ProjectionBend_"+TrackletConfigBuilder::LayerName(N_LAYER+idisk)+".tab"; + + writeTable(); + +} + + + + +void TrackletLUT::initBendMatch(unsigned int layerdisk) { + + unsigned int nrinv = NRINVBITS; + double rinvhalf = 0.5 * ((1 << nrinv) - 1); + + bool barrel = layerdisk < N_LAYER; + bool isPSmodule = layerdisk < N_PSLAYER; + double stripPitch = settings_.stripPitch(isPSmodule); + + if (barrel) { + + unsigned int nbits = isPSmodule ? N_BENDBITS_PS : N_BENDBITS_2S; + + for (unsigned int irinv = 0; irinv < (1u << nrinv); irinv++) { + double rinv = (irinv - rinvhalf) * (1 << (settings_.nbitsrinv() - nrinv)) * settings_.krinvpars(); + + double projbend = bendstrip(settings_.rmean(layerdisk), rinv, stripPitch); + for (unsigned int ibend = 0; ibend < (1u << nbits); ibend++) { + double stubbend = settings_.benddecode(ibend, layerdisk, isPSmodule); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk, isPSmodule); + table_.push_back(pass); + } + } + } else { + for (unsigned int iprojbend = 0; iprojbend < (1u << nrinv); iprojbend++) { + double projbend = 0.5 * (iprojbend - rinvhalf); + for (unsigned int ibend = 0; ibend < (1 << N_BENDBITS_2S); ibend++) { + double stubbend = settings_.benddecode(ibend, layerdisk, false); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk, false); + table_.push_back(pass); + } + } + for (unsigned int iprojbend = 0; iprojbend < (1u << nrinv); iprojbend++) { + double projbend = 0.5 * (iprojbend - rinvhalf); + for (unsigned int ibend = 0; ibend < (1 << N_BENDBITS_PS); ibend++) { + double stubbend = settings_.benddecode(ibend, layerdisk, true); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk, true); + table_.push_back(pass); + } + } + } + + positive_ = false; + + name_ = "METable_"+TrackletConfigBuilder::LayerName(layerdisk)+".tab"; + + writeTable(); + +} + + +void TrackletLUT::initVMRTable(unsigned int layerdisk, VMRTableType type, int region) { + + unsigned int zbits = settings_.vmrlutzbits(layerdisk); + unsigned int rbits = settings_.vmrlutrbits(layerdisk); + + unsigned int rbins = (1 << rbits); + unsigned int zbins = (1 << zbits); + + double zmin, zmax, rmin, rmax; + + if (layerdisk < N_LAYER) { + zmin = -settings_.zlength(); + zmax = settings_.zlength(); + rmin = settings_.rmean(layerdisk) - settings_.drmax(); + rmax = settings_.rmean(layerdisk) + settings_.drmax(); + } else { + rmin = 0; + rmax = settings_.rmaxdisk(); + zmin = settings_.zmean(layerdisk - N_LAYER) - settings_.dzmax(); + zmax = settings_.zmean(layerdisk - N_LAYER) + settings_.dzmax(); + } + + double dr = (rmax - rmin) / rbins; + double dz = (zmax - zmin) / zbins; + + int NBINS = settings_.NLONGVMBINS() * settings_.NLONGVMBINS(); + + for (unsigned int izbin = 0; izbin < zbins; izbin++) { + for (unsigned int irbin = 0; irbin < rbins; irbin++) { + double r = rmin + (irbin + 0.5) * dr; + double z = zmin + (izbin + 0.5) * dz; + + if (settings_.combined()) { + int iznew = izbin - (1 << (zbits - 1)); + if (iznew < 0) + iznew += (1 << zbits); + assert(iznew >= 0); + assert(iznew < (1 << zbits)); + z = zmin + (iznew + 0.5) * dz; + if (layerdisk < N_LAYER) { + int irnew = irbin - (1 << (rbits - 1)); + if (irnew < 0) + irnew += (1 << rbits); + assert(irnew >= 0); + assert(irnew < (1 << rbits)); + r = rmin + (irnew + 0.5) * dr; + } + } + + if (layerdisk >= N_LAYER && irbin < 10) //special case for the tabulated radii in 2S disks + r = (layerdisk < N_LAYER+2) ? settings_.rDSSinner(irbin) : settings_.rDSSouter(irbin); + + int bin; + if (layerdisk < N_LAYER) { + double zproj = z * settings_.rmean(layerdisk) / r; + bin = NBINS * (zproj + settings_.zlength()) / (2 * settings_.zlength()); + } else { + double rproj = r * settings_.zmean(layerdisk - N_LAYER) / z; + bin = NBINS * (rproj - settings_.rmindiskvm()) / (settings_.rmaxdisk() - settings_.rmindiskvm()); + } + if (bin < 0) + bin = 0; + if (bin >= NBINS) + bin = NBINS - 1; + + if (type == VMRTableType::me ) { + table_.push_back(bin); + } + + if (type == VMRTableType::disk ) { + if (layerdisk >= N_LAYER) { + double rproj = r * settings_.zmean(layerdisk - N_LAYER) / z; + bin = 0.5 * NBINS * (rproj - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm()); + //bin value of zero indicates that stub is out of range + if (bin < 0) + bin = 0; + if (bin >= NBINS / 2) + bin = 0; + table_.push_back(bin); + } + } + + if (type == VMRTableType::inner ) { + if (layerdisk == LayerDisk::L1 || layerdisk == LayerDisk::L3 || layerdisk == LayerDisk::L5 || + layerdisk == LayerDisk::D1 || layerdisk == LayerDisk::D3) { + table_.push_back(getVMRLookup(layerdisk + 1, z, r, dz, dr)); + } + if (layerdisk == LayerDisk::L2) { + table_.push_back(getVMRLookup(layerdisk + 1, z, r, dz, dr, 1)); + } + } + + if (type == VMRTableType::inneroverlap ) { + if (layerdisk == LayerDisk::L1 || layerdisk == LayerDisk::L2) { + table_.push_back(getVMRLookup(6, z, r, dz, dr, layerdisk + 6)); + } + } + + + if (type == VMRTableType::innerthird ) { + if (layerdisk == LayerDisk::L2) { //projection from L2 to D1 for L2L3D1 seeding + table_.push_back(getVMRLookup(6, z, r, dz, dr, 10)); + } + + if (layerdisk == LayerDisk::L5) { //projection from L5 to L4 for L5L6L4 seeding + table_.push_back(getVMRLookup(3, z, r, dz, dr)); + } + + if (layerdisk == LayerDisk::L3) { //projection from L3 to L5 for L3L4L2 seeding + table_.push_back(getVMRLookup(1, z, r, dz, dr)); + } + + if (layerdisk == LayerDisk::D1) { //projection from D1 to L2 for D1D2L2 seeding + table_.push_back(getVMRLookup(1, z, r, dz, dr)); + } + } + + if (type == VMRTableType::innerthird ) { + if (layerdisk == LayerDisk::L1 || layerdisk == 1) { + table_.push_back(getVMRLookup(N_LAYER, z, r, dz, dr, layerdisk + N_LAYER)); + } + } + } + } + + + if (settings_.combined()) { + if (type == VMRTableType::me) { + positive_ = false; + name_ = "VMRME_"+TrackletConfigBuilder::LayerName(layerdisk)+".tab"; + } + if (type == VMRTableType::disk) { + positive_ = false; + name_ = "VMRTE_"+TrackletConfigBuilder::LayerName(layerdisk)+".tab"; + } + if (type == VMRTableType::inner) { + positive_ = true; + nbits_ = 10; + name_ = "TP_"+TrackletConfigBuilder::LayerName(layerdisk) + +TrackletConfigBuilder::LayerName(layerdisk+1)+".tab"; + } + + if (type == VMRTableType::inneroverlap) { + positive_ = true; + nbits_ = 10; + name_ = "TP_"+TrackletConfigBuilder::LayerName(layerdisk) + +TrackletConfigBuilder::LayerName(N_LAYER)+".tab"; + } + + } else { + if (type == VMRTableType::me) { + //This if a hack where the same memory is used in both ME and TE modules + if (layerdisk==1||layerdisk==2||layerdisk==3||layerdisk==4) { + positive_ = false; + name_ = "VMTableOuter"+TrackletConfigBuilder::LayerName(layerdisk)+".tab"; + writeTable(); + } + + assert(region>=0); + char cregion='A'+region; + name_ = "VMR_"+TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_finebin.tab"; + positive_ = false; + } + + if (type == VMRTableType::inner) { + positive_ = false; + name_ = "VMTableInner"+TrackletConfigBuilder::LayerName(layerdisk) + +TrackletConfigBuilder::LayerName(layerdisk+1)+".tab"; + } + + if (type == VMRTableType::inneroverlap) { + positive_ = false; + name_ = "VMTableInner"+TrackletConfigBuilder::LayerName(layerdisk) + +TrackletConfigBuilder::LayerName(N_LAYER)+".tab"; + } + + if (type == VMRTableType::disk) { + positive_ = false; + name_ = "VMTableOuter"+TrackletConfigBuilder::LayerName(layerdisk)+".tab"; + } + } + + writeTable(); + +} + +int TrackletLUT::getVMRLookup(unsigned int layerdisk, double z, double r, double dz, double dr, int iseed) const { + double z0cut = settings_.z0cut(); + + if (layerdisk < N_LAYER) { + if (iseed == Seed::L2L3 && std::abs(z) < 52.0) + return -1; + + double rmean = settings_.rmean(layerdisk); + + double rratio1 = rmean / (r + 0.5 * dr); + double rratio2 = rmean / (r - 0.5 * dr); + + double z1 = (z - 0.5 * dz) * rratio1 + z0cut * (rratio1 - 1.0); + double z2 = (z + 0.5 * dz) * rratio1 + z0cut * (rratio1 - 1.0); + double z3 = (z - 0.5 * dz) * rratio2 + z0cut * (rratio2 - 1.0); + double z4 = (z + 0.5 * dz) * rratio2 + z0cut * (rratio2 - 1.0); + double z5 = (z - 0.5 * dz) * rratio1 - z0cut * (rratio1 - 1.0); + double z6 = (z + 0.5 * dz) * rratio1 - z0cut * (rratio1 - 1.0); + double z7 = (z - 0.5 * dz) * rratio2 - z0cut * (rratio2 - 1.0); + double z8 = (z + 0.5 * dz) * rratio2 - z0cut * (rratio2 - 1.0); + + double zmin = std::min({z1, z2, z3, z4, z5, z6, z7, z8}); + double zmax = std::max({z1, z2, z3, z4, z5, z6, z7, z8}); + + int NBINS = settings_.NLONGVMBINS() * settings_.NLONGVMBINS(); + + int zbin1 = NBINS * (zmin + settings_.zlength()) / (2 * settings_.zlength()); + int zbin2 = NBINS * (zmax + settings_.zlength()) / (2 * settings_.zlength()); + + if (zbin1 >= NBINS) + return -1; + if (zbin2 < 0) + return -1; + + if (zbin2 >= NBINS) + zbin2 = NBINS - 1; + if (zbin1 < 0) + zbin1 = 0; + + // This is a 10 bit word: + // xxx|yyy|z|rrr + // xxx is the delta z window + // yyy is the z bin + // z is flag to look in next bin + // rrr first fine z bin + // NOTE : this encoding is not efficient z is one if xxx+rrr is greater than 8 + // and xxx is only 1,2, or 3 + // should also reject xxx=0 as this means projection is outside range + + int value = zbin1 / 8; + value *= 2; + if (zbin2 / 8 - zbin1 / 8 > 0) + value += 1; + value *= 8; + value += (zbin1 & 7); + assert(value / 8 < 15); + int deltaz = zbin2 - zbin1; + if (deltaz > 7) { + deltaz = 7; + } + assert(deltaz < 8); + value += (deltaz << 7); + + return value; + + } else { + if (std::abs(z) < 2.0 * z0cut) + return -1; + + double zmean = settings_.zmean(layerdisk - N_LAYER); + if (z < 0.0) + zmean = -zmean; + + double r1 = (r + 0.5 * dr) * (zmean + z0cut) / (z + 0.5 * dz + z0cut); + double r2 = (r - 0.5 * dr) * (zmean - z0cut) / (z + 0.5 * dz - z0cut); + double r3 = (r + 0.5 * dr) * (zmean + z0cut) / (z - 0.5 * dz + z0cut); + double r4 = (r - 0.5 * dr) * (zmean - z0cut) / (z - 0.5 * dz - z0cut); + double r5 = (r + 0.5 * dr) * (zmean - z0cut) / (z + 0.5 * dz - z0cut); + double r6 = (r - 0.5 * dr) * (zmean + z0cut) / (z + 0.5 * dz + z0cut); + double r7 = (r + 0.5 * dr) * (zmean - z0cut) / (z - 0.5 * dz - z0cut); + double r8 = (r - 0.5 * dr) * (zmean + z0cut) / (z - 0.5 * dz + z0cut); + + double rmin = std::min({r1, r2, r3, r4, r5, r6, r7, r8}); + double rmax = std::max({r1, r2, r3, r4, r5, r6, r7, r8}); + + int NBINS = settings_.NLONGVMBINS() * settings_.NLONGVMBINS() / 2; + + double rmindisk = settings_.rmindiskvm(); + double rmaxdisk = settings_.rmaxdiskvm(); + + if (iseed == Seed::L1D1) + rmaxdisk = settings_.rmaxdiskl1overlapvm(); + if (iseed == Seed::L2D1) + rmindisk = settings_.rmindiskl2overlapvm(); + if (iseed == Seed::L2L3D1) + rmaxdisk = settings_.rmaxdisk(); + + if (rmin > rmaxdisk) + return -1; + if (rmax > rmaxdisk) + rmax = rmaxdisk; + + if (rmax < rmindisk) + return -1; + if (rmin < rmindisk) + rmin = rmindisk; + + int rbin1 = NBINS * (rmin - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm()); + int rbin2 = NBINS * (rmax - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm()); + + if (iseed == Seed::L2L3D1) { + constexpr double rminspec = 40.0; + rbin1 = NBINS * (rmin - rminspec) / (settings_.rmaxdisk() - rminspec); + rbin2 = NBINS * (rmax - rminspec) / (settings_.rmaxdisk() - rminspec); + } + + if (rbin2 >= NBINS) + rbin2 = NBINS - 1; + if (rbin1 < 0) + rbin1 = 0; + + // This is a 9 bit word: + // xxx|yy|z|rrr + // xxx is the delta r window + // yy is the r bin yy is three bits for overlaps + // z is flag to look in next bin + // rrr fine r bin + // NOTE : this encoding is not efficient z is one if xxx+rrr is greater than 8 + // and xxx is only 1,2, or 3 + // should also reject xxx=0 as this means projection is outside range + + bool overlap = iseed == Seed::L1D1 || iseed == Seed::L2D1 || iseed == Seed::L2L3D1; + + int value = rbin1 / 8; + if (overlap) { + if (z < 0.0) + value += 4; + } + value *= 2; + if (rbin2 / 8 - rbin1 / 8 > 0) + value += 1; + value *= 8; + value += (rbin1 & 7); + assert(value / 8 < 15); + int deltar = rbin2 - rbin1; + if (deltar > 7) + deltar = 7; + if (overlap) { + value += (deltar << 7); + } else { + value += (deltar << 6); + } + + return value; + } +} + + + + +void TrackletLUT::initPhiCorrTable(unsigned int layerdisk, unsigned int rbits) { + + bool psmodule = layerdisk < N_PSLAYER; + + unsigned int bendbits = psmodule ? N_BENDBITS_PS : N_BENDBITS_2S; + + unsigned int rbins = (1 << rbits); + + double rmean = settings_.rmean(layerdisk); + double drmax = settings_.drmax(); + + double dr = 2.0 * drmax / rbins; + + unsigned int bendbins = (1 << bendbits); + + for (unsigned int ibend = 0; ibend < bendbins; ibend++) { + for (unsigned int irbin = 0; irbin < rbins; irbin++) { + int value = getphiCorrValue(layerdisk, ibend, irbin, rmean, dr, drmax); + table_.push_back(value); + } + } + + name_ = "VMPhiCorrL" + std::to_string(layerdisk+1) + ".tab"; + nbits_ = 14; + positive_ = false; + + writeTable(); + +} + +int TrackletLUT::getphiCorrValue(unsigned int layerdisk, unsigned int ibend, unsigned int irbin, + double rmean, double dr, double drmax) const { + + bool psmodule = layerdisk < N_PSLAYER; + + double bend = -settings_.benddecode(ibend, layerdisk, psmodule); + + //for the rbin - calculate the distance to the nominal layer radius + double Delta = (irbin + 0.5) * dr - drmax; + + //calculate the phi correction - this is a somewhat approximate formula + double dphi = (Delta / 0.18) * bend * settings_.stripPitch(psmodule) / rmean; + + double kphi = psmodule ? settings_.kphi() : settings_.kphi1(); + + int idphi = dphi/kphi; + + return idphi; +} + + +// Write LUT table. +void TrackletLUT::writeTable() const{ + + if (!settings_.writeTable()) { + return; + } + + if (name_ == "") { + return; + } + + ofstream out = openfile(settings_.tablePath(), name_, __FILE__, __LINE__); + + out << "{" << endl; + for (unsigned int i = 0; i < table_.size(); i++) { + if (i != 0) { + out << "," << endl; + } + + int itable = table_[i]; + if (positive_) { + if (table_[i] < 0) { + itable = (1 << nbits_) - 1; + } + } + + out << itable; + } + out << endl << "};" << endl; + out.close(); +} + +int TrackletLUT::lookup(unsigned int index) const { + assert(index < table_.size()); + return table_[index]; +} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc index ee937c120033f..dad0a7060877b 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc @@ -19,7 +19,9 @@ using namespace trklet; TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Globals* globals) : TrackletCalculatorBase(name, settings, globals), tebuffer_(CircularBuffer(3), 0, 0, 0, 0), - vmrtable_(settings) { + pttableinner_(settings), pttableouter_(settings), useregiontable_(settings), + innerTable_(settings), innerOverlapTable_(settings) { + iAllStub_ = -1; for (unsigned int ilayer = 0; ilayer < N_LAYER; ilayer++) { @@ -35,19 +37,58 @@ TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Glob outervmstubs_ = nullptr; initLayerDisksandISeed(layerdisk1_, layerdisk2_, iSeed_); + + double rmin = -1.0; + double rmax = -1.0; + + if (iSeed_ == Seed::L1L2 ||iSeed_ == Seed::L2L3 ||iSeed_ == Seed::L3L4 ||iSeed_ == Seed::L5L6 ) { + rmin = settings_.rmean(layerdisk1_); + rmax = settings_.rmean(layerdisk2_); + } else { + if (iSeed_ == Seed::L1D1) { + rmax = settings_.rmaxdiskl1overlapvm(); + rmin = settings_.rmean(layerdisk1_); + } else if (iSeed_ == Seed::L2D1) { + rmax = settings_.rmaxdiskvm(); + rmin = settings_.rmean(layerdisk1_); + } else { + rmax = settings_.rmaxdiskvm(); + rmin = rmax * settings_.zmean(layerdisk2_ - N_LAYER - 1) / settings_.zmean(layerdisk2_ - N_LAYER); + } + } + + double dphimax = asin(0.5 * settings_.maxrinv() * rmax) - asin(0.5 * settings_.maxrinv() * rmin); + + //number of fine phi bins in sector + int nfinephibins = + settings_.nallstubs(layerdisk2_) * settings_.nvmte(1, iSeed_) * (1 << settings_.nfinephi(1, iSeed_)); + double dfinephi = settings_.dphisectorHG() / nfinephibins; + + nbitsfinephi_ = settings_.nbitsallstubs(layerdisk2_) + settings_.nbitsvmte(1, iSeed_) + settings_.nfinephi(1, iSeed_); + + int nbins = 2.0 * (dphimax / dfinephi + 1.0); + + nbitsfinephidiff_ = log(nbins) / log(2.0) + 1; nbitszfinebintable_ = settings_.vmrlutzbits(layerdisk1_); nbitsrfinebintable_ = settings_.vmrlutrbits(layerdisk1_); - vmrtable_.init(layerdisk1_); - nbitsrzbin_ = N_RZBITS; - if (iSeed_ == 4 || iSeed_ == 5) + if (iSeed_ == Seed::D1D2 || iSeed_ == Seed::D3D4) nbitsrzbin_ = 2; innerphibits_ = settings_.nfinephi(0, iSeed_); outerphibits_ = settings_.nfinephi(1, iSeed_); + if (layerdisk1_ == LayerDisk::L1 || layerdisk1_ == LayerDisk::L2 || layerdisk1_ == LayerDisk::L3 || layerdisk1_ == LayerDisk::L5 + || layerdisk1_ == LayerDisk::D1 || layerdisk1_ == LayerDisk::D3) { + innerTable_.initVMRTable(layerdisk1_, TrackletLUT::VMRTableType::inner); //projection to next layer/disk + } + + if (layerdisk1_ == LayerDisk::L1 || layerdisk1_ == LayerDisk::L2 ) { + innerOverlapTable_.initVMRTable(layerdisk1_, TrackletLUT::VMRTableType::inneroverlap); //projection to disk from layer + } + // set TC index iTC_ = name_[7] - 'A'; assert(iTC_ >= 0 && iTC_ < 14); @@ -116,9 +157,9 @@ void TrackletProcessor::addInput(MemoryBase* memory, string input) { assert(tmp != nullptr); outervmstubs_ = tmp; iAllStub_ = tmp->getName()[11] - 'A'; - if (iSeed_ == 1) + if (iSeed_ == Seed::L2L3) iAllStub_ = tmp->getName()[11] - 'I'; - if (iSeed_ == 6 || iSeed_ == 7) { + if (iSeed_ == Seed::L1D1 || iSeed_ == Seed::L2D1) { if (tmp->getName()[11] == 'X') iAllStub_ = 0; if (tmp->getName()[11] == 'Y') @@ -128,8 +169,17 @@ void TrackletProcessor::addInput(MemoryBase* memory, string input) { if (tmp->getName()[11] == 'W') iAllStub_ = 3; } - buildLUT(); //need iAllStub_ set before building the table //FIXME should be in initiall + unsigned int iTP = getName()[7]-'A'; + + pttableinner_.initTPlut(true, iSeed_, layerdisk1_, layerdisk2_, nbitsfinephidiff_, iTP); + pttableouter_.initTPlut(false, iSeed_, layerdisk1_, layerdisk2_, nbitsfinephidiff_, iTP); + + //need iAllStub_ set before building the table + + useregiontable_.initTPregionlut(iSeed_, layerdisk1_, layerdisk2_, iAllStub_, + nbitsfinephidiff_, nbitsfinephi_, pttableinner_, iTP); + TrackletEngineUnit teunit(&settings_, nbitsfinephi_, layerdisk1_, @@ -137,8 +187,8 @@ void TrackletProcessor::addInput(MemoryBase* memory, string input) { iSeed_, nbitsfinephidiff_, iAllStub_, - pttableinnernew_, - pttableouternew_, + pttableinner_, + pttableouter_, outervmstubs_); teunits_.resize(settings_.teunits(iSeed_), teunit); @@ -222,6 +272,9 @@ void TrackletProcessor::execute(unsigned int iSector, double phimin, double phim bool tebuffernearfull; for (unsigned int istep = 0; istep < maxStep_; istep++) { + + // These print statements are not on by defaul but can be enabled for the + // comparison with HLS code to track differences. if (print) { CircularBuffer& tedatabuffer = std::get<0>(tebuffer_); unsigned int& istub = std::get<1>(tebuffer_); @@ -278,11 +331,9 @@ void TrackletProcessor::execute(unsigned int iSector, double phimin, double phim bool accept = false; - if (iSeed_ < 4) { - if (print) - cout << "istep=" << istep << " TEUnit read iTE=" << iTE << endl; + if (iSeed_ == Seed::L1L2 || iSeed_ == Seed::L2L3 || iSeed_ == Seed::L3L4 || iSeed_ == Seed::L5L6 ) { accept = barrelSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); - } else if (iSeed_ < 6) { + } else if ( iSeed_ == Seed::D1D2 || iSeed_ == Seed::D3D4 ) { accept = diskSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); } else { accept = overlapSeeding(outerFPGAStub, outerStub, innerFPGAStub, innerStub); @@ -315,9 +366,6 @@ void TrackletProcessor::execute(unsigned int iSector, double phimin, double phim if (teunit.idle()) { if (notemptytebuffer) { teunit.init(std::get<0>(tebuffer_).read()); - if (print) - std::cout << "istep=" << istep << " TEUnit init iTE inner : " << ite << " " - << teunit.innerStub()->allStubIndex().value() << std::endl; notemptytebuffer = false; //prevent initialzing another TE unit } } @@ -367,9 +415,9 @@ void TrackletProcessor::execute(unsigned int iSector, double phimin, double phim int lutval = -1; if (iSeed_ < 6) { //FIXME should only be one table - but will need coordination with HLS code. - lutval = vmrtable_.lookupinner(indexz, indexr); + lutval = innerTable_.lookup((indexz<= 4) { + if ( iSeed_ == Seed::D1D2 || iSeed_ == Seed::D3D4 || iSeed_ == Seed::L1D1 || iSeed_ == Seed::L2D1 ) { //FIXME If the lookupbits were rationally organized this would be much simpler unsigned int nrbits = 3; int ir = ((start & ((1 << (nrbits - 1)) - 1)) << 1) + (rzfinebinfirst >> (NFINERZBITS - 1)); useregindex = (useregindex << nrbits) + ir; } - assert(useregindex < useregion_.size()); - unsigned int usereg = useregion_[useregindex]; - + unsigned int usereg = useregiontable_.lookup(useregindex); + tedata.regions_.clear(); tedata.stub_ = stub; tedata.rzbinfirst_ = rzfinebinfirst; @@ -423,10 +470,6 @@ void TrackletProcessor::execute(unsigned int iSector, double phimin, double phim assert(ireg * nbins + ibin < outervmstubs_->nBin()); int nstubs = outervmstubs_->nVMStubsBinned(ireg * nbins + ibin); - if (print) - cout << "Add to TEBuffer stub ibin ireg nstubs: " << stub->allStubIndex().value() << " " << ibin << " " - << ireg << " " << nstubs << endl; - if (nstubs > 0) { mask = "1" + mask; tedata.regions_.emplace_back(tuple(ibin - start, ireg, nstubs)); @@ -496,208 +539,3 @@ void TrackletProcessor::execute(unsigned int iSector, double phimin, double phim } } -void TrackletProcessor::buildLUT() { - //number of fine phi bins in sector - int nfinephibins = - settings_.nallstubs(layerdisk2_) * settings_.nvmte(1, iSeed_) * (1 << settings_.nfinephi(1, iSeed_)); - double dfinephi = settings_.dphisectorHG() / nfinephibins; - - double rmin = -1.0; - double rmax = -1.0; - - if (iSeed_ < 4) { - rmin = settings_.rmean(layerdisk1_); - rmax = settings_.rmean(layerdisk2_); - } else { - if (iSeed_ > 5) { - if (iSeed_ == 6) { - rmax = settings_.rmaxdiskl1overlapvm(); - } - if (iSeed_ == 7) { - rmax = settings_.rmaxdiskvm(); - } - rmin = settings_.rmean(layerdisk1_); - } else { - rmax = settings_.rmaxdiskvm(); - rmin = rmax * settings_.zmean(layerdisk2_ - 6 - 1) / settings_.zmean(layerdisk2_ - 6); - } - } - - double dphimax = asin(0.5 * settings_.maxrinv() * rmax) - asin(0.5 * settings_.maxrinv() * rmin); - - int nbins = 2.0 * (dphimax / dfinephi + 1.0); - - nbitsfinephidiff_ = log(nbins) / log(2.0) + 1; - - nbitsfinephi_ = settings_.nbitsallstubs(layerdisk2_) + settings_.nbitsvmte(1, iSeed_) + settings_.nfinephi(1, iSeed_); - - int outerrbits = 3; - if (iSeed_ < 4) { - outerrbits = 0; - } - - int outerrbins = (1 << outerrbits); - - double dphi[2]; - double router[2]; - - unsigned int nbendbitsinner = 3; - unsigned int nbendbitsouter = 3; - if (iSeed_ == 2) { - nbendbitsouter = 4; - } else if (iSeed_ == 3) { - nbendbitsinner = 4; - nbendbitsouter = 4; - } - - int nbinsfinephidiff = (1 << nbitsfinephidiff_); - - for (int iphibin = 0; iphibin < nbinsfinephidiff; iphibin++) { - int iphidiff = iphibin; - if (iphibin >= nbinsfinephidiff / 2) { - iphidiff = iphibin - nbinsfinephidiff; - } - //min and max dphi - dphi[0] = (iphidiff - 1.5) * dfinephi; - dphi[1] = (iphidiff + 1.5) * dfinephi; - for (int irouterbin = 0; irouterbin < outerrbins; irouterbin++) { - if (iSeed_ >= 4) { - router[0] = - settings_.rmindiskvm() + irouterbin * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins; - router[1] = - settings_.rmindiskvm() + (irouterbin + 1) * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins; - } else { - router[0] = settings_.rmean(layerdisk2_); - router[1] = settings_.rmean(layerdisk2_); - } - - double bendinnermin = 20.0; - double bendinnermax = -20.0; - double bendoutermin = 20.0; - double bendoutermax = -20.0; - double rinvmin = 1.0; - for (int i2 = 0; i2 < 2; i2++) { - for (int i3 = 0; i3 < 2; i3++) { - double rinner = 0.0; - if (iSeed_ == 4 || iSeed_ == 5) { - rinner = router[i3] * settings_.zmean(layerdisk1_ - N_LAYER) / settings_.zmean(layerdisk2_ - N_LAYER); - } else { - rinner = settings_.rmean(layerdisk1_); - } - double rinv1 = rinv(0.0, -dphi[i2], rinner, router[i3]); - double pitchinner = (rinner < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); - double pitchouter = - (router[i3] < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); - double abendinner = bendstrip(rinner, rinv1, pitchinner); - double abendouter = bendstrip(router[i3], rinv1, pitchouter); - if (abendinner < bendinnermin) - bendinnermin = abendinner; - if (abendinner > bendinnermax) - bendinnermax = abendinner; - if (abendouter < bendoutermin) - bendoutermin = abendouter; - if (abendouter > bendoutermax) - bendoutermax = abendouter; - if (std::abs(rinv1) < rinvmin) { - rinvmin = std::abs(rinv1); - } - } - } - - bool passptcut = rinvmin < settings_.rinvcutte(); - - for (int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) { - double bend = settings_.benddecode(ibend, layerdisk1_, nbendbitsinner == 3); - - bool passinner = bend <= bendinnermax + settings_.bendcutte(ibend, layerdisk1_, nbendbitsinner == 3) && - bend >= bendinnermin - settings_.bendcutte(ibend, layerdisk1_, nbendbitsinner == 3); - pttableinnernew_.push_back(passinner && passptcut); - } - - for (int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) { - double bend = settings_.benddecode(ibend, layerdisk2_, nbendbitsouter == 3); - - bool passouter = bend <= bendoutermax + settings_.bendcutte(ibend, layerdisk2_, nbendbitsouter == 3) && - bend >= bendoutermin - settings_.bendcutte(ibend, layerdisk2_, nbendbitsouter == 3); - pttableouternew_.push_back(passouter && passptcut); - } - } - } - - int nirbits = 0; - if (iSeed_ >= 4) - nirbits = 3; - - int nregmax = 0; - - for (int innerfinephi = 0; innerfinephi < (1 << nbitsfinephi_); innerfinephi++) { - for (int innerbend = 0; innerbend < (1 << nbendbitsinner); innerbend++) { - for (int ir = 0; ir < (1 << nirbits); ir++) { - int nreg = 0; - unsigned int usereg = 0; - for (unsigned int ireg = 0; ireg < settings_.nvmte(1, iSeed_); ireg++) { - bool match = false; - for (int ifinephiouter = 0; ifinephiouter < (1 << settings_.nfinephi(1, iSeed_)); ifinephiouter++) { - int outerfinephi = iAllStub_ * (1 << (nbitsfinephi_ - settings_.nbitsallstubs(layerdisk2_))) + - ireg * (1 << settings_.nfinephi(1, iSeed_)) + ifinephiouter; - int idphi = outerfinephi - innerfinephi; - bool inrange = (idphi < (1 << (nbitsfinephidiff_ - 1))) && (idphi >= -(1 << (nbitsfinephidiff_ - 1))); - if (idphi < 0) - idphi = idphi + (1 << nbitsfinephidiff_); - int idphi1 = idphi; - if (iSeed_ >= 4) - idphi1 = (idphi << 3) + ir; - int ptinnerindexnew = (idphi1 << nbendbitsinner) + innerbend; - match = match || (inrange && pttableinnernew_[ptinnerindexnew]); - } - if (match && ir < 3) - nreg++; - if (match) { - usereg = usereg | (1 << ireg); - } - } - - useregion_.push_back(usereg); - if (nreg > nregmax) - nregmax = nreg; - } - } - } - - if (settings_.writeTable()) { - ofstream out; - out.open(settings_.tablePath() + getName() + "_usereg.tab"); - - out << "{" << endl; - for (unsigned int i = 0; i < useregion_.size(); i++) { - if (i != 0) { - out << "," << endl; - } - out << useregion_[i]; - } - out << endl << "};" << endl; - out.close(); - - ofstream outstubptinnercut; - outstubptinnercut.open(settings_.tablePath() + getName() + "_stubptinnercut.tab"); - outstubptinnercut << "{" << endl; - for (unsigned int i = 0; i < pttableinnernew_.size(); i++) { - if (i != 0) - outstubptinnercut << "," << endl; - outstubptinnercut << pttableinnernew_[i]; - } - outstubptinnercut << endl << "};" << endl; - outstubptinnercut.close(); - - ofstream outstubptoutercut; - outstubptoutercut.open(settings_.tablePath() + getName() + "_stubptoutercut.tab"); - outstubptoutercut << "{" << endl; - for (unsigned int i = 0; i < pttableouternew_.size(); i++) { - if (i != 0) - outstubptoutercut << "," << endl; - outstubptoutercut << pttableouternew_[i]; - } - outstubptoutercut << endl << "};" << endl; - outstubptoutercut.close(); - } -} diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc index a64d06c28fb36..37ca217a0e92e 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc @@ -14,15 +14,37 @@ using namespace std; using namespace trklet; VMRouter::VMRouter(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global), vmrtable_(settings) { + : ProcessBase(name, settings, global), meTable_(settings), diskTable_(settings), + innerTable_(settings), innerOverlapTable_(settings), innerThirdTable_(settings) { + layerdisk_ = initLayerDisk(4); vmstubsMEPHI_.resize(settings_.nvmme(layerdisk_), nullptr); + unsigned int region = name[9]-'A'; + assert(region < settings_.nallstubs(layerdisk_)); + overlapbits_ = 7; nextrabits_ = overlapbits_ - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_)); - vmrtable_.init(layerdisk_, name); + meTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::me, region); //used for ME and outer TE barrel + + if (layerdisk_==LayerDisk::D1 || layerdisk_==LayerDisk::D2 || layerdisk_==D4) { + diskTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::disk, region); //outer disk used by D1, D2, and D4 + } + + if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L5 || + layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) { + innerTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::inner, region); //projection to next layer/disk + } + + if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L2 ) { + innerOverlapTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::inneroverlap, region); //projection to disk from layer + } + + if (layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L5 || layerdisk_ == LayerDisk::D1 ) { + innerThirdTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::innerthird, region); //projection to third layer/disk + } nbitszfinebintable_ = settings_.vmrlutzbits(layerdisk_); nbitsrfinebintable_ = settings_.vmrlutrbits(layerdisk_); @@ -60,40 +82,41 @@ void VMRouter::addOutput(MemoryBase* memory, string output) { VMStubsTEMemory* tmp = dynamic_cast(memory); assert(tmp != nullptr); if (seedtype < 'I') { - if (layerdisk_ == 0 || layerdisk_ == 1) - iseed = 0; - if (layerdisk_ == 2 || layerdisk_ == 3) - iseed = 2; - if (layerdisk_ == 4 || layerdisk_ == 5) - iseed = 3; - if (layerdisk_ == 6 || layerdisk_ == 7) - iseed = 4; - if (layerdisk_ == 8 || layerdisk_ == 9) - iseed = 5; - if (layerdisk_ == 0 || layerdisk_ == 2 || layerdisk_ == 4 || layerdisk_ == 6 || layerdisk_ == 8) + if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L2) + iseed = Seed::L1L2; + if (layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L4) + iseed = Seed::L3L4; + if (layerdisk_ == LayerDisk::L5 || layerdisk_ == LayerDisk::L6) + iseed = Seed::L5L6; + if (layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D2) + iseed = Seed::D1D2; + if (layerdisk_ == LayerDisk::D3 || layerdisk_ == LayerDisk::D4) + iseed = Seed::D3D4; + if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L5 || + layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) inner = 0; } else if (seedtype < 'M') { - if (layerdisk_ == 1 || layerdisk_ == 2) - iseed = 1; - if (layerdisk_ == 1) + if (layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3) + iseed = Seed::L2L3; + if (layerdisk_ == LayerDisk::L2) inner = 0; } else if (seedtype <= 'Z') { - if (layerdisk_ == 0 || layerdisk_ == 6) - iseed = 6; - if (layerdisk_ == 1 || layerdisk_ == 6) - iseed = 7; - if (layerdisk_ == 0 || layerdisk_ == 1) + if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::D1) + iseed = Seed::L1D1; + if (layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::D1) + iseed = Seed::L2D1; + if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L2) inner = 0; } else if (seedtype < 'o' && seedtype >= 'a') { - if (layerdisk_ == 1 || layerdisk_ == 2) - iseed = 10; - if (layerdisk_ == 1) + if (layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3) + iseed = Seed::L2L3D1; + if (layerdisk_ == LayerDisk::L1) inner = 0; } else if (seedtype > 'o' && seedtype <= 'z') { - if (layerdisk_ == 1) - iseed = 11; - if (layerdisk_ == 6) - iseed = 10; + if (layerdisk_ == LayerDisk::L2) + iseed = Seed::D1D2L2; + if (layerdisk_ == LayerDisk::D1) + iseed = Seed::L2L3D1; inner = 2; } else { throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!"; @@ -224,8 +247,7 @@ void VMRouter::execute() { assert(indexz < (1 << nbitszfinebintable_)); assert(indexr < (1 << nbitsrfinebintable_)); - int melut = vmrtable_.lookup(indexz, indexr); - + int melut = meTable_.lookup((indexz<= 0); int vmbin = melut >> 3; @@ -289,21 +311,21 @@ void VMRouter::execute() { } } } else { - lutval = vmrtable_.lookupdisk(indexz, indexr); + lutval = diskTable_.lookup((indexz< 7) { - lutval = vmrtable_.lookupinner(indexz, indexr); + lutval = innerTable_.lookup((indexz<= 6) ? 2 : 1); //number of long z/r bins in VM + nvmmebins_ = settings_.NLONGVMBINS() * ((layerdisk_ >= N_LAYER) ? 2 : 1); //number of long z/r bins in VM } void VMRouterCM::addOutput(MemoryBase* memory, string output) { @@ -63,13 +71,12 @@ void VMRouterCM::addOutput(MemoryBase* memory, string output) { } if (memory->getName().substr(3, 2) == "TE") { VMStubsTEMemory* tmp = dynamic_cast(memory); - int iseed = output[output.size() - 1] - '0'; - assert(iseed >= 0); - assert(iseed < 8); + unsigned int iseed = output[output.size() - 1] - '0'; + assert(iseed < N_SEED_PROMPT); int seedindex = -1; for (unsigned int k = 0; k < vmstubsTEPHI_.size(); k++) { - if (vmstubsTEPHI_[k].seednumber == (unsigned int)iseed) { + if (vmstubsTEPHI_[k].seednumber == iseed) { seedindex = k; } } @@ -123,7 +130,7 @@ void VMRouterCM::execute() { for (unsigned int i = 0; i < stubinput->nStubs(); i++) { if (allStubCounter > settings_.maxStep("VMR")) continue; - if (allStubCounter > 127) + if (allStubCounter >= (1<getStub(i); @@ -134,7 +141,7 @@ void VMRouterCM::execute() { //use &127 to make sure we fit into the number of bits - //though we should have protected against overflows above - FPGAWord allStubIndex(allStubCounter & 127, 7, true, __LINE__, __FILE__); + FPGAWord allStubIndex(allStubCounter & ((1<setAllStubIndex(allStubCounter); @@ -151,7 +158,7 @@ void VMRouterCM::execute() { } FPGAWord iphi = stub->phicorr(); - unsigned int iphipos = iphi.bits(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + 3), 3); + unsigned int iphipos = iphi.bits(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + N_PHIBITS), N_PHIBITS); unsigned int phicutmax = 4; unsigned int phicutmin = 4; @@ -182,15 +189,15 @@ void VMRouterCM::execute() { continue; int absz = std::abs(stub->z().value()); - if (layerdisk_ == 1 && absz < VMROUTERCUTZL2 / settings_.kz(layerdisk_)) + if (layerdisk_ == LayerDisk::L2 && absz < VMROUTERCUTZL2 / settings_.kz(layerdisk_)) continue; - if ((layerdisk_ == 2 || layerdisk_ == 4) && absz > VMROUTERCUTZL1L3L5 / settings_.kz(layerdisk_)) + if ((layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L5) && absz > VMROUTERCUTZL1L3L5 / settings_.kz(layerdisk_)) continue; - if ((layerdisk_ == 6 || layerdisk_ == 8) && stub->r().value() > VMROUTERCUTRD1D3 / settings_.kr()) + if ((layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) && stub->r().value() > VMROUTERCUTRD1D3 / settings_.kr()) continue; - if ((layerdisk_ == 6 || layerdisk_ == 8) && stub->r().value() < 2 * int(N_DSS_MOD)) + if ((layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) && stub->r().value() < 2 * int(N_DSS_MOD)) continue; - if (layerdisk_ == 0) { + if (layerdisk_ == LayerDisk::L1) { if (memtype == 'M' || memtype == 'R' || memtype == 'L') { if (absz < VMROUTERCUTZL1 / settings_.kz(layerdisk_)) continue; @@ -235,8 +242,8 @@ void VMRouterCM::execute() { assert(indexz < (1 << nbitszfinebintable_)); assert(indexr < (1 << nbitsrfinebintable_)); - int melut = vmrtable_.lookup(indexz, indexr); - + int melut = meTable_.lookup((indexz<= 0); int vmbin = melut >> NFINERZBITS; @@ -261,7 +268,7 @@ void VMRouterCM::execute() { vmstubsMEPHI_[0]->addStub(vmstub, ivm * nvmmebins_ + vmbin); //Fill the TE VM memories - if (layerdisk_ >= 6 && (!stub->isPSmodule())) + if (layerdisk_ >= N_LAYER && (!stub->isPSmodule())) continue; for (auto& ivmstubTEPHI : vmstubsTEPHI_) { @@ -273,7 +280,7 @@ void VMRouterCM::execute() { if (layerdisk_ < N_LAYER) { lutval = melut; } else { - lutval = vmrtable_.lookupdisk(indexz, indexr); + lutval = diskTable_.lookup((indexz< - -using namespace std; -using namespace trklet; - -VMRouterPhiCorrTable::VMRouterPhiCorrTable(Settings const& settings) : TETableBase(settings) { nbits_ = 14; } - -void VMRouterPhiCorrTable::init(int layer, int bendbits, int rbits) { - assert(bendbits == 3 || bendbits == 4); - - layer_ = layer; - bendbits_ = bendbits; - rbits_ = rbits; - - rbins_ = (1 << rbits); - rmin_ = settings_.rmean(layer - 1) - settings_.drmax(); - rmax_ = settings_.rmean(layer - 1) + settings_.drmax(); - dr_ = 2 * settings_.drmax() / rbins_; - - bendbins_ = (1 << bendbits); - - rmean_ = settings_.rmean(layer - 1); - - for (int ibend = 0; ibend < bendbins_; ibend++) { - for (int irbin = 0; irbin < rbins_; irbin++) { - int value = getphiCorrValue(ibend, irbin); - table_.push_back(value); - } - } - - if (settings_.writeTable()) { - writeVMTable(settings_.tablePath(), "VMPhiCorrL" + std::to_string(layer_) + ".tab", false); - } -} - -int VMRouterPhiCorrTable::getphiCorrValue(int ibend, int irbin) const { - assert(layer_ > 0.0 && layer_ <= (int)N_LAYER); - double bend = -settings_.benddecode(ibend, layer_ - 1, layer_ <= (int)N_PSLAYER); - - //for the rbin - calculate the distance to the nominal layer radius - double Delta = (irbin + 0.5) * dr_ - settings_.drmax(); - - //calculate the phi correction - this is a somewhat approximate formula - double dphi = (Delta / 0.18) * (bend * settings_.stripPitch(layer_ <= (int)N_PSLAYER)) / rmean_; - - int idphi = 0; - - if (layer_ <= (int)N_PSLAYER) { - idphi = dphi / settings_.kphi(); - } else { - idphi = dphi / settings_.kphi1(); - } - - return idphi; -} - -int VMRouterPhiCorrTable::lookupPhiCorr(int ibend, int rbin) { - int index = ibend * rbins_ + rbin; - assert(index < (int)table_.size()); - return table_[index]; -} diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc b/L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc deleted file mode 100644 index 1853a01f71f6b..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc +++ /dev/null @@ -1,390 +0,0 @@ -// VMRouterTable: Lookup table used by the VMRouter to route stubs and provide information about which VMStubs are needed by the TrackletEngine -#include "L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" -#include "L1Trigger/TrackFindingTracklet/interface/Util.h" -#include -#include - -using namespace std; -using namespace trklet; - -VMRouterTable::VMRouterTable(Settings const& settings) : settings_(settings) {} - -VMRouterTable::VMRouterTable(Settings const& settings, unsigned int layerdisk, std::string const& name) - : settings_(settings) { - init(layerdisk, name); -} - -void VMRouterTable::init(unsigned int layerdisk, std::string const& name) { - zbits_ = settings_.vmrlutzbits(layerdisk); - rbits_ = settings_.vmrlutrbits(layerdisk); - - rbins_ = (1 << rbits_); - zbins_ = (1 << zbits_); - - if (layerdisk < N_LAYER) { - zmin_ = -settings_.zlength(); - zmax_ = settings_.zlength(); - rmin_ = settings_.rmean(layerdisk) - settings_.drmax(); - rmax_ = settings_.rmean(layerdisk) + settings_.drmax(); - } else { - rmin_ = 0; - rmax_ = settings_.rmaxdisk(); - zmin_ = settings_.zmean(layerdisk - N_LAYER) - settings_.dzmax(); - zmax_ = settings_.zmean(layerdisk - N_LAYER) + settings_.dzmax(); - } - - dr_ = (rmax_ - rmin_) / rbins_; - dz_ = (zmax_ - zmin_) / zbins_; - - int NBINS = settings_.NLONGVMBINS() * settings_.NLONGVMBINS(); - - for (int izbin = 0; izbin < zbins_; izbin++) { - for (int irbin = 0; irbin < rbins_; irbin++) { - double r = rmin_ + (irbin + 0.5) * dr_; - double z = zmin_ + (izbin + 0.5) * dz_; - - if (settings_.combined()) { - int iznew = izbin - (1 << (zbits_ - 1)); - if (iznew < 0) - iznew += (1 << zbits_); - assert(iznew >= 0); - assert(iznew < (1 << zbits_)); - z = zmin_ + (iznew + 0.5) * dz_; - if (layerdisk < N_LAYER) { - int irnew = irbin - (1 << (rbits_ - 1)); - if (irnew < 0) - irnew += (1 << rbits_); - assert(irnew >= 0); - assert(irnew < (1 << rbits_)); - r = rmin_ + (irnew + 0.5) * dr_; - } - } - - if (layerdisk > (N_LAYER - 1) && irbin < 10) //special case for the tabulated radii in 2S disks - r = (layerdisk <= 7) ? settings_.rDSSinner(irbin) : settings_.rDSSouter(irbin); - - int bin; - if (layerdisk < N_LAYER) { - double zproj = z * settings_.rmean(layerdisk) / r; - bin = NBINS * (zproj + settings_.zlength()) / (2 * settings_.zlength()); - } else { - double rproj = r * settings_.zmean(layerdisk - N_LAYER) / z; - bin = NBINS * (rproj - settings_.rmindiskvm()) / (settings_.rmaxdisk() - settings_.rmindiskvm()); - } - if (bin < 0) - bin = 0; - if (bin >= NBINS) - bin = NBINS - 1; - vmrtable_.push_back(bin); - - if (layerdisk >= N_LAYER) { - double rproj = r * settings_.zmean(layerdisk - N_LAYER) / z; - bin = 0.5 * NBINS * (rproj - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm()); - //bin value of zero indicates that stub is out of range - if (bin < 0) - bin = 0; - if (bin >= NBINS / 2) - bin = 0; - vmrtabletedisk_.push_back(bin); - } - - if (layerdisk == 0 || layerdisk == 2 || layerdisk == 4 || layerdisk == 6 || layerdisk == 8) { - vmrtableteinner_.push_back(getLookup(layerdisk + 1, z, r)); - } - - if (layerdisk == 1) { - vmrtableteinner_.push_back(getLookup(layerdisk + 1, z, r, 1)); - } - - if (layerdisk == 1) { //projection from L2 to D1 for L2L3D1 seeding - vmrtableteinnerThird_.push_back(getLookup(6, z, r, 10)); - } - - if (layerdisk == 4) { //projection from L5 to L4 for L5L6L4 seeding - vmrtableteinnerThird_.push_back(getLookup(3, z, r)); - } - - if (layerdisk == 2) { //projection from L3 to L5 for L3L4L2 seeding - vmrtableteinnerThird_.push_back(getLookup(1, z, r)); - } - - if (layerdisk == 6) { //projection from D1 to L2 for D1D2L2 seeding - vmrtableteinnerThird_.push_back(getLookup(1, z, r)); - } - - if (layerdisk == 0 || layerdisk == 1) { - vmrtableteinneroverlap_.push_back(getLookup(6, z, r, layerdisk + 6)); - } - } - } - - if (settings_.writeTable()) { - if (!settings_.combined()) { - // write finebin tables - writeVMTable(settings_.tablePath(), name + "_finebin.tab", vmrtable_); - // write barrel seed teinner tables (L1L2, L2L3, L3L4, L5L6) - if (layerdisk == 0 || layerdisk == 1 || layerdisk == 2 || layerdisk == 4) { - std::string fnamesuffix = "L" + to_string(layerdisk + 1) + "L" + std::to_string(layerdisk + 2); - writeVMTable(settings_.tablePath(), "VMTableInner" + fnamesuffix + ".tab", vmrtableteinner_); - } - // write disk seed teinner tables (D1D2, D3D4) - if (layerdisk == 6 || layerdisk == 8) { - std::string fnamesuffix = "D" + to_string(layerdisk - N_LAYER + 1) + "D" + to_string(layerdisk - N_LAYER + 2); - writeVMTable(settings_.tablePath(), "VMTableInner" + fnamesuffix + ".tab", vmrtableteinner_); - } - // write overlap seed teinner tables (L1D1, L2D1) - if (layerdisk == 0 || layerdisk == 1) { - std::string fnamesuffix = "L" + to_string(layerdisk + 1) + "D1"; - writeVMTable(settings_.tablePath(), "VMTableInner" + fnamesuffix + ".tab", vmrtableteinneroverlap_); - } - // write barrel teouter tables (L2, L3, L4, L6, same as finebin tables) - if (layerdisk == 1 || layerdisk == 2 || layerdisk == 3 || layerdisk == 5) { - std::string fnamesuffix = "L" + to_string(layerdisk + 1); - writeVMTable(settings_.tablePath(), "VMTableOuter" + fnamesuffix + ".tab", vmrtable_); - } - // write disk teouter tables (D1, D2, D4) - if (layerdisk == 6 || layerdisk == 7 || layerdisk == 9) { - std::string fnamesuffix = "D" + to_string(layerdisk - N_LAYER + 1); - writeVMTable(settings_.tablePath(), "VMTableOuter" + fnamesuffix + ".tab", vmrtabletedisk_); - } - } else { - std::string fname = "VMRME_"; - if (layerdisk < 6) { - fname += "L" + std::to_string(layerdisk + 1) + ".tab"; - } else { - fname += "D" + std::to_string(layerdisk - 5) + ".tab"; - } - writeVMTable(settings_.tablePath(), fname, vmrtable_); - - if (layerdisk == 6 || layerdisk == 7 || layerdisk == 9) { - std::string fname = "VMRTE_D" + to_string(layerdisk - N_LAYER + 1) + ".tab"; - writeVMTable(settings_.tablePath(), fname, vmrtabletedisk_); - } - - if (vmrtableteinner_.size() > 0) { - ofstream out; - if (layerdisk < 6) { - out.open(settings_.tablePath() + "TP_L" + std::to_string(layerdisk + 1) + ".tab"); - } else { - out.open(settings_.tablePath() + "TP_D" + std::to_string(layerdisk - 5) + ".tab"); - } - out << "{" << endl; - for (unsigned int i = 0; i < vmrtableteinner_.size(); i++) { - if (i != 0) { - out << "," << endl; - } - if (vmrtableteinner_[i] == -1) { - out << 1023; - } else { - out << vmrtableteinner_[i]; - } - } - out << endl << "};" << endl; - out.close(); - } - } - } -} - -int VMRouterTable::getLookup(unsigned int layerdisk, double z, double r, int iseed) { - double z0cut = settings_.z0cut(); - - if (layerdisk < N_LAYER) { - if (iseed == 1 && std::abs(z) < 52.0) - return -1; - - double rmean = settings_.rmean(layerdisk); - - double rratio1 = rmean / (r + 0.5 * dr_); - double rratio2 = rmean / (r - 0.5 * dr_); - - double z1 = (z - 0.5 * dz_) * rratio1 + z0cut * (rratio1 - 1.0); - double z2 = (z + 0.5 * dz_) * rratio1 + z0cut * (rratio1 - 1.0); - double z3 = (z - 0.5 * dz_) * rratio2 + z0cut * (rratio2 - 1.0); - double z4 = (z + 0.5 * dz_) * rratio2 + z0cut * (rratio2 - 1.0); - double z5 = (z - 0.5 * dz_) * rratio1 - z0cut * (rratio1 - 1.0); - double z6 = (z + 0.5 * dz_) * rratio1 - z0cut * (rratio1 - 1.0); - double z7 = (z - 0.5 * dz_) * rratio2 - z0cut * (rratio2 - 1.0); - double z8 = (z + 0.5 * dz_) * rratio2 - z0cut * (rratio2 - 1.0); - - double zmin = std::min({z1, z2, z3, z4, z5, z6, z7, z8}); - double zmax = std::max({z1, z2, z3, z4, z5, z6, z7, z8}); - - int NBINS = settings_.NLONGVMBINS() * settings_.NLONGVMBINS(); - - int zbin1 = NBINS * (zmin + settings_.zlength()) / (2 * settings_.zlength()); - int zbin2 = NBINS * (zmax + settings_.zlength()) / (2 * settings_.zlength()); - - if (zbin1 >= NBINS) - return -1; - if (zbin2 < 0) - return -1; - - if (zbin2 >= NBINS) - zbin2 = NBINS - 1; - if (zbin1 < 0) - zbin1 = 0; - - // This is a 10 bit word: - // xxx|yyy|z|rrr - // xxx is the delta z window - // yyy is the z bin - // z is flag to look in next bin - // rrr first fine z bin - // NOTE : this encoding is not efficient z is one if xxx+rrr is greater than 8 - // and xxx is only 1,2, or 3 - // should also reject xxx=0 as this means projection is outside range - - int value = zbin1 / 8; - value *= 2; - if (zbin2 / 8 - zbin1 / 8 > 0) - value += 1; - value *= 8; - value += (zbin1 & 7); - assert(value / 8 < 15); - int deltaz = zbin2 - zbin1; - if (deltaz > 7) { - deltaz = 7; - } - assert(deltaz < 8); - value += (deltaz << 7); - - return value; - - } else { - if (std::abs(z) < 2.0 * z0cut) - return -1; - - double zmean = settings_.zmean(layerdisk - N_LAYER); - if (z < 0.0) - zmean = -zmean; - - double r1 = (r + 0.5 * dr_) * (zmean + z0cut) / (z + 0.5 * dz_ + z0cut); - double r2 = (r - 0.5 * dr_) * (zmean - z0cut) / (z + 0.5 * dz_ - z0cut); - double r3 = (r + 0.5 * dr_) * (zmean + z0cut) / (z - 0.5 * dz_ + z0cut); - double r4 = (r - 0.5 * dr_) * (zmean - z0cut) / (z - 0.5 * dz_ - z0cut); - double r5 = (r + 0.5 * dr_) * (zmean - z0cut) / (z + 0.5 * dz_ - z0cut); - double r6 = (r - 0.5 * dr_) * (zmean + z0cut) / (z + 0.5 * dz_ + z0cut); - double r7 = (r + 0.5 * dr_) * (zmean - z0cut) / (z - 0.5 * dz_ - z0cut); - double r8 = (r - 0.5 * dr_) * (zmean + z0cut) / (z - 0.5 * dz_ + z0cut); - - double rmin = std::min({r1, r2, r3, r4, r5, r6, r7, r8}); - double rmax = std::max({r1, r2, r3, r4, r5, r6, r7, r8}); - - int NBINS = settings_.NLONGVMBINS() * settings_.NLONGVMBINS() / 2; - - double rmindisk = settings_.rmindiskvm(); - double rmaxdisk = settings_.rmaxdiskvm(); - - if (iseed == 6) - rmaxdisk = settings_.rmaxdiskl1overlapvm(); - if (iseed == 7) - rmindisk = settings_.rmindiskl2overlapvm(); - if (iseed == 10) - rmaxdisk = settings_.rmaxdisk(); - - if (rmin > rmaxdisk) - return -1; - if (rmax > rmaxdisk) - rmax = rmaxdisk; - - if (rmax < rmindisk) - return -1; - if (rmin < rmindisk) - rmin = rmindisk; - - int rbin1 = NBINS * (rmin - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm()); - int rbin2 = NBINS * (rmax - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm()); - - if (iseed == 10) { - constexpr double rminspec = 40.0; - rbin1 = NBINS * (rmin - rminspec) / (settings_.rmaxdisk() - rminspec); - rbin2 = NBINS * (rmax - rminspec) / (settings_.rmaxdisk() - rminspec); - } - - if (rbin2 >= NBINS) - rbin2 = NBINS - 1; - if (rbin1 < 0) - rbin1 = 0; - - // This is a 9 bit word: - // xxx|yy|z|rrr - // xxx is the delta r window - // yy is the r bin yy is three bits for overlaps - // z is flag to look in next bin - // rrr fine r bin - // NOTE : this encoding is not efficient z is one if xxx+rrr is greater than 8 - // and xxx is only 1,2, or 3 - // should also reject xxx=0 as this means projection is outside range - - bool overlap = iseed == 6 || iseed == 7 || iseed == 10; - - int value = rbin1 / 8; - if (overlap) { - if (z < 0.0) - value += 4; - } - value *= 2; - if (rbin2 / 8 - rbin1 / 8 > 0) - value += 1; - value *= 8; - value += (rbin1 & 7); - assert(value / 8 < 15); - int deltar = rbin2 - rbin1; - if (deltar > 7) - deltar = 7; - if (overlap) { - value += (deltar << 7); - } else { - value += (deltar << 6); - } - - return value; - } -} - -int VMRouterTable::lookup(int zbin, int rbin) { - int index = zbin * rbins_ + rbin; - assert(index >= 0 && index < (int)vmrtable_.size()); - return vmrtable_[index]; -} - -int VMRouterTable::lookupdisk(int zbin, int rbin) { - int index = zbin * rbins_ + rbin; - assert(index >= 0 && index < (int)vmrtabletedisk_.size()); - return vmrtabletedisk_[index]; -} - -int VMRouterTable::lookupinner(int zbin, int rbin) { - int index = zbin * rbins_ + rbin; - assert(index >= 0 && index < (int)vmrtableteinner_.size()); - return vmrtableteinner_[index]; -} - -int VMRouterTable::lookupinneroverlap(int zbin, int rbin) { - int index = zbin * rbins_ + rbin; - assert(index >= 0 && index < (int)vmrtableteinneroverlap_.size()); - return vmrtableteinneroverlap_[index]; -} - -int VMRouterTable::lookupinnerThird(int zbin, int rbin) { - int index = zbin * rbins_ + rbin; - assert(index >= 0 && index < (int)vmrtableteinnerThird_.size()); - return vmrtableteinnerThird_[index]; -} - -void VMRouterTable::writeVMTable(std::string const& dir, std::string const& name, std::vector const& table) { - ofstream out = openfile(dir, name, __FILE__, __LINE__); - - out << "{" << endl; - for (unsigned int i = 0; i < table.size(); i++) { - if (i != 0) { - out << "," << endl; - } - int itable = table[i]; - out << itable; - } - out << endl << "};" << endl; - out.close(); -} diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc index 47c70a825d5b4..9d8ccae586cf0 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc @@ -1,4 +1,5 @@ #include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include #include @@ -6,7 +7,7 @@ using namespace std; using namespace trklet; -VMStubsTEMemory::VMStubsTEMemory(string name, Settings const& settings) : MemoryBase(name, settings) { +VMStubsTEMemory::VMStubsTEMemory(string name, Settings const& settings) : MemoryBase(name, settings), bendtable_(settings) { //set the layer or disk that the memory is in initLayerDisk(6, layer_, disk_); @@ -24,16 +25,6 @@ VMStubsTEMemory::VMStubsTEMemory(string name, Settings const& settings) : Memory phibin_ = 10 * phibin_ + (subname[1] - '0'); } - //set the bins used in the bend tabele - unsigned int nbins = 8; - if (layer_ >= 4) - nbins = 16; - if (disk_ == 1 && extended_ && overlap_) - nbins = 16; - for (unsigned int i = 0; i < nbins; i++) { - vmbendtable_.push_back(true); - } - isinner_ = (layer_ % 2 == 1 or disk_ % 2 == 1); // special cases with overlap seeding if (overlap_ and layer_ == 2) @@ -79,7 +70,7 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub, int bin) { return true; } - bool pass = passbend(vmstub.bend().value()); + bool pass = bendtable_.lookup(vmstub.bend().value()); if (!pass) { if (settings_.debugTracklet()) @@ -141,7 +132,7 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub) { //If the pt of the stub is consistent with the allowed pt of tracklets //in that can be formed in this VM and the other VM used in the TE. - bool pass = passbend(vmstub.bend().value()); + bool pass = bendtable_.lookup(vmstub.bend().value()); if (!pass) { if (settings_.debugTracklet()) @@ -271,27 +262,7 @@ void VMStubsTEMemory::getPhiRange(double& phimin, double& phimax, unsigned int i return; } -void VMStubsTEMemory::setbendtable(std::vector vmbendtable) { - assert(vmbendtable_.size() == vmbendtable.size()); - for (unsigned int i = 0; i < vmbendtable.size(); i++) { - vmbendtable_[i] = vmbendtable[i]; - } - - if (settings_.writeTable()) - writeVMBendTable(); +void VMStubsTEMemory::setbendtable(const TrackletLUT& bendtable) { + bendtable_ = bendtable; } -void VMStubsTEMemory::writeVMBendTable() { - ofstream outvmbendcut = openfile(settings_.tablePath(), getName() + "_vmbendcut.tab", __FILE__, __LINE__); - - outvmbendcut << "{" << endl; - unsigned int vmbendtableSize = vmbendtable_.size(); - assert(vmbendtableSize == 16 || vmbendtableSize == 8); - for (unsigned int i = 0; i < vmbendtableSize; i++) { - if (i != 0) - outvmbendcut << "," << endl; - outvmbendcut << vmbendtable_[i]; - } - outvmbendcut << endl << "};" << endl; - outvmbendcut.close(); -} From 0e35202a108310f9683ffc87ed0b7f0d78e39904 Mon Sep 17 00:00:00 2001 From: Louise Skinnari Date: Fri, 7 May 2021 17:08:27 +0200 Subject: [PATCH 07/15] MP updates (fixed) (#81) * Updates to MatchProcessor so that we can get full agreement with HLS version * Fix to LUT for adding stub in VMStubsTEMemory when running extendted tracking Co-authored-by: Anders Ryd --- .../interface/MatchEngineUnit.h | 19 +- .../interface/TrackletLUT.h | 2 + .../src/MatchEngineUnit.cc | 94 ++++- .../src/MatchProcessor.cc | 354 ++++++++++-------- .../src/VMStubsTEMemory.cc | 17 +- 5 files changed, 313 insertions(+), 173 deletions(-) diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h index 7dfaa3503736e..6c62b694f502d 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h @@ -35,10 +35,13 @@ namespace trklet { bool usesecondMinus, bool usesecondPlus, bool isPSseed, - Tracklet* proj); + Tracklet* proj, + bool print); bool empty() const { return candmatches_.empty(); } + int TCID() const; + std::pair read() { return candmatches_.read(); } std::pair peek() const { return candmatches_.peek(); } @@ -47,8 +50,16 @@ namespace trklet { bool idle() const { return idle_; } + bool active() const { return !idle_||goodpair_||goodpair__||!empty(); } + + bool have_() const { return havepair_; } + bool have__() const { return havepair__; } + void reset(); + unsigned int rptr() const { return candmatches_.rptr(); } + unsigned int wptr() const { return candmatches_.wptr(); } + void step(bool print); private: @@ -77,7 +88,11 @@ namespace trklet { //LUT for bend consistency with rinv const TrackletLUT& luttable_; - + //Pipeline variables + std::pair tmppair_, tmppair__; + bool goodpair_, goodpair__; + bool havepair_, havepair__; + //save the candidate matches CircularBuffer> candmatches_; }; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h b/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h index 7e7392d372e3a..d730d1270e9ec 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h @@ -59,6 +59,8 @@ namespace trklet { int lookup(unsigned int index) const; + unsigned int size() const { return table_.size(); } + private: int getphiCorrValue(unsigned int layerdisk, unsigned int ibend, unsigned int irbin, diff --git a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc index 2b89f436be2fc..20c8ab9e1b329 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc @@ -4,10 +4,14 @@ using namespace std; using namespace trklet; -MatchEngineUnit::MatchEngineUnit(bool barrel, unsigned int layerdisk, const TrackletLUT& luttable) : luttable_(luttable), candmatches_(5) { +MatchEngineUnit::MatchEngineUnit(bool barrel, unsigned int layerdisk, const TrackletLUT& luttable) : luttable_(luttable), candmatches_(3) { idle_ = true; barrel_ = barrel; layerdisk_ = layerdisk; + goodpair_ = false; + goodpair__ = false; + havepair_ = false; + havepair__ = false; } void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory, @@ -23,7 +27,8 @@ void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory, bool usesecondMinus, bool usesecondPlus, bool isPSseed, - Tracklet* proj) { + Tracklet* proj, + bool) { vmstubsmemory_ = vmstubsmemory; idle_ = false; nrzbins_ = nrzbins; @@ -39,22 +44,53 @@ void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory, if (usefirstMinus) { use_.emplace_back(0, 0); } - if (usefirstPlus) { - use_.emplace_back(0, 1); - } if (usesecondMinus) { use_.emplace_back(1, 0); } + if (usefirstPlus) { + use_.emplace_back(0, 1); + } if (usesecondPlus) { use_.emplace_back(1, 1); } assert(use_.size() != 0); isPSseed_ = isPSseed; proj_ = proj; + + //Even when you init a new projection you need to process the pipeline + //This should be fixed to be done more cleanly - but require synchronizaton + //with the HLS code + if (goodpair__) { + candmatches_.store(tmppair__); + } + + havepair__ = havepair_; + goodpair__ = goodpair_; + tmppair__ = tmppair_; + + havepair_ = false; + goodpair_ = false; + + } -void MatchEngineUnit::step(bool print) { - if (idle() || candmatches_.almostfull()) +void MatchEngineUnit::step(bool) { + + bool almostfull = candmatches_.nearfull(); + + if (goodpair__) { + assert(havepair__); + candmatches_.store(tmppair__); + } + + havepair__ = havepair_; + goodpair__ = goodpair_; + tmppair__ = tmppair_; + + havepair_ = false; + goodpair_ = false; + + if (idle() || almostfull) return; unsigned int slot = (phibin_ + use_[iuse_].second) * nrzbins_ + rzbin_ + use_[iuse_].first; @@ -106,16 +142,21 @@ void MatchEngineUnit::step(bool print) { } } - if (print) - cout << "MEU TrkId stubindex : " << 128 * proj_->TCIndex() + proj_->trackletIndex() << " " - << vmstub.stubindex().value() << " " << ((pass && dphicut) && luttable_.lookup(index)) << " index=" << index - << " projrinv bend : " << projrinv_ << " " << vmstub.bend().value() << " shift_ isPSseed_ :" << shift_ << " " - << isPSseed_ << " slot=" << slot << endl; + // Detailed printout for comparison with HLS code + //if (print) + // cout << "MEU TrkId stubindex : " << 128 * proj_->TCIndex() + proj_->trackletIndex() << " " + // << vmstub.stubindex().value() << " " << ((pass && dphicut) && luttable_.lookup(index)) << " index=" << index + // << " projrinv bend : " << projrinv_ << " " << vmstub.bend().value() << " shift_ isPSseed_ :" << shift_ << " " + // << isPSseed_ << " slot=" << slot << endl; //Check if stub bend and proj rinv consistent - if ((pass && dphicut) && luttable_.lookup(index)) { - std::pair tmp(proj_, vmstub.stub()); - candmatches_.store(tmp); + + goodpair_ = (pass && dphicut) && luttable_.lookup(index); + havepair_ = true; + + if (havepair_) { + std::pair tmppair(proj_, vmstub.stub()); + tmppair_ = tmppair; } istub_++; @@ -133,4 +174,27 @@ void MatchEngineUnit::reset() { candmatches_.reset(); idle_ = true; istub_ = 0; + goodpair_ = false; + goodpair__ = false; + havepair_ = false; + havepair__ = false; +} + +int MatchEngineUnit::TCID() const { + + if (!empty()) { + return peek().first->TCID(); + } + + if (idle_&&!havepair_&&!havepair__) { + return 16383; + } + if (havepair__) { + return tmppair__.first->TCID(); + } + if (havepair_) { + return tmppair_.first->TCID(); + } + return proj_->TCID(); + } diff --git a/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc b/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc index 4eca2ff1c4569..5723a4dcce56c 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc @@ -125,6 +125,7 @@ void MatchProcessor::addInput(MemoryBase* memory, string input) { } void MatchProcessor::execute(unsigned int iSector, double phimin) { + assert(vmstubs_.size() == 1); /* @@ -154,6 +155,11 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { unsigned int countinputproj = 0; unsigned int iprojmem = 0; + while (iprojmemnTracklets()==0) { + iprojmem++; + } + + unsigned int iproj = 0; inputProjBuffer_.reset(); @@ -166,135 +172,80 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { matchengine.reset(); } + + ProjectionTemp tmpProj_, tmpProj__; + bool good_ = false; + bool good__ = false; + for (unsigned int istep = 0; istep < settings_.maxStep("MP"); istep++) { + + bool projBuffNearFull=inputProjBuffer_.nearfull(); + + // This print statement is useful for detailed comparison with the HLS code + // It prints out detailed status information for each clock step + /* + if (print) { + cout << "istep = "<nTracklets() == 0) { - iprojmem++; - } else if (iproj < projMem->nTracklets()) { - if (!inputProjBuffer_.almostfull()) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << getName() << " have projection in memory : " << projMem->getName(); - } - - Tracklet* proj = projMem->getTracklet(iproj); - - FPGAWord fpgaphi = proj->proj(layerdisk_).fpgaphiproj(); - - unsigned int iphi = (fpgaphi.value() >> (fpgaphi.nbits() - nvmbits_)) & (nvmbins_ - 1); - - int nextrabits = 2; - int overlapbits = nvmbits_ + nextrabits; - - unsigned int extrabits = fpgaphi.bits(fpgaphi.nbits() - overlapbits, nextrabits); - - unsigned int ivmPlus = iphi; - - int shift = 0; - - if (extrabits == ((1U << nextrabits) - 1) && iphi != ((1U << settings_.nbitsvmme(layerdisk_)) - 1)) { - shift = 1; - ivmPlus++; - } - unsigned int ivmMinus = iphi; - if (extrabits == 0 && iphi != 0) { - shift = -1; - ivmMinus--; - } - - int projrinv = -1; - if (barrel_) { - FPGAWord phider = proj->proj(layerdisk_).fpgaphiprojder(); - projrinv = (1 << (nrinv_ - 1)) - 1 - (phider.value() >> (phider.nbits() - nrinv_)); - } else { - //The next lines looks up the predicted bend based on: - // 1 - r projections - // 2 - phi derivative - // 3 - the sign - i.e. if track is forward or backward - - int rindex = (proj->proj(layerdisk_).fpgarzproj().value() >> - (proj->proj(layerdisk_).fpgarzproj().nbits() - nrbits_)) & - ((1 << nrbits_) - 1); - - int phiderindex = (proj->proj(layerdisk_).fpgaphiprojder().value() >> - (proj->proj(layerdisk_).fpgaphiprojder().nbits() - nphiderbits_)) & - ((1 << nphiderbits_) - 1); - - int signindex = proj->proj(layerdisk_).fpgarzprojder().value() < 0; - - int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; - - projrinv = rinvbendlut_.lookup(bendindex); - - proj->proj(layerdisk_).setBendIndex(projrinv); - } - assert(projrinv >= 0); - - unsigned int slot = proj->proj(layerdisk_).fpgarzbin1projvm().value(); - bool second = proj->proj(layerdisk_).fpgarzbin2projvm().value(); - - unsigned int projfinephi = (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + NFINEPHIBITS))) & ((1<proj(layerdisk_).fpgafinerzvm().value(); - - bool isPSseed = proj->PSseed(); - - int nbins = (1 << N_RZBITS); - if (layerdisk_ >= N_LAYER) { - nbins*=2; //twice as many bins in disks (since there are two disks) - } - - VMStubsMEMemory* stubmem = vmstubs_[0]; - bool usefirstMinus = stubmem->nStubsBin(ivmMinus * nbins + slot) != 0; - bool usesecondMinus = (second && (stubmem->nStubsBin(ivmMinus * nbins + slot + 1) != 0)); - bool usefirstPlus = ivmPlus != ivmMinus && stubmem->nStubsBin(ivmPlus * nbins + slot) != 0; - bool usesecondPlus = - ivmPlus != ivmMinus && (second && (stubmem->nStubsBin(ivmPlus * nbins + slot + 1) != 0)); - - bool useProj = usefirstPlus || usesecondPlus || usefirstMinus || usesecondMinus; - - if (useProj) { - ProjectionTemp tmpProj(proj, - slot, - projrinv, - projfinerz, - projfinephi, - ivmMinus, - shift, - usefirstMinus, - usefirstPlus, - usesecondMinus, - usesecondPlus, - isPSseed); - inputProjBuffer_.store(tmpProj); - } - - iproj++; - if (iproj == projMem->nTracklets()) { - iproj = 0; - iprojmem++; - } - } - } - } else { - projdone = true; + //Step 3 + //Check if we have candidate match to process + + unsigned int iMEbest = 0; + int bestTCID = matchengines_[0].TCID(); + bool meactive = matchengines_[0].active(); + for (unsigned int iME = 1; iME < nMatchEngines_; iME++) { + meactive = meactive || matchengines_[iME].active(); + int tcid=matchengines_[iME].TCID(); + if (tcid candmatch = matchengines_[iMEbest].read(); + + const Stub* fpgastub = candmatch.second; + Tracklet* tracklet = candmatch.first; + + if (oldTracklet != nullptr) { + //allow equal here since we can have more than one cadidate match per tracklet projection + //cout << "old new : "<TCID()<<" "<TCID()<<" "<TCID() <= tracklet->TCID()); + } + oldTracklet = tracklet; + + bool match = matchCalculator(tracklet, fpgastub, print, istep); + + if (settings_.debugTracklet() && match) { + edm::LogVerbatim("Tracklet") << getName() << " have match"; + } + + countall++; + if (match) + countsel++; + } + //Step 2 //Check if we have ME that can process projection - + bool addedProjection = false; for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { if (!matchengines_[iME].idle()) countme++; - matchengines_[iME].step(print); //if match engine empty and we have queued projections add to match engine if ((!addedProjection) && matchengines_[iME].idle() && (!inputProjBuffer_.empty())) { ProjectionTemp tmpProj = inputProjBuffer_.read(); @@ -322,54 +273,151 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { tmpProj.use(1, 0), tmpProj.use(1, 1), tmpProj.isPSseed(), - tmpProj.proj()); + tmpProj.proj(), + print&&(iME==0)); addedProjection = true; + } else { + matchengines_[iME].step(print&&iME==0); } + } - //Step 3 - //Check if we have candidate match to process - unsigned int iMEbest = nMatchEngines_; - int bestTCID = -1; - bool bestInPipeline = false; - for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { - bool empty = matchengines_[iME].empty(); - medone = medone && (empty && matchengines_[iME].idle()); - if (empty && matchengines_[iME].idle()) - continue; - int currentTCID = empty ? matchengines_[iME].currentProj()->TCID() : matchengines_[iME].peek().first->TCID(); - if ((iMEbest == nMatchEngines_) || (currentTCID < bestTCID)) { - iMEbest = iME; - bestTCID = currentTCID; - bestInPipeline = empty; - } - } - if (iMEbest != nMatchEngines_ && (!bestInPipeline)) { - std::pair candmatch = matchengines_[iMEbest].read(); - - const Stub* fpgastub = candmatch.second; - Tracklet* tracklet = candmatch.first; + //Step 1 + //First step here checks if we have more input projections to put into + //the input puffer for projections - if (oldTracklet != nullptr) { - //allow equal here since we can have more than one cadidate match per tracklet projection - assert(oldTracklet->TCID() <= tracklet->TCID()); - } - oldTracklet = tracklet; + if (good__) { + inputProjBuffer_.store(tmpProj__); + } - bool match = matchCalculator(tracklet, fpgastub, print, istep); + good__ = good_; + tmpProj__ = tmpProj_; - if (settings_.debugTracklet() && match) { - edm::LogVerbatim("Tracklet") << getName() << " have match"; + good_ = false; + + if (istep < settings_.maxStep("MP")) { + if (iprojmem < inputprojs_.size()) { + TrackletProjectionsMemory* projMem = inputprojs_[iprojmem]; + if (!projBuffNearFull) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " have projection in memory : " << projMem->getName(); + } + + Tracklet* proj = projMem->getTracklet(iproj); + + FPGAWord fpgaphi = proj->proj(layerdisk_).fpgaphiproj(); + + unsigned int iphi = (fpgaphi.value() >> (fpgaphi.nbits() - nvmbits_)) & (nvmbins_ - 1); + + int nextrabits = 2; + int overlapbits = nvmbits_ + nextrabits; + + unsigned int extrabits = fpgaphi.bits(fpgaphi.nbits() - overlapbits, nextrabits); + + unsigned int ivmPlus = iphi; + + int shift = 0; + + if (extrabits == ((1U << nextrabits) - 1) && iphi != ((1U << settings_.nbitsvmme(layerdisk_)) - 1)) { + shift = 1; + ivmPlus++; + } + unsigned int ivmMinus = iphi; + if (extrabits == 0 && iphi != 0) { + shift = -1; + ivmMinus--; + } + + int projrinv = -1; + if (barrel_) { + FPGAWord phider = proj->proj(layerdisk_).fpgaphiprojder(); + projrinv = (1 << (nrinv_ - 1)) - 1 - (phider.value() >> (phider.nbits() - nrinv_)); + } else { + //The next lines looks up the predicted bend based on: + // 1 - r projections + // 2 - phi derivative + // 3 - the sign - i.e. if track is forward or backward + + int rindex = (proj->proj(layerdisk_).fpgarzproj().value() >> + (proj->proj(layerdisk_).fpgarzproj().nbits() - nrbits_)) & + ((1 << nrbits_) - 1); + + int phiderindex = (proj->proj(layerdisk_).fpgaphiprojder().value() >> + (proj->proj(layerdisk_).fpgaphiprojder().nbits() - nphiderbits_)) & + ((1 << nphiderbits_) - 1); + + int signindex = proj->proj(layerdisk_).fpgarzprojder().value() < 0; + + int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; + + projrinv = rinvbendlut_.lookup(bendindex); + + proj->proj(layerdisk_).setBendIndex(projrinv); + } + assert(projrinv >= 0); + + unsigned int slot = proj->proj(layerdisk_).fpgarzbin1projvm().value(); + bool second = proj->proj(layerdisk_).fpgarzbin2projvm().value(); + + unsigned int projfinephi = (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + NFINEPHIBITS))) & ((1<proj(layerdisk_).fpgafinerzvm().value(); + + bool isPSseed = proj->PSseed(); + + int nbins = (1 << N_RZBITS); + if (layerdisk_ >= N_LAYER) { + nbins*=2; //twice as many bins in disks (since there are two disks) + } + + VMStubsMEMemory* stubmem = vmstubs_[0]; + bool usefirstMinus = stubmem->nStubsBin(ivmMinus * nbins + slot) != 0; + bool usesecondMinus = (second && (stubmem->nStubsBin(ivmMinus * nbins + slot + 1) != 0)); + bool usefirstPlus = ivmPlus != ivmMinus && stubmem->nStubsBin(ivmPlus * nbins + slot) != 0; + bool usesecondPlus = + ivmPlus != ivmMinus && (second && (stubmem->nStubsBin(ivmPlus * nbins + slot + 1) != 0)); + + good_ = usefirstPlus || usesecondPlus || usefirstMinus || usesecondMinus; + + if (good_) { + ProjectionTemp tmpProj(proj, + slot, + projrinv, + projfinerz, + projfinephi, + ivmMinus, + shift, + usefirstMinus, + usefirstPlus, + usesecondMinus, + usesecondPlus, + isPSseed); + tmpProj_ = tmpProj; + } + + iproj++; + if (iproj == projMem->nTracklets()) { + iproj = 0; + do { + iprojmem++; + } while (iprojmemnTracklets()==0); + } + } + + } else { + projdone = true && !good_ && !good__; } - - countall++; - if (match) - countsel++; } - if ((projdone && medone) || (istep == settings_.maxStep("MP") - 1)) { + + // + // Check if done + // + // + // + + if ((projdone && !meactive) || (istep == settings_.maxStep("MP") - 1)) { if (settings_.writeMonitorData("MP")) { globals_->ofstream("matchprocessor.txt") << getName() << " " << istep << " " << countall << " " << countsel << " " << countme << " " << countinputproj << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc index 9d8ccae586cf0..4d7ac21ad4373 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc @@ -70,8 +70,13 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub, int bin) { return true; } - bool pass = bendtable_.lookup(vmstub.bend().value()); - + bool pass = false; + if (settings_.extended()&&bendtable_.size()==0) { + pass = true ; + } else { + pass = bendtable_.lookup(vmstub.bend().value()); + } + if (!pass) { if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << getName() << " Stub failed bend cut. bend = " @@ -132,8 +137,14 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub) { //If the pt of the stub is consistent with the allowed pt of tracklets //in that can be formed in this VM and the other VM used in the TE. - bool pass = bendtable_.lookup(vmstub.bend().value()); + bool pass = false; + if (settings_.extended()&&bendtable_.size()==0) { + pass = true ; + } else { + pass = bendtable_.lookup(vmstub.bend().value()); + } + if (!pass) { if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << getName() << " Stub failed bend cut. bend = " From 79d14e87e9f31d3e1a587d51b86cf4be7ae0c9b2 Mon Sep 17 00:00:00 2001 From: aryd Date: Fri, 7 May 2021 11:09:20 -0400 Subject: [PATCH 08/15] Corrections to fix updates to new LUTs that broke the displaced tracking (#82) * Corrections to fix updates to new LUTs that broke the displaced tracking * Fix compile errors in CMSSW * Remove commented out code Co-authored-by: Louise Skinnari --- .../interface/TrackletEngineUnit.h | 8 ++-- .../interface/TrackletLUT.h | 2 +- .../TrackFindingTracklet/interface/Util.h | 4 +- .../src/TrackletEngineUnit.cc | 6 +-- .../TrackFindingTracklet/src/TrackletLUT.cc | 42 ++++--------------- .../src/TrackletProcessor.cc | 8 +--- .../TrackFindingTracklet/src/VMRouter.cc | 14 +++---- 7 files changed, 28 insertions(+), 56 deletions(-) diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h index b8a77cf6734fb..1c84c6d0b0b08 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h @@ -34,8 +34,8 @@ namespace trklet { unsigned int iSeed, unsigned int nbitsfinephiediff, unsigned int iAllStub, - const TrackletLUT& pttableinnernew, - const TrackletLUT& pttableouternew, + const TrackletLUT* pttableinnernew, + const TrackletLUT* pttableouternew, VMStubsTEMemory* outervmstubs); ~TrackletEngineUnit() = default; @@ -83,8 +83,8 @@ namespace trklet { bool idle_; - const TrackletLUT& pttableinnernew_; - const TrackletLUT& pttableouternew_; + const TrackletLUT* pttableinnernew_; + const TrackletLUT* pttableouternew_; std::pair candpair_, candpair__; bool goodpair_, goodpair__; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h b/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h index d730d1270e9ec..3d480f0c54adb 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h @@ -60,7 +60,7 @@ namespace trklet { int lookup(unsigned int index) const; unsigned int size() const { return table_.size(); } - + private: int getphiCorrValue(unsigned int layerdisk, unsigned int ibend, unsigned int irbin, diff --git a/L1Trigger/TrackFindingTracklet/interface/Util.h b/L1Trigger/TrackFindingTracklet/interface/Util.h index 41ed3a8e25390..31fc468e9c12a 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Util.h +++ b/L1Trigger/TrackFindingTracklet/interface/Util.h @@ -138,7 +138,7 @@ namespace trklet { //Open file - create directory if not existent. inline std::ofstream openfile(const std::string& dir, const std::string& fname, const char* file, int line) { if (dirExists(dir) != 1) { - std::cout << "Creating directory : " << dir << std::endl; + edm::LogVerbatim("Tracklet") << "Creating directory : " << dir; int fail = system((std::string("mkdir -p ") + dir).c_str()); if (fail) { throw cms::Exception("BadDir") << file << " " << line << " could not create directory " << dir; @@ -159,7 +159,7 @@ namespace trklet { inline void openfile( std::ofstream& out, bool first, const std::string& dir, const std::string& fname, const char* file, int line) { if (dirExists(dir) != 1) { - std::cout << "Creating directory : " << dir << std::endl; + edm::LogVerbatim("Tracklet") << "Creating directory : " << dir; int fail = system((std::string("mkdir -p ") + dir).c_str()); if (fail) { throw cms::Exception("BadDir") << file << " " << line << " could not create directory " << dir; diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc index 9aa2fc61efd14..dcb0370ea4e77 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc @@ -12,8 +12,8 @@ TrackletEngineUnit::TrackletEngineUnit(const Settings* const settings, unsigned int iSeed, unsigned int nbitsfinephidiff, unsigned int iAllStub, - const TrackletLUT& pttableinnernew, - const TrackletLUT& pttableouternew, + const TrackletLUT* pttableinnernew, + const TrackletLUT* pttableouternew, VMStubsTEMemory* outervmstubs) : settings_(settings), pttableinnernew_(pttableinnernew), pttableouternew_(pttableouternew), candpairs_(3) { idle_ = true; @@ -101,7 +101,7 @@ void TrackletEngineUnit::step(bool, int, int) { int ptinnerindex = (idphi << tedata_.innerbend_.nbits()) + tedata_.innerbend_.value(); int ptouterindex = (idphi << outerbend.nbits()) + outerbend.value(); - if (!(inrange && pttableinnernew_.lookup(ptinnerindex) && pttableouternew_.lookup(ptouterindex))) { + if (!(inrange && pttableinnernew_->lookup(ptinnerindex) && pttableouternew_->lookup(ptouterindex))) { if (settings_->debugTracklet()) { edm::LogVerbatim("Tracklet") << " Stub pair rejected because of stub pt cut bends : " << settings_->benddecode( diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc b/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc index bb48a551f1f4d..adfb887177ce4 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc @@ -39,7 +39,7 @@ void TrackletLUT::initmatchcut(unsigned int layerdisk, MatchType type, unsigned if (type==barrelphi) { name_ += TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_phicut.tab"; - } + } if (type==barrelz) { name_ += TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_zcut.tab"; } @@ -71,28 +71,12 @@ void TrackletLUT::initTPlut(bool fillInner, unsigned int iSeed, unsigned int lay settings_.nallstubs(layerdisk2) * settings_.nvmte(1, iSeed) * (1 << settings_.nfinephi(1, iSeed)); double dfinephi = settings_.dphisectorHG() / nfinephibins; - double rmin = -1.0; - double rmax = -1.0; - int outerrbits = 3; if (iSeed == Seed::L1L2 || iSeed == Seed::L2L3 ||iSeed == Seed::L3L4 || iSeed == Seed::L5L6 ) { outerrbits = 0; - rmin = settings_.rmean(layerdisk1); - rmax = settings_.rmean(layerdisk2); - } else { - if (iSeed == Seed::L1D1) { - rmax = settings_.rmaxdiskl1overlapvm(); - rmin = settings_.rmean(layerdisk1); - } else if (iSeed == Seed::L2D1) { - rmax = settings_.rmaxdiskvm(); - rmin = settings_.rmean(layerdisk1); - } else { - rmax = settings_.rmaxdiskvm(); - rmin = rmax * settings_.zmean(layerdisk2 - N_LAYER - 1) / settings_.zmean(layerdisk2 - N_LAYER); - } } - + int outerrbins = (1 << outerrbits); double dphi[2]; @@ -209,12 +193,9 @@ void TrackletLUT::initTPregionlut(unsigned int iSeed, unsigned int layerdisk1, u } unsigned int nbendbitsinner = 3; - unsigned int nbendbitsouter = 3; - if (iSeed == Seed::L3L4) { - nbendbitsouter = 4; - } else if (iSeed == Seed::L5L6) { + + if (iSeed == Seed::L5L6) { nbendbitsinner = 4; - nbendbitsouter = 4; } for (int innerfinephi = 0; innerfinephi < (1 << nbitsfinephi); innerfinephi++) { @@ -598,7 +579,7 @@ void TrackletLUT::initVMRTable(unsigned int layerdisk, VMRTableType type, int re table_.push_back(getVMRLookup(layerdisk + 1, z, r, dz, dr)); } if (layerdisk == LayerDisk::L2) { - table_.push_back(getVMRLookup(layerdisk + 1, z, r, dz, dr, 1)); + table_.push_back(getVMRLookup(layerdisk + 1, z, r, dz, dr, Seed::L2L3)); } } @@ -611,27 +592,22 @@ void TrackletLUT::initVMRTable(unsigned int layerdisk, VMRTableType type, int re if (type == VMRTableType::innerthird ) { if (layerdisk == LayerDisk::L2) { //projection from L2 to D1 for L2L3D1 seeding - table_.push_back(getVMRLookup(6, z, r, dz, dr, 10)); + table_.push_back(getVMRLookup(LayerDisk::D1, z, r, dz, dr, Seed::L2L3D1)); } if (layerdisk == LayerDisk::L5) { //projection from L5 to L4 for L5L6L4 seeding - table_.push_back(getVMRLookup(3, z, r, dz, dr)); + table_.push_back(getVMRLookup(LayerDisk::L4, z, r, dz, dr)); } if (layerdisk == LayerDisk::L3) { //projection from L3 to L5 for L3L4L2 seeding - table_.push_back(getVMRLookup(1, z, r, dz, dr)); + table_.push_back(getVMRLookup(LayerDisk::L2, z, r, dz, dr)); } if (layerdisk == LayerDisk::D1) { //projection from D1 to L2 for D1D2L2 seeding - table_.push_back(getVMRLookup(1, z, r, dz, dr)); + table_.push_back(getVMRLookup(LayerDisk::L2, z, r, dz, dr)); } } - if (type == VMRTableType::innerthird ) { - if (layerdisk == LayerDisk::L1 || layerdisk == 1) { - table_.push_back(getVMRLookup(N_LAYER, z, r, dz, dr, layerdisk + N_LAYER)); - } - } } } diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc index dad0a7060877b..720bf62b4b6b9 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc @@ -187,8 +187,8 @@ void TrackletProcessor::addInput(MemoryBase* memory, string input) { iSeed_, nbitsfinephidiff_, iAllStub_, - pttableinner_, - pttableouter_, + &pttableinner_, + &pttableouter_, outervmstubs_); teunits_.resize(settings_.teunits(iSeed_), teunit); @@ -299,14 +299,10 @@ void TrackletProcessor::execute(unsigned int iSector, double phimin, double phim TrackletEngineUnit* teunitptr = nullptr; - int iTE = 0; - int icount = -1; for (auto& teunit : teunits_) { teunit.setNearFull(); - icount++; if (!teunit.empty()) { teunitptr = &teunit; - iTE = icount; } } diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc index 37ca217a0e92e..05549c77e1321 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc @@ -110,7 +110,7 @@ void VMRouter::addOutput(MemoryBase* memory, string output) { } else if (seedtype < 'o' && seedtype >= 'a') { if (layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3) iseed = Seed::L2L3D1; - if (layerdisk_ == LayerDisk::L1) + if (layerdisk_ == LayerDisk::L2) inner = 0; } else if (seedtype > 'o' && seedtype <= 'z') { if (layerdisk_ == LayerDisk::L2) @@ -185,7 +185,7 @@ void VMRouter::execute() { for (unsigned int i = 0; i < stubinput->nStubs(); i++) { if (allStubCounter >= settings_.maxStep("VMR")) continue; - if (allStubCounter > 127) + if (allStubCounter >= (1<getStub(i); @@ -194,7 +194,7 @@ void VMRouter::execute() { //use &127 to make sure we fit into the number of bits - //though we should have protected against overflows above - FPGAWord allStubIndex(allStubCounter & 127, 7, true, __LINE__, __FILE__); + FPGAWord allStubIndex(allStubCounter & ((1<setAllStubIndex(allStubCounter); @@ -287,7 +287,7 @@ void VMRouter::execute() { for (auto& ivmstubTEPHI : vmstubsTEPHI_) { unsigned int iseed = ivmstubTEPHI.seednumber; unsigned int inner = ivmstubTEPHI.stubposition; - if ((iseed == 4 || iseed == 5 || iseed == 6 || iseed == 7) && (!stub->isPSmodule())) + if ((iseed == Seed::D1D2 || iseed == Seed::D3D4 || iseed == Seed::L1D1 || iseed == Seed::L2D1) && (!stub->isPSmodule())) continue; unsigned int lutwidth = settings_.lutwidthtab(inner, iseed); @@ -301,7 +301,7 @@ void VMRouter::execute() { if (layerdisk_ < N_LAYER) { lutval = melut; } else { - if (inner == 2 && iseed == 10) { + if (inner == 2 && iseed == Seed::L2L3D1) { lutval = 0; if (stub->r().value() < 10) { lutval = 8 * (1 + (stub->r().value() >> 2)); @@ -317,14 +317,14 @@ void VMRouter::execute() { if (lutval == -1) continue; } else { - if (iseed < 6 || iseed > 7) { + if (iseed < Seed::L1D1 || iseed > Seed::L2D1) { lutval = innerTable_.lookup((indexz< Date: Fri, 7 May 2021 17:21:55 +0200 Subject: [PATCH 09/15] update default config with valid file + use DTC emulation in all sequences --- .../test/L1TrackNtupleMaker_cfg.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py index 494fdfc7e4470..4f1b4b92058e3 100644 --- a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py +++ b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py @@ -71,8 +71,7 @@ #inputMC=getCMSdata(dataName) # Or read specified .root file: - inputMC = ["/store/relval/CMSSW_11_3_0_pre3/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_113X_mcRun4_realistic_v3_2026D49PU200-v1/00000/001edbad-174e-46af-932a-6ce8e04aee1c.root"] - #inputMC = ["/store/relval/CMSSW_11_2_0_pre8/RelValSingleMuPt10/GEN-SIM-RECO/112X_mcRun4_realistic_v3_2026D49noPU-v1/00000/007d817e-9c59-4dec-959b-0f227942cdf0.root"] + inputMC = ["/store/relval/CMSSW_11_3_0_pre3/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_113X_mcRun4_realistic_v3_2026D49PU200_rsb-v1/00000/00260a30-734a-4a3a-a4b0-f836ce5502c6.root"] #inputMC = ["/store/relval/CMSSW_11_3_0_pre3/RelValSingleMuPt10/GEN-SIM-DIGI-RAW/113X_mcRun4_realistic_v3_2026D49noPU-v1/00000/04514913-efc7-49fc-8df4-90efe43ca047.root"] else: @@ -206,14 +205,11 @@ #process.TrackTriggerSetup.Hybrid.MinPt=1.0 process.dtc = cms.Path( process.TrackerDTCProducer )#* process.TrackerDTCAnalyzer ) - - - # use this if you want to re-run the stub making -# process.schedule = cms.Schedule(process.TTClusterStub,process.TTClusterStubTruth,process.TTTracksEmulationWithTruth,process.ana) +# process.schedule = cms.Schedule(process.TTClusterStub,process.TTClusterStubTruth,process.dtc,process.TTTracksEmulationWithTruth,process.ana) # use this if cluster/stub associators not available -# process.schedule = cms.Schedule(process.TTClusterStubTruth,process.TTTracksEmulationWithTruth,process.ana) +# process.schedule = cms.Schedule(process.TTClusterStubTruth,process.dtc,process.TTTracksEmulationWithTruth,process.ana) # use this to only run tracking + track associator process.schedule = cms.Schedule(process.dtc,process.TTTracksEmulationWithTruth,process.ana) From 3d3b0e54f3622a516ef41546a97db6672bd329f6 Mon Sep 17 00:00:00 2001 From: Louise Skinnari Date: Fri, 7 May 2021 17:25:04 +0200 Subject: [PATCH 10/15] apply code formats --- .../interface/KFTrackletTrack.h | 10 +- .../interface/L1fittedTrack.h | 10 +- L1Trigger/TrackFindingTMTT/src/KFbase.cc | 12 +- L1Trigger/TrackFindingTMTT/src/Settings.cc | 2 +- .../interface/MatchCalculator.h | 4 +- .../interface/MatchEngine.h | 3 +- .../interface/MatchEngineUnit.h | 14 +- .../interface/MatchProcessor.h | 4 +- .../interface/ProjectionRouter.h | 2 +- .../TrackFindingTracklet/interface/Settings.h | 48 +- .../interface/TrackletConfigBuilder.h | 2 - .../interface/TrackletLUT.h | 71 +-- .../interface/TrackletProcessor.h | 5 +- .../TrackFindingTracklet/interface/Util.h | 2 +- .../TrackFindingTracklet/interface/VMRouter.h | 10 +- .../interface/VMRouterCM.h | 4 +- .../interface/VMStubsTEMemory.h | 2 +- .../plugins/L1FPGATrackProducer.cc | 9 +- .../TrackFindingTracklet/src/FitTrack.cc | 2 +- .../TrackFindingTracklet/src/HybridFit.cc | 48 +- .../src/MatchCalculator.cc | 29 +- .../TrackFindingTracklet/src/MatchEngine.cc | 9 +- .../src/MatchEngineUnit.cc | 24 +- .../src/MatchProcessor.cc | 290 ++++++----- .../src/ProjectionRouter.cc | 11 +- L1Trigger/TrackFindingTracklet/src/Sector.cc | 2 +- .../src/TrackletConfigBuilder.cc | 17 +- .../src/TrackletEngine.cc | 78 ++- .../src/TrackletEngineUnit.cc | 9 +- .../TrackFindingTracklet/src/TrackletLUT.cc | 470 +++++++++--------- .../src/TrackletProcessor.cc | 59 +-- .../TrackFindingTracklet/src/VMRouter.cc | 62 ++- .../TrackFindingTracklet/src/VMRouterCM.cc | 33 +- .../src/VMStubsTEMemory.cc | 20 +- 34 files changed, 703 insertions(+), 674 deletions(-) diff --git a/L1Trigger/TrackFindingTMTT/interface/KFTrackletTrack.h b/L1Trigger/TrackFindingTMTT/interface/KFTrackletTrack.h index 293a397b5834f..997e02baf7ccc 100644 --- a/L1Trigger/TrackFindingTMTT/interface/KFTrackletTrack.h +++ b/L1Trigger/TrackFindingTMTT/interface/KFTrackletTrack.h @@ -46,11 +46,11 @@ namespace tmtt { unsigned int iPhiSec, unsigned int iEtaReg, bool accepted = true, - bool done_bcon = false, - float qOverPt_bcon = 0., - float d0_bcon = 0., - float phi0_bcon = 0., - float chi2rphi_bcon = 0.) + bool done_bcon = false, + float qOverPt_bcon = 0., + float d0_bcon = 0., + float phi0_bcon = 0., + float chi2rphi_bcon = 0.) : l1track3D_(l1track3D), stubs_(stubs), hitPattern_(hitPattern), diff --git a/L1Trigger/TrackFindingTMTT/interface/L1fittedTrack.h b/L1Trigger/TrackFindingTMTT/interface/L1fittedTrack.h index 834841dd5f9b8..3461554157a5e 100644 --- a/L1Trigger/TrackFindingTMTT/interface/L1fittedTrack.h +++ b/L1Trigger/TrackFindingTMTT/interface/L1fittedTrack.h @@ -163,11 +163,11 @@ namespace tmtt { iPhiSec(), iEtaReg(), accepted(), - done_bcon(), - qOverPt_bcon(), - d0_bcon(), - phi0_bcon(), - chi2rphi_bcon()); + done_bcon(), + qOverPt_bcon(), + d0_bcon(), + phi0_bcon(), + chi2rphi_bcon()); return trk_; } diff --git a/L1Trigger/TrackFindingTMTT/src/KFbase.cc b/L1Trigger/TrackFindingTMTT/src/KFbase.cc index aa1aa30825d99..7096e8c088272 100644 --- a/L1Trigger/TrackFindingTMTT/src/KFbase.cc +++ b/L1Trigger/TrackFindingTMTT/src/KFbase.cc @@ -103,12 +103,12 @@ namespace tmtt { double chi2rphi_bcon = 0.; TVectorD trackPars_bcon = trackParams_BeamConstr(cand, chi2rphi_bcon); - // Check scaled chi2 cut - vector kfLayerVsChiSqCut = settings_->kfLayerVsChiSq5(); - double chi2scaled = chi2rphi_bcon / settings_->kalmanChi2RphiScale() + fitTrk.chi2rz(); - bool accepted = true; - if (chi2scaled > kfLayerVsChiSqCut[cand->nStubLayers()]) - accepted = false; + // Check scaled chi2 cut + vector kfLayerVsChiSqCut = settings_->kfLayerVsChiSq5(); + double chi2scaled = chi2rphi_bcon / settings_->kalmanChi2RphiScale() + fitTrk.chi2rz(); + bool accepted = true; + if (chi2scaled > kfLayerVsChiSqCut[cand->nStubLayers()]) + accepted = false; fitTrk.setBeamConstr(trackPars_bcon[QOVERPT], trackPars_bcon[PHI0], chi2rphi_bcon, accepted); } diff --git a/L1Trigger/TrackFindingTMTT/src/Settings.cc b/L1Trigger/TrackFindingTMTT/src/Settings.cc index aa7c3ad3b162a..0ef20fd660574 100644 --- a/L1Trigger/TrackFindingTMTT/src/Settings.cc +++ b/L1Trigger/TrackFindingTMTT/src/Settings.cc @@ -42,7 +42,7 @@ namespace tmtt { //kalmanDebugLevel_(2), // Good for debugging kalmanMinNumStubs_(4), kalmanMaxNumStubs_(6), - kalmanAddBeamConstr_(false), // Apply post-fit beam-spot constraint to 5-param fit + kalmanAddBeamConstr_(false), // Apply post-fit beam-spot constraint to 5-param fit kalmanRemove2PScut_(true), kalmanMaxSkipLayersHard_(1), // On "hard" input tracks kalmanMaxSkipLayersEasy_(2), // On "easy" input tracks diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h b/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h index e2ce9a3a24f3b..3c8a0a6bd0165 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h @@ -44,12 +44,12 @@ namespace trklet { TrackletLUT phimatchcuttable_; TrackletLUT zmatchcuttable_; - + TrackletLUT rphicutPStable_; TrackletLUT rphicut2Stable_; TrackletLUT rcutPStable_; TrackletLUT rcut2Stable_; - + int ialphafactinner_[N_DSS_MOD * 2]; int ialphafactouter_[N_DSS_MOD * 2]; diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h b/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h index 6c6ccac14643b..58d667de2f310 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h @@ -35,11 +35,10 @@ namespace trklet { bool barrel_; - unsigned int nrinv_; //number of bits for rinv in stub bend LUT + unsigned int nrinv_; //number of bits for rinv in stub bend LUT //LUT for bend consistency TrackletLUT luttable_; - }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h index 6c62b694f502d..95fd87edd6939 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h @@ -15,7 +15,7 @@ namespace trklet { class Stub; class L1TStub; class TrackletLUT; - + class MatchEngineUnit { public: MatchEngineUnit(bool barrel, unsigned int layerdisk, const TrackletLUT& luttable); @@ -36,12 +36,12 @@ namespace trklet { bool usesecondPlus, bool isPSseed, Tracklet* proj, - bool print); + bool print); bool empty() const { return candmatches_.empty(); } int TCID() const; - + std::pair read() { return candmatches_.read(); } std::pair peek() const { return candmatches_.peek(); } @@ -50,11 +50,11 @@ namespace trklet { bool idle() const { return idle_; } - bool active() const { return !idle_||goodpair_||goodpair__||!empty(); } + bool active() const { return !idle_ || goodpair_ || goodpair__ || !empty(); } bool have_() const { return havepair_; } bool have__() const { return havepair__; } - + void reset(); unsigned int rptr() const { return candmatches_.rptr(); } @@ -84,7 +84,7 @@ namespace trklet { bool idle_; unsigned int layerdisk_; - + //LUT for bend consistency with rinv const TrackletLUT& luttable_; @@ -92,7 +92,7 @@ namespace trklet { std::pair tmppair_, tmppair__; bool goodpair_, goodpair__; bool havepair_, havepair__; - + //save the candidate matches CircularBuffer> candmatches_; }; diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h b/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h index 1a2c1a26cd834..78b9573734922 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h @@ -58,7 +58,7 @@ namespace trklet { TrackletLUT rphicut2Stable_; TrackletLUT rcutPStable_; TrackletLUT rcut2Stable_; - + int nrbits_; int nphiderbits_; @@ -77,7 +77,7 @@ namespace trklet { //LUT for bend consistency TrackletLUT luttable_; - + double phimin_; unsigned int nMatchEngines_; diff --git a/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h b/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h index 4f59d4fb1a342..230de71eb656d 100644 --- a/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h +++ b/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h @@ -29,7 +29,7 @@ namespace trklet { int nrbits_; int nphiderbits_; - + //disk projectionrinv table TrackletLUT rinvbendlut_; diff --git a/L1Trigger/TrackFindingTracklet/interface/Settings.h b/L1Trigger/TrackFindingTracklet/interface/Settings.h index f241b00744481..2bc340601e611 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Settings.h +++ b/L1Trigger/TrackFindingTracklet/interface/Settings.h @@ -35,20 +35,20 @@ namespace trklet { constexpr unsigned int N_RZBITS = 3; //number of bit for the r/z bins constexpr unsigned int N_PHIBITS = 3; //number of bit for the phi bins - constexpr unsigned int N_VMSTUBSMAX = 15; // maximum number of stubs in VM bin - constexpr unsigned int N_BITSMEMADDRESS = 7; // Number of bits for address in memories + constexpr unsigned int N_VMSTUBSMAX = 15; // maximum number of stubs in VM bin + constexpr unsigned int N_BITSMEMADDRESS = 7; // Number of bits for address in memories constexpr double sixth = 1.0 / 6.0; //Commonly used factor constexpr double third = 1.0 / 3.0; //Commonly used factor - constexpr double VMROUTERCUTZL2 = 50.0; //Min L2 z for inner allstub - constexpr double VMROUTERCUTZL1L3L5 = 95.0; //Max z for inner barrel layers - constexpr double VMROUTERCUTZL1 = 70.0; //Max z for L1 barrel seeding - constexpr double VMROUTERCUTRD1D3 = 55.0; //Max r for disk seeds + constexpr double VMROUTERCUTZL2 = 50.0; //Min L2 z for inner allstub + constexpr double VMROUTERCUTZL1L3L5 = 95.0; //Max z for inner barrel layers + constexpr double VMROUTERCUTZL1 = 70.0; //Max z for L1 barrel seeding + constexpr double VMROUTERCUTRD1D3 = 55.0; //Max r for disk seeds enum Seed { L1L2 = 0, L2L3, L3L4, L5L6, D1D2, D3D4, L1D1, L2D1, L2L3L4, L4L5L6, L2L3D1, D1D2L2 }; enum LayerDisk { L1 = 0, L2, L3, L4, L5, L6, D1, D2, D3, D4, D5 }; - + class Settings { public: Settings() { @@ -279,7 +279,7 @@ namespace trklet { void setNbitsseedextended(unsigned int nbitsseed) { nbitsseedextended_ = nbitsseed; } double dphisectorHG() const { - //These values are used in the DTC emulation code. + //These values are used in the DTC emulation code. double rsectmin = 21.8; double rsectmax = 112.7; return 2 * M_PI / N_SECTOR + rinvmax() * std::max(rcrit_ - rsectmin, rsectmax - rcrit_); @@ -416,13 +416,13 @@ namespace trklet { assert(bendcut > 0.0); return bendcut; } - + const std::vector& dtcLayers(const std::string& dtcName) const { - auto iter=dtclayers_.find(dtcName); - assert(iter!=dtclayers_.end()); + auto iter = dtclayers_.find(dtcName); + assert(iter != dtclayers_.end()); return iter->second; } - + double bendcutte(int ibend, int layerdisk, bool isPSmodule) const { return bendcut(ibend, layerdisk, isPSmodule); } double bendcutme(int ibend, int layerdisk, bool isPSmodule) const { @@ -478,17 +478,17 @@ namespace trklet { {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1}}}}; std::map > dtclayers_{{"PS10G_1", {0, 6, 8, 10}}, - {"PS10G_2", {0, 7, 9}}, - {"PS10G_3", {1, 7}}, - {"PS10G_4", {6, 8, 10}}, - {"PS_1", {2, 7}}, - {"PS_2", {2, 9}}, - {"2S_1", {3, 4}}, - {"2S_2", {4}}, - {"2S_3", {5}}, - {"2S_4", {5, 8}}, - {"2S_5", {6, 9}}, - {"2S_6", {7, 10}}}; + {"PS10G_2", {0, 7, 9}}, + {"PS10G_3", {1, 7}}, + {"PS10G_4", {6, 8, 10}}, + {"PS_1", {2, 7}}, + {"PS_2", {2, 9}}, + {"2S_1", {3, 4}}, + {"2S_2", {4}}, + {"2S_3", {5}}, + {"2S_4", {5, 8}}, + {"2S_5", {6, 9}}, + {"2S_6", {7, 10}}}; double rmindiskvm_{22.5}; double rmaxdiskvm_{67.0}; @@ -752,7 +752,7 @@ namespace trklet { //Number of processing steps for one event (108=18TM*240MHz/40MHz) std::unordered_map maxstep_{{"IR", 168}, //IR will run at a higher clock speed to handle - //input links running at 25 Gbits/s + //input links running at 25 Gbits/s {"VMR", 108}, {"TE", 108}, {"TC", 108}, diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h b/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h index 24894a51a11a4..64cc428205da8 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h @@ -54,7 +54,6 @@ namespace trklet { //Projection router name std::string PRName(unsigned int ilayer, unsigned int ireg); - private: // // Method to initialize the regions and VM in each layer @@ -107,7 +106,6 @@ namespace trklet { // double rinv(double r1, double phi1, double r2, double phi2); - //StubPair Name std::string SPName(unsigned int l1, unsigned int ireg1, diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h b/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h index 3d480f0c54adb..f37b8a909d498 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h @@ -10,74 +10,87 @@ namespace trklet { class Settings; class TrackletLUT { - public: - + public: TrackletLUT(const Settings& settings); TrackletLUT& operator=(const TrackletLUT& other) { - name_ = other.name_; table_ = other.table_; nbits_ = other.nbits_; positive_ = other.positive_; - + return *this; } - + ~TrackletLUT() = default; enum MatchType { barrelphi, barrelz, disk2Sphi, disk2Sr, diskPSphi, diskPSr }; - + //region only used for name - should be removed void initmatchcut(unsigned int layerdisk, MatchType type, unsigned int region); - void initTPlut(bool fillInner, unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, - unsigned int nbitsfinephidiff, unsigned int iTP); - - void initTPregionlut(unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, - unsigned int iAllStub, unsigned int nbitsfinephidiff, unsigned int nbitsfinephi, - const TrackletLUT& tplutinner, unsigned int iTP); - - void initteptlut(bool fillInner, bool fillTEMem, unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, - unsigned int innerphibits, unsigned int outerphibits, - double innerphimin, double innerphimax, double outerphimin, double outerphimax, - const std::string& innermem, const std::string& outermem); + void initTPlut(bool fillInner, + unsigned int iSeed, + unsigned int layerdisk1, + unsigned int layerdisk2, + unsigned int nbitsfinephidiff, + unsigned int iTP); + + void initTPregionlut(unsigned int iSeed, + unsigned int layerdisk1, + unsigned int layerdisk2, + unsigned int iAllStub, + unsigned int nbitsfinephidiff, + unsigned int nbitsfinephi, + const TrackletLUT& tplutinner, + unsigned int iTP); + + void initteptlut(bool fillInner, + bool fillTEMem, + unsigned int iSeed, + unsigned int layerdisk1, + unsigned int layerdisk2, + unsigned int innerphibits, + unsigned int outerphibits, + double innerphimin, + double innerphimax, + double outerphimin, + double outerphimax, + const std::string& innermem, + const std::string& outermem); - void initProjectionBend(double k_phider, unsigned int idisk, unsigned int nrbits, unsigned int nphiderbits); - + void initBendMatch(unsigned int layerdisk); - + enum VMRTableType { me, disk, inner, inneroverlap, innerthird }; //region only used for name - should be removed - void initVMRTable(unsigned int layerdisk, VMRTableType type, int region=-1); + void initVMRTable(unsigned int layerdisk, VMRTableType type, int region = -1); void initPhiCorrTable(unsigned int layerdisk, unsigned int rbits); void writeTable() const; - + int lookup(unsigned int index) const; unsigned int size() const { return table_.size(); } private: - - int getphiCorrValue(unsigned int layerdisk, unsigned int ibend, unsigned int irbin, - double rmean, double dr, double drmax) const; + int getphiCorrValue( + unsigned int layerdisk, unsigned int ibend, unsigned int irbin, double rmean, double dr, double drmax) const; int getVMRLookup(unsigned int layerdisk, double z, double r, double dz, double dr, int iseed = -1) const; - + const Settings& settings_; - + std::string name_; std::vector table_; unsigned int nbits_; - + bool positive_; - }; }; // namespace trklet #endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h b/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h index fd9fd6da8f03a..3f1ff60cc1b83 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h @@ -66,9 +66,8 @@ namespace trklet { unsigned int nbitsrzbin_; - TrackletLUT innerTable_; //projection to next layer/disk - TrackletLUT innerOverlapTable_; //projection to disk from layer - + TrackletLUT innerTable_; //projection to next layer/disk + TrackletLUT innerOverlapTable_; //projection to disk from layer }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/Util.h b/L1Trigger/TrackFindingTracklet/interface/Util.h index 31fc468e9c12a..ebed711199537 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Util.h +++ b/L1Trigger/TrackFindingTracklet/interface/Util.h @@ -138,7 +138,7 @@ namespace trklet { //Open file - create directory if not existent. inline std::ofstream openfile(const std::string& dir, const std::string& fname, const char* file, int line) { if (dirExists(dir) != 1) { - edm::LogVerbatim("Tracklet") << "Creating directory : " << dir; + edm::LogVerbatim("Tracklet") << "Creating directory : " << dir; int fail = system((std::string("mkdir -p ") + dir).c_str()); if (fail) { throw cms::Exception("BadDir") << file << " " << line << " could not create directory " << dir; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouter.h b/L1Trigger/TrackFindingTracklet/interface/VMRouter.h index ab1390490286f..b3c96d33384fe 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouter.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouter.h @@ -55,11 +55,11 @@ namespace trklet { int nbitszfinebintable_; int nbitsrfinebintable_; - TrackletLUT meTable_; //used for ME and outer TE barrel - TrackletLUT diskTable_; //outer disk used by D1, D2, and D4 - TrackletLUT innerTable_; //projection to next layer/disk - TrackletLUT innerOverlapTable_; //projection to disk from layer - TrackletLUT innerThirdTable_; //projection to disk1 for extended - iseed=10 + TrackletLUT meTable_; //used for ME and outer TE barrel + TrackletLUT diskTable_; //outer disk used by D1, D2, and D4 + TrackletLUT innerTable_; //projection to next layer/disk + TrackletLUT innerOverlapTable_; //projection to disk from layer + TrackletLUT innerThirdTable_; //projection to disk1 for extended - iseed=10 //The input stub memories the two tmp inputs are used to build the order needed in HLS std::vector stubinputs_, stubinputtmp_, stubinputdisk2stmp_; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h b/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h index 6d31e5f1d5d9c..2f6a468576361 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h @@ -54,8 +54,8 @@ namespace trklet { unsigned int nvmmebins_; //number of long z/r bins in VM - TrackletLUT meTable_; //used for ME and outer TE barrel - TrackletLUT diskTable_; //outer disk used by D1, D2, and D4 + TrackletLUT meTable_; //used for ME and outer TE barrel + TrackletLUT diskTable_; //outer disk used by D1, D2, and D4 //The input stub memories std::vector stubinputs_; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h b/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h index e487b37458d25..f8bb8c7f54545 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h @@ -63,7 +63,7 @@ namespace trklet { bool isinner_; // is inner layer/disk for TE purpose TrackletLUT bendtable_; - + std::vector stubsvm_; std::vector > stubsbinnedvm_; }; diff --git a/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc b/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc index ad83e1ec15f16..e18d67d8d5d39 100644 --- a/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc +++ b/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc @@ -460,10 +460,11 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe assert(layerdisk != -1); //Get the 36 bit word - skip the lowest 3 buts (status and layer code) - constexpr int DTCLinkWordSize = 64; - constexpr int StubWordSize = 36; - constexpr int LayerandStatusCodeSize = 3; - string stubword = stub.second.to_string().substr(DTCLinkWordSize - StubWordSize - LayerandStatusCodeSize, StubWordSize); + constexpr int DTCLinkWordSize = 64; + constexpr int StubWordSize = 36; + constexpr int LayerandStatusCodeSize = 3; + string stubword = + stub.second.to_string().substr(DTCLinkWordSize - StubWordSize - LayerandStatusCodeSize, StubWordSize); string stubwordhex = ""; //Loop over the 9 words in the 36 bit stub word diff --git a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc index 82b877da25947..7b1a9eca7a504 100644 --- a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc +++ b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc @@ -989,7 +989,7 @@ void FitTrack::execute(unsigned int iSector) { std::vector trackstublist; std::vector> stubidslist; - if ((bestTracklet->getISeed() >= (int)N_SEED_PROMPT && nMatchesUniq >= 1) || + if ((bestTracklet->getISeed() >= (int)N_SEED_PROMPT && nMatchesUniq >= 1) || nMatchesUniq >= 2) { //For seeds index >=8 (triplet seeds), there are three stubs associated from start. countFit++; diff --git a/L1Trigger/TrackFindingTracklet/src/HybridFit.cc b/L1Trigger/TrackFindingTracklet/src/HybridFit.cc index 82b6233e31c14..883af81dcbee2 100644 --- a/L1Trigger/TrackFindingTracklet/src/HybridFit.cc +++ b/L1Trigger/TrackFindingTracklet/src/HybridFit.cc @@ -195,7 +195,7 @@ void HybridFit::Fit(Tracklet* tracklet, std::vector& trackstublist) << ", phi0 = " << trk.phi0() << ", eta = " << trk.eta() << ", z0 = " << trk.z0() << ", chi2 = " << trk.chi2() << ", accepted = " << trk.accepted(); - double d0,chi2rphi,phi0,qoverpt = -999; + double d0, chi2rphi, phi0, qoverpt = -999; if (trk.done_bcon()) { d0 = trk.d0_bcon(); chi2rphi = trk.chi2rphi_bcon(); @@ -208,7 +208,7 @@ void HybridFit::Fit(Tracklet* tracklet, std::vector& trackstublist) qoverpt = trk.qOverPt(); } - // Tracklet wants phi0 with respect to lower edge of sector, not global phi0. + // Tracklet wants phi0 with respect to lower edge of sector, not global phi0. double phi0fit = reco::reduceRange(phi0 - iSector_ * 2 * M_PI / N_SECTOR + 0.5 * settings_.dphisectorHG()); double rinvfit = 0.01 * settings_.c() * settings_.bfield() * qoverpt; @@ -229,28 +229,28 @@ void HybridFit::Fit(Tracklet* tracklet, std::vector& trackstublist) } tracklet->setFitPars(rinvfit, - phi0fit, - d0, - trk.tanLambda(), - trk.z0(), - chi2rphi, - trk.chi2rz(), - rinvfit, - phi0fit, - d0, - trk.tanLambda(), - trk.z0(), - chi2rphi, - trk.chi2rz(), - irinvfit, - iphi0fit, - id0fit, - itanlfit, - iz0fit, - ichi2rphifit, - ichi2rzfit, - trk.hitPattern(), - l1stubsFromFit); + phi0fit, + d0, + trk.tanLambda(), + trk.z0(), + chi2rphi, + trk.chi2rz(), + rinvfit, + phi0fit, + d0, + trk.tanLambda(), + trk.z0(), + chi2rphi, + trk.chi2rz(), + irinvfit, + iphi0fit, + id0fit, + itanlfit, + iz0fit, + ichi2rphifit, + ichi2rzfit, + trk.hitPattern(), + l1stubsFromFit); } else { if (settings_.printDebugKF()) { edm::LogVerbatim("L1track") << "FitTrack:KF rejected track"; diff --git a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc index b9891452f3283..f63e1ece941d8 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc @@ -19,10 +19,13 @@ using namespace std; using namespace trklet; MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global), phimatchcuttable_(settings), zmatchcuttable_(settings), - rphicutPStable_(settings), rphicut2Stable_(settings), - rcutPStable_(settings), rcut2Stable_(settings) { - + : ProcessBase(name, settings, global), + phimatchcuttable_(settings), + zmatchcuttable_(settings), + rphicutPStable_(settings), + rphicut2Stable_(settings), + rcutPStable_(settings), + rcut2Stable_(settings) { phiregion_ = name[8] - 'A'; layerdisk_ = initLayerDisk(3); @@ -46,9 +49,9 @@ MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* phi0shift_ = 0; } - unsigned int region = getName()[8]-'A'; + unsigned int region = getName()[8] - 'A'; assert(region < settings_.nallstubs(layerdisk_)); - + if (layerdisk_ < N_LAYER) { phimatchcuttable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::barrelphi, region); zmatchcuttable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::barrelz, region); @@ -58,7 +61,7 @@ MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* rcutPStable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::diskPSr, region); rcut2Stable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::disk2Sr, region); } - + for (unsigned int i = 0; i < N_DSS_MOD * 2; i++) { ialphafactinner_[i] = (1 << settings_.alphashift()) * settings_.krprojshiftdisk() * settings_.half2SmoduleWidth() / (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSinner(i) * settings_.rDSSinner(i)) / @@ -213,16 +216,17 @@ void MatchCalculator::execute(double phioffset) { << ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_) << " " << dphiapprox * settings_.rmean(layerdisk_) << " " << phimatchcuttable_.lookup(seedindex) * settings_.kphi1() * settings_.rmean(layerdisk_) << " " - << ideltaz * fact_ * settings_.kz() << " " << dz << " " << zmatchcuttable_.lookup(seedindex) * settings_.kz() << endl; + << ideltaz * fact_ * settings_.kz() << " " << dz << " " + << zmatchcuttable_.lookup(seedindex) * settings_.kz() << endl; } bool imatch = (std::abs(ideltaphi) <= (int)phimatchcuttable_.lookup(seedindex)) && - (std::abs(ideltaz * fact_) <= (int)zmatchcuttable_.lookup(seedindex)); + (std::abs(ideltaz * fact_) <= (int)zmatchcuttable_.lookup(seedindex)); if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " ideltaphi cut " << ideltaphi << " " - << phimatchcuttable_.lookup(seedindex) << " ideltaz*fact cut " << ideltaz * fact_ << " " - << zmatchcuttable_.lookup(seedindex); + << phimatchcuttable_.lookup(seedindex) << " ideltaz*fact cut " << ideltaz * fact_ + << " " << zmatchcuttable_.lookup(seedindex); } if (imatch) { @@ -361,7 +365,8 @@ void MatchCalculator::execute(double phioffset) { double drcut = idrcut * settings_.krprojshiftdisk(); bool match, imatch; - if (std::abs(dphi) < third*settings_.dphisectorHG() && std::abs(dphiapprox) < third*settings_.dphisectorHG()) { //1/3 of sector size to catch errors + if (std::abs(dphi) < third * settings_.dphisectorHG() && + std::abs(dphiapprox) < third * settings_.dphisectorHG()) { //1/3 of sector size to catch errors if (settings_.writeMonitorData("Residuals")) { double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv()); diff --git a/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc b/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc index de08e2cb88a91..4338f63b9a7ac 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc @@ -15,8 +15,8 @@ using namespace std; using namespace trklet; -MatchEngine::MatchEngine(string name, Settings const& settings, Globals* global) : ProcessBase(name, settings, global), - luttable_(settings) { +MatchEngine::MatchEngine(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global), luttable_(settings) { layerdisk_ = initLayerDisk(3); barrel_ = layerdisk_ < N_LAYER; @@ -24,7 +24,6 @@ MatchEngine::MatchEngine(string name, Settings const& settings, Globals* global) luttable_.initBendMatch(layerdisk_); nrinv_ = NRINVBITS; - } void MatchEngine::addOutput(MemoryBase* memory, string output) { @@ -236,8 +235,8 @@ void MatchEngine::execute() { bool passphi = (std::abs(deltaphi) < mindeltaphicut) || (std::abs(deltaphi) > maxdeltaphicut); unsigned int index = (projrinv << nbits) + vmstub.bend().value(); - if (!barrel_&&isPSmodule) { - index += (1 << (nrinv_ + N_BENDBITS_2S)); + if (!barrel_ && isPSmodule) { + index += (1 << (nrinv_ + N_BENDBITS_2S)); } //Check if stub z position consistent diff --git a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc index 20c8ab9e1b329..ac4db12247b2a 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc @@ -4,7 +4,8 @@ using namespace std; using namespace trklet; -MatchEngineUnit::MatchEngineUnit(bool barrel, unsigned int layerdisk, const TrackletLUT& luttable) : luttable_(luttable), candmatches_(3) { +MatchEngineUnit::MatchEngineUnit(bool barrel, unsigned int layerdisk, const TrackletLUT& luttable) + : luttable_(luttable), candmatches_(3) { idle_ = true; barrel_ = barrel; layerdisk_ = layerdisk; @@ -28,7 +29,7 @@ void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory, bool usesecondPlus, bool isPSseed, Tracklet* proj, - bool) { + bool) { vmstubsmemory_ = vmstubsmemory; idle_ = false; nrzbins_ = nrzbins; @@ -66,18 +67,15 @@ void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory, havepair__ = havepair_; goodpair__ = goodpair_; - tmppair__ = tmppair_; + tmppair__ = tmppair_; havepair_ = false; goodpair_ = false; - - } void MatchEngineUnit::step(bool) { - bool almostfull = candmatches_.nearfull(); - + if (goodpair__) { assert(havepair__); candmatches_.store(tmppair__); @@ -85,11 +83,11 @@ void MatchEngineUnit::step(bool) { havepair__ = havepair_; goodpair__ = goodpair_; - tmppair__ = tmppair_; + tmppair__ = tmppair_; havepair_ = false; goodpair_ = false; - + if (idle() || almostfull) return; @@ -150,10 +148,10 @@ void MatchEngineUnit::step(bool) { // << isPSseed_ << " slot=" << slot << endl; //Check if stub bend and proj rinv consistent - + goodpair_ = (pass && dphicut) && luttable_.lookup(index); havepair_ = true; - + if (havepair_) { std::pair tmppair(proj_, vmstub.stub()); tmppair_ = tmppair; @@ -181,12 +179,11 @@ void MatchEngineUnit::reset() { } int MatchEngineUnit::TCID() const { - if (!empty()) { return peek().first->TCID(); } - if (idle_&&!havepair_&&!havepair__) { + if (idle_ && !havepair_ && !havepair__) { return 16383; } if (havepair__) { @@ -196,5 +193,4 @@ int MatchEngineUnit::TCID() const { return tmppair_.first->TCID(); } return proj_->TCID(); - } diff --git a/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc b/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc index 5723a4dcce56c..6c0526337f9b4 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc @@ -14,11 +14,17 @@ using namespace std; using namespace trklet; MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global), - phimatchcuttable_(settings), zmatchcuttable_(settings), rphicutPStable_(settings), - rphicut2Stable_(settings), rcutPStable_(settings), rcut2Stable_(settings), - fullmatches_(12), rinvbendlut_(settings), luttable_(settings), inputProjBuffer_(3) { - + : ProcessBase(name, settings, global), + phimatchcuttable_(settings), + zmatchcuttable_(settings), + rphicutPStable_(settings), + rphicut2Stable_(settings), + rcutPStable_(settings), + rcut2Stable_(settings), + fullmatches_(12), + rinvbendlut_(settings), + luttable_(settings), + inputProjBuffer_(3) { phiregion_ = name[8] - 'A'; layerdisk_ = initLayerDisk(3); @@ -42,12 +48,13 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g nphiderbits_ = 6; if (!barrel_) { - rinvbendlut_.initProjectionBend(global->ITC_L1L2()->der_phiD_final.K(), layerdisk_-N_LAYER, nrbits_, nphiderbits_); + rinvbendlut_.initProjectionBend( + global->ITC_L1L2()->der_phiD_final.K(), layerdisk_ - N_LAYER, nrbits_, nphiderbits_); } nrinv_ = NRINVBITS; - unsigned int region = getName()[8]-'A'; + unsigned int region = getName()[8] - 'A'; assert(region < settings_.nallstubs(layerdisk_)); if (barrel_) { @@ -59,7 +66,7 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g rcutPStable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::diskPSr, region); rcut2Stable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::disk2Sr, region); } - + for (unsigned int i = 0; i < N_DSS_MOD * 2; i++) { ialphafactinner_[i] = (1 << settings_.alphashift()) * settings_.krprojshiftdisk() * settings_.half2SmoduleWidth() / (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSinner(i) * settings_.rDSSinner(i)) / @@ -78,7 +85,6 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g MatchEngineUnit tmpME(barrel_, layerdisk_, luttable_); matchengines_.push_back(tmpME); } - } void MatchProcessor::addOutput(MemoryBase* memory, string output) { @@ -125,7 +131,6 @@ void MatchProcessor::addInput(MemoryBase* memory, string input) { } void MatchProcessor::execute(unsigned int iSector, double phimin) { - assert(vmstubs_.size() == 1); /* @@ -155,11 +160,10 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { unsigned int countinputproj = 0; unsigned int iprojmem = 0; - while (iprojmemnTracklets()==0) { + while (iprojmem < inputprojs_.size() && inputprojs_[iprojmem]->nTracklets() == 0) { iprojmem++; - } + } - unsigned int iproj = 0; inputProjBuffer_.reset(); @@ -172,14 +176,12 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { matchengine.reset(); } - ProjectionTemp tmpProj_, tmpProj__; bool good_ = false; bool good__ = false; - - for (unsigned int istep = 0; istep < settings_.maxStep("MP"); istep++) { - bool projBuffNearFull=inputProjBuffer_.nearfull(); + for (unsigned int istep = 0; istep < settings_.maxStep("MP"); istep++) { + bool projBuffNearFull = inputProjBuffer_.nearfull(); // This print statement is useful for detailed comparison with the HLS code // It prints out detailed status information for each clock step @@ -208,10 +210,10 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { bool meactive = matchengines_[0].active(); for (unsigned int iME = 1; iME < nMatchEngines_; iME++) { meactive = meactive || matchengines_[iME].active(); - int tcid=matchengines_[iME].TCID(); - if (tcidTCID()<<" "<TCID()<<" "<TCID()<<" "<TCID()<<" "<TCID() <= tracklet->TCID()); } oldTracklet = tracklet; @@ -241,7 +243,7 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { //Step 2 //Check if we have ME that can process projection - + bool addedProjection = false; for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { if (!matchengines_[iME].idle()) @@ -257,8 +259,8 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { int nbins = (1 << N_RZBITS); if (layerdisk_ >= N_LAYER) { - nbins*=2; //twice as many bins in disks (since there are two disks) - } + nbins *= 2; //twice as many bins in disks (since there are two disks) + } matchengines_[iME].init(stubmem, nbins, @@ -274,16 +276,13 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { tmpProj.use(1, 1), tmpProj.isPSseed(), tmpProj.proj(), - print&&(iME==0)); + print && (iME == 0)); addedProjection = true; } else { - matchengines_[iME].step(print&&iME==0); + matchengines_[iME].step(print && iME == 0); } - } - - //Step 1 //First step here checks if we have more input projections to put into //the input puffer for projections @@ -296,127 +295,126 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { tmpProj__ = tmpProj_; good_ = false; - + if (istep < settings_.maxStep("MP")) { if (iprojmem < inputprojs_.size()) { TrackletProjectionsMemory* projMem = inputprojs_[iprojmem]; - if (!projBuffNearFull) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << getName() << " have projection in memory : " << projMem->getName(); - } - - Tracklet* proj = projMem->getTracklet(iproj); - - FPGAWord fpgaphi = proj->proj(layerdisk_).fpgaphiproj(); - - unsigned int iphi = (fpgaphi.value() >> (fpgaphi.nbits() - nvmbits_)) & (nvmbins_ - 1); - - int nextrabits = 2; - int overlapbits = nvmbits_ + nextrabits; - - unsigned int extrabits = fpgaphi.bits(fpgaphi.nbits() - overlapbits, nextrabits); - - unsigned int ivmPlus = iphi; - - int shift = 0; - - if (extrabits == ((1U << nextrabits) - 1) && iphi != ((1U << settings_.nbitsvmme(layerdisk_)) - 1)) { - shift = 1; - ivmPlus++; - } - unsigned int ivmMinus = iphi; - if (extrabits == 0 && iphi != 0) { - shift = -1; - ivmMinus--; - } - - int projrinv = -1; - if (barrel_) { - FPGAWord phider = proj->proj(layerdisk_).fpgaphiprojder(); - projrinv = (1 << (nrinv_ - 1)) - 1 - (phider.value() >> (phider.nbits() - nrinv_)); - } else { - //The next lines looks up the predicted bend based on: - // 1 - r projections - // 2 - phi derivative - // 3 - the sign - i.e. if track is forward or backward - - int rindex = (proj->proj(layerdisk_).fpgarzproj().value() >> - (proj->proj(layerdisk_).fpgarzproj().nbits() - nrbits_)) & - ((1 << nrbits_) - 1); - - int phiderindex = (proj->proj(layerdisk_).fpgaphiprojder().value() >> - (proj->proj(layerdisk_).fpgaphiprojder().nbits() - nphiderbits_)) & - ((1 << nphiderbits_) - 1); - - int signindex = proj->proj(layerdisk_).fpgarzprojder().value() < 0; - - int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; - - projrinv = rinvbendlut_.lookup(bendindex); - - proj->proj(layerdisk_).setBendIndex(projrinv); - } - assert(projrinv >= 0); - - unsigned int slot = proj->proj(layerdisk_).fpgarzbin1projvm().value(); - bool second = proj->proj(layerdisk_).fpgarzbin2projvm().value(); - - unsigned int projfinephi = (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + NFINEPHIBITS))) & ((1<proj(layerdisk_).fpgafinerzvm().value(); - - bool isPSseed = proj->PSseed(); - - int nbins = (1 << N_RZBITS); - if (layerdisk_ >= N_LAYER) { - nbins*=2; //twice as many bins in disks (since there are two disks) - } - - VMStubsMEMemory* stubmem = vmstubs_[0]; - bool usefirstMinus = stubmem->nStubsBin(ivmMinus * nbins + slot) != 0; - bool usesecondMinus = (second && (stubmem->nStubsBin(ivmMinus * nbins + slot + 1) != 0)); - bool usefirstPlus = ivmPlus != ivmMinus && stubmem->nStubsBin(ivmPlus * nbins + slot) != 0; - bool usesecondPlus = - ivmPlus != ivmMinus && (second && (stubmem->nStubsBin(ivmPlus * nbins + slot + 1) != 0)); - - good_ = usefirstPlus || usesecondPlus || usefirstMinus || usesecondMinus; - - if (good_) { - ProjectionTemp tmpProj(proj, - slot, - projrinv, - projfinerz, - projfinephi, - ivmMinus, - shift, - usefirstMinus, - usefirstPlus, - usesecondMinus, - usesecondPlus, - isPSseed); - tmpProj_ = tmpProj; - } - - iproj++; - if (iproj == projMem->nTracklets()) { - iproj = 0; - do { - iprojmem++; - } while (iprojmemnTracklets()==0); - } - } - + if (!projBuffNearFull) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " have projection in memory : " << projMem->getName(); + } + + Tracklet* proj = projMem->getTracklet(iproj); + + FPGAWord fpgaphi = proj->proj(layerdisk_).fpgaphiproj(); + + unsigned int iphi = (fpgaphi.value() >> (fpgaphi.nbits() - nvmbits_)) & (nvmbins_ - 1); + + int nextrabits = 2; + int overlapbits = nvmbits_ + nextrabits; + + unsigned int extrabits = fpgaphi.bits(fpgaphi.nbits() - overlapbits, nextrabits); + + unsigned int ivmPlus = iphi; + + int shift = 0; + + if (extrabits == ((1U << nextrabits) - 1) && iphi != ((1U << settings_.nbitsvmme(layerdisk_)) - 1)) { + shift = 1; + ivmPlus++; + } + unsigned int ivmMinus = iphi; + if (extrabits == 0 && iphi != 0) { + shift = -1; + ivmMinus--; + } + + int projrinv = -1; + if (barrel_) { + FPGAWord phider = proj->proj(layerdisk_).fpgaphiprojder(); + projrinv = (1 << (nrinv_ - 1)) - 1 - (phider.value() >> (phider.nbits() - nrinv_)); + } else { + //The next lines looks up the predicted bend based on: + // 1 - r projections + // 2 - phi derivative + // 3 - the sign - i.e. if track is forward or backward + + int rindex = (proj->proj(layerdisk_).fpgarzproj().value() >> + (proj->proj(layerdisk_).fpgarzproj().nbits() - nrbits_)) & + ((1 << nrbits_) - 1); + + int phiderindex = (proj->proj(layerdisk_).fpgaphiprojder().value() >> + (proj->proj(layerdisk_).fpgaphiprojder().nbits() - nphiderbits_)) & + ((1 << nphiderbits_) - 1); + + int signindex = proj->proj(layerdisk_).fpgarzprojder().value() < 0; + + int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; + + projrinv = rinvbendlut_.lookup(bendindex); + + proj->proj(layerdisk_).setBendIndex(projrinv); + } + assert(projrinv >= 0); + + unsigned int slot = proj->proj(layerdisk_).fpgarzbin1projvm().value(); + bool second = proj->proj(layerdisk_).fpgarzbin2projvm().value(); + + unsigned int projfinephi = + (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + NFINEPHIBITS))) & ((1 << NFINEPHIBITS) - 1); + int projfinerz = proj->proj(layerdisk_).fpgafinerzvm().value(); + + bool isPSseed = proj->PSseed(); + + int nbins = (1 << N_RZBITS); + if (layerdisk_ >= N_LAYER) { + nbins *= 2; //twice as many bins in disks (since there are two disks) + } + + VMStubsMEMemory* stubmem = vmstubs_[0]; + bool usefirstMinus = stubmem->nStubsBin(ivmMinus * nbins + slot) != 0; + bool usesecondMinus = (second && (stubmem->nStubsBin(ivmMinus * nbins + slot + 1) != 0)); + bool usefirstPlus = ivmPlus != ivmMinus && stubmem->nStubsBin(ivmPlus * nbins + slot) != 0; + bool usesecondPlus = ivmPlus != ivmMinus && (second && (stubmem->nStubsBin(ivmPlus * nbins + slot + 1) != 0)); + + good_ = usefirstPlus || usesecondPlus || usefirstMinus || usesecondMinus; + + if (good_) { + ProjectionTemp tmpProj(proj, + slot, + projrinv, + projfinerz, + projfinephi, + ivmMinus, + shift, + usefirstMinus, + usefirstPlus, + usesecondMinus, + usesecondPlus, + isPSseed); + tmpProj_ = tmpProj; + } + + iproj++; + if (iproj == projMem->nTracklets()) { + iproj = 0; + do { + iprojmem++; + } while (iprojmem < inputprojs_.size() && inputprojs_[iprojmem]->nTracklets() == 0); + } + } + } else { projdone = true && !good_ && !good__; } } - // // Check if done // // // - + if ((projdone && !meactive) || (istep == settings_.maxStep("MP") - 1)) { if (settings_.writeMonitorData("MP")) { globals_->ofstream("matchprocessor.txt") << getName() << " " << istep << " " << countall << " " << countsel @@ -503,17 +501,17 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b << ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_) << " " << dphiapprox * settings_.rmean(layerdisk_) << " " << phimatchcuttable_.lookup(seedindex) * settings_.kphi1() * settings_.rmean(layerdisk_) << " " - << (ideltaz << dzshift_) * settings_.kz() << " " << dz << " " << zmatchcuttable_.lookup(seedindex) * settings_.kz() - << endl; + << (ideltaz << dzshift_) * settings_.kz() << " " << dz << " " + << zmatchcuttable_.lookup(seedindex) * settings_.kz() << endl; } bool imatch = (std::abs(ideltaphi) <= phimatchcuttable_.lookup(seedindex)) && - (std::abs(ideltaz << dzshift_) <= zmatchcuttable_.lookup(seedindex)); + (std::abs(ideltaz << dzshift_) <= zmatchcuttable_.lookup(seedindex)); if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " ideltaphi cut " << ideltaphi << " " - << phimatchcuttable_.lookup(seedindex) << " ideltaz<= third*settings_.dphisectorHG()) { + if (std::abs(dphi) >= third * settings_.dphisectorHG()) { edm::LogPrint("Tracklet") << "dphi " << dphi << " ISeed " << tracklet->getISeed(); } - assert(std::abs(dphi) < third*settings_.dphisectorHG()); - assert(std::abs(dphiapprox) < third*settings_.dphisectorHG()); + assert(std::abs(dphi) < third * settings_.dphisectorHG()); + assert(std::abs(dphiapprox) < third * settings_.dphisectorHG()); tracklet->addMatch(layerdisk_, ideltaphi, diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc index ca0aea33c6e5c..0e59a8b0dafc2 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc @@ -5,7 +5,6 @@ #include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" #include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" - #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" @@ -13,7 +12,7 @@ using namespace std; using namespace trklet; ProjectionRouter::ProjectionRouter(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global), rinvbendlut_(settings) { + : ProcessBase(name, settings, global), rinvbendlut_(settings) { layerdisk_ = initLayerDisk(3); vmprojs_.resize(settings_.nvmme(layerdisk_), nullptr); @@ -22,9 +21,9 @@ ProjectionRouter::ProjectionRouter(string name, Settings const& settings, Global nphiderbits_ = 6; if (layerdisk_ >= N_LAYER) { - rinvbendlut_.initProjectionBend(global->ITC_L1L2()->der_phiD_final.K(), layerdisk_-N_LAYER, nrbits_, nphiderbits_); + rinvbendlut_.initProjectionBend( + global->ITC_L1L2()->der_phiD_final.K(), layerdisk_ - N_LAYER, nrbits_, nphiderbits_); } - } void ProjectionRouter::addOutput(MemoryBase* memory, string output) { @@ -74,7 +73,6 @@ void ProjectionRouter::addInput(MemoryBase* memory, string input) { } void ProjectionRouter::execute() { - unsigned int allprojcount = 0; //These are just here to test that the order is correct. Does not affect the actual execution @@ -93,7 +91,6 @@ void ProjectionRouter::execute() { if (layerdisk_ < N_LAYER) { fpgaphi = tracklet->proj(layerdisk_).fpgaphiproj(); } else { - Projection& proj = tracklet->proj(layerdisk_); fpgaphi = proj.fpgaphiproj(); @@ -111,7 +108,7 @@ void ProjectionRouter::execute() { int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; - int ibendproj = rinvbendlut_.lookup(bendindex); + int ibendproj = rinvbendlut_.lookup(bendindex); proj.setBendIndex(ibendproj); } diff --git a/L1Trigger/TrackFindingTracklet/src/Sector.cc b/L1Trigger/TrackFindingTracklet/src/Sector.cc index 6127d60c87670..a1f0ade45f3b9 100644 --- a/L1Trigger/TrackFindingTracklet/src/Sector.cc +++ b/L1Trigger/TrackFindingTracklet/src/Sector.cc @@ -80,7 +80,7 @@ bool Sector::addStub(L1TStub stub, string dtc) { int bendbin = fpgastub.bend().value(); int rbin = (r.value() + (1 << (r.nbits() - 1))) >> (r.nbits() - 3); const TrackletLUT& phiCorrTable = *globals_->phiCorr(layerdisk); - int iphicorr = phiCorrTable.lookup(bendbin*(1<<3)+rbin); + int iphicorr = phiCorrTable.lookup(bendbin * (1 << 3) + rbin); fpgastub.setPhiCorr(iphicorr); } diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc b/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc index 2cf5d706aae4e..a02bdd1edd40a 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc @@ -772,7 +772,7 @@ void TrackletConfigBuilder::writeASMemories(std::ostream& os, std::ostream& memo } if (ext == "") { - ext = "_" + LayerName(l1)+iTCStr(iTC); + ext = "_" + LayerName(l1) + iTCStr(iTC); } if (iSeed < 4) { //Barrel seeding @@ -960,17 +960,18 @@ void TrackletConfigBuilder::writeVMSMemories(std::ostream& os, std::ostream& mem if (!used) continue; - string inorout = "I"; - if (innerouterseed == 1 ) - inorout = "O"; - + string inorout = "I"; + if (innerouterseed == 1) + inorout = "O"; + nmem++; memories << "VMStubsTE: VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << iVMTE + 1 << "n" << nmem << " [18]" << std::endl; os << "VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << iVMTE + 1 << "n" << nmem - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutTE"< TE_" << LayerName(l1) << "PHI" << iRegStr(TE1 / NVMTE1, iSeed) << TE1 + 1 - << "_" << LayerName(l2) << "PHI" << iRegStr(TE2 / NVMTE2, iSeed) << TE2 + 1; + << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutTE" << inorout << "PHI" + << iRegStr(iReg, iSeed) << iVMTE + 1 << " output=> TE_" << LayerName(l1) << "PHI" + << iRegStr(TE1 / NVMTE1, iSeed) << TE1 + 1 << "_" << LayerName(l2) << "PHI" + << iRegStr(TE2 / NVMTE2, iSeed) << TE2 + 1; if (innerouterseed == 0) { os << ".innervmstubin" << std::endl; } else { diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc index e4d71c40de799..1c70057008575 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc @@ -14,7 +14,7 @@ using namespace trklet; using namespace std; TrackletEngine::TrackletEngine(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global), innerptlut_(settings), outerptlut_(settings) { + : ProcessBase(name, settings, global), innerptlut_(settings), outerptlut_(settings) { stubpairs_ = nullptr; innervmstubs_ = nullptr; outervmstubs_ = nullptr; @@ -160,32 +160,66 @@ void TrackletEngine::setVMPhiBin() { string innermem = innervmstubs_->getName().substr(6); string outermem = outervmstubs_->getName().substr(6); - - innerptlut_.initteptlut(true, false, iSeed_, layerdisk1_, layerdisk2_, - innerphibits_, outerphibits_, - innerphimin, innerphimax, outerphimin, outerphimax, - innermem, outermem); - outerptlut_.initteptlut(false, false, iSeed_, layerdisk1_, layerdisk2_, - innerphibits_, outerphibits_, - innerphimin, innerphimax, outerphimin, outerphimax, - innermem, outermem); + innerptlut_.initteptlut(true, + false, + iSeed_, + layerdisk1_, + layerdisk2_, + innerphibits_, + outerphibits_, + innerphimin, + innerphimax, + outerphimin, + outerphimax, + innermem, + outermem); + + outerptlut_.initteptlut(false, + false, + iSeed_, + layerdisk1_, + layerdisk2_, + innerphibits_, + outerphibits_, + innerphimin, + innerphimax, + outerphimin, + outerphimax, + innermem, + outermem); TrackletLUT innertememlut(settings_); TrackletLUT outertememlut(settings_); - - innertememlut.initteptlut(true, true, iSeed_, layerdisk1_, layerdisk2_, - innerphibits_, outerphibits_, - innerphimin, innerphimax, outerphimin, outerphimax, - innermem, outermem); - - outertememlut.initteptlut(false, true, iSeed_, layerdisk1_, layerdisk2_, - innerphibits_, outerphibits_, - innerphimin, innerphimax, outerphimin, outerphimax, - innermem, outermem); + + innertememlut.initteptlut(true, + true, + iSeed_, + layerdisk1_, + layerdisk2_, + innerphibits_, + outerphibits_, + innerphimin, + innerphimax, + outerphimin, + outerphimax, + innermem, + outermem); + + outertememlut.initteptlut(false, + true, + iSeed_, + layerdisk1_, + layerdisk2_, + innerphibits_, + outerphibits_, + innerphimin, + innerphimax, + outerphimin, + outerphimax, + innermem, + outermem); innervmstubs_->setbendtable(innertememlut); outervmstubs_->setbendtable(outertememlut); - } - diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc index dcb0370ea4e77..3f4f4555959d9 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc @@ -12,10 +12,10 @@ TrackletEngineUnit::TrackletEngineUnit(const Settings* const settings, unsigned int iSeed, unsigned int nbitsfinephidiff, unsigned int iAllStub, - const TrackletLUT* pttableinnernew, - const TrackletLUT* pttableouternew, + const TrackletLUT* pttableinnernew, + const TrackletLUT* pttableouternew, VMStubsTEMemory* outervmstubs) -: settings_(settings), pttableinnernew_(pttableinnernew), pttableouternew_(pttableouternew), candpairs_(3) { + : settings_(settings), pttableinnernew_(pttableinnernew), pttableouternew_(pttableouternew), candpairs_(3) { idle_ = true; nbitsfinephi_ = nbitsfinephi; layerdisk2_ = layerdisk2; @@ -43,7 +43,6 @@ void TrackletEngineUnit::reset() { } void TrackletEngineUnit::step(bool, int, int) { - if (goodpair__) { candpairs_.store(candpair__); } @@ -100,7 +99,7 @@ void TrackletEngineUnit::step(bool, int, int) { int ptinnerindex = (idphi << tedata_.innerbend_.nbits()) + tedata_.innerbend_.value(); int ptouterindex = (idphi << outerbend.nbits()) + outerbend.value(); - + if (!(inrange && pttableinnernew_->lookup(ptinnerindex) && pttableouternew_->lookup(ptouterindex))) { if (settings_->debugTracklet()) { edm::LogVerbatim("Tracklet") << " Stub pair rejected because of stub pt cut bends : " diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc b/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc index adfb887177ce4..59e4aa96be1c8 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc @@ -11,72 +11,71 @@ using namespace trklet; TrackletLUT::TrackletLUT(const Settings& settings) : settings_(settings) {} void TrackletLUT::initmatchcut(unsigned int layerdisk, MatchType type, unsigned int region) { + char cregion = 'A' + region; - char cregion = 'A'+region; - for (unsigned int iSeed = 0; iSeed < 12; iSeed++) { - if (type==barrelphi) { + if (type == barrelphi) { table_.push_back(settings_.rphimatchcut(iSeed, layerdisk) / (settings_.kphi1() * settings_.rmean(layerdisk))); } - if (type==barrelz) { + if (type == barrelz) { table_.push_back(settings_.zmatchcut(iSeed, layerdisk) / settings_.kz()); } - if (type==diskPSphi) { + if (type == diskPSphi) { table_.push_back(settings_.rphicutPS(iSeed, layerdisk - N_LAYER) / (settings_.kphi() * settings_.kr())); } - if (type==disk2Sphi) { + if (type == disk2Sphi) { table_.push_back(settings_.rphicut2S(iSeed, layerdisk - N_LAYER) / (settings_.kphi() * settings_.kr())); } - if (type==disk2Sr) { + if (type == disk2Sr) { table_.push_back(settings_.rcut2S(iSeed, layerdisk - N_LAYER) / settings_.krprojshiftdisk()); } - if (type==diskPSr) { + if (type == diskPSr) { table_.push_back(settings_.rcutPS(iSeed, layerdisk - N_LAYER) / settings_.krprojshiftdisk()); } } - name_ = settings_.combined() ? "MP_" : "MC_"; + name_ = settings_.combined() ? "MP_" : "MC_"; - if (type==barrelphi) { - name_ += TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_phicut.tab"; - } - if (type==barrelz) { - name_ += TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_zcut.tab"; + if (type == barrelphi) { + name_ += TrackletConfigBuilder::LayerName(layerdisk) + "PHI" + cregion + "_phicut.tab"; + } + if (type == barrelz) { + name_ += TrackletConfigBuilder::LayerName(layerdisk) + "PHI" + cregion + "_zcut.tab"; } - if (type==diskPSphi) { - name_ += TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_PSphicut.tab"; + if (type == diskPSphi) { + name_ += TrackletConfigBuilder::LayerName(layerdisk) + "PHI" + cregion + "_PSphicut.tab"; } - if (type==disk2Sphi) { - name_ += TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_2Sphicut.tab"; + if (type == disk2Sphi) { + name_ += TrackletConfigBuilder::LayerName(layerdisk) + "PHI" + cregion + "_2Sphicut.tab"; } - if (type==disk2Sr) { - name_ += TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_2Srcut.tab"; + if (type == disk2Sr) { + name_ += TrackletConfigBuilder::LayerName(layerdisk) + "PHI" + cregion + "_2Srcut.tab"; } - if (type==diskPSr) { - name_ += TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_PSrcut.tab"; + if (type == diskPSr) { + name_ += TrackletConfigBuilder::LayerName(layerdisk) + "PHI" + cregion + "_PSrcut.tab"; } positive_ = false; - - writeTable(); + writeTable(); } - -void TrackletLUT::initTPlut(bool fillInner, unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, - unsigned int nbitsfinephidiff, unsigned int iTP) { - +void TrackletLUT::initTPlut(bool fillInner, + unsigned int iSeed, + unsigned int layerdisk1, + unsigned int layerdisk2, + unsigned int nbitsfinephidiff, + unsigned int iTP) { //number of fine phi bins in sector - int nfinephibins = - settings_.nallstubs(layerdisk2) * settings_.nvmte(1, iSeed) * (1 << settings_.nfinephi(1, iSeed)); + int nfinephibins = settings_.nallstubs(layerdisk2) * settings_.nvmte(1, iSeed) * (1 << settings_.nfinephi(1, iSeed)); double dfinephi = settings_.dphisectorHG() / nfinephibins; int outerrbits = 3; - if (iSeed == Seed::L1L2 || iSeed == Seed::L2L3 ||iSeed == Seed::L3L4 || iSeed == Seed::L5L6 ) { + if (iSeed == Seed::L1L2 || iSeed == Seed::L2L3 || iSeed == Seed::L3L4 || iSeed == Seed::L5L6) { outerrbits = 0; } - + int outerrbins = (1 << outerrbits); double dphi[2]; @@ -102,7 +101,7 @@ void TrackletLUT::initTPlut(bool fillInner, unsigned int iSeed, unsigned int lay dphi[0] = (iphidiff - 1.5) * dfinephi; dphi[1] = (iphidiff + 1.5) * dfinephi; for (int irouterbin = 0; irouterbin < outerrbins; irouterbin++) { - if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4 ||iSeed == Seed::L1D1 || iSeed == Seed::L2D1 ) { + if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4 || iSeed == Seed::L1D1 || iSeed == Seed::L2D1) { router[0] = settings_.rmindiskvm() + irouterbin * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins; router[1] = @@ -148,47 +147,49 @@ void TrackletLUT::initTPlut(bool fillInner, unsigned int iSeed, unsigned int lay bool passptcut = rinvmin < settings_.rinvcutte(); if (fillInner) { - for (int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) { - double bend = settings_.benddecode(ibend, layerdisk1, nbendbitsinner == 3); - - bool passinner = bend <= bendinnermax + settings_.bendcutte(ibend, layerdisk1, nbendbitsinner == 3) && - bend >= bendinnermin - settings_.bendcutte(ibend, layerdisk1, nbendbitsinner == 3); - table_.push_back(passinner && passptcut); - } + for (int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) { + double bend = settings_.benddecode(ibend, layerdisk1, nbendbitsinner == 3); + + bool passinner = bend <= bendinnermax + settings_.bendcutte(ibend, layerdisk1, nbendbitsinner == 3) && + bend >= bendinnermin - settings_.bendcutte(ibend, layerdisk1, nbendbitsinner == 3); + table_.push_back(passinner && passptcut); + } } else { - for (int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) { - double bend = settings_.benddecode(ibend, layerdisk2, nbendbitsouter == 3); - - bool passouter = bend <= bendoutermax + settings_.bendcutte(ibend, layerdisk2, nbendbitsouter == 3) && - bend >= bendoutermin - settings_.bendcutte(ibend, layerdisk2, nbendbitsouter == 3); - table_.push_back(passouter && passptcut); - } + for (int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) { + double bend = settings_.benddecode(ibend, layerdisk2, nbendbitsouter == 3); + + bool passouter = bend <= bendoutermax + settings_.bendcutte(ibend, layerdisk2, nbendbitsouter == 3) && + bend >= bendoutermin - settings_.bendcutte(ibend, layerdisk2, nbendbitsouter == 3); + table_.push_back(passouter && passptcut); + } } } } positive_ = false; - char cTP='A'+iTP; - - name_="TP_"+TrackletConfigBuilder::LayerName(layerdisk1)+TrackletConfigBuilder::LayerName(layerdisk2)+cTP; + char cTP = 'A' + iTP; + + name_ = "TP_" + TrackletConfigBuilder::LayerName(layerdisk1) + TrackletConfigBuilder::LayerName(layerdisk2) + cTP; if (fillInner) { - name_+="_stubptinnercut.tab"; + name_ += "_stubptinnercut.tab"; } else { - name_+="_stubptoutercut.tab"; + name_ += "_stubptoutercut.tab"; } - - writeTable(); + writeTable(); } - -void TrackletLUT::initTPregionlut(unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, - unsigned int iAllStub, unsigned int nbitsfinephidiff, unsigned int nbitsfinephi, - const TrackletLUT& tplutinner, unsigned int iTP) { - +void TrackletLUT::initTPregionlut(unsigned int iSeed, + unsigned int layerdisk1, + unsigned int layerdisk2, + unsigned int iAllStub, + unsigned int nbitsfinephidiff, + unsigned int nbitsfinephi, + const TrackletLUT& tplutinner, + unsigned int iTP) { int nirbits = 0; - if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4 ||iSeed == Seed::L1D1 || iSeed == Seed::L2D1 ) { + if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4 || iSeed == Seed::L1D1 || iSeed == Seed::L2D1) { nirbits = 3; } @@ -223,27 +224,34 @@ void TrackletLUT::initTPregionlut(unsigned int iSeed, unsigned int layerdisk1, u } table_.push_back(usereg); - } } } positive_ = false; - char cTP='A'+iTP; - - name_="TP_"+TrackletConfigBuilder::LayerName(layerdisk1)+TrackletConfigBuilder::LayerName(layerdisk2)+cTP+"_usereg.tab"; + char cTP = 'A' + iTP; + + name_ = "TP_" + TrackletConfigBuilder::LayerName(layerdisk1) + TrackletConfigBuilder::LayerName(layerdisk2) + cTP + + "_usereg.tab"; writeTable(); - } -void TrackletLUT::initteptlut(bool fillInner, bool fillTEMem, unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, - unsigned int innerphibits, unsigned int outerphibits, - double innerphimin, double innerphimax, double outerphimin, double outerphimax, - const std::string& innermem, const std::string& outermem) { - +void TrackletLUT::initteptlut(bool fillInner, + bool fillTEMem, + unsigned int iSeed, + unsigned int layerdisk1, + unsigned int layerdisk2, + unsigned int innerphibits, + unsigned int outerphibits, + double innerphimin, + double innerphimax, + double outerphimin, + double outerphimax, + const std::string& innermem, + const std::string& outermem) { int outerrbits = 0; - if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4 ||iSeed == Seed::L1D1 || iSeed == Seed::L2D1 ) { + if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4 || iSeed == Seed::L1D1 || iSeed == Seed::L2D1) { outerrbits = 3; } @@ -272,7 +280,7 @@ void TrackletLUT::initteptlut(bool fillInner, bool fillTEMem, unsigned int iSeed table_.resize((1 << nbendbitsouter), false); } } - + for (int iphiinnerbin = 0; iphiinnerbin < innerphibins; iphiinnerbin++) { phiinner[0] = innerphimin + iphiinnerbin * (innerphimax - innerphimin) / innerphibins; phiinner[1] = innerphimin + (iphiinnerbin + 1) * (innerphimax - innerphimin) / innerphibins; @@ -280,7 +288,7 @@ void TrackletLUT::initteptlut(bool fillInner, bool fillTEMem, unsigned int iSeed phiouter[0] = outerphimin + iphiouterbin * (outerphimax - outerphimin) / outerphibins; phiouter[1] = outerphimin + (iphiouterbin + 1) * (outerphimax - outerphimin) / outerphibins; for (int irouterbin = 0; irouterbin < outerrbins; irouterbin++) { - if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4 ||iSeed == Seed::L1D1 || iSeed == Seed::L2D1 ) { + if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4 || iSeed == Seed::L1D1 || iSeed == Seed::L2D1) { router[0] = settings_.rmindiskvm() + irouterbin * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins; router[1] = settings_.rmindiskvm() + @@ -328,36 +336,36 @@ void TrackletLUT::initteptlut(bool fillInner, bool fillTEMem, unsigned int iSeed bool passptcut = rinvmin < settings_.rinvcutte(); - if (fillInner) { - for (int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) { - double bend = settings_.benddecode(ibend, layerdisk1, nbendbitsinner == 3); - - bool passinner = bend > bendinnermin - settings_.bendcutte(ibend, layerdisk1, nbendbitsinner == 3) && - bend < bendinnermax + settings_.bendcutte(ibend, layerdisk1, nbendbitsinner == 3); - - if (fillTEMem) { - if (passinner) { - table_[ibend] = 1; - } - } else { - table_.push_back(passinner && passptcut); - } - } - } else { - for (int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) { - double bend = settings_.benddecode(ibend, layerdisk2, nbendbitsouter == 3); - - bool passouter = bend > bendoutermin - settings_.bendcutte(ibend, layerdisk2, nbendbitsouter == 3) && - bend < bendoutermax + settings_.bendcutte(ibend, layerdisk2, nbendbitsouter == 3); - if (fillTEMem) { - if (passouter) { - table_[ibend] = 1; - } - } else { - table_.push_back(passouter && passptcut); - } - } - } + if (fillInner) { + for (int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) { + double bend = settings_.benddecode(ibend, layerdisk1, nbendbitsinner == 3); + + bool passinner = bend > bendinnermin - settings_.bendcutte(ibend, layerdisk1, nbendbitsinner == 3) && + bend < bendinnermax + settings_.bendcutte(ibend, layerdisk1, nbendbitsinner == 3); + + if (fillTEMem) { + if (passinner) { + table_[ibend] = 1; + } + } else { + table_.push_back(passinner && passptcut); + } + } + } else { + for (int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) { + double bend = settings_.benddecode(ibend, layerdisk2, nbendbitsouter == 3); + + bool passouter = bend > bendoutermin - settings_.bendcutte(ibend, layerdisk2, nbendbitsouter == 3) && + bend < bendoutermax + settings_.bendcutte(ibend, layerdisk2, nbendbitsouter == 3); + if (fillTEMem) { + if (passouter) { + table_[ibend] = 1; + } + } else { + table_.push_back(passouter && passptcut); + } + } + } } } } @@ -366,91 +374,81 @@ void TrackletLUT::initteptlut(bool fillInner, bool fillTEMem, unsigned int iSeed if (fillTEMem) { if (fillInner) { - name_ = "VMSTE_"+innermem+"_vmbendcut.tab"; + name_ = "VMSTE_" + innermem + "_vmbendcut.tab"; } else { - name_ = "VMSTE_"+outermem+"_vmbendcut.tab"; + name_ = "VMSTE_" + outermem + "_vmbendcut.tab"; } } else { - name_ = "TE_"+innermem.substr(0,innermem.size()-2)+"_"+outermem.substr(0,outermem.size()-2); + name_ = "TE_" + innermem.substr(0, innermem.size() - 2) + "_" + outermem.substr(0, outermem.size() - 2); if (fillInner) { - name_+="_stubptinnercut.tab"; + name_ += "_stubptinnercut.tab"; } else { - name_+="_stubptoutercut.tab"; + name_ += "_stubptoutercut.tab"; } } - writeTable(); - } - void TrackletLUT::initProjectionBend(double k_phider, - unsigned int idisk, + unsigned int idisk, unsigned int nrbits, unsigned int nphiderbits) { - unsigned int nsignbins = 2; unsigned int nrbins = 1 << (nrbits); unsigned int nphiderbins = 1 << (nphiderbits); - + for (unsigned int isignbin = 0; isignbin < nsignbins; isignbin++) { for (unsigned int irbin = 0; irbin < nrbins; irbin++) { int ir = irbin; if (ir > (1 << (nrbits - 1))) - ir -= (1 << nrbits); + ir -= (1 << nrbits); ir = ir << (settings_.nrbitsstub(N_LAYER) - nrbits); for (unsigned int iphiderbin = 0; iphiderbin < nphiderbins; iphiderbin++) { - int iphider = iphiderbin; - if (iphider > (1 << (nphiderbits - 1))) - iphider -= (1 << nphiderbits); - iphider = iphider << (settings_.nbitsphiprojderL123() - nphiderbits); - - double rproj = ir * settings_.krprojshiftdisk(); - double phider = iphider * k_phider; - double t = settings_.zmean(idisk) / rproj; - - if (isignbin) - t = -t; - - double rinv = -phider * (2.0 * t); - - double stripPitch = (rproj < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); - double bendproj = bendstrip(rproj, rinv, stripPitch); - - int ibendproj = 2.0 * bendproj + 15.5; - if (ibendproj < 0) - ibendproj = 0; - if (ibendproj > 31) - ibendproj = 31; - - table_.push_back(ibendproj); + int iphider = iphiderbin; + if (iphider > (1 << (nphiderbits - 1))) + iphider -= (1 << nphiderbits); + iphider = iphider << (settings_.nbitsphiprojderL123() - nphiderbits); + + double rproj = ir * settings_.krprojshiftdisk(); + double phider = iphider * k_phider; + double t = settings_.zmean(idisk) / rproj; + + if (isignbin) + t = -t; + + double rinv = -phider * (2.0 * t); + + double stripPitch = (rproj < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double bendproj = bendstrip(rproj, rinv, stripPitch); + + int ibendproj = 2.0 * bendproj + 15.5; + if (ibendproj < 0) + ibendproj = 0; + if (ibendproj > 31) + ibendproj = 31; + + table_.push_back(ibendproj); } } } positive_ = false; name_ = settings_.combined() ? "MP_" : "PR_"; - name_ += "ProjectionBend_"+TrackletConfigBuilder::LayerName(N_LAYER+idisk)+".tab"; + name_ += "ProjectionBend_" + TrackletConfigBuilder::LayerName(N_LAYER + idisk) + ".tab"; writeTable(); - } - - - void TrackletLUT::initBendMatch(unsigned int layerdisk) { - unsigned int nrinv = NRINVBITS; double rinvhalf = 0.5 * ((1 << nrinv) - 1); bool barrel = layerdisk < N_LAYER; bool isPSmodule = layerdisk < N_PSLAYER; double stripPitch = settings_.stripPitch(isPSmodule); - - if (barrel) { + if (barrel) { unsigned int nbits = isPSmodule ? N_BENDBITS_PS : N_BENDBITS_2S; for (unsigned int irinv = 0; irinv < (1u << nrinv); irinv++) { @@ -484,15 +482,12 @@ void TrackletLUT::initBendMatch(unsigned int layerdisk) { positive_ = false; - name_ = "METable_"+TrackletConfigBuilder::LayerName(layerdisk)+".tab"; - - writeTable(); + name_ = "METable_" + TrackletConfigBuilder::LayerName(layerdisk) + ".tab"; + writeTable(); } - void TrackletLUT::initVMRTable(unsigned int layerdisk, VMRTableType type, int region) { - unsigned int zbits = settings_.vmrlutzbits(layerdisk); unsigned int rbits = settings_.vmrlutrbits(layerdisk); @@ -500,7 +495,7 @@ void TrackletLUT::initVMRTable(unsigned int layerdisk, VMRTableType type, int re unsigned int zbins = (1 << zbits); double zmin, zmax, rmin, rmax; - + if (layerdisk < N_LAYER) { zmin = -settings_.zlength(); zmax = settings_.zlength(); @@ -540,8 +535,8 @@ void TrackletLUT::initVMRTable(unsigned int layerdisk, VMRTableType type, int re } } - if (layerdisk >= N_LAYER && irbin < 10) //special case for the tabulated radii in 2S disks - r = (layerdisk < N_LAYER+2) ? settings_.rDSSinner(irbin) : settings_.rDSSouter(irbin); + if (layerdisk >= N_LAYER && irbin < 10) //special case for the tabulated radii in 2S disks + r = (layerdisk < N_LAYER + 2) ? settings_.rDSSinner(irbin) : settings_.rDSSouter(irbin); int bin; if (layerdisk < N_LAYER) { @@ -556,120 +551,115 @@ void TrackletLUT::initVMRTable(unsigned int layerdisk, VMRTableType type, int re if (bin >= NBINS) bin = NBINS - 1; - if (type == VMRTableType::me ) { - table_.push_back(bin); + if (type == VMRTableType::me) { + table_.push_back(bin); } - if (type == VMRTableType::disk ) { - if (layerdisk >= N_LAYER) { - double rproj = r * settings_.zmean(layerdisk - N_LAYER) / z; - bin = 0.5 * NBINS * (rproj - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm()); - //bin value of zero indicates that stub is out of range - if (bin < 0) - bin = 0; - if (bin >= NBINS / 2) - bin = 0; - table_.push_back(bin); - } + if (type == VMRTableType::disk) { + if (layerdisk >= N_LAYER) { + double rproj = r * settings_.zmean(layerdisk - N_LAYER) / z; + bin = 0.5 * NBINS * (rproj - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm()); + //bin value of zero indicates that stub is out of range + if (bin < 0) + bin = 0; + if (bin >= NBINS / 2) + bin = 0; + table_.push_back(bin); + } } - if (type == VMRTableType::inner ) { - if (layerdisk == LayerDisk::L1 || layerdisk == LayerDisk::L3 || layerdisk == LayerDisk::L5 || - layerdisk == LayerDisk::D1 || layerdisk == LayerDisk::D3) { - table_.push_back(getVMRLookup(layerdisk + 1, z, r, dz, dr)); - } - if (layerdisk == LayerDisk::L2) { - table_.push_back(getVMRLookup(layerdisk + 1, z, r, dz, dr, Seed::L2L3)); - } + if (type == VMRTableType::inner) { + if (layerdisk == LayerDisk::L1 || layerdisk == LayerDisk::L3 || layerdisk == LayerDisk::L5 || + layerdisk == LayerDisk::D1 || layerdisk == LayerDisk::D3) { + table_.push_back(getVMRLookup(layerdisk + 1, z, r, dz, dr)); + } + if (layerdisk == LayerDisk::L2) { + table_.push_back(getVMRLookup(layerdisk + 1, z, r, dz, dr, Seed::L2L3)); + } } - if (type == VMRTableType::inneroverlap ) { - if (layerdisk == LayerDisk::L1 || layerdisk == LayerDisk::L2) { - table_.push_back(getVMRLookup(6, z, r, dz, dr, layerdisk + 6)); - } - } - - - if (type == VMRTableType::innerthird ) { - if (layerdisk == LayerDisk::L2) { //projection from L2 to D1 for L2L3D1 seeding - table_.push_back(getVMRLookup(LayerDisk::D1, z, r, dz, dr, Seed::L2L3D1)); - } - - if (layerdisk == LayerDisk::L5) { //projection from L5 to L4 for L5L6L4 seeding - table_.push_back(getVMRLookup(LayerDisk::L4, z, r, dz, dr)); - } - - if (layerdisk == LayerDisk::L3) { //projection from L3 to L5 for L3L4L2 seeding - table_.push_back(getVMRLookup(LayerDisk::L2, z, r, dz, dr)); - } - - if (layerdisk == LayerDisk::D1) { //projection from D1 to L2 for D1D2L2 seeding - table_.push_back(getVMRLookup(LayerDisk::L2, z, r, dz, dr)); - } + if (type == VMRTableType::inneroverlap) { + if (layerdisk == LayerDisk::L1 || layerdisk == LayerDisk::L2) { + table_.push_back(getVMRLookup(6, z, r, dz, dr, layerdisk + 6)); + } } + if (type == VMRTableType::innerthird) { + if (layerdisk == LayerDisk::L2) { //projection from L2 to D1 for L2L3D1 seeding + table_.push_back(getVMRLookup(LayerDisk::D1, z, r, dz, dr, Seed::L2L3D1)); + } + + if (layerdisk == LayerDisk::L5) { //projection from L5 to L4 for L5L6L4 seeding + table_.push_back(getVMRLookup(LayerDisk::L4, z, r, dz, dr)); + } + + if (layerdisk == LayerDisk::L3) { //projection from L3 to L5 for L3L4L2 seeding + table_.push_back(getVMRLookup(LayerDisk::L2, z, r, dz, dr)); + } + + if (layerdisk == LayerDisk::D1) { //projection from D1 to L2 for D1D2L2 seeding + table_.push_back(getVMRLookup(LayerDisk::L2, z, r, dz, dr)); + } + } } } - if (settings_.combined()) { if (type == VMRTableType::me) { positive_ = false; - name_ = "VMRME_"+TrackletConfigBuilder::LayerName(layerdisk)+".tab"; + name_ = "VMRME_" + TrackletConfigBuilder::LayerName(layerdisk) + ".tab"; } if (type == VMRTableType::disk) { positive_ = false; - name_ = "VMRTE_"+TrackletConfigBuilder::LayerName(layerdisk)+".tab"; + name_ = "VMRTE_" + TrackletConfigBuilder::LayerName(layerdisk) + ".tab"; } if (type == VMRTableType::inner) { positive_ = true; nbits_ = 10; - name_ = "TP_"+TrackletConfigBuilder::LayerName(layerdisk) - +TrackletConfigBuilder::LayerName(layerdisk+1)+".tab"; + name_ = "TP_" + TrackletConfigBuilder::LayerName(layerdisk) + TrackletConfigBuilder::LayerName(layerdisk + 1) + + ".tab"; } - + if (type == VMRTableType::inneroverlap) { positive_ = true; nbits_ = 10; - name_ = "TP_"+TrackletConfigBuilder::LayerName(layerdisk) - +TrackletConfigBuilder::LayerName(N_LAYER)+".tab"; + name_ = "TP_" + TrackletConfigBuilder::LayerName(layerdisk) + TrackletConfigBuilder::LayerName(N_LAYER) + ".tab"; } } else { if (type == VMRTableType::me) { //This if a hack where the same memory is used in both ME and TE modules - if (layerdisk==1||layerdisk==2||layerdisk==3||layerdisk==4) { - positive_ = false; - name_ = "VMTableOuter"+TrackletConfigBuilder::LayerName(layerdisk)+".tab"; - writeTable(); + if (layerdisk == 1 || layerdisk == 2 || layerdisk == 3 || layerdisk == 4) { + positive_ = false; + name_ = "VMTableOuter" + TrackletConfigBuilder::LayerName(layerdisk) + ".tab"; + writeTable(); } - - assert(region>=0); - char cregion='A'+region; - name_ = "VMR_"+TrackletConfigBuilder::LayerName(layerdisk)+"PHI"+cregion+"_finebin.tab"; + + assert(region >= 0); + char cregion = 'A' + region; + name_ = "VMR_" + TrackletConfigBuilder::LayerName(layerdisk) + "PHI" + cregion + "_finebin.tab"; positive_ = false; } - + if (type == VMRTableType::inner) { positive_ = false; - name_ = "VMTableInner"+TrackletConfigBuilder::LayerName(layerdisk) - +TrackletConfigBuilder::LayerName(layerdisk+1)+".tab"; + name_ = "VMTableInner" + TrackletConfigBuilder::LayerName(layerdisk) + + TrackletConfigBuilder::LayerName(layerdisk + 1) + ".tab"; } - + if (type == VMRTableType::inneroverlap) { positive_ = false; - name_ = "VMTableInner"+TrackletConfigBuilder::LayerName(layerdisk) - +TrackletConfigBuilder::LayerName(N_LAYER)+".tab"; + name_ = "VMTableInner" + TrackletConfigBuilder::LayerName(layerdisk) + TrackletConfigBuilder::LayerName(N_LAYER) + + ".tab"; } - + if (type == VMRTableType::disk) { positive_ = false; - name_ = "VMTableOuter"+TrackletConfigBuilder::LayerName(layerdisk)+".tab"; + name_ = "VMTableOuter" + TrackletConfigBuilder::LayerName(layerdisk) + ".tab"; } } - - writeTable(); + writeTable(); } int TrackletLUT::getVMRLookup(unsigned int layerdisk, double z, double r, double dz, double dr, int iseed) const { @@ -829,20 +819,16 @@ int TrackletLUT::getVMRLookup(unsigned int layerdisk, double z, double r, double } } - - - void TrackletLUT::initPhiCorrTable(unsigned int layerdisk, unsigned int rbits) { - bool psmodule = layerdisk < N_PSLAYER; unsigned int bendbits = psmodule ? N_BENDBITS_PS : N_BENDBITS_2S; - + unsigned int rbins = (1 << rbits); double rmean = settings_.rmean(layerdisk); double drmax = settings_.drmax(); - + double dr = 2.0 * drmax / rbins; unsigned int bendbins = (1 << bendbits); @@ -854,19 +840,17 @@ void TrackletLUT::initPhiCorrTable(unsigned int layerdisk, unsigned int rbits) { } } - name_ = "VMPhiCorrL" + std::to_string(layerdisk+1) + ".tab"; + name_ = "VMPhiCorrL" + std::to_string(layerdisk + 1) + ".tab"; nbits_ = 14; positive_ = false; writeTable(); - } -int TrackletLUT::getphiCorrValue(unsigned int layerdisk, unsigned int ibend, unsigned int irbin, - double rmean, double dr, double drmax) const { - +int TrackletLUT::getphiCorrValue( + unsigned int layerdisk, unsigned int ibend, unsigned int irbin, double rmean, double dr, double drmax) const { bool psmodule = layerdisk < N_PSLAYER; - + double bend = -settings_.benddecode(ibend, layerdisk, psmodule); //for the rbin - calculate the distance to the nominal layer radius @@ -875,17 +859,15 @@ int TrackletLUT::getphiCorrValue(unsigned int layerdisk, unsigned int ibend, uns //calculate the phi correction - this is a somewhat approximate formula double dphi = (Delta / 0.18) * bend * settings_.stripPitch(psmodule) / rmean; - double kphi = psmodule ? settings_.kphi() : settings_.kphi1(); - - int idphi = dphi/kphi; + double kphi = psmodule ? settings_.kphi() : settings_.kphi1(); + + int idphi = dphi / kphi; return idphi; } - // Write LUT table. -void TrackletLUT::writeTable() const{ - +void TrackletLUT::writeTable() const { if (!settings_.writeTable()) { return; } @@ -893,7 +875,7 @@ void TrackletLUT::writeTable() const{ if (name_ == "") { return; } - + ofstream out = openfile(settings_.tablePath(), name_, __FILE__, __LINE__); out << "{" << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc index 720bf62b4b6b9..7ed7a828975cf 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc @@ -19,9 +19,11 @@ using namespace trklet; TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Globals* globals) : TrackletCalculatorBase(name, settings, globals), tebuffer_(CircularBuffer(3), 0, 0, 0, 0), - pttableinner_(settings), pttableouter_(settings), useregiontable_(settings), - innerTable_(settings), innerOverlapTable_(settings) { - + pttableinner_(settings), + pttableouter_(settings), + useregiontable_(settings), + innerTable_(settings), + innerOverlapTable_(settings) { iAllStub_ = -1; for (unsigned int ilayer = 0; ilayer < N_LAYER; ilayer++) { @@ -37,11 +39,11 @@ TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Glob outervmstubs_ = nullptr; initLayerDisksandISeed(layerdisk1_, layerdisk2_, iSeed_); - + double rmin = -1.0; double rmax = -1.0; - if (iSeed_ == Seed::L1L2 ||iSeed_ == Seed::L2L3 ||iSeed_ == Seed::L3L4 ||iSeed_ == Seed::L5L6 ) { + if (iSeed_ == Seed::L1L2 || iSeed_ == Seed::L2L3 || iSeed_ == Seed::L3L4 || iSeed_ == Seed::L5L6) { rmin = settings_.rmean(layerdisk1_); rmax = settings_.rmean(layerdisk2_); } else { @@ -65,7 +67,7 @@ TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Glob double dfinephi = settings_.dphisectorHG() / nfinephibins; nbitsfinephi_ = settings_.nbitsallstubs(layerdisk2_) + settings_.nbitsvmte(1, iSeed_) + settings_.nfinephi(1, iSeed_); - + int nbins = 2.0 * (dphimax / dfinephi + 1.0); nbitsfinephidiff_ = log(nbins) / log(2.0) + 1; @@ -80,15 +82,16 @@ TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Glob innerphibits_ = settings_.nfinephi(0, iSeed_); outerphibits_ = settings_.nfinephi(1, iSeed_); - if (layerdisk1_ == LayerDisk::L1 || layerdisk1_ == LayerDisk::L2 || layerdisk1_ == LayerDisk::L3 || layerdisk1_ == LayerDisk::L5 - || layerdisk1_ == LayerDisk::D1 || layerdisk1_ == LayerDisk::D3) { - innerTable_.initVMRTable(layerdisk1_, TrackletLUT::VMRTableType::inner); //projection to next layer/disk + if (layerdisk1_ == LayerDisk::L1 || layerdisk1_ == LayerDisk::L2 || layerdisk1_ == LayerDisk::L3 || + layerdisk1_ == LayerDisk::L5 || layerdisk1_ == LayerDisk::D1 || layerdisk1_ == LayerDisk::D3) { + innerTable_.initVMRTable(layerdisk1_, TrackletLUT::VMRTableType::inner); //projection to next layer/disk } - if (layerdisk1_ == LayerDisk::L1 || layerdisk1_ == LayerDisk::L2 ) { - innerOverlapTable_.initVMRTable(layerdisk1_, TrackletLUT::VMRTableType::inneroverlap); //projection to disk from layer + if (layerdisk1_ == LayerDisk::L1 || layerdisk1_ == LayerDisk::L2) { + innerOverlapTable_.initVMRTable(layerdisk1_, + TrackletLUT::VMRTableType::inneroverlap); //projection to disk from layer } - + // set TC index iTC_ = name_[7] - 'A'; assert(iTC_ >= 0 && iTC_ < 14); @@ -170,16 +173,16 @@ void TrackletProcessor::addInput(MemoryBase* memory, string input) { iAllStub_ = 3; } - unsigned int iTP = getName()[7]-'A'; - - pttableinner_.initTPlut(true, iSeed_, layerdisk1_, layerdisk2_, nbitsfinephidiff_, iTP); - pttableouter_.initTPlut(false, iSeed_, layerdisk1_, layerdisk2_, nbitsfinephidiff_, iTP); + unsigned int iTP = getName()[7] - 'A'; + + pttableinner_.initTPlut(true, iSeed_, layerdisk1_, layerdisk2_, nbitsfinephidiff_, iTP); + pttableouter_.initTPlut(false, iSeed_, layerdisk1_, layerdisk2_, nbitsfinephidiff_, iTP); //need iAllStub_ set before building the table - - useregiontable_.initTPregionlut(iSeed_, layerdisk1_, layerdisk2_, iAllStub_, - nbitsfinephidiff_, nbitsfinephi_, pttableinner_, iTP); - + + useregiontable_.initTPregionlut( + iSeed_, layerdisk1_, layerdisk2_, iAllStub_, nbitsfinephidiff_, nbitsfinephi_, pttableinner_, iTP); + TrackletEngineUnit teunit(&settings_, nbitsfinephi_, layerdisk1_, @@ -272,7 +275,6 @@ void TrackletProcessor::execute(unsigned int iSector, double phimin, double phim bool tebuffernearfull; for (unsigned int istep = 0; istep < maxStep_; istep++) { - // These print statements are not on by defaul but can be enabled for the // comparison with HLS code to track differences. if (print) { @@ -327,9 +329,9 @@ void TrackletProcessor::execute(unsigned int iSector, double phimin, double phim bool accept = false; - if (iSeed_ == Seed::L1L2 || iSeed_ == Seed::L2L3 || iSeed_ == Seed::L3L4 || iSeed_ == Seed::L5L6 ) { + if (iSeed_ == Seed::L1L2 || iSeed_ == Seed::L2L3 || iSeed_ == Seed::L3L4 || iSeed_ == Seed::L5L6) { accept = barrelSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); - } else if ( iSeed_ == Seed::D1D2 || iSeed_ == Seed::D3D4 ) { + } else if (iSeed_ == Seed::D1D2 || iSeed_ == Seed::D3D4) { accept = diskSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); } else { accept = overlapSeeding(outerFPGAStub, outerStub, innerFPGAStub, innerStub); @@ -411,9 +413,9 @@ void TrackletProcessor::execute(unsigned int iSector, double phimin, double phim int lutval = -1; if (iSeed_ < 6) { //FIXME should only be one table - but will need coordination with HLS code. - lutval = innerTable_.lookup((indexz<> (NFINERZBITS - 1)); @@ -441,7 +443,7 @@ void TrackletProcessor::execute(unsigned int iSector, double phimin, double phim } unsigned int usereg = useregiontable_.lookup(useregindex); - + tedata.regions_.clear(); tedata.stub_ = stub; tedata.rzbinfirst_ = rzfinebinfirst; @@ -534,4 +536,3 @@ void TrackletProcessor::execute(unsigned int iSector, double phimin, double phim << endl; } } - diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc index 05549c77e1321..b51f9ac754c94 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc @@ -14,36 +14,42 @@ using namespace std; using namespace trklet; VMRouter::VMRouter(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global), meTable_(settings), diskTable_(settings), - innerTable_(settings), innerOverlapTable_(settings), innerThirdTable_(settings) { - + : ProcessBase(name, settings, global), + meTable_(settings), + diskTable_(settings), + innerTable_(settings), + innerOverlapTable_(settings), + innerThirdTable_(settings) { layerdisk_ = initLayerDisk(4); vmstubsMEPHI_.resize(settings_.nvmme(layerdisk_), nullptr); - unsigned int region = name[9]-'A'; + unsigned int region = name[9] - 'A'; assert(region < settings_.nallstubs(layerdisk_)); - + overlapbits_ = 7; nextrabits_ = overlapbits_ - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_)); - meTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::me, region); //used for ME and outer TE barrel + meTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::me, region); //used for ME and outer TE barrel - if (layerdisk_==LayerDisk::D1 || layerdisk_==LayerDisk::D2 || layerdisk_==D4) { - diskTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::disk, region); //outer disk used by D1, D2, and D4 + if (layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D2 || layerdisk_ == D4) { + diskTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::disk, region); //outer disk used by D1, D2, and D4 } - - if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L5 || - layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) { - innerTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::inner, region); //projection to next layer/disk + + if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3 || + layerdisk_ == LayerDisk::L5 || layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) { + innerTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::inner, region); //projection to next layer/disk } - if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L2 ) { - innerOverlapTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::inneroverlap, region); //projection to disk from layer + if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L2) { + innerOverlapTable_.initVMRTable( + layerdisk_, TrackletLUT::VMRTableType::inneroverlap, region); //projection to disk from layer } - if (layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L5 || layerdisk_ == LayerDisk::D1 ) { - innerThirdTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::innerthird, region); //projection to third layer/disk + if (layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L5 || + layerdisk_ == LayerDisk::D1) { + innerThirdTable_.initVMRTable( + layerdisk_, TrackletLUT::VMRTableType::innerthird, region); //projection to third layer/disk } nbitszfinebintable_ = settings_.vmrlutzbits(layerdisk_); @@ -64,7 +70,7 @@ void VMRouter::addOutput(MemoryBase* memory, string output) { } if (output.substr(0, 12) == "vmstuboutPHI" || output.substr(0, 14) == "vmstuboutMEPHI" || - output.substr(0, 15) == "vmstuboutTEIPHI" ||output.substr(0, 15) == "vmstuboutTEOPHI" ) { + output.substr(0, 15) == "vmstuboutTEIPHI" || output.substr(0, 15) == "vmstuboutTEOPHI") { char seedtype = memory->getName().substr(11, 1)[0]; unsigned int pos = 12; int vmbin = memory->getName().substr(pos, 1)[0] - '0'; @@ -93,7 +99,7 @@ void VMRouter::addOutput(MemoryBase* memory, string output) { if (layerdisk_ == LayerDisk::D3 || layerdisk_ == LayerDisk::D4) iseed = Seed::D3D4; if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L5 || - layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) + layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) inner = 0; } else if (seedtype < 'M') { if (layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3) @@ -185,7 +191,7 @@ void VMRouter::execute() { for (unsigned int i = 0; i < stubinput->nStubs(); i++) { if (allStubCounter >= settings_.maxStep("VMR")) continue; - if (allStubCounter >= (1<= (1 << N_BITSMEMADDRESS)) continue; Stub* stub = stubinput->getStub(i); @@ -194,7 +200,7 @@ void VMRouter::execute() { //use &127 to make sure we fit into the number of bits - //though we should have protected against overflows above - FPGAWord allStubIndex(allStubCounter & ((1<setAllStubIndex(allStubCounter); @@ -247,7 +253,7 @@ void VMRouter::execute() { assert(indexz < (1 << nbitszfinebintable_)); assert(indexr < (1 << nbitsrfinebintable_)); - int melut = meTable_.lookup((indexz<= 0); int vmbin = melut >> 3; @@ -287,7 +293,8 @@ void VMRouter::execute() { for (auto& ivmstubTEPHI : vmstubsTEPHI_) { unsigned int iseed = ivmstubTEPHI.seednumber; unsigned int inner = ivmstubTEPHI.stubposition; - if ((iseed == Seed::D1D2 || iseed == Seed::D3D4 || iseed == Seed::L1D1 || iseed == Seed::L2D1) && (!stub->isPSmodule())) + if ((iseed == Seed::D1D2 || iseed == Seed::D3D4 || iseed == Seed::L1D1 || iseed == Seed::L2D1) && + (!stub->isPSmodule())) continue; unsigned int lutwidth = settings_.lutwidthtab(inner, iseed); @@ -311,21 +318,22 @@ void VMRouter::execute() { } } } else { - lutval = diskTable_.lookup((indexz< Seed::L2D1) { - lutval = innerTable_.lookup((indexz<nStubs(); i++) { if (allStubCounter > settings_.maxStep("VMR")) continue; - if (allStubCounter >= (1<= (1 << N_BITSMEMADDRESS)) continue; Stub* stub = stubinput->getStub(i); @@ -141,7 +140,7 @@ void VMRouterCM::execute() { //use &127 to make sure we fit into the number of bits - //though we should have protected against overflows above - FPGAWord allStubIndex(allStubCounter & ((1<setAllStubIndex(allStubCounter); @@ -189,11 +188,13 @@ void VMRouterCM::execute() { continue; int absz = std::abs(stub->z().value()); - if (layerdisk_ == LayerDisk::L2 && absz < VMROUTERCUTZL2 / settings_.kz(layerdisk_)) + if (layerdisk_ == LayerDisk::L2 && absz < VMROUTERCUTZL2 / settings_.kz(layerdisk_)) continue; - if ((layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L5) && absz > VMROUTERCUTZL1L3L5 / settings_.kz(layerdisk_)) + if ((layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L5) && + absz > VMROUTERCUTZL1L3L5 / settings_.kz(layerdisk_)) continue; - if ((layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) && stub->r().value() > VMROUTERCUTRD1D3 / settings_.kr()) + if ((layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) && + stub->r().value() > VMROUTERCUTRD1D3 / settings_.kr()) continue; if ((layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) && stub->r().value() < 2 * int(N_DSS_MOD)) continue; @@ -242,8 +243,8 @@ void VMRouterCM::execute() { assert(indexz < (1 << nbitszfinebintable_)); assert(indexr < (1 << nbitsrfinebintable_)); - int melut = meTable_.lookup((indexz<= 0); int vmbin = melut >> NFINERZBITS; @@ -280,7 +281,7 @@ void VMRouterCM::execute() { if (layerdisk_ < N_LAYER) { lutval = melut; } else { - lutval = diskTable_.lookup((indexz<= N_LAYER && tmp1->getName().find("2S_") != string::npos) { stubinputdisk2stmp_.push_back(tmp1); } else { stubinputtmp_.push_back(tmp1); From 6363c2d3994b98583f6495ca36c5e19d7153d19b Mon Sep 17 00:00:00 2001 From: cgsavard Date: Mon, 17 May 2021 10:06:49 -0600 Subject: [PATCH 13/15] fix matchtp variables (#76) * fix matchtp variables * remove d=0 variables * switch values for cms constants * change pi to constant * change trk_d0 sign * move tmp_tp_d0 and tmp_tp_z0 calc up * flip tp_d0 sign --- .../TrackFindingTracklet/test/BuildFile.xml | 2 + .../test/L1TrackNtupleMaker.cc | 137 +++++++++++------- 2 files changed, 86 insertions(+), 53 deletions(-) diff --git a/L1Trigger/TrackFindingTracklet/test/BuildFile.xml b/L1Trigger/TrackFindingTracklet/test/BuildFile.xml index 29aaa5e4ee8ec..e4d0fb04bb751 100644 --- a/L1Trigger/TrackFindingTracklet/test/BuildFile.xml +++ b/L1Trigger/TrackFindingTracklet/test/BuildFile.xml @@ -18,6 +18,8 @@ + + diff --git a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc index d71e9c50f5072..27e7ad8e35eed 100644 --- a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc +++ b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc @@ -56,6 +56,7 @@ //////////////// // PHYSICS TOOLS #include "CommonTools/UtilAlgos/interface/TFileService.h" +#include "CLHEP/Units/PhysicalConstants.h" /////////////// // ROOT HEADERS @@ -172,6 +173,7 @@ class L1TrackNtupleMaker : public edm::EDAnalyzer { std::vector* m_trk_matchtp_phi; std::vector* m_trk_matchtp_z0; std::vector* m_trk_matchtp_dxy; + std::vector* m_trk_matchtp_d0; std::vector* m_trk_injet; //is the track within dR<0.4 of a genjet with pt > 30 GeV? std::vector* m_trk_injet_highpt; //is the track within dR<0.4 of a genjet with pt > 100 GeV? std::vector* m_trk_injet_vhighpt; //is the track within dR<0.4 of a genjet with pt > 200 GeV? @@ -340,6 +342,7 @@ void L1TrackNtupleMaker::beginJob() { m_trk_matchtp_phi = new std::vector; m_trk_matchtp_z0 = new std::vector; m_trk_matchtp_dxy = new std::vector; + m_trk_matchtp_d0 = new std::vector; m_trk_injet = new std::vector; m_trk_injet_highpt = new std::vector; m_trk_injet_vhighpt = new std::vector; @@ -437,6 +440,7 @@ void L1TrackNtupleMaker::beginJob() { eventTree->Branch("trk_matchtp_phi", &m_trk_matchtp_phi); eventTree->Branch("trk_matchtp_z0", &m_trk_matchtp_z0); eventTree->Branch("trk_matchtp_dxy", &m_trk_matchtp_dxy); + eventTree->Branch("trk_matchtp_d0", &m_trk_matchtp_d0); if (TrackingInJets) { eventTree->Branch("trk_injet", &m_trk_injet); eventTree->Branch("trk_injet_highpt", &m_trk_injet_highpt); @@ -563,6 +567,7 @@ void L1TrackNtupleMaker::analyze(const edm::Event& iEvent, const edm::EventSetup m_trk_matchtp_phi->clear(); m_trk_matchtp_z0->clear(); m_trk_matchtp_dxy->clear(); + m_trk_matchtp_d0->clear(); m_trk_injet->clear(); m_trk_injet_highpt->clear(); m_trk_injet_vhighpt->clear(); @@ -671,6 +676,9 @@ void L1TrackNtupleMaker::analyze(const edm::Event& iEvent, const edm::EventSetup edm::ESHandle tGeomHandle; iSetup.get().get(tGeomHandle); + edm::ESHandle magneticFieldHandle; + iSetup.get().get(magneticFieldHandle); + const TrackerTopology* const tTopo = tTopoHandle.product(); const TrackerGeometry* const theTrackerGeom = tGeomHandle.product(); @@ -861,7 +869,7 @@ void L1TrackNtupleMaker::analyze(const edm::Event& iEvent, const edm::EventSetup if (L1Tk_nPar == 5) { float tmp_trk_x0 = iterL1Track->POCA().x(); float tmp_trk_y0 = iterL1Track->POCA().y(); - tmp_trk_d0 = -tmp_trk_x0 * sin(tmp_trk_phi) + tmp_trk_y0 * cos(tmp_trk_phi); + tmp_trk_d0 = tmp_trk_x0 * sin(tmp_trk_phi) - tmp_trk_y0 * cos(tmp_trk_phi); } float tmp_trk_chi2 = iterL1Track->chi2(); @@ -907,14 +915,14 @@ void L1TrackNtupleMaker::analyze(const edm::Event& iEvent, const edm::EventSetup if (detIdStub.subdetId() == StripSubdetector::TOB) { layer = static_cast(tTopo->layer(detIdStub)); if (DebugMode) - edm::LogVerbatim("Tracklet") - << " stub in layer " << layer << " at position x y z = " << x << " " << y << " " << z; + edm::LogVerbatim("Tracklet") + << " stub in layer " << layer << " at position x y z = " << x << " " << y << " " << z; tmp_trk_lhits += pow(10, layer - 1); } else if (detIdStub.subdetId() == StripSubdetector::TID) { layer = static_cast(tTopo->layer(detIdStub)); if (DebugMode) - edm::LogVerbatim("Tracklet") - << " stub in disk " << layer << " at position x y z = " << x << " " << y << " " << z; + edm::LogVerbatim("Tracklet") + << " stub in disk " << layer << " at position x y z = " << x << " " << y << " " << z; tmp_trk_dhits += pow(10, layer - 1); } @@ -981,12 +989,13 @@ void L1TrackNtupleMaker::analyze(const edm::Event& iEvent, const edm::EventSetup int myFake = 0; - int myTP_pdgid = -999; - float myTP_pt = -999; - float myTP_eta = -999; - float myTP_phi = -999; - float myTP_z0 = -999; - float myTP_dxy = -999; + int tmp_matchtp_pdgid = -999; + float tmp_matchtp_pt = -999; + float tmp_matchtp_eta = -999; + float tmp_matchtp_phi = -999; + float tmp_matchtp_z0 = -999; + float tmp_matchtp_dxy = -999; + float tmp_matchtp_d0 = -999; if (my_tp.isNull()) myFake = 0; @@ -998,32 +1007,59 @@ void L1TrackNtupleMaker::analyze(const edm::Event& iEvent, const edm::EventSetup else myFake = 1; - myTP_pdgid = my_tp->pdgId(); - myTP_pt = my_tp->p4().pt(); - myTP_eta = my_tp->p4().eta(); - myTP_phi = my_tp->p4().phi(); - myTP_z0 = my_tp->vertex().z(); + tmp_matchtp_pdgid = my_tp->pdgId(); + tmp_matchtp_pt = my_tp->pt(); + tmp_matchtp_eta = my_tp->eta(); + tmp_matchtp_phi = my_tp->phi(); + + float tmp_matchtp_vz = my_tp->vz(); + float tmp_matchtp_vx = my_tp->vx(); + float tmp_matchtp_vy = my_tp->vy(); + tmp_matchtp_dxy = sqrt(tmp_matchtp_vx * tmp_matchtp_vx + tmp_matchtp_vy * tmp_matchtp_vy); + + // ---------------------------------------------------------------------------------------------- + // get d0/z0 propagated back to the IP + + float tmp_matchtp_t = tan(2.0 * atan(1.0) - 2.0 * atan(exp(-tmp_matchtp_eta))); - float myTP_x0 = my_tp->vertex().x(); - float myTP_y0 = my_tp->vertex().y(); - myTP_dxy = sqrt(myTP_x0 * myTP_x0 + myTP_y0 * myTP_y0); + float delx = -tmp_matchtp_vx; + float dely = -tmp_matchtp_vy; + + float b_field = magneticFieldHandle.product()->inTesla(GlobalPoint(0, 0, 0)).z(); + float c_converted = CLHEP::c_light / 1.0E5; + float r2_inv = my_tp->charge() * c_converted * b_field / tmp_matchtp_pt / 2.0; + + float tmp_matchtp_x0p = delx - (1. / (2. * r2_inv) * sin(tmp_matchtp_phi)); + float tmp_matchtp_y0p = dely + (1. / (2. * r2_inv) * cos(tmp_matchtp_phi)); + float tmp_matchtp_rp = sqrt(tmp_matchtp_x0p * tmp_matchtp_x0p + tmp_matchtp_y0p * tmp_matchtp_y0p); + tmp_matchtp_d0 = my_tp->charge() * tmp_matchtp_rp - (1. / (2. * r2_inv)); + + static double pi = M_PI; + float delphi = tmp_matchtp_phi - atan2(-r2_inv * tmp_matchtp_x0p, r2_inv * tmp_matchtp_y0p); + if (delphi < -pi) + delphi += 2.0 * pi; + if (delphi > pi) + delphi -= 2.0 * pi; + tmp_matchtp_z0 = tmp_matchtp_vz + tmp_matchtp_t * delphi / (2.0 * r2_inv); + // ---------------------------------------------------------------------------------------------- if (DebugMode) { edm::LogVerbatim("Tracklet") << "TP matched to track has pt = " << my_tp->p4().pt() << " eta = " << my_tp->momentum().eta() << " phi = " << my_tp->momentum().phi() << " z0 = " << my_tp->vertex().z() << " pdgid = " << my_tp->pdgId() - << " dxy = " << myTP_dxy; + << " dxy = " << tmp_matchtp_dxy; } } m_trk_fake->push_back(myFake); - m_trk_matchtp_pdgid->push_back(myTP_pdgid); - m_trk_matchtp_pt->push_back(myTP_pt); - m_trk_matchtp_eta->push_back(myTP_eta); - m_trk_matchtp_phi->push_back(myTP_phi); - m_trk_matchtp_z0->push_back(myTP_z0); - m_trk_matchtp_dxy->push_back(myTP_dxy); + m_trk_matchtp_pdgid->push_back(tmp_matchtp_pdgid); + m_trk_matchtp_pt->push_back(tmp_matchtp_pt); + m_trk_matchtp_eta->push_back(tmp_matchtp_eta); + m_trk_matchtp_phi->push_back(tmp_matchtp_phi); + m_trk_matchtp_z0->push_back(tmp_matchtp_z0); + m_trk_matchtp_dxy->push_back(tmp_matchtp_dxy); + m_trk_matchtp_d0->push_back(tmp_matchtp_d0); // ---------------------------------------------------------------------------------------------- // for tracking in jets @@ -1092,49 +1128,44 @@ void L1TrackNtupleMaker::analyze(const edm::Event& iEvent, const edm::EventSetup float tmp_tp_z0_prod = tmp_tp_vz; float tmp_tp_d0_prod = tmp_tp_vx * sin(tmp_tp_phi) - tmp_tp_vy * cos(tmp_tp_phi); - if (MyProcess == 13 && abs(tmp_tp_pdgid) != 13) - continue; - if (MyProcess == 11 && abs(tmp_tp_pdgid) != 11) - continue; - if ((MyProcess == 6 || MyProcess == 15 || MyProcess == 211) && abs(tmp_tp_pdgid) != 211) - continue; - - if (tmp_tp_pt < TP_minPt) - continue; - if (std::abs(tmp_tp_eta) > TP_maxEta) - continue; - // ---------------------------------------------------------------------------------------------- // get d0/z0 propagated back to the IP float tmp_tp_t = tan(2.0 * atan(1.0) - 2.0 * atan(exp(-tmp_tp_eta))); + float tmp_tp_charge = iterTP->charge(); float delx = -tmp_tp_vx; float dely = -tmp_tp_vy; - float A = 0.01 * 0.5696; - float Kmagnitude = A / tmp_tp_pt; - - float tmp_tp_charge = tp_ptr->charge(); - float K = Kmagnitude * tmp_tp_charge; - float d = 0; + float b_field = magneticFieldHandle.product()->inTesla(GlobalPoint(0, 0, 0)).z(); + float c_converted = CLHEP::c_light / 1.0E5; + float r2_inv = tmp_tp_charge * c_converted * b_field / tmp_tp_pt / 2.0; - float tmp_tp_x0p = delx - (d + 1. / (2. * K) * sin(tmp_tp_phi)); - float tmp_tp_y0p = dely + (d + 1. / (2. * K) * cos(tmp_tp_phi)); + float tmp_tp_x0p = delx - (1. / (2. * r2_inv) * sin(tmp_tp_phi)); + float tmp_tp_y0p = dely + (1. / (2. * r2_inv) * cos(tmp_tp_phi)); float tmp_tp_rp = sqrt(tmp_tp_x0p * tmp_tp_x0p + tmp_tp_y0p * tmp_tp_y0p); - float tmp_tp_d0 = tmp_tp_charge * tmp_tp_rp - (1. / (2. * K)); + float tmp_tp_d0 = tmp_tp_charge * tmp_tp_rp - (1. / (2. * r2_inv)); - tmp_tp_d0 = tmp_tp_d0 * (-1); //fix d0 sign - - static double pi = 4.0 * atan(1.0); - float delphi = tmp_tp_phi - atan2(-K * tmp_tp_x0p, K * tmp_tp_y0p); + static double pi = M_PI; + float delphi = tmp_tp_phi - atan2(-r2_inv * tmp_tp_x0p, r2_inv * tmp_tp_y0p); if (delphi < -pi) delphi += 2.0 * pi; if (delphi > pi) delphi -= 2.0 * pi; - float tmp_tp_z0 = tmp_tp_vz + tmp_tp_t * delphi / (2.0 * K); + float tmp_tp_z0 = tmp_tp_vz + tmp_tp_t * delphi / (2.0 * r2_inv); // ---------------------------------------------------------------------------------------------- + if (MyProcess == 13 && abs(tmp_tp_pdgid) != 13) + continue; + if (MyProcess == 11 && abs(tmp_tp_pdgid) != 11) + continue; + if ((MyProcess == 6 || MyProcess == 15 || MyProcess == 211) && abs(tmp_tp_pdgid) != 211) + continue; + + if (tmp_tp_pt < TP_minPt) + continue; + if (std::abs(tmp_tp_eta) > TP_maxEta) + continue; if (std::abs(tmp_tp_z0) > TP_maxZ0) continue; @@ -1349,7 +1380,7 @@ void L1TrackNtupleMaker::analyze(const edm::Event& iEvent, const edm::EventSetup if (L1Tk_nPar == 5) { float tmp_matchtrk_x0 = matchedTracks.at(i_track)->POCA().x(); float tmp_matchtrk_y0 = matchedTracks.at(i_track)->POCA().y(); - tmp_matchtrk_d0 = -tmp_matchtrk_x0 * sin(tmp_matchtrk_phi) + tmp_matchtrk_y0 * cos(tmp_matchtrk_phi); + tmp_matchtrk_d0 = tmp_matchtrk_x0 * sin(tmp_matchtrk_phi) - tmp_matchtrk_y0 * cos(tmp_matchtrk_phi); } tmp_matchtrk_chi2 = matchedTracks.at(i_track)->chi2(); From b5cc180fb902a31fcf1a105dcd596dd7e07c8139 Mon Sep 17 00:00:00 2001 From: Louise Skinnari Date: Wed, 19 May 2021 16:03:01 +0200 Subject: [PATCH 14/15] correct truncation for InputRouter --- L1Trigger/TrackFindingTracklet/interface/Settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/L1Trigger/TrackFindingTracklet/interface/Settings.h b/L1Trigger/TrackFindingTracklet/interface/Settings.h index 6c3b701d407fe..e46e94b109386 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Settings.h +++ b/L1Trigger/TrackFindingTracklet/interface/Settings.h @@ -751,7 +751,7 @@ namespace trklet { unsigned int maxstepoffset_{0}; //Number of processing steps for one event (108=18TM*240MHz/40MHz) - std::unordered_map maxstep_{{"IR", 168}, //IR will run at a higher clock speed to handle + std::unordered_map maxstep_{{"IR", 156}, //IR will run at a higher clock speed to handle //input links running at 25 Gbits/s {"VMR", 108}, {"TE", 108}, From 4d410c12576e7d71006d69f57bbec1c434dcd8eb Mon Sep 17 00:00:00 2001 From: Louise Skinnari Date: Wed, 19 May 2021 18:57:30 +0200 Subject: [PATCH 15/15] apply code formats --- .../TrackFindingTracklet/src/VMRouter.cc | 2 +- .../test/L1TrackNtupleMaker.cc | 54 +++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc index 50f0cd00294f0..bef76f3ac5e41 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc @@ -335,7 +335,7 @@ void VMRouter::execute() { (iseed == Seed::L3L4 || iseed == Seed::L5L6 || iseed == Seed::D1D2 || iseed == Seed::L2L3D1)) { int lutval2 = innerThirdTable_.lookup((indexz << nbitsrfinebintable_) + indexr); if (lutval2 != -1) - lutval += (lutval2 << 10); + lutval += (lutval2 << 10); } } diff --git a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc index 27e7ad8e35eed..a795c2afd2200 100644 --- a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc +++ b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc @@ -915,14 +915,14 @@ void L1TrackNtupleMaker::analyze(const edm::Event& iEvent, const edm::EventSetup if (detIdStub.subdetId() == StripSubdetector::TOB) { layer = static_cast(tTopo->layer(detIdStub)); if (DebugMode) - edm::LogVerbatim("Tracklet") - << " stub in layer " << layer << " at position x y z = " << x << " " << y << " " << z; + edm::LogVerbatim("Tracklet") + << " stub in layer " << layer << " at position x y z = " << x << " " << y << " " << z; tmp_trk_lhits += pow(10, layer - 1); } else if (detIdStub.subdetId() == StripSubdetector::TID) { layer = static_cast(tTopo->layer(detIdStub)); if (DebugMode) - edm::LogVerbatim("Tracklet") - << " stub in disk " << layer << " at position x y z = " << x << " " << y << " " << z; + edm::LogVerbatim("Tracklet") + << " stub in disk " << layer << " at position x y z = " << x << " " << y << " " << z; tmp_trk_dhits += pow(10, layer - 1); } @@ -1012,36 +1012,36 @@ void L1TrackNtupleMaker::analyze(const edm::Event& iEvent, const edm::EventSetup tmp_matchtp_eta = my_tp->eta(); tmp_matchtp_phi = my_tp->phi(); - float tmp_matchtp_vz = my_tp->vz(); - float tmp_matchtp_vx = my_tp->vx(); - float tmp_matchtp_vy = my_tp->vy(); + float tmp_matchtp_vz = my_tp->vz(); + float tmp_matchtp_vx = my_tp->vx(); + float tmp_matchtp_vy = my_tp->vy(); tmp_matchtp_dxy = sqrt(tmp_matchtp_vx * tmp_matchtp_vx + tmp_matchtp_vy * tmp_matchtp_vy); - // ---------------------------------------------------------------------------------------------- - // get d0/z0 propagated back to the IP + // ---------------------------------------------------------------------------------------------- + // get d0/z0 propagated back to the IP - float tmp_matchtp_t = tan(2.0 * atan(1.0) - 2.0 * atan(exp(-tmp_matchtp_eta))); + float tmp_matchtp_t = tan(2.0 * atan(1.0) - 2.0 * atan(exp(-tmp_matchtp_eta))); - float delx = -tmp_matchtp_vx; - float dely = -tmp_matchtp_vy; + float delx = -tmp_matchtp_vx; + float dely = -tmp_matchtp_vy; - float b_field = magneticFieldHandle.product()->inTesla(GlobalPoint(0, 0, 0)).z(); - float c_converted = CLHEP::c_light / 1.0E5; - float r2_inv = my_tp->charge() * c_converted * b_field / tmp_matchtp_pt / 2.0; + float b_field = magneticFieldHandle.product()->inTesla(GlobalPoint(0, 0, 0)).z(); + float c_converted = CLHEP::c_light / 1.0E5; + float r2_inv = my_tp->charge() * c_converted * b_field / tmp_matchtp_pt / 2.0; - float tmp_matchtp_x0p = delx - (1. / (2. * r2_inv) * sin(tmp_matchtp_phi)); - float tmp_matchtp_y0p = dely + (1. / (2. * r2_inv) * cos(tmp_matchtp_phi)); - float tmp_matchtp_rp = sqrt(tmp_matchtp_x0p * tmp_matchtp_x0p + tmp_matchtp_y0p * tmp_matchtp_y0p); - tmp_matchtp_d0 = my_tp->charge() * tmp_matchtp_rp - (1. / (2. * r2_inv)); + float tmp_matchtp_x0p = delx - (1. / (2. * r2_inv) * sin(tmp_matchtp_phi)); + float tmp_matchtp_y0p = dely + (1. / (2. * r2_inv) * cos(tmp_matchtp_phi)); + float tmp_matchtp_rp = sqrt(tmp_matchtp_x0p * tmp_matchtp_x0p + tmp_matchtp_y0p * tmp_matchtp_y0p); + tmp_matchtp_d0 = my_tp->charge() * tmp_matchtp_rp - (1. / (2. * r2_inv)); - static double pi = M_PI; - float delphi = tmp_matchtp_phi - atan2(-r2_inv * tmp_matchtp_x0p, r2_inv * tmp_matchtp_y0p); - if (delphi < -pi) - delphi += 2.0 * pi; - if (delphi > pi) - delphi -= 2.0 * pi; - tmp_matchtp_z0 = tmp_matchtp_vz + tmp_matchtp_t * delphi / (2.0 * r2_inv); - // ---------------------------------------------------------------------------------------------- + static double pi = M_PI; + float delphi = tmp_matchtp_phi - atan2(-r2_inv * tmp_matchtp_x0p, r2_inv * tmp_matchtp_y0p); + if (delphi < -pi) + delphi += 2.0 * pi; + if (delphi > pi) + delphi -= 2.0 * pi; + tmp_matchtp_z0 = tmp_matchtp_vz + tmp_matchtp_t * delphi / (2.0 * r2_inv); + // ---------------------------------------------------------------------------------------------- if (DebugMode) { edm::LogVerbatim("Tracklet") << "TP matched to track has pt = " << my_tp->p4().pt()