CMS 3D CMS Logo

VertexWord.h
Go to the documentation of this file.
1 #ifndef DataFormats_L1TVertex_VertexWord_h
2 #define DataFormats_L1TVertex_VertexWord_h
3 
5 //
6 // class to store the 96-bit track word produced by the L1 Track Trigger. Intended to be inherited by L1 TTTrack.
7 // packing scheme given below.
8 //
9 // author: Alexx Perloff
10 // created: March 17, 2021
11 //
13 
15 
16 #include <ap_int.h>
17 #include <ap_fixed.h>
18 
19 #include <bitset>
20 #include <vector>
21 
22 namespace l1t {
23 
24  class VertexWord {
25  public:
26  // ----------constants, enums and typedefs ---------
28  // The sizes of the vertex word components and total word size
29  kValidSize = 1, // Width of the valid bit
30  kZ0Size = 15, // Width of z-position
31  kZ0MagSize = 6, // Width of z-position magnitude (signed)
32  kNTrackInPVSize = 8, // Width of the multiplicity in the PV (unsigned)
33  kSumPtSize = 10, // Width of pT
34  kSumPtMagSize = 8, // Width of pT magnitude (unsigned)
35  kQualitySize = 3, // Width of the quality field
36  kNTrackOutPVSize = 10, // Width of the multiplicity outside the PV (unsigned)
37  kUnassignedSize = 17, // Width of the unassigned bits
38 
40  kUnassignedSize, // Width of the vertex word in bits
41  };
42 
44  // The location of the least significant bit (LSB) and most significant bit (MSB) in the vertex word for different fields
45  kValidLSB = 0,
48  kZ0MSB = kZ0LSB + VertexBitWidths::kZ0Size - 1,
50  kNTrackInPVMSB = kNTrackInPVLSB + VertexBitWidths::kNTrackInPVSize - 1,
52  kSumPtMSB = kSumPtLSB + VertexBitWidths::kSumPtSize - 1,
54  kQualityMSB = kQualityLSB + VertexBitWidths::kQualitySize - 1,
56  kNTrackOutPVMSB = kNTrackOutPVLSB + VertexBitWidths::kNTrackOutPVSize - 1,
59  };
60 
61  // vertex parameters types
62  typedef ap_uint<VertexBitWidths::kValidSize> vtxvalid_t; // Vertex validity
63  typedef ap_fixed<VertexBitWidths::kZ0Size, VertexBitWidths::kZ0MagSize, AP_RND_CONV, AP_SAT> vtxz0_t; // Vertex z0
64  typedef ap_ufixed<VertexBitWidths::kNTrackInPVSize, VertexBitWidths::kNTrackInPVSize, AP_RND_CONV, AP_SAT>
65  vtxmultiplicity_t; // NTracks in vertex
66  typedef ap_ufixed<VertexBitWidths::kSumPtSize, VertexBitWidths::kSumPtMagSize, AP_RND_CONV, AP_SAT>
67  vtxsumpt_t; // Vertex Sum pT
68  typedef ap_uint<VertexBitWidths::kQualitySize> vtxquality_t; // Vertex quality
69  typedef ap_ufixed<VertexBitWidths::kNTrackOutPVSize, VertexBitWidths::kNTrackOutPVSize, AP_RND_CONV, AP_SAT>
70  vtxinversemult_t; // NTracks outside vertex
71  typedef ap_uint<VertexBitWidths::kUnassignedSize> vtxunassigned_t; // Unassigned bits
72 
73  // vertex word types
74  typedef std::bitset<VertexBitWidths::kVertexWordSize> vtxword_bs_t; // Entire track word;
75  typedef ap_uint<VertexBitWidths::kVertexWordSize> vtxword_t; // Entire vertex word;
76 
77  // reference types
78  typedef edm::Ref<l1t::VertexCollection> VertexRef; // Reference to a persistent l1t::Vertex
79 
80  public:
81  // ----------Constructors --------------------------
83  VertexWord(unsigned int valid,
84  double z0,
85  unsigned int multiplicity,
86  double pt,
87  unsigned int quality,
88  unsigned int inverseMultiplicity,
89  unsigned int unassigned);
90  VertexWord(unsigned int valid,
91  unsigned int z0,
92  unsigned int multiplicity,
93  unsigned int pt,
94  unsigned int quality,
95  unsigned int inverseMultiplicity,
96  unsigned int unassigned);
98  vtxz0_t z0,
100  vtxsumpt_t pt,
104 
106 
107  // ----------copy constructor ----------------------
108  VertexWord(const VertexWord& word) { vertexWord_ = word.vertexWord_; }
109 
110  // ----------operators -----------------------------
112  vertexWord_ = word.vertexWord_;
113  return *this;
114  }
115 
116  // ----------member functions (getters) ------------
117  // These functions return arbitarary precision words (lists of bits) for each quantity
119  vtxz0_t z0Word() const {
120  vtxz0_t ret;
121  ret.V = vertexWord()(VertexBitLocations::kZ0MSB, VertexBitLocations::kZ0LSB);
122  return ret;
123  }
125  return vertexWord()(VertexBitLocations::kNTrackInPVMSB, VertexBitLocations::kNTrackInPVLSB);
126  }
127  vtxsumpt_t ptWord() const {
128  vtxsumpt_t ret;
129  ret.V = vertexWord()(VertexBitLocations::kSumPtMSB, VertexBitLocations::kSumPtLSB);
130  return ret;
131  }
133  return vertexWord()(VertexBitLocations::kQualityMSB, VertexBitLocations::kQualityLSB);
134  }
136  return vertexWord()(VertexBitLocations::kNTrackOutPVMSB, VertexBitLocations::kNTrackOutPVLSB);
137  }
140  }
141  vtxword_t vertexWord() const { return vtxword_t(vertexWord_.to_string().c_str(), 2); }
142 
143  // These functions return the packed bits in integer format for each quantity
144  // Signed quantities have the sign enconded in the left-most bit.
145  unsigned int validBits() const { return validWord().to_uint(); }
146  unsigned int z0Bits() const { return z0Word().to_uint(); }
147  unsigned int multiplicityBits() const { return multiplicityWord().to_uint(); }
148  unsigned int ptBits() const { return ptWord().to_uint(); }
149  unsigned int qualityBits() const { return qualityWord().to_uint(); }
150  unsigned int inverseMultiplicityBits() const { return inverseMultiplicityWord().to_uint(); }
151  unsigned int unassignedBits() const { return unassignedWord().to_uint(); }
152 
153  // These functions return the unpacked and converted values
154  // These functions return real numbers converted from the digitized quantities by unpacking the 64-bit vertex word
155  bool valid() const { return validWord().to_bool(); }
156  double z0() const { return z0Word().to_double(); }
157  unsigned int multiplicity() const { return multiplicityWord().to_uint(); }
158  double pt() const { return ptWord().to_double(); }
159  unsigned int quality() const { return qualityWord().to_uint(); }
160  unsigned int inverseMultiplicity() const { return inverseMultiplicityWord().to_uint(); }
161  unsigned int unassigned() const { return unassignedWord().to_uint(); }
162 
163  // return reference to floating point vertex
164  VertexRef vertexRef() const { return vertexRef_; }
165 
166  // ----------member functions (setters) ------------
168  vtxz0_t z0,
170  vtxsumpt_t pt,
174 
175  // set reference to floating point vertex
176  void setVertexRef(const VertexRef& ref) { vertexRef_ = ref; }
177 
178  private:
179  // ----------private member functions --------------
180  double unpackSignedValue(unsigned int bits, unsigned int nBits, double lsb) const {
181  int isign = 1;
182  unsigned int digitized_maximum = (1 << nBits) - 1;
183  if (bits & (1 << (nBits - 1))) { // check the sign
184  isign = -1;
185  bits = (1 << (nBits + 1)) - bits; // if negative, flip everything for two's complement encoding
186  }
187  return (double(bits & digitized_maximum) + 0.5) * lsb * isign;
188  }
189 
190  // ----------member data ---------------------------
193  };
194 
195  typedef std::vector<VertexWord> VertexWordCollection;
197 } // namespace l1t
198 
199 #endif
vtxword_bs_t vertexWord_
Definition: VertexWord.h:191
VertexRef vertexRef() const
Definition: VertexWord.h:164
unsigned int ptBits() const
Definition: VertexWord.h:148
ap_uint< VertexBitWidths::kUnassignedSize > vtxunassigned_t
Definition: VertexWord.h:71
unsigned int unassigned() const
Definition: VertexWord.h:161
ap_uint< VertexBitWidths::kVertexWordSize > vtxword_t
Definition: VertexWord.h:75
vtxquality_t qualityWord() const
Definition: VertexWord.h:132
ap_ufixed< VertexBitWidths::kNTrackInPVSize, VertexBitWidths::kNTrackInPVSize, AP_RND_CONV, AP_SAT > vtxmultiplicity_t
Definition: VertexWord.h:65
vtxsumpt_t ptWord() const
Definition: VertexWord.h:127
ret
prodAgent to be discontinued
unsigned int quality() const
Definition: VertexWord.h:159
constexpr uint32_t bits
Definition: gpuClustering.h:23
unsigned int z0Bits() const
Definition: VertexWord.h:146
void setVertexWord(vtxvalid_t valid, vtxz0_t z0, vtxmultiplicity_t multiplicity, vtxsumpt_t pt, vtxquality_t quality, vtxinversemult_t inverseMultiplicity, vtxunassigned_t unassigned)
Definition: VertexWord.cc:65
unsigned int inverseMultiplicityBits() const
Definition: VertexWord.h:150
delete x;
Definition: CaloConfig.h:22
VertexWord & operator=(const VertexWord &word)
Definition: VertexWord.h:111
std::bitset< VertexBitWidths::kVertexWordSize > vtxword_bs_t
Definition: VertexWord.h:74
vtxz0_t z0Word() const
Definition: VertexWord.h:119
vtxmultiplicity_t multiplicityWord() const
Definition: VertexWord.h:124
unsigned int qualityBits() const
Definition: VertexWord.h:149
vtxinversemult_t inverseMultiplicityWord() const
Definition: VertexWord.h:135
unsigned int multiplicityBits() const
Definition: VertexWord.h:147
ap_ufixed< VertexBitWidths::kNTrackOutPVSize, VertexBitWidths::kNTrackOutPVSize, AP_RND_CONV, AP_SAT > vtxinversemult_t
Definition: VertexWord.h:70
uint64_t word
unsigned int validBits() const
Definition: VertexWord.h:145
ap_fixed< VertexBitWidths::kZ0Size, VertexBitWidths::kZ0MagSize, AP_RND_CONV, AP_SAT > vtxz0_t
Definition: VertexWord.h:63
void setVertexRef(const VertexRef &ref)
Definition: VertexWord.h:176
const unsigned int kValidSize
edm::Ref< VertexWordCollection > VertexWordRef
Definition: VertexWord.h:196
ap_ufixed< VertexBitWidths::kSumPtSize, VertexBitWidths::kSumPtMagSize, AP_RND_CONV, AP_SAT > vtxsumpt_t
Definition: VertexWord.h:67
std::vector< VertexWord > VertexWordCollection
Definition: VertexWord.h:195
ap_uint< VertexBitWidths::kQualitySize > vtxquality_t
Definition: VertexWord.h:68
double pt() const
Definition: VertexWord.h:158
VertexWord(const VertexWord &word)
Definition: VertexWord.h:108
vtxunassigned_t unassignedWord() const
Definition: VertexWord.h:138
VertexRef vertexRef_
Definition: VertexWord.h:192
bool valid() const
Definition: VertexWord.h:155
double z0() const
Definition: VertexWord.h:156
unsigned int unassignedBits() const
Definition: VertexWord.h:151
const unsigned int kUnassignedSize
edm::Ref< l1t::VertexCollection > VertexRef
Definition: VertexWord.h:78
unsigned int multiplicity() const
Definition: VertexWord.h:157
double unpackSignedValue(unsigned int bits, unsigned int nBits, double lsb) const
Definition: VertexWord.h:180
vtxvalid_t validWord() const
Definition: VertexWord.h:118
unsigned int inverseMultiplicity() const
Definition: VertexWord.h:160
vtxword_t vertexWord() const
Definition: VertexWord.h:141
ap_uint< VertexBitWidths::kValidSize > vtxvalid_t
Definition: VertexWord.h:62