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
11 from PhysicsTools.Heppy.physicsutils.btagsf_lowercase
import BTagSF
12 from PhysicsTools.Heppy.physicsobjects.PhysicsObjects
import GenParticle
13 from PhysicsTools.Heppy.utils.cmsswRelease
import isNewerThan
18 This analyzer filters the jets that do not correspond to the leptons
19 stored in event.selectedLeptons, and puts in the event:
20 - jets: all jets passing the pt and eta cuts
21 - cleanJets: the collection of jets away from the leptons
22 - cleanBJets: the jets passing testBJet, and away from the leptons
24 Example configuration:
26 jetAna = cfg.Analyzer(
28 jetCol = 'slimmedJets'
29 # cmg jet input collection
32 # eta range definition
34 # seed for the btag scale factor
35 btagSFseed = 0xdeadbeef,
36 # if True, the PF and PU jet ID are not applied, and the jets get flagged
41 def __init__(self, cfg_ana, cfg_comp, looperName):
42 super(JetAnalyzer,self).
__init__(cfg_ana, cfg_comp, looperName)
43 self.
btagSF = BTagSF (cfg_ana.btagSFseed)
49 self.handles[
'jets'] =
AutoHandle( self.cfg_ana.jetCol,
50 'std::vector<pat::Jet>' )
51 if self.cfg_comp.isMC:
53 self.mchandles[
'genParticles'] =
AutoHandle(
'packedGenParticles',
54 'std::vector<pat::PackedGenParticle>' )
55 self.mchandles[
'genJets'] =
AutoHandle(
'slimmedGenJets',
56 'std::vector<reco::GenJet>')
60 self.counters.addCounter(
'jets')
61 count = self.counters.counter(
'jets')
62 count.register(
'all events')
63 count.register(
'at least 2 good jets')
64 count.register(
'at least 2 clean jets')
65 count.register(
'at least 1 b jet')
66 count.register(
'at least 2 b jets')
70 self.readCollections( event.input )
71 miniaodjets = self.handles[
'jets'].product()
80 if hasattr(event,
'selectedLeptons'):
81 leptons = event.selectedLeptons
84 if self.cfg_comp.isMC:
85 genJets =
map( GenJet, self.mchandles[
'genJets'].product() )
87 for maodjet
in miniaodjets:
90 if self.cfg_comp.isMC
and hasattr( self.cfg_comp,
'jetScale'):
91 scale = random.gauss( self.cfg_comp.jetScale,
92 self.cfg_comp.jetSmear )
93 jet.scaleEnergy( scale )
97 if pairs[jet]
is None:
100 jet.matchedGenJet = pairs[jet]
102 if self.cfg_comp.isMC
and hasattr(self.cfg_ana,
'jerCorr')
and self.cfg_ana.jerCorr:
105 if self.cfg_comp.isMC
and hasattr(self.cfg_ana,
'jesCorr'):
108 event.jets.append(jet)
110 event.bJets.append(jet)
112 self.counters.counter(
'jets').inc(
'all events')
123 for lepton
in leptons:
132 for jet
in event.cleanJets:
136 for jet
in event.cleanJets:
137 jet.matchGenParton=999.0
139 if self.cfg_comp.isMC
and "BB" in self.cfg_comp.name:
140 genParticles = self.mchandles[
'genParticles'].product()
141 event.genParticles =
map( GenParticle, genParticles)
142 for gen
in genParticles:
143 if abs(gen.pdgId())==5
and gen.mother()
and abs(gen.mother().
pdgId())==21:
144 for jet
in event.cleanJets:
145 dR=
deltaR2(jet.eta(), jet.phi(), gen.eta(), gen.phi() )
146 if dR<jet.matchGenParton:
147 jet.matchGenParton=dR
149 event.jets30 = [jet
for jet
in event.jets
if jet.pt()>30]
150 event.cleanJets30 = [jet
for jet
in event.cleanJets
if jet.pt()>30]
151 if len( event.jets30 )>=2:
152 self.counters.counter(
'jets').inc(
'at least 2 good jets')
153 if len( event.cleanJets30 )>=2:
154 self.counters.counter(
'jets').inc(
'at least 2 clean jets')
155 if len(event.cleanBJets)>0:
156 self.counters.counter(
'jets').inc(
'at least 1 b jet')
157 if len(event.cleanBJets)>1:
158 self.counters.counter(
'jets').inc(
'at least 2 b jets')
162 ''' Adds JER correction according to first method at
163 https://twiki.cern.ch/twiki/bin/view/CMS/JetResolution
165 Requires some attention when genJet matching fails.
167 if not hasattr(jet,
'matchedGenJet'):
170 corrections = [0.052, 0.057, 0.096, 0.134, 0.288]
171 maxEtas = [0.5, 1.1, 1.7, 2.3, 5.0]
173 for i, maxEta
in enumerate(maxEtas):
176 deltaPt = (pt - jet.matchedGenJet.pt()) * corrections[i]
177 totalScale = (pt + deltaPt) / pt
181 jet.scaleEnergy(totalScale)
185 ''' Adds JES correction in number of sigmas (scale)
190 unc = jet.uncOnFourVectorScale()
191 totalScale = 1. + scale * unc
194 jet.scaleEnergy(totalScale)
197 jet.puJetIdPassed = jet.puJetId()
198 jet.pfJetIdPassed = jet.jetID(
"POG_PFID_Loose")
199 if self.cfg_ana.relaxJetId:
202 return jet.puJetIdPassed
and jet.pfJetIdPassed
206 return jet.pt() > self.cfg_ana.jetPt
and \
207 abs( jet.eta() ) < self.cfg_ana.jetEta
and \
213 jet.btagMVA = jet.btag(
"combinedSecondaryVertexBJetTags")
214 jet.btagFlag = self.btagSF.BTagSFcalc.isbtagged(
217 jet.btag(
"combinedSecondaryVertexBJetTags"),
218 abs(jet.partonFlavour()),
219 not self.cfg_comp.isMC,
223 return jet.pt()>20
and \
224 abs( jet.eta() ) < 2.4
and \
def cleanObjectCollection
def matchObjectCollection
Abs< T >::type abs(const T &t)
double deltaR2(const T1 &t1, const T2 &t2)