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

Implementation of TMUX18 input for EG layer-2 #126

Draft
wants to merge 8 commits into
base: L1PF_12_5_X
Choose a base branch
from
16 changes: 11 additions & 5 deletions DataFormats/L1TCorrelator/interface/TkElectron.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// Class : TkEm
//

#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/Common/interface/Ptr.h"

#include "DataFormats/L1Trigger/interface/EGamma.h"
Expand All @@ -29,27 +28,34 @@ namespace l1t {
TkElectron();

TkElectron(const LorentzVector& p4,
const edm::Ref<EGammaBxCollection>& egRef,
const edm::Ptr<L1Candidate>& egCaloPtr,
const edm::Ptr<L1TTTrackType>& trkPtr,
float tkisol = -999.);

TkElectron(const LorentzVector& p4, float tkisol = -999.);

// ---------- const member functions ---------------------

const edm::Ptr<L1TTTrackType>& trkPtr() const { return trkPtr_; }

float trkzVtx() const { return trkzVtx_; }
double trackCurvature() const { return trackCurvature_; }
float idScore() const { return idScore_; }
// ---------- member functions ---------------------------

void setTrkPtr(const edm::Ptr<L1TTTrackType>& tkPtr) { trkPtr_ = tkPtr; }
void setTrkzVtx(float TrkzVtx) { trkzVtx_ = TrkzVtx; }
void setTrackCurvature(double trackCurvature) { trackCurvature_ = trackCurvature; }
void setIdScore(float score) { idScore_ = score; }

l1gt::Electron hwObj() const {
if (encoding() != HWEncoding::GT) {
throw cms::Exception("RuntimeError") << "TkElectron::hwObj : encoding is not in GT format!" << std::endl;
}
return l1gt::Electron::unpack_ap(egBinaryWord<l1gt::Electron::BITWIDTH>());
}

private:
edm::Ptr<L1TTTrackType> trkPtr_;
float trkzVtx_;
double trackCurvature_;
float idScore_;
};
} // namespace l1t
Expand Down
39 changes: 23 additions & 16 deletions DataFormats/L1TCorrelator/interface/TkEm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
//

#include "DataFormats/L1Trigger/interface/L1Candidate.h"
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/Common/interface/Ptr.h"

#include "DataFormats/L1Trigger/interface/EGamma.h"

#include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
#include "DataFormats/L1TParticleFlow/interface/gt_datatypes.h"
#include "FWCore/Utilities/interface/Exception.h"

#include <ap_int.h>

namespace l1t {
Expand All @@ -21,22 +24,15 @@ namespace l1t {
public:
TkEm();

TkEm(const LorentzVector& p4, const edm::Ref<EGammaBxCollection>& egRef, float tkisol = -999.);

TkEm(const LorentzVector& p4,
const edm::Ref<EGammaBxCollection>& egRef,
float tkisol = -999.,
float tkisolPV = -999);

// ---------- const member functions ---------------------
TkEm(const LorentzVector& p4, float tkisol = -999., float tkisolPV = -999);

const edm::Ref<EGammaBxCollection>& EGRef() const { return egRef_; }
TkEm(const LorentzVector& p4, const edm::Ptr<L1Candidate>& egCaloPtr, float tkisol = -999., float tkisolPV = -999);

const double l1RefEta() const { return egRef_->eta(); }
enum class HWEncoding { None, CT, GT };

const double l1RefPhi() const { return egRef_->phi(); }
// ---------- const member functions ---------------------

const double l1RefEt() const { return egRef_->et(); }
const edm::Ptr<L1Candidate>& egCaloPtr() const { return egCaloPtr_; }

float trkIsol() const { return trkIsol_; } // not constrained to the PV, just track ptSum
float trkIsolPV() const { return trkIsolPV_; } // constrained to the PV by DZ
Expand All @@ -53,22 +49,32 @@ namespace l1t {
void setPFIsolPV(float pfIsolPV) { pfIsolPV_ = pfIsolPV; }
void setPuppiIsol(float puppiIsol) { puppiIsol_ = puppiIsol; }
void setPuppiIsolPV(float puppiIsolPV) { puppiIsolPV_ = puppiIsolPV; }
void setEGRef(const edm::Ref<EGammaBxCollection>& egRef) { egRef_ = egRef; }
void setEgCaloPtr(const edm::Ptr<L1Candidate>& egPtr) { egCaloPtr_ = egPtr; }

template <int N>
void setEgBinaryWord(ap_uint<N> word) {
void setEgBinaryWord(ap_uint<N> word, HWEncoding encoding) {
egBinaryWord0_ = word;
egBinaryWord1_ = (word >> 32);
egBinaryWord2_ = (word >> 64);
encoding_ = encoding;
}

l1gt::Photon hwObj() const {
if (encoding() != HWEncoding::GT) {
throw cms::Exception("RuntimeError") << "TkEm::hwObj : encoding is not in GT format!" << std::endl;
}
return l1gt::Photon::unpack_ap(egBinaryWord<l1gt::Photon::BITWIDTH>());
}

template <int N>
ap_uint<N> egBinaryWord() const {
return ap_uint<N>(egBinaryWord0_) | (ap_uint<N>(egBinaryWord1_) << 32) | (ap_uint<N>(egBinaryWord2_) << 64);
}

HWEncoding encoding() const { return encoding_; }

private:
edm::Ref<EGammaBxCollection> egRef_;
edm::Ptr<L1Candidate> egCaloPtr_;
float trkIsol_;
float trkIsolPV_;
float pfIsol_;
Expand All @@ -78,6 +84,7 @@ namespace l1t {
uint32_t egBinaryWord0_;
uint32_t egBinaryWord1_;
uint32_t egBinaryWord2_;
HWEncoding encoding_;
};
} // namespace l1t

Expand Down
10 changes: 5 additions & 5 deletions DataFormats/L1TCorrelator/src/TkElectron.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ using namespace l1t;
TkElectron::TkElectron() {}

TkElectron::TkElectron(const LorentzVector& p4,
const edm::Ref<EGammaBxCollection>& egRef,
const edm::Ptr<L1Candidate>& egCaloPtr,
const edm::Ptr<L1TTTrackType>& trackPtr,
float tkisol)
: TkEm(p4, egRef, tkisol, -999),
trkPtr_(trackPtr)

{
: TkEm(p4, egCaloPtr, tkisol, -999), trkPtr_(trackPtr) {
if (trkPtr_.isNonnull()) {
setTrkzVtx(trkPtr()->POCA().z());
}
}

TkElectron::TkElectron(const LorentzVector& p4, float tkisol)
: TkElectron(p4, edm::Ptr<L1Candidate>(), edm::Ptr<L1TTTrackType>(), tkisol) {}
13 changes: 8 additions & 5 deletions DataFormats/L1TCorrelator/src/TkEm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
//

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

using namespace l1t;

TkEm::TkEm() {}

TkEm::TkEm(const LorentzVector& p4, const edm::Ref<EGammaBxCollection>& egRef, float tkisol)
: TkEm(p4, egRef, tkisol, -999) {}
TkEm::TkEm(const LorentzVector& p4, float tkisol, float tkisolPV)
: TkEm(p4, edm::Ptr<L1Candidate>(), tkisol, tkisolPV) {}

TkEm::TkEm(const LorentzVector& p4, const edm::Ref<EGammaBxCollection>& egRef, float tkisol, float tkisolPV)
TkEm::TkEm(const LorentzVector& p4, const edm::Ptr<L1Candidate>& egCaloPtr, float tkisol, float tkisolPV)
: L1Candidate(p4),
egRef_(egRef),
egCaloPtr_(egCaloPtr),
trkIsol_(tkisol),
trkIsolPV_(tkisolPV),
pfIsol_(-999),
Expand All @@ -24,4 +26,5 @@ TkEm::TkEm(const LorentzVector& p4, const edm::Ref<EGammaBxCollection>& egRef, f
puppiIsolPV_(-999),
egBinaryWord0_(0),
egBinaryWord1_(0),
egBinaryWord2_(0) {}
egBinaryWord2_(0),
encoding_(HWEncoding::None) {}
13 changes: 11 additions & 2 deletions DataFormats/L1TCorrelator/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<class name="edm::Wrapper<l1t::TkEtMiss>"/>
<class name="edm::Wrapper<std::vector<l1t::TkEtMiss> >"/>

<class name="l1t::TkEm" ClassVersion="5">
<class name="l1t::TkEm" ClassVersion="6">
<version ClassVersion="6" checksum="3709420594"/>
<version ClassVersion="5" checksum="2211175625"/>
<version ClassVersion="4" checksum="1043577432"/>
<version ClassVersion="3" checksum="2161257944"/>
Expand All @@ -23,6 +24,12 @@
<class name="l1t::RegionalOutput<l1t::TkEmCollection>" />
<class name="edm::Wrapper<l1t::RegionalOutput<l1t::TkEmCollection>>" />

<ioread sourceClass="l1t::TkEm" targetClass="l1t::TkEm" version="[-5]" target="" source="edm::Ref<l1t::EGammaBxCollection> egRef_" include="DataFormats/Common/interface/RefToPtr.h">
<![CDATA[
newObj->setEgCaloPtr(edm::refToPtr(onfile.egRef_));
]]>
</ioread>

<class name="l1t::TkEGTau" ClassVersion="3">
<version ClassVersion="3" checksum="3759113668"/>
</class>
Expand All @@ -44,7 +51,9 @@
<class name="edm::Wrapper<std::vector<l1t::L1CaloTkTau> >"/>
<class name="edm::Ref<std::vector<l1t::L1CaloTkTau>,l1t::L1CaloTkTau,edm::refhelper::FindUsingAdvance<std::vector<l1t::L1CaloTkTau>,l1t::L1CaloTkTau> >"/>

<class name="l1t::TkElectron" ClassVersion="6">
<class name="l1t::TkElectron" ClassVersion="8">
<version ClassVersion="8" checksum="3565138561"/>
<version ClassVersion="7" checksum="3055953431"/>
<version ClassVersion="6" checksum="3899336964"/>
<version ClassVersion="5" checksum="965807884"/>
<version ClassVersion="4" checksum="3922083203"/>
Expand Down
2 changes: 2 additions & 0 deletions DataFormats/L1TParticleFlow/interface/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace l1ct {
typedef ap_uint<8> meanz_t; // mean - MEANZ_OFFSET(= 320 cm)
typedef ap_ufixed<10, 5, AP_TRN, AP_SAT> hoe_t;
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)

// 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 @@ -178,6 +179,7 @@ namespace l1ct {
inline float floatSrrTot(srrtot_t srrtot) { return srrtot.to_float() / SRRTOT_SCALE; };
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 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; }
Expand Down
27 changes: 17 additions & 10 deletions DataFormats/L1TParticleFlow/interface/egamma.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,18 @@ namespace l1ct {
// WARNING: for whatever reason, maybe connected with datamember alignment,
// in 2019.2 synthesis fails if DEta & DPhi are put before Z0 & Dxy
z0_t hwZ0;
tkdeta_t hwDEta; // relative to the region center, at calo
tkdphi_t hwDPhi; // relative to the region center, at calo
tkdeta_t hwDEta;
tkdphi_t hwDPhi;
id_score_t hwIDScore;
bool hwCharge;

phi_t hwVtxPhi() const { return hwCharge ? hwPhi + hwDPhi : hwPhi - hwDPhi; }
eta_t hwVtxEta() const { return hwEta + hwDEta; }
glbphi_t hwVtxPhi() const { return hwCharge ? hwPhi + hwDPhi : hwPhi - hwDPhi; }
glbeta_t hwVtxEta() const { return hwEta + hwDEta; }

inline bool operator==(const EGIsoEleObj &other) const {
return hwPt == other.hwPt && hwEta == other.hwEta && hwPhi == other.hwPhi && hwQual == other.hwQual &&
hwIso == other.hwIso && hwDEta == other.hwDEta && hwDPhi == other.hwDPhi && hwZ0 == other.hwZ0 &&
hwCharge == other.hwCharge;
hwIDScore == other.hwIDScore && hwCharge == other.hwCharge;
}

inline bool operator>(const EGIsoEleObj &other) const { return hwPt > other.hwPt; }
Expand All @@ -110,6 +111,7 @@ namespace l1ct {
hwDEta = 0;
hwDPhi = 0;
hwZ0 = 0;
hwIDScore = 0;
hwCharge = false;
}

Expand All @@ -119,8 +121,10 @@ namespace l1ct {
float floatVtxEta() const { return Scales::floatEta(hwVtxEta()); }
float floatVtxPhi() const { return Scales::floatPhi(hwVtxPhi()); }
float floatZ0() const { return Scales::floatZ0(hwZ0); }
float floatIDScore() const { return Scales::floatIDScore(hwIDScore); }

static const int BITWIDTH = EGIsoObj::BITWIDTH + tkdeta_t::width + tkdphi_t::width + z0_t::width + 1;
static const int BITWIDTH =
EGIsoObj::BITWIDTH + tkdeta_t::width + tkdphi_t::width + z0_t::width + id_score_t::width + 1;
inline ap_uint<BITWIDTH> pack() const {
ap_uint<BITWIDTH> ret;
unsigned int start = 0;
Expand All @@ -133,6 +137,7 @@ namespace l1ct {
pack_into_bits(ret, start, hwDPhi);
pack_into_bits(ret, start, hwZ0);
pack_bool_into_bits(ret, start, hwCharge);
pack_into_bits(ret, start, hwIDScore);
return ret;
}
inline static EGIsoEleObj unpack(const ap_uint<BITWIDTH> &src) {
Expand All @@ -152,17 +157,19 @@ namespace l1ct {
unpack_from_bits(src, start, hwDPhi);
unpack_from_bits(src, start, hwZ0);
unpack_bool_from_bits(src, start, hwCharge);
unpack_from_bits(src, start, hwIDScore);
}

l1gt::Electron toGT() const {
l1gt::Electron ele;
ele.valid = hwPt != 0;
ele.v3.pt = CTtoGT_pt(hwPt);
ele.v3.phi = CTtoGT_phi(hwPhi);
ele.v3.eta = CTtoGT_eta(hwEta);
ele.v3.phi = CTtoGT_phi(hwVtxPhi());
ele.v3.eta = CTtoGT_eta(hwVtxEta());
ele.quality = hwQual;
ele.charge = hwCharge;
ele.z0 = hwZ0;
// NOTE: GT: 0 = positive, 1 = negative, CT: 0 = negative, 1 = positive
ele.charge = !hwCharge;
ele.z0(l1ct::z0_t::width - 1, 0) = hwZ0(l1ct::z0_t::width - 1, 0);
ele.isolation = hwIso;
return ele;
}
Expand Down
24 changes: 13 additions & 11 deletions DataFormats/L1TParticleFlow/interface/layer1_emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,16 @@ namespace l1ct {

struct EGIsoObjEmu : public EGIsoObj {
const l1t::PFCluster *srcCluster;
// we use an index to the standalone object needed to retrieve a Ref when putting
int sta_idx;

// 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
int src_idx;
bool read(std::fstream &from);
bool write(std::fstream &to) const;
void clear() {
EGIsoObj::clear();
srcCluster = nullptr;
sta_idx = -1;
src_idx = -1;
clearIsoVars();
}

Expand All @@ -191,19 +193,19 @@ namespace l1ct {
};

struct EGIsoEleObjEmu : public EGIsoEleObj {
const l1t::PFCluster *srcCluster;
const l1t::PFTrack *srcTrack;
// we use an index to the standalone object needed to retrieve a Ref when putting
int sta_idx;
float idScore;
const l1t::PFCluster *srcCluster = nullptr;
const l1t::PFTrack *srcTrack = nullptr;

// 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
int src_idx;
bool read(std::fstream &from);
bool write(std::fstream &to) const;
void clear() {
EGIsoEleObj::clear();
srcCluster = nullptr;
srcTrack = nullptr;
sta_idx = -1;
idScore = -999;
src_idx = -1;
clearIsoVars();
}

Expand Down Expand Up @@ -335,7 +337,7 @@ namespace l1ct {
};

struct Event {
enum { VERSION = 12 };
enum { VERSION = 13 };
uint32_t run, lumi;
uint64_t event;
RawInputs raw;
Expand Down
4 changes: 2 additions & 2 deletions DataFormats/L1TParticleFlow/src/layer1_emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool l1ct::PuppiObjEmu::write(std::fstream& to) const { return writeObj<PuppiObj

bool l1ct::EGIsoObjEmu::read(std::fstream& from) {
srcCluster = nullptr; // not persistent
sta_idx = -1;
src_idx = -1;
clearIsoVars(); // not persistent
return readObj<EGIsoObj>(from, *this);
}
Expand All @@ -87,7 +87,7 @@ bool l1ct::EGIsoObjEmu::write(std::fstream& to) const { return writeObj<EGIsoObj
bool l1ct::EGIsoEleObjEmu::read(std::fstream& from) {
srcCluster = nullptr;
srcTrack = nullptr;
sta_idx = -1;
src_idx = -1;
clearIsoVars(); // not persistent
return readObj<EGIsoEleObj>(from, *this);
}
Expand Down
Loading