Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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     srrtot_t hwSrrTot;
0016     meanz_t hwMeanZ;
0017     hoe_t hwHoe;
0018 
0019     inline bool operator==(const HadCaloObj &other) const {
0020       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwEmPt == other.hwEmPt &&
0021              hwEmID == other.hwEmID && hwSrrTot == other.hwSrrTot && hwMeanZ == other.hwMeanZ && hwHoe == other.hwHoe;
0022     }
0023 
0024     inline bool operator>(const HadCaloObj &other) const { return hwPt > other.hwPt; }
0025     inline bool operator<(const HadCaloObj &other) const { return hwPt < other.hwPt; }
0026 
0027     inline void clear() {
0028       hwPt = 0;
0029       hwEta = 0;
0030       hwPhi = 0;
0031       hwEmPt = 0;
0032       hwEmID = 0;
0033       hwSrrTot = 0;
0034       hwMeanZ = 0;
0035       hwHoe = 0;
0036     }
0037 
0038     int intPt() const { return Scales::intPt(hwPt); }
0039     int intEmPt() const { return Scales::intPt(hwEmPt); }
0040     int intEta() const { return hwEta.to_int(); }
0041     int intPhi() const { return hwPhi.to_int(); }
0042     float floatPt() const { return Scales::floatPt(hwPt); }
0043     float floatEmPt() const { return Scales::floatPt(hwEmPt); }
0044     float floatEta() const { return Scales::floatEta(hwEta); }
0045     float floatPhi() const { return Scales::floatPhi(hwPhi); }
0046     float floatSrrTot() const { return Scales::floatSrrTot(hwSrrTot); };
0047     float floatMeanZ() const { return Scales::floatMeanZ(hwMeanZ); };
0048     float floatHoe() const { return Scales::floatHoe(hwHoe); };
0049 
0050     bool hwIsEM() const { return hwEmID != 0; }
0051 
0052     static const int BITWIDTH_SLIM = pt_t::width + eta_t::width + phi_t::width + pt_t::width + emid_t::width;
0053 
0054     static const int BITWIDTH = BITWIDTH_SLIM + srrtot_t::width + meanz_t::width + hoe_t::width;
0055 
0056     inline ap_uint<BITWIDTH> pack() const {
0057       ap_uint<BITWIDTH> ret;
0058       unsigned int start = 0;
0059       pack_into_bits(ret, start, hwPt);
0060       pack_into_bits(ret, start, hwEta);
0061       pack_into_bits(ret, start, hwPhi);
0062       pack_into_bits(ret, start, hwEmPt);
0063       pack_into_bits(ret, start, hwEmID);
0064       pack_into_bits(ret, start, hwSrrTot);
0065       pack_into_bits(ret, start, hwMeanZ);
0066       pack_into_bits(ret, start, hwHoe);
0067       return ret;
0068     }
0069 
0070     inline static HadCaloObj unpack(const ap_uint<BITWIDTH> &src) {
0071       HadCaloObj ret;
0072       unsigned int start = 0;
0073       unpack_from_bits(src, start, ret.hwPt);
0074       unpack_from_bits(src, start, ret.hwEta);
0075       unpack_from_bits(src, start, ret.hwPhi);
0076       unpack_from_bits(src, start, ret.hwEmPt);
0077       unpack_from_bits(src, start, ret.hwEmID);
0078       unpack_from_bits(src, start, ret.hwSrrTot);
0079       unpack_from_bits(src, start, ret.hwMeanZ);
0080       unpack_from_bits(src, start, ret.hwHoe);
0081       return ret;
0082     }
0083 
0084     inline ap_uint<BITWIDTH_SLIM> pack_slim() const { return pack()(BITWIDTH_SLIM - 1, 0); }
0085   };
0086 
0087   inline void clear(HadCaloObj &c) { c.clear(); }
0088 
0089   struct EmCaloObj {
0090     pt_t hwPt, hwPtErr;
0091     eta_t hwEta;  // relative to the region center, at calo
0092     phi_t hwPhi;  // relative to the region center, at calo
0093     emid_t hwEmID;
0094     srrtot_t hwSrrTot;
0095     meanz_t hwMeanZ;
0096     hoe_t hwHoe;
0097 
0098     inline bool operator==(const EmCaloObj &other) const {
0099       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwPtErr == other.hwPtErr &&
0100              hwEmID == other.hwEmID && hwSrrTot == other.hwSrrTot && hwMeanZ == other.hwMeanZ && hwHoe == other.hwHoe;
0101     }
0102 
0103     inline bool operator>(const EmCaloObj &other) const { return hwPt > other.hwPt; }
0104     inline bool operator<(const EmCaloObj &other) const { return hwPt < other.hwPt; }
0105 
0106     inline void clear() {
0107       hwPt = 0;
0108       hwPtErr = 0;
0109       hwEta = 0;
0110       hwPhi = 0;
0111       hwEmID = 0;
0112       hwSrrTot = 0;
0113       hwMeanZ = 0;
0114       hwHoe = 0;
0115     }
0116 
0117     int intPt() const { return Scales::intPt(hwPt); }
0118     int intPtErr() const { return Scales::intPt(hwPtErr); }
0119     int intEta() const { return hwEta.to_int(); }
0120     int intPhi() const { return hwPhi.to_int(); }
0121     float floatPt() const { return Scales::floatPt(hwPt); }
0122     float floatPtErr() const { return Scales::floatPt(hwPtErr); }
0123     float floatEta() const { return Scales::floatEta(hwEta); }
0124     float floatPhi() const { return Scales::floatPhi(hwPhi); }
0125     float floatSrrTot() const { return Scales::floatSrrTot(hwSrrTot); };
0126     float floatMeanZ() const { return Scales::floatMeanZ(hwMeanZ); };
0127     float floatHoe() const { return Scales::floatHoe(hwHoe); };
0128 
0129     static const int BITWIDTH_SLIM = pt_t::width + eta_t::width + phi_t::width + pt_t::width + emid_t::width;
0130 
0131     static const int BITWIDTH = BITWIDTH_SLIM + srrtot_t::width + meanz_t::width + hoe_t::width;
0132 
0133     inline ap_uint<BITWIDTH> pack() const {
0134       ap_uint<BITWIDTH> ret;
0135       unsigned int start = 0;
0136       pack_into_bits(ret, start, hwPt);
0137       pack_into_bits(ret, start, hwEta);
0138       pack_into_bits(ret, start, hwPhi);
0139       pack_into_bits(ret, start, hwPtErr);
0140       pack_into_bits(ret, start, hwEmID);
0141       pack_into_bits(ret, start, hwSrrTot);
0142       pack_into_bits(ret, start, hwMeanZ);
0143       pack_into_bits(ret, start, hwHoe);
0144       return ret;
0145     }
0146     inline static EmCaloObj unpack(const ap_uint<BITWIDTH> &src) {
0147       EmCaloObj ret;
0148       unsigned int start = 0;
0149       unpack_from_bits(src, start, ret.hwPt);
0150       unpack_from_bits(src, start, ret.hwEta);
0151       unpack_from_bits(src, start, ret.hwPhi);
0152       unpack_from_bits(src, start, ret.hwPtErr);
0153       unpack_from_bits(src, start, ret.hwEmID);
0154       unpack_from_bits(src, start, ret.hwSrrTot);
0155       unpack_from_bits(src, start, ret.hwMeanZ);
0156       unpack_from_bits(src, start, ret.hwHoe);
0157 
0158       return ret;
0159     }
0160 
0161     inline ap_uint<BITWIDTH_SLIM> pack_slim() const { return pack()(BITWIDTH_SLIM - 1, 0); }
0162   };
0163   inline void clear(EmCaloObj &c) { c.clear(); }
0164 
0165   struct TkObj {
0166     pt_t hwPt;
0167     eta_t hwEta;      // relative to the region center, at calo
0168     phi_t hwPhi;      // relative to the region center, at calo
0169     tkdeta_t hwDEta;  //  vtx - calo
0170     tkdphi_t hwDPhi;  // |vtx - calo| (sign is derived by the charge)
0171     bool hwCharge;    // 1 = positive, 0 = negative
0172     z0_t hwZ0;
0173     dxy_t hwDxy;
0174     tkquality_t hwQuality;
0175     stub_t hwStubs;
0176     redChi2Bin_t hwRedChi2RZ;    // 4 bits
0177     redChi2Bin_t hwRedChi2RPhi;  // 4 bits
0178     //FIXME: 3 bits would be enough
0179     redChi2Bin_t hwRedChi2Bend;  // 4 bits
0180 
0181     enum TkQuality { PFLOOSE = 1, PFTIGHT = 2 };
0182     bool isPFLoose() const { return hwQuality[0]; }
0183     bool isPFTight() const { return hwQuality[1]; }
0184     phi_t hwVtxPhi() const { return hwCharge ? hwPhi + hwDPhi : hwPhi - hwDPhi; }
0185     eta_t hwVtxEta() const { return hwEta + hwDEta; }
0186 
0187     inline bool operator==(const TkObj &other) const {
0188       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwDEta == other.hwDEta &&
0189              hwDPhi == other.hwDPhi && hwZ0 == other.hwZ0 && hwDxy == other.hwDxy && hwCharge == other.hwCharge &&
0190              hwQuality == other.hwQuality && hwStubs == other.hwStubs && hwRedChi2RZ == other.hwRedChi2RZ &&
0191              hwRedChi2RPhi == other.hwRedChi2RPhi && hwRedChi2Bend == other.hwRedChi2Bend;
0192     }
0193 
0194     inline bool operator>(const TkObj &other) const { return hwPt > other.hwPt; }
0195     inline bool operator<(const TkObj &other) const { return hwPt < other.hwPt; }
0196 
0197     inline void clear() {
0198       hwPt = 0;
0199       hwEta = 0;
0200       hwPhi = 0;
0201       hwDEta = 0;
0202       hwDPhi = 0;
0203       hwZ0 = 0;
0204       hwDxy = 0;
0205       hwCharge = false;
0206       hwQuality = 0;
0207       hwStubs = 0;
0208       hwRedChi2RZ = 0;
0209       hwRedChi2RPhi = 0;
0210       hwRedChi2Bend = 0;
0211     }
0212 
0213     int intPt() const { return Scales::intPt(hwPt); }
0214     int intEta() const { return hwEta.to_int(); }
0215     int intPhi() const { return hwPhi.to_int(); }
0216     int intVtxEta() const { return hwVtxEta().to_int(); }
0217     int intVtxPhi() const { return hwVtxPhi().to_int(); }
0218     int intCharge() const { return hwCharge ? +1 : -1; }
0219     float floatPt() const { return Scales::floatPt(hwPt); }
0220     float floatEta() const { return Scales::floatEta(hwEta); }
0221     float floatPhi() const { return Scales::floatPhi(hwPhi); }
0222     float floatDEta() const { return Scales::floatEta(hwDEta); }
0223     float floatDPhi() const { return Scales::floatPhi(hwDPhi); }
0224     float floatVtxEta() const { return Scales::floatEta(hwVtxEta()); }
0225     float floatVtxPhi() const { return Scales::floatPhi(hwVtxPhi()); }
0226     float floatZ0() const { return Scales::floatZ0(hwZ0); }
0227     float floatDxy() const { return Scales::floatDxy(hwDxy); }
0228 
0229     static const int BITWIDTH_SLIM = pt_t::width + eta_t::width + phi_t::width + tkdeta_t::width + tkdphi_t::width + 1 +
0230                                      z0_t::width + dxy_t::width + tkquality_t::width;
0231 
0232     static const int BITWIDTH =
0233         BITWIDTH_SLIM + stub_t::width + redChi2Bin_t::width + redChi2Bin_t::width + redChi2Bin_t::width;
0234 
0235     inline ap_uint<BITWIDTH> pack() const {
0236       ap_uint<BITWIDTH> ret;
0237       unsigned int start = 0;
0238       pack_into_bits(ret, start, hwPt);
0239       pack_into_bits(ret, start, hwEta);
0240       pack_into_bits(ret, start, hwPhi);
0241       pack_into_bits(ret, start, hwDEta);
0242       pack_into_bits(ret, start, hwDPhi);
0243       pack_bool_into_bits(ret, start, hwCharge);
0244       pack_into_bits(ret, start, hwZ0);
0245       pack_into_bits(ret, start, hwDxy);
0246       pack_into_bits(ret, start, hwQuality);
0247       pack_into_bits(ret, start, hwStubs);
0248       pack_into_bits(ret, start, hwRedChi2RZ);
0249       pack_into_bits(ret, start, hwRedChi2RPhi);
0250       pack_into_bits(ret, start, hwRedChi2Bend);
0251       return ret;
0252     }
0253     inline static TkObj unpack(const ap_uint<BITWIDTH> &src) {
0254       TkObj ret;
0255       unsigned int start = 0;
0256       unpack_from_bits(src, start, ret.hwPt);
0257       unpack_from_bits(src, start, ret.hwEta);
0258       unpack_from_bits(src, start, ret.hwPhi);
0259       unpack_from_bits(src, start, ret.hwDEta);
0260       unpack_from_bits(src, start, ret.hwDPhi);
0261       unpack_bool_from_bits(src, start, ret.hwCharge);
0262       unpack_from_bits(src, start, ret.hwZ0);
0263       unpack_from_bits(src, start, ret.hwDxy);
0264       unpack_from_bits(src, start, ret.hwQuality);
0265       unpack_from_bits(src, start, ret.hwStubs);
0266       unpack_from_bits(src, start, ret.hwRedChi2RZ);
0267       unpack_from_bits(src, start, ret.hwRedChi2RPhi);
0268       unpack_from_bits(src, start, ret.hwRedChi2Bend);
0269       return ret;
0270     }
0271     inline ap_uint<BITWIDTH_SLIM> pack_slim() const { return pack()(BITWIDTH_SLIM - 1, 0); }
0272   };
0273   inline void clear(TkObj &c) { c.clear(); }
0274 
0275   struct MuObj {
0276     pt_t hwPt;
0277     glbeta_t hwEta;   // relative to the region center, at calo
0278     glbphi_t hwPhi;   // relative to the region center, at calo
0279     tkdeta_t hwDEta;  //  vtx - calo
0280     tkdphi_t hwDPhi;  // |vtx - calo| (sign is derived by the charge)
0281     bool hwCharge;    // 1 = positive, 0 = negative
0282     z0_t hwZ0;
0283     dxy_t hwDxy;
0284     ap_uint<3> hwQuality;
0285     glbphi_t hwVtxPhi() const { return hwCharge ? hwPhi + hwDPhi : hwPhi - hwDPhi; }
0286     glbeta_t hwVtxEta() const { return hwEta + hwDEta; }
0287 
0288     inline bool operator==(const MuObj &other) const {
0289       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwDEta == other.hwDEta &&
0290              hwDPhi == other.hwDPhi && hwZ0 == other.hwZ0 && hwDxy == other.hwDxy && hwCharge == other.hwCharge &&
0291              hwQuality == other.hwQuality;
0292     }
0293 
0294     inline bool operator>(const MuObj &other) const { return hwPt > other.hwPt; }
0295     inline bool operator<(const MuObj &other) const { return hwPt < other.hwPt; }
0296 
0297     inline void clear() {
0298       hwPt = 0;
0299       hwEta = 0;
0300       hwPhi = 0;
0301       hwDEta = 0;
0302       hwDPhi = 0;
0303       hwZ0 = 0;
0304       hwDxy = 0;
0305       hwCharge = false;
0306       hwQuality = 0;
0307     }
0308 
0309     int intPt() const { return Scales::intPt(hwPt); }
0310     int intEta() const { return hwEta.to_int(); }
0311     int intPhi() const { return hwPhi.to_int(); }
0312     int intVtxEta() const { return hwVtxEta().to_int(); }
0313     int intVtxPhi() const { return hwVtxPhi().to_int(); }
0314     int intCharge() const { return hwCharge ? +1 : -1; }
0315     float floatPt() const { return Scales::floatPt(hwPt); }
0316     float floatEta() const { return Scales::floatEta(hwEta); }
0317     float floatPhi() const { return Scales::floatPhi(hwPhi); }
0318     float floatDEta() const { return Scales::floatEta(hwDEta); }
0319     float floatDPhi() const { return Scales::floatPhi(hwDPhi); }
0320     float floatVtxEta() const { return Scales::floatEta(hwVtxEta()); }
0321     float floatVtxPhi() const { return Scales::floatPhi(hwVtxPhi()); }
0322     float floatZ0() const { return Scales::floatZ0(hwZ0); }
0323     float floatDxy() const { return Scales::floatDxy(hwDxy); }
0324 
0325     static const int BITWIDTH = pt_t::width + glbeta_t::width + glbphi_t::width + tkdeta_t::width + tkdphi_t::width +
0326                                 1 + z0_t::width + dxy_t::width + ap_uint<3>::width;
0327     inline ap_uint<BITWIDTH> pack() const {
0328       ap_uint<BITWIDTH> ret;
0329       unsigned int start = 0;
0330       pack_into_bits(ret, start, hwPt);
0331       pack_into_bits(ret, start, hwEta);
0332       pack_into_bits(ret, start, hwPhi);
0333       pack_into_bits(ret, start, hwDEta);
0334       pack_into_bits(ret, start, hwDPhi);
0335       pack_bool_into_bits(ret, start, hwCharge);
0336       pack_into_bits(ret, start, hwZ0);
0337       pack_into_bits(ret, start, hwDxy);
0338       pack_into_bits(ret, start, hwQuality);
0339       return ret;
0340     }
0341     inline static MuObj unpack(const ap_uint<BITWIDTH> &src) {
0342       MuObj ret;
0343       unsigned int start = 0;
0344       unpack_from_bits(src, start, ret.hwPt);
0345       unpack_from_bits(src, start, ret.hwEta);
0346       unpack_from_bits(src, start, ret.hwPhi);
0347       unpack_from_bits(src, start, ret.hwDEta);
0348       unpack_from_bits(src, start, ret.hwDPhi);
0349       unpack_bool_from_bits(src, start, ret.hwCharge);
0350       unpack_from_bits(src, start, ret.hwZ0);
0351       unpack_from_bits(src, start, ret.hwDxy);
0352       unpack_from_bits(src, start, ret.hwQuality);
0353       return ret;
0354     }
0355   };
0356   inline void clear(MuObj &c) { c.clear(); }
0357 
0358   struct PVObj {
0359     z0_t hwZ0;
0360 
0361     inline bool operator==(const PVObj &other) const { return hwZ0 == other.hwZ0; }
0362 
0363     inline void clear() { hwZ0 = 0; }
0364 
0365     float floatZ0() const { return Scales::floatZ0(hwZ0); }
0366 
0367     static const int BITWIDTH = z0_t::width;
0368     inline ap_uint<BITWIDTH> pack() const {
0369       ap_uint<BITWIDTH> ret;
0370       unsigned int start = 0;
0371       pack_into_bits(ret, start, hwZ0);
0372       return ret;
0373     }
0374     inline static PVObj unpack(const ap_uint<BITWIDTH> &src) {
0375       PVObj ret;
0376       unsigned int start = 0;
0377       unpack_from_bits(src, start, ret.hwZ0);
0378       return ret;
0379     }
0380   };
0381   inline void clear(PVObj &c) { c.clear(); }
0382 
0383 }  // namespace l1ct
0384 
0385 #endif