Skip to content

Commit 7590d1d

Browse files
authored
Merge pull request #48002 from cerminar/151X_calodev_v2
[L1T] Restructure handling of Calorimeter input to Correlator Layer-1 + new TkElectrons in barrel (Phase-2)
2 parents 54ea8be + 67e188a commit 7590d1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3433
-1012
lines changed

DataFormats/L1TCorrelator/src/TkEm.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
//
66

77
#include "DataFormats/L1TCorrelator/interface/TkEm.h"
8-
// FIXME: can remove
9-
#include "DataFormats/Common/interface/RefToPtr.h"
108

119
using namespace l1t;
1210

DataFormats/L1TParticleFlow/interface/PFCandidate.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
#define DataFormats_L1TParticleFlow_PFCandidate_h
33

44
#include <vector>
5-
#include "DataFormats/L1Trigger/interface/L1Candidate.h"
65
#include "DataFormats/L1TMuonPhase2/interface/SAMuon.h"
7-
#include "DataFormats/L1TParticleFlow/interface/PFCluster.h"
86
#include "DataFormats/L1TParticleFlow/interface/PFTrack.h"
97
#include "DataFormats/L1Trigger/interface/RegionalOutput.h"
108

@@ -13,6 +11,7 @@ namespace l1t {
1311
class PFCandidate : public L1Candidate {
1412
public:
1513
typedef l1t::SAMuonRef MuonRef;
14+
typedef edm::Ptr<l1t::L1Candidate> L1CandPtr;
1615
enum ParticleType { ChargedHadron = 0, Electron = 1, NeutralHadron = 2, Photon = 3, Muon = 4 };
1716

1817
PFCandidate() {}
@@ -37,8 +36,8 @@ namespace l1t {
3736
const PFTrackRef& pfTrack() const { return trackRef_; }
3837
void setPFTrack(const PFTrackRef& ref) { trackRef_ = ref; }
3938

40-
const PFClusterRef& pfCluster() const { return clusterRef_; }
41-
void setPFCluster(const PFClusterRef& ref) { clusterRef_ = ref; }
39+
const L1CandPtr& caloPtr() const { return caloPtr_; }
40+
void setCaloPtr(const L1CandPtr& ptr) { caloPtr_ = ptr; }
4241

4342
const MuonRef& muon() const { return muonRef_; }
4443
void setMuon(const MuonRef& ref) { muonRef_ = ref; }
@@ -71,7 +70,7 @@ namespace l1t {
7170
void setEncodedPuppi64(uint64_t encodedPuppi64) { encodedPuppi64_ = encodedPuppi64; }
7271

7372
private:
74-
PFClusterRef clusterRef_;
73+
L1CandPtr caloPtr_;
7574
PFTrackRef trackRef_;
7675
MuonRef muonRef_;
7776
float dxy_, puppiWeight_, caloEta_, caloPhi_;

DataFormats/L1TParticleFlow/interface/PFCluster.h

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
#define DataFormats_L1TParticleFlow_PFCluster_h
33

44
#include <vector>
5+
#include <variant>
56
#include "DataFormats/L1Trigger/interface/L1Candidate.h"
67
#include "DataFormats/Common/interface/Ref.h"
8+
#include "DataFormats/L1TParticleFlow/interface/layer1_objs.h"
9+
#include <ap_int.h>
710

811
namespace l1t {
912

@@ -22,14 +25,13 @@ namespace l1t {
2225
float ptError = 0,
2326
int hwpt = 0,
2427
int hweta = 0,
25-
int hwphi = 0,
26-
float absZBarycenter = 0.,
27-
float sigmaRR = 0.)
28+
int hwphi = 0)
2829
: L1Candidate(PolarLorentzVector(pt, eta, phi, 0), hwpt, hweta, hwphi, /*hwQuality=*/isEM ? 1 : 0),
2930
hOverE_(hOverE),
3031
ptError_(ptError),
31-
absZBarycenter_(absZBarycenter),
32-
sigmaRR_(sigmaRR) {
32+
encoding_(HWEncoding::None),
33+
digiDataW0_(0),
34+
digiDataW1_(0) {
3335
setPdgId(isEM ? 22 : 130); // photon : non-photon(K0)
3436
}
3537
PFCluster(
@@ -38,15 +40,12 @@ namespace l1t {
3840
setPdgId(isEM ? 22 : 130); // photon : non-photon(K0)
3941
}
4042

43+
enum class HWEncoding { None = 0, Had = 1, Em = 2 };
44+
4145
float hOverE() const { return hOverE_; }
4246
void setHOverE(float hOverE) { hOverE_ = hOverE; }
4347

44-
void setSigmaRR(float sigmaRR) { sigmaRR_ = sigmaRR; }
45-
float absZBarycenter() const { return absZBarycenter_; }
46-
47-
void setAbsZBarycenter(float absZBarycenter) { absZBarycenter_ = absZBarycenter; }
48-
float sigmaRR() const { return sigmaRR_; }
49-
48+
// NOTE: this might not be consistent with the value stored in the HW digi
5049
float emEt() const {
5150
if (hOverE_ == -1)
5251
return 0;
@@ -70,18 +69,43 @@ namespace l1t {
7069
void setIsEM(bool isEM) { setHwQual(isEM); }
7170
unsigned int hwEmID() const { return hwQual(); }
7271

73-
float egVsPionMVAOut() const { return egVsPionMVAOut_; }
74-
void setEgVsPionMVAOut(float egVsPionMVAOut) { egVsPionMVAOut_ = egVsPionMVAOut; }
72+
std::variant<l1ct::HadCaloObj, l1ct::EmCaloObj> caloDigiObj() const {
73+
switch (encoding_) {
74+
case HWEncoding::Had:
75+
return l1ct::HadCaloObj::unpack(binaryWord<l1ct::HadCaloObj::BITWIDTH>());
76+
case HWEncoding::Em:
77+
return l1ct::EmCaloObj::unpack(binaryWord<l1ct::EmCaloObj::BITWIDTH>());
78+
default:
79+
throw std::runtime_error("No encoding for this cluster");
80+
}
81+
}
82+
83+
void setCaloDigi(const l1ct::HadCaloObj& obj) { setBinaryWord(obj.pack(), HWEncoding::Had); }
84+
85+
void setCaloDigi(const l1ct::EmCaloObj& obj) { setBinaryWord(obj.pack(), HWEncoding::Em); }
7586

76-
float egVsPUMVAOut() const { return egVsPUMVAOut_; }
77-
void setEgVsPUMVAOut(float egVsPUMVAOut) { egVsPUMVAOut_ = egVsPUMVAOut; }
87+
HWEncoding encoding() const { return encoding_; }
7888

7989
private:
80-
float hOverE_, ptError_, egVsPionMVAOut_, egVsPUMVAOut_;
81-
// HGC dedicated quantities (0ed by default)
82-
float absZBarycenter_, sigmaRR_;
90+
float hOverE_, ptError_;
8391

8492
ConstituentsAndFractions constituents_;
93+
94+
template <int N>
95+
void setBinaryWord(ap_uint<N> word, HWEncoding encoding) {
96+
digiDataW0_ = word;
97+
digiDataW1_ = (word >> 64);
98+
encoding_ = encoding;
99+
}
100+
101+
template <int N>
102+
ap_uint<N> binaryWord() const {
103+
return ap_uint<N>(digiDataW0_) | (ap_uint<N>(digiDataW1_) << 64);
104+
}
105+
106+
HWEncoding encoding_;
107+
uint64_t digiDataW0_;
108+
uint64_t digiDataW1_;
85109
};
86110

87111
typedef std::vector<l1t::PFCluster> PFClusterCollection;

DataFormats/L1TParticleFlow/interface/bit_encoding.h

Lines changed: 160 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define DATAFORMATS_L1TPARTICLEFLOW_ENCODING_H
33

44
#include <cassert>
5+
#include <type_traits>
6+
57
#include "DataFormats/L1TParticleFlow/interface/datatypes.h"
68

79
template <typename U, typename T>
@@ -28,64 +30,210 @@ inline void unpack_bool_from_bits(const U& u, unsigned int& start, bool& data) {
2830
data = u[start++];
2931
}
3032

31-
template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
33+
// Enum to define different packing strategies for data encoding
34+
// DEFAULT: Standard packing
35+
// BARREL: Packing strategy for barrel region
36+
// ENDCAP: Packing strategy for endcap region
37+
enum class PackingStrategy { DEFAULT, BARREL, ENDCAP };
38+
39+
// Default case: Calls T::unpack()
40+
template <typename T,
41+
int NB,
42+
PackingStrategy METHOD = PackingStrategy::DEFAULT,
43+
typename std::enable_if<METHOD == PackingStrategy::DEFAULT, int>::type = 0>
44+
inline auto unpack_helper(const ap_uint<NB>& data) {
45+
static_assert(T::BITWIDTH <= NB, "NB Type is too small for the object");
46+
return T::unpack(data);
47+
}
48+
49+
// Specialization for BARREL
50+
template <typename T,
51+
int NB,
52+
PackingStrategy METHOD,
53+
typename std::enable_if<METHOD == PackingStrategy::BARREL, int>::type = 0>
54+
inline auto unpack_helper(const ap_uint<NB>& data) {
55+
static_assert(T::BITWIDTH_BARREL <= NB, "NB Type is too small for the object");
56+
return T::unpack_barrel(data);
57+
}
58+
59+
// Specialization for ENDCAP
60+
template <typename T,
61+
int NB,
62+
PackingStrategy METHOD,
63+
typename std::enable_if<METHOD == PackingStrategy::ENDCAP, int>::type = 0>
64+
inline auto unpack_helper(const ap_uint<NB>& data) {
65+
static_assert(T::BITWIDTH_ENDCAP <= NB, "NB Type is too small for the object");
66+
return T::unpack_endcap(data);
67+
}
68+
69+
// Default case: Calls T::unpack()
70+
template <typename T,
71+
int NB,
72+
PackingStrategy METHOD = PackingStrategy::DEFAULT,
73+
typename std::enable_if<METHOD == PackingStrategy::DEFAULT, int>::type = 0>
74+
inline auto unpack_slim_helper(const ap_uint<NB>& data) {
75+
static_assert(T::BITWIDTH_SLIM <= NB, "NB Type is too small for the object");
76+
return T::unpack(data);
77+
}
78+
79+
// Specialization for BARREL
80+
template <typename T,
81+
int NB,
82+
PackingStrategy METHOD,
83+
typename std::enable_if<METHOD == PackingStrategy::BARREL, int>::type = 0>
84+
inline auto unpack_slim_helper(const ap_uint<NB>& data) {
85+
static_assert(T::BITWIDTH_BARREL_SLIM <= NB, "NB Type is too small for the object");
86+
return T::unpack_barrel(data);
87+
}
88+
89+
// Specialization for ENDCAP
90+
template <typename T,
91+
int NB,
92+
PackingStrategy METHOD,
93+
typename std::enable_if<METHOD == PackingStrategy::ENDCAP, int>::type = 0>
94+
inline auto unpack_slim_helper(const ap_uint<NB>& data) {
95+
static_assert(T::BITWIDTH_ENDCAP_SLIM <= NB, "NB Type is too small for the object");
96+
return T::unpack_endcap(data);
97+
}
98+
99+
// Default case: Calls T::unpack()
100+
template <typename T,
101+
int NB,
102+
PackingStrategy METHOD = PackingStrategy::DEFAULT,
103+
typename std::enable_if<METHOD == PackingStrategy::DEFAULT, int>::type = 0>
104+
inline auto pack_helper(const T& obj) {
105+
static_assert(T::BITWIDTH <= NB, "NB Type is too small for the object");
106+
return obj.pack();
107+
}
108+
109+
// Specialization for BARREL
110+
template <typename T,
111+
int NB,
112+
PackingStrategy METHOD,
113+
typename std::enable_if<METHOD == PackingStrategy::BARREL, int>::type = 0>
114+
inline auto pack_helper(const T& obj) {
115+
static_assert(T::BITWIDTH_BARREL <= NB, "NB Type is too small for the object");
116+
return obj.pack_barrel();
117+
}
118+
119+
// Specialization for ENDCAP
120+
template <typename T,
121+
int NB,
122+
PackingStrategy METHOD,
123+
typename std::enable_if<METHOD == PackingStrategy::ENDCAP, int>::type = 0>
124+
inline auto pack_helper(const T& obj) {
125+
static_assert(T::BITWIDTH_ENDCAP <= NB, "NB Type is too small for the object");
126+
return obj.pack_endcap();
127+
}
128+
129+
// Default case: Calls T::unpack()
130+
template <typename T,
131+
int NB,
132+
PackingStrategy METHOD = PackingStrategy::DEFAULT,
133+
typename std::enable_if<METHOD == PackingStrategy::DEFAULT, int>::type = 0>
134+
inline auto pack_slim_helper(const T& obj) {
135+
static_assert(T::BITWIDTH_SLIM <= NB, "NB Type is too small for the object");
136+
return obj.pack_slim();
137+
}
138+
139+
// Specialization for BARREL
140+
template <typename T,
141+
int NB,
142+
PackingStrategy METHOD,
143+
typename std::enable_if<METHOD == PackingStrategy::BARREL, int>::type = 0>
144+
inline auto pack_slim_helper(const T& obj) {
145+
static_assert(T::BITWIDTH_BARREL_SLIM <= NB, "NB Type is too small for the object");
146+
return obj.pack_barrel_slim();
147+
}
148+
149+
// Specialization for ENDCAP
150+
template <typename T,
151+
int NB,
152+
PackingStrategy METHOD,
153+
typename std::enable_if<METHOD == PackingStrategy::ENDCAP, int>::type = 0>
154+
inline auto pack_slim_helper(const T& obj) {
155+
static_assert(T::BITWIDTH_ENDCAP_SLIM <= NB, "NB Type is too small for the object");
156+
return obj.pack_endcap_slim();
157+
}
158+
159+
template <unsigned int N, PackingStrategy METHOD = PackingStrategy::DEFAULT, unsigned int OFFS = 0, typename T, int NB>
32160
inline void l1pf_pattern_pack(const T objs[N], ap_uint<NB> data[]) {
33161
#ifdef __SYNTHESIS__
34162
#pragma HLS inline
35163
#pragma HLS inline region recursive
36164
#endif
37-
assert(T::BITWIDTH <= NB);
38165
for (unsigned int i = 0; i < N; ++i) {
39166
#ifdef __SYNTHESIS__
40167
#pragma HLS unroll
41168
#endif
42-
data[i + OFFS] = objs[i].pack();
169+
data[i + OFFS] = pack_helper<T, NB, METHOD>(objs[i]);
43170
}
44171
}
45172

46-
template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
173+
// overlaod for default strategy
174+
template <unsigned int N, unsigned int OFFS, typename T, int NB>
175+
inline void l1pf_pattern_pack(const T objs[N], ap_uint<NB> data[]) {
176+
l1pf_pattern_pack<N, PackingStrategy::DEFAULT, OFFS, T, NB>(objs, data);
177+
}
178+
179+
template <unsigned int N, PackingStrategy METHOD = PackingStrategy::DEFAULT, unsigned int OFFS = 0, typename T, int NB>
47180
inline void l1pf_pattern_unpack(const ap_uint<NB> data[], T objs[N]) {
48181
#ifdef __SYNTHESIS__
49182
#pragma HLS inline
50183
#pragma HLS inline region recursive
51184
#endif
52-
assert(T::BITWIDTH <= NB);
53185
for (unsigned int i = 0; i < N; ++i) {
54186
#ifdef __SYNTHESIS__
55187
#pragma HLS unroll
56188
#endif
57-
objs[i] = T::unpack(data[i + OFFS]);
189+
objs[i] = unpack_helper<T, NB, METHOD>(data[i + OFFS]);
58190
}
59191
}
60192

61-
template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
193+
// overlaod for default strategy
194+
template <unsigned int N, unsigned int OFFS, typename T, int NB>
195+
inline void l1pf_pattern_unpack(const ap_uint<NB> data[], T objs[N]) {
196+
l1pf_pattern_unpack<N, PackingStrategy::DEFAULT, OFFS, T, NB>(data, objs);
197+
}
198+
199+
template <unsigned int N, PackingStrategy METHOD = PackingStrategy::DEFAULT, unsigned int OFFS = 0, typename T, int NB>
62200
inline void l1pf_pattern_pack_slim(const T objs[N], ap_uint<NB> data[]) {
63201
#ifdef __SYNTHESIS__
64202
#pragma HLS inline
65203
#pragma HLS inline region recursive
66204
#endif
67-
assert(T::BITWIDTH_SLIM <= NB);
68205
for (unsigned int i = 0; i < N; ++i) {
69206
#ifdef __SYNTHESIS__
70207
#pragma HLS unroll
71208
#endif
72-
data[i + OFFS] = objs[i].pack_slim();
209+
data[i + OFFS] = pack_slim_helper<T, NB, METHOD>(objs[i]);
73210
}
74211
}
75212

76-
template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
213+
// overlaod for default strategy
214+
template <unsigned int N, unsigned int OFFS, typename T, int NB>
215+
inline void l1pf_pattern_pack_slim(const T objs[N], ap_uint<NB> data[]) {
216+
l1pf_pattern_pack_slim<N, PackingStrategy::DEFAULT, OFFS, T, NB>(objs, data);
217+
}
218+
219+
template <unsigned int N, PackingStrategy METHOD = PackingStrategy::DEFAULT, unsigned int OFFS = 0, typename T, int NB>
77220
inline void l1pf_pattern_unpack_slim(const ap_uint<NB> data[], T objs[N]) {
78221
#ifdef __SYNTHESIS__
79222
#pragma HLS inline
80223
#pragma HLS inline region recursive
81224
#endif
82-
assert(T::BITWIDTH_SLIM <= NB);
83225
for (unsigned int i = 0; i < N; ++i) {
84226
#ifdef __SYNTHESIS__
85227
#pragma HLS unroll
86228
#endif
87-
objs[i] = T::unpack(data[i + OFFS]);
229+
objs[i] = unpack_slim_helper<T, NB, METHOD>(data[i + OFFS]);
88230
}
89231
}
90232

233+
// overlaod for default strategy
234+
template <unsigned int N, unsigned int OFFS, typename T, int NB>
235+
inline void l1pf_pattern_unpack_slim(const ap_uint<NB> data[], T objs[N]) {
236+
l1pf_pattern_unpack_slim<N, PackingStrategy::DEFAULT, OFFS, T, NB>(data, objs);
237+
}
238+
91239
#endif

0 commit comments

Comments
 (0)