<jupyter_start><jupyter_text>Ratio Plots with root_numpy & rootpy 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.plottingI don't know man.. just put stuff there..Oh also put style :D<jupyter_code>import numpy as np
import root_numpy as rtnp
import ROOT as rt
from rootpy.plotting import Hist, Hist2D, Canvas, Pad  # for histograms
from rootpy.io import root_open
from hsg3_style import *<jupyter_output><empty_output><jupyter_text>---Open my file with root_open (rootpy.io)<jupyter_code>infile = root_open('vbf125spin2pmin.root','read')<jupyter_output><empty_output><jupyter_text>----Let's make it simple for newbs... now get the tree...---<jupyter_code>intree = infile.MVATree
intree<jupyter_output><empty_output><jupyter_text>---Now that's why I love root_numpy...Dump the whole tree into a structured numpy array!!!---<jupyter_code>data = rtnp.tree2array(intree) # SO SIMPLE!<jupyter_output><empty_output><jupyter_text>---Now I can get one branch by simply doing....---<jupyter_code>data['Mll']<jupyter_output><empty_output><jupyter_text>--- REMEMBER:If you don't know the name of the tree or branches.. or even structures you can uselist_trees(), list_structures(), list_branches()for example....<jupyter_code>branches = rtnp.list_branches("vbf125spin2pmin.root")
branches<jupyter_output><empty_output><jupyter_text>----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<jupyter_code>hist_mll = Hist(10, 0,200, name="mll", title="mll;m(ll);Entries/20GeV")
hist_mll<jupyter_output><empty_output><jupyter_text>---Let's use the default 'ATLAS' style of roottpy (I dont like it hmm, but to bored to make it myself)<jupyter_code>from rootpy.plotting.style import get_style, set_style
style = get_hgs3_style()#set_style(#'ATLAS')
#style.SetLabelOffset(0.4,'y')
set_style(style)<jupyter_output>INFO:rootpy.plotting.style:using ROOT style ''<jupyter_text>-------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:<jupyter_code>rtnp.fill_hist(hist_mll, data['Mll']/1000., weights=data['EventWeight'])
hist_mll<jupyter_output><empty_output><jupyter_text>----Make a canvas...class rootpy.plotting.Canvas(width=None, height=None, x=None, y=None, name=None, title=None, size_includes_decorations=False)<jupyter_code>canvas = Canvas(800,600,name='c1')
canvas.cd()<jupyter_output><empty_output><jupyter_text>Let's make a fake ratio plot<jupyter_code>ratio = hist_mll.Clone()
ratio.Divide(hist_mll)
pad_hist = Pad(0,0.3,1,1); set_pad_style(pad_hist); pad_hist.Draw()
pad_ratio = Pad(0,0,1,0.3); set_subpad_style(pad_ratio); pad_ratio.Draw()
pad_hist.cd()
hist_mll.Draw()
pad_ratio.cd()
ratio.draw('E4')
canvas
canvas<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.133003300330033, 'fraction_numerical': 0.015841584158415842, 'mean_word_length': 6.4655172413793105, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '188063', 'license': 'MIT', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1092, 'n_words': 271, 'path': 'Rootpy Ratio Plots.ipynb', 'repo_name': 'nkarast/notebooks', 'size': '3030'}