CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MCTruth.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from PhysicsTools.PythonAnalysis import *
3 from ROOT import *
4 # prepare the FWLite autoloading mechanism
5 gSystem.Load("libFWCoreFWLite.so")
6 ROOT.FWLiteEnabler.enable()
7 
8 # load the file with the generator output
9 theFile = TFile("generatorOutput.root")
10 
11 events = theFile.Get("Events")
12 
13 # Needed for SetAddress to work right
14 events.GetEntry()
15 
16 # set the buffers for the branches you want to access
17 # 1) create a buffer
18 # 2) open the root branch
19 # 3) connect buffer and branch
20 # example: generator particles
21 source = edm.HepMCProduct()
22 sourceBranch = events.GetBranch(events.GetAlias("source"))
23 sourceBranch.SetAddress(source)
24 
25 # now loop over the events
26 for index in all(events):
27 
28  # update all branches - the buffers are filled automatically
29  # Hint: put all you branches in a list and loop over it
30  sourceBranch.GetEntry(index)
31  events.GetEntry(index,0)
32 
33  # do something with the data
34  genEvent = source.GetEvent();
35  print(genEvent.event_number())
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def all
workaround iterator generators for ROOT classes
Definition: cmstools.py:25