File indexing completed on 2024-04-06 12:04:39
0001 #ifndef DataFormats_L1TVertex_VertexWord_h
0002 #define DataFormats_L1TVertex_VertexWord_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "DataFormats/L1Trigger/interface/Vertex.h"
0017
0018 #include <ap_int.h>
0019 #include <ap_fixed.h>
0020
0021 #include <bitset>
0022 #include <vector>
0023
0024 namespace l1t {
0025
0026 class VertexWord {
0027 public:
0028
0029 enum VertexBitWidths {
0030
0031 kValidSize = 1,
0032 kZ0Size = 15,
0033 kZ0MagSize = 6,
0034 kNTrackInPVSize = 8,
0035 kSumPtSize = 12,
0036 kSumPtMagSize = 10,
0037 kQualitySize = 3,
0038 kNTrackOutPVSize = 10,
0039 kUnassignedSize = 15,
0040
0041 kVertexWordSize = kValidSize + kZ0Size + kNTrackInPVSize + kSumPtSize + kQualitySize + kNTrackOutPVSize +
0042 kUnassignedSize,
0043 };
0044
0045 enum VertexBitLocations {
0046
0047 kValidLSB = 0,
0048 kValidMSB = kValidLSB + VertexBitWidths::kValidSize - 1,
0049 kZ0LSB = kValidMSB + 1,
0050 kZ0MSB = kZ0LSB + VertexBitWidths::kZ0Size - 1,
0051 kNTrackInPVLSB = kZ0MSB + 1,
0052 kNTrackInPVMSB = kNTrackInPVLSB + VertexBitWidths::kNTrackInPVSize - 1,
0053 kSumPtLSB = kNTrackInPVMSB + 1,
0054 kSumPtMSB = kSumPtLSB + VertexBitWidths::kSumPtSize - 1,
0055 kQualityLSB = kSumPtMSB + 1,
0056 kQualityMSB = kQualityLSB + VertexBitWidths::kQualitySize - 1,
0057 kNTrackOutPVLSB = kQualityMSB + 1,
0058 kNTrackOutPVMSB = kNTrackOutPVLSB + VertexBitWidths::kNTrackOutPVSize - 1,
0059 kUnassignedLSB = kNTrackOutPVMSB + 1,
0060 kUnassignedMSB = kUnassignedLSB + VertexBitWidths::kUnassignedSize - 1
0061 };
0062
0063
0064 typedef ap_uint<VertexBitWidths::kValidSize> vtxvalid_t;
0065 typedef ap_fixed<VertexBitWidths::kZ0Size, VertexBitWidths::kZ0MagSize, AP_RND_CONV, AP_SAT> vtxz0_t;
0066 typedef ap_ufixed<VertexBitWidths::kNTrackInPVSize, VertexBitWidths::kNTrackInPVSize, AP_RND_CONV, AP_SAT>
0067 vtxmultiplicity_t;
0068 typedef ap_ufixed<VertexBitWidths::kSumPtSize, VertexBitWidths::kSumPtMagSize, AP_RND_CONV, AP_SAT>
0069 vtxsumpt_t;
0070 typedef ap_uint<VertexBitWidths::kQualitySize> vtxquality_t;
0071 typedef ap_ufixed<VertexBitWidths::kNTrackOutPVSize, VertexBitWidths::kNTrackOutPVSize, AP_RND_CONV, AP_SAT>
0072 vtxinversemult_t;
0073 typedef ap_uint<VertexBitWidths::kUnassignedSize> vtxunassigned_t;
0074
0075
0076 typedef std::bitset<VertexBitWidths::kVertexWordSize> vtxword_bs_t;
0077 typedef ap_uint<VertexBitWidths::kVertexWordSize> vtxword_t;
0078
0079
0080 typedef edm::Ref<l1t::VertexCollection> VertexRef;
0081
0082 public:
0083
0084 VertexWord() {}
0085 VertexWord(unsigned int valid,
0086 double z0,
0087 unsigned int multiplicity,
0088 double pt,
0089 unsigned int quality,
0090 unsigned int inverseMultiplicity,
0091 unsigned int unassigned);
0092 VertexWord(unsigned int valid,
0093 unsigned int z0,
0094 unsigned int multiplicity,
0095 unsigned int pt,
0096 unsigned int quality,
0097 unsigned int inverseMultiplicity,
0098 unsigned int unassigned);
0099 VertexWord(vtxvalid_t valid,
0100 vtxz0_t z0,
0101 vtxmultiplicity_t multiplicity,
0102 vtxsumpt_t pt,
0103 vtxquality_t quality,
0104 vtxinversemult_t inverseMultiplicity,
0105 vtxunassigned_t unassigned);
0106
0107 ~VertexWord() {}
0108
0109
0110 VertexWord(const VertexWord& word) { vertexWord_ = word.vertexWord_; }
0111
0112
0113 VertexWord& operator=(const VertexWord& word) {
0114 vertexWord_ = word.vertexWord_;
0115 return *this;
0116 }
0117
0118
0119
0120 vtxvalid_t validWord() const { return vertexWord()(VertexBitLocations::kValidMSB, VertexBitLocations::kValidLSB); }
0121 vtxz0_t z0Word() const {
0122 vtxz0_t ret;
0123 ret.V = vertexWord()(VertexBitLocations::kZ0MSB, VertexBitLocations::kZ0LSB);
0124 return ret;
0125 }
0126 vtxmultiplicity_t multiplicityWord() const {
0127 return vertexWord()(VertexBitLocations::kNTrackInPVMSB, VertexBitLocations::kNTrackInPVLSB);
0128 }
0129 vtxsumpt_t ptWord() const {
0130 vtxsumpt_t ret;
0131 ret.V = vertexWord()(VertexBitLocations::kSumPtMSB, VertexBitLocations::kSumPtLSB);
0132 return ret;
0133 }
0134 vtxquality_t qualityWord() const {
0135 return vertexWord()(VertexBitLocations::kQualityMSB, VertexBitLocations::kQualityLSB);
0136 }
0137 vtxinversemult_t inverseMultiplicityWord() const {
0138 return vertexWord()(VertexBitLocations::kNTrackOutPVMSB, VertexBitLocations::kNTrackOutPVLSB);
0139 }
0140 vtxunassigned_t unassignedWord() const {
0141 return vertexWord()(VertexBitLocations::kUnassignedMSB, VertexBitLocations::kUnassignedLSB);
0142 }
0143 vtxword_t vertexWord() const { return vtxword_t(vertexWord_.to_string().c_str(), 2); }
0144
0145
0146
0147 unsigned int validBits() const { return validWord().to_uint(); }
0148 unsigned int z0Bits() const { return z0Word().range().to_uint(); }
0149 unsigned int multiplicityBits() const { return multiplicityWord().to_uint(); }
0150 unsigned int ptBits() const { return ptWord().range().to_uint(); }
0151 unsigned int qualityBits() const { return qualityWord().to_uint(); }
0152 unsigned int inverseMultiplicityBits() const { return inverseMultiplicityWord().to_uint(); }
0153 unsigned int unassignedBits() const { return unassignedWord().to_uint(); }
0154
0155
0156
0157 bool valid() const { return validWord().to_bool(); }
0158 double z0() const { return z0Word().to_double(); }
0159 unsigned int multiplicity() const { return multiplicityWord().to_uint(); }
0160 double pt() const { return ptWord().to_double(); }
0161 unsigned int quality() const { return qualityWord().to_uint(); }
0162 unsigned int inverseMultiplicity() const { return inverseMultiplicityWord().to_uint(); }
0163 unsigned int unassigned() const { return unassignedWord().to_uint(); }
0164
0165
0166 VertexRef vertexRef() const { return vertexRef_; }
0167
0168
0169 void setVertexWord(vtxvalid_t valid,
0170 vtxz0_t z0,
0171 vtxmultiplicity_t multiplicity,
0172 vtxsumpt_t pt,
0173 vtxquality_t quality,
0174 vtxinversemult_t inverseMultiplicity,
0175 vtxunassigned_t unassigned);
0176
0177
0178 void setVertexRef(const VertexRef& ref) { vertexRef_ = ref; }
0179
0180 private:
0181
0182 double unpackSignedValue(unsigned int bits, unsigned int nBits, double lsb) const {
0183 int isign = 1;
0184 unsigned int digitized_maximum = (1 << nBits) - 1;
0185 if (bits & (1 << (nBits - 1))) {
0186 isign = -1;
0187 bits = (1 << (nBits + 1)) - bits;
0188 }
0189 return (double(bits & digitized_maximum) + 0.5) * lsb * isign;
0190 }
0191
0192
0193 vtxword_bs_t vertexWord_;
0194 VertexRef vertexRef_;
0195 };
0196
0197 typedef std::vector<VertexWord> VertexWordCollection;
0198 typedef edm::Ref<VertexWordCollection> VertexWordRef;
0199 }
0200
0201 #endif