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/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/lowPtElectrons_cff.py b/PhysicsTools/NanoAOD/python/lowPtElectrons_cff.py index 5539d7c7e60a3..c6dc53ac78175 100644 --- a/PhysicsTools/NanoAOD/python/lowPtElectrons_cff.py +++ b/PhysicsTools/NanoAOD/python/lowPtElectrons_cff.py @@ -67,8 +67,9 @@ 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)"), + 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 +99,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/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/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)'), diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py index bd46fde7f45b7..4e9965a19b938 100644 --- a/PhysicsTools/NanoAOD/python/nano_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -40,7 +40,9 @@ electrons=cms.InputTag("finalElectrons"), lowPtElectrons=cms.InputTag("finalLowPtElectrons"), taus=cms.InputTag("finalTaus"), + boostedTaus=cms.InputTag("finalBoostedTaus"), photons=cms.InputTag("finalPhotons"), + vertices=cms.InputTag("slimmedSecondaryVertices") ) # Switch to AK4 CHS jets for Run-2 @@ -48,27 +50,11 @@ 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") +# boosted taus don't exist in 122X MINI +run3_nanoAOD_122.toModify( + linkedObjects, boostedTaus=None, ) - lhcInfoTable = cms.EDProducer("LHCInfoProducer") nanoTableTaskCommon = cms.Task( @@ -82,7 +68,7 @@ jetPuppiTablesTask, jetAK8TablesTask, muonTablesTask, fsrTablesTask, tauTablesTask, boostedTauTablesTask, electronTablesTask, lowPtElectronTablesTask, photonTablesTask, - globalTablesTask, vertexTablesTask, metTablesTask, simpleCleanerTable, extraFlagsTableTask, + globalTablesTask, vertexTablesTask, metTablesTask, extraFlagsTableTask, isoTrackTablesTask,softActivityTablesTask ) diff --git a/PhysicsTools/NanoAOD/python/taus_cff.py b/PhysicsTools/NanoAOD/python/taus_cff.py index 624873b418631..b78b58c49e3ec 100644 --- a/PhysicsTools/NanoAOD/python/taus_cff.py +++ b/PhysicsTools/NanoAOD/python/taus_cff.py @@ -54,6 +54,11 @@ 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"), 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 f2f99463783b8..ef790ad65c14f 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,12 @@ 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; @@ -87,10 +94,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> photons_; + edm::InputTag boostedTausTag_; + edm::EDGetTokenT> boostedTaus_; + edm::InputTag verticesTag_; + edm::EDGetTokenT> vertices_; }; // @@ -100,19 +111,28 @@ PATObjectCrossLinker::PATObjectCrossLinker(const edm::ParameterSet& params) : jets_(consumes>(params.getParameter("jets"))), muons_(consumes>(params.getParameter("muons"))), electrons_(consumes>(params.getParameter("electrons"))), - lowPtElectronsTag_(params.getParameter("lowPtElectrons")), - lowPtElectrons_(mayConsume>(lowPtElectronsTag_)), + photons_(consumes>(params.getParameter("photons"))), taus_(consumes>(params.getParameter("taus"))), - photons_(consumes>(params.getParameter("photons"))) - -{ + lowPtElectronsTag_(params.getParameter("lowPtElectrons")), + boostedTausTag_(params.getParameter("boostedTaus")), + verticesTag_(params.getParameter("vertices")) { produces>("jets"); produces>("muons"); produces>("electrons"); - if (!lowPtElectronsTag_.label().empty()) - produces>("lowPtElectrons"); - produces>("taus"); produces>("photons"); + produces>("taus"); + if (!lowPtElectronsTag_.label().empty()) { + lowPtElectrons_ = consumes>(lowPtElectronsTag_), + produces>("lowPtElectrons"); + } + if (!boostedTausTag_.label().empty()) { + boostedTaus_ = consumes>(boostedTausTag_); + produces>("boostedTaus"); + } + if (!verticesTag_.label().empty()) { + vertices_ = consumes>(verticesTag_); + produces>("vertices"); + } } PATObjectCrossLinker::~PATObjectCrossLinker() { @@ -150,6 +170,7 @@ void PATObjectCrossLinker::matchOneToMany(const C1& refProdOne, } } +// one electron can be matched to several photons template void PATObjectCrossLinker::matchElectronToPhoton(const C1& refProdOne, C2& itemsOne, @@ -173,6 +194,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, @@ -203,70 +225,148 @@ 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; - 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); - 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"); + auto lowPtElectrons = std::make_unique>(); + if (!lowPtElectronsTag_.label().empty()) { + 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()) { + 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()) { + const auto& verticesIn = iEvent.get(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", 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()) { auto lowPtEleRefProd = iEvent.getRefBeforePut>("lowPtElectrons"); matchLowPtToElectron(lowPtEleRefProd, *lowPtElectrons, "lowPtElectron", eleRefProd, *electrons, "electrons"); + matchElectronToPhoton(lowPtEleRefProd, *lowPtElectrons, "lowPtElectron", phRefProd, *photons, "photons"); + } + + 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(photons), "photons"); + 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 ------------ @@ -277,11 +377,19 @@ 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("photons")->setComment("a photon collection derived from pat::Photon"); + 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); } //define this as a plug-in