Skip to content

Commit

Permalink
Merge pull request cms-sw#1 from aperloff/phase2-l1t-integration-CMSS…
Browse files Browse the repository at this point in the history
…W_12_3_0_pre4-METUpdate

Match track px and py during MET computation
  • Loading branch information
Chriisbrown committed Sep 9, 2022
2 parents 1923329 + f28d65b commit 98406f0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@
process.L1TrackJetsEmulation.VertexInputTag = cms.InputTag("VertexProducer", "l1verticesEmulation")
process.L1TrackerEmuEtMiss.L1VertexInputTag = cms.InputTag("VertexProducer", "l1verticesEmulation")
process.L1TrackerEmuEtMiss.debug = options.debug
process.L1TrackerEmuHTMiss.debug = (options.debug > 0)

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
24 changes: 18 additions & 6 deletions L1Trigger/L1TTrackMatch/interface/L1TkEtMissEmuAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ namespace l1tmetemu {
const unsigned int kPtMagSize{9};
const unsigned int kEtExtra{4};
const unsigned int kGlobalPhiExtra{3};
const unsigned int kCosLUTSize{10};
const unsigned int kCosLUTMagSize{1};

typedef ap_uint<TTTrack_TrackWord::TrackBitWidths::kPhiSize + kGlobalPhiExtra> global_phi_t;
typedef ap_fixed<kInternalPtWidth + kEtExtra + kEtExtra,kPtMagSize + kEtExtra> Et_t;
typedef ap_fixed<kInternalPtWidth + kPtMagSize + kEtExtra,2*kPtMagSize + kEtExtra> E2t_t;
typedef ap_ufixed<kCosLUTSize, kCosLUTMagSize, AP_RND_CONV, AP_SAT> cos_lut_fixed_t;
typedef ap_fixed<kInternalPtWidth + kEtExtra + kEtExtra, kPtMagSize + kEtExtra, AP_RND_CONV, AP_SAT> Et_t;
typedef ap_fixed<kInternalPtWidth + kPtMagSize + kEtExtra,2*kPtMagSize + kEtExtra, AP_RND_CONV, AP_SAT> E2t_t;

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

const unsigned int kMETSize{16}; // For output Magnitude default 16
const unsigned int kMETMagSize{11};
Expand All @@ -43,7 +46,7 @@ namespace l1tmetemu {

// 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};
const double kMaxCosLUTPhi{M_PI / 2};

const unsigned int kNSector{9};
const unsigned int kNQuadrants{4};
Expand All @@ -54,11 +57,20 @@ namespace l1tmetemu {
METWordphi_t Phi;
};

std::vector<Et_t> generateCosLUT(unsigned int size);
std::vector<cos_lut_fixed_t> generateCosLUT(unsigned int size);

global_phi_t localToGlobalPhi(TTTrack_TrackWord::phi_t local_phi, global_phi_t sector_shift );

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

template <typename T>
void printLUT(std::vector<T> lut, std::string module = "", std::string name = "") {
edm::LogVerbatim log(module);
log << "The " << name << "[" << lut.size() << "] values are ... \n";
for (unsigned int i = 0; i < lut.size(); i++) {
log << "\t" << i << "\t" << lut[i] << "\n";
}
}

} // namespace l1tmetemu
#endif
37 changes: 24 additions & 13 deletions L1Trigger/L1TTrackMatch/plugins/L1TrackerEtMissEmulatorProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class L1TrackerEtMissEmulatorProducer : public edm::stream::EDProducer<> {

// ----------member data ---------------------------

std::vector<l1tmetemu::Et_t> cosLUT_; // Cos LUT array
std::vector<l1tmetemu::cos_lut_fixed_t> cosLUT_; // Cos LUT array
std::vector<l1tmetemu::global_phi_t> phiQuadrants_;
std::vector<l1tmetemu::global_phi_t> phiShifts_;

Expand Down Expand Up @@ -92,11 +92,18 @@ L1TrackerEtMissEmulatorProducer::L1TrackerEtMissEmulatorProducer(const edm::Para

// To have same bin spacing between 0 and pi/2 as between original phi
// granularity
int cosLUTbins = floor(l1tmetemu::kMaxCosLUTPhi / TTTrack_TrackWord::stepPhi0);
int cosLUTbins = std::floor(l1tmetemu::kMaxCosLUTPhi / TTTrack_TrackWord::stepPhi0);

// Compute LUTs
cosLUT_ = l1tmetemu::generateCosLUT(cosLUTbins);

// Print LUTs
if (debug_ == 1) {
l1tmetemu::printLUT(phiQuadrants_, "L1TrackerEtMissEmulatorProducer", "phiQuadrants_");
l1tmetemu::printLUT(phiShifts_, "L1TrackerEtMissEmulatorProducer", "phiShifts_");
l1tmetemu::printLUT(cosLUT_, "L1TrackerEtMissEmulatorProducer", "cosLUT_");
}

produces<std::vector<EtSum>>(L1MetCollectionName_);
}

Expand Down Expand Up @@ -177,8 +184,8 @@ void L1TrackerEtMissEmulatorProducer::produce(edm::Event& iEvent, const edm::Eve
// through cosLUT_ gives sin Sum sector Et -ve when cos or sin phi are -ve
sector_totals[track->phiSector()] += 1;
if (globalPhi >= phiQuadrants_[0] && globalPhi < phiQuadrants_[1]) {
temppx = (ptEmulation * cosLUT_[globalPhi]);
temppy = (ptEmulation * cosLUT_[phiQuadrants_[1] - 1 - globalPhi]);
temppx = ((l1tmetemu::Et_t)ptEmulation * cosLUT_[globalPhi]);
temppy = ((l1tmetemu::Et_t)ptEmulation * cosLUT_[phiQuadrants_[1] - 1 - globalPhi]);

if (debug_ == 2) {
edm::LogVerbatim("L1TrackerEtMissEmulatorProducer")
Expand All @@ -188,8 +195,8 @@ void L1TrackerEtMissEmulatorProducer::produce(edm::Event& iEvent, const edm::Eve

}
} else if (globalPhi >= phiQuadrants_[1] && globalPhi < phiQuadrants_[2]) {
temppx = -(ptEmulation * cosLUT_[phiQuadrants_[2] - 1 - globalPhi]);
temppy = (ptEmulation * cosLUT_[globalPhi - phiQuadrants_[1]]);
temppx = -((l1tmetemu::Et_t)ptEmulation * cosLUT_[phiQuadrants_[2] - 1 - globalPhi]);
temppy = ((l1tmetemu::Et_t)ptEmulation * cosLUT_[globalPhi - phiQuadrants_[1]]);

if (debug_ == 2) {
edm::LogVerbatim("L1TrackerEtMissEmulatorProducer")
Expand All @@ -199,8 +206,8 @@ void L1TrackerEtMissEmulatorProducer::produce(edm::Event& iEvent, const edm::Eve
<< " Emu Sin(Phi): " << cosLUT_[globalPhi - phiQuadrants_[1]] << "\n";
}
} else if (globalPhi >= phiQuadrants_[2] && globalPhi < phiQuadrants_[3]) {
temppx = -(ptEmulation * cosLUT_[globalPhi - phiQuadrants_[2]]);
temppy = -(ptEmulation * cosLUT_[phiQuadrants_[3] - 1 - globalPhi]);
temppx = -((l1tmetemu::Et_t)ptEmulation * cosLUT_[globalPhi - phiQuadrants_[2]]);
temppy = -((l1tmetemu::Et_t)ptEmulation * cosLUT_[phiQuadrants_[3] - 1 - globalPhi]);

if (debug_ == 2) {
edm::LogVerbatim("L1TrackerEtMissEmulatorProducer")
Expand All @@ -210,8 +217,8 @@ void L1TrackerEtMissEmulatorProducer::produce(edm::Event& iEvent, const edm::Eve
}

} else if (globalPhi >= phiQuadrants_[3] && globalPhi < phiQuadrants_[4]) {
temppx = (ptEmulation * cosLUT_[phiQuadrants_[4] - 1 - globalPhi]);
temppy = -(ptEmulation * cosLUT_[globalPhi - phiQuadrants_[3]]);
temppx = ((l1tmetemu::Et_t)ptEmulation * cosLUT_[phiQuadrants_[4] - 1 - globalPhi]);
temppy = -((l1tmetemu::Et_t)ptEmulation * cosLUT_[globalPhi - phiQuadrants_[3]]);

if (debug_ == 2) {
edm::LogVerbatim("L1TrackerEtMissEmulatorProducer")
Expand All @@ -233,7 +240,9 @@ void L1TrackerEtMissEmulatorProducer::produce(edm::Event& iEvent, const edm::Eve
if (debug_ == 4) {
edm::LogVerbatim("L1TrackerEtMissEmulatorProducer")
<< "Sector: " << track->phiSector() << " Eta sector: " << EtaSector << "\n"
<< "Track Px: " << temppx << " Track Py: " << temppy << "\n"
<< "Track Ref Pt: " << track->momentum().perp()
<< " Track Ref Px: " << track->momentum().x() << " Track Ref Py: " << track->momentum().y() << "\n"
<< "Track Pt: " << ptEmulation << " Track Px: " << temppx << " Track Py: " << temppy << "\n"
<< "Sector Sum Px: " << sumPx[link_number] << " Sector Sum Py: " << sumPy[link_number] << "\n";
}
}
Expand All @@ -257,15 +266,16 @@ void L1TrackerEtMissEmulatorProducer::produce(edm::Event& iEvent, const edm::Eve
else if ((GlobalPx < 0) && (GlobalPy >= 0))
EtMiss.Phi += l1tmetemu::METWordphi_t(M_PI/l1tmetemu::kStepMETwordPhi);

if (debug_ == 6) {
if (debug_ == 4 || debug_ == 6) {

edm::LogVerbatim("L1TrackerEtMissEmulatorProducer")
<< "====Sector Pt====\n";

for (unsigned int i = 0; i < l1tmetemu::kNSector * 2; i++) {
edm::LogVerbatim("L1TrackerEtMissEmulatorProducer")
<< "Sector " << i << "\n"
<< "Px: " << sumPx[i] << " | Py: " << sumPy[i]
<< "Px: " << sumPx[i] << " | Py: " << sumPy[i]
<< " | Link Totals: " << link_totals[i]
<< " | Sector Totals: " << sector_totals[(int)(i/2)] << "\n";
}

Expand All @@ -278,6 +288,7 @@ void L1TrackerEtMissEmulatorProducer::produce(edm::Event& iEvent, const edm::Eve
<< "MET word Et: " << EtMiss.Et.range()*l1tmetemu::kStepMETwordEt << "| MET word phi: " << EtMiss.Phi << "\n"
<< "MET: " << EtMiss.Et.to_double()
<< "| MET phi: " << (float)EtMiss.Phi * l1tmetemu::kStepMETwordPhi << "\n"
<< "Word MET: " << EtMiss.Et.to_string(2) << " | Word MET phi: " << EtMiss.Phi.to_string(2) << "\n"
<< "# Tracks Associated to Vertex: " << num_assoc_tracks << "\n"
<< "========================================================\n";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# set useVertexEmulator to true
L1MetCollectionName = cms.string("L1TrackerEmuEtMiss"),

nCordicSteps = cms.int32( 27 ), #Number of steps for cordic sqrt and phi computation
nCordicSteps = cms.int32( 13 ), #Number of steps for cordic sqrt and phi computation
debug = cms.int32( 6 ), #0 - No Debug, 1 - LUT debug, 2 - Phi Debug, 3 - Z debug, 4 - Et Debug, 5 - Cordic Debug, 6 - Output, 7 - Every Selected Track

)
Expand Down
10 changes: 5 additions & 5 deletions L1Trigger/L1TTrackMatch/src/L1TkEtMissEmuAlgo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
using namespace std;

namespace l1tmetemu {
std::vector<Et_t> generateCosLUT(unsigned int size) { // Fill cosine LUT with integer values
std::vector<cos_lut_fixed_t> generateCosLUT(unsigned int size) { // Fill cosine LUT with integer values
float phi = 0;
std::vector<Et_t> cosLUT;
std::vector<cos_lut_fixed_t> cosLUT;
for (unsigned int LUT_idx = 0; LUT_idx < size; LUT_idx++) {
cosLUT.push_back((Et_t)(cos(phi)));
cosLUT.push_back((cos_lut_fixed_t)(cos(phi)));
phi += TTTrack_TrackWord::stepPhi0;
//std::cout << LUT_idx << "," << (Et_t)(cos(phi)) << std::endl;
//std::cout << LUT_idx << "," << (cos_lut_fixed_t)(cos(phi)) << std::endl;
}
cosLUT.push_back((Et_t)(0)); //Prevent overflow in last bin
cosLUT.push_back((cos_lut_fixed_t)(0)); //Prevent overflow in last bin
return cosLUT;
}

Expand Down

0 comments on commit 98406f0

Please sign in to comment.