From ec75314667468e7afb427b0ff16c674953b2516a Mon Sep 17 00:00:00 2001 From: Dylan Rankin Date: Fri, 26 Aug 2022 08:31:29 -0500 Subject: [PATCH 1/8] adding extended tracking for l1 (no fix yet for propogator) --- .../python/DeregionizerProducer_cfi.py | 2 ++ .../python/l1ctLayer1_cff.py | 20 +++++++++++++++++-- .../python/l1pfJetMet_cff.py | 10 ++++++++-- .../python/pfTracksFromL1Tracks_cfi.py | 13 ++++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/L1Trigger/Phase2L1ParticleFlow/python/DeregionizerProducer_cfi.py b/L1Trigger/Phase2L1ParticleFlow/python/DeregionizerProducer_cfi.py index d010a5cd6de33..c5a268bcae7f0 100644 --- a/L1Trigger/Phase2L1ParticleFlow/python/DeregionizerProducer_cfi.py +++ b/L1Trigger/Phase2L1ParticleFlow/python/DeregionizerProducer_cfi.py @@ -8,3 +8,5 @@ nPuppiSecondBuffers = cms.uint32(32), nPuppiThirdBuffers = cms.uint32(64) ) + +DeregionizerProducerExtended = DeregionizerProducer.clone(RegionalPuppiCands = cms.InputTag("l1ctLayer1Extended","PuppiRegional")) diff --git a/L1Trigger/Phase2L1ParticleFlow/python/l1ctLayer1_cff.py b/L1Trigger/Phase2L1ParticleFlow/python/l1ctLayer1_cff.py index f554065241f29..aca48e624c2e3 100644 --- a/L1Trigger/Phase2L1ParticleFlow/python/l1ctLayer1_cff.py +++ b/L1Trigger/Phase2L1ParticleFlow/python/l1ctLayer1_cff.py @@ -2,7 +2,7 @@ import math -from L1Trigger.Phase2L1ParticleFlow.pfTracksFromL1Tracks_cfi import pfTracksFromL1Tracks +from L1Trigger.Phase2L1ParticleFlow.pfTracksFromL1Tracks_cfi import pfTracksFromL1Tracks, pfTracksFromL1TracksExtended from L1Trigger.Phase2L1ParticleFlow.pfClustersFromL1EGClusters_cfi import pfClustersFromL1EGClusters from L1Trigger.Phase2L1ParticleFlow.pfClustersFromCombinedCalo_cff import pfClustersFromCombinedCaloHCal, pfClustersFromCombinedCaloHF from L1Trigger.Phase2L1ParticleFlow.pfClustersFromHGC3DClusters_cfi import pfClustersFromHGC3DClusters @@ -137,6 +137,8 @@ ) ) +l1ctLayer1BarrelExtended = l1ctLayer1Barrel.clone(tracks = cms.InputTag('pfTracksFromL1TracksExtended')) + _hgcalSectors = cms.VPSet( cms.PSet( etaBoundaries = cms.vdouble(-3.0, -1.5), @@ -285,6 +287,7 @@ writeRawHgcalCluster = cms.untracked.bool(True) ) +l1ctLayer1HGCalExtended = l1ctLayer1HGCal.clone(tracks = cms.InputTag('pfTracksFromL1TracksExtended')) l1ctLayer1HGCalNoTK = cms.EDProducer("L1TCorrelatorLayer1Producer", tracks = cms.InputTag(''), @@ -467,6 +470,15 @@ regionalLabelsToMerge = cms.vstring("Puppi"), ) +l1ctLayer1Extended = l1ctLayer1.clone( + pfProducers = cms.VInputTag( + cms.InputTag("l1ctLayer1BarrelExtended"), + cms.InputTag("l1ctLayer1HGCalExtended"), + cms.InputTag("l1ctLayer1HGCalNoTK"), + cms.InputTag("l1ctLayer1HF") + ) +) + l1ctLayer1EG = cms.EDProducer( "L1TEGMultiMerger", tkElectrons=cms.VPSet( @@ -514,14 +526,18 @@ pfClustersFromCombinedCaloHCal, pfClustersFromCombinedCaloHF, pfClustersFromHGC3DClusters, - pfTracksFromL1Tracks + pfTracksFromL1Tracks, + pfTracksFromL1TracksExtended ) l1ctLayer1Task = cms.Task( l1ctLayer1Barrel, + l1ctLayer1BarrelExtended, l1ctLayer1HGCal, + l1ctLayer1HGCalExtended, l1ctLayer1HGCalNoTK, l1ctLayer1HF, l1ctLayer1, + l1ctLayer1Extended, l1ctLayer1EG ) diff --git a/L1Trigger/Phase2L1ParticleFlow/python/l1pfJetMet_cff.py b/L1Trigger/Phase2L1ParticleFlow/python/l1pfJetMet_cff.py index f30988264bdbf..4d213b9a534fd 100644 --- a/L1Trigger/Phase2L1ParticleFlow/python/l1pfJetMet_cff.py +++ b/L1Trigger/Phase2L1ParticleFlow/python/l1pfJetMet_cff.py @@ -1,7 +1,7 @@ import FWCore.ParameterSet.Config as cms from L1Trigger.Phase2L1ParticleFlow.L1SeedConePFJetProducer_cfi import L1SeedConePFJetProducer, L1SeedConePFJetEmulatorProducer -from L1Trigger.Phase2L1ParticleFlow.DeregionizerProducer_cfi import DeregionizerProducer as l1ctLayer2Deregionizer +from L1Trigger.Phase2L1ParticleFlow.DeregionizerProducer_cfi import DeregionizerProducer as l1ctLayer2Deregionizer, DeregionizerProducerExtended as l1ctLayer2DeregionizerExtended scPFL1PF = L1SeedConePFJetProducer.clone(L1PFObjects = 'l1ctLayer1:PF') scPFL1Puppi = L1SeedConePFJetProducer.clone() scPFL1PuppiEmulator = L1SeedConePFJetEmulatorProducer.clone(L1PFObject = cms.InputTag('l1ctLayer2Deregionizer', 'Puppi')) @@ -22,9 +22,15 @@ from L1Trigger.Phase2L1ParticleFlow.L1MhtPfProducer_cfi import L1MhtPfProducer scPFL1PuppiCorrectedEmulatorMHT = L1MhtPfProducer.clone() #(jets = cms.InputTag("scPFL1PuppiCorrectedEmulator")) +scPFL1PuppiExtended = scPFL1Puppi.clone(L1PFObjects = 'l1ctLayer1Extended:Puppi') +scPFL1PuppiExtendedEmulator = scPFL1PuppiEmulator.clone(L1PFObjects = cms.InputTag('l1ctLayer2DeregionizerExtended', 'Puppi')) +scPFL1PuppiExtendedCorrectedEmulator = _correctedJets.clone(jets = 'scPFL1PuppiExtendedEmulator', correctorDir = 'L1PuppiSC4EmuDeregJets') l1PFJetsTask = cms.Task( - l1ctLayer2Deregionizer, scPFL1PF, scPFL1Puppi, scPFL1PuppiEmulator, scPFL1PuppiCorrectedEmulator, scPFL1PuppiCorrectedEmulatorMHT + l1ctLayer2Deregionizer, scPFL1PF, scPFL1Puppi, scPFL1PuppiEmulator, scPFL1PuppiCorrectedEmulator, scPFL1PuppiCorrectedEmulatorMHT, +) +l1PFJetsExtendedTask = cms.Task( + l1ctLayer2DeregionizerExtended, scPFL1PuppiExtended, scPFL1PuppiExtendedEmulator, scPFL1PuppiExtendedCorrectedEmulator ) diff --git a/L1Trigger/Phase2L1ParticleFlow/python/pfTracksFromL1Tracks_cfi.py b/L1Trigger/Phase2L1ParticleFlow/python/pfTracksFromL1Tracks_cfi.py index e37ab47123b00..f63c9acda1f06 100644 --- a/L1Trigger/Phase2L1ParticleFlow/python/pfTracksFromL1Tracks_cfi.py +++ b/L1Trigger/Phase2L1ParticleFlow/python/pfTracksFromL1Tracks_cfi.py @@ -25,3 +25,16 @@ redigitizeTrackWord = cms.bool(True), ) +pfTracksFromL1TracksExtended = pfTracksFromL1Tracks.clone( + L1TrackTag = cms.InputTag("TTTracksFromExtendedTrackletEmulation", "Level1TTTracks"), + nParam = 5, + qualityBits = cms.vstring( + "momentum.perp > 2 && getStubRefs.size >= 4 && chi2Red < 15 && POCA.x < 1.0 && POCA.x > -1.0 && POCA.y < 1.0 && POCA.y > -1.0", + "momentum.perp > 2 && getStubRefs.size >= 6 && chi2Red < 15 && chi2 < 50 && POCA.x < 1.0 && POCA.x > -1.0 && POCA.y < 1.0 && POCA.y > -1.0", # historical reasons + "momentum.perp > 5 && getStubRefs.size >= 4 && POCA.x < 1.0 && POCA.x > -1.0 && POCA.y < 1.0 && POCA.y > -1.0" + #using restriction on track x,y for now + #long term fix would be to alter track propagation in L1Trigger/Phase2L1ParticleFlow/plugins/PFTrackProducerFromL1Tracks.cc + ), + redigitizeTrackWord = cms.bool(True), +) + From a84e503ca1e02f578a92eaadad732ed6c1045be1 Mon Sep 17 00:00:00 2001 From: Dylan Rankin Date: Fri, 26 Aug 2022 08:32:56 -0500 Subject: [PATCH 2/8] modifying PFJet to store PFCandidate instead of L1Candidate --- DataFormats/L1TParticleFlow/interface/PFJet.h | 7 ++++--- DataFormats/L1TParticleFlow/src/classes_def.xml | 3 ++- .../plugins/L1TCorrectedPFJetProducer.cc | 17 +++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/DataFormats/L1TParticleFlow/interface/PFJet.h b/DataFormats/L1TParticleFlow/interface/PFJet.h index 301fd1a36ff76..e1cfc282659c0 100644 --- a/DataFormats/L1TParticleFlow/interface/PFJet.h +++ b/DataFormats/L1TParticleFlow/interface/PFJet.h @@ -3,6 +3,7 @@ #include #include "DataFormats/L1Trigger/interface/L1Candidate.h" +#include "DataFormats/L1TParticleFlow/interface/PFCandidate.h" #include "DataFormats/Common/interface/Ptr.h" namespace l1t { @@ -10,7 +11,7 @@ namespace l1t { class PFJet : public L1Candidate { public: /// constituent information. note that this is not going to be available in the hardware! - typedef std::vector> Constituents; + typedef std::vector> Constituents; PFJet() {} PFJet(float pt, float eta, float phi, float mass = 0, int hwpt = 0, int hweta = 0, int hwphi = 0) @@ -28,13 +29,13 @@ namespace l1t { /// constituent information. note that this is not going to be available in the hardware! const Constituents& constituents() const { return constituents_; } /// adds a candidate to this cluster; note that this only records the information, it's up to you to also set the 4-vector appropriately - void addConstituent(const edm::Ptr& cand) { constituents_.emplace_back(cand); } + void addConstituent(const edm::Ptr& cand) { constituents_.emplace_back(cand); } // candidate interface size_t numberOfDaughters() const override { return constituents_.size(); } const reco::Candidate* daughter(size_type i) const override { return constituents_[i].get(); } using reco::LeafCandidate::daughter; // avoid hiding the base - edm::Ptr daughterPtr(size_type i) const { return constituents_[i]; } + edm::Ptr daughterPtr(size_type i) const { return constituents_[i]; } // Get and set the encodedJet_ bits. The Jet is encoded in 128 bits as a 2-element array of uint64_t std::array encodedJet() { return encodedJet_; } diff --git a/DataFormats/L1TParticleFlow/src/classes_def.xml b/DataFormats/L1TParticleFlow/src/classes_def.xml index b1ed9da86adda..5f90ab44bb63d 100644 --- a/DataFormats/L1TParticleFlow/src/classes_def.xml +++ b/DataFormats/L1TParticleFlow/src/classes_def.xml @@ -33,7 +33,8 @@ - + + diff --git a/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCorrectedPFJetProducer.cc b/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCorrectedPFJetProducer.cc index 46b76e20f45a5..1421b09331de3 100644 --- a/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCorrectedPFJetProducer.cc +++ b/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCorrectedPFJetProducer.cc @@ -21,12 +21,12 @@ class L1TCorrectedPFJetProducer : public edm::global::EDProducer<> { private: void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; - edm::EDGetTokenT> jets_; + edm::EDGetTokenT> jets_; l1tpf::corrector corrector_; }; L1TCorrectedPFJetProducer::L1TCorrectedPFJetProducer(const edm::ParameterSet& iConfig) - : jets_(consumes>(iConfig.getParameter("jets"))), + : jets_(consumes>(iConfig.getParameter("jets"))), corrector_(iConfig.getParameter("correctorFile"), iConfig.getParameter("correctorDir")) { produces>(); @@ -35,7 +35,7 @@ L1TCorrectedPFJetProducer::L1TCorrectedPFJetProducer(const edm::ParameterSet& iC L1TCorrectedPFJetProducer::~L1TCorrectedPFJetProducer() {} void L1TCorrectedPFJetProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const { - edm::Handle> jets; + edm::Handle> jets; iEvent.getByToken(jets_, jets); auto out = std::make_unique>(); @@ -44,11 +44,12 @@ void L1TCorrectedPFJetProducer::produce(edm::StreamID, edm::Event& iEvent, const out->emplace_back(srcjet.p4()); auto& jet = out->back(); // copy daughters - //if (copyDaughters_) { - // for (const auto& dau : srcjet.daughterPtrVector()) { - // jet.addConstituent(edm::Ptr(dau)); - // } - //} + bool copyDaughters_ = true; + if (copyDaughters_) { + for (const auto& dau : srcjet.constituents()) { + jet.addConstituent(dau); + } + } // apply corrections jet.calibratePt(corrector_.correctedPt(jet.pt(), jet.eta())); } From 9421d6c47d254f98013a2d2b1b41ff465b86b544 Mon Sep 17 00:00:00 2001 From: Dylan Rankin Date: Fri, 26 Aug 2022 08:36:51 -0500 Subject: [PATCH 3/8] adding bjets --- .../python/L1Trigger_EventContent_cff.py | 9 ++ .../Configuration/python/SimL1Emulator_cff.py | 5 + .../Phase2L1ParticleFlow/interface/BJetId.h | 37 +++++ .../plugins/L1BJetPFJetProducer.cc | 150 ++++++++++++++++++ .../python/L1BJetProducer_cff.py | 24 +++ L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc | 96 +++++++++++ 6 files changed, 321 insertions(+) create mode 100644 L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h create mode 100644 L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc create mode 100644 L1Trigger/Phase2L1ParticleFlow/python/L1BJetProducer_cff.py create mode 100644 L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc diff --git a/L1Trigger/Configuration/python/L1Trigger_EventContent_cff.py b/L1Trigger/Configuration/python/L1Trigger_EventContent_cff.py index 70cc49a0a6ec2..1480e29c03d79 100644 --- a/L1Trigger/Configuration/python/L1Trigger_EventContent_cff.py +++ b/L1Trigger/Configuration/python/L1Trigger_EventContent_cff.py @@ -190,6 +190,8 @@ def _appendPhase2Digis(obj): 'keep *_scPFL1PF_*_*', 'keep *_scPFL1Puppi_*_*', 'keep *_scPFL1PuppiCorrectedEmulator_*_*', + 'keep *_scPFL1PuppiExtended_*_*', + 'keep *_scPFL1PuppiExtendedCorrectedEmulator_*_*', 'keep *_scPFL1PuppiCorrectedEmulatorMHT_*_*', 'keep *_Phase1L1TJetProducer_*_*', 'keep *_Phase1L1TJetCalibrator_*_*', @@ -199,10 +201,17 @@ def _appendPhase2Digis(obj): 'keep *_l1ctLayer1HGCalNoTK_*_*', 'keep *_l1ctLayer1HF_*_*', 'keep *_l1ctLayer1_*_*', + 'keep *_l1ctLayer1BarrelExtended_*_*', + 'keep *_l1ctLayer1HGCalExtended_*_*', + 'keep *_l1ctLayer1Extended_*_*', 'keep *_l1ctLayer1EG_*_*', + 'keep *_pfTracksFromL1Tracks_*_*', + 'keep *_pfTracksFromL1TracksExtended_*_*', 'keep *_L1MetPfProducer_*_*', 'keep *_l1NNTauProducer_*_*', 'keep *_l1NNTauProducerPuppi_*_*', + 'keep *_l1BJetProducerPuppi_*_*', + 'keep *_l1BJetProducerPuppiCorrectedEmulator_*_*', 'keep *_TTStubsFromPhase2TrackerDigis_*_*', 'keep *_TTClustersFromPhase2TrackerDigis_*_*', 'keep *_TTTracksFromExtendedTrackletEmulation_*_*', diff --git a/L1Trigger/Configuration/python/SimL1Emulator_cff.py b/L1Trigger/Configuration/python/SimL1Emulator_cff.py index b117f24b5cb9c..b5ab4f1ea5d0e 100644 --- a/L1Trigger/Configuration/python/SimL1Emulator_cff.py +++ b/L1Trigger/Configuration/python/SimL1Emulator_cff.py @@ -222,6 +222,11 @@ #_phase2_siml1emulator.add(L1NNTauProducerPuppi2Vtx) _phase2_siml1emulator.add(tau2VtxTaskHW) +# BJets +# ######################################################################## +from L1Trigger.Phase2L1ParticleFlow.L1BJetProducer_cff import * +_phase2_siml1emulator.add(l1BJetsTask) + # --> add modules from Configuration.Eras.Modifier_phase2_trigger_cff import phase2_trigger diff --git a/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h b/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h new file mode 100644 index 0000000000000..ce3ee4a8a9481 --- /dev/null +++ b/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h @@ -0,0 +1,37 @@ +#ifndef L1TRIGGER_PHASE2L1PARTICLEFLOWS_TAUNNID_H +#define L1TRIGGER_PHASE2L1PARTICLEFLOWS_TAUNNID_H + +#include +#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" +#include "DataFormats/L1TParticleFlow/interface/PFCandidate.h" +#include "DataFormats/L1TParticleFlow/interface/PFJet.h" + +struct BJetTFCache { + BJetTFCache() : graphDef(nullptr) {} + std::atomic graphDef; +}; + +class BJetId { +public: + BJetId(const std::string &iInput, const BJetTFCache *cache, const std::string &iWeightFile, int iNParticles); + ~BJetId(); + + void setNNVectorVar(); + float EvaluateNN(); + float compute(const l1t::PFJet &iJet, float vz, bool useRawPt); + +private: + tensorflow::Session *session_; + std::vector NNvectorVar_; + std::string fInput_; + int fNParticles_; + unique_ptr fPt_; + unique_ptr fEta_; + unique_ptr fPhi_; + unique_ptr fId_; + unique_ptr fCharge_; + unique_ptr fDZ_; + unique_ptr fDX_; + unique_ptr fDY_; +}; +#endif diff --git a/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc b/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc new file mode 100644 index 0000000000000..213d93023cb19 --- /dev/null +++ b/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc @@ -0,0 +1,150 @@ +#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/BJetId.h" +#include "DataFormats/Common/interface/ValueMap.h" + +#include "DataFormats/L1TCorrelator/interface/TkPrimaryVertex.h" +#include "DataFormats/L1Trigger/interface/Vertex.h" +#include "DataFormats/L1Trigger/interface/VertexWord.h" + +#include "DataFormats/Math/interface/deltaR.h" +#include +#include + +using namespace l1t; + +class L1BJetProducer : public edm::stream::EDProducer> { +public: + explicit L1BJetProducer(const edm::ParameterSet&, const BJetTFCache*); + ~L1BJetProducer() override; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + static std::unique_ptr initializeGlobalCache(const edm::ParameterSet&); + static void globalEndJob(const BJetTFCache*); + +private: + std::unique_ptr fBJetId_; + void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override; + + edm::EDGetTokenT> jets_; + bool fUseRawPt_; + double fMinPt_; + double fMaxEta_; + unsigned int fMaxJets_; + int fNParticles_; + edm::EDGetTokenT> fTkVtx_; + edm::EDGetTokenT> fVtxEmu_; + bool fVtxEmulation_; + edm::EDGetTokenT fL1PFToken_; +}; + +static constexpr float track_trigger_eta_max = 2.5; + +L1BJetProducer::L1BJetProducer(const edm::ParameterSet& cfg, const BJetTFCache* cache) + : jets_(consumes>(cfg.getParameter("jets"))), + fUseRawPt_(cfg.getParameter("useRawPt")), + fMinPt_(cfg.getParameter("minPt")), + fMaxEta_(cfg.getParameter("maxEta")), + fMaxJets_(cfg.getParameter("maxJets")), + fNParticles_(cfg.getParameter("nParticles")), + fVtxEmulation_(cfg.getParameter("vtxEmulation")), + fL1PFToken_(consumes(cfg.getParameter("L1PFObjects"))) { + std::string lNNFile = cfg.getParameter("NNFileName"); + fBJetId_ = std::make_unique( + lNNFile.find("qModel") == std::string::npos ? "input:0" : "Conv1D_1_input:0", cache, lNNFile, fNParticles_); + if (fVtxEmulation_) { + fVtxEmu_ = consumes>(cfg.getParameter("vtx")); + } else { + fTkVtx_ = consumes>(cfg.getParameter("vtx")); + } + produces>("L1PFBJets"); +} +std::unique_ptr L1BJetProducer::initializeGlobalCache(const edm::ParameterSet& cfg) { + tensorflow::setLogging("3"); + std::string lNNFile = cfg.getParameter("NNFileName"); + edm::FileInPath fp(lNNFile); + BJetTFCache* cache = new BJetTFCache(); + cache->graphDef = tensorflow::loadGraphDef(fp.fullPath()); + return std::unique_ptr(cache); +} +void L1BJetProducer::globalEndJob(const BJetTFCache* cache) { + if (cache->graphDef != nullptr) { + delete cache->graphDef; + } +} +void L1BJetProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + + edm::Handle> jets; + iEvent.getByToken(jets_, jets); + + edm::Handle l1PFCandidates; + iEvent.getByToken(fL1PFToken_, l1PFCandidates); + + float vz = 0.; + double ptsum = 0; + if (fVtxEmulation_) { + edm::Handle> vtxEmuHandle; + iEvent.getByToken(fVtxEmu_, vtxEmuHandle); + for (const auto &vtx : *vtxEmuHandle) { + if (ptsum == 0 || vtx.pt() > ptsum) { + ptsum = vtx.pt(); + vz = vtx.z0(); + } + } + } else { + edm::Handle> vtxHandle; + iEvent.getByToken(fTkVtx_, vtxHandle); + for (const l1t::TkPrimaryVertex & vtx : *vtxHandle) { + if (ptsum == 0 || vtx.sum() > ptsum) { + ptsum = vtx.sum(); + vz = vtx.zvertex(); + } + } + } + + std::vector bScores; + + for (const auto& srcjet : *jets) { + if ((srcjet.pt()fMaxEta_ || bScores.size() >= fMaxJets_) { + bScores.push_back(-1.); + continue; + } + float NN = fBJetId_->compute(srcjet, vz, fUseRawPt_); + bScores.push_back(NN); + } + + auto outT = std::make_unique>(); + edm::ValueMap::Filler fillerT(*outT); + fillerT.insert(jets, bScores.begin(), bScores.end()); + fillerT.fill(); + + iEvent.put(std::move(outT), "L1PFBJets"); +} + +void L1BJetProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + // L1BJetProducer + edm::ParameterSetDescription desc; + desc.add("jets", edm::InputTag("scPFL1Puppi")); + desc.add("useRawPt", true); + desc.add("NNFileName", "L1Trigger/Phase2L1ParticleFlow/data/modelTT_PUP_Off_dXY_XYCut_Graph.pb"); + desc.add("maxJets", 10); + desc.add("nParticles", 10); + desc.add("minPt", 20); + desc.add("maxEta", 2.4); + desc.add("vtx", edm::InputTag("L1VertexFinderEmulator","l1verticesEmulation")); + desc.add("vtxEmulation", true); + desc.add("L1PFObjects", edm::InputTag("l1ctLayer1", "Puppi")); + descriptions.add("L1BJetProducer", desc); +} +L1BJetProducer::~L1BJetProducer() {} + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(L1BJetProducer); diff --git a/L1Trigger/Phase2L1ParticleFlow/python/L1BJetProducer_cff.py b/L1Trigger/Phase2L1ParticleFlow/python/L1BJetProducer_cff.py new file mode 100644 index 0000000000000..0420ef2e2ecec --- /dev/null +++ b/L1Trigger/Phase2L1ParticleFlow/python/L1BJetProducer_cff.py @@ -0,0 +1,24 @@ +import FWCore.ParameterSet.Config as cms + +from L1Trigger.Phase2L1ParticleFlow.l1pfJetMet_cff import l1PFJetsExtendedTask + +l1BJetProducerPuppi = cms.EDProducer("L1BJetProducer", + jets = cms.InputTag("scPFL1PuppiExtended", ""), + useRawPt = cms.bool(True), + NNFileName = cms.string("L1Trigger/Phase2L1ParticleFlow/data/modelTT_PUP_Off_dXY_XYCut_Graph.pb"), + maxJets = cms.int32(6), + nParticles = cms.int32(10), + minPt = cms.double(10), + maxEta = cms.double(2.4), + vtx = cms.InputTag("L1VertexFinderEmulator","l1verticesEmulation"), + vtxEmulation = cms.bool(True), + L1PFObjects = cms.InputTag("l1ctLayer1Extended","Puppi"), +) +l1BJetProducerPuppiCorrectedEmulator = l1BJetProducerPuppi.clone( + jets = cms.InputTag("scPFL1PuppiExtendedCorrectedEmulator", ""), + L1PFObjects = cms.InputTag("l1ctLayer2DeregionizerExtended","Puppi"), +) + +l1BJetsTask = cms.Task( + l1PFJetsExtendedTask, l1BJetProducerPuppi, l1BJetProducerPuppiCorrectedEmulator +) diff --git a/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc b/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc new file mode 100644 index 0000000000000..1b1c5a9ac37bb --- /dev/null +++ b/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc @@ -0,0 +1,96 @@ +#include "L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h" +#include "FWCore/ParameterSet/interface/FileInPath.h" +#include "DataFormats/Math/interface/deltaPhi.h" +#include + +static constexpr unsigned int n_particles_max = 10; + +BJetId::BJetId(const std::string &iInput, const BJetTFCache *cache, const std::string &iWeightFile, int iNParticles) { + NNvectorVar_.clear(); + edm::FileInPath fp(iWeightFile); + session_ = tensorflow::createSession(cache->graphDef); + fNParticles_ = iNParticles; + + fPt_ = std::make_unique(fNParticles_); + fEta_ = std::make_unique(fNParticles_); + fPhi_ = std::make_unique(fNParticles_); + fId_ = std::make_unique(fNParticles_); + fCharge_ = std::make_unique(fNParticles_); + fDZ_ = std::make_unique(fNParticles_); + fDX_ = std::make_unique(fNParticles_); + fDY_ = std::make_unique(fNParticles_); + fInput_ = iInput; +} + +BJetId::~BJetId() { tensorflow::closeSession(session_); } +void BJetId::setNNVectorVar() { + NNvectorVar_.clear(); + for (int i0 = 0; i0 < fNParticles_; i0++) { + if (fPt_.get()[i0] == 0) { + for (int i1 = 0; i1 < 13; i1++) + NNvectorVar_.push_back(0); + continue; + } + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Electron && fCharge_.get()[i0]<0); // Electron + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Electron && fCharge_.get()[i0]>0); // Positron + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Muon && fCharge_.get()[i0]<0); // Muon + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Muon && fCharge_.get()[i0]>0); // Anti-Muon + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Photon && fCharge_.get()[i0]==0); // Photon + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::NeutralHadron && fCharge_.get()[i0]==0); // Neutral Had + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron && fCharge_.get()[i0]<0); // Pion + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron && fCharge_.get()[i0]>0); // Anti-Pion + NNvectorVar_.push_back(fDZ_.get()[i0]); //dZ + NNvectorVar_.push_back(std::sqrt(fDX_.get()[i0]*fDX_.get()[i0] + fDY_.get()[i0]*fDY_.get()[i0])); //d0 + NNvectorVar_.push_back(fPt_.get()[i0]); //pT as a fraction of jet pT + NNvectorVar_.push_back(fEta_.get()[i0]); //dEta from jet axis + NNvectorVar_.push_back(fPhi_.get()[i0]); //dPhi from jet axis + } +} +float BJetId::EvaluateNN() { + tensorflow::Tensor input(tensorflow::DT_FLOAT, + {1, (unsigned int)NNvectorVar_.size(), 1}); + for (unsigned int i = 0; i < NNvectorVar_.size(); i++) { + input.tensor()(0, i, 0) = float(NNvectorVar_[i]); + } + std::vector outputs; + tensorflow::run(session_, {{fInput_, input}}, {"sequential/dense_2/Sigmoid"}, &outputs); + //tensorflow::run(session_, {{fInput_, input}}, {"sequential/sigmoid/Sigmoid"}, &outputs);//TODO: for QKeras models, add auto switch + return outputs[0].matrix()(0,0); +} //end EvaluateNN + +float BJetId::compute(const l1t::PFJet &iJet, float vz, bool useRawPt) { + for (int i0 = 0; i0 < fNParticles_; i0++) { + fPt_.get()[i0] = 0; + fEta_.get()[i0] = 0; + fPhi_.get()[i0] = 0; + fId_.get()[i0] = 0; + fCharge_.get()[i0] = 0; + fDZ_.get()[i0] = 0; + fDX_.get()[i0] = 0; + fDY_.get()[i0] = 0; + } + auto iParts = iJet.constituents(); + std::sort(iParts.begin(), iParts.end(), [](edm::Ptr i, edm::Ptr j) { return (i->pt() > j->pt()); }); + float jetpt; + if (useRawPt) { + jetpt = iJet.rawPt(); + } else { + jetpt = iJet.pt(); + } + for (unsigned int i0 = 0; i0 < iParts.size(); i0++) { + if (i0 > n_particles_max || i0 >= (unsigned int)fNParticles_) + break; + fPt_.get()[i0] = iParts[i0]->pt()/jetpt; + fEta_.get()[i0] = iParts[i0]->eta() - iJet.eta(); + fPhi_.get()[i0] = deltaPhi(iParts[i0]->phi(), iJet.phi()); + fId_.get()[i0] = iParts[i0]->id(); + fCharge_.get()[i0] = iParts[i0]->charge(); + if (iParts[i0]->pfTrack().isNonnull()) { + fDX_.get()[i0] = iParts[i0]->pfTrack()->vx(); + fDY_.get()[i0] = iParts[i0]->pfTrack()->vy(); + fDZ_.get()[i0] = iParts[i0]->pfTrack()->vz()-vz; + } + } + setNNVectorVar(); + return EvaluateNN(); +} From dccae6b39ffc49208b01a359dac4d027deecaddd Mon Sep 17 00:00:00 2001 From: Dylan Rankin Date: Fri, 26 Aug 2022 08:40:49 -0500 Subject: [PATCH 4/8] adding model file --- .../data/modelTT_PUP_Off_dXY_XYCut_Graph.pb | Bin 0 -> 12733 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 L1Trigger/Phase2L1ParticleFlow/data/modelTT_PUP_Off_dXY_XYCut_Graph.pb diff --git a/L1Trigger/Phase2L1ParticleFlow/data/modelTT_PUP_Off_dXY_XYCut_Graph.pb b/L1Trigger/Phase2L1ParticleFlow/data/modelTT_PUP_Off_dXY_XYCut_Graph.pb new file mode 100644 index 0000000000000000000000000000000000000000..3031dc01977c8e45e5640b53e3c31ac39ef9c96a GIT binary patch literal 12733 zcmch730RHW_kX9kx0H@F91)2Unv@}DuT5kgGiN*v6iqsnnFc9@BCab@NfZeg>%41c z$Q;R>=~m{UE@htn=iaN-RribE^Za|BQ>SzG-fLc;^{&0R-kgfJUqEn>P;;1%#NE@& z-^ar<&{C6A@d%m|;3-tJ5m>h3RHR-K`9Fq^`a(_hFV#N+p^|#IK&YrL;D&SNQqP&e zo_;~z5+7@Kf4>l0kLo|pvjZf49=*MNrPdzazCx8={(jP++7y&5g`7%=#3$HOsNtlh zt|U}&6bQHwuJsQbDdfH#FZxFk(T}oX$#Kdf|6)neM#)l*6O8;zT5gF3M}C0tWLs+& zPl?B9NuamH&Bt?SfOVj!)IT`T-LoDE1(v(jt3^yxciN(^E)Z(T71!u5<;h=qrm^aY zSEhi)jbgIkV_Q_)nubXZ?}=G@0g-5Kg1y%LDTav2lyqe_uT2Pv*qhTmSidRU7&j9} zC@GO+g^x(ar(`&Mj$^AMW7x<{cQ|I&iZO+w~V$Ww~e81k}0exk3m#)f`~tI`5pmxQD7*clZ`$R z1Iq}i7;p!UT))l=ZO1Ti_#Ln)31#<3_u^fATCnE+`%y1029}Jd#L8v4Sl+Y(N>2{Q zz?o8f;a0?&1RMmz)6=O}Q6g0t{U>=HE}=`rQfBm)vc8!+S;SG@yug8!&N{c0Cow53 zCnKEl9j?fhJD$g_y0^s=$3&L*Vj&s(bUC(O+eoakqca_KHX2SmnL_%1_C{Qc8(6Xm#fs2t*fGt8&9_p=l3~B|Hk}T# zwmwsM!{6t#FL875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Tt)SwujNARiKptX>Swx!Y(wzU`}^Xg?$ywL@LF>?x2*1D&p$lb{R+hNtTt#@r_NvT zg_Glpz|^AUH32nwo(79zgFw%$HN@IVVW?RV`p?K?=%mHQowjB3hA6Ol!>j>bYT5Mr zFl%5>jYEDDe{FqXR=vF@%)YA?s_(IC&+7cA>gpDB|GUO>uP4szeksn3s?E~aN&9P@ z2`rV5cHG3*8$%5dsip7lW2m7`^(egF7^>O-Uoli|l{)i2)k^=x7#dJdK-*c5@Sf)D z@9iNUocrfZog)8V6u-GrxH4BW;#o^u-$!8$0a3e2wUX)Ak*fM75joVe^t&OfzumI- z^t-72_uCrG*P<@37PUA2t)K>6Rb>AC%6h9=k>z&_8|J%?8vn6R14VLu$JRLC Wzp$~cb*jx?FSj*LV5+2^CHQ}ZtuoyJ literal 0 HcmV?d00001 From 80f73bc0e02050ee28cfca2bd763f6ca07ad4605 Mon Sep 17 00:00:00 2001 From: Dylan Rankin Date: Fri, 26 Aug 2022 08:54:29 -0500 Subject: [PATCH 5/8] fixing header --- L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h b/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h index ce3ee4a8a9481..ae2eabae1ca38 100644 --- a/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h +++ b/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h @@ -1,5 +1,5 @@ -#ifndef L1TRIGGER_PHASE2L1PARTICLEFLOWS_TAUNNID_H -#define L1TRIGGER_PHASE2L1PARTICLEFLOWS_TAUNNID_H +#ifndef L1TRIGGER_PHASE2L1PARTICLEFLOWS_BJETID_H +#define L1TRIGGER_PHASE2L1PARTICLEFLOWS_BJETID_H #include #include "PhysicsTools/TensorFlow/interface/TensorFlow.h" From 5c9456ccd671cf04097159d088fa2d2a90179182 Mon Sep 17 00:00:00 2001 From: Dylan Rankin Date: Tue, 6 Sep 2022 13:45:51 -0500 Subject: [PATCH 6/8] cleanup --- L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h | 4 ++-- .../Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc | 8 ++------ .../plugins/L1TCorrectedPFJetProducer.cc | 7 ++----- L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc | 3 +-- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h b/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h index ae2eabae1ca38..086d6cf1c9cfc 100644 --- a/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h +++ b/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h @@ -7,8 +7,8 @@ #include "DataFormats/L1TParticleFlow/interface/PFJet.h" struct BJetTFCache { - BJetTFCache() : graphDef(nullptr) {} - std::atomic graphDef; + BJetTFCache(std::string graphPath) : graphDef(tensorflow::loadGraphDef(graphPath)) {} + std::unique_ptr graphDef; }; class BJetId { diff --git a/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc b/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc index 213d93023cb19..ffaecad92a8d1 100644 --- a/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc +++ b/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc @@ -71,14 +71,10 @@ std::unique_ptr L1BJetProducer::initializeGlobalCache(const edm::Pa tensorflow::setLogging("3"); std::string lNNFile = cfg.getParameter("NNFileName"); edm::FileInPath fp(lNNFile); - BJetTFCache* cache = new BJetTFCache(); - cache->graphDef = tensorflow::loadGraphDef(fp.fullPath()); - return std::unique_ptr(cache); + auto cache = std::make_unique(fp.fullPath()); + return cache; } void L1BJetProducer::globalEndJob(const BJetTFCache* cache) { - if (cache->graphDef != nullptr) { - delete cache->graphDef; - } } void L1BJetProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { diff --git a/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCorrectedPFJetProducer.cc b/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCorrectedPFJetProducer.cc index 1421b09331de3..d01b8cb7eaee1 100644 --- a/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCorrectedPFJetProducer.cc +++ b/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCorrectedPFJetProducer.cc @@ -44,11 +44,8 @@ void L1TCorrectedPFJetProducer::produce(edm::StreamID, edm::Event& iEvent, const out->emplace_back(srcjet.p4()); auto& jet = out->back(); // copy daughters - bool copyDaughters_ = true; - if (copyDaughters_) { - for (const auto& dau : srcjet.constituents()) { - jet.addConstituent(dau); - } + for (const auto& dau : srcjet.constituents()) { + jet.addConstituent(dau); } // apply corrections jet.calibratePt(corrector_.correctedPt(jet.pt(), jet.eta())); diff --git a/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc b/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc index 1b1c5a9ac37bb..d24f91f6b34c6 100644 --- a/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc +++ b/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc @@ -7,8 +7,7 @@ static constexpr unsigned int n_particles_max = 10; BJetId::BJetId(const std::string &iInput, const BJetTFCache *cache, const std::string &iWeightFile, int iNParticles) { NNvectorVar_.clear(); - edm::FileInPath fp(iWeightFile); - session_ = tensorflow::createSession(cache->graphDef); + session_ = tensorflow::createSession(cache->graphDef.get()); fNParticles_ = iNParticles; fPt_ = std::make_unique(fNParticles_); From 4844f9201ea947a472f52d5213528dcccb81c3a8 Mon Sep 17 00:00:00 2001 From: Dylan Rankin Date: Wed, 7 Sep 2022 12:06:29 -0500 Subject: [PATCH 7/8] more cleanup --- .../Phase2L1ParticleFlow/interface/BJetId.h | 5 ++-- .../plugins/L1BJetPFJetProducer.cc | 14 ++++------- .../python/L1BJetProducer_cff.py | 4 ++-- L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc | 24 +++++++------------ 4 files changed, 18 insertions(+), 29 deletions(-) diff --git a/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h b/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h index 086d6cf1c9cfc..6bf3aa2b5c72b 100644 --- a/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h +++ b/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h @@ -7,13 +7,13 @@ #include "DataFormats/L1TParticleFlow/interface/PFJet.h" struct BJetTFCache { - BJetTFCache(std::string graphPath) : graphDef(tensorflow::loadGraphDef(graphPath)) {} + BJetTFCache(const std::string &graphPath) : graphDef(tensorflow::loadGraphDef(graphPath)) {} std::unique_ptr graphDef; }; class BJetId { public: - BJetId(const std::string &iInput, const BJetTFCache *cache, const std::string &iWeightFile, int iNParticles); + BJetId(const std::string &iInput, const std::string &iOutput, const BJetTFCache *cache, const std::string &iWeightFile, int iNParticles); ~BJetId(); void setNNVectorVar(); @@ -24,6 +24,7 @@ class BJetId { tensorflow::Session *session_; std::vector NNvectorVar_; std::string fInput_; + std::string fOutput_; int fNParticles_; unique_ptr fPt_; unique_ptr fEta_; diff --git a/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc b/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc index ffaecad92a8d1..d4894715fb386 100644 --- a/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc +++ b/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc @@ -43,7 +43,6 @@ class L1BJetProducer : public edm::stream::EDProducer> fTkVtx_; edm::EDGetTokenT> fVtxEmu_; bool fVtxEmulation_; - edm::EDGetTokenT fL1PFToken_; }; static constexpr float track_trigger_eta_max = 2.5; @@ -55,11 +54,10 @@ L1BJetProducer::L1BJetProducer(const edm::ParameterSet& cfg, const BJetTFCache* fMaxEta_(cfg.getParameter("maxEta")), fMaxJets_(cfg.getParameter("maxJets")), fNParticles_(cfg.getParameter("nParticles")), - fVtxEmulation_(cfg.getParameter("vtxEmulation")), - fL1PFToken_(consumes(cfg.getParameter("L1PFObjects"))) { + fVtxEmulation_(cfg.getParameter("vtxEmulation")) { std::string lNNFile = cfg.getParameter("NNFileName"); fBJetId_ = std::make_unique( - lNNFile.find("qModel") == std::string::npos ? "input:0" : "Conv1D_1_input:0", cache, lNNFile, fNParticles_); + cfg.getParameter("NNInput"), cfg.getParameter("NNOutput"), cache, lNNFile, fNParticles_); if (fVtxEmulation_) { fVtxEmu_ = consumes>(cfg.getParameter("vtx")); } else { @@ -81,9 +79,6 @@ void L1BJetProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) edm::Handle> jets; iEvent.getByToken(jets_, jets); - edm::Handle l1PFCandidates; - iEvent.getByToken(fL1PFToken_, l1PFCandidates); - float vz = 0.; double ptsum = 0; if (fVtxEmulation_) { @@ -109,7 +104,7 @@ void L1BJetProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) std::vector bScores; for (const auto& srcjet : *jets) { - if ((srcjet.pt()fMaxEta_ || bScores.size() >= fMaxJets_) { + if (((fUseRawPt_ ? srcjet.rawPt() : srcjet.pt()) < fMinPt_) || std::abs(srcjet.eta())>fMaxEta_ || bScores.size() >= fMaxJets_) { bScores.push_back(-1.); continue; } @@ -131,13 +126,14 @@ void L1BJetProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptio desc.add("jets", edm::InputTag("scPFL1Puppi")); desc.add("useRawPt", true); desc.add("NNFileName", "L1Trigger/Phase2L1ParticleFlow/data/modelTT_PUP_Off_dXY_XYCut_Graph.pb"); + desc.add("NNInput", "input:0"); + desc.add("NNOutput", "sequential/dense_2/Sigmoid"); desc.add("maxJets", 10); desc.add("nParticles", 10); desc.add("minPt", 20); desc.add("maxEta", 2.4); desc.add("vtx", edm::InputTag("L1VertexFinderEmulator","l1verticesEmulation")); desc.add("vtxEmulation", true); - desc.add("L1PFObjects", edm::InputTag("l1ctLayer1", "Puppi")); descriptions.add("L1BJetProducer", desc); } L1BJetProducer::~L1BJetProducer() {} diff --git a/L1Trigger/Phase2L1ParticleFlow/python/L1BJetProducer_cff.py b/L1Trigger/Phase2L1ParticleFlow/python/L1BJetProducer_cff.py index 0420ef2e2ecec..2d706b245c59f 100644 --- a/L1Trigger/Phase2L1ParticleFlow/python/L1BJetProducer_cff.py +++ b/L1Trigger/Phase2L1ParticleFlow/python/L1BJetProducer_cff.py @@ -6,17 +6,17 @@ jets = cms.InputTag("scPFL1PuppiExtended", ""), useRawPt = cms.bool(True), NNFileName = cms.string("L1Trigger/Phase2L1ParticleFlow/data/modelTT_PUP_Off_dXY_XYCut_Graph.pb"), + NNInput = cms.string("input:0"), + NNOutput = cms.string("sequential/dense_2/Sigmoid"), maxJets = cms.int32(6), nParticles = cms.int32(10), minPt = cms.double(10), maxEta = cms.double(2.4), vtx = cms.InputTag("L1VertexFinderEmulator","l1verticesEmulation"), vtxEmulation = cms.bool(True), - L1PFObjects = cms.InputTag("l1ctLayer1Extended","Puppi"), ) l1BJetProducerPuppiCorrectedEmulator = l1BJetProducerPuppi.clone( jets = cms.InputTag("scPFL1PuppiExtendedCorrectedEmulator", ""), - L1PFObjects = cms.InputTag("l1ctLayer2DeregionizerExtended","Puppi"), ) l1BJetsTask = cms.Task( diff --git a/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc b/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc index d24f91f6b34c6..082d8aa5f0c13 100644 --- a/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc +++ b/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc @@ -1,11 +1,8 @@ #include "L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h" -#include "FWCore/ParameterSet/interface/FileInPath.h" #include "DataFormats/Math/interface/deltaPhi.h" #include -static constexpr unsigned int n_particles_max = 10; - -BJetId::BJetId(const std::string &iInput, const BJetTFCache *cache, const std::string &iWeightFile, int iNParticles) { +BJetId::BJetId(const std::string &iInput, const std::string &iOutput, const BJetTFCache *cache, const std::string &iWeightFile, int iNParticles) { NNvectorVar_.clear(); session_ = tensorflow::createSession(cache->graphDef.get()); fNParticles_ = iNParticles; @@ -19,6 +16,7 @@ BJetId::BJetId(const std::string &iInput, const BJetTFCache *cache, const std::s fDX_ = std::make_unique(fNParticles_); fDY_ = std::make_unique(fNParticles_); fInput_ = iInput; + fOutput_ = iOutput; } BJetId::~BJetId() { tensorflow::closeSession(session_); } @@ -34,12 +32,12 @@ void BJetId::setNNVectorVar() { NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Electron && fCharge_.get()[i0]>0); // Positron NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Muon && fCharge_.get()[i0]<0); // Muon NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Muon && fCharge_.get()[i0]>0); // Anti-Muon - NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Photon && fCharge_.get()[i0]==0); // Photon - NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::NeutralHadron && fCharge_.get()[i0]==0); // Neutral Had + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Photon); // Photon + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::NeutralHadron); // Neutral Had NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron && fCharge_.get()[i0]<0); // Pion NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron && fCharge_.get()[i0]>0); // Anti-Pion NNvectorVar_.push_back(fDZ_.get()[i0]); //dZ - NNvectorVar_.push_back(std::sqrt(fDX_.get()[i0]*fDX_.get()[i0] + fDY_.get()[i0]*fDY_.get()[i0])); //d0 + NNvectorVar_.push_back(std::hypot(fDX_.get()[i0], fDY_.get()[i0])); //d0 NNvectorVar_.push_back(fPt_.get()[i0]); //pT as a fraction of jet pT NNvectorVar_.push_back(fEta_.get()[i0]); //dEta from jet axis NNvectorVar_.push_back(fPhi_.get()[i0]); //dPhi from jet axis @@ -52,8 +50,7 @@ float BJetId::EvaluateNN() { input.tensor()(0, i, 0) = float(NNvectorVar_[i]); } std::vector outputs; - tensorflow::run(session_, {{fInput_, input}}, {"sequential/dense_2/Sigmoid"}, &outputs); - //tensorflow::run(session_, {{fInput_, input}}, {"sequential/sigmoid/Sigmoid"}, &outputs);//TODO: for QKeras models, add auto switch + tensorflow::run(session_, {{fInput_, input}}, {fOutput_}, &outputs); return outputs[0].matrix()(0,0); } //end EvaluateNN @@ -70,14 +67,9 @@ float BJetId::compute(const l1t::PFJet &iJet, float vz, bool useRawPt) { } auto iParts = iJet.constituents(); std::sort(iParts.begin(), iParts.end(), [](edm::Ptr i, edm::Ptr j) { return (i->pt() > j->pt()); }); - float jetpt; - if (useRawPt) { - jetpt = iJet.rawPt(); - } else { - jetpt = iJet.pt(); - } + float jetpt = useRawPt ? iJet.rawPt() : iJet.pt(); for (unsigned int i0 = 0; i0 < iParts.size(); i0++) { - if (i0 > n_particles_max || i0 >= (unsigned int)fNParticles_) + if (i0 >= (unsigned int)fNParticles_) break; fPt_.get()[i0] = iParts[i0]->pt()/jetpt; fEta_.get()[i0] = iParts[i0]->eta() - iJet.eta(); From 85a3d3743021cbc8b1b47eab916fa076ff933f6e Mon Sep 17 00:00:00 2001 From: Dylan Rankin Date: Wed, 7 Sep 2022 13:10:47 -0500 Subject: [PATCH 8/8] format --- .../Phase2L1ParticleFlow/interface/BJetId.h | 6 ++- .../plugins/L1BJetPFJetProducer.cc | 15 ++++--- L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc | 41 +++++++++++-------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h b/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h index 6bf3aa2b5c72b..860908f7a35fd 100644 --- a/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h +++ b/L1Trigger/Phase2L1ParticleFlow/interface/BJetId.h @@ -13,7 +13,11 @@ struct BJetTFCache { class BJetId { public: - BJetId(const std::string &iInput, const std::string &iOutput, const BJetTFCache *cache, const std::string &iWeightFile, int iNParticles); + BJetId(const std::string &iInput, + const std::string &iOutput, + const BJetTFCache *cache, + const std::string &iWeightFile, + int iNParticles); ~BJetId(); void setNNVectorVar(); diff --git a/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc b/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc index d4894715fb386..70bc8aa0bf32e 100644 --- a/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc +++ b/L1Trigger/Phase2L1ParticleFlow/plugins/L1BJetPFJetProducer.cc @@ -55,7 +55,7 @@ L1BJetProducer::L1BJetProducer(const edm::ParameterSet& cfg, const BJetTFCache* fMaxJets_(cfg.getParameter("maxJets")), fNParticles_(cfg.getParameter("nParticles")), fVtxEmulation_(cfg.getParameter("vtxEmulation")) { - std::string lNNFile = cfg.getParameter("NNFileName"); + std::string lNNFile = cfg.getParameter("NNFileName"); fBJetId_ = std::make_unique( cfg.getParameter("NNInput"), cfg.getParameter("NNOutput"), cache, lNNFile, fNParticles_); if (fVtxEmulation_) { @@ -72,10 +72,8 @@ std::unique_ptr L1BJetProducer::initializeGlobalCache(const edm::Pa auto cache = std::make_unique(fp.fullPath()); return cache; } -void L1BJetProducer::globalEndJob(const BJetTFCache* cache) { -} +void L1BJetProducer::globalEndJob(const BJetTFCache* cache) {} void L1BJetProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - edm::Handle> jets; iEvent.getByToken(jets_, jets); @@ -84,7 +82,7 @@ void L1BJetProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) if (fVtxEmulation_) { edm::Handle> vtxEmuHandle; iEvent.getByToken(fVtxEmu_, vtxEmuHandle); - for (const auto &vtx : *vtxEmuHandle) { + for (const auto& vtx : *vtxEmuHandle) { if (ptsum == 0 || vtx.pt() > ptsum) { ptsum = vtx.pt(); vz = vtx.z0(); @@ -93,7 +91,7 @@ void L1BJetProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) } else { edm::Handle> vtxHandle; iEvent.getByToken(fTkVtx_, vtxHandle); - for (const l1t::TkPrimaryVertex & vtx : *vtxHandle) { + for (const l1t::TkPrimaryVertex& vtx : *vtxHandle) { if (ptsum == 0 || vtx.sum() > ptsum) { ptsum = vtx.sum(); vz = vtx.zvertex(); @@ -104,7 +102,8 @@ void L1BJetProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) std::vector bScores; for (const auto& srcjet : *jets) { - if (((fUseRawPt_ ? srcjet.rawPt() : srcjet.pt()) < fMinPt_) || std::abs(srcjet.eta())>fMaxEta_ || bScores.size() >= fMaxJets_) { + if (((fUseRawPt_ ? srcjet.rawPt() : srcjet.pt()) < fMinPt_) || std::abs(srcjet.eta()) > fMaxEta_ || + bScores.size() >= fMaxJets_) { bScores.push_back(-1.); continue; } @@ -132,7 +131,7 @@ void L1BJetProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptio desc.add("nParticles", 10); desc.add("minPt", 20); desc.add("maxEta", 2.4); - desc.add("vtx", edm::InputTag("L1VertexFinderEmulator","l1verticesEmulation")); + desc.add("vtx", edm::InputTag("L1VertexFinderEmulator", "l1verticesEmulation")); desc.add("vtxEmulation", true); descriptions.add("L1BJetProducer", desc); } diff --git a/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc b/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc index 082d8aa5f0c13..3cfb2dc76055e 100644 --- a/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc +++ b/L1Trigger/Phase2L1ParticleFlow/src/BJetId.cc @@ -2,7 +2,11 @@ #include "DataFormats/Math/interface/deltaPhi.h" #include -BJetId::BJetId(const std::string &iInput, const std::string &iOutput, const BJetTFCache *cache, const std::string &iWeightFile, int iNParticles) { +BJetId::BJetId(const std::string &iInput, + const std::string &iOutput, + const BJetTFCache *cache, + const std::string &iWeightFile, + int iNParticles) { NNvectorVar_.clear(); session_ = tensorflow::createSession(cache->graphDef.get()); fNParticles_ = iNParticles; @@ -28,30 +32,29 @@ void BJetId::setNNVectorVar() { NNvectorVar_.push_back(0); continue; } - NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Electron && fCharge_.get()[i0]<0); // Electron - NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Electron && fCharge_.get()[i0]>0); // Positron - NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Muon && fCharge_.get()[i0]<0); // Muon - NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Muon && fCharge_.get()[i0]>0); // Anti-Muon - NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Photon); // Photon - NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::NeutralHadron); // Neutral Had - NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron && fCharge_.get()[i0]<0); // Pion - NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron && fCharge_.get()[i0]>0); // Anti-Pion - NNvectorVar_.push_back(fDZ_.get()[i0]); //dZ - NNvectorVar_.push_back(std::hypot(fDX_.get()[i0], fDY_.get()[i0])); //d0 + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Electron && fCharge_.get()[i0] < 0); // Electron + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Electron && fCharge_.get()[i0] > 0); // Positron + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Muon && fCharge_.get()[i0] < 0); // Muon + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Muon && fCharge_.get()[i0] > 0); // Anti-Muon + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Photon); // Photon + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::NeutralHadron); // Neutral Had + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron && fCharge_.get()[i0] < 0); // Pion + NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron && fCharge_.get()[i0] > 0); // Anti-Pion + NNvectorVar_.push_back(fDZ_.get()[i0]); //dZ + NNvectorVar_.push_back(std::hypot(fDX_.get()[i0], fDY_.get()[i0])); //d0 NNvectorVar_.push_back(fPt_.get()[i0]); //pT as a fraction of jet pT NNvectorVar_.push_back(fEta_.get()[i0]); //dEta from jet axis NNvectorVar_.push_back(fPhi_.get()[i0]); //dPhi from jet axis } } float BJetId::EvaluateNN() { - tensorflow::Tensor input(tensorflow::DT_FLOAT, - {1, (unsigned int)NNvectorVar_.size(), 1}); + tensorflow::Tensor input(tensorflow::DT_FLOAT, {1, (unsigned int)NNvectorVar_.size(), 1}); for (unsigned int i = 0; i < NNvectorVar_.size(); i++) { - input.tensor()(0, i, 0) = float(NNvectorVar_[i]); + input.tensor()(0, i, 0) = float(NNvectorVar_[i]); } std::vector outputs; tensorflow::run(session_, {{fInput_, input}}, {fOutput_}, &outputs); - return outputs[0].matrix()(0,0); + return outputs[0].matrix()(0, 0); } //end EvaluateNN float BJetId::compute(const l1t::PFJet &iJet, float vz, bool useRawPt) { @@ -66,12 +69,14 @@ float BJetId::compute(const l1t::PFJet &iJet, float vz, bool useRawPt) { fDY_.get()[i0] = 0; } auto iParts = iJet.constituents(); - std::sort(iParts.begin(), iParts.end(), [](edm::Ptr i, edm::Ptr j) { return (i->pt() > j->pt()); }); + std::sort(iParts.begin(), iParts.end(), [](edm::Ptr i, edm::Ptr j) { + return (i->pt() > j->pt()); + }); float jetpt = useRawPt ? iJet.rawPt() : iJet.pt(); for (unsigned int i0 = 0; i0 < iParts.size(); i0++) { if (i0 >= (unsigned int)fNParticles_) break; - fPt_.get()[i0] = iParts[i0]->pt()/jetpt; + fPt_.get()[i0] = iParts[i0]->pt() / jetpt; fEta_.get()[i0] = iParts[i0]->eta() - iJet.eta(); fPhi_.get()[i0] = deltaPhi(iParts[i0]->phi(), iJet.phi()); fId_.get()[i0] = iParts[i0]->id(); @@ -79,7 +84,7 @@ float BJetId::compute(const l1t::PFJet &iJet, float vz, bool useRawPt) { if (iParts[i0]->pfTrack().isNonnull()) { fDX_.get()[i0] = iParts[i0]->pfTrack()->vx(); fDY_.get()[i0] = iParts[i0]->pfTrack()->vy(); - fDZ_.get()[i0] = iParts[i0]->pfTrack()->vz()-vz; + fDZ_.get()[i0] = iParts[i0]->pfTrack()->vz() - vz; } } setNNVectorVar();