CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/PhysicsTools/PatExamples/bin/PatBasicFWLiteAnalyzer.py

Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import ROOT
00004 import sys
00005 from DataFormats.FWLite import Events, Handle
00006 
00007 files = ["patTuple.root"]
00008 events = Events (files)
00009 handle  = Handle ("std::vector<pat::Muon>")
00010 
00011 # for now, label is just a tuple of strings that is initialized just
00012 # like and edm::InputTag
00013 label = ("cleanPatMuons")
00014 
00015 f = ROOT.TFile("analyzerPython.root", "RECREATE")
00016 f.cd()
00017 
00018 muonPt  = ROOT.TH1F("muonPt", "pt",    100,  0.,300.)
00019 muonEta = ROOT.TH1F("muonEta","eta",   100, -3.,  3.)
00020 muonPhi = ROOT.TH1F("muonPhi","phi",   100, -5.,  5.) 
00021 
00022 # loop over events
00023 i = 0
00024 for event in events:
00025     i = i + 1
00026     print  i
00027     # use getByLabel, just like in cmsRun
00028     event.getByLabel (label, handle)
00029     # get the product
00030     muons = handle.product()
00031 
00032     for muon in muons :
00033         muonPt.Fill( muon.pt() )
00034         muonEta.Fill( muon.eta() )
00035         muonPhi.Fill( muon.phi() )
00036 
00037 
00038 f.cd()
00039 
00040 muonPt.Write()
00041 muonEta.Write()
00042 muonPhi.Write()
00043 
00044 f.Close()