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 #include <vector>
5 #include <ap_int.h>
6 #include <cassert>
7 #include <cmath>
8 #include <bitset>
9 #include <string>
10 
11 namespace l1t {
12 
13  class TkJetWord {
14  public:
15  // ----------constants, enums and typedefs ---------
16  int INTPHI_PI = 720;
18  float INTPT_LSB = 1 >> 5;
19  float ETAPHI_LSB = M_PI / (1 << 12);
20  float Z0_LSB = 0.05;
21 
23  kPtSize = 16,
24  kPtMagSize = 11,
27  kZ0Size = 10,
28  kNtSize = 5,
29  kXtSize = 4,
32  };
33 
35  kPtLSB = 0,
36  kPtMSB = kPtLSB + TkJetBitWidths::kPtSize - 1,
38  kGlbEtaMSB = kGlbEtaLSB + TkJetBitWidths::kGlbEtaSize - 1,
40  kGlbPhiMSB = kGlbPhiLSB + TkJetBitWidths::kGlbPhiSize - 1,
42  kZ0MSB = kZ0LSB + TkJetBitWidths::kZ0Size - 1,
43  kNtLSB = kZ0MSB + 1,
44  kNtMSB = kNtLSB + TkJetBitWidths::kNtSize - 1,
45  kXtLSB = kNtMSB + 1,
46  kXtMSB = kXtLSB + TkJetBitWidths::kXtSize - 1,
48  kUnassignedMSB = kUnassignedLSB + TkJetBitWidths::kUnassignedSize - 1,
49  };
50 
51  typedef ap_ufixed<kPtSize, kPtMagSize, AP_TRN, AP_SAT> pt_t;
52  typedef ap_int<kGlbEtaSize> glbeta_t;
53  typedef ap_int<kGlbPhiSize> glbphi_t;
54  typedef ap_int<kZ0Size> z0_t; // 40cm / 0.1
55  typedef ap_uint<kNtSize> nt_t; //number of tracks
56  typedef ap_uint<kXtSize> nx_t; //number of tracks with xbit = 1
57  typedef ap_uint<TkJetBitWidths::kUnassignedSize> tkjetunassigned_t; // Unassigned bits
58  typedef std::bitset<TkJetBitWidths::kTkJetWordSize> tkjetword_bs_t;
59  typedef ap_uint<TkJetBitWidths::kTkJetWordSize> tkjetword_t;
60 
61  public:
62  // ----------Constructors --------------------------
63  TkJetWord() {}
65  std::string word = "";
66  word.append(TkJetBitWidths::kUnassignedSize - (unassigned.to_string().length() - 2), '0');
67  word = word + (unassigned.to_string().substr(2, unassigned.to_string().length() - 2));
68  word.append(TkJetBitWidths::kXtSize - (nx.to_string().length() - 2), '0');
69  word = word + (nx.to_string().substr(2, nx.to_string().length() - 2));
70  word.append(TkJetBitWidths::kNtSize - (nt.to_string().length() - 2), '0');
71  word = word + (nt.to_string().substr(2, nt.to_string().length() - 2));
72  word.append(TkJetBitWidths::kZ0Size - (z0.to_string().length() - 2), '0');
73  word = word + (z0.to_string().substr(2, z0.to_string().length() - 2));
74  word.append(TkJetBitWidths::kGlbPhiSize - (phi.to_string().length() - 2), '0');
75  word = word + (phi.to_string().substr(2, phi.to_string().length() - 2));
76  word.append(TkJetBitWidths::kGlbEtaSize - (eta.to_string().length() - 2), '0');
77  word = word + (eta.to_string().substr(2, eta.to_string().length() - 2));
78  ap_ufixed<kPtSize + 5, kPtMagSize + 5, AP_TRN, AP_SAT> pt_2 = pt;
79  ap_uint<kPtSize> pt_temp = pt_2 << 5;
80  word.append(TkJetBitWidths::kPtSize - (pt_temp.to_string().length() - 2), '0');
81  word = word + (pt_temp.to_string().substr(2, pt_temp.to_string().length() - 2));
82 
84  tkJetWord_ = tmp;
85  }
86 
88 
89  // ----------copy constructor ----------------------
90  TkJetWord(const TkJetWord& word) { tkJetWord_ = word.tkJetWord_; }
91 
92  // ----------operators -----------------------------
94  tkJetWord_ = word.tkJetWord_;
95  return *this;
96  }
97 
98  // ----------member functions (getters) ------------
99  // These functions return arbitarary precision words (lists of bits) for each quantity
100  pt_t ptWord() const {
101  pt_t ret;
102  ret.V = tkJetWord()(TkJetBitLocations::kPtMSB, TkJetBitLocations::kPtLSB);
103  return ret;
104  }
106  glbeta_t ret;
107  ret.V = tkJetWord()(TkJetBitLocations::kGlbEtaMSB, TkJetBitLocations::kGlbEtaLSB);
108  return ret;
109  }
111  glbphi_t ret;
112  ret.V = tkJetWord()(TkJetBitLocations::kGlbPhiMSB, TkJetBitLocations::kGlbPhiLSB);
113  return ret;
114  }
115  z0_t z0Word() const {
116  z0_t ret;
117  ret.V = tkJetWord()(TkJetBitLocations::kZ0MSB, TkJetBitLocations::kZ0LSB);
118  return ret;
119  }
120  nt_t ntWord() const {
121  nt_t ret;
122  ret.V = tkJetWord()(TkJetBitLocations::kNtMSB, TkJetBitLocations::kNtLSB);
123  return ret;
124  }
125  nx_t xtWord() const {
126  nx_t ret;
127  ret.V = tkJetWord()(TkJetBitLocations::kXtMSB, TkJetBitLocations::kXtLSB);
128  return ret;
129  }
131  return tkJetWord()(TkJetBitLocations::kUnassignedMSB, TkJetBitLocations::kUnassignedLSB);
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 unassignedBits() const { return unassignedWord().to_uint(); }
144 
145  // These functions return the unpacked and converted values
146  // These functions return real numbers converted from the digitized quantities by unpacking the 64-bit vertex word
147  float pt() const { return ptWord().to_float(); }
148  float glbeta() const { return glbEtaWord().to_float() * ETAPHI_LSB; }
149  float glbphi() const { return glbPhiWord().to_float() * ETAPHI_LSB; }
150  float z0() const { return z0Word().to_float() * Z0_LSB; }
151  int nt() const { return (ap_ufixed<kNtSize + 2, kNtSize>(ntWord())).to_int(); }
152  int xt() const { return (ap_ufixed<kXtSize + 2, kXtSize>(xtWord())).to_int(); }
153  unsigned int unassigned() const { return unassignedWord().to_uint(); }
154 
155  // ----------member functions (setters) ------------
157 
158  private:
159  // ----------private member functions --------------
160  double unpackSignedValue(unsigned int bits, unsigned int nBits, double lsb) const {
161  int isign = 1;
162  unsigned int digitized_maximum = (1 << nBits) - 1;
163  if (bits & (1 << (nBits - 1))) { // check the sign
164  isign = -1;
165  bits = (1 << (nBits + 1)) - bits; // if negative, flip everything for two's complement encoding
166  }
167  return (double(bits & digitized_maximum) + 0.5) * lsb * isign;
168  }
169 
170  // ----------member data ---------------------------
172  };
173 
174  typedef std::vector<l1t::TkJetWord> TkJetWordCollection;
175 
176 } // namespace l1t
177 
178 #endif
unsigned int xtBits() const
Definition: TkJetWord.h:142
int xt() const
Definition: TkJetWord.h:152
std::vector< l1t::TkJetWord > TkJetWordCollection
Definition: TkJetWord.h:174
unsigned int z0Bits() const
Definition: TkJetWord.h:140
ap_int< kGlbEtaSize > glbeta_t
Definition: TkJetWord.h:52
double unpackSignedValue(unsigned int bits, unsigned int nBits, double lsb) const
Definition: TkJetWord.h:160
int INTPHI_TWOPI
Definition: TkJetWord.h:17
ret
prodAgent to be discontinued
z0_t z0Word() const
Definition: TkJetWord.h:115
constexpr uint32_t bits
Definition: gpuClustering.h:23
ap_int< kGlbPhiSize > glbphi_t
Definition: TkJetWord.h:53
delete x;
Definition: CaloConfig.h:22
ap_ufixed< kPtSize, kPtMagSize, AP_TRN, AP_SAT > pt_t
Definition: TkJetWord.h:51
ap_uint< TkJetBitWidths::kUnassignedSize > tkjetunassigned_t
Definition: TkJetWord.h:57
ap_int< kZ0Size > z0_t
Definition: TkJetWord.h:54
ap_uint< TkJetBitWidths::kTkJetWordSize > tkjetword_t
Definition: TkJetWord.h:59
float pt() const
Definition: TkJetWord.h:147
uint64_t word
tkjetword_t tkJetWord() const
Definition: TkJetWord.h:133
TkJetWord & operator=(const TkJetWord &word)
Definition: TkJetWord.h:93
TkJetWord(pt_t pt, glbeta_t eta, glbphi_t phi, z0_t z0, nt_t nt, nx_t nx, tkjetunassigned_t unassigned)
Definition: TkJetWord.h:64
tkjetword_bs_t tkJetWord_
Definition: TkJetWord.h:171
float glbphi() const
Definition: TkJetWord.h:149
float z0() const
Definition: TkJetWord.h:150
glbeta_t glbEtaWord() const
Definition: TkJetWord.h:105
ap_uint< kXtSize > nx_t
Definition: TkJetWord.h:56
ap_int< 10 > z0_t
Definition: data.h:10
#define M_PI
int nt() const
Definition: TkJetWord.h:151
nx_t xtWord() const
Definition: TkJetWord.h:125
unsigned int glbPhiBits() const
Definition: TkJetWord.h:139
unsigned int glbEtaBits() const
Definition: TkJetWord.h:138
unsigned int ntBits() const
Definition: TkJetWord.h:141
float glbeta() const
Definition: TkJetWord.h:148
float INTPT_LSB
Definition: TkJetWord.h:18
unsigned int unassignedBits() const
Definition: TkJetWord.h:143
float Z0_LSB
Definition: TkJetWord.h:20
ap_int< 16 > pt_t
Definition: data.h:6
unsigned int unassigned() const
Definition: TkJetWord.h:153
glbphi_t glbPhiWord() const
Definition: TkJetWord.h:110
std::bitset< TkJetBitWidths::kTkJetWordSize > tkjetword_bs_t
Definition: TkJetWord.h:58
ap_uint< kNtSize > nt_t
Definition: TkJetWord.h:55
float ETAPHI_LSB
Definition: TkJetWord.h:19
pt_t ptWord() const
Definition: TkJetWord.h:100
tmp
align.sh
Definition: createJobs.py:716
TkJetWord(const TkJetWord &word)
Definition: TkJetWord.h:90
tkjetunassigned_t unassignedWord() const
Definition: TkJetWord.h:130
nt_t ntWord() const
Definition: TkJetWord.h:120
void setTkJetWord(pt_t pt, glbeta_t eta, glbphi_t phi, z0_t z0, nt_t nt, nx_t nx, tkjetunassigned_t unassigned)
unsigned int ptBits() const
Definition: TkJetWord.h:137