Skip to content

Commit da8ba1f

Browse files
committed
Temp commit for Luke.
1 parent aba10ee commit da8ba1f

File tree

12 files changed

+617
-88
lines changed

12 files changed

+617
-88
lines changed

bin/plots2tdr

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ plot_map_common = {}
1717
plot_map_paper = {
1818
# # <src relative to DPS plots folder> : <dst relative to TDR plots folder>,
1919
# # results 8 TeV
20-
# 'background_subtraction/7TeV/MET/central/normalised_xsection_combined_*.pdf': '7TeV/MET/',
21-
# 'background_subtraction/7TeV/HT/central/normalised_xsection_combined_*.pdf': '7TeV/HT/',
22-
# 'background_subtraction/7TeV/ST/central/normalised_xsection_combined_*.pdf': '7TeV/ST/',
23-
# 'background_subtraction/7TeV/WPT/central/normalised_xsection_combined_*.pdf': '7TeV/WPT/',
20+
'background_subtraction/7TeV/MET/central/normalised_xsection_combined_*.pdf': '7TeV/MET/',
21+
'background_subtraction/7TeV/HT/central/normalised_xsection_combined_*.pdf': '7TeV/HT/',
22+
'background_subtraction/7TeV/ST/central/normalised_xsection_combined_*.pdf': '7TeV/ST/',
23+
'background_subtraction/7TeV/WPT/central/normalised_xsection_combined_*.pdf': '7TeV/WPT/',
2424
# # results 8 TeV
25-
# 'background_subtraction/8TeV/MET/central/normalised_xsection_combined_*.pdf': '8TeV/MET/',
26-
# 'background_subtraction/8TeV/HT/central/normalised_xsection_combined_*.pdf': '8TeV/HT/',
27-
# 'background_subtraction/8TeV/ST/central/normalised_xsection_combined_*.pdf': '8TeV/ST/',
28-
# 'background_subtraction/8TeV/WPT/central/normalised_xsection_combined_*.pdf': '8TeV/WPT/',
25+
'background_subtraction/8TeV/MET/central/normalised_xsection_combined_*.pdf': '8TeV/MET/',
26+
'background_subtraction/8TeV/HT/central/normalised_xsection_combined_*.pdf': '8TeV/HT/',
27+
'background_subtraction/8TeV/ST/central/normalised_xsection_combined_*.pdf': '8TeV/ST/',
28+
'background_subtraction/8TeV/WPT/central/normalised_xsection_combined_*.pdf': '8TeV/WPT/',
2929
# # control plots 8 TeV
30-
# 'control_plots/before_fit/8TeV/*_patType1CorrectedPFMet_2orMoreBtags_with_ratio.pdf': 'control/',
31-
# 'control_plots/before_fit/8TeV/*_*T_2orMoreBtags_with_ratio.pdf': 'control/',
30+
'control_plots/before_fit/8TeV/*_patType1CorrectedPFMet_2orMoreBtags_with_ratio.pdf': 'control/',
31+
'control_plots/before_fit/8TeV/*_*T_2orMoreBtags_with_ratio.pdf': 'control/',
3232

33-
'../tables/background_subtraction/*/*/*_normalised_xsection_*combined.tex': '../tables/'
33+
# '../tables/background_subtraction/*/*/*_normalised_xsection_*combined.tex': '../tables/'
3434
}
3535

3636
plot_map_AN = {}

bin/x_03b_all_vars

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ for var in MET HT ST WPT; do
1414
wait;
1515
fi
1616

17-
# nohup time python src/cross_section_measurement/03_calculate_systematics.py -s -v $var -c 8 -p data/normalisation/background_subtraction/ &> logs/03b_${var}_calculate_8TeV.log &
18-
# let i+=1
19-
# if (( $i % N_JOBS == 0 ))
20-
# then
21-
# echo "Waiting on the above to finish."
22-
# wait;
23-
# fi
17+
nohup time python src/cross_section_measurement/03_calculate_systematics.py -s -v $var -c 8 -p data/normalisation/background_subtraction/ &> logs/03b_${var}_calculate_8TeV.log &
18+
let i+=1
19+
if (( $i % N_JOBS == 0 ))
20+
then
21+
echo "Waiting on the above to finish."
22+
wait;
23+
fi
2424
done
2525

2626
wait;

config/latex_labels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
'MADGRAPH': 'Madgraph + Pythia',
3232
'MADGRAPH_ptreweight': 'Madgraph + $p_\mathrm{T}$ reweighting',
3333
'MCATNLO': 'MC@NLO + Herwig',
34-
'powheg_v1_pythia': 'Powheg v1 + Pythia6',
35-
'powheg_v2_pythia': 'Powheg v2 + Pythia6',
34+
'powheg_v1_pythia': 'Powheg v1 + Pythia',
35+
'powheg_v2_pythia': 'Powheg v2 + Pythia',
3636
'powheg_v1_herwig': 'Powheg v1 + Herwig',
3737
'powheg_v2_herwig': 'Powheg v2 + Herwig',
3838
'matchingdown': 'Matching down',

src/cross_section_measurement/02_unfold_and_measure.py

Lines changed: 84 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66
# rootpy
77
from rootpy.io import File
88
from rootpy.plotting import Hist2D
9+
from rootpy.matrix import Matrix
10+
from rootpy import asrootpy
11+
import root_numpy as rnp
12+
import numpy as np
13+
from ROOT import TH2F
914
# DailyPythonScripts
1015
import config.RooUnfold as unfoldCfg
1116
from config.variable_binning import bin_widths, bin_edges
1217
from config import XSectionConfig
1318
from tools.Calculation import calculate_xsection, calculate_normalised_xsection, \
14-
combine_complex_results
19+
combine_complex_results, calculate_covariance_for_normalised_xsection
1520
from tools.hist_utilities import hist_to_value_error_tuplelist, \
1621
value_error_tuplelist_to_hist
1722
from tools.Unfolding import Unfolding, get_unfold_histogram_tuple
@@ -32,7 +37,20 @@ def unfold_results( results, category, channel, k_value, h_truth, h_measured, h_
3237
unfoldCfg.Hreco = options.Hreco
3338

3439
h_unfolded_data = unfolding.unfold( h_data )
35-
40+
41+
# unfolding.unfoldObject.GetCov()
42+
43+
covariance_matrix = None
44+
if category == 'central':
45+
covariance_matrix = asrootpy( unfolding.unfoldObject.Ereco(options.Hreco) ).to_numpy()
46+
# print list( h_unfolded_data.y() )
47+
# unfolding.unfoldObject.ErecoV(options.Hreco).Draw()
48+
# raw_input()
49+
# cov_matrix =
50+
# cov_matrix.Draw('COLZ text')
51+
# print cov_matrix
52+
# raw_input('...')
53+
3654
if options.write_unfolding_objects:
3755
# export the D and SV distributions
3856
SVD_path = path_to_JSON + '/unfolding_objects/' + channel + '/kv_' + str( k_value ) + '/'
@@ -73,7 +91,7 @@ def unfold_results( results, category, channel, k_value, h_truth, h_measured, h_
7391
unfoldingObjectFile.Close()
7492

7593
del unfolding
76-
return hist_to_value_error_tuplelist( h_unfolded_data )
94+
return hist_to_value_error_tuplelist( h_unfolded_data ), covariance_matrix
7795

7896
def data_covariance_matrix( data ):
7997
values = list( data )
@@ -265,16 +283,16 @@ def get_unfolded_normalisation( TTJet_fit_results, category, channel, k_value ):
265283
scaledown_results = hist_to_value_error_tuplelist( h_truth_scaledown )
266284
scaleup_results = hist_to_value_error_tuplelist( h_truth_scaleup )
267285

268-
TTJet_fit_results_unfolded = unfold_results( TTJet_fit_results,
269-
category,
270-
channel,
271-
k_value,
272-
h_truth,
273-
h_measured,
274-
h_response,
275-
h_fakes,
276-
method
277-
)
286+
TTJet_fit_results_unfolded, covariance_matrix = unfold_results( TTJet_fit_results,
287+
category,
288+
channel,
289+
k_value,
290+
h_truth,
291+
h_measured,
292+
h_response,
293+
h_fakes,
294+
method
295+
)
278296

279297
normalisation_unfolded = {
280298
'TTJet_measured' : TTJet_fit_results,
@@ -295,7 +313,9 @@ def get_unfolded_normalisation( TTJet_fit_results, category, channel, k_value ):
295313
normalisation_unfolded['powheg_v1_herwig'] = powheg_v1_herwig_results
296314
normalisation_unfolded['powheg_v1_pythia'] = powheg_v1_pythia_results
297315

298-
return normalisation_unfolded
316+
return normalisation_unfolded, covariance_matrix
317+
318+
299319

300320
def calculate_xsections( normalisation, category, channel, k_value = None ):
301321
global variable, met_type, path_to_JSON
@@ -396,7 +416,7 @@ def calculate_normalised_xsections( normalisation, category, channel, k_value =
396416
write_data_to_JSON( normalised_xsection, filename )
397417

398418
if __name__ == '__main__':
399-
set_root_defaults( msg_ignore_level = 3001 )
419+
set_root_defaults( set_batch=False, msg_ignore_level = 3001 )
400420
# setup
401421
parser = OptionParser()
402422
parser.add_option( "-p", "--path", dest = "path", default = 'data/',
@@ -579,11 +599,15 @@ def calculate_normalised_xsections( normalisation, category, channel, k_value =
579599
filename = ''
580600

581601
# get unfolded normalisation
582-
unfolded_normalisation_electron = get_unfolded_normalisation( TTJet_fit_results_electron, category, 'electron', k_value_electron )
583-
unfolded_normalisation_muon = get_unfolded_normalisation( TTJet_fit_results_muon, category, 'muon', k_value_muon )
602+
unfolded_normalisation_electron, covariance_electron = get_unfolded_normalisation( TTJet_fit_results_electron, category, 'electron', k_value_electron )
603+
unfolded_normalisation_muon, covariance_muon = get_unfolded_normalisation( TTJet_fit_results_muon, category, 'muon', k_value_muon )
604+
covariance_combined = None
584605
if combine_before_unfolding:
585-
unfolded_normalisation_combined = get_unfolded_normalisation( TTJet_fit_results_combined, category, 'combined', k_value_combined )
606+
unfolded_normalisation_combined, covariance_combined = get_unfolded_normalisation( TTJet_fit_results_combined, category, 'combined', k_value_combined )
586607
else:
608+
covariance_combined = covariance_electron
609+
covariance_combined += covariance_muon
610+
# covariance_combined = asrootpy( covariance_combined )
587611
unfolded_normalisation_combined = combine_complex_results( unfolded_normalisation_electron, unfolded_normalisation_muon )
588612

589613
filename = path_to_JSON + '/xsection_measurement_results/electron/kv%d/%s/normalisation_%s.txt' % ( k_value_electron_central, category, met_type )
@@ -592,6 +616,9 @@ def calculate_normalised_xsections( normalisation, category, channel, k_value =
592616
write_data_to_JSON( unfolded_normalisation_muon, filename )
593617
filename = path_to_JSON + '/xsection_measurement_results/combined/%s/normalisation_%s.txt' % ( category, met_type )
594618
write_data_to_JSON( unfolded_normalisation_combined, filename )
619+
620+
621+
595622

596623
# if measurement_config.include_higgs:
597624
# # now the same for the Higgs
@@ -613,15 +640,44 @@ def calculate_normalised_xsections( normalisation, category, channel, k_value =
613640
# write_data_to_JSON( unfolded_normalisation_combined_higgs, filename )
614641

615642
# measure xsection
616-
calculate_xsections( unfolded_normalisation_electron, category, 'electron', k_value_electron_central )
617-
calculate_xsections( unfolded_normalisation_muon, category, 'muon', k_value_muon_central )
618-
calculate_xsections( unfolded_normalisation_combined, category, 'combined' )
643+
# calculate_xsections( unfolded_normalisation_electron, category, 'electron', k_value_electron_central )
644+
# calculate_xsections( unfolded_normalisation_muon, category, 'muon', k_value_muon_central )
645+
# calculate_xsections( unfolded_normalisation_combined, category, 'combined' )
619646

620-
calculate_normalised_xsections( unfolded_normalisation_electron, category, 'electron', k_value_electron_central )
621-
calculate_normalised_xsections( unfolded_normalisation_muon, category, 'muon', k_value_muon_central )
622-
calculate_normalised_xsections( unfolded_normalisation_combined, category, 'combined' )
647+
# calculate_normalised_xsections( unfolded_normalisation_electron, category, 'electron', k_value_electron_central )
648+
# calculate_normalised_xsections( unfolded_normalisation_muon, category, 'muon', k_value_muon_central )
649+
# calculate_normalised_xsections( unfolded_normalisation_combined, category, 'combined' )
623650

624-
normalise_to_one = True
625-
calculate_normalised_xsections( unfolded_normalisation_electron, category, 'electron', k_value_electron_central, normalise_to_one )
626-
calculate_normalised_xsections( unfolded_normalisation_muon, category, 'muon', k_value_muon_central, normalise_to_one )
627-
calculate_normalised_xsections( unfolded_normalisation_combined, category, 'combined', normalise_to_one )
651+
# normalise_to_one = True
652+
# calculate_normalised_xsections( unfolded_normalisation_electron, category, 'electron', k_value_electron_central, normalise_to_one )
653+
# calculate_normalised_xsections( unfolded_normalisation_muon, category, 'muon', k_value_muon_central, normalise_to_one )
654+
# calculate_normalised_xsections( unfolded_normalisation_combined, category, 'combined', normalise_to_one )
655+
656+
if category == 'central':
657+
normalised_xsection_covariance_electron = calculate_covariance_for_normalised_xsection( covariance_electron, unfolded_normalisation_electron['TTJet_unfolded'], bin_widths[variable] )
658+
normalised_xsection_covariance_muon = calculate_covariance_for_normalised_xsection( covariance_muon, unfolded_normalisation_muon['TTJet_unfolded'], bin_widths[variable] )
659+
normalised_xsection_covariance_combined = calculate_covariance_for_normalised_xsection( covariance_combined, unfolded_normalisation_combined['TTJet_unfolded'], bin_widths[variable] )
660+
661+
# Write covariance matrices to file
662+
filename = path_to_JSON + '/xsection_measurement_results/electron/kv%d/%s/covariance.txt' % ( k_value_electron_central, category )
663+
np.savetxt( filename, normalised_xsection_covariance_electron, delimiter = ',' )
664+
665+
# cov_file = File( filename, 'recreate' )
666+
# covariance_electron.Write()
667+
# normalised_xsection_covariance_electron.(filename,',')
668+
# cov_file.Close()
669+
670+
filename = path_to_JSON + '/xsection_measurement_results/muon/kv%d/%s/covariance.txt' % ( k_value_muon_central, category )
671+
np.savetxt( filename, normalised_xsection_covariance_muon, delimiter = ',' )
672+
673+
# cov_file = File( filename, 'recreate' )
674+
# covariance_muon.Write()
675+
# normalised_xsection_covariance_muon.Write()
676+
# cov_file.Close()
677+
678+
filename = path_to_JSON + '/xsection_measurement_results/combined/%s/covariance.txt' % ( category )
679+
np.savetxt( filename, normalised_xsection_covariance_combined, delimiter = ',' )
680+
# cov_file = File( filename, 'recreate' )
681+
# covariance_combined.Write()
682+
# normalised_xsection_covariance_combined.Write()
683+
# cov_file.Close()

src/cross_section_measurement/03_calculate_systematics.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
from config import XSectionConfig
2121
from tools.file_utilities import read_data_from_JSON, write_data_to_JSON
2222
from tools.Calculation import calculate_lower_and_upper_PDFuncertainty, \
23-
calculate_lower_and_upper_systematics, combine_errors_in_quadrature
23+
calculate_lower_and_upper_systematics, combine_errors_in_quadrature, \
24+
calculate_lower_and_upper_systematics_properly
2425

2526
def read_normalised_xsection_measurement( category, channel ):
2627
global path_to_JSON, met_type, met_uncertainties_list, k_values
@@ -108,39 +109,37 @@ def summarise_systematics( list_of_central_measurements, dictionary_of_systemati
108109
elif mass_systematic:
109110
list_of_systematics = [systematic[bin_i][0] for systematic in dictionary_of_systematics.values()]
110111
error_down, error_up = calculate_lower_and_upper_systematics( central_value, list_of_systematics, False )
111-
print (list_of_systematics)
112-
print ('Top systematic :',error_down,error_up)
113112
# Scale errors calculated using very different top masses
114113
error_down, error_up = scaleTopMassSystematicErrors( [error_down], [error_up] )
115114
error_down = error_down[0]
116115
error_up = error_up[0]
117-
print ('After scaling :',error_down,error_up)
118116
elif kValueSystematic:
119117
list_of_systematics = [systematic[bin_i][0] for systematic in dictionary_of_systematics.values()]
120118
error_down, error_up = calculate_lower_and_upper_systematics( central_value, list_of_systematics, True )
121119
else:
122120
list_of_systematics = [systematic[bin_i][0] for systematic in dictionary_of_systematics.values()]
123121
error_down, error_up = calculate_lower_and_upper_systematics( central_value, list_of_systematics, symmetrise_errors )
124122

123+
# print 'DOING A PROPER JOB'
124+
# dictionary_of_systematics_for_this_bin = { category : systematic[bin_i][0] for category, systematic in dictionary_of_systematics.iteritems()}
125+
# error_down, error_up = calculate_lower_and_upper_systematics_properly( central_value, dictionary_of_systematics_for_this_bin )
126+
125127
down_errors[bin_i] = error_down
126128
up_errors[bin_i] = error_up
129+
127130

131+
128132
return down_errors, up_errors
129133

130134
def scaleTopMassSystematicErrors( error_down, error_up ):
131135
error_down_new, error_up_new = [], []
132-
print ('Original down :',error_down)
133-
print ('Original up :',error_up)
134-
print 'Scale down :', 1 / ( measurement_config.topMasses[1] - measurement_config.topMasses[0] )
135-
print 'Scale up :', 1 / ( measurement_config.topMasses[2] - measurement_config.topMasses[1] )
136+
136137
for down,up in zip( error_down,error_up ):
137138
upMassDifference = measurement_config.topMasses[2] - measurement_config.topMasses[1]
138139
downMassDifference = measurement_config.topMasses[1] - measurement_config.topMasses[0]
139140

140141
error_down_new.append( down * measurement_config.topMassUncertainty / downMassDifference )
141142
error_up_new.append( up * measurement_config.topMassUncertainty / upMassDifference )
142-
print ('New down :',error_down_new)
143-
print ('New up :',error_up_new)
144143

145144
return error_down_new, error_up_new
146145

0 commit comments

Comments
 (0)