User Tools

Site Tools


root:ttreedraw

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
root:ttreedraw [2013/06/14 11:10]
nchiap [Basic Usage]
root:ttreedraw [2013/06/14 11:41] (current)
nchiap
Line 67: Line 67:
 } }
 </​file>​ </​file>​
 +
 +===== Pitfalls =====
 +
 +==== Unable to add to existing histograms ====
 +Adding data to an existing histogram will fail, if any file was opened after creating the histogram!
 +TTree::​Draw() searches for the named histogram in the active directory - and this is changed when opening a file.
 +
 +To avoid this make sure to load the input files before you create any histograms or
 +create a storage file and switch back there after opening any files:
 +<code c++>
 +TFile tmp("​tmp.root",​ "​recreate"​);​
 +float bins[] = {0, 10, 20, 40, 80}; 
 +TH1F  myhist("​myhist",​ "​myhist",​ 4, bins)
 +
 +TFile file("​myinput.root"​);​
 +TTree *tree = file.Get("​mytree"​);​
 +
 +tmp.cd()
 +tree->​Draw("​myvar>>​+myhist"​);​
 +</​code>​
  
  
root/ttreedraw.txt ยท Last modified: 2013/06/14 11:41 by nchiap