Skip to content

Commit

Permalink
Minor improvements (cms-sw#120)
Browse files Browse the repository at this point in the history
* Minor improvements

* Added comments
  • Loading branch information
tomalin committed Jun 10, 2022
1 parent c592cb7 commit d870e5e
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 29 deletions.
7 changes: 7 additions & 0 deletions L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h
Expand Up @@ -7,6 +7,13 @@

#include <vector>

// Run algorithm to remove duplicate tracks.
// Returns Track object that represent output at end of L1 track chain,
// (and are later converted to TTTrack). Duplicate Track objects are flagged,
// but only deleted if using the Hybrid algo.
// Also writes to memory the same tracks in more detailed Tracklet format,
// where duplicates are all deleted.

namespace trklet {

class Settings;
Expand Down
3 changes: 3 additions & 0 deletions L1Trigger/TrackFindingTracklet/interface/Settings.h
Expand Up @@ -298,6 +298,7 @@ namespace trklet {
double phicritminmc() const { return phicritmin() - dphicritmc_; }
double phicritmaxmc() const { return phicritmax() + dphicritmc_; }

// Stub digitization granularities
double kphi() const { return dphisectorHG() / (1 << nphibitsstub(0)); }
double kphi1() const { return dphisectorHG() / (1 << nphibitsstub(N_LAYER - 1)); }
double kphi(unsigned int layerdisk) const { return dphisectorHG() / (1 << nphibitsstub(layerdisk)); }
Expand Down Expand Up @@ -383,6 +384,7 @@ namespace trklet {
int chisqphifactbits() const { return chisqphifactbits_; }
int chisqzfactbits() const { return chisqzfactbits_; }

// Helix param digisation granularities
//0.02 here is the maximum range in rinv values that can be represented
double krinvpars() const {
int shift = ceil(-log2(0.02 * rmaxdisk_ / ((1 << nbitsrinv_) * dphisectorHG())));
Expand Down Expand Up @@ -775,6 +777,7 @@ namespace trklet {
{"PR", 108},
{"ME", 108},
{"MC", 105},
{"TB", 108},
{"MP", 108},
{"TP", 108},
{"TRE", 108}};
Expand Down
6 changes: 4 additions & 2 deletions L1Trigger/TrackFindingTracklet/interface/Track.h
Expand Up @@ -17,8 +17,9 @@ namespace trklet {

class Track {
public:
Track(TrackPars<int> ipars,
int ichisqrphi,
// Create track from digitized helix params & stubs
Track(TrackPars<int> ipars, // digi helix
int ichisqrphi, // digi chi2
int ichisqrz,
double chisqrphi,
double chisqrz,
Expand Down Expand Up @@ -54,6 +55,7 @@ namespace trklet {
return (settings.c() * settings.bfield() * 0.01) / (ipars_.rinv() * settings.krinvpars());
}

// Get floating point helix params by undigitized digi helix params
double phi0(Settings const& settings) const;

double eta(Settings const& settings) const { return asinh(ipars_.t() * settings.ktpars()); }
Expand Down
2 changes: 2 additions & 0 deletions L1Trigger/TrackFindingTracklet/interface/Tracklet.h
Expand Up @@ -157,6 +157,7 @@ namespace trklet {
return FPGAWord(ichisqrphifit_.value() + ichisqrzfit_.value(), ichisqrphifit_.nbits());
}

// Note floating & digitized helix params after track fit.
void setFitPars(double rinvfit,
double phi0fit,
double d0fit,
Expand Down Expand Up @@ -185,6 +186,7 @@ namespace trklet {
const std::string diskstubstr(const unsigned disk) const;
std::string trackfitstr() const;

// Create a Track object from stubs & digitized track helix params
Track makeTrack(const std::vector<const L1TStub*>& l1stubs);

Track* getTrack() {
Expand Down
21 changes: 12 additions & 9 deletions L1Trigger/TrackFindingTracklet/src/FitTrack.cc
Expand Up @@ -124,13 +124,15 @@ void FitTrack::trackFitKF(Tracklet* tracklet,
stubidslist.push_back(std::make_pair(layer, it->phiregionaddress()));
}

// And that's all we need! The rest is just for fitting (in PurgeDuplicate)
return;
}
// And that's all we need! The rest is just for track fit (done in PurgeDuplicate)

HybridFit hybridFitter(iSector_, settings_, globals_);
hybridFitter.Fit(tracklet, trackstublist);
return;
} else {

// Track fit only called here if not running duplicate removal
// before fit. (e.g. If skipping duplicate removal).
HybridFit hybridFitter(iSector_, settings_, globals_);
hybridFitter.Fit(tracklet, trackstublist);
}
}
}
#endif
Expand Down Expand Up @@ -889,8 +891,8 @@ void FitTrack::execute(unsigned int iSector) {
indexArray[i] = 0;
}

int countAll = 0;
int countFit = 0;
unsigned int countAll = 0;
unsigned int countFit = 0;

Tracklet* bestTracklet = nullptr;
do {
Expand Down Expand Up @@ -989,6 +991,7 @@ void FitTrack::execute(unsigned int iSector) {

std::vector<const Stub*> trackstublist;
std::vector<std::pair<int, int>> stubidslist;
// Track Builder cut of >= 4 layers with stubs.
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++;
Expand Down Expand Up @@ -1021,7 +1024,7 @@ void FitTrack::execute(unsigned int iSector) {
}
}

} while (bestTracklet != nullptr);
} while (bestTracklet != nullptr && countAll < settings_.maxStep("TB"));

if (settings_.writeMonitorData("FT")) {
globals_->ofstream("fittrack.txt") << getName() << " " << countAll << " " << countFit << endl;
Expand Down
39 changes: 21 additions & 18 deletions L1Trigger/TrackFindingTracklet/src/PurgeDuplicate.cc
Expand Up @@ -323,26 +323,29 @@ void PurgeDuplicate::execute(std::vector<Track>& outputtracks_, unsigned int iSe

// Make the final track objects, fit with KF, and send to output
for (unsigned int itrk = 0; itrk < numStublists; itrk++) {
Tracklet* tracklet = inputtracklets_[itrk];
std::vector<const Stub*> trackstublist = inputstublists_[itrk];

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);
if (trackInfo[itrk].second == true)
outtrack->setDuplicate(true);
else
bool duplicateTrack = trackInfo[itrk].second;
if (not duplicateTrack) { // Don't waste CPU by calling KF for duplicates

Tracklet* tracklet = inputtracklets_[itrk];
std::vector<const Stub*> trackstublist = inputstublists_[itrk];

// Run KF track fit
HybridFit hybridFitter(iSector, settings_, globals_);
hybridFitter.Fit(tracklet, trackstublist);

// If the track was accepted (and thus fit), add to output
if (tracklet->fit()) {
// Add fitted Track to output (later converted to TTTrack)
Track* outtrack = tracklet->getTrack();
outtrack->setSector(iSector);
// Also store fitted track as more detailed Tracklet object.
outputtracklets_[trackInfo[itrk].first]->addTrack(tracklet);

// Add all tracks to standalone root file output
outtrack->setStubIDpremerge(inputstubidslists_[itrk]);
outtrack->setStubIDprefit(mergedstubidslists_[itrk]);
outputtracks_.push_back(*outtrack);
// Add all tracks to standalone root file output
outtrack->setStubIDpremerge(inputstubidslists_[itrk]);
outtrack->setStubIDprefit(mergedstubidslists_[itrk]);
outputtracks_.push_back(*outtrack);
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions L1Trigger/TrackFindingTracklet/src/Sector.cc
Expand Up @@ -410,12 +410,17 @@ void Sector::executeMP() {
}
}

// Order here reflects Tracklet algo that calls FitTrack before PurgeDuplicates.
// If using Hybrid, then PurgeDuplicates runs both duplicate removal & KF steps.
// (unless duplicate removal disabled, in which case FitTrack runs KF).

void Sector::executeFT() {
for (auto& i : FT_) {
i->execute(isector_);
}
}

// Returns tracks reconstructed by L1 track chain.
void Sector::executePD(std::vector<Track>& tracks) {
for (auto& i : PD_) {
i->execute(tracks, isector_);
Expand Down
3 changes: 3 additions & 0 deletions L1Trigger/TrackFindingTracklet/src/Tracklet.cc
Expand Up @@ -735,9 +735,12 @@ std::string Tracklet::trackfitstr() const {
return oss;
}

// Create a Track object from stubs & digitized track helix params

Track Tracklet::makeTrack(const vector<const L1TStub*>& l1stubs) {
assert(fit());

// Digitized track helix params
TrackPars<int> ipars(fpgafitpars_.rinv().value(),
fpgafitpars_.phi0().value(),
fpgafitpars_.d0().value(),
Expand Down

0 comments on commit d870e5e

Please sign in to comment.