In [1]:
%pylab inline
In [2]:
import ROOT
from rep.plotting import default_canvas
c1 = default_canvas()
fun1 = ROOT.TF1( 'fun1', 'abs(sin(x)/x)', 0, 10)
c1.SetGridx()
c1.SetGridy()
fun1.Draw()
c1
Out[2]:
In [3]:
F = ROOT.TFile("toy_datasets/toyMC_bck_mass.root")
In [4]:
T = F.Get("Tau23Mu")
In [5]:
T.Draw("min_DOCA")
c1
Out[5]:
In [6]:
h1 = ROOT.TH1F("h1","hist from tree",50, -0.25, 0.25)
In [7]:
T.Draw("min_DOCA>>h1")
c1
Out[7]:
There are two comfortable libraries to read and work with root files
In [8]:
import root_numpy
# read root data to numpy.array
data = root_numpy.root2array("toy_datasets/toyMC_bck_mass.root", 'Tau23Mu', branches=['min_DOCA', 'mass'])
In [9]:
import numpy
data2 = numpy.array(data[:10], dtype=[('1', numpy.float32), ('2', numpy.float32)])
In [10]:
import pandas
pandas.DataFrame(data)
Out[10]:
In [11]:
figure(figsize=(9, 7))
hist(data['min_DOCA'], bins=50)
xlabel('min_doca')
Out[11]:
In [12]:
figure(figsize=(9, 7))
hist(data['mass'], bins=50)
xlabel('mass')
Out[12]:
In [13]:
data = root_numpy.root2array("toy_datasets/toyMC_bck_mass.root", 'Tau23Mu', branches=['mass'], selection='mass > 1700')
In [14]:
figure(figsize=(9, 7))
hist(data['mass'], bins=50)
xlabel('mass')
Out[14]:
In [ ]: