CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PatBasicFWLiteAnalyzer.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 import ROOT
4 import sys
5 from DataFormats.FWLite import Events, Handle
6 
7 files = ["patTuple.root"]
8 events = Events (files)
9 handle = Handle ("std::vector<pat::Muon>")
10 
11 # for now, label is just a tuple of strings that is initialized just
12 # like and edm::InputTag
13 label = ("cleanPatMuons")
14 
15 f = ROOT.TFile("analyzerPython.root", "RECREATE")
16 f.cd()
17 
18 muonPt = ROOT.TH1F("muonPt", "pt", 100, 0.,300.)
19 muonEta = ROOT.TH1F("muonEta","eta", 100, -3., 3.)
20 muonPhi = ROOT.TH1F("muonPhi","phi", 100, -5., 5.)
21 
22 # loop over events
23 i = 0
24 for event in events:
25  i = i + 1
26  print i
27  # use getByLabel, just like in cmsRun
28  event.getByLabel (label, handle)
29  # get the product
30  muons = handle.product()
31 
32  for muon in muons :
33  muonPt.Fill( muon.pt() )
34  muonEta.Fill( muon.eta() )
35  muonPhi.Fill( muon.phi() )
36 
37 
38 f.cd()
39 
40 muonPt.Write()
41 muonEta.Write()
42 muonPhi.Write()
43 
44 f.Close()