CMS 3D CMS Logo

TkJetWord.h
Go to the documentation of this file.
1 #ifndef FIRMWARE_TkJetWord_h
2 #define FIRMWARE_TkJetWord_h
3 
4 // Class to store the 96-bit TkJet word for L1 Track Trigger.
5 // Author: Emily MacDonald, updated by Benjamin Radburn-Smith (September 2022)
6 
7 #include <vector>
8 #include <ap_int.h>
9 #include <cassert>
10 #include <cmath>
11 #include <bitset>
12 #include <string>
13 
14 namespace l1t {
15 
16  class TkJetWord {
17  public:
18  // ----------constants, enums and typedefs ---------
19  int INTPHI_PI = 720;
21  float INTPT_LSB = 1 >> 5;
22  float ETAPHI_LSB = M_PI / (1 << 12);
23  float Z0_LSB = 0.05;
24 
26  kPtSize = 16,
27  kPtMagSize = 11,
30  kZ0Size = 10,
31  kNtSize = 5,
32  kXtSize = 4,
35  };
36 
38  kPtLSB = 0,
39  kPtMSB = kPtLSB + TkJetBitWidths::kPtSize - 1,
41  kGlbEtaMSB = kGlbEtaLSB + TkJetBitWidths::kGlbEtaSize - 1,
43  kGlbPhiMSB = kGlbPhiLSB + TkJetBitWidths::kGlbPhiSize - 1,
45  kZ0MSB = kZ0LSB + TkJetBitWidths::kZ0Size - 1,
46  kNtLSB = kZ0MSB + 1,
47  kNtMSB = kNtLSB + TkJetBitWidths::kNtSize - 1,
48  kXtLSB = kNtMSB + 1,
49  kXtMSB = kXtLSB + TkJetBitWidths::kXtSize - 1,
52  };
53 
54  typedef ap_ufixed<kPtSize, kPtMagSize, AP_TRN, AP_SAT> pt_t;
55  typedef ap_int<kGlbEtaSize> glbeta_t;
56  typedef ap_int<kGlbPhiSize> glbphi_t;
57  typedef ap_int<kZ0Size> z0_t; // 40cm / 0.1
58  typedef ap_uint<kNtSize> nt_t; //number of tracks
59  typedef ap_uint<kXtSize> nx_t; //number of tracks with xbit = 1
60  typedef ap_uint<TkJetBitWidths::kUnassignedSize> tkjetunassigned_t; // Unassigned bits
61  typedef std::bitset<TkJetBitWidths::kTkJetWordSize> tkjetword_bs_t;
62  typedef ap_uint<TkJetBitWidths::kTkJetWordSize> tkjetword_t;
63 
64  public:
65  // ----------Constructors --------------------------
66  TkJetWord() {}
68 
70 
71  // ----------copy constructor ----------------------
72  TkJetWord(const TkJetWord& word) { tkJetWord_ = word.tkJetWord_; }
73 
74  // ----------operators -----------------------------
76  tkJetWord_ = word.tkJetWord_;
77  return *this;
78  }
79 
80  // ----------member functions (getters) ------------
81  // These functions return arbitarary precision words (lists of bits) for each quantity
82  pt_t ptWord() const {
83  pt_t ret;
84  ret.V = tkJetWord()(TkJetBitLocations::kPtMSB, TkJetBitLocations::kPtLSB);
85  return ret;
86  }
87  glbeta_t glbEtaWord() const {
88  glbeta_t ret;
89  ret.V = tkJetWord()(TkJetBitLocations::kGlbEtaMSB, TkJetBitLocations::kGlbEtaLSB);
90  return ret;
91  }
92  glbphi_t glbPhiWord() const {
93  glbphi_t ret;
94  ret.V = tkJetWord()(TkJetBitLocations::kGlbPhiMSB, TkJetBitLocations::kGlbPhiLSB);
95  return ret;
96  }
97  z0_t z0Word() const {
98  z0_t ret;
99  ret.V = tkJetWord()(TkJetBitLocations::kZ0MSB, TkJetBitLocations::kZ0LSB);
100  return ret;
101  }
102  nt_t ntWord() const {
103  nt_t ret;
104  ret.V = tkJetWord()(TkJetBitLocations::kNtMSB, TkJetBitLocations::kNtLSB);
105  return ret;
106  }
107  nx_t xtWord() const {
108  nx_t ret;
109  ret.V = tkJetWord()(TkJetBitLocations::kXtMSB, TkJetBitLocations::kXtLSB);
110  return ret;
111  }
114  }
115  tkjetword_t tkJetWord() const { return tkjetword_t(tkJetWord_.to_string().c_str(), 2); }
116 
117  // These functions return the packed bits in integer format for each quantity
118  // Signed quantities have the sign enconded in the left-most bit.
119  unsigned int ptBits() const { return ptWord().to_uint(); }
120  unsigned int glbEtaBits() const { return glbEtaWord().to_uint(); }
121  unsigned int glbPhiBits() const { return glbPhiWord().to_uint(); }
122  unsigned int z0Bits() const { return z0Word().to_uint(); }
123  unsigned int ntBits() const { return ntWord().to_uint(); }
124  unsigned int xtBits() const { return xtWord().to_uint(); }
125  unsigned int unassignedBits() const { return unassignedWord().to_uint(); }
126 
127  // These functions return the unpacked and converted values
128  // These functions return real numbers converted from the digitized quantities by unpacking the 64-bit vertex word
129  float pt() const { return ptWord().to_float(); }
130  float glbeta() const { return glbEtaWord().to_float() * ETAPHI_LSB; }
131  float glbphi() const { return glbPhiWord().to_float() * ETAPHI_LSB; }
132  float z0() const { return z0Word().to_float() * Z0_LSB; }
133  int nt() const { return (ap_ufixed<kNtSize + 2, kNtSize>(ntWord())).to_int(); }
134  int xt() const { return (ap_ufixed<kXtSize + 2, kXtSize>(xtWord())).to_int(); }
135  unsigned int unassigned() const { return unassignedWord().to_uint(); }
136 
137  // ----------member functions (setters) ------------
139 
140  private:
141  // ----------private member functions --------------
142  double unpackSignedValue(unsigned int bits, unsigned int nBits, double lsb) const {
143  int isign = 1;
144  unsigned int digitized_maximum = (1 << nBits) - 1;
145  if (bits & (1 << (nBits - 1))) { // check the sign
146  isign = -1;
147  bits = (1 << (nBits + 1)) - bits; // if negative, flip everything for two's complement encoding
148  }
149  return (double(bits & digitized_maximum) + 0.5) * lsb * isign;
150  }
151 
152  // ----------member data ---------------------------
154  };
155 
156  typedef std::vector<l1t::TkJetWord> TkJetWordCollection;
157 
158 } // namespace l1t
159 
160 #endif
unsigned int xtBits() const
Definition: TkJetWord.h:124
int xt() const
Definition: TkJetWord.h:134
std::vector< l1t::TkJetWord > TkJetWordCollection
Definition: TkJetWord.h:156
unsigned int z0Bits() const
Definition: TkJetWord.h:122
ap_int< kGlbEtaSize > glbeta_t
Definition: TkJetWord.h:55
double unpackSignedValue(unsigned int bits, unsigned int nBits, double lsb) const
Definition: TkJetWord.h:142
int INTPHI_TWOPI
Definition: TkJetWord.h:20
ret
prodAgent to be discontinued
z0_t z0Word() const
Definition: TkJetWord.h:97
constexpr uint32_t bits
Definition: gpuClustering.h:23
ap_int< kGlbPhiSize > glbphi_t
Definition: TkJetWord.h:56
delete x;
Definition: CaloConfig.h:22
ap_ufixed< kPtSize, kPtMagSize, AP_TRN, AP_SAT > pt_t
Definition: TkJetWord.h:54
ap_uint< TkJetBitWidths::kUnassignedSize > tkjetunassigned_t
Definition: TkJetWord.h:60
ap_int< kZ0Size > z0_t
Definition: TkJetWord.h:57
ap_uint< TkJetBitWidths::kTkJetWordSize > tkjetword_t
Definition: TkJetWord.h:62
float pt() const
Definition: TkJetWord.h:129
uint64_t word
tkjetword_t tkJetWord() const
Definition: TkJetWord.h:115
TkJetWord & operator=(const TkJetWord &word)
Definition: TkJetWord.h:75
tkjetword_bs_t tkJetWord_
Definition: TkJetWord.h:153
float glbphi() const
Definition: TkJetWord.h:131
float z0() const
Definition: TkJetWord.h:132
glbeta_t glbEtaWord() const
Definition: TkJetWord.h:87
ap_uint< kXtSize > nx_t
Definition: TkJetWord.h:59
#define M_PI
int nt() const
Definition: TkJetWord.h:133
nx_t xtWord() const
Definition: TkJetWord.h:107
unsigned int glbPhiBits() const
Definition: TkJetWord.h:121
unsigned int glbEtaBits() const
Definition: TkJetWord.h:120
unsigned int ntBits() const
Definition: TkJetWord.h:123
float glbeta() const
Definition: TkJetWord.h:130
float INTPT_LSB
Definition: TkJetWord.h:21
unsigned int unassignedBits() const
Definition: TkJetWord.h:125
float Z0_LSB
Definition: TkJetWord.h:23
unsigned int unassigned() const
Definition: TkJetWord.h:135
glbphi_t glbPhiWord() const
Definition: TkJetWord.h:92
std::bitset< TkJetBitWidths::kTkJetWordSize > tkjetword_bs_t
Definition: TkJetWord.h:61
ap_uint< kNtSize > nt_t
Definition: TkJetWord.h:58
float ETAPHI_LSB
Definition: TkJetWord.h:22
pt_t ptWord() const
Definition: TkJetWord.h:82
const unsigned int kUnassignedSize
TkJetWord(const TkJetWord &word)
Definition: TkJetWord.h:72
ap_ufixed< 16, 14 > pt_t
Definition: TauNNIdHW.h:27
tkjetunassigned_t unassignedWord() const
Definition: TkJetWord.h:112
nt_t ntWord() const
Definition: TkJetWord.h:102
void setTkJetWord(pt_t pt, glbeta_t eta, glbphi_t phi, z0_t z0, nt_t nt, nx_t nx, tkjetunassigned_t unassigned)
Definition: TkJetWord.cc:11
unsigned int ptBits() const
Definition: TkJetWord.h:119