This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
root:ttreedraw [2012/07/12 20:04] – created bursche | root:ttreedraw [2013/06/14 11:41] (current) – nchiap | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | To apply a fuction | + | ====== TTree:: |
+ | |||
+ | ===== Basic Usage ===== | ||
+ | |||
+ | The '' | ||
+ | The following code creates a histogram with the default settings. | ||
+ | <code c++> | ||
+ | TFile file(" | ||
+ | TTree *tree = file.Get(" | ||
+ | tree-> | ||
+ | </ | ||
+ | |||
+ | 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-> | ||
+ | TH1F *hist = gPad-> | ||
+ | tree-> | ||
+ | </ | ||
+ | |||
+ | For more information have a look at [[http:// | ||
+ | |||
+ | ===== Useful Tricks ===== | ||
+ | |||
+ | ==== Using a Custom Function | ||
+ | You can define a custom function and use it in the expression of TTree:: | ||
+ | |||
+ | To apply such a function | ||
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 | + | These can be defined and initialised |
<code python > | <code python > | ||
h = ROOT.TH1D(" | h = ROOT.TH1D(" | ||
Line 41: | Line 67: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ===== 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:: | ||
+ | |||
+ | 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(" | ||
+ | float bins[] = {0, 10, 20, 40, 80}; | ||
+ | TH1F myhist(" | ||
+ | |||
+ | TFile file(" | ||
+ | TTree *tree = file.Get(" | ||
+ | |||
+ | tmp.cd() | ||
+ | tree-> | ||
+ | </ | ||