diff --git a/Plotting/configs/jec_comparisons.py b/Plotting/configs/jec_comparisons.py index 40b921b..0bb6dc1 100755 --- a/Plotting/configs/jec_comparisons.py +++ b/Plotting/configs/jec_comparisons.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- import Excalibur.Plotting.utility.colors as colors -from Excalibur.Plotting.utility.toolsZJet import PlottingJob +from Excalibur.Plotting.utility.toolsZJet import PlottingJob, get_input_files import argparse import copy @@ -34,54 +34,23 @@ def get_special_parser(args): return known_args, args def response_extrapolation(args=None, additional_dictionary=None): - """Do the extrapolation plot for balance and MPF, add Ratio, display fit parameters.""" - if additional_dictionary is not None: - additional_dictionary = additional_dictionary.copy() - if 'files' in additional_dictionary and len(additional_dictionary['files']) == 2: - files = [ - additional_dictionary['files'][0], - additional_dictionary['files'][1], - additional_dictionary['files'][0], - additional_dictionary['files'][1], - additional_dictionary['files'][1], - ] - additional_dictionary.pop('files') - else: - files = None - if 'corrections' in additional_dictionary and len(additional_dictionary['corrections']) == 2: - corrections = [ - additional_dictionary['corrections'][0], - additional_dictionary['corrections'][1], - additional_dictionary['corrections'][0], - additional_dictionary['corrections'][1], - additional_dictionary['corrections'][1], - ] - additional_dictionary.pop('corrections') - else: - corrections = ['L1L2L3Res', 'L1L2L3', 'L1L2L3Res', 'L1L2L3', 'L1L2L3'] - if 'algorithms' in additional_dictionary and len(additional_dictionary['algorithms']) == 2: - algorithms = [ - additional_dictionary['algorithms'][0], - additional_dictionary['algorithms'][1], - additional_dictionary['algorithms'][0], - additional_dictionary['algorithms'][1], - additional_dictionary['algorithms'][1], - ] - additional_dictionary.pop('algorithms') - else: - algorithms = ['AK5PFJetsCHS'] - if 'labels' in additional_dictionary: - labels = additional_dictionary['labels'] - additional_dictionary.pop('labels') - elif 'nicks' in additional_dictionary: - labels = additional_dictionary['nicks'] - additional_dictionary.pop('nicks') + """Do the extrapolation plot for balance and MPF, add Ratio, display fit parameters. Requires an input tuple of data, mc.""" + additional_dictionary = additional_dictionary.copy() if additional_dictionary else {} + additional_dictionary['files'] = additional_dictionary.pop('files', get_input_files(args)[0]) + print " o>>", additional_dictionary['files'] + assert additional_dictionary['files'] >= 2, "extrapolation requires data, mc tuple as input" + # clone expansion parameters to provide additional MC quantities + for key, default in (('files', None), ('corrections', ['L1L2L3Res', 'L1L2L3', 'L1L2L3Res', 'L1L2L3', 'L1L2L3']), ('algorithms', ['AK5PFJetsCHS'])): + if key in additional_dictionary: + if len(additional_dictionary[key]) > 1: + additional_dictionary[key] = list(additional_dictionary[key][:2]) * 2 + [additional_dictionary[key][1]] + print " >>>", key, additional_dictionary[key] else: - labels = ['', ''] - else: + additional_dictionary = default + try: + labels = ["({0})".format(name) for name in additional_dictionary.pop('labels', additional_dictionary.pop('nicks'))] + except KeyError: labels = ['', ''] - if labels != ['', '']: - labels = ["({0})".format(l) for l in labels] d = { 'filename': 'extrapolation', @@ -94,8 +63,6 @@ def response_extrapolation(args=None, additional_dictionary=None): r'$\\mathit{p}_{T}$ balance', 'MPF', '', '', '', '', '', '', '', '', ''], - 'algorithms': algorithms, - 'corrections': corrections, 'zjetfolders': ['noalphacuts'], 'lines': [1.0], 'legend': 'lower left', @@ -129,12 +96,9 @@ def response_extrapolation(args=None, additional_dictionary=None): 'subplot_fraction': 40, 'subplot_legend': 'lower left', } - - if files is not None: - d['files'] = files - if additional_dictionary != None: d.update(additional_dictionary) + print d return [PlottingJob(plots=[d], args=args)] def response_bin_comparisons(args=None, additional_dictionary=None, data_quantities=True): @@ -596,10 +560,6 @@ def comparison_run2(args=None): """Comparison for run2 samples.""" plotting_jobs = [] d = { - 'files': [ - 'work/data15.root', - 'work/mc15.root', - ], 'labels': ['Data L1L2L3Res','MC L1L2L3'], 'y_subplot_label' : "Data/MC", 'algorithms': ['ak4PFJetsCHS'], diff --git a/Plotting/python/utility/toolsZJet.py b/Plotting/python/utility/toolsZJet.py index e898f8a..15dc271 100644 --- a/Plotting/python/utility/toolsZJet.py +++ b/Plotting/python/utility/toolsZJet.py @@ -62,6 +62,32 @@ def call_python_function(function_name, python_path, unknown_args=None): return log.warning("Could not execute function {}".format(function_name)) +def get_input_files(args=None): + """ + Extract the list of input files from given CLI arguments + + :param args: command line arguments + :type args: list[str] + :returns: input files and remaining CLI arguments + :rtype: list[str], list[str] + """ + if args is None: + return [], [] + args_nofiles = [] + input_files = [] + input_file_args = False + for elem in args: + if not input_file_args and elem == "-i": + input_file_args = True + continue + if input_file_args: + if not elem.startswith("-"): + input_files.append(elem) + continue + else: + input_file_args = False + args_nofiles.append(elem) + return input_files, args_nofiles def get_module_list(path): """get a list with all python modules in the path."""