CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Static Public Attributes
objects.JetAnalyzer.JetAnalyzer Class Reference
Inheritance diagram for objects.JetAnalyzer.JetAnalyzer:

Public Member Functions

def __init__ (self, cfg_ana, cfg_comp, looperName)
 
def beginLoop (self, setup)
 
def declareHandles (self)
 
def jetFlavour (self, event)
 
def matchJets (self, event, jets)
 
def process (self, event)
 
def smearJets (self, event, jets)
 
def testJetID (self, jet)
 
def testJetNoID (self, jet)
 

Public Attributes

 allJetsUsedForMET
 
 bqObjects
 
 cleanGenJets
 
 cleanJets
 
 cleanJetsAll
 
 cleanJetsFailId
 
 cleanJetsFailIdAll
 Jet Id, after jet/lepton cleaning. More...
 
 cleanJetsFwd
 
 cqObjects
 
 deltaMetFromJEC
 Read jets, if necessary recalibrate and shift MET. More...
 
 deltaMetFromJetSmearing
 Associate jets to leptons. More...
 
 discardedJets
 
 doJEC
 
 gamma_cleanJetaAll
 Clean Jets from photons (first cleaning, then Jet Id) More...
 
 gamma_cleanJets
 
 gamma_cleanJetsAll
 
 gamma_cleanJetsFailId
 
 gamma_cleanJetsFailIdAll
 Jet Id, after jet/photon cleaning. More...
 
 gamma_cleanJetsFwd
 
 gamma_noIdCleanJets
 
 gamma_noIdCleanJetsAll
 
 gamma_noIdCleanJetsFwd
 
 genJets
 
 heaviestQCDFlavour
 
 jetReCalibrator
 
 jets
 Sort Jets by pT. More...
 
 jetsAllNoID
 
 jetsFailId
 
 jetsIdOnly
 
 lepPtMin
 
 noIdCleanJets
 First cleaning, then Jet Id. More...
 
 noIdCleanJetsAll
 
 noIdCleanJetsFwd
 
 noIdDiscardedJets
 
 partons
 
 qglcalc
 
 type1METCorr
 

Static Public Attributes

 addJECShifts
 
 addJERShifts
 
 alwaysCleanPhotons
 
 applyL2L3Residual
 
 attachNeutrinos
 
 calculateSeparateCorrections
 
 calculateType1METCorrection
 
 checkLeptonPFOverlap
 
 class_object
 
 cleanFromLepAndGammaSimultaneously
 
 cleanGenJetsFromPhoton
 
 cleanJetsFromFirstPhoton
 
 cleanJetsFromIsoTracks
 
 cleanJetsFromTaus
 
 cleanSelectedLeptons
 
 collectionPostFix
 
 copyJetsByValue
 
 do_mc_match
 
 doPuId
 
 doQG
 
 genJetCol
 
 genNuSelection
 
 jecPath
 
 jetCol
 
 jetEta
 
 jetEtaCentral
 
 jetGammaDR
 
 jetGammaLepDR
 
 jetLepArbitration
 
 jetLepDR
 
 jetPt
 
 lepSelCut
 
 minLepPt
 
 recalibrateJets
 
 recalibrationType
 
 relaxJetId
 
 rho
 
 shiftJEC
 
 shiftJER
 
 smearJets
 
 type1METParams
 

Detailed Description

Taken from RootTools.JetAnalyzer, simplified, modified, added corrections    

Definition at line 67 of file JetAnalyzer.py.

Constructor & Destructor Documentation

◆ __init__()

def objects.JetAnalyzer.JetAnalyzer.__init__ (   self,
  cfg_ana,
  cfg_comp,
  looperName 
)

Definition at line 69 of file JetAnalyzer.py.

References objects.JetAnalyzer.JetAnalyzer.addJECShifts, analyzer.Analyzer.cfg_ana, analyzer.Analyzer.cfg_comp, looper.Looper.cfg_comp, objects.JetAnalyzer.JetAnalyzer.recalibrateJets, and objects.JetAnalyzer.JetAnalyzer.shiftJEC.

69  def __init__(self, cfg_ana, cfg_comp, looperName):
70  super(JetAnalyzer,self).__init__(cfg_ana, cfg_comp, looperName)
71  mcGT = cfg_ana.mcGT if hasattr(cfg_ana,'mcGT') else "PHYS14_25_V2"
72  dataGT = cfg_ana.dataGT if hasattr(cfg_ana,'dataGT') else "GR_70_V2_AN1"
73  self.shiftJEC = self.cfg_ana.shiftJEC if hasattr(self.cfg_ana, 'shiftJEC') else 0
74  self.recalibrateJets = self.cfg_ana.recalibrateJets
75  self.addJECShifts = self.cfg_ana.addJECShifts if hasattr(self.cfg_ana, 'addJECShifts') else 0
76  if self.recalibrateJets == "MC" : self.recalibrateJets = self.cfg_comp.isMC
77  elif self.recalibrateJets == "Data": self.recalibrateJets = not self.cfg_comp.isMC
78  elif self.recalibrateJets not in [True,False]: raise RuntimeError("recalibrateJets must be any of { True, False, 'MC', 'Data' }, while it is %r " % self.recalibrateJets)
79 
80  calculateSeparateCorrections = getattr(cfg_ana,"calculateSeparateCorrections", False);
81  calculateType1METCorrection = getattr(cfg_ana,"calculateType1METCorrection", False);
82  self.doJEC = self.recalibrateJets or (self.shiftJEC != 0) or self.addJECShifts or calculateSeparateCorrections or calculateType1METCorrection
83  if self.doJEC:
84  doResidual = getattr(cfg_ana, 'applyL2L3Residual', 'Data')
85  if doResidual == "MC": doResidual = self.cfg_comp.isMC
86  elif doResidual == "Data": doResidual = not self.cfg_comp.isMC
87  elif doResidual not in [True,False]: raise RuntimeError("If specified, applyL2L3Residual must be any of { True, False, 'MC', 'Data'(default)}")
88  GT = getattr(cfg_comp, 'jecGT', mcGT if self.cfg_comp.isMC else dataGT)
89  # Now take care of the optional arguments
90  kwargs = { 'calculateSeparateCorrections':calculateSeparateCorrections,
91  'calculateType1METCorrection' :calculateType1METCorrection, }
92  if kwargs['calculateType1METCorrection']: kwargs['type1METParams'] = cfg_ana.type1METParams
93  # instantiate the jet re-calibrator
94  self.jetReCalibrator = JetReCalibrator(GT, cfg_ana.recalibrationType, doResidual, cfg_ana.jecPath, **kwargs)
95  self.doPuId = getattr(self.cfg_ana, 'doPuId', True)
96  self.jetLepDR = getattr(self.cfg_ana, 'jetLepDR', 0.4)
97  self.jetLepArbitration = getattr(self.cfg_ana, 'jetLepArbitration', lambda jet,lepton: lepton)
98  self.lepPtMin = getattr(self.cfg_ana, 'minLepPt', -1)
99  self.lepSelCut = getattr(self.cfg_ana, 'lepSelCut', lambda lep : True)
100  self.jetGammaDR = getattr(self.cfg_ana, 'jetGammaDR', 0.4)
101  self.jetGammaLepDR = getattr(self.cfg_ana, 'jetGammaLepDR', 0.4)
102  self.cleanFromLepAndGammaSimultaneously = getattr(self.cfg_ana, 'cleanFromLepAndGammaSimultaneously', False)
103  if self.cleanFromLepAndGammaSimultaneously:
104  if hasattr(self.cfg_ana, 'jetGammaLepDR'):
105  self.jetGammaLepDR = self.jetGammaLepDR
106  elif (self.jetGammaDR == self.jetLepDR):
107  self.jetGammaLepDR = self.jetGammaDR
108  else:
109  raise RuntimeError("DR for simultaneous cleaning of jets from leptons and photons is not defined, and dR(gamma, jet)!=dR(lep, jet)")
110  if(self.cfg_ana.doQG):
111  qgdefname="{CMSSW_BASE}/src/PhysicsTools/Heppy/data/pdfQG_AK4chs_13TeV_v2b.root"
112  self.qglcalc = QGLikelihoodCalculator(getattr(self.cfg_ana,"QGpath",qgdefname).format(CMSSW_BASE= os.environ['CMSSW_BASE']))
113  if not hasattr(self.cfg_ana ,"collectionPostFix"):self.cfg_ana.collectionPostFix=""
114 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

Member Function Documentation

◆ beginLoop()

def objects.JetAnalyzer.JetAnalyzer.beginLoop (   self,
  setup 
)

Definition at line 123 of file JetAnalyzer.py.

123  def beginLoop(self, setup):
124  super(JetAnalyzer,self).beginLoop(setup)
125 

◆ declareHandles()

def objects.JetAnalyzer.JetAnalyzer.declareHandles (   self)

Definition at line 115 of file JetAnalyzer.py.

References objects.JetAnalyzer.JetAnalyzer.addJERShifts, analyzer.Analyzer.cfg_ana, core.AutoHandle.AutoHandle.handles, core.Analyzer.Analyzer.handles, HTTP.RequestManager.handles, and objects.JetAnalyzer.JetAnalyzer.shiftJER.

115  def declareHandles(self):
116  super(JetAnalyzer, self).declareHandles()
117  self.handles['jets'] = AutoHandle( self.cfg_ana.jetCol, 'std::vector<pat::Jet>' )
118  self.handles['genJet'] = AutoHandle( self.cfg_ana.genJetCol, 'vector<reco::GenJet>' )
119  self.shiftJER = self.cfg_ana.shiftJER if hasattr(self.cfg_ana, 'shiftJER') else 0
120  self.addJERShifts = self.cfg_ana.addJERShifts if hasattr(self.cfg_ana, 'addJERShifts') else 0
121  self.handles['rho'] = AutoHandle( self.cfg_ana.rho, 'double' )
122 

◆ jetFlavour()

def objects.JetAnalyzer.JetAnalyzer.jetFlavour (   self,
  event 
)

Definition at line 395 of file JetAnalyzer.py.

References funct.abs().

395  def jetFlavour(self,event):
396  def isFlavour(x,f):
397  id = abs(x.pdgId())
398  if id > 999: return (id/1000)%10 == f
399  if id > 99: return (id/100)%10 == f
400  return id % 100 == f
401 
402 
403 
404  self.bqObjects = [ p for p in event.genParticles if (p.status() == 2 and isFlavour(p,5)) ]
405  self.cqObjects = [ p for p in event.genParticles if (p.status() == 2 and isFlavour(p,4)) ]
406 
407  self.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]) ) ]
408  match = matchObjectCollection2(self.cleanJetsAll,
409  self.partons,
410  deltaRMax = 0.3)
411 
412  for jet in self.cleanJetsAll:
413  parton = match[jet]
414  jet.partonId = (parton.pdgId() if parton != None else 0)
415  jet.partonMotherId = (parton.mother(0).pdgId() if parton != None and parton.numberOfMothers()>0 else 0)
416 
417  for jet in self.jets:
418  (bmatch, dr) = bestMatch(jet, self.bqObjects)
419  if dr < 0.4:
420  jet.mcFlavour = 5
421  else:
422  (cmatch, dr) = bestMatch(jet, self.cqObjects)
423  if dr < 0.4:
424  jet.mcFlavour = 4
425  else:
426  jet.mcFlavour = 0
427 
428  self.heaviestQCDFlavour = 5 if len(self.bqObjects) else (4 if len(self.cqObjects) else 1);
429 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def bestMatch(object, matchCollection)
Definition: deltar.py:138
def matchObjectCollection2(objects, matchCollection, deltaRMax=0.3)
Definition: deltar.py:166

◆ matchJets()

def objects.JetAnalyzer.JetAnalyzer.matchJets (   self,
  event,
  jets 
)

Definition at line 430 of file JetAnalyzer.py.

References funct.abs(), EVTColContainer.genJets, objects.JetAnalyzer.JetAnalyzer.genJets, and deltar.matchObjectCollection2().

430  def matchJets(self, event, jets):
431  match = matchObjectCollection2(jets,
432  event.genbquarks + event.genwzquarks,
433  deltaRMax = 0.3)
434  for jet in jets:
435  gen = match[jet]
436  jet.mcParton = gen
437  jet.mcMatchId = (gen.sourceId if gen != None else 0)
438  jet.mcMatchFlav = (abs(gen.pdgId()) if gen != None else 0)
439 
440  match = matchObjectCollection2(jets,
441  self.genJets,
442  deltaRMax = 0.3)
443  for jet in jets:
444  jet.mcJet = match[jet]
445 
446 
447 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def matchObjectCollection2(objects, matchCollection, deltaRMax=0.3)
Definition: deltar.py:166

◆ process()

def objects.JetAnalyzer.JetAnalyzer.process (   self,
  event 
)

Definition at line 126 of file JetAnalyzer.py.

References analyzer.Analyzer.cfg_ana, dqmMemoryStats.float, core.AutoHandle.AutoHandle.handles, core.Analyzer.Analyzer.handles, HTTP.RequestManager.handles, genParticles_cff.map, core.Analyzer.Analyzer.readCollections(), correctionValue_class.rho, AlignmentMonitorMuonSystemMap1D::MyResidual.rho, and objects.JetAnalyzer.JetAnalyzer.rho.

126  def process(self, event):
127  self.readCollections( event.input )
128  rho = float(self.handles['rho'].product()[0])
129  self.rho = rho
130 
131 
132  if self.cfg_ana.copyJetsByValue:
133  import ROOT
134  #from ROOT.heppy import JetUtils
135  allJets = map(lambda j:Jet(ROOT.heppy.JetUtils.copyJet(j)), self.handles['jets'].product()) #copy-by-value is safe if JetAnalyzer is ran more than once
136  else:
137  allJets = map(Jet, self.handles['jets'].product())
138 
139  #set dummy MC flavour for all jets in case we want to ntuplize discarded jets later
140  for jet in allJets:
141  jet.mcFlavour = 0
142 
143  self.deltaMetFromJEC = [0.,0.]
144  self.type1METCorr = [0.,0.,0.]
145 # print "before. rho",self.rho,self.cfg_ana.collectionPostFix,'allJets len ',len(allJets),'pt', [j.pt() for j in allJets]
146  if self.doJEC:
147  if not self.recalibrateJets: # check point that things won't change
148  jetsBefore = [ (j.pt(),j.eta(),j.phi(),j.rawFactor()) for j in allJets ]
149  self.jetReCalibrator.correctAll(allJets, rho, delta=self.shiftJEC,
150  addCorr=True, addShifts=self.addJECShifts,
151  metShift=self.deltaMetFromJEC, type1METCorr=self.type1METCorr )
152  if not self.recalibrateJets:
153  jetsAfter = [ (j.pt(),j.eta(),j.phi(),j.rawFactor()) for j in allJets ]
154  if len(jetsBefore) != len(jetsAfter):
155  print("ERROR: I had to recompute jet corrections, and they rejected some of the jets:\nold = %s\n new = %s\n" % (jetsBefore,jetsAfter))
156  else:
157  for (told, tnew) in zip(jetsBefore,jetsAfter):
158  if (deltaR2(told[1],told[2],tnew[1],tnew[2])) > 0.0001:
159  print("ERROR: I had to recompute jet corrections, and one jet direction moved: old = %s, new = %s\n" % (told, tnew))
160  elif abs(told[0]-tnew[0])/(told[0]+tnew[0]) > 0.5e-3 or abs(told[3]-tnew[3]) > 0.5e-3:
161  print("ERROR: I had to recompute jet corrections, and one jet pt or corr changed: old = %s, new = %s\n" % (told, tnew))
162  self.allJetsUsedForMET = allJets
163 # print "after. rho",self.rho,self.cfg_ana.collectionPostFix,'allJets len ',len(allJets),'pt', [j.pt() for j in allJets]
164 
165  if self.cfg_comp.isMC:
166  self.genJets = [ x for x in self.handles['genJet'].product() ]
167  if self.cfg_ana.do_mc_match:
168  for igj, gj in enumerate(self.genJets):
169  gj.index = igj
170 # self.matchJets(event, allJets)
171  self.matchJets(event, [ j for j in allJets if j.pt()>self.cfg_ana.jetPt ]) # To match only jets above chosen threshold
172  if getattr(self.cfg_ana, 'smearJets', False):
173  self.smearJets(event, allJets)
174 
175 
176 
177 
178 
179  allJets.sort(key = lambda j : j.pt(), reverse = True)
180 
181  leptons = []
182  if hasattr(event, 'selectedLeptons'):
183  leptons = [ l for l in event.selectedLeptons if l.pt() > self.lepPtMin and self.lepSelCut(l) ]
184  if self.cfg_ana.cleanJetsFromTaus and hasattr(event, 'selectedTaus'):
185  leptons = leptons[:] + event.selectedTaus
186  if self.cfg_ana.cleanJetsFromIsoTracks and hasattr(event, 'selectedIsoCleanTrack'):
187  leptons = leptons[:] + event.selectedIsoCleanTrack
188 
189 
190  self.jets = []
191  self.jetsFailId = []
192  self.jetsAllNoID = []
193  self.jetsIdOnly = []
194  for jet in allJets:
195  #Check if lepton and jet have overlapping PF candidates
196  leps_with_overlaps = []
197  if getattr(self.cfg_ana, 'checkLeptonPFOverlap', True):
198  for i in range(jet.numberOfSourceCandidatePtrs()):
199  p1 = jet.sourceCandidatePtr(i) #Ptr<Candidate> p1
200  for lep in leptons:
201  for j in range(lep.numberOfSourceCandidatePtrs()):
202  p2 = lep.sourceCandidatePtr(j)
203  has_overlaps = p1.key() == p2.key() and p1.refCore().id().productIndex() == p2.refCore().id().productIndex() and p1.refCore().id().processIndex() == p2.refCore().id().processIndex()
204  if has_overlaps:
205  leps_with_overlaps += [lep]
206  if len(leps_with_overlaps)>0:
207  for lep in leps_with_overlaps:
208  lep.jetOverlap = jet
209  if self.testJetNoID( jet ):
210  self.jetsAllNoID.append(jet)
211  if(self.cfg_ana.doQG):
212  jet.qgl_calc = self.qglcalc.computeQGLikelihood
213  jet.qgl_rho = rho
214  if self.testJetID( jet ):
215  self.jets.append(jet)
216  self.jetsIdOnly.append(jet)
217  else:
218  self.jetsFailId.append(jet)
219  elif self.testJetID (jet ):
220  self.jetsIdOnly.append(jet)
221 
222  jetsEtaCut = [j for j in self.jets if abs(j.eta()) < self.cfg_ana.jetEta ]
223  self.cleanJetsAll, cleanLeptons = cleanJetsAndLeptons(jetsEtaCut, leptons, self.jetLepDR, self.jetLepArbitration)
224 
225  self.cleanJets = [j for j in self.cleanJetsAll if abs(j.eta()) < self.cfg_ana.jetEtaCentral ]
226  self.cleanJetsFwd = [j for j in self.cleanJetsAll if abs(j.eta()) >= self.cfg_ana.jetEtaCentral ]
227  self.discardedJets = [j for j in self.jets if j not in self.cleanJetsAll]
228  if hasattr(event, 'selectedLeptons') and self.cfg_ana.cleanSelectedLeptons:
229  event.discardedLeptons = [ l for l in leptons if l not in cleanLeptons ]
230  event.selectedLeptons = [ l for l in event.selectedLeptons if l not in event.discardedLeptons ]
231  for lep in leptons:
232  if hasattr(lep, "jetOverlap"):
233  if lep.jetOverlap in self.cleanJetsAll:
234  #print "overlap reco", lep.p4().pt(), lep.p4().eta(), lep.p4().phi(), lep.jetOverlap.p4().pt(), lep.jetOverlap.p4().eta(), lep.jetOverlap.p4().phi()
235  lep.jetOverlapIdx = self.cleanJetsAll.index(lep.jetOverlap)
236  elif lep.jetOverlap in self.discardedJets:
237  #print "overlap discarded", lep.p4().pt(), lep.p4().eta(), lep.p4().phi(), lep.jetOverlap.p4().pt(), lep.jetOverlap.p4().eta(), lep.jetOverlap.p4().phi()
238  lep.jetOverlapIdx = 1000 + self.discardedJets.index(lep.jetOverlap)
239 
240 
241  self.noIdCleanJetsAll, cleanLeptons = cleanJetsAndLeptons(self.jetsAllNoID, leptons, self.jetLepDR, self.jetLepArbitration)
242  self.noIdCleanJets = [j for j in self.noIdCleanJetsAll if abs(j.eta()) < self.cfg_ana.jetEtaCentral ]
243  self.noIdCleanJetsFwd = [j for j in self.noIdCleanJetsAll if abs(j.eta()) >= self.cfg_ana.jetEtaCentral ]
244  self.noIdDiscardedJets = [j for j in self.jetsAllNoID if j not in self.noIdCleanJetsAll]
245 
246 
247  photons = []
248  if hasattr(event, 'selectedPhotons'):
249  if self.cfg_ana.cleanJetsFromFirstPhoton:
250  photons = event.selectedPhotons[:1]
251  else:
252  photons = [ g for g in event.selectedPhotons ]
253 
254  self.gamma_cleanJetaAll = []
255  self.gamma_noIdCleanJetsAll = []
256 
257  if self.cleanFromLepAndGammaSimultaneously:
258  self.gamma_cleanJetsAll = cleanNearestJetOnly(jetsEtaCut, photons+leptons, self.jetGammaLepDR)
259  self.gamma_noIdCleanJetsAll = cleanNearestJetOnly(self.jetsAllNoID, photons+leptons, self.jetGammaLepDR)
260  else:
261  self.gamma_cleanJetsAll = cleanNearestJetOnly(self.cleanJetsAll, photons, self.jetGammaDR)
262  self.gamma_noIdCleanJetsAll = cleanNearestJetOnly(self.noIdCleanJetsAll, photons, self.jetGammaDR)
263 
264  self.gamma_cleanJets = [j for j in self.gamma_cleanJetsAll if abs(j.eta()) < self.cfg_ana.jetEtaCentral ]
265  self.gamma_cleanJetsFwd = [j for j in self.gamma_cleanJetsAll if abs(j.eta()) >= self.cfg_ana.jetEtaCentral ]
266 
267  self.gamma_noIdCleanJets = [j for j in self.gamma_noIdCleanJetsAll if abs(j.eta()) < self.cfg_ana.jetEtaCentral ]
268  self.gamma_noIdCleanJetsFwd = [j for j in self.gamma_noIdCleanJetsAll if abs(j.eta()) >= self.cfg_ana.jetEtaCentral ]
269 
270 
271  if self.cfg_ana.alwaysCleanPhotons:
272  self.cleanJets = self.gamma_cleanJets
273  self.cleanJetsAll = self.gamma_cleanJetsAll
274  self.cleanJetsFwd = self.gamma_cleanJetsFwd
275  #
276  self.noIdCleanJets = self.gamma_noIdCleanJets
277  self.noIdCleanJetsAll = self.gamma_noIdCleanJetsAll
278  self.noIdCleanJetsFwd = self.gamma_noIdCleanJetsFwd
279 
280 
281  self.cleanJetsFailIdAll = []
282  for jet in self.noIdCleanJetsAll:
283  if not self.testJetID( jet ):
284  self.cleanJetsFailIdAll.append(jet)
285 
286  self.cleanJetsFailId = [j for j in self.cleanJetsFailIdAll if abs(j.eta()) < self.cfg_ana.jetEtaCentral ]
287 
288 
289  self.gamma_cleanJetsFailIdAll = []
290  for jet in self.gamma_noIdCleanJetsAll:
291  if not self.testJetID( jet ):
292  self.gamma_cleanJetsFailIdAll.append(jet)
293 
294  self.gamma_cleanJetsFailId = [j for j in self.gamma_cleanJetsFailIdAll if abs(j.eta()) < self.cfg_ana.jetEtaCentral ]
295 
296 
297  incleptons = event.inclusiveLeptons if hasattr(event, 'inclusiveLeptons') else event.selectedLeptons
298  jlpairs = matchObjectCollection(incleptons, allJets, self.jetLepDR**2)
299 
300  for jet in allJets:
301  jet.leptons = [l for l in jlpairs if jlpairs[l] == jet ]
302  for lep in incleptons:
303  jet = jlpairs[lep]
304  if jet is None:
305  setattr(lep,"jet"+self.cfg_ana.collectionPostFix,lep)
306  else:
307  setattr(lep,"jet"+self.cfg_ana.collectionPostFix,jet)
308 
309  taus = getattr(event,'selectedTaus',[])
310  jtaupairs = matchObjectCollection( taus, allJets, self.jetLepDR**2)
311 
312  for jet in allJets:
313  jet.taus = [l for l in jtaupairs if jtaupairs[l] == jet ]
314  for tau in taus:
315  setattr(tau,"jet"+self.cfg_ana.collectionPostFix,jtaupairs[tau])
316 
317  #MC stuff
318  if self.cfg_comp.isMC:
319  self.deltaMetFromJetSmearing = [0, 0]
320  for j in self.cleanJetsAll:
321  if hasattr(j, 'deltaMetFromJetSmearing'):
322  self.deltaMetFromJetSmearing[0] += j.deltaMetFromJetSmearing[0]
323  self.deltaMetFromJetSmearing[1] += j.deltaMetFromJetSmearing[1]
324 
325  self.cleanGenJets = cleanNearestJetOnly(self.genJets, leptons, self.jetLepDR)
326 
327  if self.cfg_ana.cleanGenJetsFromPhoton:
328  self.cleanGenJets = cleanNearestJetOnly(self.cleanGenJets, photons, self.jetLepDR)
329 
330  if getattr(self.cfg_ana, 'attachNeutrinos', True) and hasattr(self.cfg_ana,"genNuSelection") :
331  jetNus=[x for x in event.genParticles if abs(x.pdgId()) in [12,14,16] and self.cfg_ana.genNuSelection(x) ]
332  pairs= matchObjectCollection (jetNus, self.genJets, 0.4**2)
333 
334  for (nu,genJet) in pairs.items() :
335  if genJet is not None :
336  if not hasattr(genJet,"nu") :
337  genJet.nu=nu.p4()
338  else :
339  genJet.nu+=nu.p4()
340 
341 
342  if self.cfg_ana.do_mc_match:
343  self.jetFlavour(event)
344 
345  if hasattr(event,"jets"+self.cfg_ana.collectionPostFix): raise RuntimeError("Event already contains a jet collection with the following postfix: "+self.cfg_ana.collectionPostFix)
346  setattr(event,"rho" +self.cfg_ana.collectionPostFix, self.rho )
347  setattr(event,"deltaMetFromJEC" +self.cfg_ana.collectionPostFix, self.deltaMetFromJEC )
348  setattr(event,"type1METCorr" +self.cfg_ana.collectionPostFix, self.type1METCorr )
349  setattr(event,"allJetsUsedForMET" +self.cfg_ana.collectionPostFix, self.allJetsUsedForMET )
350  setattr(event,"jets" +self.cfg_ana.collectionPostFix, self.jets )
351  setattr(event,"jetsFailId" +self.cfg_ana.collectionPostFix, self.jetsFailId )
352  setattr(event,"jetsAllNoID" +self.cfg_ana.collectionPostFix, self.jetsAllNoID )
353  setattr(event,"jetsIdOnly" +self.cfg_ana.collectionPostFix, self.jetsIdOnly )
354  setattr(event,"cleanJetsAll" +self.cfg_ana.collectionPostFix, self.cleanJetsAll )
355  setattr(event,"cleanJets" +self.cfg_ana.collectionPostFix, self.cleanJets )
356  setattr(event,"cleanJetsFwd" +self.cfg_ana.collectionPostFix, self.cleanJetsFwd )
357  setattr(event,"cleanJetsFailIdAll" +self.cfg_ana.collectionPostFix, self.cleanJetsFailIdAll )
358  setattr(event,"cleanJetsFailId" +self.cfg_ana.collectionPostFix, self.cleanJetsFailId )
359  setattr(event,"discardedJets" +self.cfg_ana.collectionPostFix, self.discardedJets )
360  setattr(event,"gamma_cleanJetsAll" +self.cfg_ana.collectionPostFix, self.gamma_cleanJetsAll )
361  setattr(event,"gamma_cleanJets" +self.cfg_ana.collectionPostFix, self.gamma_cleanJets )
362  setattr(event,"gamma_cleanJetsFwd" +self.cfg_ana.collectionPostFix, self.gamma_cleanJetsFwd )
363  setattr(event,"gamma_cleanJetsFailIdAll" +self.cfg_ana.collectionPostFix, self.gamma_cleanJetsFailIdAll )
364  setattr(event,"gamma_cleanJetsFailId" +self.cfg_ana.collectionPostFix, self.gamma_cleanJetsFailId )
365 
366 
367  if self.cfg_comp.isMC:
368  setattr(event,"deltaMetFromJetSmearing"+self.cfg_ana.collectionPostFix, self.deltaMetFromJetSmearing)
369  setattr(event,"cleanGenJets" +self.cfg_ana.collectionPostFix, self.cleanGenJets )
370  setattr(event,"genJets" +self.cfg_ana.collectionPostFix, self.genJets )
371  if self.cfg_ana.do_mc_match:
372  setattr(event,"bqObjects" +self.cfg_ana.collectionPostFix, self.bqObjects )
373  setattr(event,"cqObjects" +self.cfg_ana.collectionPostFix, self.cqObjects )
374  setattr(event,"partons" +self.cfg_ana.collectionPostFix, self.partons )
375  setattr(event,"heaviestQCDFlavour" +self.cfg_ana.collectionPostFix, self.heaviestQCDFlavour )
376 
377 
378  return True
379 
380 
381 
def matchObjectCollection
Definition: deltar.py:151
Definition: Jet.py:1
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def cleanNearestJetOnly(jets, leptons, deltaR)
Definition: JetAnalyzer.py:14
def cleanJetsAndLeptons(jets, leptons, deltaR, arbitration)
Definition: JetAnalyzer.py:26

◆ smearJets()

def objects.JetAnalyzer.JetAnalyzer.smearJets (   self,
  event,
  jets 
)

Definition at line 448 of file JetAnalyzer.py.

References funct.abs(), objects.JetAnalyzer.JetAnalyzer.addJERShifts, SiStripPI.max, objects.JetAnalyzer.JetAnalyzer.shiftJER, objects.JetAnalyzer.shiftJERfactor(), and objects.JetAnalyzer.JetAnalyzer.smearJets.

448  def smearJets(self, event, jets):
449  # https://twiki.cern.ch/twiki/bin/viewauth/CMS/TWikiTopRefSyst#Jet_energy_resolution
450  for jet in jets:
451  gen = jet.mcJet
452  if gen != None:
453  genpt, jetpt, aeta = gen.pt(), jet.pt(), abs(jet.eta())
454  # from https://twiki.cern.ch/twiki/bin/view/CMS/JetResolution
455  #8 TeV tables
456  factor = shiftJERfactor(self.shiftJER, aeta)
457  ptscale = max(0.0, (jetpt + (factor-1)*(jetpt-genpt))/jetpt)
458  #print "get with pt %.1f (gen pt %.1f, ptscale = %.3f)" % (jetpt,genpt,ptscale)
459  jet.deltaMetFromJetSmearing = [ -(ptscale-1)*jet.rawFactor()*jet.px(), -(ptscale-1)*jet.rawFactor()*jet.py() ]
460  if ptscale != 0:
461  jet.setP4(jet.p4()*ptscale)
462  # leave the uncorrected unchanged for sync
463  jet.setRawFactor(jet.rawFactor()/ptscale)
464  #else: print "jet with pt %.1d, eta %.2f is unmatched" % (jet.pt(), jet.eta())
465  if (self.shiftJER==0) and (self.addJERShifts):
466  setattr(jet, "corrJER", ptscale )
467  factorJERUp= shiftJERfactor(1, aeta)
468  ptscaleJERUp = max(0.0, (jetpt + (factorJERUp-1)*(jetpt-genpt))/jetpt)
469  setattr(jet, "corrJERUp", ptscaleJERUp)
470  factorJERDown= shiftJERfactor(-1, aeta)
471  ptscaleJERDown = max(0.0, (jetpt + (factorJERDown-1)*(jetpt-genpt))/jetpt)
472  setattr(jet, "corrJERDown", ptscaleJERDown)
473 
474 
475 
476 
477 
478 setattr(JetAnalyzer,"defaultConfig", cfg.Analyzer(
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def shiftJERfactor(JERShift, aeta)
Definition: JetAnalyzer.py:53

◆ testJetID()

def objects.JetAnalyzer.JetAnalyzer.testJetID (   self,
  jet 
)

Definition at line 382 of file JetAnalyzer.py.

References analyzer.Analyzer.cfg_ana, and objects.JetAnalyzer.JetAnalyzer.doPuId.

382  def testJetID(self, jet):
383  jet.puJetIdPassed = jet.puJetId()
384  jet.pfJetIdPassed = jet.jetID('POG_PFID_Loose')
385  if self.cfg_ana.relaxJetId:
386  return True
387  else:
388  return jet.pfJetIdPassed and (jet.puJetIdPassed or not(self.doPuId))
389 

◆ testJetNoID()

def objects.JetAnalyzer.JetAnalyzer.testJetNoID (   self,
  jet 
)

Definition at line 390 of file JetAnalyzer.py.

References funct.abs(), and analyzer.Analyzer.cfg_ana.

390  def testJetNoID( self, jet ):
391  # 2 is loose pile-up jet id
392  return jet.pt() > self.cfg_ana.jetPt and \
393  abs( jet.eta() ) < self.cfg_ana.jetEta;
394 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

Member Data Documentation

◆ addJECShifts

objects.JetAnalyzer.JetAnalyzer.addJECShifts
static

Definition at line 500 of file JetAnalyzer.py.

Referenced by objects.JetAnalyzer.JetAnalyzer.__init__().

◆ addJERShifts

objects.JetAnalyzer.JetAnalyzer.addJERShifts
static

◆ allJetsUsedForMET

objects.JetAnalyzer.JetAnalyzer.allJetsUsedForMET

Definition at line 162 of file JetAnalyzer.py.

◆ alwaysCleanPhotons

objects.JetAnalyzer.JetAnalyzer.alwaysCleanPhotons
static

Definition at line 511 of file JetAnalyzer.py.

◆ applyL2L3Residual

objects.JetAnalyzer.JetAnalyzer.applyL2L3Residual
static

Definition at line 497 of file JetAnalyzer.py.

◆ attachNeutrinos

objects.JetAnalyzer.JetAnalyzer.attachNeutrinos
static

Definition at line 517 of file JetAnalyzer.py.

◆ bqObjects

objects.JetAnalyzer.JetAnalyzer.bqObjects

Definition at line 404 of file JetAnalyzer.py.

◆ calculateSeparateCorrections

objects.JetAnalyzer.JetAnalyzer.calculateSeparateCorrections
static

Definition at line 504 of file JetAnalyzer.py.

◆ calculateType1METCorrection

objects.JetAnalyzer.JetAnalyzer.calculateType1METCorrection
static

Definition at line 505 of file JetAnalyzer.py.

◆ checkLeptonPFOverlap

objects.JetAnalyzer.JetAnalyzer.checkLeptonPFOverlap
static

Definition at line 495 of file JetAnalyzer.py.

◆ class_object

objects.JetAnalyzer.JetAnalyzer.class_object
static

Definition at line 479 of file JetAnalyzer.py.

Referenced by config.Analyzer.build_name(), and config.Service.build_name().

◆ cleanFromLepAndGammaSimultaneously

objects.JetAnalyzer.JetAnalyzer.cleanFromLepAndGammaSimultaneously
static

Definition at line 515 of file JetAnalyzer.py.

◆ cleanGenJets

objects.JetAnalyzer.JetAnalyzer.cleanGenJets

Definition at line 325 of file JetAnalyzer.py.

◆ cleanGenJetsFromPhoton

objects.JetAnalyzer.JetAnalyzer.cleanGenJetsFromPhoton
static

Definition at line 513 of file JetAnalyzer.py.

◆ cleanJets

objects.JetAnalyzer.JetAnalyzer.cleanJets

Definition at line 225 of file JetAnalyzer.py.

◆ cleanJetsAll

objects.JetAnalyzer.JetAnalyzer.cleanJetsAll

Definition at line 273 of file JetAnalyzer.py.

◆ cleanJetsFailId

objects.JetAnalyzer.JetAnalyzer.cleanJetsFailId

Definition at line 286 of file JetAnalyzer.py.

◆ cleanJetsFailIdAll

objects.JetAnalyzer.JetAnalyzer.cleanJetsFailIdAll

Jet Id, after jet/lepton cleaning.

Definition at line 281 of file JetAnalyzer.py.

◆ cleanJetsFromFirstPhoton

objects.JetAnalyzer.JetAnalyzer.cleanJetsFromFirstPhoton
static

Definition at line 508 of file JetAnalyzer.py.

◆ cleanJetsFromIsoTracks

objects.JetAnalyzer.JetAnalyzer.cleanJetsFromIsoTracks
static

Definition at line 510 of file JetAnalyzer.py.

◆ cleanJetsFromTaus

objects.JetAnalyzer.JetAnalyzer.cleanJetsFromTaus
static

Definition at line 509 of file JetAnalyzer.py.

◆ cleanJetsFwd

objects.JetAnalyzer.JetAnalyzer.cleanJetsFwd

Definition at line 226 of file JetAnalyzer.py.

◆ cleanSelectedLeptons

objects.JetAnalyzer.JetAnalyzer.cleanSelectedLeptons
static

Definition at line 489 of file JetAnalyzer.py.

◆ collectionPostFix

objects.JetAnalyzer.JetAnalyzer.collectionPostFix
static

Definition at line 519 of file JetAnalyzer.py.

◆ copyJetsByValue

objects.JetAnalyzer.JetAnalyzer.copyJetsByValue
static

Definition at line 481 of file JetAnalyzer.py.

◆ cqObjects

objects.JetAnalyzer.JetAnalyzer.cqObjects

Definition at line 405 of file JetAnalyzer.py.

◆ deltaMetFromJEC

objects.JetAnalyzer.JetAnalyzer.deltaMetFromJEC

Read jets, if necessary recalibrate and shift MET.

Definition at line 143 of file JetAnalyzer.py.

◆ deltaMetFromJetSmearing

objects.JetAnalyzer.JetAnalyzer.deltaMetFromJetSmearing

Associate jets to leptons.

Associate jets to taus

Definition at line 319 of file JetAnalyzer.py.

◆ discardedJets

objects.JetAnalyzer.JetAnalyzer.discardedJets

Definition at line 227 of file JetAnalyzer.py.

◆ do_mc_match

objects.JetAnalyzer.JetAnalyzer.do_mc_match
static

Definition at line 512 of file JetAnalyzer.py.

◆ doJEC

objects.JetAnalyzer.JetAnalyzer.doJEC

Definition at line 82 of file JetAnalyzer.py.

◆ doPuId

objects.JetAnalyzer.JetAnalyzer.doPuId
static

Definition at line 493 of file JetAnalyzer.py.

Referenced by objects.JetAnalyzer.JetAnalyzer.testJetID().

◆ doQG

objects.JetAnalyzer.JetAnalyzer.doQG
static

Definition at line 494 of file JetAnalyzer.py.

◆ gamma_cleanJetaAll

objects.JetAnalyzer.JetAnalyzer.gamma_cleanJetaAll

Clean Jets from photons (first cleaning, then Jet Id)

Definition at line 254 of file JetAnalyzer.py.

◆ gamma_cleanJets

objects.JetAnalyzer.JetAnalyzer.gamma_cleanJets

Definition at line 264 of file JetAnalyzer.py.

◆ gamma_cleanJetsAll

objects.JetAnalyzer.JetAnalyzer.gamma_cleanJetsAll

Definition at line 258 of file JetAnalyzer.py.

◆ gamma_cleanJetsFailId

objects.JetAnalyzer.JetAnalyzer.gamma_cleanJetsFailId

Definition at line 294 of file JetAnalyzer.py.

◆ gamma_cleanJetsFailIdAll

objects.JetAnalyzer.JetAnalyzer.gamma_cleanJetsFailIdAll

Jet Id, after jet/photon cleaning.

Definition at line 289 of file JetAnalyzer.py.

◆ gamma_cleanJetsFwd

objects.JetAnalyzer.JetAnalyzer.gamma_cleanJetsFwd

Definition at line 265 of file JetAnalyzer.py.

◆ gamma_noIdCleanJets

objects.JetAnalyzer.JetAnalyzer.gamma_noIdCleanJets

Definition at line 267 of file JetAnalyzer.py.

◆ gamma_noIdCleanJetsAll

objects.JetAnalyzer.JetAnalyzer.gamma_noIdCleanJetsAll

Definition at line 255 of file JetAnalyzer.py.

◆ gamma_noIdCleanJetsFwd

objects.JetAnalyzer.JetAnalyzer.gamma_noIdCleanJetsFwd

Definition at line 268 of file JetAnalyzer.py.

◆ genJetCol

objects.JetAnalyzer.JetAnalyzer.genJetCol
static

Definition at line 482 of file JetAnalyzer.py.

◆ genJets

objects.JetAnalyzer.JetAnalyzer.genJets

Definition at line 166 of file JetAnalyzer.py.

Referenced by objects.JetAnalyzer.JetAnalyzer.matchJets().

◆ genNuSelection

objects.JetAnalyzer.JetAnalyzer.genNuSelection
static

Definition at line 518 of file JetAnalyzer.py.

◆ heaviestQCDFlavour

objects.JetAnalyzer.JetAnalyzer.heaviestQCDFlavour

Definition at line 428 of file JetAnalyzer.py.

◆ jecPath

objects.JetAnalyzer.JetAnalyzer.jecPath
static

Definition at line 503 of file JetAnalyzer.py.

◆ jetCol

objects.JetAnalyzer.JetAnalyzer.jetCol
static

Definition at line 480 of file JetAnalyzer.py.

◆ jetEta

objects.JetAnalyzer.JetAnalyzer.jetEta
static

Definition at line 485 of file JetAnalyzer.py.

◆ jetEtaCentral

objects.JetAnalyzer.JetAnalyzer.jetEtaCentral
static

Definition at line 486 of file JetAnalyzer.py.

◆ jetGammaDR

objects.JetAnalyzer.JetAnalyzer.jetGammaDR
static

Definition at line 514 of file JetAnalyzer.py.

◆ jetGammaLepDR

objects.JetAnalyzer.JetAnalyzer.jetGammaLepDR
static

Definition at line 516 of file JetAnalyzer.py.

◆ jetLepArbitration

objects.JetAnalyzer.JetAnalyzer.jetLepArbitration
static

Definition at line 488 of file JetAnalyzer.py.

◆ jetLepDR

objects.JetAnalyzer.JetAnalyzer.jetLepDR
static

Definition at line 487 of file JetAnalyzer.py.

◆ jetPt

objects.JetAnalyzer.JetAnalyzer.jetPt
static

Definition at line 484 of file JetAnalyzer.py.

◆ jetReCalibrator

objects.JetAnalyzer.JetAnalyzer.jetReCalibrator

Definition at line 94 of file JetAnalyzer.py.

◆ jets

objects.JetAnalyzer.JetAnalyzer.jets

Sort Jets by pT.

Apply jet selection

Definition at line 190 of file JetAnalyzer.py.

◆ jetsAllNoID

objects.JetAnalyzer.JetAnalyzer.jetsAllNoID

Definition at line 192 of file JetAnalyzer.py.

◆ jetsFailId

objects.JetAnalyzer.JetAnalyzer.jetsFailId

Definition at line 191 of file JetAnalyzer.py.

◆ jetsIdOnly

objects.JetAnalyzer.JetAnalyzer.jetsIdOnly

Definition at line 193 of file JetAnalyzer.py.

◆ lepPtMin

objects.JetAnalyzer.JetAnalyzer.lepPtMin

Definition at line 98 of file JetAnalyzer.py.

◆ lepSelCut

objects.JetAnalyzer.JetAnalyzer.lepSelCut
static

Definition at line 491 of file JetAnalyzer.py.

◆ minLepPt

objects.JetAnalyzer.JetAnalyzer.minLepPt
static

Definition at line 490 of file JetAnalyzer.py.

◆ noIdCleanJets

objects.JetAnalyzer.JetAnalyzer.noIdCleanJets

First cleaning, then Jet Id.

Definition at line 242 of file JetAnalyzer.py.

◆ noIdCleanJetsAll

objects.JetAnalyzer.JetAnalyzer.noIdCleanJetsAll

Definition at line 277 of file JetAnalyzer.py.

◆ noIdCleanJetsFwd

objects.JetAnalyzer.JetAnalyzer.noIdCleanJetsFwd

Definition at line 243 of file JetAnalyzer.py.

◆ noIdDiscardedJets

objects.JetAnalyzer.JetAnalyzer.noIdDiscardedJets

Definition at line 244 of file JetAnalyzer.py.

◆ partons

objects.JetAnalyzer.JetAnalyzer.partons

Definition at line 407 of file JetAnalyzer.py.

◆ qglcalc

objects.JetAnalyzer.JetAnalyzer.qglcalc

Definition at line 112 of file JetAnalyzer.py.

◆ recalibrateJets

objects.JetAnalyzer.JetAnalyzer.recalibrateJets
static

Definition at line 496 of file JetAnalyzer.py.

Referenced by objects.JetAnalyzer.JetAnalyzer.__init__().

◆ recalibrationType

objects.JetAnalyzer.JetAnalyzer.recalibrationType
static

Definition at line 498 of file JetAnalyzer.py.

◆ relaxJetId

objects.JetAnalyzer.JetAnalyzer.relaxJetId
static

Definition at line 492 of file JetAnalyzer.py.

◆ rho

objects.JetAnalyzer.JetAnalyzer.rho
static

◆ shiftJEC

objects.JetAnalyzer.JetAnalyzer.shiftJEC
static

Definition at line 499 of file JetAnalyzer.py.

Referenced by objects.JetAnalyzer.JetAnalyzer.__init__().

◆ shiftJER

objects.JetAnalyzer.JetAnalyzer.shiftJER
static

◆ smearJets

objects.JetAnalyzer.JetAnalyzer.smearJets
static

Definition at line 501 of file JetAnalyzer.py.

Referenced by objects.JetAnalyzer.JetAnalyzer.smearJets().

◆ type1METCorr

objects.JetAnalyzer.JetAnalyzer.type1METCorr

Definition at line 144 of file JetAnalyzer.py.

◆ type1METParams

objects.JetAnalyzer.JetAnalyzer.type1METParams
static