Skip to content

Commit

Permalink
Modify emulator scheleton for integration of Composite ID.
Browse files Browse the repository at this point in the history
Adapt the data-formats and preselect candidates for BDT evaluation.
Composite ID can be run as alternative to Elliptic Matching.
  • Loading branch information
Peter Eduard Meiring authored and cerminar committed Apr 5, 2023
1 parent 805046c commit f120144
Show file tree
Hide file tree
Showing 15 changed files with 509 additions and 30 deletions.
5 changes: 4 additions & 1 deletion DataFormats/L1TCorrelator/interface/TkElectron.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ namespace l1t {

float trkzVtx() const { return trkzVtx_; }
double trackCurvature() const { return trackCurvature_; }

float compositeBdtScore() const { return compositeBdtScore_; }
// ---------- member functions ---------------------------

void setTrkzVtx(float TrkzVtx) { trkzVtx_ = TrkzVtx; }
void setTrackCurvature(double trackCurvature) { trackCurvature_ = trackCurvature; }
void setCompositeBdtScore(float score) { compositeBdtScore_ = score; }


private:
edm::Ptr<L1TTTrackType> trkPtr_;
float trkzVtx_;
double trackCurvature_;
float compositeBdtScore_;
};
} // namespace l1t
#endif
3 changes: 2 additions & 1 deletion DataFormats/L1TCorrelator/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
<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="5">
<class name="l1t::TkElectron" ClassVersion="6">
<version ClassVersion="6" checksum="1759715068"/>
<version ClassVersion="5" checksum="965807884"/>
<version ClassVersion="4" checksum="3922083203"/>
<version ClassVersion="3" checksum="3970647299"/>
Expand Down
7 changes: 6 additions & 1 deletion DataFormats/L1TParticleFlow/interface/PFCandidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ namespace l1t {

void setZ0(float z0) { setVertex(reco::Particle::Point(0, 0, z0)); }
void setDxy(float dxy) { dxy_ = dxy; }
void setCaloEta(float caloeta) { caloEta_ = caloeta; }
void setCaloPhi(float calophi) { caloPhi_ = calophi; }


float z0() const { return vz(); }
float dxy() const { return dxy_; }
float caloEta() const { return caloEta_; }
float caloPhi() const { return caloPhi_; }

int16_t hwZ0() const { return hwZ0_; }
int16_t hwDxy() const { return hwDxy_; }
Expand All @@ -70,7 +75,7 @@ namespace l1t {
PFClusterRef clusterRef_;
PFTrackRef trackRef_;
MuonRef muonRef_;
float dxy_, puppiWeight_;
float dxy_, puppiWeight_, caloEta_, caloPhi_;

int16_t hwZ0_, hwDxy_;
uint16_t hwTkQuality_, hwPuppiWeight_, hwEmID_;
Expand Down
2 changes: 2 additions & 0 deletions DataFormats/L1TParticleFlow/interface/layer1_emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,15 @@ namespace l1ct {
const l1t::PFTrack *srcTrack = nullptr;
// we use an index to the standalone object needed to retrieve a Ref when putting
int sta_idx;
float bdtScore;
bool read(std::fstream &from);
bool write(std::fstream &to) const;
void clear() {
EGIsoEleObj::clear();
srcCluster = nullptr;
srcTrack = nullptr;
sta_idx = -1;
bdtScore = -999;
clearIsoVars();
}

Expand Down
2 changes: 2 additions & 0 deletions DataFormats/L1TParticleFlow/src/PFCandidate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ l1t::PFCandidate::PFCandidate(
: L1Candidate(p, hwpt, hweta, hwphi, /*hwQuality=*/int(kind)),
dxy_(0),
puppiWeight_(puppiWeight),
caloEta_(0),
caloPhi_(0),
hwZ0_(0),
hwDxy_(0),
hwTkQuality_(0),
Expand Down
4 changes: 2 additions & 2 deletions DataFormats/L1TParticleFlow/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<class name="edm::RefVector<l1t::PFTrackCollection>" />
<class name="std::vector<edm::Ref<l1t::PFTrackCollection> >" />

<class name="l1t::PFCandidate" ClassVersion="6">
<class name="l1t::PFCandidate" ClassVersion="7">
<version ClassVersion="7" checksum="2118795037"/>
<version ClassVersion="6" checksum="2195440462"/>
<version ClassVersion="5" checksum="3777180193"/>
<version ClassVersion="4" checksum="3798885201"/>
Expand Down Expand Up @@ -66,4 +67,3 @@
<class name="std::vector<edm::Ref<l1t::HPSPFTauCollection> >" />

</lcgdict>

Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ void HGCalTriggerNtupleHGCMulticlusters::fill(const edm::Event& e, const HGCalTr
cl3d_layer_pt_.emplace_back(layer_pt);
}

// Retrieve indices of trigger cells inside cluster
cl3d_clusters_id_.emplace_back(cl3d_itr->constituents().size());
std::transform(cl3d_itr->constituents_begin(),
cl3d_itr->constituents_end(),
cl3d_clusters_id_.back().begin(),
[](const std::pair<uint32_t, edm::Ptr<l1t::HGCalCluster>>& id_cl) { return id_cl.second->detId(); });
// // Retrieve indices of trigger cells inside cluster
// cl3d_clusters_id_.emplace_back(cl3d_itr->constituents().size());
// std::transform(cl3d_itr->constituents_begin(),
// cl3d_itr->constituents_end(),
// cl3d_clusters_id_.back().begin(),
// [](const std::pair<uint32_t, edm::Ptr<l1t::HGCalCluster>>& id_cl) { return id_cl.second->detId(); });
}
}

Expand Down
87 changes: 81 additions & 6 deletions L1Trigger/Phase2L1ParticleFlow/interface/egamma/pftkegalgo_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "DataFormats/L1TParticleFlow/interface/layer1_emulator.h"
#include "DataFormats/L1TParticleFlow/interface/egamma.h"
#include "DataFormats/L1TParticleFlow/interface/pf.h"
#include "L1Trigger/Phase2L1ParticleFlow/interface/conifer.h"

namespace edm {
class ParameterSet;
Expand Down Expand Up @@ -53,6 +54,48 @@ namespace l1ct {
bool doPfIso;
EGIsoEleObjEmu::IsoType hwIsoTypeTkEle;
EGIsoObjEmu::IsoType hwIsoTypeTkEm;

bool doCompositeTkEle;
struct CompIDParameters {
CompIDParameters(const edm::ParameterSet &);
CompIDParameters(double hoeMin, double hoeMax, double tkptMin, double tkptMax, double srrtotMin, double srrtotMax, double detaMin, double detaMax, double dptMin, double dptMax, double meanzMin, double meanzMax, double dphiMin, double dphiMax, double tkchi2Min, double tkchi2Max, double tkz0Min, double tkz0Max, double tknstubsMin, double tknstubsMax, double BDTcut_wp97p5, double BDTcut_wp95p0)
: hoeMin(hoeMin), hoeMax(hoeMax),
tkptMin(tkptMin),tkptMax(tkptMax),
srrtotMin(srrtotMin),srrtotMax(srrtotMax),
detaMin(detaMin),detaMax(detaMax),
dptMin(dptMin),dptMax(dptMax),
meanzMin(meanzMin),meanzMax(meanzMax),
dphiMin(dphiMin),dphiMax(dphiMax),
tkchi2Min(tkchi2Min),tkchi2Max(tkchi2Max),
tkz0Min(tkz0Min),tkz0Max(tkz0Max),
tknstubsMin(tknstubsMin),tknstubsMax(tknstubsMax),
BDTcut_wp97p5(BDTcut_wp97p5),BDTcut_wp95p0(BDTcut_wp95p0){}
double hoeMin;
double hoeMax;
double tkptMin;
double tkptMax;
double srrtotMin;
double srrtotMax;
double detaMin;
double detaMax;
double dptMin;
double dptMax;
double meanzMin;
double meanzMax;
double dphiMin;
double dphiMax;
double tkchi2Min;
double tkchi2Max;
double tkz0Min;
double tkz0Max;
double tknstubsMin;
double tknstubsMax;
double BDTcut_wp97p5;
double BDTcut_wp95p0;
};

CompIDParameters myCompIDparams;

int debug = 0;

PFTkEGAlgoEmuConfig(const edm::ParameterSet &iConfig);
Expand Down Expand Up @@ -81,6 +124,8 @@ namespace l1ct {
bool doPfIso = false,
EGIsoEleObjEmu::IsoType hwIsoTypeTkEle = EGIsoEleObjEmu::IsoType::TkIso,
EGIsoObjEmu::IsoType hwIsoTypeTkEm = EGIsoObjEmu::IsoType::TkIsoPV,
bool doCompositeTkEle = false,
const CompIDParameters &myCompIDparams = {-1.0, 1566.547607421875, 1.9501149654388428, 11102.0048828125, 0.0, 0.01274710614234209, -0.24224889278411865, 0.23079538345336914, 0.010325592942535877, 184.92538452148438, 325.0653991699219, 499.6089782714844, -6.281332015991211, 6.280326843261719, 0.024048099294304848, 1258.37158203125, -14.94140625, 14.94140625, 4.0, 6.0, 0.5406244, 0.9693441},
int debug = 0)

: nTRACK(nTrack),
Expand All @@ -95,6 +140,9 @@ namespace l1ct {
emClusterPtMin(emClusterPtMin),
dEtaMaxBrem(dEtaMaxBrem),
dPhiMaxBrem(dPhiMaxBrem),
//absEtaBoundaries(std::move(absEtaBoundaries)),
//dEtaValues(std::move(dEtaValues)),
//dPhiValues(std::move(dPhiValues)),
absEtaBoundaries(absEtaBoundaries),
dEtaValues(dEtaValues),
dPhiValues(dPhiValues),
Expand All @@ -108,12 +156,16 @@ namespace l1ct {
doPfIso(doPfIso),
hwIsoTypeTkEle(hwIsoTypeTkEle),
hwIsoTypeTkEm(hwIsoTypeTkEm),
doCompositeTkEle(doCompositeTkEle),
myCompIDparams(myCompIDparams),
debug(debug) {}
};

class PFTkEGAlgoEmulator {
public:
PFTkEGAlgoEmulator(const PFTkEGAlgoEmuConfig &config) : cfg(config), debug_(cfg.debug) {}

PFTkEGAlgoEmulator(const PFTkEGAlgoEmuConfig &config);


virtual ~PFTkEGAlgoEmulator() {}

Expand All @@ -133,12 +185,31 @@ namespace l1ct {
bool writeEgSta() const { return cfg.writeEgSta; }

private:


void link_emCalo2emCalo(const std::vector<EmCaloObjEmu> &emcalo, std::vector<int> &emCalo2emCalo) const;

void link_emCalo2tk(const PFRegionEmu &r,
const std::vector<EmCaloObjEmu> &emcalo,
const std::vector<TkObjEmu> &track,
std::vector<int> &emCalo2tk) const;
void link_emCalo2tk_elliptic(const PFRegionEmu &r,
const std::vector<EmCaloObjEmu> &emcalo,
const std::vector<TkObjEmu> &track,
std::vector<int> &emCalo2tk) const;

void link_emCalo2tk_composite(const PFRegionEmu &r,
const std::vector<EmCaloObjEmu> &emcalo,
const std::vector<TkObjEmu> &track,
std::vector<int> &emCalo2tk,
std::vector<float> &emCaloTkBdtScore) const;

struct CompositeCandidate {
unsigned int cluster_idx;
unsigned int track_idx;
double dpt; // For sorting
};

float compute_composite_score(CompositeCandidate &cand,
const std::vector<EmCaloObjEmu> &emcalo,
const std::vector<TkObjEmu> &track,
const PFTkEGAlgoEmuConfig::CompIDParameters &params) const;

//FIXME: still needed
float deltaPhi(float phi1, float phi2) const;
Expand All @@ -152,6 +223,7 @@ namespace l1ct {
const std::vector<TkObjEmu> &track,
const std::vector<int> &emCalo2emCalo,
const std::vector<int> &emCalo2tk,
const std::vector<float> &emCaloTkBdtScore,
std::vector<EGObjEmu> &egstas,
std::vector<EGIsoObjEmu> &egobjs,
std::vector<EGIsoEleObjEmu> &egeleobjs) const;
Expand All @@ -165,6 +237,7 @@ namespace l1ct {
const unsigned int hwQual,
const pt_t ptCorr,
const int tk_idx,
const float bdtScore,
const std::vector<unsigned int> &components = {}) const;

EGObjEmu &addEGStaToPF(std::vector<EGObjEmu> &egobjs,
Expand All @@ -182,7 +255,8 @@ namespace l1ct {
const EmCaloObjEmu &calo,
const TkObjEmu &track,
const unsigned int hwQual,
const pt_t ptCorr) const;
const pt_t ptCorr,
const float bdtScore) const;

// FIXME: reimplemented from PFAlgoEmulatorBase
template <typename T>
Expand Down Expand Up @@ -309,6 +383,7 @@ namespace l1ct {
z0_t z0) const;

PFTkEGAlgoEmuConfig cfg;
std::unique_ptr<conifer::BDT<ap_fixed<22,3,AP_RND_CONV,AP_SAT>,ap_fixed<22,3,AP_RND_CONV,AP_SAT>,0>> composite_bdt_;
int debug_;
};
} // namespace l1ct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class L1TCorrelatorLayer1Producer : public edm::stream::EDProducer<> {
std::unique_ptr<l1t::PFCandidateCollection> fetchEmCalo() const;
std::unique_ptr<l1t::PFCandidateCollection> fetchTracks() const;
std::unique_ptr<l1t::PFCandidateCollection> fetchPF() const;
std::unique_ptr<std::vector<l1t::PFTrack>> fetchDecodedTracks() const;
void putPuppi(edm::Event &iEvent) const;

void putEgStaObjects(edm::Event &iEvent,
Expand Down Expand Up @@ -175,6 +176,9 @@ L1TCorrelatorLayer1Producer::L1TCorrelatorLayer1Producer(const edm::ParameterSet
#if 0 // LATER
produces<l1t::PFCandidateCollection>("TKVtx");
#endif
#if 1 // LATER
produces<std::vector<l1t::PFTrack>>("DecodedTK");
#endif

for (const auto &tag : iConfig.getParameter<std::vector<edm::InputTag>>("emClusters")) {
emCands_.push_back(consumes<l1t::PFClusterCollection>(tag));
Expand Down Expand Up @@ -360,6 +364,10 @@ void L1TCorrelatorLayer1Producer::produce(edm::Event &iEvent, const edm::EventSe
iEvent.put(fetchEmCalo(), "EmCalo");
iEvent.put(fetchHadCalo(), "Calo");
iEvent.put(fetchTracks(), "TK");

#if 1
iEvent.put(fetchDecodedTracks(), "DecodedTK");
#endif

// Then do the vertexing, and save it out
std::vector<float> z0s;
Expand Down Expand Up @@ -837,6 +845,37 @@ std::unique_ptr<l1t::PFCandidateCollection> L1TCorrelatorLayer1Producer::fetchTr
return ret;
}

std::unique_ptr<std::vector<l1t::PFTrack>> L1TCorrelatorLayer1Producer::fetchDecodedTracks() const {
auto ret = std::make_unique<std::vector<l1t::PFTrack>>();
for (const auto r : event_.decoded.track) {
const auto &reg = r.region;
for (const auto &p : r.obj) {
if (p.hwPt == 0 || !reg.isFiducial(p))
continue;
reco::Particle::PolarLorentzVector p4(p.floatPt(), reg.floatGlbEta(p.hwVtxEta()), reg.floatGlbPhi(p.hwVtxPhi()), 0);

reco::Particle::Point vtx(0,0,p.floatZ0());

ret->emplace_back(l1t::PFTrack(p.intCharge(),
reco::Particle::LorentzVector(p4),
vtx,
p.src->track(),
0,
reg.floatGlbEta(p.hwEta),
reg.floatGlbPhi(p.hwPhi),
-1,
-1,
p.hwQuality.to_int(),
false,
p.intPt(),
p.intEta(),
p.intPhi()));
}
}
return ret;
}


std::unique_ptr<l1t::PFCandidateCollection> L1TCorrelatorLayer1Producer::fetchPF() const {
auto ret = std::make_unique<l1t::PFCandidateCollection>();
for (unsigned int ir = 0, nr = event_.pfinputs.size(); ir < nr; ++ir) {
Expand All @@ -857,6 +896,9 @@ std::unique_ptr<l1t::PFCandidateCollection> L1TCorrelatorLayer1Producer::fetchPF
ret->back().setHwZ0(p.hwZ0);
ret->back().setHwDxy(p.hwDxy);
ret->back().setHwTkQuality(p.hwTkQuality);
ret->back().setCaloEta(reg.floatGlbEtaOf(p));
ret->back().setCaloPhi(reg.floatGlbPhiOf(p));

setRefs_(ret->back(), p);
}
for (const auto &p : event_.out[ir].pfneutral) {
Expand All @@ -867,6 +909,8 @@ std::unique_ptr<l1t::PFCandidateCollection> L1TCorrelatorLayer1Producer::fetchPF
p.hwId.isPhoton() ? l1t::PFCandidate::Photon : l1t::PFCandidate::NeutralHadron;
ret->emplace_back(type, 0, p4, 1, p.intPt(), p.intEta(), p.intPhi());
ret->back().setHwEmID(p.hwEmID);
ret->back().setCaloEta(reg.floatGlbEtaOf(p));
ret->back().setCaloPhi(reg.floatGlbPhiOf(p));
setRefs_(ret->back(), p);
}
}
Expand Down Expand Up @@ -1038,6 +1082,7 @@ void L1TCorrelatorLayer1Producer::putEgObjects(edm::Event &iEvent,
tkele.setHwQual(egele.hwQual);
tkele.setPFIsol(egele.floatRelIso(l1ct::EGIsoEleObjEmu::IsoType::PfIso));
tkele.setEgBinaryWord(egele.pack());
tkele.setCompositeBdtScore(egele.bdtScore);
tkeles->push_back(tkele);
nele_obj.push_back(tkeles->size() - 1);
}
Expand Down
Loading

0 comments on commit f120144

Please sign in to comment.