Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-06-20 01:53:08

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     id_prob_t hwPiProb;
0019     id_prob_t hwEmProb;
0020 
0021     // NOTE: empty objects will have hwPiProb = 0, hwEmID = 0, hwPuProb = 1
0022     id_prob_t hwPuProb() const { return id_prob_t(1) - hwPiProb - hwEmProb; }
0023 
0024     inline bool operator==(const HadCaloObj &other) const {
0025       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwEmPt == other.hwEmPt &&
0026              hwEmID == other.hwEmID && hwSrrTot == other.hwSrrTot && hwMeanZ == other.hwMeanZ && hwHoe == other.hwHoe &&
0027              hwPiProb == other.hwPiProb && hwEmProb == other.hwEmProb;
0028     }
0029 
0030     inline bool operator>(const HadCaloObj &other) const { return hwPt > other.hwPt; }
0031     inline bool operator<(const HadCaloObj &other) const { return hwPt < other.hwPt; }
0032 
0033     inline void clear() {
0034       hwPt = 0;
0035       hwEta = 0;
0036       hwPhi = 0;
0037       hwEmPt = 0;
0038       hwEmID = 0;
0039       hwSrrTot = 0;
0040       hwMeanZ = 0;
0041       hwHoe = 0;
0042       hwPiProb = 0;
0043       hwEmProb = 0;
0044     }
0045 
0046     int intPt() const { return Scales::intPt(hwPt); }
0047     int intEmPt() const { return Scales::intPt(hwEmPt); }
0048     int intEta() const { return hwEta.to_int(); }
0049     int intPhi() const { return hwPhi.to_int(); }
0050     float floatPt() const { return Scales::floatPt(hwPt); }
0051     float floatEmPt() const { return Scales::floatPt(hwEmPt); }
0052     float floatEta() const { return Scales::floatEta(hwEta); }
0053     float floatPhi() const { return Scales::floatPhi(hwPhi); }
0054     float floatSrrTot() const { return Scales::floatSrrTot(hwSrrTot); }
0055     float floatMeanZ() const { return Scales::floatMeanZ(hwMeanZ); }
0056     float floatHoe() const { return Scales::floatHoe(hwHoe); }
0057     float floatPiProb() const { return Scales::floatIDProb(hwPiProb); }
0058     float floatEmProb() const { return Scales::floatIDProb(hwEmProb); }
0059     float floatPuProb() const { return Scales::floatIDProb(hwPuProb()); }
0060 
0061     bool hwIsEM() const { return hwEmID != 0; }
0062 
0063     static const int BITWIDTH_BARREL_SLIM = pt_t::width + eta_t::width + phi_t::width + pt_t::width + emid_t::width;
0064     static const int BITWIDTH_ENDCAP_SLIM =
0065         pt_t::width + eta_t::width + phi_t::width + pt_t::width + emid_t::width + id_prob_t::width + id_prob_t::width;
0066 
0067     static const int BITWIDTH_BARREL = BITWIDTH_BARREL_SLIM;
0068     static const int BITWIDTH_ENDCAP = BITWIDTH_ENDCAP_SLIM + srrtot_t::width + meanz_t::width + hoe_t::width;
0069 
0070     inline ap_uint<BITWIDTH_ENDCAP> pack_endcap() const {
0071       ap_uint<BITWIDTH_ENDCAP> ret;
0072       unsigned int start = 0;
0073       pack_into_bits(ret, start, hwPt);
0074       pack_into_bits(ret, start, hwEta);
0075       pack_into_bits(ret, start, hwPhi);
0076       pack_into_bits(ret, start, hwEmPt);
0077       pack_into_bits(ret, start, hwEmID);
0078       pack_into_bits(ret, start, hwPiProb);
0079       pack_into_bits(ret, start, hwEmProb);
0080       pack_into_bits(ret, start, hwSrrTot);
0081       pack_into_bits(ret, start, hwMeanZ);
0082       pack_into_bits(ret, start, hwHoe);
0083       return ret;
0084     }
0085 
0086     inline ap_uint<BITWIDTH_ENDCAP_SLIM> pack_endcap_slim() const { return pack_endcap()(BITWIDTH_ENDCAP_SLIM - 1, 0); }
0087 
0088     inline ap_uint<BITWIDTH_BARREL> pack_barrel() const {
0089       ap_uint<BITWIDTH_BARREL> ret;
0090       unsigned int start = 0;
0091       pack_into_bits(ret, start, hwPt);
0092       pack_into_bits(ret, start, hwEta);
0093       pack_into_bits(ret, start, hwPhi);
0094       pack_into_bits(ret, start, hwEmPt);
0095       pack_into_bits(ret, start, hwEmID);
0096       return ret;
0097     }
0098 
0099     inline ap_uint<BITWIDTH_BARREL_SLIM> pack_barrel_slim() const { return pack_barrel()(BITWIDTH_BARREL_SLIM - 1, 0); }
0100 
0101     inline static HadCaloObj unpack_barrel(const ap_uint<BITWIDTH_BARREL> &src) {
0102       HadCaloObj ret;
0103       ret.clear();
0104       unsigned int start = 0;
0105       unpack_from_bits(src, start, ret.hwPt);
0106       unpack_from_bits(src, start, ret.hwEta);
0107       unpack_from_bits(src, start, ret.hwPhi);
0108       unpack_from_bits(src, start, ret.hwEmPt);
0109       unpack_from_bits(src, start, ret.hwEmID);
0110       return ret;
0111     }
0112 
0113     inline static HadCaloObj unpack_endcap(const ap_uint<BITWIDTH_ENDCAP> &src) {
0114       HadCaloObj ret;
0115       ret.clear();
0116       unsigned int start = 0;
0117       unpack_from_bits(src, start, ret.hwPt);
0118       unpack_from_bits(src, start, ret.hwEta);
0119       unpack_from_bits(src, start, ret.hwPhi);
0120       unpack_from_bits(src, start, ret.hwEmPt);
0121       unpack_from_bits(src, start, ret.hwEmID);
0122       unpack_from_bits(src, start, ret.hwPiProb);
0123       unpack_from_bits(src, start, ret.hwEmProb);
0124       unpack_from_bits(src, start, ret.hwSrrTot);
0125       unpack_from_bits(src, start, ret.hwMeanZ);
0126       unpack_from_bits(src, start, ret.hwHoe);
0127       return ret;
0128     }
0129 #ifndef __SYNTHESIS__
0130     // NOTE: The generic pack/unpack functions are not meant to be used in the firmware but only
0131     // to read/dump the emulator data to/from files.
0132     // The firmware implementation should actually use the specific pack/unpack implementations
0133     static const int BITWIDTH = pt_t::width + eta_t::width + phi_t::width + pt_t::width + emid_t::width +
0134                                 id_prob_t::width + id_prob_t::width + srrtot_t::width + meanz_t::width + hoe_t::width;
0135 
0136     inline ap_uint<BITWIDTH> pack() const {
0137       ap_uint<BITWIDTH> ret;
0138       unsigned int start = 0;
0139       pack_into_bits(ret, start, hwPt);
0140       pack_into_bits(ret, start, hwEta);
0141       pack_into_bits(ret, start, hwPhi);
0142       pack_into_bits(ret, start, hwEmPt);
0143       pack_into_bits(ret, start, hwEmID);
0144       pack_into_bits(ret, start, hwPiProb);
0145       pack_into_bits(ret, start, hwEmProb);
0146       pack_into_bits(ret, start, hwSrrTot);
0147       pack_into_bits(ret, start, hwMeanZ);
0148       pack_into_bits(ret, start, hwHoe);
0149       return ret;
0150     }
0151 
0152     inline static HadCaloObj unpack(const ap_uint<BITWIDTH> &src) {
0153       HadCaloObj ret;
0154       unsigned int start = 0;
0155       unpack_from_bits(src, start, ret.hwPt);
0156       unpack_from_bits(src, start, ret.hwEta);
0157       unpack_from_bits(src, start, ret.hwPhi);
0158       unpack_from_bits(src, start, ret.hwEmPt);
0159       unpack_from_bits(src, start, ret.hwEmID);
0160       unpack_from_bits(src, start, ret.hwPiProb);
0161       unpack_from_bits(src, start, ret.hwEmProb);
0162       unpack_from_bits(src, start, ret.hwSrrTot);
0163       unpack_from_bits(src, start, ret.hwMeanZ);
0164       unpack_from_bits(src, start, ret.hwHoe);
0165       return ret;
0166     }
0167 #endif
0168   };
0169 
0170   inline void clear(HadCaloObj &c) { c.clear(); }
0171 
0172   struct EmCaloObj {
0173     pt_t hwPt, hwPtErr;
0174     eta_t hwEta;  // relative to the region center, at calo
0175     phi_t hwPhi;  // relative to the region center, at calo
0176     emid_t hwEmID;
0177     shower_shape_t hwShowerShape;
0178     rel_iso_t hwRelIso;
0179     srrtot_t hwSrrTot;
0180     meanz_t hwMeanZ;
0181     hoe_t hwHoe;
0182     id_prob_t hwPiProb;
0183     id_prob_t hwEmProb;
0184 
0185     inline bool operator==(const EmCaloObj &other) const {
0186       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwPtErr == other.hwPtErr &&
0187              hwEmID == other.hwEmID && hwShowerShape == other.hwShowerShape && hwRelIso == other.hwRelIso &&
0188              hwSrrTot == other.hwSrrTot && hwMeanZ == other.hwMeanZ && hwHoe == other.hwHoe &&
0189              hwPiProb == other.hwPiProb && hwEmProb == other.hwEmProb;
0190     }
0191 
0192     inline bool operator>(const EmCaloObj &other) const { return hwPt > other.hwPt; }
0193     inline bool operator<(const EmCaloObj &other) const { return hwPt < other.hwPt; }
0194 
0195     inline void clear() {
0196       hwPt = 0;
0197       hwPtErr = 0;
0198       hwEta = 0;
0199       hwPhi = 0;
0200       hwEmID = 0;
0201       hwShowerShape = 0;
0202       hwRelIso = 0;
0203       hwSrrTot = 0;
0204       hwMeanZ = 0;
0205       hwHoe = 0;
0206       hwPiProb = 0;
0207       hwEmProb = 0;
0208     }
0209 
0210     // NOTE: empty objects will have hwPiProb = 0, hwEgProb = 0, hwPuProb = 1
0211     id_prob_t hwPuProb() const { return id_prob_t(1) - hwPiProb - hwEmProb; }
0212 
0213     int intPt() const { return Scales::intPt(hwPt); }
0214     int intPtErr() const { return Scales::intPt(hwPtErr); }
0215     int intEta() const { return hwEta.to_int(); }
0216     int intPhi() const { return hwPhi.to_int(); }
0217     float floatPt() const { return Scales::floatPt(hwPt); }
0218     float floatPtErr() const { return Scales::floatPt(hwPtErr); }
0219     float floatEta() const { return Scales::floatEta(hwEta); }
0220     float floatPhi() const { return Scales::floatPhi(hwPhi); }
0221     float floatShowerShape() const { return Scales::floatShoweShape(hwShowerShape); }
0222     float floatRelIso() const { return Scales::floatRelIso(hwRelIso); }
0223     float floatSrrTot() const { return Scales::floatSrrTot(hwSrrTot); }
0224     float floatMeanZ() const { return Scales::floatMeanZ(hwMeanZ); }
0225     float floatHoe() const { return Scales::floatHoe(hwHoe); }
0226     float floatPiProb() const { return Scales::floatIDProb(hwPiProb); }
0227     float floatEmProb() const { return Scales::floatIDProb(hwEmProb); }
0228     float floatPuProb() const { return Scales::floatIDProb(hwPuProb()); }
0229 
0230     static const int BITWIDTH_BARREL_SLIM = pt_t::width + pt_t::width + eta_t::width + phi_t::width + emid_t::width;
0231     static const int BITWIDTH_ENDCAP_SLIM =
0232         pt_t::width + pt_t::width + eta_t::width + phi_t::width + emid_t::width + id_prob_t::width + id_prob_t::width;
0233 
0234     static const int BITWIDTH_BARREL = BITWIDTH_BARREL_SLIM + shower_shape_t::width + rel_iso_t::width;
0235     static const int BITWIDTH_ENDCAP = BITWIDTH_ENDCAP_SLIM + srrtot_t::width + meanz_t::width + hoe_t::width;
0236 
0237     inline ap_uint<BITWIDTH_ENDCAP> pack_endcap() const {
0238       ap_uint<BITWIDTH_ENDCAP> ret;
0239       unsigned int start = 0;
0240       pack_into_bits(ret, start, hwPt);
0241       pack_into_bits(ret, start, hwEta);
0242       pack_into_bits(ret, start, hwPhi);
0243       pack_into_bits(ret, start, hwPtErr);
0244       pack_into_bits(ret, start, hwEmID);
0245       pack_into_bits(ret, start, hwPiProb);
0246       pack_into_bits(ret, start, hwEmProb);
0247       pack_into_bits(ret, start, hwSrrTot);
0248       pack_into_bits(ret, start, hwMeanZ);
0249       pack_into_bits(ret, start, hwHoe);
0250       return ret;
0251     }
0252 
0253     inline ap_uint<BITWIDTH_ENDCAP_SLIM> pack_endcap_slim() const { return pack_endcap()(BITWIDTH_ENDCAP_SLIM - 1, 0); }
0254 
0255     inline ap_uint<BITWIDTH_BARREL> pack_barrel() const {
0256       ap_uint<BITWIDTH_BARREL> ret;
0257       unsigned int start = 0;
0258       pack_into_bits(ret, start, hwPt);
0259       pack_into_bits(ret, start, hwEta);
0260       pack_into_bits(ret, start, hwPhi);
0261       pack_into_bits(ret, start, hwPtErr);
0262       pack_into_bits(ret, start, hwEmID);
0263       pack_into_bits(ret, start, hwShowerShape);
0264       pack_into_bits(ret, start, hwRelIso);
0265       return ret;
0266     }
0267 
0268     inline ap_uint<BITWIDTH_BARREL_SLIM> pack_barrel_slim() const { return pack_barrel()(BITWIDTH_BARREL_SLIM - 1, 0); }
0269 
0270     inline static EmCaloObj unpack_barrel(const ap_uint<BITWIDTH_BARREL> &src) {
0271       EmCaloObj ret;
0272       ret.clear();
0273       unsigned int start = 0;
0274       unpack_from_bits(src, start, ret.hwPt);
0275       unpack_from_bits(src, start, ret.hwEta);
0276       unpack_from_bits(src, start, ret.hwPhi);
0277       unpack_from_bits(src, start, ret.hwPtErr);
0278       unpack_from_bits(src, start, ret.hwEmID);
0279       unpack_from_bits(src, start, ret.hwShowerShape);
0280       unpack_from_bits(src, start, ret.hwRelIso);
0281       return ret;
0282     }
0283 
0284     inline static EmCaloObj unpack_endcap(const ap_uint<BITWIDTH_ENDCAP> &src) {
0285       EmCaloObj ret;
0286       ret.clear();
0287       unsigned int start = 0;
0288       unpack_from_bits(src, start, ret.hwPt);
0289       unpack_from_bits(src, start, ret.hwEta);
0290       unpack_from_bits(src, start, ret.hwPhi);
0291       unpack_from_bits(src, start, ret.hwPtErr);
0292       unpack_from_bits(src, start, ret.hwEmID);
0293       unpack_from_bits(src, start, ret.hwPiProb);
0294       unpack_from_bits(src, start, ret.hwEmProb);
0295       unpack_from_bits(src, start, ret.hwSrrTot);
0296       unpack_from_bits(src, start, ret.hwMeanZ);
0297       unpack_from_bits(src, start, ret.hwHoe);
0298       return ret;
0299     }
0300 
0301 #ifndef __SYNTHESIS__
0302     // NOTE: The generic pack/unpack functions are not meant to be used in the firmware but only
0303     // to read/dump the emulator data to/from files.
0304     // The firmware implementation should actually use the specific pack/unpack implementations
0305 
0306     static const int BITWIDTH = pt_t::width + pt_t::width + eta_t::width + phi_t::width + emid_t::width +
0307                                 shower_shape_t::width + rel_iso_t::width + id_prob_t::width + id_prob_t::width +
0308                                 srrtot_t::width + meanz_t::width + hoe_t::width;
0309 
0310     inline ap_uint<BITWIDTH> pack() const {
0311       ap_uint<BITWIDTH> ret;
0312       unsigned int start = 0;
0313       pack_into_bits(ret, start, hwPt);
0314       pack_into_bits(ret, start, hwEta);
0315       pack_into_bits(ret, start, hwPhi);
0316       pack_into_bits(ret, start, hwPtErr);
0317       pack_into_bits(ret, start, hwEmID);
0318       pack_into_bits(ret, start, hwShowerShape);
0319       pack_into_bits(ret, start, hwRelIso);
0320       pack_into_bits(ret, start, hwPiProb);
0321       pack_into_bits(ret, start, hwEmProb);
0322       pack_into_bits(ret, start, hwSrrTot);
0323       pack_into_bits(ret, start, hwMeanZ);
0324       pack_into_bits(ret, start, hwHoe);
0325       return ret;
0326     }
0327     inline static EmCaloObj unpack(const ap_uint<BITWIDTH> &src) {
0328       EmCaloObj ret;
0329       unsigned int start = 0;
0330       unpack_from_bits(src, start, ret.hwPt);
0331       unpack_from_bits(src, start, ret.hwEta);
0332       unpack_from_bits(src, start, ret.hwPhi);
0333       unpack_from_bits(src, start, ret.hwPtErr);
0334       unpack_from_bits(src, start, ret.hwEmID);
0335       unpack_from_bits(src, start, ret.hwShowerShape);
0336       unpack_from_bits(src, start, ret.hwRelIso);
0337       unpack_from_bits(src, start, ret.hwPiProb);
0338       unpack_from_bits(src, start, ret.hwEmProb);
0339       unpack_from_bits(src, start, ret.hwSrrTot);
0340       unpack_from_bits(src, start, ret.hwMeanZ);
0341       unpack_from_bits(src, start, ret.hwHoe);
0342       return ret;
0343     }
0344 #endif
0345   };
0346   inline void clear(EmCaloObj &c) { c.clear(); }
0347 
0348   struct TkObj {
0349     pt_t hwPt;
0350     eta_t hwEta;      // relative to the region center, at calo
0351     phi_t hwPhi;      // relative to the region center, at calo
0352     tkdeta_t hwDEta;  //  vtx - calo
0353     tkdphi_t hwDPhi;  // |vtx - calo| (sign is derived by the charge)
0354     bool hwCharge;    // 1 = positive, 0 = negative
0355     z0_t hwZ0;
0356     dxy_t hwDxy;
0357     tkquality_t hwQuality;
0358     redChi2Bin_t hwRedChi2RPhi;  // 4 bits
0359     redChi2Bin_t hwRedChi2RZ;    // 4 bits
0360     //FIXME: 3 bits would be enough
0361     redChi2Bin_t hwRedChi2Bend;  // 4 bits
0362     stub_t hwStubs;
0363 
0364     enum TkQuality { PFLOOSE = 1, PFTIGHT = 2 };
0365     bool isPFLoose() const { return hwQuality[0]; }
0366     bool isPFTight() const { return hwQuality[1]; }
0367     phi_t hwVtxPhi() const { return hwCharge ? hwPhi + hwDPhi : hwPhi - hwDPhi; }
0368     eta_t hwVtxEta() const { return hwEta + hwDEta; }
0369 
0370     inline bool operator==(const TkObj &other) const {
0371       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwDEta == other.hwDEta &&
0372              hwDPhi == other.hwDPhi && hwZ0 == other.hwZ0 && hwDxy == other.hwDxy && hwCharge == other.hwCharge &&
0373              hwQuality == other.hwQuality && hwStubs == other.hwStubs && hwRedChi2RZ == other.hwRedChi2RZ &&
0374              hwRedChi2RPhi == other.hwRedChi2RPhi && hwRedChi2Bend == other.hwRedChi2Bend;
0375     }
0376 
0377     inline bool operator>(const TkObj &other) const { return hwPt > other.hwPt; }
0378     inline bool operator<(const TkObj &other) const { return hwPt < other.hwPt; }
0379 
0380     inline void clear() {
0381       hwPt = 0;
0382       hwEta = 0;
0383       hwPhi = 0;
0384       hwDEta = 0;
0385       hwDPhi = 0;
0386       hwZ0 = 0;
0387       hwDxy = 0;
0388       hwCharge = false;
0389       hwQuality = 0;
0390       hwRedChi2RPhi = 0;
0391       hwRedChi2RZ = 0;
0392       hwRedChi2Bend = 0;
0393       hwStubs = 0;
0394     }
0395 
0396     int intPt() const { return Scales::intPt(hwPt); }
0397     int intEta() const { return hwEta.to_int(); }
0398     int intPhi() const { return hwPhi.to_int(); }
0399     int intVtxEta() const { return hwVtxEta().to_int(); }
0400     int intVtxPhi() const { return hwVtxPhi().to_int(); }
0401     int intCharge() const { return hwCharge ? +1 : -1; }
0402     float floatPt() const { return Scales::floatPt(hwPt); }
0403     float floatEta() const { return Scales::floatEta(hwEta); }
0404     float floatPhi() const { return Scales::floatPhi(hwPhi); }
0405     float floatDEta() const { return Scales::floatEta(hwDEta); }
0406     float floatDPhi() const { return Scales::floatPhi(hwDPhi); }
0407     float floatVtxEta() const { return Scales::floatEta(hwVtxEta()); }
0408     float floatVtxPhi() const { return Scales::floatPhi(hwVtxPhi()); }
0409     float floatZ0() const { return Scales::floatZ0(hwZ0); }
0410     float floatDxy() const { return Scales::floatDxy(hwDxy); }
0411 
0412     static const int BITWIDTH_SLIM = pt_t::width + eta_t::width + phi_t::width + tkdeta_t::width + tkdphi_t::width + 1 +
0413                                      z0_t::width + dxy_t::width + tkquality_t::width;
0414 
0415     static const int BITWIDTH_BARREL = BITWIDTH_SLIM + redChi2Bin_t::width;
0416     static const int BITWIDTH_ENDCAP =
0417         BITWIDTH_SLIM + redChi2Bin_t::width + redChi2Bin_t::width + redChi2Bin_t::width + stub_t::width;
0418 
0419     static const int BITWIDTH =
0420         BITWIDTH_SLIM + redChi2Bin_t::width + redChi2Bin_t::width + redChi2Bin_t::width + stub_t::width;
0421 
0422 #ifndef __SYNTHESIS__
0423 
0424     inline ap_uint<BITWIDTH> pack() const {
0425       ap_uint<BITWIDTH> ret;
0426       unsigned int start = 0;
0427       pack_into_bits(ret, start, hwPt);
0428       pack_into_bits(ret, start, hwEta);
0429       pack_into_bits(ret, start, hwPhi);
0430       pack_into_bits(ret, start, hwDEta);
0431       pack_into_bits(ret, start, hwDPhi);
0432       pack_bool_into_bits(ret, start, hwCharge);
0433       pack_into_bits(ret, start, hwZ0);
0434       pack_into_bits(ret, start, hwDxy);
0435       pack_into_bits(ret, start, hwQuality);
0436       pack_into_bits(ret, start, hwRedChi2RPhi);
0437       pack_into_bits(ret, start, hwRedChi2RZ);
0438       pack_into_bits(ret, start, hwRedChi2Bend);
0439       pack_into_bits(ret, start, hwStubs);
0440 
0441       return ret;
0442     }
0443 
0444 #endif
0445 
0446     inline static TkObj unpack(const ap_uint<BITWIDTH> &src) {
0447       TkObj ret;
0448       unsigned int start = 0;
0449       unpack_from_bits(src, start, ret.hwPt);
0450       unpack_from_bits(src, start, ret.hwEta);
0451       unpack_from_bits(src, start, ret.hwPhi);
0452       unpack_from_bits(src, start, ret.hwDEta);
0453       unpack_from_bits(src, start, ret.hwDPhi);
0454       unpack_bool_from_bits(src, start, ret.hwCharge);
0455       unpack_from_bits(src, start, ret.hwZ0);
0456       unpack_from_bits(src, start, ret.hwDxy);
0457       unpack_from_bits(src, start, ret.hwQuality);
0458       unpack_from_bits(src, start, ret.hwRedChi2RPhi);
0459       unpack_from_bits(src, start, ret.hwRedChi2RZ);
0460       unpack_from_bits(src, start, ret.hwRedChi2Bend);
0461       unpack_from_bits(src, start, ret.hwStubs);
0462       return ret;
0463     }
0464 
0465     inline ap_uint<BITWIDTH_BARREL> pack_barrel() const {
0466       ap_uint<BITWIDTH_BARREL> ret;
0467       unsigned int start = 0;
0468       pack_into_bits(ret, start, hwPt);
0469       pack_into_bits(ret, start, hwEta);
0470       pack_into_bits(ret, start, hwPhi);
0471       pack_into_bits(ret, start, hwDEta);
0472       pack_into_bits(ret, start, hwDPhi);
0473       pack_bool_into_bits(ret, start, hwCharge);
0474       pack_into_bits(ret, start, hwZ0);
0475       pack_into_bits(ret, start, hwDxy);
0476       pack_into_bits(ret, start, hwQuality);
0477       pack_into_bits(ret, start, hwRedChi2RPhi);
0478       return ret;
0479     }
0480 
0481     inline ap_uint<BITWIDTH_ENDCAP> pack_endcap() const {
0482       ap_uint<BITWIDTH_ENDCAP> ret;
0483       unsigned int start = 0;
0484       pack_into_bits(ret, start, hwPt);
0485       pack_into_bits(ret, start, hwEta);
0486       pack_into_bits(ret, start, hwPhi);
0487       pack_into_bits(ret, start, hwDEta);
0488       pack_into_bits(ret, start, hwDPhi);
0489       pack_bool_into_bits(ret, start, hwCharge);
0490       pack_into_bits(ret, start, hwZ0);
0491       pack_into_bits(ret, start, hwDxy);
0492       pack_into_bits(ret, start, hwQuality);
0493       pack_into_bits(ret, start, hwRedChi2RPhi);
0494       pack_into_bits(ret, start, hwRedChi2RZ);
0495       pack_into_bits(ret, start, hwRedChi2Bend);
0496       pack_into_bits(ret, start, hwStubs);
0497 
0498       return ret;
0499     }
0500 
0501     inline static TkObj unpack_barrel(const ap_uint<BITWIDTH_BARREL> &src) {
0502       TkObj ret;
0503       ret.clear();
0504       unsigned int start = 0;
0505       unpack_from_bits(src, start, ret.hwPt);
0506       unpack_from_bits(src, start, ret.hwEta);
0507       unpack_from_bits(src, start, ret.hwPhi);
0508       unpack_from_bits(src, start, ret.hwDEta);
0509       unpack_from_bits(src, start, ret.hwDPhi);
0510       unpack_bool_from_bits(src, start, ret.hwCharge);
0511       unpack_from_bits(src, start, ret.hwZ0);
0512       unpack_from_bits(src, start, ret.hwDxy);
0513       unpack_from_bits(src, start, ret.hwQuality);
0514       unpack_from_bits(src, start, ret.hwRedChi2RPhi);
0515       return ret;
0516     }
0517 
0518     inline static TkObj unpack_endcap(const ap_uint<BITWIDTH_ENDCAP> &src) {
0519       TkObj ret;
0520       ret.clear();
0521       unsigned int start = 0;
0522       unpack_from_bits(src, start, ret.hwPt);
0523       unpack_from_bits(src, start, ret.hwEta);
0524       unpack_from_bits(src, start, ret.hwPhi);
0525       unpack_from_bits(src, start, ret.hwDEta);
0526       unpack_from_bits(src, start, ret.hwDPhi);
0527       unpack_bool_from_bits(src, start, ret.hwCharge);
0528       unpack_from_bits(src, start, ret.hwZ0);
0529       unpack_from_bits(src, start, ret.hwDxy);
0530       unpack_from_bits(src, start, ret.hwQuality);
0531       unpack_from_bits(src, start, ret.hwRedChi2RPhi);
0532       unpack_from_bits(src, start, ret.hwRedChi2RZ);
0533       unpack_from_bits(src, start, ret.hwRedChi2Bend);
0534       unpack_from_bits(src, start, ret.hwStubs);
0535       return ret;
0536     }
0537 
0538     inline ap_uint<BITWIDTH_SLIM> pack_slim() const { return pack_endcap()(BITWIDTH_SLIM - 1, 0); }
0539   };
0540   inline void clear(TkObj &c) { c.clear(); }
0541 
0542   struct MuObj {
0543     pt_t hwPt;
0544     glbeta_t hwEta;   // relative to the region center, at calo
0545     glbphi_t hwPhi;   // relative to the region center, at calo
0546     tkdeta_t hwDEta;  //  vtx - calo
0547     tkdphi_t hwDPhi;  // |vtx - calo| (sign is derived by the charge)
0548     bool hwCharge;    // 1 = positive, 0 = negative
0549     z0_t hwZ0;
0550     dxy_t hwDxy;
0551     ap_uint<3> hwQuality;
0552     glbphi_t hwVtxPhi() const { return hwCharge ? hwPhi + hwDPhi : hwPhi - hwDPhi; }
0553     glbeta_t hwVtxEta() const { return hwEta + hwDEta; }
0554 
0555     inline bool operator==(const MuObj &other) const {
0556       return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwDEta == other.hwDEta &&
0557              hwDPhi == other.hwDPhi && hwZ0 == other.hwZ0 && hwDxy == other.hwDxy && hwCharge == other.hwCharge &&
0558              hwQuality == other.hwQuality;
0559     }
0560 
0561     inline bool operator>(const MuObj &other) const { return hwPt > other.hwPt; }
0562     inline bool operator<(const MuObj &other) const { return hwPt < other.hwPt; }
0563 
0564     inline void clear() {
0565       hwPt = 0;
0566       hwEta = 0;
0567       hwPhi = 0;
0568       hwDEta = 0;
0569       hwDPhi = 0;
0570       hwZ0 = 0;
0571       hwDxy = 0;
0572       hwCharge = false;
0573       hwQuality = 0;
0574     }
0575 
0576     int intPt() const { return Scales::intPt(hwPt); }
0577     int intEta() const { return hwEta.to_int(); }
0578     int intPhi() const { return hwPhi.to_int(); }
0579     int intVtxEta() const { return hwVtxEta().to_int(); }
0580     int intVtxPhi() const { return hwVtxPhi().to_int(); }
0581     int intCharge() const { return hwCharge ? +1 : -1; }
0582     float floatPt() const { return Scales::floatPt(hwPt); }
0583     float floatEta() const { return Scales::floatEta(hwEta); }
0584     float floatPhi() const { return Scales::floatPhi(hwPhi); }
0585     float floatDEta() const { return Scales::floatEta(hwDEta); }
0586     float floatDPhi() const { return Scales::floatPhi(hwDPhi); }
0587     float floatVtxEta() const { return Scales::floatEta(hwVtxEta()); }
0588     float floatVtxPhi() const { return Scales::floatPhi(hwVtxPhi()); }
0589     float floatZ0() const { return Scales::floatZ0(hwZ0); }
0590     float floatDxy() const { return Scales::floatDxy(hwDxy); }
0591 
0592     static const int BITWIDTH = pt_t::width + glbeta_t::width + glbphi_t::width + tkdeta_t::width + tkdphi_t::width +
0593                                 1 + z0_t::width + dxy_t::width + ap_uint<3>::width;
0594     inline ap_uint<BITWIDTH> pack() const {
0595       ap_uint<BITWIDTH> ret;
0596       unsigned int start = 0;
0597       pack_into_bits(ret, start, hwPt);
0598       pack_into_bits(ret, start, hwEta);
0599       pack_into_bits(ret, start, hwPhi);
0600       pack_into_bits(ret, start, hwDEta);
0601       pack_into_bits(ret, start, hwDPhi);
0602       pack_bool_into_bits(ret, start, hwCharge);
0603       pack_into_bits(ret, start, hwZ0);
0604       pack_into_bits(ret, start, hwDxy);
0605       pack_into_bits(ret, start, hwQuality);
0606       return ret;
0607     }
0608     inline static MuObj unpack(const ap_uint<BITWIDTH> &src) {
0609       MuObj ret;
0610       unsigned int start = 0;
0611       unpack_from_bits(src, start, ret.hwPt);
0612       unpack_from_bits(src, start, ret.hwEta);
0613       unpack_from_bits(src, start, ret.hwPhi);
0614       unpack_from_bits(src, start, ret.hwDEta);
0615       unpack_from_bits(src, start, ret.hwDPhi);
0616       unpack_bool_from_bits(src, start, ret.hwCharge);
0617       unpack_from_bits(src, start, ret.hwZ0);
0618       unpack_from_bits(src, start, ret.hwDxy);
0619       unpack_from_bits(src, start, ret.hwQuality);
0620       return ret;
0621     }
0622   };
0623   inline void clear(MuObj &c) { c.clear(); }
0624 
0625   struct PVObj {
0626     z0_t hwZ0;
0627 
0628     inline bool operator==(const PVObj &other) const { return hwZ0 == other.hwZ0; }
0629 
0630     inline void clear() { hwZ0 = 0; }
0631 
0632     float floatZ0() const { return Scales::floatZ0(hwZ0); }
0633 
0634     static const int BITWIDTH = z0_t::width;
0635     inline ap_uint<BITWIDTH> pack() const {
0636       ap_uint<BITWIDTH> ret;
0637       unsigned int start = 0;
0638       pack_into_bits(ret, start, hwZ0);
0639       return ret;
0640     }
0641     inline static PVObj unpack(const ap_uint<BITWIDTH> &src) {
0642       PVObj ret;
0643       unsigned int start = 0;
0644       unpack_from_bits(src, start, ret.hwZ0);
0645       return ret;
0646     }
0647   };
0648   inline void clear(PVObj &c) { c.clear(); }
0649 
0650 }  // namespace l1ct
0651 
0652 #endif