diff --git a/DataFormats/L1TParticleFlow/interface/datatypes.h b/DataFormats/L1TParticleFlow/interface/datatypes.h index c9101348b2ef5..39d938d6d025d 100644 --- a/DataFormats/L1TParticleFlow/interface/datatypes.h +++ b/DataFormats/L1TParticleFlow/interface/datatypes.h @@ -1,15 +1,6 @@ #ifndef DataFormats_L1TParticleFlow_datatypes_h #define DataFormats_L1TParticleFlow_datatypes_h -#if (!defined(__CLANG__)) && defined(__GNUC__) && defined(CMSSW_GIT_HASH) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wuninitialized" -#endif -#include -#if (!defined(__CLANG__)) && defined(__GNUC__) && defined(CMSSW_GIT_HASH) -#pragma GCC diagnostic pop -#endif - #include #include #include @@ -162,8 +153,14 @@ namespace l1ct { inline float floatPt(pt_t pt) { return pt.to_float(); } inline float floatPt(dpt_t pt) { return pt.to_float(); } inline float floatPt(pt2_t pt2) { return pt2.to_float(); } - inline int intPt(pt_t pt) { return (ap_ufixed<16, 14>(pt) << 2).to_int(); } - inline int intPt(dpt_t pt) { return (ap_fixed<18, 16>(pt) << 2).to_int(); } + inline int intPt(pt_t pt) { + ap_uint rawPt = pt.range(); + return rawPt.to_int(); + } + inline int intPt(dpt_t pt) { + ap_int rawPt = pt.range(); + return rawPt.to_int(); + } inline float floatEta(eta_t eta) { return eta.to_float() * ETAPHI_LSB; } inline float floatPhi(phi_t phi) { return phi.to_float() * ETAPHI_LSB; } inline float floatEta(tkdeta_t eta) { return eta.to_float() * ETAPHI_LSB; } @@ -181,9 +178,9 @@ namespace l1ct { inline pt_t makePt(int pt) { return ap_ufixed<16, 14>(pt) >> 2; } inline dpt_t makeDPt(int dpt) { return ap_fixed<18, 16>(dpt) >> 2; } - inline pt_t makePtFromFloat(float pt) { return pt_t(0.25 * round(pt * 4)); } + inline pt_t makePtFromFloat(float pt) { return pt_t(0.25 * std::round(pt * 4)); } inline dpt_t makeDPtFromFloat(float dpt) { return dpt_t(dpt); } - inline z0_t makeZ0(float z0) { return z0_t(round(z0 / Z0_LSB)); } + inline z0_t makeZ0(float z0) { return z0_t(std::round(z0 / Z0_LSB)); } inline ap_uint ptToInt(pt_t pt) { // note: this can be synthethized, e.g. when pT is used as intex in a LUT @@ -216,7 +213,7 @@ namespace l1ct { inline float maxAbsPhi() { return ((1 << (phi_t::width - 1)) - 1) * ETAPHI_LSB; } inline float maxAbsGlbEta() { return ((1 << (glbeta_t::width - 1)) - 1) * ETAPHI_LSB; } inline float maxAbsGlbPhi() { return ((1 << (glbphi_t::width - 1)) - 1) * ETAPHI_LSB; } - }; // namespace Scales + } // namespace Scales inline int dr2_int(eta_t eta1, phi_t phi1, eta_t eta2, phi_t phi2) { ap_int deta = (eta1 - eta2); diff --git a/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/buffered_folded_multififo_regionizer_ref.h b/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/buffered_folded_multififo_regionizer_ref.h index 9e171a75cfd6a..8e446691aa2fe 100644 --- a/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/buffered_folded_multififo_regionizer_ref.h +++ b/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/buffered_folded_multififo_regionizer_ref.h @@ -6,38 +6,6 @@ #include #include -namespace l1ct { - namespace multififo_regionizer { - template - inline bool local_eta_window(const T& t, const l1ct::glbeta_t& etaMin, const l1ct::glbeta_t& etaMax); - template <> - inline bool local_eta_window(const l1ct::TkObjEmu& t, - const l1ct::glbeta_t& etaMin, - const l1ct::glbeta_t& etaMax); - - template - class EtaBuffer { - public: - EtaBuffer() {} - EtaBuffer(unsigned int maxitems, const l1ct::glbeta_t& etaMin = 0, const l1ct::glbeta_t& etaMax = 0) - : size_(maxitems), iwrite_(0), iread_(0), etaMin_(etaMin), etaMax_(etaMax) {} - void maybe_push(const T& t); - void writeNewEvent() { - iwrite_ = 1 - iwrite_; - items_[iwrite_].clear(); - } - void readNewEvent() { iread_ = 1 - iread_; } - T pop(); - unsigned int writeSize() const { return items_[iwrite_].size(); } - unsigned int readSize() const { return items_[iread_].size(); } - - private: - unsigned int size_, iwrite_, iread_; - l1ct::glbeta_t etaMin_, etaMax_; - std::deque items_[2]; - }; - } // namespace multififo_regionizer -} // namespace l1ct namespace l1ct { class BufferedFoldedMultififoRegionizerEmulator : public FoldedMultififoRegionizerEmulator { public: @@ -88,9 +56,9 @@ namespace l1ct { } protected: - std::vector> tkBuffers_; - std::vector> caloBuffers_; - std::vector> muBuffers_; + std::vector> tkBuffers_; + std::vector> caloBuffers_; + std::vector> muBuffers_; void findEtaBounds_(const l1ct::PFRegionEmu& sec, const std::vector& reg, @@ -106,41 +74,4 @@ namespace l1ct { }; } // namespace l1ct -template -inline bool l1ct::multififo_regionizer::local_eta_window(const T& t, - const l1ct::glbeta_t& etaMin, - const l1ct::glbeta_t& etaMax) { - return (etaMin == etaMax) || (etaMin <= t.hwEta && t.hwEta <= etaMax); -} -template <> -inline bool l1ct::multififo_regionizer::local_eta_window(const l1ct::TkObjEmu& t, - const l1ct::glbeta_t& etaMin, - const l1ct::glbeta_t& etaMax) { - return (etaMin == etaMax) || (etaMin <= t.hwEta && t.hwEta <= etaMax) || - (etaMin <= t.hwVtxEta() && t.hwVtxEta() <= etaMax); -} -template -void l1ct::multififo_regionizer::EtaBuffer::maybe_push(const T& t) { - if ((t.hwPt != 0) && local_eta_window(t, etaMin_, etaMax_)) { - if (items_[iwrite_].size() < size_) { - items_[iwrite_].push_back(t); - } else { - // uncommenting the message below may be useful for debugging - //dbgCout() << "WARNING: sector buffer is full for " << typeid(T).name() << ", pt = " << t.intPt() - // << ", eta = " << t.intEta() << ", phi = " << t.intPhi() << "\n"; - } - } -} - -template -T l1ct::multififo_regionizer::EtaBuffer::pop() { - T ret; - ret.clear(); - if (!items_[iread_].empty()) { - ret = items_[iread_].front(); - items_[iread_].pop_front(); - } - return ret; -} - #endif diff --git a/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/middle_buffer_multififo_regionizer_ref.h b/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/middle_buffer_multififo_regionizer_ref.h new file mode 100644 index 0000000000000..b53d34f05a6f3 --- /dev/null +++ b/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/middle_buffer_multififo_regionizer_ref.h @@ -0,0 +1,125 @@ +#ifndef middle_buffer_multififo_regionizer_ref_h +#define middle_buffer_multififo_regionizer_ref_h + +#include "L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_ref.h" +#include "L1Trigger/Phase2L1ParticleFlow/interface/dbgPrintf.h" +#include +#include + +namespace l1ct { + class MiddleBufferMultififoRegionizerEmulator : public RegionizerEmulator { + public: + MiddleBufferMultififoRegionizerEmulator(unsigned int nclocks, + unsigned int nbuffers, + unsigned int etabufferDepth, + unsigned int ntklinks, + unsigned int nHCalLinks, + unsigned int nECalLinks, + unsigned int ntk, + unsigned int ncalo, + unsigned int nem, + unsigned int nmu, + bool streaming, + unsigned int outii, + unsigned int pauseii, + bool useAlsoVtxCoords); + // note: this one will work only in CMSSW + MiddleBufferMultififoRegionizerEmulator(const edm::ParameterSet& iConfig); + + ~MiddleBufferMultififoRegionizerEmulator() override; + + static edm::ParameterSetDescription getParameterSetDescription(); + + void initSectorsAndRegions(const RegionizerDecodedInputs& in, const std::vector& out) override; + + void run(const RegionizerDecodedInputs& in, std::vector& out) override; + + // link emulation from decoded inputs (for simulation) + void fillLinks(unsigned int iclock, + const RegionizerDecodedInputs& in, + std::vector& links, + std::vector& valid); + void fillLinks(unsigned int iclock, + const RegionizerDecodedInputs& in, + std::vector& links, + std::vector& valid); + void fillLinks(unsigned int iclock, + const RegionizerDecodedInputs& in, + std::vector& links, + std::vector& valid); + void fillLinks(unsigned int iclock, + const RegionizerDecodedInputs& in, + std::vector& links, + std::vector& valid); + template + void fillLinks(unsigned int iclock, const RegionizerDecodedInputs& in, std::vector& links) { + std::vector unused; + fillLinks(iclock, in, links, unused); + } + + void destream(int iclock, + const std::vector& tk_out, + const std::vector& em_out, + const std::vector& calo_out, + const std::vector& mu_out, + PFInputRegion& out); + + // clock-cycle emulation + bool step(bool newEvent, + const std::vector& links_tk, + const std::vector& links_hadCalo, + const std::vector& links_emCalo, + const std::vector& links_mu, + std::vector& out_tk, + std::vector& out_hadCalo, + std::vector& out_emCalo, + std::vector& out_mu, + bool /*unused*/); + + template + void toFirmware(const std::vector& emu, TFw fw[]) { + for (unsigned int i = 0, n = emu.size(); i < n; ++i) { + fw[i] = emu[i]; + } + } + + void reset(); + + protected: + const unsigned int NTK_SECTORS, NCALO_SECTORS; + const unsigned int NTK_LINKS, HCAL_LINKS, ECAL_LINKS, NMU_LINKS; + unsigned int nclocks_, nbuffers_, etabuffer_depth_, ntk_, ncalo_, nem_, nmu_, outii_, pauseii_, nregions_pre_, + nregions_post_; + bool streaming_; + bool init_; + unsigned int iclock_; + std::vector mergedRegions_, outputRegions_; + multififo_regionizer::Regionizer tkRegionizerPre_, tkRegionizerPost_; + multififo_regionizer::Regionizer hadCaloRegionizerPre_, hadCaloRegionizerPost_; + multififo_regionizer::Regionizer emCaloRegionizerPre_, emCaloRegionizerPost_; + multififo_regionizer::Regionizer muRegionizerPre_, muRegionizerPost_; + std::vector tkRoutes_, caloRoutes_, emCaloRoutes_, muRoutes_; + std::vector> tkBuffers_; + std::vector> hadCaloBuffers_; + std::vector> emCaloBuffers_; + std::vector> muBuffers_; + + template + void fillCaloLinks_(unsigned int iclock, + const std::vector>& in, + std::vector& links, + std::vector& valid); + + void fillSharedCaloLinks(unsigned int iclock, + const std::vector>& em_in, + const std::vector>& had_in, + std::vector& links, + std::vector& valid); + + void encode(const l1ct::EmCaloObjEmu& from, l1ct::HadCaloObjEmu& to); + void encode(const l1ct::HadCaloObjEmu& from, l1ct::HadCaloObjEmu& to); + void decode(l1ct::HadCaloObjEmu& had, l1ct::EmCaloObjEmu& em); + }; +} // namespace l1ct + +#endif diff --git a/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_elements_ref.h b/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_elements_ref.h index 91d36a366a1ae..0d7adcf55fe30 100644 --- a/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_elements_ref.h +++ b/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_elements_ref.h @@ -5,6 +5,7 @@ #include #include +#include #include namespace l1ct { @@ -76,6 +77,60 @@ namespace l1ct { T pop_queue_(std::vector& queue); }; + template + inline bool local_eta_phi_window(const T& t, + const l1ct::glbeta_t& etaMin, + const l1ct::glbeta_t& etaMax, + const l1ct::glbphi_t& phiMin, + const l1ct::glbphi_t& phiMax); + template <> + inline bool local_eta_phi_window(const l1ct::TkObjEmu& t, + const l1ct::glbeta_t& etaMin, + const l1ct::glbeta_t& etaMax, + const l1ct::glbphi_t& phiMin, + const l1ct::glbphi_t& phiMax); + + template + class EtaPhiBuffer { + public: + EtaPhiBuffer() {} + EtaPhiBuffer(unsigned int maxitems, + const l1ct::glbeta_t& etaMin = 0, + const l1ct::glbeta_t& etaMax = 0, + const l1ct::glbeta_t& etaShift = 0, + const l1ct::glbphi_t& phiMin = 0, + const l1ct::glbphi_t& phiMax = 0, + const l1ct::glbphi_t& phiShift = 0) + : size_(maxitems), + iwrite_(0), + iread_(0), + etaMin_(etaMin), + etaMax_(etaMax), + etaShift_(etaShift), + phiMin_(phiMin), + phiMax_(phiMax), + phiShift_(phiShift) {} + void maybe_push(const T& t); + void writeNewEvent() { + iwrite_ = 1 - iwrite_; + items_[iwrite_].clear(); + } + void readNewEvent() { iread_ = 1 - iread_; } + T pop(); + unsigned int writeSize() const { return items_[iwrite_].size(); } + unsigned int readSize() const { return items_[iread_].size(); } + unsigned int maxSize() const { return size_; } + void reset(); + + private: + unsigned int size_, iwrite_, iread_; + l1ct::glbeta_t etaMin_, etaMax_; + l1ct::glbeta_t etaShift_; + l1ct::glbphi_t phiMin_, phiMax_; + l1ct::glbphi_t phiShift_; + std::deque items_[2]; + }; + // forward decl for later template class RegionMux; @@ -183,4 +238,57 @@ namespace l1ct { } // namespace multififo_regionizer } // namespace l1ct +template +inline bool l1ct::multififo_regionizer::local_eta_phi_window(const T& t, + const l1ct::glbeta_t& etaMin, + const l1ct::glbeta_t& etaMax, + const l1ct::glbphi_t& phiMin, + const l1ct::glbphi_t& phiMax) { + return (etaMin == etaMax) || + (etaMin <= t.hwEta && t.hwEta <= etaMax && ((phiMin == phiMax) || (phiMin <= t.hwPhi && t.hwPhi <= phiMax))); +} +template <> +inline bool l1ct::multififo_regionizer::local_eta_phi_window(const l1ct::TkObjEmu& t, + const l1ct::glbeta_t& etaMin, + const l1ct::glbeta_t& etaMax, + const l1ct::glbphi_t& phiMin, + const l1ct::glbphi_t& phiMax) { + return (etaMin == etaMax) || + (etaMin <= t.hwEta && t.hwEta <= etaMax && ((phiMin == phiMax) || (phiMin <= t.hwPhi && t.hwPhi <= phiMax))) || + (etaMin <= t.hwVtxEta() && t.hwVtxEta() <= etaMax && + ((phiMin == phiMax) || (phiMin <= t.hwVtxPhi() && t.hwVtxPhi() <= phiMax))); +} +template +void l1ct::multififo_regionizer::EtaPhiBuffer::maybe_push(const T& t) { + if ((t.hwPt != 0) && local_eta_phi_window(t, etaMin_, etaMax_, phiMin_, phiMax_)) { + if (items_[iwrite_].size() < size_) { + items_[iwrite_].push_back(t); + items_[iwrite_].back().hwEta += etaShift_; + items_[iwrite_].back().hwPhi += phiShift_; + } else { + // uncommenting the message below may be useful for debugging + //dbgCout() << "WARNING: sector buffer is full for " << typeid(T).name() << ", pt = " << t.intPt() + // << ", eta = " << t.intEta() << ", phi = " << t.intPhi() << "\n"; + } + } +} + +template +T l1ct::multififo_regionizer::EtaPhiBuffer::pop() { + T ret; + ret.clear(); + if (!items_[iread_].empty()) { + ret = items_[iread_].front(); + items_[iread_].pop_front(); + } + return ret; +} +template +void l1ct::multififo_regionizer::EtaPhiBuffer::reset() { + iread_ = 0; + iwrite_ = 0; + items_[0].clear(); + items_[1].clear(); +} + #endif diff --git a/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_elements_ref.icc b/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_elements_ref.icc index 66b0538ac38fe..a884ed2f91780 100644 --- a/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_elements_ref.icc +++ b/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_elements_ref.icc @@ -41,6 +41,11 @@ void l1ct::multififo_regionizer::maybe_push(const l1ct::TkObjEmu template void l1ct::multififo_regionizer::RegionBuffer::initFifos(unsigned int nfifos) { assert(nfifos_ == 0); + bool isGood = + (nfifos == 1 || nfifos == 2 || nfifos == 3 || nfifos == 4 || nfifos == 6 || nfifos == 8 || nfifos == 12); + if (!isGood) { + dbgCerr() << "Error, created regionizer for nfifos == " << nfifos << ", not supported." << std::endl; + } nfifos_ = nfifos; fifos_.resize(nfifos); unsigned int nmerged = nfifos; @@ -53,11 +58,6 @@ void l1ct::multififo_regionizer::RegionBuffer::initFifos(unsigned int nfifos) for (auto& t : queues_.back().second) t.clear(); } - bool isGood = - (nfifos == 1 || nfifos == 2 || nfifos == 3 || nfifos == 4 || nfifos == 6 || nfifos == 8 || nfifos == 12); - if (!isGood) { - dbgCerr() << "Error, created regionizer for nfifos == " << nfifos << ", not supported." << std::endl; - } assert(isGood); } diff --git a/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_ref.h b/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_ref.h index d2b6bbce52b72..965f87dbadcdf 100644 --- a/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_ref.h +++ b/L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_ref.h @@ -34,6 +34,7 @@ namespace l1ct { enum class BarrelSetup { Full54, Full27, Central18, Central9, Phi18, Phi9 }; MultififoRegionizerEmulator(BarrelSetup barrelSetup, + unsigned int ntklinks, unsigned int nHCalLinks, unsigned int nECalLinks, unsigned int nclocks, diff --git a/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCorrelatorLayer1Producer.cc b/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCorrelatorLayer1Producer.cc index 155437be33466..38e8222dab630 100644 --- a/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCorrelatorLayer1Producer.cc +++ b/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCorrelatorLayer1Producer.cc @@ -28,6 +28,7 @@ #include "L1Trigger/Phase2L1ParticleFlow/interface/regionizer/regionizer_base_ref.h" #include "L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_ref.h" #include "L1Trigger/Phase2L1ParticleFlow/interface/regionizer/buffered_folded_multififo_regionizer_ref.h" +#include "L1Trigger/Phase2L1ParticleFlow/interface/regionizer/middle_buffer_multififo_regionizer_ref.h" #include "L1Trigger/Phase2L1ParticleFlow/interface/regionizer/tdr_regionizer_ref.h" #include "L1Trigger/Phase2L1ParticleFlow/interface/pf/pfalgo2hgc_ref.h" #include "L1Trigger/Phase2L1ParticleFlow/interface/pf/pfalgo3_ref.h" @@ -265,6 +266,9 @@ L1TCorrelatorLayer1Producer::L1TCorrelatorLayer1Producer(const edm::ParameterSet const auto &pset = iConfig.getParameter("regionizerAlgoParameters"); regionizer_ = std::make_unique(pset.getParameter("barrelSetup"), pset); + } else if (regalgo == "MiddleBufferMultififo") { + regionizer_ = std::make_unique( + iConfig.getParameter("regionizerAlgoParameters")); } else if (regalgo == "TDR") { regionizer_ = std::make_unique( iConfig.getParameter("regionizerAlgoParameters")); @@ -367,9 +371,11 @@ void L1TCorrelatorLayer1Producer::fillDescriptions(edm::ConfigurationDescription auto bfMultififoRegPD = getParDesc("regionizerAlgo"); auto multififoBarrelRegPD = edm::ParameterDescription( "regionizerAlgoParameters", l1ct::MultififoRegionizerEmulator::getParameterSetDescriptionBarrel(), true); + auto mbMultififoRegPD = getParDesc("regionizerAlgo"); desc.ifValue(edm::ParameterDescription("regionizerAlgo", "Ideal", true), "Ideal" >> idealRegPD or "TDR" >> tdrRegPD or "Multififo" >> multififoRegPD or - "BufferedFoldedMultififo" >> bfMultififoRegPD or "MultififoBarrel" >> multififoBarrelRegPD); + "BufferedFoldedMultififo" >> bfMultififoRegPD or "MultififoBarrel" >> multififoBarrelRegPD or + "MiddleBufferMultififo" >> mbMultififoRegPD); // PF desc.ifValue(edm::ParameterDescription("pfAlgo", "PFAlgo3", true), "PFAlgo3" >> getParDesc("pfAlgo") or diff --git a/L1Trigger/Phase2L1ParticleFlow/src/regionizer/buffered_folded_multififo_regionizer_ref.cpp b/L1Trigger/Phase2L1ParticleFlow/src/regionizer/buffered_folded_multififo_regionizer_ref.cpp index 9717416c15b0d..9f1e9ca3f8bcf 100644 --- a/L1Trigger/Phase2L1ParticleFlow/src/regionizer/buffered_folded_multififo_regionizer_ref.cpp +++ b/L1Trigger/Phase2L1ParticleFlow/src/regionizer/buffered_folded_multififo_regionizer_ref.cpp @@ -88,16 +88,17 @@ void l1ct::BufferedFoldedMultififoRegionizerEmulator::initSectorsAndRegions(cons l1ct::glbeta_t etaMin, etaMax; findEtaBounds_(fold_[ie].sectors.track[0].region, fold_[ie].regions, etaMin, etaMax); for (unsigned int isec = 0; ntk_ > 0 && isec < NTK_SECTORS; ++isec) { - tkBuffers_[2 * isec + ie] = l1ct::multififo_regionizer::EtaBuffer(nclocks_ / 2, etaMin, etaMax); + tkBuffers_[2 * isec + ie] = + l1ct::multififo_regionizer::EtaPhiBuffer(nclocks_ / 2, etaMin, etaMax); } findEtaBounds_(fold_[ie].sectors.hadcalo[0].region, fold_[ie].regions, etaMin, etaMax); for (unsigned int isec = 0; ncalo_ > 0 && isec < NCALO_SECTORS; ++isec) { caloBuffers_[2 * isec + ie] = - l1ct::multififo_regionizer::EtaBuffer(nclocks_ / 2, etaMin, etaMax); + l1ct::multififo_regionizer::EtaPhiBuffer(nclocks_ / 2, etaMin, etaMax); } findEtaBounds_(fold_[ie].sectors.muon.region, fold_[ie].regions, etaMin, etaMax); if (nmu_ > 0) { - muBuffers_[ie] = l1ct::multififo_regionizer::EtaBuffer(nclocks_ / 2, etaMin, etaMax); + muBuffers_[ie] = l1ct::multififo_regionizer::EtaPhiBuffer(nclocks_ / 2, etaMin, etaMax); } } } diff --git a/L1Trigger/Phase2L1ParticleFlow/src/regionizer/middle_buffer_multififo_regionizer_ref.cpp b/L1Trigger/Phase2L1ParticleFlow/src/regionizer/middle_buffer_multififo_regionizer_ref.cpp new file mode 100644 index 0000000000000..aa818bb139ab6 --- /dev/null +++ b/L1Trigger/Phase2L1ParticleFlow/src/regionizer/middle_buffer_multififo_regionizer_ref.cpp @@ -0,0 +1,631 @@ +#include "L1Trigger/Phase2L1ParticleFlow/interface/regionizer/middle_buffer_multififo_regionizer_ref.h" +#include "L1Trigger/Phase2L1ParticleFlow/interface/dbgPrintf.h" +#include "L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_elements_ref.icc" + +#include +#include +#include + +#ifdef CMSSW_GIT_HASH +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "FWCore/ParameterSet/interface/allowedValues.h" + +l1ct::MiddleBufferMultififoRegionizerEmulator::MiddleBufferMultififoRegionizerEmulator(const edm::ParameterSet& iConfig) + : MiddleBufferMultififoRegionizerEmulator(iConfig.getParameter("nClocks"), + iConfig.getParameter("nBuffers"), + iConfig.getParameter("etaBufferDepth"), + iConfig.getParameter("nTkLinks"), + iConfig.getParameter("nHCalLinks"), + iConfig.getParameter("nECalLinks"), + iConfig.getParameter("nTrack"), + iConfig.getParameter("nCalo"), + iConfig.getParameter("nEmCalo"), + iConfig.getParameter("nMu"), + /*streaming=*/true, + /*outii=*/2, + /*pauseii=*/1, + iConfig.getParameter("useAlsoVtxCoords")) { + debug_ = iConfig.getUntrackedParameter("debug", false); +} + +edm::ParameterSetDescription l1ct::MiddleBufferMultififoRegionizerEmulator::getParameterSetDescription() { + edm::ParameterSetDescription description; + description.add("nClocks", 162); + description.add("nBuffers", 27); + description.add("etaBufferDepth", 54); + description.add("nTkLinks", 1); + description.add("nHCalLinks", 1); + description.add("nECalLinks", 0); + description.add("nTrack", 22); + description.add("nCalo", 15); + description.add("nEmCalo", 12); + description.add("nMu", 2); + description.add("useAlsoVtxCoords", true); + description.addUntracked("debug", false); + return description; +} + +#endif + +l1ct::MiddleBufferMultififoRegionizerEmulator::MiddleBufferMultififoRegionizerEmulator(unsigned int nclocks, + unsigned int nbuffers, + unsigned int etabufferDepth, + unsigned int ntklinks, + unsigned int nHCalLinks, + unsigned int nECalLinks, + unsigned int ntk, + unsigned int ncalo, + unsigned int nem, + unsigned int nmu, + bool streaming, + unsigned int outii, + unsigned int pauseii, + bool useAlsoVtxCoords) + : RegionizerEmulator(useAlsoVtxCoords), + NTK_SECTORS(9), + NCALO_SECTORS(3), + NTK_LINKS(ntklinks), + HCAL_LINKS(nHCalLinks), + ECAL_LINKS(nECalLinks), + NMU_LINKS(1), + nclocks_(nclocks), + nbuffers_(nbuffers), + etabuffer_depth_(etabufferDepth), + ntk_(ntk), + ncalo_(ncalo), + nem_(nem), + nmu_(nmu), + outii_(outii), + pauseii_(pauseii), + nregions_pre_(27), + nregions_post_(54), + streaming_(streaming), + init_(false), + iclock_(0), + tkRegionizerPre_(ntk, ntk, false, outii, pauseii, useAlsoVtxCoords), + tkRegionizerPost_(ntk, (ntk + outii - 1) / outii, true, outii, pauseii, useAlsoVtxCoords), + hadCaloRegionizerPre_(ncalo, ncalo, false, outii, pauseii), + hadCaloRegionizerPost_(ncalo, (ncalo + outii - 1) / outii, true, outii, pauseii), + emCaloRegionizerPre_(nem, nem, false, outii, pauseii), + emCaloRegionizerPost_(nem, (nem + outii - 1) / outii, true, outii, pauseii), + muRegionizerPre_(nmu, nmu, false, outii, pauseii), + muRegionizerPost_(nmu, std::max(1u, (nmu + outii - 1) / outii), true, outii, pauseii), + tkBuffers_(ntk ? nbuffers_ : 0), + hadCaloBuffers_(ncalo ? nbuffers_ : 0), + emCaloBuffers_(nem ? nbuffers_ : 0), + muBuffers_(nmu ? nbuffers_ : 0) { + assert(nbuffers_ == nregions_post_ || nbuffers_ == nregions_pre_); + unsigned int phisectors = 9, etaslices = 3; + for (unsigned int ietaslice = 0; ietaslice < etaslices && ntk > 0; ++ietaslice) { + for (unsigned int ie = 0; ie < 2; ++ie) { // 0 = negative, 1 = positive + unsigned int nTFEtaSlices = ietaslice == 1 ? 2 : 1; + if ((ietaslice == 0 && ie == 1) || (ietaslice == 2 && ie == 0)) + continue; + unsigned int ireg0 = phisectors * ietaslice, il0 = 3 * NTK_LINKS * (nTFEtaSlices - 1) * ie; + for (unsigned int is = 0; is < NTK_SECTORS; ++is) { // 9 tf sectors + for (unsigned int il = 0; il < NTK_LINKS; ++il) { // max tracks per sector per clock + unsigned int isp = (is + 1) % NTK_SECTORS, ism = (is + NTK_SECTORS - 1) % NTK_SECTORS; + tkRoutes_.emplace_back(is + NTK_SECTORS * ie, il, is + ireg0, il0 + il); + tkRoutes_.emplace_back(is + NTK_SECTORS * ie, il, isp + ireg0, il0 + il + NTK_LINKS); + tkRoutes_.emplace_back(is + NTK_SECTORS * ie, il, ism + ireg0, il0 + il + 2 * NTK_LINKS); + } + } + } + } + // calo + for (unsigned int ie = 0; ie < etaslices; ++ie) { + for (unsigned int is = 0; is < NCALO_SECTORS; ++is) { // NCALO_SECTORS sectors + for (unsigned int j = 0; j < 3; ++j) { // 3 regions x sector + for (unsigned int il = 0; il < HCAL_LINKS; ++il) { + caloRoutes_.emplace_back(is, il, 3 * is + j + phisectors * ie, il); + if (j) { + caloRoutes_.emplace_back((is + 1) % 3, il, 3 * is + j + phisectors * ie, il + HCAL_LINKS); + } + } + for (unsigned int il = 0; il < ECAL_LINKS; ++il) { + emCaloRoutes_.emplace_back(is, il, 3 * is + j + phisectors * ie, il); + if (j) { + emCaloRoutes_.emplace_back((is + 1) % 3, il, 3 * is + j + phisectors * ie, il + ECAL_LINKS); + } + } + } + } + } + // mu + for (unsigned int il = 0; il < NMU_LINKS && nmu > 0; ++il) { + for (unsigned int j = 0; j < nregions_pre_; ++j) { + muRoutes_.emplace_back(0, il, j, il); + } + } +} + +l1ct::MiddleBufferMultififoRegionizerEmulator::~MiddleBufferMultififoRegionizerEmulator() {} + +void l1ct::MiddleBufferMultififoRegionizerEmulator::initSectorsAndRegions(const RegionizerDecodedInputs& in, + const std::vector& out) { + assert(!init_); + init_ = true; + assert(out.size() == nregions_post_); + + std::vector mergedRegions; + unsigned int neta = 3, nphi = 9; + mergedRegions.reserve(nregions_pre_); + mergedRegions_.reserve(nregions_pre_); + outputRegions_.reserve(nregions_post_); + for (unsigned int ieta = 0; ieta < neta; ++ieta) { + for (unsigned int iphi = 0; iphi < nphi; ++iphi) { + const PFRegionEmu& reg0 = out[(2 * ieta + 0) * nphi + iphi].region; + const PFRegionEmu& reg1 = out[(2 * ieta + 1) * nphi + iphi].region; + assert(reg0.hwPhiCenter == reg1.hwPhiCenter); + mergedRegions.emplace_back(reg0.floatEtaMin(), + reg1.floatEtaMax(), + reg0.floatPhiCenter(), + reg0.floatPhiHalfWidth() * 2, + reg0.floatEtaExtra(), + reg0.floatPhiExtra()); + mergedRegions_.push_back(mergedRegions.back().region); + outputRegions_.push_back(reg0); + outputRegions_.push_back(reg1); + if (debug_) { + dbgCout() << "Created region with etaCenter " << mergedRegions.back().region.hwEtaCenter.to_int() + << ", halfWidth " << mergedRegions.back().region.hwEtaHalfWidth.to_int() << "\n"; + } + if (nbuffers_ == nregions_post_) { + for (int i = 0; i < 2; ++i) { + unsigned int iout = (2 * ieta + i) * nphi + iphi; + const l1ct::PFRegionEmu& from = mergedRegions.back().region; + const l1ct::PFRegionEmu& to = out[iout].region; + l1ct::glbeta_t etaMin = to.hwEtaCenter - to.hwEtaHalfWidth - to.hwEtaExtra - from.hwEtaCenter; + l1ct::glbeta_t etaMax = to.hwEtaCenter + to.hwEtaHalfWidth + to.hwEtaExtra - from.hwEtaCenter; + l1ct::glbeta_t etaShift = from.hwEtaCenter - to.hwEtaCenter; + l1ct::glbphi_t phiMin = -to.hwPhiHalfWidth - to.hwPhiExtra; + l1ct::glbphi_t phiMax = +to.hwPhiHalfWidth + to.hwPhiExtra; + l1ct::glbphi_t phiShift = 0; + if (ntk_ > 0) + tkBuffers_[iout] = l1ct::multififo_regionizer::EtaPhiBuffer( + etabuffer_depth_, etaMin, etaMax, etaShift, phiMin, phiMax, phiShift); + if (ncalo_ > 0) + hadCaloBuffers_[iout] = l1ct::multififo_regionizer::EtaPhiBuffer( + etabuffer_depth_, etaMin, etaMax, etaShift, phiMin, phiMax, phiShift); + if (nem_ > 0) + emCaloBuffers_[iout] = l1ct::multififo_regionizer::EtaPhiBuffer( + etabuffer_depth_, etaMin, etaMax, etaShift, phiMin, phiMax, phiShift); + if (nmu_ > 0) + muBuffers_[iout] = l1ct::multififo_regionizer::EtaPhiBuffer( + etabuffer_depth_, etaMin, etaMax, etaShift, phiMin, phiMax, phiShift); + } + } else if (nbuffers_ == nregions_pre_) { + unsigned int iout = ieta * nphi + iphi; + if (ntk_ > 0) + tkBuffers_[iout] = l1ct::multififo_regionizer::EtaPhiBuffer(etabuffer_depth_); + if (ncalo_ > 0) + hadCaloBuffers_[iout] = l1ct::multififo_regionizer::EtaPhiBuffer(etabuffer_depth_); + if (nem_ > 0) + emCaloBuffers_[iout] = l1ct::multififo_regionizer::EtaPhiBuffer(etabuffer_depth_); + if (nmu_ > 0) + muBuffers_[iout] = l1ct::multififo_regionizer::EtaPhiBuffer(etabuffer_depth_); + } + } + } + if (ntk_) { + assert(in.track.size() == 2 * NTK_SECTORS); + tkRegionizerPre_.initSectors(in.track); + tkRegionizerPre_.initRegions(mergedRegions); + tkRegionizerPre_.initRouting(tkRoutes_); + tkRegionizerPost_.initRegions(out); + } + if (ncalo_) { + assert(in.hadcalo.size() == NCALO_SECTORS); + hadCaloRegionizerPre_.initSectors(in.hadcalo); + hadCaloRegionizerPre_.initRegions(mergedRegions); + hadCaloRegionizerPre_.initRouting(caloRoutes_); + hadCaloRegionizerPost_.initRegions(out); + } + if (nem_) { + assert(in.emcalo.size() == NCALO_SECTORS); + emCaloRegionizerPre_.initSectors(in.emcalo); + emCaloRegionizerPre_.initRegions(mergedRegions); + if (ECAL_LINKS) + emCaloRegionizerPre_.initRouting(emCaloRoutes_); + emCaloRegionizerPost_.initRegions(out); + } + if (nmu_) { + muRegionizerPre_.initSectors(in.muon); + muRegionizerPre_.initRegions(mergedRegions); + muRegionizerPre_.initRouting(muRoutes_); + muRegionizerPost_.initRegions(out); + } +} + +bool l1ct::MiddleBufferMultififoRegionizerEmulator::step(bool newEvent, + const std::vector& links_tk, + const std::vector& links_hadCalo, + const std::vector& links_emCalo, + const std::vector& links_mu, + std::vector& out_tk, + std::vector& out_hadCalo, + std::vector& out_emCalo, + std::vector& out_mu, + bool /*unused*/) { + iclock_ = (newEvent ? 0 : iclock_ + 1); + bool newRead = iclock_ == 2 * etabuffer_depth_; + + std::vector pre_out_tk; + std::vector pre_out_hadCalo; + std::vector pre_out_emCalo; + std::vector pre_out_mu; + bool ret = false; + if (ntk_) + ret = tkRegionizerPre_.step(newEvent, links_tk, pre_out_tk, false); + if (nmu_) + ret = muRegionizerPre_.step(newEvent, links_mu, pre_out_mu, false); + if (ncalo_) + ret = hadCaloRegionizerPre_.step(newEvent, links_hadCalo, pre_out_hadCalo, false); + if (nem_) { + if (ECAL_LINKS) { + ret = emCaloRegionizerPre_.step(newEvent, links_emCalo, pre_out_emCalo, false); + } else if (ncalo_) { + pre_out_emCalo.resize(pre_out_hadCalo.size()); + for (unsigned int i = 0, n = pre_out_hadCalo.size(); i < n; ++i) { + decode(pre_out_hadCalo[i], pre_out_emCalo[i]); + } + } + } + + // in the no-streaming case, we just output the pre-regionizer + if (!streaming_) { + out_tk.swap(pre_out_tk); + out_mu.swap(pre_out_mu); + out_hadCalo.swap(pre_out_hadCalo); + out_emCalo.swap(pre_out_emCalo); + return ret; + } + + // otherwise, we push into the eta buffers + if (newEvent) { + for (auto& b : tkBuffers_) + b.writeNewEvent(); + for (auto& b : hadCaloBuffers_) + b.writeNewEvent(); + for (auto& b : emCaloBuffers_) + b.writeNewEvent(); + for (auto& b : muBuffers_) + b.writeNewEvent(); + } + unsigned int neta = 3, nphi = 9; + for (unsigned int ieta = 0; ieta < neta; ++ieta) { + for (unsigned int iphi = 0; iphi < nphi; ++iphi) { + unsigned int iin = ieta * nphi + iphi; + for (int i = 0, n = nbuffers_ == nregions_pre_ ? 1 : 2; i < n; ++i) { + unsigned int iout = (n * ieta + i) * nphi + iphi; + if (ntk_) + tkBuffers_[iout].maybe_push(pre_out_tk[iin]); + if (ncalo_) + hadCaloBuffers_[iout].maybe_push(pre_out_hadCalo[iin]); + if (nem_) + emCaloBuffers_[iout].maybe_push(pre_out_emCalo[iin]); + if (nmu_) + muBuffers_[iout].maybe_push(pre_out_mu[iin]); + } + } + } + + // and we read from eta buffers into muxes + if (newRead) { + for (auto& b : tkBuffers_) + b.readNewEvent(); + for (auto& b : hadCaloBuffers_) + b.readNewEvent(); + for (auto& b : emCaloBuffers_) + b.readNewEvent(); + for (auto& b : muBuffers_) + b.readNewEvent(); + } + std::vector bufferOut_tk(ntk_ ? nregions_post_ : 0); + std::vector bufferOut_hadCalo(ncalo_ ? nregions_post_ : 0); + std::vector bufferOut_emCalo(nem_ ? nregions_post_ : 0); + std::vector bufferOut_mu(nmu_ ? nregions_post_ : 0); + if (nbuffers_ == nregions_post_) { // just copy directly + for (unsigned int i = 0; i < nregions_post_; ++i) { + if (ntk_) + bufferOut_tk[i] = tkBuffers_[i].pop(); + if (ncalo_) + bufferOut_hadCalo[i] = hadCaloBuffers_[i].pop(); + if (nem_) + bufferOut_emCalo[i] = emCaloBuffers_[i].pop(); + if (nmu_) + bufferOut_mu[i] = muBuffers_[i].pop(); + } + } else if (nbuffers_ == nregions_pre_) { // propagate and copy + unsigned int neta = 3, nphi = 9; + for (unsigned int ieta = 0; ieta < neta; ++ieta) { + for (unsigned int iphi = 0; iphi < nphi; ++iphi) { + unsigned int iin = ieta * nphi + iphi; + const l1ct::PFRegionEmu& from = mergedRegions_[iin]; + l1ct::TkObjEmu tk = ntk_ ? tkBuffers_[iin].pop() : l1ct::TkObjEmu(); + l1ct::HadCaloObjEmu calo = ncalo_ ? hadCaloBuffers_[iin].pop() : l1ct::HadCaloObjEmu(); + l1ct::EmCaloObjEmu em = nem_ ? emCaloBuffers_[iin].pop() : l1ct::EmCaloObjEmu(); + l1ct::MuObjEmu mu = nmu_ ? muBuffers_[iin].pop() : l1ct::MuObjEmu(); + for (int i = 0; i < 2; ++i) { + const l1ct::PFRegionEmu& to = outputRegions_[2 * iin + i]; + unsigned int iout = (2 * ieta + i) * nphi + iphi; + l1ct::glbeta_t etaMin = to.hwEtaCenter - to.hwEtaHalfWidth - to.hwEtaExtra - from.hwEtaCenter; + l1ct::glbeta_t etaMax = to.hwEtaCenter + to.hwEtaHalfWidth + to.hwEtaExtra - from.hwEtaCenter; + l1ct::glbeta_t etaShift = from.hwEtaCenter - to.hwEtaCenter; + l1ct::glbphi_t phiMin = -to.hwPhiHalfWidth - to.hwPhiExtra; + l1ct::glbphi_t phiMax = +to.hwPhiHalfWidth + to.hwPhiExtra; + if (tk.hwPt > 0 && l1ct::multififo_regionizer::local_eta_phi_window(tk, etaMin, etaMax, phiMin, phiMax)) { + bufferOut_tk[iout] = tk; + bufferOut_tk[iout].hwEta += etaShift; + } + if (calo.hwPt > 0 && l1ct::multififo_regionizer::local_eta_phi_window(calo, etaMin, etaMax, phiMin, phiMax)) { + bufferOut_hadCalo[iout] = calo; + bufferOut_hadCalo[iout].hwEta += etaShift; + } + if (em.hwPt > 0 && l1ct::multififo_regionizer::local_eta_phi_window(em, etaMin, etaMax, phiMin, phiMax)) { + bufferOut_emCalo[iout] = em; + bufferOut_emCalo[iout].hwEta += etaShift; + } + if (mu.hwPt > 0 && l1ct::multififo_regionizer::local_eta_phi_window(mu, etaMin, etaMax, phiMin, phiMax)) { + bufferOut_mu[iout] = mu; + bufferOut_mu[iout].hwEta += etaShift; + } + } + } + } + } + if (ntk_) + tkRegionizerPost_.muxonly_step(newEvent, /*flush=*/true, bufferOut_tk, out_tk); + if (ncalo_) + hadCaloRegionizerPost_.muxonly_step(newEvent, /*flush=*/true, bufferOut_hadCalo, out_hadCalo); + if (nem_) + emCaloRegionizerPost_.muxonly_step(newEvent, /*flush=*/true, bufferOut_emCalo, out_emCalo); + if (nmu_) + muRegionizerPost_.muxonly_step(newEvent, /*flush=*/true, bufferOut_mu, out_mu); + + return newRead; +} + +void l1ct::MiddleBufferMultififoRegionizerEmulator::fillLinks(unsigned int iclock, + const l1ct::RegionizerDecodedInputs& in, + std::vector& links, + std::vector& valid) { + if (ntk_ == 0) + return; + assert(NTK_LINKS == 1); + links.resize(NTK_SECTORS * NTK_LINKS * 2); + valid.resize(links.size()); + // emulate reduced rate from 96b tracks on 64b links + unsigned int itkclock = 2 * (iclock / 3) + (iclock % 3) - 1; // will underflow for iclock == 0 but it doesn't matter + for (unsigned int is = 0, idx = 0; is < 2 * NTK_SECTORS; ++is, ++idx) { // tf sectors + const l1ct::DetectorSector& sec = in.track[is]; + unsigned int ntracks = sec.size(); + unsigned int nw64 = (ntracks * 3 + 1) / 2; + if (iclock % 3 == 0) { + links[idx].clear(); + valid[idx] = (iclock == 0) || (iclock < nw64); + } else if (itkclock < ntracks && itkclock < nclocks_ - 1) { + links[idx] = sec[itkclock]; + valid[idx] = true; + } else { + links[idx].clear(); + valid[idx] = false; + } + } +} + +template +void l1ct::MiddleBufferMultififoRegionizerEmulator::fillCaloLinks_(unsigned int iclock, + const std::vector>& in, + std::vector& links, + std::vector& valid) { + unsigned int NLINKS = (typeid(T) == typeid(l1ct::HadCaloObjEmu) ? HCAL_LINKS : ECAL_LINKS); + links.resize(NCALO_SECTORS * NLINKS); + valid.resize(links.size()); + for (unsigned int is = 0, idx = 0; is < NCALO_SECTORS; ++is) { + for (unsigned int il = 0; il < NLINKS; ++il, ++idx) { + unsigned int ioffs = iclock * NLINKS + il; + if (ioffs < in[is].size() && iclock < nclocks_ - 1) { + links[idx] = in[is][ioffs]; + valid[idx] = true; + } else { + links[idx].clear(); + valid[idx] = false; + } + } + } +} +void l1ct::MiddleBufferMultififoRegionizerEmulator::fillSharedCaloLinks( + unsigned int iclock, + const std::vector>& em_in, + const std::vector>& had_in, + std::vector& links, + std::vector& valid) { + assert(ECAL_LINKS == 0 && HCAL_LINKS == 1 && ncalo_ != 0 && nem_ != 0); + links.resize(NCALO_SECTORS); + valid.resize(links.size()); + // for the moment we assume the first 54 clocks are for EM, the rest for HAD + const unsigned int NCLK_EM = 54; + for (unsigned int is = 0; is < NCALO_SECTORS; ++is) { + links[is].clear(); + if (iclock < NCLK_EM) { + valid[is] = true; + if (iclock < em_in[is].size()) { + encode(em_in[is][iclock], links[is]); + } + } else { + if (iclock - NCLK_EM < had_in[is].size()) { + encode(had_in[is][iclock - NCLK_EM], links[is]); + valid[is] = true; + } else { + valid[is] = false; + } + } + } // sectors +} + +void l1ct::MiddleBufferMultififoRegionizerEmulator::fillLinks(unsigned int iclock, + const l1ct::RegionizerDecodedInputs& in, + std::vector& links, + std::vector& valid) { + if (ncalo_ == 0) + return; + if (nem_ != 0 && ECAL_LINKS == 0 && HCAL_LINKS == 1) + fillSharedCaloLinks(iclock, in.emcalo, in.hadcalo, links, valid); + else + fillCaloLinks_(iclock, in.hadcalo, links, valid); +} + +void l1ct::MiddleBufferMultififoRegionizerEmulator::fillLinks(unsigned int iclock, + const l1ct::RegionizerDecodedInputs& in, + std::vector& links, + std::vector& valid) { + if (nem_ == 0) + return; + fillCaloLinks_(iclock, in.emcalo, links, valid); +} + +void l1ct::MiddleBufferMultififoRegionizerEmulator::fillLinks(unsigned int iclock, + const l1ct::RegionizerDecodedInputs& in, + std::vector& links, + std::vector& valid) { + if (nmu_ == 0) + return; + assert(NMU_LINKS == 1); + links.resize(NMU_LINKS); + valid.resize(links.size()); + if (iclock < in.muon.size() && iclock < nclocks_ - 1) { + links[0] = in.muon[iclock]; + valid[0] = true; + } else { + links[0].clear(); + valid[0] = false; + } +} + +void l1ct::MiddleBufferMultififoRegionizerEmulator::destream(int iclock, + const std::vector& tk_out, + const std::vector& em_out, + const std::vector& calo_out, + const std::vector& mu_out, + PFInputRegion& out) { + if (ntk_) + tkRegionizerPost_.destream(iclock, tk_out, out.track); + if (ncalo_) + hadCaloRegionizerPost_.destream(iclock, calo_out, out.hadcalo); + if (nem_) + emCaloRegionizerPost_.destream(iclock, em_out, out.emcalo); + if (nmu_) + muRegionizerPost_.destream(iclock, mu_out, out.muon); +} + +void l1ct::MiddleBufferMultififoRegionizerEmulator::reset() { + tkRegionizerPre_.reset(); + emCaloRegionizerPre_.reset(); + hadCaloRegionizerPre_.reset(); + muRegionizerPre_.reset(); + tkRegionizerPost_.reset(); + emCaloRegionizerPost_.reset(); + hadCaloRegionizerPost_.reset(); + muRegionizerPost_.reset(); + for (auto& b : tkBuffers_) + b.reset(); + for (auto& b : hadCaloBuffers_) + b.reset(); + for (auto& b : emCaloBuffers_) + b.reset(); + for (auto& b : muBuffers_) + b.reset(); +} + +void l1ct::MiddleBufferMultififoRegionizerEmulator::run(const RegionizerDecodedInputs& in, + std::vector& out) { + assert(streaming_); // doesn't make sense otherwise + if (!init_) + initSectorsAndRegions(in, out); + reset(); + std::vector tk_links_in, tk_out; + std::vector em_links_in, em_out; + std::vector calo_links_in, calo_out; + std::vector mu_links_in, mu_out; + + // read and sort the inputs + for (unsigned int iclock = 0; iclock < nclocks_; ++iclock) { + fillLinks(iclock, in, tk_links_in); + fillLinks(iclock, in, em_links_in); + fillLinks(iclock, in, calo_links_in); + fillLinks(iclock, in, mu_links_in); + + bool newevt = (iclock == 0); + step(newevt, tk_links_in, calo_links_in, em_links_in, mu_links_in, tk_out, calo_out, em_out, mu_out, true); + } + + // set up an empty event + for (auto& l : tk_links_in) + l.clear(); + for (auto& l : em_links_in) + l.clear(); + for (auto& l : calo_links_in) + l.clear(); + for (auto& l : mu_links_in) + l.clear(); + + // read and put the inputs in the regions + assert(out.size() == nregions_post_); + for (unsigned int iclock = 0; iclock < nclocks_; ++iclock) { + bool newevt = (iclock == 0); + step(newevt, tk_links_in, calo_links_in, em_links_in, mu_links_in, tk_out, calo_out, em_out, mu_out, true); + + unsigned int ireg = (iclock / (outii_ + pauseii_)); + if ((iclock % (outii_ + pauseii_)) >= outii_) + continue; + if (ireg >= nregions_post_) + break; + + if (streaming_) { + destream(iclock, tk_out, em_out, calo_out, mu_out, out[ireg]); + } else { + if (iclock % outii_ == 0) { + out[ireg].track = tk_out; + out[ireg].emcalo = em_out; + out[ireg].hadcalo = calo_out; + out[ireg].muon = mu_out; + } + } + } + + reset(); +} + +void l1ct::MiddleBufferMultififoRegionizerEmulator::encode(const l1ct::EmCaloObjEmu& from, l1ct::HadCaloObjEmu& to) { + assert(!from.hwEmID[5]); + to.hwPt = from.hwPt; + to.hwEmPt = from.hwPtErr; + to.hwEta = from.hwEta; + to.hwPhi = from.hwPhi; + to.hwEmID[5] = true; + to.hwEmID(4, 0) = from.hwEmID(4, 0); + to.src = from.src; +} +void l1ct::MiddleBufferMultififoRegionizerEmulator::encode(const l1ct::HadCaloObjEmu& from, l1ct::HadCaloObjEmu& to) { + assert(!from.hwEmID[5]); + to = from; +} +void l1ct::MiddleBufferMultififoRegionizerEmulator::decode(l1ct::HadCaloObjEmu& had, l1ct::EmCaloObjEmu& em) { + if (had.hwPt && had.hwEmID[5]) { + em.hwPt = had.hwPt; + em.hwPtErr = had.hwEmPt; + em.hwEta = had.hwEta; + em.hwPhi = had.hwPhi; + em.hwEmID[5] = 0; + em.hwEmID(4, 0) = had.hwEmID(4, 0); + em.hwSrrTot = 0; + em.hwMeanZ = 0; + em.hwHoe = 0; + em.src = had.src; + had.clear(); + } else { + em.clear(); + } +} \ No newline at end of file diff --git a/L1Trigger/Phase2L1ParticleFlow/src/regionizer/multififo_regionizer_ref.cpp b/L1Trigger/Phase2L1ParticleFlow/src/regionizer/multififo_regionizer_ref.cpp index a9e9d3977dde4..ef509bb4ccaf1 100644 --- a/L1Trigger/Phase2L1ParticleFlow/src/regionizer/multififo_regionizer_ref.cpp +++ b/L1Trigger/Phase2L1ParticleFlow/src/regionizer/multififo_regionizer_ref.cpp @@ -34,6 +34,7 @@ l1ct::MultififoRegionizerEmulator::MultififoRegionizerEmulator(const edm::Parame l1ct::MultififoRegionizerEmulator::MultififoRegionizerEmulator(const std::string& barrelSetup, const edm::ParameterSet& iConfig) : MultififoRegionizerEmulator(parseBarrelSetup(barrelSetup), + iConfig.getParameter("nTkLinks"), iConfig.getParameter("nHCalLinks"), iConfig.getParameter("nECalLinks"), iConfig.getParameter("nClocks"), @@ -71,6 +72,7 @@ edm::ParameterSetDescription l1ct::MultififoRegionizerEmulator::getParameterSetD description.ifValue(edm::ParameterDescription("barrelSetup", "Full54", true), edm::allowedValues("Full54", "Full27")); description.add("nClocks", 54); + description.add("nTkLinks", 2); description.add("nHCalLinks", 2); description.add("nECalLinks", 1); description.add("nTrack", 22); @@ -154,6 +156,7 @@ l1ct::MultififoRegionizerEmulator::MultififoRegionizerEmulator(unsigned int nend } l1ct::MultififoRegionizerEmulator::MultififoRegionizerEmulator(BarrelSetup barrelSetup, + unsigned int ntklinks, unsigned int nHCalLinks, unsigned int nECalLinks, unsigned int nclocks, @@ -168,7 +171,7 @@ l1ct::MultififoRegionizerEmulator::MultififoRegionizerEmulator(BarrelSetup barre : RegionizerEmulator(useAlsoVtxCoords), NTK_SECTORS((barrelSetup == BarrelSetup::Phi18 || barrelSetup == BarrelSetup::Phi9) ? 5 : 9), NCALO_SECTORS((barrelSetup == BarrelSetup::Phi18 || barrelSetup == BarrelSetup::Phi9) ? 2 : 3), - NTK_LINKS(2), + NTK_LINKS(ntklinks), NCALO_LINKS(2), HCAL_LINKS(nHCalLinks), ECAL_LINKS(nECalLinks), @@ -237,13 +240,13 @@ l1ct::MultififoRegionizerEmulator::MultififoRegionizerEmulator(BarrelSetup barre } else if (barrelSetup == BarrelSetup::Central18 || barrelSetup == BarrelSetup::Central9) { nTFEtaSlices = 2; } - unsigned int ireg0 = phisectors * ietaslice, il0 = 6 * (nTFEtaSlices - 1) * ie; + unsigned int ireg0 = phisectors * ietaslice, il0 = 3 * NTK_LINKS * (nTFEtaSlices - 1) * ie; if (barrelSetup == BarrelSetup::Phi18 || barrelSetup == BarrelSetup::Phi9) { for (unsigned int iregphi = 0; iregphi < (nregions_ / etaslices); ++iregphi) { for (unsigned int il = 0; il < NTK_LINKS; ++il) { tkRoutes_.emplace_back((iregphi + 1) + NTK_SECTORS * ie, il, iregphi + ireg0, il0 + il); - tkRoutes_.emplace_back((iregphi + 0) + NTK_SECTORS * ie, il, iregphi + ireg0, il0 + il + 2); - tkRoutes_.emplace_back((iregphi + 2) + NTK_SECTORS * ie, il, iregphi + ireg0, il0 + il + 4); + tkRoutes_.emplace_back((iregphi + 0) + NTK_SECTORS * ie, il, iregphi + ireg0, il0 + il + NTK_LINKS); + tkRoutes_.emplace_back((iregphi + 2) + NTK_SECTORS * ie, il, iregphi + ireg0, il0 + il + 2 * NTK_LINKS); } } } else { @@ -251,8 +254,8 @@ l1ct::MultififoRegionizerEmulator::MultififoRegionizerEmulator(BarrelSetup barre for (unsigned int il = 0; il < NTK_LINKS; ++il) { // max tracks per sector per clock unsigned int isp = (is + 1) % NTK_SECTORS, ism = (is + NTK_SECTORS - 1) % NTK_SECTORS; tkRoutes_.emplace_back(is + NTK_SECTORS * ie, il, is + ireg0, il0 + il); - tkRoutes_.emplace_back(is + NTK_SECTORS * ie, il, isp + ireg0, il0 + il + 2); - tkRoutes_.emplace_back(is + NTK_SECTORS * ie, il, ism + ireg0, il0 + il + 4); + tkRoutes_.emplace_back(is + NTK_SECTORS * ie, il, isp + ireg0, il0 + il + NTK_LINKS); + tkRoutes_.emplace_back(is + NTK_SECTORS * ie, il, ism + ireg0, il0 + il + 2 * NTK_LINKS); } } } diff --git a/L1Trigger/Phase2L1ParticleFlow/src/regionizer/tdr_regionizer_ref.cpp b/L1Trigger/Phase2L1ParticleFlow/src/regionizer/tdr_regionizer_ref.cpp index 79616c2753888..5d9d635dc8b02 100644 --- a/L1Trigger/Phase2L1ParticleFlow/src/regionizer/tdr_regionizer_ref.cpp +++ b/L1Trigger/Phase2L1ParticleFlow/src/regionizer/tdr_regionizer_ref.cpp @@ -75,9 +75,11 @@ void l1ct::TDRRegionizerEmulator::initSectorsAndRegions(const RegionizerDecodedI netaInBR_, nphiInBR_, nmu_, bigRegionEdges_[i], bigRegionEdges_[i + 1], nclocks_, 1, false); } - dbgCout() << "in.track.size() = " << in.track.size() << std::endl; - dbgCout() << "in.hadcalo.size() = " << in.hadcalo.size() << std::endl; - dbgCout() << "in.emcalo.size() = " << in.emcalo.size() << std::endl; + if (debug_) { + dbgCout() << "in.track.size() = " << in.track.size() << std::endl; + dbgCout() << "in.hadcalo.size() = " << in.hadcalo.size() << std::endl; + dbgCout() << "in.emcalo.size() = " << in.emcalo.size() << std::endl; + } if (ntk_) { for (unsigned int i = 0; i < nBigRegions_; i++) { diff --git a/L1Trigger/Phase2L1ParticleFlow/test/make_l1ct_binaryFiles_cfg.py b/L1Trigger/Phase2L1ParticleFlow/test/make_l1ct_binaryFiles_cfg.py index 4b12b019246b1..facae0439020f 100644 --- a/L1Trigger/Phase2L1ParticleFlow/test/make_l1ct_binaryFiles_cfg.py +++ b/L1Trigger/Phase2L1ParticleFlow/test/make_l1ct_binaryFiles_cfg.py @@ -175,13 +175,24 @@ del process.l1tLayer1HGCalNoTKTM18.regionizerAlgoParameters.nEndcaps del process.l1tLayer1HGCalNoTKTM18.regionizerAlgoParameters.nTkLinks del process.l1tLayer1HGCalNoTKTM18.regionizerAlgoParameters.nCaloLinks + process.l1tLayer1BarrelSerenityTM18 = process.l1tLayer1BarrelSerenity.clone() + process.l1tLayer1BarrelSerenityTM18.regionizerAlgo = "MiddleBufferMultififo" + process.l1tLayer1BarrelSerenityTM18.regionizerAlgoParameters = cms.PSet( + nTrack = process.l1tLayer1BarrelSerenity.regionizerAlgoParameters.nTrack, + nCalo = process.l1tLayer1BarrelSerenity.regionizerAlgoParameters.nCalo, + nEmCalo = process.l1tLayer1BarrelSerenity.regionizerAlgoParameters.nEmCalo, + nMu = process.l1tLayer1BarrelSerenity.regionizerAlgoParameters.nMu, + ) + process.l1tLayer1BarrelSerenityTM18.boards = cms.VPSet(*[cms.PSet(regions = cms.vuint32(*range(18*i,18*i+18))) for i in range(3)]) process.runPF.insert(process.runPF.index(process.l1tLayer1HGCal)+1, process.l1tLayer1HGCalTM18) process.runPF.insert(process.runPF.index(process.l1tLayer1HGCalNoTK)+1, process.l1tLayer1HGCalNoTKTM18) + process.runPF.insert(process.runPF.index(process.l1tLayer1BarrelSerenity)+1, process.l1tLayer1BarrelSerenityTM18) if not args.patternFilesOFF: process.l1tLayer1HGCalTM18.patternWriters = cms.untracked.VPSet(*hgcalTM18WriterConfigs) process.l1tLayer1HGCalNoTKTM18.patternWriters = cms.untracked.VPSet(hgcalNoTKOutputTM18WriterConfig) + process.l1tLayer1BarrelSerenityTM18.patternWriters = cms.untracked.VPSet() if not args.dumpFilesOFF: - for det in "HGCalTM18", "HGCalNoTKTM18": + for det in "HGCalTM18", "HGCalNoTKTM18", "BarrelSerenityTM18": getattr(process, 'l1tLayer1'+det).dumpFileName = cms.untracked.string("TTbar_PU200_"+det+".dump") process.source.fileNames = [ '/store/cmst3/group/l1tr/gpetrucc/12_5_X/NewInputs125X/150223/TTbar_PU200/inputs125X_1.root' ]