Skip to content

Commit

Permalink
Change naming to match TM18 and TM16 input logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cerminar committed Nov 23, 2023
1 parent 2f68970 commit 735f23d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 40 deletions.
51 changes: 25 additions & 26 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,
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
4 changes: 2 additions & 2 deletions L1Trigger/Phase2L1ParticleFlow/plugins/L1TCtL2EgProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void L1TCtL2EgProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::Ev
merge(tkEGInputs_, iEvent, constituents, outEgs);
iEvent.put(std::move(outEgs), tkEGInstanceLabel_);

auto regions = std::make_unique<std::vector<l1ct::OutputBoard>>(l2egsorter.nInputBoards());
auto regions = std::make_unique<std::vector<l1ct::OutputBoard>>(l2egsorter.nInputRegions());

merge(tkEleInputs_, iEvent, constituents, regions);
merge(tkEmInputs_, iEvent, constituents, regions);
Expand All @@ -326,7 +326,7 @@ void L1TCtL2EgProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::Ev

if (inData.has(linkData.linkId))
data = inData.at(linkData.linkId);
encodeLayer1EgObjs(l2egsorter.nInputObjPerBoard(), data, (*regions)[ireg].egphoton, (*regions)[ireg].egelectron);
encodeLayer1EgObjs(l2egsorter.nInputObjPerRegion(), data, (*regions)[ireg].egphoton, (*regions)[ireg].egelectron);
data.resize(data.size() + linkData.nTrailingWords, {0});
inData.add(linkData.linkId, data);
}
Expand Down
4 changes: 2 additions & 2 deletions L1Trigger/Phase2L1ParticleFlow/python/l1ctLayer2EG_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
tkEmInstanceLabel=cms.string("L1CtTkEm"),
tkEleInstanceLabel=cms.string("L1CtTkElectron"),
sorter=cms.PSet(
nBOARDS=cms.uint32(5),
nEGPerBoard=cms.uint32(16),
nREGIONS=cms.uint32(5),
nEGPerRegion=cms.uint32(16),
nEGOut=cms.uint32(12),
debug=cms.untracked.uint32(0),
),
Expand Down
20 changes: 10 additions & 10 deletions L1Trigger/Phase2L1ParticleFlow/src/egamma/l2egsorter_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ using namespace l1ct;
#include "FWCore/ParameterSet/interface/ParameterSet.h"

l1ct::L2EgSorterEmulator::L2EgSorterEmulator(const edm::ParameterSet &pset)
: L2EgSorterEmulator(pset.getParameter<uint32_t>("nBOARDS"),
pset.getParameter<uint32_t>("nEGPerBoard"),
: L2EgSorterEmulator(pset.getParameter<uint32_t>("nREGIONS"),
pset.getParameter<uint32_t>("nEGPerRegion"),
pset.getParameter<uint32_t>("nEGOut"),
pset.getUntrackedParameter<uint32_t>("debug", 0)) {}
#endif
Expand Down Expand Up @@ -43,11 +43,11 @@ void L2EgSorterEmulator::run(const std::vector<l1ct::OutputBoard> &in,
std::vector<EGIsoObjEmu> &out_photons,
std::vector<EGIsoEleObjEmu> &out_eles) const {
if (debug_) {
unsigned int board_n = 0;
for (const auto &board : in) {
dbgCout() << "BOARD " << board_n++ << std::endl;
print_objects(board.egphoton, "photon_in");
print_objects(board.egelectron, "electron_in");
unsigned int region_n = 0;
for (const auto &region : in) {
dbgCout() << "REGION " << region_n++ << std::endl;
print_objects(region.egphoton, "photon_in");
print_objects(region.egelectron, "electron_in");
}
}

Expand All @@ -56,9 +56,9 @@ void L2EgSorterEmulator::run(const std::vector<l1ct::OutputBoard> &in,
std::vector<std::vector<EGIsoEleObjEmu>> eles_in;
photons_in.reserve(in.size());
eles_in.reserve(in.size());
for (const auto &board : in) {
std::vector<EGIsoObjEmu> photons = board.egphoton;
std::vector<EGIsoEleObjEmu> eles = board.egelectron;
for (const auto &region : in) {
std::vector<EGIsoObjEmu> photons = region.egphoton;
std::vector<EGIsoEleObjEmu> eles = region.egelectron;
resize_input(photons);
resize_input(eles);

Expand Down

0 comments on commit 735f23d

Please sign in to comment.