EGIsoEleObj

EGIsoObj

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
#ifndef DataFormats_L1TParticleFlow_egamma_h
#define DataFormats_L1TParticleFlow_egamma_h

#include "DataFormats/L1TParticleFlow/interface/datatypes.h"
#include "DataFormats/L1TParticleFlow/interface/gt_datatypes.h"
#include "DataFormats/L1TParticleFlow/interface/bit_encoding.h"

namespace l1ct {

  struct EGIsoObj {
    pt_t hwPt;
    glbeta_t hwEta;  // at calo face
    glbphi_t hwPhi;
    egquality_t hwQual;
    iso_t hwIso;

    int intPt() const { return Scales::intPt(hwPt); }
    int intEta() const { return hwEta.to_int(); }
    int intPhi() const { return hwPhi.to_int(); }
    int intQual() const { return hwQual.to_int(); }
    int intIso() const { return hwIso.to_int(); }

    float floatPt() const { return Scales::floatPt(hwPt); }
    float floatEta() const { return Scales::floatEta(hwEta); }
    float floatPhi() const { return Scales::floatPhi(hwPhi); }
    float floatIso() const { return Scales::floatIso(hwIso); }

    inline bool operator==(const EGIsoObj &other) const {
      return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwQual == other.hwQual &&
             hwIso == other.hwIso;
    }

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

    inline void clear() {
      hwPt = 0;
      hwEta = 0;
      hwPhi = 0;
      hwQual = 0;
      hwIso = 0;
    }

    static const int BITWIDTH = pt_t::width + glbeta_t::width + glbphi_t::width + egquality_t::width + iso_t::width;
    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, hwQual);
      pack_into_bits(ret, start, hwIso);
      return ret;
    }
    inline static EGIsoObj unpack(const ap_uint<BITWIDTH> &src) {
      EGIsoObj ret;
      ret.initFromBits(src);
      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, hwQual);
      unpack_from_bits(src, start, hwIso);
    }

    l1gt::Photon toGT() const {
      l1gt::Photon pho;
      pho.valid = hwPt != 0;
      pho.v3.pt = CTtoGT_pt(hwPt);
      pho.v3.phi = CTtoGT_phi(hwPhi);
      pho.v3.eta = CTtoGT_eta(hwEta);
      pho.qualityFlags = hwQual;
      pho.isolationPT = hwIso;
      return pho;
    }
  };

  inline void clear(EGIsoObj &c) { c.clear(); }

  struct EGIsoEleObj : public EGIsoObj {
    // WARNING: for whatever reason, maybe connected with datamember alignment,
    //          in 2019.2 synthesis fails if DEta & DPhi are put before Z0 & Dxy
    z0_t hwZ0;
    tkdeta_t hwDEta;
    tkdphi_t hwDPhi;
    id_score_t hwIDScore;
    bool hwCharge;

    glbphi_t hwVtxPhi() const { return hwCharge ? hwPhi + hwDPhi : hwPhi - hwDPhi; }
    glbeta_t hwVtxEta() const { return hwEta + hwDEta; }

    inline bool operator==(const EGIsoEleObj &other) const {
      return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwQual == other.hwQual &&
             hwIso == other.hwIso && hwDEta == other.hwDEta && hwDPhi == other.hwDPhi && hwZ0 == other.hwZ0 &&
             hwIDScore == other.hwIDScore && hwCharge == other.hwCharge;
    }

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

    inline void clear() {
      hwPt = 0;
      hwEta = 0;
      hwPhi = 0;
      hwQual = 0;
      hwIso = 0;
      hwDEta = 0;
      hwDPhi = 0;
      hwZ0 = 0;
      hwIDScore = 0;
      hwCharge = false;
    }

    int intCharge() const { return hwCharge ? +1 : -1; }
    float floatDEta() const { return Scales::floatEta(hwDEta); }
    float floatDPhi() const { return Scales::floatPhi(hwDPhi); }
    float floatVtxEta() const { return Scales::floatEta(hwVtxEta()); }
    float floatVtxPhi() const { return Scales::floatPhi(hwVtxPhi()); }
    float floatZ0() const { return Scales::floatZ0(hwZ0); }
    float floatIDScore() const { return Scales::floatIDScore(hwIDScore); }

    static const int BITWIDTH =
        EGIsoObj::BITWIDTH + tkdeta_t::width + tkdphi_t::width + z0_t::width + id_score_t::width + 1;
    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, hwQual);
      pack_into_bits(ret, start, hwIso);
      pack_into_bits(ret, start, hwDEta);
      pack_into_bits(ret, start, hwDPhi);
      pack_into_bits(ret, start, hwZ0);
      pack_bool_into_bits(ret, start, hwCharge);
      pack_into_bits(ret, start, hwIDScore);
      return ret;
    }
    inline static EGIsoEleObj unpack(const ap_uint<BITWIDTH> &src) {
      EGIsoEleObj ret;
      ret.initFromBits(src);
      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, hwQual);
      unpack_from_bits(src, start, hwIso);
      unpack_from_bits(src, start, hwDEta);
      unpack_from_bits(src, start, hwDPhi);
      unpack_from_bits(src, start, hwZ0);
      unpack_bool_from_bits(src, start, hwCharge);
      unpack_from_bits(src, start, hwIDScore);
    }

    l1gt::Electron toGT() const {
      l1gt::Electron ele;
      ele.valid = hwPt != 0;
      ele.v3.pt = CTtoGT_pt(hwPt);
      ele.v3.phi = CTtoGT_phi(hwVtxPhi());
      ele.v3.eta = CTtoGT_eta(hwVtxEta());
      ele.qualityFlags = hwQual;
      // NOTE: GT:  0 = positive, 1 = negative, CT: 0 = negative, 1 = positive
      ele.charge = (!hwCharge) & ele.valid;
      ele.z0(l1ct::z0_t::width - 1, 0) = hwZ0(l1ct::z0_t::width - 1, 0);
      ele.isolationPT = hwIso;
      return ele;
    }
  };

  inline void clear(EGIsoEleObj &c) { c.clear(); }
}  // namespace l1ct
#endif