File indexing completed on 2024-04-06 12:04:35
0001 #ifndef DataFormats_L1TParticleFlow_egamma_h
0002 #define DataFormats_L1TParticleFlow_egamma_h
0003
0004 #include "DataFormats/L1TParticleFlow/interface/datatypes.h"
0005 #include "DataFormats/L1TParticleFlow/interface/gt_datatypes.h"
0006 #include "DataFormats/L1TParticleFlow/interface/bit_encoding.h"
0007
0008 namespace l1ct {
0009
0010 struct EGIsoObj {
0011 pt_t hwPt;
0012 glbeta_t hwEta;
0013 glbphi_t hwPhi;
0014 egquality_t hwQual;
0015 iso_t hwIso;
0016
0017 int intPt() const { return Scales::intPt(hwPt); }
0018 int intEta() const { return hwEta.to_int(); }
0019 int intPhi() const { return hwPhi.to_int(); }
0020 int intQual() const { return hwQual.to_int(); }
0021 int intIso() const { return hwIso.to_int(); }
0022
0023 float floatPt() const { return Scales::floatPt(hwPt); }
0024 float floatEta() const { return Scales::floatEta(hwEta); }
0025 float floatPhi() const { return Scales::floatPhi(hwPhi); }
0026 float floatIso() const { return Scales::floatIso(hwIso); }
0027
0028 inline bool operator==(const EGIsoObj &other) const {
0029 return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwQual == other.hwQual &&
0030 hwIso == other.hwIso;
0031 }
0032
0033 inline bool operator>(const EGIsoObj &other) const { return hwPt > other.hwPt; }
0034 inline bool operator<(const EGIsoObj &other) const { return hwPt < other.hwPt; }
0035
0036 inline void clear() {
0037 hwPt = 0;
0038 hwEta = 0;
0039 hwPhi = 0;
0040 hwQual = 0;
0041 hwIso = 0;
0042 }
0043
0044 static const int BITWIDTH = pt_t::width + glbeta_t::width + glbphi_t::width + egquality_t::width + iso_t::width;
0045 inline ap_uint<BITWIDTH> pack() const {
0046 ap_uint<BITWIDTH> ret;
0047 unsigned int start = 0;
0048 pack_into_bits(ret, start, hwPt);
0049 pack_into_bits(ret, start, hwEta);
0050 pack_into_bits(ret, start, hwPhi);
0051 pack_into_bits(ret, start, hwQual);
0052 pack_into_bits(ret, start, hwIso);
0053 return ret;
0054 }
0055 inline static EGIsoObj unpack(const ap_uint<BITWIDTH> &src) {
0056 EGIsoObj ret;
0057 ret.initFromBits(src);
0058 return ret;
0059 }
0060
0061 inline void initFromBits(const ap_uint<BITWIDTH> &src) {
0062 unsigned int start = 0;
0063 unpack_from_bits(src, start, hwPt);
0064 unpack_from_bits(src, start, hwEta);
0065 unpack_from_bits(src, start, hwPhi);
0066 unpack_from_bits(src, start, hwQual);
0067 unpack_from_bits(src, start, hwIso);
0068 }
0069
0070 l1gt::Photon toGT() const {
0071 l1gt::Photon pho;
0072 pho.valid = hwPt != 0;
0073 pho.v3.pt = CTtoGT_pt(hwPt);
0074 pho.v3.phi = CTtoGT_phi(hwPhi);
0075 pho.v3.eta = CTtoGT_eta(hwEta);
0076 pho.qualityFlags = hwQual;
0077 pho.isolationPT = hwIso;
0078 return pho;
0079 }
0080 };
0081
0082 inline void clear(EGIsoObj &c) { c.clear(); }
0083
0084 struct EGIsoEleObj : public EGIsoObj {
0085
0086
0087 z0_t hwZ0;
0088 tkdeta_t hwDEta;
0089 tkdphi_t hwDPhi;
0090 id_score_t hwIDScore;
0091 bool hwCharge;
0092
0093 glbphi_t hwVtxPhi() const { return hwCharge ? hwPhi + hwDPhi : hwPhi - hwDPhi; }
0094 glbeta_t hwVtxEta() const { return hwEta + hwDEta; }
0095
0096 inline bool operator==(const EGIsoEleObj &other) const {
0097 return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwQual == other.hwQual &&
0098 hwIso == other.hwIso && hwDEta == other.hwDEta && hwDPhi == other.hwDPhi && hwZ0 == other.hwZ0 &&
0099 hwIDScore == other.hwIDScore && hwCharge == other.hwCharge;
0100 }
0101
0102 inline bool operator>(const EGIsoEleObj &other) const { return hwPt > other.hwPt; }
0103 inline bool operator<(const EGIsoEleObj &other) const { return hwPt < other.hwPt; }
0104
0105 inline void clear() {
0106 hwPt = 0;
0107 hwEta = 0;
0108 hwPhi = 0;
0109 hwQual = 0;
0110 hwIso = 0;
0111 hwDEta = 0;
0112 hwDPhi = 0;
0113 hwZ0 = 0;
0114 hwIDScore = 0;
0115 hwCharge = false;
0116 }
0117
0118 int intCharge() const { return hwCharge ? +1 : -1; }
0119 float floatDEta() const { return Scales::floatEta(hwDEta); }
0120 float floatDPhi() const { return Scales::floatPhi(hwDPhi); }
0121 float floatVtxEta() const { return Scales::floatEta(hwVtxEta()); }
0122 float floatVtxPhi() const { return Scales::floatPhi(hwVtxPhi()); }
0123 float floatZ0() const { return Scales::floatZ0(hwZ0); }
0124 float floatIDScore() const { return Scales::floatIDScore(hwIDScore); }
0125
0126 static const int BITWIDTH =
0127 EGIsoObj::BITWIDTH + tkdeta_t::width + tkdphi_t::width + z0_t::width + id_score_t::width + 1;
0128 inline ap_uint<BITWIDTH> pack() const {
0129 ap_uint<BITWIDTH> ret;
0130 unsigned int start = 0;
0131 pack_into_bits(ret, start, hwPt);
0132 pack_into_bits(ret, start, hwEta);
0133 pack_into_bits(ret, start, hwPhi);
0134 pack_into_bits(ret, start, hwQual);
0135 pack_into_bits(ret, start, hwIso);
0136 pack_into_bits(ret, start, hwDEta);
0137 pack_into_bits(ret, start, hwDPhi);
0138 pack_into_bits(ret, start, hwZ0);
0139 pack_bool_into_bits(ret, start, hwCharge);
0140 pack_into_bits(ret, start, hwIDScore);
0141 return ret;
0142 }
0143 inline static EGIsoEleObj unpack(const ap_uint<BITWIDTH> &src) {
0144 EGIsoEleObj ret;
0145 ret.initFromBits(src);
0146 return ret;
0147 }
0148
0149 inline void initFromBits(const ap_uint<BITWIDTH> &src) {
0150 unsigned int start = 0;
0151 unpack_from_bits(src, start, hwPt);
0152 unpack_from_bits(src, start, hwEta);
0153 unpack_from_bits(src, start, hwPhi);
0154 unpack_from_bits(src, start, hwQual);
0155 unpack_from_bits(src, start, hwIso);
0156 unpack_from_bits(src, start, hwDEta);
0157 unpack_from_bits(src, start, hwDPhi);
0158 unpack_from_bits(src, start, hwZ0);
0159 unpack_bool_from_bits(src, start, hwCharge);
0160 unpack_from_bits(src, start, hwIDScore);
0161 }
0162
0163 l1gt::Electron toGT() const {
0164 l1gt::Electron ele;
0165 ele.valid = hwPt != 0;
0166 ele.v3.pt = CTtoGT_pt(hwPt);
0167 ele.v3.phi = CTtoGT_phi(hwVtxPhi());
0168 ele.v3.eta = CTtoGT_eta(hwVtxEta());
0169 ele.qualityFlags = hwQual;
0170
0171 ele.charge = (!hwCharge) & ele.valid;
0172 ele.z0(l1ct::z0_t::width - 1, 0) = hwZ0(l1ct::z0_t::width - 1, 0);
0173 ele.isolationPT = hwIso;
0174 return ele;
0175 }
0176 };
0177
0178 inline void clear(EGIsoEleObj &c) { c.clear(); }
0179 }
0180 #endif