From b7fa8c83eb0f9715024c68c65a420bc667d57ad7 Mon Sep 17 00:00:00 2001 From: Andrew Hart Date: Sun, 21 Feb 2021 18:17:32 -0500 Subject: [PATCH] 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(); }