3 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
4 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
5 from PhysicsTools.Heppy.physicsobjects.PhysicsObjects
import Jet, GenJet
8 from PhysicsTools.HeppyCore.statistics.counter
import Counter, Counters
12 from PhysicsTools.Heppy.physicsutils.BTagSF
import BTagSF
13 from PhysicsTools.Heppy.physicsobjects.PhysicsObjects
import GenParticle
14 from PhysicsTools.Heppy.utils.cmsswRelease
import isNewerThan
19 This analyzer filters the jets that do not correspond to the leptons 20 stored in event.selectedLeptons, and puts in the event: 21 - jets: all jets passing the pt and eta cuts 22 - cleanJets: the collection of jets away from the leptons 23 - cleanBJets: the jets passing testBJet, and away from the leptons 25 Example configuration: 27 jetAna = cfg.Analyzer( 29 jetCol = 'slimmedJets' 30 # cmg jet input collection 33 # eta range definition 35 # seed for the btag scale factor 36 btagSFseed = 0xdeadbeef, 37 # if True, the PF and PU jet ID are not applied, and the jets get flagged 42 def __init__(self, cfg_ana, cfg_comp, looperName):
43 super(JetAnalyzer,self).
__init__(cfg_ana, cfg_comp, looperName)
44 self.
btagSF = BTagSF (cfg_ana.btagSFseed)
50 self.handles[
'jets'] = AutoHandle( self.cfg_ana.jetCol,
51 'std::vector<pat::Jet>' )
52 if self.cfg_comp.isMC:
54 self.mchandles[
'genParticles'] = AutoHandle(
'packedGenParticles',
55 'std::vector<pat::PackedGenParticle>' )
56 self.mchandles[
'genJets'] = AutoHandle(
'slimmedGenJets',
57 'std::vector<reco::GenJet>')
61 self.counters.addCounter(
'jets')
62 count = self.counters.counter(
'jets')
63 count.register(
'all events')
64 count.register(
'at least 2 good jets')
65 count.register(
'at least 2 clean jets')
66 count.register(
'at least 1 b jet')
67 count.register(
'at least 2 b jets')
71 self.readCollections( event.input )
72 miniaodjets = self.handles[
'jets'].product()
81 if hasattr(event,
'selectedLeptons'):
82 leptons = event.selectedLeptons
85 if self.cfg_comp.isMC:
86 genJets =
map( GenJet, self.mchandles[
'genJets'].product() )
88 for maodjet
in miniaodjets:
91 if self.cfg_comp.isMC
and hasattr( self.cfg_comp,
'jetScale'):
92 scale = random.gauss( self.cfg_comp.jetScale,
93 self.cfg_comp.jetSmear )
94 jet.scaleEnergy( scale )
98 if pairs[jet]
is None:
101 jet.matchedGenJet = pairs[jet]
103 if self.cfg_comp.isMC
and hasattr(self.cfg_ana,
'jerCorr')
and self.cfg_ana.jerCorr:
106 if self.cfg_comp.isMC
and hasattr(self.cfg_ana,
'jesCorr'):
109 event.jets.append(jet)
111 event.bJets.append(jet)
113 self.counters.counter(
'jets').inc(
'all events')
124 for lepton
in leptons:
133 for jet
in event.cleanJets:
137 for jet
in event.cleanJets:
138 jet.matchGenParton=999.0
140 if self.cfg_comp.isMC
and "BB" in self.cfg_comp.name:
141 genParticles = self.mchandles[
'genParticles'].product()
142 event.genParticles =
map( GenParticle, genParticles)
143 for gen
in genParticles:
144 if abs(gen.pdgId())==5
and gen.mother()
and abs(gen.mother().
pdgId())==21:
145 for jet
in event.cleanJets:
146 dR=
deltaR2(jet.eta(), jet.phi(), gen.eta(), gen.phi() )
147 if dR<jet.matchGenParton:
148 jet.matchGenParton=dR
150 event.jets30 = [jet
for jet
in event.jets
if jet.pt()>30]
151 event.cleanJets30 = [jet
for jet
in event.cleanJets
if jet.pt()>30]
152 if len( event.jets30 )>=2:
153 self.counters.counter(
'jets').inc(
'at least 2 good jets')
154 if len( event.cleanJets30 )>=2:
155 self.counters.counter(
'jets').inc(
'at least 2 clean jets')
156 if len(event.cleanBJets)>0:
157 self.counters.counter(
'jets').inc(
'at least 1 b jet')
158 if len(event.cleanBJets)>1:
159 self.counters.counter(
'jets').inc(
'at least 2 b jets')
163 ''' Adds JER correction according to first method at 164 https://twiki.cern.ch/twiki/bin/view/CMS/JetResolution 166 Requires some attention when genJet matching fails. 168 if not hasattr(jet,
'matchedGenJet'):
171 corrections = [0.052, 0.057, 0.096, 0.134, 0.288]
172 maxEtas = [0.5, 1.1, 1.7, 2.3, 5.0]
174 for i, maxEta
in enumerate(maxEtas):
177 deltaPt = (pt - jet.matchedGenJet.pt()) * corrections[i]
178 totalScale = (pt + deltaPt) / pt
182 jet.scaleEnergy(totalScale)
186 ''' Adds JES correction in number of sigmas (scale) 191 unc = jet.uncOnFourVectorScale()
192 totalScale = 1. + scale * unc
195 jet.scaleEnergy(totalScale)
198 jet.puJetIdPassed = jet.puJetId()
199 jet.pfJetIdPassed = jet.jetID(
"POG_PFID_Loose")
200 if self.cfg_ana.relaxJetId:
203 return jet.puJetIdPassed
and jet.pfJetIdPassed
207 return jet.pt() > self.cfg_ana.jetPt
and \
208 abs( jet.eta() ) < self.cfg_ana.jetEta
and \
214 jet.btagMVA = jet.btag(
"combinedSecondaryVertexBJetTags")
215 jet.btagFlag = self.btagSF.BTagSFcalc.isbtagged(
218 jet.btag(
"combinedSecondaryVertexBJetTags"),
219 abs(jet.partonFlavour()),
220 not self.cfg_comp.isMC,
224 return jet.pt()>20
and \
225 abs( jet.eta() ) < 2.4
and \
def jerCorrection(self, jet)
def __init__(self, cfg_ana, cfg_comp, looperName)
def matchObjectCollection
Abs< T >::type abs(const T &t)
def jesCorrection(self, jet, scale=0.)
def cleanObjectCollection(objects, masks, deltaRMin)
def beginLoop(self, setup)
def isNewerThan(release1, release2=None)