Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 from __future__ import print_function
0002 from PhysicsTools.PythonAnalysis import *
0003 from ROOT import *
0004 # prepare the FWLite autoloading mechanism
0005 gSystem.Load("libFWCoreFWLite.so")
0006 ROOT.FWLiteEnabler.enable()
0007 
0008 # load the file with the generator output
0009 theFile = TFile("generatorOutput.root")
0010 
0011 events = theFile.Get("Events")
0012 
0013 # Needed for SetAddress to work right
0014 events.GetEntry()
0015 
0016 # set the buffers for the branches you want to access
0017 # 1) create a buffer
0018 # 2) open the root branch
0019 # 3) connect buffer and branch
0020 # example: generator particles
0021 source = edm.HepMCProduct()
0022 sourceBranch = events.GetBranch(events.GetAlias("source"))
0023 sourceBranch.SetAddress(source)
0024 
0025 # now loop over the events
0026 for index in all(events):
0027 
0028     # update all branches - the buffers are filled automatically
0029     # Hint: put all you branches in a list and loop over it
0030     sourceBranch.GetEntry(index)
0031     events.GetEntry(index,0)
0032 
0033     # do something with the data
0034     genEvent = source.GetEvent();
0035     print(genEvent.event_number())