User Tools

Site Tools


root:pyroot_ttree

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
root:pyroot_ttree [2017/09/05 10:33] iwnroot:pyroot_ttree [2018/02/28 14:03] (current) – [TChain] iwn
Line 3: Line 3:
 ====== Handling TTree trees ====== ====== Handling TTree trees ======
  
-[[https://root.cern.ch/doc/master/classTTree.html|Here]] is the reference manual for the ''TTree'' class.+[[https://root.cern.ch/doc/master/classTTree.html|Here]] is the class reference for ''TTree''.
  
 [[root:example_TTree|Here]] is one file containing multiple examples. [[root:example_TTree|Here]] is one file containing multiple examples.
Line 102: Line 102:
 <code python> <code python>
 for event in tree: for event in tree:
-    print tree.px+    print event.px
 </code> </code>
 If you also need the event's index: If you also need the event's index:
 <code python> <code python>
 for i, event in enumerate(tree): for i, event in enumerate(tree):
-    print i, tree.px+    print i, event.px
 </code> </code>
- 
  
 ===== Making a histogram with TTree ===== ===== Making a histogram with TTree =====
Line 175: Line 174:
 tree.Scan("run:lum:evt","pt1>30 && pt2>30") tree.Scan("run:lum:evt","pt1>30 && pt2>30")
 </code> </code>
 +
 +
 +
 +
 +===== TChain =====
 +
 +If you have a samples split into many files, each containing the same tree, you can either add the files into one big one in the command line with ''hadd'' or load them in a ''TChain'' in you analysis code.
 +
 +With ''hadd'' in the command line:
 +<code bash>
 +hadd sample.root sample_1.root sample_2.root sample_3.root
 +</code>
 +
 +With ''TChain'':
 +<code python>
 +chain = TChain("tree_name")
 +chain.Add("sample_1.root")
 +chain.Add("sample_2.root")
 +chain.Add("sample_3.root")
 +for event in chain:
 +  print event.px
 +</code>
 +Looping over the events in a chain is similar as for [[root:pyroot_ttree#looping_over_a_ttree|trees]]. Note it's also possible to use a glob wildcard: ''chain.Add("sample_*.root")''
root/pyroot_ttree.1504600421.txt.gz · Last modified: 2017/09/05 10:33 by iwn