def plotHistograms( histogram_files, var_to_plot, output_folder): ''' ''' global measurement_config weightBranchSignalRegion = 'EventWeight * PUWeight * BJetWeight' weightBranchControlRegion = 'EventWeight' # Names of QCD regions to use qcd_data_region = '' qcd_data_region_electron = 'QCD non iso e+jets' qcd_data_region_muon = 'QCD non iso mu+jets 1p5to3' sr_e_tree = 'TTbar_plus_X_analysis/EPlusJets/Ref selection/AnalysisVariables' sr_mu_tree = 'TTbar_plus_X_analysis/MuPlusJets/Ref selection/AnalysisVariables' cr_e_tree = 'TTbar_plus_X_analysis/EPlusJets/{}/AnalysisVariables'.format(qcd_data_region_electron) cr_mu_tree = 'TTbar_plus_X_analysis/MuPlusJets/{}/AnalysisVariables'.format(qcd_data_region_muon) print "Trees : " print "\t {}".format(sr_e_tree) print "\t {}".format(sr_mu_tree) print "\t {}".format(cr_e_tree) print "\t {}".format(cr_mu_tree) histogram_files_electron = dict(histogram_files) histogram_files_electron['data'] = measurement_config.data_file_electron histogram_files_electron['QCD'] = measurement_config.electron_QCD_MC_trees histogram_files_muon = dict(histogram_files) histogram_files_muon['data'] = measurement_config.data_file_muon histogram_files_muon['QCD'] = measurement_config.muon_QCD_MC_trees signal_region_hists = {} control_region_hists = {} for var in var_to_plot: selectionSignalRegion = '{} >= 0'.format(var) # Print all the weights applied to this plot print "Variable : {}".format(var) print "Weight applied : {}".format(weightBranchSignalRegion) print "Selection applied : {}".format(selectionSignalRegion) histograms_electron = get_histograms_from_trees( trees = [sr_e_tree], branch = var, weightBranch = weightBranchSignalRegion + ' * ElectronEfficiencyCorrection', files = histogram_files_electron, nBins = 20, xMin = control_plots_bins[var][0], xMax = control_plots_bins[var][-1], selection = selectionSignalRegion ) histograms_muon = get_histograms_from_trees( trees = [sr_mu_tree], branch = var, weightBranch = weightBranchSignalRegion + ' * MuonEfficiencyCorrection', files = histogram_files_muon, nBins = 20, xMin = control_plots_bins[var][0], xMax = control_plots_bins[var][-1], selection = selectionSignalRegion ) histograms_electron_QCDControlRegion = get_histograms_from_trees( trees = [cr_e_tree], branch = var, weightBranch = weightBranchControlRegion, files = histogram_files_electron, nBins = 20, xMin = control_plots_bins[var][0], xMax = control_plots_bins[var][-1], selection = selectionSignalRegion ) histograms_muon_QCDControlRegion = get_histograms_from_trees( trees = [cr_mu_tree], branch = var, weightBranch = weightBranchControlRegion, files = histogram_files_muon, nBins = 20, xMin = control_plots_bins[var][0], xMax = control_plots_bins[var][-1], selection = selectionSignalRegion ) # Combine the electron and muon histograms for sample in histograms_electron: h_electron = histograms_electron[sample][sr_e_tree] h_muon = histograms_muon[sample][sr_mu_tree] h_qcd_electron = histograms_electron_QCDControlRegion[sample][cr_e_tree] h_qcd_muon = histograms_muon_QCDControlRegion[sample][cr_mu_tree] signal_region_hists[sample] = h_electron + h_muon control_region_hists[sample] = h_qcd_electron + h_qcd_muon # NORMALISE TO LUMI prepare_histograms( signal_region_hists, scale_factor = measurement_config.luminosity_scale ) prepare_histograms( control_region_hists, scale_factor = measurement_config.luminosity_scale ) # BACKGROUND SUBTRACTION FOR QCD qcd_from_data = None qcd_from_data = clean_control_region( control_region_hists, subtract = ['TTJet', 'V+Jets', 'SingleTop'] ) # DATA DRIVEN QCD nBins = signal_region_hists['QCD'].GetNbinsX() n, error = signal_region_hists['QCD'].integral(0,nBins+1,error=True) n_qcd_predicted_mc_signal = ufloat( n, error) n, error = control_region_hists['QCD'].integral(0,nBins+1,error=True) n_qcd_predicted_mc_control = ufloat( n, error) n, error = qcd_from_data.integral(0,nBins+1,error=True) n_qcd_control_region = ufloat( n, error) dataDrivenQCDScale = n_qcd_predicted_mc_signal / n_qcd_predicted_mc_control qcd_from_data.Scale( dataDrivenQCDScale.nominal_value ) signal_region_hists['QCD'] = qcd_from_data # PLOTTING histograms_to_draw = [] histogram_lables = [] histogram_colors = [] histograms_to_draw = [ # signal_region_hists['data'], # qcd_from_data, # signal_region_hists['V+Jets'], signal_region_hists['SingleTop'], signal_region_hists['ST_s'], signal_region_hists['ST_t'], signal_region_hists['ST_tW'], signal_region_hists['STbar_t'], signal_region_hists['STbar_tW'], # signal_region_hists['TTJet'], ] histogram_lables = [ 'data', # 'QCD', # 'V+Jets', # 'Single-Top', 'ST-s', 'ST-t', 'ST-tW', 'STbar-t', 'STbar-tW', # samples_latex['TTJet'], ] histogram_colors = [ colours['data'], # colours['QCD'], # colours['V+Jets'], # colours['Single-Top'], colours['ST_s'], colours['ST_t'], colours['ST_tW'], colours['STbar_t'], colours['STbar_tW'], # colours['TTJet'], ] # Find maximum y of samples maxData = max( list(signal_region_hists['SingleTop'].y()) ) y_limits = [0, maxData * 1.5] log_y = False if log_y: y_limits = [0.1, maxData * 100 ] # Lumi title of plots title_template = '%.1f fb$^{-1}$ (%d TeV)' title = title_template % ( measurement_config.new_luminosity/1000., measurement_config.centre_of_mass_energy ) x_axis_title = '$%s$ [GeV]' % variables_latex[var] y_axis_title = 'Events/(%i GeV)' % binWidth(control_plots_bins[var]) # More histogram settings to look semi decent histogram_properties = Histogram_properties() histogram_properties.name = var + '_with_ratio' histogram_properties.title = title histogram_properties.x_axis_title = x_axis_title histogram_properties.y_axis_title = y_axis_title histogram_properties.x_limits = control_plots_bins[var] histogram_properties.y_limits = y_limits histogram_properties.y_max_scale = 1.4 histogram_properties.xerr = None histogram_properties.emptybins = True histogram_properties.additional_text = channel_latex['combined'] histogram_properties.legend_location = ( 0.9, 0.73 ) histogram_properties.cms_logo_location = 'left' histogram_properties.preliminary = True histogram_properties.set_log_y = log_y histogram_properties.legend_color = False histogram_properties.ratio_y_limits = [0.1,1.9] if log_y: histogram_properties.name += '_logy' loc = histogram_properties.legend_location 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, ) histogram_properties.name = var + '_ST_TTJet_Shape' if log_y: histogram_properties.name += '_logy' histogram_properties.y_axis_title = 'Normalised Distribution' histogram_properties.y_limits = [0,0.5] make_shape_comparison_plot( shapes = [ signal_region_hists['TTJet'], signal_region_hists['ST_t'], signal_region_hists['ST_tW'], signal_region_hists['ST_s'], signal_region_hists['STbar_t'], signal_region_hists['STbar_tW'], ], names = [ samples_latex['TTJet'], 'Single-Top t channel', 'Single-Top tW channel', 'Single-Top s channel', 'Single-AntiTop t channel', 'Single-AntiTop tW channel', ], colours = [ colours['TTJet'], colours['ST_t'], colours['ST_tW'], colours['ST_s'], colours['STbar_t'], colours['STbar_tW'], ], histogram_properties = histogram_properties, save_folder = output_folder, fill_area = False, add_error_bars = False, save_as = ['pdf'], make_ratio = True, alpha = 1, ) print_output(signal_region_hists, output_folder, var, 'combined') return
def plotHistograms(histogram_files, var_to_plot, output_folder): ''' ''' global measurement_config weightBranchSignalRegion = 'EventWeight * PUWeight * BJetWeight' weightBranchControlRegion = 'EventWeight' # Names of QCD regions to use qcd_data_region = '' qcd_data_region_electron = 'QCD non iso e+jets' qcd_data_region_muon = 'QCD non iso mu+jets 1p5to3' sr_e_tree = 'TTbar_plus_X_analysis/EPlusJets/Ref selection/AnalysisVariables' sr_mu_tree = 'TTbar_plus_X_analysis/MuPlusJets/Ref selection/AnalysisVariables' cr_e_tree = 'TTbar_plus_X_analysis/EPlusJets/{}/AnalysisVariables'.format( qcd_data_region_electron) cr_mu_tree = 'TTbar_plus_X_analysis/MuPlusJets/{}/AnalysisVariables'.format( qcd_data_region_muon) print "Trees : " print "\t {}".format(sr_e_tree) print "\t {}".format(sr_mu_tree) print "\t {}".format(cr_e_tree) print "\t {}".format(cr_mu_tree) histogram_files_electron = dict(histogram_files) histogram_files_electron['data'] = measurement_config.data_file_electron histogram_files_electron['QCD'] = measurement_config.electron_QCD_MC_trees histogram_files_muon = dict(histogram_files) histogram_files_muon['data'] = measurement_config.data_file_muon histogram_files_muon['QCD'] = measurement_config.muon_QCD_MC_trees signal_region_hists = {} control_region_hists = {} for var in var_to_plot: selectionSignalRegion = '{} >= 0'.format(var) # Print all the weights applied to this plot print "Variable : {}".format(var) print "Weight applied : {}".format(weightBranchSignalRegion) print "Selection applied : {}".format(selectionSignalRegion) histograms_electron = get_histograms_from_trees( trees=[sr_e_tree], branch=var, weightBranch=weightBranchSignalRegion + ' * ElectronEfficiencyCorrection', files=histogram_files_electron, nBins=20, xMin=control_plots_bins[var][0], xMax=control_plots_bins[var][-1], selection=selectionSignalRegion) histograms_muon = get_histograms_from_trees( trees=[sr_mu_tree], branch=var, weightBranch=weightBranchSignalRegion + ' * MuonEfficiencyCorrection', files=histogram_files_muon, nBins=20, xMin=control_plots_bins[var][0], xMax=control_plots_bins[var][-1], selection=selectionSignalRegion) histograms_electron_QCDControlRegion = get_histograms_from_trees( trees=[cr_e_tree], branch=var, weightBranch=weightBranchControlRegion, files=histogram_files_electron, nBins=20, xMin=control_plots_bins[var][0], xMax=control_plots_bins[var][-1], selection=selectionSignalRegion) histograms_muon_QCDControlRegion = get_histograms_from_trees( trees=[cr_mu_tree], branch=var, weightBranch=weightBranchControlRegion, files=histogram_files_muon, nBins=20, xMin=control_plots_bins[var][0], xMax=control_plots_bins[var][-1], selection=selectionSignalRegion) # Combine the electron and muon histograms for sample in histograms_electron: h_electron = histograms_electron[sample][sr_e_tree] h_muon = histograms_muon[sample][sr_mu_tree] h_qcd_electron = histograms_electron_QCDControlRegion[sample][ cr_e_tree] h_qcd_muon = histograms_muon_QCDControlRegion[sample][cr_mu_tree] signal_region_hists[sample] = h_electron + h_muon control_region_hists[sample] = h_qcd_electron + h_qcd_muon # NORMALISE TO LUMI prepare_histograms(signal_region_hists, scale_factor=measurement_config.luminosity_scale) prepare_histograms(control_region_hists, scale_factor=measurement_config.luminosity_scale) # BACKGROUND SUBTRACTION FOR QCD qcd_from_data = None qcd_from_data = clean_control_region( control_region_hists, subtract=['TTJet', 'V+Jets', 'SingleTop']) # DATA DRIVEN QCD nBins = signal_region_hists['QCD'].GetNbinsX() n, error = signal_region_hists['QCD'].integral(0, nBins + 1, error=True) n_qcd_predicted_mc_signal = ufloat(n, error) n, error = control_region_hists['QCD'].integral(0, nBins + 1, error=True) n_qcd_predicted_mc_control = ufloat(n, error) n, error = qcd_from_data.integral(0, nBins + 1, error=True) n_qcd_control_region = ufloat(n, error) dataDrivenQCDScale = n_qcd_predicted_mc_signal / n_qcd_predicted_mc_control qcd_from_data.Scale(dataDrivenQCDScale.nominal_value) signal_region_hists['QCD'] = qcd_from_data # PLOTTING histograms_to_draw = [] histogram_lables = [] histogram_colors = [] histograms_to_draw = [ # signal_region_hists['data'], # qcd_from_data, # signal_region_hists['V+Jets'], signal_region_hists['SingleTop'], signal_region_hists['ST_s'], signal_region_hists['ST_t'], signal_region_hists['ST_tW'], signal_region_hists['STbar_t'], signal_region_hists['STbar_tW'], # signal_region_hists['TTJet'], ] histogram_lables = [ 'data', # 'QCD', # 'V+Jets', # 'Single-Top', 'ST-s', 'ST-t', 'ST-tW', 'STbar-t', 'STbar-tW', # samples_latex['TTJet'], ] histogram_colors = [ colours['data'], # colours['QCD'], # colours['V+Jets'], # colours['Single-Top'], colours['ST_s'], colours['ST_t'], colours['ST_tW'], colours['STbar_t'], colours['STbar_tW'], # colours['TTJet'], ] # Find maximum y of samples maxData = max(list(signal_region_hists['SingleTop'].y())) y_limits = [0, maxData * 1.5] log_y = False if log_y: y_limits = [0.1, maxData * 100] # Lumi title of plots title_template = '%.1f fb$^{-1}$ (%d TeV)' title = title_template % (measurement_config.new_luminosity / 1000., measurement_config.centre_of_mass_energy) x_axis_title = '$%s$ [GeV]' % variables_latex[var] y_axis_title = 'Events/(%i GeV)' % binWidth(control_plots_bins[var]) # More histogram settings to look semi decent histogram_properties = Histogram_properties() histogram_properties.name = var + '_with_ratio' histogram_properties.title = title histogram_properties.x_axis_title = x_axis_title histogram_properties.y_axis_title = y_axis_title histogram_properties.x_limits = control_plots_bins[var] histogram_properties.y_limits = y_limits histogram_properties.y_max_scale = 1.4 histogram_properties.xerr = None histogram_properties.emptybins = True histogram_properties.additional_text = channel_latex['combined'] histogram_properties.legend_location = (0.9, 0.73) histogram_properties.cms_logo_location = 'left' histogram_properties.preliminary = True histogram_properties.set_log_y = log_y histogram_properties.legend_color = False histogram_properties.ratio_y_limits = [0.1, 1.9] if log_y: histogram_properties.name += '_logy' loc = histogram_properties.legend_location 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, ) histogram_properties.name = var + '_ST_TTJet_Shape' if log_y: histogram_properties.name += '_logy' histogram_properties.y_axis_title = 'Normalised Distribution' histogram_properties.y_limits = [0, 0.5] make_shape_comparison_plot( shapes=[ signal_region_hists['TTJet'], signal_region_hists['ST_t'], signal_region_hists['ST_tW'], signal_region_hists['ST_s'], signal_region_hists['STbar_t'], signal_region_hists['STbar_tW'], ], names=[ samples_latex['TTJet'], 'Single-Top t channel', 'Single-Top tW channel', 'Single-Top s channel', 'Single-AntiTop t channel', 'Single-AntiTop tW channel', ], colours=[ colours['TTJet'], colours['ST_t'], colours['ST_tW'], colours['ST_s'], colours['STbar_t'], colours['STbar_tW'], ], histogram_properties=histogram_properties, save_folder=output_folder, fill_area=False, add_error_bars=False, save_as=['pdf'], make_ratio=True, alpha=1, ) print_output(signal_region_hists, output_folder, var, 'combined') return
def drawHistograms( dictionaryOfHistograms, uncertaintyBand, config, channel, variable ) : histograms_to_draw = [ dictionaryOfHistograms['Data'], dictionaryOfHistograms['QCD'], dictionaryOfHistograms['V+Jets'], dictionaryOfHistograms['SingleTop'], dictionaryOfHistograms['TTJet'], ] histogram_lables = [ 'data', 'QCD', 'V+jets', 'single-top', samples_latex['TTJet'], ] histogram_colors = [ colours['data'], colours['QCD'], colours['V+Jets'], colours['Single-Top'], colours['TTJet'], ] # Find maximum y of samples maxData = max( list(histograms_to_draw[0].y()) ) y_limits = [0, maxData * 1.4] # More histogram settings to look semi decent histogram_properties = Histogram_properties() histogram_properties.name = '{channel}_{variable}'.format(channel = channel, variable=variable) histogram_properties.title = '$%.1f$ fb$^{-1}$ (%d TeV)' % ( config.new_luminosity/1000., config.centre_of_mass_energy ) histogram_properties.x_axis_title = variables_latex[variable] histogram_properties.y_axis_title = 'Events' if variable in ['HT', 'ST', 'MET', 'WPT', 'lepton_pt']: histogram_properties.y_axis_title = 'Events / {binWidth} GeV'.format( binWidth=binWidth ) histogram_properties.x_axis_title = '{variable} (GeV)'.format( variable = variables_latex[variable] ) histogram_properties.x_limits = [ reco_bin_edges[0], reco_bin_edges[-1] ] histogram_properties.y_limits = y_limits histogram_properties.y_max_scale = 1.3 histogram_properties.xerr = None # workaround for rootpy issue #638 histogram_properties.emptybins = True histogram_properties.additional_text = channel_latex[channel.lower()] histogram_properties.legend_location = ( 0.9, 0.73 ) histogram_properties.cms_logo_location = 'left' histogram_properties.preliminary = True # histogram_properties.preliminary = False histogram_properties.set_log_y = False histogram_properties.legend_color = False histogram_properties.ratio_y_limits = [0.5, 1.5] # Draw histogram with ratio plot 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 = 'plots/control_plots_with_systematic/', show_ratio = True, normalise = False, systematics_for_ratio = uncertaintyBand, systematics_for_plot = uncertaintyBand, ) histogram_properties.set_log_y = True histogram_properties.y_limits = [0.1, y_limits[-1]*100 ] histogram_properties.legend_location = ( 0.9, 0.9 ) histogram_properties.name += '_logY' make_data_mc_comparison_plot( histograms_to_draw, histogram_lables, histogram_colors, histogram_properties, save_folder = 'plots/control_plots_with_systematic/logY/', show_ratio = True, normalise = False, systematics_for_ratio = uncertaintyBand, systematics_for_plot = uncertaintyBand, )
def make_ttbarReco_plot( channel, x_axis_title, y_axis_title, signal_region_tree, control_region_tree, branchName, name_prefix, x_limits, nBins, use_qcd_data_region=False, y_limits=[], y_max_scale=1.2, rebin=1, legend_location=(0.98, 0.78), cms_logo_location='right', log_y=False, legend_color=False, ratio_y_limits=[0.3, 1.7], normalise=False, ): global output_folder, measurement_config, category, normalise_to_fit global preliminary, norm_variable, sum_bins, b_tag_bin, histogram_files # Input files, normalisations, tree/region names qcd_data_region = '' title = title_template % (measurement_config.new_luminosity / 1000., measurement_config.centre_of_mass_energy) normalisation = None if channel == 'electron': histogram_files['data'] = measurement_config.data_file_electron_trees histogram_files[ 'QCD'] = measurement_config.electron_QCD_MC_category_templates_trees[ category] if normalise_to_fit: normalisation = normalisations_electron[norm_variable] if use_qcd_data_region: qcd_data_region = 'QCDConversions' if channel == 'muon': histogram_files['data'] = measurement_config.data_file_muon_trees histogram_files[ 'QCD'] = measurement_config.muon_QCD_MC_category_templates_trees[ category] if normalise_to_fit: normalisation = normalisations_muon[norm_variable] if use_qcd_data_region: qcd_data_region = 'QCD non iso mu+jets ge3j' histograms = get_histograms_from_trees( trees=[signal_region_tree, control_region_tree], branch=branchName, weightBranch='1', files=histogram_files, nBins=nBins, xMin=x_limits[0], xMax=x_limits[-1]) selection = 'SolutionCategory == 0' histogramsNoSolution = 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 == 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, )
def make_ttbarReco_plot( channel, x_axis_title, y_axis_title, signal_region_tree, control_region_tree, branchName, name_prefix, x_limits, nBins, use_qcd_data_region = False, y_limits = [], y_max_scale = 1.2, rebin = 1, legend_location = ( 0.98, 0.78 ), cms_logo_location = 'right', log_y = False, legend_color = False, ratio_y_limits = [0.3, 1.7], normalise = False, ): global output_folder, measurement_config, category, normalise_to_fit global preliminary, norm_variable, sum_bins, b_tag_bin, histogram_files # Input files, normalisations, tree/region names qcd_data_region = '' title = title_template % ( measurement_config.new_luminosity / 1000., measurement_config.centre_of_mass_energy ) normalisation = None if channel == 'electron': histogram_files['data'] = measurement_config.data_file_electron_trees histogram_files['QCD'] = measurement_config.electron_QCD_MC_category_templates_trees[category] if normalise_to_fit: normalisation = normalisations_electron[norm_variable] if use_qcd_data_region: qcd_data_region = 'QCDConversions' if channel == 'muon': histogram_files['data'] = measurement_config.data_file_muon_trees histogram_files['QCD'] = measurement_config.muon_QCD_MC_category_templates_trees[category] if normalise_to_fit: normalisation = normalisations_muon[norm_variable] if use_qcd_data_region: qcd_data_region = 'QCD non iso mu+jets ge3j' histograms = get_histograms_from_trees( trees = [signal_region_tree, control_region_tree], branch = branchName, weightBranch = '1', files = histogram_files, nBins = nBins, xMin = x_limits[0], xMax = x_limits[-1] ) selection = 'SolutionCategory == 0' histogramsNoSolution = 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 == 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, )