CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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__
 
def beginLoop
 
def declareHandles
 
def jetFlavour
 
def matchJets
 
def process
 
def smearJets
 
def testJetID
 
def testJetNoID
 

Public Attributes

 addJERShifts
 
 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
 
 jetGammaDR
 
 jetGammaLepDR
 
 jetLepArbitration
 
 jetLepDR
 
 jetReCalibrator
 
 jets
 Sort Jets by pT. More...
 
 jetsAllNoID
 
 jetsFailId
 
 jetsIdOnly
 
 lepPtMin
 
 noIdCleanJets
 First cleaning, then Jet Id. More...
 
 noIdCleanJetsAll
 
 noIdCleanJetsFwd
 
 noIdDiscardedJets
 
 partons
 
 qglcalc
 
 rho
 
 shiftJEC
 
 shiftJER
 
 type1METCorr
 

Static Public Attributes

 addJECShifts = False,
 
int addJERShifts = 0
 
 alwaysCleanPhotons = False,
 
string applyL2L3Residual = 'Data'
 
 attachNeutrinos = True,
 
 calculateSeparateCorrections = False,
 
 calculateType1METCorrection = False,
 
 checkLeptonPFOverlap = True,
 
 class_object = JetAnalyzer,
 
 cleanFromLepAndGammaSimultaneously = False,
 
 cleanGenJetsFromPhoton = False,
 
 cleanJetsFromFirstPhoton = False,
 
 cleanJetsFromIsoTracks = False,
 
 cleanJetsFromTaus = False,
 
 cleanSelectedLeptons = True,
 
string collectionPostFix = ""
 
 copyJetsByValue = False,
 
 do_mc_match = True,
 
 doPuId = False,
 
 doQG = False,
 
string genJetCol = 'slimmedGenJets'
 
 genNuSelection = lambdanu:True,
 
string jecPath = ""
 
string jetCol = 'slimmedJets'
 
float jetEta = 4.7
 
float jetEtaCentral = 2.4
 
float jetGammaDR = 0.4
 
float jetGammaLepDR = 0.4
 
tuple jetLepArbitration = (lambda jet,lepton : lepton)
 
float jetLepDR = 0.4
 
int jetPt = 25
 
 lepSelCut = lambdalep:True,
 
int minLepPt = 10
 
 recalibrateJets = False,
 
string recalibrationType = "AK4PFchs"
 
 relaxJetId = False,
 
tuple rho = ('fixedGridRhoFastjetAll','','')
 
int shiftJEC = 0
 
int shiftJER = 0
 
 smearJets = True,
 
dictionary type1METParams = { 'jetPtThreshold':15., 'skipEMfractionThreshold':0.9, 'skipMuons':True }
 

Detailed Description

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

Definition at line 67 of file JetAnalyzer.py.

Constructor & Destructor Documentation

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

Definition at line 69 of file JetAnalyzer.py.

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

Member Function Documentation

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

Definition at line 123 of file JetAnalyzer.py.

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

Definition at line 115 of file JetAnalyzer.py.

References core.AutoHandle.AutoHandle.handles, core.Analyzer.Analyzer.handles, and HTTP.RequestManager.handles.

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

Definition at line 395 of file JetAnalyzer.py.

References funct.abs().

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

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

Definition at line 126 of file JetAnalyzer.py.

References core.AutoHandle.AutoHandle.handles, core.Analyzer.Analyzer.handles, HTTP.RequestManager.handles, and core.Analyzer.Analyzer.readCollections().

127  def process(self, event):
128  self.readCollections( event.input )
129  rho = float(self.handles['rho'].product()[0])
130  self.rho = rho
131 
132  ## Read jets, if necessary recalibrate and shift MET
133  if self.cfg_ana.copyJetsByValue:
134  import ROOT
135  #from ROOT.heppy import JetUtils
136  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
137  else:
138  allJets = map(Jet, self.handles['jets'].product())
139 
140  #set dummy MC flavour for all jets in case we want to ntuplize discarded jets later
141  for jet in allJets:
142  jet.mcFlavour = 0
144  self.deltaMetFromJEC = [0.,0.]
145  self.type1METCorr = [0.,0.,0.]
146 # print "before. rho",self.rho,self.cfg_ana.collectionPostFix,'allJets len ',len(allJets),'pt', [j.pt() for j in allJets]
147  if self.doJEC:
148  if not self.recalibrateJets: # check point that things won't change
149  jetsBefore = [ (j.pt(),j.eta(),j.phi(),j.rawFactor()) for j in allJets ]
150  self.jetReCalibrator.correctAll(allJets, rho, delta=self.shiftJEC,
151  addCorr=True, addShifts=self.addJECShifts,
152  metShift=self.deltaMetFromJEC, type1METCorr=self.type1METCorr )
153  if not self.recalibrateJets:
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))
157  else:
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))
163  self.allJetsUsedForMET = allJets
164 # print "after. rho",self.rho,self.cfg_ana.collectionPostFix,'allJets len ',len(allJets),'pt', [j.pt() for j in allJets]
165 
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):
170  gj.index = igj
171 # self.matchJets(event, allJets)
172  self.matchJets(event, [ j for j in allJets if j.pt()>self.cfg_ana.jetPt ]) # To match only jets above chosen threshold
173  if getattr(self.cfg_ana, 'smearJets', False):
174  self.smearJets(event, allJets)
175 
176 
177 
178 
179  ##Sort Jets by pT
180  allJets.sort(key = lambda j : j.pt(), reverse = True)
181 
182  leptons = []
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
189 
190  ## Apply jet selection
191  self.jets = []
192  self.jetsFailId = []
193  self.jetsAllNoID = []
194  self.jetsIdOnly = []
195  for jet in allJets:
196  #Check if lepton and jet have overlapping PF candidates
197  leps_with_overlaps = []
198  if getattr(self.cfg_ana, 'checkLeptonPFOverlap', True):
199  for i in range(jet.numberOfSourceCandidatePtrs()):
200  p1 = jet.sourceCandidatePtr(i) #Ptr<Candidate> p1
201  for lep in leptons:
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()
205  if has_overlaps:
206  leps_with_overlaps += [lep]
207  if len(leps_with_overlaps)>0:
208  for lep in leps_with_overlaps:
209  lep.jetOverlap = jet
210  if self.testJetNoID( jet ):
211  self.jetsAllNoID.append(jet)
212  if(self.cfg_ana.doQG):
213  jet.qgl_calc = self.qglcalc.computeQGLikelihood
214  jet.qgl_rho = rho
215  if self.testJetID( jet ):
216  self.jets.append(jet)
217  self.jetsIdOnly.append(jet)
218  else:
219  self.jetsFailId.append(jet)
220  elif self.testJetID (jet ):
221  self.jetsIdOnly.append(jet)
222 
223  jetsEtaCut = [j for j in self.jets if abs(j.eta()) < self.cfg_ana.jetEta ]
224  self.cleanJetsAll, cleanLeptons = cleanJetsAndLeptons(jetsEtaCut, leptons, self.jetLepDR, self.jetLepArbitration)
226  self.cleanJets = [j for j in self.cleanJetsAll if abs(j.eta()) < self.cfg_ana.jetEtaCentral ]
227  self.cleanJetsFwd = [j for j in self.cleanJetsAll if abs(j.eta()) >= self.cfg_ana.jetEtaCentral ]
228  self.discardedJets = [j for j in self.jets if j not in self.cleanJetsAll]
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 ]
232  for lep in leptons:
233  if hasattr(lep, "jetOverlap"):
234  if lep.jetOverlap in self.cleanJetsAll:
235  #print "overlap reco", lep.p4().pt(), lep.p4().eta(), lep.p4().phi(), lep.jetOverlap.p4().pt(), lep.jetOverlap.p4().eta(), lep.jetOverlap.p4().phi()
236  lep.jetOverlapIdx = self.cleanJetsAll.index(lep.jetOverlap)
237  elif lep.jetOverlap in self.discardedJets:
238  #print "overlap discarded", lep.p4().pt(), lep.p4().eta(), lep.p4().phi(), lep.jetOverlap.p4().pt(), lep.jetOverlap.p4().eta(), lep.jetOverlap.p4().phi()
239  lep.jetOverlapIdx = 1000 + self.discardedJets.index(lep.jetOverlap)
240 
241  ## First cleaning, then Jet Id
242  self.noIdCleanJetsAll, cleanLeptons = cleanJetsAndLeptons(self.jetsAllNoID, leptons, self.jetLepDR, self.jetLepArbitration)
243  self.noIdCleanJets = [j for j in self.noIdCleanJetsAll if abs(j.eta()) < self.cfg_ana.jetEtaCentral ]
244  self.noIdCleanJetsFwd = [j for j in self.noIdCleanJetsAll if abs(j.eta()) >= self.cfg_ana.jetEtaCentral ]
245  self.noIdDiscardedJets = [j for j in self.jetsAllNoID if j not in self.noIdCleanJetsAll]
246 
247  ## Clean Jets from photons (first cleaning, then Jet Id)
248  photons = []
249  if hasattr(event, 'selectedPhotons'):
250  if self.cfg_ana.cleanJetsFromFirstPhoton:
251  photons = event.selectedPhotons[:1]
252  else:
253  photons = [ g for g in event.selectedPhotons ]
256  self.gamma_noIdCleanJetsAll = []
257 
259  self.gamma_cleanJetsAll = cleanNearestJetOnly(jetsEtaCut, photons+leptons, self.jetGammaLepDR)
260  self.gamma_noIdCleanJetsAll = cleanNearestJetOnly(self.jetsAllNoID, photons+leptons, self.jetGammaLepDR)
261  else:
265  self.gamma_cleanJets = [j for j in self.gamma_cleanJetsAll if abs(j.eta()) < self.cfg_ana.jetEtaCentral ]
266  self.gamma_cleanJetsFwd = [j for j in self.gamma_cleanJetsAll if abs(j.eta()) >= self.cfg_ana.jetEtaCentral ]
268  self.gamma_noIdCleanJets = [j for j in self.gamma_noIdCleanJetsAll if abs(j.eta()) < self.cfg_ana.jetEtaCentral ]
269  self.gamma_noIdCleanJetsFwd = [j for j in self.gamma_noIdCleanJetsAll if abs(j.eta()) >= self.cfg_ana.jetEtaCentral ]
270  ###
271 
272  if self.cfg_ana.alwaysCleanPhotons:
274  self.cleanJetsAll = self.gamma_cleanJetsAll
275  self.cleanJetsFwd = self.gamma_cleanJetsFwd
276  #
280 
281  ## Jet Id, after jet/lepton cleaning
282  self.cleanJetsFailIdAll = []
283  for jet in self.noIdCleanJetsAll:
284  if not self.testJetID( jet ):
285  self.cleanJetsFailIdAll.append(jet)
287  self.cleanJetsFailId = [j for j in self.cleanJetsFailIdAll if abs(j.eta()) < self.cfg_ana.jetEtaCentral ]
288 
289  ## Jet Id, after jet/photon cleaning
290  self.gamma_cleanJetsFailIdAll = []
291  for jet in self.gamma_noIdCleanJetsAll:
292  if not self.testJetID( jet ):
293  self.gamma_cleanJetsFailIdAll.append(jet)
295  self.gamma_cleanJetsFailId = [j for j in self.gamma_cleanJetsFailIdAll if abs(j.eta()) < self.cfg_ana.jetEtaCentral ]
296 
297  ## Associate jets to leptons
298  incleptons = event.inclusiveLeptons if hasattr(event, 'inclusiveLeptons') else event.selectedLeptons
299  jlpairs = matchObjectCollection(incleptons, allJets, self.jetLepDR**2)
300 
301  for jet in allJets:
302  jet.leptons = [l for l in jlpairs if jlpairs[l] == jet ]
303  for lep in incleptons:
304  jet = jlpairs[lep]
305  if jet is None:
306  setattr(lep,"jet"+self.cfg_ana.collectionPostFix,lep)
307  else:
308  setattr(lep,"jet"+self.cfg_ana.collectionPostFix,jet)
309  ## Associate jets to taus
310  taus = getattr(event,'selectedTaus',[])
311  jtaupairs = matchObjectCollection( taus, allJets, self.jetLepDR**2)
312 
313  for jet in allJets:
314  jet.taus = [l for l in jtaupairs if jtaupairs[l] == jet ]
315  for tau in taus:
316  setattr(tau,"jet"+self.cfg_ana.collectionPostFix,jtaupairs[tau])
317 
318  #MC stuff
319  if self.cfg_comp.isMC:
320  self.deltaMetFromJetSmearing = [0, 0]
321  for j in self.cleanJetsAll:
322  if hasattr(j, 'deltaMetFromJetSmearing'):
323  self.deltaMetFromJetSmearing[0] += j.deltaMetFromJetSmearing[0]
324  self.deltaMetFromJetSmearing[1] += j.deltaMetFromJetSmearing[1]
326  self.cleanGenJets = cleanNearestJetOnly(self.genJets, leptons, self.jetLepDR)
327 
328  if self.cfg_ana.cleanGenJetsFromPhoton:
329  self.cleanGenJets = cleanNearestJetOnly(self.cleanGenJets, photons, self.jetLepDR)
330 
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)
334 
335  for (nu,genJet) in pairs.items() :
336  if genJet is not None :
337  if not hasattr(genJet,"nu") :
338  genJet.nu=nu.p4()
339  else :
340  genJet.nu+=nu.p4()
341 
342 
343  if self.cfg_ana.do_mc_match:
344  self.jetFlavour(event)
345 
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 )
364  setattr(event,"gamma_cleanJetsFailIdAll" +self.cfg_ana.collectionPostFix, self.gamma_cleanJetsFailIdAll )
365  setattr(event,"gamma_cleanJetsFailId" +self.cfg_ana.collectionPostFix, self.gamma_cleanJetsFailId )
366 
367 
368  if self.cfg_comp.isMC:
369  setattr(event,"deltaMetFromJetSmearing"+self.cfg_ana.collectionPostFix, self.deltaMetFromJetSmearing)
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 )
377 
378 
379  return True
380 
381 
deltaMetFromJEC
Read jets, if necessary recalibrate and shift MET.
Definition: JetAnalyzer.py:143
uint16_t *__restrict__ id
gamma_cleanJetaAll
Clean Jets from photons (first cleaning, then Jet Id)
Definition: JetAnalyzer.py:254
cleanJetsFailIdAll
Jet Id, after jet/lepton cleaning.
Definition: JetAnalyzer.py:281
noIdCleanJets
First cleaning, then Jet Id.
Definition: JetAnalyzer.py:242
const uint16_t range(const Frame &aFrame)
def matchObjectCollection
Definition: deltar.py:151
deltaMetFromJetSmearing
Associate jets to leptons.
Definition: JetAnalyzer.py:319
Definition: Jet.py:1
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
if(conf_.getParameter< bool >("UseStripCablingDB"))
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
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
gamma_cleanJetsFailIdAll
Jet Id, after jet/photon cleaning.
Definition: JetAnalyzer.py:289
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.

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

Definition at line 382 of file JetAnalyzer.py.

References objects.JetAnalyzer.JetAnalyzer.doPuId.

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

Definition at line 390 of file JetAnalyzer.py.

References funct.abs().

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

Member Data Documentation

objects.JetAnalyzer.JetAnalyzer.addJECShifts = False,
static

Definition at line 500 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.addJERShifts

Definition at line 120 of file JetAnalyzer.py.

int objects.JetAnalyzer.JetAnalyzer.addJERShifts = 0
static

Definition at line 507 of file JetAnalyzer.py.

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

objects.JetAnalyzer.JetAnalyzer.allJetsUsedForMET

Definition at line 162 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.alwaysCleanPhotons = False,
static

Definition at line 511 of file JetAnalyzer.py.

string objects.JetAnalyzer.JetAnalyzer.applyL2L3Residual = 'Data'
static

Definition at line 497 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.attachNeutrinos = True,
static

Definition at line 517 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.bqObjects

Definition at line 404 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.calculateSeparateCorrections = False,
static

Definition at line 504 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.calculateType1METCorrection = False,
static

Definition at line 505 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.checkLeptonPFOverlap = True,
static

Definition at line 495 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.class_object = JetAnalyzer,
static

Definition at line 479 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.cleanFromLepAndGammaSimultaneously = False,
static

Definition at line 515 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.cleanGenJets

Definition at line 325 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.cleanGenJetsFromPhoton = False,
static

Definition at line 513 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.cleanJets

Definition at line 225 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.cleanJetsAll

Definition at line 273 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.cleanJetsFailId

Definition at line 286 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.cleanJetsFailIdAll

Jet Id, after jet/lepton cleaning.

Definition at line 281 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.cleanJetsFromFirstPhoton = False,
static

Definition at line 508 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.cleanJetsFromIsoTracks = False,
static

Definition at line 510 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.cleanJetsFromTaus = False,
static

Definition at line 509 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.cleanJetsFwd

Definition at line 226 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.cleanSelectedLeptons = True,
static

Definition at line 489 of file JetAnalyzer.py.

string objects.JetAnalyzer.JetAnalyzer.collectionPostFix = ""
static

Definition at line 519 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.copyJetsByValue = False,
static

Definition at line 481 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.cqObjects

Definition at line 405 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.deltaMetFromJEC

Read jets, if necessary recalibrate and shift MET.

Definition at line 143 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.deltaMetFromJetSmearing

Associate jets to leptons.

Associate jets to taus

Definition at line 319 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.discardedJets

Definition at line 227 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.do_mc_match = True,
static

Definition at line 512 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.doJEC

Definition at line 82 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.doPuId = False,
static

Definition at line 493 of file JetAnalyzer.py.

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

objects.JetAnalyzer.JetAnalyzer.doQG = False,
static

Definition at line 494 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.gamma_cleanJetaAll

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

Definition at line 254 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.gamma_cleanJets

Definition at line 264 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.gamma_cleanJetsAll

Definition at line 258 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.gamma_cleanJetsFailId

Definition at line 294 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.gamma_cleanJetsFailIdAll

Jet Id, after jet/photon cleaning.

Definition at line 289 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.gamma_cleanJetsFwd

Definition at line 265 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.gamma_noIdCleanJets

Definition at line 267 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.gamma_noIdCleanJetsAll

Definition at line 255 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.gamma_noIdCleanJetsFwd

Definition at line 268 of file JetAnalyzer.py.

string objects.JetAnalyzer.JetAnalyzer.genJetCol = 'slimmedGenJets'
static

Definition at line 482 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.genJets

Definition at line 166 of file JetAnalyzer.py.

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

objects.JetAnalyzer.JetAnalyzer.genNuSelection = lambdanu:True,
static

Definition at line 518 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.heaviestQCDFlavour

Definition at line 428 of file JetAnalyzer.py.

string objects.JetAnalyzer.JetAnalyzer.jecPath = ""
static

Definition at line 503 of file JetAnalyzer.py.

string objects.JetAnalyzer.JetAnalyzer.jetCol = 'slimmedJets'
static

Definition at line 480 of file JetAnalyzer.py.

float objects.JetAnalyzer.JetAnalyzer.jetEta = 4.7
static

Definition at line 485 of file JetAnalyzer.py.

float objects.JetAnalyzer.JetAnalyzer.jetEtaCentral = 2.4
static

Definition at line 486 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.jetGammaDR

Definition at line 100 of file JetAnalyzer.py.

float objects.JetAnalyzer.JetAnalyzer.jetGammaDR = 0.4
static

Definition at line 514 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.jetGammaLepDR

Definition at line 101 of file JetAnalyzer.py.

float objects.JetAnalyzer.JetAnalyzer.jetGammaLepDR = 0.4
static

Definition at line 516 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.jetLepArbitration

Definition at line 97 of file JetAnalyzer.py.

tuple objects.JetAnalyzer.JetAnalyzer.jetLepArbitration = (lambda jet,lepton : lepton)
static

Definition at line 488 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.jetLepDR

Definition at line 96 of file JetAnalyzer.py.

float objects.JetAnalyzer.JetAnalyzer.jetLepDR = 0.4
static

Definition at line 487 of file JetAnalyzer.py.

int objects.JetAnalyzer.JetAnalyzer.jetPt = 25
static

Definition at line 484 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.jetReCalibrator

Definition at line 94 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.jets

Sort Jets by pT.

Apply jet selection

Definition at line 190 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.jetsAllNoID

Definition at line 192 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.jetsFailId

Definition at line 191 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.jetsIdOnly

Definition at line 193 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.lepPtMin

Definition at line 98 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.lepSelCut = lambdalep:True,
static

Definition at line 491 of file JetAnalyzer.py.

int objects.JetAnalyzer.JetAnalyzer.minLepPt = 10
static

Definition at line 490 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.noIdCleanJets

First cleaning, then Jet Id.

Definition at line 242 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.noIdCleanJetsAll

Definition at line 277 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.noIdCleanJetsFwd

Definition at line 243 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.noIdDiscardedJets

Definition at line 244 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.partons

Definition at line 407 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.qglcalc

Definition at line 112 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.recalibrateJets = False,
static

Definition at line 496 of file JetAnalyzer.py.

string objects.JetAnalyzer.JetAnalyzer.recalibrationType = "AK4PFchs"
static

Definition at line 498 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.relaxJetId = False,
static

Definition at line 492 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.rho

Definition at line 129 of file JetAnalyzer.py.

Referenced by Lepton.Lepton.absIsoFromEA(), Muon.Muon.absIsoWithFSR(), Electron.Electron.absIsoWithFSR(), Photon.Photon.chargedHadronIso(), Electron.Electron.electronID(), Electron.Electron.mvaNonTrigV0(), Electron.Electron.mvaRun2(), Electron.Electron.mvaTrigNoIPV0(), Electron.Electron.mvaTrigV0(), Photon.Photon.neutralHadronIso(), and Photon.Photon.photonIso().

tuple objects.JetAnalyzer.JetAnalyzer.rho = ('fixedGridRhoFastjetAll','','')
static

Definition at line 483 of file JetAnalyzer.py.

Referenced by Lepton.Lepton.absIsoFromEA(), Muon.Muon.absIsoWithFSR(), Electron.Electron.absIsoWithFSR(), Photon.Photon.chargedHadronIso(), Electron.Electron.electronID(), Electron.Electron.mvaNonTrigV0(), Electron.Electron.mvaRun2(), Electron.Electron.mvaTrigNoIPV0(), Electron.Electron.mvaTrigV0(), Photon.Photon.neutralHadronIso(), and Photon.Photon.photonIso().

objects.JetAnalyzer.JetAnalyzer.shiftJEC

Definition at line 73 of file JetAnalyzer.py.

int objects.JetAnalyzer.JetAnalyzer.shiftJEC = 0
static

Definition at line 499 of file JetAnalyzer.py.

objects.JetAnalyzer.JetAnalyzer.shiftJER

Definition at line 119 of file JetAnalyzer.py.

int objects.JetAnalyzer.JetAnalyzer.shiftJER = 0
static

Definition at line 502 of file JetAnalyzer.py.

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

objects.JetAnalyzer.JetAnalyzer.smearJets = True,
static

Definition at line 501 of file JetAnalyzer.py.

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

objects.JetAnalyzer.JetAnalyzer.type1METCorr

Definition at line 144 of file JetAnalyzer.py.

dictionary objects.JetAnalyzer.JetAnalyzer.type1METParams = { 'jetPtThreshold':15., 'skipEMfractionThreshold':0.9, 'skipMuons':True }
static

Definition at line 506 of file JetAnalyzer.py.

Referenced by JetReCalibrator.JetReCalibrator.correct(), and JetReCalibrator.JetReCalibrator.rawP4forType1MET_().