CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/PhysicsTools/PythonAnalysis/examples/MCTruth.py

Go to the documentation of this file.
00001 from PhysicsTools.PythonAnalysis import *
00002 from ROOT import *
00003 # prepare the FWLite autoloading mechanism
00004 gSystem.Load("libFWCoreFWLite.so")
00005 AutoLibraryLoader.enable()
00006 
00007 # load the file with the generator output
00008 theFile = TFile("generatorOutput.root")
00009 
00010 events = theFile.Get("Events")
00011 
00012 # Needed for SetAddress to work right
00013 events.GetEntry()
00014 
00015 # set the buffers for the branches you want to access
00016 # 1) create a buffer
00017 # 2) open the root branch
00018 # 3) connect buffer and branch
00019 # example: generator particles
00020 source = edm.HepMCProduct()
00021 sourceBranch = events.GetBranch(events.GetAlias("source"))
00022 sourceBranch.SetAddress(source)
00023 
00024 # now loop over the events
00025 for index in all(events):
00026     
00027     # update all branches - the buffers are filled automatically
00028     # Hint: put all you branches in a list and loop over it
00029     sourceBranch.GetEntry(index)
00030     events.GetEntry(index,0)
00031 
00032     # do something with the data
00033     genEvent = source.GetEvent();
00034     print genEvent.event_number()