From b1491d4de4aad6b599ac98af811f17d794b2b881 Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Fri, 30 Oct 2015 15:42:59 +0000 Subject: [PATCH 01/29] Channel text not italic, legends on ratio plot on same line. Comment several histograms for debugging. --- .../04_make_plots_matplotlib.py | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/cross_section_measurement/04_make_plots_matplotlib.py b/src/cross_section_measurement/04_make_plots_matplotlib.py index ea7cd8a4..9f3eec00 100644 --- a/src/cross_section_measurement/04_make_plots_matplotlib.py +++ b/src/cross_section_measurement/04_make_plots_matplotlib.py @@ -466,7 +466,7 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True plt.text(0.05, 0.98, r"\textbf{CMS}", transform=axes.transAxes, fontsize=42, verticalalignment='top',horizontalalignment='left') # channel text plt.text(0.95, 0.98 - axes.text(0.95, 0.98, r"\emph{%s}" %channel_label, transform=axes.transAxes, fontsize=42, + axes.text(0.95, 0.98, r"%s" %channel_label, transform=axes.transAxes, fontsize=42, verticalalignment='top',horizontalalignment='right') if show_ratio: @@ -515,13 +515,11 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True rplt.fill_between( stat_upper, stat_lower, ax1, color = '0.75', alpha = 0.5 ) # legend for ratio plot - p_stat = mpatches.Patch(facecolor='0.75', label='Stat.',alpha = 0.5, edgecolor='black' ) - p_stat_and_syst = mpatches.Patch(facecolor='yellow', label=r'Stat. $\oplus$ Syst.', alpha = 0.5, edgecolor='black' ) - l1 = ax1.legend(handles = [p_stat], loc = 'upper left', - frameon = False, prop = {'size':26}) - - ax1.legend(handles = [p_stat_and_syst], loc = 'lower left', - frameon = False, prop = {'size':26}) + p_stat = mpatches.Patch(facecolor='0.75', label='Stat.', edgecolor='black' ) + p_stat_and_syst = mpatches.Patch(facecolor='yellow', label=r'Stat. $\oplus$ Syst.', edgecolor='black' ) + + l1 = ax1.legend(handles = [p_stat, p_stat_and_syst], loc = 'upper left', + frameon = False, prop = {'size':26}, ncol = 2) ax1.add_artist(l1) if variable == 'MET': @@ -726,14 +724,14 @@ def get_unit_string(fit_variable): if met_type == 'PFMETJetEnDown': met_type = 'patPFMetJetEnDown' - if not channel == 'combined' and options.additional_plots: - #Don't make additional plots for e.g. generator systematics, mass systematics, k value systematics and pdf systematics because they are now done \ - #in the unfolding process with BLT unfolding files. - if category in ttbar_generator_systematics or category in ttbar_mass_systematics or category in kValue_systematics or category in pdf_uncertainties: - continue - fit_templates, fit_results = read_fit_templates_and_results_as_histograms( category, channel ) - make_template_plots( fit_templates, category, channel ) - plot_fit_results( fit_results, category, channel ) + # if not channel == 'combined' and options.additional_plots: + # #Don't make additional plots for e.g. generator systematics, mass systematics, k value systematics and pdf systematics because they are now done \ + # #in the unfolding process with BLT unfolding files. + # if category in ttbar_generator_systematics or category in ttbar_mass_systematics or category in kValue_systematics or category in pdf_uncertainties: + # continue + # fit_templates, fit_results = read_fit_templates_and_results_as_histograms( category, channel ) + # make_template_plots( fit_templates, category, channel ) + # plot_fit_results( fit_results, category, channel ) # change back to original MET type met_type = translate_options[options.metType] @@ -743,7 +741,7 @@ def get_unit_string(fit_variable): histograms_normalised_xsection_different_generators, histograms_normalised_xsection_systematics_shifts = read_xsection_measurement_results( category, channel ) make_plots( histograms_normalised_xsection_different_generators, category, output_folder, 'normalised_xsection_' + channel + '_different_generators' ) - make_plots( histograms_normalised_xsection_systematics_shifts, category, output_folder, 'normalised_xsection_' + channel + '_systematics_shifts' ) + # make_plots( histograms_normalised_xsection_systematics_shifts, category, output_folder, 'normalised_xsection_' + channel + '_systematics_shifts' ) del histograms_normalised_xsection_different_generators, histograms_normalised_xsection_systematics_shifts From 089cc77ced70500b9f9de80f676d204c992127b1 Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Fri, 30 Oct 2015 17:23:30 +0000 Subject: [PATCH 02/29] Change labels in plots. --- config/latex_labels.py | 62 ++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/config/latex_labels.py b/config/latex_labels.py index 088bc68c..a887185b 100644 --- a/config/latex_labels.py +++ b/config/latex_labels.py @@ -3,11 +3,11 @@ @author: kreczko ''' -b_tag_bins_latex = {'0btag':'0 b-tags', '0orMoreBtag':'$\geq$ 0 b-tags', '1btag':'1 b-tag', - '1orMoreBtag':'$\geq$ 1 b-tags', - '2btags':'2 b-tags', '2orMoreBtags':'$\geq$ 2 b-tags', - '3btags':'3 b-tags', '3orMoreBtags':'$\geq$ 3 b-tags', - '4orMoreBtags':'$\geq$ 4 b-tags'} +b_tag_bins_latex = {'0btag':'0 b tags', '0orMoreBtag':'$\geq$ 0 b tags', '1btag':'1 b tag', + '1orMoreBtag':'$\geq$ 1 b tags', + '2btags':'2 b tags', '2orMoreBtags':'$\geq$ 2 b tags', + '3btags':'3 b tags', '3orMoreBtags':'$\geq$ 3 b tags', + '4orMoreBtags':'$\geq$ 4 b tags'} variables_latex = { 'MET': 'E_{\mathrm{T}}^{\mathrm{miss}}', @@ -16,35 +16,37 @@ 'MT': 'M^{\mathrm{W}}_{\mathrm{T}}', 'WPT': 'p^\mathrm{W}_{\mathrm{T}}'} +ttBarLatex = '$\mathrm{t}\\bar{\mathrm{t}}$' + measurements_latex = {'unfolded': 'unfolded', 'measured': 'measured', - 'MADGRAPH': '$t\\bar{t}$ (MADGRAPH+Pythia)', - 'MADGRAPH_ptreweight': '$t\\bar{t}$ (MADGRAPH+$p_\mathrm{T}^\mathrm{reweight}$)', - 'MCATNLO': '$t\\bar{t}$ (MC@NLO+Herwig)', - 'POWHEG_PYTHIA': '$t\\bar{t}$ (POWHEG+Pythia)', - 'POWHEG_HERWIG': '$t\\bar{t}$ (POWHEG+Herwig)', - 'matchingdown': '$t\\bar{t}$ (matching down)', - 'matchingup': '$t\\bar{t}$ (matching up)', - 'scaledown': '$t\\bar{t}$ ($Q^{2}$ down)', - 'scaleup': '$t\\bar{t}$ ($Q^{2}$ up)', - 'TTJets_matchingdown': '$t\\bar{t}$ (matching down)', - 'TTJets_matchingup': '$t\\bar{t}$ (matching up)', - 'TTJets_scaledown': '$t\\bar{t}$ ($Q^{2}$ down)', - 'TTJets_scaleup': '$t\\bar{t}$ ($Q^{2}$ up)', - 'TTJets_massdown': '$t\\bar{t}$ (top mass down)', - 'TTJets_massup': '$t\\bar{t}$ (top mass up)', + 'MADGRAPH': 'Madgraph Pythia', + 'MADGRAPH_ptreweight': 'Madgraph+$p_\mathrm{T}$ reweighting', + 'MCATNLO': 'MC@NLO Herwig', + 'POWHEG_PYTHIA': 'Powheg Pythia', + 'POWHEG_HERWIG': 'Powheg Herwig', + 'matchingdown': 'Matching down', + 'matchingup': 'Matching up', + 'scaledown': '$Q^{2}$ down', + 'scaleup': '$Q^{2}$ up', + 'TTJets_matchingdown': 'Matching down', + 'TTJets_matchingup': 'Matching up', + 'TTJets_scaledown': '$Q^{2}$ down', + 'TTJets_scaleup': '$Q^{2}$ up', + 'TTJets_massdown': 'Top mass down', + 'TTJets_massup': 'Top mass up', 'VJets_matchingdown': 'V+jets (matching down)', 'VJets_matchingup': 'V+jets (matching up)', 'VJets_scaledown': 'V+jets ($Q^{2}$ down)', 'VJets_scaleup': 'V+jets ($Q^{2}$ up)', - 'BJet_down':'b-tagging efficiency $-1\sigma$', - 'BJet_up':'b-tagging efficiency $+1\sigma$', + 'BJet_down':'b tagging efficiency $-1\sigma$', + 'BJet_up':'b tagging efficiency $+1\sigma$', 'JES_down':'Jet energy scale $-1\sigma$', 'JES_up':'Jet energy scale $+1\sigma$', 'JER_down':'Jet energy resolution $-1\sigma$', 'JER_up':'Jet energy resolution $+1\sigma$', - 'LightJet_down':'b-tagging mis-tag rate $-1\sigma$', - 'LightJet_up':'b-tagging mis-tag rate $+1\sigma$', + 'LightJet_down':'b tagging mis-tag rate $-1\sigma$', + 'LightJet_up':'b tagging mis-tag rate $+1\sigma$', 'PU_down':'Pile-up $-1\sigma$', 'PU_up':'Pile-up $+1\sigma$', 'central':'central', @@ -55,8 +57,8 @@ 'QCD_shape' : 'QCD shape uncertainty', 'luminosity+' : 'Luminosity $+1\sigma$', 'luminosity-' : 'Luminosity $-1\sigma$', - 'TTJet_cross_section+' : '$t\\bar{t}$ cross section $+1\sigma$', - 'TTJet_cross_section-' : '$t\\bar{t}$ cross section $-1\sigma$', + 'TTJet_cross_section+' : ttBarLatex + ' cross section $+1\sigma$', + 'TTJet_cross_section-' : ttBarLatex + ' cross section $-1\sigma$', 'SingleTop_cross_section+' : 'Single top cross section $+1\sigma$', 'SingleTop_cross_section-' : 'Single top cross section $-1\sigma$', 'V+Jets_cross_section+': 'V+jets cross section \ensuremath{+1\sigma}', @@ -87,18 +89,18 @@ } samples_latex = { - 'data':'data', + 'data':'Data', 'QCD':'QCD', 'WJets':'W $\\rightarrow \ell\\nu$', 'ZJets':'Z/$\gamma^*$ + jets', - 'TTJet':'$\mathrm{t}\\bar{\mathrm{t}}$', - 'SingleTop':'Single-Top' , + 'TTJet':ttBarLatex, + 'SingleTop':'Single Top' , 'V+Jets' : 'W/Z + jets' } fit_variables_latex = { 'absolute_eta' : r'lepton $|\eta|$', - 'M3' : r'$M3$', + 'M3' : r'$M_3$', 'M_bl' : r'$M(b,l)$', 'angle_bl' : r'$\alpha$', } From b7830d2785fe0fd77b68b5c8cac22b320450232d Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Fri, 30 Oct 2015 17:23:51 +0000 Subject: [PATCH 03/29] Try to change x axis range of angle bl control plot. --- config/variable_binning.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/variable_binning.py b/config/variable_binning.py index 0b618401..8a6ffbc2 100644 --- a/config/variable_binning.py +++ b/config/variable_binning.py @@ -2,7 +2,7 @@ 'absolute_eta' : [round( i * 0.2, 2 ) for i in range ( int( 3 / 0.2 ) + 1 )], 'M3' : [i * 25 for i in range ( int( 1000 / 25 ) + 1 )], 'M_bl' : [i * 10 for i in range ( int( 1000 / 20 ) + 1 )], - 'angle_bl' : [round( i * 0.2, 2 ) for i in range ( int( 4 / 0.2 ) + 1 )], + 'angle_bl' : [round( i * 0.2, 2 ) for i in range ( int( 3.2 / 0.2 ) + 1 )], } bin_edges = { 'MET':[0.0, 27.0, 52.0, 87.0, 130.0, 172.0, 300.0], From f7f6c263aba36f84ac1c025720061ac1fe74324b Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Fri, 30 Oct 2015 17:24:44 +0000 Subject: [PATCH 04/29] Add more space between x axis and label of control plots. Don't use emph for channel latex. --- tools/plotting.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/plotting.py b/tools/plotting.py index 0c1e169e..8a130249 100644 --- a/tools/plotting.py +++ b/tools/plotting.py @@ -578,6 +578,7 @@ def set_labels( plt, histogram_properties, show_x_label = True, if show_x_label: plt.xlabel( histogram_properties.x_axis_title, CMS.x_axis_title ) plt.ylabel( histogram_properties.y_axis_title, CMS.y_axis_title ) + plt.tick_params( **CMS.axis_label_major ) plt.tick_params( **CMS.axis_label_minor ) if show_title: @@ -585,6 +586,8 @@ def set_labels( plt, histogram_properties, show_x_label = True, if not axes: return + axes.xaxis.labelpad = 20 + # CMS text # note: fontweight/weight does not change anything as we use Latex text!!! logo_location = (0.05, 0.98) @@ -605,7 +608,7 @@ def set_labels( plt, histogram_properties, show_x_label = True, verticalalignment='top',horizontalalignment=loc) # channel text axes.text(additional_location[0], additional_location[1], - r"\emph{%s}" %histogram_properties.additional_text, + r"%s" %histogram_properties.additional_text, transform=axes.transAxes, fontsize=40, verticalalignment='top', horizontalalignment='right') From 4bb3f4dfd8fdf1f6c9206e6ec992bf51565cc7e9 Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Fri, 30 Oct 2015 17:25:10 +0000 Subject: [PATCH 05/29] Other similar changes for result plots. --- src/cross_section_measurement/04_make_plots_matplotlib.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cross_section_measurement/04_make_plots_matplotlib.py b/src/cross_section_measurement/04_make_plots_matplotlib.py index 9f3eec00..667aceca 100644 --- a/src/cross_section_measurement/04_make_plots_matplotlib.py +++ b/src/cross_section_measurement/04_make_plots_matplotlib.py @@ -441,7 +441,7 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True data_handle = handles[data_label_index] labels.remove( 'data' ) handles.remove( data_handle ) - labels.insert( 0, 'unfolded data' ) + labels.insert( 0, 'Unfolded data' ) handles.insert( 0, data_handle ) new_handles, new_labels = [], [] @@ -481,9 +481,10 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True ax1.yaxis.set_minor_locator( MultipleLocator( 0.1 ) ) plt.xlabel( '$%s$ [GeV]' % variables_latex[variable], CMS.x_axis_title ) + ax1.xaxis.labelpad = 20 plt.tick_params( **CMS.axis_label_major ) plt.tick_params( **CMS.axis_label_minor ) - plt.ylabel( '$\\frac{\\textrm{pred.}}{\\textrm{data}}$', CMS.y_axis_title ) + plt.ylabel( '$\\frac{\\mathrm{pred.}}{\\mathrm{data}}$', CMS.y_axis_title ) ax1.yaxis.set_label_coords(-0.115, 0.8) #draw a horizontal line at y=1 for data plt.axhline(y = 1, color = 'black', linewidth = 2) @@ -741,7 +742,7 @@ def get_unit_string(fit_variable): histograms_normalised_xsection_different_generators, histograms_normalised_xsection_systematics_shifts = read_xsection_measurement_results( category, channel ) make_plots( histograms_normalised_xsection_different_generators, category, output_folder, 'normalised_xsection_' + channel + '_different_generators' ) - # make_plots( histograms_normalised_xsection_systematics_shifts, category, output_folder, 'normalised_xsection_' + channel + '_systematics_shifts' ) + make_plots( histograms_normalised_xsection_systematics_shifts, category, output_folder, 'normalised_xsection_' + channel + '_systematics_shifts' ) del histograms_normalised_xsection_different_generators, histograms_normalised_xsection_systematics_shifts From c73340b041b28ee597cfcd2a249266e2a773c5ca Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Fri, 30 Oct 2015 17:25:33 +0000 Subject: [PATCH 06/29] Tweak some control plots. --- .../make_control_plots.py | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/cross_section_measurement/make_control_plots.py b/src/cross_section_measurement/make_control_plots.py index d368e8e4..254228a8 100644 --- a/src/cross_section_measurement/make_control_plots.py +++ b/src/cross_section_measurement/make_control_plots.py @@ -219,7 +219,7 @@ def make_plot( channel, x_axis_title, y_axis_title, if normalise_to_fit: histogram_properties.mc_error = get_normalisation_error( normalisation ) - histogram_properties.mc_errors_label = 'fit uncertainty' + histogram_properties.mc_errors_label = 'Fit uncertainty' else: histogram_properties.mc_error = mc_uncertainty histogram_properties.mc_errors_label = 'MC unc.' @@ -307,22 +307,22 @@ def make_plot( channel, x_axis_title, y_axis_title, # comment out plots you don't want include_plots = [ 'eta', - 'pT', + # 'pT', 'MET', - 'MET log', - 'MET phi', + # 'MET log', + # 'MET phi', 'HT', 'ST', 'WPT', - 'MT', + # 'MT', 'M3', 'angle_bl', - 'bjet invariant mass', - 'b-tag multiplicity', - 'b-tag multiplicity reweighted', - 'jet multiplicity', - 'n vertex', - 'n vertex reweighted', + # 'bjet invariant mass', + # 'b-tag multiplicity', + # 'b-tag multiplicity reweighted', + # 'jet multiplicity', + # 'n vertex', + # 'n vertex reweighted', ] additional_qcd_plots = [ 'eta in MET bins', @@ -624,12 +624,12 @@ def make_plot( channel, x_axis_title, y_axis_title, tmp = 'TTbar_plus_X_analysis/EPlusJets/Ref selection/Binned_MT_Analysis/MT_with_patType1CorrectedPFMet_bin_%s/angle_bl_' + b_tag_bin regions = [tmp % bin_i for bin_i in variable_bins_ROOT['MT']] make_plot( 'electron', - x_axis_title = fit_variables_latex['angle_bl'], + x_axis_title = fit_variables_latex['angle_bl'] + ' [radians]', y_axis_title = 'Events/(0.2)', signal_region = regions, qcd_data_region_btag = '1btag', name_prefix = 'EPlusJets_angle_bl_', - x_limits = [0, 4], + x_limits = [0, 3.2], rebin = 2, legend_location = ( 0.95, 0.78 ), cms_logo_location = 'right', @@ -642,7 +642,7 @@ def make_plot( channel, x_axis_title, y_axis_title, signal_region = regions, qcd_data_region_btag = '1btag', name_prefix = 'MuPlusJets_angle_bl_', - x_limits = [0, 4], + x_limits = [0, 3.2], rebin = 2, legend_location = ( 0.95, 0.78 ), cms_logo_location = 'right', From 177db27b728f01c7ca486ccc67bc22cf8161536e Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Tue, 3 Nov 2015 17:30:24 +0000 Subject: [PATCH 07/29] Make lines more black and white friendly. --- .../04_make_plots_matplotlib.py | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/cross_section_measurement/04_make_plots_matplotlib.py b/src/cross_section_measurement/04_make_plots_matplotlib.py index 667aceca..bf6ce082 100644 --- a/src/cross_section_measurement/04_make_plots_matplotlib.py +++ b/src/cross_section_measurement/04_make_plots_matplotlib.py @@ -411,30 +411,46 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True if show_before_unfolding: rplt.errorbar( hist_measured, axes = axes, label = 'data (before unfolding)', xerr = None, zorder = len( histograms ) ) + dashes = {} for key, hist in sorted( histograms.iteritems() ): + zorder = sorted( histograms, reverse = False ).index( key ) + if key == 'MADGRAPH' and zorder != len(histograms) - 3: + zorder = len(histograms) - 3 + elif key != 'MADGRAPH' and not 'unfolded' in key: + while zorder >= len(histograms) - 3: + zorder = zorder - 1 + if not 'unfolded' in key and not 'measured' in key: hist.linewidth = 4 + linestyle = None # setting colours if 'POWHEG_PYTHIA' in key or 'matchingdown' in key: - hist.linestyle = 'longdashdot' + dashes[key] = [25,5,5,5,5,5,5,5] hist.SetLineColor( kBlue ) elif 'POWHEG_HERWIG' in key or 'scaledown' in key: - hist.linestyle = 'dashed' + dashes[key] = [5,5] hist.SetLineColor( kGreen ) elif 'MADGRAPH_ptreweight' in key: - hist.linestyle = 'dashed' - hist.SetLineColor( kBlack ) + dashes[key] = [20,5] + hist.SetLineColor( kRed + 3 ) elif 'MADGRAPH' in key: - hist.linestyle = 'solid' + linestyle = 'solid' + dashes[key] = None hist.SetLineColor( kRed + 1 ) elif 'matchingup' in key: - hist.linestyle = 'verylongdashdot' - hist.linecolor = 'orange' + dashes[key] = [25,5,5,5,25,5,5,5] + hist.SetLineColor( kMagenta + 1 ) elif 'MCATNLO' in key or 'scaleup' in key: - hist.linestyle = 'dotted' - hist.SetLineColor( kMagenta + 3 ) - rplt.hist( hist, axes = axes, label = measurements_latex[key], zorder = sorted( histograms, reverse = True ).index( key ) ) - + dashes[key] = [5,5,10,5] + hist.linecolor = 'orange' + + if linestyle != None: + hist.linestyle = linestyle + line, h = rplt.hist( hist, axes = axes, label = measurements_latex[key], zorder = zorder ) + + if dashes[key] != None: + line.set_dashes(dashes[key]) + h.set_dashes(dashes[key]) handles, labels = axes.get_legend_handles_labels() # making data first in the list data_label_index = labels.index( 'data' ) @@ -493,7 +509,9 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True if not 'unfolded' in key and not 'measured' in key: ratio = hist.Clone() ratio.Divide( hist_data ) #divide by data - rplt.hist( ratio, axes = ax1, label = 'do_not_show' ) + line, h = rplt.hist( ratio, axes = ax1, label = 'do_not_show' ) + if dashes[key] != None: + h.set_dashes(dashes[key]) stat_lower = hist_data.Clone() stat_upper = hist_data.Clone() From 5aa7423e1a0635c2bef5711922b6904bd6f6052e Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Fri, 18 Dec 2015 14:06:08 +0000 Subject: [PATCH 08/29] Back porting some plot changes. --- tools/plotting.py | 176 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 171 insertions(+), 5 deletions(-) diff --git a/tools/plotting.py b/tools/plotting.py index 8a130249..ed4ba60d 100644 --- a/tools/plotting.py +++ b/tools/plotting.py @@ -16,7 +16,7 @@ from copy import deepcopy import matplotlib.gridspec as gridspec from matplotlib.ticker import MultipleLocator, FixedLocator -from itertools import cycle +from itertools import cycle, combinations from tools.latex import setup_matplotlib setup_matplotlib() @@ -47,7 +47,7 @@ class Histogram_properties: #If True (the default) then plot bins with zero content otherwise only # show bins with nonzero content. emptybins = False - + formats = ['pdf'] def __init__( self, dictionary = {} ): for name, value in dictionary.iteritems(): @@ -79,6 +79,85 @@ class PlotConfig: def __init__( self, config_file, **kwargs ): self.config_file = config_file +class Plot(object): + ''' + A class to define a plot + ''' + delegate_attr = attribute_names=['name', 'title', 'formats'] + def __init__(self, histograms, properties, **kwargs): + self.__draw_method = 'errorbar' + self.__properties = properties + self._path = properties.path + self.__histograms = histograms + if self._path != '' and not self._path.endswith('/'): + self._path += '/' + self.__errorbands = [] + if kwargs.has_key('errorbands'): + self.__errorbands = kwargs.pop('errorbands') + + def add_error_band(self, errorband): + self.__errorbands.append(errorband) + + @property + def errorbands(self): + return self.__errorbands + + @property + def properties(self): + return self.__properties + + def save(self): + make_folder_if_not_exists(self._path) + for f in self.__properties.formats: + file_name = '{path}{name}.{format}' + file_name = file_name.format( + path = self._path, + name = self.__properties.name, + format = f, + ) + plt.savefig(file_name) + + def cleanup(self): + # clear current figure and axes + plt.clf() + plt.cla() + plt.close() + + def __enter__(self): + self.cleanup() + return self + + def __exit__(self, exc_type, exc_value, traceback): + self.cleanup() + + @property + def draw_method(self): + return self.__draw_method + + @draw_method.setter + def draw_method(self, method): + if method in rplt.__dict__.keys(): + self.__draw_method = method + else: + raise ValueError('Invalid draw method') + + @property + def histograms(self): + return self.__histograms + + @property + def show_ratios(self): + return self.__properties.has_ratio and len(self.__histograms) > 1 + + @property + def fix_to_zero(self): + return self.__properties.fix_to_zero + +# def __getattr__(self, name): +# print name +# if name in Plot.delegate_attr: +# return getattr(self.__properties, name) + def make_data_mc_comparison_plot( histograms = [], histogram_lables = [], histogram_colors = [], @@ -222,7 +301,7 @@ def make_data_mc_comparison_plot( histograms = [], ymax = histogram_properties.ratio_y_limits[1] ) # dynamic tick placement - adjust_ratio_ticks(ax1.yaxis, n_ticks = 3) + adjust_ratio_ticks(ax1.yaxis, n_ticks = 3, y_limits = histogram_properties.y_limits) if CMS.tight_layout: plt.tight_layout() @@ -662,16 +741,103 @@ def check_save_folder(save_folder): return save_folder -def adjust_ratio_ticks( axis, n_ticks = 3 ): +def adjust_ratio_ticks( axis, n_ticks = 3, y_limits = None ): # dynamic tick placement ticks = axis.get_ticklocs() tick_min, tick_max = ticks[0], ticks[-1] + # Check if these are outside of the y_limits. Use those instead if so. + if y_limits != None: + if tick_min < y_limits[0] and tick_max > y_limits[-1]: + tick_min = y_limits[0] + tick_max = y_limits[-1] + # limit to 3 ticks tick_distance = abs( tick_max - tick_min ) / ( n_ticks + 1 ) includes_one = tick_max > 1 and tick_min < 1 if includes_one: - axis.set_major_locator( FixedLocator( [tick_min + tick_distance/2, 1, tick_max - tick_distance/2] ) ) + axis.set_major_locator( FixedLocator( [round(tick_min + tick_distance/2,1), 1, round(tick_max - tick_distance/2,1)] ) ) else: axis.set_major_locator( MultipleLocator( tick_distance ) ) axis.set_minor_locator( MultipleLocator( tick_distance / 2 ) ) +def compare_histograms(plot): + histograms = plot.histograms + properties = plot.properties + # the cycling needs to be better + colors = ['green', 'red', 'blue', 'magenta'] + colorcycler = cycle( colors ) + markers = [20, 23, 22, 33, 21, 29] + markercycler = cycle( markers ) + + plt.figure( figsize = CMS.figsize, dpi = CMS.dpi, facecolor = CMS.facecolor ) + axes = plt.axes() + if plot.show_ratios: + gs = gridspec.GridSpec( 2, 1, height_ratios = [5, 1] ) + axes = plt.subplot( gs[0] ) + plot_function = rplt.__dict__[plot.draw_method] + for label, histogram in histograms.items(): + histogram.markersize = 2 + histogram.markerstyle = next( markercycler ) + histogram.color = next( colorcycler ) + plot_function( histogram, axes = axes, label = label, + emptybins = properties.emptybins, + yerr = True, + xerr = properties.xerr, elinewidth = 2 ) + + set_labels( plt, properties, show_x_label = not plot.show_ratios, axes = axes ) + errorbands = plot.errorbands + handles, labels = axes.get_legend_handles_labels() + for band in errorbands: + band.draw(axes) + p1 = Rectangle( ( 0, 0 ), 1, 1, fc = "0.75", alpha = 0.5, hatch = '/' , + label = band.name) + handles.append( p1 ) + labels.append( band.name ) + adjust_axis_limits( axes, properties, histograms.values() ) + + # or sort legend by labels + import operator + hl = sorted(zip(handles, labels), + key=operator.itemgetter(1)) + handles2, labels2 = zip(*hl) + l1 = axes.legend( + handles2, labels2, numpoints = 1, + frameon = properties.legend_color, + bbox_to_anchor = properties.legend_location, + bbox_transform=plt.gcf().transFigure, + prop = CMS.legend_properties, + ncol = properties.legend_columns, + ) + l1.set_zorder(102) + + ratios = {} + if plot.show_ratios: + for (l1, l2) in combinations(histograms.keys(), 2): + label = '{0}/{1}'.format(l1, l2) + h = histograms[l1].clone() + h.Divide(histograms[l2]) + h.SetName(label) + ratios[label] = h + plt.setp( axes.get_xticklabels(), visible = False ) + axes_ratio = plt.subplot( gs[1] ) + axes_ratio.set_ylim(properties.ratio_y_limits[0],properties.ratio_y_limits[-1]) + axes_ratio.minorticks_on() + axes_ratio.grid( True, 'major', linewidth = 1) + axes_ratio.axhline(y=1, linewidth = 1, linestyle = 'dashed', color = 'black') + set_labels( plt, properties, show_x_label = True, show_title = False ) + plt.ylabel('ratio') + axes_ratio.yaxis.set_label_coords(-0.115, 0.8) + for label, ratio in ratios.items(): + plot_function( ratio, xerr = properties.xerr, + emptybins = properties.emptybins, + axes = axes_ratio, elinewidth = 2 ) + + adjust_ratio_ticks(axes_ratio.yaxis, n_ticks = 3, y_limits = properties.ratio_y_limits ) + axes_ratio.set_ylim(properties.ratio_y_limits[0],properties.ratio_y_limits[-1]) + # adjust_axis_limits( axes_ratio, properties, ratios.values() ) + axes_ratio.set_xlim(properties.x_limits[0], properties.x_limits[-1]) + if CMS.tight_layout: + plt.tight_layout() + + plot.save() + plt.close() \ No newline at end of file From b1096780dab0847785708a5edda5f70b4bab5de1 Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Fri, 18 Dec 2015 14:07:04 +0000 Subject: [PATCH 09/29] Add extra powheg samples. Modify plotting style. --- .../02_unfold_and_measure.py | 96 ++++++++++++++----- .../03_calculate_systematics.py | 23 +++-- .../04_make_plots_matplotlib.py | 95 ++++++++++++------ 3 files changed, 155 insertions(+), 59 deletions(-) diff --git a/src/cross_section_measurement/02_unfold_and_measure.py b/src/cross_section_measurement/02_unfold_and_measure.py index 3403b5ab..e445752f 100644 --- a/src/cross_section_measurement/02_unfold_and_measure.py +++ b/src/cross_section_measurement/02_unfold_and_measure.py @@ -85,10 +85,10 @@ def data_covariance_matrix( data ): return cov_matrix def get_unfolded_normalisation( TTJet_fit_results, category, channel, k_value ): - global variable, met_type, path_to_JSON, file_for_unfolding, file_for_powheg_pythia, file_for_powheg_herwig, file_for_ptreweight, files_for_pdfs + global variable, met_type, path_to_JSON, file_for_unfolding, file_for_powheg_v2_pythia, file_for_powheg_v2_herwig, file_for_ptreweight, files_for_pdfs global centre_of_mass, luminosity, ttbar_xsection, load_fakes, method if centre_of_mass == 8: - global file_for_mcatnlo + global file_for_mcatnlo, file_for_powheg_v1_herwig, file_for_powheg_v1_pythia global file_for_matchingdown, file_for_matchingup, file_for_scaledown, file_for_scaleup global file_for_massdown, file_for_massup global ttbar_generator_systematics, ttbar_theory_systematics, pdf_uncertainties @@ -101,8 +101,10 @@ def get_unfolded_normalisation( TTJet_fit_results, category, channel, k_value ): ttbar_theory_systematic_prefix + 'scaleup':file_for_scaleup, ttbar_theory_systematic_prefix + 'massdown':file_for_massdown, ttbar_theory_systematic_prefix + 'massup':file_for_massup, - ttbar_theory_systematic_prefix + 'powheg_pythia':file_for_powheg_pythia, - ttbar_theory_systematic_prefix + 'powheg_herwig':file_for_powheg_herwig, + ttbar_theory_systematic_prefix + 'powheg_v1_pythia':file_for_powheg_v1_pythia, + ttbar_theory_systematic_prefix + 'powheg_v1_herwig':file_for_powheg_v1_herwig, + ttbar_theory_systematic_prefix + 'powheg_v2_pythia':file_for_powheg_v2_pythia, + ttbar_theory_systematic_prefix + 'powheg_v2_herwig':file_for_powheg_v2_herwig, ttbar_theory_systematic_prefix + 'ptreweight':file_for_ptreweight, } @@ -148,7 +150,7 @@ def get_unfolded_normalisation( TTJet_fit_results, category, channel, k_value ): load_fakes = load_fakes ) - h_truth_POWHEG_PYTHIA, _, _, _ = get_unfold_histogram_tuple( inputfile = file_for_powheg_pythia, + h_truth_powheg_v2_pythia, _, _, _ = get_unfold_histogram_tuple( inputfile = file_for_powheg_v2_pythia, variable = variable, channel = channel, met_type = met_type, @@ -157,7 +159,7 @@ def get_unfolded_normalisation( TTJet_fit_results, category, channel, k_value ): luminosity = luminosity, load_fakes = load_fakes ) - h_truth_POWHEG_HERWIG, _, _, _ = get_unfold_histogram_tuple( inputfile = file_for_powheg_herwig, + h_truth_powheg_v2_herwig, _, _, _ = get_unfold_histogram_tuple( inputfile = file_for_powheg_v2_herwig, variable = variable, channel = channel, met_type = met_type, @@ -167,6 +169,8 @@ def get_unfolded_normalisation( TTJet_fit_results, category, channel, k_value ): load_fakes = load_fakes ) h_truth_MCATNLO = None + h_truth_powheg_v1_herwig = None + h_truth_powheg_v1_pythia = None if centre_of_mass == 8: h_truth_MCATNLO, _, _, _ = get_unfold_histogram_tuple( inputfile = file_for_mcatnlo, variable = variable, @@ -177,6 +181,26 @@ def get_unfolded_normalisation( TTJet_fit_results, category, channel, k_value ): luminosity = luminosity, load_fakes = load_fakes ) + h_truth_powheg_v1_herwig, _, _, _ = get_unfold_histogram_tuple( inputfile = file_for_powheg_v1_herwig, + variable = variable, + channel = channel, + met_type = met_type, + centre_of_mass = centre_of_mass, + ttbar_xsection = ttbar_xsection, + luminosity = luminosity, + load_fakes = load_fakes + ) + + h_truth_powheg_v1_pythia, _, _, _ = get_unfold_histogram_tuple( inputfile = file_for_powheg_v1_pythia, + variable = variable, + channel = channel, + met_type = met_type, + centre_of_mass = centre_of_mass, + ttbar_xsection = ttbar_xsection, + luminosity = luminosity, + load_fakes = load_fakes + ) + h_truth_matchingdown, _, _, _ = get_unfold_histogram_tuple( inputfile = file_for_matchingdown, variable = variable, channel = channel, @@ -226,12 +250,16 @@ def get_unfolded_normalisation( TTJet_fit_results, category, channel, k_value ): MADGRAPH_results = hist_to_value_error_tuplelist( h_truth ) MADGRAPH_ptreweight_results = hist_to_value_error_tuplelist( h_truth_ptreweight ) - POWHEG_PYTHIA_results = hist_to_value_error_tuplelist( h_truth_POWHEG_PYTHIA ) - POWHEG_HERWIG_results = hist_to_value_error_tuplelist( h_truth_POWHEG_HERWIG ) + powheg_v2_pythia_results = hist_to_value_error_tuplelist( h_truth_powheg_v2_pythia ) + powheg_v2_herwig_results = hist_to_value_error_tuplelist( h_truth_powheg_v2_herwig ) MCATNLO_results = None + powheg_v1_herwig_results = None + powheg_v1_pythia_results = None if centre_of_mass == 8: MCATNLO_results = hist_to_value_error_tuplelist( h_truth_MCATNLO ) - + powheg_v1_herwig_results = hist_to_value_error_tuplelist( h_truth_powheg_v1_herwig ) + powheg_v1_pythia_results = hist_to_value_error_tuplelist( h_truth_powheg_v1_pythia ) + matchingdown_results = hist_to_value_error_tuplelist( h_truth_matchingdown ) matchingup_results = hist_to_value_error_tuplelist( h_truth_matchingup ) scaledown_results = hist_to_value_error_tuplelist( h_truth_scaledown ) @@ -254,8 +282,8 @@ def get_unfolded_normalisation( TTJet_fit_results, category, channel, k_value ): 'MADGRAPH': MADGRAPH_results, 'MADGRAPH_ptreweight': MADGRAPH_ptreweight_results, # other generators - 'POWHEG_PYTHIA': POWHEG_PYTHIA_results, - 'POWHEG_HERWIG': POWHEG_HERWIG_results, + 'powheg_v2_pythia': powheg_v2_pythia_results, + 'powheg_v2_herwig': powheg_v2_herwig_results, # systematics 'matchingdown': matchingdown_results, 'matchingup': matchingup_results, @@ -264,6 +292,8 @@ def get_unfolded_normalisation( TTJet_fit_results, category, channel, k_value ): } if centre_of_mass == 8: normalisation_unfolded['MCATNLO'] = MCATNLO_results + normalisation_unfolded['powheg_v1_herwig'] = powheg_v1_herwig_results + normalisation_unfolded['powheg_v1_pythia'] = powheg_v1_pythia_results return normalisation_unfolded @@ -277,11 +307,16 @@ def calculate_xsections( normalisation, category, channel, k_value = None ): TTJet_xsection_unfolded = calculate_xsection( normalisation['TTJet_unfolded'], luminosity, branching_ratio ) # L in pb1 MADGRAPH_xsection = calculate_xsection( normalisation['MADGRAPH'], luminosity, branching_ratio ) # L in pb1 MADGRAPH_ptreweight_xsection = calculate_xsection( normalisation['MADGRAPH_ptreweight'], luminosity, branching_ratio ) # L in pb1 - POWHEG_PYTHIA_xsection = calculate_xsection( normalisation['POWHEG_PYTHIA'], luminosity, branching_ratio ) # L in pb1 - POWHEG_HERWIG_xsection = calculate_xsection( normalisation['POWHEG_HERWIG'], luminosity, branching_ratio ) # L in pb1 + powheg_v2_pythia_xsection = calculate_xsection( normalisation['powheg_v2_pythia'], luminosity, branching_ratio ) # L in pb1 + powheg_v2_herwig_xsection = calculate_xsection( normalisation['powheg_v2_herwig'], luminosity, branching_ratio ) # L in pb1 MCATNLO_xsection = None + powheg_v1_herwig_xsection = None + powheg_v1_pythia_xsection = None if centre_of_mass == 8: MCATNLO_xsection = calculate_xsection( normalisation['MCATNLO'], luminosity, branching_ratio ) # L in pb1 + powheg_v1_herwig_xsection = calculate_xsection( normalisation['powheg_v1_herwig'], luminosity, branching_ratio ) # L in pb1 + powheg_v1_pythia_xsection = calculate_xsection( normalisation['powheg_v1_pythia'], luminosity, branching_ratio ) # L in pb1 + matchingdown_xsection = calculate_xsection( normalisation['matchingdown'], luminosity, branching_ratio ) # L in pb1 matchingup_xsection = calculate_xsection( normalisation['matchingup'], luminosity, branching_ratio ) # L in pb1 scaledown_xsection = calculate_xsection( normalisation['scaledown'], luminosity, branching_ratio ) # L in pb1 @@ -291,8 +326,8 @@ def calculate_xsections( normalisation, category, channel, k_value = None ): 'TTJet_unfolded' : TTJet_xsection_unfolded, 'MADGRAPH': MADGRAPH_xsection, 'MADGRAPH_ptreweight': MADGRAPH_ptreweight_xsection, - 'POWHEG_PYTHIA': POWHEG_PYTHIA_xsection, - 'POWHEG_HERWIG': POWHEG_HERWIG_xsection, + 'powheg_v2_pythia': powheg_v2_pythia_xsection, + 'powheg_v2_herwig': powheg_v2_herwig_xsection, # systematics 'matchingdown': matchingdown_xsection, 'matchingup': matchingup_xsection, @@ -301,7 +336,9 @@ def calculate_xsections( normalisation, category, channel, k_value = None ): } if centre_of_mass == 8: xsection_unfolded['MCATNLO'] = MCATNLO_xsection - + xsection_unfolded['powheg_v1_herwig'] = powheg_v1_herwig_xsection + xsection_unfolded['powheg_v1_pythia'] = powheg_v1_pythia_xsection + if k_value: filename = path_to_JSON + '/xsection_measurement_results/%s/kv%d/%s/xsection_%s.txt' % ( channel, k_value, category, met_type ) elif not channel == 'combined': @@ -317,11 +354,16 @@ def calculate_normalised_xsections( normalisation, category, channel, k_value = TTJet_normalised_xsection_unfolded = calculate_normalised_xsection( normalisation['TTJet_unfolded'], bin_widths[variable], normalise_to_one ) MADGRAPH_normalised_xsection = calculate_normalised_xsection( normalisation['MADGRAPH'], bin_widths[variable], normalise_to_one ) MADGRAPH_ptreweight_normalised_xsection = calculate_normalised_xsection( normalisation['MADGRAPH_ptreweight'], bin_widths[variable], normalise_to_one ) - POWHEG_PYTHIA_normalised_xsection = calculate_normalised_xsection( normalisation['POWHEG_PYTHIA'], bin_widths[variable], normalise_to_one ) - POWHEG_HERWIG_normalised_xsection = calculate_normalised_xsection( normalisation['POWHEG_HERWIG'], bin_widths[variable], normalise_to_one ) + powheg_v2_pythia_normalised_xsection = calculate_normalised_xsection( normalisation['powheg_v2_pythia'], bin_widths[variable], normalise_to_one ) + powheg_v2_herwig_normalised_xsection = calculate_normalised_xsection( normalisation['powheg_v2_herwig'], bin_widths[variable], normalise_to_one ) MCATNLO_normalised_xsection = None + powheg_v1_herwig_normalised_xsection = None + powheg_v1_pythia_normalised_xsection = None if centre_of_mass == 8: MCATNLO_normalised_xsection = calculate_normalised_xsection( normalisation['MCATNLO'], bin_widths[variable], normalise_to_one ) + powheg_v1_herwig_normalised_xsection = calculate_normalised_xsection( normalisation['powheg_v1_herwig'], bin_widths[variable], normalise_to_one ) + powheg_v1_pythia_normalised_xsection = calculate_normalised_xsection( normalisation['powheg_v1_pythia'], bin_widths[variable], normalise_to_one ) + matchingdown_normalised_xsection = calculate_normalised_xsection( normalisation['matchingdown'], bin_widths[variable], normalise_to_one ) matchingup_normalised_xsection = calculate_normalised_xsection( normalisation['matchingup'], bin_widths[variable], normalise_to_one ) scaledown_normalised_xsection = calculate_normalised_xsection( normalisation['scaledown'], bin_widths[variable], normalise_to_one ) @@ -331,8 +373,8 @@ def calculate_normalised_xsections( normalisation, category, channel, k_value = 'TTJet_unfolded' : TTJet_normalised_xsection_unfolded, 'MADGRAPH': MADGRAPH_normalised_xsection, 'MADGRAPH_ptreweight': MADGRAPH_ptreweight_normalised_xsection, - 'POWHEG_PYTHIA': POWHEG_PYTHIA_normalised_xsection, - 'POWHEG_HERWIG': POWHEG_HERWIG_normalised_xsection, + 'powheg_v2_pythia': powheg_v2_pythia_normalised_xsection, + 'powheg_v2_herwig': powheg_v2_herwig_normalised_xsection, # systematics 'matchingdown': matchingdown_normalised_xsection, 'matchingup': matchingup_normalised_xsection, @@ -341,6 +383,8 @@ def calculate_normalised_xsections( normalisation, category, channel, k_value = } if centre_of_mass == 8: normalised_xsection['MCATNLO'] = MCATNLO_normalised_xsection + normalised_xsection['powheg_v1_herwig'] = powheg_v1_herwig_normalised_xsection + normalised_xsection['powheg_v1_pythia'] = powheg_v1_pythia_normalised_xsection if not channel == 'combined': filename = path_to_JSON + '/xsection_measurement_results/%s/kv%d/%s/normalised_xsection_%s.txt' % ( channel, k_value, category, met_type ) @@ -398,11 +442,15 @@ def calculate_normalised_xsections( normalisation, category, channel, k_value = path_to_files = measurement_config.path_to_files file_for_unfolding = File( measurement_config.unfolding_madgraph, 'read' ) - file_for_powheg_pythia = File( measurement_config.unfolding_powheg_pythia, 'read' ) - file_for_powheg_herwig = File( measurement_config.unfolding_powheg_herwig, 'read' ) + file_for_powheg_v2_pythia = File( measurement_config.unfolding_powheg_v2_pythia, 'read' ) + file_for_powheg_v2_herwig = File( measurement_config.unfolding_powheg_v2_herwig, 'read' ) file_for_mcatnlo = None + file_for_powheg_v1_herwig = None + file_for_powheg_v1_pythia = None if centre_of_mass == 8: file_for_mcatnlo = File( measurement_config.unfolding_mcatnlo, 'read' ) + file_for_powheg_v1_herwig = File( measurement_config.unfolding_powheg_v1_herwig, 'read' ) + file_for_powheg_v1_pythia = File( measurement_config.unfolding_powheg_v1_pythia, 'read' ) file_for_ptreweight = File ( measurement_config.unfolding_ptreweight, 'read' ) files_for_pdfs = { 'PDFWeights_%d' % index : File ( measurement_config.unfolding_pdfweights[index] ) for index in range( 1, 45 ) } @@ -434,7 +482,9 @@ def calculate_normalised_xsections( normalisation, category, channel, k_value = # ttbar theory systematics, including pt reweighting and hadronisation systematic ttbar_theory_systematics = [ ttbar_theory_systematic_prefix + 'ptreweight' ] - ttbar_theory_systematics.extend( [ttbar_theory_systematic_prefix + 'powheg_pythia', ttbar_theory_systematic_prefix + 'powheg_herwig'] ) + ttbar_theory_systematics.extend( [ttbar_theory_systematic_prefix + 'powheg_v2_pythia', ttbar_theory_systematic_prefix + 'powheg_v2_herwig'] ) + if centre_of_mass == 8: + ttbar_theory_systematics.extend( [ttbar_theory_systematic_prefix + 'powheg_v1_pythia', ttbar_theory_systematic_prefix + 'powheg_v1_herwig'] ) categories.extend( ttbar_theory_systematics ) # Add mass systematics diff --git a/src/cross_section_measurement/03_calculate_systematics.py b/src/cross_section_measurement/03_calculate_systematics.py index 6ca05ca9..c8595a76 100644 --- a/src/cross_section_measurement/03_calculate_systematics.py +++ b/src/cross_section_measurement/03_calculate_systematics.py @@ -25,11 +25,22 @@ def read_normalised_xsection_measurement( category, channel ): global path_to_JSON, met_type, met_uncertainties_list, k_values filename = '' - + path_to_use = path_to_JSON + k_value_to_use = k_values[channel] + # Use 8 TeV samples for hadronisation systematic + if 'powheg_v1_pythia' in category or 'powheg_v1_herwig' in category: + if '7TeV' in path_to_JSON: + path_to_use = path_to_JSON.replace('7TeV','8TeV') + config8TeV = XSectionConfig( 8 ) + if channel == 'electron': + k_value_to_use = config8TeV.k_values_electron[variable] + elif channel == 'muon': + k_value_to_use = config8TeV.k_values_muon[variable] + if category in met_uncertainties_list and variable == 'HT': - filename = path_to_JSON + '/' + channel + '/kv' + str( k_values[channel] ) + '/central/normalised_xsection_' + met_type + '.txt' + filename = path_to_use + '/' + channel + '/kv' + str( k_value_to_use ) + '/central/normalised_xsection_' + met_type + '.txt' else: - filename = path_to_JSON + '/' + channel + '/kv' + str( k_values[channel] ) + '/' + category + '/normalised_xsection_' + met_type + '.txt' + filename = path_to_use + '/' + channel + '/kv' + str( k_value_to_use ) + '/' + category + '/normalised_xsection_' + met_type + '.txt' if channel == 'combined': filename = filename.replace( 'kv' + str( k_values[channel] ), '' ) @@ -85,8 +96,8 @@ def summarise_systematics( list_of_central_measurements, dictionary_of_systemati error_up = max( error_down, error_up ) elif hadronisation_systematic: # always symmetric: absolute value of the difference between powheg_herwig and powheg_pythia - powheg_herwig = dictionary_of_systematics['TTJets_powheg_herwig'][bin_i][0] - powheg_pythia = dictionary_of_systematics['TTJets_powheg_pythia'][bin_i][0] + powheg_herwig = dictionary_of_systematics['TTJets_powheg_v1_herwig'][bin_i][0] + powheg_pythia = dictionary_of_systematics['TTJets_powheg_v1_pythia'][bin_i][0] difference = powheg_herwig - powheg_pythia mean = (powheg_herwig + powheg_pythia)/2.0 difference = abs(difference) @@ -212,7 +223,7 @@ def replace_measurement_with_deviation_from_central( central_measurement, dictio # ttbar theory systematics: ptreweighting, hadronisation systematic (powheg_pythia - powheg_herwig) ttbar_ptreweight_systematic_list = [ttbar_theory_systematic_prefix + 'ptreweight'] - ttbar_hadronisation_systematic_list = [ttbar_theory_systematic_prefix + 'powheg_pythia', ttbar_theory_systematic_prefix + 'powheg_herwig'] + ttbar_hadronisation_systematic_list = [ttbar_theory_systematic_prefix + 'powheg_v1_pythia', ttbar_theory_systematic_prefix + 'powheg_v1_herwig'] # 45 PDF uncertainties pdf_uncertainties = ['PDFWeights_%d' % index for index in range( 1, 45 )] diff --git a/src/cross_section_measurement/04_make_plots_matplotlib.py b/src/cross_section_measurement/04_make_plots_matplotlib.py index bf6ce082..6d8d3ba5 100644 --- a/src/cross_section_measurement/04_make_plots_matplotlib.py +++ b/src/cross_section_measurement/04_make_plots_matplotlib.py @@ -10,9 +10,10 @@ from tools.file_utilities import read_data_from_JSON, make_folder_if_not_exists from tools.hist_utilities import value_error_tuplelist_to_hist, spread_x,\ value_tuplelist_to_hist, value_errors_tuplelist_to_graph, graph_to_value_errors_tuplelist +from tools.plotting import adjust_ratio_ticks from math import sqrt # rootpy & matplotlib -from ROOT import kRed, kGreen, kMagenta, kBlue, kBlack +from ROOT import kRed, kGreen, kMagenta, kBlue, kBlack, kCyan from tools.ROOT_utils import set_root_defaults import matplotlib as mpl from tools.plotting import get_best_max_y @@ -64,11 +65,16 @@ def read_xsection_measurement_results( category, channel ): # true distributions h_normalised_xsection_MADGRAPH = value_error_tuplelist_to_hist( normalised_xsection_unfolded['MADGRAPH'], bin_edges[variable] ) h_normalised_xsection_MADGRAPH_ptreweight = value_error_tuplelist_to_hist( normalised_xsection_unfolded['MADGRAPH_ptreweight'], bin_edges[variable] ) - h_normalised_xsection_POWHEG_PYTHIA = value_error_tuplelist_to_hist( normalised_xsection_unfolded['POWHEG_PYTHIA'], bin_edges[variable] ) - h_normalised_xsection_POWHEG_HERWIG = value_error_tuplelist_to_hist( normalised_xsection_unfolded['POWHEG_HERWIG'], bin_edges[variable] ) + h_normalised_xsection_POWHEG_V2_PYTHIA = value_error_tuplelist_to_hist( normalised_xsection_unfolded['powheg_v2_pythia'], bin_edges[variable] ) + h_normalised_xsection_POWHEG_V2_HERWIG = value_error_tuplelist_to_hist( normalised_xsection_unfolded['powheg_v2_herwig'], bin_edges[variable] ) h_normalised_xsection_MCATNLO = None + h_normalised_xsection_POWHEG_V1_HERWIG = None + h_normalised_xsection_POWHEG_V1_PYTHIA = None if measurement_config.centre_of_mass_energy == 8: h_normalised_xsection_MCATNLO = value_error_tuplelist_to_hist( normalised_xsection_unfolded['MCATNLO'], bin_edges[variable] ) + h_normalised_xsection_POWHEG_V1_HERWIG = value_error_tuplelist_to_hist( normalised_xsection_unfolded['powheg_v1_herwig'], bin_edges[variable] ) + h_normalised_xsection_POWHEG_V1_PYTHIA = value_error_tuplelist_to_hist( normalised_xsection_unfolded['powheg_v1_pythia'], bin_edges[variable] ) + h_normalised_xsection_mathchingup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['matchingup'], bin_edges[variable] ) h_normalised_xsection_mathchingdown = value_error_tuplelist_to_hist( normalised_xsection_unfolded['matchingdown'], bin_edges[variable] ) h_normalised_xsection_scaleup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['scaleup'], bin_edges[variable] ) @@ -76,10 +82,14 @@ def read_xsection_measurement_results( category, channel ): histograms_normalised_xsection_different_generators.update( {'MADGRAPH':h_normalised_xsection_MADGRAPH, 'MADGRAPH_ptreweight':h_normalised_xsection_MADGRAPH_ptreweight, - 'POWHEG_PYTHIA':h_normalised_xsection_POWHEG_PYTHIA, - 'POWHEG_HERWIG':h_normalised_xsection_POWHEG_HERWIG} ) + 'powheg_v2_pythia':h_normalised_xsection_POWHEG_V2_PYTHIA, + 'powheg_v2_herwig':h_normalised_xsection_POWHEG_V2_HERWIG, + } ) if measurement_config.centre_of_mass_energy == 8: histograms_normalised_xsection_different_generators.update( {'MCATNLO':h_normalised_xsection_MCATNLO} ) + histograms_normalised_xsection_different_generators.update( {'powheg_v1_herwig':h_normalised_xsection_POWHEG_V1_HERWIG} ) + histograms_normalised_xsection_different_generators.update( {'powheg_v1_pythia':h_normalised_xsection_POWHEG_V1_PYTHIA} ) + histograms_normalised_xsection_systematics_shifts.update( {'MADGRAPH':h_normalised_xsection_MADGRAPH, 'MADGRAPH_ptreweight':h_normalised_xsection_MADGRAPH_ptreweight, @@ -424,10 +434,13 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True hist.linewidth = 4 linestyle = None # setting colours - if 'POWHEG_PYTHIA' in key or 'matchingdown' in key: + if 'powheg_v2_pythia' in key or 'matchingdown' in key: dashes[key] = [25,5,5,5,5,5,5,5] + hist.SetLineColor( kCyan + 2 ) + elif 'powheg_v1_pythia' in key: + dashes[key] = [10,5,5,10,5,5] hist.SetLineColor( kBlue ) - elif 'POWHEG_HERWIG' in key or 'scaledown' in key: + elif key == 'powheg_v1_herwig' or 'scaledown' in key: dashes[key] = [5,5] hist.SetLineColor( kGreen ) elif 'MADGRAPH_ptreweight' in key: @@ -437,7 +450,7 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True linestyle = 'solid' dashes[key] = None hist.SetLineColor( kRed + 1 ) - elif 'matchingup' in key: + elif 'matchingup' in key or 'powheg_v2_herwig' in key: dashes[key] = [25,5,5,5,25,5,5,5] hist.SetLineColor( kMagenta + 1 ) elif 'MCATNLO' in key or 'scaleup' in key: @@ -447,7 +460,6 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True if linestyle != None: hist.linestyle = linestyle line, h = rplt.hist( hist, axes = axes, label = measurements_latex[key], zorder = zorder ) - if dashes[key] != None: line.set_dashes(dashes[key]) h.set_dashes(dashes[key]) @@ -511,6 +523,7 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True ratio.Divide( hist_data ) #divide by data line, h = rplt.hist( ratio, axes = ax1, label = 'do_not_show' ) if dashes[key] != None: + line.set_dashes(dashes[key]) h.set_dashes(dashes[key]) stat_lower = hist_data.Clone() @@ -529,34 +542,56 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True syst_upper.SetBinContent( bin_i, 1 + syst_errors[bin_i-1][2]/syst_errors[bin_i-1][0] ) if category == 'central': rplt.fill_between( syst_lower, syst_upper, ax1, - color = 'yellow', alpha = 0.5 ) + color = 'yellow' ) - rplt.fill_between( stat_upper, stat_lower, ax1, color = '0.75', - alpha = 0.5 ) + rplt.fill_between( stat_upper, stat_lower, ax1, color = '0.75' ) # legend for ratio plot p_stat = mpatches.Patch(facecolor='0.75', label='Stat.', edgecolor='black' ) p_stat_and_syst = mpatches.Patch(facecolor='yellow', label=r'Stat. $\oplus$ Syst.', edgecolor='black' ) - l1 = ax1.legend(handles = [p_stat, p_stat_and_syst], loc = 'upper left', - frameon = False, prop = {'size':26}, ncol = 2) - ax1.add_artist(l1) - + ratioLegendLocation = 'best' if variable == 'MET': - ax1.set_ylim( ymin = 0.7, ymax = 1.3 ) - ax1.yaxis.set_major_locator( MultipleLocator( 0.2 ) ) -# ax1.yaxis.set_minor_locator( MultipleLocator( 0.1 ) ) + ax1.set_ylim( ymin = 0.6, ymax = 1.4 ) + # ax1.yaxis.set_major_locator( MultipleLocator( 0.3 ) ) + # ax1.yaxis.set_minor_locator( MultipleLocator( 0.1 ) ) + if measurement_config.centre_of_mass_energy == 7: + ratioLegendLocation = 'upper left' + elif measurement_config.centre_of_mass_energy == 8: + ratioLegendLocation = 'upper left' + if variable == 'MT': ax1.set_ylim( ymin = 0.8, ymax = 1.2 ) - ax1.yaxis.set_major_locator( MultipleLocator( 0.2 ) ) - ax1.yaxis.set_minor_locator( MultipleLocator( 0.1 ) ) - elif variable == 'HT' or variable == 'ST': - ax1.set_ylim( ymin = 0.5, ymax = 1.5 ) - ax1.yaxis.set_major_locator( MultipleLocator( 0.5 ) ) - ax1.yaxis.set_minor_locator( MultipleLocator( 0.1 ) ) + # ax1.yaxis.set_major_locator( MultipleLocator( 0.2 ) ) + # ax1.yaxis.set_minor_locator( MultipleLocator( 0.1 ) ) + elif variable == 'ST': + ax1.set_ylim( ymin = 0.6, ymax = 1.4 ) + # ax1.yaxis.set_major_locator( MultipleLocator( 0.3 ) ) + # ax1.yaxis.set_minor_locator( MultipleLocator( 0.1 ) ) + if measurement_config.centre_of_mass_energy == 7: + ratioLegendLocation = 'lower center' + elif measurement_config.centre_of_mass_energy == 8: + ratioLegendLocation = 'lower left' + elif variable == 'HT': + ax1.set_ylim( ymin = 0.6, ymax = 1.4 ) + # ax1.yaxis.set_major_locator( MultipleLocator( 0.3 ) ) + # ax1.yaxis.set_minor_locator( MultipleLocator( 0.1 ) ) + if measurement_config.centre_of_mass_energy == 7: + ratioLegendLocation = 'lower center' + elif measurement_config.centre_of_mass_energy == 8: + ratioLegendLocation = 'upper left' elif variable == 'WPT': - ax1.set_ylim( ymin = 0.75, ymax = 1.5 ) - ax1.yaxis.set_major_locator( MultipleLocator( 0.25 ) ) - ax1.yaxis.set_minor_locator( MultipleLocator( 0.05 ) ) + ax1.set_ylim( ymin = 0.6, ymax = 1.4 ) + # ax1.yaxis.set_major_locator( MultipleLocator( 0.2 ) ) + # ax1.yaxis.set_minor_locator( MultipleLocator( 0.1 ) ) + if measurement_config.centre_of_mass_energy == 7: + ratioLegendLocation = 'upper left' + elif measurement_config.centre_of_mass_energy == 8: + ratioLegendLocation = 'upper left' + adjust_ratio_ticks(ax1.yaxis, n_ticks = 3, y_limits = ax1.get_ylim() ) + + l1 = ax1.legend(handles = [p_stat, p_stat_and_syst], loc = ratioLegendLocation, + frameon = False, prop = {'size':26}, ncol = 2) + ax1.add_artist(l1) if CMS.tight_layout: plt.tight_layout() @@ -726,7 +761,8 @@ def get_unit_string(fit_variable): all_measurements.extend( met_uncertainties ) all_measurements.extend( new_uncertainties ) all_measurements.extend( rate_changing_systematics ) - for channel in ['electron', 'muon', 'combined']: + # for channel in ['electron', 'muon', 'combined']: + for channel in ['combined']: for category in all_measurements: if not category == 'central' and not options.draw_systematics: continue @@ -758,7 +794,6 @@ def get_unit_string(fit_variable): met_type = 'patMETsPFlow' histograms_normalised_xsection_different_generators, histograms_normalised_xsection_systematics_shifts = read_xsection_measurement_results( category, channel ) - make_plots( histograms_normalised_xsection_different_generators, category, output_folder, 'normalised_xsection_' + channel + '_different_generators' ) make_plots( histograms_normalised_xsection_systematics_shifts, category, output_folder, 'normalised_xsection_' + channel + '_systematics_shifts' ) From 0bacbbcd52314654c4b515b527cf438006e7524f Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Fri, 18 Dec 2015 14:10:11 +0000 Subject: [PATCH 10/29] Add additional powheg samples to unfolding files. Add some debugging plots. --- .../produceUnfoldingHistograms.py | 100 +++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/experimental/BLTUnfold/createAsymmetricBinningUnfoldingFiles/produceUnfoldingHistograms.py b/experimental/BLTUnfold/createAsymmetricBinningUnfoldingFiles/produceUnfoldingHistograms.py index 0ea9c605..f6b7c6d0 100644 --- a/experimental/BLTUnfold/createAsymmetricBinningUnfoldingFiles/produceUnfoldingHistograms.py +++ b/experimental/BLTUnfold/createAsymmetricBinningUnfoldingFiles/produceUnfoldingHistograms.py @@ -82,7 +82,10 @@ def copyEventFilterHist( inputFile, outputFile ): 'matchingup' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_matchingup_8TeV.root', 'matchingdown' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_matchingdown_8TeV.root', 'powheg' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_powhegpythia_8TeV.root', + 'powhegV2pythia' : '/storage/ec6821/NTupleProd/CMSSW_5_3_23/src/TTJets_PowhegPythia_new__8TeV.root', 'powhegherwig' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_powhegherwig_8TeV.root', + # 'powhegherwig_new' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_powhegherwig_NEW_8TeV.root', + 'powhegherwig_new' : '/storage/ec6821/NTupleProd/CMSSW_5_3_23/src/TTJets_nTuple_53X_mc.root', 'mcatnlo' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_mcatnlo_8TeV.root', 'massdown' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_mass_169_5_8TeV.root', 'massup' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_mass_173_5_8TeV.root', @@ -218,7 +221,24 @@ def main(): truth = Hist( bin_edges[variable], name='truth') measured = Hist( bin_edges[variable], name='measured') fake = Hist( bin_edges[variable], name='fake') + + h_nJets = Hist([-0.5,0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5], name='nJets') + h_nJetsG20 = Hist([-0.5,0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5], name='nJetsG20') + h_nJetsG30 = Hist([-0.5,0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5], name='nJetsG30') + h_htG20 = Hist([i*20 for i in range(5,26)], name='htG20') + h_htG30 = Hist([i*20 for i in range(5,26)], name='htG30') + + jetPt = Hist([i*2.5 for i in range(8,20)], name='jetPt') + + jetPt1 = Hist([i*5 for i in range(3,40)], name='jetPt1') + jetPt2 = Hist([i*5 for i in range(3,40)], name='jetPt2') + jetPt3 = Hist([i*5 for i in range(3,40)], name='jetPt3') + jetPt4 = Hist([i*5 for i in range(3,40)], name='jetPt4') + jetPt5 = Hist([i*5 for i in range(3,40)], name='jetPt5') + jetPt6 = Hist([i*5 for i in range(3,40)], name='jetPt6') + jetPt7 = Hist([i*5 for i in range(3,40)], name='jetPt7') + # 2D histograms response = Hist2D( bin_edges[variable], bin_edges[variable], name='response') response_without_fakes = Hist2D( bin_edges[variable], bin_edges[variable], name='response_without_fakes') @@ -244,6 +264,10 @@ def main(): tree.Draw(genVariable,genWeight+'*'+genSelection,hist=truth) tree.Draw(recoVariable,offlineWeight+'*'+offlineSelection,hist=measured) tree.Draw(recoVariable,offlineWeight+'*'+fakeSelection,hist=fake) + tree.Draw("@(unfolding.jetPt).size()",genWeight+'*'+genSelection,hist=nJets) + tree.Draw('unfolding.jetPt',genWeight+'*'+genSelection,hist=jetPt) + tree.Draw('unfolding.recoNJets',offlineSelection+'&&'+genSelection,hist=h_nJets) + # 2D tree.Draw(recoVariable+':'+genVariable,offlineWeight+'*'+offlineSelection,hist=response) tree.Draw(recoVariable+':'+genVariable,offlineWeight+'* ('+offlineSelection+'&&'+genSelection +')',hist=response_without_fakes) @@ -252,11 +276,85 @@ def main(): if options.extraHists: tree.Draw( 'unfolding.puWeight','unfolding.OfflineSelection',hist=puOffline) pass - + + + # tree.SetBranchStatus('*',0) + # tree.SetBranchStatus('unfolding.jetPt',1) + # tree.SetBranchStatus('unfolding.GenSelection',1) + # tree.SetBranchStatus('unfolding.OfflineSelection',1) + # print tree.GetEntries() + # nEvents = 0 + # for event in tree: + # nEvents += 1 + # genSelection = event.__getattr__('unfolding.GenSelection') + # offlineSelection = event.__getattr__('unfolding.OfflineSelection') + + # if genSelection == 1 and offlineSelection == 1 : + # jets = event.__getattr__('unfolding.jetPt') + # nJetsG20 = 0 + # nJetsG30 = 0 + # htG20 = 0 + # htG30 = 0 + + # if len(jets) > 0 : + # jetPt1.Fill(jets[0]) + + # if len(jets) > 1: + # jetPt2.Fill(jets[1]) + + # if len(jets) > 2: + # jetPt3.Fill(jets[2]) + + # if len(jets) > 3: + # jetPt4.Fill(jets[3]) + + # if len(jets) > 4: + # jetPt5.Fill(jets[4]) + + # if len(jets) > 5: + # jetPt6.Fill(jets[5]) + + # if len(jets) > 6: + # jetPt7.Fill(jets[6]) + # for jetPt in jets: + # if jetPt >= 20: + # nJetsG20 += 1 + # htG20 += jetPt + # if jetPt >= 30: + # nJetsG30 += 1 + # htG30 += jetPt + # h_nJetsG20.Fill(nJetsG20) + # h_nJetsG30.Fill(nJetsG30) + # h_htG20.Fill(htG20) + # h_htG30.Fill(htG30) + # if nEvents > 100000 : break # Output histgorams to file outputDir.cd() + # truth.Scale(1/truth.Integral()) truth.Write() measured.Write() + + # h_nJetsG20.Scale(1/h_nJetsG20.Integral()) + # h_nJetsG30.Scale(1/h_nJetsG30.Integral()) + # h_htG20.Scale(1/h_htG20.Integral()) + # h_htG30.Scale(1/h_htG30.Integral()) + + h_nJets.Write() + h_nJetsG20.Write() + h_nJetsG30.Write() + h_htG20.Write() + h_htG30.Write() + + jetPt1.Write() + jetPt2.Write() + jetPt3.Write() + jetPt4.Write() + jetPt5.Write() + jetPt6.Write() + jetPt7.Write() + + # jetPt.Scale( 1/jetPt.Integral() ) + # jetPt.Write() fake.Write() response.Write() response_without_fakes.Write() From 4e11e7bb01c7bc2a10224a82129e4d6f934195a8 Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Fri, 18 Dec 2015 14:10:47 +0000 Subject: [PATCH 11/29] Add powheg files to config. --- config/__init__.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/config/__init__.py b/config/__init__.py index 47f97dd4..603a0119 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -42,8 +42,9 @@ class XSectionConfig(): 'unfolding_matching_up', 'unfolding_matching_up_raw', 'unfolding_mass_down', 'unfolding_mass_up', 'unfolding_mcatnlo', 'unfolding_mcatnlo_raw', - 'unfolding_powheg_pythia', 'unfolding_powheg_pythia_raw', - 'unfolding_powheg_herwig', 'unfolding_powheg_herwig_raw', + 'unfolding_powheg_v2_pythia', 'unfolding_powheg_v2_pythia_raw', + 'unfolding_powheg_v1_herwig', 'unfolding_powheg_v1_herwig_raw', + 'unfolding_powheg_v2_herwig', 'unfolding_powheg_v2_herwig_raw', 'unfolding_scale_down', 'unfolding_scale_down_raw', 'unfolding_scale_up', 'unfolding_scale_up_raw', 'unfolding_ptreweight', 'unfolding_ptreweight_raw', @@ -217,8 +218,10 @@ def __fill_defaults__( self ): } self.unfolding_madgraph_raw = path_to_unfolding_histograms + 'unfolding_TTJets_%dTeV.root' % self.centre_of_mass_energy - self.unfolding_powheg_pythia_raw = path_to_unfolding_histograms + 'unfolding_TTJets_%dTeV_powheg.root' % self.centre_of_mass_energy - self.unfolding_powheg_herwig_raw = path_to_unfolding_histograms + 'unfolding_TTJets_%dTeV_powhegherwig.root' % self.centre_of_mass_energy + self.unfolding_powheg_v1_pythia_raw = path_to_unfolding_histograms + 'unfolding_TTJets_%dTeV_powhegV1pythia.root' % self.centre_of_mass_energy + self.unfolding_powheg_v2_pythia_raw = path_to_unfolding_histograms + 'unfolding_TTJets_%dTeV_powhegV2pythia.root' % self.centre_of_mass_energy + self.unfolding_powheg_v1_herwig_raw = path_to_unfolding_histograms + 'unfolding_TTJets_%dTeV_powhegV1herwig.root' % self.centre_of_mass_energy + self.unfolding_powheg_v2_herwig_raw = path_to_unfolding_histograms + 'unfolding_TTJets_%dTeV_powhegV2herwig.root' % self.centre_of_mass_energy self.unfolding_mcatnlo_raw = path_to_unfolding_histograms + 'unfolding_TTJets_%dTeV_mcatnlo.root' % self.centre_of_mass_energy self.unfolding_ptreweight_raw = path_to_unfolding_histograms + 'unfolding_TTJets_%dTeV_withTopPtReweighting.root' % self.centre_of_mass_energy @@ -228,8 +231,10 @@ def __fill_defaults__( self ): self.unfolding_matching_up_raw = path_to_unfolding_histograms + 'unfolding_TTJets_%dTeV_matchingup.root' % self.centre_of_mass_energy self.unfolding_madgraph = self.unfolding_madgraph_raw.replace( '.root', '_asymmetric.root' ) - self.unfolding_powheg_pythia = self.unfolding_powheg_pythia_raw.replace( '.root', '_asymmetric.root' ) - self.unfolding_powheg_herwig = self.unfolding_powheg_herwig_raw.replace( '.root', '_asymmetric.root' ) + self.unfolding_powheg_v1_pythia = self.unfolding_powheg_v1_pythia_raw.replace( '.root', '_asymmetric.root' ) + self.unfolding_powheg_v2_pythia = self.unfolding_powheg_v2_pythia_raw.replace( '.root', '_asymmetric.root' ) + self.unfolding_powheg_v1_herwig = self.unfolding_powheg_v1_herwig_raw.replace( '.root', '_asymmetric.root' ) + self.unfolding_powheg_v2_herwig = self.unfolding_powheg_v2_herwig_raw.replace( '.root', '_asymmetric.root' ) self.unfolding_mcatnlo = self.unfolding_mcatnlo_raw.replace( '.root', '_asymmetric.root' ) self.unfolding_ptreweight = path_to_unfolding_histograms + 'unfolding_TTJets_%dTeV_asymmetric_withTopPtReweighting.root' % self.centre_of_mass_energy @@ -419,11 +424,15 @@ def __fill_defaults_8TeV__( self ): 'JES_down': path_to_files + 'JES_down/SingleElectron' + middle + self.categories_and_prefixes['JES_down'] + '.root' } -fit_var_inputs = ['absolute_eta', 'M3', 'M_bl', 'angle_bl', - 'absolute_eta_angle_bl', - 'absolute_eta_M3', - 'absolute_eta_M_bl', - 'absolute_eta_M_bl_angle_bl', +fit_var_inputs = [ + 'absolute_eta', 'M3', +# 'M_bl', + 'angle_bl', + # 'absolute_eta_angle_bl', + # 'absolute_eta_M3', + # 'absolute_eta_M_bl', + # 'absolute_eta_M_bl_angle_bl', 'absolute_eta_M3_angle_bl', - 'absolute_eta_M_bl_M3', - 'absolute_eta_M_bl_M3_angle_bl' ] + # 'absolute_eta_M_bl_M3', + # 'absolute_eta_M_bl_M3_angle_bl' + ] From 2b2d6c46be9a14be93815638b8f9cfd58913b02a Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Fri, 18 Dec 2015 14:11:11 +0000 Subject: [PATCH 12/29] Update latex for variables and samples. --- config/latex_labels.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/config/latex_labels.py b/config/latex_labels.py index a887185b..63167512 100644 --- a/config/latex_labels.py +++ b/config/latex_labels.py @@ -10,11 +10,12 @@ '4orMoreBtags':'$\geq$ 4 b tags'} variables_latex = { - 'MET': 'E_{\mathrm{T}}^{\mathrm{miss}}', - 'HT': 'H_{\mathrm{T}}', - 'ST': 'S_{\mathrm{T}}', - 'MT': 'M^{\mathrm{W}}_{\mathrm{T}}', - 'WPT': 'p^\mathrm{W}_{\mathrm{T}}'} + 'MET': '\ensuremath{E_{\mathrm{T}}^{\mathrm{miss}}}', + 'HT': '\ensuremath{H_{\mathrm{T}}}', + 'ST': '\ensuremath{S_{\mathrm{T}}}', + 'MT': '\ensuremath{M^{\mathrm{W}}_{\mathrm{T}}}', + 'WPT': '\ensuremath{p^\mathrm{W}_{\mathrm{T}}}' + } ttBarLatex = '$\mathrm{t}\\bar{\mathrm{t}}$' @@ -23,8 +24,10 @@ 'MADGRAPH': 'Madgraph Pythia', 'MADGRAPH_ptreweight': 'Madgraph+$p_\mathrm{T}$ reweighting', 'MCATNLO': 'MC@NLO Herwig', - 'POWHEG_PYTHIA': 'Powheg Pythia', - 'POWHEG_HERWIG': 'Powheg Herwig', + 'powheg_v1_pythia': 'Powheg (v1) Pythia6', + 'powheg_v2_pythia': 'Powheg (v2) Pythia6', + 'powheg_v1_herwig': 'Powheg (v1) Herwig', + 'powheg_v2_herwig': 'Powheg (v2) Herwig++', 'matchingdown': 'Matching down', 'matchingup': 'Matching up', 'scaledown': '$Q^{2}$ down', From f3c1ac2556129edee222cd9d74e1fa78abe98ebc Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Fri, 18 Dec 2015 14:13:49 +0000 Subject: [PATCH 13/29] Comment out some stuff for debugging. --- .../98b_fit_cross_checks.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/cross_section_measurement/98b_fit_cross_checks.py b/src/cross_section_measurement/98b_fit_cross_checks.py index ae8be4c7..6eb324dc 100644 --- a/src/cross_section_measurement/98b_fit_cross_checks.py +++ b/src/cross_section_measurement/98b_fit_cross_checks.py @@ -125,6 +125,7 @@ def create_latex_string( fit_var_input ): initial_values_electron = {} initial_values_muon = {} for fit_variable in fit_variables: + path = path_to_JSON + fit_variable + '/' + str( come ) + 'TeV/' fit_results_electron[fit_variable] = read_normalisation( path, variable, @@ -149,16 +150,16 @@ def create_latex_string( fit_var_input ): 'muon', met_type ) - if not 'closure' in path_to_JSON: - fit_results_electron['before'] = read_normalisation( 'data_single_var_fit/8TeV/', - variable, - category, - 'electron', - met_type ) - fit_results_muon['before'] = read_normalisation( 'data_single_var_fit/8TeV/', - variable, - category, - 'muon', - met_type ) + # if not 'closure' in path_to_JSON: + # fit_results_electron['before'] = read_normalisation( 'data_single_var_fit/8TeV/', + # variable, + # category, + # 'electron', + # met_type ) + # fit_results_muon['before'] = read_normalisation( 'data_single_var_fit/8TeV/', + # variable, + # category, + # 'muon', + # met_type ) plot_fit_results( fit_results_electron, initial_values_electron, 'electron' ) plot_fit_results( fit_results_muon, initial_values_muon, 'muon' ) From 0019c853811bfaf9b384f32dc5168c32a4570bf3 Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Fri, 18 Dec 2015 14:14:20 +0000 Subject: [PATCH 14/29] Update path in plots2tdr. --- bin/plots2tdr | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/plots2tdr b/bin/plots2tdr index 8515758a..d9da56cc 100755 --- a/bin/plots2tdr +++ b/bin/plots2tdr @@ -17,15 +17,15 @@ plot_map_common = {} plot_map_paper = { # : , # results 8 TeV - '7TeV/MET/central/normalised_xsection_combined_*.pdf': '7TeV/MET/', - '7TeV/HT/central/normalised_xsection_combined_*.pdf': '7TeV/HT/', - '7TeV/ST/central/normalised_xsection_combined_*.pdf': '7TeV/ST/', - '7TeV/WPT/central/normalised_xsection_combined_*.pdf': '7TeV/WPT/', + 'fit/7TeV/MET/central/normalised_xsection_combined_*.pdf': '7TeV/MET/', + 'fit/7TeV/HT/central/normalised_xsection_combined_*.pdf': '7TeV/HT/', + 'fit/7TeV/ST/central/normalised_xsection_combined_*.pdf': '7TeV/ST/', + 'fit/7TeV/WPT/central/normalised_xsection_combined_*.pdf': '7TeV/WPT/', # results 8 TeV - '8TeV/MET/central/normalised_xsection_combined_*.pdf': '8TeV/MET/', - '8TeV/HT/central/normalised_xsection_combined_*.pdf': '8TeV/HT/', - '8TeV/ST/central/normalised_xsection_combined_*.pdf': '8TeV/ST/', - '8TeV/WPT/central/normalised_xsection_combined_*.pdf': '8TeV/WPT/', + 'fit/8TeV/MET/central/normalised_xsection_combined_*.pdf': '8TeV/MET/', + 'fit/8TeV/HT/central/normalised_xsection_combined_*.pdf': '8TeV/HT/', + 'fit/8TeV/ST/central/normalised_xsection_combined_*.pdf': '8TeV/ST/', + 'fit/8TeV/WPT/central/normalised_xsection_combined_*.pdf': '8TeV/WPT/', # control plots 8 TeV 'control_plots/after_fit/8TeV/*_HT_2orMoreBtags_with_ratio.pdf': 'control/', 'control_plots/after_fit/8TeV/*_patType1CorrectedPFMet_2orMoreBtags_with_ratio.pdf': 'control/', From 94e2d7c6843dc87c6fdd96b13a8538e056dd3bb3 Mon Sep 17 00:00:00 2001 From: Emyr Clement Date: Fri, 18 Dec 2015 14:14:39 +0000 Subject: [PATCH 15/29] Small changes --- bin/x_01_all_vars | 5 ++++- bin/x_02_all_vars | 3 +++ bin/x_03_all_vars | 3 +++ bin/x_04_all_vars | 7 +++++-- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bin/x_01_all_vars b/bin/x_01_all_vars index 39a3d201..b983c5c5 100755 --- a/bin/x_01_all_vars +++ b/bin/x_01_all_vars @@ -1,7 +1,10 @@ #!/bin/bash echo "This will take a while ... grab a coffee/tea/water/cocktail" mkdir -p logs -fit_var="absolute_eta,M3,angle_bl" +# fit_var="absolute_eta,M3,angle_bl" +# fit_var="absolute_eta" +# fit_var="M3" +fit_var="angle_bl" nice_fit_var=`echo $fit_var | sed 's/,/_/g'` N_JOBS=6 diff --git a/bin/x_02_all_vars b/bin/x_02_all_vars index f23010cb..65ad197e 100755 --- a/bin/x_02_all_vars +++ b/bin/x_02_all_vars @@ -2,6 +2,9 @@ echo "This will take a while ... grab a coffee/tea/water" mkdir -p logs fit_var="absolute_eta,M3,angle_bl" +# fit_var="absolute_eta" +# fit_var="M3" +# fit_var="angle_bl" nice_fit_var=`echo $fit_var | sed 's/,/_/g'` N_JOBS=6 diff --git a/bin/x_03_all_vars b/bin/x_03_all_vars index 4eba0c74..b436ef13 100755 --- a/bin/x_03_all_vars +++ b/bin/x_03_all_vars @@ -2,6 +2,9 @@ echo "This will take a while ... grab a coffee/tea/water" mkdir -p logs fit_var="absolute_eta,M3,angle_bl" +# fit_var="absolute_eta" +# fit_var="M3" +# fit_var="angle_bl" nice_fit_var=`echo $fit_var | sed 's/,/_/g'` N_JOBS=6 diff --git a/bin/x_04_all_vars b/bin/x_04_all_vars index 4b705c10..facab725 100755 --- a/bin/x_04_all_vars +++ b/bin/x_04_all_vars @@ -3,6 +3,9 @@ echo "This will take a while ... grab a coffee/tea/water" mkdir -p logs mkdir -p plots fit_var="absolute_eta,M3,angle_bl" +# fit_var="absolute_eta" +# fit_var="M3" +# fit_var="angle_bl" nice_fit_var=`echo $fit_var | sed 's/,/_/g'` N_JOBS=5 @@ -11,7 +14,7 @@ echo "Using the fit variable(s): $fit_var" i=0 for var in MET HT ST MT WPT; do echo "Plotting diff. x-section for distribution: $var" - nohup time python src/cross_section_measurement/04_make_plots_matplotlib.py -v $var -c 7 -p data/$nice_fit_var -o plots/fit &> logs/04_${var}_plot_7TeV_${nice_fit_var}.log & # -a -s <--add -a option for additional plots, -s option to include the final results from background subtraction as well as from fitting + nohup time python src/cross_section_measurement/04_make_plots_matplotlib.py -v $var -c 7 -p data/$nice_fit_var -o plots/fit/ &> logs/04_${var}_plot_7TeV_${nice_fit_var}.log & # -a -s <--add -a option for additional plots, -s option to include the final results from background subtraction as well as from fitting let i+=1 if (( $i % N_JOBS == 0 )) then @@ -19,7 +22,7 @@ for var in MET HT ST MT WPT; do wait; fi - nohup time python src/cross_section_measurement/04_make_plots_matplotlib.py -v $var -c 8 -p data/$nice_fit_var -o plots/fit &> logs/04_${var}_plot_8TeV_${nice_fit_var}.log & # -a -s <--add -a option for additional plots, -s option to include the final results from background subtraction as well as from fitting + nohup time python src/cross_section_measurement/04_make_plots_matplotlib.py -v $var -c 8 -p data/$nice_fit_var -o plots/fit/ &> logs/04_${var}_plot_8TeV_${nice_fit_var}.log & # -a -s <--add -a option for additional plots, -s option to include the final results from background subtraction as well as from fitting let i+=1 if (( $i % N_JOBS == 0 )) then From 7ab39c42c3cb672ed4ddf4ce6d4731f9e77a7bce Mon Sep 17 00:00:00 2001 From: jjacob Date: Fri, 18 Dec 2015 11:52:50 +0000 Subject: [PATCH 16/29] Fixing bug in axes labels in control plots. --- src/cross_section_measurement/make_control_plots.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cross_section_measurement/make_control_plots.py b/src/cross_section_measurement/make_control_plots.py index 254228a8..20e74cc8 100644 --- a/src/cross_section_measurement/make_control_plots.py +++ b/src/cross_section_measurement/make_control_plots.py @@ -73,8 +73,8 @@ def compare_shapes( channel, x_axis_title, y_axis_title, histogram_properties = Histogram_properties() histogram_properties.name = name_prefix + b_tag_bin histogram_properties.title = title - histogram_properties.x_axis_title = y_axis_title - histogram_properties.y_axis_title = x_axis_title + histogram_properties.x_axis_title = x_axis_title + histogram_properties.y_axis_title = y_axis_title histogram_properties.x_limits = x_limits histogram_properties.y_limits = y_limits histogram_properties.legend_location = legend_location From ab9d749436843c4e34ad5b793d3e5c818a0a9ac2 Mon Sep 17 00:00:00 2001 From: jjacob Date: Fri, 18 Dec 2015 11:53:18 +0000 Subject: [PATCH 17/29] changing x-axis label from angle(b,l) to \alpha. --- src/cross_section_measurement/make_fit_variable_plots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cross_section_measurement/make_fit_variable_plots.py b/src/cross_section_measurement/make_fit_variable_plots.py index b2f1daac..9f5e217c 100644 --- a/src/cross_section_measurement/make_fit_variable_plots.py +++ b/src/cross_section_measurement/make_fit_variable_plots.py @@ -28,7 +28,7 @@ fit_variable_properties = { 'M3': {'min':0, 'max':1000, 'rebin':5, 'x-title': 'M3 [GeV]', 'y-title': 'Events/25 GeV'}, 'M_bl': {'min':0, 'max':400, 'rebin':2, 'x-title': 'M(b,l) [GeV]', 'y-title': 'Events/10 GeV'}, - 'angle_bl': {'min':0, 'max':3.5, 'rebin':2, 'x-title': 'angle(b,l)', 'y-title': 'Events/(0.2)'}, + 'angle_bl': {'min':0, 'max':3.5, 'rebin':2, 'x-title': '\alpha', 'y-title': 'Events/(0.2)'}, 'electron_absolute_eta': {'min':0, 'max':2.6, 'rebin':2, 'x-title': '$\left|\eta(e)\\right|$', 'y-title': 'Events/(0.2)'}, 'muon_absolute_eta': {'min':0, 'max':2.6, 'rebin':2, 'x-title': '$\left|\eta(\mu)\\right|$', 'y-title': 'Events/(0.2)'}, } From d124b79ff3b3d75a95af0502f9464d19269938dd Mon Sep 17 00:00:00 2001 From: jjacob Date: Sun, 27 Dec 2015 11:02:04 +0000 Subject: [PATCH 18/29] Reinstating some previously erroneously commented out lines. --- bin/x_01_all_vars | 4 ++-- .../04_make_plots_matplotlib.py | 16 +++++++------- .../98b_fit_cross_checks.py | 22 +++++++++---------- .../make_control_plots.py | 20 ++++++++--------- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/bin/x_01_all_vars b/bin/x_01_all_vars index b983c5c5..8194f633 100755 --- a/bin/x_01_all_vars +++ b/bin/x_01_all_vars @@ -1,10 +1,10 @@ #!/bin/bash echo "This will take a while ... grab a coffee/tea/water/cocktail" mkdir -p logs -# fit_var="absolute_eta,M3,angle_bl" +fit_var="absolute_eta,M3,angle_bl" # fit_var="absolute_eta" # fit_var="M3" -fit_var="angle_bl" +#fit_var="angle_bl" nice_fit_var=`echo $fit_var | sed 's/,/_/g'` N_JOBS=6 diff --git a/src/cross_section_measurement/04_make_plots_matplotlib.py b/src/cross_section_measurement/04_make_plots_matplotlib.py index 6d8d3ba5..3dc94284 100644 --- a/src/cross_section_measurement/04_make_plots_matplotlib.py +++ b/src/cross_section_measurement/04_make_plots_matplotlib.py @@ -779,14 +779,14 @@ def get_unit_string(fit_variable): if met_type == 'PFMETJetEnDown': met_type = 'patPFMetJetEnDown' - # if not channel == 'combined' and options.additional_plots: - # #Don't make additional plots for e.g. generator systematics, mass systematics, k value systematics and pdf systematics because they are now done \ - # #in the unfolding process with BLT unfolding files. - # if category in ttbar_generator_systematics or category in ttbar_mass_systematics or category in kValue_systematics or category in pdf_uncertainties: - # continue - # fit_templates, fit_results = read_fit_templates_and_results_as_histograms( category, channel ) - # make_template_plots( fit_templates, category, channel ) - # plot_fit_results( fit_results, category, channel ) + if not channel == 'combined' and options.additional_plots: + #Don't make additional plots for e.g. generator systematics, mass systematics, k value systematics and pdf systematics because they are now done \ + #in the unfolding process with BLT unfolding files. + if category in ttbar_generator_systematics or category in ttbar_mass_systematics or category in kValue_systematics or category in pdf_uncertainties: + continue + fit_templates, fit_results = read_fit_templates_and_results_as_histograms( category, channel ) + make_template_plots( fit_templates, category, channel ) + plot_fit_results( fit_results, category, channel ) # change back to original MET type met_type = translate_options[options.metType] diff --git a/src/cross_section_measurement/98b_fit_cross_checks.py b/src/cross_section_measurement/98b_fit_cross_checks.py index 6eb324dc..252700b5 100644 --- a/src/cross_section_measurement/98b_fit_cross_checks.py +++ b/src/cross_section_measurement/98b_fit_cross_checks.py @@ -150,16 +150,16 @@ def create_latex_string( fit_var_input ): 'muon', met_type ) - # if not 'closure' in path_to_JSON: - # fit_results_electron['before'] = read_normalisation( 'data_single_var_fit/8TeV/', - # variable, - # category, - # 'electron', - # met_type ) - # fit_results_muon['before'] = read_normalisation( 'data_single_var_fit/8TeV/', - # variable, - # category, - # 'muon', - # met_type ) + if not 'closure' in path_to_JSON: + fit_results_electron['before'] = read_normalisation( 'data_single_var_fit/8TeV/', + variable, + category, + 'electron', + met_type ) + fit_results_muon['before'] = read_normalisation( 'data_single_var_fit/8TeV/', + variable, + category, + 'muon', + met_type ) plot_fit_results( fit_results_electron, initial_values_electron, 'electron' ) plot_fit_results( fit_results_muon, initial_values_muon, 'muon' ) diff --git a/src/cross_section_measurement/make_control_plots.py b/src/cross_section_measurement/make_control_plots.py index 20e74cc8..e4a8453a 100644 --- a/src/cross_section_measurement/make_control_plots.py +++ b/src/cross_section_measurement/make_control_plots.py @@ -307,22 +307,22 @@ def make_plot( channel, x_axis_title, y_axis_title, # comment out plots you don't want include_plots = [ 'eta', - # 'pT', + 'pT', 'MET', - # 'MET log', - # 'MET phi', + 'MET log', + 'MET phi', 'HT', 'ST', 'WPT', - # 'MT', + 'MT', 'M3', 'angle_bl', - # 'bjet invariant mass', - # 'b-tag multiplicity', - # 'b-tag multiplicity reweighted', - # 'jet multiplicity', - # 'n vertex', - # 'n vertex reweighted', + 'bjet invariant mass', + 'b-tag multiplicity', + 'b-tag multiplicity reweighted', + 'jet multiplicity', + 'n vertex', + 'n vertex reweighted', ] additional_qcd_plots = [ 'eta in MET bins', From 38113c56a3f8c044e6b79f526833c36b6ced5c97 Mon Sep 17 00:00:00 2001 From: jjacob Date: Sun, 27 Dec 2015 11:05:33 +0000 Subject: [PATCH 19/29] Fixing errors in filepaths and updating to use new BLT files for powheg-pythia and powheg-herwig. --- .../produceUnfoldingHistograms.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/experimental/BLTUnfold/createAsymmetricBinningUnfoldingFiles/produceUnfoldingHistograms.py b/experimental/BLTUnfold/createAsymmetricBinningUnfoldingFiles/produceUnfoldingHistograms.py index f6b7c6d0..8369eb74 100644 --- a/experimental/BLTUnfold/createAsymmetricBinningUnfoldingFiles/produceUnfoldingHistograms.py +++ b/experimental/BLTUnfold/createAsymmetricBinningUnfoldingFiles/produceUnfoldingHistograms.py @@ -81,11 +81,10 @@ def copyEventFilterHist( inputFile, outputFile ): 'scaledown' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_scaledown_8TeV.root', 'matchingup' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_matchingup_8TeV.root', 'matchingdown' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_matchingdown_8TeV.root', - 'powheg' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_powhegpythia_8TeV.root', - 'powhegV2pythia' : '/storage/ec6821/NTupleProd/CMSSW_5_3_23/src/TTJets_PowhegPythia_new__8TeV.root', + 'powheg' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_8TeV_powheg_v1_pythia.root', + 'powhegV2pythia' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_8TeV_powheg_v2_pythia.root', 'powhegherwig' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_powhegherwig_8TeV.root', - # 'powhegherwig_new' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_powhegherwig_NEW_8TeV.root', - 'powhegherwig_new' : '/storage/ec6821/NTupleProd/CMSSW_5_3_23/src/TTJets_nTuple_53X_mc.root', + 'powhegherwig_new' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_powhegherwig_NEW_8TeV.root', 'mcatnlo' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_mcatnlo_8TeV.root', 'massdown' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_mass_169_5_8TeV.root', 'massup' : '/hdfs/TopQuarkGroup/mc/8TeV/v11/NoSkimUnfolding/BLT/unfolding_TTJets_mass_173_5_8TeV.root', From 2f113eb800d6c465e7cf4c8d063e8092d8c75615 Mon Sep 17 00:00:00 2001 From: jjacob Date: Sun, 27 Dec 2015 11:48:55 +0000 Subject: [PATCH 20/29] Changing default centre of mass energy to 8TeV in src/unfolding_tests/create_toy_mc.py --- src/unfolding_tests/create_toy_mc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/unfolding_tests/create_toy_mc.py b/src/unfolding_tests/create_toy_mc.py index f266da71..c2b81283 100644 --- a/src/unfolding_tests/create_toy_mc.py +++ b/src/unfolding_tests/create_toy_mc.py @@ -35,8 +35,8 @@ def main(): # help="set the variable to analyse (MET, HT, ST, MT, WPT)") parser.add_option("-m", "--metType", dest="metType", default='type1', help="set MET type for analysis of MET, ST or MT") - parser.add_option("-c", "--centre-of-mass-energy", dest="CoM", default=13, - help="set the centre of mass energy for analysis. Default = 13 [TeV]", type=int) + parser.add_option("-c", "--centre-of-mass-energy", dest="CoM", default=8, + help="set the centre of mass energy for analysis. Default = 8 [TeV]", type=int) parser.add_option('-V', '--verbose', dest="verbose", action="store_true", help="Print the event number, reco and gen variable value") From 28e6407f4f775604fe99c8ff72b9def4c953ee34 Mon Sep 17 00:00:00 2001 From: jjacob Date: Sun, 27 Dec 2015 12:38:28 +0000 Subject: [PATCH 21/29] Changing unfolding error flag from Hreco to error_treatment, and changed default from 2 to 3. Same as change made in master branch commit 552ec412c7584a0a5175bb32e87f781cfebe8a77. --- config/RooUnfold_template.py | 2 +- src/cross_section_measurement/02_unfold_and_measure.py | 10 +++++----- src/unfolding_tests/k_value_determination.py | 2 +- src/unfolding_tests/k_value_optimisation_plots.py | 2 +- tools/Unfolding.py | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/config/RooUnfold_template.py b/config/RooUnfold_template.py index 5ac768a8..2242ada3 100644 --- a/config/RooUnfold_template.py +++ b/config/RooUnfold_template.py @@ -15,7 +15,7 @@ SVD_k_value = 5 SVD_tau_value = -1 SVD_n_toy = 1000 -Hreco = 2 +error_treatment = 3 Bayes_n_repeat = 4 unfolded_markerStyle = 20 diff --git a/src/cross_section_measurement/02_unfold_and_measure.py b/src/cross_section_measurement/02_unfold_and_measure.py index e445752f..0aef20a7 100644 --- a/src/cross_section_measurement/02_unfold_and_measure.py +++ b/src/cross_section_measurement/02_unfold_and_measure.py @@ -27,9 +27,9 @@ def unfold_results( results, category, channel, k_value, h_truth, h_measured, h_ # turning off the unfolding errors for systematic samples if not category == 'central': - unfoldCfg.Hreco = 0 + unfoldCfg.error_treatment = 0 else: - unfoldCfg.Hreco = options.Hreco + unfoldCfg.error_treatment = options.error_treatment h_unfolded_data = unfolding.unfold( h_data ) @@ -411,8 +411,8 @@ def calculate_normalised_xsections( normalisation, category, channel, k_value = help = "Load fakes histogram and perform manual fake subtraction in TSVDUnfold" ) parser.add_option( "-u", "--unfolding_method", dest = "unfolding_method", default = 'RooUnfoldSvd', help = "Unfolding method: RooUnfoldSvd (default), TSVDUnfold, RooUnfoldTUnfold, RooUnfoldInvert, RooUnfoldBinByBin, RooUnfoldBayes" ) - parser.add_option( "-H", "--hreco", type = 'int', - dest = "Hreco", default = 2, + parser.add_option( "-e", "--error_treatment", type = 'int', + dest = "error_treatment", default = unfoldCfg.error_treatment, help = "Hreco parameter for error treatment in RooUnfold" ) parser.add_option( "-c", "--centre-of-mass-energy", dest = "CoM", default = 8, help = "set the centre of mass energy for analysis. Default = 8 [TeV]", type = int ) @@ -467,7 +467,7 @@ def calculate_normalised_xsections( normalisation, category, channel, k_value = k_value_muon_central = measurement_config.k_values_muon[variable] k_value_combined_central = measurement_config.k_values_combined[variable] load_fakes = options.load_fakes - unfoldCfg.Hreco = options.Hreco + unfoldCfg.error_treatment = options.error_treatment method = options.unfolding_method combine_before_unfolding = options.combine_before_unfolding met_type = translate_options[options.metType] diff --git a/src/unfolding_tests/k_value_determination.py b/src/unfolding_tests/k_value_determination.py index 058ab487..050048e6 100644 --- a/src/unfolding_tests/k_value_determination.py +++ b/src/unfolding_tests/k_value_determination.py @@ -48,7 +48,7 @@ def get_k_from_d_i( h_truth, h_measured, h_response, h_fakes = None, h_data = No h_fakes, method = method, k_value = k_start, - Hreco = 0, + error_treatment = 0, verbose = 1 ) unfolding.unfold( h_data ) hist_d_i = None diff --git a/src/unfolding_tests/k_value_optimisation_plots.py b/src/unfolding_tests/k_value_optimisation_plots.py index 26af8249..62b660a6 100644 --- a/src/unfolding_tests/k_value_optimisation_plots.py +++ b/src/unfolding_tests/k_value_optimisation_plots.py @@ -37,7 +37,7 @@ def draw_regularisation_histograms( h_truth, h_measured, h_response, h_fakes = N h_fakes, method = method, k_value = k_max, - Hreco = 2, + error_treatment = 3, verbose = 1 ) RMSerror, MeanResiduals, RMSresiduals, Chi2 = unfolding.test_regularisation ( h_data, k_max ) diff --git a/tools/Unfolding.py b/tools/Unfolding.py index fb4ad5c7..0b8f6cfa 100644 --- a/tools/Unfolding.py +++ b/tools/Unfolding.py @@ -27,7 +27,7 @@ def __init__( self, k_value = unfoldCfg.SVD_k_value, n_toy = unfoldCfg.SVD_n_toy, Bayes_n_repeat = unfoldCfg.Bayes_n_repeat, - Hreco = unfoldCfg.Hreco, + error_treatment = unfoldCfg.error_treatment, measured_truth_without_fakes = None, verbose = 0 ): if not method in unfoldCfg.availablemethods: @@ -46,7 +46,7 @@ def __init__( self, self.k_value = int(k_value) self.n_toy = n_toy self.Bayes_n_repeat = Bayes_n_repeat - self.Hreco = Hreco + self.error_treatment = error_treatment self.measured_truth_without_fakes = measured_truth_without_fakes def setup_unfolding ( self, data ): @@ -100,7 +100,7 @@ def setup_unfolding ( self, data ): def test_regularisation ( self, data, k_max ): self.setup_unfolding( data ) if self.method == 'RooUnfoldSvd': - findingK = RooUnfoldParms( self.unfoldObject, self.Hreco, self.truth ) + findingK = RooUnfoldParms( self.unfoldObject, self.error_treatment, self.truth ) findingK.SetMinParm( 1 ) findingK.SetMaxParm( k_max ) findingK.SetStepSizeParm( 1 ) @@ -124,7 +124,7 @@ def unfold( self, data ): else: # remove unfold reports (faster) self.unfoldObject.SetVerbose( self.verbose ) - self.unfolded_data = asrootpy( self.unfoldObject.Hreco( self.Hreco ) ) + self.unfolded_data = asrootpy( self.unfoldObject.Hreco( self.error_treatment ) ) return self.unfolded_data def closureTest( self ): From 2b601c34626343b040430723210dea5abae008ee Mon Sep 17 00:00:00 2001 From: jjacob Date: Sun, 27 Dec 2015 12:42:41 +0000 Subject: [PATCH 22/29] Changing fontsize from 40 to 42 in unfolding pull plots so that they actually appear. --- config/CMS.py | 6 +++--- src/cross_section_measurement/99_QCD_cross_checks.py | 8 ++++---- .../make_new_physics_plots_8TeV.py | 8 ++++---- src/unfolding_tests/make_unfolding_pull_plots.py | 9 ++++----- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/config/CMS.py b/config/CMS.py index 5b97410e..ed88e292 100644 --- a/config/CMS.py +++ b/config/CMS.py @@ -22,7 +22,7 @@ } y_axis_title_small = { - 'fontsize':40, + 'fontsize':42, 'position' : (0, 1.), 'verticalalignment': 'bottom', 'horizontalalignment': 'right' @@ -30,14 +30,14 @@ axis_label_major = { 'which':'major', - 'labelsize':41, + 'labelsize':42, 'length':20, 'width': 1, 'pad': 12 } axis_label_minor = { 'which':'minor', - 'labelsize':41, + 'labelsize':42, 'length':10, 'width': 1, 'pad': 12 diff --git a/src/cross_section_measurement/99_QCD_cross_checks.py b/src/cross_section_measurement/99_QCD_cross_checks.py index ce69a4cc..337520b9 100644 --- a/src/cross_section_measurement/99_QCD_cross_checks.py +++ b/src/cross_section_measurement/99_QCD_cross_checks.py @@ -140,12 +140,12 @@ def do_shape_check(channel, control_region_1, control_region_2, variable, normal category = options.category met_type = translate_options[options.metType] - CMS.title['fontsize'] = 40 + CMS.title['fontsize'] = 42 CMS.x_axis_title['fontsize'] = 50 CMS.y_axis_title['fontsize'] = 50 - CMS.axis_label_major['labelsize'] = 40 - CMS.axis_label_minor['labelsize'] = 40 - CMS.legend_properties['size'] = 40 + CMS.axis_label_major['labelsize'] = 42 + CMS.axis_label_minor['labelsize'] = 42 + CMS.legend_properties['size'] = 42 histogram_files = { 'electron' : measurement_config.data_file_electron, diff --git a/src/cross_section_measurement/make_new_physics_plots_8TeV.py b/src/cross_section_measurement/make_new_physics_plots_8TeV.py index 271e727b..c32db5e0 100644 --- a/src/cross_section_measurement/make_new_physics_plots_8TeV.py +++ b/src/cross_section_measurement/make_new_physics_plots_8TeV.py @@ -69,12 +69,12 @@ def get_normalisation_error(normalisation): met_type = measurement_config.translate_options[options.metType] make_additional_QCD_plots = options.additional_QCD_plots - CMS.title['fontsize'] = 40 + CMS.title['fontsize'] = 42 CMS.x_axis_title['fontsize'] = 50 CMS.y_axis_title['fontsize'] = 50 - CMS.axis_label_major['labelsize'] = 40 - CMS.axis_label_minor['labelsize'] = 40 - CMS.legend_properties['size'] = 40 + CMS.axis_label_major['labelsize'] = 42 + CMS.axis_label_minor['labelsize'] = 42 + CMS.legend_properties['size'] = 42 from config.latex_labels import b_tag_bins_latex, samples_latex diff --git a/src/unfolding_tests/make_unfolding_pull_plots.py b/src/unfolding_tests/make_unfolding_pull_plots.py index 6157ea67..d182819a 100644 --- a/src/unfolding_tests/make_unfolding_pull_plots.py +++ b/src/unfolding_tests/make_unfolding_pull_plots.py @@ -151,7 +151,6 @@ def get_k_value(k_value, config, channel, variable): if k_values.has_key(variable): k_value = k_values[variable] - def get_tau_value(tau_value, config, channel, variable): if tau_value >= 0: return tau_value @@ -259,10 +258,10 @@ def plot_pull(pulls, centre_of_mass, channel, variable, k_value, tau_value, filling(pull) stats += 1 -# printstats +# print stats # h_list = hist_to_value_error_tuplelist(h_pull) -# printh_list -# printlen(hist_data), min(hist_data), max(hist_data) +# print h_list +# print len(hist_data), min(hist_data), max(hist_data) fr = None if bin_index is None: fr = plot_h_pull(h_pull, centre_of_mass, channel, variable, k_value, @@ -342,7 +341,7 @@ def plot_h_pull(h_pull, centre_of_mass, channel, variable, k_value, tau_value, axes.text(0.6, 0.8, text, verticalalignment='bottom', horizontalalignment='left', transform=axes.transAxes, - color='black', fontsize=40, bbox=dict(facecolor='white', edgecolor='none', alpha=0.5)) + color='black', fontsize=42, bbox=dict(facecolor='white', edgecolor='none', alpha=0.5)) plt.tight_layout() for save in output_formats: From 16d87620ed4341241ed56c694cbaede4dd517328 Mon Sep 17 00:00:00 2001 From: jjacob Date: Sun, 27 Dec 2015 12:44:56 +0000 Subject: [PATCH 23/29] Fixes to config/__init.py and tools/hist_utilities.py so unfolding pull jobs work. --- bin/create_unfolding_pulls_on_DICE | 4 ++-- config/__init__.py | 12 ++++++++++++ tools/hist_utilities.py | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bin/create_unfolding_pulls_on_DICE b/bin/create_unfolding_pulls_on_DICE index 2f7dd824..c2d7d217 100755 --- a/bin/create_unfolding_pulls_on_DICE +++ b/bin/create_unfolding_pulls_on_DICE @@ -76,8 +76,8 @@ def main(): ) pull_jobs.append(pull_job) - # Since we are analysing 300 x 300 = 90000 samples and one 10x10 sample - # takes around 7 seconds it will take 1.75h in a single job. + # Since, in testing, one 10x10 sample took around 7 seconds + # and here we are analysing 300 x 300 = 90000 samples, it will take 1.75h in a single job. # For very fast (~1 min) processing we want at least 100 jobs. n_jobs_to_run = 100 # this is per pull_job n_jobs_to_split = 100 diff --git a/config/__init__.py b/config/__init__.py index 603a0119..64aa412e 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -363,6 +363,12 @@ def __fill_defaults_7TeV__( self ): 'WPT' : 0 } + self.tau_values_electron = { + } + + self.tau_values_muon = { + } + self.categories_and_prefixes['PU_down'] = '_PU_64600mb' self.categories_and_prefixes['PU_up'] = '_PU_71400mb' @@ -414,6 +420,12 @@ def __fill_defaults_8TeV__( self ): 'WPT' : 0 } + self.tau_values_electron = { + } + + self.tau_values_muon = { + } + self.categories_and_prefixes['PU_down'] = '_PU_65835mb' self.categories_and_prefixes['PU_up'] = '_PU_72765mb' diff --git a/tools/hist_utilities.py b/tools/hist_utilities.py index ebab3a43..fbfc171b 100644 --- a/tools/hist_utilities.py +++ b/tools/hist_utilities.py @@ -396,6 +396,12 @@ def copy_style(copy_from, copy_to): # legend copy_to.legendstyle = copy_from.legendstyle +def make_line_hist(bin_edges, y_value): + l = Hist(bin_edges, type = 'D') + for i in range(1, len(bin_edges)): + l.SetBinContent(i, y_value) + return l + if __name__ == '__main__': value_error_tuplelist = [( 0.006480446927374301, 0.0004647547547401945 ), ( 0.012830288388947605, 0.0010071677178938234 ), From c8b2b47af223ff43d8d5057d3dcbac70f24a7d09 Mon Sep 17 00:00:00 2001 From: jjacob Date: Sun, 27 Dec 2015 12:46:17 +0000 Subject: [PATCH 24/29] Updating condor/run.sh and README.md to use environment_conda.sh and setup_with_conda.sh in setup of DPS. --- README.md | 6 +++--- condor/run.sh | 4 ++-- setup_with_conda.sh | 8 -------- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 876a8568..583aef9d 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,11 @@ cd DailyPythonScripts # get submodules: git submodule init && git submodule update -# setup run: -./setup.sh +# setup environment (using virtualenv for python): +./setup_with_conda.sh # setup environment (using virtualenv for python): -source environment.sh +source environment_conda.sh # make sure matplotlib is up to date (should return 1.3.1 or above): python -c 'import matplotlib; print matplotlib.__version__' diff --git a/condor/run.sh b/condor/run.sh index 7e4a9c2b..6cb7dc72 100755 --- a/condor/run.sh +++ b/condor/run.sh @@ -1,6 +1,6 @@ #!/bin/bash cmssw_version=CMSSW_7_4_7 -git_branch=master +git_branch=run1 echo "Setting up ${cmssw_version} ..." echo "... sourcing CMS default environment from CVMFS" source /cvmfs/cms.cern.ch/cmsset_default.sh @@ -22,7 +22,7 @@ time git submodule init && git submodule update echo "... extracting ${_CONDOR_JOB_IWD}/dps.tar on top" tar -xf ${_CONDOR_JOB_IWD}/dps.tar --overwrite echo "... running setup routine" ->&2 "... running setup routine" +>&2 echo "... running setup routine" time source setup_with_conda.sh echo "... enforcing conda python environment" # this is safe, as the dangerous part is only executed on soolin diff --git a/setup_with_conda.sh b/setup_with_conda.sh index 494768d5..9a183a7a 100755 --- a/setup_with_conda.sh +++ b/setup_with_conda.sh @@ -26,14 +26,6 @@ export BOOST_INCLUDEDIR=/software/miniconda/envs/${conda_env}/include # the following should only be done on soolin # otherwise DICE jobs might interfere with each other echo "I am running on machine ${HOSTNAME}" -if [ "$HOSTNAME" = "soolin.phy.bris.ac.uk" ]; then - echo "Installing/upgrading rootpy" - pip install -U rootpy - echo "Applying local rootpy changes on top" - cp -r external/rootpy/rootpy /software/miniconda/envs/${conda_env}/lib/python2.7/site-packages/. - # and fix the permissions - chmod g+w -R /software/miniconda/envs/${conda_env}/lib/python2.7/site-packages/rootpy* -fi if [ ! -d "$base/external/lib" ]; then mkdir $base/external/lib From 6eeba2f411086fd6820c7a11ac73cf27c9ad7d90 Mon Sep 17 00:00:00 2001 From: jjacob Date: Wed, 6 Jan 2016 16:19:10 +0000 Subject: [PATCH 25/29] Updating README with instructions to include background subtraction, and measurement scripts output folders. --- README.md | 10 ++++++++++ bin/x_04_all_vars | 14 ++++++++------ bin/x_04b_all_vars | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 583aef9d..c01e3613 100644 --- a/README.md +++ b/README.md @@ -101,13 +101,23 @@ number of jobs: enter the number of merging jobs for the centre of mass energy i - ```cd``` up to the folder containing DailyPythonScripts and ```tar --exclude='external/vpython' --exclude='any other large/unnecessary folders in DailyPythonScripts' -cf dps.tar DailyPythonScripts``` (tar file should be approximately 100MB in size) - Merge the required BAT output files (e.g. SingleTop, QCD etc.) using ```condor_submit DailyPythonScripts/experimental/mergeBATOutputFilesOnDICE/submitMerge.description``` +### Prepare config files for background subtraction +```python src/cross_section_measurement/create_measurement.py -c 8``` +```python src/cross_section_measurement/create_measurement.py -c 7``` +This puts config files in config/measurements/background_subtraction/ for use by the x_0Nb_all_vars scripts. + ### Run final measurement scripts in bin/: ``` x_01_all_vars +x_01b_all_vars x_02_all_vars +x_02b_all_vars x_03_all_vars +x_03b_all_vars x_04_all_vars +x_04b_all_vars x_05_all_vars +x_05b_all_vars x_98_all_vars x_99_QCD_cross_checks x_make_binning_plots diff --git a/bin/x_04_all_vars b/bin/x_04_all_vars index facab725..7c669ac3 100755 --- a/bin/x_04_all_vars +++ b/bin/x_04_all_vars @@ -7,23 +7,25 @@ fit_var="absolute_eta,M3,angle_bl" # fit_var="M3" # fit_var="angle_bl" nice_fit_var=`echo $fit_var | sed 's/,/_/g'` -N_JOBS=5 +N_JOBS=6 echo "Using the fit variable(s): $fit_var" i=0 -for var in MET HT ST MT WPT; do +for var in MET MT; do echo "Plotting diff. x-section for distribution: $var" - nohup time python src/cross_section_measurement/04_make_plots_matplotlib.py -v $var -c 7 -p data/$nice_fit_var -o plots/fit/ &> logs/04_${var}_plot_7TeV_${nice_fit_var}.log & # -a -s <--add -a option for additional plots, -s option to include the final results from background subtraction as well as from fitting - let i+=1 + nohup time python src/cross_section_measurement/04_make_plots_matplotlib.py -v $var -c 7 -p data/$nice_fit_var -o plots/results/fit/ &> logs/04_${var}_plot_7TeV_${nice_fit_var}.log & # -a -s <--add -a option for additional plots, -s option to include the final results from background subtraction as well as from fitting + nohup time python src/cross_section_measurement/04_make_plots_matplotlib.py -v $var -c 7 -p data/$nice_fit_var -o plots/results/fit/ -s &> logs/04_${var}_plot_7TeV_${nice_fit_var}_with_bkgd_sub.log & # -a -s <--add -a option for additional plots, -s option to include the final results from background subtraction as well as from fitting + let i+=2 if (( $i % N_JOBS == 0 )) then echo "Waiting on the above to finish." wait; fi - nohup time python src/cross_section_measurement/04_make_plots_matplotlib.py -v $var -c 8 -p data/$nice_fit_var -o plots/fit/ &> logs/04_${var}_plot_8TeV_${nice_fit_var}.log & # -a -s <--add -a option for additional plots, -s option to include the final results from background subtraction as well as from fitting - let i+=1 + nohup time python src/cross_section_measurement/04_make_plots_matplotlib.py -v $var -c 8 -p data/$nice_fit_var -o plots/results/fit/ &> logs/04_${var}_plot_8TeV_${nice_fit_var}.log & # -a -s <--add -a option for additional plots, -s option to include the final results from background subtraction as well as from fitting + nohup time python src/cross_section_measurement/04_make_plots_matplotlib.py -v $var -c 8 -p data/$nice_fit_var -o plots/results/fit/ -s &> logs/04_${var}_plot_8TeV_${nice_fit_var}_with_bkgd_sub.log & # -a -s <--add -a option for additional plots, -s option to include the final results from background subtraction as well as from fitting + let i+=2 if (( $i % N_JOBS == 0 )) then echo "Waiting on the above to finish." diff --git a/bin/x_04b_all_vars b/bin/x_04b_all_vars index 5e5013ca..6d14b1a7 100755 --- a/bin/x_04b_all_vars +++ b/bin/x_04b_all_vars @@ -8,7 +8,7 @@ i=0 echo "Visible phase space" for var in MET HT ST WPT MT; do echo "Plotting diff. x-section for distribution: $var" - nohup time python src/cross_section_measurement/04_make_plots_matplotlib.py -v $var -c 7 -p data/normalisation/background_subtraction/ -o plots/background_subtraction &> logs/04b_${var}_plot_7TeV.log & # -a <--add this option for additional plots + nohup time python src/cross_section_measurement/04_make_plots_matplotlib.py -v $var -c 7 -p data/normalisation/background_subtraction/ -o plots/results/background_subtraction &> logs/04b_${var}_plot_7TeV.log & # -a <--add this option for additional plots let i+=1 if (( $i % N_JOBS == 0 )) then @@ -16,7 +16,7 @@ for var in MET HT ST WPT MT; do wait; fi - nohup time python src/cross_section_measurement/04_make_plots_matplotlib.py -v $var -c 8 -p data/normalisation/background_subtraction/ -o plots/background_subtraction &> logs/04b_${var}_plot_8TeV.log & # -a <--add this option for additional plots + nohup time python src/cross_section_measurement/04_make_plots_matplotlib.py -v $var -c 8 -p data/normalisation/background_subtraction/ -o plots/results/background_subtraction &> logs/04b_${var}_plot_8TeV.log & # -a <--add this option for additional plots let i+=1 if (( $i % N_JOBS == 0 )) then From 6a0f3e0f1f272251f69b48e5151a1fe60da67284 Mon Sep 17 00:00:00 2001 From: jjacob Date: Wed, 6 Jan 2016 16:39:04 +0000 Subject: [PATCH 26/29] Adjusting legend and channel info location for lepton eta templates, removing ttbar+single_top line from tepmlate plots, setting y_limits to automatically calculated values, setting angle(b,) to $\alpha$, additional plot of muon PFRelIso with cutline at 0.3 indicating control region. --- .../make_control_plots.py | 24 ++++++++++++++--- .../make_fit_variable_plots.py | 26 ++++++++++++------- tools/plotting.py | 6 ++++- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/cross_section_measurement/make_control_plots.py b/src/cross_section_measurement/make_control_plots.py index e4a8453a..3000122e 100644 --- a/src/cross_section_measurement/make_control_plots.py +++ b/src/cross_section_measurement/make_control_plots.py @@ -103,10 +103,12 @@ def make_plot( channel, x_axis_title, y_axis_title, y_max_scale = 1.2, rebin = 1, legend_location = ( 0.98, 0.78 ), cms_logo_location = 'right', + additional_location = (), log_y = False, legend_color = False, ratio_y_limits = [0.3, 1.7], normalise = False, + draw_vertical_line = 0, ): global output_folder, measurement_config, category, normalise_to_fit global preliminary, norm_variable, sum_bins, b_tag_bin, histogram_files @@ -226,7 +228,8 @@ def make_plot( channel, x_axis_title, y_axis_title, make_data_mc_comparison_plot( histograms_to_draw, histogram_lables, histogram_colors, histogram_properties, save_folder = output_folder, - show_ratio = False, normalise = normalise, + show_ratio = False, normalise = normalise, + draw_vertical_line = draw_vertical_line, ) histogram_properties.name += '_with_ratio' loc = histogram_properties.legend_location @@ -235,6 +238,7 @@ def make_plot( channel, x_axis_title, y_axis_title, make_data_mc_comparison_plot( histograms_to_draw, histogram_lables, histogram_colors, histogram_properties, save_folder = output_folder, show_ratio = True, normalise = normalise, + draw_vertical_line = draw_vertical_line, ) if __name__ == '__main__': @@ -1200,6 +1204,20 @@ def make_plot( channel, x_axis_title, y_axis_title, cms_logo_location = 'right', log_y = True, ) + make_plot( 'muon', + x_axis_title = 'PF reliso($\mu$)', + y_axis_title = 'Events/(0.1)', + signal_region = 'TTbar_plus_X_analysis/MuPlusJets/QCD mu+jets PFRelIso ge3j/Muon/muon_pfIsolation_04_' + b_tag_bin, + use_qcd_data_region = False, + name_prefix = 'QCD_muon_pfIsolation_with_cutline_', + x_limits = [0, 3], + rebin = 10, + legend_location = ( 0.95, 0.815 ), + additional_location = (0.95, 0.90), + cms_logo_location = 'right', + log_y = True, + draw_vertical_line = 0.3, + ) ################################################### # QCD lepton |eta| ################################################### @@ -1213,7 +1231,7 @@ def make_plot( channel, x_axis_title, y_axis_title, name_prefix = 'QCD_electron_AbsEta_conversion_control_region_', x_limits = [0, 2.6], rebin = 10, - legend_location = ( 0.98, 0.78 ), + legend_location = ( 0.42, 0.78 ), cms_logo_location = 'right', ) make_plot( 'electron', @@ -1247,7 +1265,7 @@ def make_plot( channel, x_axis_title, y_axis_title, name_prefix = 'QCD_electron_AbsEta_conversion_control_region_', x_limits = [0, 2.6], rebin = 10, - legend_location = ( 0.98, 0.78 ), + legend_location = ( 0.42, 0.78 ), cms_logo_location = 'right', ) make_plot( 'electron', diff --git a/src/cross_section_measurement/make_fit_variable_plots.py b/src/cross_section_measurement/make_fit_variable_plots.py index 9f5e217c..2ad27ec6 100644 --- a/src/cross_section_measurement/make_fit_variable_plots.py +++ b/src/cross_section_measurement/make_fit_variable_plots.py @@ -28,7 +28,7 @@ fit_variable_properties = { 'M3': {'min':0, 'max':1000, 'rebin':5, 'x-title': 'M3 [GeV]', 'y-title': 'Events/25 GeV'}, 'M_bl': {'min':0, 'max':400, 'rebin':2, 'x-title': 'M(b,l) [GeV]', 'y-title': 'Events/10 GeV'}, - 'angle_bl': {'min':0, 'max':3.5, 'rebin':2, 'x-title': '\alpha', 'y-title': 'Events/(0.2)'}, + 'angle_bl': {'min':0, 'max':3.5, 'rebin':2, 'x-title': r'$\alpha$ [radians]', 'y-title': 'Events/(0.2)'}, 'electron_absolute_eta': {'min':0, 'max':2.6, 'rebin':2, 'x-title': '$\left|\eta(e)\\right|$', 'y-title': 'Events/(0.2)'}, 'muon_absolute_eta': {'min':0, 'max':2.6, 'rebin':2, 'x-title': '$\left|\eta(\mu)\\right|$', 'y-title': 'Events/(0.2)'}, } @@ -146,7 +146,7 @@ def plot_fit_variable( histograms, fit_variable, variable, bin_range, histogram_properties.y_axis_title = fit_variable_properties[fit_variable]['y-title'] histogram_properties.x_limits = [fit_variable_properties[fit_variable]['min'], fit_variable_properties[fit_variable]['max']] histogram_properties.y_max_scale = 2 - + histogram_lables = ['data', 'QCD', 'V+Jets', 'Single-Top', samples_latex['TTJet']] histogram_colors = ['black', 'yellow', 'green', 'magenta', 'red'] # qcd_from_data = histograms_['data'][qcd_fit_variable_distribution].Clone() @@ -156,14 +156,14 @@ def plot_fit_variable( histograms, fit_variable, variable, bin_range, 'SingleTop':histograms_['SingleTop'][qcd_fit_variable_distribution], 'TTJet':histograms_['TTJet'][qcd_fit_variable_distribution]} qcd_from_data = clean_control_region( histograms_for_cleaning, subtract = ['TTJet', 'V+Jets', 'SingleTop'] ) - - + + histograms_to_draw = [histograms_['data'][qcd_fit_variable_distribution], histograms_['QCD'][qcd_fit_variable_distribution], histograms_['V+Jets'][qcd_fit_variable_distribution], histograms_['SingleTop'][qcd_fit_variable_distribution], histograms_['TTJet'][qcd_fit_variable_distribution]] - + histogram_properties.title = title histogram_properties.additional_text = channel_latex[channel] + ', ' + b_tag_bins_latex[b_tag_bin_ctl] if channel == 'electron': @@ -201,12 +201,12 @@ def plot_fit_variable( histograms, fit_variable, variable, bin_range, n_qcd_fit_variable_distribution = qcd_from_data.Integral() if not n_qcd_fit_variable_distribution == 0: qcd_from_data.Scale( 1.0 / n_qcd_fit_variable_distribution * n_qcd_predicted_mc ) - + histograms_to_draw = [histograms_['data'][fit_variable_distribution], qcd_from_data, histograms_['V+Jets'][fit_variable_distribution], histograms_['SingleTop'][fit_variable_distribution], histograms_['TTJet'][fit_variable_distribution]] - + histogram_properties.additional_text = channel_latex[channel] + ', ' + b_tag_bins_latex[b_tag_bin] histogram_properties.name = variable + '_' + bin_range + '_' + fit_variable + '_' + b_tag_bin make_data_mc_comparison_plot( histograms_to_draw, @@ -225,16 +225,22 @@ def plot_fit_variable( histograms, fit_variable, variable, bin_range, histogram_properties.name = variable + '_' + bin_range + '_' + fit_variable + '_' + b_tag_bin + '_templates' histogram_properties.y_max_scale = 2 # change histogram order for better visibility - histograms_to_draw = [histograms_['TTJet'][fit_variable_distribution] + histograms_['SingleTop'][fit_variable_distribution], + histograms_to_draw = [#histograms_['TTJet'][fit_variable_distribution] + histograms_['SingleTop'][fit_variable_distribution], histograms_['TTJet'][fit_variable_distribution], histograms_['SingleTop'][fit_variable_distribution], histograms_['V+Jets'][fit_variable_distribution], qcd_from_data] - histogram_lables = ['QCD', 'V+Jets', 'Single-Top', samples_latex['TTJet'], samples_latex['TTJet'] + ' + ' + 'Single-Top'] + histogram_lables = ['QCD', 'V+Jets', 'Single-Top', samples_latex['TTJet']] #, samples_latex['TTJet'] + ' + ' + 'Single-Top'] histogram_lables.reverse() # change QCD color to orange for better visibility - histogram_colors = ['orange', 'green', 'magenta', 'red', 'black'] + histogram_colors = ['orange', 'green', 'magenta', 'red'] #, 'black'] histogram_colors.reverse() + #move legend for lepton eta template plots + if fit_variable == 'electron_absolute_eta' or fit_variable == 'muon_absolute_eta': + histogram_properties.legend_location = (0.45, 0.33) + histogram_properties.additional_location = (0.42, 0.29) + else: + histogram_properties.legend_location = (0.97, 0.80) # plot template make_shape_comparison_plot( shapes = histograms_to_draw, names = histogram_lables, diff --git a/tools/plotting.py b/tools/plotting.py index ed4ba60d..be4cc058 100644 --- a/tools/plotting.py +++ b/tools/plotting.py @@ -38,6 +38,7 @@ class Histogram_properties: ratio_y_limits = [0.7, 1.3] #[min, max] rebin = 1 additional_text = '' + additional_location = () preliminary = False cms_logo_location = 'left' # left|right ratio_y_title = 'I am the ratio' @@ -274,6 +275,7 @@ def make_data_mc_comparison_plot( histograms = [], else: y_max = get_best_max_y(histograms_, x_limits=x_limits) * histogram_properties.y_max_scale axes.set_ylim( ymin = 0, ymax = y_max ) + y_limits = [0, y_max] if histogram_properties.set_log_y: if not len( y_limits ) == 2: # if not user set y-limits, set default axes.set_ylim( ymin = 1e-1 ) @@ -677,6 +679,8 @@ def set_labels( plt, histogram_properties, show_x_label = True, logo_location = (0.95, 0.98) prelim_location = (0.95, 0.92) additional_location = (0.95, 0.86) + if histogram_properties.additional_location: + additional_location = histogram_properties.additional_location plt.text(logo_location[0], logo_location[1], r"\textbf{CMS}", transform=axes.transAxes, fontsize=42, @@ -688,7 +692,7 @@ def set_labels( plt, histogram_properties, show_x_label = True, # channel text axes.text(additional_location[0], additional_location[1], r"%s" %histogram_properties.additional_text, - transform=axes.transAxes, fontsize=40, verticalalignment='top', + transform=axes.transAxes, fontsize=42, verticalalignment='top', horizontalalignment='right') def adjust_axis_limits( axes, histogram_properties, histograms = [] ): From 05aeda1fae2311bd2f58749bbb0377e0e5fb3008 Mon Sep 17 00:00:00 2001 From: jjacob Date: Wed, 6 Jan 2016 16:39:28 +0000 Subject: [PATCH 27/29] Updating unfolding pull jobs README. --- src/unfolding_tests/README.md | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/unfolding_tests/README.md b/src/unfolding_tests/README.md index 4ce9bcbc..6a56343f 100644 --- a/src/unfolding_tests/README.md +++ b/src/unfolding_tests/README.md @@ -3,19 +3,19 @@ ## Creating toy MC First we need to create a set of toy MC. Run ```shell -python src/unfolding_tests/create_toy_mc.py -n 10 +python src/unfolding_tests/create_toy_mc.py -n 10 -c 8 ``` For more information about available parameters, execute ```shell python src/unfolding_tests/create_toy_mc.py -h ``` -This will create a root file in data/toy_mc named toy_mc_MET_N_from_1_to_10_8TeV.root -(generally toy_mc__N_from_1_to__TeV.root). +This will create a root file in data/toy_mc named toy_mc_N_10_from_1_to_11_8TeV.root +(generally toy_mc_N__from_1_to__TeV.root). This file can be used in the next step. ## Creating pull distributions ```shell -python src/unfolding_tests/create_unfolding_pull_data.py -f data/toy_mc/toy_mc_MET_N_10_8TeV.root -c electron -n 10 +python src/unfolding_tests/create_unfolding_pull_data.py -f data/toy_mc/toy_mc_N_10_from_1_to_11_8TeV.root -c electron -n 10 -v MET ``` which will create ``` @@ -27,14 +27,24 @@ python src/unfolding_tests/create_unfolding_pull_data.py -h ``` for usage instructions. You can also use the DICE cluster for this step (all variables for a given centre-of-mass energy): ```shell -create_unfolding_pulls_on_DICE -c 8 +create_unfolding_pulls_on_DICE -c 8 -v MET,HT,ST,WPT,MT -i data/toy_mc/toy_mc_N_300_from_1_to_301_8TeV.root ``` This script can only be executed on submission nodes (like soolin). +If you actually somehow manage to successfully run ```create_unfolding_pulls_on_DICE```, then you will first need to untar the output files: +```shell +for f in *.tar.gz; do tar zxvf "$f"; done +``` +This will put the output files in a ```TeV//_toy_mc/_toy_data/k_value_/*.txt``` +Now move the output files to /data/pull_data: +```shell +mkdir data/pull_data +mv 8TeV data/pull_data/ +``` ## Analysing pull data Making the plots: ```shell -python src/unfolding_tests/make_unfolding_pull_plots.py -s 8 -c electron data/pull_data/8TeV/MET/10_input_toy_mc/10_input_toy_data/k_value_3/*.txt +python src/unfolding_tests/make_unfolding_pull_plots.py -v MET -s 8 -c electron -k 3 data/pull_data/8TeV/MET/10_input_toy_mc/10_input_toy_data/k_value_3/*.txt ``` for more information on which plots are going to be produce please consult ```shell From 8dc26ab64d79123d5dae21ac93e615c2bd933650 Mon Sep 17 00:00:00 2001 From: jjacob Date: Tue, 12 Jan 2016 15:57:06 +0000 Subject: [PATCH 28/29] Fixes for typical systematics table. --- config/latex_labels.py | 22 +++++++++---------- .../05_make_tables.py | 10 ++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/config/latex_labels.py b/config/latex_labels.py index 63167512..42d0cdb8 100644 --- a/config/latex_labels.py +++ b/config/latex_labels.py @@ -13,21 +13,21 @@ 'MET': '\ensuremath{E_{\mathrm{T}}^{\mathrm{miss}}}', 'HT': '\ensuremath{H_{\mathrm{T}}}', 'ST': '\ensuremath{S_{\mathrm{T}}}', - 'MT': '\ensuremath{M^{\mathrm{W}}_{\mathrm{T}}}', - 'WPT': '\ensuremath{p^\mathrm{W}_{\mathrm{T}}}' + 'WPT': '\ensuremath{p^{\mathrm{W}}_{\mathrm{T}}}', + 'MT': '\ensuremath{M^{\mathrm{W}}_{\mathrm{T}}}' } ttBarLatex = '$\mathrm{t}\\bar{\mathrm{t}}$' measurements_latex = {'unfolded': 'unfolded', 'measured': 'measured', - 'MADGRAPH': 'Madgraph Pythia', + 'MADGRAPH': 'Madgraph Pythia6', 'MADGRAPH_ptreweight': 'Madgraph+$p_\mathrm{T}$ reweighting', - 'MCATNLO': 'MC@NLO Herwig', + 'MCATNLO': 'MC@NLO Herwig6', 'powheg_v1_pythia': 'Powheg (v1) Pythia6', 'powheg_v2_pythia': 'Powheg (v2) Pythia6', - 'powheg_v1_herwig': 'Powheg (v1) Herwig', - 'powheg_v2_herwig': 'Powheg (v2) Herwig++', + 'powheg_v1_herwig': 'Powheg (v1) Herwig6', + 'powheg_v2_herwig': 'Powheg (v2) Herwig6', 'matchingdown': 'Matching down', 'matchingup': 'Matching up', 'scaledown': '$Q^{2}$ down', @@ -110,17 +110,17 @@ typical_systematics_latex = {"typical_systematics_electron": "Electron trigger efficiency \& electron selection", "typical_systematics_muon": "Muon trigger efficiency \& muon selection", - "typical_systematics_btagging": "btagging", + "typical_systematics_btagging": "b-tagging", "typical_systematics_JES": "Jet Energy Scale", "typical_systematics_JER": "Jet Energy Resolution", - "typical_systematics_PU": "pileup", - "typical_systematics_hadronisation": "hadronisation", + "typical_systematics_PU": "Pileup", + "typical_systematics_hadronisation": "Hadronisation", "typical_systematics_QCD_shape": "QCD shape", "typical_systematics_PDF": "PDF uncertainties", - "typical_systematics_top_mass": "top mass", + "typical_systematics_top_mass": "Top mass", "typical_systematics_theoretical": "Theoretical systematics", 'typical_systematics_background_other': 'Background (other)', - 'typical_systematics_MET': '$E_{T}^{miss}$ uncertainties', + 'typical_systematics_MET': '$E_{\mathrm{T}}^{\mathrm{miss}}$ uncertainties', 'typical_systematics_pt_reweight': '$p_\mathrm{T}$ reweighting' } diff --git a/src/cross_section_measurement/05_make_tables.py b/src/cross_section_measurement/05_make_tables.py index d96b8bbb..3d810add 100644 --- a/src/cross_section_measurement/05_make_tables.py +++ b/src/cross_section_measurement/05_make_tables.py @@ -437,7 +437,7 @@ def print_typical_systematics_table(central_values, errors, channel, toFile = Tr if values_for_typical_systematics_table.has_key(source): values_for_typical_systematics_table[source].append(value) else: - values_for_typical_systematics_table[source] = [typical_systematics_latex[systematic_group] + ' (\%)', value] + values_for_typical_systematics_table[source] = [typical_systematics_latex[systematic_group], value] rows_for_typical_systematics_table = {} @@ -491,11 +491,11 @@ def print_typical_systematics_table(central_values, errors, channel, toFile = Tr printout += '\\begin{table}[htbp]\n' printout += '\\centering\n' printout += '\\caption{Typical systematic uncertainties in percent (median values) for the normalised \\ttbar\n' - printout += '\\differential cross section measurement at \ensuremath{\roots=%d\TeV} ' + printout += 'differential cross section measurement at \ensuremath{\\roots=%d\TeV}' % (measurement_config.centre_of_mass_energy) if channel == 'combined': - printout += '(combination of electron and muon channels). ' + printout += ' (combination of electron and muon channels).\n' else: - printout += '(%s channel).' % channel + printout += ' (%s channel).\n' % channel printout += 'Typical values of the total systematic uncertainty are also shown.}\n' printout += '\\label{tab:typical_systematics_%dTeV_%s}\n' % (measurement_config.centre_of_mass_energy, channel) @@ -538,7 +538,7 @@ def print_typical_systematics_table(central_values, errors, channel, toFile = Tr for line_number, line in enumerate (lines): if line.startswith("Uncertainty source"): lines[line_number] = lines[line_number].strip() + " & " + variables_latex[variable] + "\n" - elif variable == "HT" and line.startswith("$E_{T}^{miss}$ uncertainties"): + elif variable == "HT" and line.startswith("$E_{\mathrm{T}}^{\mathrm{miss}}$ uncertainties"): lines[line_number] = lines[line_number].strip() + " & - \n" else: for table_entry in enumerate(typical_systematics_latex): From 1b6f5bb78ddc89ab195545fe3887239a403fe21d Mon Sep 17 00:00:00 2001 From: jjacob Date: Tue, 12 Jan 2016 15:58:14 +0000 Subject: [PATCH 29/29] Setting normalise variable to false unless passed as an argument. --- tools/HistSet.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/HistSet.py b/tools/HistSet.py index a092c830..7d9e2db2 100644 --- a/tools/HistSet.py +++ b/tools/HistSet.py @@ -61,7 +61,9 @@ def plot( self, plot_options = {} ): if plot_options.has_key( 'normalise' ): normalise = plot_options['normalise'] - + else: + normalise = False + if plot_type == 'shape_comparison': make_shape_comparison_plot( shapes = self.histograms, names = self.labels,