Adding the option to smearJets in the JetAnalyzer results in an Attribute error
cbeiraod opened this issue · 3 comments
I am on branch heppy_80X, as recommended for Moriond 2017 analyses (https://twiki.cern.ch/twiki/bin/viewauth/CMS/CMGToolsReleasesExperimental)
When setting the option "smearJets = True" for the JetAnalyzer the code no longer runs and reports the following error (note the second to last file in the trace):
Traceback (most recent call last):
File "/afs/cern.ch/work/c/cbeiraod/Stop4Body/CMSSW_8_0_25/python/PhysicsTools/HeppyCore/framework/heppy_loop.py", line 35, in runLoopAsync
loop = runLoop( comp, outDir, copy.copy(sys.modules[configName].config), options)
File "/afs/cern.ch/work/c/cbeiraod/Stop4Body/CMSSW_8_0_25/python/PhysicsTools/HeppyCore/framework/heppy_loop.py", line 61, in runLoop
loop.loop()
File "/afs/cern.ch/work/c/cbeiraod/Stop4Body/CMSSW_8_0_25/python/PhysicsTools/HeppyCore/framework/looper.py", line 198, in loop
self.process( iEv )
File "/afs/cern.ch/work/c/cbeiraod/Stop4Body/CMSSW_8_0_25/python/PhysicsTools/HeppyCore/framework/looper.py", line 256, in process
ret = analyzer.process( self.event )
File "/afs/cern.ch/work/c/cbeiraod/Stop4Body/CMSSW_8_0_25/python/PhysicsTools/Heppy/analyzers/objects/JetAnalyzer.py", line 184, in process
self.smearJets(event, allJets)
File "/afs/cern.ch/work/c/cbeiraod/Stop4Body/CMSSW_8_0_25/python/PhysicsTools/Heppy/analyzers/objects/JetAnalyzer.py", line 468, in smearJets
gen = jet.mcJet
File "/afs/cern.ch/work/c/cbeiraod/Stop4Body/CMSSW_8_0_25/python/PhysicsTools/Heppy/physicsobjects/PhysicsObject.py", line 28, in __getattr__
return getattr(self.physObj, name)
AttributeError: 'pat::Jet' object has no attribute 'mcJet'
I have traced this problem to the fact that not all jets have a matched genJet. The cause can be easily observed by looking at the following lines of code:
self.matchJets(event, [ j for j in allJets if j.pt()>self.cfg_ana.jetPt ]) # To match only jets above chosen threshold
if getattr(self.cfg_ana, 'smearJets', False):
self.smearJets(event, allJets)
From here: JetAnalyzer.py lines 182-184
To fix, it should be fairly straightforward, either match all jets or smear only the jets that were matched. The intended behavior is not clear and choosing between the two options is not as straightforward. The two fixes, below:
- Match all jets:
self.matchJets(event, allJets)
if getattr(self.cfg_ana, 'smearJets', False):
self.smearJets(event, allJets)
- Smear only matched jets:
self.matchJets(event, [ j for j in allJets if j.pt()>self.cfg_ana.jetPt ])
if getattr(self.cfg_ana, 'smearJets', False):
self.smearJets(event, [ j for j in allJets if j.pt()>self.cfg_ana.jetPt ])
I would be happy to implement the fix and make a pull request if the desired behavior can be made clear.
Hi,
There is actually a PR too, that I opened following the discussion 9 months ago. PR #645
Cheers,
Mario
Thanks for pointing that out!
Any indication why it hasn't been pulled into the main repository?