Skip to content

Commit

Permalink
Merge pull request cms-sw#40563 from gkaratha/trackjet_emulator
Browse files Browse the repository at this point in the history
L1track jet emulator update
  • Loading branch information
cmsbuild authored May 4, 2023
2 parents 3cd98a0 + 79afeb4 commit 69fbbc1
Show file tree
Hide file tree
Showing 16 changed files with 1,211 additions and 1,341 deletions.
77 changes: 56 additions & 21 deletions DataFormats/L1Trigger/interface/TkJetWord.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@

#ifndef FIRMWARE_TkJetWord_h
#define FIRMWARE_TkJetWord_h

// Class to store the 96-bit TkJet word for L1 Track Trigger.
// Class to store the 128-bit TkJet word for L1 Track Trigger.
// Author: Emily MacDonald, updated by Benjamin Radburn-Smith (September 2022)
// 2nd update: George Karathanasis (Oct 2022)

#include <vector>
#include <ap_int.h>
#include <cassert>
#include <cmath>
#include <bitset>
#include <string>
#include "DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h"

namespace l1t {

class TkJetWord {
public:
// ----------constants, enums and typedefs ---------
int INTPHI_PI = 720;
int INTPHI_TWOPI = 2 * INTPHI_PI;
float INTPT_LSB = 1 >> 5;
float ETAPHI_LSB = M_PI / (1 << 12);
float Z0_LSB = 0.05;
static constexpr double MAX_Z0 = 30.;
static constexpr double MAX_ETA = 8.;

enum TkJetBitWidths {
kPtSize = 16,
Expand All @@ -30,41 +30,53 @@ namespace l1t {
kZ0Size = 10,
kNtSize = 5,
kXtSize = 4,
kUnassignedSize = 8,
kTkJetWordSize = kPtSize + kGlbEtaSize + kGlbPhiSize + kZ0Size + kNtSize + kXtSize + kUnassignedSize,
kDispFlagSize = 1,
kUnassignedSize = 65,
kTkJetWordSize =
kPtSize + kGlbEtaSize + kGlbPhiSize + kZ0Size + kNtSize + kXtSize + kDispFlagSize + kUnassignedSize,
};

enum TkJetBitLocations {
kPtLSB = 0,
kPtMSB = kPtLSB + TkJetBitWidths::kPtSize - 1,
kGlbEtaLSB = kPtMSB + 1,
kGlbEtaMSB = kGlbEtaLSB + TkJetBitWidths::kGlbEtaSize - 1,
kGlbPhiLSB = kGlbEtaMSB + 1,
kGlbPhiLSB = kPtMSB + 1,
kGlbPhiMSB = kGlbPhiLSB + TkJetBitWidths::kGlbPhiSize - 1,
kZ0LSB = kGlbPhiMSB + 1,
kGlbEtaLSB = kGlbPhiMSB + 1,
kGlbEtaMSB = kGlbEtaLSB + TkJetBitWidths::kGlbEtaSize - 1,
kZ0LSB = kGlbEtaMSB + 1,
kZ0MSB = kZ0LSB + TkJetBitWidths::kZ0Size - 1,
kNtLSB = kZ0MSB + 1,
kNtMSB = kNtLSB + TkJetBitWidths::kNtSize - 1,
kXtLSB = kNtMSB + 1,
kXtMSB = kXtLSB + TkJetBitWidths::kXtSize - 1,
kUnassignedLSB = kXtMSB + 1,
kDispFlagLSB = kXtMSB + 1,
kDispFlagMSB = kDispFlagLSB + TkJetBitWidths::kDispFlagSize - 1,
kUnassignedLSB = kDispFlagMSB + 1,
kUnassignedMSB = kUnassignedLSB + TkJetBitWidths::kUnassignedSize - 1,
};

typedef ap_ufixed<kPtSize, kPtMagSize, AP_TRN, AP_SAT> pt_t;
typedef ap_int<kGlbEtaSize> glbeta_t;
typedef ap_int<kGlbPhiSize> glbphi_t;
typedef ap_int<kZ0Size> z0_t; // 40cm / 0.1
typedef ap_uint<kNtSize> nt_t; //number of tracks
typedef ap_uint<kXtSize> nx_t; //number of tracks with xbit = 1
typedef ap_int<kZ0Size> z0_t; // 40cm / 0.1
typedef ap_uint<kNtSize> nt_t; //number of tracks
typedef ap_uint<kXtSize> nx_t; //number of tracks with xbit = 1
typedef ap_uint<kDispFlagSize> dispflag_t;
typedef ap_uint<TkJetBitWidths::kUnassignedSize> tkjetunassigned_t; // Unassigned bits
typedef std::bitset<TkJetBitWidths::kTkJetWordSize> tkjetword_bs_t;
typedef ap_uint<TkJetBitWidths::kTkJetWordSize> tkjetword_t;

public:
// ----------Constructors --------------------------
TkJetWord() {}
TkJetWord(pt_t pt, glbeta_t eta, glbphi_t phi, z0_t z0, nt_t nt, nx_t nx, tkjetunassigned_t unassigned);
TkJetWord(pt_t pt,
glbeta_t eta,
glbphi_t phi,
z0_t z0,
nt_t nt,
nx_t nx,
dispflag_t dispflag,
tkjetunassigned_t unassigned);

~TkJetWord() {}

Expand Down Expand Up @@ -109,6 +121,12 @@ namespace l1t {
ret.V = tkJetWord()(TkJetBitLocations::kXtMSB, TkJetBitLocations::kXtLSB);
return ret;
}
dispflag_t dispFlagWord() const {
dispflag_t ret;
ret.V = tkJetWord()(TkJetBitLocations::kDispFlagMSB, TkJetBitLocations::kDispFlagLSB);
return ret;
}

tkjetunassigned_t unassignedWord() const {
return tkJetWord()(TkJetBitLocations::kUnassignedMSB, TkJetBitLocations::kUnassignedLSB);
}
Expand All @@ -122,20 +140,37 @@ namespace l1t {
unsigned int z0Bits() const { return z0Word().to_uint(); }
unsigned int ntBits() const { return ntWord().to_uint(); }
unsigned int xtBits() const { return xtWord().to_uint(); }
unsigned int dispFlagBits() const { return dispFlagWord().to_uint(); }
unsigned int unassignedBits() const { return unassignedWord().to_uint(); }

// These functions return the unpacked and converted values
// These functions return real numbers converted from the digitized quantities by unpacking the 64-bit vertex word
float pt() const { return ptWord().to_float(); }
float glbeta() const { return glbEtaWord().to_float() * ETAPHI_LSB; }
float glbphi() const { return glbPhiWord().to_float() * ETAPHI_LSB; }
float z0() const { return z0Word().to_float() * Z0_LSB; }
float glbeta() const {
return unpackSignedValue(
glbEtaWord(), TkJetBitWidths::kGlbEtaSize, (MAX_ETA) / (1 << TkJetBitWidths::kGlbEtaSize));
}
float glbphi() const {
return unpackSignedValue(
glbPhiWord(), TkJetBitWidths::kGlbPhiSize, (2. * std::abs(M_PI)) / (1 << TkJetBitWidths::kGlbPhiSize));
}
float z0() const {
return unpackSignedValue(z0Word(), TkJetBitWidths::kZ0Size, MAX_Z0 / (1 << TkJetBitWidths::kZ0Size));
}
int nt() const { return (ap_ufixed<kNtSize + 2, kNtSize>(ntWord())).to_int(); }
int xt() const { return (ap_ufixed<kXtSize + 2, kXtSize>(xtWord())).to_int(); }
int dispflag() const { return (ap_ufixed<kDispFlagSize + 2, kDispFlagSize>(dispFlagWord())).to_int(); }
unsigned int unassigned() const { return unassignedWord().to_uint(); }

// ----------member functions (setters) ------------
void setTkJetWord(pt_t pt, glbeta_t eta, glbphi_t phi, z0_t z0, nt_t nt, nx_t nx, tkjetunassigned_t unassigned);
void setTkJetWord(pt_t pt,
glbeta_t eta,
glbphi_t phi,
z0_t z0,
nt_t nt,
nx_t nx,
dispflag_t dispflag,
tkjetunassigned_t unassigned);

private:
// ----------private member functions --------------
Expand Down
35 changes: 26 additions & 9 deletions DataFormats/L1Trigger/src/TkJetWord.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,39 @@
#include "DataFormats/L1Trigger/interface/TkJetWord.h"

namespace l1t {
TkJetWord::TkJetWord(pt_t pt, glbeta_t eta, glbphi_t phi, z0_t z0, nt_t nt, nx_t nx, tkjetunassigned_t unassigned) {
setTkJetWord(pt, eta, phi, z0, nt, nx, unassigned);
TkJetWord::TkJetWord(pt_t pt,
glbeta_t eta,
glbphi_t phi,
z0_t z0,
nt_t nt,
nx_t nx,
dispflag_t dispflag,
tkjetunassigned_t unassigned) {
setTkJetWord(pt, eta, phi, z0, nt, nx, dispflag, unassigned);
}

void TkJetWord::setTkJetWord(
pt_t pt, glbeta_t eta, glbphi_t phi, z0_t z0, nt_t nt, nx_t nx, tkjetunassigned_t unassigned) {
void TkJetWord::setTkJetWord(pt_t pt,
glbeta_t eta,
glbphi_t phi,
z0_t z0,
nt_t nt,
nx_t nx,
dispflag_t dispflag,
tkjetunassigned_t unassigned) {
// pack the TkJet word
unsigned int offset = 0;
for (unsigned int b = offset; b < (offset + TkJetBitWidths::kPtSize); b++) {
tkJetWord_.set(b, pt[b - offset]);
}
offset += TkJetBitWidths::kPtSize;
for (unsigned int b = offset; b < (offset + TkJetBitWidths::kGlbEtaSize); b++) {
tkJetWord_.set(b, eta[b - offset]);
}
offset += TkJetBitWidths::kGlbEtaSize;
for (unsigned int b = offset; b < (offset + TkJetBitWidths::kGlbPhiSize); b++) {
tkJetWord_.set(b, phi[b - offset]);
}
offset += TkJetBitWidths::kGlbPhiSize;
for (unsigned int b = offset; b < (offset + TkJetBitWidths::kGlbEtaSize); b++) {
tkJetWord_.set(b, eta[b - offset]);
}
offset += TkJetBitWidths::kGlbEtaSize;
for (unsigned int b = offset; b < (offset + TkJetBitWidths::kZ0Size); b++) {
tkJetWord_.set(b, z0[b - offset]);
}
Expand All @@ -36,9 +49,13 @@ namespace l1t {
tkJetWord_.set(b, nx[b - offset]);
}
offset += TkJetBitWidths::kXtSize;
for (unsigned int b = offset; b < (offset + TkJetBitWidths::kDispFlagSize); b++) {
tkJetWord_.set(b, nx[b - offset]);
}
offset += TkJetBitWidths::kDispFlagSize;
for (unsigned int b = offset; b < (offset + TkJetBitWidths::kUnassignedSize); b++) {
tkJetWord_.set(b, unassigned[b - offset]);
}
}

} //namespace l1t
} //namespace l1t
3 changes: 2 additions & 1 deletion DataFormats/L1Trigger/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@
<class name="edm::Wrapper<l1t::VertexWordCollection>"/>
<class name="edm::Ref<l1t::VertexWordCollection>" />

<class name="l1t::TkJetWord" ClassVersion="3">
<class name="l1t::TkJetWord" ClassVersion="4">
<version ClassVersion="4" checksum="2346039066"/>
<version ClassVersion="3" checksum="3521396532"/>
</class>
<class name="std::vector<l1t::TkJetWord>"/>
Expand Down
1 change: 1 addition & 0 deletions DataFormats/StdDictionaries/src/classes_def_others.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<class name="std::bitset<27>"/>
<class name="std::bitset<64>"/>
<class name="std::bitset<96>"/>
<class name="std::bitset<128>"/>
<class name="std::deque<int>"/>
<class name="std::forward_iterator_tag"/>
<class name="std::input_iterator_tag"/>
Expand Down
4 changes: 2 additions & 2 deletions L1Trigger/Configuration/python/SimL1Emulator_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@
from L1Trigger.L1TTrackMatch.l1tTrackerEtMiss_cfi import *
from L1Trigger.L1TTrackMatch.l1tTrackerHTMiss_cfi import *
# make the input tags consistent with the choice L1VertexFinder above
l1tTrackJets.L1PVertexCollection = ("l1tVertexFinder", "l1vertices")
l1tTrackJets.L1PVertexInputTag = ("l1tVertexFinderEmulator","l1verticesEmulation")
l1tTrackFastJets.L1PrimaryVertexTag = ("l1tVertexFinder", "l1vertices")
l1tTrackJetsExtended.L1PVertexCollection = ("l1tVertexFinder", "l1vertices")
l1tTrackJetsExtended.L1PVertexInputTag = ("l1tVertexFinderEmulator","l1verticesEmulation")
#l1tTrackerEtMiss.L1VertexInputTag = ("l1tVertexFinder", "l1vertices")
#l1tTrackerEtMissExtended.L1VertexInputTag = ("l1tVertexFinder", "l1vertices")

Expand Down
20 changes: 13 additions & 7 deletions L1Trigger/DemonstratorTools/src/codecs_tkjets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ namespace l1t::demo::codecs {
//if (not x.test(TkJetWord::kValidLSB))
// break;

TkJetWord j(TkJetWord::pt_t(frames[f](TkJetWord::kPtMSB, TkJetWord::kPtLSB)),
TkJetWord::glbeta_t(frames[f](TkJetWord::kGlbEtaMSB, TkJetWord::kGlbEtaLSB)),
TkJetWord::glbphi_t(frames[f](TkJetWord::kGlbPhiMSB, TkJetWord::kGlbPhiLSB)),
TkJetWord::z0_t(frames[f](TkJetWord::kZ0MSB, TkJetWord::kZ0LSB)),
TkJetWord::nt_t(frames[f](TkJetWord::kNtMSB, TkJetWord::kNtLSB)),
TkJetWord::nx_t(frames[f](TkJetWord::kXtMSB, TkJetWord::kXtLSB)),
TkJetWord::tkjetunassigned_t(frames[f](TkJetWord::kUnassignedMSB, TkJetWord::kUnassignedLSB)));
TkJetWord j(
TkJetWord::pt_t(frames[f](TkJetWord::TkJetBitLocations::kPtMSB, TkJetWord::TkJetBitLocations::kPtLSB)),
TkJetWord::glbphi_t(
frames[f](TkJetWord::TkJetBitLocations::kGlbPhiMSB, TkJetWord::TkJetBitLocations::kGlbPhiLSB)),
TkJetWord::glbeta_t(
frames[f](TkJetWord::TkJetBitLocations::kGlbEtaMSB, TkJetWord::TkJetBitLocations::kGlbEtaLSB)),
TkJetWord::z0_t(frames[f](TkJetWord::TkJetBitLocations::kZ0MSB, TkJetWord::TkJetBitLocations::kZ0LSB)),
TkJetWord::nt_t(frames[f](TkJetWord::TkJetBitLocations::kNtMSB, TkJetWord::TkJetBitLocations::kNtLSB)),
TkJetWord::nx_t(frames[f](TkJetWord::TkJetBitLocations::kXtMSB, TkJetWord::TkJetBitLocations::kXtLSB)),
TkJetWord::dispflag_t(
frames[f](TkJetWord::TkJetBitLocations::kDispFlagMSB, TkJetWord::TkJetBitLocations::kDispFlagLSB)),
TkJetWord::tkjetunassigned_t(
frames[f](TkJetWord::TkJetBitLocations::kUnassignedMSB, TkJetWord::TkJetBitLocations::kUnassignedLSB)));
tkJets.push_back(j);
}

Expand Down
Loading

0 comments on commit 69fbbc1

Please sign in to comment.