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