ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/CMSSW/PhysicsTools/PythonAnalysis/examples/MCTruth.py
Revision: 1.2
Committed: Sat Mar 3 03:49:59 2007 UTC (18 years, 2 months ago) by hegner
Content type: text/x-python
Branch: MAIN
Changes since 1.1: +1 -1 lines
Log Message:
Updated documentation.

File Contents

# User Rev Content
1 hegner 1.2 from PhysicsTools.PythonAnalysis.cmstools import *
2 hegner 1.1 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()