Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:07

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