Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure CTL1 input handling #129

Draft
wants to merge 22 commits into
base: L1PF_14_2_X
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
86346a0
Initial prototype to integrate the new multiclass model
cerminar Apr 4, 2024
7b20cad
skeleton for hgc multiclass id integration
Apr 30, 2024
14659f4
Switch to emulated crystal clusters and store digitized version in PF…
cerminar May 23, 2024
834389d
Initial implementation of new barrel and endcap Composite ID model
cerminar Aug 27, 2024
69a4f66
Update HGC multiclass ID to EEmulticlass_tinymodel and pT binned WPs
Sep 26, 2024
d3e5ba8
set photon WP to false and fix the quality for collection before sele…
cerminar Nov 11, 2024
1290f27
Fist step towards removing input conversion to PFCluster.
cerminar Nov 14, 2024
36e86f7
Initial implementation of HGC cluster encoding/decoding + multiclass …
cerminar Nov 27, 2024
266b841
Move emulator objects sources to L1Candidate + code format
cerminar Dec 9, 2024
66326c8
Restructure model configuration and handling
cerminar Dec 11, 2024
273c800
Remove redundant conifer header
cerminar Dec 11, 2024
f30bff2
Add chi2 to Tk format for PF and start adding ID prob to calo cluster…
cerminar Dec 12, 2024
9b15abb
Towards a more realistic implementation + some cleaning
cerminar Dec 13, 2024
63c51b8
Complete info into decoded PFClusters
cerminar Dec 13, 2024
3f3c71f
Propagate multiclass weights and handles hoe and EM scenarios
cerminar Dec 17, 2024
b94a4f4
Restructure the PFCluster object to store the decoded calorimeter inf…
cerminar Jan 13, 2025
2224834
Fix eta phi bias in GCT clusters + some cosmetics
cerminar Jan 20, 2025
5d6c41b
Update to more recent geometry
cerminar Jan 10, 2025
a0b910d
Schema evolution for PFCandidates ref2calo
cerminar Jan 27, 2025
e7cab22
Code format
cerminar Jan 29, 2025
d8ac857
Switch off calibration for GCT EM clusters
cerminar Feb 4, 2025
1dd1a81
equip for endcap barrel dedicated packing and unpacking of calo objs
cerminar Feb 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions DataFormats/L1TCorrelator/src/TkEm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
//

#include "DataFormats/L1TCorrelator/interface/TkEm.h"
// FIXME: can remove
#include "DataFormats/Common/interface/RefToPtr.h"

using namespace l1t;

Expand Down
9 changes: 4 additions & 5 deletions DataFormats/L1TParticleFlow/interface/PFCandidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#define DataFormats_L1TParticleFlow_PFCandidate_h

#include <vector>
#include "DataFormats/L1Trigger/interface/L1Candidate.h"
#include "DataFormats/L1TMuonPhase2/interface/SAMuon.h"
#include "DataFormats/L1TParticleFlow/interface/PFCluster.h"
#include "DataFormats/L1TParticleFlow/interface/PFTrack.h"
#include "DataFormats/L1Trigger/interface/RegionalOutput.h"

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

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

const PFClusterRef& pfCluster() const { return clusterRef_; }
void setPFCluster(const PFClusterRef& ref) { clusterRef_ = ref; }
const L1CandPtr& caloPtr() const { return caloPtr_; }
void setCaloPtr(const L1CandPtr& ptr) { caloPtr_ = ptr; }

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

private:
PFClusterRef clusterRef_;
L1CandPtr caloPtr_;
PFTrackRef trackRef_;
MuonRef muonRef_;
float dxy_, puppiWeight_, caloEta_, caloPhi_;
Expand Down
60 changes: 42 additions & 18 deletions DataFormats/L1TParticleFlow/interface/PFCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
#define DataFormats_L1TParticleFlow_PFCluster_h

#include <vector>
#include <variant>
#include "DataFormats/L1Trigger/interface/L1Candidate.h"
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/L1TParticleFlow/interface/layer1_objs.h"
#include <ap_int.h>

namespace l1t {

Expand All @@ -22,14 +25,13 @@ namespace l1t {
float ptError = 0,
int hwpt = 0,
int hweta = 0,
int hwphi = 0,
float absZBarycenter = 0.,
float sigmaRR = 0.)
int hwphi = 0)
: L1Candidate(PolarLorentzVector(pt, eta, phi, 0), hwpt, hweta, hwphi, /*hwQuality=*/isEM ? 1 : 0),
hOverE_(hOverE),
ptError_(ptError),
absZBarycenter_(absZBarycenter),
sigmaRR_(sigmaRR) {
encoding_(HWEncoding::None),
digiDataW0_(0),
digiDataW1_(0) {
setPdgId(isEM ? 22 : 130); // photon : non-photon(K0)
}
PFCluster(
Expand All @@ -38,15 +40,12 @@ namespace l1t {
setPdgId(isEM ? 22 : 130); // photon : non-photon(K0)
}

enum class HWEncoding { None = 0, Had = 1, Em = 2, Gct = 3 };

float hOverE() const { return hOverE_; }
void setHOverE(float hOverE) { hOverE_ = hOverE; }

void setSigmaRR(float sigmaRR) { sigmaRR_ = sigmaRR; }
float absZBarycenter() const { return absZBarycenter_; }

void setAbsZBarycenter(float absZBarycenter) { absZBarycenter_ = absZBarycenter; }
float sigmaRR() const { return sigmaRR_; }

// FIXME: this might nor be consistent with the value stored in the HW digi
float emEt() const {
if (hOverE_ == -1)
return 0;
Expand All @@ -70,18 +69,43 @@ namespace l1t {
void setIsEM(bool isEM) { setHwQual(isEM); }
unsigned int hwEmID() const { return hwQual(); }

float egVsPionMVAOut() const { return egVsPionMVAOut_; }
void setEgVsPionMVAOut(float egVsPionMVAOut) { egVsPionMVAOut_ = egVsPionMVAOut; }
std::variant<l1ct::HadCaloObj, l1ct::EmCaloObj> caloDigiObj() const {
switch (encoding_) {
case HWEncoding::Had:
return l1ct::HadCaloObj::unpack(binaryWord<l1ct::HadCaloObj::BITWIDTH>());
case HWEncoding::Em:
return l1ct::EmCaloObj::unpack(binaryWord<l1ct::EmCaloObj::BITWIDTH>());
default:
throw std::runtime_error("No encoding for this cluster");
}
}

void setCaloDigi(const l1ct::HadCaloObj& obj) { setBinaryWord(obj.pack(), HWEncoding::Had); }

void setCaloDigi(const l1ct::EmCaloObj& obj) { setBinaryWord(obj.pack(), HWEncoding::Em); }

float egVsPUMVAOut() const { return egVsPUMVAOut_; }
void setEgVsPUMVAOut(float egVsPUMVAOut) { egVsPUMVAOut_ = egVsPUMVAOut; }
HWEncoding encoding() const { return encoding_; }

private:
float hOverE_, ptError_, egVsPionMVAOut_, egVsPUMVAOut_;
// HGC dedicated quantities (0ed by default)
float absZBarycenter_, sigmaRR_;
float hOverE_, ptError_;

ConstituentsAndFractions constituents_;

template <int N>
void setBinaryWord(ap_uint<N> word, HWEncoding encoding) {
digiDataW0_ = word;
digiDataW1_ = (word >> 64);
encoding_ = encoding;
}

template <int N>
ap_uint<N> binaryWord() const {
return ap_uint<N>(digiDataW0_) | (ap_uint<N>(digiDataW1_) << 64);
}

HWEncoding encoding_;
uint64_t digiDataW0_;
uint64_t digiDataW1_;
};

typedef std::vector<l1t::PFCluster> PFClusterCollection;
Expand Down
68 changes: 56 additions & 12 deletions DataFormats/L1TParticleFlow/interface/bit_encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,63 +28,107 @@ inline void unpack_bool_from_bits(const U& u, unsigned int& start, bool& data) {
data = u[start++];
}

template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
enum class PackingStrategy { DEFAULT, BARREL, ENDCAP };

// Helper function that calls the correct unpack method based on user input
template <typename T, int NB, PackingStrategy METHOD = PackingStrategy::DEFAULT>
inline auto unpack_helper(const ap_uint<NB>& data) {
if constexpr (METHOD == PackingStrategy::BARREL) {
static_assert(T::BITWIDTH_BARREL <= NB, "NB Type is too small for the object");
return T::unpack_barrel(data);
} else if constexpr (METHOD == PackingStrategy::ENDCAP) {
static_assert(T::BITWIDTH_ENDCAP <= NB, "NB Type is too small for the object");
return T::unpack_endcap(data);
} else {
static_assert(T::BITWIDTH <= NB, "NB Type is too small for the object");
return T::unpack(data);
}
}

template <typename T, int NB, PackingStrategy METHOD = PackingStrategy::DEFAULT>
inline auto pack_helper(const T& obj) {
if constexpr (METHOD == PackingStrategy::BARREL) {
static_assert(T::BITWIDTH_BARREL <= NB, "NB Type is too small for the object");

return obj.pack_barrel();
} else if constexpr (METHOD == PackingStrategy::ENDCAP) {
static_assert(T::BITWIDTH_ENDCAP <= NB, "NB Type is too small for the object");

return obj.pack_endcap();
} else {
static_assert(T::BITWIDTH <= NB, "NB Type is too small for the object");

return obj.pack();
}
}

template <typename T, int NB, PackingStrategy METHOD>
inline auto pack_slim_helper(const T& obj) {
if constexpr (METHOD == PackingStrategy::BARREL) {
static_assert(T::BITWIDTH_BARREL_SLIM <= NB, "NB Type is too small for the object");
return obj.pack_barrel_slim();
} else if constexpr (METHOD == PackingStrategy::ENDCAP) {
static_assert(T::BITWIDTH_ENDCAP_SLIM <= NB, "NB Type is too small for the object");
return obj.pack_endcap_slim();
} else {
static_assert(T::BITWIDTH_SLIM <= NB, "NB Type is too small for the object");
return obj.pack_slim();
}
}

template <unsigned int N, PackingStrategy METHOD = PackingStrategy::DEFAULT, 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__
#pragma HLS unroll
#endif
data[i + OFFS] = objs[i].pack();
data[i + OFFS] = pack_helper<T, NB, METHOD>(objs[i]);
}
}

template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
template <unsigned int N, PackingStrategy METHOD = PackingStrategy::DEFAULT, 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__
#pragma HLS unroll
#endif
objs[i] = T::unpack(data[i + OFFS]);
objs[i] = unpack_helper<T, NB, METHOD>(data[i + OFFS]);
}
}

template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
template <unsigned int N, PackingStrategy METHOD = PackingStrategy::DEFAULT, unsigned int OFFS = 0, typename T, int NB>
inline void l1pf_pattern_pack_slim(const T objs[N], ap_uint<NB> data[]) {
#ifdef __SYNTHESIS__
#pragma HLS inline
#pragma HLS inline region recursive
#endif
assert(T::BITWIDTH_SLIM <= NB);
for (unsigned int i = 0; i < N; ++i) {
#ifdef __SYNTHESIS__
#pragma HLS unroll
#endif
data[i + OFFS] = objs[i].pack_slim();
data[i + OFFS] = pack_slim_helper<T, NB, METHOD>(objs[i]);
}
}

template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
template <unsigned int N, PackingStrategy METHOD = PackingStrategy::DEFAULT, unsigned int OFFS = 0, typename T, int NB>
inline void l1pf_pattern_unpack_slim(const ap_uint<NB> data[], T objs[N]) {
#ifdef __SYNTHESIS__
#pragma HLS inline
#pragma HLS inline region recursive
#endif
assert(T::BITWIDTH_SLIM <= NB);
for (unsigned int i = 0; i < N; ++i) {
#ifdef __SYNTHESIS__
#pragma HLS unroll
#endif
objs[i] = T::unpack(data[i + OFFS]);
objs[i] = unpack_helper<T, NB, METHOD>(data[i + OFFS]);
}
}

Expand Down
3 changes: 3 additions & 0 deletions DataFormats/L1TParticleFlow/interface/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ namespace l1ct {
typedef ap_uint<4> redChi2Bin_t;
typedef ap_fixed<10, 1, AP_RND_CONV, AP_SAT> id_score_t; // ID score to be between -1 (background) and 1 (signal)
typedef ap_ufixed<10, 1, AP_RND, AP_SAT> b_tag_score_t; // result_t from the NN is still apx_fixed<16,6>
//FIXME: no optimization for now
typedef ap_ufixed<8, 1, AP_RND_CONV, AP_SAT> id_prob_t; // ID prob between 0 and 1 (signal)

// FIXME: adjust range 10-11bits -> 1/4 - 1/2TeV is probably more than enough for all reasonable use cases
typedef ap_ufixed<11, 9, AP_TRN, AP_SAT> iso_t;
Expand Down Expand Up @@ -176,6 +178,7 @@ namespace l1ct {
inline float floatMeanZ(meanz_t meanz) { return meanz + MEANZ_OFFSET; };
inline float floatHoe(hoe_t hoe) { return hoe.to_float(); };
inline float floatIDScore(id_score_t score) { return score.to_float(); };
inline float floatIDProb(id_prob_t prob) { return prob.to_float(); };
inline float floatBtagScore(b_tag_score_t b_tag_score) { return b_tag_score.to_float(); }

inline pt_t makePt(int pt) { return ap_ufixed<16, 14>(pt) >> 2; }
Expand Down
20 changes: 10 additions & 10 deletions DataFormats/L1TParticleFlow/interface/layer1_emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

namespace l1t {
class PFTrack;
class PFCluster;
class PFCandidate;
class L1Candidate;
class SAMuon;
} // namespace l1t

namespace l1ct {

struct HadCaloObjEmu : public HadCaloObj {
const l1t::PFCluster *src = nullptr;
const l1t::L1Candidate *src = nullptr;
bool read(std::fstream &from);
bool write(std::fstream &to) const;
void clear() {
Expand All @@ -29,7 +29,7 @@ namespace l1ct {
};

struct EmCaloObjEmu : public EmCaloObj {
const l1t::PFCluster *src = nullptr;
const l1t::L1Candidate *src = nullptr;
bool read(std::fstream &from);
bool write(std::fstream &to) const;
void clear() {
Expand Down Expand Up @@ -69,7 +69,7 @@ namespace l1ct {
};

struct PFChargedObjEmu : public PFChargedObj {
const l1t::PFCluster *srcCluster = nullptr;
const l1t::L1Candidate *srcCluster = nullptr;
const l1t::PFTrack *srcTrack = nullptr;
const l1t::SAMuon *srcMu = nullptr;
const l1t::PFCandidate *srcCand = nullptr;
Expand All @@ -85,7 +85,7 @@ namespace l1ct {
};

struct PFNeutralObjEmu : public PFNeutralObj {
const l1t::PFCluster *srcCluster = nullptr;
const l1t::L1Candidate *srcCluster = nullptr;
const l1t::PFCandidate *srcCand = nullptr;
bool read(std::fstream &from);
bool write(std::fstream &to) const;
Expand All @@ -112,7 +112,7 @@ namespace l1ct {
};

struct PuppiObjEmu : public PuppiObj {
const l1t::PFCluster *srcCluster = nullptr;
const l1t::L1Candidate *srcCluster = nullptr;
const l1t::PFTrack *srcTrack = nullptr;
const l1t::SAMuon *srcMu = nullptr;
const l1t::PFCandidate *srcCand = nullptr;
Expand Down Expand Up @@ -149,15 +149,15 @@ namespace l1ct {
};

struct EGObjEmu : public EGIsoObj {
const l1t::PFCluster *srcCluster = nullptr;
const l1t::L1Candidate *srcCluster = nullptr;
void clear() {
srcCluster = nullptr;
EGIsoObj::clear();
}
};

struct EGIsoObjEmu : public EGIsoObj {
const l1t::PFCluster *srcCluster;
const l1t::L1Candidate *srcCluster;

// NOTE: we use an index to the persistable RefPtr when we reshuffle collections
// this way we avoid complex object in the object interface which needs to be used in standalone programs
Expand Down Expand Up @@ -193,7 +193,7 @@ namespace l1ct {
};

struct EGIsoEleObjEmu : public EGIsoEleObj {
const l1t::PFCluster *srcCluster = nullptr;
const l1t::L1Candidate *srcCluster = nullptr;
const l1t::PFTrack *srcTrack = nullptr;

// NOTE: we use an index to the persistable RefPtr when we reshuffle collections
Expand Down Expand Up @@ -337,7 +337,7 @@ namespace l1ct {
};

struct Event {
enum { VERSION = 13 };
enum { VERSION = 14 };
uint32_t run, lumi;
uint64_t event;
RawInputs raw;
Expand Down
Loading