Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:27

0001 from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer
0002 from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle
0003 from PhysicsTools.Heppy.physicsobjects.Jet import Jet, GenJet
0004 from PhysicsTools.HeppyCore.utils.deltar import matchObjectCollection
0005 
0006 class SimpleJetAnalyzer(Analyzer):
0007     '''Just a simple jet analyzer, to be used in tutorials.
0008 
0009     example configuration:
0010     
0011     jets = cfg.Analyzer(
0012        SimpleJetAnalyzer,
0013        'jets',
0014        filter_func = lambda x : x.pt()>30 # filtering function for the jets
0015        njets = 4, # keeping the first 4 leading jets passing cuts 
0016     )
0017     '''
0018 
0019     def declareHandles(self):
0020         super(SimpleJetAnalyzer, self).declareHandles()
0021         self.handles['jets'] = AutoHandle( 'slimmedJets',
0022                                            'std::vector<pat::Jet>' )
0023         self.mchandles['genjets'] = AutoHandle( 'slimmedGenJets',
0024                                                 'std::vector<reco::GenJet>')
0025         
0026     def process(self, event):
0027         super(SimpleJetAnalyzer, self).readCollections(event.input)
0028         # creating Jet python objects wrapping the EDM jets
0029         jets = map(Jet, self.handles['jets'].product())
0030         jets = [ jet for jet in jets if self.cfg_ana.filter_func(jet)]
0031         jets = jets[:self.cfg_ana.njets]
0032 
0033         if self.cfg_comp.isMC:
0034             genjets =  map(GenJet, self.mchandles['genjets'].product())
0035             matches = matchObjectCollection(jets, genjets, 0.2)
0036             for jet in jets:
0037                 jet.gen = matches[jet]
0038             
0039         setattr(event, self.instance_label, jets)
0040         setattr(event, '_'.join([self.instance_label, 'gen']), genjets)