User Tools

Site Tools


root:ttreedraw

Differences

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

Link to this comparison view

Next revision
Previous revision
Last revisionBoth sides next revision
root:ttreedraw [2012/07/12 20:04] – created burscheroot:ttreedraw [2013/06/14 11:10] – [Basic Usage] nchiap
Line 1: Line 1:
-To apply fuction in TTree::Draw it must be known to CINT.+====== TTree::Draw() ====== 
 + 
 +===== Basic Usage ===== 
 + 
 +The ''Draw()''-Method of TTrees is very useful tool to quickly create histograms. 
 +The following code creates a histogram with the default settings. 
 +<code c++> 
 +TFile file("myfile.root"); 
 +TTree *tree = file.Get("mytree"); 
 +tree->Draw("myvar"); 
 +</code> 
 + 
 +Alternatively the name of the histogram to be created can be given or the data can be added to an existing histogram. 
 +<code c++> 
 +tree->Draw("myvar>>myhist(10,0,100)");     // create a new histogram *myhist* with 10 bins between 0 and 100 
 +TH1F *hist = gPad->GetPrimitive("myhist"); // create a pointer to the new histogram 
 +tree->Draw("myvar>>+myhist");              // add additional entries to *myhist* 
 +</code> 
 + 
 +For more information have a look at [[http://root.cern.ch/root/html/TTree#TTree:Draw@2|the official TTree::Draw documentation]]. 
 + 
 +===== Useful Tricks ===== 
 + 
 +==== Using a Custom Function in TTree::Draw ==== 
 +You can define a custom function and use it in the expression of TTree::Draw. 
 + 
 +To apply such a function it must be known to CINT.
 This can be done with ProcessLineSync This can be done with ProcessLineSync
  
Line 23: Line 49:
 If one of those is missing you get an error (even though it may still work). If one of those is missing you get an error (even though it may still work).
  
-Data structures (like histogramms) can be stored in a global pointer known to cint.  +Data structures (like histograms) can be stored in a global pointer known to cint.  
-These can be defined and inititalised in another call of ProcessLineSync.+These can be defined and initialised in another call of ProcessLineSync.
 <code python > <code python >
 h = ROOT.TH1D("myHist","",0,1,10) h = ROOT.TH1D("myHist","",0,1,10)
root/ttreedraw.txt · Last modified: 2013/06/14 11:41 by nchiap