CMS 3D CMS Logo

applySubstructure_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
3 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
4 
5 def applySubstructure( process, postfix="" ) :
6 
7  task = getPatAlgosToolsTask(process)
8 
9  from PhysicsTools.PatAlgos.tools.jetTools import addJetCollection
10 
11 
12  from PhysicsTools.PatAlgos.producersLayer1.jetProducer_cfi import _patJets as patJetsDefault
13 
14 
15  # Configure the RECO jets
16  from RecoJets.JetProducers.ak8PFJets_cfi import ak8PFJetsPuppi, ak8PFJetsPuppiSoftDrop, ak8PFJetsPuppiConstituents
17  setattr(process,'ak8PFJetsPuppi'+postfix,ak8PFJetsPuppi.clone())
18  setattr(process,'ak8PFJetsPuppiConstituents'+postfix, ak8PFJetsPuppiConstituents.clone(cut = cms.string('pt > 170.0 && abs(rapidity()) < 2.4') ))
19  setattr(process,'ak8PFJetsPuppiSoftDrop'+postfix, ak8PFJetsPuppiSoftDrop.clone( src = 'ak8PFJetsPuppiConstituents'+postfix+':constituents' ))
20  from RecoJets.JetProducers.ak8PFJetsPuppi_groomingValueMaps_cfi import ak8PFJetsPuppiSoftDropMass
21  setattr(process,'ak8PFJetsPuppiSoftDropMass'+postfix, ak8PFJetsPuppiSoftDropMass.clone())
22  from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy
23  from Configuration.Eras.Modifier_run2_miniAOD_94XFall17_cff import run2_miniAOD_94XFall17
24  from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL
25  _run2_miniAOD_ANY = (run2_miniAOD_80XLegacy | run2_miniAOD_94XFall17 | run2_miniAOD_UL)
26  from Configuration.Eras.Modifier_pA_2016_cff import pA_2016
27  if postfix=='':
28  # Avoid recomputing the PUPPI collections that are present in AOD
29  _rerun_puppijets_task = task.copy()
30  _rerun_puppijets_task.add(getattr(process,'ak8PFJetsPuppi'),
31  getattr(process,'ak8PFJetsPuppiConstituents'),
32  getattr(process,'ak8PFJetsPuppiSoftDrop'),
33  getattr(process,'ak8PFJetsPuppiSoftDropMass'))
34  (_run2_miniAOD_ANY | pA_2016 ).toReplaceWith(task, _rerun_puppijets_task)
35  else:
36  task.add(getattr(process,'ak8PFJetsPuppi'+postfix),
37  getattr(process,'ak8PFJetsPuppiConstituents'+postfix),
38  getattr(process,'ak8PFJetsPuppiSoftDrop'+postfix),
39  getattr(process,'ak8PFJetsPuppiSoftDropMass'+postfix))
40 
41  from RecoJets.JetProducers.ak8GenJets_cfi import ak8GenJets, ak8GenJetsSoftDrop, ak8GenJetsConstituents
42  addToProcessAndTask('ak8GenJetsNoNuConstituents'+postfix, ak8GenJetsConstituents.clone(src='ak8GenJetsNoNu'), process, task )
43  addToProcessAndTask('ak8GenJetsNoNuSoftDrop'+postfix,ak8GenJetsSoftDrop.clone(src=cms.InputTag('ak8GenJetsNoNuConstituents'+postfix, 'constituents')),process,task)
44  addToProcessAndTask('slimmedGenJetsAK8SoftDropSubJets'+postfix,
45  cms.EDProducer("PATGenJetSlimmer",
46  src = cms.InputTag("ak8GenJetsNoNuSoftDrop"+postfix, "SubJets"),
47  packedGenParticles = cms.InputTag("packedGenParticles"),
48  cut = cms.string(""),
49  cutLoose = cms.string(""),
50  nLoose = cms.uint32(0),
51  clearDaughters = cms.bool(False), #False means rekeying
52  dropSpecific = cms.bool(True), # Save space
53  ), process, task )
54 
55 
56  addJetCollection(
57  process,
58  postfix=postfix,
59  labelName = 'AK8PFPuppiSoftDrop' + postfix,
60  jetSource = cms.InputTag('ak8PFJetsPuppiSoftDrop'+postfix),
61  btagDiscriminators = ['None'],
62  genJetCollection = cms.InputTag('slimmedGenJetsAK8'),
63  jetCorrections = ('AK8PFPuppi', ['L2Relative', 'L3Absolute'], 'None'),
64  getJetMCFlavour = False # jet flavor disabled
65  )
66 
67  addJetCollection(
68  process,
69  postfix=postfix,
70  labelName = 'AK8PFPuppiSoftDropSubjets',
71  jetSource = cms.InputTag('ak8PFJetsPuppiSoftDrop'+postfix,'SubJets'),
72  algo = 'ak', # needed for subjet flavor clustering
73  rParam = 0.8, # needed for subjet flavor clustering
74  btagDiscriminators = ['pfDeepCSVJetTags:probb', 'pfDeepCSVJetTags:probbb', 'pfCombinedInclusiveSecondaryVertexV2BJetTags','pfCombinedMVAV2BJetTags'],
75  jetCorrections = ('AK4PFPuppi', ['L2Relative', 'L3Absolute'], 'None'),
76  explicitJTA = True, # needed for subjet b tagging
77  svClustering = True, # needed for subjet b tagging
78  genJetCollection = cms.InputTag('slimmedGenJetsAK8SoftDropSubJets'),
79  fatJets=cms.InputTag('ak8PFJetsPuppi'), # needed for subjet flavor clustering
80  groomedFatJets=cms.InputTag('ak8PFJetsPuppiSoftDrop') # needed for subjet flavor clustering
81  )
82 
83 
84  # add groomed ECFs and N-subjettiness to soft dropped pat::Jets for fat jets and subjets
85  process.load('RecoJets.JetProducers.ECF_cff')
86  addToProcessAndTask('nb1AK8PuppiSoftDrop'+postfix, process.ecfNbeta1.clone(src = cms.InputTag("ak8PFJetsPuppiSoftDrop"+postfix), cuts = cms.vstring('', '', 'pt > 250')), process, task)
87  addToProcessAndTask('nb2AK8PuppiSoftDrop'+postfix, process.ecfNbeta2.clone(src = cms.InputTag("ak8PFJetsPuppiSoftDrop"+postfix), cuts = cms.vstring('', '', 'pt > 250')), process, task)
88 
89  #too slow now ==> disable
90  from Configuration.Eras.Modifier_pp_on_XeXe_2017_cff import pp_on_XeXe_2017
91  from Configuration.Eras.Modifier_phase2_common_cff import phase2_common
92 
93  for e in [pp_on_XeXe_2017, phase2_common]:
94  e.toModify(getattr(process,'nb1AK8PuppiSoftDrop'+postfix), cuts = ['pt > 999999', 'pt > 999999', 'pt > 999999'] )
95  e.toModify(getattr(process,'nb2AK8PuppiSoftDrop'+postfix), cuts = ['pt > 999999', 'pt > 999999', 'pt > 999999'] )
96 
97  from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
98  addToProcessAndTask('NjettinessAK8Subjets'+postfix, Njettiness.clone(), process, task)
99  getattr(process,"NjettinessAK8Subjets"+postfix).src = cms.InputTag("ak8PFJetsPuppiSoftDrop"+postfix, "SubJets")
100  getattr(process,"patJetsAK8PFPuppiSoftDrop").userData.userFloats.src += ['nb1AK8PuppiSoftDrop'+postfix+':ecfN2','nb1AK8PuppiSoftDrop'+postfix+':ecfN3']
101  getattr(process,"patJetsAK8PFPuppiSoftDrop").userData.userFloats.src += ['nb2AK8PuppiSoftDrop'+postfix+':ecfN2','nb2AK8PuppiSoftDrop'+postfix+':ecfN3']
102  addToProcessAndTask('nb1AK8PuppiSoftDropSubjets'+postfix, process.ecfNbeta1.clone(src = cms.InputTag("ak8PFJetsPuppiSoftDrop"+postfix, "SubJets")), process, task)
103  addToProcessAndTask('nb2AK8PuppiSoftDropSubjets'+postfix, process.ecfNbeta2.clone(src = cms.InputTag("ak8PFJetsPuppiSoftDrop"+postfix, "SubJets")), process, task)
104  getattr(process,"patJetsAK8PFPuppiSoftDropSubjets"+postfix).userData.userFloats.src += ['nb1AK8PuppiSoftDropSubjets'+postfix+':ecfN2','nb1AK8PuppiSoftDropSubjets'+postfix+':ecfN3']
105  getattr(process,"patJetsAK8PFPuppiSoftDropSubjets"+postfix).userData.userFloats.src += ['nb2AK8PuppiSoftDropSubjets'+postfix+':ecfN2','nb2AK8PuppiSoftDropSubjets'+postfix+':ecfN3']
106  getattr(process,"patJetsAK8PFPuppiSoftDropSubjets"+postfix).userData.userFloats.src += ['NjettinessAK8Subjets'+postfix+':tau1','NjettinessAK8Subjets'+postfix+':tau2','NjettinessAK8Subjets'+postfix+':tau3','NjettinessAK8Subjets'+postfix+':tau4']
107 
108  for e in [pp_on_XeXe_2017, phase2_common]:
109  e.toModify(getattr(process,'nb1AK8PuppiSoftDropSubjets'+postfix), cuts = ['pt > 999999', 'pt > 999999', 'pt > 999999'] )
110  e.toModify(getattr(process,'nb2AK8PuppiSoftDropSubjets'+postfix), cuts = ['pt > 999999', 'pt > 999999', 'pt > 999999'] )
111 
112 
113  # Patify AK8 PF PUPPI
114  addJetCollection(process, postfix=postfix, labelName = 'AK8Puppi',
115  jetSource = cms.InputTag('ak8PFJetsPuppi'+postfix),
116  algo= 'AK', rParam = 0.8,
117  jetCorrections = ('AK8PFPuppi', cms.vstring(['L2Relative', 'L3Absolute']), 'None'),
118  btagDiscriminators = ([
119  'pfCombinedSecondaryVertexV2BJetTags',
120  'pfCombinedInclusiveSecondaryVertexV2BJetTags',
121  'pfCombinedMVAV2BJetTags',
122  'pfDeepCSVJetTags:probb',
123  'pfDeepCSVJetTags:probc',
124  'pfDeepCSVJetTags:probudsg',
125  'pfDeepCSVJetTags:probbb',
126  'pfBoostedDoubleSecondaryVertexAK8BJetTags']),
127  genJetCollection = cms.InputTag('slimmedGenJetsAK8')
128  )
129  getattr(process,"patJetsAK8Puppi"+postfix).userData.userFloats.src = [] # start with empty list of user floats
130  getattr(process,"selectedPatJetsAK8Puppi"+postfix).cut = cms.string("pt > 100")
131  getattr(process,"selectedPatJetsAK8Puppi"+postfix).cutLoose = cms.string("pt > 30")
132  getattr(process,"selectedPatJetsAK8Puppi"+postfix).nLoose = cms.uint32(3)
133 
134  from RecoJets.JetAssociationProducers.j2tParametersVX_cfi import j2tParametersVX
135  addToProcessAndTask('ak8PFJetsPuppiTracksAssociatorAtVertex'+postfix, cms.EDProducer("JetTracksAssociatorAtVertex",
136  j2tParametersVX.clone( coneSize = cms.double(0.8) ),
137  jets = cms.InputTag("ak8PFJetsPuppi") ),
138  process, task)
139  addToProcessAndTask('patJetAK8PuppiCharge'+postfix, cms.EDProducer("JetChargeProducer",
140  src = cms.InputTag("ak8PFJetsPuppiTracksAssociatorAtVertex"),
141  var = cms.string('Pt'),
142  exp = cms.double(1.0) ),
143  process, task)
144 
145 
146  getattr(process,"patJetsAK8Puppi"+postfix).userData.userFloats.src += ['ak8PFJetsPuppiSoftDropMass'+postfix]
147  getattr(process,"patJetsAK8Puppi"+postfix).addTagInfos = cms.bool(False)
148 
149 
150  # add PUPPI Njetiness
151  addToProcessAndTask('NjettinessAK8Puppi'+postfix, Njettiness.clone(), process, task)
152  getattr(process,"NjettinessAK8Puppi"+postfix).src = cms.InputTag("ak8PFJetsPuppi"+postfix)
153  getattr(process,"patJetsAK8Puppi").userData.userFloats.src += ['NjettinessAK8Puppi'+postfix+':tau1','NjettinessAK8Puppi'+postfix+':tau2','NjettinessAK8Puppi'+postfix+':tau3','NjettinessAK8Puppi'+postfix+':tau4']
154 
155 
156  addToProcessAndTask("slimmedJetsAK8PFPuppiSoftDropSubjets"+postfix,
157  cms.EDProducer("PATJetSlimmer",
158  src = cms.InputTag("selectedPatJetsAK8PFPuppiSoftDropSubjets"),
159  packedPFCandidates = cms.InputTag("packedPFCandidates"),
160  dropJetVars = cms.string("1"),
161  dropDaughters = cms.string("0"),
162  rekeyDaughters = cms.string("1"),
163  dropTrackRefs = cms.string("1"),
164  dropSpecific = cms.string("1"),
165  dropTagInfos = cms.string("1"),
166  modifyJets = cms.bool(True),
167  mixedDaughters = cms.bool(False),
168  modifierConfig = cms.PSet( modifications = cms.VPSet() )
169  ),
170  process, task)
171 
172 
173 
174  addToProcessAndTask("slimmedJetsAK8PFPuppiSoftDropPacked"+postfix,
175  cms.EDProducer("BoostedJetMerger",
176  jetSrc=cms.InputTag("selectedPatJetsAK8PFPuppiSoftDrop"),
177  subjetSrc=cms.InputTag("slimmedJetsAK8PFPuppiSoftDropSubjets")
178  ),
179  process, task )
180 
181 
182  addToProcessAndTask("packedPatJetsAK8"+postfix, cms.EDProducer("JetSubstructurePacker",
183  jetSrc = cms.InputTag("selectedPatJetsAK8Puppi"+postfix),
184  distMax = cms.double(0.8),
185  algoTags = cms.VInputTag(
186  cms.InputTag("slimmedJetsAK8PFPuppiSoftDropPacked"+postfix)
187  ),
188  algoLabels = cms.vstring(
189  'SoftDropPuppi'
190  ),
191  fixDaughters = cms.bool(True),
192  packedPFCandidates = cms.InputTag("packedPFCandidates"+postfix),
193  ),
194  process, task)
195 
196  # switch off daughter re-keying since it's done in the JetSubstructurePacker (and can't be done afterwards)
197  process.slimmedJetsAK8.rekeyDaughters = "0"
198  # Reconfigure the slimmedAK8 jet information to keep
199  process.slimmedJetsAK8.dropDaughters = cms.string("pt < 170")
200  process.slimmedJetsAK8.dropSpecific = cms.string("pt < 170")
201  process.slimmedJetsAK8.dropTagInfos = cms.string("pt < 170")
j2tParametersVX_cfi
helpers.getPatAlgosToolsTask
def getPatAlgosToolsTask(process)
Definition: helpers.py:14
ak8PFJets_cfi
jetTools
jetProducer_cfi
helpers
helpers.addToProcessAndTask
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:29
applySubstructure_cff.applySubstructure
def applySubstructure(process, postfix="")
Definition: applySubstructure_cff.py:5