Skip to content

Commit

Permalink
Merge pull request cms-sw#77 from gpetruc/test_multififo_barrel
Browse files Browse the repository at this point in the history
Updates of barrel geometry & multififo regionizer
  • Loading branch information
gpetruc authored Nov 10, 2021
2 parents 8e0057d + d617067 commit b739036
Show file tree
Hide file tree
Showing 15 changed files with 532 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,13 @@ void L1TCorrelatorLayer1Producer::initSectorsAndRegions(const edm::ParameterSet
float phiWidth = 2 * M_PI / phiSlices;
if (phiWidth > 2 * l1ct::Scales::maxAbsPhi())
throw cms::Exception("Configuration", "caloSectors phi range too large for phi_t data type");
double phiZero = preg.getParameter<double>("phiZero");
for (unsigned int ieta = 0, neta = etaBoundaries.size() - 1; ieta < neta; ++ieta) {
float etaWidth = etaBoundaries[ieta + 1] - etaBoundaries[ieta];
if (etaWidth > 2 * l1ct::Scales::maxAbsEta())
throw cms::Exception("Configuration", "caloSectors eta range too large for eta_t data type");
for (unsigned int iphi = 0; iphi < phiSlices; ++iphi) {
float phiCenter = reco::reduceRange(iphi * phiWidth +
M_PI / 6.); //L1 TrackFinder phi sector and HGCal sectors shifted by 30deg
float phiCenter = reco::reduceRange(iphi * phiWidth + phiZero);
event_.decoded.hadcalo.emplace_back(etaBoundaries[ieta], etaBoundaries[ieta + 1], phiCenter, phiWidth);
event_.decoded.emcalo.emplace_back(etaBoundaries[ieta], etaBoundaries[ieta + 1], phiCenter, phiWidth);
event_.raw.hgcalcluster.emplace_back(etaBoundaries[ieta], etaBoundaries[ieta + 1], phiCenter, phiWidth);
Expand Down
21 changes: 14 additions & 7 deletions L1Trigger/Phase2L1ParticleFlow/python/l1ctLayer1_cff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import FWCore.ParameterSet.Config as cms

import math

from L1Trigger.Phase2L1ParticleFlow.pfTracksFromL1Tracks_cfi import pfTracksFromL1Tracks
from L1Trigger.Phase2L1ParticleFlow.pfClustersFromL1EGClusters_cfi import pfClustersFromL1EGClusters
from L1Trigger.Phase2L1ParticleFlow.pfClustersFromCombinedCalo_cff import pfClustersFromCombinedCaloHCal, pfClustersFromCombinedCaloHF
Expand Down Expand Up @@ -83,8 +85,9 @@
),
caloSectors = cms.VPSet(
cms.PSet(
etaBoundaries = cms.vdouble(-1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5),
phiSlices = cms.uint32(6)
etaBoundaries = cms.vdouble(-1.5, 1.5),
phiSlices = cms.uint32(3),
phiZero = cms.double(0),
)
),
regions = cms.VPSet(
Expand All @@ -101,11 +104,13 @@
_hgcalSectors = cms.VPSet(
cms.PSet(
etaBoundaries = cms.vdouble(-3.0, -1.5),
phiSlices = cms.uint32(3)
phiSlices = cms.uint32(3),
phiZero = cms.double(math.pi/6) # L1 TrackFinder phi sector and HGCal sectors shifted by 30deg
),
cms.PSet(
etaBoundaries = cms.vdouble(+1.5, +3.0),
phiSlices = cms.uint32(3)
phiSlices = cms.uint32(3),
phiZero = cms.double(math.pi/6)
)

)
Expand Down Expand Up @@ -187,7 +192,7 @@
nIn = cms.uint32(20),
nOut = cms.uint32(20),
nFinalSort = cms.uint32(18),
finalSortAlgo = cms.string("Hybrid"),
finalSortAlgo = cms.string("FoldedHybrid"),
dZ = cms.double(1.33),
dr = cms.double(0.3),
drMin = cms.double(0.04),
Expand Down Expand Up @@ -362,11 +367,13 @@
caloSectors = cms.VPSet(
cms.PSet(
etaBoundaries = cms.vdouble(-5.5, -3.0),
phiSlices = cms.uint32(9)
phiSlices = cms.uint32(9),
phiZero = cms.double(0),
),
cms.PSet(
etaBoundaries = cms.vdouble(+3.0, +5.5),
phiSlices = cms.uint32(9)
phiSlices = cms.uint32(9),
phiZero = cms.double(0),
)
),
regions = cms.VPSet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,46 @@ namespace hybridBitonicSortUtils {
std::swap(a[i], a[j]);
}
}

inline unsigned int bitonicMergeLatencyRef(unsigned int nIn) {
if (nIn <= 1)
return 0;
return 1 +
std::max(bitonicMergeLatencyRef(PowerOf2LessThan(nIn)), bitonicMergeLatencyRef(nIn - PowerOf2LessThan(nIn)));
}

inline unsigned int bitonicSortLatencyRef(unsigned int nIn, unsigned int nOut) {
if (nIn <= 1)
return 0;
unsigned int sort1Size = nIn / 2, sort2Size = nIn - sort1Size;
unsigned int sort1Latency = bitonicSortLatencyRef(sort1Size, nOut);
unsigned int sort2Latency = bitonicSortLatencyRef(sort2Size, nOut);
unsigned int mergeLatency = bitonicMergeLatencyRef(std::min(sort1Size, nOut) + std::min(sort2Size, nOut));
return std::max(sort1Latency, sort2Latency) + mergeLatency;
}

inline unsigned int hybridBitonicSortLatencyRef(unsigned int nIn, unsigned int nOut) {
if (nIn <= 1)
return 0;
if (nIn == 5 || nIn == 6)
return 3;
if (nIn == 12)
return 8;
if (nIn == 13)
return 9;
unsigned int sort1Size = nIn / 2, sort2Size = nIn - sort1Size;
unsigned int sort1Latency = hybridBitonicSortLatencyRef(sort1Size, nOut);
unsigned int sort2Latency = hybridBitonicSortLatencyRef(sort2Size, nOut);
unsigned int mergeLatency = bitonicMergeLatencyRef(std::min(sort1Size, nOut) + std::min(sort2Size, nOut));
return std::max(sort1Latency, sort2Latency) + mergeLatency;
}

// may be specialized for different types if needed
template <typename T>
void clear(T& t) {
t.clear();
}

} // namespace hybridBitonicSortUtils

template <typename T>
Expand All @@ -50,6 +90,26 @@ void hybridBitonicMergeRef(T a[], int N, int low, bool dir) {
}
}

template <typename T>
void check_sorted(T a[], int N, int low, bool dir) {
bool ok = true;
if (dir) {
for (int i = 1; i < N; ++i)
ok = ok && (!(a[low + i - 1] > a[low + i]));
} else {
for (int i = 1; i < N; ++i)
ok = ok && (!(a[low + i - 1] < a[low + i]));
}
if (!ok) {
printf("ERROR in sorting[N=%d,low=%d,dir=%d]: ", N, low, int(dir));
//for (int i = 0; i < N; ++i) printf("%d[%s] ", a[low+i].intPt(), a[low+i].pack().to_string(16).c_str());
//for (int i = 0; i < N; ++i) printf("%d ", a[low+i]);
printf("\n");
fflush(stdout);
assert(ok);
}
}

template <typename T>
void hybridBitonicSortRef(T a[], int N, int low, bool dir, bool hybrid) {
if (hybrid) { // sorting networks defined by hand for a few cases
Expand All @@ -62,6 +122,7 @@ void hybridBitonicSortRef(T a[], int N, int low, bool dir, bool hybrid) {
hybridBitonicSortUtils::compAndSwap(a, low + 1, low + 2, dir);
//---
hybridBitonicSortUtils::compAndSwap(a, low + 0, low + 1, dir);
//check_sorted(a, N, low, dir);
return;
case 4:
hybridBitonicSortUtils::compAndSwap(a, low + 0, low + 1, dir);
Expand All @@ -71,10 +132,11 @@ void hybridBitonicSortRef(T a[], int N, int low, bool dir, bool hybrid) {
hybridBitonicSortUtils::compAndSwap(a, low + 1, low + 3, dir);
//---
hybridBitonicSortUtils::compAndSwap(a, low + 1, low + 2, dir);
//check_sorted(a, N, low, dir);
return;
case 5:
hybridBitonicSortUtils::compAndSwap(a, low + 0, low + 1, dir);
hybridBitonicSortUtils::compAndSwap(a, low + 1, low + 2, dir);
hybridBitonicSortUtils::compAndSwap(a, low + 2, low + 3, dir);
//---
hybridBitonicSortUtils::compAndSwap(a, low + 1, low + 3, dir);
hybridBitonicSortUtils::compAndSwap(a, low + 2, low + 4, dir);
Expand All @@ -86,6 +148,7 @@ void hybridBitonicSortRef(T a[], int N, int low, bool dir, bool hybrid) {
hybridBitonicSortUtils::compAndSwap(a, low + 3, low + 4, dir);
//--
hybridBitonicSortUtils::compAndSwap(a, low + 2, low + 3, dir);
//check_sorted(a, N, low, dir);
return;
case 6:
//---
Expand All @@ -106,6 +169,7 @@ void hybridBitonicSortRef(T a[], int N, int low, bool dir, bool hybrid) {
//---
hybridBitonicSortUtils::compAndSwap(a, low + 1, low + 2, dir);
hybridBitonicSortUtils::compAndSwap(a, low + 3, low + 4, dir);
//check_sorted(a, N, low, dir);
return;
case 12:
for (int i = 0; i < 12; i += 2) {
Expand Down Expand Up @@ -150,6 +214,7 @@ void hybridBitonicSortRef(T a[], int N, int low, bool dir, bool hybrid) {
hybridBitonicSortUtils::compAndSwap(a, low + 3, low + 4, dir);
hybridBitonicSortUtils::compAndSwap(a, low + 5, low + 6, dir);
hybridBitonicSortUtils::compAndSwap(a, low + 7, low + 8, dir);
//check_sorted(a, N, low, dir);
return;
case 13:
for (int i = 0; i + 1 < 13; i += 2) {
Expand Down Expand Up @@ -202,6 +267,7 @@ void hybridBitonicSortRef(T a[], int N, int low, bool dir, bool hybrid) {
hybridBitonicSortUtils::compAndSwap(a, low + 7, low + 8, dir);
hybridBitonicSortUtils::compAndSwap(a, low + 9, low + 10, dir);
hybridBitonicSortUtils::compAndSwap(a, low + 11, low + 12, dir);
//check_sorted(a, N, low, dir);
return;
}
}
Expand All @@ -214,6 +280,7 @@ void hybridBitonicSortRef(T a[], int N, int low, bool dir, bool hybrid) {
hybridBitonicSortRef(a, lowerSize, low, notDir, hybrid);
hybridBitonicSortRef(a, upperSize, low + lowerSize, dir, hybrid);
hybridBitonicMergeRef(a, N, low, dir);
//check_sorted(a, N, low, dir);
}
}

Expand All @@ -230,4 +297,59 @@ void hybrid_bitonic_sort_and_crop_ref(
}
}

template <typename T>
void folded_hybrid_bitonic_sort_and_crop_ref(
unsigned int nIn, unsigned int nOut, const T in[], T out[], bool hybrid = true) { // just an interface
unsigned int nHalf = (nIn + 1) / 2;
T work[nHalf], halfsorted[nHalf];
//printf("hybrid sort input %u items: ", nIn);
//for (int i = 0; i < nIn; ++i) printf("%d.%03d ", work[i].intPt(), work[i].intEta());
//for (int i = 0; i < nIn; ++i) if (in[i].hwPt) printf("[%d]%s ", i, in[i].pack().to_string(16).c_str());
//printf("\n");
//fflush(stdout);
for (int o = 1; o >= 0; --o) {
for (unsigned int i = 0; i < nHalf && 2 * i + o < nIn; ++i) {
work[i] = in[2 * i + o];
}
if ((nIn % 2 == 1) && (o == 1)) {
hybridBitonicSortUtils::clear(work[nHalf - 1]);
}
hybridBitonicSortRef(work, nHalf, 0, false, hybrid);
//printf("hybrid sort offset %d with %u items: ", o, nHalf);
//for (int i = 0; i < nHalf; ++i) printf("%d.%03d ", work[i].intPt(), work[i].intEta());
//for (int i = 0; i < nHalf; ++i) printf("%s ", work[i].pack().to_string(16).c_str());
//printf("\n");
//fflush(stdout);
for (unsigned int i = 1; i < nHalf; ++i)
assert(!(work[i - 1] < work[i]));
if (o == 1) {
for (unsigned int i = 0; i < nHalf; ++i) {
halfsorted[i] = work[i];
}
}
}
// now merge work with the reversed of half-sorted
unsigned int nMerge = std::min(nOut, nHalf);
T tomerge[2 * nMerge];
for (unsigned int i = 0; i < nMerge; ++i) {
tomerge[nMerge - i - 1] = halfsorted[i];
tomerge[nMerge + i] = work[i];
}
//printf("hybrid sort tomerge %u items before: ", 2*nMerge);
//for (int i = 0; i < 2*nMerge; ++i) printf("%d.%03d ", tomerge[i].intPt(), tomerge[i].intEta());
//for (int i = 0; i < 2*nMerge; ++i) printf("%s ", tomerge[i].pack().to_string(16).c_str());
//printf("\n");
hybridBitonicMergeRef(tomerge, 2 * nMerge, 0, false);
//printf("hybrid sort tomerge %u items after: ", 2*nMerge);
//for (int i = 0; i < 2*nMerge; ++i) printf("%d.%03d ", tomerge[i].intPt(), tomerge[i].intEta());
//for (int i = 0; i < nOut; ++i) printf("%s ", tomerge[i].pack().to_string(16).c_str());
//printf("\n");
//fflush(stdout);
for (unsigned int i = 0; i < nOut; ++i) {
out[i] = tomerge[i];
if (i > 0)
assert(!(out[i - 1] < out[i]));
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ inline void _unpack_bool_from_bits(const U& u, unsigned int& start, bool& data)

template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
inline void l1pf_pattern_pack(const T objs[N], ap_uint<NB> data[]) {
#ifdef __SYNTHESIS__
#pragma HLS inline
#pragma HLS inline region recursive
#endif
assert(T::BITWIDTH <= NB);
for (unsigned int i = 0; i < N; ++i) {
#ifdef __SYNTHESIS__
Expand All @@ -41,6 +45,10 @@ inline void l1pf_pattern_pack(const T objs[N], ap_uint<NB> data[]) {

template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
inline void l1pf_pattern_unpack(const ap_uint<NB> data[], T objs[N]) {
#ifdef __SYNTHESIS__
#pragma HLS inline
#pragma HLS inline region recursive
#endif
assert(T::BITWIDTH <= NB);
for (unsigned int i = 0; i < N; ++i) {
#ifdef __SYNTHESIS__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,20 @@ l1ct::PFRegionEmu::PFRegionEmu(
}

bool l1ct::PFRegionEmu::contains(float eta, float phi) const {
float dphi = reco::deltaPhi(floatPhiCenter(), phi);
return (floatEtaMinExtra() < eta && eta <= floatEtaMaxExtra() && -floatPhiHalfWidthExtra() < dphi &&
float dphi = reco::deltaPhi(phi, floatPhiCenter());
return (floatEtaMinExtra() <= eta && eta <= floatEtaMaxExtra() && -floatPhiHalfWidthExtra() <= dphi &&
dphi <= floatPhiHalfWidthExtra());
}
bool l1ct::PFRegionEmu::containsHw(glbeta_t glbeta, glbphi_t glbphi) const {
glbeta_t loceta = glbeta - hwEtaCenter;
ap_int<glbphi_t::width + 1> locphi = glbphi - hwPhiCenter;
if (locphi > Scales::INTPHI_PI)
locphi -= Scales::INTPHI_TWOPI;
else if (locphi <= -Scales::INTPHI_PI)
locphi += Scales::INTPHI_TWOPI;
return isInside(loceta, locphi);
}

float l1ct::PFRegionEmu::localEta(float globalEta) const { return globalEta - floatEtaCenter(); }
float l1ct::PFRegionEmu::localPhi(float globalPhi) const { return reco::deltaPhi(globalPhi, floatPhiCenter()); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace l1ct {

// global coordinates
bool contains(float eta, float phi) const;
bool containsHw(glbeta_t glbeta, glbphi_t phi) const;
float localEta(float globalEta) const;
float localPhi(float globalPhi) const;

Expand Down
Loading

0 comments on commit b739036

Please sign in to comment.