Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update of L1 tracking (matching PR #30168) #30245

Merged
merged 7 commits into from Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions L1Trigger/TrackFindingTracklet/interface/MemoryBase.h
Expand Up @@ -37,6 +37,8 @@ namespace trklet {

void openFile(bool first, std::string filebase);

static size_t find_nth(const std::string& haystack, size_t pos, const std::string& needle, size_t nth);

protected:
std::string name_;
unsigned int iSector_;
Expand Down
34 changes: 32 additions & 2 deletions L1Trigger/TrackFindingTracklet/interface/Settings.h
Expand Up @@ -42,6 +42,8 @@ namespace trklet {
std::string const& processingModulesFile() const { return processingModulesFile_; }
std::string const& memoryModulesFile() const { return memoryModulesFile_; }
std::string const& wiresFile() const { return wiresFile_; }
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; }
Expand All @@ -54,6 +56,8 @@ namespace trklet {
}
void setMemoryModulesFile(std::string memoryModulesFileName) { memoryModulesFile_ = memoryModulesFileName; }
void setWiresFile(std::string wiresFileName) { wiresFile_ = wiresFileName; }
void setTableTEDFile(std::string tableTEDFileName) { tableTEDFile_ = tableTEDFileName; }
void setTableTREFile(std::string tableTREFileName) { tableTREFile_ = tableTREFileName; }

unsigned int nzbitsstub(unsigned int layerdisk) const { return nzbitsstub_[layerdisk]; }
unsigned int nphibitsstub(unsigned int layerdisk) const { return nphibitsstub_[layerdisk]; }
Expand All @@ -65,6 +69,8 @@ namespace trklet {
unsigned int nbitszprojderL123() const { return nbitszprojderL123_; }
unsigned int nbitszprojderL456() const { return nbitszprojderL456_; }

unsigned int nbendbitsmedisk() const { return nbendbitsmedisk_; }

bool useSeed(unsigned int iSeed) const { return useseeding_.find(iSeed) != useseeding_.end(); }
unsigned int nbitsvmte(unsigned int inner, unsigned int iSeed) const { return nbitsvmte_[inner][iSeed]; }
unsigned int nvmte(unsigned int inner, unsigned int iSeed) const { return (1 << nbitsvmte_[inner][iSeed]); }
Expand Down Expand Up @@ -172,8 +178,13 @@ namespace trklet {
unsigned int MEBinsBits() const { return MEBinsBits_; }
unsigned int MEBins() const { return 1u << MEBinsBits_; }
unsigned int MEBinsDisks() const { return MEBinsDisks_; }
unsigned int maxStubsPerBin() const { return maxStubsPerBin_; }

std::string geomext() const { return extended_ ? "hourglassExtended" : "hourglass"; }
std::string geomext() const {
if (combined_)
return "hourglassCombined";
return extended_ ? "hourglassExtended" : "hourglass";
}

bool exactderivatives() const { return exactderivatives_; }
bool exactderivativesforfloating() const { return exactderivativesforfloating_; }
Expand All @@ -184,6 +195,7 @@ namespace trklet {
std::string removalType() const { return removalType_; }
std::string mergeComparison() const { return mergeComparison_; }
bool doKF() const { return doKF_; }
bool doMultipleMatches() const { return doMultipleMatches_; }
bool fakefit() const { return fakefit_; }

// configurable
Expand All @@ -192,6 +204,8 @@ namespace trklet {

bool extended() const { return extended_; }
void setExtended(bool extended) { extended_ = extended; }
bool combined() const { return combined_; }
void setCombined(bool combined) { combined_ = combined; }

double bfield() const { return bfield_; }
void setBfield(double bfield) { bfield_ = bfield; }
Expand Down Expand Up @@ -332,6 +346,8 @@ namespace trklet {
std::string processingModulesFile_;
std::string memoryModulesFile_;
std::string wiresFile_;
std::string tableTEDFile_;
std::string tableTREFile_;

double rcrit_{55.0}; // critical radius for the hourglass configuration

Expand All @@ -355,6 +371,8 @@ namespace trklet {
unsigned int nbitszprojderL123_{10};
unsigned int nbitszprojderL456_{9};

unsigned int nbendbitsmedisk_{4}; // Always 4 bits even for PS disk hits, for HLS compatibility

std::set<unsigned int> useseeding_{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};

std::array<unsigned int, N_LAYER + N_DISK> nbitsallstubs_{{3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}};
Expand Down Expand Up @@ -466,7 +484,7 @@ namespace trklet {
{{5, 4, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4}}, //outer
{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4}}}}; //outermost (triplets only)

std::array<std::array<unsigned int, N_SEED>, 3> lutwidthtab_{{{{10, 11, 11, 11, 11, 11, 11, 11, 0, 0, 11, 0}},
std::array<std::array<unsigned int, N_SEED>, 3> lutwidthtab_{{{{10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 11, 0}},
{{6, 6, 6, 6, 10, 10, 10, 10, 0, 0, 6, 0}},
{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6}}}};

Expand Down Expand Up @@ -553,8 +571,11 @@ 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

//Offset to the maximum number of steps in each processing step. Set to 0 for standard
//trunction. Set to large value, e.g. 10000 to remove truncation
unsigned int maxstepoffset_{10000};

//Default number of processing steps for one event
std::unordered_map<std::string, unsigned int> maxstep_{{"Link", 108},
{"MC", 108},
{"ME", 108},
Expand All @@ -566,6 +587,7 @@ namespace trklet {
{"TRE", 108},
{"VMR", 108}};

// If set to true this will generate debub printout in text files
std::unordered_map<std::string, bool> writeMonitorData_{{"IL", false},
{"TE", false},
{"CT", false},
Expand Down Expand Up @@ -643,6 +665,7 @@ namespace trklet {

unsigned int MEBinsBits_{3};
unsigned int MEBinsDisks_{8}; //on each side
unsigned int maxStubsPerBin_{16};

// Options for chisq fit
bool exactderivatives_{false};
Expand Down Expand Up @@ -671,11 +694,18 @@ namespace trklet {
std::string mergeComparison_{""};
#endif

// When false, match calculator does not save multiple matches, even when doKF=true.
// This is a temporary fix for compatibilty with HLS. We will need to implement multiple match
// printing in emulator eventually, possibly after CMSSW-integration inspired rewrites
// Use false when generating HLS files, use true when doing full hybrid tracking
bool doMultipleMatches_{true};

// if true, run a dummy fit, producing TTracks directly from output of tracklet pattern reco stage
bool fakefit_{false};

unsigned int nHelixPar_{4}; // 4 or 5 param helix fit
bool extended_{false}; // turn on displaced tracking
bool combined_{false}; // use combined TP (TE+TC) and MP (PR+ME+MC) configuration

std::string skimfile_{""}; //if not empty events will be written out in ascii format to this file

Expand Down
1 change: 0 additions & 1 deletion L1Trigger/TrackFindingTracklet/interface/VMStubTE.h
Expand Up @@ -37,7 +37,6 @@ namespace trklet {

private:
FPGAWord finephi_;
FPGAWord finerz_;
FPGAWord bend_;
FPGAWord vmbits_;
FPGAWord allStubIndex_;
Expand Down
6 changes: 5 additions & 1 deletion L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h
Expand Up @@ -19,7 +19,11 @@ namespace trklet {

~VMStubsMEMemory() override = default;

void addStub(VMStubME stub, unsigned int bin) { binnedstubs_[bin].push_back(stub); }
void addStub(VMStubME stub, unsigned int bin) {
if (binnedstubs_[bin].size() < settings_.maxStubsPerBin()) {
binnedstubs_[bin].push_back(stub);
}
}

unsigned int nStubsBin(unsigned int bin) const {
assert(bin < binnedstubs_.size());
Expand Down
21 changes: 18 additions & 3 deletions L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc
Expand Up @@ -151,9 +151,11 @@ class L1FPGATrackProducer : public edm::stream::EDProducer<> {

edm::FileInPath DTCLinkFile;
edm::FileInPath moduleCablingFile;

edm::FileInPath DTCLinkLayerDiskFile;

edm::FileInPath tableTEDFile;
edm::FileInPath tableTREFile;

string asciiEventOutName_;
std::ofstream asciiEventOut_;

Expand Down Expand Up @@ -230,12 +232,16 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig)

DTCLinkFile = iConfig.getParameter<edm::FileInPath>("DTCLinkFile");
moduleCablingFile = iConfig.getParameter<edm::FileInPath>("moduleCablingFile");

DTCLinkLayerDiskFile = iConfig.getParameter<edm::FileInPath>("DTCLinkLayerDiskFile");

extended_ = iConfig.getParameter<bool>("Extended");
nHelixPar_ = iConfig.getParameter<unsigned int>("Hnpar");

if (extended_) {
tableTEDFile = iConfig.getParameter<edm::FileInPath>("tableTEDFile");
tableTREFile = iConfig.getParameter<edm::FileInPath>("tableTREFile");
}

// --------------------------------------------------------------------------------
// set options in Settings based on inputs from configuration files
// --------------------------------------------------------------------------------
Expand All @@ -251,6 +257,11 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig)
settings.setMemoryModulesFile(memoryModulesFile.fullPath());
settings.setWiresFile(wiresFile.fullPath());

if (extended_) {
settings.setTableTEDFile(tableTEDFile.fullPath());
settings.setTableTREFile(tableTREFile.fullPath());
}

eventnum = 0;
if (not asciiEventOutName_.empty()) {
asciiEventOut_.open(asciiEventOutName_.c_str());
Expand All @@ -264,6 +275,10 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig)
<< "\n process modules : " << processingModulesFile.fullPath()
<< "\n memory modules : " << memoryModulesFile.fullPath()
<< "\n wires : " << wiresFile.fullPath();
if (extended_) {
edm::LogVerbatim("Tracklet") << "table_TED : " << tableTEDFile.fullPath()
<< "\n table_TRE : " << tableTREFile.fullPath();
}
}
}

Expand Down Expand Up @@ -554,7 +569,7 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
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());
bool isFlipped = (posStub_outer.mag() < posStub_inner.mag());

// -----------------------------------------------------
// correct sign for stubs in negative endcap
Expand Down
3 changes: 3 additions & 0 deletions L1Trigger/TrackFindingTracklet/python/Tracklet_cfi.py
Expand Up @@ -27,5 +27,8 @@
memoryModulesFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/memorymodules_hourglassExtended.dat'),
processingModulesFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/processingmodules_hourglassExtended.dat'),
wiresFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/wires_hourglassExtended.dat'),
# specifying where the TrackletEngineDisplaced(TED)/TripletEngine(TRE) tables are located
tableTEDFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/table_TED/table_TED_D1PHIA1_D2PHIA1.txt'),
tableTREFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/table_TRE/table_TRE_D1AD2A_1.txt')
)

7 changes: 4 additions & 3 deletions L1Trigger/TrackFindingTracklet/src/FitTrack.cc
Expand Up @@ -277,7 +277,7 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector<const Stub*>&, std:
}
}

for (unsigned int d1 = 1; d1 <= N_DISK; d1++) {
for (int d1 = 1; d1 <= N_DISK; d1++) {
int d = d1;

// skip F/B5 if there's already a L2 match
Expand All @@ -286,7 +286,7 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector<const Stub*>&, std:

if (tracklet->fpgat().value() < 0.0)
d = -d1;
if (d == tracklet->disk() || d == tracklet->disk2()) {
if (d1 == abs(tracklet->disk()) || d1 == abs(tracklet->disk()) + 1) {
dmatches.set(2 * d1 - 1);
diskmask |= (1 << (2 * (N_DISK - d1) + 1));
alpha[ndisks] = 0.0;
Expand Down Expand Up @@ -981,7 +981,8 @@ void FitTrack::execute() {
nMatchesUniq++;

if (settings_.debugTracklet()) {
edm::LogVerbatim("Tracklet") << getName() << " : nMatches = " << nMatches << " " << asinh(bestTracklet->t());
edm::LogVerbatim("Tracklet") << getName() << " : nMatches = " << nMatches << " nMatchesUniq = " << nMatchesUniq
<< " " << asinh(bestTracklet->t());
}

std::vector<const Stub*> trackstublist;
Expand Down
10 changes: 4 additions & 6 deletions L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc
Expand Up @@ -10,15 +10,13 @@ using namespace trklet;

FullMatchMemory::FullMatchMemory(string name, Settings const& settings, unsigned int iSector)
: MemoryBase(name, settings, iSector) {
if (settings_.extended()) {
initLayerDisk(10, layer_, disk_);
} else {
initLayerDisk(8, layer_, disk_);
}
size_t pos = find_nth(name, 0, "_", 1);
assert(pos != string::npos);
initLayerDisk(pos + 1, layer_, disk_);
}

void FullMatchMemory::addMatch(Tracklet* tracklet, const Stub* stub) {
if (!settings_.doKF()) { //When using KF we allow multiple matches
if (!settings_.doKF() || !settings_.doMultipleMatches()) { //When using KF we allow multiple matches
for (auto& match : matches_) {
if (match.first == tracklet) { //Better match, replace
match.second = stub;
Expand Down
1 change: 1 addition & 0 deletions L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc
Expand Up @@ -48,6 +48,7 @@ void MatchEngineUnit::step() {
int deltaphi = stubfinephi - projfinephi_;

bool dphicut = (abs(deltaphi) < 3) || (abs(deltaphi) > 5); //TODO - need better implementations
dphicut = true; //Not used until cuts cleaned up

if (!barrel_)
dphicut = true;
Expand Down
13 changes: 12 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc
Expand Up @@ -246,8 +246,11 @@ void MatchProcessor::execute() {
iprojmem++;
} else if (iproj < projMem->nTracklets()) {
if (!inputProjBuffer_.almostfull()) {
Tracklet* proj = projMem->getTracklet(iproj);
if (settings_.debugTracklet()) {
edm::LogVerbatim("Tracklet") << getName() << " have projection in memory : " << projMem->getName();
}

Tracklet* proj = projMem->getTracklet(iproj);
FPGAWord fpgaphi = barrel_ ? proj->fpgaphiproj(layer_) : proj->fpgaphiprojdisk(disk_);

int iphi = (fpgaphi.value() >> (fpgaphi.nbits() - nvmbits_)) & (nvmbins_ - 1);
Expand Down Expand Up @@ -314,6 +317,10 @@ void MatchProcessor::execute() {
ProjectionTemp tmpProj = inputProjBuffer_.read();
VMStubsMEMemory* stubmem = vmstubs_[tmpProj.iphi()];

if (settings_.debugTracklet()) {
edm::LogVerbatim("Tracklet") << getName() << " adding projection to match engine";
}

matchengines_[iME].init(stubmem,
tmpProj.slot(),
tmpProj.projrinv(),
Expand Down Expand Up @@ -357,6 +364,10 @@ void MatchProcessor::execute() {

bool match = matchCalculator(tracklet, fpgastub);

if (settings_.debugTracklet() && match) {
edm::LogVerbatim("Tracklet") << getName() << " have match";
}

countall++;
if (match)
countsel++;
Expand Down
7 changes: 7 additions & 0 deletions L1Trigger/TrackFindingTracklet/src/MemoryBase.cc
Expand Up @@ -104,3 +104,10 @@ void MemoryBase::openFile(bool first, std::string filebase) {
if (bx_ > 7)
bx_ = 0;
}

size_t MemoryBase::find_nth(const string& haystack, size_t pos, const string& needle, size_t nth) {
size_t found_pos = haystack.find(needle, pos);
if (0 == nth || string::npos == found_pos)
return found_pos;
return find_nth(haystack, found_pos + 1, needle, nth - 1);
}
2 changes: 1 addition & 1 deletion L1Trigger/TrackFindingTracklet/src/ProcessBase.cc
Expand Up @@ -93,7 +93,7 @@ void ProcessBase::initLayerDisksandISeed(unsigned int& layerdisk1, unsigned int&
}
}

if (name_.substr(0, 3) == "TC_") {
if ((name_.substr(0, 3) == "TC_") || (name_.substr(0, 3) == "TP_")) {
if (name_[3] == 'L') {
layerdisk1 = name_[4] - '1';
} else if (name_[3] == 'D') {
Expand Down
3 changes: 2 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/PurgeDuplicate.cc
Expand Up @@ -67,7 +67,8 @@ void PurgeDuplicate::addInput(MemoryBase* memory, std::string input) {
"trackin8",
"trackin9",
"trackin10",
"trackin11"};
"trackin11",
"trackin12"};
if (inputs.find(input) != inputs.end()) {
auto* tmp = dynamic_cast<TrackFitMemory*>(memory);
assert(tmp != nullptr);
Expand Down
6 changes: 4 additions & 2 deletions L1Trigger/TrackFindingTracklet/src/Tracklet.cc
Expand Up @@ -209,8 +209,10 @@ std::string Tracklet::trackletparstr() {
if (middleFPGAStub_) {
str += middleFPGAStub_->stubindex().str() + "|";
}
str += outerFPGAStub_->stubindex().str() + "|" + fpgapars_.rinv().str() + "|" + fpgapars_.phi0().str() + "|" +
fpgapars_.d0().str() + "|" + fpgapars_.z0().str() + "|" + fpgapars_.t().str();
str += outerFPGAStub_->stubindex().str() + "|" + fpgapars_.rinv().str() + "|" + fpgapars_.phi0().str() + "|";
if (middleFPGAStub_)
str += fpgapars_.d0().str() + "|";
str += fpgapars_.z0().str() + "|" + fpgapars_.t().str();
return str;
}
}
Expand Down
Expand Up @@ -1075,7 +1075,7 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub,
true);

if (settings_.debugTracklet()) {
edm::LogVerbatim("Tracklet") << "Found tracklet for seed = " << iSeed_ << " " << tracklet << " " << iSector_;
edm::LogVerbatim("Tracklet") << "Found tracklet for disk seed = " << iSeed_ << " " << tracklet << " " << iSector_;
}

tracklet->setTrackletIndex(trackletpars_->nTracklets());
Expand Down