Skip to content

Commit 002f487

Browse files
committed
Merge pull request #90 from senkin/ratio_plots_etc
Added the ratio plots, updated k-values, fixed some cosmetics
2 parents 339c51b + 3810a4c commit 002f487

File tree

9 files changed

+111
-40
lines changed

9 files changed

+111
-40
lines changed

bin/convert_unfolding

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
# in read speed between fine-binned and asymmetric is a factor of 200!
66
# TODO: create the combined histograms as well.
77
from src.cross_section_measurement.lib import convert_unfolding_histograms
8-
import config.cross_section_measurement_7TeV as config_7TeV
9-
import config.cross_section_measurement_8TeV as config_8TeV
8+
from config import XSectionConfig
109
from tools.Timer import Timer
1110
from multiprocessing import Pool
1211

12+
config_7TeV = XSectionConfig(7)
13+
config_8TeV = XSectionConfig(8)
14+
1315
# it takes ~ 20 min to do all files
1416
files_to_load = [config_7TeV.unfolding_madgraph_raw,
1517
config_7TeV.unfolding_matching_down_raw,

bin/x_02_all_vars

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/bash
2-
python src/cross_section_measurement/02_unfold_and_measure.py --combine-before-unfolding &> logs/MET_unfold_8TeV.log &
3-
python src/cross_section_measurement/02_unfold_and_measure.py --combine-before-unfolding -v HT &> logs/HT_unfold_8TeV.log &
4-
python src/cross_section_measurement/02_unfold_and_measure.py --combine-before-unfolding -v ST &> logs/ST_unfold_8TeV.log &
5-
python src/cross_section_measurement/02_unfold_and_measure.py --combine-before-unfolding -v MT &> logs/MT_unfold_8TeV.log &
6-
python src/cross_section_measurement/02_unfold_and_measure.py --combine-before-unfolding -v WPT &> logs/WPT_unfold_8TeV.log &
2+
python src/cross_section_measurement/02_unfold_and_measure.py &> logs/MET_unfold_8TeV.log &
3+
python src/cross_section_measurement/02_unfold_and_measure.py -v HT &> logs/HT_unfold_8TeV.log &
4+
python src/cross_section_measurement/02_unfold_and_measure.py -v ST &> logs/ST_unfold_8TeV.log &
5+
python src/cross_section_measurement/02_unfold_and_measure.py -v MT &> logs/MT_unfold_8TeV.log &
6+
python src/cross_section_measurement/02_unfold_and_measure.py -v WPT &> logs/WPT_unfold_8TeV.log &
77
# 7 TeV
8-
python src/cross_section_measurement/02_unfold_and_measure.py --combine-before-unfolding -c 7 &> logs/MET_unfold_7TeV.log &
9-
python src/cross_section_measurement/02_unfold_and_measure.py --combine-before-unfolding -c 7 -v HT &> logs/HT_unfold_7TeV.log &
10-
python src/cross_section_measurement/02_unfold_and_measure.py --combine-before-unfolding -c 7 -v ST &> logs/ST_unfold_7TeV.log &
11-
python src/cross_section_measurement/02_unfold_and_measure.py --combine-before-unfolding -c 7 -v MT &> logs/MT_unfold_7TeV.log &
12-
python src/cross_section_measurement/02_unfold_and_measure.py --combine-before-unfolding -c 7 -v WPT &> logs/WPT_unfold_7TeV.log &
8+
python src/cross_section_measurement/02_unfold_and_measure.py -c 7 &> logs/MET_unfold_7TeV.log &
9+
python src/cross_section_measurement/02_unfold_and_measure.py -c 7 -v HT &> logs/HT_unfold_7TeV.log &
10+
python src/cross_section_measurement/02_unfold_and_measure.py -c 7 -v ST &> logs/ST_unfold_7TeV.log &
11+
python src/cross_section_measurement/02_unfold_and_measure.py -c 7 -v MT &> logs/MT_unfold_7TeV.log &
12+
python src/cross_section_measurement/02_unfold_and_measure.py -c 7 -v WPT &> logs/WPT_unfold_7TeV.log &

bin/x_05_all_vars

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
2-
mkdir -p plots
32
python src/cross_section_measurement/05_make_tables.py &> logs/MET_table_8TeV.log &
43
python src/cross_section_measurement/05_make_tables.py -v HT &> logs/HT_table_8TeV.log &
54
python src/cross_section_measurement/05_make_tables.py -v ST &> logs/ST_table_8TeV.log &

config/CMS.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
'horizontalalignment': 'right'
2222
}
2323

24+
y_axis_title_small = {
25+
'fontsize':40,
26+
'position' : (0, 1.),
27+
'verticalalignment': 'bottom',
28+
'horizontalalignment': 'right'
29+
}
30+
2431
axis_label_major = {
2532
'which':'major',
2633
'labelsize':40,
@@ -36,7 +43,7 @@
3643
'pad': 12
3744
}
3845

39-
legend_properties = {'size':40}
46+
legend_properties = {'size':35}
4047

4148
figsize = (16,16)
4249
dpi = 400

config/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,18 @@ def __fill_defaults__( self ):
182182
# optimal regularisation parameters
183183
self.k_values_electron = {
184184
'MET' : 3,
185-
'HT' : 7,
186-
'ST' : 6,
185+
'HT' : 4,
186+
'ST' : 3,
187187
'MT' : 2,
188188
'WPT' : 3
189189
}
190190

191191
self.k_values_muon = {
192192
'MET' : 3,
193-
'HT' : 6,
194-
'ST' : 6,
193+
'HT' : 4,
194+
'ST' : 3,
195195
'MT' : 2,
196-
'WPT' : 6
196+
'WPT' : 3
197197
}
198198

199199
self.k_values_combined = {
@@ -242,7 +242,7 @@ def __fill_defaults_8TeV__( self ):
242242
middle = self.middle
243243
path_to_files = self.path_to_files
244244

245-
self.new_luminosity = self.luminosity # pb^-1
245+
self.new_luminosity = 19712 # pb^-1
246246
self.ttbar_xsection = 245.8 # pb
247247

248248
self.data_file_electron = path_to_files + 'central/SingleElectron' + middle + '.root'

config/latex_labels.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
measurements_latex = {'unfolded': 'unfolded',
2020
'measured': 'measured',
21-
'MADGRAPH': '$t\\bar{t}$ (MadGraph)',
22-
'MCATNLO': '$t\\bar{t}$ (MC@NLO)',
23-
'POWHEG': '$t\\bar{t}$ (POWHEG)',
21+
'MADGRAPH': '$t\\bar{t}$ (MadGraph+Pythia)',
22+
'MCATNLO': '$t\\bar{t}$ (MC@NLO+Herwig)',
23+
'POWHEG': '$t\\bar{t}$ (POWHEG+Pythia)',
2424
'matchingdown': '$t\\bar{t}$ (matching down)',
2525
'matchingup': '$t\\bar{t}$ (matching up)',
2626
'scaledown': '$t\\bar{t}$ ($Q^{2}$ down)',

src/cross_section_measurement/04_make_plots_matplotlib.py

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from config import XSectionConfig
1010
from tools.file_utilities import read_data_from_JSON, make_folder_if_not_exists
1111
from tools.hist_utilities import value_error_tuplelist_to_hist, \
12-
value_tuplelist_to_hist, value_errors_tuplelist_to_graph
12+
value_tuplelist_to_hist, value_errors_tuplelist_to_graph, graph_to_value_errors_tuplelist
1313
from math import sqrt
1414
# rootpy & matplotlib
1515
from ROOT import kRed, kGreen, kMagenta, kBlue
@@ -18,6 +18,8 @@
1818
mpl.use( 'agg' )
1919
import rootpy.plotting.root2matplotlib as rplt
2020
import matplotlib.pyplot as plt
21+
import matplotlib.gridspec as gridspec
22+
from matplotlib.ticker import MultipleLocator
2123
from config import CMS
2224
from matplotlib import rc
2325
rc( 'font', **CMS.font )
@@ -258,7 +260,7 @@ def get_cms_labels( channel ):
258260
return label
259261

260262

261-
def make_plots( histograms, category, output_folder, histname, show_before_unfolding = False ):
263+
def make_plots( histograms, category, output_folder, histname, show_ratio = True, show_before_unfolding = False ):
262264
global variable, k_values
263265

264266
channel = 'electron'
@@ -286,11 +288,16 @@ def make_plots( histograms, category, output_folder, histname, show_before_unfol
286288
hist_measured.marker = 'o'
287289
hist_measured.color = 'red'
288290

289-
plt.figure( figsize = ( 16, 16 ), dpi = 200, facecolor = 'white' )
290-
axes = plt.axes()
291+
plt.figure( figsize = CMS.figsize, dpi = CMS.dpi, facecolor = CMS.facecolor )
292+
if show_ratio:
293+
gs = gridspec.GridSpec( 2, 1, height_ratios = [5, 1] )
294+
axes = plt.subplot( gs[0] )
295+
else:
296+
axes = plt.axes()
297+
plt.xlabel( '$%s$ [GeV]' % variables_latex[variable], CMS.x_axis_title )
298+
291299
axes.minorticks_on()
292300

293-
plt.xlabel( '$%s$ [GeV]' % variables_latex[variable], CMS.x_axis_title )
294301
plt.ylabel( r'$\frac{1}{\sigma} \frac{d\sigma}{d' + variables_latex[variable] + '} \left[\mathrm{GeV}^{-1}\\right]$', CMS.y_axis_title )
295302
plt.tick_params( **CMS.axis_label_major )
296303
plt.tick_params( **CMS.axis_label_minor )
@@ -341,9 +348,64 @@ def make_plots( histograms, category, output_folder, histname, show_before_unfol
341348
new_handles.append( handle )
342349
new_labels.append( label )
343350

344-
plt.legend( new_handles, new_labels, numpoints = 1, loc = 'upper right', prop = CMS.legend_properties )
351+
legend_location = 'upper right'
352+
if variable == 'MT':
353+
legend_location = 'upper left'
354+
plt.legend( new_handles, new_labels, numpoints = 1, loc = legend_location, prop = CMS.legend_properties )
345355
plt.title( get_cms_labels( channel ), CMS.title )
346-
plt.tight_layout()
356+
357+
if show_ratio:
358+
plt.setp( axes.get_xticklabels(), visible = False )
359+
ax1 = plt.subplot( gs[1] )
360+
ax1.minorticks_on()
361+
#ax1.grid( True, 'major', linewidth = 1 )
362+
# setting the x_limits identical to the main plot
363+
x_limits = axes.get_xlim()
364+
ax1.set_xlim(x_limits)
365+
ax1.yaxis.set_major_locator( MultipleLocator( 0.5 ) )
366+
ax1.yaxis.set_minor_locator( MultipleLocator( 0.1 ) )
367+
368+
plt.xlabel( '$%s$ [GeV]' % variables_latex[variable], CMS.x_axis_title )
369+
plt.tick_params( **CMS.axis_label_major )
370+
plt.tick_params( **CMS.axis_label_minor )
371+
plt.ylabel( '$\\frac{\\textrm{theory}}{\\textrm{data}}$', CMS.y_axis_title_small )
372+
ax1.yaxis.set_label_coords(-0.115, 0.8)
373+
#draw a horizontal line at y=1 for data
374+
plt.axhline(y = 1, color = 'black', linewidth = 1)
375+
376+
for key, hist in sorted( histograms.iteritems() ):
377+
if not 'unfolded' in key and not 'measured' in key:
378+
ratio = hist.Clone()
379+
ratio.Divide( hist_data ) #divide by data
380+
rplt.hist( ratio, axes = ax1, label = 'do_not_show' )
381+
382+
stat_lower = hist_data.Clone()
383+
stat_upper = hist_data.Clone()
384+
syst_lower = hist_data.Clone()
385+
syst_upper = hist_data.Clone()
386+
387+
# plot error bands on data in the ratio plot
388+
for bin_i in range( 1, hist_data.GetNbinsX() + 1 ):
389+
stat_errors = graph_to_value_errors_tuplelist(hist_data)
390+
stat_lower.SetBinContent( bin_i, 1 - stat_errors[bin_i-1][1]/stat_errors[bin_i-1][0] )
391+
stat_upper.SetBinContent( bin_i, 1 + stat_errors[bin_i-1][2]/stat_errors[bin_i-1][0] )
392+
if category == 'central':
393+
syst_errors = graph_to_value_errors_tuplelist(hist_data_with_systematics)
394+
syst_lower.SetBinContent( bin_i, 1 - syst_errors[bin_i-1][1]/syst_errors[bin_i-1][0] )
395+
syst_upper.SetBinContent( bin_i, 1 + syst_errors[bin_i-1][2]/syst_errors[bin_i-1][0] )
396+
397+
if category == 'central':
398+
rplt.fill_between( syst_lower, syst_upper, ax1, facecolor = 'yellow', alpha = 0.5 )
399+
400+
rplt.fill_between( stat_upper, stat_lower, ax1, facecolor = '0.75', alpha = 0.5 )
401+
402+
# p1 = plt.Rectangle((0, 0), 1, 1, fc="yellow")
403+
# p2 = plt.Rectangle((0, 0), 1, 1, fc="0.75")
404+
# plt.legend([p1, p2], ['Stat. $\\oplus$ Syst.', 'Stat.'], loc = 'upper left', prop = {'size':20})
405+
ax1.set_ylim( ymin = 0.5, ymax = 1.5 )
406+
407+
if CMS.tight_layout:
408+
plt.tight_layout()
347409

348410
path = output_folder + str( measurement_config.centre_of_mass_energy ) + 'TeV/' + variable + '/' + category
349411
make_folder_if_not_exists( path )

src/unfolding_tests/compare_unfolding_parameters.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def run_test( h_truth, h_measured, h_response, h_data, h_fakes = None, variable
6868
result = calculate_normalised_xsection(
6969
hist_to_value_error_tuplelist( unfolded_data ),
7070
bin_widths[variable],
71-
normalise_to_one = True )
71+
normalise_to_one = False )
7272
h_result = value_error_tuplelist_to_hist( result, bin_edges[variable] )
7373
k_value_results[k_value] = deepcopy( h_result )
7474

@@ -87,7 +87,7 @@ def run_test( h_truth, h_measured, h_response, h_data, h_fakes = None, variable
8787
result = calculate_normalised_xsection(
8888
hist_to_value_error_tuplelist( unfolded_data ),
8989
bin_widths[variable],
90-
normalise_to_one = True )
90+
normalise_to_one = False)
9191
h_result = value_error_tuplelist_to_hist( result, bin_edges[variable] )
9292
tau_value_results[tau_value] = deepcopy( h_result )
9393

@@ -112,11 +112,11 @@ def compare( central_mc, expected_result = None, measured_result = None, results
112112
title_template = 'CMS Simulation at $\sqrt{s}$ = %d TeV \n %s'
113113
title = title_template % ( centre_of_mass, channel_label )
114114

115-
models = {'central' : central_mc}
115+
models = {latex_labels.measurements_latex['MADGRAPH'] : central_mc}
116116
if expected_result:
117-
models['expected'] = expected_result
118-
if measured_result:
119-
models['measured'] = measured_result
117+
models.update({'expected' : expected_result})
118+
if measured_result and test != 'data':
119+
models.update({'measured' : measured_result})
120120

121121
measurements = collections.OrderedDict()
122122
for key, value in results['k_value_results'].iteritems():
@@ -213,6 +213,7 @@ def compare( central_mc, expected_result = None, measured_result = None, results
213213

214214
if test == 'data':
215215
h_data = get_data_histogram( channel, variable, met_type )
216+
h_expected = deepcopy( h_data )
216217
elif test == 'bias':
217218
h_truth_bias, h_measured_bias, _, h_fakes = get_unfold_histogram_tuple(
218219
inputfile = input_file_bias,
@@ -233,19 +234,19 @@ def compare( central_mc, expected_result = None, measured_result = None, results
233234
central_mc_result = calculate_normalised_xsection(
234235
hist_to_value_error_tuplelist( h_truth ),
235236
bin_widths[variable],
236-
normalise_to_one = True )
237+
normalise_to_one = False )
237238
central_mc = value_error_tuplelist_to_hist( central_mc_result, bin_edges[variable] )
238239
if h_expected:
239240
expected_result = calculate_normalised_xsection(
240241
hist_to_value_error_tuplelist( h_expected ),
241242
bin_widths[variable],
242-
normalise_to_one = True )
243+
normalise_to_one = False )
243244
h_expected = value_error_tuplelist_to_hist( expected_result, bin_edges[variable] )
244245

245246
data_result = calculate_normalised_xsection(
246247
hist_to_value_error_tuplelist( h_data ),
247248
bin_widths[variable],
248-
normalise_to_one = True )
249+
normalise_to_one = False )
249250
h_data = value_error_tuplelist_to_hist( data_result, bin_edges[variable] )
250251

251252
compare( central_mc = central_mc, expected_result = h_expected, measured_result = h_data,

src/unfolding_tests/tau_value_determination.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def draw_l_shape( l_shape, best_tau, x_value, y_value, channel, variable ):
163163
plt.savefig( 'plots/tau_from_L_shape_%s_channel_%s_MC.png' % ( channel, variable ) )
164164

165165
def get_data_histogram( channel, variable, met_type ):
166-
fit_result_input = '../cross_section_measurement/data/8TeV/%(variable)s/fit_results/central/fit_results_%(channel)s_%(met_type)s.txt'
166+
fit_result_input = '../../data/8TeV/%(variable)s/fit_results/central/fit_results_%(channel)s_%(met_type)s.txt'
167167
fit_results = read_data_from_JSON( fit_result_input % {'channel': channel, 'variable': variable, 'met_type':met_type} )
168168
fit_data = fit_results['TTJet']
169169
h_data = value_error_tuplelist_to_hist( fit_data, bin_edges[variable] )

0 commit comments

Comments
 (0)