From ff77cd3007c9478f369b09d616e20276ee76001a Mon Sep 17 00:00:00 2001 From: Sebastien Wertz Date: Mon, 31 Oct 2022 16:19:44 +0100 Subject: [PATCH 01/14] move PATObjectCrossLinker to Event::get, avoid copies in push_back --- .../PatAlgos/plugins/PATObjectCrossLinker.cc | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc index f2f99463783b8..cd6cc23750e17 100644 --- a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc +++ b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc @@ -205,47 +205,47 @@ void PATObjectCrossLinker::matchLowPtToElectron(const C1& refProdOne, void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { using namespace edm; - edm::Handle> jetsIn; - iEvent.getByToken(jets_, jetsIn); + const auto& jetsIn = iEvent.get(jets_); auto jets = std::make_unique>(); - for (const auto& j : *jetsIn) + jets->reserve(jetsIn.size()); + for (const auto& j : jetsIn) jets->push_back(j); auto jetRefProd = iEvent.getRefBeforePut>("jets"); - edm::Handle> muonsIn; - iEvent.getByToken(muons_, muonsIn); + const auto& muonsIn = iEvent.get(muons_); auto muons = std::make_unique>(); - for (const auto& m : *muonsIn) + muons->reserve(muonsIn.size()); + for (const auto& m : muonsIn) muons->push_back(m); auto muRefProd = iEvent.getRefBeforePut>("muons"); - edm::Handle> electronsIn; - iEvent.getByToken(electrons_, electronsIn); + const auto& electronsIn = iEvent.get(electrons_); auto electrons = std::make_unique>(); - for (const auto& e : *electronsIn) + electrons->reserve(electronsIn.size()); + for (const auto& e : electronsIn) electrons->push_back(e); auto eleRefProd = iEvent.getRefBeforePut>("electrons"); - edm::Handle> lowPtElectronsIn; auto lowPtElectrons = std::make_unique>(); if (!lowPtElectronsTag_.label().empty()) { - iEvent.getByToken(lowPtElectrons_, lowPtElectronsIn); + auto lowPtElectronsIn = iEvent.getHandle(lowPtElectrons_); + lowPtElectrons->reserve(lowPtElectronsIn->size()); for (const auto& e : *lowPtElectronsIn) { lowPtElectrons->push_back(e); } } - edm::Handle> tausIn; - iEvent.getByToken(taus_, tausIn); + const auto& tausIn = iEvent.get(taus_); auto taus = std::make_unique>(); - for (const auto& t : *tausIn) + taus->reserve(tausIn.size()); + for (const auto& t : tausIn) taus->push_back(t); auto tauRefProd = iEvent.getRefBeforePut>("taus"); - edm::Handle> photonsIn; - iEvent.getByToken(photons_, photonsIn); + const auto& photonsIn = iEvent.get(photons_); auto photons = std::make_unique>(); - for (const auto& p : *photonsIn) + photons->reserve(photonsIn.size()); + for (const auto& p : photonsIn) photons->push_back(p); auto phRefProd = iEvent.getRefBeforePut>("photons"); From 58d8e3cdc02daf5489ce7491f95850b6e806ea4f Mon Sep 17 00:00:00 2001 From: Sebastien Wertz Date: Mon, 31 Oct 2022 16:52:59 +0100 Subject: [PATCH 02/14] add parameter description to PATObjectCrossLinker --- .../PatAlgos/plugins/PATObjectCrossLinker.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc index cd6cc23750e17..c6c4fa994dd61 100644 --- a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc +++ b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc @@ -277,11 +277,15 @@ void PATObjectCrossLinker::endStream() {} // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ void PATObjectCrossLinker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; - desc.setUnknown(); - descriptions.addDefault(desc); + desc.add("jets")->setComment("a jet collection derived from pat::Jet"); + desc.add("muons")->setComment("a muon collection derived from pat::Muon"); + desc.add("electrons")->setComment("an electron collection derived from pat::Electron"); + desc.add("lowPtElectrons") + ->setComment("an optional electron collection derived from pat::Electron, empty=>not used"); + desc.add("taus")->setComment("a tau collection derived from pat::Tau"); + desc.add("photons")->setComment("a photon collection derived from pat::Photon"); + descriptions.add("patObjectCrossLinker", desc); } //define this as a plug-in From 9e902d817b3df54b16b20bbadde523bba78efe7b Mon Sep 17 00:00:00 2001 From: Sebastien Wertz Date: Tue, 22 Nov 2022 13:59:27 +0100 Subject: [PATCH 03/14] add boostedTaus to PATObjectCrossLinker --- PhysicsTools/NanoAOD/python/boostedTaus_cff.py | 2 +- PhysicsTools/NanoAOD/python/nano_cff.py | 1 + .../PatAlgos/plugins/PATObjectCrossLinker.cc | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/PhysicsTools/NanoAOD/python/boostedTaus_cff.py b/PhysicsTools/NanoAOD/python/boostedTaus_cff.py index b5f7b63319f9f..409c028082026 100644 --- a/PhysicsTools/NanoAOD/python/boostedTaus_cff.py +++ b/PhysicsTools/NanoAOD/python/boostedTaus_cff.py @@ -19,7 +19,7 @@ ) boostedTauTable = simpleCandidateFlatTableProducer.clone( - src = cms.InputTag("finalBoostedTaus"), + src = cms.InputTag("linkedObjects", "boostedTaus"), name= cms.string("boostedTau"), doc = cms.string("slimmedBoostedTaus after basic selection (" + finalBoostedTaus.cut.value()+")"), variables = cms.PSet() # PSet defined below in era dependent way diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py index bd46fde7f45b7..9c51e97bb32ca 100644 --- a/PhysicsTools/NanoAOD/python/nano_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -40,6 +40,7 @@ electrons=cms.InputTag("finalElectrons"), lowPtElectrons=cms.InputTag("finalLowPtElectrons"), taus=cms.InputTag("finalTaus"), + boostedTaus=cms.InputTag("finalBoostedTaus"), photons=cms.InputTag("finalPhotons"), ) diff --git a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc index c6c4fa994dd61..04e25047b7231 100644 --- a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc +++ b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc @@ -90,6 +90,7 @@ class PATObjectCrossLinker : public edm::stream::EDProducer<> { edm::InputTag lowPtElectronsTag_; edm::EDGetTokenT> lowPtElectrons_; const edm::EDGetTokenT> taus_; + const edm::EDGetTokenT> boostedTaus_; const edm::EDGetTokenT> photons_; }; @@ -103,6 +104,7 @@ PATObjectCrossLinker::PATObjectCrossLinker(const edm::ParameterSet& params) lowPtElectronsTag_(params.getParameter("lowPtElectrons")), lowPtElectrons_(mayConsume>(lowPtElectronsTag_)), taus_(consumes>(params.getParameter("taus"))), + boostedTaus_(consumes>(params.getParameter("boostedTaus"))), photons_(consumes>(params.getParameter("photons"))) { @@ -112,6 +114,7 @@ PATObjectCrossLinker::PATObjectCrossLinker(const edm::ParameterSet& params) if (!lowPtElectronsTag_.label().empty()) produces>("lowPtElectrons"); produces>("taus"); + produces>("boostedTaus"); produces>("photons"); } @@ -242,6 +245,13 @@ void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iS taus->push_back(t); auto tauRefProd = iEvent.getRefBeforePut>("taus"); + const auto& boostedTausIn = iEvent.get(boostedTaus_); + auto boostedTaus = std::make_unique>(); + boostedTaus->reserve(boostedTausIn.size()); + for (const auto& t : boostedTausIn) + boostedTaus->push_back(t); + auto boostedTauRefProd = iEvent.getRefBeforePut>("boostedTaus"); + const auto& photonsIn = iEvent.get(photons_); auto photons = std::make_unique>(); photons->reserve(photonsIn.size()); @@ -252,6 +262,7 @@ void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iS matchOneToMany(jetRefProd, *jets, "jet", muRefProd, *muons, "muons"); matchOneToMany(jetRefProd, *jets, "jet", eleRefProd, *electrons, "electrons"); matchOneToMany(jetRefProd, *jets, "jet", tauRefProd, *taus, "taus"); + matchOneToMany(jetRefProd, *jets, "jet", boostedTauRefProd, *boostedTaus, "boostedTaus"); matchOneToMany(jetRefProd, *jets, "jet", phRefProd, *photons, "photons"); matchElectronToPhoton(eleRefProd, *electrons, "electron", phRefProd, *photons, "photons"); @@ -266,6 +277,7 @@ void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iS if (!lowPtElectronsTag_.label().empty()) iEvent.put(std::move(lowPtElectrons), "lowPtElectrons"); iEvent.put(std::move(taus), "taus"); + iEvent.put(std::move(boostedTaus), "boostedTaus"); iEvent.put(std::move(photons), "photons"); } @@ -284,6 +296,7 @@ void PATObjectCrossLinker::fillDescriptions(edm::ConfigurationDescriptions& desc desc.add("lowPtElectrons") ->setComment("an optional electron collection derived from pat::Electron, empty=>not used"); desc.add("taus")->setComment("a tau collection derived from pat::Tau"); + desc.add("boostedTaus")->setComment("a boosted tau collection derived from pat::Tau"); desc.add("photons")->setComment("a photon collection derived from pat::Photon"); descriptions.add("patObjectCrossLinker", desc); } From 1560f6daf66c550d8521b3fee8744a0bcc589c56 Mon Sep 17 00:00:00 2001 From: Sebastien Wertz Date: Wed, 23 Nov 2022 12:09:09 +0100 Subject: [PATCH 04/14] add matching between secondary vertices and electrons, muons, jets, taus --- PhysicsTools/NanoAOD/python/electrons_cff.py | 3 +- .../NanoAOD/python/jetsAK4_CHS_cff.py | 3 + .../NanoAOD/python/jetsAK4_Puppi_cff.py | 3 + PhysicsTools/NanoAOD/python/muons_cff.py | 1 + PhysicsTools/NanoAOD/python/nano_cff.py | 1 + PhysicsTools/NanoAOD/python/taus_cff.py | 3 + PhysicsTools/NanoAOD/python/vertices_cff.py | 4 +- .../PatAlgos/plugins/PATObjectCrossLinker.cc | 72 ++++++++++++++++++- 8 files changed, 86 insertions(+), 4 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/electrons_cff.py b/PhysicsTools/NanoAOD/python/electrons_cff.py index 71907cd8d1270..6e902d74a2a0f 100644 --- a/PhysicsTools/NanoAOD/python/electrons_cff.py +++ b/PhysicsTools/NanoAOD/python/electrons_cff.py @@ -280,7 +280,8 @@ def _get_bitmapVIDForEle_docstring(modules,WorkingPoints): doc = cms.string("slimmedElectrons after basic selection (" + finalElectrons.cut.value()+")"), variables = cms.PSet(CandVars, jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"), - photonIdx = Var("?overlaps('photons').size()>0?overlaps('photons')[0].key():-1", int, doc="index of the associated photon (-1 if none)"), + photonIdx = Var("?overlaps('photons').size()>0?overlaps('photons')[0].key():-1", int, doc="index of the first associated photon (-1 if none)"), + svIdx = Var("?hasUserCand('vertex')?userCand('vertex').key():-1", int, doc="index of matching secondary vertex"), energyErr = Var("p4Error('P4_COMBINATION')",float,doc="energy error of the cluster-track combination",precision=6), dz = Var("dB('PVDZ')",float,doc="dz (with sign) wrt first PV, in cm",precision=10), dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6), diff --git a/PhysicsTools/NanoAOD/python/jetsAK4_CHS_cff.py b/PhysicsTools/NanoAOD/python/jetsAK4_CHS_cff.py index 20ef3e0646d10..6c2dd9195438b 100644 --- a/PhysicsTools/NanoAOD/python/jetsAK4_CHS_cff.py +++ b/PhysicsTools/NanoAOD/python/jetsAK4_CHS_cff.py @@ -119,6 +119,9 @@ electronIdx1 = Var("?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1", int, doc="index of first matching electron"), electronIdx2 = Var("?overlaps('electrons').size()>1?overlaps('electrons')[1].key():-1", int, doc="index of second matching electron"), nElectrons = Var("?hasOverlaps('electrons')?overlaps('electrons').size():0", int, doc="number of electrons in the jet"), + svIdx1 = Var("?overlaps('vertices').size()>0?overlaps('vertices')[0].key():-1", int, doc="index of first matching secondary vertex"), + svIdx2 = Var("?overlaps('vertices').size()>1?overlaps('vertices')[1].key():-1", int, doc="index of second matching secondary vertex"), + nSVs = Var("?hasOverlaps('vertices')?overlaps('vertices').size():0", int, doc="number of secondary vertices in the jet"), btagDeepB = Var("?(bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb'))>=0?bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb'):-1",float,doc="DeepCSV b+bb tag discriminator",precision=10), btagDeepFlavB = Var("bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')",float,doc="DeepJet b+bb+lepb tag discriminator",precision=10), btagCSVV2 = Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10), diff --git a/PhysicsTools/NanoAOD/python/jetsAK4_Puppi_cff.py b/PhysicsTools/NanoAOD/python/jetsAK4_Puppi_cff.py index d5b6739c94838..41dce3c9a7c36 100644 --- a/PhysicsTools/NanoAOD/python/jetsAK4_Puppi_cff.py +++ b/PhysicsTools/NanoAOD/python/jetsAK4_Puppi_cff.py @@ -77,6 +77,9 @@ electronIdx1 = Var("?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1", int, doc="index of first matching electron"), electronIdx2 = Var("?overlaps('electrons').size()>1?overlaps('electrons')[1].key():-1", int, doc="index of second matching electron"), nElectrons = Var("?hasOverlaps('electrons')?overlaps('electrons').size():0", int, doc="number of electrons in the jet"), + svIdx1 = Var("?overlaps('vertices').size()>0?overlaps('vertices')[0].key():-1", int, doc="index of first matching secondary vertex"), + svIdx2 = Var("?overlaps('vertices').size()>1?overlaps('vertices')[1].key():-1", int, doc="index of second matching secondary vertex"), + nSVs = Var("?hasOverlaps('vertices')?overlaps('vertices').size():0", int, doc="number of secondary vertices in the jet"), btagDeepB = Var("?(bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb'))>=0?bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb'):-1",float,doc="DeepCSV b+bb tag discriminator",precision=10), btagDeepFlavB = Var("bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')",float,doc="DeepJet b+bb+lepb tag discriminator",precision=10), btagCSVV2 = Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10), diff --git a/PhysicsTools/NanoAOD/python/muons_cff.py b/PhysicsTools/NanoAOD/python/muons_cff.py index 2938cf8308bdd..28ae0184feeac 100644 --- a/PhysicsTools/NanoAOD/python/muons_cff.py +++ b/PhysicsTools/NanoAOD/python/muons_cff.py @@ -138,6 +138,7 @@ nTrackerLayers = Var("?track.isNonnull?innerTrack().hitPattern().trackerLayersWithMeasurement():0", int, doc = "number of layers in the tracker"), highPurity = Var("?track.isNonnull?innerTrack().quality('highPurity'):0", bool, doc = "inner track is high purity"), jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"), + svIdx = Var("?hasUserCand('vertex')?userCand('vertex').key():-1", int, doc="index of matching secondary vertex"), tkRelIso = Var("isolationR03().sumPt/tunePMuonBestTrack().pt",float,doc="Tracker-based relative isolation dR=0.3 for highPt, trkIso/tunePpt",precision=6), miniPFRelIso_chg = Var("userFloat('miniIsoChg')/pt",float,doc="mini PF relative isolation, charged component"), miniPFRelIso_all = Var("userFloat('miniIsoAll')/pt",float,doc="mini PF relative isolation, total (with scaled rho*EA PU corrections)"), diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py index 9c51e97bb32ca..5ef42977531c7 100644 --- a/PhysicsTools/NanoAOD/python/nano_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -42,6 +42,7 @@ taus=cms.InputTag("finalTaus"), boostedTaus=cms.InputTag("finalBoostedTaus"), photons=cms.InputTag("finalPhotons"), + vertices=cms.InputTag("slimmedSecondaryVertices") ) # Switch to AK4 CHS jets for Run-2 diff --git a/PhysicsTools/NanoAOD/python/taus_cff.py b/PhysicsTools/NanoAOD/python/taus_cff.py index 624873b418631..4be415027f799 100644 --- a/PhysicsTools/NanoAOD/python/taus_cff.py +++ b/PhysicsTools/NanoAOD/python/taus_cff.py @@ -54,6 +54,9 @@ def _tauIdWPMask(pattern, choices, doc="", from_raw=False, wp_thrs=None): _tauVarsBase = cms.PSet(P4Vars, charge = Var("charge", int, doc="electric charge"), jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"), + svIdx1 = Var("?overlaps('vertices').size()>0?overlaps('vertices')[0].key():-1", int, doc="index of first matching secondary vertex"), + svIdx2 = Var("?overlaps('vertices').size()>1?overlaps('vertices')[1].key():-1", int, doc="index of second matching secondary vertex"), + nSVs = Var("?hasOverlaps('vertices')?overlaps('vertices').size():0", int, doc="number of secondary vertices in the tau"), decayMode = Var("decayMode()",int), idDecayModeOldDMs = Var("tauID('decayModeFinding')", bool), diff --git a/PhysicsTools/NanoAOD/python/vertices_cff.py b/PhysicsTools/NanoAOD/python/vertices_cff.py index 4870fe5a70337..ddda0ba422c1e 100644 --- a/PhysicsTools/NanoAOD/python/vertices_cff.py +++ b/PhysicsTools/NanoAOD/python/vertices_cff.py @@ -10,8 +10,8 @@ vertexTable = cms.EDProducer("VertexTableProducer", pvSrc = cms.InputTag("offlineSlimmedPrimaryVertices"), goodPvCut = cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"), - svSrc = cms.InputTag("slimmedSecondaryVertices"), - svCut = cms.string(""), + svSrc = cms.InputTag("linkedObjects", "vertices"), + svCut = cms.string(""), # careful: adding a cut here would make the collection matching inconsistent with the SV table dlenMin = cms.double(0), dlenSigMin = cms.double(3), pvName = cms.string("PV"), diff --git a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc index 04e25047b7231..368d57bf1e3fb 100644 --- a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc +++ b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc @@ -34,6 +34,7 @@ #include "DataFormats/PatCandidates/interface/Electron.h" #include "DataFormats/PatCandidates/interface/Photon.h" #include "DataFormats/PatCandidates/interface/Tau.h" +#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h" #include "DataFormats/Common/interface/View.h" @@ -78,6 +79,18 @@ class PATObjectCrossLinker : public edm::stream::EDProducer<> { C4& itemsMany, const std::string& nameMany); + template + void matchOneToVertices(C1& itemsOne, + const C2& refProdVtx, + C3& itemsVtx, + const std::string& nameVtx); + + template + void matchVertexToMany(const C1& refProdVtx, + C2& itemsVtx, + const std::string& nameVtx, + C3& itemsMany); + //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; @@ -92,6 +105,7 @@ class PATObjectCrossLinker : public edm::stream::EDProducer<> { const edm::EDGetTokenT> taus_; const edm::EDGetTokenT> boostedTaus_; const edm::EDGetTokenT> photons_; + const edm::EDGetTokenT> vertices_; }; // @@ -105,7 +119,8 @@ PATObjectCrossLinker::PATObjectCrossLinker(const edm::ParameterSet& params) lowPtElectrons_(mayConsume>(lowPtElectronsTag_)), taus_(consumes>(params.getParameter("taus"))), boostedTaus_(consumes>(params.getParameter("boostedTaus"))), - photons_(consumes>(params.getParameter("photons"))) + photons_(consumes>(params.getParameter("photons"))), + vertices_(consumes>(params.getParameter("vertices"))) { produces>("jets"); @@ -116,6 +131,7 @@ PATObjectCrossLinker::PATObjectCrossLinker(const edm::ParameterSet& params) produces>("taus"); produces>("boostedTaus"); produces>("photons"); + produces>("vertices"); } PATObjectCrossLinker::~PATObjectCrossLinker() { @@ -153,6 +169,7 @@ void PATObjectCrossLinker::matchOneToMany(const C1& refProdOne, } } +// one electron can be matched to several photons template void PATObjectCrossLinker::matchElectronToPhoton(const C1& refProdOne, C2& itemsOne, @@ -176,6 +193,7 @@ void PATObjectCrossLinker::matchElectronToPhoton(const C1& refProdOne, } } +// one low pt electron can be matched to several electrons template void PATObjectCrossLinker::matchLowPtToElectron(const C1& refProdOne, C2& itemsOne, @@ -206,6 +224,44 @@ void PATObjectCrossLinker::matchLowPtToElectron(const C1& refProdOne, } } +// several vertices stored as overlap with a jet +// (reco vertices have no userCands) +template +void PATObjectCrossLinker::matchOneToVertices(C1& itemsOne, + const C2& refProdVtx, + C3& itemsVtx, + const std::string& nameVtx) { + for (auto& j : itemsOne) { + edm::PtrVector overlaps(refProdVtx.id()); + size_t vi = 0; + for (auto& v : itemsVtx) { + if (matchByCommonSourceCandidatePtr(j, v)) { + overlaps.push_back(reco::CandidatePtr(refProdVtx.id(), vi, refProdVtx.productGetter())); + } + vi++; + } + j.setOverlaps(nameVtx, overlaps); + } +} + +// vertex stored as userCand to matched object +// (reco vertices have no overlaps) +template +void PATObjectCrossLinker::matchVertexToMany(const C1& refProdVtx, + C2& itemsVtx, + const std::string& nameVtx, + C3& itemsMany) { + size_t vi = 0; + for (auto& v : itemsVtx) { + for (auto& m : itemsMany) { + if (matchByCommonSourceCandidatePtr(v, m) && (!m.hasUserCand(nameVtx))) { + m.addUserCand(nameVtx, reco::CandidatePtr(refProdVtx.id(), vi, refProdVtx.productGetter())); + } + } + vi++; + } +} + void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { using namespace edm; const auto& jetsIn = iEvent.get(jets_); @@ -259,6 +315,13 @@ void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iS photons->push_back(p); auto phRefProd = iEvent.getRefBeforePut>("photons"); + const auto& verticesIn = iEvent.get(vertices_); + auto vertices = std::make_unique>(); + vertices->reserve(verticesIn.size()); + for (const auto& v : verticesIn) + vertices->push_back(v); + auto vtxRefProd = iEvent.getRefBeforePut>("vertices"); + matchOneToMany(jetRefProd, *jets, "jet", muRefProd, *muons, "muons"); matchOneToMany(jetRefProd, *jets, "jet", eleRefProd, *electrons, "electrons"); matchOneToMany(jetRefProd, *jets, "jet", tauRefProd, *taus, "taus"); @@ -271,6 +334,11 @@ void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iS matchLowPtToElectron(lowPtEleRefProd, *lowPtElectrons, "lowPtElectron", eleRefProd, *electrons, "electrons"); } + matchOneToVertices(*jets, vtxRefProd, *vertices, "vertices"); + matchOneToVertices(*taus, vtxRefProd, *vertices, "vertices"); + matchVertexToMany(vtxRefProd, *vertices, "vertex", *muons); + matchVertexToMany(vtxRefProd, *vertices, "vertex", *electrons); + iEvent.put(std::move(jets), "jets"); iEvent.put(std::move(muons), "muons"); iEvent.put(std::move(electrons), "electrons"); @@ -279,6 +347,7 @@ void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iS iEvent.put(std::move(taus), "taus"); iEvent.put(std::move(boostedTaus), "boostedTaus"); iEvent.put(std::move(photons), "photons"); + iEvent.put(std::move(vertices), "vertices"); } // ------------ method called once each stream before processing any runs, lumis or events ------------ @@ -298,6 +367,7 @@ void PATObjectCrossLinker::fillDescriptions(edm::ConfigurationDescriptions& desc desc.add("taus")->setComment("a tau collection derived from pat::Tau"); desc.add("boostedTaus")->setComment("a boosted tau collection derived from pat::Tau"); desc.add("photons")->setComment("a photon collection derived from pat::Photon"); + desc.add("vertices")->setComment("a vertex collection derived from reco::VertexCompositePtrCandidate"); descriptions.add("patObjectCrossLinker", desc); } From 345ecd8fc19c6c62acf7fa83781dc5ba752dce04 Mon Sep 17 00:00:00 2001 From: Sebastien Wertz Date: Wed, 23 Nov 2022 13:21:53 +0100 Subject: [PATCH 05/14] add index of matching photon and jet to lowPtElectron --- PhysicsTools/NanoAOD/python/lowPtElectrons_cff.py | 5 ++--- PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/lowPtElectrons_cff.py b/PhysicsTools/NanoAOD/python/lowPtElectrons_cff.py index 5539d7c7e60a3..ef3868c63058c 100644 --- a/PhysicsTools/NanoAOD/python/lowPtElectrons_cff.py +++ b/PhysicsTools/NanoAOD/python/lowPtElectrons_cff.py @@ -69,6 +69,8 @@ CandVars, # Overlaps with PF electron electronIdx = Var("?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1", int, doc="index of the overlapping PF electron (-1 if none)"), + jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"), + photonIdx = Var("?overlaps('photons').size()>0?overlaps('photons')[0].key():-1", int, doc="index of the first associated photon (-1 if none)"), # BDT scores and WPs ID = Var("electronID('ID')",float,doc="ID, BDT (raw) score"), unbiased = Var("electronID('unbiased')",float,doc="ElectronSeed, pT- and dxy- agnostic BDT (raw) score"), @@ -98,9 +100,6 @@ dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6), dz = Var("dB('PVDZ')",float,doc="dz (with sign) wrt first PV, in cm",precision=10), dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6), - # Cross-referencing - #jetIdx - #photonIdx ), ) diff --git a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc index 368d57bf1e3fb..9197a9602f46d 100644 --- a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc +++ b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc @@ -329,9 +329,12 @@ void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iS matchOneToMany(jetRefProd, *jets, "jet", phRefProd, *photons, "photons"); matchElectronToPhoton(eleRefProd, *electrons, "electron", phRefProd, *photons, "photons"); + if (!lowPtElectronsTag_.label().empty()) { auto lowPtEleRefProd = iEvent.getRefBeforePut>("lowPtElectrons"); matchLowPtToElectron(lowPtEleRefProd, *lowPtElectrons, "lowPtElectron", eleRefProd, *electrons, "electrons"); + matchOneToMany(jetRefProd, *jets, "jet", lowPtEleRefProd, *lowPtElectrons, "lowPtElectrons"); + matchElectronToPhoton(lowPtEleRefProd, *lowPtElectrons, "lowPtElectron", phRefProd, *photons, "photons"); } matchOneToVertices(*jets, vtxRefProd, *vertices, "vertices"); From f0eec96de5ba0d99503c4e56efd7828e1d80e0fe Mon Sep 17 00:00:00 2001 From: Sebastien Wertz Date: Fri, 25 Nov 2022 16:49:16 +0100 Subject: [PATCH 06/14] add indices of muon and electron matched to tau --- PhysicsTools/NanoAOD/python/taus_cff.py | 2 ++ PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc | 3 +++ 2 files changed, 5 insertions(+) diff --git a/PhysicsTools/NanoAOD/python/taus_cff.py b/PhysicsTools/NanoAOD/python/taus_cff.py index 4be415027f799..b78b58c49e3ec 100644 --- a/PhysicsTools/NanoAOD/python/taus_cff.py +++ b/PhysicsTools/NanoAOD/python/taus_cff.py @@ -54,6 +54,8 @@ def _tauIdWPMask(pattern, choices, doc="", from_raw=False, wp_thrs=None): _tauVarsBase = cms.PSet(P4Vars, charge = Var("charge", int, doc="electric charge"), jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"), + eleIdx = Var("?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1", int, doc="index of first matching electron"), + muIdx = Var("?overlaps('muons').size()>0?overlaps('muons')[0].key():-1", int, doc="index of first matching muon"), svIdx1 = Var("?overlaps('vertices').size()>0?overlaps('vertices')[0].key():-1", int, doc="index of first matching secondary vertex"), svIdx2 = Var("?overlaps('vertices').size()>1?overlaps('vertices')[1].key():-1", int, doc="index of second matching secondary vertex"), nSVs = Var("?hasOverlaps('vertices')?overlaps('vertices').size():0", int, doc="number of secondary vertices in the tau"), diff --git a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc index 9197a9602f46d..e71ffc2feab2d 100644 --- a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc +++ b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc @@ -328,6 +328,9 @@ void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iS matchOneToMany(jetRefProd, *jets, "jet", boostedTauRefProd, *boostedTaus, "boostedTaus"); matchOneToMany(jetRefProd, *jets, "jet", phRefProd, *photons, "photons"); + matchOneToMany(tauRefProd, *taus, "tau", muRefProd, *muons, "muons"); + matchOneToMany(tauRefProd, *taus, "tau", eleRefProd, *electrons, "electrons"); + matchElectronToPhoton(eleRefProd, *electrons, "electron", phRefProd, *photons, "photons"); if (!lowPtElectronsTag_.label().empty()) { From 8fc6ff13ab69e0dc019e4c5c78fa648d260082b4 Mon Sep 17 00:00:00 2001 From: Sebastien Wertz Date: Fri, 25 Nov 2022 16:50:09 +0100 Subject: [PATCH 07/14] remove clean mask from default nanoAODs - use indices from matching instead --- PhysicsTools/NanoAOD/python/nano_cff.py | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py index 5ef42977531c7..7d2298e6d84fd 100644 --- a/PhysicsTools/NanoAOD/python/nano_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -50,27 +50,6 @@ linkedObjects, jets="finalJets" ) -simpleCleanerTable = cms.EDProducer("NanoAODSimpleCrossCleaner", - name=cms.string("cleanmask"), - doc=cms.string("simple cleaning mask with priority to leptons"), - jets=cms.InputTag("linkedObjects","jets"), - muons=cms.InputTag("linkedObjects","muons"), - electrons=cms.InputTag("linkedObjects","electrons"), - lowPtElectrons=cms.InputTag("linkedObjects","lowPtElectrons"), - taus=cms.InputTag("linkedObjects","taus"), - photons=cms.InputTag("linkedObjects","photons"), - jetSel=cms.string("pt>15"), - muonSel=cms.string("track.isNonnull && isLooseMuon && isPFMuon && innerTrack.validFraction >= 0.49 && ( isGlobalMuon && globalTrack.normalizedChi2 < 3 && combinedQuality.chi2LocalPosition < 12 && combinedQuality.trkKink < 20 && segmentCompatibility >= 0.303 || segmentCompatibility >= 0.451 )"), - electronSel=cms.string(""), - lowPtElectronSel=cms.string(""), - tauSel=cms.string(""), - photonSel=cms.string(""), - jetName=cms.string("Jet"),muonName=cms.string("Muon"),electronName=cms.string("Electron"), - lowPtElectronName=cms.string("LowPtElectron"), - tauName=cms.string("Tau"),photonName=cms.string("Photon") -) - - lhcInfoTable = cms.EDProducer("LHCInfoProducer") nanoTableTaskCommon = cms.Task( @@ -84,7 +63,7 @@ jetPuppiTablesTask, jetAK8TablesTask, muonTablesTask, fsrTablesTask, tauTablesTask, boostedTauTablesTask, electronTablesTask, lowPtElectronTablesTask, photonTablesTask, - globalTablesTask, vertexTablesTask, metTablesTask, simpleCleanerTable, extraFlagsTableTask, + globalTablesTask, vertexTablesTask, metTablesTask, extraFlagsTableTask, isoTrackTablesTask,softActivityTablesTask ) From 1048cfe90b2430f1211d1417b26a6931e5df2e6a Mon Sep 17 00:00:00 2001 From: Sebastien Wertz Date: Fri, 25 Nov 2022 17:33:16 +0100 Subject: [PATCH 08/14] make matching with boostedTaus and vertices optional for nanoV10 backwards compatibility --- .../PatAlgos/plugins/PATObjectCrossLinker.cc | 108 ++++++++++-------- 1 file changed, 63 insertions(+), 45 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc index e71ffc2feab2d..5daab4f9404a7 100644 --- a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc +++ b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc @@ -100,12 +100,14 @@ class PATObjectCrossLinker : public edm::stream::EDProducer<> { const edm::EDGetTokenT> jets_; const edm::EDGetTokenT> muons_; const edm::EDGetTokenT> electrons_; + const edm::EDGetTokenT> photons_; + const edm::EDGetTokenT> taus_; edm::InputTag lowPtElectronsTag_; edm::EDGetTokenT> lowPtElectrons_; - const edm::EDGetTokenT> taus_; - const edm::EDGetTokenT> boostedTaus_; - const edm::EDGetTokenT> photons_; - const edm::EDGetTokenT> vertices_; + edm::InputTag boostedTausTag_; + edm::EDGetTokenT> boostedTaus_; + edm::InputTag verticesTag_; + edm::EDGetTokenT> vertices_; }; // @@ -115,23 +117,26 @@ PATObjectCrossLinker::PATObjectCrossLinker(const edm::ParameterSet& params) : jets_(consumes>(params.getParameter("jets"))), muons_(consumes>(params.getParameter("muons"))), electrons_(consumes>(params.getParameter("electrons"))), + photons_(consumes>(params.getParameter("photons"))), + taus_(consumes>(params.getParameter("taus"))), lowPtElectronsTag_(params.getParameter("lowPtElectrons")), lowPtElectrons_(mayConsume>(lowPtElectronsTag_)), - taus_(consumes>(params.getParameter("taus"))), - boostedTaus_(consumes>(params.getParameter("boostedTaus"))), - photons_(consumes>(params.getParameter("photons"))), - vertices_(consumes>(params.getParameter("vertices"))) - + boostedTausTag_(params.getParameter("boostedTaus")), + boostedTaus_(mayConsume>(boostedTausTag_)), + verticesTag_(params.getParameter("vertices")), + vertices_(mayConsume>(verticesTag_)) { produces>("jets"); produces>("muons"); produces>("electrons"); + produces>("photons"); + produces>("taus"); if (!lowPtElectronsTag_.label().empty()) produces>("lowPtElectrons"); - produces>("taus"); - produces>("boostedTaus"); - produces>("photons"); - produces>("vertices"); + if (!boostedTausTag_.label().empty()) + produces>("boostedTaus"); + if (!verticesTag_.label().empty()) + produces>("vertices"); } PATObjectCrossLinker::~PATObjectCrossLinker() { @@ -285,15 +290,6 @@ void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iS electrons->push_back(e); auto eleRefProd = iEvent.getRefBeforePut>("electrons"); - auto lowPtElectrons = std::make_unique>(); - if (!lowPtElectronsTag_.label().empty()) { - auto lowPtElectronsIn = iEvent.getHandle(lowPtElectrons_); - lowPtElectrons->reserve(lowPtElectronsIn->size()); - for (const auto& e : *lowPtElectronsIn) { - lowPtElectrons->push_back(e); - } - } - const auto& tausIn = iEvent.get(taus_); auto taus = std::make_unique>(); taus->reserve(tausIn.size()); @@ -301,13 +297,6 @@ void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iS taus->push_back(t); auto tauRefProd = iEvent.getRefBeforePut>("taus"); - const auto& boostedTausIn = iEvent.get(boostedTaus_); - auto boostedTaus = std::make_unique>(); - boostedTaus->reserve(boostedTausIn.size()); - for (const auto& t : boostedTausIn) - boostedTaus->push_back(t); - auto boostedTauRefProd = iEvent.getRefBeforePut>("boostedTaus"); - const auto& photonsIn = iEvent.get(photons_); auto photons = std::make_unique>(); photons->reserve(photonsIn.size()); @@ -315,17 +304,36 @@ void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iS photons->push_back(p); auto phRefProd = iEvent.getRefBeforePut>("photons"); - const auto& verticesIn = iEvent.get(vertices_); + auto lowPtElectrons = std::make_unique>(); + if (!lowPtElectronsTag_.label().empty()) { + auto lowPtElectronsIn = iEvent.getHandle(lowPtElectrons_); + lowPtElectrons->reserve(lowPtElectronsIn->size()); + for (const auto& e : *lowPtElectronsIn) { + lowPtElectrons->push_back(e); + } + } + + auto boostedTaus = std::make_unique>(); + if (!boostedTausTag_.label().empty()) { + auto boostedTausIn = iEvent.getHandle(boostedTaus_); + boostedTaus->reserve(boostedTausIn->size()); + for (const auto& e : *boostedTausIn) { + boostedTaus->push_back(e); + } + } + auto vertices = std::make_unique>(); - vertices->reserve(verticesIn.size()); - for (const auto& v : verticesIn) - vertices->push_back(v); - auto vtxRefProd = iEvent.getRefBeforePut>("vertices"); + if (!verticesTag_.label().empty()) { + auto verticesIn = iEvent.getHandle(vertices_); + vertices->reserve(verticesIn->size()); + for (const auto& e : *verticesIn) { + vertices->push_back(e); + } + } matchOneToMany(jetRefProd, *jets, "jet", muRefProd, *muons, "muons"); matchOneToMany(jetRefProd, *jets, "jet", eleRefProd, *electrons, "electrons"); matchOneToMany(jetRefProd, *jets, "jet", tauRefProd, *taus, "taus"); - matchOneToMany(jetRefProd, *jets, "jet", boostedTauRefProd, *boostedTaus, "boostedTaus"); matchOneToMany(jetRefProd, *jets, "jet", phRefProd, *photons, "photons"); matchOneToMany(tauRefProd, *taus, "tau", muRefProd, *muons, "muons"); @@ -340,20 +348,30 @@ void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iS matchElectronToPhoton(lowPtEleRefProd, *lowPtElectrons, "lowPtElectron", phRefProd, *photons, "photons"); } - matchOneToVertices(*jets, vtxRefProd, *vertices, "vertices"); - matchOneToVertices(*taus, vtxRefProd, *vertices, "vertices"); - matchVertexToMany(vtxRefProd, *vertices, "vertex", *muons); - matchVertexToMany(vtxRefProd, *vertices, "vertex", *electrons); + if (!boostedTausTag_.label().empty()) { + auto boostedTauRefProd = iEvent.getRefBeforePut>("boostedTaus"); + matchOneToMany(jetRefProd, *jets, "jet", boostedTauRefProd, *boostedTaus, "boostedTaus"); + } + + if (!verticesTag_.label().empty()) { + auto vtxRefProd = iEvent.getRefBeforePut>("vertices"); + matchOneToVertices(*jets, vtxRefProd, *vertices, "vertices"); + matchOneToVertices(*taus, vtxRefProd, *vertices, "vertices"); + matchVertexToMany(vtxRefProd, *vertices, "vertex", *muons); + matchVertexToMany(vtxRefProd, *vertices, "vertex", *electrons); + } iEvent.put(std::move(jets), "jets"); iEvent.put(std::move(muons), "muons"); iEvent.put(std::move(electrons), "electrons"); - if (!lowPtElectronsTag_.label().empty()) - iEvent.put(std::move(lowPtElectrons), "lowPtElectrons"); iEvent.put(std::move(taus), "taus"); - iEvent.put(std::move(boostedTaus), "boostedTaus"); iEvent.put(std::move(photons), "photons"); - iEvent.put(std::move(vertices), "vertices"); + if (!lowPtElectronsTag_.label().empty()) + iEvent.put(std::move(lowPtElectrons), "lowPtElectrons"); + if (!boostedTausTag_.label().empty()) + iEvent.put(std::move(boostedTaus), "boostedTaus"); + if (!verticesTag_.label().empty()) + iEvent.put(std::move(vertices), "vertices"); } // ------------ method called once each stream before processing any runs, lumis or events ------------ @@ -371,9 +389,9 @@ void PATObjectCrossLinker::fillDescriptions(edm::ConfigurationDescriptions& desc desc.add("lowPtElectrons") ->setComment("an optional electron collection derived from pat::Electron, empty=>not used"); desc.add("taus")->setComment("a tau collection derived from pat::Tau"); - desc.add("boostedTaus")->setComment("a boosted tau collection derived from pat::Tau"); + desc.add("boostedTaus")->setComment("a boosted tau collection derived from pat::Tau, empty=>not used"); desc.add("photons")->setComment("a photon collection derived from pat::Photon"); - desc.add("vertices")->setComment("a vertex collection derived from reco::VertexCompositePtrCandidate"); + desc.add("vertices")->setComment("a vertex collection derived from reco::VertexCompositePtrCandidate, empty=>not used"); descriptions.add("patObjectCrossLinker", desc); } From a2016a73bfa0ebcf6429e802d04df972ede29bd0 Mon Sep 17 00:00:00 2001 From: Sebastien Wertz Date: Sun, 27 Nov 2022 21:13:13 +0100 Subject: [PATCH 09/14] code format --- .../PatAlgos/plugins/PATObjectCrossLinker.cc | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc index 5daab4f9404a7..fcba0ea345a6b 100644 --- a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc +++ b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc @@ -80,16 +80,10 @@ class PATObjectCrossLinker : public edm::stream::EDProducer<> { const std::string& nameMany); template - void matchOneToVertices(C1& itemsOne, - const C2& refProdVtx, - C3& itemsVtx, - const std::string& nameVtx); + void matchOneToVertices(C1& itemsOne, const C2& refProdVtx, C3& itemsVtx, const std::string& nameVtx); template - void matchVertexToMany(const C1& refProdVtx, - C2& itemsVtx, - const std::string& nameVtx, - C3& itemsMany); + void matchVertexToMany(const C1& refProdVtx, C2& itemsVtx, const std::string& nameVtx, C3& itemsMany); //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; @@ -124,8 +118,7 @@ PATObjectCrossLinker::PATObjectCrossLinker(const edm::ParameterSet& params) boostedTausTag_(params.getParameter("boostedTaus")), boostedTaus_(mayConsume>(boostedTausTag_)), verticesTag_(params.getParameter("vertices")), - vertices_(mayConsume>(verticesTag_)) -{ + vertices_(mayConsume>(verticesTag_)) { produces>("jets"); produces>("muons"); produces>("electrons"); @@ -233,9 +226,9 @@ void PATObjectCrossLinker::matchLowPtToElectron(const C1& refProdOne, // (reco vertices have no userCands) template void PATObjectCrossLinker::matchOneToVertices(C1& itemsOne, - const C2& refProdVtx, - C3& itemsVtx, - const std::string& nameVtx) { + const C2& refProdVtx, + C3& itemsVtx, + const std::string& nameVtx) { for (auto& j : itemsOne) { edm::PtrVector overlaps(refProdVtx.id()); size_t vi = 0; @@ -253,9 +246,9 @@ void PATObjectCrossLinker::matchOneToVertices(C1& itemsOne, // (reco vertices have no overlaps) template void PATObjectCrossLinker::matchVertexToMany(const C1& refProdVtx, - C2& itemsVtx, - const std::string& nameVtx, - C3& itemsMany) { + C2& itemsVtx, + const std::string& nameVtx, + C3& itemsMany) { size_t vi = 0; for (auto& v : itemsVtx) { for (auto& m : itemsMany) { @@ -391,7 +384,8 @@ void PATObjectCrossLinker::fillDescriptions(edm::ConfigurationDescriptions& desc desc.add("taus")->setComment("a tau collection derived from pat::Tau"); desc.add("boostedTaus")->setComment("a boosted tau collection derived from pat::Tau, empty=>not used"); desc.add("photons")->setComment("a photon collection derived from pat::Photon"); - desc.add("vertices")->setComment("a vertex collection derived from reco::VertexCompositePtrCandidate, empty=>not used"); + desc.add("vertices") + ->setComment("a vertex collection derived from reco::VertexCompositePtrCandidate, empty=>not used"); descriptions.add("patObjectCrossLinker", desc); } From 3d4a0ae2cf89a088adaae56191be1c859afa657d Mon Sep 17 00:00:00 2001 From: Sebastien Wertz Date: Mon, 28 Nov 2022 09:32:05 +0100 Subject: [PATCH 10/14] fix for V10 frozen config --- .../PatAlgos/plugins/PATObjectCrossLinker.cc | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc index fcba0ea345a6b..2ce2523a9481c 100644 --- a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc +++ b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc @@ -114,22 +114,25 @@ PATObjectCrossLinker::PATObjectCrossLinker(const edm::ParameterSet& params) photons_(consumes>(params.getParameter("photons"))), taus_(consumes>(params.getParameter("taus"))), lowPtElectronsTag_(params.getParameter("lowPtElectrons")), - lowPtElectrons_(mayConsume>(lowPtElectronsTag_)), boostedTausTag_(params.getParameter("boostedTaus")), - boostedTaus_(mayConsume>(boostedTausTag_)), - verticesTag_(params.getParameter("vertices")), - vertices_(mayConsume>(verticesTag_)) { + verticesTag_(params.getParameter("vertices")) { produces>("jets"); produces>("muons"); produces>("electrons"); produces>("photons"); produces>("taus"); - if (!lowPtElectronsTag_.label().empty()) + if (!lowPtElectronsTag_.label().empty()) { + lowPtElectrons_ = consumes>(lowPtElectronsTag_), produces>("lowPtElectrons"); - if (!boostedTausTag_.label().empty()) + } + if (!boostedTausTag_.label().empty()) { + boostedTaus_ = consumes>(boostedTausTag_); produces>("boostedTaus"); - if (!verticesTag_.label().empty()) + } + if (!verticesTag_.label().empty()) { + vertices_ = consumes>(verticesTag_); produces>("vertices"); + } } PATObjectCrossLinker::~PATObjectCrossLinker() { @@ -379,13 +382,14 @@ void PATObjectCrossLinker::fillDescriptions(edm::ConfigurationDescriptions& desc desc.add("jets")->setComment("a jet collection derived from pat::Jet"); desc.add("muons")->setComment("a muon collection derived from pat::Muon"); desc.add("electrons")->setComment("an electron collection derived from pat::Electron"); - desc.add("lowPtElectrons") - ->setComment("an optional electron collection derived from pat::Electron, empty=>not used"); - desc.add("taus")->setComment("a tau collection derived from pat::Tau"); - desc.add("boostedTaus")->setComment("a boosted tau collection derived from pat::Tau, empty=>not used"); desc.add("photons")->setComment("a photon collection derived from pat::Photon"); - desc.add("vertices") - ->setComment("a vertex collection derived from reco::VertexCompositePtrCandidate, empty=>not used"); + desc.add("taus")->setComment("a tau collection derived from pat::Tau"); + desc.add("lowPtElectrons", edm::InputTag("")) + ->setComment("an optional electron collection derived from pat::Electron, empty=>not used"); + desc.add("boostedTaus", edm::InputTag("")) + ->setComment("an optional boosted tau collection derived from pat::Tau, empty=>not used"); + desc.add("vertices", edm::InputTag("")) + ->setComment("an optional vertex collection derived from reco::VertexCompositePtrCandidate,empty=>not used"); descriptions.add("patObjectCrossLinker", desc); } From 94744662bf83f18934843390edb9fb170e88acd8 Mon Sep 17 00:00:00 2001 From: Sebastien Wertz Date: Mon, 28 Nov 2022 14:41:33 +0100 Subject: [PATCH 11/14] fix 122X input, boostedTaus don't exist --- PhysicsTools/NanoAOD/python/nano_cff.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py index 7d2298e6d84fd..4e9965a19b938 100644 --- a/PhysicsTools/NanoAOD/python/nano_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -50,6 +50,11 @@ linkedObjects, jets="finalJets" ) +# boosted taus don't exist in 122X MINI +run3_nanoAOD_122.toModify( + linkedObjects, boostedTaus=None, +) + lhcInfoTable = cms.EDProducer("LHCInfoProducer") nanoTableTaskCommon = cms.Task( From cb850af449fe100a35db11cbf15f4f57bdc63ce8 Mon Sep 17 00:00:00 2001 From: Sebastien Wertz Date: Tue, 29 Nov 2022 08:45:22 +0100 Subject: [PATCH 12/14] remove matching between lowPtElectrons and jets - didn't work because lowPtElectrons are not PF --- PhysicsTools/NanoAOD/python/lowPtElectrons_cff.py | 3 +-- PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/lowPtElectrons_cff.py b/PhysicsTools/NanoAOD/python/lowPtElectrons_cff.py index ef3868c63058c..c6dc53ac78175 100644 --- a/PhysicsTools/NanoAOD/python/lowPtElectrons_cff.py +++ b/PhysicsTools/NanoAOD/python/lowPtElectrons_cff.py @@ -67,9 +67,8 @@ variables = cms.PSet( # Basic variables CandVars, - # Overlaps with PF electron + # Overlaps with PF electron and photon electronIdx = Var("?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1", int, doc="index of the overlapping PF electron (-1 if none)"), - jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"), photonIdx = Var("?overlaps('photons').size()>0?overlaps('photons')[0].key():-1", int, doc="index of the first associated photon (-1 if none)"), # BDT scores and WPs ID = Var("electronID('ID')",float,doc="ID, BDT (raw) score"), diff --git a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc index 2ce2523a9481c..e5a7ed44164e3 100644 --- a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc +++ b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc @@ -340,7 +340,6 @@ void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iS if (!lowPtElectronsTag_.label().empty()) { auto lowPtEleRefProd = iEvent.getRefBeforePut>("lowPtElectrons"); matchLowPtToElectron(lowPtEleRefProd, *lowPtElectrons, "lowPtElectron", eleRefProd, *electrons, "electrons"); - matchOneToMany(jetRefProd, *jets, "jet", lowPtEleRefProd, *lowPtElectrons, "lowPtElectrons"); matchElectronToPhoton(lowPtEleRefProd, *lowPtElectrons, "lowPtElectron", phRefProd, *photons, "photons"); } From fc90a07456328e498299dac5d96687ae39f3c12c Mon Sep 17 00:00:00 2001 From: Sebastien Wertz Date: Tue, 29 Nov 2022 11:48:14 +0100 Subject: [PATCH 13/14] remove cleanmask from nanoDQM --- PhysicsTools/NanoAOD/python/nanoDQM_cfi.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py b/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py index 061a71a8894d7..97917179c4d29 100644 --- a/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py +++ b/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py @@ -53,7 +53,6 @@ plots = cms.VPSet( Count1D('_size', 8, -0.5, 7.5, 'slimmedElectrons after basic selection (pt > 5 )'), Plot1D('charge', 'charge', 3, -1.5, 1.5, 'electric charge'), - Plot1D('cleanmask', 'cleanmask', 1, 0.5, 1.5, 'simple cleaning mask with priority to leptons'), Plot1D('convVeto', 'convVeto', 2, -0.5, 1.5, 'pass conversion veto'), Plot1D('cutBased', 'cutBased', 5, -0.5, 4.5, 'cut-based ID (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)'), Plot1D('cutBased_Fall17V2', 'cutBased_Fall17V2', 5, -0.5, 4.5, 'cut-based ID Fall17 V2 (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)'), @@ -412,7 +411,6 @@ Plot1D('chEmEF', 'chEmEF', 20, 0, 1, 'charged Electromagnetic Energy Fraction'), Plot1D('chFPV0EF', 'chFPV0EF', 20, 0, 2, 'charged fromPV==0 Energy Fraction (energy excluded from CHS jets). Previously called betastar.'), Plot1D('chHEF', 'chHEF', 20, 0, 2, 'charged Hadron Energy Fraction'), - Plot1D('cleanmask', 'cleanmask', 2, -0.5, 1.5, 'simple cleaning mask with priority to leptons'), NoPlot('electronIdx1'), NoPlot('electronIdx2'), Plot1D('eta', 'eta', 20, -6, 6, 'eta'), @@ -491,7 +489,6 @@ plots = cms.VPSet( Count1D('_size', 5, -0.5, 4.5, 'slimmedMuons after basic selection (pt > 3 && track.isNonnull && isLooseMuon)'), Plot1D('charge', 'charge', 3, -1.5, 1.5, 'electric charge'), - Plot1D('cleanmask', 'cleanmask', 2, -0.5, 1.5, 'simple cleaning mask with priority to leptons'), Plot1D('dxy', 'dxy', 20, -0.1, 0.1, 'dxy (with sign) wrt first PV, in cm'), Plot1D('dxyErr', 'dxyErr', 20, 0, 0.1, 'dxy uncertainty, in cm'), Plot1D('dxybs', 'dxybs', 20, -0.1, 0.1, 'dxy (with sign) wrt the beam spot, in cm'), @@ -596,7 +593,6 @@ plots = cms.VPSet( Count1D('_size', 9, -0.5, 8.5, 'slimmedPhotons after basic selection (pt > 5 )'), Plot1D('charge', 'charge', 1, -0.5, 0.5, 'electric charge'), - Plot1D('cleanmask', 'cleanmask', 1, 0.5, 1.5, 'simple cleaning mask with priority to leptons'), Plot1D('cutBased', 'cutBased', 4, -0.5, 3.5,'cut-based ID bitmap, (0:fail, 1:loose, 2:medium, 3:tight)'), Plot1D('cutBased_Fall17V2', 'cutBased_Fall17V2', 4, -0.5, 3.5, 'cut-based ID bitmap, Fall17V2, (0:fail, 1:loose, 2:medium, 3:tight)'), NoPlot('electronIdx'), @@ -775,7 +771,6 @@ Count1D('_size', 7, -0.5, 6.5, "slimmedTaus after basic selection (pt > 18 && tauID('decayModeFindingNewDMs') && (tauID('byLooseCombinedIsolationDeltaBetaCorr3Hits') || tauID('byVLooseIsolationMVArun2v1DBoldDMwLT') || tauID('byVLooseIsolationMVArun2v1DBnewDMwLT') || tauID('byVLooseIsolationMVArun2v1DBdR03oldDMwLT')))"), Plot1D('charge', 'charge', 3, -1.5, 1.5, 'electric charge'), Plot1D('chargedIso', 'chargedIso', 20, 0, 200, 'charged isolation'), - Plot1D('cleanmask', 'cleanmask', 1, 0.5, 1.5, 'simple cleaning mask with priority to leptons'), Plot1D('decayMode', 'decayMode', 12, -0.5, 11.5, 'decayMode()'), Plot1D('dxy', 'dxy', 20, -1000, 1000, 'd_{xy} of lead track with respect to PV, in cm (with sign)'), Plot1D('dz', 'dz', 20, -20, 20, 'd_{z} of lead track with respect to PV, in cm (with sign)'), From fa4d9948bd8f0ddd82180c33b894f71b82537320 Mon Sep 17 00:00:00 2001 From: Sebastien Wertz Date: Wed, 30 Nov 2022 13:07:17 +0100 Subject: [PATCH 14/14] use event::get everywhere --- .../PatAlgos/plugins/PATObjectCrossLinker.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc index e5a7ed44164e3..ef790ad65c14f 100644 --- a/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc +++ b/PhysicsTools/PatAlgos/plugins/PATObjectCrossLinker.cc @@ -302,27 +302,27 @@ void PATObjectCrossLinker::produce(edm::Event& iEvent, const edm::EventSetup& iS auto lowPtElectrons = std::make_unique>(); if (!lowPtElectronsTag_.label().empty()) { - auto lowPtElectronsIn = iEvent.getHandle(lowPtElectrons_); - lowPtElectrons->reserve(lowPtElectronsIn->size()); - for (const auto& e : *lowPtElectronsIn) { + const auto& lowPtElectronsIn = iEvent.get(lowPtElectrons_); + lowPtElectrons->reserve(lowPtElectronsIn.size()); + for (const auto& e : lowPtElectronsIn) { lowPtElectrons->push_back(e); } } auto boostedTaus = std::make_unique>(); if (!boostedTausTag_.label().empty()) { - auto boostedTausIn = iEvent.getHandle(boostedTaus_); - boostedTaus->reserve(boostedTausIn->size()); - for (const auto& e : *boostedTausIn) { + const auto& boostedTausIn = iEvent.get(boostedTaus_); + boostedTaus->reserve(boostedTausIn.size()); + for (const auto& e : boostedTausIn) { boostedTaus->push_back(e); } } auto vertices = std::make_unique>(); if (!verticesTag_.label().empty()) { - auto verticesIn = iEvent.getHandle(vertices_); - vertices->reserve(verticesIn->size()); - for (const auto& e : *verticesIn) { + const auto& verticesIn = iEvent.get(vertices_); + vertices->reserve(verticesIn.size()); + for (const auto& e : verticesIn) { vertices->push_back(e); } }