Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:05

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