Skip to content

Commit

Permalink
Merge pull request #39836 from cecilecaillol/l1t-1049bis
Browse files Browse the repository at this point in the history
[L1T] Phase-2, track MET update for FW sync (new)
  • Loading branch information
cmsbuild committed Nov 3, 2022
2 parents 1fc50dc + 9fad9f0 commit e01b0cd
Show file tree
Hide file tree
Showing 15 changed files with 337 additions and 576 deletions.
8 changes: 4 additions & 4 deletions L1Trigger/DemonstratorTools/src/codecs_etsums.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace l1t::demo::codecs {

ap_uint<64> encodeEtSum(const l1t::EtSum& etSum) {
l1tmetemu::EtMiss etMiss;
etMiss.Et = etSum.hwPt();
etMiss.Et.V = etSum.hwPt();
etMiss.Phi = etSum.hwPhi();
ap_uint<1> valid = (etSum.hwQual() > 0);
ap_uint<64 - (l1tmetemu::kMETSize + l1tmetemu::kMETPhiSize + 1)> unassigned = 0;
ap_uint<64> etSumWord = (unassigned, etMiss.Phi, etMiss.Et, valid);
ap_uint<64> etSumWord = (unassigned, etMiss.Phi, etMiss.Et.range(), valid);
return etSumWord;
}

Expand Down Expand Up @@ -41,9 +41,9 @@ namespace l1t::demo::codecs {
math::XYZTLorentzVector v(0, 0, 0, 0);
l1t::EtSum s(v,
l1t::EtSum::EtSumType::kMissingEt,
l1tmetemu::MET_t(x(1 + l1tmetemu::kMETSize, 1)).to_int(),
l1tmetemu::METWord_t(x(1 + l1tmetemu::kMETSize, 1)),
0,
l1tmetemu::METphi_t(x(1 + l1tmetemu::kMETSize + l1tmetemu::kMETPhiSize, 17)).to_int(),
l1tmetemu::METWordphi_t(x(1 + l1tmetemu::kMETSize + l1tmetemu::kMETPhiSize, 17)).to_int(),
0);
etSums.push_back(s);
}
Expand Down
6 changes: 3 additions & 3 deletions L1Trigger/DemonstratorTools/src/codecs_htsums.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace l1t::demo::codecs {
l1tmhtemu::EtMiss htMiss;
htMiss.Et = htSum.p4().energy();
htMiss.Phi = htSum.hwPhi();
l1tmhtemu::Et_t HT = htSum.hwPt();
ap_uint<l1tmhtemu::kMHTSize> HT = htSum.hwPt();
ap_uint<l1tmhtemu::kValidSize> valid = (htSum.hwQual() > 0);
ap_uint<l1tmhtemu::kUnassignedSize> unassigned = 0;
ap_uint<64> htSumWord = (unassigned, HT, htMiss.Phi, htMiss.Et, valid);
ap_uint<64> htSumWord = (unassigned, HT, htMiss.Phi, htMiss.Et.range(), valid);
return htSumWord;
}

Expand Down Expand Up @@ -42,7 +42,7 @@ namespace l1t::demo::codecs {
math::XYZTLorentzVector v(0, 0, 0, l1tmhtemu::MHT_t(x(l1tmhtemu::kMHTMSB, l1tmhtemu::kMHTLSB)).to_int());
l1t::EtSum s(v,
l1t::EtSum::EtSumType::kMissingHt,
l1tmhtemu::Et_t(x(l1tmhtemu::kHTMSB, l1tmhtemu::kHTLSB)).to_int(),
l1tmhtemu::MHT_t(x(l1tmhtemu::kHTMSB, l1tmhtemu::kHTLSB)),
0,
l1tmhtemu::MHTphi_t(x(l1tmhtemu::kMHTPhiMSB, l1tmhtemu::kMHTPhiLSB)).to_int(),
0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@

if options.debug:
process.MessageLogger.cerr.INFO.limit = cms.untracked.int32(1000000000)
process.MessageLogger.suppressInfo = cms.untracked.vstring('CondDBESSource', 'PoolDBESSource')
process.MessageLogger.cerr.CondDBESSource = cms.untracked.PSet(
limit = cms.untracked.int32(0)
)

process.GTTFileWriter.format = cms.untracked.string(options.format)
# process.GTTFileWriter.outputFilename = cms.untracked.string("myOutputFile.txt")
Expand Down
15 changes: 5 additions & 10 deletions L1Trigger/L1TTrackMatch/interface/Cordic.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,21 @@
class Cordic {
public:
Cordic();
Cordic(int aPhiScale, int aMagnitudeBits, const int aSteps, bool debug);
Cordic(const int aSteps, bool debug);

template <typename T>
void cordic_subfunc(T &x, T &y, T &z) const;
l1tmetemu::EtMiss toPolar(l1tmetemu::Et_t x, l1tmetemu::Et_t y) const;

private:
// Scale for Phi calculation to maintain precision
const int mPhiScale;
// Scale for Magnitude calculation
const int mMagnitudeScale;
// Bit width for internal magnitude
const int mMagnitudeBits;
// Number of cordic iterations
const int cordicSteps;

const bool debug;

// To calculate atan
std::vector<l1tmetemu::METphi_t> atanLUT;
std::vector<l1tmetemu::atan_lut_fixed_t> atanLUT;
// To normalise final magnitude
std::vector<l1tmetemu::Et_t> magNormalisationLUT;
std::vector<l1tmetemu::atan_lut_fixed_t> magNormalisationLUT;
};

#endif
128 changes: 43 additions & 85 deletions L1Trigger/L1TTrackMatch/interface/L1TkEtMissEmuAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <numeric>

#include "DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h"
Expand All @@ -18,105 +19,62 @@
// Includes functions for writing LUTs and converting to integer representations
namespace l1tmetemu {

const unsigned int kInternalVTXWidth{12}; //default 8 max 12
const unsigned int kInternalEtaWidth{8}; //default 8 max 16
const unsigned int kInternalPtWidth{15}; // default 15 max 15
const unsigned int kInternalPhiWidth{8}; //default 8 max 12
const unsigned int kInternalPtWidth{14};
const unsigned int kPtMagSize{9};
const unsigned int kMETSize{16}; // For output Magnitude default 16
const unsigned int kMETMagSize{11};
const unsigned int kMETPhiSize{13}; // For Output Phi default 13
const unsigned int kEtExtra{4};
const unsigned int kGlobalPhiExtra{4};
const unsigned int kCosLUTSize{10};
const unsigned int kCosLUTMagSize{1};
const unsigned int kAtanLUTSize{64};
const unsigned int kAtanLUTMagSize{2};

typedef ap_ufixed<kMETSize, kMETMagSize, AP_RND_CONV, AP_SAT> METWord_t;
typedef ap_int<kMETPhiSize> METWordphi_t;
typedef ap_int<TTTrack_TrackWord::TrackBitWidths::kPhiSize + kGlobalPhiExtra> global_phi_t;
typedef ap_ufixed<kCosLUTSize, kCosLUTMagSize, AP_RND_CONV, AP_SAT> cos_lut_fixed_t;
typedef ap_ufixed<kAtanLUTSize, kAtanLUTMagSize, AP_RND_CONV, AP_SAT> atan_lut_fixed_t;
typedef ap_fixed<kMETSize + kEtExtra, kMETMagSize + kEtExtra, AP_RND_CONV, AP_SAT> Et_t;
typedef ap_fixed<kMETPhiSize + kEtExtra, 4, AP_RND_CONV, AP_SAT> metphi_fixed_t;
typedef ap_ufixed<kMETPhiSize + kEtExtra + 7, kMETPhiSize - 2, AP_RND_CONV, AP_SAT> pi_bins_fixed_t;

// Output definition as per interface document, only used when creating output format
const double kMaxMET = 1 << kMETMagSize; // 2 TeV
const double kMaxMETPhi{2 * M_PI};

const double kStepMETwordEt = kMaxMET / (1 << kMETSize);
const double kStepMETwordPhi = kMaxMETPhi / (1 << kMETPhiSize);
const double kBinsInPi = 1.0 / kStepMETwordPhi;

// Extra bits needed by global phi to span full range
const unsigned int kGlobalPhiExtra{3}; // default 3
// Extra room for Et sums
const unsigned int kEtExtra{10}; // default 8

typedef ap_uint<3> nstub_t;

typedef ap_uint<kInternalPhiWidth + kGlobalPhiExtra> global_phi_t;

typedef ap_uint<kInternalPtWidth> pt_t;
typedef ap_uint<kInternalEtaWidth> eta_t;
typedef ap_uint<kInternalVTXWidth> z_t;
// For internal Et representation, sums become larger than initial pt
// representation
typedef ap_int<kInternalPtWidth + kEtExtra> Et_t;

//Output format
const float kMaxMET{4096}; // 4 TeV
const float kMaxMETPhi{2 * M_PI};
const unsigned int kMETSize{15}; // For output Magnitude default 15
const unsigned int kMETPhiSize{14}; // For Output Phi default 14

typedef ap_uint<kMETSize> MET_t;
// Cordic means this is evaluated between 0 and 2Pi rather than -pi to pi so
// unsigned
typedef ap_uint<kMETPhiSize> METphi_t;

const unsigned int kGlobalPhiBins = 1 << kInternalPhiWidth;
const unsigned int kMETBins = 1 << kMETSize;
const unsigned int kMETPhiBins = 1 << kMETPhiSize;
// Enough symmetry in cos and sin between 0 and pi/2 to get all possible values
// of cos and sin phi
const double kMaxCosLUTPhi{M_PI / 2};

const unsigned int kNEtaRegion{6};
const unsigned int kNSector{9};
const unsigned int kNQuadrants{4};

const float kMaxTrackZ0{-TTTrack_TrackWord::minZ0};
const float kMaxTrackPt{512};
const float kMaxTrackEta{4};

// Steps used to convert from track word floats to track MET integer representations

const double kStepPt = (std::abs(kMaxTrackPt)) / (1 << kInternalPtWidth);
const double kStepEta = (2 * std::abs(kMaxTrackEta)) / (1 << kInternalEtaWidth);
const double kStepZ0 = (2 * std::abs(kMaxTrackZ0)) / (1 << kInternalVTXWidth);

const double kStepPhi = (2 * -TTTrack_TrackWord::minPhi0) / (kGlobalPhiBins - 1);

const double kStepMET = (l1tmetemu::kMaxMET / l1tmetemu::kMETBins);
const double kStepMETPhi = (l1tmetemu::kMaxMETPhi / l1tmetemu::kMETPhiBins);

// Enough symmetry in cos and sin between 0 and pi/2 to get all possible values
// of cos and sin phi
const float kMaxCosLUTPhi{M_PI / 2};

// Simple struct used for ouput of cordic
struct EtMiss {
MET_t Et;
METphi_t Phi;
METWord_t Et;
METWordphi_t Phi;
};

std::vector<global_phi_t> generateCosLUT(unsigned int size);
std::vector<eta_t> generateEtaRegionLUT(std::vector<double> EtaRegions);
std::vector<z_t> generateDeltaZLUT(std::vector<double> DeltaZBins);

template <typename T>
T digitizeSignedValue(double value, unsigned int nBits, double lsb) {
// Digitize the incoming value
int digitizedValue = std::floor(value / lsb);

// Calculate the maxmum possible positive value given an output of nBits in size
int digitizedMaximum = (1 << (nBits - 1)) - 1; // The remove 1 bit from nBits to account for the sign
int digitizedMinimum = -1. * (digitizedMaximum + 1);
std::vector<cos_lut_fixed_t> generateCosLUT(unsigned int size);

// Saturate the digitized value
digitizedValue = std::clamp(digitizedValue, digitizedMinimum, digitizedMaximum);
global_phi_t localToGlobalPhi(TTTrack_TrackWord::phi_t local_phi, global_phi_t sector_shift);

// Do the two's compliment encoding
T twosValue = digitizedValue;
if (digitizedValue < 0) {
twosValue += (1 << nBits);
}

return twosValue;
}
std::vector<global_phi_t> generatePhiSliceLUT(unsigned int N);

template <typename T>
unsigned int getBin(double value, const T& bins) {
auto up = std::upper_bound(bins.begin(), bins.end(), value);
return (up - bins.begin() - 1);
void printLUT(std::vector<T> lut, std::string module = "", std::string name = "") {
edm::LogVerbatim log(module);
log << "The " << name << "[" << lut.size() << "] values are ... \n" << std::setprecision(30);
for (unsigned int i = 0; i < lut.size(); i++) {
log << "\t" << i << "\t" << lut[i] << "\n";
}
}

int unpackSignedValue(unsigned int bits, unsigned int nBits);

unsigned int transformSignedValue(unsigned int bits, unsigned int oldnBits, unsigned int newnBits);

} // namespace l1tmetemu
#endif
133 changes: 0 additions & 133 deletions L1Trigger/L1TTrackMatch/interface/L1TkEtMissEmuTrackTransform.h

This file was deleted.

Loading

0 comments on commit e01b0cd

Please sign in to comment.