{"metadata":{"language_info":{"name":"python","version":"3.7.8","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This notebook is for comparing signal and background distributions from 2 different ROOT files.\n# Using python\nfrom ROOT import gStyle, TFile, TH1, TH1D, TH2D, TCanvas, TLegend, TColor","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Let's start with setting some ROOT style parameters:\n# You do not need to know what they mean, but can directly use these settings\n\ngStyle.SetOptStat(0)\ngStyle.SetPalette(1)\n\ngStyle.SetTextFont(42)\n\ngStyle.SetTitleStyle(0000)\ngStyle.SetTitleBorderSize(0)\ngStyle.SetTitleFont(42)\ngStyle.SetTitleFontSize(0.055)\n\ngStyle.SetTitleFont(42, \"xyz\")\ngStyle.SetTitleSize(0.5, \"xyz\")\ngStyle.SetLabelFont(42, \"xyz\")\ngStyle.SetLabelSize(0.45, \"xyz\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Open the files with signal and bg histograms given by CutLang: \nfs = TFile(\"../runs/histoOut-VSOPSUSY_sg.root\")\nfb = TFile(\"../runs/histoOut-VSOPSUSY_bg.root\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Get the histograms\n# MET and HT histograms from the signal file\nhmetsg = fs.Get(\"SR/hmet\")\nhhtsg = fs.Get(\"SR/hht\")\n# MET and HT histograms from the BG file\nhmetbg = fb.Get(\"SR/hmet\")\nhhtbg = fb.Get(\"SR/hht\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Our purpose in this exercise is to compare the shapes of signal and background distributions.\n# To do this comparison best, the area integral under histograms being compared should be the same.\n# Therefore we scale the hisgograms so that the area integral under the histograms equals 1. \nhmetsg.Scale(1./hmetsg.Integral())\nhmetbg.Scale(1./hmetbg.Integral())\nhhtsg.Scale(1./hhtsg.Integral())\nhhtbg.Scale(1./hhtbg.Integral())","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Histogram style settings:\nhmetsg.SetLineWidth(2)\nhhtsg.SetLineWidth(2)\nhmetbg.SetLineWidth(2)\nhhtbg.SetLineWidth(2)\n\nhmetsg.SetLineColor(600) # kBlue\nhmetbg.SetLineColor(416+2) # kGreen + 2\nhhtsg.SetLineColor(600) # kBlue\nhhtbg.SetLineColor(416+2) # kGreen + 2\n\n# Titles, labels. \n# Remember that it is enough to set these variables ONLY FOR THE FIRST HISTOGRAM YOU WILL DRAW\n# i.e., the one you will call by .Draw(). The rest you will draw by .Draw(\"same\") will only \n# contribute with the historam curve.\nhmetbg.SetTitle(\"MET\")\nhmetbg.GetXaxis().SetTitle(\"MET (GeV)\")\nhmetbg.GetXaxis().SetTitleOffset(1.25)\nhmetbg.GetXaxis().SetTitleSize(0.05)\nhmetbg.GetXaxis().SetLabelSize(0.045)\nhmetbg.GetXaxis().SetNdivisions(8, 5, 0)\nhmetbg.GetYaxis().SetTitle(\"number of events\")\nhmetbg.GetYaxis().SetTitleOffset(1.4)\nhmetbg.GetYaxis().SetTitleSize(0.05)\nhmetbg.GetYaxis().SetLabelSize(0.045)\n\nhhtbg.SetTitle(\"HT\")\nhhtbg.GetXaxis().SetTitle(\"HT (GeV)\")\nhhtbg.GetXaxis().SetTitleOffset(1.25)\nhhtbg.GetXaxis().SetTitleSize(0.05)\nhhtbg.GetXaxis().SetLabelSize(0.045)\nhhtbg.GetXaxis().SetNdivisions(8, 5, 0)\nhhtbg.GetYaxis().SetTitle(\"number of events\")\nhhtbg.GetYaxis().SetTitleOffset(1.4)\nhhtbg.GetYaxis().SetTitleSize(0.05)\nhhtbg.GetYaxis().SetLabelSize(0.045)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Make a generically usable legend\nl = TLegend(0.65, 0.75, 0.88, 0.87)\nl.SetBorderSize(0)\nl.SetFillStyle(0000)\nl.AddEntry(hmetsg,\"signal\", \"l\")\nl.AddEntry(hmetbg,\"BG\", \"l\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot and display MET\n# Make a dedicated canvas\ncmet = TCanvas(\"cmet\", \"cmet\", 620, 500)\ncmet.SetBottomMargin(0.15)\ncmet.SetLeftMargin(0.15)\ncmet.SetRightMargin(0.15)\n# Draw the histograms and the legend\n# Make sure you draw the background before the signal\nhmetbg.Draw()\nhmetsg.Draw(\"same\")\nl.Draw(\"same\")\ncmet.Draw()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot and display HT\n# Make a dedicated canvas\ncht = TCanvas(\"cht\", \"cht\", 620, 500)\ncht.SetBottomMargin(0.15)\ncht.SetLeftMargin(0.15)\ncht.SetRightMargin(0.15)\n# Draw the histograms and the legend\n# Make sure you draw the background before the signal\nhhtbg.Draw()\nhhtsg.Draw(\"same\")\nl.Draw(\"same\")\ncht.Draw()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}