本文整理汇总了Python中tools.plotting.Histogram_properties.xerr方法的典型用法代码示例。如果您正苦于以下问题:Python Histogram_properties.xerr方法的具体用法?Python Histogram_properties.xerr怎么用?Python Histogram_properties.xerr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tools.plotting.Histogram_properties
的用法示例。
在下文中一共展示了Histogram_properties.xerr方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compare_combine_before_after_unfolding
# 需要导入模块: from tools.plotting import Histogram_properties [as 别名]
# 或者: from tools.plotting.Histogram_properties import xerr [as 别名]
def compare_combine_before_after_unfolding(measurement='normalised_xsection',
add_before_unfolding=False):
file_template = 'data/normalisation/background_subtraction/13TeV/'
file_template += '{variable}/VisiblePS/central/'
file_template += '{measurement}_{channel}_RooUnfold{method}.txt'
variables = ['MET', 'HT', 'ST', 'NJets',
'lepton_pt', 'abs_lepton_eta', 'WPT']
for variable in variables:
combineBefore = file_template.format(
variable=variable,
method='Svd',
channel='combinedBeforeUnfolding',
measurement=measurement)
combineAfter = file_template.format(
variable=variable,
method='Svd',
channel='combined',
measurement=measurement)
data = read_data_from_JSON(combineBefore)
before_unfolding = data['TTJet_measured']
combineBefore_data = data['TTJet_unfolded']
combineAfter_data = read_data_from_JSON(combineAfter)['TTJet_unfolded']
h_combineBefore = value_error_tuplelist_to_hist(
combineBefore_data, bin_edges_vis[variable])
h_combineAfter = value_error_tuplelist_to_hist(
combineAfter_data, bin_edges_vis[variable])
h_before_unfolding = value_error_tuplelist_to_hist(
before_unfolding, bin_edges_vis[variable])
properties = Histogram_properties()
properties.name = '{0}_compare_combine_before_after_unfolding_{1}'.format(
measurement, variable)
properties.title = 'Comparison of combining before/after unfolding'
properties.path = 'plots'
properties.has_ratio = True
properties.xerr = True
properties.x_limits = (
bin_edges_vis[variable][0], bin_edges_vis[variable][-1])
properties.x_axis_title = variables_latex[variable]
if 'xsection' in measurement:
properties.y_axis_title = r'$\frac{1}{\sigma} \frac{d\sigma}{d' + \
variables_latex[variable] + '}$'
else:
properties.y_axis_title = r'$t\bar{t}$ normalisation'
histograms = {'Combine before unfolding': h_combineBefore, 'Combine after unfolding': h_combineAfter}
if add_before_unfolding:
histograms['before unfolding'] = h_before_unfolding
properties.name += '_ext'
properties.has_ratio = False
plot = Plot(histograms, properties)
plot.draw_method = 'errorbar'
compare_histograms(plot)
示例2: compare_unfolding_methods
# 需要导入模块: from tools.plotting import Histogram_properties [as 别名]
# 或者: from tools.plotting.Histogram_properties import xerr [as 别名]
def compare_unfolding_methods(measurement='normalised_xsection',
add_before_unfolding=False, channel='combined'):
file_template = '/hdfs/TopQuarkGroup/run2/dpsData/'
file_template += 'data/normalisation/background_subtraction/13TeV/'
file_template += '{variable}/VisiblePS/central/'
file_template += '{measurement}_{channel}_RooUnfold{method}.txt'
variables = ['MET', 'HT', 'ST', 'NJets',
'lepton_pt', 'abs_lepton_eta', 'WPT']
for variable in variables:
svd = file_template.format(
variable=variable,
method='Svd',
channel=channel,
measurement=measurement)
bayes = file_template.format(
variable=variable,
method='Bayes', channel=channel,
measurement=measurement)
data = read_data_from_JSON(svd)
before_unfolding = data['TTJet_measured_withoutFakes']
svd_data = data['TTJet_unfolded']
bayes_data = read_data_from_JSON(bayes)['TTJet_unfolded']
h_svd = value_error_tuplelist_to_hist(
svd_data, bin_edges_vis[variable])
h_bayes = value_error_tuplelist_to_hist(
bayes_data, bin_edges_vis[variable])
h_before_unfolding = value_error_tuplelist_to_hist(
before_unfolding, bin_edges_vis[variable])
properties = Histogram_properties()
properties.name = '{0}_compare_unfolding_methods_{1}_{2}'.format(
measurement, variable, channel)
properties.title = 'Comparison of unfolding methods'
properties.path = 'plots'
properties.has_ratio = True
properties.xerr = True
properties.x_limits = (
bin_edges_vis[variable][0], bin_edges_vis[variable][-1])
properties.x_axis_title = variables_latex[variable]
if 'xsection' in measurement:
properties.y_axis_title = r'$\frac{1}{\sigma} \frac{d\sigma}{d' + \
variables_latex[variable] + '}$'
else:
properties.y_axis_title = r'$t\bar{t}$ normalisation'
histograms = {'SVD': h_svd, 'Bayes': h_bayes}
if add_before_unfolding:
histograms['before unfolding'] = h_before_unfolding
properties.name += '_ext'
properties.has_ratio = False
plot = Plot(histograms, properties)
plot.draw_method = 'errorbar'
compare_histograms(plot)
示例3: compare_combine_before_after_unfolding_uncertainties
# 需要导入模块: from tools.plotting import Histogram_properties [as 别名]
# 或者: from tools.plotting.Histogram_properties import xerr [as 别名]
def compare_combine_before_after_unfolding_uncertainties():
file_template = 'data/normalisation/background_subtraction/13TeV/'
file_template += '{variable}/VisiblePS/central/'
file_template += 'unfolded_normalisation_{channel}_RooUnfoldSvd.txt'
variables = ['MET', 'HT', 'ST', 'NJets',
'lepton_pt', 'abs_lepton_eta', 'WPT']
# variables = ['ST']
for variable in variables:
beforeUnfolding = file_template.format(
variable=variable, channel='combinedBeforeUnfolding')
afterUnfolding = file_template.format(
variable=variable, channel='combined')
data = read_data_from_JSON(beforeUnfolding)
before_unfolding = data['TTJet_measured']
beforeUnfolding_data = data['TTJet_unfolded']
afterUnfolding_data = read_data_from_JSON(afterUnfolding)['TTJet_unfolded']
before_unfolding = [e / v * 100 for v, e in before_unfolding]
beforeUnfolding_data = [e / v * 100 for v, e in beforeUnfolding_data]
afterUnfolding_data = [e / v * 100 for v, e in afterUnfolding_data]
h_beforeUnfolding = value_tuplelist_to_hist(
beforeUnfolding_data, bin_edges_vis[variable])
h_afterUnfolding = value_tuplelist_to_hist(
afterUnfolding_data, bin_edges_vis[variable])
h_before_unfolding = value_tuplelist_to_hist(
before_unfolding, bin_edges_vis[variable])
properties = Histogram_properties()
properties.name = 'compare_combine_before_after_unfolding_uncertainties_{0}'.format(
variable)
properties.title = 'Comparison of unfolding uncertainties'
properties.path = 'plots'
properties.has_ratio = False
properties.xerr = True
properties.x_limits = (
bin_edges_vis[variable][0], bin_edges_vis[variable][-1])
properties.x_axis_title = variables_latex[variable]
properties.y_axis_title = 'relative uncertainty (\\%)'
properties.legend_location = (0.98, 0.95)
histograms = {'Combine before unfolding': h_beforeUnfolding, 'Combine after unfolding': h_afterUnfolding,
# 'before unfolding': h_before_unfolding
}
plot = Plot(histograms, properties)
plot.draw_method = 'errorbar'
compare_histograms(plot)
示例4: compare_unfolding_uncertainties
# 需要导入模块: from tools.plotting import Histogram_properties [as 别名]
# 或者: from tools.plotting.Histogram_properties import xerr [as 别名]
def compare_unfolding_uncertainties():
file_template = '/hdfs/TopQuarkGroup/run2/dpsData/'
file_template += 'data/normalisation/background_subtraction/13TeV/'
file_template += '{variable}/VisiblePS/central/'
file_template += 'unfolded_normalisation_combined_RooUnfold{method}.txt'
variables = ['MET', 'HT', 'ST', 'NJets',
'lepton_pt', 'abs_lepton_eta', 'WPT']
# variables = ['ST']
for variable in variables:
svd = file_template.format(
variable=variable, method='Svd')
bayes = file_template.format(
variable=variable, method='Bayes')
data = read_data_from_JSON(svd)
before_unfolding = data['TTJet_measured_withoutFakes']
svd_data = data['TTJet_unfolded']
bayes_data = read_data_from_JSON(bayes)['TTJet_unfolded']
before_unfolding = [e / v * 100 for v, e in before_unfolding]
svd_data = [e / v * 100 for v, e in svd_data]
bayes_data = [e / v * 100 for v, e in bayes_data]
h_svd = value_tuplelist_to_hist(
svd_data, bin_edges_vis[variable])
h_bayes = value_tuplelist_to_hist(
bayes_data, bin_edges_vis[variable])
h_before_unfolding = value_tuplelist_to_hist(
before_unfolding, bin_edges_vis[variable])
properties = Histogram_properties()
properties.name = 'compare_unfolding_uncertainties_{0}'.format(
variable)
properties.title = 'Comparison of unfolding uncertainties'
properties.path = 'plots'
properties.has_ratio = False
properties.xerr = True
properties.x_limits = (
bin_edges_vis[variable][0], bin_edges_vis[variable][-1])
properties.x_axis_title = variables_latex[variable]
properties.y_axis_title = 'relative uncertainty (\\%)'
properties.legend_location = (0.98, 0.95)
histograms = {'SVD': h_svd, 'Bayes': h_bayes,
'before unfolding': h_before_unfolding}
plot = Plot(histograms, properties)
plot.draw_method = 'errorbar'
compare_histograms(plot)
示例5: plot_fit_results
# 需要导入模块: from tools.plotting import Histogram_properties [as 别名]
# 或者: from tools.plotting.Histogram_properties import xerr [as 别名]
def plot_fit_results(fit_results, centre_of_mass, channel, variable, k_value,
tau_value, output_folder, output_formats, bin_edges):
h_mean = Hist(bin_edges, type='D')
h_sigma = Hist(bin_edges, type='D')
n_bins = h_mean.nbins()
assert len(fit_results) == n_bins
for i, fr in enumerate(fit_results):
h_mean.SetBinContent(i + 1, fr.mean)
h_mean.SetBinError(i + 1, fr.meanError)
h_sigma.SetBinContent(i + 1, fr.sigma)
h_sigma.SetBinError(i + 1, fr.sigmaError)
histogram_properties = Histogram_properties()
name_mpt = 'pull_distribution_mean_and_sigma_{0}_{1}_{2}TeV'
histogram_properties.name = name_mpt.format(
variable,
channel,
centre_of_mass
)
histogram_properties.y_axis_title = r'$\mu_{\text{pull}}$ ($\sigma_{\text{pull}}$)'
histogram_properties.x_axis_title = latex_labels.variables_latex[variable]
value = get_value_title(k_value, tau_value)
title = 'pull distribution mean \& sigma for {0}'.format(value)
histogram_properties.title = title
histogram_properties.y_limits = [-0.5, 2]
histogram_properties.xerr = True
compare_measurements(
models={
'ideal $\mu$': make_line_hist(bin_edges, 0),
'ideal $\sigma$': make_line_hist(bin_edges, 1)
},
measurements={
r'$\mu_{\text{pull}}$': h_mean,
r'$\sigma_{\text{pull}}$': h_sigma
},
show_measurement_errors=True,
histogram_properties=histogram_properties,
save_folder=output_folder,
save_as=output_formats)
示例6: make_ttbarReco_plot
# 需要导入模块: from tools.plotting import Histogram_properties [as 别名]
# 或者: from tools.plotting.Histogram_properties import xerr [as 别名]
#.........这里部分代码省略.........
selection = 'SolutionCategory == 1'
histogramsCorrect = get_histograms_from_trees( trees = [signal_region_tree], branch = branchName, weightBranch = '1', selection = selection, files = histogram_files, nBins = nBins, xMin = x_limits[0], xMax = x_limits[-1] )
selection = 'SolutionCategory == 2'
histogramsNotSL = get_histograms_from_trees( trees = [signal_region_tree], branch = branchName, weightBranch = '1', selection = selection, files = histogram_files, nBins = nBins, xMin = x_limits[0], xMax = x_limits[-1] )
selection = 'SolutionCategory == 3'
histogramsNotReco = get_histograms_from_trees( trees = [signal_region_tree], branch = branchName, weightBranch = '1', selection = selection, files = histogram_files, nBins = nBins, xMin = x_limits[0], xMax = x_limits[-1] )
selection = 'SolutionCategory > 3'
histogramsWrong = get_histograms_from_trees( trees = [signal_region_tree], branch = branchName, weightBranch = '1', selection = selection, files = histogram_files, nBins = nBins, xMin = x_limits[0], xMax = x_limits[-1] )
# Split histograms up into signal/control (?)
signal_region_hists = {}
inclusive_control_region_hists = {}
for sample in histograms.keys():
signal_region_hists[sample] = histograms[sample][signal_region_tree]
if use_qcd_data_region:
inclusive_control_region_hists[sample] = histograms[sample][control_region_tree]
prepare_histograms( histograms, rebin = 1, scale_factor = measurement_config.luminosity_scale )
prepare_histograms( histogramsNoSolution, rebin = 1, scale_factor = measurement_config.luminosity_scale )
prepare_histograms( histogramsCorrect, rebin = 1, scale_factor = measurement_config.luminosity_scale )
prepare_histograms( histogramsNotSL, rebin = 1, scale_factor = measurement_config.luminosity_scale )
prepare_histograms( histogramsNotReco, rebin = 1, scale_factor = measurement_config.luminosity_scale )
prepare_histograms( histogramsWrong, rebin = 1, scale_factor = measurement_config.luminosity_scale )
qcd_from_data = signal_region_hists['QCD']
# Which histograms to draw, and properties
histograms_to_draw = [signal_region_hists['data'], qcd_from_data,
signal_region_hists['V+Jets'],
signal_region_hists['SingleTop'],
histogramsNoSolution['TTJet'][signal_region_tree],
histogramsNotSL['TTJet'][signal_region_tree],
histogramsNotReco['TTJet'][signal_region_tree],
histogramsWrong['TTJet'][signal_region_tree],
histogramsCorrect['TTJet'][signal_region_tree]
]
histogram_lables = ['data', 'QCD', 'V+Jets', 'Single-Top',
samples_latex['TTJet'] + ' - no solution',
samples_latex['TTJet'] + ' - not SL',
samples_latex['TTJet'] + ' - not reconstructible',
samples_latex['TTJet'] + ' - wrong reco',
samples_latex['TTJet'] + ' - correct',
]
histogram_colors = ['black', 'yellow', 'green', 'magenta',
'black',
'burlywood',
'chartreuse',
'blue',
'red'
]
histogram_properties = Histogram_properties()
histogram_properties.name = name_prefix + b_tag_bin
if category != 'central':
histogram_properties.name += '_' + category
histogram_properties.title = title
histogram_properties.x_axis_title = x_axis_title
histogram_properties.y_axis_title = y_axis_title
histogram_properties.x_limits = x_limits
histogram_properties.y_limits = y_limits
histogram_properties.y_max_scale = y_max_scale
histogram_properties.xerr = None
# workaround for rootpy issue #638
histogram_properties.emptybins = True
if b_tag_bin:
histogram_properties.additional_text = channel_latex[channel] + ', ' + b_tag_bins_latex[b_tag_bin]
else:
histogram_properties.additional_text = channel_latex[channel]
histogram_properties.legend_location = legend_location
histogram_properties.cms_logo_location = cms_logo_location
histogram_properties.preliminary = preliminary
histogram_properties.set_log_y = log_y
histogram_properties.legend_color = legend_color
if ratio_y_limits:
histogram_properties.ratio_y_limits = ratio_y_limits
if normalise_to_fit:
histogram_properties.mc_error = get_normalisation_error( normalisation )
histogram_properties.mc_errors_label = 'fit uncertainty'
else:
histogram_properties.mc_error = mc_uncertainty
histogram_properties.mc_errors_label = 'MC unc.'
# Actually draw histograms
make_data_mc_comparison_plot( histograms_to_draw, histogram_lables, histogram_colors,
histogram_properties, save_folder = output_folder,
show_ratio = False, normalise = normalise,
)
histogram_properties.name += '_with_ratio'
loc = histogram_properties.legend_location
# adjust legend location as it is relative to canvas!
histogram_properties.legend_location = ( loc[0], loc[1] + 0.05 )
make_data_mc_comparison_plot( histograms_to_draw, histogram_lables, histogram_colors,
histogram_properties, save_folder = output_folder,
show_ratio = True, normalise = normalise,
)
示例7: debug_last_bin
# 需要导入模块: from tools.plotting import Histogram_properties [as 别名]
# 或者: from tools.plotting.Histogram_properties import xerr [as 别名]
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)
示例8: compare_QCD_control_regions_to_MC
# 需要导入模块: from tools.plotting import Histogram_properties [as 别名]
# 或者: from tools.plotting.Histogram_properties import xerr [as 别名]
#.........这里部分代码省略.........
"EventWeight",
"PUWeight",
"BJetWeight",
"MuonEfficiencyCorrection"
]
variables = ['MET', 'HT', 'ST', 'NJets',
'lepton_pt', 'abs_lepton_eta', 'WPT']
# variables = ['abs_lepton_eta']
for variable in variables:
branch = variable
selection = '{0} >= 0'.format(branch)
if variable == 'abs_lepton_eta':
branch = 'abs(lepton_eta)'
selection = 'lepton_eta >= -3'
for channel in ['electron', 'muon']:
data_file = data_file_e
qcd_file = qcd_file_e
ctrl1 = ctrl_e1
ctrl2 = ctrl_e2
mc = mc_e
weight_branches = weight_branches_electron
if channel == 'muon':
data_file = data_file_mu
qcd_file = qcd_file_mu
ctrl1 = ctrl_mu1
ctrl2 = ctrl_mu2
mc = mc_mu
weight_branches = weight_branches_mu
inputs = {
'branch': branch,
'weight_branches': weight_branches,
'tree': ctrl1,
'bin_edges': bin_edges_vis[variable],
'selection': selection,
}
hs_ctrl1 = {
'data': get_histogram_from_tree(input_file=data_file, **inputs),
'TTJet': get_histogram_from_tree(input_file=ttbar_file, **inputs),
'VJets': get_histogram_from_tree(input_file=vjets_file, **inputs),
'SingleTop': get_histogram_from_tree(input_file=singleTop_file, **inputs),
'QCD': get_histogram_from_tree(input_file=qcd_file, **inputs),
}
inputs['tree'] = ctrl2
hs_ctrl2 = {
'data': get_histogram_from_tree(input_file=data_file, **inputs),
'TTJet': get_histogram_from_tree(input_file=ttbar_file, **inputs),
'VJets': get_histogram_from_tree(input_file=vjets_file, **inputs),
'SingleTop': get_histogram_from_tree(input_file=singleTop_file, **inputs),
'QCD': get_histogram_from_tree(input_file=qcd_file, **inputs),
}
inputs['tree'] = mc
h_qcd = get_histogram_from_tree(input_file=qcd_file, **inputs)
h_ctrl1 = clean_control_region(
hs_ctrl1,
data_label='data',
subtract=['TTJet', 'VJets', 'SingleTop'],
fix_to_zero=True)
h_ctrl2 = clean_control_region(
hs_ctrl2,
data_label='data',
subtract=['TTJet', 'VJets', 'SingleTop'],
fix_to_zero=True)
n_qcd_ctrl1 = hs_ctrl1['QCD'].integral()
n_qcd_ctrl2 = hs_ctrl2['QCD'].integral()
n_data1 = h_ctrl1.integral()
n_data2 = h_ctrl2.integral()
n_qcd_sg = h_qcd.integral()
ratio_ctrl1 = n_data1 / n_qcd_ctrl1
ratio_ctrl2 = n_data2 / n_qcd_ctrl2
qcd_estimate_ctrl1 = n_qcd_sg * ratio_ctrl1
qcd_estimate_ctrl2 = n_qcd_sg * ratio_ctrl2
h_ctrl1.Scale(qcd_estimate_ctrl1 / n_data1)
h_ctrl2.Scale(qcd_estimate_ctrl2 / n_data2)
properties = Histogram_properties()
properties.name = 'compare_qcd_control_regions_to_mc_{0}_{1}_channel'.format(
variable, channel)
properties.title = 'Comparison of QCD control regions ({0} channel)'.format(
channel)
properties.path = 'plots'
properties.has_ratio = False
properties.xerr = True
properties.x_limits = (
bin_edges_vis[variable][0], bin_edges_vis[variable][-1])
properties.x_axis_title = variables_latex[variable]
properties.y_axis_title = 'number of QCD events'
histograms = {'control region 1': h_ctrl1,
'control region 2': h_ctrl2,
'MC prediction': h_qcd}
diff = absolute(h_ctrl1 - h_ctrl2)
lower = h_ctrl1 - diff
upper = h_ctrl1 + diff
err_e = ErrorBand('uncertainty', lower, upper)
plot_e = Plot(histograms, properties)
plot_e.draw_method = 'errorbar'
plot_e.add_error_band(err_e)
compare_histograms(plot_e)