예제 #1
0
def get_best_tau(regularisation_settings):
    '''
        returns TODO
         - optimal_tau: TODO
    '''
    h_truth, h_response, h_measured, h_data, h_fakes = regularisation_settings.get_histograms(
    )
    variable = regularisation_settings.variable

    h_data = removeFakes(h_measured, h_fakes, h_data)

    unfolding = Unfolding(h_data,
                          h_truth,
                          h_measured,
                          h_response,
                          fakes=None,
                          method='TUnfold',
                          tau=-1)

    # bestTau_LCurve = tau_from_L_curve( unfolding.unfoldObject )
    # unfolding.tau = bestTau_LCurve

    bestTauScan = tau_from_scan(unfolding.unfoldObject,
                                regularisation_settings)
    unfolding.tau = bestTauScan

    return unfolding.tau
def get_best_tau( regularisation_settings ):
    '''
        returns TODO
         - optimal_tau: TODO
    '''
    h_truth, h_response, h_measured, h_data, h_fakes = regularisation_settings.get_histograms()
    variable = regularisation_settings.variable

    h_data = removeFakes( h_measured, h_fakes, h_data )

    unfolding = Unfolding( 
                            h_data, 
                            h_truth, 
                            h_measured, 
                            h_response,
                            fakes = None,
                            method = 'TUnfold', 
                            tau = -1
                        )

    # bestTau_LCurve = tau_from_L_curve( unfolding.unfoldObject )
    # unfolding.tau = bestTau_LCurve

    bestTauScan = tau_from_scan( unfolding.unfoldObject, regularisation_settings )
    unfolding.tau = bestTauScan

    return unfolding.tau
def unfold_results( results, category, channel, tau_value, h_truth, h_measured, h_response, h_fakes, method, visiblePS ):
    global variable, path_to_DF, args

    edges = reco_bin_edges_full[variable]
    if visiblePS:
        edges = reco_bin_edges_vis[variable]

    h_data = value_error_tuplelist_to_hist( results, edges )

    # Rebin original TTJet_Measured in terms of final binning (h_data is later replaced with h_data_no_fakes)
    h_data_rebinned = h_data.rebinned(2)

    # Remove fakes before unfolding
    h_data_no_fakes = removeFakes( h_measured, h_fakes, h_data )

    # unfold
    unfolding = Unfolding( h_data_no_fakes, h_truth, h_measured, h_response, h_fakes, method = method, tau = tau_value )

    # turning off the unfolding errors for systematic samples
    if not category == 'central':
        unfoldCfg.error_treatment = 0
    else:
        unfoldCfg.error_treatment = args.error_treatment

    h_unfolded_data = unfolding.unfold()
    h_data_no_fakes = h_data_no_fakes.rebinned(2)
    covariance_matrix = None
    if category == 'central':
        # Return the covariance matrices (They have been normailsed)
        covariance_matrix, correlation_matrix = unfolding.get_covariance_matrix()

        # Write covariance matrices
        covariance_output_tempalte = '{path_to_DF}/central/covarianceMatrices/{cat}_{label}_{channel}.txt'
        # Unfolded number of events
        table_outfile=covariance_output_tempalte.format( path_to_DF=path_to_DF, channel = channel, label='Covariance', cat='Stat_unfoldedNormalisation' )
        create_covariance_matrix( covariance_matrix, table_outfile)
        table_outfile=covariance_output_tempalte.format( path_to_DF=path_to_DF, channel = channel, label='Correlation', cat='Stat_unfoldedNormalisation' )
        create_covariance_matrix( correlation_matrix, table_outfile )
        # # Normalised cross section
        # table_outfile=covariance_output_tempalte.format( path_to_DF=path_to_DF, channel = channel, label='Covariance', cat='Stat_normalisedXsection' )
        # create_covariance_matrix( norm_covariance_matrix, table_outfile)
        # table_outfile=covariance_output_tempalte.format( path_to_DF=path_to_DF, channel = channel, label='Correlation', cat='Stat_normalisedXsection' )
        # create_covariance_matrix( norm_correlation_matrix, table_outfile )

    del unfolding
    return hist_to_value_error_tuplelist( h_data_rebinned ), hist_to_value_error_tuplelist( h_unfolded_data ), hist_to_value_error_tuplelist( h_data_no_fakes ), covariance_matrix
def unfold_results( results, category, channel, tau_value, h_truth, h_measured, h_response, h_fakes, method, visiblePS ):
    global variable, path_to_JSON, options
    edges = reco_bin_edges_full[variable]
    if visiblePS:
        edges = reco_bin_edges_vis[variable]
    h_data = value_error_tuplelist_to_hist( results, edges )

    # Remove fakes before unfolding
    h_data = removeFakes( h_measured, h_fakes, h_data )

    unfolding = Unfolding( h_data, h_truth, h_measured, h_response, h_fakes, method = method, tau = tau_value )

    # turning off the unfolding errors for systematic samples
    if not category == 'central':
        unfoldCfg.error_treatment = 0
    else:
        unfoldCfg.error_treatment = options.error_treatment

    h_unfolded_data = unfolding.unfold()
    print "h_response bin edges : ", h_response
    print "h_unfolded_data bin edges : ", h_unfolded_data

    del unfolding
    return hist_to_value_error_tuplelist( h_unfolded_data ), hist_to_value_error_tuplelist( h_data )
def main():

	config = XSectionConfig(13)

	file_for_powhegPythia  		= File(config.unfolding_central_firstHalf, 'read')
	file_for_ptReweight_up 		= File(config.unfolding_ptreweight_up_firstHalf, 'read')
	file_for_ptReweight_down 	= File(config.unfolding_ptreweight_down_firstHalf, 'read')
	file_for_amcatnlo_pythia8 			= File(config.unfolding_amcatnlo_pythia8, 'read')
	file_for_powhegHerwig 		= File(config.unfolding_powheg_herwig, 'read')
	file_for_etaReweight_up 	= File(config.unfolding_etareweight_up, 'read')
	file_for_etaReweight_down 	= File(config.unfolding_etareweight_down, 'read')
	file_for_data_template 		= 'data/normalisation/background_subtraction/13TeV/{variable}/VisiblePS/central/normalisation_{channel}.txt'

	for channel in config.analysis_types.keys():
		if channel is 'combined':continue
		for variable in config.variables:
			print variable
		# for variable in ['HT']:
			# Get the central powheg pythia distributions
			_, _, response_central, fakes_central = get_unfold_histogram_tuple(
				inputfile=file_for_powhegPythia,
				variable=variable,
				channel=channel,
				centre_of_mass=13,
				load_fakes=True,
				visiblePS=True
			)

			measured_central = asrootpy(response_central.ProjectionX('px',1))
			truth_central = asrootpy(response_central.ProjectionY())


			# Get the reweighted powheg pythia distributions
			_, _, response_pt_reweighted_up, _ = get_unfold_histogram_tuple(
				inputfile=file_for_ptReweight_up,
				variable=variable,
				channel=channel,
				centre_of_mass=13,
				load_fakes=False,
				visiblePS=True
			)

			measured_pt_reweighted_up = asrootpy(response_pt_reweighted_up.ProjectionX('px',1))
			truth_pt_reweighted_up = asrootpy(response_pt_reweighted_up.ProjectionY())

			_, _, response_pt_reweighted_down, _ = get_unfold_histogram_tuple(
				inputfile=file_for_ptReweight_down,
				variable=variable,
				channel=channel,
				centre_of_mass=13,
				load_fakes=False,
				visiblePS=True
			)

			measured_pt_reweighted_down = asrootpy(response_pt_reweighted_down.ProjectionX('px',1))
			truth_pt_reweighted_down = asrootpy(response_pt_reweighted_down.ProjectionY())

			# _, _, response_eta_reweighted_up, _ = get_unfold_histogram_tuple(
			# 	inputfile=file_for_etaReweight_up,
			# 	variable=variable,
			# 	channel=channel,
			# 	centre_of_mass=13,
			# 	load_fakes=False,
			# 	visiblePS=True
			# )

			# measured_eta_reweighted_up = asrootpy(response_eta_reweighted_up.ProjectionX('px',1))
			# truth_eta_reweighted_up = asrootpy(response_eta_reweighted_up.ProjectionY())

			# _, _, response_eta_reweighted_down, _ = get_unfold_histogram_tuple(
			# 	inputfile=file_for_etaReweight_down,
			# 	variable=variable,
			# 	channel=channel,
			# 	centre_of_mass=13,
			# 	load_fakes=False,
			# 	visiblePS=True
			# )

			# measured_eta_reweighted_down = asrootpy(response_eta_reweighted_down.ProjectionX('px',1))
			# truth_eta_reweighted_down = asrootpy(response_eta_reweighted_down.ProjectionY())

			# Get the distributions for other MC models
			_, _, response_amcatnlo_pythia8, _ = get_unfold_histogram_tuple(
				inputfile=file_for_amcatnlo_pythia8,
				variable=variable,
				channel=channel,
				centre_of_mass=13,
				load_fakes=False,
				visiblePS=True
			)

			measured_amcatnlo_pythia8 = asrootpy(response_amcatnlo_pythia8.ProjectionX('px',1))
			truth_amcatnlo_pythia8 = asrootpy(response_amcatnlo_pythia8.ProjectionY())

			_, _, response_powhegHerwig, _ = get_unfold_histogram_tuple(
				inputfile=file_for_powhegHerwig,
				variable=variable,
				channel=channel,
				centre_of_mass=13,
				load_fakes=False,
				visiblePS=True
			)

			measured_powhegHerwig = asrootpy(response_powhegHerwig.ProjectionX('px',1))
			truth_powhegHerwig = asrootpy(response_powhegHerwig.ProjectionY())

			# Get the data input (data after background subtraction, and fake removal)
			file_for_data = file_for_data_template.format( variable = variable, channel = channel )
			data = read_tuple_from_file(file_for_data)['TTJet']
			data = value_error_tuplelist_to_hist( data, reco_bin_edges_vis[variable] )
			data = removeFakes( measured_central, fakes_central, data )

			# Plot all three

			hp = Histogram_properties()
			hp.name = 'Reweighting_check_{channel}_{variable}_at_{com}TeV'.format(
				channel=channel,
				variable=variable,
				com='13',
			)

			v_latex = latex_labels.variables_latex[variable]
			unit = ''
			if variable in ['HT', 'ST', 'MET', 'WPT', 'lepton_pt']:
			    unit = ' [GeV]'
			hp.x_axis_title = v_latex + unit
			hp.x_limits = [ reco_bin_edges_vis[variable][0], reco_bin_edges_vis[variable][-1]]
			hp.ratio_y_limits = [0.1,1.9]
			hp.ratio_y_title = 'Reweighted / Central'
			hp.y_axis_title = 'Number of events'
			hp.title = 'Reweighting check for {variable}'.format(variable=v_latex)

			measured_central.Rebin(2)
			measured_pt_reweighted_up.Rebin(2)
			measured_pt_reweighted_down.Rebin(2)
			# measured_eta_reweighted_up.Rebin(2)
			# measured_eta_reweighted_down.Rebin(2)
			measured_amcatnlo_pythia8.Rebin(2)
			measured_powhegHerwig.Rebin(2)
			data.Rebin(2)

			measured_central.Scale( 1 / measured_central.Integral() )
			measured_pt_reweighted_up.Scale( 1 / measured_pt_reweighted_up.Integral() )
			measured_pt_reweighted_down.Scale( 1 / measured_pt_reweighted_down.Integral() )
			measured_amcatnlo_pythia8.Scale( 1 / measured_amcatnlo_pythia8.Integral() )
			measured_powhegHerwig.Scale( 1 / measured_powhegHerwig.Integral() )

			# measured_eta_reweighted_up.Scale( 1 / measured_eta_reweighted_up.Integral() )
			# measured_eta_reweighted_down.Scale( 1/ measured_eta_reweighted_down.Integral() )

			data.Scale( 1 / data.Integral() )

			print list(measured_central.y())
			print list(measured_amcatnlo_pythia8.y())
			print list(measured_powhegHerwig.y())
			print list(data.y())
			compare_measurements(
				# models = {'Central' : measured_central, 'PtReweighted Up' : measured_pt_reweighted_up, 'PtReweighted Down' : measured_pt_reweighted_down, 'EtaReweighted Up' : measured_eta_reweighted_up, 'EtaReweighted Down' : measured_eta_reweighted_down},
				models = OrderedDict([('Central' , measured_central), ('PtReweighted Up' , measured_pt_reweighted_up), ('PtReweighted Down' , measured_pt_reweighted_down), ('amc@nlo' , measured_amcatnlo_pythia8), ('powhegHerwig' , measured_powhegHerwig) ] ),
				measurements = {'Data' : data},
				show_measurement_errors=True,
				histogram_properties=hp,
				save_folder='plots/unfolding/reweighting_check',
				save_as=['pdf'],
                line_styles_for_models = ['solid','solid','solid','dashed','dashed'],
				show_ratio_for_pairs = OrderedDict( [ 
					('PtUpVsCentral' , [ measured_pt_reweighted_up, measured_central ] ),
					('PtDownVsCentral' , [ measured_pt_reweighted_down, measured_central ] ),
					('amcatnloVsCentral' , [ measured_amcatnlo_pythia8, measured_central ] ),
					('powhegHerwigVsCentral' , [ measured_powhegHerwig, measured_central ] ),
					('DataVsCentral' , [data, measured_central] ) 
					]),
			)
def main():

    config = XSectionConfig(13)

    file_for_powhegPythia = File(config.unfolding_central, "read")
    file_for_ptReweight_up = File(config.unfolding_ptreweight_up, "read")
    file_for_ptReweight_down = File(config.unfolding_ptreweight_down, "read")
    file_for_etaReweight_up = File(config.unfolding_etareweight_up, "read")
    file_for_etaReweight_down = File(config.unfolding_etareweight_down, "read")
    file_for_data_template = "data/normalisation/background_subtraction/13TeV/{variable}/VisiblePS/central/normalisation_combined_patType1CorrectedPFMet.txt"

    for channel in ["combined"]:
        for variable in config.variables:
            print variable
            # for variable in ['HT']:
            # Get the central powheg pythia distributions
            _, _, response_central, fakes_central = get_unfold_histogram_tuple(
                inputfile=file_for_powhegPythia,
                variable=variable,
                channel=channel,
                centre_of_mass=13,
                load_fakes=True,
                visiblePS=True,
            )

            measured_central = asrootpy(response_central.ProjectionX("px", 1))
            truth_central = asrootpy(response_central.ProjectionY())

            # Get the reweighted powheg pythia distributions
            _, _, response_pt_reweighted_up, _ = get_unfold_histogram_tuple(
                inputfile=file_for_ptReweight_up,
                variable=variable,
                channel=channel,
                centre_of_mass=13,
                load_fakes=False,
                visiblePS=True,
            )

            measured_pt_reweighted_up = asrootpy(response_pt_reweighted_up.ProjectionX("px", 1))
            truth_pt_reweighted_up = asrootpy(response_pt_reweighted_up.ProjectionY())

            _, _, response_pt_reweighted_down, _ = get_unfold_histogram_tuple(
                inputfile=file_for_ptReweight_down,
                variable=variable,
                channel=channel,
                centre_of_mass=13,
                load_fakes=False,
                visiblePS=True,
            )

            measured_pt_reweighted_down = asrootpy(response_pt_reweighted_down.ProjectionX("px", 1))
            truth_pt_reweighted_down = asrootpy(response_pt_reweighted_down.ProjectionY())

            _, _, response_eta_reweighted_up, _ = get_unfold_histogram_tuple(
                inputfile=file_for_etaReweight_up,
                variable=variable,
                channel=channel,
                centre_of_mass=13,
                load_fakes=False,
                visiblePS=True,
            )

            measured_eta_reweighted_up = asrootpy(response_eta_reweighted_up.ProjectionX("px", 1))
            truth_eta_reweighted_up = asrootpy(response_eta_reweighted_up.ProjectionY())

            _, _, response_eta_reweighted_down, _ = get_unfold_histogram_tuple(
                inputfile=file_for_etaReweight_down,
                variable=variable,
                channel=channel,
                centre_of_mass=13,
                load_fakes=False,
                visiblePS=True,
            )

            measured_eta_reweighted_down = asrootpy(response_eta_reweighted_down.ProjectionX("px", 1))
            truth_eta_reweighted_down = asrootpy(response_eta_reweighted_down.ProjectionY())

            # Get the data input (data after background subtraction, and fake removal)
            file_for_data = file_for_data_template.format(variable=variable)
            data = read_data_from_JSON(file_for_data)["TTJet"]
            data = value_error_tuplelist_to_hist(data, reco_bin_edges_vis[variable])
            data = removeFakes(measured_central, fakes_central, data)

            # Plot all three

            hp = Histogram_properties()
            hp.name = "Reweighting_check_{channel}_{variable}_at_{com}TeV".format(
                channel=channel, variable=variable, com="13"
            )

            v_latex = latex_labels.variables_latex[variable]
            unit = ""
            if variable in ["HT", "ST", "MET", "WPT", "lepton_pt"]:
                unit = " [GeV]"
            hp.x_axis_title = v_latex + unit
            hp.y_axis_title = "Number of events"
            hp.title = "Reweighting check for {variable}".format(variable=v_latex)

            measured_central.Rebin(2)
            measured_pt_reweighted_up.Rebin(2)
            measured_pt_reweighted_down.Rebin(2)
            measured_eta_reweighted_up.Rebin(2)
            measured_eta_reweighted_down.Rebin(2)
            data.Rebin(2)

            measured_central.Scale(1 / measured_central.Integral())
            measured_pt_reweighted_up.Scale(1 / measured_pt_reweighted_up.Integral())
            measured_pt_reweighted_down.Scale(1 / measured_pt_reweighted_down.Integral())
            measured_eta_reweighted_up.Scale(1 / measured_eta_reweighted_up.Integral())
            measured_eta_reweighted_down.Scale(1 / measured_eta_reweighted_down.Integral())

            data.Scale(1 / data.Integral())

            compare_measurements(
                models={
                    "Central": measured_central,
                    "PtReweighted Up": measured_pt_reweighted_up,
                    "PtReweighted Down": measured_pt_reweighted_down,
                    "EtaReweighted Up": measured_eta_reweighted_up,
                    "EtaReweighted Down": measured_eta_reweighted_down,
                },
                measurements={"Data": data},
                show_measurement_errors=True,
                histogram_properties=hp,
                save_folder="plots/unfolding/reweighting_check",
                save_as=["pdf"],
            )
예제 #7
0
def get_chi2s_of_tau_range( regularisation_settings, args, unfold_test=False ):
    '''
        Takes each tau value, unfolds and refolds, calcs the chi2, the prob of chi2 given ndf (n_bins)
        and returns a dictionary of (1-P(Chi2|NDF)) for each tau
        For measured test where we only worry about tau=0 outputs tau variables to data frame (+smeared measured values)
    '''
    h_truth, h_response, h_measured, h_data, h_fakes = regularisation_settings.get_histograms()
    if not args.run_measured_as_data : 
        h_data = removeFakes( h_measured, h_fakes, h_data )
    variable = regularisation_settings.variable
    taus = regularisation_settings.taus_to_test
    chi2_ndf = []

    for tau in taus:

        unfolding = Unfolding( 
            h_data, 
            h_truth, 
            h_measured, 
            h_response,
            fakes = None,#Fakes or no?
            method = 'TUnfold', 
            tau = tau
        )
        # Cannot refold without first unfolding
        h_unfolded_data = unfolding.unfold()
        h_refolded_data = unfolding.refold()

        # print("Data")
        # print (hist_to_value_error_tuplelist(h_data))
        # print("Unfolded Data")
        # print (hist_to_value_error_tuplelist(h_unfolded_data))
        # print("Refolded Data")
        # print (hist_to_value_error_tuplelist(h_refolded_data))

        regularisation_settings.h_refolded = h_refolded_data
        ndf = regularisation_settings.ndf

        if args.run_refold_plots:
            plot_data_vs_refold(args, regularisation_settings, tau)
        if args.unfolded_binning:
            unfolding.refolded_data = h_refolded_data.rebinned(2)
            unfolding.data = h_data.rebinned(2)
            ndf = int(regularisation_settings.ndf / 2)
            # print("Data")
            # print (hist_to_value_error_tuplelist(regularisation_settings.h_data))
            # print("Refolded Data")
            # print (hist_to_value_error_tuplelist(regularisation_settings.h_refolded))

        chi2 = unfolding.getUnfoldRefoldChi2()
        prob = TMath.Prob( chi2, ndf ) 
        chi2_ndf.append(1-prob)
        # print( tau, chi2, prob, 1-prob )

    # Create pandas dictionary
    d_chi2 = {variable : pd.Series( chi2_ndf )}
    d_taus = {'tau' : pd.Series( taus )}

    if unfold_test: 
        d_tau_vars = {
            variable : {
                'Tau' : tau,
                'Chi2' : chi2,
                'Prob' : prob,
                '1-Prob' : 1-prob,
            }
        }
        df_unfold_tests = tau_vars_to_df(d_tau_vars, regularisation_settings)
        return df_unfold_tests

    df_chi2 = chi2_to_df(d_chi2, d_taus, regularisation_settings )
    return df_chi2
예제 #8
0
def get_chi2( regularisation_settings, args, smearing_test=False ):
    '''
        Takes each tau value, unfolds and refolds, calcs the chi2, the prob of chi2 given ndf (n_bins)
        and returns a dictionary of (1-P(Chi2|NDF)) for each tau
        For measured test where we only worry about tau=0 outputs tau variables to data frame (+smeared measured values)
    '''
    h_truth, h_response, h_measured, h_data, h_fakes = regularisation_settings.get_histograms()

    # Dont remove any fakes if we are using the true mc distribution
    if not args.run_measured_as_data or not args.run_smeared_measured_as_data: 
        h_data = removeFakes( h_measured, h_fakes, h_data )
    variable = regularisation_settings.variable
    taus = regularisation_settings.taus_to_test
    chi2_ndf = []

    for tau in taus:
        unfolding = Unfolding( 
            h_data, 
            h_truth, 
            h_measured, 
            h_response,
            fakes = None,#Fakes or no?
            method = 'TUnfold', 
            tau = tau
        )

        # Cannot refold without first unfolding
        h_unfolded_data = unfolding.unfold()
        h_refolded_data = unfolding.refold()

        # print("Data")
        # print (hist_to_value_error_tuplelist(h_data))
        # print("Unfolded Data")
        # print (hist_to_value_error_tuplelist(h_unfolded_data))
        # print("Refolded Data")
        # print (hist_to_value_error_tuplelist(h_refolded_data))

        regularisation_settings.h_refolded = h_refolded_data
        ndf = regularisation_settings.ndf

        if args.unfolded_binning:
            unfolding.refolded_data = h_refolded_data.rebinned(2)
            unfolding.data = h_data.rebinned(2)
            ndf = int(regularisation_settings.ndf / 2)
            regularisation_settings.h_refolded = unfolding.refolded_data
            regularisation_settings.h_data = unfolding.data
        if args.create_refold_plots:
            plot_data_vs_refold(args, regularisation_settings, tau)

        # Calculate the chi2 between refold and unfold 
        chi2 = unfolding.getUnfoldRefoldChi2()
        # Calculate the Prob chi2 given NDF
        prob = TMath.Prob( chi2, ndf ) 
        # 1-P(Chi2|NDF)
        chi2_ndf.append(1-prob)
        # print( tau, chi2, prob, 1-prob )

    # Create tau and Chi2 dictionary
    d_chi2 = {variable : pd.Series( chi2_ndf )}
    d_taus = {'tau' : pd.Series( taus )}

    if smearing_test: 
        d_tau_vars = {
            variable : {
                'Tau' : tau,
                'Chi2' : chi2,
                'Prob' : prob,
                '1-Prob' : 1-prob,
            }
        }
        df_unfold_tests = tau_vars_to_df(d_tau_vars, regularisation_settings)
        return df_unfold_tests

    df_chi2 = chi2_to_df(d_chi2, d_taus, regularisation_settings )
    return df_chi2
예제 #9
0
def main():

    config = XSectionConfig(13)

    file_for_powhegPythia = File(config.unfolding_central_firstHalf, 'read')
    file_for_ptReweight_up = File(config.unfolding_ptreweight_up_firstHalf,
                                  'read')
    file_for_ptReweight_down = File(config.unfolding_ptreweight_down_firstHalf,
                                    'read')
    file_for_amcatnlo_pythia8 = File(config.unfolding_amcatnlo_pythia8, 'read')
    file_for_powhegHerwig = File(config.unfolding_powheg_herwig, 'read')
    file_for_etaReweight_up = File(config.unfolding_etareweight_up, 'read')
    file_for_etaReweight_down = File(config.unfolding_etareweight_down, 'read')
    file_for_data_template = 'data/normalisation/background_subtraction/13TeV/{variable}/VisiblePS/central/normalisation_{channel}.txt'

    for channel in config.analysis_types.keys():
        if channel is 'combined': continue
        for variable in config.variables:
            print variable
            # for variable in ['HT']:
            # Get the central powheg pythia distributions
            _, _, response_central, fakes_central = get_unfold_histogram_tuple(
                inputfile=file_for_powhegPythia,
                variable=variable,
                channel=channel,
                centre_of_mass=13,
                load_fakes=True,
                visiblePS=True)

            measured_central = asrootpy(response_central.ProjectionX('px', 1))
            truth_central = asrootpy(response_central.ProjectionY())

            # Get the reweighted powheg pythia distributions
            _, _, response_pt_reweighted_up, _ = get_unfold_histogram_tuple(
                inputfile=file_for_ptReweight_up,
                variable=variable,
                channel=channel,
                centre_of_mass=13,
                load_fakes=False,
                visiblePS=True)

            measured_pt_reweighted_up = asrootpy(
                response_pt_reweighted_up.ProjectionX('px', 1))
            truth_pt_reweighted_up = asrootpy(
                response_pt_reweighted_up.ProjectionY())

            _, _, response_pt_reweighted_down, _ = get_unfold_histogram_tuple(
                inputfile=file_for_ptReweight_down,
                variable=variable,
                channel=channel,
                centre_of_mass=13,
                load_fakes=False,
                visiblePS=True)

            measured_pt_reweighted_down = asrootpy(
                response_pt_reweighted_down.ProjectionX('px', 1))
            truth_pt_reweighted_down = asrootpy(
                response_pt_reweighted_down.ProjectionY())

            # _, _, response_eta_reweighted_up, _ = get_unfold_histogram_tuple(
            # 	inputfile=file_for_etaReweight_up,
            # 	variable=variable,
            # 	channel=channel,
            # 	centre_of_mass=13,
            # 	load_fakes=False,
            # 	visiblePS=True
            # )

            # measured_eta_reweighted_up = asrootpy(response_eta_reweighted_up.ProjectionX('px',1))
            # truth_eta_reweighted_up = asrootpy(response_eta_reweighted_up.ProjectionY())

            # _, _, response_eta_reweighted_down, _ = get_unfold_histogram_tuple(
            # 	inputfile=file_for_etaReweight_down,
            # 	variable=variable,
            # 	channel=channel,
            # 	centre_of_mass=13,
            # 	load_fakes=False,
            # 	visiblePS=True
            # )

            # measured_eta_reweighted_down = asrootpy(response_eta_reweighted_down.ProjectionX('px',1))
            # truth_eta_reweighted_down = asrootpy(response_eta_reweighted_down.ProjectionY())

            # Get the distributions for other MC models
            _, _, response_amcatnlo_pythia8, _ = get_unfold_histogram_tuple(
                inputfile=file_for_amcatnlo_pythia8,
                variable=variable,
                channel=channel,
                centre_of_mass=13,
                load_fakes=False,
                visiblePS=True)

            measured_amcatnlo_pythia8 = asrootpy(
                response_amcatnlo_pythia8.ProjectionX('px', 1))
            truth_amcatnlo_pythia8 = asrootpy(
                response_amcatnlo_pythia8.ProjectionY())

            _, _, response_powhegHerwig, _ = get_unfold_histogram_tuple(
                inputfile=file_for_powhegHerwig,
                variable=variable,
                channel=channel,
                centre_of_mass=13,
                load_fakes=False,
                visiblePS=True)

            measured_powhegHerwig = asrootpy(
                response_powhegHerwig.ProjectionX('px', 1))
            truth_powhegHerwig = asrootpy(response_powhegHerwig.ProjectionY())

            # Get the data input (data after background subtraction, and fake removal)
            file_for_data = file_for_data_template.format(variable=variable,
                                                          channel=channel)
            data = read_tuple_from_file(file_for_data)['TTJet']
            data = value_error_tuplelist_to_hist(data,
                                                 reco_bin_edges_vis[variable])
            data = removeFakes(measured_central, fakes_central, data)

            # Plot all three

            hp = Histogram_properties()
            hp.name = 'Reweighting_check_{channel}_{variable}_at_{com}TeV'.format(
                channel=channel,
                variable=variable,
                com='13',
            )

            v_latex = latex_labels.variables_latex[variable]
            unit = ''
            if variable in ['HT', 'ST', 'MET', 'WPT', 'lepton_pt']:
                unit = ' [GeV]'
            hp.x_axis_title = v_latex + unit
            hp.x_limits = [
                reco_bin_edges_vis[variable][0],
                reco_bin_edges_vis[variable][-1]
            ]
            hp.ratio_y_limits = [0.1, 1.9]
            hp.ratio_y_title = 'Reweighted / Central'
            hp.y_axis_title = 'Number of events'
            hp.title = 'Reweighting check for {variable}'.format(
                variable=v_latex)

            measured_central.Rebin(2)
            measured_pt_reweighted_up.Rebin(2)
            measured_pt_reweighted_down.Rebin(2)
            # measured_eta_reweighted_up.Rebin(2)
            # measured_eta_reweighted_down.Rebin(2)
            measured_amcatnlo_pythia8.Rebin(2)
            measured_powhegHerwig.Rebin(2)
            data.Rebin(2)

            measured_central.Scale(1 / measured_central.Integral())
            measured_pt_reweighted_up.Scale(
                1 / measured_pt_reweighted_up.Integral())
            measured_pt_reweighted_down.Scale(
                1 / measured_pt_reweighted_down.Integral())
            measured_amcatnlo_pythia8.Scale(
                1 / measured_amcatnlo_pythia8.Integral())
            measured_powhegHerwig.Scale(1 / measured_powhegHerwig.Integral())

            # measured_eta_reweighted_up.Scale( 1 / measured_eta_reweighted_up.Integral() )
            # measured_eta_reweighted_down.Scale( 1/ measured_eta_reweighted_down.Integral() )

            data.Scale(1 / data.Integral())

            print list(measured_central.y())
            print list(measured_amcatnlo_pythia8.y())
            print list(measured_powhegHerwig.y())
            print list(data.y())
            compare_measurements(
                # models = {'Central' : measured_central, 'PtReweighted Up' : measured_pt_reweighted_up, 'PtReweighted Down' : measured_pt_reweighted_down, 'EtaReweighted Up' : measured_eta_reweighted_up, 'EtaReweighted Down' : measured_eta_reweighted_down},
                models=OrderedDict([
                    ('Central', measured_central),
                    ('PtReweighted Up', measured_pt_reweighted_up),
                    ('PtReweighted Down', measured_pt_reweighted_down),
                    ('amc@nlo', measured_amcatnlo_pythia8),
                    ('powhegHerwig', measured_powhegHerwig)
                ]),
                measurements={'Data': data},
                show_measurement_errors=True,
                histogram_properties=hp,
                save_folder='plots/unfolding/reweighting_check',
                save_as=['pdf'],
                line_styles_for_models=[
                    'solid', 'solid', 'solid', 'dashed', 'dashed'
                ],
                show_ratio_for_pairs=OrderedDict([
                    ('PtUpVsCentral',
                     [measured_pt_reweighted_up, measured_central]),
                    ('PtDownVsCentral',
                     [measured_pt_reweighted_down, measured_central]),
                    ('amcatnloVsCentral',
                     [measured_amcatnlo_pythia8, measured_central]),
                    ('powhegHerwigVsCentral',
                     [measured_powhegHerwig, measured_central]),
                    ('DataVsCentral', [data, measured_central])
                ]),
            )