Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:36

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;  // wider range to support global coordinates
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       puppiWgt_t ret;
0078       ret(puppiWgt_t::width - 1, 0) = hwData(BITS_PUPPIW_START + puppiWgt_t::width - 1, BITS_PUPPIW_START);
0079       return ret;
0080     }
0081 
0082     inline void setHwPuppiW(puppiWgt_t w) {
0083 #ifndef __SYNTHESIS__
0084       assert(hwId.neutral());
0085 #endif
0086       hwData(BITS_PUPPIW_START + puppiWgt_t::width - 1, BITS_PUPPIW_START) = w(puppiWgt_t::width - 1, 0);
0087     }
0088 
0089     inline emid_t hwEmID() const {
0090 #ifndef __SYNTHESIS__
0091       assert(hwId.neutral());
0092 #endif
0093       return emid_t(hwData(BITS_EMID_START + emid_t::width - 1, BITS_EMID_START));
0094     }
0095 
0096     inline void setHwEmID(emid_t w) {
0097 #ifndef __SYNTHESIS__
0098       assert(hwId.neutral());
0099 #endif
0100       hwData(BITS_EMID_START + emid_t::width - 1, BITS_EMID_START) = w(emid_t::width - 1, 0);
0101     }
0102 
0103     inline bool operator==(const PuppiObj &other) const {
0104       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwId == other.hwId &&
0105              hwData == other.hwData;
0106     }
0107 
0108     inline bool operator>(const PuppiObj &other) const { return hwPt > other.hwPt; }
0109     inline bool operator<(const PuppiObj &other) const { return hwPt < other.hwPt; }
0110 
0111     inline void clear() {
0112       hwPt = 0;
0113       hwEta = 0;
0114       hwPhi = 0;
0115       hwId.clear();
0116       hwData = 0;
0117     }
0118 
0119     inline void fill(const PFRegion &region, const PFChargedObj &src) {
0120       hwEta = region.hwGlbEta(src.hwVtxEta());
0121       hwPhi = region.hwGlbPhi(src.hwVtxPhi());
0122       hwId = src.hwId;
0123       hwPt = src.hwPt;
0124       hwData = 0;
0125       setHwZ0(src.hwZ0);
0126       setHwDxy(src.hwDxy);
0127       setHwTkQuality(src.hwTkQuality);
0128     }
0129     inline void fill(const PFRegion &region, const PFNeutralObj &src, pt_t puppiPt, puppiWgt_t puppiWgt) {
0130       hwEta = region.hwGlbEta(src.hwEta);
0131       hwPhi = region.hwGlbPhi(src.hwPhi);
0132       hwId = src.hwId;
0133       hwPt = puppiPt;
0134       hwData = 0;
0135       setHwPuppiW(puppiWgt);
0136       setHwEmID(src.hwEmID);
0137     }
0138     inline void fill(const PFRegion &region, const HadCaloObj &src, pt_t puppiPt, puppiWgt_t puppiWgt) {
0139       hwEta = region.hwGlbEta(src.hwEta);
0140       hwPhi = region.hwGlbPhi(src.hwPhi);
0141       hwId = src.hwIsEM() ? ParticleID::PHOTON : ParticleID::HADZERO;
0142       hwPt = puppiPt;
0143       hwData = 0;
0144       setHwPuppiW(puppiWgt);
0145       setHwEmID(src.hwEmID);
0146     }
0147 
0148     int intPt() const { return Scales::intPt(hwPt); }
0149     int intEta() const { return hwEta.to_int(); }
0150     int intPhi() const { return hwPhi.to_int(); }
0151     float floatPt() const { return Scales::floatPt(hwPt); }
0152     float floatEta() const { return Scales::floatEta(hwEta); }
0153     float floatPhi() const { return Scales::floatPhi(hwPhi); }
0154     int intId() const { return hwId.rawId(); }
0155     int pdgId() const { return hwId.pdgId(); }
0156     int oldId() const { return hwPt > 0 ? hwId.oldId() : 0; }
0157     int intCharge() const { return hwId.intCharge(); }
0158     float floatZ0() const { return Scales::floatZ0(hwZ0()); }
0159     float floatDxy() const { return Scales::floatDxy(hwDxy()); }
0160     float floatPuppiW() const { return hwId.neutral() ? Scales::floatPuppiW(hwPuppiW()) : 1.0f; }
0161 
0162     static const int BITWIDTH = pt_t::width + glbeta_t::width + glbphi_t::width + 3 + DATA_BITS_TOTAL;
0163     inline ap_uint<BITWIDTH> pack() const {
0164       ap_uint<BITWIDTH> ret;
0165       unsigned int start = 0;
0166       pack_into_bits(ret, start, hwPt);
0167       pack_into_bits(ret, start, hwEta);
0168       pack_into_bits(ret, start, hwPhi);
0169       pack_into_bits(ret, start, hwId.bits);
0170       pack_into_bits(ret, start, hwData);
0171       return ret;
0172     }
0173     inline void initFromBits(const ap_uint<BITWIDTH> &src) {
0174       unsigned int start = 0;
0175       unpack_from_bits(src, start, hwPt);
0176       unpack_from_bits(src, start, hwEta);
0177       unpack_from_bits(src, start, hwPhi);
0178       unpack_from_bits(src, start, hwId.bits);
0179       unpack_from_bits(src, start, hwData);
0180     }
0181     inline static PuppiObj unpack(const ap_uint<BITWIDTH> &src) {
0182       PuppiObj ret;
0183       ret.initFromBits(src);
0184       return ret;
0185     }
0186   };
0187   inline void clear(PuppiObj &c) { c.clear(); }
0188 
0189 }  // namespace l1ct
0190 
0191 #endif