Skip to content

Commit

Permalink
Merge branch 'L1TK-dev-12_0_0_pre4' into tschuh_SummerChainDemonstrator
Browse files Browse the repository at this point in the history
  • Loading branch information
tschuh authored Feb 4, 2022
2 parents 0c9c972 + ab44554 commit a809821
Show file tree
Hide file tree
Showing 15 changed files with 279 additions and 195 deletions.
7 changes: 7 additions & 0 deletions L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h
Original file line number Diff line number Diff line change
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
7 changes: 5 additions & 2 deletions L1Trigger/TrackFindingTracklet/interface/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,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 @@ -387,6 +388,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 @@ -773,12 +775,13 @@ namespace trklet {
//input links running at 25 Gbits/s
//Set to 108 to match firmware project 240 MHz clock

{"VMR", 108},
{"VMR", 107},
{"TE", 107},
{"TC", 108},
{"PR", 108},
{"ME", 108},
{"MC", 105},
{"MC", 104},
{"TB", 108},
{"MP", 108},
{"TP", 108},
{"TRE", 108}};
Expand Down
19 changes: 11 additions & 8 deletions L1Trigger/TrackFindingTracklet/interface/Track.h
Original file line number Diff line number Diff line change
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,13 +55,15 @@ 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()); }
double tanL(Settings const& settings) const { return ipars_.t() * settings.ktpars(); }
double z0(Settings const& settings) const { return ipars_.z0() * settings.kz0pars(); }
double rinv(Settings const& settings) const { return ipars_.rinv() * settings.krinvpars(); }
double d0(Settings const& settings) const { return ipars_.d0() * settings.kd0pars(); }
//The following return the floating point track parameters by undigitizing the digitized parameters
double eta(Settings const& settings) const { return (asinh(ipars_.t() + 0.5) * settings.ktpars()); }
double tanL(Settings const& settings) const { return (ipars_.t() + 0.5) * settings.ktpars(); }
double z0(Settings const& settings) const { return (ipars_.z0() + 0.5) * settings.kz0pars(); }
double rinv(Settings const& settings) const { return (ipars_.rinv() + 0.5) * settings.krinvpars(); }
double d0(Settings const& settings) const { return (ipars_.d0() + 0.5) * settings.kd0pars(); }
double chisq() const { return chisqrphi_ + chisqrz_; }

double chisqrphi() const { return chisqrphi_; }
Expand All @@ -76,7 +79,7 @@ namespace trklet {
}

private:
TrackPars<int> ipars_;
TrackPars<int> ipars_; //digitized track parameters
int ichisqrphi_;
int ichisqrz_;

Expand Down
2 changes: 2 additions & 0 deletions L1Trigger/TrackFindingTracklet/interface/Tracklet.h
Original file line number Diff line number Diff line change
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
6 changes: 3 additions & 3 deletions L1Trigger/TrackFindingTracklet/src/FPGAWord.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ void FPGAWord::set(int value, int nbits, bool positive, int line, const char* fi
}
assert(value < (1 << nbits));
} else {
if (value > (1 << (nbits - 1))) {
edm::LogProblem("Tracklet") << "value too large:" << value << " " << (1 << (nbits - 1)) << " (" << file << ":"
if (value >= (1 << (nbits - 1))) {
edm::LogProblem("Tracklet") << "value too large:" << value << " " << (1 << (nbits - 1)) - 1 << " (" << file << ":"
<< line << ")";
}
assert(value <= (1 << (nbits - 1)));
assert(value < (1 << (nbits - 1)));
if (value < -(1 << (nbits - 1))) {
edm::LogProblem("Tracklet") << "value too negative:" << value << " " << -(1 << (nbits - 1)) << " (" << file << ":"
<< line << ")";
Expand Down
21 changes: 12 additions & 9 deletions L1Trigger/TrackFindingTracklet/src/FitTrack.cc
Original file line number Diff line number Diff line change
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 @@ -892,8 +894,8 @@ void FitTrack::execute(const ChannelAssignment* channelAssignment,
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 @@ -992,6 +994,7 @@ void FitTrack::execute(const ChannelAssignment* channelAssignment,

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 @@ -1071,7 +1074,7 @@ void FitTrack::execute(const ChannelAssignment* channelAssignment,
}
}

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

if (settings_.writeMonitorData("FT")) {
globals_->ofstream("fittrack.txt") << getName() << " " << countAll << " " << countFit << endl;
Expand Down
10 changes: 5 additions & 5 deletions L1Trigger/TrackFindingTracklet/src/HybridFit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ void HybridFit::Fit(Tracklet* tracklet, std::vector<const Stub*>& trackstublist)
double phi0fit = reco::reduceRange(phi0 - iSector_ * 2 * M_PI / N_SECTOR + 0.5 * settings_.dphisectorHG());
double rinvfit = 0.01 * settings_.c() * settings_.bfield() * qoverpt;

int irinvfit = rinvfit / settings_.krinvpars();
int iphi0fit = phi0fit / settings_.kphi0pars();
int itanlfit = trk.tanLambda() / settings_.ktpars();
int iz0fit = trk.z0() / settings_.kz0pars();
int id0fit = d0 / settings_.kd0pars();
int irinvfit = floor(rinvfit / settings_.krinvpars());
int iphi0fit = floor(phi0fit / settings_.kphi0pars());
int itanlfit = floor(trk.tanLambda() / settings_.ktpars());
int iz0fit = floor(trk.z0() / settings_.kz0pars());
int id0fit = floor(d0 / settings_.kd0pars());
int ichi2rphifit = chi2rphi / 16;
int ichi2rzfit = trk.chi2rz() / 16;

Expand Down
3 changes: 2 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ void MatchCalculator::execute(double phioffset) {
}

bool imatch = (std::abs(ideltaphi) <= (int)phimatchcuttable_.lookup(seedindex)) &&
(std::abs(ideltaz * fact_) <= (int)zmatchcuttable_.lookup(seedindex));
(ideltaz * fact_ < (int)zmatchcuttable_.lookup(seedindex)) &&
(ideltaz * fact_ >= - (int)zmatchcuttable_.lookup(seedindex));

if (settings_.debugTracklet()) {
edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " ideltaphi cut " << ideltaphi << " "
Expand Down
3 changes: 2 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b
}

bool imatch = (std::abs(ideltaphi) <= phimatchcuttable_.lookup(seedindex)) &&
(std::abs(ideltaz << dzshift_) <= zmatchcuttable_.lookup(seedindex));
(ideltaz << dzshift_ < zmatchcuttable_.lookup(seedindex)) &&
(ideltaz << dzshift_ >= -zmatchcuttable_.lookup(seedindex));

if (settings_.debugTracklet()) {
edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " ideltaphi cut " << ideltaphi << " "
Expand Down
39 changes: 21 additions & 18 deletions L1Trigger/TrackFindingTracklet/src/PurgeDuplicate.cc
Original file line number Diff line number Diff line change
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
4 changes: 4 additions & 0 deletions L1Trigger/TrackFindingTracklet/src/Sector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ 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(const ChannelAssignment* channelAssignment,
tt::Streams& streamsTrack,
tt::StreamsStub& streamsStub) {
Expand All @@ -431,6 +434,7 @@ void Sector::executeFT(const ChannelAssignment* channelAssignment,
}
}

// 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
Original file line number Diff line number Diff line change
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
6 changes: 3 additions & 3 deletions L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub,
continue;

if (irprojdisk[i] < settings_.rmindisk() / ITC->rD_0_final.K() ||
irprojdisk[i] > settings_.rmaxdisk() / ITC->rD_0_final.K())
irprojdisk[i] >= settings_.rmaxdisk() / ITC->rD_0_final.K())
continue;

projs[i + N_LAYER].init(settings_,
Expand Down Expand Up @@ -1022,7 +1022,7 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub,
continue;

//check that r projection in range
if (irprojdisk[i] <= 0 || irprojdisk[i] > settings_.rmaxdisk() / ITC->rD_0_final.K())
if (irprojdisk[i] <= 0 || irprojdisk[i] >= settings_.rmaxdisk() / ITC->rD_0_final.K())
continue;

projs[settings_.projdisks(iSeed_, i) + N_LAYER - 1].init(settings_,
Expand Down Expand Up @@ -1383,7 +1383,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub,
continue;

//check that r projection in range
if (irprojdisk[i] <= 0 || irprojdisk[i] > settings_.rmaxdisk() / ITC->rD_0_final.K())
if (irprojdisk[i] <= 0 || irprojdisk[i] >= settings_.rmaxdisk() / ITC->rD_0_final.K())
continue;

projs[N_LAYER + i + 1].init(settings_,
Expand Down
11 changes: 5 additions & 6 deletions L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
############################################################

GEOMETRY = "D76"
# Set L1 tracking algorithm:
# 'HYBRID' (baseline, 4par fit) or 'HYBRID_DISPLACED' (extended, 5par fit).
# Set L1 tracking algorithm:
# 'HYBRID' (baseline, 4par fit) or 'HYBRID_DISPLACED' (extended, 5par fit).
# 'HYBRID_NEWKF' (baseline, 4par fit, with bit-accurate KF emulation),
# 'HYBRID_REDUCED' to use the "Summer Chain" configuration with reduced inputs.
# (Or legacy algos 'TMTT' or 'TRACKLET').
Expand Down Expand Up @@ -64,7 +64,7 @@
#from MCsamples.Scripts.getCMSlocaldata_cfi import *

if GEOMETRY == "D49":
inputMC = ["/store/relval/CMSSW_11_3_0_pre3/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_113X_mcRun4_realistic_v3_2026D49PU200_rsb-v1/00000/00260a30-734a-4a3a-a4b0-f836ce5502c6.root"]
inputMC = ["/store/relval/CMSSW_11_3_0_pre3/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_113X_mcRun4_realistic_v3_2026D49PU200_rsb-v1/00000/00260a30-734a-4a3a-a4b0-f836ce5502c6.root"]

elif GEOMETRY == "D76":
# Read data from card files (defines getCMSdataFromCards()):
Expand Down Expand Up @@ -173,7 +173,7 @@
L1TRK_LABEL = "Level1TTTracks"
L1TRUTH_NAME = "TTTrackAssociatorFromPixelDigisReduced"

# LEGACY ALGORITHM (EXPERTS ONLY): TRACKLET
# LEGACY ALGORITHM (EXPERTS ONLY): TRACKLET
elif (L1TRKALGO == 'TRACKLET'):
print("\n WARNING: This is not the baseline algorithm! Prefer HYBRID or HYBRID_DISPLACED!")
print("\n To run the Tracklet-only algorithm, ensure you have commented out 'CXXFLAGS=-DUSEHYBRID' in BuildFile.xml & recompiled! \n")
Expand Down Expand Up @@ -224,7 +224,7 @@
L1Tk_minNStub = cms.int32(4), # L1 tracks with >= 4 stubs
TP_minNStub = cms.int32(4), # require TP to have >= X number of stubs associated with it
TP_minNStubLayer = cms.int32(4), # require TP to have stubs in >= X layers/disks
TP_minPt = cms.double(2.0), # only save TPs with pt > X GeV
TP_minPt = cms.double(1.9), # only save TPs with pt > X GeV
TP_maxEta = cms.double(2.5), # only save TPs with |eta| < X
TP_maxZ0 = cms.double(30.0), # only save TPs with |z0| < X cm
L1TrackInputTag = cms.InputTag(L1TRK_NAME, L1TRK_LABEL), # TTTrack input
Expand Down Expand Up @@ -277,4 +277,3 @@

process.pd = cms.EndPath(process.writeDataset)
process.schedule.append(process.pd)

Loading

0 comments on commit a809821

Please sign in to comment.