Skip to content

Commit

Permalink
Merge pull request #48 from gpetruc/l1t-sync-firmware-mr12
Browse files Browse the repository at this point in the history
Sync dataformats with correlator common: new layer 2 dataformats
  • Loading branch information
gpetruc authored Mar 17, 2021
2 parents 649ea2f + 7923010 commit 58a8adb
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace l1ct {

typedef ap_ufixed<14, 12, AP_TRN, AP_SAT> pt_t;
typedef ap_ufixed<10, 8, AP_TRN, AP_SAT> pt10_t;
typedef ap_fixed<16, 14, AP_TRN, AP_SAT> dpt_t;
typedef ap_ufixed<28, 24, AP_TRN, AP_SAT> pt2_t;
typedef ap_int<10> eta_t;
Expand Down
57 changes: 57 additions & 0 deletions L1Trigger/Phase2L1ParticleFlow/src/newfirmware/dataformats/jets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef FIRMWARE_dataformats_jets_h
#define FIRMWARE_dataformats_jets_h

#include "datatypes.h"
#include "bit_encoding.h"

namespace l1ct {

struct Jet {
pt_t hwPt;
glbeta_t hwEta;
glbphi_t hwPhi;

inline bool operator==(const Jet &other) const {
return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi;
}

inline bool operator>(const Jet &other) const { return hwPt > other.hwPt; }
inline bool operator<(const Jet &other) const { return hwPt < other.hwPt; }

inline void clear() {
hwPt = 0;
hwEta = 0;
hwPhi = 0;
}

int intPt() const { return Scales::intPt(hwPt); }
int intEta() const { return hwEta.to_int(); }
int intPhi() const { return hwPhi.to_int(); }
float floatPt() const { return Scales::floatPt(hwPt); }
float floatEta() const { return Scales::floatEta(hwEta); }
float floatPhi() const { return Scales::floatPhi(hwPhi); }

static const int BITWIDTH = pt_t::width + glbeta_t::width + glbphi_t::width;
inline ap_uint<BITWIDTH> pack() const {
ap_uint<BITWIDTH> ret;
unsigned int start = 0;
_pack_into_bits(ret, start, hwPt);
_pack_into_bits(ret, start, hwEta);
_pack_into_bits(ret, start, hwPhi);
return ret;
}
inline static Jet unpack(const ap_uint<BITWIDTH> &src) {
Jet ret;
unsigned int start = 0;
_unpack_from_bits(src, start, ret.hwPt);
_unpack_from_bits(src, start, ret.hwEta);
_unpack_from_bits(src, start, ret.hwPhi);
return ret;
}
};

inline void clear(Jet &c) { c.clear(); }

} // namespace l1ct

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ bool l1ct::PFChargedObjEmu::read(std::fstream& from) {
srcTrack = nullptr; // not persistent
srcCluster = nullptr; // not persistent
srcMu = nullptr; // not persistent
srcCand = nullptr; // not persistent
return readObj<PFChargedObj>(from, *this);
}
bool l1ct::PFChargedObjEmu::write(std::fstream& to) const { return writeObj<PFChargedObj>(*this, to); }

bool l1ct::PFNeutralObjEmu::read(std::fstream& from) {
srcCluster = nullptr; // not persistent
srcCand = nullptr; // not persistent
return readObj<PFNeutralObj>(from, *this);
}
bool l1ct::PFNeutralObjEmu::write(std::fstream& to) const { return writeObj<PFNeutralObj>(*this, to); }
Expand All @@ -65,6 +67,7 @@ bool l1ct::PuppiObjEmu::read(std::fstream& from) {
srcTrack = nullptr; // not persistent
srcCluster = nullptr; // not persistent
srcMu = nullptr; // not persistent
srcCand = nullptr; // not persistent
return readObj<PuppiObj>(from, *this);
}
bool l1ct::PuppiObjEmu::write(std::fstream& to) const { return writeObj<PuppiObj>(*this, to); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,27 @@ namespace l1ct {
const l1t::PFCluster *srcCluster;
const l1t::PFTrack *srcTrack;
const l1t::Muon *srcMu;
const l1t::PFCandidate *srcCand;
bool read(std::fstream &from);
bool write(std::fstream &to) const;
void clear() {
PFChargedObj::clear();
srcCluster = nullptr;
srcTrack = nullptr;
srcMu = nullptr;
srcCand = nullptr;
}
};

struct PFNeutralObjEmu : public PFNeutralObj {
const l1t::PFCluster *srcCluster;
const l1t::PFCandidate *srcCand;
bool read(std::fstream &from);
bool write(std::fstream &to) const;
void clear() {
PFNeutralObj::clear();
srcCluster = nullptr;
srcCand = nullptr;
}
};

Expand All @@ -101,31 +105,36 @@ namespace l1ct {
const l1t::PFCluster *srcCluster;
const l1t::PFTrack *srcTrack;
const l1t::Muon *srcMu;
const l1t::PFCandidate *srcCand;
bool read(std::fstream &from);
bool write(std::fstream &to) const;
void clear() {
PuppiObj::clear();
srcCluster = nullptr;
srcTrack = nullptr;
srcMu = nullptr;
srcCand = nullptr;
}
inline void fill(const PFRegionEmu &region, const PFChargedObjEmu &src) {
PuppiObj::fill(region, src);
srcCluster = src.srcCluster;
srcTrack = src.srcTrack;
srcMu = src.srcMu;
srcCand = src.srcCand;
}
inline void fill(const PFRegionEmu &region, const PFNeutralObjEmu &src, pt_t puppiPt, puppiWgt_t puppiWgt) {
PuppiObj::fill(region, src, puppiPt, puppiWgt);
srcCluster = src.srcCluster;
srcTrack = nullptr;
srcMu = nullptr;
srcCand = src.srcCand;
}
inline void fill(const PFRegionEmu &region, const HadCaloObjEmu &src, pt_t puppiPt, puppiWgt_t puppiWgt) {
PuppiObj::fill(region, src, puppiPt, puppiWgt);
srcCluster = src.src;
srcTrack = nullptr;
srcMu = nullptr;
srcCand = nullptr;
}
};

Expand Down
54 changes: 54 additions & 0 deletions L1Trigger/Phase2L1ParticleFlow/src/newfirmware/dataformats/sums.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef FIRMWARE_dataformats_sums_h
#define FIRMWARE_dataformats_sums_h

#include "datatypes.h"
#include "bit_encoding.h"

namespace l1ct {

struct Sum {
pt_t hwPt;
glbphi_t hwPhi;
pt_t hwSumPt;

inline bool operator==(const Sum &other) const {
return hwPt == other.hwPt && hwPhi == other.hwPhi && hwSumPt == other.hwSumPt;
}

inline void clear() {
hwPt = 0;
hwPhi = 0;
hwSumPt = 0;
}

int intPt() const { return Scales::intPt(hwPt); }
int intPhi() const { return hwPhi.to_int(); }
int intSumPt() const { return Scales::intPt(hwSumPt); }
float floatPt() const { return Scales::floatPt(hwPt); }
float floatPhi() const { return Scales::floatPhi(hwPhi); }
float floatSumPt() const { return Scales::floatPt(hwSumPt); }

static const int BITWIDTH = pt_t::width + glbphi_t::width + pt_t::width;
inline ap_uint<BITWIDTH> pack() const {
ap_uint<BITWIDTH> ret;
unsigned int start = 0;
_pack_into_bits(ret, start, hwPt);
_pack_into_bits(ret, start, hwPhi);
_pack_into_bits(ret, start, hwSumPt);
return ret;
}
inline static Sum unpack(const ap_uint<BITWIDTH> &src) {
Sum ret;
unsigned int start = 0;
_unpack_from_bits(src, start, ret.hwPt);
_unpack_from_bits(src, start, ret.hwPhi);
_unpack_from_bits(src, start, ret.hwSumPt);
return ret;
}
};

inline void clear(Sum &c) { c.clear(); }

} // namespace l1ct

#endif
107 changes: 107 additions & 0 deletions L1Trigger/Phase2L1ParticleFlow/src/newfirmware/dataformats/taus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#ifndef FIRMWARE_dataformats_jets_h
#define FIRMWARE_dataformats_jets_h

#include "datatypes.h"
#include "bit_encoding.h"

namespace l1ct {

struct Tau {
typedef ap_uint<2> type_t;
typedef ap_uint<10> rawid_t;
typedef ap_uint<2> lepid_t;

pt_t hwPt;
glbeta_t hwEta;
glbphi_t hwPhi;
pt10_t hwSeedPt;
z0_t hwSeedZ0;
bool hwCharge;
type_t hwType;
rawid_t hwRawId; // will contain isolation or MVA output
lepid_t hwIdVsMu;
lepid_t hwIdVsEle;

inline bool operator==(const Tau &other) const {
return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwSeedPt == other.hwSeedPt &&
hwSeedZ0 == other.hwSeedZ0 && hwCharge == other.hwCharge && hwType == other.hwType &&
hwIsoOrMVA == other.hwIsoOrMVA && hwIdVsMu == other.hwIdVsMu && hwIdVsEle == other.hwIdVsEle;
}

inline bool operator>(const Tau &other) const { return hwPt > other.hwPt; }
inline bool operator<(const Tau &other) const { return hwPt < other.hwPt; }

inline pt10_t hwAbsIso() const {
pt10_t ret;
ret(9, 0) = hwRawId(9, 0);
return ret;
}

inline void setAbsIso(pt10_t absIso) { hwRawId(9, 0) = absIso(9, 0); }

inline void clear() {
hwPt = 0;
hwEta = 0;
hwPhi = 0;
hwSeedPt = 0;
hwSeedZ0 = 0;
hwCharge = 0;
hwType = 0;
hwIsoOrMVA = 0;
hwIdVsMu = 0;
hwIdVsEle = 0;
}

int intPt() const { return Scales::intPt(hwPt); }
int intEta() const { return hwEta.to_int(); }
int intPhi() const { return hwPhi.to_int(); }
int intSeedPt() const { return Scales::intPt(hwSeedPt); }
float floatPt() const { return Scales::floatPt(hwPt); }
float floatEta() const { return Scales::floatEta(hwEta); }
float floatPhi() const { return Scales::floatPhi(hwPhi); }
float floatSeedPt() const { return Scales::floatPt(hwSeedPt); }
float floatSeedZ0() const { return Scales::floatZ0(hwSeedZ0); }
int intCharge() const { return hwCharge ? +1 : -1; }
int pdgId() const { return -15 * intCharge(); }
int intType() const { return hwType.to_int(); }

float floatAbsIso() const { return Scales::floatPt(hwAbsIso()); }

static const int BITWIDTH = pt_t::width + glbeta_t::width + glbphi_t::width + pt10_t::width + z0_t::width + 1 +
type_t::width + rawid_t::width + 2 * lepid_t::width;
inline ap_uint<BITWIDTH> pack() const {
ap_uint<BITWIDTH> ret;
unsigned int start = 0;
_pack_into_bits(ret, start, hwPt);
_pack_into_bits(ret, start, hwEta);
_pack_into_bits(ret, start, hwPhi);
_pack_into_bits(ret, start, hwSeedPt);
_pack_into_bits(ret, start, hwSeedZ0);
_pack_bool_into_bits(ret, start, hwCharge);
_pack_into_bits(ret, start, hwType);
_pack_into_bits(ret, start, hwRawId);
_pack_into_bits(ret, start, hwIdVsMu);
_pack_into_bits(ret, start, hwIdVsEle);
return ret;
}
inline static Tau unpack(const ap_uint<BITWIDTH> &src) {
Tau ret;
unsigned int start = 0;
_unpack_from_bits(src, start, ret.hwPt);
_unpack_from_bits(src, start, ret.hwEta);
_unpack_from_bits(src, start, ret.hwPhi);
_unpack_from_bits(src, start, ret.hwSeedPt);
_unpack_from_bits(src, start, ret.hwSeedZ0);
_unpack_from_bits(src, start, ret.hwType);
_unpack_from_bits(src, start, ret.hwRawId);
_unpack_from_bits(src, start, ret.hwIdVsMu);
_unpack_from_bits(src, start, ret.hwIdVsEle);
return ret;
}
};

inline void clear(Tau &c) { c.clear(); }

} // namespace l1ct

#endif

0 comments on commit 58a8adb

Please sign in to comment.