Skip to content

Commit

Permalink
Disabled the TED and TRE tables by default. (#47)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
aehart authored and aryd committed Dec 8, 2020
1 parent 4caaabd commit cb90ebc
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 73 deletions.
19 changes: 13 additions & 6 deletions L1Trigger/TrackFindingTracklet/interface/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ namespace trklet {

unsigned int writememsect() const { return writememsect_; }

bool enableTripletTables() const { return enableTripletTables_; }
bool writeTripletTables() const { return writeTripletTables_; }

bool writeoutReal() const { return writeoutReal_; }
Expand Down Expand Up @@ -243,6 +244,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 {
double rsectmin=21.8;
double rsectmax=112.7;
Expand Down Expand Up @@ -292,7 +296,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_; }
Expand Down Expand Up @@ -466,7 +470,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};
Expand Down Expand Up @@ -745,10 +749,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};

Expand Down
4 changes: 2 additions & 2 deletions L1Trigger/TrackFindingTracklet/interface/Tracklet.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,15 @@ 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_; }

void setTCIndex(int index) { TCIndex_ = index; }

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace trklet {

void readTables();

const short memNameToIndex(const std::string& name);

private:
int layer1_;
int layer2_;
Expand All @@ -41,7 +43,7 @@ namespace trklet {

std::vector<StubPairsMemory*> stubpairs_;

std::vector<std::set<std::string> > table_;
std::vector<std::set<short> > table_;

int firstphibits_;
int secondphibits_;
Expand Down
5 changes: 5 additions & 0 deletions L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,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;
Expand Down
4 changes: 2 additions & 2 deletions L1Trigger/TrackFindingTracklet/src/FitTrack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -826,15 +826,15 @@ std::vector<Tracklet*> FitTrack::orderedMatches(vector<FullMatchMemory*>& 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()) {
//skip as we were at the end
continue;
}
int TCID = fullmatch[i]->getTracklet(indexArray[i])->TCID();
if (TCID < bestTCID) {
if (TCID < bestTCID || bestTCID < 0) {
bestTCID = TCID;
bestIndex = i;
}
Expand Down
4 changes: 2 additions & 2 deletions L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ std::vector<std::pair<std::pair<Tracklet*, int>, 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()) {
Expand All @@ -523,7 +523,7 @@ std::vector<std::pair<std::pair<Tracklet*, int>, const Stub*> > MatchCalculator:
bestIndex = i;
}
if (dSector == bestSector) {
if (TCID < bestTCID) {
if (TCID < bestTCID || bestTCID < 0) {
bestTCID = TCID;
bestIndex = i;
}
Expand Down
12 changes: 6 additions & 6 deletions L1Trigger/TrackFindingTracklet/src/Tracklet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand All @@ -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__);
Expand Down Expand Up @@ -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__);
Expand All @@ -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__);
Expand Down Expand Up @@ -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 {
Expand Down
43 changes: 26 additions & 17 deletions L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ TrackletEngineDisplaced::TrackletEngineDisplaced(string name,

firstphibits_ = settings_.nfinephi(0, iSeed_);
secondphibits_ = settings_.nfinephi(1, iSeed_);

readTables();
}

TrackletEngineDisplaced::~TrackletEngineDisplaced() { table_.clear(); }
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -170,23 +171,24 @@ 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 : "
<< settings_.benddecode(firstvmstub.bend().value(),layer1_-1, firstvmstub.isPSmodule()) << " "
<< settings_.benddecode(secondvmstub.bend().value(),layer2_-1, secondvmstub.isPSmodule());
}

//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_.writeTripletTables() || table_.at(index).count(stubpairs_.at(isp)->getName())||true) {
if (settings_.writeMonitorData("Seeds")) {
ofstream fout("seeds.txt", ofstream::app);
Expand Down Expand Up @@ -253,21 +255,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 : "
<< settings_.benddecode(firstvmstub.bend().value(), layer1_-1, firstvmstub.isPSmodule()) << " "
<< settings_.benddecode(secondvmstub.bend().value(), layer2_-1, 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;
Expand Down Expand Up @@ -333,22 +335,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 : "
<< settings_.benddecode(firstvmstub.bend().value(), disk1_+5, firstvmstub.isPSmodule()) << " "
<< settings_.benddecode(secondvmstub.bend().value(), disk2_+5, 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;
Expand Down Expand Up @@ -409,7 +411,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;
}
Loading

0 comments on commit cb90ebc

Please sign in to comment.