Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DataFormats_L1TParticleFlow_layer1_objs_h
0002 #define DataFormats_L1TParticleFlow_layer1_objs_h
0003 
0004 #include "DataFormats/L1TParticleFlow/interface/datatypes.h"
0005 #include "DataFormats/L1TParticleFlow/interface/bit_encoding.h"
0006 
0007 namespace l1ct {
0008 
0009   struct HadCaloObj {
0010     pt_t hwPt;
0011     eta_t hwEta;  // relative to the region center, at calo
0012     phi_t hwPhi;  // relative to the region center, at calo
0013     pt_t hwEmPt;
0014     emid_t hwEmID;
0015 
0016     inline bool operator==(const HadCaloObj &other) const {
0017       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwEmPt == other.hwEmPt &&
0018              hwEmID == other.hwEmID;
0019     }
0020 
0021     inline bool operator>(const HadCaloObj &other) const { return hwPt > other.hwPt; }
0022     inline bool operator<(const HadCaloObj &other) const { return hwPt < other.hwPt; }
0023 
0024     inline void clear() {
0025       hwPt = 0;
0026       hwEta = 0;
0027       hwPhi = 0;
0028       hwEmPt = 0;
0029       hwEmID = 0;
0030     }
0031 
0032     int intPt() const { return Scales::intPt(hwPt); }
0033     int intEmPt() const { return Scales::intPt(hwEmPt); }
0034     int intEta() const { return hwEta.to_int(); }
0035     int intPhi() const { return hwPhi.to_int(); }
0036     float floatPt() const { return Scales::floatPt(hwPt); }
0037     float floatEmPt() const { return Scales::floatPt(hwEmPt); }
0038     float floatEta() const { return Scales::floatEta(hwEta); }
0039     float floatPhi() const { return Scales::floatPhi(hwPhi); }
0040 
0041     bool hwIsEM() const { return hwEmID != 0; }
0042 
0043     static const int BITWIDTH = pt_t::width + eta_t::width + phi_t::width + pt_t::width + emid_t::width;
0044     inline ap_uint<BITWIDTH> pack() const {
0045       ap_uint<BITWIDTH> ret;
0046       unsigned int start = 0;
0047       pack_into_bits(ret, start, hwPt);
0048       pack_into_bits(ret, start, hwEta);
0049       pack_into_bits(ret, start, hwPhi);
0050       pack_into_bits(ret, start, hwEmPt);
0051       pack_into_bits(ret, start, hwEmID);
0052       return ret;
0053     }
0054     inline static HadCaloObj unpack(const ap_uint<BITWIDTH> &src) {
0055       HadCaloObj ret;
0056       unsigned int start = 0;
0057       unpack_from_bits(src, start, ret.hwPt);
0058       unpack_from_bits(src, start, ret.hwEta);
0059       unpack_from_bits(src, start, ret.hwPhi);
0060       unpack_from_bits(src, start, ret.hwEmPt);
0061       unpack_from_bits(src, start, ret.hwEmID);
0062       return ret;
0063     }
0064   };
0065 
0066   inline void clear(HadCaloObj &c) { c.clear(); }
0067 
0068   struct EmCaloObj {
0069     pt_t hwPt, hwPtErr;
0070     eta_t hwEta;  // relative to the region center, at calo
0071     phi_t hwPhi;  // relative to the region center, at calo
0072     emid_t hwEmID;
0073 
0074     inline bool operator==(const EmCaloObj &other) const {
0075       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwPtErr == other.hwPtErr &&
0076              hwEmID == other.hwEmID;
0077     }
0078 
0079     inline bool operator>(const EmCaloObj &other) const { return hwPt > other.hwPt; }
0080     inline bool operator<(const EmCaloObj &other) const { return hwPt < other.hwPt; }
0081 
0082     inline void clear() {
0083       hwPt = 0;
0084       hwPtErr = 0;
0085       hwEta = 0;
0086       hwPhi = 0;
0087       hwEmID = 0;
0088     }
0089 
0090     int intPt() const { return Scales::intPt(hwPt); }
0091     int intPtErr() const { return Scales::intPt(hwPtErr); }
0092     int intEta() const { return hwEta.to_int(); }
0093     int intPhi() const { return hwPhi.to_int(); }
0094     float floatPt() const { return Scales::floatPt(hwPt); }
0095     float floatPtErr() const { return Scales::floatPt(hwPtErr); }
0096     float floatEta() const { return Scales::floatEta(hwEta); }
0097     float floatPhi() const { return Scales::floatPhi(hwPhi); }
0098 
0099     static const int BITWIDTH = pt_t::width + eta_t::width + phi_t::width + pt_t::width + emid_t::width;
0100     inline ap_uint<BITWIDTH> pack() const {
0101       ap_uint<BITWIDTH> ret;
0102       unsigned int start = 0;
0103       pack_into_bits(ret, start, hwPt);
0104       pack_into_bits(ret, start, hwEta);
0105       pack_into_bits(ret, start, hwPhi);
0106       pack_into_bits(ret, start, hwPtErr);
0107       pack_into_bits(ret, start, hwEmID);
0108       return ret;
0109     }
0110     inline static EmCaloObj unpack(const ap_uint<BITWIDTH> &src) {
0111       EmCaloObj ret;
0112       unsigned int start = 0;
0113       unpack_from_bits(src, start, ret.hwPt);
0114       unpack_from_bits(src, start, ret.hwEta);
0115       unpack_from_bits(src, start, ret.hwPhi);
0116       unpack_from_bits(src, start, ret.hwPtErr);
0117       unpack_from_bits(src, start, ret.hwEmID);
0118       return ret;
0119     }
0120   };
0121   inline void clear(EmCaloObj &c) { c.clear(); }
0122 
0123   struct TkObj {
0124     pt_t hwPt;
0125     eta_t hwEta;      // relative to the region center, at calo
0126     phi_t hwPhi;      // relative to the region center, at calo
0127     tkdeta_t hwDEta;  //  vtx - calo
0128     tkdphi_t hwDPhi;  // |vtx - calo| (sign is derived by the charge)
0129     bool hwCharge;    // 1 = positive, 0 = negative
0130     z0_t hwZ0;
0131     dxy_t hwDxy;
0132     tkquality_t hwQuality;
0133 
0134     enum TkQuality { PFLOOSE = 1, PFTIGHT = 2 };
0135     bool isPFLoose() const { return hwQuality[0]; }
0136     bool isPFTight() const { return hwQuality[1]; }
0137     phi_t hwVtxPhi() const { return hwCharge ? hwPhi + hwDPhi : hwPhi - hwDPhi; }
0138     eta_t hwVtxEta() const { return hwEta + hwDEta; }
0139 
0140     inline bool operator==(const TkObj &other) const {
0141       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwDEta == other.hwDEta &&
0142              hwDPhi == other.hwDPhi && hwZ0 == other.hwZ0 && hwDxy == other.hwDxy && hwCharge == other.hwCharge &&
0143              hwQuality == other.hwQuality;
0144     }
0145 
0146     inline bool operator>(const TkObj &other) const { return hwPt > other.hwPt; }
0147     inline bool operator<(const TkObj &other) const { return hwPt < other.hwPt; }
0148 
0149     inline void clear() {
0150       hwPt = 0;
0151       hwEta = 0;
0152       hwPhi = 0;
0153       hwDEta = 0;
0154       hwDPhi = 0;
0155       hwZ0 = 0;
0156       hwDxy = 0;
0157       hwCharge = false;
0158       hwQuality = 0;
0159     }
0160 
0161     int intPt() const { return Scales::intPt(hwPt); }
0162     int intEta() const { return hwEta.to_int(); }
0163     int intPhi() const { return hwPhi.to_int(); }
0164     int intVtxEta() const { return hwVtxEta().to_int(); }
0165     int intVtxPhi() const { return hwVtxPhi().to_int(); }
0166     int intCharge() const { return hwCharge ? +1 : -1; }
0167     float floatPt() const { return Scales::floatPt(hwPt); }
0168     float floatEta() const { return Scales::floatEta(hwEta); }
0169     float floatPhi() const { return Scales::floatPhi(hwPhi); }
0170     float floatDEta() const { return Scales::floatEta(hwDEta); }
0171     float floatDPhi() const { return Scales::floatPhi(hwDPhi); }
0172     float floatVtxEta() const { return Scales::floatEta(hwVtxEta()); }
0173     float floatVtxPhi() const { return Scales::floatPhi(hwVtxPhi()); }
0174     float floatZ0() const { return Scales::floatZ0(hwZ0); }
0175     float floatDxy() const { return Scales::floatDxy(hwDxy); }
0176 
0177     static const int BITWIDTH = pt_t::width + eta_t::width + phi_t::width + tkdeta_t::width + tkdphi_t::width + 1 +
0178                                 z0_t::width + dxy_t::width + tkquality_t::width;
0179     inline ap_uint<BITWIDTH> pack() const {
0180       ap_uint<BITWIDTH> ret;
0181       unsigned int start = 0;
0182       pack_into_bits(ret, start, hwPt);
0183       pack_into_bits(ret, start, hwEta);
0184       pack_into_bits(ret, start, hwPhi);
0185       pack_into_bits(ret, start, hwDEta);
0186       pack_into_bits(ret, start, hwDPhi);
0187       pack_bool_into_bits(ret, start, hwCharge);
0188       pack_into_bits(ret, start, hwZ0);
0189       pack_into_bits(ret, start, hwDxy);
0190       pack_into_bits(ret, start, hwQuality);
0191       return ret;
0192     }
0193     inline static TkObj unpack(const ap_uint<BITWIDTH> &src) {
0194       TkObj ret;
0195       unsigned int start = 0;
0196       unpack_from_bits(src, start, ret.hwPt);
0197       unpack_from_bits(src, start, ret.hwEta);
0198       unpack_from_bits(src, start, ret.hwPhi);
0199       unpack_from_bits(src, start, ret.hwDEta);
0200       unpack_from_bits(src, start, ret.hwDPhi);
0201       unpack_bool_from_bits(src, start, ret.hwCharge);
0202       unpack_from_bits(src, start, ret.hwZ0);
0203       unpack_from_bits(src, start, ret.hwDxy);
0204       unpack_from_bits(src, start, ret.hwQuality);
0205       return ret;
0206     }
0207   };
0208   inline void clear(TkObj &c) { c.clear(); }
0209 
0210   struct MuObj {
0211     pt_t hwPt;
0212     glbeta_t hwEta;   // relative to the region center, at calo
0213     glbphi_t hwPhi;   // relative to the region center, at calo
0214     tkdeta_t hwDEta;  //  vtx - calo
0215     tkdphi_t hwDPhi;  // |vtx - calo| (sign is derived by the charge)
0216     bool hwCharge;    // 1 = positive, 0 = negative
0217     z0_t hwZ0;
0218     dxy_t hwDxy;
0219     ap_uint<3> hwQuality;
0220     glbphi_t hwVtxPhi() const { return hwCharge ? hwPhi + hwDPhi : hwPhi - hwDPhi; }
0221     glbeta_t hwVtxEta() const { return hwEta + hwDEta; }
0222 
0223     inline bool operator==(const MuObj &other) const {
0224       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwDEta == other.hwDEta &&
0225              hwDPhi == other.hwDPhi && hwZ0 == other.hwZ0 && hwDxy == other.hwDxy && hwCharge == other.hwCharge &&
0226              hwQuality == other.hwQuality;
0227     }
0228 
0229     inline bool operator>(const MuObj &other) const { return hwPt > other.hwPt; }
0230     inline bool operator<(const MuObj &other) const { return hwPt < other.hwPt; }
0231 
0232     inline void clear() {
0233       hwPt = 0;
0234       hwEta = 0;
0235       hwPhi = 0;
0236       hwDEta = 0;
0237       hwDPhi = 0;
0238       hwZ0 = 0;
0239       hwDxy = 0;
0240       hwCharge = false;
0241       hwQuality = 0;
0242     }
0243 
0244     int intPt() const { return Scales::intPt(hwPt); }
0245     int intEta() const { return hwEta.to_int(); }
0246     int intPhi() const { return hwPhi.to_int(); }
0247     int intVtxEta() const { return hwVtxEta().to_int(); }
0248     int intVtxPhi() const { return hwVtxPhi().to_int(); }
0249     int intCharge() const { return hwCharge ? +1 : -1; }
0250     float floatPt() const { return Scales::floatPt(hwPt); }
0251     float floatEta() const { return Scales::floatEta(hwEta); }
0252     float floatPhi() const { return Scales::floatPhi(hwPhi); }
0253     float floatDEta() const { return Scales::floatEta(hwDEta); }
0254     float floatDPhi() const { return Scales::floatPhi(hwDPhi); }
0255     float floatVtxEta() const { return Scales::floatEta(hwVtxEta()); }
0256     float floatVtxPhi() const { return Scales::floatPhi(hwVtxPhi()); }
0257     float floatZ0() const { return Scales::floatZ0(hwZ0); }
0258     float floatDxy() const { return Scales::floatDxy(hwDxy); }
0259 
0260     static const int BITWIDTH = pt_t::width + glbeta_t::width + glbphi_t::width + tkdeta_t::width + tkdphi_t::width +
0261                                 1 + z0_t::width + dxy_t::width + ap_uint<3>::width;
0262     inline ap_uint<BITWIDTH> pack() const {
0263       ap_uint<BITWIDTH> ret;
0264       unsigned int start = 0;
0265       pack_into_bits(ret, start, hwPt);
0266       pack_into_bits(ret, start, hwEta);
0267       pack_into_bits(ret, start, hwPhi);
0268       pack_into_bits(ret, start, hwDEta);
0269       pack_into_bits(ret, start, hwDPhi);
0270       pack_bool_into_bits(ret, start, hwCharge);
0271       pack_into_bits(ret, start, hwZ0);
0272       pack_into_bits(ret, start, hwDxy);
0273       pack_into_bits(ret, start, hwQuality);
0274       return ret;
0275     }
0276     inline static MuObj unpack(const ap_uint<BITWIDTH> &src) {
0277       MuObj ret;
0278       unsigned int start = 0;
0279       unpack_from_bits(src, start, ret.hwPt);
0280       unpack_from_bits(src, start, ret.hwEta);
0281       unpack_from_bits(src, start, ret.hwPhi);
0282       unpack_from_bits(src, start, ret.hwDEta);
0283       unpack_from_bits(src, start, ret.hwDPhi);
0284       unpack_bool_from_bits(src, start, ret.hwCharge);
0285       unpack_from_bits(src, start, ret.hwZ0);
0286       unpack_from_bits(src, start, ret.hwDxy);
0287       unpack_from_bits(src, start, ret.hwQuality);
0288       return ret;
0289     }
0290   };
0291   inline void clear(MuObj &c) { c.clear(); }
0292 
0293   struct PVObj {
0294     z0_t hwZ0;
0295 
0296     inline bool operator==(const PVObj &other) const { return hwZ0 == other.hwZ0; }
0297 
0298     inline void clear() { hwZ0 = 0; }
0299 
0300     float floatZ0() const { return Scales::floatZ0(hwZ0); }
0301 
0302     static const int BITWIDTH = z0_t::width;
0303     inline ap_uint<BITWIDTH> pack() const {
0304       ap_uint<BITWIDTH> ret;
0305       unsigned int start = 0;
0306       pack_into_bits(ret, start, hwZ0);
0307       return ret;
0308     }
0309     inline static PVObj unpack(const ap_uint<BITWIDTH> &src) {
0310       PVObj ret;
0311       unsigned int start = 0;
0312       unpack_from_bits(src, start, ret.hwZ0);
0313       return ret;
0314     }
0315   };
0316   inline void clear(PVObj &c) { c.clear(); }
0317 
0318 }  // namespace l1ct
0319 
0320 #endif