This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
root:pyroot_th1 [2017/06/22 12:06] – [Handling TH1 histograms] iwn | root:pyroot_th1 [2017/09/05 10:34] – [Handling TH1 histograms] iwn | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | [[root: | ||
+ | |||
====== Handling TH1 histograms ====== | ====== Handling TH1 histograms ====== | ||
- | To use '' | + | [[https:// |
+ | |||
+ | |||
+ | ===== Importing ROOT classes ===== | ||
+ | |||
+ | To use '' | ||
<code python> | <code python> | ||
from ROOT import TH1D | from ROOT import TH1D | ||
hist = TH1D(" | hist = TH1D(" | ||
</ | </ | ||
- | or | + | or //all// classes: |
<code python> | <code python> | ||
from ROOT import * # loads all classes, and thus takes longer | from ROOT import * # loads all classes, and thus takes longer | ||
hist = TH1D(" | hist = TH1D(" | ||
</ | </ | ||
- | or | + | or only the '' |
<code python> | <code python> | ||
import ROOT | import ROOT | ||
hist = ROOT.TH1D(" | hist = ROOT.TH1D(" | ||
</ | </ | ||
- | The examples below also make use of '' | + | The examples below also make use of '' |
- | '' | + | |
===== Filling a histogram ===== | ===== Filling a histogram ===== | ||
Line 36: | Line 42: | ||
===== Filling a histogram from a tree ===== | ===== Filling a histogram from a tree ===== | ||
- | The classic way would be | + | The classic way would be with a simple for loop |
<code python> | <code python> | ||
hist = TH1D(" | hist = TH1D(" | ||
Line 50: | Line 56: | ||
Note that the histogram has been saved into '' | Note that the histogram has been saved into '' | ||
- | You can also use mathematical expressions, | + | You can also use **mathematical expressions**, including |
<code python> | <code python> | ||
tree.Draw(" | tree.Draw(" | ||
tree.Draw(" | tree.Draw(" | ||
tree.Draw(" | tree.Draw(" | ||
+ | </ | ||
+ | This also includes custom functions, which you can load into '' | ||
+ | <code python> | ||
+ | from ROOT import gROOT, ... | ||
+ | gROOT.Macro(" | ||
+ | ... | ||
+ | tree.Draw(" | ||
+ | tree.Draw(" | ||
</ | </ | ||
- | You can apply some selections using variable, available in the tree's branches: | + | You can apply some **selections** using variable, available in the tree's branches: |
<code python> | <code python> | ||
tree.Draw(" | tree.Draw(" | ||
</ | </ | ||
- | You can apply some selections and/or a weight, if a weight variable is available in the tree: | + | You can apply some selections and/or a **weight**, if a weight variable is available in the tree: |
<code python> | <code python> | ||
- | tree.Draw(" | ||
tree.Draw(" | tree.Draw(" | ||
+ | tree.Draw(" | ||
</ | </ | ||
Line 76: | Line 90: | ||
</ | </ | ||
- | It's also possible to pass some option you would normally use in " | + | It's also possible to pass some **draw |
<code python> | <code python> | ||
tree.Draw(" | tree.Draw(" | ||
Line 91: | Line 105: | ||
[2] tree-> | [2] tree-> | ||
[3] tree-> | [3] tree-> | ||
- | [4] tree-> | + | [4] tree-> |
</ | </ |