def make_histogram(result, bin_edges): if len(result[0]) == 2: h = value_error_tuplelist_to_hist(result, bin_edges) return h else: # len(result[0]) == 3 g = value_errors_tuplelist_to_graph(result, bin_edges) return g
def make_histogram(result, bin_edges): if len(result[0]) == 2: h = value_error_tuplelist_to_hist(result, bin_edges) return h else: # len(result[0]) == 3 g = value_errors_tuplelist_to_graph(result, bin_edges) return g
def read_xsection_measurement_results(path_to_JSON, variable, bin_edges, category, channel, k_values, met_type='patType1CorrectedPFMet', met_uncertainties=[]): filename = '' if category in met_uncertainties and variable == 'HT' and not 'JES' in category and not 'JER' in category: filename = path_to_JSON + '/xsection_measurement_results/' + \ channel + '/central/normalised_xsection_' + met_type + '.txt' else: filename = path_to_JSON + '/xsection_measurement_results/' + channel + \ '/' + category + '/normalised_xsection_' + met_type + '.txt' if channel == 'combined': filename = filename.replace('kv' + str(k_values[channel]), '') normalised_xsection_unfolded = read_data_from_JSON(filename) h_normalised_xsection = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJet_measured'], bin_edges[variable]) h_normalised_xsection_unfolded = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJet_unfolded'], bin_edges[variable]) histograms_normalised_xsection_different_generators = {'measured': h_normalised_xsection, 'unfolded': h_normalised_xsection_unfolded} histograms_normalised_xsection_systematics_shifts = {'measured': h_normalised_xsection, 'unfolded': h_normalised_xsection_unfolded} if category == 'central': # true distributions h_normalised_xsection_MADGRAPH = value_error_tuplelist_to_hist( normalised_xsection_unfolded['MADGRAPH'], bin_edges[variable]) h_normalised_xsection_POWHEG_PYTHIA = value_error_tuplelist_to_hist( normalised_xsection_unfolded['POWHEG_PYTHIA'], bin_edges[variable]) h_normalised_xsection_POWHEG_HERWIG = value_error_tuplelist_to_hist( normalised_xsection_unfolded['POWHEG_HERWIG'], bin_edges[variable]) h_normalised_xsection_MCATNLO = value_error_tuplelist_to_hist( normalised_xsection_unfolded['MCATNLO'], bin_edges[variable]) h_normalised_xsection_mathchingup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['matchingup'], bin_edges[variable]) h_normalised_xsection_mathchingdown = value_error_tuplelist_to_hist( normalised_xsection_unfolded['matchingdown'], bin_edges[variable]) h_normalised_xsection_scaleup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['scaleup'], bin_edges[variable]) h_normalised_xsection_scaledown = value_error_tuplelist_to_hist( normalised_xsection_unfolded['scaledown'], bin_edges[variable]) histograms_normalised_xsection_different_generators.update({'MADGRAPH': h_normalised_xsection_MADGRAPH, 'POWHEG_PYTHIA': h_normalised_xsection_POWHEG_PYTHIA, 'POWHEG_HERWIG': h_normalised_xsection_POWHEG_HERWIG, 'MCATNLO': h_normalised_xsection_MCATNLO}) histograms_normalised_xsection_systematics_shifts.update({'MADGRAPH': h_normalised_xsection_MADGRAPH, 'matchingdown': h_normalised_xsection_mathchingdown, 'matchingup': h_normalised_xsection_mathchingup, 'scaledown': h_normalised_xsection_scaledown, 'scaleup': h_normalised_xsection_scaleup}) file_template = path_to_JSON + '/xsection_measurement_results/' + channel + \ '/kv' + str(k_values[channel]) + '/' + \ category + '/normalised_xsection_' + met_type if channel == 'combined': file_template = file_template.replace( 'kv' + str(k_values[channel]), '') # normalised_xsection_unfolded_with_errors = read_data_from_JSON( file_template + '_with_errors.txt' ) normalised_xsection_unfolded_with_errors_with_systematics_but_without_ttbar_theory = read_data_from_JSON( file_template + '_with_systematics_but_without_ttbar_theory_errors.txt') normalised_xsection_unfolded_with_errors_with_systematics_but_without_generator = read_data_from_JSON( file_template + '_with_systematics_but_without_generator_errors.txt') # a rootpy.Graph with asymmetric errors! h_normalised_xsection_with_systematics_but_without_ttbar_theory = value_errors_tuplelist_to_graph( normalised_xsection_unfolded_with_errors_with_systematics_but_without_ttbar_theory[ 'TTJet_measured'], bin_edges[variable]) h_normalised_xsection_with_systematics_but_without_ttbar_theory_unfolded = value_errors_tuplelist_to_graph( normalised_xsection_unfolded_with_errors_with_systematics_but_without_ttbar_theory[ 'TTJet_unfolded'], bin_edges[variable]) h_normalised_xsection_with_systematics_but_without_generator = value_errors_tuplelist_to_graph( normalised_xsection_unfolded_with_errors_with_systematics_but_without_generator[ 'TTJet_measured'], bin_edges[variable]) h_normalised_xsection_with_systematics_but_without_generator_unfolded = value_errors_tuplelist_to_graph( normalised_xsection_unfolded_with_errors_with_systematics_but_without_generator[ 'TTJet_unfolded'], bin_edges[variable]) histograms_normalised_xsection_different_generators[ 'measured_with_systematics'] = h_normalised_xsection_with_systematics_but_without_generator histograms_normalised_xsection_different_generators[ 'unfolded_with_systematics'] = h_normalised_xsection_with_systematics_but_without_generator_unfolded histograms_normalised_xsection_systematics_shifts[ 'measured_with_systematics'] = h_normalised_xsection_with_systematics_but_without_ttbar_theory histograms_normalised_xsection_systematics_shifts[ 'unfolded_with_systematics'] = h_normalised_xsection_with_systematics_but_without_ttbar_theory_unfolded return histograms_normalised_xsection_different_generators, histograms_normalised_xsection_systematics_shifts
def test_get_max_y_graph(): g = value_errors_tuplelist_to_graph(data_g, bin_edges) max_y = get_best_max_y([g]) assert max_y == 3 + 1
def debug_last_bin(): ''' For debugging why the last bin in the problematic variables deviates a lot in _one_ of the channels only. ''' file_template = '/hdfs/TopQuarkGroup/run2/dpsData/' file_template += 'data/normalisation/background_subtraction/13TeV/' file_template += '{variable}/VisiblePS/central/' file_template += 'normalised_xsection_{channel}_RooUnfoldSvd{suffix}.txt' problematic_variables = ['HT', 'MET', 'NJets', 'lepton_pt'] for variable in problematic_variables: results = {} Result = namedtuple( 'Result', ['before_unfolding', 'after_unfolding', 'model']) for channel in ['electron', 'muon', 'combined']: input_file_data = file_template.format( variable=variable, channel=channel, suffix='_with_errors', ) input_file_model = file_template.format( variable=variable, channel=channel, suffix='', ) data = read_data_from_JSON(input_file_data) data_model = read_data_from_JSON(input_file_model) before_unfolding = data['TTJet_measured_withoutFakes'] after_unfolding = data['TTJet_unfolded'] model = data_model['powhegPythia8'] # only use the last bin h_before_unfolding = value_errors_tuplelist_to_graph( [before_unfolding[-1]], bin_edges_vis[variable][-2:]) h_after_unfolding = value_errors_tuplelist_to_graph( [after_unfolding[-1]], bin_edges_vis[variable][-2:]) h_model = value_error_tuplelist_to_hist( [model[-1]], bin_edges_vis[variable][-2:]) r = Result(before_unfolding, after_unfolding, model) h = Result(h_before_unfolding, h_after_unfolding, h_model) results[channel] = (r, h) models = {'POWHEG+PYTHIA': results['combined'][1].model} h_unfolded = [results[channel][1].after_unfolding for channel in [ 'electron', 'muon', 'combined']] tmp_hists = spread_x(h_unfolded, bin_edges_vis[variable][-2:]) measurements = {} for channel, hist in zip(['electron', 'muon', 'combined'], tmp_hists): value = results[channel][0].after_unfolding[-1][0] error = results[channel][0].after_unfolding[-1][1] label = '{c_label} ({value:1.2g} $\pm$ {error:1.2g})'.format( c_label=channel, value=value, error=error, ) measurements[label] = hist properties = Histogram_properties() properties.name = 'normalised_xsection_compare_channels_{0}_{1}_last_bin'.format( variable, channel) properties.title = 'Comparison of channels' properties.path = 'plots' properties.has_ratio = True properties.xerr = False properties.x_limits = ( bin_edges_vis[variable][-2], bin_edges_vis[variable][-1]) properties.x_axis_title = variables_latex[variable] properties.y_axis_title = r'$\frac{1}{\sigma} \frac{d\sigma}{d' + \ variables_latex[variable] + '}$' properties.legend_location = (0.95, 0.40) if variable == 'NJets': properties.legend_location = (0.97, 0.80) properties.formats = ['png'] compare_measurements(models=models, measurements=measurements, show_measurement_errors=True, histogram_properties=properties, save_folder='plots/', save_as=properties.formats)
def read_xsection_measurement_results(path_to_JSON, variable, bin_edges, category, channel, k_values, met_type='patType1CorrectedPFMet', met_uncertainties=[]): filename = '' if category in met_uncertainties and variable == 'HT' and not 'JES' in category and not 'JER' in category: filename = path_to_JSON + '/xsection_measurement_results/' + \ channel + '/central/normalised_xsection_' + met_type + '.txt' else: filename = path_to_JSON + '/xsection_measurement_results/' + channel + \ '/' + category + '/normalised_xsection_' + met_type + '.txt' if channel == 'combined': filename = filename.replace('kv' + str(k_values[channel]), '') normalised_xsection_unfolded = read_data_from_JSON(filename) h_normalised_xsection = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJet_measured'], bin_edges[variable]) h_normalised_xsection_unfolded = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJet_unfolded'], bin_edges[variable]) histograms_normalised_xsection_different_generators = { 'measured': h_normalised_xsection, 'unfolded': h_normalised_xsection_unfolded } histograms_normalised_xsection_systematics_shifts = { 'measured': h_normalised_xsection, 'unfolded': h_normalised_xsection_unfolded } if category == 'central': # true distributions h_normalised_xsection_MADGRAPH = value_error_tuplelist_to_hist( normalised_xsection_unfolded['MADGRAPH'], bin_edges[variable]) h_normalised_xsection_POWHEG_PYTHIA = value_error_tuplelist_to_hist( normalised_xsection_unfolded['POWHEG_PYTHIA'], bin_edges[variable]) h_normalised_xsection_POWHEG_HERWIG = value_error_tuplelist_to_hist( normalised_xsection_unfolded['POWHEG_HERWIG'], bin_edges[variable]) h_normalised_xsection_MCATNLO = value_error_tuplelist_to_hist( normalised_xsection_unfolded['MCATNLO'], bin_edges[variable]) h_normalised_xsection_mathchingup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['matchingup'], bin_edges[variable]) h_normalised_xsection_mathchingdown = value_error_tuplelist_to_hist( normalised_xsection_unfolded['matchingdown'], bin_edges[variable]) h_normalised_xsection_scaleup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['scaleup'], bin_edges[variable]) h_normalised_xsection_scaledown = value_error_tuplelist_to_hist( normalised_xsection_unfolded['scaledown'], bin_edges[variable]) histograms_normalised_xsection_different_generators.update({ 'MADGRAPH': h_normalised_xsection_MADGRAPH, 'POWHEG_PYTHIA': h_normalised_xsection_POWHEG_PYTHIA, 'POWHEG_HERWIG': h_normalised_xsection_POWHEG_HERWIG, 'MCATNLO': h_normalised_xsection_MCATNLO }) histograms_normalised_xsection_systematics_shifts.update({ 'MADGRAPH': h_normalised_xsection_MADGRAPH, 'matchingdown': h_normalised_xsection_mathchingdown, 'matchingup': h_normalised_xsection_mathchingup, 'scaledown': h_normalised_xsection_scaledown, 'scaleup': h_normalised_xsection_scaleup }) file_template = path_to_JSON + '/xsection_measurement_results/' + channel + \ '/kv' + str(k_values[channel]) + '/' + \ category + '/normalised_xsection_' + met_type if channel == 'combined': file_template = file_template.replace( 'kv' + str(k_values[channel]), '') # normalised_xsection_unfolded_with_errors = read_data_from_JSON( file_template + '_with_errors.txt' ) normalised_xsection_unfolded_with_errors_with_systematics_but_without_ttbar_theory = read_data_from_JSON( file_template + '_with_systematics_but_without_ttbar_theory_errors.txt') normalised_xsection_unfolded_with_errors_with_systematics_but_without_generator = read_data_from_JSON( file_template + '_with_systematics_but_without_generator_errors.txt') # a rootpy.Graph with asymmetric errors! h_normalised_xsection_with_systematics_but_without_ttbar_theory = value_errors_tuplelist_to_graph( normalised_xsection_unfolded_with_errors_with_systematics_but_without_ttbar_theory[ 'TTJet_measured'], bin_edges[variable]) h_normalised_xsection_with_systematics_but_without_ttbar_theory_unfolded = value_errors_tuplelist_to_graph( normalised_xsection_unfolded_with_errors_with_systematics_but_without_ttbar_theory[ 'TTJet_unfolded'], bin_edges[variable]) h_normalised_xsection_with_systematics_but_without_generator = value_errors_tuplelist_to_graph( normalised_xsection_unfolded_with_errors_with_systematics_but_without_generator[ 'TTJet_measured'], bin_edges[variable]) h_normalised_xsection_with_systematics_but_without_generator_unfolded = value_errors_tuplelist_to_graph( normalised_xsection_unfolded_with_errors_with_systematics_but_without_generator[ 'TTJet_unfolded'], bin_edges[variable]) histograms_normalised_xsection_different_generators[ 'measured_with_systematics'] = h_normalised_xsection_with_systematics_but_without_generator histograms_normalised_xsection_different_generators[ 'unfolded_with_systematics'] = h_normalised_xsection_with_systematics_but_without_generator_unfolded histograms_normalised_xsection_systematics_shifts[ 'measured_with_systematics'] = h_normalised_xsection_with_systematics_but_without_ttbar_theory histograms_normalised_xsection_systematics_shifts[ 'unfolded_with_systematics'] = h_normalised_xsection_with_systematics_but_without_ttbar_theory_unfolded return histograms_normalised_xsection_different_generators, histograms_normalised_xsection_systematics_shifts
def read_xsection_measurement_results( category, channel, unc_type, scale_uncertanties=False ): ''' Reading the unfolded xsection results from DFs into graphs ''' global path_to_DF, variable, phase_space, method file_template = '{path}/{category}/xsection_{name}_{channel}_{method}{suffix}.txt' filename = file_template.format( path = path_to_DF, category = category, name = unc_type, channel = channel, method = method, suffix = '', ) xsec_04_log.debug('Reading file {0}'.format(filename)) edges = bin_edges_full[variable] if phase_space == 'VisiblePS': edges = bin_edges_vis[variable] # Collect the cross section measured/unfolded results from dataframes normalised_xsection_unfolded = read_tuple_from_file( filename ) # Create TTJets_Scale d_scale_syst = {} partonShower_uncertainties = measurement_config.list_of_systematics['TTJets_scale'] for psUnc in partonShower_uncertainties: normalised_xsection_unfolded[psUnc] = [value for value, error in normalised_xsection_unfolded[psUnc]] d_scale_syst[psUnc] = normalised_xsection_unfolded[psUnc] normalised_xsection_unfolded['TTJets_scaledown'], normalised_xsection_unfolded['TTJets_scaleup'] = get_scale_envelope( d_scale_syst, normalised_xsection_unfolded['TTJets_powhegPythia8'], ) # Need to strip errors from central before passing to scaleFSR() central = [c[0] for c in normalised_xsection_unfolded['TTJets_powhegPythia8']] # Scale FSR if scale_uncertanties: normalised_xsection_unfolded['TTJets_fsrdown'] = scaleFSR( normalised_xsection_unfolded['TTJets_fsrdown'], central, ) normalised_xsection_unfolded['TTJets_fsrup'] = scaleFSR( normalised_xsection_unfolded['TTJets_fsrup'], central, ) # h_normalised_xsection = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_measured'], edges ) h_normalised_xsection_unfolded = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_unfolded'], edges ) histograms_normalised_xsection_different_generators = { # 'measured':h_normalised_xsection, 'unfolded':h_normalised_xsection_unfolded, } histograms_normalised_xsection_different_systematics = { 'unfolded':h_normalised_xsection_unfolded, } if category == 'central': # Add in distributions for the different MC to be shown h_normalised_xsection_powhegPythia8 = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_powhegPythia8'], edges ) h_normalised_xsection_amcatnlo = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_amcatnloPythia8'], edges ) h_normalised_xsection_madgraphMLM = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_madgraphMLM'], edges ) h_normalised_xsection_powhegHerwigpp = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_powhegHerwig'], edges ) # SCALE BREAKDOWN h_normalised_xsection_fsrup = value_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_fsrup'], edges ) h_normalised_xsection_fsrdown = value_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_fsrdown'], edges ) h_normalised_xsection_isrdown = value_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_isrdown'], edges ) h_normalised_xsection_isrup = value_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_isrup'], edges ) h_normalised_xsection_factorisationup = value_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_factorisationup'], edges ) h_normalised_xsection_factorisationdown = value_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_factorisationdown'], edges ) h_normalised_xsection_renormalisationup = value_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_renormalisationup'], edges ) h_normalised_xsection_renormalisationdown = value_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_renormalisationdown'], edges ) h_normalised_xsection_combinedup = value_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_combinedup'], edges ) h_normalised_xsection_combineddown = value_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_combineddown'], edges ) # PARTON SHOWER h_normalised_xsection_scaleup = value_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_scaleup'], edges ) h_normalised_xsection_scaledown = value_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_scaledown'], edges ) h_normalised_xsection_massup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_massup'], edges ) h_normalised_xsection_massdown = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_massdown'], edges ) h_normalised_xsection_ueup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_ueup'], edges ) h_normalised_xsection_uedown = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_uedown'], edges ) h_normalised_xsection_hdampup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_hdampup'], edges ) h_normalised_xsection_hdampdown = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_hdampdown'], edges ) h_normalised_xsection_erdOn = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_erdOn'], edges ) h_normalised_xsection_QCDbased_erdOn = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_QCDbased_erdOn'], edges ) # h_normalised_xsection_GluonMove = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_GluonMove'], edges ) h_normalised_xsection_semiLepBrup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_semiLepBrup'], edges ) h_normalised_xsection_semiLepBrdown = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_semiLepBrdown'], edges ) h_normalised_xsection_fragup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_fragup'], edges ) h_normalised_xsection_fragdown = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_fragdown'], edges ) h_normalised_xsection_petersonFrag = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_petersonFrag'], edges ) # OTHER # h_normalised_xsection_alphaSup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_alphaSup'], edges ) # h_normalised_xsection_alphaSdown = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_alphaSdown'], edges ) h_normalised_xsection_topPt = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJets_topPt'], edges ) # And update histograms_normalised_xsection_different_generators.update( { 'TTJets_powhegPythia8' : h_normalised_xsection_powhegPythia8, 'TTJets_amcatnloPythia8' : h_normalised_xsection_amcatnlo, 'TTJets_madgraphMLM' : h_normalised_xsection_madgraphMLM, 'TTJets_powhegHerwig' : h_normalised_xsection_powhegHerwigpp, } ) if scale_uncertanties: histograms_normalised_xsection_different_systematics.update( { 'TTJets_powhegPythia8' : h_normalised_xsection_powhegPythia8, 'TTJets_fsrup' : h_normalised_xsection_fsrup, 'TTJets_fsrdown' : h_normalised_xsection_fsrdown, 'TTJets_isrdown' : h_normalised_xsection_isrdown, 'TTJets_isrup' : h_normalised_xsection_isrup, 'TTJets_factorisationup' : h_normalised_xsection_factorisationup, 'TTJets_factorisationdown' : h_normalised_xsection_factorisationdown, 'TTJets_renormalisationup' : h_normalised_xsection_renormalisationup, 'TTJets_renormalisationdown' : h_normalised_xsection_renormalisationdown, 'TTJets_combinedup' : h_normalised_xsection_combinedup, 'TTJets_combineddown' : h_normalised_xsection_combineddown, } ) else: histograms_normalised_xsection_different_systematics.update( { 'TTJets_powhegPythia8' : h_normalised_xsection_powhegPythia8, 'TTJets_scaleup' : h_normalised_xsection_scaleup, 'TTJets_scaledown' : h_normalised_xsection_scaledown, # 'TTJets_massup' : h_normalised_xsection_massup, # 'TTJets_massdown' : h_normalised_xsection_massdown, # 'TTJets_ueup' : h_normalised_xsection_ueup, # 'TTJets_uedown' : h_normalised_xsection_uedown, 'TTJets_hdampup' : h_normalised_xsection_hdampup, 'TTJets_hdampdown' : h_normalised_xsection_hdampdown, # 'TTJets_erdOn' : h_normalised_xsection_erdOn, # 'TTJets_QCDbased_erdOn' : h_normalised_xsection_QCDbased_erdOn, # 'TTJets_GluonMove' : h_normalised_xsection_GluonMove, # 'TTJets_semiLepBrup' : h_normalised_xsection_semiLepBrup, # 'TTJets_semiLepBrdown' : h_normalised_xsection_semiLepBrdown, # 'TTJets_fragup' : h_normalised_xsection_fragup, # 'TTJets_fragdown' : h_normalised_xsection_fragdown, # 'TTJets_petersonFrag' : h_normalised_xsection_petersonFrag, 'TTJets_topPt' : h_normalised_xsection_topPt, } ) filename = file_template.format( path = path_to_DF, category = category, name = unc_type, channel = channel, method = method, suffix = '_summary_absolute', ) # Now for the systematic uncertainties normalised_xsection_unfolded_with_errors = file_to_df( filename ) normalised_xsection_unfolded_with_errors['TTJets_unfolded'] = tupleise_cols( normalised_xsection_unfolded_with_errors['central'], normalised_xsection_unfolded_with_errors['systematic'], ) xsec_04_log.debug('Reading file {0}'.format(filename)) # Transform unfolded data into graph form h_normalised_xsection_unfolded_with_errors_unfolded = value_errors_tuplelist_to_graph( normalised_xsection_unfolded_with_errors['TTJets_unfolded'], edges, is_symmetric_errors=True ) # Add to list of histograms histograms_normalised_xsection_different_generators['unfolded_with_systematics'] = h_normalised_xsection_unfolded_with_errors_unfolded histograms_normalised_xsection_different_systematics['unfolded_with_systematics'] = h_normalised_xsection_unfolded_with_errors_unfolded return histograms_normalised_xsection_different_generators, histograms_normalised_xsection_different_systematics
def test_get_max_y_graph(): g = value_errors_tuplelist_to_graph(data_g, bin_edges) max_y = get_best_max_y([g]) assert max_y == 3 + 1
def read_xsection_measurement_results( category, channel ): ''' Reading the unfolded xsection results from DFs into graphs ''' global path_to_DF, variable, phase_space, method file_template = '{path}/{category}/{name}_{channel}_{method}{suffix}.txt' filename = file_template.format( path = path_to_DF, category = category, name = 'xsection_normalised', channel = channel, method = method, suffix = '', ) xsec_04_log.debug('Reading file {0}'.format(filename)) edges = bin_edges_full[variable] if phase_space == 'VisiblePS': edges = bin_edges_vis[variable] # Collect the cross section measured/unfolded results from dataframes normalised_xsection_unfolded = read_tuple_from_file( filename ) h_normalised_xsection = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJet_measured'], edges ) h_normalised_xsection_unfolded = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJet_unfolded'], edges ) histograms_normalised_xsection_different_generators = { 'measured':h_normalised_xsection, 'unfolded':h_normalised_xsection_unfolded, } histograms_normalised_xsection_systematics_shifts = deepcopy( histograms_normalised_xsection_different_generators ) if category == 'central': # Add in distributions for the different MC to be shown h_normalised_xsection_powhegPythia8 = value_error_tuplelist_to_hist( normalised_xsection_unfolded['powhegPythia8'], edges ) # h_normalised_xsection_amcatnlo = value_error_tuplelist_to_hist( normalised_xsection_unfolded['amcatnlo'], edges ) # h_normalised_xsection_madgraphMLM = value_error_tuplelist_to_hist( normalised_xsection_unfolded['madgraphMLM'], edges ) h_normalised_xsection_powhegHerwigpp = value_error_tuplelist_to_hist( normalised_xsection_unfolded['powhegHerwig'], edges ) h_normalised_xsection_massup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['massup'], edges ) h_normalised_xsection_massdown = value_error_tuplelist_to_hist( normalised_xsection_unfolded['massdown'], edges ) # And update histograms_normalised_xsection_different_generators.update( { 'powhegPythia8' : h_normalised_xsection_powhegPythia8, # 'amcatnloPythia8' : h_normalised_xsection_amcatnlo, # 'madgraphMLM' : h_normalised_xsection_madgraphMLM, 'powhegHerwig' : h_normalised_xsection_powhegHerwigpp, } ) histograms_normalised_xsection_systematics_shifts.update( { 'powhegPythia8' : h_normalised_xsection_powhegPythia8, 'massdown' : h_normalised_xsection_massdown, 'massup' : h_normalised_xsection_massup } ) filename = file_template.format( path = path_to_DF, category = category, name = 'xsection_normalised', channel = channel, method = method, suffix = '_summary_absolute', ) # Now for the systematic uncertainties normalised_xsection_unfolded_with_errors = file_to_df( filename ) normalised_xsection_unfolded_with_errors['TTJet_unfolded'] = tupleise_cols( normalised_xsection_unfolded_with_errors['central'], normalised_xsection_unfolded_with_errors['systematic'], ) xsec_04_log.debug('Reading file {0}'.format(filename)) # Transform unfolded data into graph form h_normalised_xsection_unfolded_with_errors_unfolded = value_errors_tuplelist_to_graph( normalised_xsection_unfolded_with_errors['TTJet_unfolded'], edges, is_symmetric_errors=True ) # Add to list of histograms histograms_normalised_xsection_different_generators['unfolded_with_systematics'] = h_normalised_xsection_unfolded_with_errors_unfolded histograms_normalised_xsection_systematics_shifts['unfolded_with_systematics'] = h_normalised_xsection_unfolded_with_errors_unfolded return histograms_normalised_xsection_different_generators, histograms_normalised_xsection_systematics_shifts
def read_xsection_measurement_results( category, channel ): global path_to_JSON, variable, met_type, phase_space, method file_template = '{path}/{category}/{name}_{channel}_{method}{suffix}.txt' filename = file_template.format( path = path_to_JSON, category = category, name = 'normalised_xsection', channel = channel, method = method, suffix = '', ) xsec_04_log.debug('Reading file {0}'.format(filename)) normalised_xsection_unfolded = read_data_from_JSON( filename ) edges = bin_edges_full[variable] if phase_space == 'VisiblePS': edges = bin_edges_vis[variable] h_normalised_xsection = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJet_measured'], edges ) h_normalised_xsection_unfolded = value_error_tuplelist_to_hist( normalised_xsection_unfolded['TTJet_unfolded'], edges ) histograms_normalised_xsection_different_generators = {'measured':h_normalised_xsection, 'unfolded':h_normalised_xsection_unfolded} histograms_normalised_xsection_systematics_shifts = {'measured':h_normalised_xsection, 'unfolded':h_normalised_xsection_unfolded} if category == 'central': # true distributions h_normalised_xsection_powhegPythia8 = value_error_tuplelist_to_hist( normalised_xsection_unfolded['powhegPythia8'], edges ) h_normalised_xsection_amcatnlo = value_error_tuplelist_to_hist( normalised_xsection_unfolded['amcatnlo'], edges ) h_normalised_xsection_madgraphMLM = value_error_tuplelist_to_hist( normalised_xsection_unfolded['madgraphMLM'], edges ) h_normalised_xsection_powhegHerwigpp = value_error_tuplelist_to_hist( normalised_xsection_unfolded['powhegHerwig'], edges ) # h_normalised_xsection_amcatnloHerwigpp = value_error_tuplelist_to_hist( normalised_xsection_unfolded['amcatnloHerwig'], edges ) # h_normalised_xsection_scaleup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['scaleup'], edges ) # h_normalised_xsection_scaledown = value_error_tuplelist_to_hist( normalised_xsection_unfolded['scaledown'], edges ) h_normalised_xsection_massup = value_error_tuplelist_to_hist( normalised_xsection_unfolded['massup'], edges ) h_normalised_xsection_massdown = value_error_tuplelist_to_hist( normalised_xsection_unfolded['massdown'], edges ) histograms_normalised_xsection_different_generators.update( { 'powhegPythia8':h_normalised_xsection_powhegPythia8, 'amcatnloPythia8':h_normalised_xsection_amcatnlo, 'madgraphMLM':h_normalised_xsection_madgraphMLM, 'powhegHerwig':h_normalised_xsection_powhegHerwigpp, # 'amcatnloHerwig':h_normalised_xsection_amcatnloHerwigpp, }) histograms_normalised_xsection_systematics_shifts.update( {'powhegPythia8':h_normalised_xsection_powhegPythia8, # 'scaledown': h_normalised_xsection_scaledown, # 'scaleup': h_normalised_xsection_scaleup, 'massdown': h_normalised_xsection_massdown, 'massup': h_normalised_xsection_massup }) filename = file_template.format( path = path_to_JSON, category = category, name = 'normalised_xsection', channel = channel, method = method, suffix = '_with_errors', ) normalised_xsection_unfolded_with_errors = read_data_from_JSON( filename ) xsec_04_log.debug('Reading file {0}'.format(filename)) # filename = file_template.format( # path = path_to_JSON, # category = category, # name = 'normalised_xsection', # channel = channel, # method = method, # suffix = '_with_systematics_but_without_generator_errors', # ) ### normalised_xsection_unfolded_with_errors_with_systematics_but_without_ttbar_theory = read_data_from_JSON( file_template + '_with_systematics_but_without_ttbar_theory_errors.txt' ) # normalised_xsection_unfolded_with_errors_with_systematics_but_without_generator = normalised_xsection_unfolded_with_errors # a rootpy.Graph with asymmetric errors! ### h_normalised_xsection_with_systematics_but_without_ttbar_theory = value_errors_tuplelist_to_graph( ### normalised_xsection_unfolded_with_errors_with_systematics_but_without_ttbar_theory['TTJet_measured'], ### edges ) ### h_normalised_xsection_with_systematics_but_without_ttbar_theory_unfolded = value_errors_tuplelist_to_graph( ### normalised_xsection_unfolded_with_errors_with_systematics_but_without_ttbar_theory['TTJet_unfolded'], ### edges ) h_normalised_xsection_unfolded_with_errors = value_errors_tuplelist_to_graph( normalised_xsection_unfolded_with_errors['TTJet_measured'], edges ) h_normalised_xsection_unfolded_with_errors_unfolded = value_errors_tuplelist_to_graph( normalised_xsection_unfolded_with_errors['TTJet_unfolded'], edges ) # histograms_normalised_xsection_different_generators['measured_with_systematics'] = h_normalised_xsection_with_systematics_but_without_ttbar_theory # histograms_normalised_xsection_different_generators['unfolded_with_systematics'] = h_normalised_xsection_with_systematics_but_without_ttbar_theory_unfolded histograms_normalised_xsection_different_generators['measured_with_systematics'] = h_normalised_xsection_unfolded_with_errors histograms_normalised_xsection_different_generators['unfolded_with_systematics'] = h_normalised_xsection_unfolded_with_errors_unfolded histograms_normalised_xsection_systematics_shifts['measured_with_systematics'] = h_normalised_xsection_unfolded_with_errors histograms_normalised_xsection_systematics_shifts['unfolded_with_systematics'] = h_normalised_xsection_unfolded_with_errors_unfolded return histograms_normalised_xsection_different_generators, histograms_normalised_xsection_systematics_shifts