Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions DPGAnalysis/Phase2L1TNanoAOD/python/l1tPh2Nanotables_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,13 @@
)

sc8JetTable = pfJetTable.clone(
src = 'l1tSC8PFL1PuppiCorrectedEmulator',
src = cms.InputTag('l1tSC82ProngJetProducer', 'l1tSC82ProngJets'),
name = "L1puppiJetSC8",
doc = "SeededCone 0.8 Puppi jet, origin: Correlator",
variables = cms.PSet(
pfJetTable.variables.clone(),
mass = Var("mass", float)
mass = Var("mass", float),
nprongTagScore = Var('getTagScore("nprong")', float)
)
)

Expand Down Expand Up @@ -580,7 +581,7 @@
# ## jets
sc4JetTable,
sc8JetTable,
sc4ExtJetTable,
sc4ExtJetTable,
sc4NGJetTable,
histoJetTable,
caloJetTable,
Expand Down
6 changes: 3 additions & 3 deletions DataFormats/L1TParticleFlow/interface/jets.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace l1ct {
// all possible tag categories (can be extended for new / separate taggers)
class JetTagClass {
public:
enum JetTagClassValue : uint8_t { b, c, uds, g, tau_p, tau_n, mu, e };
enum JetTagClassValue : uint8_t { b, c, uds, g, tau_p, tau_n, mu, e, nprong };
JetTagClass() = default;
JetTagClass(JetTagClassValue aJetTagClassValue) : value_(aJetTagClassValue) {}
JetTagClass(std::string aJetTagClassValueString) {
Expand Down Expand Up @@ -47,7 +47,7 @@ namespace l1ct {

// Define a separate class/struct for jet tag handling
struct JetTagClassHandler {
static const unsigned NTagFields = 8;
static const unsigned NTagFields = 9;
static const JetTagClass tagClassesDefault_[NTagFields];

JetTagClass tagClassesArray[NTagFields];
Expand Down Expand Up @@ -197,7 +197,7 @@ namespace l1ct {
j.v3.phi = CTtoGT_phi(hwPhi);
j.v3.eta = CTtoGT_eta(hwEta);
j.z0(l1ct::z0_t::width - 1, 0) = hwZ0(l1ct::z0_t::width - 1, 0);
j.hwNProngScore = 0;
j.hwNProngScore = hwTagScores[0]; // currently only one WideJet tagger
j.hwMassSq = CTtoGT_massSq(hwMassSq);

return j;
Expand Down
6 changes: 4 additions & 2 deletions DataFormats/L1TParticleFlow/src/jets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const std::unordered_map<std::string, l1ct::JetTagClass::JetTagClassValue> l1ct:
{"tau_p", l1ct::JetTagClass::JetTagClassValue::tau_p},
{"tau_n", l1ct::JetTagClass::JetTagClassValue::tau_n},
{"mu", l1ct::JetTagClass::JetTagClassValue::mu},
{"e", l1ct::JetTagClass::JetTagClassValue::e}};
{"e", l1ct::JetTagClass::JetTagClassValue::e},
{"nprong", l1ct::JetTagClass::JetTagClassValue::nprong}};

const l1ct::JetTagClass l1ct::JetTagClassHandler::tagClassesDefault_[NTagFields] = {l1ct::JetTagClass("b"),
l1ct::JetTagClass("c"),
Expand All @@ -17,4 +18,5 @@ const l1ct::JetTagClass l1ct::JetTagClassHandler::tagClassesDefault_[NTagFields]
l1ct::JetTagClass("tau_p"),
l1ct::JetTagClass("tau_n"),
l1ct::JetTagClass("mu"),
l1ct::JetTagClass("e")};
l1ct::JetTagClass("e"),
l1ct::JetTagClass("nprong")};
45 changes: 45 additions & 0 deletions L1Trigger/Phase2L1ParticleFlow/interface/L1TSC82ProngJetID.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef L1TRIGGER_PHASE2L1PARTICLEFLOWS_L1TSC82ProngJetID_H
#define L1TRIGGER_PHASE2L1PARTICLEFLOWS_L1TSC82ProngJetID_H

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should L1TSC82ProngJetID be uppercase?

#include "DataFormats/L1TParticleFlow/interface/PFJet.h"
#include <memory>
#include <vector>

//HLS4ML compiled emulator modeling
#include "ap_fixed.h"
#include "hls4ml/emulator.h"

class L1TSC82ProngJetID {
public:
L1TSC82ProngJetID(const std::shared_ptr<hls4mlEmulator::Model> model, int iNParticles);

typedef ap_fixed<24, 12, AP_RND, AP_SAT, 0> inputtype;
typedef ap_ufixed<20, 10, AP_RND, AP_SAT, 0> prong_score;

void setNNVectorVar();
std::vector<float> EvaluateNNFixed();
Comment on lines +19 to +20

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could these be const?

std::vector<float> computeFixed(const l1t::PFJet &iJet);

private:
std::vector<inputtype> NNvectorVar_;
int fNParticles_;
std::unique_ptr<float[]> fPt_;
std::unique_ptr<float[]> fPt_rel_;
std::unique_ptr<float[]> fDEta_;
std::unique_ptr<float[]> fDPhi_;
std::unique_ptr<float[]> fPt_log_;
std::unique_ptr<float[]> fMass_;
std::unique_ptr<float[]> fZ0_;
std::unique_ptr<float[]> fDxy_;
std::unique_ptr<int[]> fIs_filled_;
std::unique_ptr<float[]> fPuppi_weight_;
std::unique_ptr<int[]> fEmID_;
std::unique_ptr<float[]> fQuality_;

std::unique_ptr<int[]> fCharge_;
std::unique_ptr<int[]> fId_;
std::shared_ptr<hls4mlEmulator::Model> modelRef_;

//bool isDebugEnabled_;
};
#endif
108 changes: 108 additions & 0 deletions L1Trigger/Phase2L1ParticleFlow/plugins/L1TSC82ProngJetModelProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"

#include "DataFormats/L1TParticleFlow/interface/PFJet.h"
#include "DataFormats/JetReco/interface/Jet.h"
#include "DataFormats/L1TParticleFlow/interface/PFCandidate.h"
#include "L1Trigger/Phase2L1ParticleFlow/interface/L1TSC82ProngJetID.h"
#include "DataFormats/Common/interface/ValueMap.h"

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

#include <cmath>
#include <vector>

#include <string>
#include "ap_fixed.h"
#include "hls4ml/emulator.h"

using namespace l1t;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you use l1t::name rather than using namespace l1t?


class L1TSC82ProngJetProducer : public edm::stream::EDProducer<> {
public:
explicit L1TSC82ProngJetProducer(const edm::ParameterSet&);
~L1TSC82ProngJetProducer() override = default;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
std::unique_ptr<L1TSC82ProngJetID> fJetId_;
void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;

edm::EDGetTokenT<edm::View<l1t::PFJet>> const jets_;
double const fMinPt_;
double const fMaxEta_;
unsigned int const fMaxJets_;
int const fNParticles_;

hls4mlEmulator::ModelLoader loader;
std::shared_ptr<hls4mlEmulator::Model> model;
};

L1TSC82ProngJetProducer::L1TSC82ProngJetProducer(const edm::ParameterSet& cfg)
: jets_(consumes<edm::View<l1t::PFJet>>(cfg.getParameter<edm::InputTag>("jets"))),
fMinPt_(cfg.getParameter<double>("minPt")),
fMaxEta_(cfg.getParameter<double>("maxEta")),
fMaxJets_(cfg.getParameter<int>("maxJets")),
fNParticles_(cfg.getParameter<int>("nParticles")),
loader(hls4mlEmulator::ModelLoader(cfg.getParameter<std::string>("l1tSC82ProngJetModelPath"))) {
model = loader.load_model();
fJetId_ = std::make_unique<L1TSC82ProngJetID>(model, fNParticles_);
produces<l1t::PFJetCollection>("l1tSC82ProngJets");
}

void L1TSC82ProngJetProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::Handle<edm::View<l1t::PFJet>> jets;
iEvent.getByToken(jets_, jets);
std::vector<l1t::PFJet> taggedJets;

for (const auto& srcjet : *jets) {
l1ct::Jet ctHWJet = l1ct::Jet::unpack(srcjet.encodedJet(l1t::PFJet::HWEncoding::CT));

if (srcjet.pt() < fMinPt_ || std::abs(srcjet.eta()) > fMaxEta_ || taggedJets.size() >= fMaxJets_) {
ctHWJet.clear();
continue;
}
std::vector<float> JetProngScore_float = fJetId_->computeFixed(srcjet);
l1gt::WideJet gtwHWJet = l1gt::WideJet::unpack(srcjet.getHWJetGTWide());

l1t::PFJet edmJet(
srcjet.pt(), srcjet.eta(), srcjet.phi(), srcjet.mass(), gtwHWJet.v3.pt.V, gtwHWJet.v3.eta.V, gtwHWJet.v3.phi.V);

std::vector<l1ct::JetTagClass> classes{l1ct::JetTagClass(l1ct::JetTagClass::JetTagClassValue::nprong)};

edmJet.addTagScores(JetProngScore_float, classes, 1.);
edmJet.setEncodedJet(l1t::PFJet::HWEncoding::CT, ctHWJet.pack());
edmJet.setEncodedJet(l1t::PFJet::HWEncoding::GTWide, gtwHWJet.pack());

std::vector<edm::Ptr<l1t::PFCandidate>> constituents;
std::for_each(srcjet.constituents().begin(), srcjet.constituents().end(), [&](auto constituent) {
edmJet.addConstituent(constituent);
});

taggedJets.push_back(edmJet);
}
std::sort(taggedJets.begin(), taggedJets.end(), [](l1t::PFJet a, l1t::PFJet b) { return (a.pt() > b.pt()); });

std::unique_ptr<l1t::PFJetCollection> taggedJetsCollection(new l1t::PFJetCollection);
taggedJetsCollection->swap(taggedJets);
iEvent.put(std::move(taggedJetsCollection), "l1tSC82ProngJets");
}

void L1TSC82ProngJetProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("jets", edm::InputTag("l1tSC8PFL1PuppiEmulator"));
desc.add<std::string>("l1tSC82ProngJetModelPath", std::string("L1TSC82ProngJetModel_v0"));
desc.add<double>("minPt", 0.);
desc.add<double>("maxEta", 5.);
desc.add<int>("maxJets", 16);
desc.add<int>("nParticles", 8);
descriptions.add("l1tSC82ProngJetProducer", desc);
}

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(L1TSC82ProngJetProducer);
14 changes: 4 additions & 10 deletions L1Trigger/Phase2L1ParticleFlow/python/l1ctLayer1_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,10 @@
emulateCorrections = cms.bool(False), # NOTE: should switch this on for FW bit-wise agreement!
emInterpScenario = cms.string("allKeepHad"), # for all clusters, use EM intepretation to redefine the EM part of the energy
),
regionizerAlgo = cms.string("Multififo"),
regionizerAlgo = cms.string("BufferedFoldedMultififo"),
regionizerAlgoParameters = cms.PSet(
useAlsoVtxCoords = cms.bool(True),
nEndcaps = cms.uint32(2),
nClocks = cms.uint32(54),
nTkLinks = cms.uint32(2),
nCaloLinks = cms.uint32(3),
nClocks = cms.uint32(162),
nTrack = cms.uint32(30),
nCalo = cms.uint32(20),
nEmCalo = cms.uint32(10),
Expand Down Expand Up @@ -365,13 +362,10 @@
emulateCorrections = cms.bool(False), # NOTE: should switch this on for FW bit-wise agreement!
emInterpScenario = cms.string("allKeepHad"), # for all clusters, use EM intepretation to redefine the EM part of the energy
),
regionizerAlgo = cms.string("Multififo"),
regionizerAlgo = cms.string("BufferedFoldedMultififo"),
regionizerAlgoParameters = cms.PSet(
useAlsoVtxCoords = cms.bool(True),
nEndcaps = cms.uint32(2),
nClocks = cms.uint32(54),
nTkLinks = cms.uint32(0),
nCaloLinks = cms.uint32(3),
nClocks = cms.uint32(162),
nTrack = cms.uint32(0),
nCalo = cms.uint32(12),
nEmCalo = cms.uint32(12),
Expand Down
Loading