Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:36

0001 #ifndef DataFormats_L1TParticleFlow_pf_h
0002 #define DataFormats_L1TParticleFlow_pf_h
0003 
0004 #include "DataFormats/L1TParticleFlow/interface/datatypes.h"
0005 #include "DataFormats/L1TParticleFlow/interface/bit_encoding.h"
0006 
0007 namespace l1ct {
0008 
0009   struct PFCommonObj {
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     ParticleID hwId;
0014 
0015     int intPt() const { return Scales::intPt(hwPt); }
0016     int intEta() const { return hwEta.to_int(); }
0017     int intPhi() const { return hwPhi.to_int(); }
0018     float floatPt() const { return Scales::floatPt(hwPt); }
0019     float floatEta() const { return Scales::floatEta(hwEta); }
0020     float floatPhi() const { return Scales::floatPhi(hwPhi); }
0021     int intId() const { return hwId.rawId(); }
0022     int oldId() const { return hwPt > 0 ? hwId.oldId() : 0; }
0023     int pdgId() const { return hwId.pdgId(); }
0024     int intCharge() const { return hwId.intCharge(); }
0025 
0026     static const int _PFCOMMON_BITWIDTH = pt_t::width + eta_t::width + phi_t::width + 3;
0027     template <typename U>
0028     inline void pack_common(U &out, unsigned int &start) const {
0029       pack_into_bits(out, start, hwPt);
0030       pack_into_bits(out, start, hwEta);
0031       pack_into_bits(out, start, hwPhi);
0032       pack_into_bits(out, start, hwId.bits);
0033     }
0034     template <typename U>
0035     inline void unpack_common(const U &src, unsigned int &start) {
0036       unpack_from_bits(src, start, hwPt);
0037       unpack_from_bits(src, start, hwEta);
0038       unpack_from_bits(src, start, hwPhi);
0039       unpack_from_bits(src, start, hwId.bits);
0040     }
0041   };
0042 
0043   struct PFChargedObj : public PFCommonObj {
0044     // WARNING: for whatever reason, maybe connected with datamember alignment,
0045     //          in 2019.2 synthesis fails if DEta & DPhi are put before Z0 & Dxy
0046     z0_t hwZ0;
0047     dxy_t hwDxy;
0048     tkdeta_t hwDEta;  // relative to the region center, at calo
0049     tkdphi_t hwDPhi;  // relative to the region center, at calo
0050     tkquality_t hwTkQuality;
0051 
0052     phi_t hwVtxPhi() const { return hwId.chargeOrNull() ? hwPhi + hwDPhi : hwPhi - hwDPhi; }
0053     eta_t hwVtxEta() const { return hwEta + hwDEta; }
0054 
0055     inline bool operator==(const PFChargedObj &other) const {
0056       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwId == other.hwId &&
0057              hwDEta == other.hwDEta && hwDPhi == other.hwDPhi && hwZ0 == other.hwZ0 && hwDxy == other.hwDxy &&
0058              hwTkQuality == other.hwTkQuality;
0059     }
0060 
0061     inline bool operator>(const PFChargedObj &other) const { return hwPt > other.hwPt; }
0062     inline bool operator<(const PFChargedObj &other) const { return hwPt < other.hwPt; }
0063 
0064     inline void clear() {
0065       hwPt = 0;
0066       hwEta = 0;
0067       hwPhi = 0;
0068       hwId.clear();
0069       hwDEta = 0;
0070       hwDPhi = 0;
0071       hwZ0 = 0;
0072       hwDxy = 0;
0073       hwTkQuality = 0;
0074     }
0075 
0076     int intVtxEta() const { return hwVtxEta().to_int(); }
0077     int intVtxPhi() const { return hwVtxPhi().to_int(); }
0078     float floatDEta() const { return Scales::floatEta(hwDEta); }
0079     float floatDPhi() const { return Scales::floatPhi(hwDPhi); }
0080     float floatVtxEta() const { return Scales::floatEta(hwVtxEta()); }
0081     float floatVtxPhi() const { return Scales::floatPhi(hwVtxPhi()); }
0082     float floatZ0() const { return Scales::floatZ0(hwZ0); }
0083     float floatDxy() const { return Scales::floatDxy(hwDxy); }
0084 
0085     static const int BITWIDTH =
0086         _PFCOMMON_BITWIDTH + tkdeta_t::width + tkdphi_t::width + z0_t::width + dxy_t::width + tkquality_t::width;
0087     inline ap_uint<BITWIDTH> pack() const {
0088       ap_uint<BITWIDTH> ret;
0089       unsigned int start = 0;
0090       pack_common(ret, start);
0091       pack_into_bits(ret, start, hwDEta);
0092       pack_into_bits(ret, start, hwDPhi);
0093       pack_into_bits(ret, start, hwZ0);
0094       pack_into_bits(ret, start, hwDxy);
0095       pack_into_bits(ret, start, hwTkQuality);
0096       return ret;
0097     }
0098     inline static PFChargedObj unpack(const ap_uint<BITWIDTH> &src) {
0099       PFChargedObj ret;
0100       unsigned int start = 0;
0101       ret.unpack_common(src, start);
0102       unpack_from_bits(src, start, ret.hwDEta);
0103       unpack_from_bits(src, start, ret.hwDPhi);
0104       unpack_from_bits(src, start, ret.hwZ0);
0105       unpack_from_bits(src, start, ret.hwDxy);
0106       unpack_from_bits(src, start, ret.hwTkQuality);
0107       return ret;
0108     }
0109   };
0110   inline void clear(PFChargedObj &c) { c.clear(); }
0111 
0112   struct PFNeutralObj : public PFCommonObj {
0113     pt_t hwEmPt;
0114     emid_t hwEmID;
0115     ap_uint<6> hwPUID;
0116 
0117     inline bool operator==(const PFNeutralObj &other) const {
0118       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwId == other.hwId &&
0119              hwEmPt == other.hwEmPt && hwEmID == other.hwEmID && hwPUID == other.hwPUID;
0120     }
0121 
0122     inline bool operator>(const PFNeutralObj &other) const { return hwPt > other.hwPt; }
0123     inline bool operator<(const PFNeutralObj &other) const { return hwPt < other.hwPt; }
0124 
0125     inline void clear() {
0126       hwPt = 0;
0127       hwEta = 0;
0128       hwPhi = 0;
0129       hwId.clear();
0130       hwEmPt = 0;
0131       hwEmID = 0;
0132       hwPUID = 0;
0133     }
0134 
0135     int intEmPt() const { return Scales::intPt(hwEmPt); }
0136     float floatEmPt() const { return Scales::floatPt(hwEmPt); }
0137 
0138     static const int BITWIDTH = _PFCOMMON_BITWIDTH + pt_t::width + ap_uint<6>::width + ap_uint<6>::width;
0139     inline ap_uint<BITWIDTH> pack() const {
0140       ap_uint<BITWIDTH> ret;
0141       unsigned int start = 0;
0142       pack_common(ret, start);
0143       pack_into_bits(ret, start, hwEmPt);
0144       pack_into_bits(ret, start, hwEmID);
0145       pack_into_bits(ret, start, hwPUID);
0146       return ret;
0147     }
0148     inline static PFNeutralObj unpack(const ap_uint<BITWIDTH> &src) {
0149       PFNeutralObj ret;
0150       unsigned int start = 0;
0151       ret.unpack_common(src, start);
0152       unpack_from_bits(src, start, ret.hwEmPt);
0153       unpack_from_bits(src, start, ret.hwEmID);
0154       unpack_from_bits(src, start, ret.hwPUID);
0155       return ret;
0156     }
0157   };
0158 
0159   inline void clear(PFNeutralObj &c) { c.clear(); }
0160 
0161   struct PFRegion {
0162     glbeta_t hwEtaCenter;
0163     glbphi_t hwPhiCenter;
0164     eta_t hwEtaHalfWidth;
0165     phi_t hwPhiHalfWidth;
0166     eta_t hwEtaExtra;
0167     phi_t hwPhiExtra;
0168 
0169     inline int intEtaCenter() const { return hwEtaCenter.to_int(); }
0170     inline int intPhiCenter() const { return hwPhiCenter.to_int(); }
0171     inline float floatEtaCenter() const { return Scales::floatEta(hwEtaCenter); }
0172     inline float floatPhiCenter() const { return Scales::floatPhi(hwPhiCenter); }
0173     inline float floatEtaHalfWidth() const { return Scales::floatEta(hwEtaHalfWidth); }
0174     inline float floatPhiHalfWidth() const { return Scales::floatPhi(hwPhiHalfWidth); }
0175     inline float floatEtaExtra() const { return Scales::floatEta(hwEtaExtra); }
0176     inline float floatPhiExtra() const { return Scales::floatPhi(hwPhiExtra); }
0177     inline float floatPhiHalfWidthExtra() const { return floatPhiHalfWidth() + floatPhiExtra(); }
0178     inline float floatEtaMin() const { return Scales::floatEta(glbeta_t(hwEtaCenter - hwEtaHalfWidth)); }
0179     inline float floatEtaMax() const { return Scales::floatEta(glbeta_t(hwEtaCenter + hwEtaHalfWidth)); }
0180     inline float floatEtaMinExtra() const {
0181       return Scales::floatEta(glbeta_t(hwEtaCenter - hwEtaHalfWidth - hwEtaExtra));
0182     }
0183     inline float floatEtaMaxExtra() const {
0184       return Scales::floatEta(glbeta_t(hwEtaCenter + hwEtaHalfWidth + hwEtaExtra));
0185     }
0186 
0187     inline glbeta_t hwGlbEta(eta_t hwEta) const { return hwEtaCenter + hwEta; }
0188     inline glbeta_t hwGlbEta(glbeta_t hwEta) const { return hwEtaCenter + hwEta; }
0189     inline glbphi_t hwGlbPhi(glbphi_t hwPhi) const {
0190       ap_int<glbphi_t::width + 1> ret = hwPhiCenter + hwPhi;
0191       if (ret > Scales::INTPHI_PI)
0192         return ret - Scales::INTPHI_TWOPI;
0193       else if (ret <= -Scales::INTPHI_PI)
0194         return ret + Scales::INTPHI_TWOPI;
0195       else
0196         return ret;
0197     }
0198 
0199     template <typename T>
0200     inline glbeta_t hwGlbEtaOf(const T &t) const {
0201       return hwGlbEta(t.hwEta);
0202     }
0203     template <typename T>
0204     inline glbphi_t hwGlbPhiOf(const T &t) const {
0205       return hwGlbPhi(t.hwPhi);
0206     }
0207 
0208     inline float floatGlbEta(eta_t hwEta) const { return Scales::floatEta(hwGlbEta(hwEta)); }
0209     inline float floatGlbPhi(phi_t hwPhi) const { return Scales::floatPhi(hwGlbPhi(hwPhi)); }
0210     inline float floatGlbEta(glbeta_t hwEta) const { return Scales::floatEta(hwGlbEta(hwEta)); }
0211     inline float floatGlbPhi(glbphi_t hwPhi) const { return Scales::floatPhi(hwGlbPhi(hwPhi)); }
0212 
0213     template <typename T>
0214     inline float floatGlbEtaOf(const T &t) const {
0215       return floatGlbEta(t.hwEta);
0216     }
0217     template <typename T>
0218     inline float floatGlbPhiOf(const T &t) const {
0219       return floatGlbPhi(t.hwPhi);
0220     }
0221 
0222     inline bool isFiducial(eta_t hwEta, phi_t hwPhi) const {
0223       return hwEta <= hwEtaHalfWidth && hwEta > -hwEtaHalfWidth && hwPhi <= hwPhiHalfWidth && hwPhi > -hwPhiHalfWidth;
0224     }
0225     template <typename ET, typename PT>  // forcing down to eta_t and phi_t may have overflows & crops
0226     inline bool isInside(ET hwEta, PT hwPhi) const {
0227       return hwEta <= hwEtaHalfWidth + hwEtaExtra && hwEta >= -hwEtaHalfWidth - hwEtaExtra &&
0228              hwPhi <= hwPhiHalfWidth + hwPhiExtra && hwPhi >= -hwPhiHalfWidth - hwPhiExtra;
0229     }
0230 
0231     template <typename T>
0232     inline bool isFiducial(const T &t) const {
0233       return isFiducial(t.hwEta, t.hwPhi);
0234     }
0235     template <typename T>
0236     inline bool isInside(const T &t) const {
0237       return isInside(t.hwEta, t.hwPhi);
0238     }
0239 
0240     static const int BITWIDTH = glbeta_t::width + glbphi_t::width + 2 * eta_t::width + 2 * phi_t::width;
0241     inline ap_uint<BITWIDTH> pack() const {
0242       ap_uint<BITWIDTH> ret;
0243       unsigned int start = 0;
0244       pack_into_bits(ret, start, hwEtaCenter);
0245       pack_into_bits(ret, start, hwPhiCenter);
0246       pack_into_bits(ret, start, hwEtaHalfWidth);
0247       pack_into_bits(ret, start, hwPhiHalfWidth);
0248       pack_into_bits(ret, start, hwEtaExtra);
0249       pack_into_bits(ret, start, hwPhiExtra);
0250       return ret;
0251     }
0252     inline static PFRegion unpack(const ap_uint<BITWIDTH> &src) {
0253       PFRegion ret;
0254       unsigned int start = 0;
0255       unpack_from_bits(src, start, ret.hwEtaCenter);
0256       unpack_from_bits(src, start, ret.hwPhiCenter);
0257       unpack_from_bits(src, start, ret.hwEtaHalfWidth);
0258       unpack_from_bits(src, start, ret.hwPhiHalfWidth);
0259       unpack_from_bits(src, start, ret.hwEtaExtra);
0260       unpack_from_bits(src, start, ret.hwPhiExtra);
0261       return ret;
0262     }
0263   };
0264 
0265 }  // namespace l1ct
0266 
0267 #endif