Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phase2 L1T, Correlator Layer-2 : support emulation of with TMUX18 input + GT interface tweaks #44346

Merged
merged 6 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions DataFormats/L1TParticleFlow/interface/egamma.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ namespace l1ct {
pho.v3.pt = CTtoGT_pt(hwPt);
pho.v3.phi = CTtoGT_phi(hwPhi);
pho.v3.eta = CTtoGT_eta(hwEta);
pho.quality = hwQual;
pho.isolation = hwIso;
pho.qualityFlags = hwQual;
pho.isolationPT = hwIso;
return pho;
}
};
Expand Down Expand Up @@ -166,11 +166,11 @@ namespace l1ct {
ele.v3.pt = CTtoGT_pt(hwPt);
ele.v3.phi = CTtoGT_phi(hwVtxPhi());
ele.v3.eta = CTtoGT_eta(hwVtxEta());
ele.quality = hwQual;
ele.qualityFlags = hwQual;
// NOTE: GT: 0 = positive, 1 = negative, CT: 0 = negative, 1 = positive
ele.charge = !hwCharge;
ele.charge = (!hwCharge) & ele.valid;
ele.z0(l1ct::z0_t::width - 1, 0) = hwZ0(l1ct::z0_t::width - 1, 0);
ele.isolation = hwIso;
ele.isolationPT = hwIso;
return ele;
}
};
Expand Down
24 changes: 12 additions & 12 deletions DataFormats/L1TParticleFlow/interface/gt_datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,19 @@ namespace l1gt {
struct Electron {
valid_t valid;
ThreeVector v3;
egquality_t quality;
egquality_t qualityFlags;
ap_uint<1> charge;
z0_t z0;
iso_t isolation;
iso_t isolationPT;

static const int BITWIDTH = 96;
inline ap_uint<BITWIDTH> pack() const {
ap_uint<BITWIDTH> ret(0);
unsigned int start = 0;
pack_into_bits(ret, start, valid);
pack_into_bits(ret, start, v3.pack());
pack_into_bits(ret, start, quality);
pack_into_bits(ret, start, isolation);
pack_into_bits(ret, start, qualityFlags);
pack_into_bits(ret, start, isolationPT);
pack_into_bits(ret, start, charge);
pack_into_bits(ret, start, z0);
return ret;
Expand All @@ -281,8 +281,8 @@ namespace l1gt {
unpack_from_bits(src, start, v3.pt);
unpack_from_bits(src, start, v3.phi);
unpack_from_bits(src, start, v3.eta);
unpack_from_bits(src, start, quality);
unpack_from_bits(src, start, isolation);
unpack_from_bits(src, start, qualityFlags);
unpack_from_bits(src, start, isolationPT);
unpack_from_bits(src, start, charge);
unpack_from_bits(src, start, z0);
}
Expand All @@ -309,17 +309,17 @@ namespace l1gt {
struct Photon {
valid_t valid;
ThreeVector v3;
egquality_t quality;
iso_t isolation;
egquality_t qualityFlags;
iso_t isolationPT;

static const int BITWIDTH = 96;
inline ap_uint<BITWIDTH> pack() const {
ap_uint<96> ret(0);
unsigned int start = 0;
pack_into_bits(ret, start, valid);
pack_into_bits(ret, start, v3.pack());
pack_into_bits(ret, start, quality);
pack_into_bits(ret, start, isolation);
pack_into_bits(ret, start, qualityFlags);
pack_into_bits(ret, start, isolationPT);
return ret;
}

Expand All @@ -329,8 +329,8 @@ namespace l1gt {
unpack_from_bits(src, start, v3.pt);
unpack_from_bits(src, start, v3.phi);
unpack_from_bits(src, start, v3.eta);
unpack_from_bits(src, start, quality);
unpack_from_bits(src, start, isolation);
unpack_from_bits(src, start, qualityFlags);
unpack_from_bits(src, start, isolationPT);
}

inline static Photon unpack_ap(const ap_uint<BITWIDTH> &src) {
Expand Down
12 changes: 6 additions & 6 deletions L1Trigger/Phase2L1GT/plugins/L1GTProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ namespace l1t {
std::unique_ptr<P2GTCandidateCollection> outputCollection = std::make_unique<P2GTCandidateCollection>();
const TkEmCollection &collection = event.get(cl2PhotonToken_);
for (size_t i = 0; i < collection.size() && i < 12; i++) {
l1gt::Photon gtPhoton = l1gt::Photon::unpack_ap(const_cast<TkEm &>(collection[i]).egBinaryWord<96>());
l1gt::Photon gtPhoton = collection[i].hwObj();
P2GTCandidate gtObj(0,
reco::ParticleState::PolarLorentzVector(scales_.to_pT(gtPhoton.v3.pt.V.to_int()),
scales_.to_eta(gtPhoton.v3.eta.V.to_int()),
Expand All @@ -319,8 +319,8 @@ namespace l1t {
gtObj.hwPT_ = gtPhoton.v3.pt.V.to_int();
gtObj.hwPhi_ = gtPhoton.v3.phi.V.to_int();
gtObj.hwEta_ = gtPhoton.v3.eta.V.to_int();
gtObj.hwIso_ = gtPhoton.isolation.V.to_int();
gtObj.hwQual_ = gtPhoton.quality.V.to_int();
gtObj.hwIso_ = gtPhoton.isolationPT.V.to_int();
gtObj.hwQual_ = gtPhoton.qualityFlags.V.to_int();
gtObj.objectType_ = P2GTCandidate::CL2Photons;

outputCollection->push_back(gtObj);
Expand All @@ -332,7 +332,7 @@ namespace l1t {
std::unique_ptr<P2GTCandidateCollection> outputCollection = std::make_unique<P2GTCandidateCollection>();
const TkElectronCollection &collection = event.get(cl2ElectronToken_);
for (size_t i = 0; i < collection.size() && i < 12; i++) {
l1gt::Electron gtElectron = l1gt::Electron::unpack_ap(const_cast<TkElectron &>(collection[i]).egBinaryWord<96>());
l1gt::Electron gtElectron = collection[i].hwObj();
int hwZ0 = gtElectron.z0.V.to_int() << 7;
P2GTCandidate gtObj(scales_.to_chg(gtElectron.charge.V.to_int()),
reco::ParticleState::PolarLorentzVector(scales_.to_pT(gtElectron.v3.pt.V.to_int()),
Expand All @@ -344,8 +344,8 @@ namespace l1t {
gtObj.hwPhi_ = gtElectron.v3.phi.V.to_int();
gtObj.hwEta_ = gtElectron.v3.eta.V.to_int();
gtObj.hwZ0_ = hwZ0;
gtObj.hwIso_ = gtElectron.isolation.V.to_int();
gtObj.hwQual_ = gtElectron.quality.V.to_int();
gtObj.hwIso_ = gtElectron.isolationPT.V.to_int();
gtObj.hwQual_ = gtElectron.qualityFlags.V.to_int();
gtObj.hwCharge_ = gtElectron.charge.V.to_int();
gtObj.objectType_ = P2GTCandidate::CL2Electrons;

Expand Down
55 changes: 27 additions & 28 deletions L1Trigger/Phase2L1ParticleFlow/interface/egamma/l2egsorter_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ namespace l1ct {

class L2EgSorterEmulator {
public:
L2EgSorterEmulator(unsigned int nBoards, unsigned int nEGPerBoard, unsigned int nEGOut, bool debug)
: nBOARDS(nBoards), nEGPerBoard(nEGPerBoard), nEGOut(nEGOut), debug_(debug) {}
L2EgSorterEmulator(unsigned int nRegions, unsigned int nEGPerRegion, unsigned int nEGOut, bool debug)
: nREGIONS(nRegions), nEGPerRegion(nEGPerRegion), nEGOut(nEGOut), debug_(debug) {}

L2EgSorterEmulator(const edm::ParameterSet &iConfig);

virtual ~L2EgSorterEmulator() {}

template <int NBoards, int NObjs>
template <int NRegions, int NObjs>
void toFirmware(const std::vector<l1ct::OutputBoard> &in,
EGIsoObj (&photons_in)[NBoards][NObjs],
EGIsoEleObj (&eles_in)[NBoards][NObjs]) const {
for (unsigned int ib = 0; ib < NBoards; ib++) {
const auto &board = in[ib];
EGIsoObj (&photons_in)[NRegions][NObjs],
EGIsoEleObj (&eles_in)[NRegions][NObjs]) const {
for (unsigned int ib = 0; ib < NRegions; ib++) {
const auto &region = in[ib];
for (unsigned int io = 0; io < NObjs; io++) {
EGIsoObj pho;
EGIsoEleObj ele;
if (io < board.egphoton.size())
pho = board.egphoton[io];
if (io < region.egphoton.size())
pho = region.egphoton[io];
else
pho.clear();
if (io < board.egelectron.size())
ele = board.egelectron[io];
if (io < region.egelectron.size())
ele = region.egelectron[io];
else
ele.clear();

Expand All @@ -59,17 +59,17 @@ namespace l1ct {

void setDebug(int verbose) { debug_ = verbose; }

unsigned int nInputBoards() const { return nBOARDS; }
unsigned int nInputObjPerBoard() const { return nEGPerBoard; }
unsigned int nInputRegions() const { return nREGIONS; }
unsigned int nInputObjPerRegion() const { return nEGPerRegion; }
unsigned int nOutputObj() const { return nEGOut; }

private:
template <typename T>
void resize_input(std::vector<T> &in) const {
if (in.size() > nEGPerBoard) {
in.resize(nEGPerBoard);
} else if (in.size() < nEGPerBoard) {
for (unsigned int i = 0, diff = (nEGPerBoard - in.size()); i < diff; ++i) {
if (in.size() > nEGPerRegion) {
in.resize(nEGPerRegion);
} else if (in.size() < nEGPerRegion) {
for (unsigned int i = 0, diff = (nEGPerRegion - in.size()); i < diff; ++i) {
in.push_back(T());
in.back().clear();
}
Expand All @@ -90,17 +90,16 @@ namespace l1ct {
}

template <typename T>
void merge_boards(const std::vector<T> &in_board1,
const std::vector<T> &in_board2,
std::vector<T> &out,
unsigned int nOut) const {
void merge_regions(const std::vector<T> &in_region1,
const std::vector<T> &in_region2,
std::vector<T> &out,
unsigned int nOut) const {
// we crate a bitonic list
out = in_board1;
out = in_region1;
std::reverse(out.begin(), out.end());
std::copy(in_board2.begin(), in_board2.end(), std::back_inserter(out));
std::copy(in_region2.begin(), in_region2.end(), std::back_inserter(out));
hybridBitonicMergeRef(&out[0], out.size(), 0, false);

// std::merge(in_board1.begin(), in_board1.end(), in_board2_copy.begin(), in_board2_copy.end(), std::back_inserter(out), comparePt<T>);
if (out.size() > nOut)
out.resize(nOut);
}
Expand All @@ -112,24 +111,24 @@ namespace l1ct {
if (out.size() > nEGOut)
out.resize(nEGOut);
} else if (in_objs.size() == 2) {
merge_boards(in_objs[0], in_objs[1], out, nEGOut);
merge_regions(in_objs[0], in_objs[1], out, nEGOut);
} else {
std::vector<std::vector<T>> to_merge;
for (unsigned int id = 0, idn = 1; id < in_objs.size(); id += 2, idn = id + 1) {
if (idn >= in_objs.size()) {
to_merge.push_back(in_objs[id]);
} else {
std::vector<T> pair_merge;
merge_boards(in_objs[id], in_objs[idn], pair_merge, nEGPerBoard);
merge_regions(in_objs[id], in_objs[idn], pair_merge, nEGPerRegion);
to_merge.push_back(pair_merge);
}
}
merge(to_merge, out);
}
}

const unsigned int nBOARDS;
const unsigned int nEGPerBoard;
const unsigned int nREGIONS;
const unsigned int nEGPerRegion;
const unsigned int nEGOut;
int debug_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ void L1TCorrelatorLayer1Producer::putEgObjects(edm::Event &iEvent,
tkele.setEgBinaryWord(egele.pack(), l1t::TkElectron::HWEncoding::CT);
tkele.setIdScore(egele.floatIDScore());
tkele.setCharge(egele.intCharge());
tkele.setTrkzVtx(egele.floatZ0());
tkeles->push_back(tkele);
nele_obj.push_back(tkeles->size() - 1);
}
Expand Down
Loading