This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| root:ttreedraw [2013/06/14 11:09] – nchiap | root:ttreedraw [2013/06/14 11:41] (current) – nchiap | ||
|---|---|---|---|
| Line 13: | Line 13: | ||
| Alternatively the name of the histogram to be created can be given or the data can be added to an existing histogram. | Alternatively the name of the histogram to be created can be given or the data can be added to an existing histogram. | ||
| <code c++> | <code c++> | ||
| - | tree-> | + | tree-> |
| - | TH1F *hist = gPad-> | + | TH1F *hist = gPad-> |
| - | tree-> | + | tree-> |
| </ | </ | ||
| Line 67: | 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-> | ||
| + | </ | ||