Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:51

0001 #! /usr/bin/env python
0002 
0003 import ROOT
0004 import sys
0005 from DataFormats.FWLite import Events, Handle
0006 
0007 files = ["patTuple.root"]
0008 events = Events (files)
0009 handle  = Handle ("std::vector<pat::Muon>")
0010 
0011 # for now, label is just a tuple of strings that is initialized just
0012 # like and edm::InputTag
0013 label = ("cleanPatMuons")
0014 
0015 f = ROOT.TFile("analyzerPython.root", "RECREATE")
0016 f.cd()
0017 
0018 muonPt  = ROOT.TH1F("muonPt", "pt",    100,  0.,300.)
0019 muonEta = ROOT.TH1F("muonEta","eta",   100, -3.,  3.)
0020 muonPhi = ROOT.TH1F("muonPhi","phi",   100, -5.,  5.) 
0021 
0022 # loop over events
0023 i = 0
0024 for event in events:
0025     i = i + 1
0026     print(i)
0027     # use getByLabel, just like in cmsRun
0028     event.getByLabel (label, handle)
0029     # get the product
0030     muons = handle.product()
0031 
0032     for muon in muons :
0033         muonPt.Fill( muon.pt() )
0034         muonEta.Fill( muon.eta() )
0035         muonPhi.Fill( muon.phi() )
0036 
0037 
0038 f.cd()
0039 
0040 muonPt.Write()
0041 muonEta.Write()
0042 muonPhi.Write()
0043 
0044 f.Close()