Ejemplo n.º 1
0
def init_palette():
    from rootpy.plotting.style import set_style, get_style

    atlas = get_style("ATLAS")
    atlas.SetPalette(51)
    set_style(atlas)
    return True
Ejemplo n.º 2
0
def main(parameters):
  style = get_style('CMSTDR')
  style.SetTitleSize(0.07, "XYZ")
  style.SetLegendBorderSize(0)
  style.SetLegendFillColor(0)
  style.SetLegendFont(43)
  style.SetTextSize(25)
  set_style(style)
  input_file = parameters.input_file
  plot_distributions(input_file, parameters.distribution_plots)
  plot_comparisons(input_file, parameters.comparison_plots)
Ejemplo n.º 3
0
def SetupATLAS():
    rootpy.log.basic_config_colorized()
    #use latex for text
    rc('text', usetex=True)
    # set the style
    style = get_style('ATLAS')
    style.SetEndErrorSize(3)
    set_style(style)
    set_style('ATLAS', mpl=True)
    rc('font', family='sans-serif', weight='medium', size=16)
    rc('legend', fontsize=16)
Ejemplo n.º 4
0
def test_cmstdr():

    style = get_style('CMSTDR')
    with style:
        hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution")
        ROOT.gRandom.SetSeed()
        for i in xrange(1000):
            hpx.Fill(ROOT.gRandom.Gaus())
        hpx.GetXaxis().SetTitle("random variable [unit]")
        hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]")
        hpx.SetMaximum(100.)
        hpx.Draw()
Ejemplo n.º 5
0
def test_cmstdr():

    style = get_style('CMSTDR')
    with style:
        hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution")
        ROOT.gRandom.SetSeed()
        for i in xrange(1000):
            hpx.Fill(ROOT.gRandom.Gaus())
        hpx.GetXaxis().SetTitle("random variable [unit]")
        hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]")
        hpx.SetMaximum(100.)
        hpx.Draw()
        labels.CMS_label("Testing 2050", sqrts=100)
Ejemplo n.º 6
0
def test_atlas():

    style = get_style('ATLAS')
    with style:
        hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution")
        ROOT.gRandom.SetSeed()
        for i in xrange(1000):
            hpx.Fill(ROOT.gRandom.Gaus())
        hpx.GetXaxis().SetTitle("random variable [unit]")
        hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]")
        hpx.SetMaximum(80.)
        hpx.Draw()
        ATLAS_label(.4, .8)
Ejemplo n.º 7
0
def test_lhcb():
    style = get_style('LHCb')

    with style:
        canvas = Canvas()
        hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution")
        ROOT.gRandom.SetSeed()
        for i in xrange(1000):
            hpx.Fill(ROOT.gRandom.Gaus())
        hpx.GetXaxis().SetTitle("random variable [unit]")
        hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]")
        hpx.SetMaximum(80.)
        hpx.Draw()
        LHCb_label("R", "preliminary")
        if INTERACTIVE:
            wait()
Ejemplo n.º 8
0
def set_hsg4_style(shape='square'):
    style = get_style('ATLAS', shape=shape)
    #style.SetFrameLineWidth(2)
    #style.SetLineWidth(2)
    #style.SetTitleYOffset(1.8)
    #style.SetTickLength(0.04, 'X')
    #style.SetTickLength(0.02, 'Y')

    # custom HSG4 modifications
    # style.SetPadTopMargin(0.06)
    style.SetPadLeftMargin(0.16)
    style.SetTitleYOffset(1.6)
    style.SetHistTopMargin(0.)
    style.SetHatchesLineWidth(1)
    style.SetHatchesSpacing(1)
    set_style(style)
Ejemplo n.º 9
0
def test_cmstdr():

    style = get_style('CMSTDR')
    with style:
        canvas = Canvas()
        hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution")
        ROOT.gRandom.SetSeed()
        for i in xrange(1000):
            hpx.Fill(ROOT.gRandom.Gaus())
        hpx.GetXaxis().SetTitle("random variable [unit]")
        hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]")
        hpx.SetMaximum(100.)
        hpx.Draw()
        CMS_label("Testing 2050", sqrts=100)
        if INTERACTIVE:
            wait()
Ejemplo n.º 10
0
def set_hsg4_style(shape='square'):
    style = get_style('ATLAS', shape=shape)
    #style.SetFrameLineWidth(2)
    #style.SetLineWidth(2)
    #style.SetTitleYOffset(1.8)
    #style.SetTickLength(0.04, 'X')
    #style.SetTickLength(0.02, 'Y')

    # custom HSG4 modifications
    # style.SetPadTopMargin(0.06)
    style.SetPadLeftMargin(0.16)
    style.SetTitleYOffset(1.6)
    style.SetHistTopMargin(0.)
    style.SetHatchesLineWidth(1)
    style.SetHatchesSpacing(1)
    ROOT.TGaxis.SetMaxDigits(4)
    set_style(style)
Ejemplo n.º 11
0
def MyStyle():
    """customize ROOT style based on *CMSTDR* style"""

    style = get_style('CMSTDR')
    style.SetTitleSize(0.03, "XYZ")
    style.SetLabelSize(0.03, "XYZ")
    style.SetLegendBorderSize(0)
    style.SetLegendFillColor(0)
    font = 42  # Helvetica
    style.SetTextFont(font)
    style.SetLegendFont(43)
    style.SetPalette(ROOT.kBird)  # 55 ROOT.kCMYK # 112 ROOT.kViridis
    style.SetErrorX()
    style.SetPadTopMargin(0.05)
    style.SetPadBottomMargin(0.10)
    style.SetPadLeftMargin(0.12)
    style.SetPadRightMargin(0.04)
    return style
Ejemplo n.º 12
0
def test_get_style():

    mystyle = TStyle('mystyle', 'some style')
    assert(isinstance(get_style('mystyle'), Style))
Ejemplo n.º 13
0
def test_get_style():

    mystyle = TStyle('mystyle', 'some style')
    assert (isinstance(get_style('mystyle'), Style))
Ejemplo n.º 14
0
def init_palette():
  from rootpy.plotting.style import set_style, get_style
  atlas = get_style('ATLAS')
  atlas.SetPalette(51)
  set_style(atlas)
  return True
Ejemplo n.º 15
0
def fithist(data,weightdata,central,eff=eff,plotDir=None):
  plotting = not (plotDir==None)
  if plotting and not os.path.exists(plotDir):
    print '== Making folder '+options.plotDir+' =='
    os.makedirs(options.plotDir)
  if plotting:
    try:
      from rootpy.plotting.style import set_style, get_style
      print '== Using ATLAS style =='
      atlas = get_style('ATLAS')
      atlas.SetPalette(51)
      set_style(atlas)
      set_style('ATLAS',mpl=True)
    except ImportError: print '== Not using ATLAS style (Can\'t import rootpy.) =='

  if plotting: n,bins,patches = plt.hist(data,normed=True,bins=100,weights=weightdata,facecolor='b',histtype='stepfilled')
  weightdata = weightdata/sum(weightdata)
  if central == 'absolute_median' or central == 'mode':
    if eff<0 or eff>1: raise RuntimeError('In order to use absolute IQR, you have to provide the reconstruction efficiency. Use --eff option.')
    (mu,mu_err,sigma,sigma_err,upper_quantile,lower_quantile,err) = distribution_values(data,weightdata,central,eff=eff)
    if plotting:
      plt.plot((mu,mu),(0,plt.ylim()[1]),'r--',linewidth=2)
      height = 0.607*max(n) #height at x=1*sigma in normal distribution
      if lower_quantile>float('-inf'):
        plt.plot((lower_quantile,upper_quantile),(height,height),'r--',linewidth=2)
        plt.plot((lower_quantile,lower_quantile),(height-0.02,height+0.02),'r-',linewidth=2)
      else:
        plt.plot((mu,upper_quantile),(height,height),'r--',linewidth=2)
      plt.plot((upper_quantile,upper_quantile),(height-0.02,height+0.02),'r-',linewidth=2)
  if central == 'median':
    (mu,mu_err,sigma,sigma_err,upper_quantile,lower_quantile) = distribution_values(data,weightdata,central)
    if plotting:
      plt.plot((mu,mu),(0,plt.ylim()[1]),'r--',linewidth=2)
      height = 0.607*max(n) #height at x=1*sigma in normal distribution
      plt.plot((lower_quantile,upper_quantile),(height,height),'r--',linewidth=2)
      plt.plot((lower_quantile,lower_quantile),(height-0.02,height+0.02),'r-',linewidth=2)
      plt.plot((upper_quantile,upper_quantile),(height-0.02,height+0.02),'r-',linewidth=2)
  if central == 'mean':
    (mu,mu_err,sigma,sigma_err) = distribution_values(data,weightdata,central)
    if plotting:
      gfunc = norm
      y = gfunc.pdf( bins, mu, sigma)
      plt.plot((mu,mu),(0,gfunc.pdf(mu,mu,sigma)),'r--',linewidth=2)
      l = plt.plot(bins, y, 'r--', linewidth=2)
  if central == 'trimmed':
    (mu,mu_err,sigma,sigma_err,lower,upper) = distribution_values(data,weightdata,central)
    if plotting:
      #print mu,sigma,ptbin
      gfunc = norm
      y = gfunc.pdf(bins, mu, sigma)
      plt.plot((mu,mu),(0,gfunc.pdf(mu,mu,sigma)),'r--',linewidth=2)
      newbins = bins[all([bins>lower,bins<upper],axis=0)]
      newy = y[all([bins>lower,bins<upper],axis=0)]
      l = plt.plot(newbins, newy, 'r--', linewidth=2)
  if plotting:
    plt.xlabel('$p_T^{reco}/p_T^{true}$')
    plt.ylabel('a.u.')
    plt.savefig(plotDir+'/'+'histfit_'+central+'.png')
    plt.close()
    #avgres.append(mu)
    #avgres_errs.append(mu_err)
    #sigmaRs.append(sigma)
    #sigmaR_errs.append(sigma_err)

  return mu,mu_err,sigma,sigma_err 
Ejemplo n.º 16
0
import rootpy
rootpy.log.basic_config_colorized()
from rootpy.plotting import Canvas, Hist
from rootpy.plotting.style import get_style
from rootpy.interactive import wait

try:
    kwargs = {}
    for arg in extra:
        name, value = arg.lstrip('--').split('=')
        kwargs[name] = value
except ValueError:
    sys.exit("specify style parameters with --name=value")

try:
    style = get_style(args.style, **kwargs)
except ValueError:
    print('Invalid style: `{0}`. Using the `ATLAS` style.'.format(args.style))
    style = get_style('ATLAS')

# Use styles as context managers. The selected style will only apply
# within the following context:
with style:
    c = Canvas()
    hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution")
    # generate some random data
    ROOT.gRandom.SetSeed()
    for i in xrange(25000):
        hpx.Fill(ROOT.gRandom.Gaus())
    hpx.GetXaxis().SetTitle("random variable [unit]")
    hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]")
Ejemplo n.º 17
0
        help='Enable batch mode for ROOT.',
    )

    # parse the arguments, throw errors if missing any
    args = parser.parse_args()

    import ROOT

    ROOT.PyConfig.IgnoreCommandLineOptions = True
    ROOT.gROOT.SetBatch(args.batch_mode)

    import numpy as np

    from rootpy.plotting.style import set_style, get_style

    atlas = get_style('ATLAS')
    atlas.SetPalette(51)
    set_style(atlas)

    summary = json.load(file(args.summary))

    plot_array = {
        'sig': [r['significance'] for r in summary],
        'signal': [r['signal'] for r in summary],
        'bkgd': [r['bkgd'] for r in summary],
        'mgluino': [r['m_gluino'] for r in summary],
        'mlsp': [r['m_lsp'] for r in summary],
        'ratio': [r['ratio'] for r in summary],
    }

    # load in supercuts
Ejemplo n.º 18
0
h1.linecolor = 'green'
h1.linewidth = 0

h2.fillstyle = 'solid'
h2.fillcolor = 'red'
h2.linecolor = 'red'
h2.linewidth = 0

stack = HistStack()
stack.Add(h1)
stack.Add(h2)
# hack to change y-axis range in ROOT
stack.SetMaximum(stack.GetMaximum() * 1.2)

# plot with ROOT
style = get_style('ATLAS')
style.SetEndErrorSize(3)
set_style(style)
canvas = Canvas(width=700, height=500)
stack.Draw('HIST E1 X0')
h3.Draw('SAME E1 X0')
stack.xaxis.SetTitle('Mass')
stack.yaxis.SetTitle('Events')
# set the number of expected legend entries
legend = Legend(3, leftmargin=0.45, margin=0.3)
legend.AddEntry(h1, style='F')
legend.AddEntry(h2, style='F')
legend.AddEntry(h3, style='LEP')
legend.Draw()
label = ROOT.TText(0.3, 0.8, 'ROOT')
label.SetTextFont(43)
Ejemplo n.º 19
0
import ROOT
from rootpy.plotting import Canvas, Hist
from rootpy.plotting.style import get_style
from rootpy.interactive import wait
from rootpy.extern.six.moves import range

try:
    kwargs = {}
    for arg in extra:
        name, value = arg.lstrip('--').split('=')
        kwargs[name] = value
except ValueError:
    print("specify style parameters with --name=value")

try:
    style = get_style(args.style, **kwargs)
except ValueError:
    print('Invalid style: `{0}`. Using the `ATLAS` style.'.format(args.style))
    style = get_style('ATLAS')

# Use styles as context managers. The selected style will only apply
# within the following context:
with style:
    c = Canvas()
    hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution")
    # generate some random data
    ROOT.gRandom.SetSeed()
    for i in range(25000):
        hpx.Fill(ROOT.gRandom.Gaus())
    hpx.GetXaxis().SetTitle("random variable [unit]")
    hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]")
Ejemplo n.º 20
0
 def __enter__(self):
     """Override the __enter__ method to remember the current gStyle.
     """
     self.old_gStyle = get_style(ROOT.gStyle.name)
     set_style(self)
     return self
Ejemplo n.º 21
0
Setting the plotting style
==========================

This example demonstrates how to set the plotting style.
"""
print __doc__
import ROOT
import rootpy

rootpy.log.basic_config_colorized()
from rootpy.plotting import Hist
from rootpy.plotting.style import get_style
from rootpy.interactive import wait


atlas_style = get_style("ATLAS")

# Use styles as context managers. The ATLAS style will only apply
# within the following context:
with atlas_style:
    hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution")
    # generate some random data
    ROOT.gRandom.SetSeed()
    for i in xrange(25000):
        hpx.Fill(ROOT.gRandom.Gaus())
    hpx.GetXaxis().SetTitle("random variable [unit]")
    hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]")
    hpx.SetMaximum(1000.0)
    hpx.Draw()
    wait()
Ejemplo n.º 22
0
import rootpy

rootpy.log.basic_config_colorized()
from rootpy.plotting import Hist
from rootpy.plotting.style import get_style
from rootpy.interactive import wait

try:
    style_name = sys.argv[1]
except IndexError:
    print('Specify the style with the style name as an argument')
    print('Using the ATLAS style')
    style_name = 'ATLAS'

try:
    style = get_style(style_name)
except ValueError:
    print('Invalid style: `{}`. Using the `ATLAS` style.'.format(style_name))
    style = get_style('ATLAS')

# Use styles as context managers. The ATLAS style will only apply
# within the following context:
with style:
    hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution")
    # generate some random data
    ROOT.gRandom.SetSeed()
    for i in xrange(25000):
        hpx.Fill(ROOT.gRandom.Gaus())
    hpx.GetXaxis().SetTitle("random variable [unit]")
    hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]")
    hpx.SetMaximum(1000.)
Ejemplo n.º 23
0
    if not os.path.exists(dir):
        mkdir_p(dir)
    return dir

import numpy as np
# for reproducibilty
# especially for test/train set selection
np.random.seed(1987) # my birth year ;)

MMC_VERSION = 1
MMC_MASS = 'mmc%d_mass' % MMC_VERSION
MMC_PT = 'mmc%d_resonance_pt' % MMC_VERSION

from rootpy.plotting.style import get_style, set_style

style = get_style('ATLAS', shape='square')
#style.SetFrameLineWidth(2)
#style.SetLineWidth(2)
#style.SetTitleYOffset(1.8)
#style.SetTickLength(0.04, 'X')
#style.SetTickLength(0.02, 'Y')

# custom HSG4 modifications
style.SetPadLeftMargin(0.16)
style.SetTitleYOffset(1.6)

style.SetHistTopMargin(0.)
style.SetHatchesLineWidth(1)
style.SetHatchesSpacing(1)
set_style(style)
Ejemplo n.º 24
0
import ROOT
import rootpy
rootpy.log.basic_config_colorized()
from rootpy.plotting import Hist
from rootpy.plotting.style import get_style
from rootpy.interactive import wait

try:
    style_name = sys.argv[1]
except IndexError:
    print('Specify the style with the style name as an argument')
    print('Using the ATLAS style')
    style_name = 'ATLAS'

try:
    style = get_style(style_name)
except ValueError:
    print('Invalid style: `{}`. Using the `ATLAS` style.'.format(style_name))
    style = get_style('ATLAS')

# Use styles as context managers. The ATLAS style will only apply
# within the following context:
with style:
    hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution")
    # generate some random data
    ROOT.gRandom.SetSeed()
    for i in xrange(25000):
        hpx.Fill(ROOT.gRandom.Gaus())
    hpx.GetXaxis().SetTitle("random variable [unit]")
    hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]")
    hpx.SetMaximum(1000.)
Ejemplo n.º 25
0
#!/bin/env python2

import optparse,csv,sys
sys.argv.append("-b")
from ROOT import *
import rootpy as rpy
from rootpy.plotting.style import set_style, get_style
import os

atlas = get_style('ATLAS')
atlas.SetPalette(51)
set_style(atlas)
sys.argv = sys.argv[:-1]

topmass = 173.34

def parse_argv():

    parser = optparse.OptionParser()
    parser.add_option("--lumi", help="luminosity", default=5, type=int)
    #parser.add_option("--z-label", help="z axis title", default="significance in optimal cut")
    parser.add_option("--text-file", help="text csv file", default=None, type=str)
    parser.add_option("--outdir", help="outfile directory", default="plots")
    parser.add_option("--outfilebase", help="outfile base name", default="output")
    parser.add_option("--g-min", help="min gluino mass", default=800, type=float)
    parser.add_option("--g-max", help="max gluino mass", default=2000, type=float)
    parser.add_option("--l-min", help="min lsp mass", default=0, type=float)
    parser.add_option("--l-max", help="max lsp mass", default=1300, type=float)
    parser.add_option("--bin-width", help="bin width", default=100, type=float)
    parser.add_option("--x-dim", help="x dimension of figure", default=800, type=float)
    parser.add_option("--y-dim", help="y dimension of figure", default=600, type=float)
Ejemplo n.º 26
0
def test_get_style():

    mystyle = TStyle("mystyle", "some style")
    assert isinstance(get_style("mystyle"), Style)
Ejemplo n.º 27
0
import os.path, sys
from rootpy.plotting import F1, Hist, Hist2D, HistStack, Canvas, Legend, Pad
from rootpy.plotting.utils import draw
#from rootpy.interactive import wait
from rootpy.io import root_open
from rootpy.tree import Cut
from rootpy.plotting.style import get_style, set_style
from decimal import Decimal
import ROOT

ROOT.gROOT.SetBatch(True)
style = get_style('ATLAS')
style.SetEndErrorSize(3)
titlesize = 25
style.SetTitleSize(titlesize, "x")
style.SetTitleSize(titlesize, "y")
style.SetTitleYOffset(1)
#style.SetTitleXOffset(3)
#style.SetPadTopMargin(0.0)
#style.SetPadRightMargin(0.05)
#style.SetPadBottomMargin(0.2)
#style.SetPadLeftMargin(0.15)
#style.setPalette(51,0)
set_style(style)

labelmargin = 0.18  #Labeling

#==================== EDIT THESE ========================#
lumipb = 12300  #pb-1 (10 fb-1)
lumifb = lumipb / 1000.0
sqrts = 13
Ejemplo n.º 28
0
This example demonstrates how to set the plotting style.
"""
print __doc__
import sys
import ROOT
import rootpy
rootpy.log.basic_config_colorized()
from rootpy.plotting import Hist
from rootpy.plotting.style import get_style
from rootpy.interactive import wait

if len(sys.argv) == 1:
    print "you can also specify a style as argument"

style = get_style(sys.argv[1] if len(sys.argv) > 1 else 'ATLAS')

# Use styles as context managers. The ATLAS style will only apply
# within the following context:
with style:
    hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution")
    # generate some random data
    ROOT.gRandom.SetSeed()
    for i in xrange(25000):
        hpx.Fill(ROOT.gRandom.Gaus())
    hpx.GetXaxis().SetTitle("random variable [unit]")
    hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]")
    hpx.SetMaximum(1000.)
    hpx.Draw()
    wait()