#!/usr/bin/env python # coding: utf-8 # # rf107_plotstyles # Basic functionality: demonstration of various plotting styles of data, functions in a RooPlot # # # # # **Author:** Clemens Lange, Wouter Verkerke (C++ version) # This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, May 15, 2024 at 09:50 AM. # In[1]: import ROOT # Set up model # --------------------- # Create observables # In[2]: x = ROOT.RooRealVar("x", "x", -10, 10) # Create Gaussian # In[3]: sigma = ROOT.RooRealVar("sigma", "sigma", 3, 0.1, 10) mean = ROOT.RooRealVar("mean", "mean", -3, -10, 10) gauss = ROOT.RooGaussian("gauss", "gauss", x, mean, sigma) # Generate a sample of 100 events with sigma=3 # In[4]: data = gauss.generate({x}, 100) # Fit pdf to data # In[5]: gauss.fitTo(data, PrintLevel=-1) # Make plot frames # ------------------------------- # Make four plot frames to demonstrate various plotting features # In[6]: frame1 = x.frame(Name="xframe", Title="Red Curve / SumW2 Histo errors", Bins=20) frame2 = x.frame(Name="xframe", Title="Dashed Curve / No XError bars", Bins=20) frame3 = x.frame(Name="xframe", Title="Filled Curve / Blue Histo", Bins=20) frame4 = x.frame(Name="xframe", Title="Partial Range / Filled Bar chart", Bins=20) # Data plotting styles # --------------------------------------- # Use sqrt(sum(weights^2)) error instead of Poisson errors # In[7]: data.plotOn(frame1, DataError="SumW2") # Remove horizontal error bars # In[8]: data.plotOn(frame2, XErrorSize=0) # Blue markers and error bors # In[9]: data.plotOn(frame3, MarkerColor="b", LineColor="b") # Filled bar chart # In[10]: data.plotOn(frame4, DrawOption="B", DataError=None, XErrorSize=0, FillColor="kGray") # Function plotting styles # ----------------------------------------------- # Change line color to red # In[11]: gauss.plotOn(frame1, LineColor="r") # Change line style to dashed # In[12]: gauss.plotOn(frame2, LineStyle="--") # Filled shapes in green color # In[13]: gauss.plotOn(frame3, MoveToBack=True, DrawOption="F", FillColor="kOrange") # In[14]: gauss.plotOn(frame4, Range=(-8, 3), LineColor="m") c = ROOT.TCanvas("rf107_plotstyles", "rf107_plotstyles", 800, 800) c.Divide(2, 2) c.cd(1) ROOT.gPad.SetLeftMargin(0.15) frame1.GetYaxis().SetTitleOffset(1.6) frame1.Draw() c.cd(2) ROOT.gPad.SetLeftMargin(0.15) frame2.GetYaxis().SetTitleOffset(1.6) frame2.Draw() c.cd(3) ROOT.gPad.SetLeftMargin(0.15) frame3.GetYaxis().SetTitleOffset(1.6) frame3.Draw() c.cd(4) ROOT.gPad.SetLeftMargin(0.15) frame4.GetYaxis().SetTitleOffset(1.6) frame4.Draw() c.SaveAs("rf107_plotstyles.png") # Draw all canvases # In[15]: from ROOT import gROOT gROOT.GetListOfCanvases().Draw()