Skip to content

Commit

Permalink
Merge pull request #43705 from gpetruc/barrel_tm18_master
Browse files Browse the repository at this point in the history
L1T Correlator support for TMUX 18 in the barrel
  • Loading branch information
cmsbuild authored Jan 22, 2024
2 parents 8a30dff + 9793955 commit 90bddf0
Show file tree
Hide file tree
Showing 12 changed files with 921 additions and 105 deletions.
25 changes: 11 additions & 14 deletions DataFormats/L1TParticleFlow/interface/datatypes.h
Original file line number Diff line number Diff line change
@@ -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 <ap_int.h>
#if (!defined(__CLANG__)) && defined(__GNUC__) && defined(CMSSW_GIT_HASH)
#pragma GCC diagnostic pop
#endif

#include <ap_int.h>
#include <cassert>
#include <cmath>
Expand Down Expand Up @@ -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<pt_t::width> rawPt = pt.range();
return rawPt.to_int();
}
inline int intPt(dpt_t pt) {
ap_int<dpt_t::width> 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; }
Expand All @@ -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<pt_t::width> ptToInt(pt_t pt) {
// note: this can be synthethized, e.g. when pT is used as intex in a LUT
Expand Down Expand Up @@ -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<eta_t::width + 1> deta = (eta1 - eta2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,6 @@
#include <memory>
#include <deque>

namespace l1ct {
namespace multififo_regionizer {
template <typename T>
inline bool local_eta_window(const T& t, const l1ct::glbeta_t& etaMin, const l1ct::glbeta_t& etaMax);
template <>
inline bool local_eta_window<l1ct::TkObjEmu>(const l1ct::TkObjEmu& t,
const l1ct::glbeta_t& etaMin,
const l1ct::glbeta_t& etaMax);

template <typename T>
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<T> items_[2];
};
} // namespace multififo_regionizer
} // namespace l1ct
namespace l1ct {
class BufferedFoldedMultififoRegionizerEmulator : public FoldedMultififoRegionizerEmulator {
public:
Expand Down Expand Up @@ -88,9 +56,9 @@ namespace l1ct {
}

protected:
std::vector<l1ct::multififo_regionizer::EtaBuffer<l1ct::TkObjEmu>> tkBuffers_;
std::vector<l1ct::multififo_regionizer::EtaBuffer<l1ct::HadCaloObjEmu>> caloBuffers_;
std::vector<l1ct::multififo_regionizer::EtaBuffer<l1ct::MuObjEmu>> muBuffers_;
std::vector<l1ct::multififo_regionizer::EtaPhiBuffer<l1ct::TkObjEmu>> tkBuffers_;
std::vector<l1ct::multififo_regionizer::EtaPhiBuffer<l1ct::HadCaloObjEmu>> caloBuffers_;
std::vector<l1ct::multififo_regionizer::EtaPhiBuffer<l1ct::MuObjEmu>> muBuffers_;

void findEtaBounds_(const l1ct::PFRegionEmu& sec,
const std::vector<PFInputRegion>& reg,
Expand All @@ -106,41 +74,4 @@ namespace l1ct {
};
} // namespace l1ct

template <typename T>
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<l1ct::TkObjEmu>(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 <typename T>
void l1ct::multififo_regionizer::EtaBuffer<T>::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 <typename T>
T l1ct::multififo_regionizer::EtaBuffer<T>::pop() {
T ret;
ret.clear();
if (!items_[iread_].empty()) {
ret = items_[iread_].front();
items_[iread_].pop_front();
}
return ret;
}

#endif
Original file line number Diff line number Diff line change
@@ -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 <memory>
#include <deque>

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<PFInputRegion>& out) override;

void run(const RegionizerDecodedInputs& in, std::vector<PFInputRegion>& out) override;

// link emulation from decoded inputs (for simulation)
void fillLinks(unsigned int iclock,
const RegionizerDecodedInputs& in,
std::vector<l1ct::TkObjEmu>& links,
std::vector<bool>& valid);
void fillLinks(unsigned int iclock,
const RegionizerDecodedInputs& in,
std::vector<l1ct::HadCaloObjEmu>& links,
std::vector<bool>& valid);
void fillLinks(unsigned int iclock,
const RegionizerDecodedInputs& in,
std::vector<l1ct::EmCaloObjEmu>& links,
std::vector<bool>& valid);
void fillLinks(unsigned int iclock,
const RegionizerDecodedInputs& in,
std::vector<l1ct::MuObjEmu>& links,
std::vector<bool>& valid);
template <typename T>
void fillLinks(unsigned int iclock, const RegionizerDecodedInputs& in, std::vector<T>& links) {
std::vector<bool> unused;
fillLinks(iclock, in, links, unused);
}

void destream(int iclock,
const std::vector<l1ct::TkObjEmu>& tk_out,
const std::vector<l1ct::EmCaloObjEmu>& em_out,
const std::vector<l1ct::HadCaloObjEmu>& calo_out,
const std::vector<l1ct::MuObjEmu>& mu_out,
PFInputRegion& out);

// clock-cycle emulation
bool step(bool newEvent,
const std::vector<l1ct::TkObjEmu>& links_tk,
const std::vector<l1ct::HadCaloObjEmu>& links_hadCalo,
const std::vector<l1ct::EmCaloObjEmu>& links_emCalo,
const std::vector<l1ct::MuObjEmu>& links_mu,
std::vector<l1ct::TkObjEmu>& out_tk,
std::vector<l1ct::HadCaloObjEmu>& out_hadCalo,
std::vector<l1ct::EmCaloObjEmu>& out_emCalo,
std::vector<l1ct::MuObjEmu>& out_mu,
bool /*unused*/);

template <typename TEmu, typename TFw>
void toFirmware(const std::vector<TEmu>& 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<l1ct::PFRegionEmu> mergedRegions_, outputRegions_;
multififo_regionizer::Regionizer<l1ct::TkObjEmu> tkRegionizerPre_, tkRegionizerPost_;
multififo_regionizer::Regionizer<l1ct::HadCaloObjEmu> hadCaloRegionizerPre_, hadCaloRegionizerPost_;
multififo_regionizer::Regionizer<l1ct::EmCaloObjEmu> emCaloRegionizerPre_, emCaloRegionizerPost_;
multififo_regionizer::Regionizer<l1ct::MuObjEmu> muRegionizerPre_, muRegionizerPost_;
std::vector<l1ct::multififo_regionizer::Route> tkRoutes_, caloRoutes_, emCaloRoutes_, muRoutes_;
std::vector<l1ct::multififo_regionizer::EtaPhiBuffer<l1ct::TkObjEmu>> tkBuffers_;
std::vector<l1ct::multififo_regionizer::EtaPhiBuffer<l1ct::HadCaloObjEmu>> hadCaloBuffers_;
std::vector<l1ct::multififo_regionizer::EtaPhiBuffer<l1ct::EmCaloObjEmu>> emCaloBuffers_;
std::vector<l1ct::multififo_regionizer::EtaPhiBuffer<l1ct::MuObjEmu>> muBuffers_;

template <typename T>
void fillCaloLinks_(unsigned int iclock,
const std::vector<DetectorSector<T>>& in,
std::vector<T>& links,
std::vector<bool>& valid);

void fillSharedCaloLinks(unsigned int iclock,
const std::vector<DetectorSector<l1ct::EmCaloObjEmu>>& em_in,
const std::vector<DetectorSector<l1ct::HadCaloObjEmu>>& had_in,
std::vector<l1ct::HadCaloObjEmu>& links,
std::vector<bool>& 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
Loading

0 comments on commit 90bddf0

Please sign in to comment.