128 self.readCollections( event.input )
129 rho =
float(self.handles[
'rho'].product()[0])
133 if self.cfg_ana.copyJetsByValue:
136 allJets =
map(
lambda j:
Jet(ROOT.heppy.JetUtils.copyJet(j)), self.handles[
'jets'].product())
138 allJets =
map(Jet, self.handles[
'jets'].product())
149 jetsBefore = [ (j.pt(),j.eta(),j.phi(),j.rawFactor())
for j
in allJets ]
150 self.jetReCalibrator.correctAll(allJets, rho, delta=self.
shiftJEC,
154 jetsAfter = [ (j.pt(),j.eta(),j.phi(),j.rawFactor())
for j
in allJets ]
155 if len(jetsBefore) != len(jetsAfter):
156 print(
"ERROR: I had to recompute jet corrections, and they rejected some of the jets:\nold = %s\n new = %s\n" % (jetsBefore,jetsAfter))
158 for (told, tnew)
in zip(jetsBefore,jetsAfter):
159 if (
deltaR2(told[1],told[2],tnew[1],tnew[2])) > 0.0001:
160 print(
"ERROR: I had to recompute jet corrections, and one jet direction moved: old = %s, new = %s\n" % (told, tnew))
161 elif abs(told[0]-tnew[0])/(told[0]+tnew[0]) > 0.5e-3
or abs(told[3]-tnew[3]) > 0.5e-3:
162 print(
"ERROR: I had to recompute jet corrections, and one jet pt or corr changed: old = %s, new = %s\n" % (told, tnew))
166 if self.cfg_comp.isMC:
167 self.
genJets = [ x
for x
in self.handles[
'genJet'].product() ]
168 if self.cfg_ana.do_mc_match:
169 for igj, gj
in enumerate(self.
genJets):
172 self.
matchJets(event, [ j
for j
in allJets
if j.pt()>self.cfg_ana.jetPt ])
173 if getattr(self.cfg_ana,
'smearJets',
False):
180 allJets.sort(key =
lambda j : j.pt(), reverse =
True)
183 if hasattr(event,
'selectedLeptons'):
184 leptons = [ l
for l
in event.selectedLeptons
if l.pt() > self.
lepPtMin and self.
lepSelCut(l) ]
185 if self.cfg_ana.cleanJetsFromTaus
and hasattr(event,
'selectedTaus'):
186 leptons = leptons[:] + event.selectedTaus
187 if self.cfg_ana.cleanJetsFromIsoTracks
and hasattr(event,
'selectedIsoCleanTrack'):
188 leptons = leptons[:] + event.selectedIsoCleanTrack
197 leps_with_overlaps = []
198 if getattr(self.cfg_ana,
'checkLeptonPFOverlap',
True):
199 for i
in range(jet.numberOfSourceCandidatePtrs()):
200 p1 = jet.sourceCandidatePtr(i)
202 for j
in range(lep.numberOfSourceCandidatePtrs()):
203 p2 = lep.sourceCandidatePtr(j)
204 has_overlaps = p1.key() == p2.key()
and p1.refCore().
id().productIndex() == p2.refCore().
id().productIndex()
and p1.refCore().
id().processIndex() == p2.refCore().
id().processIndex()
206 leps_with_overlaps += [lep]
207 if len(leps_with_overlaps)>0:
208 for lep
in leps_with_overlaps:
211 self.jetsAllNoID.append(jet)
212 if(self.cfg_ana.doQG):
213 jet.qgl_calc = self.qglcalc.computeQGLikelihood
216 self.jets.append(jet)
217 self.jetsIdOnly.append(jet)
219 self.jetsFailId.append(jet)
221 self.jetsIdOnly.append(jet)
223 jetsEtaCut = [j
for j
in self.
jets if abs(j.eta()) < self.cfg_ana.jetEta ]
229 if hasattr(event,
'selectedLeptons')
and self.cfg_ana.cleanSelectedLeptons:
230 event.discardedLeptons = [ l
for l
in leptons
if l
not in cleanLeptons ]
231 event.selectedLeptons = [ l
for l
in event.selectedLeptons
if l
not in event.discardedLeptons ]
233 if hasattr(lep,
"jetOverlap"):
236 lep.jetOverlapIdx = self.cleanJetsAll.index(lep.jetOverlap)
239 lep.jetOverlapIdx = 1000 + self.discardedJets.index(lep.jetOverlap)
249 if hasattr(event,
'selectedPhotons'):
250 if self.cfg_ana.cleanJetsFromFirstPhoton:
251 photons = event.selectedPhotons[:1]
253 photons = [ g
for g
in event.selectedPhotons ]
272 if self.cfg_ana.alwaysCleanPhotons:
285 self.cleanJetsFailIdAll.append(jet)
293 self.gamma_cleanJetsFailIdAll.append(jet)
298 incleptons = event.inclusiveLeptons
if hasattr(event,
'inclusiveLeptons')
else event.selectedLeptons
302 jet.leptons = [l
for l
in jlpairs
if jlpairs[l] == jet ]
303 for lep
in incleptons:
306 setattr(lep,
"jet"+self.cfg_ana.collectionPostFix,lep)
308 setattr(lep,
"jet"+self.cfg_ana.collectionPostFix,jet)
310 taus = getattr(event,
'selectedTaus',[])
314 jet.taus = [l
for l
in jtaupairs
if jtaupairs[l] == jet ]
316 setattr(tau,
"jet"+self.cfg_ana.collectionPostFix,jtaupairs[tau])
319 if self.cfg_comp.isMC:
322 if hasattr(j,
'deltaMetFromJetSmearing'):
328 if self.cfg_ana.cleanGenJetsFromPhoton:
331 if getattr(self.cfg_ana,
'attachNeutrinos',
True)
and hasattr(self.cfg_ana,
"genNuSelection") :
332 jetNus=[x
for x
in event.genParticles
if abs(x.pdgId())
in [12,14,16]
and self.cfg_ana.genNuSelection(x) ]
333 pairs= matchObjectCollection (jetNus, self.
genJets, 0.4**2)
335 for (nu,genJet)
in six.iteritems(pairs) :
336 if genJet
is not None :
337 if not hasattr(genJet,
"nu") :
343 if self.cfg_ana.do_mc_match:
346 if hasattr(event,
"jets"+self.cfg_ana.collectionPostFix):
raise RuntimeError(
"Event already contains a jet collection with the following postfix: "+self.cfg_ana.collectionPostFix)
347 setattr(event,
"rho" +self.cfg_ana.collectionPostFix, self.
rho )
348 setattr(event,
"deltaMetFromJEC" +self.cfg_ana.collectionPostFix, self.
deltaMetFromJEC )
349 setattr(event,
"type1METCorr" +self.cfg_ana.collectionPostFix, self.
type1METCorr )
350 setattr(event,
"allJetsUsedForMET" +self.cfg_ana.collectionPostFix, self.
allJetsUsedForMET )
351 setattr(event,
"jets" +self.cfg_ana.collectionPostFix, self.
jets )
352 setattr(event,
"jetsFailId" +self.cfg_ana.collectionPostFix, self.
jetsFailId )
353 setattr(event,
"jetsAllNoID" +self.cfg_ana.collectionPostFix, self.
jetsAllNoID )
354 setattr(event,
"jetsIdOnly" +self.cfg_ana.collectionPostFix, self.
jetsIdOnly )
355 setattr(event,
"cleanJetsAll" +self.cfg_ana.collectionPostFix, self.
cleanJetsAll )
356 setattr(event,
"cleanJets" +self.cfg_ana.collectionPostFix, self.
cleanJets )
357 setattr(event,
"cleanJetsFwd" +self.cfg_ana.collectionPostFix, self.
cleanJetsFwd )
358 setattr(event,
"cleanJetsFailIdAll" +self.cfg_ana.collectionPostFix, self.
cleanJetsFailIdAll )
359 setattr(event,
"cleanJetsFailId" +self.cfg_ana.collectionPostFix, self.
cleanJetsFailId )
360 setattr(event,
"discardedJets" +self.cfg_ana.collectionPostFix, self.
discardedJets )
361 setattr(event,
"gamma_cleanJetsAll" +self.cfg_ana.collectionPostFix, self.
gamma_cleanJetsAll )
362 setattr(event,
"gamma_cleanJets" +self.cfg_ana.collectionPostFix, self.
gamma_cleanJets )
363 setattr(event,
"gamma_cleanJetsFwd" +self.cfg_ana.collectionPostFix, self.
gamma_cleanJetsFwd )
368 if self.cfg_comp.isMC:
370 setattr(event,
"cleanGenJets" +self.cfg_ana.collectionPostFix, self.
cleanGenJets )
371 setattr(event,
"genJets" +self.cfg_ana.collectionPostFix, self.
genJets )
372 if self.cfg_ana.do_mc_match:
373 setattr(event,
"bqObjects" +self.cfg_ana.collectionPostFix, self.
bqObjects )
374 setattr(event,
"cqObjects" +self.cfg_ana.collectionPostFix, self.
cqObjects )
375 setattr(event,
"partons" +self.cfg_ana.collectionPostFix, self.
partons )
376 setattr(event,
"heaviestQCDFlavour" +self.cfg_ana.collectionPostFix, self.
heaviestQCDFlavour )
deltaMetFromJEC
Read jets, if necessary recalibrate and shift MET.
def testJetNoID(self, jet)
gamma_cleanJetaAll
Clean Jets from photons (first cleaning, then Jet Id)
S & print(S &os, JobReport::InputFile const &f)
cleanJetsFailIdAll
Jet Id, after jet/lepton cleaning.
noIdCleanJets
First cleaning, then Jet Id.
cleanFromLepAndGammaSimultaneously
def matchObjectCollection
def matchJets(self, event, jets)
deltaMetFromJetSmearing
Associate jets to leptons.
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
Abs< T >::type abs(const T &t)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
def jetFlavour(self, event)
def cleanNearestJetOnly(jets, leptons, deltaR)
def cleanJetsAndLeptons(jets, leptons, deltaR, arbitration)
gamma_cleanJetsFailIdAll
Jet Id, after jet/photon cleaning.