1 |
from PhysicsTools.PythonAnalysis.cmstools import *
|
2 |
from ROOT import *
|
3 |
# prepare the FWLite autoloading mechanism
|
4 |
gSystem.Load("libFWCoreFWLite.so")
|
5 |
AutoLibraryLoader.enable()
|
6 |
|
7 |
# load the file with the generator output
|
8 |
theFile = TFile("generatorOutput.root")
|
9 |
|
10 |
events = theFile.Get("Events")
|
11 |
|
12 |
# Needed for SetAddress to work right
|
13 |
events.GetEntry()
|
14 |
|
15 |
# set the buffers for the branches you want to access
|
16 |
# 1) create a buffer
|
17 |
# 2) open the root branch
|
18 |
# 3) connect buffer and branch
|
19 |
# example: generator particles
|
20 |
source = edm.HepMCProduct()
|
21 |
sourceBranch = events.GetBranch(events.GetAlias("source"))
|
22 |
sourceBranch.SetAddress(source)
|
23 |
|
24 |
# now loop over the events
|
25 |
for index in all(events):
|
26 |
|
27 |
# update all branches - the buffers are filled automatically
|
28 |
# Hint: put all you branches in a list and loop over it
|
29 |
sourceBranch.GetEntry(index)
|
30 |
events.GetEntry(index,0)
|
31 |
|
32 |
# do something with the data
|
33 |
genEvent = source.GetEvent();
|
34 |
print genEvent.event_number()
|