Skip to content

Commit 7eda831

Browse files
committed
Complete emulation of compositeID_EB_v1 and reworking of code for Composite ID models
1 parent 261a935 commit 7eda831

File tree

10 files changed

+13114
-333
lines changed

10 files changed

+13114
-333
lines changed

DataFormats/L1TParticleFlow/interface/datatypes.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ namespace l1ct {
4141

4242
// FIXME: adjust range 10-11bits -> 1/4 - 1/2TeV is probably more than enough for all reasonable use cases
4343
typedef ap_ufixed<11, 9, AP_TRN, AP_SAT> iso_t;
44+
typedef ap_ufixed<6, 0, AP_RND, AP_SAT> rel_iso_t;
45+
typedef ap_ufixed<6, 0, AP_RND, AP_SAT> shower_shape_t;
4446

4547
struct ParticleID {
4648
ap_uint<3> bits;
@@ -142,6 +144,7 @@ namespace l1ct {
142144
};
143145

144146
namespace Scales {
147+
145148
constexpr int INTPHI_PI = 720;
146149
constexpr int INTPHI_TWOPI = 2 * INTPHI_PI;
147150
constexpr float INTPT_LSB = 0.25;
@@ -154,6 +157,7 @@ namespace l1ct {
154157
constexpr float SRRTOT_LSB = 0.0019531250; // pow(2, -9)
155158
constexpr unsigned int SRRTOT_SCALE = 64; // pow(2, 6)
156159
constexpr float HOE_LSB = 0.031250000; // pow(2, -5)
160+
constexpr unsigned int RELISO_SCALE = 16;
157161

158162
inline float floatPt(pt_t pt) { return pt.to_float(); }
159163
inline float floatPt(dpt_t pt) { return pt.to_float(); }
@@ -182,6 +186,8 @@ namespace l1ct {
182186
inline float floatIDScore(id_score_t score) { return score.to_float(); };
183187
inline float floatMass(mass2_t mass) { return mass.to_float(); }
184188
inline float floatIDProb(id_prob_t prob) { return prob.to_float(); };
189+
inline float floatRelIso(rel_iso_t rel_iso) { return rel_iso.to_float() * RELISO_SCALE; }
190+
inline float floatShoweShape(shower_shape_t showe_shape) { return showe_shape.to_float(); }
185191

186192
inline pt_t makePt(int pt) { return ap_ufixed<16, 14>(pt) >> 2; }
187193
inline dpt_t makeDPt(int dpt) { return ap_fixed<18, 16>(dpt) >> 2; }
@@ -216,6 +222,7 @@ namespace l1ct {
216222
inline srrtot_t makeSrrTot(float var) { return srrtot_t(SRRTOT_LSB * round(var * SRRTOT_SCALE / SRRTOT_LSB)); };
217223
inline meanz_t makeMeanZ(float var) { return round(var - MEANZ_OFFSET); };
218224
inline hoe_t makeHoe(float var) { return hoe_t(HOE_LSB * round(var / HOE_LSB)); };
225+
inline rel_iso_t makeRelIso(float var) { return rel_iso_t(var / RELISO_SCALE); };
219226

220227
inline float maxAbsEta() { return ((1 << (eta_t::width - 1)) - 1) * ETAPHI_LSB; }
221228
inline float maxAbsPhi() { return ((1 << (phi_t::width - 1)) - 1) * ETAPHI_LSB; }

DataFormats/L1TParticleFlow/interface/layer1_objs.h

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace l1ct {
6464
static const int BITWIDTH_ENDCAP_SLIM =
6565
pt_t::width + eta_t::width + phi_t::width + pt_t::width + emid_t::width + id_prob_t::width + id_prob_t::width;
6666

67-
static const int BITWIDTH_BARREL = BITWIDTH_BARREL_SLIM; // FIXME: add barrel isolation
67+
static const int BITWIDTH_BARREL = BITWIDTH_BARREL_SLIM;
6868
static const int BITWIDTH_ENDCAP = BITWIDTH_ENDCAP_SLIM + srrtot_t::width + meanz_t::width + hoe_t::width;
6969

7070
inline ap_uint<BITWIDTH_ENDCAP> pack_endcap() const {
@@ -100,6 +100,7 @@ namespace l1ct {
100100

101101
inline static HadCaloObj unpack_barrel(const ap_uint<BITWIDTH_BARREL> &src) {
102102
HadCaloObj ret;
103+
ret.clear();
103104
unsigned int start = 0;
104105
unpack_from_bits(src, start, ret.hwPt);
105106
unpack_from_bits(src, start, ret.hwEta);
@@ -111,6 +112,7 @@ namespace l1ct {
111112

112113
inline static HadCaloObj unpack_endcap(const ap_uint<BITWIDTH_ENDCAP> &src) {
113114
HadCaloObj ret;
115+
ret.clear();
114116
unsigned int start = 0;
115117
unpack_from_bits(src, start, ret.hwPt);
116118
unpack_from_bits(src, start, ret.hwEta);
@@ -172,6 +174,8 @@ namespace l1ct {
172174
eta_t hwEta; // relative to the region center, at calo
173175
phi_t hwPhi; // relative to the region center, at calo
174176
emid_t hwEmID;
177+
shower_shape_t hwShowerShape;
178+
rel_iso_t hwRelIso;
175179
srrtot_t hwSrrTot;
176180
meanz_t hwMeanZ;
177181
hoe_t hwHoe;
@@ -180,7 +184,8 @@ namespace l1ct {
180184

181185
inline bool operator==(const EmCaloObj &other) const {
182186
return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwPtErr == other.hwPtErr &&
183-
hwEmID == other.hwEmID && hwSrrTot == other.hwSrrTot && hwMeanZ == other.hwMeanZ && hwHoe == other.hwHoe &&
187+
hwEmID == other.hwEmID && hwShowerShape == other.hwShowerShape && hwRelIso == other.hwRelIso &&
188+
hwSrrTot == other.hwSrrTot && hwMeanZ == other.hwMeanZ && hwHoe == other.hwHoe &&
184189
hwPiProb == other.hwPiProb && hwEmProb == other.hwEmProb;
185190
}
186191

@@ -193,6 +198,8 @@ namespace l1ct {
193198
hwEta = 0;
194199
hwPhi = 0;
195200
hwEmID = 0;
201+
hwShowerShape = 0;
202+
hwRelIso = 0;
196203
hwSrrTot = 0;
197204
hwMeanZ = 0;
198205
hwHoe = 0;
@@ -211,6 +218,8 @@ namespace l1ct {
211218
float floatPtErr() const { return Scales::floatPt(hwPtErr); }
212219
float floatEta() const { return Scales::floatEta(hwEta); }
213220
float floatPhi() const { return Scales::floatPhi(hwPhi); }
221+
float floatShowerShape() const { return Scales::floatShoweShape(hwShowerShape); }
222+
float floatRelIso() const { return Scales::floatRelIso(hwRelIso); }
214223
float floatSrrTot() const { return Scales::floatSrrTot(hwSrrTot); };
215224
float floatMeanZ() const { return Scales::floatMeanZ(hwMeanZ); };
216225
float floatHoe() const { return Scales::floatHoe(hwHoe); };
@@ -222,7 +231,7 @@ namespace l1ct {
222231
static const int BITWIDTH_ENDCAP_SLIM =
223232
pt_t::width + pt_t::width + eta_t::width + phi_t::width + emid_t::width + id_prob_t::width + id_prob_t::width;
224233

225-
static const int BITWIDTH_BARREL = BITWIDTH_BARREL_SLIM; // FIXME: add barrel isolation
234+
static const int BITWIDTH_BARREL = BITWIDTH_BARREL_SLIM + shower_shape_t::width + rel_iso_t::width;
226235
static const int BITWIDTH_ENDCAP = BITWIDTH_ENDCAP_SLIM + srrtot_t::width + meanz_t::width + hoe_t::width;
227236

228237
inline ap_uint<BITWIDTH_ENDCAP> pack_endcap() const {
@@ -251,24 +260,30 @@ namespace l1ct {
251260
pack_into_bits(ret, start, hwPhi);
252261
pack_into_bits(ret, start, hwPtErr);
253262
pack_into_bits(ret, start, hwEmID);
263+
pack_into_bits(ret, start, hwShowerShape);
264+
pack_into_bits(ret, start, hwRelIso);
254265
return ret;
255266
}
256267

257268
inline ap_uint<BITWIDTH_BARREL_SLIM> pack_barrel_slim() const { return pack_barrel()(BITWIDTH_BARREL_SLIM - 1, 0); }
258269

259270
inline static EmCaloObj unpack_barrel(const ap_uint<BITWIDTH_BARREL> &src) {
260271
EmCaloObj ret;
272+
ret.clear();
261273
unsigned int start = 0;
262274
unpack_from_bits(src, start, ret.hwPt);
263275
unpack_from_bits(src, start, ret.hwEta);
264276
unpack_from_bits(src, start, ret.hwPhi);
265277
unpack_from_bits(src, start, ret.hwPtErr);
266278
unpack_from_bits(src, start, ret.hwEmID);
279+
unpack_from_bits(src, start, ret.hwShowerShape);
280+
unpack_from_bits(src, start, ret.hwRelIso);
267281
return ret;
268282
}
269283

270284
inline static EmCaloObj unpack_endcap(const ap_uint<BITWIDTH_ENDCAP> &src) {
271285
EmCaloObj ret;
286+
ret.clear();
272287
unsigned int start = 0;
273288
unpack_from_bits(src, start, ret.hwPt);
274289
unpack_from_bits(src, start, ret.hwEta);
@@ -289,7 +304,8 @@ namespace l1ct {
289304
// The firmware implementation should actually use the specific pack/unpack implementations
290305

291306
static const int BITWIDTH = pt_t::width + pt_t::width + eta_t::width + phi_t::width + emid_t::width +
292-
id_prob_t::width + id_prob_t::width + srrtot_t::width + meanz_t::width + hoe_t::width;
307+
shower_shape_t::width + rel_iso_t::width + id_prob_t::width + id_prob_t::width +
308+
srrtot_t::width + meanz_t::width + hoe_t::width;
293309

294310
inline ap_uint<BITWIDTH> pack() const {
295311
ap_uint<BITWIDTH> ret;
@@ -299,6 +315,8 @@ namespace l1ct {
299315
pack_into_bits(ret, start, hwPhi);
300316
pack_into_bits(ret, start, hwPtErr);
301317
pack_into_bits(ret, start, hwEmID);
318+
pack_into_bits(ret, start, hwShowerShape);
319+
pack_into_bits(ret, start, hwRelIso);
302320
pack_into_bits(ret, start, hwPiProb);
303321
pack_into_bits(ret, start, hwEmProb);
304322
pack_into_bits(ret, start, hwSrrTot);
@@ -314,6 +332,8 @@ namespace l1ct {
314332
unpack_from_bits(src, start, ret.hwPhi);
315333
unpack_from_bits(src, start, ret.hwPtErr);
316334
unpack_from_bits(src, start, ret.hwEmID);
335+
unpack_from_bits(src, start, ret.hwShowerShape);
336+
unpack_from_bits(src, start, ret.hwRelIso);
317337
unpack_from_bits(src, start, ret.hwPiProb);
318338
unpack_from_bits(src, start, ret.hwEmProb);
319339
unpack_from_bits(src, start, ret.hwSrrTot);
@@ -480,6 +500,7 @@ namespace l1ct {
480500

481501
inline static TkObj unpack_barrel(const ap_uint<BITWIDTH_BARREL> &src) {
482502
TkObj ret;
503+
ret.clear();
483504
unsigned int start = 0;
484505
unpack_from_bits(src, start, ret.hwPt);
485506
unpack_from_bits(src, start, ret.hwEta);
@@ -496,6 +517,7 @@ namespace l1ct {
496517

497518
inline static TkObj unpack_endcap(const ap_uint<BITWIDTH_ENDCAP> &src) {
498519
TkObj ret;
520+
ret.clear();
499521
unsigned int start = 0;
500522
unpack_from_bits(src, start, ret.hwPt);
501523
unpack_from_bits(src, start, ret.hwEta);
@@ -514,7 +536,6 @@ namespace l1ct {
514536
}
515537

516538
inline ap_uint<BITWIDTH_SLIM> pack_slim() const { return pack_endcap()(BITWIDTH_SLIM - 1, 0); }
517-
518539
};
519540
inline void clear(TkObj &c) { c.clear(); }
520541

0 commit comments

Comments
 (0)