CMS 3D CMS Logo

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