CMS 3D CMS Logo

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