Esempio n. 1
0
def get_plot_attributes(year, dmc, plot):
    """
    Get the plot attributes for a given plot
    """
    year_colors = {
        '2012': 1,
        '2016': default_colors()[0],
        '2017': default_colors()[1]
    }
    marker_style = {'2012': 20, '2016': 22, '2017': 23}
    marker_style_open = {'2012': 24, '2016': 26, '2017': 32}
    fill_style = {'chic1': 3354, 'chic2': 3345, 'chib1': 3354, 'chib2': 3345}
    size = 2
    linewidth = 2

    color = year_colors[year]
    if plot == 'ratio' or plot == 'chic2' or plot == 'chib2':
        marker = marker_style[year]
    else:
        marker = marker_style_open[year]

    attr = {'color': color, 'marker': marker, 'size': size, 'width': linewidth}
    if dmc == 'mc':
        attr['size'] = 0  # do not plot markers for mc
        attr['width'] = 0
        if plot == 'ratio':
            attr['fillalpha'] = (color, 0.5)
        else:
            attr['fillstyle'] = fill_style[plot]

    return attr
def make_mass_quantile_plot(hist, quantile_pairs, color, savename):
    """
    Quantile plots for one state.

    TODO:
    """
    y_range = [0, hist.GetMaximum() * 1.05]
    set_range_hists([hist], y_range=y_range)

    can = mkplot([hist], colors=[color], drawOpt='H')

    leg = r.TLegend(0.1, 0.91, 0.9, 0.95)
    leg.SetNColumns(len(quantile_pairs))
    leg.SetBorderSize(0)

    line_styles = [2, 3, 5, 6]
    # store all lines in this list so that they live long enough to be plotted
    lines = []
    for i, pair in enumerate(quantile_pairs):
        quantiles = get_quantiles(hist, pair)
        qline_1, qline_2 = get_quantile_lines(quantiles, y_range,
                                              default_colors()[0], line_styles[i])
        qline_2.Draw()
        qline_1.Draw()

        leg.AddEntry(qline_1, '[{}, {}]'.format(*pair), 'l')

        lines.append(qline_1)
        lines.append(qline_2)

    leg.Draw()
    can.Draw()
    can.SaveAs(savename)
def make_mass_quantile_plots(mcfile, quantile_pairs, savename_base):
    """
    TODO
    """
    chic1_h, chic2_h = get_gen_splitted_hists(mcfile, 'chicMass',
                                              [select_trigger(),
                                               base_selection()])
    set_labels(chic1_h, xlabel='M^{#mu#mu#gamma}')
    set_labels(chic2_h, xlabel='M^{#mu#mu#gamma}')

    chic1_col = default_colors()[1]
    chic2_col = default_colors()[2]

    make_mass_quantile_plot(chic1_h, quantile_pairs, chic1_col,
                            savename_base + '_chic1.pdf')
    make_mass_quantile_plot(chic2_h, quantile_pairs, chic2_col,
                            savename_base + '_chic2.pdf')
 def get_attributes():
     """attributes for plotting nicely in accordance with order of histograms as
     returned by select_histsk"""
     defc = default_colors()
     # return [
     #     {'color': defc[0], 'marker': 20, 'size': 1.5}, {'color': defc[0], 'marker': 24, 'size': 1.5},
     #     {'color': defc[1], 'marker': 21, 'size': 1.5}, {'color': defc[1], 'marker': 25, 'size': 1.5},
     #     {'color': defc[2], 'marker': 22, 'size': 1.5}, {'color': defc[2], 'marker': 26, 'size': 1.5},
     #     {'color': defc[3], 'marker': 23, 'size': 1.5}, {'color': defc[3], 'marker': 32, 'size': 1.5}
     # ]
     return [
         {'color': defc[0], 'marker': 20, 'size': 1.5},
         {'color': defc[1], 'marker': 21, 'size': 1.5},
         {'color': defc[2], 'marker': 22, 'size': 1.5},
         {'color': defc[3], 'marker': 23, 'size': 1.5}
     ]
def make_var_plot(nom_file, var_files, var):
    """
    Make a variation plot comparing the nominal PPD to the variations PPDs
    """
    nom_ppd = get_scaled_ppd(nom_file, var)
    nom_quants = get_quantiles(nom_ppd, QUANTILES)
    nom_lo, nom_hi = np.diff(nom_quants)
    nom_graph = get_nom_graph(len(var_files), nom_lo, nom_hi)

    # var_graphs = get_var_graphs_wrt_nominal(var_files, nom_quants, var)
    var_graphs = get_var_graphs_wrt_nominal(
        var_files, [nom_ppd.GetMean(), nom_ppd.GetRMS()], var)

    xran = np.max([nom_lo, nom_hi]) * 1.75
    yran = [-0.25, len(var_files) - 0.75]

    can = mkplot(nom_graph,
                 attr=[{
                     'fillalpha': (default_colors()[1], 0.5)
                 }],
                 drawOpt='E2',
                 xLabel=get_label(var),
                 xRange=[-xran, xran],
                 yRange=yran)
    mkplot(r.TLine(0, yran[0], 0, yran[1]),
           can=can,
           drawOpt='same',
           attr=default_attributes(widht=2)[1:])
    mkplot(var_graphs, drawOpt='samePE', can=can, attr=VAR_ATTR)

    phist = can.pltables[0]
    phist.GetYaxis().SetLabelSize(0)
    phist.GetYaxis().SetTickSize(0)

    ltx = setup_latex()
    put_on_latex(ltx, get_labels(var_files.keys()), ndc=True)
    ltx.Draw()
    can.Draw()

    return can
Esempio n. 6
0
def make_plot(data_graph, mc_graphs, pdfname, canvas_sett):
    """
    Make plot and save
    """
    mc_attributes = [{
        'color': default_colors()[0],
        'marker': 25,
        'size': 1.5,
        'fillalpha': (default_colors()[0], 0.5)
    }, {
        'color': default_colors()[1],
        'marker': 26,
        'size': 1.5,
        'fillalpha': (default_colors()[1], 0.5)
    }, {
        'color': default_colors()[2],
        'marker': 27,
        'size': 1.5,
        'fillalpha': (default_colors()[2], 0.5)
    }]

    data_attributes = [{'color': 1, 'marker': 20, 'size': 1.5}]

    set_TDR_style()
    can = r.TCanvas('rcan', 'rcan', 50, 50, 600, 600)
    frame = can.DrawFrame(*canvas_sett['range'])
    frame.SetXTitle(canvas_sett['xtitle'])
    frame.SetYTitle(canvas_sett['ytitle'])

    leg = setup_legend()

    mc_rescaled = rescale_MC_graphs(data_graph, mc_graphs.values(), SCALE_FUNC)

    plot_on_canvas(can,
                   mc_rescaled,
                   drawOpt='P2',
                   leg=leg,
                   legOpt='PF',
                   legEntries=mc_graphs.keys(),
                   attr=mc_attributes)
    plot_on_canvas(can, [data_graph],
                   drawOpt='samePE',
                   leg=leg,
                   legEntries=['data'],
                   attr=data_attributes)

    can.SaveAs(pdfname)
Esempio n. 7
0
import ROOT as r

r.PyConfig.IgnoreCommandLineOptions = True
r.gROOT.SetBatch()

from utils.plot_helpers import (mkplot, setup_legend, default_colors,
                                setup_latex, put_on_latex)
from utils.plot_decoration import YLABELS
from utils.data_handling import list_obj
from utils.graph_utils import get_errors, scale_graph_x
from utils.setup_plot_style import set_TDR_style, add_auxiliary_info
from utils.misc_helpers import cond_mkdir, fmt_float
from utils.constants import m_psiPDG

PCOLOR = default_colors()[0]
SCOLOR = default_colors()[2]
FCOLOR = default_colors()[1]

ATTR = {
    'central': [{
        'color': PCOLOR,
        'marker': 20,
        'size': 1.0,
        'width': 2
    }],
    '1': [{
        'fillalpha': (PCOLOR, 0.65),
        'size': 0,
        'width': 0
    }],
Script that plots all data to best fit model comparisons
"""
import numpy as np

import ROOT as r
r.PyConfig.IgnoreCommandLineOptions = True
r.gROOT.SetBatch()

from utils.plot_helpers import (mkplot, setup_legend, default_colors,
                                _setup_canvas)
from utils.misc_helpers import cond_mkdir
from utils.setup_plot_style import set_basic_style
from utils.data_handling import list_obj
from utils.graph_utils import scale_graph, pull_graph, divide_func, shift_graph

COL = default_colors()

DATA_ATTR = [{
    'color': 1,
    'marker': 20,
    'size': 0.75
}, {
    'color': 1,
    'marker': 25,
    'size': 0.75
}, {
    'color': 1,
    'marker': 26,
    'size': 0.75
}]
# define which variables to read in
# first the ones that are common to both Toy and real MC, then the ones only
# present in the real MC (into a separate) list, then add the efficiencies to
# the Toy MC
TOY_VARIABLES = [
    'Jpsi{Pt,Rap}',
    'photon{Pt,Eta}',
    'mu{P,N}{Pt,Eta}',
    'costh_HX',
]
MC_VARIABLES = TOY_VARIABLES + ['trigger', 'pdgId', 'vtxProb', 'gen_photonEta']
TOY_VARIABLES += ['*eff_sm']
PLOT_ATTRIBUTES = {
    'loose': {
        'mc': {
            'fillalpha': (default_colors()[4], 0.5),
            'size': 0,
            'marker': 22
        },
        'toy': {
            'color': default_colors()[4],
            'size': 1.5,
            'marker': 22
        }
    },
    'fiducial': {
        'mc': {
            'fillalpha': (default_colors()[3], 0.5),
            'size': 0,
            'marker': 23
        },
Esempio n. 10
0
logging.basicConfig(level=logging.DEBUG,
                    format='%(levelname)s - %(funcName)s: %(message)s')

from os.path import dirname

from utils.misc_helpers import cond_mkdir, get_storable_name, get_bin_cut_df
from utils.plot_helpers import plot_on_canvas, default_colors
from utils.roofit_utils import get_var_err
from utils.data_handling import get_dataframe
from utils.setup_plot_style import set_TDR_style
from utils.graph_utils import scale_graph, get_y

from common_func import get_bin_sel_info

mc_attributes = [{
    'color': default_colors()[0],
    'marker': 25,
    'size': 1.5,
    'fillalpha': (default_colors()[0], 0.5)
}, {
    'color': default_colors()[1],
    'marker': 26,
    'size': 1.5,
    'fillalpha': (default_colors()[1], 0.5)
}, {
    'color': default_colors()[2],
    'marker': 27,
    'size': 1.5,
    'fillalpha': (default_colors()[2], 0.5)
}]
def make_comp_plot(graph, intgraph, fit=False):
    """
    Make one comparison plot and return the TCanvasWrapper
    """
    plt_attr = [{
        'color': default_colors()[0],
        'marker': 20,
        'size': 1.5
    }, {
        'color': default_colors()[1],
        'marker': 24,
        'size': 0.5,
        'fillalpha': (default_colors()[1], 0.5)
    }, {
        'color': default_colors()[4],
        'line': 2,
        'width': 2
    }]

    graph_name = graph.GetName().replace('_v_costh', '')
    if graph_name in FIX_RANGES:
        yRange = FIX_RANGES[graph_name]
    else:
        yRange = None

    ylabel = YLABELS[graph_name] if graph_name in YLABELS else graph_name

    can = mkplot(graph,
                 xRange=[0, 1],
                 drawOpt='PE',
                 attr=plt_attr[0:],
                 yRange=yRange,
                 yLabel=ylabel,
                 xLabel='|cos#vartheta^{HX}|')

    # some cosmetics
    can.SetTopMargin(0.05)
    can.SetRightMargin(0.02)
    can.SetLeftMargin(0.15)
    can.pltables[0].SetTitleOffset(2.1, 'Y')

    if intgraph is not None or fit:
        leg = setup_legend(0.65, 0.85, 0.97, 0.94)

    if intgraph is not None:
        can = mkplot(intgraph,
                     can=can,
                     drawOpt='sameP2',
                     attr=plt_attr[1:],
                     leg=leg,
                     legEntries=['cos#vartheta^{HX} int. fit'],
                     legOpt='PLEF')
        can = mkplot(intgraph, can=can, drawOpt='samePE', attr=plt_attr[1:])
    if fit:
        const = r.TF1('const', '[0]', 0, 1)
        const.SetParameter(0, np.array(graph.GetX())[0])
        fit_res = graph.Fit(const, 'NSEX0')

        can = mkplot(const,
                     can=can,
                     drawOpt='sameL',
                     attr=plt_attr[2:],
                     leg=leg,
                     legEntries=['fit to constant'],
                     legOpt='L')

        ltx = setup_latex()
        can.add_tobject(ltx)
        put_on_latex(ltx,
                     [(0.595, 0.2, 'c = {:.2e} +/- {:.2e}'.format(
                         const.GetParameter(0), const.GetParError(0))),
                      (0.595, 0.25, '#chi^{{2}} / ndf = {:.2f} / {}'.format(
                          fit_res.Chi2(), fit_res.Ndf()))],
                     ndc=True)
    can.Update()

    return can