コード例 #1
0
def set_style():
    """
    Definition:
    -----------
            Set the plotting style to ATLAS-style and then point this function to
            "None" so that it can only be called once

    Args:
    -----------
            None
    """
    logging.getLogger("plot_atlas").info("Setting ATLAS style")
    rpp.set_style("ATLAS", mpl=True)
    mpl.rcParams["figure.figsize"] = (6, 6)
    # Force Helvetica in mathmode
    mpl.rcParams["font.family"] = "sans-serif"
    mpl.rcParams["font.sans-serif"] = "Helvetica"
    mpl.rcParams["mathtext.fontset"] = "custom"
    # mpl.rcParams["mathtext.default"] = "regular"
    mpl.rcParams["mathtext.default"] = "sf"
    mpl.rcParams["mathtext.rm"] = "serif"
    mpl.rcParams["mathtext.tt"] = "sans"
    mpl.rcParams["mathtext.it"] = "sans:italic"
    mpl.rcParams["mathtext.bf"] = "sans:bold"
    set_style.func_code = (lambda: None).func_code
コード例 #2
0
def main():
  style = get_style('CMSTDR')
  style.SetTitleSize(0.07, "XYZ")
  style.SetPalette(54) # kBlueYellow
  style.SetPadLeftMargin(0.10)
  style.SetPadRightMargin(0.12)
  set_style(style)
  input_dir = '/home/sauvan/Documents/HEP/Projects/CMS/L1CalorimeterTrigger_Phase2HGCal/Misc/FastShower/output/'
  files = glob(input_dir+'*.root')
  for file_name in files:
    with root_open(file_name) as file:
      for object in file.objects(cls=TCanvas):
        if 'Event 1' in object.GetName():
          plot_event(splitext(basename(file_name))[0], object)
コード例 #3
0
ファイル: plot_overlay.py プロジェクト: zhufengGNSS/rootpy
#!/usr/bin/env python
"""
============================
Overlay Histograms or Graphs
============================

This example demonstrates how to overlay multiple histograms or graphs while
automatically setting axis limits that are visually pleasing.
"""
print(__doc__)
from rootpy.plotting import F1, Hist, HistStack, Graph, Canvas, set_style
from rootpy.plotting.utils import draw
from rootpy.interactive import wait
from math import sin

set_style('ATLAS')

mus = (0, -1, 2)
sigmas = (2, 1, 0.5)
events = (1000, 2000, 100)
colors = ('lawngreen', 'forestgreen', 'mistyrose')
styles = ('\\', '/', '-')

canvas = Canvas()
objects = []

# create a stack
stack = HistStack()
stack.Add(
    Hist(100, -5, 5, color='salmon',
         drawstyle='hist').FillRandom(F1('TMath::Gaus(x, 2, 1)'), 500))
コード例 #4
0
import ROOT
import os
import uuid
from rootpy.plotting import set_style
set_style('ATLAS', shape='rect')
ROOT.gROOT.SetBatch(True)

class correlation_matrix(object):

    def __init__(self, corr_hist):
        self._corr = corr_hist
        self._labels = [str(label) for label in self._corr.GetXaxis().GetLabels()]

    @property
    def names(self):
        return self._labels

    def correlation(self, x, y):
        if not x in self._labels:
            return -999.
        
        if not y in self._labels:
            return -999.

        corr_value = self._corr.GetBinContent(
            self._corr.GetXaxis().FindBin(x),
            self._corr.GetYaxis().FindBin(y))
        return corr_value
        

def correlation_plot(cats, corr_matrices, x_cor, y_cor):
コード例 #5
0
from array import array
import rootpy
import ROOT
rootpy.log.basic_config_colorized()
from rootpy.io import root_open
from rootpy.plotting import Canvas,Graph
from rootpy.plotting import set_style

from statstools.finalfit_uncertband_plot import getPostFitPlottingObjects
from statstools.finalfit_uncertband_plot import UncertGraph

set_style('ATLAS')
# ------------------------------
def Fit_WS(workspace):
    """
    Fit the WS and compute the histograms and TGraphAssymErrors
    for the final plotting drawing

    Parameters
    ----------

    workspace : RooWorkspace
        HSG4 like workspace
    """

    # --> Get the Model Config object
    mc = workspace.obj("ModelConfig")
    if not mc:
        raise RuntimeError('Could not retrieve the ModelConfig object')
    mc.GetParametersOfInterest().first().setVal(1)
#     fit_res = 0
コード例 #6
0
ファイル: trigger_sf.py プロジェクト: cnellist/hhntup
ROOT.gROOT.SetBatch(True)
from externaltools import TauTriggerCorrections
base = TauTriggerCorrections.RESOURCE_PATH

from rootpy.plotting import Canvas, Graph, Legend, Hist2D
from rootpy.plotting.shapes import Line
from rootpy.plotting import get_style, set_style
from rootpy.interactive import wait

import numpy as np

style = get_style('ATLAS', shape='square')
style.SetPadLeftMargin(0.16)
style.SetTitleYOffset(1.6)
style.SetHistTopMargin(0.)
set_style(style)

triggers = [
    ('EF_tau20_medium1', 'red'),
    ('EF_tau20T_medium1', 'black'),
    ('EF_tau29_medium1', 'blue'),
    ('EF_tau29T_medium1', 'green'),
]

pt = np.linspace(20000, 100000, 100)

def draw_curve_7(_func, name, title, ylow, yhigh):
    """ Draw 7TeV trigger efficiency curves """
    graphs = []
    for (trigger, color) in triggers:
        tool = ROOT.TauTriggerCorrections(os.path.join(base, 'triggerSF_%s.root' % trigger))
コード例 #7
0
ファイル: trigger_sf.py プロジェクト: aashaqshah/hhntup
from externaltools import TauTriggerCorrections

base = TauTriggerCorrections.RESOURCE_PATH

from rootpy.plotting import Canvas, Graph, Legend, Hist2D
from rootpy.plotting.shapes import Line
from rootpy.plotting import get_style, set_style
from rootpy.interactive import wait

import numpy as np

style = get_style('ATLAS', shape='square')
style.SetPadLeftMargin(0.16)
style.SetTitleYOffset(1.6)
style.SetHistTopMargin(0.)
set_style(style)

triggers = [
    ('EF_tau20_medium1', 'red'),
    ('EF_tau20T_medium1', 'black'),
    ('EF_tau29_medium1', 'blue'),
    ('EF_tau29T_medium1', 'green'),
]

pt = np.linspace(20000, 100000, 100)


def draw_curve_7(_func, name, title, ylow, yhigh):
    """ Draw 7TeV trigger efficiency curves """
    graphs = []
    for (trigger, color) in triggers:
コード例 #8
0
ファイル: contours.py プロジェクト: Reikyo/hhana
import ROOT
from matplotlib import pyplot as plt
from rootpy import asrootpy
from rootpy.plotting import Hist2D, Canvas, set_style
from rootpy.interactive import wait
import numpy as np
from array import array
from mva.plotting import draw_contours

set_style("ATLAS")

a = Hist2D(20, -3, 3, 20, 0, 6)
a.fill_array(np.random.multivariate_normal(mean=(0, 3), cov=np.arange(4).reshape(2, 2), size=(1e6,)))

c = Canvas()
draw_contours(
    a, linewidths=2, linecolors="red", linestyles="solid", labelsizes=18, labelcolors="red", labelformats="%i"
)
c.Update()
c.SaveAs("plot.png")
wait()