Ejemplo n.º 1
0
def jetid_changes(args, additional_dictionary=None):
    """Plot changes from jetID veto for leading jet vs leading skim jet over pt, eta, phi"""
    plots = []
    input_files, args_nofiles = get_input_files(args)
    #binningsZJet.BinningsDictZJet().binnings_dict["abseta"]
    for x_expr, x_binning in [
        ("jet1pt", "20,0,200"),
        ("jet1eta", binningsZJet.BinningsDictZJet().binnings_dict["eta"]),
        ("jet1phi", binningsZJet.BinningsDictZJet().binnings_dict["phi"])
    ]:
        d = {
            'labels':
            ['valid'] * len(input_files) + ["total"] * len(input_files),
            'x_expressions': [x_expr],
            'y_expressions': ["skim%s" % x_expr],
            'x_lims': lims_from_binning(x_binning),
            'y_lims': lims_from_binning(x_binning),
            'x_bins': x_binning,
            'y_bins': x_binning,
            'filename': "jetid_changes_" + x_expr,
        }
        if additional_dictionary is not None:
            d.update(additional_dictionary)
        plots.append(d)
    return [PlottingJob(plots=plots, args=args)]
Ejemplo n.º 2
0
def fit_function(args=None, additional_dictionary=None, only_normalized=False, channel='m', quantity_list=None):
    if quantity_list is None:
        quantity_list = []
    plots = []
    for quantity in quantity_list:
        d = {
            'x_expressions': [quantity],
            'cutlabel': True,
            'analysis_modules': [],
            'plot_modules': ['PlotMplZJet'],
            'filename': 'Z' + channel + channel + '_' + quantity.replace('/', '%') + '_fit',
            'legend': 'center left',
            'y_subplot_lims': [0.75, 1.25],
            'alphas': '0.5',
            'markers': ['_', '_', 'fill', 'fill'],
            'colors': ['black', 'blue', 'black'],
            'ratio_denominator_nicks': ['nick1'],
            'ratio_numerator_nicks': ['nick0'],
            'output_dir': "plots/%s/" % datetime.date.today().strftime('%Y_%m_%d')
        }
        if quantity in binningsZJet.BinningsDictZJet().binnings_dict:
            x_bins = binningsZJet.BinningsDictZJet().binnings_dict[quantity].replace('000', '0')
            x_lims = lims_from_binning(x_bins)
            d['x_bins'] = [x_bins]
            # d['x_bins'] = '400,0,2'
            # d['x_lims'] = x_lims

        if additional_dictionary:
            d.update(additional_dictionary)

        if len(d['files']) == 2:
            fit_function_datamc_gauss(d)
            d['analysis_modules'] = d['analysis_modules'] + ['Ratio']
        elif len(d['files']) == 1:
            # pass
            fit_function_mc_gauss(d)
            # fit_function_mc_doublegauss(d)
            # fit_function_mc_crystalball(d)
        if False:
            if channel == 'e':
                d['function_ranges'] = '0.87225,1.15225'  # for jet1pt/genjet1pt with 0.25<=alpha<0.3, 94.0% truncation
            if channel == 'm':
                d['function_ranges'] = '0.77925,1.22825'  # for jet1pt/genjet1pt with 0.25<=alpha<0.3, 98.5% truncation

        if only_normalized:
            # shape comparison
            d['analysis_modules'] = d['analysis_modules'] + ['NormalizeToFirstHisto']
            d['filename'] = 'Z' + channel + channel + '_' + quantity.replace('/', '%') + '_shapeComparison'

        plots.append(d)

    return [PlottingJob(plots=plots, args=args)]
Ejemplo n.º 3
0
def jetid_efficiency(args, additional_dictionary=None):
    """Plot efficiency of jetID veto for leading skim jet over pt, eta, phi"""
    plots = []
    input_files, args_nofiles = get_input_files(args)
    binnings = binningsZJet.BinningsDictZJet()
    for x_expr, x_binning in [
        ("skimjet1pt", "20,0,200"),
        ("skimjet1eta", binnings.binnings_dict["eta"]),
        ("skimjet1phi", binnings.binnings_dict["phi"]),
        ("zpt", "50,0,200"),
    ]:
        d = {
            'labels':
            ['valid'] * len(input_files) + ["total"] * len(input_files),
            'x_expressions': [x_expr],
            'x_lims':
            lims_from_binning(x_binning),
            'weights': ['(weight*skimjet1validity)'] * len(input_files) +
            ["(weight*(skimjet1pt>=0))"] * len(input_files),
            'x_bins':
            x_binning,
            'filename':
            "jetid_efficiency_" + x_expr,
            'analysis_modules': ['Ratio'],
            'y_subplot_lims': [0.01, 0.99],
        }
        if additional_dictionary is not None:
            d.update(additional_dictionary)
        plots.append(d)
    return [PlottingJob(plots=plots, args=args)]
Ejemplo n.º 4
0
def response_time_dependence(args=None, additional_dictionary=None):
    """ Plot the response vs time (run-number) for different eta regions"""
    plots = []
    etabins = binningsZJet.BinningsDictZJet().binnings_dict["abseta"].split(
        " ")
    weights = [
        "{}<abs(jet1eta)&&{}>abs(jet1eta)".format(lower, upper)
        for lower, upper in zip(etabins, etabins[1:])
    ]
    labels = [
        r"{:.2f}<|$\\eta_{{jet}}$|<{:.2f}".format(float(lower), float(upper))
        for lower, upper in zip(etabins, etabins[1:])
    ]
    for response in ['mpf', 'ptbalance']:
        d = {
            # input
            'zjetfolders': ['noetacuts'],
            'x_expressions':
            'run',
            'y_expressions':
            response,
            'weights':
            weights,
            'tree_draw_options':
            'prof',
            # analysis
            'analysis_modules': ['FunctionPlot'],
            'functions': ['[0]+[1]*x'],
            'function_fit': ['nick{}'.format(i) for i in range(len(weights))],
            'function_parameters': ['1,1'],
            'function_nicknames':
            ['fnick{}'.format(i) for i in range(len(weights))],
            # formatting
            'y_lims': [0.8, 1.1],
            'alphas': [0.3],
            'colors':
            ['black', 'red', 'blue', 'green', 'purple', 'orange', 'cyan'
             ][:len(weights)] *
            2,  # TODO take color names directly from plotmpl.py
            # TODO improve x-axis ticks and ticklabels
            'labels':
            labels + [None] * len(labels),
            'legend_cols':
            2,
            # output
            'filename':
            'time_dependence_' + response,
        }
        if response == 'mpf':
            d['legend'] = 'lower left'
        if additional_dictionary:
            d.update(additional_dictionary)
        plots.append(d)
    return [PlottingJob(plots=plots, args=args)]
Ejemplo n.º 5
0
def twodimplot_datamc_comparison(args=None,
                                 additional_dictionary=None,
                                 only_normalized=False,
                                 channel="m"):
    """Comparison in 2D Plots"""
    plots = []
    x_dict = generate_dict(channel_dict=channel)

    #Plotting profile plots of various quantities:
    quantity_2d_list = []
    if channel == 'm':
        quantity_2d_list.extend([
            ['muminuseta', 'mupluseta'],
        ])
    elif channel == 'e':
        quantity_2d_list.extend([
            ['eminuseta', 'epluseta'],
        ])

    for quantity_pair in quantity_2d_list:
        nick_list = ['nick0', 'nick1', 'nick_div']
        for nick, label in [[nick_list[0], 'DATA'], [nick_list[1], 'MC'],
                            [nick_list[2], 'DATA/MC']]:
            print nick
            d = {
                'cutlabel': True,
                #'analysis_modules': ['NormalizeToFirstHisto'],
                #"plot_modules": ["PlotMplZJet"],
                #'y_subplot_lims': [0.99, 1.01],
                'colormap': 'Blues',
            }
            if additional_dictionary:
                d.update(additional_dictionary)
            d.update({
                'y_expressions': [quantity_pair[1]],
                'x_expressions': [quantity_pair[0]],
                'labels':
                label,
                "title":
                'Work in Progress',  #quantity_pair[0]+' vs. '+quantity_pair[1],
                'filename':
                quantity_pair[0] + '_vs_' + quantity_pair[1] + '_' + nick,
                #'y_log': quantity_pair[1] in ['jet1pt', 'zpt'],
                #'x_log': quantity_pair[0] in ['jet1pt', 'zpt'],
            })
            if nick == 'nick_div':
                d.update({
                    'analysis_modules': ['Divide'],
                    'divide_numerator_nicks': 'nick1',
                    'divide_denominator_nicks': 'nick0',
                    'divide_result_nicks': nick,
                    'event_number_label': False,
                })
            d.update({
                'nicks_blacklist':
                list(filter(lambda x: x != nick, nick_list)),
                'nicks_whitelist':
                nick,
            })

            if quantity_pair[0] in binningsZJet.BinningsDictZJet(
            ).binnings_dict:
                x_bins = binningsZJet.BinningsDictZJet().binnings_dict[
                    quantity_pair[0]]
                x_lims = lims_from_binning(x_bins)
                d["x_bins"] = [x_bins]
                d["x_lims"] = x_lims
            elif quantity_pair[0] in x_dict:
                d["x_bins"] = [x_dict[quantity_pair[0]][0]]
                d["x_lims"] = lims_from_binning(x_dict[quantity_pair[0]][0])
            if quantity_pair[1] in binningsZJet.BinningsDictZJet(
            ).binnings_dict:
                y_bins = binningsZJet.BinningsDictZJet().binnings_dict[
                    quantity_pair[1]]
                y_lims = lims_from_binning(x_bins)
                d["y_bins"] = [y_bins]
                d["y_lims"] = y_lims
            elif quantity_pair[1] in x_dict:
                d["y_bins"] = [x_dict[quantity_pair[1]][0]]
                d["y_lims"] = lims_from_binning(x_dict[quantity_pair[1]][0])
            print d
            plots.append(d)

    return [PlottingJob(plots=plots, args=args)]
Ejemplo n.º 6
0
def profplot_datamc_comparison(args=None,
                               additional_dictionary=None,
                               only_normalized=False,
                               channel="m"):
    """Comparison in 2D Plots"""
    plots = []
    x_dict = generate_dict(channel_dict=channel)

    #Plotting profile plots of various quantities:
    quantity_2d_list = [['zeta', 'zmass'], ['zpt', 'zmass'], ['zpt', 'mpf']]
    if channel == 'm':
        quantity_2d_list.extend([
            ['muminuseta', 'zmass'],
            ['mupluseta', 'zmass'],
        ])
    elif channel == 'e':
        quantity_2d_list.extend([
            ['eminuseta', 'zmass'],
            ['epluseta', 'zmass'],
        ])


#  x_dict.update({'zmass': ['40,90,92'],})
    x_dict.update({
        'zmass': ['40,82.1876,100.1876'],
    })
    for quantity_pair in quantity_2d_list:
        d = {
            'cutlabel': True,
            'analysis_modules': ['Ratio'],
            'tree_draw_options': 'prof',
            "plot_modules": ["PlotMplZJet"],
            'y_subplot_lims': [0.90, 1.1],
        }
        if additional_dictionary:
            d.update(additional_dictionary)
        d.update({
            'y_expressions': [quantity_pair[1]],
            'x_expressions': [quantity_pair[0]],
            "title":
            'Work in Progress',  #quantity_pair[0]+' vs. '+quantity_pair[1],
            'filename': quantity_pair[0] + '_vs_' + quantity_pair[1],
            'y_log': quantity_pair[1] in ['jet1pt', 'zpt'],
            'x_log': quantity_pair[0] in ['jet1pt', 'zpt'],
        })
        if quantity_pair[1] == "zmass":
            d['lines'] = ['91.1876']
        if quantity_pair[0] in [
                'zeta', 'mupluseta', 'muminuseta', 'epluseta', 'eminuseta'
        ]:
            d["plot_modules"] = ["PlotMplZJet", "PlotMplRectangle"]
            if channel == 'm':
                d["rectangle_x"] = [-6, -1.3, 1.3, 6]
            elif channel == 'e':
                d["rectangle_x"] = [-6, -1.479, 1.479, 6]
            d["rectangle_alpha"] = [0.2]
            d["rectangle_color"] = ["red"]
        if quantity_pair[0] in binningsZJet.BinningsDictZJet().binnings_dict:
            x_bins = binningsZJet.BinningsDictZJet().binnings_dict[
                quantity_pair[0]]
            x_lims = lims_from_binning(x_bins)
            d["x_bins"] = [x_bins]
            d["x_lims"] = x_lims
        elif quantity_pair[0] in x_dict:
            d["x_bins"] = [x_dict[quantity_pair[0]][0]]
            d["x_lims"] = lims_from_binning(x_dict[quantity_pair[0]][0])
        if quantity_pair[1] in binningsZJet.BinningsDictZJet().binnings_dict:
            y_bins = binningsZJet.BinningsDictZJet().binnings_dict[
                quantity_pair[1]]
            y_lims = lims_from_binning(x_bins)
            #  d["y_bins"] = [y_bins]
            d["y_lims"] = y_lims
        elif quantity_pair[1] in x_dict:
            #  d["y_bins"] = [x_dict[quantity_pair[1]][0]]
            d["y_lims"] = lims_from_binning(x_dict[quantity_pair[1]][0])
        plots.append(d)

    return [PlottingJob(plots=plots, args=args)]
Ejemplo n.º 7
0
def general_comparison(args=None,
                       additional_dictionary=None,
                       only_normalized=False,
                       channel='m'):
    """Comparison of: various quantities, both absolute and normalized"""
    plots = []
    x_dict = generate_dict(channel_dict=channel)
    quantity_list = [
        'zpt', 'zeta', 'zphi', 'zy', 'metphi', 'met', 'npv', 'jet1pt',
        'jet1eta', 'jet2pt', 'jet2eta', 'mpf', 'zmass'
    ]
    quantity_list_ee = [
        'epluseta', 'eminuseta', 'eminuspt', 'epluspt', 'eminusphi', 'eplusphi'
    ]
    quantity_list_mm = [
        'mupluseta', 'muminuseta', 'muminuspt', 'mupluspt', 'muminusphi',
        'muplusphi'
    ]
    if channel == "m": quantity_list.extend(quantity_list_mm)
    elif channel == "e": quantity_list.extend(quantity_list_ee)
    for quantity in quantity_list:
        # normal comparison
        d = {
            'x_expressions': [quantity],
            'cutlabel': True,
            'analysis_modules': ['Ratio'],
            'y_subplot_lims': [0.75, 1.25],
            'y_log': quantity in ['zpt'],
            'x_log': quantity in ['zpt'],
            "plot_modules": ["PlotMplZJet"],
        }
        if quantity in x_dict:
            d["x_bins"] = [x_dict[quantity][0]]
            d["legend"] = x_dict[quantity][1]

        if additional_dictionary:
            d.update(additional_dictionary)
        if quantity == 'alpha' and (additional_dictionary is None
                                    or 'zjetfolders'
                                    not in additional_dictionary):
            d['zjetfolders'] = ['noalphacuts']

        if quantity == 'zphi':
            d['y_rel_lims'] = [1, 1.3]
        elif quantity == 'zpt':
            d['y_rel_lims'] = [1, 400]

        if quantity in binningsZJet.BinningsDictZJet().binnings_dict:
            x_bins = binningsZJet.BinningsDictZJet().binnings_dict[quantity]
            x_lims = lims_from_binning(x_bins)
            d["x_bins"] = [x_bins]
            d["x_lims"] = x_lims
        elif quantity in x_dict:
            d["x_bins"] = [x_dict[quantity][0]]
            d["x_lims"] = lims_from_binning(x_dict[quantity][0])

        if quantity in [
                'zeta', 'mupluseta', 'muminuseta', 'epluseta', 'eminuseta'
        ]:
            d["plot_modules"] = ["PlotMplZJet", "PlotMplRectangle"]
            if channel == 'm':
                d["rectangle_x"] = [-6, -1.3, 1.3, 6]
            elif channel == 'e':
                d["rectangle_x"] = [-6, -1.479, 1.479, 6]
            d["rectangle_alpha"] = [0.2]
            d["rectangle_color"] = ["red"]

        if not only_normalized:
            plots.append(d)

        # shape comparison
        d2 = copy.deepcopy(d)
        d2.update({
            'analysis_modules': ['NormalizeToFirstHisto', 'Ratio'],
            'filename': quantity + "_shapeComparison",
            'title': 'Work in Progress',  #"Shape Comparison",
            'legend': 'upper right',
            'y_subplot_lims': [0.75, 1.25],
        })
        if channel == 'em':
            d2['y_label'] = 'Electron Events'
        if additional_dictionary:
            d2.update(additional_dictionary)
        plots.append(d2)

    return [PlottingJob(plots=plots, args=args)]
Ejemplo n.º 8
0
def general_mc_comparison(args=None, additional_dictionary=None, channel="m"):
    """Comparison of: various quantities, both absolute and normalized"""
    plots = []
    x_dict = generate_dict(channel_dict=channel)
    quantity_list = ['puWeight', 'generatorWeight', 'weight', 'hlt']  #
    quantity_list_ee = []
    quantity_list_mm = []
    if channel == "m": quantity_list.extend(quantity_list_mm)
    elif channel == "e": quantity_list.extend(quantity_list_ee)
    for quantity in quantity_list:
        # normal comparison
        d = {
            'x_expressions': [quantity],
            'cutlabel':
            True,
            'no_weight':
            quantity in ['generatorWeight', 'weight', 'puWeight', 'hlt'],
            'y_log':
            quantity in ['zpt'],
            'x_log':
            quantity in ['zpt'],
            "plot_modules": ["PlotMplZJet"],
        }
        if quantity in x_dict:
            d["x_bins"] = [x_dict[quantity][0]]
            d["legend"] = x_dict[quantity][1]

        if additional_dictionary:
            d.update(additional_dictionary)
        if quantity == 'alpha' and (additional_dictionary is None
                                    or 'zjetfolders'
                                    not in additional_dictionary):
            d['zjetfolders'] = ['noalphacuts']

        if quantity == 'zphi':
            d['y_rel_lims'] = [1, 1.3]
        elif quantity == 'zpt':
            d['y_rel_lims'] = [1, 400]
        elif quantity in ['generatorWeight', 'weight', 'puWeight', 'hlt']:
            d['plot_modules'] = ['PlotMplZJet', 'PlotMplMean']

        if quantity in binningsZJet.BinningsDictZJet().binnings_dict:
            x_bins = binningsZJet.BinningsDictZJet().binnings_dict[quantity]
            x_lims = lims_from_binning(x_bins)
            d["x_bins"] = [x_bins]
            d["x_lims"] = x_lims
        elif quantity in x_dict:
            d["x_bins"] = [x_dict[quantity][0]]
            d["x_lims"] = lims_from_binning(x_dict[quantity][0])

        if quantity in [
                'zeta', 'mupluseta', 'muminuseta', 'epluseta', 'eminuseta'
        ]:
            d["plot_modules"] = ["PlotMplZJet", "PlotMplRectangle"]
            if channel == 'm':
                d["rectangle_x"] = [-6, -1.3, 1.3, 6]
            elif channel == 'e':
                d["rectangle_x"] = [-6, -1.479, 1.479, 6]
            d["rectangle_alpha"] = [0.2]
            d["rectangle_color"] = ["red"]

        plots.append(d)
    return [PlottingJob(plots=plots, args=args)]
Ejemplo n.º 9
0
def zmass_comparison(args=None,
                     additional_dictionary=None,
                     only_normalized=False,
                     channel="m"):
    """Comparison of: zmass, both absolute and normalized"""
    plots = []
    x_dict = generate_dict(channel_dict=channel)
    quantity = 'zmass'
    d = {
        'x_expressions': [quantity],
        'cutlabel': True,
        'y_subplot_lims': [0.75, 1.25],
        'analysis_modules': ['NormalizeToFirstHisto', 'Ratio', 'FunctionPlot'],
        #'analysis_modules': ['Ratio', 'FunctionPlot'],
        'filename': quantity + '_fit',
        'title': 'Work in Progress',  #r'$\\mathrm{M_{Z}}$',
        'legend': 'upper right',
        'y_subplot_lims': [0.75, 1.25],
    }
    if quantity in x_dict:
        d["x_bins"] = [x_dict[quantity][0]]
        d["legend"] = x_dict[quantity][1]
    if quantity in binningsZJet.BinningsDictZJet().binnings_dict:
        x_bins = binningsZJet.BinningsDictZJet().binnings_dict[quantity]
        x_lims = lims_from_binning(x_bins)
        d["x_bins"] = [x_bins]
        d["x_lims"] = x_lims
    elif quantity in x_dict:
        d["x_bins"] = [x_dict[quantity][0]]
        d["x_lims"] = lims_from_binning(x_dict[quantity][0])
    if additional_dictionary:
        d.update(additional_dictionary)
    fit_function(d)
    if channel == "m":
        d.update({
            #"function_parameters": "91,2.3,3100",
            "function_parameters": "91,2.2,0.,0.,3500",
        })
    if channel == "e":
        d.update({
            #"function_parameters": "91,2.3,3100",
            "function_parameters": "91,2.2,0.,0.,3100",
        })
    plots.append(d)
    d2 = {}
    weight_name = 'error'
    for det_part in ['Barrel', 'EndCap+', 'EndCap-']:
        d2["{0}".format(det_part)] = copy.deepcopy(d)
        if channel == "m":
            cut = '1.3'
            minus_quantity = 'muminuseta'
            plus_quantity = 'mupluseta'
        elif channel == "e":
            cut = '1.479'
            minus_quantity = 'eminuseta'
            plus_quantity = 'epluseta'
        if det_part == "EndCap+":
            weight_name = minus_quantity + '>' + cut + '&&' + plus_quantity + '>' + cut
            if channel == "m":
                d2["{0}".format(det_part)].update({
                    #"function_parameters": "91,2.3,3100",
                    "function_parameters":
                    "91,2.2,0.,0.,3000",
                })
            if channel == "e":
                d2["{0}".format(det_part)].update({
                    #"function_parameters": "91,2.3,3100",
                    "function_parameters":
                    "91,2.2,0.,0.,3100",
                })
        elif det_part == "EndCap-":
            weight_name = minus_quantity + '<-' + cut + '&&' + plus_quantity + '<-' + cut
            if channel == "m":
                d2["{0}".format(det_part)].update({
                    #"function_parameters": "91,2.3,3100",
                    "function_parameters":
                    "91,2.2,0.,0.,3100",
                })
            if channel == "e":
                d2["{0}".format(det_part)].update({
                    #"function_parameters": "91,2.3,3100",
                    "function_parameters":
                    "91,2.2,0.,0.,3100",
                })
        elif det_part == "Barrel":
            weight_name = 'abs(' + minus_quantity + ')<' + cut + '&&abs(' + plus_quantity + ')<' + cut
            if channel == "m":
                d2["{0}".format(det_part)].update({
                    #"function_parameters": "91,2.3,1000",
                    "function_parameters":
                    "91,2.2,0.,0.,1200",
                })
            if channel == "e":
                d2["{0}".format(det_part)].update({
                    #"function_parameters": "91,2.3,1000",
                    "function_parameters":
                    "91,2.2,0.,0.,1000",
                })
        d2["{0}".format(det_part)].update({
            'filename':
            quantity + '_' + det_part + '_fit',
            'title':
            'Work in Progress',  #r'$M\\mathrm{_{Z}}'+'('+det_part+')$',
            'weights':
            weight_name,
        })
        plots.append(d2["{0}".format(det_part)])
    return [PlottingJob(plots=plots, args=args)]
Ejemplo n.º 10
0
def genzmass_fit(args=None,
                 additional_dictionary=None,
                 only_normalized=False,
                 channel="m"):
    """Comparison of: zmass, both absolute and normalized"""
    plots = []
    x_dict = generate_dict(channel_dict=channel)
    quantity = 'genzmass'
    d = {
        'x_expressions': [quantity],
        'cutlabel': True,
        'y_subplot_lims': [0.75, 1.25],
        'analysis_modules': ['FunctionPlot'],
        'filename': quantity + '_fit',
        'title': 'Work in Progress',  #r'$\\mathrm{M_{Z,gen}}$',
        'legend': 'upper right',
        'y_subplot_lims': [0.75, 1.25],
        "markers": ["fill"],
    }
    if quantity in x_dict:
        d["x_bins"] = [x_dict[quantity][0]]
        d["legend"] = x_dict[quantity][1]
    if quantity in binningsZJet.BinningsDictZJet().binnings_dict:
        x_bins = binningsZJet.BinningsDictZJet().binnings_dict[quantity]
        x_lims = lims_from_binning(x_bins)
        d["x_bins"] = [x_bins]
        d["x_lims"] = x_lims
    elif quantity in x_dict:
        d["x_bins"] = [x_dict[quantity][0]]
        d["x_lims"] = lims_from_binning(x_dict[quantity][0])
    if additional_dictionary:
        d.update(additional_dictionary)
    fit_function_gen(d)
    if channel == "m":
        d.update({
            "labels": [r"$\\mu_\\mathrm{MC}$",
                       ""],  #default format of labels ["MC", "MC_fit"]
            "function_parameters": "91,2.4,2500",
        })
    elif channel == "e":
        d.update({
            "labels": [r"$e_\\mathrm{MC}$",
                       ""],  #default format of labels ["MC", "MC_fit"]
            "function_parameters": "91,2.3,5000",
        })
#  d.update({"texts": [d.get('texts'),r"$\\mathrm{\\Gamma_{Z,PDG} = 2.4952 \\pm 0.0023}$"],
#    "texts_x": [d.get('texts_x'),0.55],
#    "texts_y": [d.get('texts_y'),0.80],
#    })
    plots.append(d)
    d2 = {}
    weight_name = 'error'
    for det_part in [
            'Barrel', 'EndCap+', 'EndCap-'
    ]:  #,'Barrel&EndCap+','Barrel&EndCap-','EndCap+&EndCap-']:
        d2["{0}".format(det_part)] = copy.deepcopy(d)
        if channel == "m":
            cut = '1.3'
            minus_quantity = 'muminuseta'
            plus_quantity = 'mupluseta'
        elif channel == "e":
            cut = '1.479'
            minus_quantity = 'eminuseta'
            plus_quantity = 'epluseta'
        if det_part == "EndCap+":
            weight_name = minus_quantity + '>' + cut + '&&' + plus_quantity + '>' + cut
            if channel == "m":
                d2["{0}".format(det_part)].update({
                    "function_parameters":
                    "91,2.2,2500",
                })
            if channel == "e":
                d2["{0}".format(det_part)].update({
                    "function_parameters":
                    "91,2.2,2500",
                })
        elif det_part == "EndCap-":
            weight_name = minus_quantity + '<-' + cut + '&&' + plus_quantity + '<-' + cut
            if channel == "m":
                d2["{0}".format(det_part)].update({
                    "function_parameters":
                    "91,2.2,2500",
                })
            if channel == "e":
                d2["{0}".format(det_part)].update({
                    "function_parameters":
                    "91,2.2,2500",
                })
        elif det_part == "Barrel":
            weight_name = 'abs(' + minus_quantity + ')<' + cut + '&&abs(' + plus_quantity + ')<' + cut
            if channel == "m":
                d2["{0}".format(det_part)].update({
                    "function_parameters":
                    "91,2.2,3500",
                })
            if channel == "e":
                d2["{0}".format(det_part)].update({
                    "function_parameters":
                    "91,2.3,4500",
                })


#    elif det_part=="Barrel&EndCap+":
#      weight_name='abs('+minus_quantity+')<'+cut+'&&'+plus_quantity+'>'+cut+'||abs('+plus_quantity+')<'+cut+'&&'+minus_quantity+'>'+cut
#      if channel == "m":
#        d2["{0}".format(det_part)].update({
#        "function_parameters": "91,2.2,3500",
#        })
#      if channel == "e":
#        d2["{0}".format(det_part)].update({
#        "function_parameters": "91,2.3,4500",
#        })
#
#    elif det_part=="Barrel&EndCap-":
#      weight_name='abs('+minus_quantity+')<'+cut+'&&'+plus_quantity+'>-'+cut+'||abs('+plus_quantity+')<'+cut+'&&'+minus_quantity+'>-'+cut
#      if channel == "m":
#        d2["{0}".format(det_part)].update({
#        "function_parameters": "91,2.2,3500",
#        })
#      if channel == "e":
#        d2["{0}".format(det_part)].update({
#        "function_parameters": "91,2.3,4500",
#        })
#
#    elif det_part=="EndCap+&EndCap-":
#      weight_name=minus_quantity+'>'+cut+'&&'+plus_quantity+'>-'+cut+'||'+plus_quantity+'>'+cut+'&&'+minus_quantity+'>-'+cut
#      if channel == "m":
#        d2["{0}".format(det_part)].update({
#        "function_parameters": "91,2.2,3500",
#        })
#      if channel == "e":
#        d2["{0}".format(det_part)].update({
#        "function_parameters": "91,2.3,4500",
#        })
        d2["{0}".format(det_part)].update({
            'filename':
            quantity + '_' + det_part + '_fit',
            'title':
            'Work in Progress',  #r'$M\\mathrm{_{Z}}'+'('+det_part+')$',
            'weights':
            weight_name,
        })
        plots.append(d2["{0}".format(det_part)])
    return [PlottingJob(plots=plots, args=args)]
Ejemplo n.º 11
0
def jer_truncation_scan_jer_only(args=None,
                                 additional_dictionary=None,
                                 channel='m'):
    """Profile Plot of RMS quantity in bins of alpha"""
    # x_dict = generate_dict(channel_dict=channel)

    cut_quantity = 'alpha'  # x_quantity on the plot
    # cut_binnings=['0.025 0.05 0.075 0.1 0.125 0.15 0.175 0.2 0.225 0.25 0.275 0.3'] # x_bins in plot
    cut_binning = [0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3]  # x_bins in plot

    truncations_list = [98.5, 97., 95.5, 94.,
                        92.5]  # [85., 93., 95., 97., 98.5]
    plots_list = ['MC', 'Data']
    plots = []

    for plot_type in plots_list:
        d = {
            'analysis_modules': [],
            'plot_modules': ['PlotMplZJet'],
            'legend':
            'upper left',
            'filename':
            'Z' + channel + channel + '_JER_alpha_truncationscan_JER_' +
            plot_type,
        }
        if additional_dictionary:
            d.update(additional_dictionary)

        if plot_type == 'Data':
            rms_quantities = [
                'ptbalance', 'genjet1pt/genzpt', 'genzpt/zpt',
                'jet1pt/genjet1pt'
            ]
            rms_quantities_labels = [
                'PTBal(Data)', 'PLI(MC)', 'ZRes(MC)', 'JER(MC-generated)'
            ]
            rms_quantities_colors = [
                'grey', 'springgreen', 'forestgreen', 'orange'
            ]
            minuend_quantity = 'PTBal(Data)'
            subtrahend_quantities = 'PLI(MC) ZRes(MC)'
            result_quantity = 'JER(Data-extracted)'
        elif plot_type == 'MC':
            rms_quantities = [
                'jet1pt/zpt', 'genjet1pt/genzpt', 'genzpt/zpt',
                'jet1pt/genjet1pt'
            ]
            rms_quantities_labels = [
                'PTBal(MC)', 'PLI(MC)', 'ZRes(MC)', 'JER(MC-generated)'
            ]
            rms_quantities_colors = [
                'royalblue', 'springgreen', 'forestgreen', 'orange'
            ]
            minuend_quantity = 'PTBal(MC)'
            subtrahend_quantities = 'PLI(MC) ZRes(MC)'
            result_quantity = 'JER(MC-extracted)'
        else:
            rms_quantities = []
            rms_quantities_labels = []
            rms_quantities_colors = []
            minuend_quantity = ''
            subtrahend_quantities = ''
            result_quantity = ''

        # saving old entries for new order usage
        old_files = d['files']  # contains ['MC_file', 'Data_file']
        old_corrections = d['corrections']  # analogous to files
        old_weights = d['weights']

        # deleting old entries for new order
        d.update({
            'files': [],
            'nicks': [],
            'corrections': [],
            'x_expressions': [],
            'nicks_whitelist': [],
            'histogram_from_rms_nicks': [],
            'histogram_from_rms_newnicks': [],
            'histogram_from_rms_x_values': [],
            'histogram_from_rms_truncations': [],
            'colors': [],
            'alphas': [],
            'labels': [],
            'markers': ['+'],
            'weights': [],
            'function_fit': [],
            'function_nicknames': [],
            'functions': [],
            'function_parameters': [],
            'function_ranges': [],
            'line_styles': [],
            'x_bins': [],
            # 'x_lims': [],
            'histogram_from_quadratic_subtraction_minuend_nicks': [],
            'histogram_from_quadratic_subtraction_subtrahend_nicks': [],
            'histogram_from_quadratic_subtraction_result_nicks': [],
        })

        for truncation in truncations_list:
            # Saving nicks for quadratic subtraction
            minuend_nick = []
            subtrahend_nicks = []
            result_nick = []

            for (index2, rms_quantity) in enumerate(rms_quantities):
                nick_list = []
                for index in range(len(cut_binning) - 1):
                    nick = 'nick_' + str(rms_quantity) + '_' + str(
                        index) + str(truncation)
                    weight = cut_quantity + '>' + str(
                        cut_binning[index]) + '&&' + cut_quantity + '<' + str(
                            cut_binning[index + 1])
                    d.update({
                        'x_expressions':
                        d['x_expressions'] +
                        [rms_quantity],  # y_expression in the plot
                        'nicks':
                        d['nicks'] + [nick],
                        # 'labels': d['labels'] + [nick],
                        # 'colors': d['colors'] + [str(rms_quantities_colors[index2])],
                    })

                    # update x range from predefined values:
                    if rms_quantity in binningsZJet.BinningsDictZJet(
                    ).binnings_dict:
                        x_bins = binningsZJet.BinningsDictZJet(
                        ).binnings_dict[rms_quantity]
                        d['x_bins'] = d['x_bins'] + [x_bins]
                    else:
                        d['x_bins'] = d['x_bins'] + ['4000,0.,2.']

                    # update values for Data and MC entries separately:
                    if rms_quantity not in ['ptbalance']:
                        d.update({
                            'files':
                            d['files'] + [old_files[1]],
                            'corrections':
                            d['corrections'] + [old_corrections[1]],
                            'weights':
                            d['weights'] + [weight + '&&' + old_weights[1]],
                        })
                    else:
                        d.update({
                            'files':
                            d['files'] + [old_files[0]],
                            'corrections':
                            d['corrections'] + [old_corrections[0]],
                            'weights':
                            d['weights'] + [weight + '&&' + old_weights[0]],
                        })
                    nick_list.append(nick)

                # Format plot:
                d.update({
                    'x_label': cut_quantity,
                    'lines': [1.],
                    # 'line_styles': ['--'],
                    'line_widths': ['1.'],
                })

                # Prepare new nicks for RMS and fit
                nick_string = ' '.join(nick_list)
                rms_nick_string = 'nick_' + str(rms_quantity) + '_rms' + str(
                    truncation)

                if rms_quantities_labels[index2] == minuend_quantity:
                    minuend_nick += [rms_nick_string]
                if rms_quantities_labels[
                        index2] in subtrahend_quantities.split():
                    subtrahend_nicks += [rms_nick_string]
                result_nick = 'nick_' + str(result_quantity.replace('(', '').replace(')', '')) + '_subtracted_' + \
                              str(truncation)

                # Get RMS value of each alpha bin for all variables and write them in new nicks
                if True:
                    if 'HistogramFromRMSValues' not in d['analysis_modules']:
                        d['analysis_modules'] = d['analysis_modules'] + [
                            'HistogramFromRMSValues'
                        ]
                    d.update({
                        'histogram_from_rms_nicks':
                        d['histogram_from_rms_nicks'] + [nick_string],
                        'histogram_from_rms_newnicks':
                        d['histogram_from_rms_newnicks'] + [rms_nick_string],
                        'histogram_from_rms_x_values':
                        d['histogram_from_rms_x_values'] +
                        [' '.join(map(str, cut_binning))],
                        'histogram_from_rms_truncations':
                        d['histogram_from_rms_truncations'] + [truncation],
                        # 'nicks_whitelist': d['nicks_whitelist'] + [rms_nick_string],
                        # 'nicks': d['nicks'] + [rms_nick_string],
                        'y_label':
                        'resolution',
                        'y_lims': [0.0, 0.3],
                        # 'colors': d['colors'] + [rms_quantities_colors[index2]],
                        # 'alphas': d['alphas'] + [1.0],
                        # 'labels': d['labels'] + [rms_quantities_labels[index2] + str(truncation)],
                        # 'line_styles': d['line_styles'] + [''],
                    })
            # Getting JER from quadratic subtraction
            if True:
                if 'HistogramFromQuadraticSubtraction' not in d[
                        'analysis_modules']:
                    d['analysis_modules'] = d['analysis_modules'] + [
                        'HistogramFromQuadraticSubtraction'
                    ]
                d.update({
                    'histogram_from_quadratic_subtraction_minuend_nicks':
                    d['histogram_from_quadratic_subtraction_minuend_nicks'] +
                    [minuend_nick],
                    'histogram_from_quadratic_subtraction_subtrahend_nicks':
                    d['histogram_from_quadratic_subtraction_subtrahend_nicks']
                    + [' '.join(subtrahend_nicks)],
                    'histogram_from_quadratic_subtraction_result_nicks':
                    d['histogram_from_quadratic_subtraction_result_nicks'] +
                    [result_nick],
                    'nicks_whitelist':
                    d['nicks_whitelist'] + [result_nick],
                    # 'nicks_whitelist': [result_nick],
                    # 'nicks': d['nicks'] + [result_nick],
                    'colors':
                    d['colors'] + ['red'],
                    'alphas':
                    d['alphas'] + [1.0],
                    'labels':
                    d['labels'] + [
                        result_quantity + ' truncation to ' + str(truncation) +
                        '%'
                    ],
                    'line_styles':
                    d['line_styles'] + [''],
                })
        # extrapolate to alpha equal zero by fitting a function
        if True:
            nick_whitelist = d['nicks_whitelist']
            nick_colors = d['colors']
            nick_labels = d['labels']
            nick_linestyles = d['line_styles']
            d['alphas'] = []
            d['colors'] = []
            d['labels'] = []
            d['line_styles'] = []
            for index, nick_white in enumerate(nick_whitelist):
                fit_nick_white = nick_white + '_fit'
                if 'FunctionPlot' not in d['analysis_modules']:
                    d['analysis_modules'] = d['analysis_modules'] + [
                        'FunctionPlot'
                    ]
                d.update({
                    'function_fit':
                    d['function_fit'] + [nick_white],
                    'function_nicknames':
                    d['function_nicknames'] + [fit_nick_white],
                    'functions':
                    d['functions'] + ['[0]+[1]*x'],
                    # 'functions': d['functions'] + ['[0]*x*x*x+[1]*x*x+[2]*x+[3]'],
                    'function_parameters':
                    d['function_parameters'] + ['0., 0.'],
                    # 'function_parameters': d['function_parameters'] + ['0., 0., 0., 0.'],
                    'function_ranges':
                    d['function_ranges'] + ['0.0, 0.3'],
                    'nicks_whitelist':
                    d['nicks_whitelist'] + [fit_nick_white],
                    'alphas':
                    d['alphas'] + [1.0, 0.4],
                    'colors':
                    d['colors'] + [nick_colors[index], nick_colors[index]],
                    'labels':
                    d['labels'] + [nick_labels[index], ''],
                    'line_styles':
                    d['line_styles'] + [nick_linestyles[index], '--'],
                    'markers': [
                        'd', '', 'v', '', 'o', '', '^', '', '<', '', '>', '',
                        '*', '', '8', '', 's', '', 'p', '', 'h', '', 'D', ''
                    ],
                    'x_lims': [0.0, 0.3],
                })
        plots.append(d)
    return [PlottingJob(plots=plots, args=args)]
Ejemplo n.º 12
0
def jer_truncation_scan_without_jer(args=None,
                                    additional_dictionary=None,
                                    channel='m'):
    """Profile Plot of RMS quantity in bins of alpha"""
    plots = []
    # x_dict = generate_dict(channel_dict=channel)

    cut_quantity = 'alpha'  # x_quantity on the plot
    # cut_binnings=['0.025 0.05 0.075 0.1 0.125 0.15 0.175 0.2 0.225 0.25 0.275 0.3'] # x_bins in plot
    cut_binning = [0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3]  # x_bins in plot

    # plots_list = ['JER(MC-Truth)', 'PLI', 'ZRes', 'PTBal(MC)', 'PTbal(Data)']
    plots_list = ['JER-gen', 'PLI', 'ZRes', 'PTBal-MC']

    for plot_type in plots_list:
        if plot_type == 'JER-gen':
            rms_quantity = 'jet1pt/genjet1pt'
            rms_quantity_label = 'JER(MC-gen)'
            rms_quantity_color = 'orange'
        elif plot_type == 'PLI':
            rms_quantity = 'genjet1pt/genzpt'
            rms_quantity_label = 'PLI(MC)'
            rms_quantity_color = 'springgreen'
        elif plot_type == 'ZRes':
            rms_quantity = 'genzpt/zpt'
            rms_quantity_label = 'ZRes(MC)'
            rms_quantity_color = 'forestgreen'
        elif plot_type == 'PTBal-MC':
            rms_quantity = 'jet1pt/zpt'
            rms_quantity_label = 'PTBal(MC)'
            rms_quantity_color = 'royalblue'
        elif plot_type == 'PTBal-Data':
            rms_quantity = 'ptbalance'
            rms_quantity_label = 'PTBal(Data)'
            rms_quantity_color = 'grey'
        else:
            rms_quantity = ''
            rms_quantity_label = ''
            rms_quantity_color = ''

        d = {
            'analysis_modules': [],
            'plot_modules': ['PlotMplZJet'],
            'legend':
            'upper left',
            'filename':
            'Z' + channel + channel + '_JER_alpha_truncationscan_' + plot_type,
        }

        if additional_dictionary:
            d.update(additional_dictionary)

        # saving old entries for new order usage
        old_files = d['files']  # contains ['MC_file', 'Data_file']
        old_corrections = d['corrections']  # analogous to files
        old_weights = d['weights']

        # deleting old entries for new order
        d.update({
            'files': [],
            'nicks': [],
            'corrections': [],
            'x_expressions': [],
            'nicks_whitelist': [],
            'histogram_from_rms_nicks': [],
            'histogram_from_rms_newnicks': [],
            'histogram_from_rms_x_values': [],
            'histogram_from_rms_truncations': [],
            'colors': [],
            'alphas': [],
            'labels': [],
            'markers': ['+'],
            'weights': [],
            'function_fit': [],
            'function_nicknames': [],
            'functions': [],
            'function_parameters': [],
            'function_ranges': [],
            'line_styles': [],
            'x_bins': [],
            # 'x_lims': [],
        })

        # Scan for optimal truncation value
        truncations_list = [98.5, 97., 95.5, 94.,
                            92.5]  # [85., 93., 95., 97., 98.5, 100]
        for truncation in truncations_list:
            nick_list = []
            for index in range(len(cut_binning) - 1):
                nick = 'nick_' + str(rms_quantity) + '_' + str(
                    index) + '_' + str(truncation)
                weight = cut_quantity + '>' + str(
                    cut_binning[index]) + '&&' + cut_quantity + '<' + str(
                        cut_binning[index + 1])
                d.update({
                    'x_expressions': d['x_expressions'] +
                    [rms_quantity],  # y_expression in the plot
                    'nicks': d['nicks'] + [nick],
                })

                # update x range from predefined values:
                if rms_quantity in binningsZJet.BinningsDictZJet(
                ).binnings_dict:
                    x_bins = binningsZJet.BinningsDictZJet(
                    ).binnings_dict[rms_quantity]
                    d['x_bins'] = d['x_bins'] + [x_bins]
                else:
                    d['x_bins'] = d['x_bins'] + ['40,0.,2.']

                # update values for Data and MC entries separately:
                if rms_quantity not in ['ptbalance']:
                    d.update({
                        'files':
                        d['files'] + [old_files[1]],
                        'corrections':
                        d['corrections'] + [old_corrections[1]],
                        'weights':
                        d['weights'] + [weight + '&&' + old_weights[1]],
                    })
                else:
                    d.update({
                        'files':
                        d['files'] + [old_files[0]],
                        'corrections':
                        d['corrections'] + [old_corrections[0]],
                        'weights':
                        d['weights'] + [weight + '&&' + old_weights[0]],
                    })
                nick_list.append(nick)

            # Format plot:
            d.update({
                'x_label': cut_quantity,
                'lines': [1.],
                # 'line_styles': ['--'],
                'line_widths': ['1.'],
            })

            # Prepare new nicks for RMS and fit
            nick_string = ' '.join(nick_list)
            rms_nick_string = 'nick_' + str(rms_quantity) + '_rms_' + str(
                truncation)
            fit_nick_string = 'nick_' + str(rms_quantity) + '_fit_' + str(
                truncation)

            # Get RMS value of each alpha bin for all variables and write them in new nicks
            if True:
                if 'HistogramFromRMSValues' not in d['analysis_modules']:
                    d['analysis_modules'] = d['analysis_modules'] + [
                        'HistogramFromRMSValues'
                    ]
                d.update({
                    'histogram_from_rms_nicks':
                    d['histogram_from_rms_nicks'] + [nick_string],
                    'histogram_from_rms_newnicks':
                    d['histogram_from_rms_newnicks'] + [rms_nick_string],
                    'histogram_from_rms_x_values':
                    d['histogram_from_rms_x_values'] +
                    [' '.join(map(str, cut_binning))],
                    'histogram_from_rms_truncations':
                    d['histogram_from_rms_truncations'] + [truncation],
                    'nicks_whitelist':
                    d['nicks_whitelist'] + [rms_nick_string],
                    'y_label':
                    'resolution',
                    'y_lims': [0.0, 0.3],
                    'colors':
                    d['colors'] + [rms_quantity_color],
                    'alphas':
                    d['alphas'] + [1.0],
                    'labels':
                    d['labels'] + [
                        rms_quantity_label + ' truncation to ' +
                        str(truncation) + '%'
                    ],
                    'line_styles':
                    d['line_styles'] + [''],
                })
            # extrapolate to alpha equal zero
            if True:
                if 'FunctionPlot' not in d['analysis_modules']:
                    d['analysis_modules'] = d['analysis_modules'] + [
                        'FunctionPlot'
                    ]
                d.update({
                    'function_fit':
                    d['function_fit'] + [rms_nick_string],
                    'function_nicknames':
                    d['function_nicknames'] + [fit_nick_string],
                    'functions':
                    d['functions'] + ['[0]+[1]*x'],
                    # 'functions': d['functions'] + ['[0]*x*x*x+[1]*x*x+[2]*x+[3]'],
                    'function_parameters':
                    d['function_parameters'] + ['0., 0.'],
                    # 'function_parameters': d['function_parameters'] + ['0., 0., 0., 0.'],
                    'function_ranges':
                    d['function_ranges'] + ['0.0, 0.3'],
                    'nicks_whitelist':
                    d['nicks_whitelist'] + [fit_nick_string],
                    'colors':
                    d['colors'] + [rms_quantity_color],
                    'alphas':
                    d['alphas'] + [0.4],
                    'labels':
                    d['labels'] + [''],
                    'line_styles':
                    d['line_styles'] + ['--'],
                    'markers': [
                        'd', '', 'v', '', 'o', '', '^', '', '<', '', '>', '',
                        '*', '', '8', '', 's', '', 'p', '', 'h', '', 'D', ''
                    ],
                    'x_lims': [0.0, 0.3],
                })

        # if len(filter(None, d['labels'])) == 1:
        #     d['labels'] = filter(None, d['labels']) + ['fit']
        plots.append(d)
    return [PlottingJob(plots=plots, args=args)]
Ejemplo n.º 13
0
def jer_extrapolation(args=None, additional_dictionary=None, channel='m'):
    """Profile Plot of RMS quantity in bins of alpha"""
    cut_binning = []  # x_bins in plot
    cut_range = []
    plots = []
    ratio_plot = False

    cut_quantities = ['alpha', 'zeta', 'zpt']  # Quantities used as x-axis

    whitelist_quantities = []  # for whitelisting all quantities per default
    y_lims = [0.0, 1.0]  # for setting range of y axis per default

    for cut_quantity in cut_quantities:  # x_quantity on the plot

        if cut_quantity == 'alpha':
            # cut_binnings=['0.025 0.05 0.075 0.1 0.125 0.15 0.175 0.2 0.225 0.25 0.275 0.3']
            cut_binning = [0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3]
            cut_range = ['0.0, 0.3']
        elif cut_quantity == 'zeta':
            cut_binning = [
                -5.191, -3.139, -2.964, -2.5, -1.93, -1.305, -0.783, 0., 0.783,
                1.305, 1.93, 2.5, 2.964, 3.139, 5.191
            ]
            cut_range = ['-5.191, 5.191']
        elif cut_quantity == 'zpt':
            # cut_binning = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 110, 130, 150, 170, 190, 220,
            #                250, 400, 1000]
            cut_binning = [30, 50, 75, 125, 175, 225, 300, 400, 1000]
            cut_range = ['30, 1000']

        # TODO: adjust truncation values to optimal working point (gamma channel: 98.5%)
        plots_list = ['MC', 'Data']
        # plots_list = ['MC-ZRes-study']

        if channel == 'm':
            truncation = 98.5
        elif channel == 'e':
            truncation = 94.
        else:
            truncation = 100.

        for plot_type in plots_list:
            d = {
                'analysis_modules': [],
                'plot_modules': ['PlotMplZJet'],
                'legend':
                'upper left',
                'filename':
                'Z' + channel + channel + '_JER_' + cut_quantity +
                '_extrapolation' + '_' + plot_type,
                'x_log':
                cut_quantity in ['zpt']
            }
            if additional_dictionary:
                d.update(additional_dictionary)

            if 'texts' in d.keys():
                d.update({
                    'texts':
                    d['texts'] + ['truncation to ' + str(truncation)],
                    'texts_y':
                    d['texts_y'] + [0.95],
                    'texts_x':
                    d['texts_x'] + [0.65],
                    'texts_size':
                    d['texts_size'] + [13],
                })
            else:
                d.update({
                    'texts': ['truncation to ' + str(truncation) + '%'],
                    'texts_y': [0.95],
                    'texts_x': [0.65],
                    'texts_size': [13],
                })

            if plot_type == 'Data':
                # whitelist_quantities = []  # automatically add all to whitelist
                whitelist_quantities = [
                    'jet1pt/genjet1pt'
                ]  # JER extracted is automatically added to whitelist
                rms_quantities = [
                    'ptbalance', 'genjet1pt/genzpt', 'genzpt/zpt',
                    'jet1pt/genjet1pt'
                ]
                rms_quantities_labels = [
                    'PTBal(Data)', 'PLI(MC)', 'ZRes(MC)', 'JER(MC-generated)'
                ]
                rms_quantities_colors = [
                    'grey', 'springgreen', 'forestgreen', 'orange', 'blue',
                    'blue'
                ]
                minuend_quantity = 'PTBal(Data)'
                subtrahend_quantities = 'PLI(MC) ZRes(MC)'
                result_quantity = 'JER(Data-extracted)'
                y_lims = [0.0, 0.3]
            elif plot_type == 'MC':
                # whitelist_quantities = []  # automatically add all to whitelist
                whitelist_quantities = [
                    'jet1pt/genjet1pt'
                ]  # JER extracted is automatically added to whitelist
                rms_quantities = [
                    'jet1pt/zpt', 'genjet1pt/genzpt', 'genzpt/zpt',
                    'jet1pt/genjet1pt'
                ]
                rms_quantities_labels = [
                    'PTBal(MC)', 'PLI(MC)', 'ZRes(MC)', 'JER(MC-generated)'
                ]
                rms_quantities_colors = [
                    'royalblue', 'springgreen', 'forestgreen', 'orange'
                ]
                minuend_quantity = 'PTBal(MC)'
                subtrahend_quantities = 'PLI(MC) ZRes(MC)'
                result_quantity = 'JER(MC-extracted)'
                y_lims = [0.0, 0.3]
            elif plot_type == 'MC-ZRes-study':
                # whitelist_quantities = []  # all quantities are automatically added to whitelist
                rms_quantities = [
                    'genzpt/zpt', 'genepluspt/epluspt', 'genmupluspt/mupluspt'
                ]
                rms_quantities_labels = ['ZRes(MC)', 'eRes(MC)', 'muRes(MC)']
                rms_quantities_colors = ['forestgreen', 'blue', 'blue']
                minuend_quantity = ''
                subtrahend_quantities = ''
                result_quantity = ''
                y_lims = [0.0, 0.05]
            else:
                rms_quantities = []
                rms_quantities_labels = []
                rms_quantities_colors = []
                minuend_quantity = ''
                subtrahend_quantities = ''
                result_quantity = ''

            if whitelist_quantities == []:
                whitelist_quantities = rms_quantities

            # saving old entries for new order usage
            old_files = d['files']  # contains ['MC_file', 'Data_file']
            old_corrections = d['corrections']  # analogous to files
            old_weights = d['weights']

            # deleting old entries for new order
            d.update({
                'files': [],
                'nicks': [],
                'corrections': [],
                'x_expressions': [],
                'nicks_whitelist': [],
                'histogram_from_rms_nicks': [],
                'histogram_from_rms_newnicks': [],
                'histogram_from_rms_x_values': [],
                'histogram_from_rms_truncations': [],
                'colors': [],
                'alphas': [],
                'labels': [],
                'markers': ['+'],
                'weights': [],
                'function_fit': [],
                'function_nicknames': [],
                'functions': [],
                'function_parameters': [],
                'function_ranges': [],
                'line_styles': [],
                'x_bins': [],
                # 'x_lims': [],
                'ratio_numerator_nicks': [],
                'ratio_denominator_nicks': [],
                'ratio_result_nicks': [],
                # 'ratio_denominator_no_errors': False,
            })

            # Saving nicks for quadratic subtraction
            minuend_nick = []
            subtrahend_nicks = []
            result_nick = []

            nick_colors = []
            nick_labels = []
            nick_linestyles = []

            for (index2, rms_quantity) in enumerate(rms_quantities):
                nick_list = []
                for index in range(len(cut_binning) - 1):
                    nick = 'nick_' + str(rms_quantity) + '_' + str(index)
                    weight = cut_quantity + '>' + str(
                        cut_binning[index]) + '&&' + cut_quantity + '<' + str(
                            cut_binning[index + 1])
                    d.update({
                        'x_expressions':
                        d['x_expressions'] +
                        [rms_quantity],  # y_expression in the plot
                        'nicks':
                        d['nicks'] + [nick],
                        # 'labels': d['labels'] + [nick],
                        # 'colors': d['colors'] + [str(rms_quantities_colors[index2])],
                    })

                    # update x range from predefined values:
                    if rms_quantity in binningsZJet.BinningsDictZJet(
                    ).binnings_dict:
                        x_bins = binningsZJet.BinningsDictZJet(
                        ).binnings_dict[rms_quantity]
                        d['x_bins'] = d['x_bins'] + [x_bins]
                    else:
                        d['x_bins'] = d['x_bins'] + ['4000,0.,2.']

                    # update values for Data and MC entries separately:
                    if rms_quantity not in ['ptbalance']:
                        d.update({
                            'files':
                            d['files'] + [old_files[1]],
                            'corrections':
                            d['corrections'] + [old_corrections[1]],
                            'weights':
                            d['weights'] + [weight + '&&' + old_weights[1]],
                        })
                    else:
                        d.update({
                            'files':
                            d['files'] + [old_files[0]],
                            'corrections':
                            d['corrections'] + [old_corrections[0]],
                            'weights':
                            d['weights'] + [weight + '&&' + old_weights[0]],
                        })
                    nick_list.append(nick)

                # Format plot:
                d.update({
                    'x_label': cut_quantity,
                    'lines': [1.],
                    # 'line_styles': ['--'],
                    'line_widths': ['1.'],
                })

                # Prepare new nicks for RMS and fit
                nick_string = ' '.join(nick_list)
                rms_nick_string = 'nick_' + str(rms_quantity) + '_rms'

                if rms_quantities_labels[index2] == minuend_quantity:
                    minuend_nick += [rms_nick_string]
                if rms_quantities_labels[
                        index2] in subtrahend_quantities.split():
                    subtrahend_nicks += [rms_nick_string]
                result_nick = 'nick_' + str(
                    result_quantity.replace('(', '').replace(
                        ')', '')) + '_subtracted'

                # Get RMS value of each alpha bin for all variables and write them in new nicks
                if True:
                    if 'HistogramFromRMSValues' not in d['analysis_modules']:
                        d['analysis_modules'] = d['analysis_modules'] + [
                            'HistogramFromRMSValues'
                        ]
                    d.update({
                        'histogram_from_rms_nicks':
                        d['histogram_from_rms_nicks'] + [nick_string],
                        'histogram_from_rms_newnicks':
                        d['histogram_from_rms_newnicks'] + [rms_nick_string],
                        'histogram_from_rms_x_values':
                        d['histogram_from_rms_x_values'] +
                        [' '.join(map(str, cut_binning))],
                        'histogram_from_rms_truncations':
                        d['histogram_from_rms_truncations'] + [truncation],
                        # 'nicks': d['nicks'] + [rms_nick_string],
                        'y_label':
                        'resolution',
                        'y_lims':
                        y_lims,
                    })
                    if rms_quantity in whitelist_quantities:
                        d.update({
                            'nicks_whitelist':
                            d['nicks_whitelist'] + [rms_nick_string],
                            'colors':
                            d['colors'] + [rms_quantities_colors[index2]],
                            'alphas':
                            d['alphas'] + [1.0],
                            'labels':
                            d['labels'] + [rms_quantities_labels[index2]],
                            'line_styles':
                            d['line_styles'] + [''],
                        })
                        nick_colors += [rms_quantities_colors[index2]]
                        nick_labels += [rms_quantities_labels[index2]]
                        nick_linestyles += ['']
                        if ratio_plot:
                            d.update({
                                'ratio_numerator_nicks':
                                d['ratio_numerator_nicks'] + [rms_nick_string],
                                # 'ratio_denominator_nicks': d['ratio_denominator_nicks'] + [rms_nick_string],
                                'ratio_result_nicks':
                                d['ratio_result_nicks'] +
                                [rms_nick_string + '_ratio'],
                                # 'nicks_whitelist': d['nicks_whitelist'] + [rms_nick_string + '_ratio'],
                                'colors':
                                d['colors'] + [rms_quantities_colors[index2]],
                                'alphas':
                                d['alphas'] + [1.0],
                                'labels':
                                d['labels'] + [''],
                                'line_styles':
                                d['line_styles'] + [''],
                            })

            # Getting JER from quadratic subtraction
            if minuend_quantity != '':
                if 'HistogramFromQuadraticSubtraction' not in d[
                        'analysis_modules']:
                    d['analysis_modules'] = d['analysis_modules'] + [
                        'HistogramFromQuadraticSubtraction'
                    ]
                d.update({
                    'histogram_from_quadratic_subtraction_minuend_nicks':
                    [minuend_nick],
                    'histogram_from_quadratic_subtraction_subtrahend_nicks':
                    [' '.join(subtrahend_nicks)],
                    'histogram_from_quadratic_subtraction_result_nicks':
                    [result_nick],
                    'nicks_whitelist':
                    d['nicks_whitelist'] + [result_nick],
                    # 'nicks': d['nicks'] + [result_nick],
                    'colors':
                    d['colors'] + ['red'],
                    'alphas':
                    d['alphas'] + [1.0],
                    'labels':
                    d['labels'] + [result_quantity],
                    'line_styles':
                    d['line_styles'] + [''],
                })
                nick_colors += ['red']
                nick_labels += [result_quantity]
                nick_linestyles += ['']
                if ratio_plot:
                    if 'Ratio' not in d['analysis_modules']:
                        d['analysis_modules'] = d['analysis_modules'] + [
                            'Ratio'
                        ]
                    d.update({
                        'ratio_denominator_nicks':
                        d['ratio_denominator_nicks'] + [result_nick],
                        'y_subplot_lims': [0.75, 1.25],
                        'y_subplot_label':
                        'Ratio',
                        'subplot_fraction':
                        25,
                        'subplot_legend':
                        'upper right',
                    })
            # extrapolate to alpha equal zero by fitting a function
            if cut_quantity in ['alpha']:
                nick_whitelist = d['nicks_whitelist']
                # nick_colors = d['colors']
                # nick_labels = d['labels']
                # nick_linestyles = d['line_styles']
                d['alphas'] = []
                d['colors'] = []
                d['labels'] = []
                d['line_styles'] = []
                for index, nick_white in enumerate(nick_whitelist):
                    fit_nick_white = nick_white + '_fit'
                    if 'FunctionPlot' not in d['analysis_modules']:
                        d['analysis_modules'] = d['analysis_modules'] + [
                            'FunctionPlot'
                        ]
                    d.update({
                        'function_fit':
                        d['function_fit'] + [nick_white],
                        'function_nicknames':
                        d['function_nicknames'] + [fit_nick_white],
                        'functions':
                        d['functions'] + ['[0]+[1]*x'],
                        'function_parameters':
                        d['function_parameters'] + ['0., 0.'],
                        'function_ranges':
                        d['function_ranges'] + cut_range,
                    })
                    if not ratio_plot or nick_white == result_nick:
                        d.update({
                            'alphas':
                            d['alphas'] + [1.0, 0.4],
                            'colors':
                            d['colors'] +
                            [nick_colors[index], nick_colors[index]],
                            'labels':
                            d['labels'] + [nick_labels[index], ''],
                            'line_styles':
                            d['line_styles'] + [nick_linestyles[index], '--'],
                        })
                    else:
                        d.update({
                            'alphas':
                            d['alphas'] + [1.0, 1.0, 0.4],
                            'colors':
                            d['colors'] + [
                                nick_colors[index], nick_colors[index],
                                nick_colors[index]
                            ],
                            'labels':
                            d['labels'] + [nick_labels[index], '', ''],
                            'line_styles':
                            d['line_styles'] +
                            [nick_linestyles[index], '', '--'],
                        })

            plots.append(d)

    return [PlottingJob(plots=plots, args=args)]