Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gen vertex time and position to NanoAOD #32008

Merged
merged 14 commits into from
Nov 15, 2020
Merged
Original file line number Diff line number Diff line change
@@ -9,7 +9,11 @@ typedef EventSingletonSimpleFlatTableProducer<GenEventInfoProduct> SimpleGenEven
#include "SimDataFormats/HTXS/interface/HiggsTemplateCrossSections.h"
typedef EventSingletonSimpleFlatTableProducer<HTXS::HiggsClassification> SimpleHTXSFlatTableProducer;

#include "DataFormats/Math/interface/Point3D.h"
typedef EventSingletonSimpleFlatTableProducer<math::XYZPointF> SimpleXYZPointFlatTableProducer;

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(SimpleCandidateFlatTableProducer);
DEFINE_FWK_MODULE(SimpleGenEventFlatTableProducer);
DEFINE_FWK_MODULE(SimpleHTXSFlatTableProducer);
DEFINE_FWK_MODULE(SimpleXYZPointFlatTableProducer);
24 changes: 24 additions & 0 deletions PhysicsTools/NanoAOD/python/genVertex_cff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import FWCore.ParameterSet.Config as cms
from PhysicsTools.NanoAOD.common_cff import Var,ExtVar

genVertexTable = cms.EDProducer("SimpleXYZPointFlatTableProducer",
src = cms.InputTag("genParticles:xyz0"),
cut = cms.string(""),
name= cms.string("GenVtx"),
doc = cms.string("Gen vertex"),
singleton = cms.bool(True),
extension = cms.bool(False),
variables = cms.PSet(
x = Var("X", float, doc="gen vertex x", precision=10),
y = Var("Y", float, doc="gen vertex y", precision=10),
z = Var("Z", float, doc="gen vertex z", precision=16),
)
)

genVertexT0Table = cms.EDProducer("GlobalVariablesTableProducer",
variables = cms.PSet(
GenVtx_t0 = ExtVar( cms.InputTag("genParticles:t0"), "float", doc = "gen vertex t0", precision=12),
)
)

genVertexTables = cms.Sequence(genVertexTable+genVertexT0Table)
9 changes: 9 additions & 0 deletions PhysicsTools/NanoAOD/python/nanoDQM_cfi.py
Original file line number Diff line number Diff line change
@@ -299,6 +299,15 @@
Plot1D('statusFlags', 'statusFlags', 32768, 0, 32768, 'gen status flags stored bitwise, bits are: 0 : isPrompt, 1 : isDecayedLeptonHadron, 2 : isTauDecayProduct, 3 : isPromptTauDecayProduct, 4 : isDirectTauDecayProduct, 5 : isDirectPromptTauDecayProduct, 6 : isDirectHadronDecayProduct, 7 : isHardProcess, 8 : fromHardProcess, 9 : isHardProcessTauDecayProduct, 10 : isDirectHardProcessTauDecayProduct, 11 : fromHardProcessBeforeFSR, 12 : isFirstCopy, 13 : isLastCopy, 14 : isLastCopyBeforeFSR, '),
)
),
GenVtx = cms.PSet(
sels = cms.PSet(),
plots = cms.VPSet(
Plot1D('x', 'x', 20, -1, 1, 'x'),
Plot1D('y', 'y', 20, -1, 1, 'y'),
Plot1D('z', 'z', 30, -15, 15, 'z'),
Plot1D('t0', 't0', 20, -1, 1, 't0'),
)
),
GenVisTau = cms.PSet(
sels = cms.PSet(),
plots = cms.VPSet(
8 changes: 7 additions & 1 deletion PhysicsTools/NanoAOD/python/nano_cff.py
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
from PhysicsTools.NanoAOD.genparticles_cff import *
from PhysicsTools.NanoAOD.particlelevel_cff import *
from PhysicsTools.NanoAOD.genWeightsTable_cfi import *
from PhysicsTools.NanoAOD.genVertex_cff import *
from PhysicsTools.NanoAOD.vertices_cff import *
from PhysicsTools.NanoAOD.met_cff import *
from PhysicsTools.NanoAOD.triggerObjects_cff import *
@@ -117,7 +118,12 @@

nanoSequence = cms.Sequence(nanoSequenceCommon + nanoSequenceOnlyFullSim)

nanoSequenceFS = cms.Sequence(genParticleSequence + particleLevelSequence + nanoSequenceCommon + jetMC + muonMC + electronMC + photonMC + tauMC + metMC + ttbarCatMCProducers + globalTablesMC + btagWeightTable + genWeightsTable + genParticleTables + particleLevelTables + lheInfoTable + ttbarCategoryTable )
nanoSequenceFS = cms.Sequence(genParticleSequence + genVertexTables + particleLevelSequence + nanoSequenceCommon + jetMC + muonMC + electronMC + photonMC + tauMC + metMC + ttbarCatMCProducers + globalTablesMC + btagWeightTable + genWeightsTable + genVertexTable + genParticleTables + particleLevelTables + lheInfoTable + ttbarCategoryTable )

# GenVertex only stored in newer MiniAOD
(run2_nanoAOD_92X | run2_miniAOD_80XLegacy | run2_nanoAOD_94X2016 | run2_nanoAOD_94X2016 | \
run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94XMiniAODv2 | \
run2_nanoAOD_102Xv1).toReplaceWith(nanoSequenceFS, nanoSequenceFS.copyAndExclude([genVertexTables]))

nanoSequenceMC = nanoSequenceFS.copy()
nanoSequenceMC.insert(nanoSequenceFS.index(nanoSequenceCommon)+1,nanoSequenceOnlyFullSim)
1 change: 1 addition & 0 deletions PhysicsTools/NanoAOD/python/nanogenDQM_cff.py
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
GenJetAK8 = nanoDQM.vplots.GenJetAK8,
GenMET = nanoDQM.vplots.GenMET,
GenPart = nanoDQM.vplots.GenPart,
GenVtx = nanoDQM.vplots.GenVtx,
GenVisTau = nanoDQM.vplots.GenVisTau,
LHEPart = nanoDQM.vplots.LHEPart,
LHEScaleWeight = nanoDQM.vplots.LHEScaleWeight,
29 changes: 21 additions & 8 deletions PhysicsTools/NanoAOD/python/nanogen_cff.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
from PhysicsTools.NanoAOD.particlelevel_cff import *
from PhysicsTools.NanoAOD.lheInfoTable_cfi import *
from PhysicsTools.NanoAOD.genWeightsTable_cfi import *
from PhysicsTools.NanoAOD.genVertex_cff import *
from PhysicsTools.NanoAOD.common_cff import Var,CandVars

nanoMetadata = cms.EDProducer("UniqueStringProducer",
@@ -30,6 +31,7 @@
genVisTauTable+
genTable+
genParticleTables+
genVertexTables+
tautagger+
rivetProducerHTXS+
particleLevelTables+
@@ -57,9 +59,19 @@ def nanoGenCommonCustomize(process):
setGenPhiPrecision(process, CandVars.phi.precision)

def customizeNanoGENFromMini(process):
process.nanoAOD_step.insert(0, process.genParticles2HepMCHiggsVtx)
process.nanoAOD_step.insert(0, process.genParticles2HepMC)
process.nanoAOD_step.insert(0, process.mergedGenParticles)
process.nanogenSequence.insert(0, process.genParticles2HepMCHiggsVtx)
process.nanogenSequence.insert(0, process.genParticles2HepMC)
process.nanogenSequence.insert(0, process.mergedGenParticles)

from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy
from Configuration.Eras.Modifier_run2_nanoAOD_94X2016_cff import run2_nanoAOD_94X2016
from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv1_cff import run2_nanoAOD_94XMiniAODv1
from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv2_cff import run2_nanoAOD_94XMiniAODv2
from Configuration.Eras.Modifier_run2_nanoAOD_102Xv1_cff import run2_nanoAOD_102Xv1

(run2_nanoAOD_92X | run2_miniAOD_80XLegacy | run2_nanoAOD_94X2016 | run2_nanoAOD_94X2016 | \
run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94XMiniAODv2 | \
run2_nanoAOD_102Xv1).toReplaceWith(nanogenSequence, nanogenSequence.copyAndExclude([genVertexTables]))

process.metMCTable.src = "slimmedMETs"
process.metMCTable.variables.pt = Var("genMET.pt", float, doc="pt")
@@ -75,6 +87,7 @@ def customizeNanoGENFromMini(process):
process.genJetAK8Table.src = "slimmedGenJetsAK8"
process.tauGenJets.GenParticles = "prunedGenParticles"
process.genVisTaus.srcGenParticles = "prunedGenParticles"

nanoGenCommonCustomize(process)

return process
@@ -105,19 +118,19 @@ def pruneGenParticlesNano(process):
process.finalGenParticles = finalGenParticles.clone()
process.genParticleTable.src = "prunedGenParticles"
process.patJetPartons.particles = "prunedGenParticles"
process.nanoAOD_step.insert(0, process.finalGenParticles)
process.nanogenSequence.insert(0, process.finalGenParticles)
Copy link
Contributor

Choose a reason for hiding this comment

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

return process

# Prune gen particles with conditions applied in usual MiniAOD
def pruneGenParticlesMini(process):
from PhysicsTools.PatAlgos.slimming.prunedGenParticles_cfi import prunedGenParticles
process.prunedGenParticles = prunedGenParticles.clone()
if process.nanoAOD_step.contains(process.nanogenMiniSequence):
if process.nanogenSequence.contains(process.mergedGenParticles):
raise ValueError("Applying the MiniAOD genParticle pruner to MiniAOD is redunant. " \
"Use a different customization.")
from PhysicsTools.PatAlgos.slimming.prunedGenParticles_cfi import prunedGenParticles
process.prunedGenParticles = prunedGenParticles.clone()
process.genParticleTable.src = "prunedGenParticles"
process.patJetPartons.particles = "prunedGenParticles"
process.nanoAOD_step.insert(0, process.prunedGenParticles)
process.nanogenSequence.insert(0, process.prunedGenParticles)
return process

def setGenFullPrecision(process):