File indexing completed on 2022-06-10 01:50:16
0001 #ifndef DataFormats_L1TParticleFlow_puppi_h
0002 #define DataFormats_L1TParticleFlow_puppi_h
0003
0004 #include "DataFormats/L1TParticleFlow/interface/datatypes.h"
0005 #include "DataFormats/L1TParticleFlow/interface/bit_encoding.h"
0006 #include "DataFormats/L1TParticleFlow/interface/layer1_objs.h"
0007 #include "DataFormats/L1TParticleFlow/interface/pf.h"
0008
0009 namespace l1ct {
0010
0011 struct PuppiObj {
0012 pt_t hwPt;
0013 glbeta_t hwEta;
0014 glbphi_t hwPhi;
0015 ParticleID hwId;
0016
0017 static const int BITS_Z0_START = 0;
0018 static const int BITS_DXY_START = BITS_Z0_START + z0_t::width;
0019 static const int BITS_TKQUAL_START = BITS_DXY_START + dxy_t::width;
0020 static const int DATA_CHARGED_BITS_TOTAL = BITS_TKQUAL_START + tkquality_t::width;
0021
0022 static const int BITS_PUPPIW_START = 0;
0023 static const int BITS_EMID_START = BITS_PUPPIW_START + puppiWgt_t::width;
0024 static const int DATA_NEUTRAL_BITS_TOTAL = BITS_EMID_START + emid_t::width;
0025
0026 static const int DATA_BITS_TOTAL =
0027 DATA_CHARGED_BITS_TOTAL >= DATA_NEUTRAL_BITS_TOTAL ? DATA_CHARGED_BITS_TOTAL : DATA_NEUTRAL_BITS_TOTAL;
0028
0029 ap_uint<DATA_BITS_TOTAL> hwData;
0030
0031 inline z0_t hwZ0() const {
0032 #ifndef __SYNTHESIS__
0033 assert(hwId.charged() || hwPt == 0);
0034 #endif
0035 return z0_t(hwData(BITS_Z0_START + z0_t::width - 1, BITS_Z0_START));
0036 }
0037
0038 inline void setHwZ0(z0_t z0) {
0039 #ifndef __SYNTHESIS__
0040 assert(hwId.charged() || hwPt == 0);
0041 #endif
0042 hwData(BITS_Z0_START + z0_t::width - 1, BITS_Z0_START) = z0(z0_t::width - 1, 0);
0043 }
0044
0045 inline dxy_t hwDxy() const {
0046 #ifndef __SYNTHESIS__
0047 assert(hwId.charged() || hwPt == 0);
0048 #endif
0049 return dxy_t(hwData(BITS_DXY_START + dxy_t::width - 1, BITS_DXY_START));
0050 }
0051
0052 inline void setHwDxy(dxy_t dxy) {
0053 #ifndef __SYNTHESIS__
0054 assert(hwId.charged() || hwPt == 0);
0055 #endif
0056 hwData(BITS_DXY_START + dxy_t::width - 1, BITS_DXY_START) = dxy(7, 0);
0057 }
0058
0059 inline tkquality_t hwTkQuality() const {
0060 #ifndef __SYNTHESIS__
0061 assert(hwId.charged() || hwPt == 0);
0062 #endif
0063 return tkquality_t(hwData(BITS_TKQUAL_START + tkquality_t::width - 1, BITS_TKQUAL_START));
0064 }
0065
0066 inline void setHwTkQuality(tkquality_t qual) {
0067 #ifndef __SYNTHESIS__
0068 assert(hwId.charged() || hwPt == 0);
0069 #endif
0070 hwData(BITS_TKQUAL_START + tkquality_t::width - 1, BITS_TKQUAL_START) = qual(tkquality_t::width - 1, 0);
0071 }
0072
0073 inline puppiWgt_t hwPuppiW() const {
0074 #ifndef __SYNTHESIS__
0075 assert(hwId.neutral());
0076 #endif
0077 return puppiWgt_t(hwData(BITS_PUPPIW_START + puppiWgt_t::width - 1, BITS_PUPPIW_START));
0078 }
0079
0080 inline void setHwPuppiW(puppiWgt_t w) {
0081 #ifndef __SYNTHESIS__
0082 assert(hwId.neutral());
0083 #endif
0084 hwData(BITS_PUPPIW_START + puppiWgt_t::width - 1, BITS_PUPPIW_START) = w(puppiWgt_t::width - 1, 0);
0085 }
0086
0087 inline puppiWgt_t hwEmID() const {
0088 #ifndef __SYNTHESIS__
0089 assert(hwId.neutral());
0090 #endif
0091 return puppiWgt_t(hwData(BITS_EMID_START + emid_t::width - 1, BITS_EMID_START));
0092 }
0093
0094 inline void setHwEmID(emid_t w) {
0095 #ifndef __SYNTHESIS__
0096 assert(hwId.neutral());
0097 #endif
0098 hwData(BITS_EMID_START + emid_t::width - 1, BITS_EMID_START) = w(emid_t::width - 1, 0);
0099 }
0100
0101 inline bool operator==(const PuppiObj &other) const {
0102 return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwId == other.hwId &&
0103 hwData == other.hwData;
0104 }
0105
0106 inline bool operator>(const PuppiObj &other) const { return hwPt > other.hwPt; }
0107 inline bool operator<(const PuppiObj &other) const { return hwPt < other.hwPt; }
0108
0109 inline void clear() {
0110 hwPt = 0;
0111 hwEta = 0;
0112 hwPhi = 0;
0113 hwId.clear();
0114 hwData = 0;
0115 }
0116
0117 inline void fill(const PFRegion ®ion, const PFChargedObj &src) {
0118 hwEta = region.hwGlbEta(src.hwVtxEta());
0119 hwPhi = region.hwGlbPhi(src.hwVtxPhi());
0120 hwId = src.hwId;
0121 hwPt = src.hwPt;
0122 hwData = 0;
0123 setHwZ0(src.hwZ0);
0124 setHwDxy(src.hwDxy);
0125 setHwTkQuality(src.hwTkQuality);
0126 }
0127 inline void fill(const PFRegion ®ion, const PFNeutralObj &src, pt_t puppiPt, puppiWgt_t puppiWgt) {
0128 hwEta = region.hwGlbEta(src.hwEta);
0129 hwPhi = region.hwGlbPhi(src.hwPhi);
0130 hwId = src.hwId;
0131 hwPt = puppiPt;
0132 hwData = 0;
0133 setHwPuppiW(puppiWgt);
0134 setHwEmID(src.hwEmID);
0135 }
0136 inline void fill(const PFRegion ®ion, const HadCaloObj &src, pt_t puppiPt, puppiWgt_t puppiWgt) {
0137 hwEta = region.hwGlbEta(src.hwEta);
0138 hwPhi = region.hwGlbPhi(src.hwPhi);
0139 hwId = src.hwIsEM() ? ParticleID::PHOTON : ParticleID::HADZERO;
0140 hwPt = puppiPt;
0141 hwData = 0;
0142 setHwPuppiW(puppiWgt);
0143 setHwEmID(src.hwEmID);
0144 }
0145
0146 int intPt() const { return Scales::intPt(hwPt); }
0147 int intEta() const { return hwEta.to_int(); }
0148 int intPhi() const { return hwPhi.to_int(); }
0149 float floatPt() const { return Scales::floatPt(hwPt); }
0150 float floatEta() const { return Scales::floatEta(hwEta); }
0151 float floatPhi() const { return Scales::floatPhi(hwPhi); }
0152 int intId() const { return hwId.rawId(); }
0153 int pdgId() const { return hwId.pdgId(); }
0154 int oldId() const { return hwPt > 0 ? hwId.oldId() : 0; }
0155 int intCharge() const { return hwId.intCharge(); }
0156 float floatZ0() const { return Scales::floatZ0(hwZ0()); }
0157 float floatDxy() const { return Scales::floatDxy(hwDxy()); }
0158 float floatPuppiW() const { return hwId.neutral() ? Scales::floatPuppiW(hwPuppiW()) : 1.0f; }
0159
0160 static const int BITWIDTH = pt_t::width + glbeta_t::width + glbphi_t::width + 3 + DATA_BITS_TOTAL;
0161 inline ap_uint<BITWIDTH> pack() const {
0162 ap_uint<BITWIDTH> ret;
0163 unsigned int start = 0;
0164 pack_into_bits(ret, start, hwPt);
0165 pack_into_bits(ret, start, hwEta);
0166 pack_into_bits(ret, start, hwPhi);
0167 pack_into_bits(ret, start, hwId.bits);
0168 pack_into_bits(ret, start, hwData);
0169 return ret;
0170 }
0171 inline void initFromBits(const ap_uint<BITWIDTH> &src) {
0172 unsigned int start = 0;
0173 unpack_from_bits(src, start, hwPt);
0174 unpack_from_bits(src, start, hwEta);
0175 unpack_from_bits(src, start, hwPhi);
0176 unpack_from_bits(src, start, hwId.bits);
0177 unpack_from_bits(src, start, hwData);
0178 }
0179 inline static PuppiObj unpack(const ap_uint<BITWIDTH> &src) {
0180 PuppiObj ret;
0181 ret.initFromBits(src);
0182 return ret;
0183 }
0184 };
0185 inline void clear(PuppiObj &c) { c.clear(); }
0186
0187 }
0188
0189 #endif