PuppiObj

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
#ifndef DataFormats_L1TParticleFlow_puppi_h
#define DataFormats_L1TParticleFlow_puppi_h

#include "DataFormats/L1TParticleFlow/interface/datatypes.h"
#include "DataFormats/L1TParticleFlow/interface/bit_encoding.h"
#include "DataFormats/L1TParticleFlow/interface/layer1_objs.h"
#include "DataFormats/L1TParticleFlow/interface/pf.h"

namespace l1ct {

  struct PuppiObj {
    pt_t hwPt;
    glbeta_t hwEta;  // wider range to support global coordinates
    glbphi_t hwPhi;
    ParticleID hwId;

    static const int BITS_Z0_START = 0;
    static const int BITS_DXY_START = BITS_Z0_START + z0_t::width;
    static const int BITS_TKQUAL_START = BITS_DXY_START + dxy_t::width;
    static const int DATA_CHARGED_BITS_TOTAL = BITS_TKQUAL_START + tkquality_t::width;

    static const int BITS_PUPPIW_START = 0;
    static const int BITS_EMID_START = BITS_PUPPIW_START + puppiWgt_t::width;
    static const int DATA_NEUTRAL_BITS_TOTAL = BITS_EMID_START + emid_t::width;

    static const int DATA_BITS_TOTAL =
        DATA_CHARGED_BITS_TOTAL >= DATA_NEUTRAL_BITS_TOTAL ? DATA_CHARGED_BITS_TOTAL : DATA_NEUTRAL_BITS_TOTAL;

    ap_uint<DATA_BITS_TOTAL> hwData;

    inline z0_t hwZ0() const {
#ifndef __SYNTHESIS__
      assert(hwId.charged() || hwPt == 0);
#endif
      return z0_t(hwData(BITS_Z0_START + z0_t::width - 1, BITS_Z0_START));
    }

    inline void setHwZ0(z0_t z0) {
#ifndef __SYNTHESIS__
      assert(hwId.charged() || hwPt == 0);
#endif
      hwData(BITS_Z0_START + z0_t::width - 1, BITS_Z0_START) = z0(z0_t::width - 1, 0);
    }

    inline dxy_t hwDxy() const {
#ifndef __SYNTHESIS__
      assert(hwId.charged() || hwPt == 0);
#endif
      return dxy_t(hwData(BITS_DXY_START + dxy_t::width - 1, BITS_DXY_START));
    }

    inline void setHwDxy(dxy_t dxy) {
#ifndef __SYNTHESIS__
      assert(hwId.charged() || hwPt == 0);
#endif
      hwData(BITS_DXY_START + dxy_t::width - 1, BITS_DXY_START) = dxy(7, 0);
    }

    inline tkquality_t hwTkQuality() const {
#ifndef __SYNTHESIS__
      assert(hwId.charged() || hwPt == 0);
#endif
      return tkquality_t(hwData(BITS_TKQUAL_START + tkquality_t::width - 1, BITS_TKQUAL_START));
    }

    inline void setHwTkQuality(tkquality_t qual) {
#ifndef __SYNTHESIS__
      assert(hwId.charged() || hwPt == 0);
#endif
      hwData(BITS_TKQUAL_START + tkquality_t::width - 1, BITS_TKQUAL_START) = qual(tkquality_t::width - 1, 0);
    }

    inline puppiWgt_t hwPuppiW() const {
#ifndef __SYNTHESIS__
      assert(hwId.neutral());
#endif
      puppiWgt_t ret;
      ret(puppiWgt_t::width - 1, 0) = hwData(BITS_PUPPIW_START + puppiWgt_t::width - 1, BITS_PUPPIW_START);
      return ret;
    }

    inline void setHwPuppiW(puppiWgt_t w) {
#ifndef __SYNTHESIS__
      assert(hwId.neutral());
#endif
      hwData(BITS_PUPPIW_START + puppiWgt_t::width - 1, BITS_PUPPIW_START) = w(puppiWgt_t::width - 1, 0);
    }

    inline emid_t hwEmID() const {
#ifndef __SYNTHESIS__
      assert(hwId.neutral());
#endif
      return emid_t(hwData(BITS_EMID_START + emid_t::width - 1, BITS_EMID_START));
    }

    inline void setHwEmID(emid_t w) {
#ifndef __SYNTHESIS__
      assert(hwId.neutral());
#endif
      hwData(BITS_EMID_START + emid_t::width - 1, BITS_EMID_START) = w(emid_t::width - 1, 0);
    }

    inline bool operator==(const PuppiObj &other) const {
      return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwId == other.hwId &&
             hwData == other.hwData;
    }

    inline bool operator>(const PuppiObj &other) const { return hwPt > other.hwPt; }
    inline bool operator<(const PuppiObj &other) const { return hwPt < other.hwPt; }

    inline void clear() {
      hwPt = 0;
      hwEta = 0;
      hwPhi = 0;
      hwId.clear();
      hwData = 0;
    }

    inline void fill(const PFRegion &region, const PFChargedObj &src) {
      hwEta = region.hwGlbEta(src.hwVtxEta());
      hwPhi = region.hwGlbPhi(src.hwVtxPhi());
      hwId = src.hwId;
      hwPt = src.hwPt;
      hwData = 0;
      setHwZ0(src.hwZ0);
      setHwDxy(src.hwDxy);
      setHwTkQuality(src.hwTkQuality);
    }
    inline void fill(const PFRegion &region, const PFNeutralObj &src, pt_t puppiPt, puppiWgt_t puppiWgt) {
      hwEta = region.hwGlbEta(src.hwEta);
      hwPhi = region.hwGlbPhi(src.hwPhi);
      hwId = src.hwId;
      hwPt = puppiPt;
      hwData = 0;
      setHwPuppiW(puppiWgt);
      setHwEmID(src.hwEmID);
    }
    inline void fill(const PFRegion &region, const HadCaloObj &src, pt_t puppiPt, puppiWgt_t puppiWgt) {
      hwEta = region.hwGlbEta(src.hwEta);
      hwPhi = region.hwGlbPhi(src.hwPhi);
      hwId = src.hwIsEM() ? ParticleID::PHOTON : ParticleID::HADZERO;
      hwPt = puppiPt;
      hwData = 0;
      setHwPuppiW(puppiWgt);
      setHwEmID(src.hwEmID);
    }

    int intPt() const { return Scales::intPt(hwPt); }
    int intEta() const { return hwEta.to_int(); }
    int intPhi() const { return hwPhi.to_int(); }
    float floatPt() const { return Scales::floatPt(hwPt); }
    float floatEta() const { return Scales::floatEta(hwEta); }
    float floatPhi() const { return Scales::floatPhi(hwPhi); }
    int intId() const { return hwId.rawId(); }
    int pdgId() const { return hwId.pdgId(); }
    int oldId() const { return hwPt > 0 ? hwId.oldId() : 0; }
    int intCharge() const { return hwId.intCharge(); }
    float floatZ0() const { return Scales::floatZ0(hwZ0()); }
    float floatDxy() const { return Scales::floatDxy(hwDxy()); }
    float floatPuppiW() const { return hwId.neutral() ? Scales::floatPuppiW(hwPuppiW()) : 1.0f; }

    static const int BITWIDTH = pt_t::width + glbeta_t::width + glbphi_t::width + 3 + DATA_BITS_TOTAL;
    inline ap_uint<BITWIDTH> pack() const {
      ap_uint<BITWIDTH> ret;
      unsigned int start = 0;
      pack_into_bits(ret, start, hwPt);
      pack_into_bits(ret, start, hwEta);
      pack_into_bits(ret, start, hwPhi);
      pack_into_bits(ret, start, hwId.bits);
      pack_into_bits(ret, start, hwData);
      return ret;
    }
    inline void initFromBits(const ap_uint<BITWIDTH> &src) {
      unsigned int start = 0;
      unpack_from_bits(src, start, hwPt);
      unpack_from_bits(src, start, hwEta);
      unpack_from_bits(src, start, hwPhi);
      unpack_from_bits(src, start, hwId.bits);
      unpack_from_bits(src, start, hwData);
    }
    inline static PuppiObj unpack(const ap_uint<BITWIDTH> &src) {
      PuppiObj ret;
      ret.initFromBits(src);
      return ret;
    }
  };
  inline void clear(PuppiObj &c) { c.clear(); }

}  // namespace l1ct

#endif