2 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
3 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
4 from PhysicsTools.Heppy.physicsobjects.PhysicsObjects
import Jet
6 from PhysicsTools.Heppy.physicsutils.JetReCalibrator
import JetReCalibrator
9 from PhysicsTools.Heppy.physicsutils.QGLikelihoodCalculator
import QGLikelihoodCalculator
13 good = [
True for j
in jets ]
16 for i,j
in enumerate(jets):
17 d2i =
deltaR2(l.eta(),l.phi(), j.eta(),j.phi())
20 if ibest != -1: good[ibest] =
False
21 return [ j
for (i,j)
in enumerate(jets)
if good[i] ==
True ]
25 """Taken from RootTools.JetAnalyzer, simplified, modified, added corrections """
26 def __init__(self, cfg_ana, cfg_comp, looperName):
27 super(JetAnalyzer,self).
__init__(cfg_ana, cfg_comp, looperName)
28 mcGT = cfg_ana.mcGT
if hasattr(cfg_ana,
'mcGT')
else "PHYS14_25_V2"
29 dataGT = cfg_ana.dataGT
if hasattr(cfg_ana,
'dataGT')
else "GR_70_V2_AN1"
30 self.
shiftJEC = self.cfg_ana.shiftJEC
if hasattr(self.cfg_ana,
'shiftJEC')
else 0
34 elif self.
recalibrateJets not in [
True,
False]:
raise RuntimeError,
"recalibrateJets must be any of { True, False, 'MC', 'Data' }, while it is %r " % self.
recalibrateJets
37 if self.cfg_comp.isMC:
41 self.
doPuId = self.cfg_ana.doPuId
if hasattr(self.cfg_ana,
'doPuId')
else True
42 self.
jetLepDR = self.cfg_ana.jetLepDR
if hasattr(self.cfg_ana,
'jetLepDR')
else 0.5
43 self.
lepPtMin = self.cfg_ana.minLepPt
if hasattr(self.cfg_ana,
'minLepPt')
else -1
44 self.
jetGammaDR = self.cfg_ana.jetGammaDR
if hasattr(self.cfg_ana,
'jetGammaDR')
else 0.4
45 if(self.cfg_ana.doQG):
50 self.handles[
'jets'] = AutoHandle( self.cfg_ana.jetCol,
'std::vector<pat::Jet>' )
51 self.handles[
'genJet'] = AutoHandle(
'slimmedGenJets',
'vector<reco::GenJet>' )
52 self.
shiftJER = self.cfg_ana.shiftJER
if hasattr(self.cfg_ana,
'shiftJER')
else 0
53 self.handles[
'rho'] = AutoHandle( (
'fixedGridRhoFastjetAll',
'',
''),
'double' )
59 self.readCollections( event.input )
60 rho = float(self.handles[
'rho'].product()[0])
64 allJets =
map(Jet, self.handles[
'jets'].product())
66 event.deltaMetFromJEC = [0.,0.]
69 self.jetReCalibrator.correctAll(allJets, rho, delta=self.
shiftJEC, metShift=event.deltaMetFromJEC)
70 event.allJetsUsedForMET = allJets
72 if self.cfg_comp.isMC:
73 event.genJets = [ x
for x
in self.handles[
'genJet'].product() ]
75 if getattr(self.cfg_ana,
'smearJets',
False):
81 event.jetsAllNoID = []
85 event.jetsAllNoID.append(jet)
88 if(self.cfg_ana.doQG):
90 jet.qgl = self.qglcalc.computeQGLikelihood(jet, rho)
93 event.jets.append(jet)
94 event.jetsIdOnly.append(jet)
96 event.jetsFailId.append(jet)
98 event.jetsIdOnly.append(jet)
102 if hasattr(event,
'selectedLeptons'):
103 leptons = [ l
for l
in event.selectedLeptons
if l.pt() > self.
lepPtMin ]
104 if self.cfg_ana.cleanJetsFromTaus
and hasattr(event,
'selectedTaus'):
105 leptons = leptons[:] + event.selectedTaus
106 if self.cfg_ana.cleanJetsFromIsoTracks
and hasattr(event,
'selectedIsoCleanTrack'):
107 leptons = leptons[:] + event.selectedIsoCleanTrack
109 event.cleanJets = [j
for j
in event.cleanJetsAll
if abs(j.eta()) < self.cfg_ana.jetEtaCentral ]
110 event.cleanJetsFwd = [j
for j
in event.cleanJetsAll
if abs(j.eta()) >= self.cfg_ana.jetEtaCentral ]
114 if hasattr(event,
'selectedPhotons'):
115 photons = [ g
for g
in event.selectedPhotons ]
117 event.gamma_cleanJets = [j
for j
in event.gamma_cleanJetsAll
if abs(j.eta()) < self.cfg_ana.jetEtaCentral ]
118 event.gamma_cleanJetsFwd = [j
for j
in event.gamma_cleanJetsAll
if abs(j.eta()) >= self.cfg_ana.jetEtaCentral ]
123 leptons = event.inclusiveLeptons
if hasattr(event,
'inclusiveLeptons')
else event.selectedLeptons
127 jet.leptons = [l
for l
in jlpairs
if jlpairs[l] == jet ]
136 if self.cfg_comp.isMC:
137 event.deltaMetFromJetSmearing = [0, 0]
138 for j
in event.cleanJetsAll:
139 if hasattr(j,
'deltaMetFromJetSmearing'):
140 event.deltaMetFromJetSmearing[0] += j.deltaMetFromJetSmearing[0]
141 event.deltaMetFromJetSmearing[1] += j.deltaMetFromJetSmearing[1]
160 jet.puJetIdPassed = jet.puJetId()
161 jet.pfJetIdPassed = jet.jetID(
'POG_PFID_Loose')
162 if self.cfg_ana.relaxJetId:
165 return jet.pfJetIdPassed
and (jet.puJetIdPassed
or not(self.
doPuId))
169 return jet.pt() > self.cfg_ana.jetPt
and \
170 abs( jet.eta() ) < self.cfg_ana.jetEta;
185 for ii
in range(0, jet.numberOfDaughters()) :
187 part = jet.daughter(ii)
191 if part.charge() == 0 :
193 if part.pt() > 1.: jet.mult += 1
199 if part.trackHighPurity()==
False: usePart=
False
200 if part.fromPV()<=1: usePart=
False
205 deta = part.eta() - jet.eta()
206 dphi =
deltaPhi(part.phi(), jet.phi())
208 weight = partPt*partPt
211 sum_deta += deta*weight
212 sum_dphi += dphi*weight
213 sum_deta2 += deta*deta*weight
214 sum_detadphi += deta*dphi*weight
215 sum_dphi2 += dphi*dphi*weight
225 jet.ptd = math.sqrt(sum_weight)/sum_pt
226 ave_deta = sum_deta/sum_weight
227 ave_dphi = sum_dphi/sum_weight
228 ave_deta2 = sum_deta2/sum_weight
229 ave_dphi2 = sum_dphi2/sum_weight
230 a = ave_deta2 - ave_deta*ave_deta
231 b = ave_dphi2 - ave_dphi*ave_dphi
232 c = -(sum_detadphi/sum_weight - ave_deta*ave_dphi)
235 delta = math.sqrt(math.fabs((a-b)*(a-b)+4.*c*c))
237 if a+b-delta > 0: jet.axis2 = -math.log(math.sqrt(0.5*(a+b-delta)))
238 else: jet.axis2 = -1.
244 if id > 999:
return (id/1000)%10 == f
245 if id > 99:
return (id/100)%10 == f
250 event.bqObjects = [ p
for p
in event.genParticles
if (p.status() == 2
and isFlavour(p,5)) ]
251 event.cqObjects = [ p
for p
in event.genParticles
if (p.status() == 2
and isFlavour(p,4)) ]
253 event.partons = [ p
for p
in event.genParticles
if ((p.status() == 23
or p.status() == 3)
and abs(p.pdgId())>0
and (
abs(p.pdgId())
in [1,2,3,4,5,21]) ) ]
258 for jet
in event.cleanJetsAll:
260 jet.partonId = (parton.pdgId()
if parton !=
None else 0)
261 jet.partonMotherId = (parton.mother(0).
pdgId()
if parton !=
None and parton.numberOfMothers()>0
else 0)
263 for jet
in event.jets:
264 (bmatch, dr) =
bestMatch(jet, event.bqObjects)
268 (cmatch, dr) =
bestMatch(jet, event.cqObjects)
274 event.heaviestQCDFlavour = 5
if len(event.bqObjects)
else (4
if len(event.cqObjects)
else 1);
279 event.genbquarks + event.genwzquarks,
284 jet.mcMatchId = (gen.sourceId
if gen !=
None else 0)
285 jet.mcMatchFlav = (
abs(gen.pdgId())
if gen !=
None else 0)
291 jet.mcJet = match[jet]
300 genpt, jetpt, aeta = gen.pt(), jet.pt(),
abs(jet.eta())
302 factor = 1.052 + self.shiftJER*math.hypot(0.012,0.062);
303 if aeta > 2.3: factor = 1.288 + self.shiftJER*math.hypot(0.127,0.154)
304 elif aeta > 1.7: factor = 1.134 + self.shiftJER*math.hypot(0.035,0.066)
305 elif aeta > 1.1: factor = 1.096 + self.shiftJER*math.hypot(0.017,0.063)
306 elif aeta > 0.5: factor = 1.057 + self.shiftJER*math.hypot(0.012,0.056)
307 ptscale =
max(0.0, (jetpt + (factor-1)*(jetpt-genpt))/jetpt)
309 jet.deltaMetFromJetSmearing = [ -(ptscale-1)*jet.rawFactor()*jet.px(), -(ptscale-1)*jet.rawFactor()*jet.py() ]
311 jet.setP4(jet.p4()*ptscale)
313 jet._rawFactorMultiplier *= (1.0/ptscale)
if ptscale != 0
else 1
318 setattr(JetAnalyzer,
"defaultConfig", cfg.Analyzer(
319 class_object = JetAnalyzer,
320 jetCol =
'slimmedJets',
329 recalibrateJets =
False,
333 cleanJetsFromTaus =
False,
334 cleanJetsFromIsoTracks =
False,
def matchObjectCollection
def matchObjectCollection2
Abs< T >::type abs(const T &t)
double deltaR2(const T1 &t1, const T2 &t2)
if(conf.exists("allCellsPositionCalc"))