From 958757ef3bd206bbb5466ef4d4bc964923b2e8fc Mon Sep 17 00:00:00 2001 From: Andrew Hart Date: Mon, 19 Oct 2020 08:56:08 -0400 Subject: [PATCH] Disabled the TED and TRE tables by default. (#47) * Added a flag for enabling the application of the TED and TRE tables. * Fixed code format issues. * Updated bestTCID to not depend on the number of bits used to represent TCIDs. * Removed confusing comment. --- .../TrackFindingTracklet/interface/Settings.h | 19 +++-- .../TrackFindingTracklet/interface/Tracklet.h | 4 +- .../interface/TrackletEngineDisplaced.h | 4 +- .../plugins/L1FPGATrackProducer.cc | 5 ++ .../TrackFindingTracklet/src/FitTrack.cc | 4 +- .../src/MatchCalculator.cc | 4 +- .../TrackFindingTracklet/src/Tracklet.cc | 12 +-- .../src/TrackletEngineDisplaced.cc | 46 +++++----- .../TrackFindingTracklet/src/TripletEngine.cc | 83 ++++++++++--------- 9 files changed, 103 insertions(+), 78 deletions(-) diff --git a/L1Trigger/TrackFindingTracklet/interface/Settings.h b/L1Trigger/TrackFindingTracklet/interface/Settings.h index 5aa4bbd85da54..ad1fd636d04fd 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Settings.h +++ b/L1Trigger/TrackFindingTracklet/interface/Settings.h @@ -170,6 +170,7 @@ namespace trklet { unsigned int writememsect() const { return writememsect_; } + bool enableTripletTables() const { return enableTripletTables_; } bool writeTripletTables() const { return writeTripletTables_; } bool writeoutReal() const { return writeoutReal_; } @@ -238,6 +239,9 @@ namespace trklet { std::string skimfile() const { return skimfile_; } void setSkimfile(std::string skimfile) { skimfile_ = skimfile; } + unsigned int nbitstrackletindex() const { return nbitstrackletindex_; } + void setNbitstrackletindex(unsigned int nbitstrackletindex) { nbitstrackletindex_ = nbitstrackletindex; } + 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_)), @@ -282,7 +286,7 @@ namespace trklet { unsigned int NLONGVMBITS() const { return NLONGVMBITS_; } unsigned int NLONGVMBINS() const { return (1 << NLONGVMBITS_); } - unsigned int ntrackletmax() const { return ntrackletmax_; } + unsigned int ntrackletmax() const { return ((1 << nbitstrackletindex_) - 1); } //Bits used to store track parameter in tracklet int nbitsrinv() const { return nbitsrinv_; } @@ -434,7 +438,7 @@ namespace trklet { double ptcutte_{1.8}; //Minimum pt in TE - unsigned int ntrackletmax_{127}; //maximum number of tracklets that can be stored + unsigned int nbitstrackletindex_{7}; //Bits used to store the tracklet index //Bits used to store track parameter in tracklet int nbitsrinv_{14}; @@ -672,10 +676,13 @@ namespace trklet { unsigned int writememsect_{3}; //writemem only for this sector (note that the files will have _4 extension) - bool writeTripletTables_{false}; //Train and write the TED and TRE tables. N.B.: the tables - //cannot be applied while they are being trained, i.e., - //this flag effectively turns off the cuts in - //TrackletEngineDisplaced and TripletEngine + bool enableTripletTables_{false}; //Enable the application of the TED and + //TRE tables; when this flag is false, + //the tables will not be read from disk + bool writeTripletTables_{false}; //Train and write the TED and TRE tables. N.B.: the tables + //cannot be applied while they are being trained, i.e., + //this flag effectively turns off the cuts in + //TrackletEngineDisplaced and TripletEngine bool writeoutReal_{false}; diff --git a/L1Trigger/TrackFindingTracklet/interface/Tracklet.h b/L1Trigger/TrackFindingTracklet/interface/Tracklet.h index 41899ba349500..6137a600b2ac1 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Tracklet.h +++ b/L1Trigger/TrackFindingTracklet/interface/Tracklet.h @@ -489,7 +489,7 @@ namespace trklet { bool isOverlap() const { return overlap_; } int isDisk() const { return disk_; } - void setTrackletIndex(int index); + void setTrackletIndex(unsigned int index); int trackletIndex() const { return trackletIndex_; } @@ -497,7 +497,7 @@ namespace trklet { int TCIndex() const { return TCIndex_; } - int TCID() const { return TCIndex_ * (1 << 7) + trackletIndex_; } + int TCID() const { return TCIndex_ * (1 << settings_.nbitstrackletindex()) + trackletIndex_; } int getISeed() const; int getITC() const; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h index 6affb50111dfb..79eadb944b67e 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h @@ -30,6 +30,8 @@ namespace trklet { void readTables(); + const short memNameToIndex(const std::string& name); + private: int layer1_; int layer2_; @@ -41,7 +43,7 @@ namespace trklet { std::vector stubpairs_; - std::vector > table_; + std::vector > table_; int firstphibits_; int secondphibits_; diff --git a/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc b/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc index 88f050ea6271b..f468446048403 100644 --- a/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc +++ b/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc @@ -261,6 +261,11 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig) if (extended_) { settings.setTableTEDFile(tableTEDFile.fullPath()); settings.setTableTREFile(tableTREFile.fullPath()); + + //FIXME: The TED and TRE tables are currently disabled by default, so we + //need to allow for the additional tracklets that will eventually be + //removed by these tables, once they are finalized + settings.setNbitstrackletindex(10); } eventnum = 0; diff --git a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc index 4182fca50f7e3..440174026b1ac 100644 --- a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc +++ b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc @@ -826,7 +826,7 @@ std::vector FitTrack::orderedMatches(vector& fullma int bestIndex = -1; do { - int bestTCID = (1 << 16); + int bestTCID = -1; bestIndex = -1; for (unsigned int i = 0; i < fullmatch.size(); i++) { if (indexArray[i] >= fullmatch[i]->nMatches()) { @@ -834,7 +834,7 @@ std::vector FitTrack::orderedMatches(vector& fullma continue; } int TCID = fullmatch[i]->getTracklet(indexArray[i])->TCID(); - if (TCID < bestTCID) { + if (TCID < bestTCID || bestTCID < 0) { bestTCID = TCID; bestIndex = i; } diff --git a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc index 21b2fc8d73845..00a09b6a7044b 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc @@ -501,7 +501,7 @@ std::vector, const Stub*> > MatchCalculator: int bestIndex = -1; do { int bestSector = 100; - int bestTCID = (1 << 16); + int bestTCID = -1; bestIndex = -1; for (unsigned int i = 0; i < candmatch.size(); i++) { if (indexArray[i] >= candmatch[i]->nMatches()) { @@ -523,7 +523,7 @@ std::vector, const Stub*> > MatchCalculator: bestIndex = i; } if (dSector == bestSector) { - if (TCID < bestTCID) { + if (TCID < bestTCID || bestTCID < 0) { bestTCID = TCID; bestIndex = i; } diff --git a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc index 6488b8bc8a820..8340f44957cb7 100644 --- a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc +++ b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc @@ -274,7 +274,7 @@ std::string Tracklet::trackletprojstr(int layer) const { if (trackletIndex_ < 0 || trackletIndex_ > (int)settings_.ntrackletmax()) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " trackletIndex_ = " << trackletIndex_; } - tmp.set(trackletIndex_, 7, true, __LINE__, __FILE__); + tmp.set(trackletIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); FPGAWord tcid; if (settings_.extended()) { tcid.set(TCIndex_, 8, true, __LINE__, __FILE__); @@ -294,7 +294,7 @@ std::string Tracklet::trackletprojstrD(int disk) const { if (trackletIndex_ < 0 || trackletIndex_ > (int)settings_.ntrackletmax()) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " trackletIndex_ = " << trackletIndex_; } - tmp.set(trackletIndex_, 7, true, __LINE__, __FILE__); + tmp.set(trackletIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); FPGAWord tcid; if (settings_.extended()) { tcid.set(TCIndex_, 8, true, __LINE__, __FILE__); @@ -379,7 +379,7 @@ std::string Tracklet::fullmatchstr(int layer) { if (trackletIndex_ < 0 || trackletIndex_ > (int)settings_.ntrackletmax()) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " trackletIndex_ = " << trackletIndex_; } - tmp.set(trackletIndex_, 7, true, __LINE__, __FILE__); + tmp.set(trackletIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); FPGAWord tcid; if (settings_.extended()) { tcid.set(TCIndex_, 8, true, __LINE__, __FILE__); @@ -398,7 +398,7 @@ std::string Tracklet::fullmatchdiskstr(int disk) { if (trackletIndex_ < 0 || trackletIndex_ > (int)settings_.ntrackletmax()) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " trackletIndex_ = " << trackletIndex_; } - tmp.set(trackletIndex_, 7, true, __LINE__, __FILE__); + tmp.set(trackletIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); FPGAWord tcid; if (settings_.extended()) { tcid.set(TCIndex_, 8, true, __LINE__, __FILE__); @@ -841,9 +841,9 @@ int Tracklet::disk2() const { return innerStub_->disk() - 1; } -void Tracklet::setTrackletIndex(int index) { +void Tracklet::setTrackletIndex(unsigned int index) { trackletIndex_ = index; - assert(index < 128); + assert(index <= settings_.ntrackletmax()); } int Tracklet::getISeed() const { diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc index 145e84cb06164..201b0b9b99723 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc @@ -56,8 +56,6 @@ TrackletEngineDisplaced::TrackletEngineDisplaced(string name, firstphibits_ = settings_.nfinephi(0, iSeed_); secondphibits_ = settings_.nfinephi(1, iSeed_); - - readTables(); } TrackletEngineDisplaced::~TrackletEngineDisplaced() { table_.clear(); } @@ -100,6 +98,9 @@ void TrackletEngineDisplaced::execute() { if (!settings_.useSeed(iSeed_)) return; + if (table_.empty() && (settings_.enableTripletTables() && !settings_.writeTripletTables())) + readTables(); + unsigned int countall = 0; unsigned int countpass = 0; unsigned int nInnerStubs = 0; @@ -170,23 +171,21 @@ void TrackletEngineDisplaced::execute() { index = (index << firstbend.nbits()) + firstbend.value(); index = (index << secondbend.nbits()) + secondbend.value(); - if (index >= table_.size()) - table_.resize(index + 1); - - if (table_.at(index).empty()) { + 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()); } - if (!settings_.writeTripletTables()) - continue; + continue; } if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName(); for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) { - if (settings_.writeTripletTables() || table_.at(index).count(stubpairs_.at(isp)->getName())) { + if ((!settings_.enableTripletTables() || settings_.writeTripletTables()) || + (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; @@ -252,21 +251,21 @@ void TrackletEngineDisplaced::execute() { index = (index << firstbend.nbits()) + firstbend.value(); index = (index << secondbend.nbits()) + secondbend.value(); - if (index >= table_.size()) - table_.resize(index + 1); - - if (table_.at(index).empty()) { + 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()); } + continue; } if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName(); for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) { - if (settings_.writeTripletTables() || table_.at(index).count(stubpairs_.at(isp)->getName()) || true) { + if ((!settings_.enableTripletTables() || settings_.writeTripletTables()) || + (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; @@ -332,22 +331,22 @@ void TrackletEngineDisplaced::execute() { index = (index << firstbend.nbits()) + firstbend.value(); index = (index << secondbend.nbits()) + secondbend.value(); - if (index >= table_.size()) - table_.resize(index + 1); - - if (table_.at(index).empty()) { + 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()); } + continue; } if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "Adding disk-disk pair in " << getName(); for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) { - if (settings_.writeTripletTables() || table_.at(index).count(stubpairs_.at(isp)->getName()) || true) { + if ((!settings_.enableTripletTables() || settings_.writeTripletTables()) || + (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; @@ -408,7 +407,14 @@ void TrackletEngineDisplaced::readTables() { table_.resize(table_.size() + 1); while (iss >> word) - table_[table_.size() - 1].insert(word); + table_[table_.size() - 1].insert(memNameToIndex(word)); } fin.close(); } + +const short TrackletEngineDisplaced::memNameToIndex(const string& name) { + for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) + if (stubpairs_.at(isp)->getName() == name) + return isp; + return -1; +} diff --git a/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc b/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc index 403bf8f02ef48..a7ef1821f3273 100644 --- a/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc +++ b/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc @@ -65,7 +65,8 @@ TripletEngine::TripletEngine(string name, Settings const &settings, Globals *glo secondphibits_ = settings_.nfinephi(1, iSeed_); thirdphibits_ = settings_.nfinephi(2, iSeed_); } - readTables(); + if (settings_.enableTripletTables() && !settings_.writeTripletTables()) + readTables(); } TripletEngine::~TripletEngine() { @@ -201,29 +202,29 @@ void TripletEngine::execute() { index = (index << secondbend.nbits()) + secondbend.value(); index = (index << thirdbend.nbits()) + thirdbend.value(); - if (index >= table_.size()) - table_.resize(index + 1, false); - - if (!table_[index]) { + if ((settings_.enableTripletTables() && !settings_.writeTripletTables()) && + (index >= table_.size() || !table_[index])) { 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()); } - if (!settings_.writeTripletTables()) - continue; + continue; } - if (settings_.writeTripletTables()) + if (settings_.writeTripletTables()) { + if (index >= table_.size()) + table_.resize(index + 1, false); table_[index] = true; - const unsigned spIndex = stubpairs_.at(i)->getIndex(j); - const string &tedName = stubpairs_.at(i)->getTEDName(j); - if (!tmpSPTable_.count(tedName)) - tmpSPTable_[tedName]; - if (spIndex >= tmpSPTable_.at(tedName).size()) - tmpSPTable_.at(tedName).resize(spIndex + 1); - tmpSPTable_.at(tedName).at(spIndex).push_back(stubpairs_.at(i)->getName()); + const unsigned spIndex = stubpairs_.at(i)->getIndex(j); + const string &tedName = stubpairs_.at(i)->getTEDName(j); + if (!tmpSPTable_.count(tedName)) + tmpSPTable_[tedName]; + if (spIndex >= tmpSPTable_.at(tedName).size()) + tmpSPTable_.at(tedName).resize(spIndex + 1); + tmpSPTable_.at(tedName).at(spIndex).push_back(stubpairs_.at(i)->getName()); + } if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName(); @@ -284,27 +285,29 @@ void TripletEngine::execute() { index = (index << secondbend.nbits()) + secondbend.value(); index = (index << thirdbend.nbits()) + thirdbend.value(); - if (index >= table_.size()) - table_.resize(index + 1, false); - - if (!table_[index]) { + if ((settings_.enableTripletTables() && !settings_.writeTripletTables()) && + (index >= table_.size() || !table_[index])) { 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()); } + continue; } - if (settings_.writeTripletTables()) + if (settings_.writeTripletTables()) { + if (index >= table_.size()) + table_.resize(index + 1, false); table_[index] = true; - const unsigned spIndex = stubpairs_.at(i)->getIndex(j); - const string &tedName = stubpairs_.at(i)->getTEDName(j); - if (!tmpSPTable_.count(tedName)) - tmpSPTable_[tedName]; - if (spIndex >= tmpSPTable_.at(tedName).size()) - tmpSPTable_.at(tedName).resize(spIndex + 1); - tmpSPTable_.at(tedName).at(spIndex).push_back(stubpairs_.at(i)->getName()); + const unsigned spIndex = stubpairs_.at(i)->getIndex(j); + const string &tedName = stubpairs_.at(i)->getTEDName(j); + if (!tmpSPTable_.count(tedName)) + tmpSPTable_[tedName]; + if (spIndex >= tmpSPTable_.at(tedName).size()) + tmpSPTable_.at(tedName).resize(spIndex + 1); + tmpSPTable_.at(tedName).at(spIndex).push_back(stubpairs_.at(i)->getName()); + } if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "Adding layer-disk pair in " << getName(); @@ -366,27 +369,29 @@ void TripletEngine::execute() { index = (index << secondbend.nbits()) + secondbend.value(); index = (index << thirdbend.nbits()) + thirdbend.value(); - if (index >= table_.size()) - table_.resize(index + 1, false); - - if (!table_[index]) { + if ((settings_.enableTripletTables() && !settings_.writeTripletTables()) && + (index >= table_.size() || !table_[index])) { 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()); } + continue; } - if (settings_.writeTripletTables()) + if (settings_.writeTripletTables()) { + if (index >= table_.size()) + table_.resize(index + 1, false); table_[index] = true; - const unsigned spIndex = stubpairs_.at(i)->getIndex(j); - const string &tedName = stubpairs_.at(i)->getTEDName(j); - if (!tmpSPTable_.count(tedName)) - tmpSPTable_[tedName]; - if (spIndex >= tmpSPTable_.at(tedName).size()) - tmpSPTable_.at(tedName).resize(spIndex + 1); - tmpSPTable_.at(tedName).at(spIndex).push_back(stubpairs_.at(i)->getName()); + const unsigned spIndex = stubpairs_.at(i)->getIndex(j); + const string &tedName = stubpairs_.at(i)->getTEDName(j); + if (!tmpSPTable_.count(tedName)) + tmpSPTable_[tedName]; + if (spIndex >= tmpSPTable_.at(tedName).size()) + tmpSPTable_.at(tedName).resize(spIndex + 1); + tmpSPTable_.at(tedName).at(spIndex).push_back(stubpairs_.at(i)->getName()); + } if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "Adding layer-disk pair in " << getName();