CMS 3D CMS Logo

TkTripletWord.h
Go to the documentation of this file.
1 #ifndef FIRMWARE_TkTripletWord_h
2 #define FIRMWARE_TkTripletWord_h
3 
4 // Class to store the 128-bit TkTriplet word for the L1TrackTriggerMatch.
5 // Original author: George Karathanasis (Dec 2023)
6 
7 #include <vector>
8 #include <ap_int.h>
9 #include <cassert>
10 #include <cmath>
11 #include <bitset>
12 #include <string>
14 
15 namespace l1t {
16 
17  class TkTripletWord {
18  public:
19  // ----------constants, enums and typedefs ---------
20  static constexpr double MAX_MASS = 1000.;
21  static constexpr double MAX_ETA = 8.;
22  static constexpr double MAX_CHARGE = 3.;
23  static constexpr double MAX_Z0 = 25.;
24 
26  // The sizes of the triplet word components and total word size
27  kValidSize = 1, // Width of the valid bit
28  kPtSize = 16, // Width of the triplet pt
29  kPtMagSize = 11,
30  kGlbEtaSize = 14, // Width of the triplet eta
31  kGlbPhiSize = 13, // Width of the triplet phi
32  kMassSize = 16, // Width of the triplet mass
33  kChargeSize = 3, // Width of the triplet charge
34  kDiTrackMinMassSize = 16, // Width of the mass of min mass pair
35  kDiTrackMaxMassSize = 16, // Width of the mass of max mass pair
36  kDiTrackMinZ0Size = 8, // Width of the Dz of min Dz pair
37  kDiTrackMaxZ0Size = 8, // Width of the Dz of max Dz pair
42  };
43 
45  // The location of the least significant bit (LSB) and most significant bit (MSB) in the triplet word for different fields
46  kValidLSB = 0,
49  kPtMSB = kPtLSB + TkTripletBitWidths::kPtSize - 1,
51  kGlbPhiMSB = kGlbPhiLSB + TkTripletBitWidths::kGlbPhiSize - 1,
53  kGlbEtaMSB = kGlbEtaLSB + TkTripletBitWidths::kGlbEtaSize - 1,
55  kMassMSB = kMassLSB + TkTripletBitWidths::kMassSize - 1,
57  kChargeMSB = kChargeLSB + TkTripletBitWidths::kChargeSize - 1,
59  kDiTrackMinMassMSB = kDiTrackMinMassLSB + TkTripletBitWidths::kDiTrackMinMassSize - 1,
61  kDiTrackMaxMassMSB = kDiTrackMaxMassLSB + TkTripletBitWidths::kDiTrackMaxMassSize - 1,
63  kDiTrackMinZ0MSB = kDiTrackMinZ0LSB + TkTripletBitWidths::kDiTrackMinZ0Size - 1,
65  kDiTrackMaxZ0MSB = kDiTrackMaxZ0LSB + TkTripletBitWidths::kDiTrackMaxZ0Size - 1,
68  };
69 
70  // vertex parameters types
71  typedef ap_uint<kValidSize> valid_t; //valid
72  typedef ap_ufixed<kPtSize, kPtMagSize, AP_TRN, AP_SAT> pt_t; //triplet pt
73  typedef ap_int<kGlbEtaSize> glbeta_t; //triplet eta
74  typedef ap_int<kGlbPhiSize> glbphi_t; //triplet phi
75  typedef ap_int<kMassSize> mass_t; //triplet mass
76  typedef ap_int<kChargeSize> charge_t; //triplet Q
77  typedef ap_int<kDiTrackMinMassSize> ditrack_minmass_t; //pair min mass
78  typedef ap_int<kDiTrackMaxMassSize> ditrack_maxmass_t; //pair max mass
79  typedef ap_int<kDiTrackMinZ0Size> ditrack_minz0_t; //pair dz min
80  typedef ap_int<kDiTrackMaxZ0Size> ditrack_maxz0_t; //pair dz max
81  typedef ap_uint<TkTripletBitWidths::kUnassignedSize> unassigned_t;
82  typedef std::bitset<TkTripletBitWidths::kTkTripletWordSize> tktripletword_bs_t;
83  typedef ap_uint<TkTripletBitWidths::kTkTripletWordSize> tktripletword_t;
84 
85  public:
86  // ----------Constructors --------------------------
89  pt_t pt,
90  glbeta_t eta,
91  glbphi_t phi,
92  mass_t mass,
94  ditrack_minmass_t ditrack_minmass,
95  ditrack_maxmass_t ditrack_maxmass,
99 
101 
102  // ----------copy constructor ----------------------
103  TkTripletWord(const TkTripletWord& word) { tkTripletWord_ = word.tkTripletWord_; }
104 
105  // ----------operators -----------------------------
107  tkTripletWord_ = word.tkTripletWord_;
108  return *this;
109  }
110 
111  // ----------member functions (getters) ------------
112  // These functions return arbitarary precision words (lists of bits) for each quantity
113  valid_t validWord() const {
115  }
116  pt_t ptWord() const {
117  pt_t ret;
118  ret.V = tkTripletWord()(TkTripletBitLocations::kPtMSB, TkTripletBitLocations::kPtLSB);
119  return ret;
120  }
122  glbeta_t ret;
123  ret.V = tkTripletWord()(TkTripletBitLocations::kGlbEtaMSB, TkTripletBitLocations::kGlbEtaLSB);
124  return ret;
125  }
127  glbphi_t ret;
128  ret.V = tkTripletWord()(TkTripletBitLocations::kGlbPhiMSB, TkTripletBitLocations::kGlbPhiLSB);
129  return ret;
130  }
131  mass_t massWord() const {
132  mass_t ret;
133  ret.V = tkTripletWord()(TkTripletBitLocations::kMassMSB, TkTripletBitLocations::kMassLSB);
134  return ret;
135  }
137  charge_t ret;
138  ret.V = tkTripletWord()(TkTripletBitLocations::kChargeMSB, TkTripletBitLocations::kChargeLSB);
139  return ret;
140  }
141 
144  ret.V = tkTripletWord()(TkTripletBitLocations::kDiTrackMinMassMSB, TkTripletBitLocations::kDiTrackMinMassLSB);
145  return ret;
146  }
149  ret.V = tkTripletWord()(TkTripletBitLocations::kDiTrackMaxMassMSB, TkTripletBitLocations::kDiTrackMaxMassLSB);
150  return ret;
151  }
154  ret.V = tkTripletWord()(TkTripletBitLocations::kDiTrackMinZ0MSB, TkTripletBitLocations::kDiTrackMinZ0LSB);
155  return ret;
156  }
159  ret.V = tkTripletWord()(TkTripletBitLocations::kDiTrackMaxZ0MSB, TkTripletBitLocations::kDiTrackMaxZ0LSB);
160  return ret;
161  }
164  }
165  tktripletword_t tkTripletWord() const { return tktripletword_t(tkTripletWord_.to_string().c_str(), 2); }
166 
167  // These functions return the packed bits in integer format for each quantity
168  // Signed quantities have the sign enconded in the left-most bit.
169  unsigned int validBits() const { return validWord().to_uint(); }
170  unsigned int ptBits() const { return ptWord().to_uint(); }
171  unsigned int glbEtaBits() const { return glbEtaWord().to_uint(); }
172  unsigned int glbPhiBits() const { return glbPhiWord().to_uint(); }
173  unsigned int massBits() const { return massWord().to_uint(); }
174  unsigned int chargeBits() const { return chargeWord().to_uint(); }
175  unsigned int ditrackMinMassBits() const { return ditrackMinMassWord().to_uint(); }
176  unsigned int ditrackMaxMassBits() const { return ditrackMaxMassWord().to_uint(); }
177  unsigned int ditrackMinZ0Bits() const { return ditrackMinZ0Word().to_uint(); }
178  unsigned int ditrackMaxZ0Bits() const { return ditrackMaxZ0Word().to_uint(); }
179  unsigned int unassignedBits() const { return unassignedWord().to_uint(); }
180 
181  // These functions return the unpacked and converted values
182  // These functions return real numbers converted from the digitized quantities by unpacking the 64-bit vertex word
183  bool valid() const { return validWord().to_bool(); }
184  float pt() const { return ptWord().to_float(); }
185  float glbeta() const {
186  return unpackSignedValue(
187  glbEtaWord(), TkTripletBitWidths::kGlbEtaSize, (MAX_ETA) / (1 << TkTripletBitWidths::kGlbEtaSize));
188  }
189  float glbphi() const {
190  return unpackSignedValue(glbPhiWord(),
191  TkTripletBitWidths::kGlbPhiSize,
192  (2. * std::abs(M_PI)) / (1 << TkTripletBitWidths::kGlbPhiSize));
193  }
194  float mass() const {
195  return unpackSignedValue(
196  massWord(), TkTripletBitWidths::kMassSize, MAX_MASS / (1 << TkTripletBitWidths::kMassSize));
197  }
198  int charge() const {
199  return unpackSignedValue(
200  chargeWord(), TkTripletBitWidths::kChargeSize, MAX_CHARGE / (1 << TkTripletBitWidths::kChargeSize));
201  }
202  float ditrackMinMass() const {
204  TkTripletBitWidths::kDiTrackMinMassSize,
205  MAX_MASS / (1 << TkTripletBitWidths::kDiTrackMinMassSize));
206  }
207  float ditrackMaxMass() const {
209  TkTripletBitWidths::kDiTrackMaxMassSize,
210  MAX_MASS / (1 << TkTripletBitWidths::kDiTrackMaxMassSize));
211  }
212  float ditrackMinZ0() const {
214  TkTripletBitWidths::kDiTrackMinZ0Size,
215  MAX_Z0 / (1 << TkTripletBitWidths::kDiTrackMinZ0Size));
216  }
217  float ditrackMaxZ0() const {
219  TkTripletBitWidths::kDiTrackMaxZ0Size,
220  MAX_Z0 / (1 << TkTripletBitWidths::kDiTrackMaxZ0Size));
221  }
222  unsigned int unassigned() const { return unassignedWord().to_uint(); }
223 
224  // ----------member functions (setters) ------------
226  pt_t pt,
227  glbeta_t eta,
228  glbphi_t phi,
229  mass_t mass,
231  ditrack_minmass_t ditrack_minmass,
232  ditrack_maxmass_t ditrack_maxmass,
233  ditrack_minz0_t ditrack_minz0,
234  ditrack_maxz0_t ditrack_maxz0,
236 
237  template <class packVarType>
238  inline void packIntoWord(unsigned int& currentOffset, unsigned int wordChunkSize, packVarType& packVar);
239 
240  private:
241  // ----------private member functions --------------
242  double unpackSignedValue(unsigned int bits, unsigned int nBits, double lsb) const {
243  int isign = 1;
244  unsigned int digitized_maximum = (1 << nBits) - 1;
245  if (bits & (1 << (nBits - 1))) { // check the sign
246  isign = -1;
247  bits = (1 << (nBits + 1)) - bits; // if negative, flip everything for two's complement encoding
248  }
249  return (double(bits & digitized_maximum) + 0.5) * lsb * isign;
250  }
251 
252  // ----------member data ---------------------------
254  };
255 
256  typedef std::vector<l1t::TkTripletWord> TkTripletWordCollection;
257 
258 } // namespace l1t
259 
260 #endif
unsigned int ptBits() const
ap_int< kChargeSize > charge_t
Definition: TkTripletWord.h:76
ret
prodAgent to be discontinued
unsigned int ditrackMaxMassBits() const
charge_t chargeWord() const
float pt() const
double unpackSignedValue(unsigned int bits, unsigned int nBits, double lsb) const
TkTripletWord(const TkTripletWord &word)
delete x;
Definition: CaloConfig.h:22
glbeta_t glbEtaWord() const
float glbeta() const
ditrack_minmass_t ditrackMinMassWord() const
void setTkTripletWord(valid_t valid, pt_t pt, glbeta_t eta, glbphi_t phi, mass_t mass, charge_t charge, ditrack_minmass_t ditrack_minmass, ditrack_maxmass_t ditrack_maxmass, ditrack_minz0_t ditrack_minz0, ditrack_maxz0_t ditrack_maxz0, unassigned_t unassigned)
ap_int< kGlbEtaSize > glbeta_t
Definition: TkTripletWord.h:73
float ditrackMinZ0() const
static constexpr double MAX_ETA
Definition: TkTripletWord.h:21
unsigned int massBits() const
unsigned int ditrackMinZ0Bits() const
uint64_t word
unsigned int unassignedBits() const
ap_int< kMassSize > mass_t
Definition: TkTripletWord.h:75
float glbphi() const
ap_int< kDiTrackMinMassSize > ditrack_minmass_t
Definition: TkTripletWord.h:77
const unsigned int kValidSize
unsigned int ditrackMaxZ0Bits() const
ditrack_minz0_t ditrackMinZ0Word() const
ap_uint< TkTripletBitWidths::kUnassignedSize > unassigned_t
Definition: TkTripletWord.h:81
std::vector< l1t::TkTripletWord > TkTripletWordCollection
unsigned int glbPhiBits() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool valid() const
static constexpr double MAX_MASS
Definition: TkTripletWord.h:20
tktripletword_t tkTripletWord() const
unsigned int unassigned() const
pt_t ptWord() const
static constexpr double MAX_CHARGE
Definition: TkTripletWord.h:22
ap_int< kDiTrackMinZ0Size > ditrack_minz0_t
Definition: TkTripletWord.h:79
ap_int< kGlbPhiSize > glbphi_t
Definition: TkTripletWord.h:74
#define M_PI
unsigned int validBits() const
float ditrackMinMass() const
TkTripletWord & operator=(const TkTripletWord &word)
ap_ufixed< kPtSize, kPtMagSize, AP_TRN, AP_SAT > pt_t
Definition: TkTripletWord.h:72
tktripletword_bs_t tkTripletWord_
ap_uint< TkTripletBitWidths::kTkTripletWordSize > tktripletword_t
Definition: TkTripletWord.h:83
glbphi_t glbPhiWord() const
unsigned int ditrackMinMassBits() const
static constexpr double MAX_Z0
Definition: TkTripletWord.h:23
ap_int< kDiTrackMaxMassSize > ditrack_maxmass_t
Definition: TkTripletWord.h:78
ap_int< kDiTrackMaxZ0Size > ditrack_maxz0_t
Definition: TkTripletWord.h:80
ditrack_maxmass_t ditrackMaxMassWord() const
const unsigned int kUnassignedSize
valid_t validWord() const
unsigned int glbEtaBits() const
mass_t massWord() const
int charge() const
std::bitset< TkTripletBitWidths::kTkTripletWordSize > tktripletword_bs_t
Definition: TkTripletWord.h:82
float mass() const
unsigned int chargeBits() const
float ditrackMaxZ0() const
float ditrackMaxMass() const
ap_ufixed< 16, 14 > pt_t
Definition: TauNNIdHW.h:13
unassigned_t unassignedWord() const
void packIntoWord(unsigned int &currentOffset, unsigned int wordChunkSize, packVarType &packVar)
ap_uint< kValidSize > valid_t
Definition: TkTripletWord.h:71
ditrack_maxz0_t ditrackMaxZ0Word() const