|
| 1 | +import FWCore.ParameterSet.Config as cms |
| 2 | + |
| 3 | +from PhysicsTools.NanoAOD.common_cff import * |
| 4 | +from PhysicsTools.NanoAOD.jetsAK8_cff import fatJetTable as _fatJetTable |
| 5 | + |
| 6 | +############################################################## |
| 7 | +# Take AK8 jets and collect their PF constituents |
| 8 | +############################################################### |
| 9 | +finalJetsAK8PFConstituents = cms.EDProducer("PatJetConstituentPtrSelector", |
| 10 | + src = _fatJetTable.src, |
| 11 | + cut = cms.string("abs(eta) <= 2.5") |
| 12 | +) |
| 13 | + |
| 14 | +selectedFinalJetsAK8PFConstituents = cms.EDFilter("PATPackedCandidatePtrSelector", |
| 15 | + src = cms.InputTag("finalJetsAK8PFConstituents", "constituents"), |
| 16 | + cut = cms.string("") |
| 17 | +) |
| 18 | + |
| 19 | +############################################################## |
| 20 | +# Setup PF candidates table |
| 21 | +############################################################## |
| 22 | +finalPFCandidates = cms.EDProducer("PackedCandidatePtrMerger", |
| 23 | + src = cms.VInputTag(cms.InputTag("selectedFinalJetsAK8PFConstituents")), |
| 24 | + skipNulls = cms.bool(True), |
| 25 | + warnOnSkip = cms.bool(True) |
| 26 | +) |
| 27 | + |
| 28 | +pfCandidatesTable = cms.EDProducer("SimplePATCandidateFlatTableProducer", |
| 29 | + src = cms.InputTag("finalPFCandidates"), |
| 30 | + cut = cms.string(""), |
| 31 | + name = cms.string("PFCand"), |
| 32 | + doc = cms.string("PF candidate constituents of AK8 puppi jets (FatJet) with |eta| <= 2.5"), |
| 33 | + singleton = cms.bool(False), |
| 34 | + extension = cms.bool(False), |
| 35 | + variables = cms.PSet( |
| 36 | + pt = Var("pt * puppiWeight()", float, doc="Puppi-weighted pt", precision=10), |
| 37 | + mass = Var("mass * puppiWeight()", float, doc="Puppi-weighted mass", precision=10), |
| 38 | + eta = Var("eta", float, precision=12), |
| 39 | + phi = Var("phi", float, precision=12), |
| 40 | + pdgId = Var("pdgId", int, doc="PF candidate type (+/-211 = ChgHad, 130 = NeuHad, 22 = Photon, +/-11 = Electron, +/-13 = Muon, 1 = HFHad, 2 = HFEM)") |
| 41 | + ) |
| 42 | +) |
| 43 | + |
| 44 | +############################################################## |
| 45 | +# Setup AK8 jet constituents table |
| 46 | +############################################################## |
| 47 | +finalJetsAK8ConstituentsTable = cms.EDProducer("SimplePatJetConstituentTableProducer", |
| 48 | + name = cms.string(_fatJetTable.name.value()+"PFCand"), |
| 49 | + candIdxName = cms.string("pfCandIdx"), |
| 50 | + candIdxDoc = cms.string("Index in the PFCand table"), |
| 51 | + candidates = pfCandidatesTable.src, |
| 52 | + jets = _fatJetTable.src, |
| 53 | + jetCut = _fatJetTable.cut, |
| 54 | + jetConstCut = selectedFinalJetsAK8PFConstituents.cut |
| 55 | +) |
| 56 | + |
| 57 | +jetConstituentsTask = cms.Task(finalJetsAK8PFConstituents,selectedFinalJetsAK8PFConstituents) |
| 58 | +jetConstituentsTablesTask = cms.Task(finalPFCandidates,pfCandidatesTable,finalJetsAK8ConstituentsTable) |
| 59 | + |
| 60 | + |
| 61 | +def SaveAK4JetConstituents(process, jetCut="", jetConstCut=""): |
| 62 | + """ |
| 63 | + This function can be used as a cmsDriver customization |
| 64 | + function to add AK4 jet constituents, on top of the AK8 |
| 65 | + jet constituents. |
| 66 | + """ |
| 67 | + process.finalJetsPuppiPFConstituents = process.finalJetsAK8PFConstituents.clone( |
| 68 | + src = process.jetPuppiTable.src, |
| 69 | + cut = jetCut |
| 70 | + ) |
| 71 | + process.jetConstituentsTask.add(process.finalJetsPuppiPFConstituents) |
| 72 | + |
| 73 | + process.selectedFinalJetsPuppiPFConstituents = process.selectedFinalJetsAK8PFConstituents.clone( |
| 74 | + src = cms.InputTag("finalJetsPuppiPFConstituents", "constituents"), |
| 75 | + cut = jetConstCut |
| 76 | + ) |
| 77 | + process.jetConstituentsTask.add(process.selectedFinalJetsPuppiPFConstituents) |
| 78 | + |
| 79 | + process.finalPFCandidates.src += ["selectedFinalJetsPuppiPFConstituents"] |
| 80 | + process.pfCandidatesTable.doc = pfCandidatesTable.doc.value()+" and AK4 puppi jets (Jet)" |
| 81 | + |
| 82 | + process.finalJetsPuppiConstituentsTable = process.finalJetsAK8ConstituentsTable.clone( |
| 83 | + name = process.jetPuppiTable.name.value()+"PFCand", |
| 84 | + jets = process.jetPuppiTable.src, |
| 85 | + jetCut = process.jetPuppiTable.cut, |
| 86 | + jetConstCut = process.selectedFinalJetsPuppiPFConstituents.cut |
| 87 | + ) |
| 88 | + process.jetConstituentsTablesTask.add(process.finalJetsPuppiConstituentsTable) |
| 89 | + |
| 90 | + return process |
| 91 | + |
| 92 | +def SaveGenJetConstituents(process, addGenJetConst, addGenJetAK8Const, genJetConstCut="",genJetAK8ConstCut=""): |
| 93 | + """ |
| 94 | + This function can be used as a cmsDriver |
| 95 | + customization function to add gen jet |
| 96 | + constituents. |
| 97 | + """ |
| 98 | + process.genjetConstituentsTask = cms.Task() |
| 99 | + process.genjetConstituentsTableTask = cms.Task() |
| 100 | + |
| 101 | + if addGenJetConst: |
| 102 | + process.genJetConstituents = cms.EDProducer("GenJetPackedConstituentPtrSelector", |
| 103 | + src = process.genJetTable.src, |
| 104 | + cut = process.genJetTable.cut, |
| 105 | + ) |
| 106 | + process.genjetConstituentsTask.add(process.genJetConstituents) |
| 107 | + |
| 108 | + process.selectedGenJetConstituents = cms.EDFilter("PATPackedGenParticlePtrSelector", |
| 109 | + src = cms.InputTag("genJetConstituents", "constituents"), |
| 110 | + cut = cms.string(genJetConstCut) |
| 111 | + ) |
| 112 | + process.genjetConstituentsTask.add(process.selectedGenJetConstituents) |
| 113 | + |
| 114 | + if addGenJetAK8Const: |
| 115 | + process.genJetAK8Constituents = cms.EDProducer("GenJetPackedConstituentPtrSelector", |
| 116 | + src = process.genJetAK8Table.src, |
| 117 | + cut = process.genJetAK8Table.cut, |
| 118 | + ) |
| 119 | + process.genjetConstituentsTask.add(process.genJetAK8Constituents) |
| 120 | + |
| 121 | + process.selectedGenJetAK8Constituents = cms.EDFilter("PATPackedGenParticlePtrSelector", |
| 122 | + src = cms.InputTag("genJetAK8Constituents", "constituents"), |
| 123 | + cut = cms.string(genJetAK8ConstCut) |
| 124 | + ) |
| 125 | + process.genjetConstituentsTask.add(process.selectedGenJetAK8Constituents) |
| 126 | + |
| 127 | + if addGenJetConst or addGenJetAK8Const: |
| 128 | + process.finalGenPartCandidates = cms.EDProducer("PackedGenParticlePtrMerger", |
| 129 | + src = cms.VInputTag(), |
| 130 | + skipNulls = cms.bool(True), |
| 131 | + warnOnSkip = cms.bool(True) |
| 132 | + ) |
| 133 | + process.genjetConstituentsTableTask.add(process.finalGenPartCandidates) |
| 134 | + |
| 135 | + process.genPartCandidatesTable = cms.EDProducer("SimplePATGenParticleFlatTableProducer", |
| 136 | + src = cms.InputTag("finalGenPartCandidates"), |
| 137 | + cut = cms.string(""), |
| 138 | + name = cms.string("GenPartCand"), |
| 139 | + doc = cms.string("Gen particle constituents:"), |
| 140 | + singleton = cms.bool(False), |
| 141 | + extension = cms.bool(False), |
| 142 | + variables = cms.PSet(P4Vars, |
| 143 | + pdgId = Var("pdgId", int, doc="pdgId") |
| 144 | + ) |
| 145 | + ) |
| 146 | + process.genjetConstituentsTableTask.add(process.genPartCandidatesTable) |
| 147 | + process.genPartCandidatesTable.variables.pt.precision=10 |
| 148 | + process.genPartCandidatesTable.variables.mass.precision=10 |
| 149 | + |
| 150 | + if addGenJetConst: |
| 151 | + process.finalGenPartCandidates.src += ["selectedGenJetConstituents"] |
| 152 | + process.genPartCandidatesTable.doc = process.genPartCandidatesTable.doc.value()+" AK4 Gen jets (GenJet) " |
| 153 | + |
| 154 | + process.genJetConstituentsTable = cms.EDProducer("SimpleGenJetConstituentTableProducer", |
| 155 | + name = cms.string(process.genJetTable.name.value()+"GenPartCand"), |
| 156 | + candIdxName = cms.string("genPartCandIdx"), |
| 157 | + candIdxDoc = cms.string("Index in the GenPartCand table"), |
| 158 | + candidates = process.genPartCandidatesTable.src, |
| 159 | + jets = process.genJetTable.src, |
| 160 | + jetCut = process.genJetTable.cut, |
| 161 | + jetConstCut = process.selectedGenJetConstituents.cut |
| 162 | + ) |
| 163 | + process.genjetConstituentsTableTask.add(process.genJetConstituentsTable) |
| 164 | + |
| 165 | + if addGenJetAK8Const: |
| 166 | + process.finalGenPartCandidates.src += ["selectedGenJetAK8Constituents"] |
| 167 | + process.genPartCandidatesTable.doc = process.genPartCandidatesTable.doc.value()+" AK8 Gen jets (GenJetAK8)" |
| 168 | + |
| 169 | + process.genJetAK8ConstituentsTable = cms.EDProducer("SimpleGenJetConstituentTableProducer", |
| 170 | + name = cms.string(process.genJetAK8Table.name.value()+"GenPartCand"), |
| 171 | + candIdxName = cms.string("genPartCandIdx"), |
| 172 | + candIdxDoc = cms.string("Index in the GenPartCand table"), |
| 173 | + candidates = process.genPartCandidatesTable.src, |
| 174 | + jets = process.genJetAK8Table.src, |
| 175 | + jetCut = process.genJetAK8Table.cut, |
| 176 | + jetConstCut = process.selectedGenJetAK8Constituents.cut |
| 177 | + ) |
| 178 | + process.genjetConstituentsTableTask.add(process.genJetAK8ConstituentsTable) |
| 179 | + |
| 180 | + process.nanoTableTaskFS.add(process.genjetConstituentsTask) |
| 181 | + process.nanoTableTaskFS.add(process.genjetConstituentsTableTask) |
| 182 | + |
| 183 | + return process |
| 184 | + |
| 185 | +def SaveGenJetAK4Constituents(process): |
| 186 | + process = SaveGenJetConstituents(process,addGenJetConst=True,addGenJetAK8Const=False) |
| 187 | + return process |
| 188 | +def SaveGenJetAK8Constituents(process): |
| 189 | + process = SaveGenJetConstituents(process,addGenJetConst=False,addGenJetAK8Const=True) |
| 190 | + return process |
| 191 | +def SaveGenJetAK4AK8Constituents(process): |
| 192 | + process = SaveGenJetConstituents(process,addGenJetConst=True,addGenJetAK8Const=True) |
| 193 | + return process |
| 194 | + |
0 commit comments