Skip to content

Commit

Permalink
Fixing integer range check in FPGAWord. (#125)
Browse files Browse the repository at this point in the history
* fixing integer range check in FPGAWord.

* Fixing `zmatchcut_` for L1 and L2

* Undo the -0.06 in Settings.h as there is a cleaner fix to the overflows

* Slight rewerite to use <= instead < and not do subtracktion

* Fix < to <= to avoid overflow by one

Co-authored-by: Brent R. Yates <brentRyates@gmail.com>
Co-authored-by: Anders <aryd@cern.ch>
  • Loading branch information
3 people committed Jan 30, 2022
1 parent 4ac97d7 commit 315339a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
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
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
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

0 comments on commit 315339a

Please sign in to comment.