Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-10 01:50:14

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;  // at calo face
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.quality = hwQual;
0077       pho.isolation = hwIso;
0078       return pho;
0079     }
0080   };
0081 
0082   inline void clear(EGIsoObj &c) { c.clear(); }
0083 
0084   struct EGIsoEleObj : public EGIsoObj {
0085     // WARNING: for whatever reason, maybe connected with datamember alignment,
0086     //          in 2019.2 synthesis fails if DEta & DPhi are put before Z0 & Dxy
0087     z0_t hwZ0;
0088     tkdeta_t hwDEta;  // relative to the region center, at calo
0089     tkdphi_t hwDPhi;  // relative to the region center, at calo
0090     bool hwCharge;
0091 
0092     phi_t hwVtxPhi() const { return hwCharge ? hwPhi + hwDPhi : hwPhi - hwDPhi; }
0093     eta_t hwVtxEta() const { return hwEta + hwDEta; }
0094 
0095     inline bool operator==(const EGIsoEleObj &other) const {
0096       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwQual == other.hwQual &&
0097              hwIso == other.hwIso && hwDEta == other.hwDEta && hwDPhi == other.hwDPhi && hwZ0 == other.hwZ0 &&
0098              hwCharge == other.hwCharge;
0099     }
0100 
0101     inline bool operator>(const EGIsoEleObj &other) const { return hwPt > other.hwPt; }
0102     inline bool operator<(const EGIsoEleObj &other) const { return hwPt < other.hwPt; }
0103 
0104     inline void clear() {
0105       hwPt = 0;
0106       hwEta = 0;
0107       hwPhi = 0;
0108       hwQual = 0;
0109       hwIso = 0;
0110       hwDEta = 0;
0111       hwDPhi = 0;
0112       hwZ0 = 0;
0113       hwCharge = false;
0114     }
0115 
0116     int intCharge() const { return hwCharge ? +1 : -1; }
0117     float floatDEta() const { return Scales::floatEta(hwDEta); }
0118     float floatDPhi() const { return Scales::floatPhi(hwDPhi); }
0119     float floatVtxEta() const { return Scales::floatEta(hwVtxEta()); }
0120     float floatVtxPhi() const { return Scales::floatPhi(hwVtxPhi()); }
0121     float floatZ0() const { return Scales::floatZ0(hwZ0); }
0122 
0123     static const int BITWIDTH = EGIsoObj::BITWIDTH + tkdeta_t::width + tkdphi_t::width + z0_t::width + 1;
0124     inline ap_uint<BITWIDTH> pack() const {
0125       ap_uint<BITWIDTH> ret;
0126       unsigned int start = 0;
0127       pack_into_bits(ret, start, hwPt);
0128       pack_into_bits(ret, start, hwEta);
0129       pack_into_bits(ret, start, hwPhi);
0130       pack_into_bits(ret, start, hwQual);
0131       pack_into_bits(ret, start, hwIso);
0132       pack_into_bits(ret, start, hwDEta);
0133       pack_into_bits(ret, start, hwDPhi);
0134       pack_into_bits(ret, start, hwZ0);
0135       pack_bool_into_bits(ret, start, hwCharge);
0136       return ret;
0137     }
0138     inline static EGIsoEleObj unpack(const ap_uint<BITWIDTH> &src) {
0139       EGIsoEleObj ret;
0140       ret.initFromBits(src);
0141       return ret;
0142     }
0143 
0144     inline void initFromBits(const ap_uint<BITWIDTH> &src) {
0145       unsigned int start = 0;
0146       unpack_from_bits(src, start, hwPt);
0147       unpack_from_bits(src, start, hwEta);
0148       unpack_from_bits(src, start, hwPhi);
0149       unpack_from_bits(src, start, hwQual);
0150       unpack_from_bits(src, start, hwIso);
0151       unpack_from_bits(src, start, hwDEta);
0152       unpack_from_bits(src, start, hwDPhi);
0153       unpack_from_bits(src, start, hwZ0);
0154       unpack_bool_from_bits(src, start, hwCharge);
0155     }
0156 
0157     l1gt::Electron toGT() const {
0158       l1gt::Electron ele;
0159       ele.valid = hwPt != 0;
0160       ele.v3.pt = CTtoGT_pt(hwPt);
0161       ele.v3.phi = CTtoGT_phi(hwPhi);
0162       ele.v3.eta = CTtoGT_eta(hwEta);
0163       ele.quality = hwQual;
0164       ele.charge = hwCharge;
0165       ele.z0 = hwZ0;
0166       ele.isolation = hwIso;
0167       return ele;
0168     }
0169   };
0170 
0171   inline void clear(EGIsoEleObj &c) { c.clear(); }
0172 }  // namespace l1ct
0173 #endif