From 718f9f63ee976a3e8aabd25bb111bbcf6fdfb3cc Mon Sep 17 00:00:00 2001 From: jjacob Date: Fri, 28 Feb 2014 15:53:28 +0000 Subject: [PATCH 1/5] Redirecting outputs of measurement scripts to files. --- src/cross_section_measurement/AN-13-015.sh | 63 +++++++++++----------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/cross_section_measurement/AN-13-015.sh b/src/cross_section_measurement/AN-13-015.sh index 107e543d..80644d98 100755 --- a/src/cross_section_measurement/AN-13-015.sh +++ b/src/cross_section_measurement/AN-13-015.sh @@ -1,46 +1,47 @@ +mkdir logs mkdir plots mkdir plots/fitchecks -python 01_get_fit_results.py >& plots/fitchecks/correlation_MET.txt & -python 01_get_fit_results.py -v HT >& plots/fitchecks/correlation_HT.txt & -python 01_get_fit_results.py -v ST >& plots/fitchecks/correlation_ST.txt & -python 01_get_fit_results.py -v MT >& plots/fitchecks/correlation_MT.txt & -python 01_get_fit_results.py -v WPT >& plots/fitchecks/correlation_WPT.txt & +nohup python 01_get_fit_results.py >& plots/fitchecks/correlation_MET.txt & +nohup python 01_get_fit_results.py -v HT >& plots/fitchecks/correlation_HT.txt & +nohup python 01_get_fit_results.py -v ST >& plots/fitchecks/correlation_ST.txt & +nohup python 01_get_fit_results.py -v MT >& plots/fitchecks/correlation_MT.txt & +nohup python 01_get_fit_results.py -v WPT >& plots/fitchecks/correlation_WPT.txt & wait -python 02_unfold_and_measure.py & -python 02_unfold_and_measure.py -v HT & -python 02_unfold_and_measure.py -v ST & -python 02_unfold_and_measure.py -v MT & -python 02_unfold_and_measure.py -v WPT & +nohup python 02_unfold_and_measure.py >& logs/02_unfold_and_measure_MET.log & +nohup python 02_unfold_and_measure.py -v HT >& logs/02_unfold_and_measure_HT.log & +nohup python 02_unfold_and_measure.py -v ST >& logs/02_unfold_and_measure_ST.log & +nohup python 02_unfold_and_measure.py -v MT >& logs/02_unfold_and_measure_MT.log & +nohup python 02_unfold_and_measure.py -v WPT >& logs/02_unfold_and_measure_WPT.log & wait -python 03_calculate_systematics.py & -python 03_calculate_systematics.py -v HT & -python 03_calculate_systematics.py -v ST & -python 03_calculate_systematics.py -v MT & -python 03_calculate_systematics.py -v WPT & +nohup python 03_calculate_systematics.py >& logs/03_calculate_systematics_MET.log & +nohup python 03_calculate_systematics.py -v HT >& logs/03_calculate_systematics_HT.log & +nohup python 03_calculate_systematics.py -v ST >& logs/03_calculate_systematics_ST.log & +nohup python 03_calculate_systematics.py -v MT >& logs/03_calculate_systematics_MT.log & +nohup python 03_calculate_systematics.py -v WPT >& logs/03_calculate_systematics_WPT.log & wait -python 04_make_plots_matplotlib.py & -python 04_make_plots_matplotlib.py -v HT & -python 04_make_plots_matplotlib.py -v ST & -python 04_make_plots_matplotlib.py -v MT & -python 04_make_plots_matplotlib.py -v WPT & +nohup python 04_make_plots_matplotlib.py >& logs/04_make_plots_matpotlib_MET.log & +nohup python 04_make_plots_matplotlib.py -v HT >& logs/04_make_plots_matpotlib_HT.log & +nohup python 04_make_plots_matplotlib.py -v ST >& logs/04_make_plots_matpotlib_ST.log & +nohup python 04_make_plots_matplotlib.py -v MT >& logs/04_make_plots_matpotlib_MT.log & +nohup python 04_make_plots_matplotlib.py -v WPT >& logs/04_make_plots_matpotlib_WPT.log & wait -python 05_make_tables.py & -python 05_make_tables.py -v HT & -python 05_make_tables.py -v ST & -python 05_make_tables.py -v MT & -python 05_make_tables.py -v WPT & +nohup python 05_make_tables.py >& logs/05_make_tables_MET.log & +nohup python 05_make_tables.py -v HT >& logs/05_make_tables_HT.log & +nohup python 05_make_tables.py -v ST >& logs/05_make_tables_ST.log & +nohup python 05_make_tables.py -v MT >& logs/05_make_tables_MT.log & +nohup python 05_make_tables.py -v WPT >& logs/05_make_tables_WPT.log & wait -python 99_QCD_cross_checks.py & +nohup python 99_QCD_cross_checks.py >& logs/99_QCD_cross_checks.log & -python 98_fit_cross_checks.py & -python 98_fit_cross_checks.py -v HT & -python 98_fit_cross_checks.py -v ST & -python 98_fit_cross_checks.py -v MT & -python 98_fit_cross_checks.py -v WPT & +nohup python 98_fit_cross_checks.py >& logs/98_fit_cross_checks_MET.log & +nohup python 98_fit_cross_checks.py -v HT >& logs/98_fit_cross_checks_HT.log & +nohup python 98_fit_cross_checks.py -v ST >& logs/98_fit_cross_checks_ST.log & +nohup python 98_fit_cross_checks.py -v MT >& logs/98_fit_cross_checks_MT.log & +nohup python 98_fit_cross_checks.py -v WPT >& logs/98_fit_cross_checks_WPT.log & wait From 923740d997b983c7528462c565a3063ff6473450 Mon Sep 17 00:00:00 2001 From: jjacob Date: Thu, 1 May 2014 15:16:18 +0100 Subject: [PATCH 2/5] Correcting typo. --- tools/Fitting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/Fitting.py b/tools/Fitting.py index 4aefbbc9..85732458 100644 --- a/tools/Fitting.py +++ b/tools/Fitting.py @@ -33,7 +33,7 @@ def __init__(self, histograms, data_label='data'): self.vectors, self.errors = TemplateFit.vectorise(self.templates) self.param_indices = {} # check for consistency - # vectos and templates all same size!! + # vectors and templates all same size!! data_length = len(self.vectors[data_label]) error = False for sample in self.vectors.keys(): From b8daed70f505edae714d12f43b919f71474a4894 Mon Sep 17 00:00:00 2001 From: jjacob Date: Thu, 1 May 2014 15:40:13 +0100 Subject: [PATCH 3/5] Updating scripts for merging histograms files for both 7TeV and 8TeV. Fixed so that maximum 8 jobs run simultaneously. --- experimental/merge_samples_7TeV.py | 43 ++++++++++++++++++++++++++++-- experimental/merge_samples_8TeV.py | 33 +++++++++++++++++------ tools/file_utilities.py | 3 ++- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/experimental/merge_samples_7TeV.py b/experimental/merge_samples_7TeV.py index bd5e3ee9..be4bdd45 100644 --- a/experimental/merge_samples_7TeV.py +++ b/experimental/merge_samples_7TeV.py @@ -3,24 +3,63 @@ from tools.file_utilities import merge_ROOT_files import os +import subprocess +import time new_files = [] +#merge generator systematics histogram files and unfolding ntuples +for sample, input_samples in sample_summations.iteritems(): + if not sample in ['WJets', 'VJets_matchingup', 'VJets_matchingdown', 'VJets_scaleup', 'VJets_scaledown', 'unfolding_merged', 'unfolding_TTJets_7TeV_mcatnlo', 'unfolding_TTJets_7TeV_powheg', 'unfolding_TTJets_7TeV_matchingup', 'unfolding_TTJets_7TeV_matchingdown', 'unfolding_TTJets_7TeV_scaleup', 'unfolding_TTJets_7TeV_scaledown']: # No 'DYJets' because there is only one inclusive DYJets dataset + continue + print "Merging" + if 'unfolding' in sample: + output_file = measurement_config.unfolding_output_general_template % sample + input_files = [measurement_config.unfolding_input_templates[sample] % input_sample for input_sample in input_samples] + else: + output_file = measurement_config.central_general_template % sample + input_files = [measurement_config.central_general_template % input_sample for input_sample in input_samples] + + print output_file + for input_file in input_files: + print input_file + + if not os.path.exists(output_file): + merge_ROOT_files(input_files, output_file, compression = 7) + new_files.append(output_file) + print '='*120 + + #if 8 concurrent processes, wait until they are finished before starting the next set to avoid overloading the machine + number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) + while number_of_running_hadds >= 10: + time.sleep(30) #sleep for 30 seconds + number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) + + +#merge all other histogram files for category in measurement_config.categories_and_prefixes.keys(): for sample, input_samples in sample_summations.iteritems(): - if not sample in ['VJets', 'SingleTop']: + if not sample in ['VJets', 'SingleTop', 'QCD_Electron']: # No QCD_Muon because there is only one MuEnriched QCD dataset continue print "Merging" output_file = measurement_config.general_category_templates[category] % sample - print output_file input_files = [measurement_config.general_category_templates[category] % input_sample for input_sample in input_samples] + + print output_file for input_file in input_files: print input_file + if not os.path.exists(output_file): merge_ROOT_files(input_files, output_file, compression = 7) new_files.append(output_file) print '='*120 + #if 8 concurrent processes, wait until they are finished before starting the next set to avoid overloading the machine + number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) + while number_of_running_hadds >= 10: + time.sleep(30) #sleep for 30 seconds + number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) + print '='*120 print 'Created:' for f in new_files: diff --git a/experimental/merge_samples_8TeV.py b/experimental/merge_samples_8TeV.py index 062451d2..cfb58d03 100644 --- a/experimental/merge_samples_8TeV.py +++ b/experimental/merge_samples_8TeV.py @@ -3,47 +3,64 @@ from tools.file_utilities import merge_ROOT_files import os +import subprocess +import time new_files = [] #merge generator systematics histogram files and unfolding ntuples for sample, input_samples in sample_summations.iteritems(): - if not sample in ['QCD_Electron', 'WJets', 'DYJets', 'VJets_matchingup', 'VJets_matchingdown', 'VJets_scaleup', 'VJets_scaledown', 'unfolding_merged', 'unfolding_TTJets_8TeV_mcatnlo', 'unfolding_TTJets_8TeV_powheg', 'unfolding_TTJets_8TeV_matchingup', 'unfolding_TTJets_8TeV_matchingdown', 'unfolding_TTJets_8TeV_scaleup', 'unfolding_TTJets_8TeV_scaledown']: # + if not sample in ['WJets', 'DYJets', 'VJets_matchingup', 'VJets_matchingdown', 'VJets_scaleup', 'VJets_scaledown', 'unfolding_merged', 'unfolding_TTJets_8TeV_mcatnlo', 'unfolding_TTJets_8TeV_powheg', 'unfolding_TTJets_8TeV_matchingup', 'unfolding_TTJets_8TeV_matchingdown', 'unfolding_TTJets_8TeV_scaleup', 'unfolding_TTJets_8TeV_scaledown']: # continue print "Merging" if 'unfolding' in sample: -# print 'unfolding in sample' output_file = measurement_config.unfolding_output_general_template % sample - input_files = [measurement_config.unfolding_input_templates[sample] % input_sample for input_sample in input_samples] + input_files = [measurement_config.unfolding_input_templates[sample] % input_sample for input_sample in input_samples] else: #if any (generator_systematic in sample for generator_systematic in measurement_config.generator_systematics): -# print 'generator systematic in sample' - output_file = measurement_config.central_general_template % sample + output_file = measurement_config.central_general_template % sample input_files = [measurement_config.central_general_template % input_sample for input_sample in input_samples] - + print output_file for input_file in input_files: print input_file + if not os.path.exists(output_file): merge_ROOT_files(input_files, output_file, compression = 7) + print "merging ", sample new_files.append(output_file) print '='*120 + + #if 8 concurrent processes, wait until they are finished before starting the next set to avoid overloading the machine + number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) + while number_of_running_hadds >= 10: + time.sleep(30) #sleep for 30 seconds + number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) #merge all other histogram files for category in measurement_config.categories_and_prefixes.keys(): for sample, input_samples in sample_summations.iteritems(): - if not sample in ['VJets', 'QCD_Muon', 'SingleTop']: # + if not sample in ['QCD_Electron', 'QCD_Muon', 'SingleTop', 'VJets']: # continue print "Merging" output_file = measurement_config.general_category_templates[category] % sample - print output_file input_files = [measurement_config.general_category_templates[category] % input_sample for input_sample in input_samples] + + print output_file for input_file in input_files: print input_file + if not os.path.exists(output_file): merge_ROOT_files(input_files, output_file, compression = 7) + print "merging ", category, " ", sample new_files.append(output_file) print '='*120 + #if 8 concurrent processes, wait until they are finished before starting the next set to avoid overloading the machine + number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) + while number_of_running_hadds >= 10: + time.sleep(30) #sleep for 30 seconds + number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) + print '='*120 print 'Created:' for f in new_files: diff --git a/tools/file_utilities.py b/tools/file_utilities.py index 4c879eb7..308d9441 100644 --- a/tools/file_utilities.py +++ b/tools/file_utilities.py @@ -90,7 +90,8 @@ def find_duplicate_CRAB_output_files(job_files): def merge_ROOT_files(file_list, output_file, compression = 7): input_files = ' '.join(file_list) - command = 'hadd -f%d %s %s' %(compression, output_file, input_files) + output_log_file = output_file.replace(".root", ".log") + command = 'nice -n 19 hadd -f%d %s %s >& %s &' %(compression, output_file, input_files, output_log_file) subprocess.Popen(command, shell=True) def get_process_from_file(file_in_path): From b7f9d935c8431edad16f05a56945478b16f23d7e Mon Sep 17 00:00:00 2001 From: jjacob Date: Thu, 1 May 2014 15:43:55 +0100 Subject: [PATCH 4/5] Updating config files for latest 7TeV measurement with v10 nTuples. Adding Electron and Muon scale factor systematics. --- config/cross_section_measurement_7TeV.py | 27 +++++----------- config/cross_section_measurement_8TeV.py | 6 +++- config/summations_7TeV.py | 39 ++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/config/cross_section_measurement_7TeV.py b/config/cross_section_measurement_7TeV.py index 2289e803..8f0515df 100644 --- a/config/cross_section_measurement_7TeV.py +++ b/config/cross_section_measurement_7TeV.py @@ -3,7 +3,6 @@ @author: kreczko ''' - centre_of_mass = 7 # TeV ''' @@ -15,6 +14,7 @@ new_luminosity = 5050 # pb-1 luminosity_scale = float(new_luminosity)/float(luminosity) ttbar_xsection = 164 # pb + middle = '_' + str(luminosity) + 'pb_PFElectron_PFMuon_PF2PATJets_PFMET' data_file_electron = path_to_files + 'central/ElectronHad' + middle + '.root' @@ -38,20 +38,22 @@ categories_and_prefixes = { 'central':'', + 'Electron_down':'_minusElectron', + 'Electron_up':'_plusElectron', + 'Muon_down':'_minusMuon', + 'Muon_up':'_plusMuon', 'BJet_down':'_minusBJet', 'BJet_up':'_plusBjet', 'JES_down':'_minusJES', 'JES_up':'_plusJES', - #placeholders -# 'JER_down':'_minusJER', -# 'JER_up':'_plusJER', + 'JER_down':'_minusJER', + 'JER_up':'_plusJER', 'LightJet_down':'_minusLightJet', 'LightJet_up':'_plusLightJet', 'PU_down':'_PU_64600mb', 'PU_up':'_PU_71400mb' } - general_category_templates = {category: path_to_files + category + '/%s' + middle + prefix + '.root' for category, prefix in categories_and_prefixes.iteritems()} ttbar_category_templates = {category: path_to_files + category + '/TTJet' + middle + prefix + '.root' for category, prefix in categories_and_prefixes.iteritems()} SingleTop_category_templates = {category: path_to_files + category + '/SingleTop' + middle + prefix + '.root' for (category, prefix) in categories_and_prefixes.iteritems()} @@ -68,15 +70,6 @@ 'JES_down': path_to_files + 'JES_down/SingleMu' + middle + categories_and_prefixes['JES_down'] + '.root' } -# unfolding_madgraph_file = path_to_files + 'unfolding_TTJets_7TeV_madgraph.root' -# unfolding_powheg = path_to_files + 'unfolding_TTJets_7TeV_powheg.root' -# unfolding_mcatnlo = path_to_files + 'unfolding_TTJets_7TeV_pythia.root' -# -# unfolding_scale_down = path_to_files + 'unfolding_TTJets_7TeV_scaledown.root' -# unfolding_scale_up = path_to_files + 'unfolding_TTJets_7TeV_scaleup.root' -# unfolding_matching_down = path_to_files + 'unfolding_TTJets_7TeV_matchingdown.root' -# unfolding_matching_up = path_to_files + 'unfolding_TTJets_7TeV_matchingup.root' - unfolding_output_general_template = path_to_unfolding_histograms + '%s.root' unfolding_madgraph_file = path_to_unfolding_histograms + 'unfolding_merged.root' unfolding_powheg = path_to_unfolding_histograms + 'unfolding_TTJets_7TeV_powheg.root' @@ -87,12 +80,6 @@ unfolding_matching_down = path_to_unfolding_histograms + 'unfolding_TTJets_7TeV_matchingdown.root' unfolding_matching_up = path_to_unfolding_histograms + 'unfolding_TTJets_7TeV_matchingup.root' -# histogram_path_templates = { -# 'MET' : 'TTbarPlusMetAnalysis/%s/Ref selection/BinnedMETAnalysis/%s_%s_bin_%s/%s_AbsEta', -# 'HT' : 'TTbarPlusMetAnalysis/%s/Ref selection/Binned_HT_Analysis/HT_bin_%s/%s_absolute_eta', -# 'ST': 'TTbarPlusMetAnalysis/%s/Ref selection/Binned_ST_Analysis/ST_with_%s_bin_%s/%s_absolute_eta', -# 'MT': 'TTbarPlusMetAnalysis/%s/Ref selection/Binned_MT_Analysis/MT_with_%s_bin_%s/%s_absolute_eta' -# } histogram_path_templates = { 'MET' : 'TTbar_plus_X_analysis/%s/Ref selection/Binned_MET_Analysis/%s_bin_%s/%s_absolute_eta', 'HT' : 'TTbar_plus_X_analysis/%s/Ref selection/Binned_HT_Analysis/HT_bin_%s/%s_absolute_eta', diff --git a/config/cross_section_measurement_8TeV.py b/config/cross_section_measurement_8TeV.py index 0a24053b..8b27242d 100644 --- a/config/cross_section_measurement_8TeV.py +++ b/config/cross_section_measurement_8TeV.py @@ -11,7 +11,7 @@ path_to_files = '/storage/TopQuarkGroup/results/histogramfiles/AN-14-071_first_draft/8TeV/' path_to_unfolding_histograms = path_to_files + '/unfolding/' -path_to_unfolding_ntuples = '/storage/TopQuarkGroup/mc/8TeV/NoSkimUnfolding/v10/' #for merging +path_to_unfolding_ntuples = '/storage/TopQuarkGroup/mc/8TeV/NoSkimUnfolding/v10/' #for merging to create files to put in path_to_unfolding_histograms above new_luminosity = 19712 # pb-1 luminosity = 19584 # pb-1 luminosity_scale = float(new_luminosity)/float(luminosity) @@ -42,6 +42,10 @@ categories_and_prefixes = { 'central':'', + 'Electron_down':'_minusElectron', + 'Electron_up':'_plusElectron', + 'Muon_down':'_minusMuon', + 'Muon_up':'_plusMuon', 'BJet_down':'_minusBJet', 'BJet_up':'_plusBjet', 'JES_down':'_minusJES', diff --git a/config/summations_7TeV.py b/config/summations_7TeV.py index d198bec3..fdd43ace 100644 --- a/config/summations_7TeV.py +++ b/config/summations_7TeV.py @@ -26,11 +26,46 @@ diboson_samples = [ 'WWtoAnything', 'WZtoAnything', 'ZZtoAnything'] signal_samples = [ 'TTJet', 'SingleTop'] +wplusjets_matchingup_samples = [ 'WJets-matchingup' ] +dyplusjets_matchingup_samples = [ 'ZJets-matchingup' ] +vplusjets_matchingup_samples = wplusjets_matchingup_samples + dyplusjets_matchingup_samples + +wplusjets_matchingdown_samples = [ 'WJets-matchingdown' ] +dyplusjets_matchingdown_samples = [ 'ZJets-matchingdown' ] +vplusjets_matchingdown_samples = wplusjets_matchingdown_samples + dyplusjets_matchingdown_samples + +wplusjets_scaledown_samples = [ 'WJets-scaledown' ] +dyplusjets_scaledown_samples = [ 'ZJets-scaledown' ] +vplusjets_scaledown_samples = wplusjets_scaledown_samples + dyplusjets_scaledown_samples + +wplusjets_scaleup_samples = [ 'WJets-scaleup' ] +dyplusjets_scaleup_samples = [ 'ZJets-scaleup' ] +vplusjets_scaleup_samples = wplusjets_scaleup_samples + dyplusjets_scaleup_samples + +ttjets_unfolding_samples = ['TTJets'] +ttjets_mcatnlo_unfolding_samples = ['TTJets'] +ttjets_powheg_unfolding_samples = ['TTJets'] +ttjets_matchingup_unfolding_samples = ['TTJets-matchingup'] +ttjets_matchingdown_unfolding_samples = ['TTJets-matchingdown'] +ttjets_scaleup_unfolding_samples = ['TTJets-scaleup'] +ttjets_scaledown_unfolding_samples = ['TTJets-scaledown'] + sample_summations = { 'QCD_Electron':electron_qcd_samples, 'SingleTop' : singleTop_samples, 'WJets' : wplusjets_samples, 'VJets' : vplusjets_samples, - 'DiBoson': diboson_samples, - 'Signal': signal_samples +# 'DiBoson': diboson_samples, + 'Signal': signal_samples, + 'VJets_matchingup' : vplusjets_matchingup_samples, + 'VJets_matchingdown' : vplusjets_matchingdown_samples, + 'VJets_scaledown' : vplusjets_scaledown_samples, + 'VJets_scaleup' : vplusjets_scaleup_samples, + 'unfolding_merged' : ttjets_unfolding_samples, + 'unfolding_TTJets_7TeV_mcatnlo' : ttjets_mcatnlo_unfolding_samples, + 'unfolding_TTJets_7TeV_powheg' : ttjets_powheg_unfolding_samples, + 'unfolding_TTJets_7TeV_matchingup' : ttjets_matchingup_unfolding_samples, + 'unfolding_TTJets_7TeV_matchingdown' : ttjets_matchingdown_unfolding_samples, + 'unfolding_TTJets_7TeV_scaleup' : ttjets_scaleup_unfolding_samples, + 'unfolding_TTJets_7TeV_scaledown' : ttjets_scaledown_unfolding_samples, } From 49990b800eaa13a6147f9455d329481952c02c65 Mon Sep 17 00:00:00 2001 From: jjacob Date: Thu, 1 May 2014 16:10:21 +0100 Subject: [PATCH 5/5] Modifications to scripts to perform measurement on v10 7TeV 44X nTuples. In all cases, added functionality to choose centre of mass energy. Commented out ptreweighting for 7TeV, will have to add back in at a later stage. --- bin/AN-13-015.sh | 47 +++++++++++++++ config/cross_section_measurement_7TeV.py | 1 + config/cross_section_measurement_8TeV.py | 11 ---- experimental/merge_samples_7TeV.py | 24 +++----- experimental/merge_samples_8TeV.py | 54 ++++++++--------- .../01_get_fit_results.py | 1 + .../03_calculate_systematics.py | 12 ++-- .../98_fit_cross_checks.py | 26 ++++++--- .../99_QCD_cross_checks.py | 58 ++++++++++++------- src/cross_section_measurement/AN-13-015.sh | 47 --------------- 10 files changed, 142 insertions(+), 139 deletions(-) create mode 100755 bin/AN-13-015.sh delete mode 100755 src/cross_section_measurement/AN-13-015.sh diff --git a/bin/AN-13-015.sh b/bin/AN-13-015.sh new file mode 100755 index 00000000..ca452875 --- /dev/null +++ b/bin/AN-13-015.sh @@ -0,0 +1,47 @@ +mkdir logs +mkdir plots +mkdir plots/fitchecks + +nohup python src/cross_section_measurement/01_get_fit_results.py >& plots/fitchecks/correlation_MET.txt & +nohup python src/cross_section_measurement/01_get_fit_results.py -v HT >& plots/fitchecks/correlation_HT.txt & +nohup python src/cross_section_measurement/01_get_fit_results.py -v ST >& plots/fitchecks/correlation_ST.txt & +nohup python src/cross_section_measurement/01_get_fit_results.py -v MT >& plots/fitchecks/correlation_MT.txt & +nohup python src/cross_section_measurement/01_get_fit_results.py -v WPT >& plots/fitchecks/correlation_WPT.txt & +wait + +nohup python src/cross_section_measurement/02_unfold_and_measure.py >& logs/02_unfold_and_measure_MET.log & +nohup python src/cross_section_measurement/02_unfold_and_measure.py -v HT >& logs/02_unfold_and_measure_HT.log & +nohup python src/cross_section_measurement/02_unfold_and_measure.py -v ST >& logs/02_unfold_and_measure_ST.log & +nohup python src/cross_section_measurement/02_unfold_and_measure.py -v MT >& logs/02_unfold_and_measure_MT.log & +nohup python src/cross_section_measurement/02_unfold_and_measure.py -v WPT >& logs/02_unfold_and_measure_WPT.log & +wait + +nohup python src/cross_section_measurement/03_calculate_systematics.py >& logs/03_calculate_systematics_MET.log & +nohup python src/cross_section_measurement/03_calculate_systematics.py -v HT >& logs/03_calculate_systematics_HT.log & +nohup python src/cross_section_measurement/03_calculate_systematics.py -v ST >& logs/03_calculate_systematics_ST.log & +nohup python src/cross_section_measurement/03_calculate_systematics.py -v MT >& logs/03_calculate_systematics_MT.log & +nohup python src/cross_section_measurement/03_calculate_systematics.py -v WPT >& logs/03_calculate_systematics_WPT.log & +wait + +nohup python src/cross_section_measurement/04_make_plots_matplotlib.py >& logs/04_make_plots_matpotlib_MET.log & +nohup python src/cross_section_measurement/04_make_plots_matplotlib.py -v HT >& logs/04_make_plots_matpotlib_HT.log & +nohup python src/cross_section_measurement/04_make_plots_matplotlib.py -v ST >& logs/04_make_plots_matpotlib_ST.log & +nohup python src/cross_section_measurement/04_make_plots_matplotlib.py -v MT >& logs/04_make_plots_matpotlib_MT.log & +nohup python src/cross_section_measurement/04_make_plots_matplotlib.py -v WPT >& logs/04_make_plots_matpotlib_WPT.log & +wait + +nohup python src/cross_section_measurement/05_make_tables.py >& logs/05_make_tables_MET.log & +nohup python src/cross_section_measurement/05_make_tables.py -v HT >& logs/05_make_tables_HT.log & +nohup python src/cross_section_measurement/05_make_tables.py -v ST >& logs/05_make_tables_ST.log & +nohup python src/cross_section_measurement/05_make_tables.py -v MT >& logs/05_make_tables_MT.log & +nohup python src/cross_section_measurement/05_make_tables.py -v WPT >& logs/05_make_tables_WPT.log & +wait + +nohup python src/cross_section_measurement/99_QCD_cross_checks.py >& logs/99_QCD_cross_checks.log & + +nohup python src/cross_section_measurement/98_fit_cross_checks.py >& logs/98_fit_cross_checks_MET.log & +nohup python src/cross_section_measurement/98_fit_cross_checks.py -v HT >& logs/98_fit_cross_checks_HT.log & +nohup python src/cross_section_measurement/98_fit_cross_checks.py -v ST >& logs/98_fit_cross_checks_ST.log & +nohup python src/cross_section_measurement/98_fit_cross_checks.py -v MT >& logs/98_fit_cross_checks_MT.log & +nohup python src/cross_section_measurement/98_fit_cross_checks.py -v WPT >& logs/98_fit_cross_checks_WPT.log & +wait diff --git a/config/cross_section_measurement_7TeV.py b/config/cross_section_measurement_7TeV.py index 8f0515df..af7fb778 100644 --- a/config/cross_section_measurement_7TeV.py +++ b/config/cross_section_measurement_7TeV.py @@ -31,6 +31,7 @@ generator_systematics = [ 'matchingup', 'matchingdown', 'scaleup', 'scaledown' ] ttbar_generator_systematics = [ 'matchingup', 'matchingdown', 'scaleup', 'scaledown', 'mcatnlo'] +central_general_template = path_to_files + 'central/%s' + middle + '.root' generator_systematic_ttbar_templates = { systematic: path_to_files + 'central/TTJets-%s_%dpb_PFElectron_PFMuon_PF2PATJets_PFMET.root' % (systematic, luminosity) for systematic in ttbar_generator_systematics} generator_systematic_vjets_templates = { systematic:path_to_files + 'central/VJets-%s_%dpb_PFElectron_PFMuon_PF2PATJets_PFMET.root' % (systematic, luminosity) for systematic in generator_systematics} diff --git a/config/cross_section_measurement_8TeV.py b/config/cross_section_measurement_8TeV.py index 8b27242d..0505d26a 100644 --- a/config/cross_section_measurement_8TeV.py +++ b/config/cross_section_measurement_8TeV.py @@ -11,7 +11,6 @@ path_to_files = '/storage/TopQuarkGroup/results/histogramfiles/AN-14-071_first_draft/8TeV/' path_to_unfolding_histograms = path_to_files + '/unfolding/' -path_to_unfolding_ntuples = '/storage/TopQuarkGroup/mc/8TeV/NoSkimUnfolding/v10/' #for merging to create files to put in path_to_unfolding_histograms above new_luminosity = 19712 # pb-1 luminosity = 19584 # pb-1 luminosity_scale = float(new_luminosity)/float(luminosity) @@ -74,16 +73,6 @@ 'JES_down': path_to_files + 'JES_down/SingleMu' + middle + categories_and_prefixes['JES_down'] + '.root' } -unfolding_input_templates = {'unfolding_merged': path_to_unfolding_ntuples + 'TTJets_MassiveBinDECAY_TuneZ2star_8TeV-madgraph-tauola/unfolding_v10_Summer12_DR53X-PU_S10_START53_V7C-v1_NoSkim/%s*.root', - 'unfolding_TTJets_8TeV_mcatnlo': path_to_unfolding_ntuples + 'TT_8TeV-mcatnlo/unfolding_v10_Summer12_DR53X-PU_S10_START53_V7A-v1_NoSkim/%s*.root', - 'unfolding_TTJets_8TeV_powheg': path_to_unfolding_ntuples + 'TT_CT10_TuneZ2star_8TeV-powheg-tauola/unfolding_v10_Summer12_DR53X-PU_S10_START53_V7A-v1_NoSkim/%s*.root', - 'unfolding_TTJets_8TeV_matchingup': path_to_unfolding_ntuples + 'TTJets_matchingup_TuneZ2star_8TeV-madgraph-tauola/unfolding_v10_Summer12_DR53X-PU_S10_START53_V7A-v1_NoSkim/%s*.root', - 'unfolding_TTJets_8TeV_matchingdown': path_to_unfolding_ntuples + 'TTJets_matchingdown_TuneZ2star_8TeV-madgraph-tauola/unfolding_v10_Summer12_DR53X-PU_S10_START53_V7A-v1_NoSkim/%s*.root', - 'unfolding_TTJets_8TeV_scaleup': path_to_unfolding_ntuples + 'TTJets_scaleup_TuneZ2star_8TeV-madgraph-tauola/unfolding_v10_Summer12_DR53X-PU_S10_START53_V7A-v1_NoSkim/%s*.root', - 'unfolding_TTJets_8TeV_scaledown': path_to_unfolding_ntuples + 'TTJets_scaledown_TuneZ2star_8TeV-madgraph-tauola/unfolding_v10_Summer12_DR53X-PU_S10_START53_V7A-v1_NoSkim/%s*.root' - } - -unfolding_output_general_template = path_to_unfolding_histograms + '%s.root' unfolding_madgraph_file = path_to_unfolding_histograms + 'unfolding_merged.root' unfolding_powheg = path_to_unfolding_histograms + 'unfolding_TTJets_8TeV_powheg.root' unfolding_mcatnlo = path_to_unfolding_histograms + 'unfolding_TTJets_8TeV_mcatnlo.root' diff --git a/experimental/merge_samples_7TeV.py b/experimental/merge_samples_7TeV.py index be4bdd45..e0632cc0 100644 --- a/experimental/merge_samples_7TeV.py +++ b/experimental/merge_samples_7TeV.py @@ -10,15 +10,11 @@ #merge generator systematics histogram files and unfolding ntuples for sample, input_samples in sample_summations.iteritems(): - if not sample in ['WJets', 'VJets_matchingup', 'VJets_matchingdown', 'VJets_scaleup', 'VJets_scaledown', 'unfolding_merged', 'unfolding_TTJets_7TeV_mcatnlo', 'unfolding_TTJets_7TeV_powheg', 'unfolding_TTJets_7TeV_matchingup', 'unfolding_TTJets_7TeV_matchingdown', 'unfolding_TTJets_7TeV_scaleup', 'unfolding_TTJets_7TeV_scaledown']: # No 'DYJets' because there is only one inclusive DYJets dataset + if not sample in ['WJets', 'VJets_matchingup', 'VJets_matchingdown', 'VJets_scaleup', 'VJets_scaledown']: # No 'DYJets' because there is only one inclusive DYJets dataset continue print "Merging" - if 'unfolding' in sample: - output_file = measurement_config.unfolding_output_general_template % sample - input_files = [measurement_config.unfolding_input_templates[sample] % input_sample for input_sample in input_samples] - else: - output_file = measurement_config.central_general_template % sample - input_files = [measurement_config.central_general_template % input_sample for input_sample in input_samples] + output_file = measurement_config.central_general_template % sample + input_files = [measurement_config.central_general_template % input_sample for input_sample in input_samples] print output_file for input_file in input_files: @@ -29,11 +25,9 @@ new_files.append(output_file) print '='*120 - #if 8 concurrent processes, wait until they are finished before starting the next set to avoid overloading the machine - number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) - while number_of_running_hadds >= 10: - time.sleep(30) #sleep for 30 seconds - number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) + # if 8 concurrent processes, wait until they are finished before starting the next set to avoid overloading the machine + while ( int( subprocess.check_output( "ps ax | grep 'hadd' | wc -l", shell = True ) ) - 2 ) >= 8: + time.sleep( 30 ) # sleep for 30 seconds #merge all other histogram files @@ -55,10 +49,8 @@ print '='*120 #if 8 concurrent processes, wait until they are finished before starting the next set to avoid overloading the machine - number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) - while number_of_running_hadds >= 10: - time.sleep(30) #sleep for 30 seconds - number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) + while ( int( subprocess.check_output( "ps ax | grep 'hadd' | wc -l", shell = True ) ) - 2 ) >= 8: + time.sleep( 30 ) # sleep for 30 seconds print '='*120 print 'Created:' diff --git a/experimental/merge_samples_8TeV.py b/experimental/merge_samples_8TeV.py index cfb58d03..951145db 100644 --- a/experimental/merge_samples_8TeV.py +++ b/experimental/merge_samples_8TeV.py @@ -8,38 +8,34 @@ new_files = [] -#merge generator systematics histogram files and unfolding ntuples +# merge generator systematics histogram files and unfolding ntuples for sample, input_samples in sample_summations.iteritems(): - if not sample in ['WJets', 'DYJets', 'VJets_matchingup', 'VJets_matchingdown', 'VJets_scaleup', 'VJets_scaledown', 'unfolding_merged', 'unfolding_TTJets_8TeV_mcatnlo', 'unfolding_TTJets_8TeV_powheg', 'unfolding_TTJets_8TeV_matchingup', 'unfolding_TTJets_8TeV_matchingdown', 'unfolding_TTJets_8TeV_scaleup', 'unfolding_TTJets_8TeV_scaledown']: # + if not sample in ['WJets', 'DYJets', 'VJets_matchingup', + 'VJets_matchingdown', 'VJets_scaleup', + 'VJets_scaledown']: # continue print "Merging" - if 'unfolding' in sample: - output_file = measurement_config.unfolding_output_general_template % sample - input_files = [measurement_config.unfolding_input_templates[sample] % input_sample for input_sample in input_samples] - else: #if any (generator_systematic in sample for generator_systematic in measurement_config.generator_systematics): - output_file = measurement_config.central_general_template % sample - input_files = [measurement_config.central_general_template % input_sample for input_sample in input_samples] - + output_file = measurement_config.central_general_template % sample + input_files = [measurement_config.central_general_template % input_sample for input_sample in input_samples] + print output_file for input_file in input_files: print input_file - if not os.path.exists(output_file): - merge_ROOT_files(input_files, output_file, compression = 7) + if not os.path.exists( output_file ): + merge_ROOT_files( input_files, output_file, compression = 7 ) print "merging ", sample - new_files.append(output_file) - print '='*120 + new_files.append( output_file ) + print '=' * 120 - #if 8 concurrent processes, wait until they are finished before starting the next set to avoid overloading the machine - number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) - while number_of_running_hadds >= 10: - time.sleep(30) #sleep for 30 seconds - number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) + # if 8 concurrent processes, wait until they are finished before starting the next set to avoid overloading the machine + while ( int( subprocess.check_output( "ps ax | grep 'hadd' | wc -l", shell = True ) ) - 2 ) >= 8: + time.sleep( 30 ) # sleep for 30 seconds -#merge all other histogram files +# merge all other histogram files for category in measurement_config.categories_and_prefixes.keys(): for sample, input_samples in sample_summations.iteritems(): - if not sample in ['QCD_Electron', 'QCD_Muon', 'SingleTop', 'VJets']: # + if not sample in ['QCD_Electron', 'QCD_Muon', 'SingleTop', 'VJets']: # continue print "Merging" output_file = measurement_config.general_category_templates[category] % sample @@ -49,19 +45,17 @@ for input_file in input_files: print input_file - if not os.path.exists(output_file): - merge_ROOT_files(input_files, output_file, compression = 7) + if not os.path.exists( output_file ): + merge_ROOT_files( input_files, output_file, compression = 7 ) print "merging ", category, " ", sample - new_files.append(output_file) - print '='*120 + new_files.append( output_file ) + print '=' * 120 - #if 8 concurrent processes, wait until they are finished before starting the next set to avoid overloading the machine - number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) - while number_of_running_hadds >= 10: - time.sleep(30) #sleep for 30 seconds - number_of_running_hadds = int(subprocess.check_output("ps ax | grep 'hadd' | wc -l", shell=True)) + # if 8 concurrent processes, wait until they are finished before starting the next set to avoid overloading the machine + while ( int( subprocess.check_output( "ps ax | grep 'hadd' | wc -l", shell = True ) ) - 2 ) >= 8: + time.sleep( 30 ) # sleep for 30 seconds -print '='*120 +print '=' * 120 print 'Created:' for f in new_files: print f diff --git a/src/cross_section_measurement/01_get_fit_results.py b/src/cross_section_measurement/01_get_fit_results.py index e2566f8e..7f25d392 100644 --- a/src/cross_section_measurement/01_get_fit_results.py +++ b/src/cross_section_measurement/01_get_fit_results.py @@ -13,6 +13,7 @@ from tools.Calculation import decombine_result, combine_complex_results from tools.Fitting import TMinuitFit, RooFitFit from tools.file_utilities import write_data_to_JSON +from tools.hist_utilities import hist_to_value_error_tuplelist def get_histograms(channel, input_files, variable, met_type, variable_bin, b_tag_bin, rebin=1): global b_tag_bin_VJets diff --git a/src/cross_section_measurement/03_calculate_systematics.py b/src/cross_section_measurement/03_calculate_systematics.py index ef20fd2a..15ef68d4 100644 --- a/src/cross_section_measurement/03_calculate_systematics.py +++ b/src/cross_section_measurement/03_calculate_systematics.py @@ -217,20 +217,20 @@ def replace_measurement_with_deviation_from_central( central_measurement, dictio other_min, other_max = summarise_systematics( central_measurement, other_systematics ) other_min_unfolded, other_max_unfolded = summarise_systematics( central_measurement_unfolded, other_systematics_unfolded ) # new ones - ptreweight_min, ptreweight_max = summarise_systematics( central_measurement, {'ptreweight':new_systematics[ttbar_theory_systematic_prefix + 'ptreweight']} ) - ptreweight_min_unfolded, ptreweight_max_unfolded = summarise_systematics( central_measurement_unfolded, {'ptreweight':new_systematics_unfolded[ttbar_theory_systematic_prefix + 'ptreweight']} ) + ptreweight_min, ptreweight_max = summarise_systematics( central_measurement, {'ptreweight':new_systematics[ttbar_theory_systematic_prefix + 'ptreweight']} ) #add back in later + ptreweight_min_unfolded, ptreweight_max_unfolded = summarise_systematics( central_measurement_unfolded, {'ptreweight':new_systematics_unfolded[ttbar_theory_systematic_prefix + 'ptreweight']} ) #add back in later mcatnlo_min, mcatnlo_max = summarise_systematics( central_measurement, {'mcatnlo_matrix':new_systematics[ttbar_theory_systematic_prefix + 'mcatnlo_matrix']} ) mcatnlo_min_unfolded, mcatnlo_max_unfolded = summarise_systematics( central_measurement_unfolded, {'mcatnlo_matrix':new_systematics_unfolded[ttbar_theory_systematic_prefix + 'mcatnlo_matrix']} ) # get the central measurement with fit, unfolding and systematic errors combined central_measurement_with_systematics = get_measurement_with_lower_and_upper_errors( central_measurement, [ttbar_theory_min, pdf_min, met_min, other_min, - ptreweight_min, mcatnlo_min], + ptreweight_min, mcatnlo_min], [ttbar_theory_max, pdf_max, met_max, other_max, ptreweight_max, mcatnlo_max] ) central_measurement_with_systematics_but_without_ttbar_theory = get_measurement_with_lower_and_upper_errors( central_measurement, [pdf_min, met_min, other_min, - ptreweight_min, mcatnlo_min], + ptreweight_min, mcatnlo_min], [pdf_max, met_max, other_max, ptreweight_max, mcatnlo_max] ) central_measurement_with_systematics_but_without_generator = get_measurement_with_lower_and_upper_errors( central_measurement, @@ -290,8 +290,8 @@ def replace_measurement_with_deviation_from_central( central_measurement, dictio other_systematics_unfolded['total_lower'], other_systematics_unfolded['total_upper'] = other_min_unfolded, other_max_unfolded new_systematics['mcatnlo_min'], new_systematics['mcatnlo_max'] = mcatnlo_min, mcatnlo_max new_systematics_unfolded['mcatnlo_min'], new_systematics_unfolded['mcatnlo_max'] = mcatnlo_min_unfolded, mcatnlo_max_unfolded - new_systematics['ptreweight_min'], new_systematics['ptreweight_max'] = ptreweight_min, ptreweight_max - new_systematics_unfolded['ptreweight_min'], new_systematics_unfolded['ptreweight_max'] = ptreweight_min_unfolded, ptreweight_max_unfolded + new_systematics['ptreweight_min'], new_systematics['ptreweight_max'] = ptreweight_min, ptreweight_max #add back in later + new_systematics_unfolded['ptreweight_min'], new_systematics_unfolded['ptreweight_max'] = ptreweight_min_unfolded, ptreweight_max_unfolded #add back in later write_normalised_xsection_measurement( ttbar_theory_systematics, ttbar_theory_systematics_unfolded, channel, summary = 'ttbar_theory' ) write_normalised_xsection_measurement( pdf_systematics, pdf_systematics_unfolded, channel, summary = 'PDF' ) diff --git a/src/cross_section_measurement/98_fit_cross_checks.py b/src/cross_section_measurement/98_fit_cross_checks.py index 96f7d90f..4a99c46f 100644 --- a/src/cross_section_measurement/98_fit_cross_checks.py +++ b/src/cross_section_measurement/98_fit_cross_checks.py @@ -1,9 +1,7 @@ from config import CMS from optparse import OptionParser -import config.cross_section_measurement_8TeV as measurement_config from config.latex_labels import b_tag_bins_latex from config.cross_section_measurement_common import translate_options -from config.variable_binning_8TeV import bin_edges, variable_bins_ROOT from tools.ROOT_utililities import get_histograms_from_files from tools.file_utilities import read_data_from_JSON from tools.plotting import Histogram_properties, make_control_region_comparison @@ -134,11 +132,27 @@ def make_correlation_plot_from_file(channel, variable, normalisation, title, x_t help="set the category to take the fit results from (default: central)") parser.add_option("-n", "--normalise_to_fit", dest="normalise_to_fit", action="store_true", help="normalise the MC to fit results") + parser.add_option("-e", "--centre-of-mass-energy", dest="CoM", default=8, type=int, + help="set the centre of mass energy for analysis. Default = 8 [TeV]") # parser.add_option("-i", "--use_inputs", dest="use_inputs", action="store_true", # help="use fit inputs instead of fit results") (options, args) = parser.parse_args() - path_to_JSON = options.path + '/' + '8TeV/' + if options.CoM == 8: + from config.variable_binning_8TeV import bin_edges, variable_bins_ROOT + import config.cross_section_measurement_8TeV as measurement_config + electron_histogram_title = 'CMS Preliminary, $\mathcal{L}$ = 19.7 fb$^{-1}$ at $\sqrt{s}$ = 8 TeV \n e+jets, $\geq$4 jets' + muon_histogram_title = 'CMS Preliminary, $\mathcal{L}$ = 19.7 fb$^{-1}$ at $\sqrt{s}$ = 8 TeV \n $\mu$+jets, $\geq$4 jets' + elif options.CoM == 7: + from config.variable_binning_7TeV import bin_edges, variable_bins_ROOT + import config.cross_section_measurement_7TeV as measurement_config + electron_histogram_title = 'CMS Preliminary, $\mathcal{L}$ = 5.0 fb$^{-1}$ at $\sqrt{s}$ = 7 TeV \n e+jets, $\geq$4 jets' + muon_histogram_title = 'CMS Preliminary, $\mathcal{L}$ = 5.0 fb$^{-1}$ at $\sqrt{s}$ = 7 TeV \n $\mu$+jets, $\geq$4 jets' + else: + import sys + sys.exit('Unknown centre of mass energy') + + path_to_JSON = options.path + '/' + str(measurement_config.centre_of_mass) + 'TeV/' output_folder = options.output_folder normalise_to_fit = options.normalise_to_fit category = options.category @@ -177,7 +191,5 @@ def make_correlation_plot_from_file(channel, variable, normalisation, title, x_t normalisations_electron, normalisations_muon = fit_results_electron, fit_results_muon #make correlation plots for electron and muon channel - histogram_title = 'CMS Preliminary, $\mathcal{L}$ = 19.7 fb$^{-1}$ at $\sqrt{s}$ = 8 TeV \n e+jets, $\geq$4 jets' - make_correlation_plot_from_file(channel='electron', variable=options.variable, normalisation=normalisations_electron, title=histogram_title, x_title='', y_title='', x_limits=[0,3], y_limits=[0,3], rebin=1, save_folder='plots/fitchecks/', save_as=['pdf', 'png']) - histogram_title = 'CMS Preliminary, $\mathcal{L}$ = 19.7 fb$^{-1}$ at $\sqrt{s}$ = 8 TeV \n $\mu$+jets, $\geq$4 jets' - make_correlation_plot_from_file(channel='muon', variable=options.variable, normalisation=normalisations_electron, title=histogram_title, x_title='', y_title='', x_limits=[0,3], y_limits=[0,3], rebin=1, save_folder='plots/fitchecks/', save_as=['pdf', 'png']) + make_correlation_plot_from_file(channel='electron', variable=options.variable, normalisation=normalisations_electron, title=electron_histogram_title, x_title='', y_title='', x_limits=[0,3], y_limits=[0,3], rebin=1, save_folder='plots/fitchecks/', save_as=['pdf', 'png']) + make_correlation_plot_from_file(channel='muon', variable=options.variable, normalisation=normalisations_electron, title=muon_histogram_title, x_title='', y_title='', x_limits=[0,3], y_limits=[0,3], rebin=1, save_folder='plots/fitchecks/', save_as=['pdf', 'png']) diff --git a/src/cross_section_measurement/99_QCD_cross_checks.py b/src/cross_section_measurement/99_QCD_cross_checks.py index ad4a2e1c..d6dfc057 100644 --- a/src/cross_section_measurement/99_QCD_cross_checks.py +++ b/src/cross_section_measurement/99_QCD_cross_checks.py @@ -1,9 +1,7 @@ from config import CMS from optparse import OptionParser -import config.cross_section_measurement_8TeV as measurement_config from config.latex_labels import b_tag_bins_latex from config.cross_section_measurement_common import translate_options -from config.variable_binning_8TeV import bin_edges, variable_bins_ROOT from tools.ROOT_utililities import get_histograms_from_files from tools.file_utilities import read_data_from_JSON from tools.plotting import Histogram_properties, make_control_region_comparison @@ -125,9 +123,25 @@ def do_shape_check(channel, control_region_1, control_region_2, variable, normal help="normalise the MC to fit results") parser.add_option("-i", "--use_inputs", dest="use_inputs", action="store_true", help="use fit inputs instead of fit results") + parser.add_option("-e", "--centre-of-mass-energy", dest="CoM", default=8, type=int, + help="set the centre of mass energy for analysis. Default = 8 [TeV]") (options, args) = parser.parse_args() - path_to_JSON = options.path + '/' + '8TeV/' + if options.CoM == 8: + from config.variable_binning_8TeV import bin_edges, variable_bins_ROOT + import config.cross_section_measurement_8TeV as measurement_config + electron_histogram_title = 'CMS Preliminary, $\mathcal{L}$ = 19.6 fb$^{-1}$ at $\sqrt{s}$ = 8 TeV \n e+jets, $\geq$4 jets' + muon_histogram_title = 'CMS Preliminary, $\mathcal{L}$ = 19.6 fb$^{-1}$ at $\sqrt{s}$ = 8 TeV \n $\mu$+jets, $\geq$4 jets' + elif options.CoM == 7: + from config.variable_binning_7TeV import bin_edges, variable_bins_ROOT + import config.cross_section_measurement_7TeV as measurement_config + electron_histogram_title = 'CMS Preliminary, $\mathcal{L}$ = 5.0 fb$^{-1}$ at $\sqrt{s}$ = 7 TeV \n e+jets, $\geq$4 jets' + muon_histogram_title = 'CMS Preliminary, $\mathcal{L}$ = 5.0 fb$^{-1}$ at $\sqrt{s}$ = 7 TeV \n $\mu$+jets, $\geq$4 jets' + else: + import sys + sys.exit('Unknown centre of mass energy') + + path_to_JSON = options.path + '/' + str(measurement_config.centre_of_mass) + 'TeV/' output_folder = options.output_folder normalise_to_fit = options.normalise_to_fit category = options.category @@ -184,7 +198,8 @@ def do_shape_check(channel, control_region_1, control_region_2, variable, normal 'WPT': get_fit_inputs('TTbar_plus_X_analysis/MuPlusJets/QCD non iso mu+jets ge3j/Binned_WPT_Analysis/WPT_with_patType1CorrectedPFMet_bin_%s/muon_absolute_eta_0btag', 'WPT', 'muon'), } normalisations_electron, normalisations_muon = inputs_electron, inputs_muon - + + # electrons histogram_title = 'CMS Preliminary, $\mathcal{L}$ = 19.6 fb$^{-1}$ at $\sqrt{s}$ = 8 TeV \n e+jets, $\geq$4 jets' b_tag_bin = '0btag' name_region_1, name_region_2, name_region_3 = 'conversions', 'non-isolated electrons', 'fit results' @@ -195,7 +210,7 @@ def do_shape_check(channel, control_region_1, control_region_2, variable, normal control_region_2='TTbar_plus_X_analysis/EPlusJets/QCD non iso e+jets/MET/patType1CorrectedPFMet/MET_' + b_tag_bin, variable='MET', normalisation=normalisations_electron, - title=histogram_title, + title=electron_histogram_title, x_title='$E_{\mathrm{T}}^{\mathrm{miss}}$ [GeV]', y_title='arbitrary units/(5 GeV)', x_limits=[0, 250], @@ -210,7 +225,7 @@ def do_shape_check(channel, control_region_1, control_region_2, variable, normal control_region_2='TTbar_plus_X_analysis/EPlusJets/QCD non iso e+jets/MET/HT_' + b_tag_bin, variable='HT', normalisation=normalisations_electron, - title=histogram_title, + title=electron_histogram_title, x_title='$H_\mathrm{T}$ [GeV]', y_title='arbitrary units/(20 GeV)', x_limits=[80, 1000], @@ -219,13 +234,13 @@ def do_shape_check(channel, control_region_1, control_region_2, variable, normal name_region_2=name_region_2, name_region_3=name_region_3, rebin=4) - + do_shape_check(channel='electron', control_region_1='TTbar_plus_X_analysis/EPlusJets/QCDConversions/MET/patType1CorrectedPFMet/ST_' + b_tag_bin, control_region_2='TTbar_plus_X_analysis/EPlusJets/QCD non iso e+jets/MET/patType1CorrectedPFMet/ST_' + b_tag_bin, variable='ST', normalisation=normalisations_electron, - title=histogram_title, + title=electron_histogram_title, x_title='$S_\mathrm{T}$ [GeV]', y_title='arbitrary units/(20 GeV)', x_limits=[106, 1000], @@ -234,13 +249,13 @@ def do_shape_check(channel, control_region_1, control_region_2, variable, normal name_region_2=name_region_2, name_region_3=name_region_3, rebin=4) - + do_shape_check(channel='electron', control_region_1='TTbar_plus_X_analysis/EPlusJets/QCDConversions/MET/patType1CorrectedPFMet/Transverse_Mass_' + b_tag_bin, control_region_2='TTbar_plus_X_analysis/EPlusJets/QCD non iso e+jets/MET/patType1CorrectedPFMet/Transverse_Mass_' + b_tag_bin, variable='MT', normalisation=normalisations_electron, - title=histogram_title, + title=electron_histogram_title, x_title='$M^\mathrm{W}_\mathrm{T}$ [GeV]', y_title='arbitrary units/(10 GeV)', x_limits=[0, 200], @@ -249,13 +264,13 @@ def do_shape_check(channel, control_region_1, control_region_2, variable, normal name_region_2=name_region_2, name_region_3=name_region_3, rebin=10) - + do_shape_check(channel='electron', control_region_1='TTbar_plus_X_analysis/EPlusJets/QCDConversions/MET/patType1CorrectedPFMet/WPT_' + b_tag_bin, control_region_2='TTbar_plus_X_analysis/EPlusJets/QCD non iso e+jets/MET/patType1CorrectedPFMet/WPT_' + b_tag_bin, variable='WPT', normalisation=normalisations_electron, - title=histogram_title, + title=electron_histogram_title, x_title='$p^\mathrm{W}_\mathrm{T}$ [GeV]', y_title='arbitrary units/(5 GeV)', x_limits=[0, 250], @@ -264,9 +279,8 @@ def do_shape_check(channel, control_region_1, control_region_2, variable, normal name_region_2=name_region_2, name_region_3=name_region_3, rebin=5) - + # muons - histogram_title = 'CMS Preliminary, $\mathcal{L}$ = 19.6 fb$^{-1}$ at $\sqrt{s}$ = 8 TeV \n $\mu$+jets, $\geq$4 jets' b_tag_bin = '0btag' name_region_1, name_region_2, name_region_3 = 'non-isolated muons', 'non-isolated muons', 'fit results' if options.use_inputs: @@ -277,7 +291,7 @@ def do_shape_check(channel, control_region_1, control_region_2, variable, normal control_region_2='TTbar_plus_X_analysis/MuPlusJets/QCD non iso mu+jets ge3j/MET/patType1CorrectedPFMet/MET_' + b_tag_bin, variable='MET', normalisation=normalisations_muon, - title=histogram_title, + title=muon_histogram_title, x_title='$E_{\mathrm{T}}^{\mathrm{miss}}$ [GeV]', y_title='arbitrary units/(5 GeV)', x_limits=[0, 250], @@ -292,7 +306,7 @@ def do_shape_check(channel, control_region_1, control_region_2, variable, normal control_region_2='TTbar_plus_X_analysis/MuPlusJets/QCD non iso mu+jets ge3j/MET/HT_' + b_tag_bin, variable='HT', normalisation=normalisations_muon, - title=histogram_title, + title=muon_histogram_title, x_title='$H_\mathrm{T}$ [GeV]', y_title='arbitrary units/(20 GeV)', x_limits=[80, 1000], @@ -301,13 +315,13 @@ def do_shape_check(channel, control_region_1, control_region_2, variable, normal name_region_2=name_region_2, name_region_3=name_region_3, rebin=4) - + do_shape_check(channel='muon', control_region_1='TTbar_plus_X_analysis/MuPlusJets/QCD non iso mu+jets ge3j/MET/patType1CorrectedPFMet/ST_' + b_tag_bin, control_region_2='TTbar_plus_X_analysis/MuPlusJets/QCD non iso mu+jets ge3j/MET/patType1CorrectedPFMet/ST_' + b_tag_bin, variable='ST', normalisation=normalisations_muon, - title=histogram_title, + title=muon_histogram_title, x_title='$S_\mathrm{T}$ [GeV]', y_title='arbitrary units/(20 GeV)', x_limits=[106, 1000], @@ -316,13 +330,13 @@ def do_shape_check(channel, control_region_1, control_region_2, variable, normal name_region_2=name_region_2, name_region_3=name_region_3, rebin=4) - + do_shape_check(channel='muon', control_region_1='TTbar_plus_X_analysis/MuPlusJets/QCD non iso mu+jets ge3j/MET/patType1CorrectedPFMet/Transverse_Mass_' + b_tag_bin, control_region_2='TTbar_plus_X_analysis/MuPlusJets/QCD non iso mu+jets ge3j/MET/patType1CorrectedPFMet/Transverse_Mass_' + b_tag_bin, variable='MT', normalisation=normalisations_muon, - title=histogram_title, + title=muon_histogram_title, x_title='$M^\mathrm{W}_\mathrm{T}$ [GeV]', y_title='arbitrary units/(10 GeV)', x_limits=[0, 200], @@ -331,13 +345,13 @@ def do_shape_check(channel, control_region_1, control_region_2, variable, normal name_region_2=name_region_2, name_region_3=name_region_3, rebin=10) - + do_shape_check(channel='muon', control_region_1='TTbar_plus_X_analysis/MuPlusJets/QCD non iso mu+jets ge3j/MET/patType1CorrectedPFMet/WPT_' + b_tag_bin, control_region_2='TTbar_plus_X_analysis/MuPlusJets/QCD non iso mu+jets ge3j/MET/patType1CorrectedPFMet/WPT_' + b_tag_bin, variable='WPT', normalisation=normalisations_muon, - title=histogram_title, + title=muon_histogram_title, x_title='$p^\mathrm{W}_\mathrm{T}$ [GeV]', y_title='arbitrary units/(5 GeV)', x_limits=[0, 250], diff --git a/src/cross_section_measurement/AN-13-015.sh b/src/cross_section_measurement/AN-13-015.sh deleted file mode 100755 index 80644d98..00000000 --- a/src/cross_section_measurement/AN-13-015.sh +++ /dev/null @@ -1,47 +0,0 @@ -mkdir logs -mkdir plots -mkdir plots/fitchecks - -nohup python 01_get_fit_results.py >& plots/fitchecks/correlation_MET.txt & -nohup python 01_get_fit_results.py -v HT >& plots/fitchecks/correlation_HT.txt & -nohup python 01_get_fit_results.py -v ST >& plots/fitchecks/correlation_ST.txt & -nohup python 01_get_fit_results.py -v MT >& plots/fitchecks/correlation_MT.txt & -nohup python 01_get_fit_results.py -v WPT >& plots/fitchecks/correlation_WPT.txt & -wait - -nohup python 02_unfold_and_measure.py >& logs/02_unfold_and_measure_MET.log & -nohup python 02_unfold_and_measure.py -v HT >& logs/02_unfold_and_measure_HT.log & -nohup python 02_unfold_and_measure.py -v ST >& logs/02_unfold_and_measure_ST.log & -nohup python 02_unfold_and_measure.py -v MT >& logs/02_unfold_and_measure_MT.log & -nohup python 02_unfold_and_measure.py -v WPT >& logs/02_unfold_and_measure_WPT.log & -wait - -nohup python 03_calculate_systematics.py >& logs/03_calculate_systematics_MET.log & -nohup python 03_calculate_systematics.py -v HT >& logs/03_calculate_systematics_HT.log & -nohup python 03_calculate_systematics.py -v ST >& logs/03_calculate_systematics_ST.log & -nohup python 03_calculate_systematics.py -v MT >& logs/03_calculate_systematics_MT.log & -nohup python 03_calculate_systematics.py -v WPT >& logs/03_calculate_systematics_WPT.log & -wait - -nohup python 04_make_plots_matplotlib.py >& logs/04_make_plots_matpotlib_MET.log & -nohup python 04_make_plots_matplotlib.py -v HT >& logs/04_make_plots_matpotlib_HT.log & -nohup python 04_make_plots_matplotlib.py -v ST >& logs/04_make_plots_matpotlib_ST.log & -nohup python 04_make_plots_matplotlib.py -v MT >& logs/04_make_plots_matpotlib_MT.log & -nohup python 04_make_plots_matplotlib.py -v WPT >& logs/04_make_plots_matpotlib_WPT.log & -wait - -nohup python 05_make_tables.py >& logs/05_make_tables_MET.log & -nohup python 05_make_tables.py -v HT >& logs/05_make_tables_HT.log & -nohup python 05_make_tables.py -v ST >& logs/05_make_tables_ST.log & -nohup python 05_make_tables.py -v MT >& logs/05_make_tables_MT.log & -nohup python 05_make_tables.py -v WPT >& logs/05_make_tables_WPT.log & -wait - -nohup python 99_QCD_cross_checks.py >& logs/99_QCD_cross_checks.log & - -nohup python 98_fit_cross_checks.py >& logs/98_fit_cross_checks_MET.log & -nohup python 98_fit_cross_checks.py -v HT >& logs/98_fit_cross_checks_HT.log & -nohup python 98_fit_cross_checks.py -v ST >& logs/98_fit_cross_checks_ST.log & -nohup python 98_fit_cross_checks.py -v MT >& logs/98_fit_cross_checks_MT.log & -nohup python 98_fit_cross_checks.py -v WPT >& logs/98_fit_cross_checks_WPT.log & -wait