Skip to content

Commit

Permalink
Remove Ref to Standalone object in favor of generic pointer to L1Cand…
Browse files Browse the repository at this point in the history
…idate and cleanup TkElectron interface
  • Loading branch information
cerminar committed Nov 16, 2023
1 parent 4ff7c3e commit 49ac2c5
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 267 deletions.
9 changes: 4 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,21 +28,22 @@ 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 {
Expand All @@ -56,7 +56,6 @@ namespace l1t {
private:
edm::Ptr<L1TTTrackType> trkPtr_;
float trkzVtx_;
double trackCurvature_;
float idScore_;
};
} // namespace l1t
Expand Down
21 changes: 6 additions & 15 deletions DataFormats/L1TCorrelator/interface/TkEm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//

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

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

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

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

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

enum class HWEncoding { None, CT, GT };

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

const edm::Ref<EGammaBxCollection>& EGRef() const { return egRef_; }

const double l1RefEta() const { return egRef_->eta(); }

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

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 @@ -58,7 +49,7 @@ 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, HWEncoding encoding) {
Expand All @@ -83,7 +74,7 @@ namespace l1t {
HWEncoding encoding() const { return encoding_; }

private:
edm::Ref<EGammaBxCollection> egRef_;
edm::Ptr<L1Candidate> egCaloPtr_;
float trkIsol_;
float trkIsolPV_;
float pfIsol_;
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>(nullptr, 0), edm::Ptr<L1TTTrackType>(nullptr, 0), tkisol) {}
10 changes: 6 additions & 4 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>(nullptr, 0), 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 Down
13 changes: 10 additions & 3 deletions DataFormats/L1TCorrelator/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<class name="edm::Wrapper<std::vector<l1t::TkEtMiss> >"/>

<class name="l1t::TkEm" ClassVersion="6">
<version ClassVersion="6" checksum="2264937788"/>
<version ClassVersion="6" checksum="3709420594"/>
<version ClassVersion="5" checksum="2211175625"/>
<version ClassVersion="4" checksum="1043577432"/>
<version ClassVersion="3" checksum="2161257944"/>
Expand All @@ -24,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 @@ -45,8 +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="7">
<version ClassVersion="7" checksum="3405419557"/>
<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
16 changes: 10 additions & 6 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 Down Expand Up @@ -193,15 +195,17 @@ 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;

// 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;
src_idx = -1;
clearIsoVars();
}

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
78 changes: 37 additions & 41 deletions L1Trigger/L1TNtuples/src/L1AnalysisPhaseII.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,18 @@ void L1Analysis::L1AnalysisPhaseII::SetTkEG(const edm::Handle<l1t::TkElectronCol
l1extra_.tkElectronEt.push_back(it->et());
l1extra_.tkElectronEta.push_back(it->eta());
l1extra_.tkElectronPhi.push_back(it->phi());
int chargeFromCurvature = (it->trackCurvature() > 0) ? 1 : -1; // ThisIsACheck
l1extra_.tkElectronChg.push_back(chargeFromCurvature);
l1extra_.tkElectronChg.push_back(it->charge());
l1extra_.tkElectronzVtx.push_back(it->trkzVtx());
l1extra_.tkElectronTrkIso.push_back(it->trkIsol());
l1extra_.tkElectronHwQual.push_back(it->EGRef()->hwQual());
l1extra_.tkElectronEGRefPt.push_back(it->EGRef()->et());
l1extra_.tkElectronEGRefEta.push_back(it->EGRef()->eta());
l1extra_.tkElectronEGRefPhi.push_back(it->EGRef()->phi());
l1extra_.tkElectronHwQual.push_back(it->egCaloPtr()->hwQual());
l1extra_.tkElectronEGRefPt.push_back(it->egCaloPtr()->et());
l1extra_.tkElectronEGRefEta.push_back(it->egCaloPtr()->eta());
l1extra_.tkElectronEGRefPhi.push_back(it->egCaloPtr()->phi());
l1extra_.tkElectronBx.push_back(0); //it->bx());
l1extra_.tkElectronHGC.push_back(0);
bool quality = ((it->EGRef()->hwQual() >> 1) & 1) > 0; // LooseTrackID should be the second bit
bool quality = ((it->egCaloPtr()->hwQual() >> 1) & 1) > 0; // LooseTrackID should be the second bit
l1extra_.tkElectronPassesLooseTrackID.push_back(quality);
quality = ((it->EGRef()->hwQual() >> 2) & 1) > 0; // LooseTrackID should be the second bit
quality = ((it->egCaloPtr()->hwQual() >> 2) & 1) > 0; // LooseTrackID should be the second bit
l1extra_.tkElectronPassesPhotonID.push_back(quality);
l1extra_.nTkElectrons++;
}
Expand All @@ -227,17 +226,16 @@ void L1Analysis::L1AnalysisPhaseII::SetTkEG(const edm::Handle<l1t::TkElectronCol
l1extra_.tkElectronEt.push_back(it->et());
l1extra_.tkElectronEta.push_back(it->eta());
l1extra_.tkElectronPhi.push_back(it->phi());
int chargeFromCurvature = (it->trackCurvature() > 0) ? 1 : -1; // ThisIsACheck
l1extra_.tkElectronChg.push_back(chargeFromCurvature);
l1extra_.tkElectronChg.push_back(it->charge());
l1extra_.tkElectronzVtx.push_back(it->trkzVtx());
l1extra_.tkElectronTrkIso.push_back(it->trkIsol());
l1extra_.tkElectronHwQual.push_back(it->EGRef()->hwQual());
l1extra_.tkElectronEGRefPt.push_back(it->EGRef()->et());
l1extra_.tkElectronEGRefEta.push_back(it->EGRef()->eta());
l1extra_.tkElectronEGRefPhi.push_back(it->EGRef()->phi());
l1extra_.tkElectronHwQual.push_back(it->egCaloPtr()->hwQual());
l1extra_.tkElectronEGRefPt.push_back(it->egCaloPtr()->et());
l1extra_.tkElectronEGRefEta.push_back(it->egCaloPtr()->eta());
l1extra_.tkElectronEGRefPhi.push_back(it->egCaloPtr()->phi());
l1extra_.tkElectronBx.push_back(0); //it->bx());
l1extra_.tkElectronHGC.push_back(1);
bool quality = (it->EGRef()->hwQual() == 5);
bool quality = (it->egCaloPtr()->hwQual() == 5);
l1extra_.tkElectronPassesLooseTrackID.push_back(quality);
l1extra_.tkElectronPassesPhotonID.push_back(quality);
l1extra_.nTkElectrons++;
Expand All @@ -255,19 +253,18 @@ void L1Analysis::L1AnalysisPhaseII::SetTkEGV2(const edm::Handle<l1t::TkElectronC
l1extra_.tkElectronV2Et.push_back(it->et());
l1extra_.tkElectronV2Eta.push_back(it->eta());
l1extra_.tkElectronV2Phi.push_back(it->phi());
int chargeFromCurvature = (it->trackCurvature() > 0) ? 1 : -1; // ThisIsACheck
l1extra_.tkElectronV2Chg.push_back(chargeFromCurvature);
l1extra_.tkElectronV2Chg.push_back(it->charge());
l1extra_.tkElectronV2zVtx.push_back(it->trkzVtx());
l1extra_.tkElectronV2TrkIso.push_back(it->trkIsol());
l1extra_.tkElectronV2HwQual.push_back(it->EGRef()->hwQual());
l1extra_.tkElectronV2EGRefPt.push_back(it->EGRef()->et());
l1extra_.tkElectronV2EGRefEta.push_back(it->EGRef()->eta());
l1extra_.tkElectronV2EGRefPhi.push_back(it->EGRef()->phi());
l1extra_.tkElectronV2HwQual.push_back(it->egCaloPtr()->hwQual());
l1extra_.tkElectronV2EGRefPt.push_back(it->egCaloPtr()->et());
l1extra_.tkElectronV2EGRefEta.push_back(it->egCaloPtr()->eta());
l1extra_.tkElectronV2EGRefPhi.push_back(it->egCaloPtr()->phi());
l1extra_.tkElectronV2Bx.push_back(0); //it->bx());
l1extra_.tkElectronV2HGC.push_back(0);
bool quality = ((it->EGRef()->hwQual() >> 1) & 1) > 0;
bool quality = ((it->egCaloPtr()->hwQual() >> 1) & 1) > 0;
l1extra_.tkElectronV2PassesLooseTrackID.push_back(quality);
quality = ((it->EGRef()->hwQual() >> 2) & 1) > 0;
quality = ((it->egCaloPtr()->hwQual() >> 2) & 1) > 0;
l1extra_.tkElectronV2PassesPhotonID.push_back(quality);
l1extra_.nTkElectronsV2++;
}
Expand All @@ -280,17 +277,16 @@ void L1Analysis::L1AnalysisPhaseII::SetTkEGV2(const edm::Handle<l1t::TkElectronC
l1extra_.tkElectronV2Et.push_back(it->et());
l1extra_.tkElectronV2Eta.push_back(it->eta());
l1extra_.tkElectronV2Phi.push_back(it->phi());
int chargeFromCurvature = (it->trackCurvature() > 0) ? 1 : -1; // ThisIsACheck
l1extra_.tkElectronV2Chg.push_back(chargeFromCurvature);
l1extra_.tkElectronV2Chg.push_back(it->charge());
l1extra_.tkElectronV2zVtx.push_back(it->trkzVtx());
l1extra_.tkElectronV2TrkIso.push_back(it->trkIsol());
l1extra_.tkElectronV2HwQual.push_back(it->EGRef()->hwQual());
l1extra_.tkElectronV2EGRefPt.push_back(it->EGRef()->et());
l1extra_.tkElectronV2EGRefEta.push_back(it->EGRef()->eta());
l1extra_.tkElectronV2EGRefPhi.push_back(it->EGRef()->phi());
l1extra_.tkElectronV2HwQual.push_back(it->egCaloPtr()->hwQual());
l1extra_.tkElectronV2EGRefPt.push_back(it->egCaloPtr()->et());
l1extra_.tkElectronV2EGRefEta.push_back(it->egCaloPtr()->eta());
l1extra_.tkElectronV2EGRefPhi.push_back(it->egCaloPtr()->phi());
l1extra_.tkElectronV2Bx.push_back(0); //it->bx());
l1extra_.tkElectronV2HGC.push_back(1);
bool quality = (it->EGRef()->hwQual() == 5);
bool quality = (it->egCaloPtr()->hwQual() == 5);
l1extra_.tkElectronV2PassesLooseTrackID.push_back(quality);
l1extra_.tkElectronV2PassesPhotonID.push_back(quality);
l1extra_.nTkElectronsV2++;
Expand All @@ -311,14 +307,14 @@ void L1Analysis::L1AnalysisPhaseII::SetTkEM(const edm::Handle<l1t::TkEmCollectio
l1extra_.tkPhotonTrkIso.push_back(it->trkIsol());
l1extra_.tkPhotonTrkIsoPV.push_back(it->trkIsolPV());
l1extra_.tkPhotonBx.push_back(0); //it->bx());
l1extra_.tkPhotonHwQual.push_back(it->EGRef()->hwQual());
l1extra_.tkPhotonEGRefPt.push_back(it->EGRef()->et());
l1extra_.tkPhotonEGRefEta.push_back(it->EGRef()->eta());
l1extra_.tkPhotonEGRefPhi.push_back(it->EGRef()->phi());
l1extra_.tkPhotonHwQual.push_back(it->egCaloPtr()->hwQual());
l1extra_.tkPhotonEGRefPt.push_back(it->egCaloPtr()->et());
l1extra_.tkPhotonEGRefEta.push_back(it->egCaloPtr()->eta());
l1extra_.tkPhotonEGRefPhi.push_back(it->egCaloPtr()->phi());
l1extra_.tkPhotonHGC.push_back(0);
bool quality = ((it->EGRef()->hwQual() >> 1) & 1) > 0;
bool quality = ((it->egCaloPtr()->hwQual() >> 1) & 1) > 0;
l1extra_.tkPhotonPassesLooseTrackID.push_back(quality);
quality = ((it->EGRef()->hwQual() >> 2) & 1) > 0; // Photon Id should be the third bit
quality = ((it->egCaloPtr()->hwQual() >> 2) & 1) > 0; // Photon Id should be the third bit
l1extra_.tkPhotonPassesPhotonID.push_back(quality);
l1extra_.nTkPhotons++;
}
Expand All @@ -333,12 +329,12 @@ void L1Analysis::L1AnalysisPhaseII::SetTkEM(const edm::Handle<l1t::TkEmCollectio
l1extra_.tkPhotonTrkIso.push_back(it->trkIsol());
l1extra_.tkPhotonTrkIsoPV.push_back(it->trkIsolPV());
l1extra_.tkPhotonBx.push_back(0); //it->bx());
l1extra_.tkPhotonHwQual.push_back(it->EGRef()->hwQual());
l1extra_.tkPhotonEGRefPt.push_back(it->EGRef()->et());
l1extra_.tkPhotonEGRefEta.push_back(it->EGRef()->eta());
l1extra_.tkPhotonEGRefPhi.push_back(it->EGRef()->phi());
l1extra_.tkPhotonHwQual.push_back(it->egCaloPtr()->hwQual());
l1extra_.tkPhotonEGRefPt.push_back(it->egCaloPtr()->et());
l1extra_.tkPhotonEGRefEta.push_back(it->egCaloPtr()->eta());
l1extra_.tkPhotonEGRefPhi.push_back(it->egCaloPtr()->phi());
l1extra_.tkPhotonHGC.push_back(1);
bool quality = (it->EGRef()->hwQual() == 5);
bool quality = (it->egCaloPtr()->hwQual() == 5);
l1extra_.tkPhotonPassesLooseTrackID.push_back(quality);
l1extra_.tkPhotonPassesPhotonID.push_back(quality);
l1extra_.nTkPhotons++;
Expand Down
Loading

0 comments on commit 49ac2c5

Please sign in to comment.