CMS 3D CMS Logo

Functions
applySubstructure_cff Namespace Reference

Functions

def applySubstructure (process, postfix="")
 

Function Documentation

◆ applySubstructure()

def applySubstructure_cff.applySubstructure (   process,
  postfix = "" 
)

Definition at line 5 of file applySubstructure_cff.py.

References helpers.addToProcessAndTask(), and helpers.getPatAlgosToolsTask().

Referenced by miniAOD_tools.miniAOD_customizeCommon().

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