CMS 3D CMS Logo

genparticles_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
3 from PhysicsTools.NanoAOD.simpleGenParticleFlatTableProducer_cfi import simpleGenParticleFlatTableProducer
4 
5 
6 
7 
8 finalGenParticles = cms.EDProducer("GenParticlePruner",
9  src = cms.InputTag("prunedGenParticles"),
10  select = cms.vstring(
11  "drop *",
12  "keep++ abs(pdgId) == 15 & (pt > 15 || isPromptDecayed() )",# keep full tau decay chain for some taus
13  #"drop status==1 & pt < 1", #drop soft stable particle in tau decay
14  "keep+ abs(pdgId) == 15 ", # keep first gen decay product for all tau
15  "+keep pdgId == 22 && status == 1 && (pt > 10 || isPromptFinalState())", # keep gamma above 10 GeV (or all prompt) and its first parent
16  "+keep abs(pdgId) == 11 || abs(pdgId) == 13 || abs(pdgId) == 15", #keep leptons, with at most one mother back in the history
17  "drop abs(pdgId)= 2212 && abs(pz) > 1000", #drop LHC protons accidentally added by previous keeps
18  "keep (400 < abs(pdgId) < 600) || (4000 < abs(pdgId) < 6000)", #keep all B and C hadrons
19  "keep abs(pdgId) == 12 || abs(pdgId) == 14 || abs(pdgId) == 16", # keep neutrinos
20  "keep status == 3 || (status > 20 && status < 30)", #keep matrix element summary
21  "keep isHardProcess() || fromHardProcessDecayed() || fromHardProcessFinalState() || (statusFlags().fromHardProcess() && statusFlags().isLastCopy())", #keep event summary based on status flags
22  "keep (status > 70 && status < 80 && pt > 15) ", # keep high pt partons right before hadronization
23  "keep abs(pdgId) == 23 || abs(pdgId) == 24 || abs(pdgId) == 25 || abs(pdgId) == 37 ", # keep VIP(articles)s
24  #"keep abs(pdgId) == 310 && abs(eta) < 2.5 && pt > 1 ", # keep K0
25  "keep (1000001 <= abs(pdgId) <= 1000039 ) || ( 2000001 <= abs(pdgId) <= 2000015)", #keep SUSY fiction particles
26  )
27 )
28 
29 
30 
31 
32 genParticleTable = simpleGenParticleFlatTableProducer.clone(
33  src = cms.InputTag("finalGenParticles"),
34  name= cms.string("GenPart"),
35  doc = cms.string("interesting gen particles "),
36  externalVariables = cms.PSet(
37  iso = ExtVar(cms.InputTag("genIso"), float, precision=8, doc="Isolation for leptons"),
38  ),
39  variables = cms.PSet(
40  pt = Var("pt", float, precision=8),
41  phi = Var("phi", float,precision=8),
42  eta = Var("eta", float,precision=8),
43  mass = Var("?!((abs(pdgId)>=1 && abs(pdgId)<=5) || (abs(pdgId)>=11 && abs(pdgId)<=16) || pdgId==21 || pdgId==111 || abs(pdgId)==211 || abs(pdgId)==421 || abs(pdgId)==411 || (pdgId==22 && mass<1))?mass:0", float,precision="?((abs(pdgId)==6 || abs(pdgId)>1000000) && statusFlags().isLastCopy())?20:8",doc="Mass stored for all particles with the exception of quarks (except top), leptons/neutrinos, photons with mass < 1 GeV, gluons, pi0(111), pi+(211), D0(421), and D+(411). For these particles, you can lookup the value from PDG."),
44  pdgId = Var("pdgId", int, doc="PDG id"),
45  status = Var("status", int, doc="Particle status. 1=stable"),
46  genPartIdxMother = Var("?numberOfMothers>0?motherRef(0).key():-1", "int16", doc="index of the mother particle"),
47  statusFlags = (Var(
48  "statusFlags().isLastCopyBeforeFSR() * 16384 +"
49  "statusFlags().isLastCopy() * 8192 +"
50  "statusFlags().isFirstCopy() * 4096 +"
51  "statusFlags().fromHardProcessBeforeFSR() * 2048 +"
52  "statusFlags().isDirectHardProcessTauDecayProduct() * 1024 +"
53  "statusFlags().isHardProcessTauDecayProduct() * 512 +"
54  "statusFlags().fromHardProcess() * 256 +"
55  "statusFlags().isHardProcess() * 128 +"
56  "statusFlags().isDirectHadronDecayProduct() * 64 +"
57  "statusFlags().isDirectPromptTauDecayProduct() * 32 +"
58  "statusFlags().isDirectTauDecayProduct() * 16 +"
59  "statusFlags().isPromptTauDecayProduct() * 8 +"
60  "statusFlags().isTauDecayProduct() * 4 +"
61  "statusFlags().isDecayedLeptonHadron() * 2 +"
62  "statusFlags().isPrompt() * 1 ",
63  "uint16", doc=("gen status flags stored bitwise, bits are: "
64  "0 : isPrompt, "
65  "1 : isDecayedLeptonHadron, "
66  "2 : isTauDecayProduct, "
67  "3 : isPromptTauDecayProduct, "
68  "4 : isDirectTauDecayProduct, "
69  "5 : isDirectPromptTauDecayProduct, "
70  "6 : isDirectHadronDecayProduct, "
71  "7 : isHardProcess, "
72  "8 : fromHardProcess, "
73  "9 : isHardProcessTauDecayProduct, "
74  "10 : isDirectHardProcessTauDecayProduct, "
75  "11 : fromHardProcessBeforeFSR, "
76  "12 : isFirstCopy, "
77  "13 : isLastCopy, "
78  "14 : isLastCopyBeforeFSR, ")
79  )),
80  )
81 )
82 
83 genIso = cms.EDProducer("GenPartIsoProducer",
84  genPart=cms.InputTag("finalGenParticles"),
85  packedGenPart=cms.InputTag("packedGenParticles"),
86  additionalPdgId=cms.int32(22),
87  )
88 
89 genParticleTask = cms.Task(finalGenParticles, genIso)
90 genParticleTablesTask = cms.Task(genParticleTable)
def Var(expr, valtype, doc=None, precision=-1, lazyEval=False)
Definition: common_cff.py:17
def ExtVar(tag, valtype, doc=None, precision=-1)
Definition: common_cff.py:28