This is a check to see if I can run my stuff with root_numpy and rootpy :P
Start by importing my modules... Numpy, root_numpy, ROOT, rootpy.plotting
I don't know man.. just put stuff there..
Oh also put style :D
In [1]:
import numpy as np
In [2]:
import root_numpy as rtnp
In [3]:
import ROOT as rt
In [4]:
from rootpy.plotting import Hist, Hist2D, Canvas, Pad # for histograms
In [5]:
from rootpy.io import root_open
In [6]:
from hsg3_style import *
Open my file with root_open (rootpy.io)
In [7]:
infile = root_open('vbf125spin2pmin.root','read')
Let's make it simple for newbs... now get the tree...
In [8]:
intree = infile.MVATree
In [9]:
intree
Out[9]:
Now that's why I love root_numpy...
Dump the whole tree into a structured numpy array!!!
In [10]:
data = rtnp.tree2array(intree) # SO SIMPLE!
Now I can get one branch by simply doing....
In [11]:
data['Mll']
Out[11]:
REMEMBER: If you don't know the name of the tree or branches.. or even structures you can use
list_trees(), list_structures(), list_branches()
for example....
In [12]:
branches = rtnp.list_branches("vbf125spin2pmin.root")
In [13]:
branches
Out[13]:
Good eh? (''kalo e?'')
Anyways, now we can have the 'Mll' branch out of the tree...
Lets make a histogram to store the mll variable
In [14]:
hist_mll = Hist(10, 0,200, name="mll", title="mll;m(ll);Entries/20GeV")
In [15]:
hist_mll
Out[15]:
Let's use the default 'ATLAS' style of roottpy (I dont like it hmm, but to bored to make it myself)
In [16]:
from rootpy.plotting.style import get_style, set_style
In [17]:
style = get_hgs3_style()#set_style(#'ATLAS')
In [18]:
#style.SetLabelOffset(0.4,'y')
In [19]:
set_style(style)
Anyways let's fill the histogram..
Remember Mll is in [MeV] so simply divide each index by 1000. to get GeV's
WEIGHTS:
This is Monte Carlo sample. So the events are weighted! The weights are stored in the 'EventWeight' branch.. So simply use it as weights, like this:
In [20]:
rtnp.fill_hist(hist_mll, data['Mll']/1000., weights=data['EventWeight'])
In [21]:
hist_mll
Out[21]:
Make a canvas...
class rootpy.plotting.Canvas(width=None, height=None, x=None, y=None, name=None, title=None, size_includes_decorations=False)
In [22]:
canvas = Canvas(800,600,name='c1')
In [23]:
canvas.cd()
Out[23]:
Let's make a fake ratio plot
In [24]:
ratio = hist_mll.Clone()
In [25]:
ratio.Divide(hist_mll)
Out[25]:
In [26]:
pad_hist = Pad(0,0.3,1,1); set_pad_style(pad_hist); pad_hist.Draw()
In [27]:
pad_ratio = Pad(0,0,1,0.3); set_subpad_style(pad_ratio); pad_ratio.Draw()
In [28]:
pad_hist.cd()
Out[28]:
In [29]:
hist_mll.Draw()
In [30]:
pad_ratio.cd()
Out[30]:
In [31]:
ratio.draw('E4')
In [32]:
canvas
Out[32]:
In [ ]:
In [33]:
canvas
Out[33]:
In [ ]:
In [ ]: