Skip to content

Commit

Permalink
Merge pull request #212 from kreczko/random-things-p1
Browse files Browse the repository at this point in the history
[MRG] Random things p1
  • Loading branch information
kreczko committed May 20, 2015
2 parents 298d78e + ae8f222 commit edcb5ad
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 16 deletions.
84 changes: 84 additions & 0 deletions bin/plots2tdr
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env python
'''
plot2tdr --plots <path to DPS plots folder> --tdr <path to tdr plot folder [--noop, --type=paper|AN]
Copies plots from the DailyPythonScripts plots folder to the latex document folder
--plots DailyPythonScripts plots folder
--tdr latex document plots folder
--noop Don't do anything, just print what you will do (aka dry-run)
--type paper|AN, default is paper. Determines the set of plots to be copied
'''
from optparse import OptionParser
import shutil
from glob import glob

plot_map_common = {}

plot_map_paper = {
# <src relative to DPS plots folder> : <dst relative to TDR plots folder>,
# 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/',
# 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/',
# 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/',
# fit variables 8 TeV
'control_plots/after_fit/8TeV/*_angle_bl_2orMoreBtags_with_ratio.pdf': 'control/fit_variables/8TeV/',
'control_plots/after_fit/8TeV/*_AbsEta_2orMoreBtags_with_ratio.pdf': 'control/fit_variables/8TeV/',
'control_plots/after_fit/8TeV/*_M3_2orMoreBtags_with_ratio.pdf': 'control/fit_variables/8TeV/',
}

plot_map_AN = {}

noop = False

def main():
global noop
plot_src, tdr_dst, t = parse_options()
if t == 'paper':
plot_map_common.update(plot_map_paper)
if t == 'AN':
plot_map_common.update(plot_map_AN)

for src, dst in plot_map_common.iteritems():
full_src = plot_src + src
full_dst = tdr_dst + dst
src_files = glob(full_src)
for f in src_files:
dst_file = full_dst + f.split('/')[-1]
print 'Copying %s -> %s' % (f, dst_file)
if not noop:
shutil.copy2(f, dst_file)

def parse_options():
global noop
parser = OptionParser( __doc__ )
parser.add_option( "--plots", dest = "plot_src", default = "plots/",
help = "path to DPS plot location" )
parser.add_option( "--tdr", dest = "tdr_dst", default = "tdr/",
help = "path to tdr plot location" )
parser.add_option( "--type", dest = "type", default = "paper",
help = "paper|AN" )
parser.add_option( "--noop", dest = "noop", action = "store_true",
help = "Don't copy anything" )
( options, _ ) = parser.parse_args()
plot_src, tdr_dst = options.plot_src, options.tdr_dst
t = options.type
if not plot_src.endswith('/'):
plot_src += '/'
if not tdr_dst.endswith('/'):
tdr_dst += '/'

noop = options.noop

return plot_src, tdr_dst, t

if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class XSectionConfig():
current_analysis_path = '/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_7th_draft/'
known_centre_of_mass_energies = [7, 8]
# has to be separate as many variables depend on it
luminosities = {7:5050, 8:19584}
luminosities = {7:5050, 8:19712}
parameters = ['SingleTop_category_templates', 'SingleTop_file',
'VJets_category_templates', 'analysis_types',
'categories_and_prefixes', 'central_general_template',
Expand Down Expand Up @@ -281,7 +281,7 @@ def __fill_defaults_7TeV__( self ):
middle = self.middle
path_to_files = self.path_to_files

self.new_luminosity = self.luminosity # pb^-1
self.new_luminosity = 5050 # pb^-1
self.ttbar_xsection = 177.31 # pb from https://twiki.cern.ch/twiki/bin/view/LHCPhysics/TtbarNNLO

self.data_file_electron = path_to_files + 'central/ElectronHad' + middle + '.root'
Expand Down
2 changes: 1 addition & 1 deletion config/latex_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
'absolute_eta' : r'lepton $|\eta|$',
'M3' : r'$M3$',
'M_bl' : r'$M(b,l)$',
'angle_bl' : r'angle$(b,l)$',
'angle_bl' : r'$\alpha$',
}

typical_systematics_latex = {"typical_systematics_electron": "Electron trigger efficiency \& electron selection",
Expand Down
19 changes: 10 additions & 9 deletions src/cross_section_measurement/04_make_plots_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True

axes.minorticks_on()

plt.ylabel( r'$\frac{1}{\sigma} \frac{d\sigma}{d' + variables_latex[variable] + '} \left[\mathrm{GeV}^{-1}\\right]$', CMS.y_axis_title )
plt.ylabel( r'$\frac{1}{\sigma} \frac{d\sigma}{d' + variables_latex[variable] + '}$', CMS.y_axis_title )
plt.tick_params( **CMS.axis_label_major )
plt.tick_params( **CMS.axis_label_minor )

Expand All @@ -342,7 +342,7 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True

for key, hist in sorted( histograms.iteritems() ):
if not 'unfolded' in key and not 'measured' in key:
hist.linewidth = 2
hist.linewidth = 4
# setting colours
if 'POWHEG_PYTHIA' in key or 'matchingdown' in key:
hist.linestyle = 'longdashdot'
Expand Down Expand Up @@ -415,7 +415,7 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True
plt.ylabel( '$\\frac{\\textrm{pred.}}{\\textrm{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 = 1)
plt.axhline(y = 1, color = 'black', linewidth = 2)

for key, hist in sorted( histograms.iteritems() ):
if not 'unfolded' in key and not 'measured' in key:
Expand All @@ -437,14 +437,15 @@ def make_plots( histograms, category, output_folder, histname, show_ratio = True
syst_errors = graph_to_value_errors_tuplelist(hist_data_with_systematics)
syst_lower.SetBinContent( bin_i, 1 - syst_errors[bin_i-1][1]/syst_errors[bin_i-1][0] )
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, facecolor = 'yellow', alpha = 0.5 )
rplt.fill_between( syst_lower, syst_upper, ax1,
color = 'yellow', alpha = 0.5 )

rplt.fill_between( stat_upper, stat_lower, ax1, facecolor = '0.75', alpha = 0.5 )
rplt.fill_between( stat_upper, stat_lower, ax1, color = '0.75',
alpha = 0.5 )
# legend for ratio plot
p_stat = mpatches.Patch(color='0.75', label='Stat.', alpha = 0.5 )
p_stat_and_syst = mpatches.Patch(color='yellow', label=r'Stat. $\oplus$ Syst.', alpha = 0.5 )
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})

Expand Down Expand Up @@ -498,7 +499,7 @@ def plot_central_and_systematics( channel, systematics, exclude = [], suffix = '


plt.xlabel( '$%s$ [GeV]' % variables_latex[variable], CMS.x_axis_title )
plt.ylabel( r'$\frac{1}{\sigma} \frac{d\sigma}{d' + variables_latex[variable] + '} \left[\mathrm{GeV}^{-1}\\right]$', CMS.y_axis_title )
plt.ylabel( r'$\frac{1}{\sigma} \frac{d\sigma}{d' + variables_latex[variable] + '}$', CMS.y_axis_title )
plt.tick_params( **CMS.axis_label_major )
plt.tick_params( **CMS.axis_label_minor )

Expand Down
6 changes: 3 additions & 3 deletions src/cross_section_measurement/make_control_plots.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from optparse import OptionParser
from config.latex_labels import b_tag_bins_latex, samples_latex, channel_latex, \
variables_latex
variables_latex, fit_variables_latex
from config.variable_binning import variable_bins_ROOT
from config import XSectionConfig
from tools.file_utilities import read_data_from_JSON, make_folder_if_not_exists
Expand Down Expand Up @@ -637,7 +637,7 @@ 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 = 'angle(bl)',
x_axis_title = fit_variables_latex['angle_bl'],
y_axis_title = 'Events/(0.2)',
signal_region = regions,
qcd_data_region_btag = '1btag',
Expand All @@ -651,7 +651,7 @@ def make_plot( channel, x_axis_title, y_axis_title,
tmp = 'TTbar_plus_X_analysis/MuPlusJets/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( 'muon',
x_axis_title = 'angle(bl)',
x_axis_title = fit_variables_latex['angle_bl'],
y_axis_title = 'Events/(0.2)',
signal_region = regions,
qcd_data_region_btag = '1btag',
Expand Down
2 changes: 1 addition & 1 deletion test/config_XSectionConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_invalid_centre_of_mass_energy( self ):

def test_luminosity( self ):
self.assertEqual( self.config_7TeV.luminosity, 5050 )
self.assertEqual( self.config_8TeV.luminosity, 19584 )
self.assertEqual( self.config_8TeV.luminosity, 19712 )

def test_parameters( self ):
for param in XSectionConfig.parameters:
Expand Down

0 comments on commit edcb5ad

Please sign in to comment.