CMS 3D CMS Logo

SimpleJetAnalyzer.py
Go to the documentation of this file.
1 from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer
2 from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle
3 from PhysicsTools.Heppy.physicsobjects.Jet import Jet, GenJet
4 from PhysicsTools.HeppyCore.utils.deltar import matchObjectCollection
5 
6 class SimpleJetAnalyzer(Analyzer):
7  '''Just a simple jet analyzer, to be used in tutorials.
8 
9  example configuration:
10 
11  jets = cfg.Analyzer(
12  SimpleJetAnalyzer,
13  'jets',
14  filter_func = lambda x : x.pt()>30 # filtering function for the jets
15  njets = 4, # keeping the first 4 leading jets passing cuts
16  )
17  '''
18 
19  def declareHandles(self):
20  super(SimpleJetAnalyzer, self).declareHandles()
21  self.handles['jets'] = AutoHandle( 'slimmedJets',
22  'std::vector<pat::Jet>' )
23  self.mchandles['genjets'] = AutoHandle( 'slimmedGenJets',
24  'std::vector<reco::GenJet>')
25 
26  def process(self, event):
27  super(SimpleJetAnalyzer, self).readCollections(event.input)
28  # creating Jet python objects wrapping the EDM jets
29  jets = map(Jet, self.handles['jets'].product())
30  jets = [ jet for jet in jets if self.cfg_ana.filter_func(jet)]
31  jets = jets[:self.cfg_ana.njets]
32 
33  if self.cfg_comp.isMC:
34  genjets = map(GenJet, self.mchandles['genjets'].product())
35  matches = matchObjectCollection(jets, genjets, 0.2)
36  for jet in jets:
37  jet.gen = matches[jet]
38 
39  setattr(event, self.instance_label, jets)
40  setattr(event, '_'.join([self.instance_label, 'gen']), genjets)
def matchObjectCollection
Definition: deltar.py:151
static std::string join(char **cmd)
Definition: RemoteFile.cc:18