예제 #1
0
def main():
    config = XSectionConfig(13)
#     method = 'RooUnfoldSvd'
    method = 'RooUnfoldBayes'
    file_for_unfolding = File(config.unfolding_central, 'read')
    for channel in ['electron', 'muon', 'combined']:
        for variable in bin_edges.keys():
            tau_value = get_tau_value(config, channel, variable)
            h_truth, h_measured, h_response, h_fakes = get_unfold_histogram_tuple(
                inputfile=file_for_unfolding,
                variable=variable,
                channel=channel,
                met_type=config.met_type,
                centre_of_mass=config.centre_of_mass_energy,
                ttbar_xsection=config.ttbar_xsection,
                luminosity=config.luminosity,
                load_fakes=False,
                visiblePS=False,
            )
            unfolding = Unfolding(
                h_truth, h_measured, h_response, h_fakes,
                method=method, k_value=-1, tau=tau_value)

            unfolded_data = unfolding.closureTest()
            plot_closure(h_truth, unfolded_data, variable, channel,
                         config.centre_of_mass_energy, method)
예제 #2
0
def main():
    config = XSectionConfig(13)
    #     method = 'RooUnfoldSvd'
    method = 'RooUnfoldBayes'
    file_for_unfolding = File(config.unfolding_central, 'read')
    for channel in ['electron', 'muon', 'combined']:
        for variable in bin_edges.keys():
            tau_value = get_tau_value(config, channel, variable)
            h_truth, h_measured, h_response, h_fakes = get_unfold_histogram_tuple(
                inputfile=file_for_unfolding,
                variable=variable,
                channel=channel,
                met_type=config.met_type,
                centre_of_mass=config.centre_of_mass_energy,
                ttbar_xsection=config.ttbar_xsection,
                luminosity=config.luminosity,
                load_fakes=False,
                visiblePS=False,
            )
            unfolding = Unfolding(h_truth,
                                  h_measured,
                                  h_response,
                                  h_fakes,
                                  method=method,
                                  k_value=-1,
                                  tau=tau_value)

            unfolded_data = unfolding.closureTest()
            plot_closure(h_truth, unfolded_data, variable, channel,
                         config.centre_of_mass_energy, method)
        'y-title': 'Events/(0.2)'
    },
    'muon_absolute_eta': {
        'min': 0,
        'max': 2.6,
        'rebin': 2,
        'x-title': '$\left|\eta(\mu)\\right|$',
        'y-title': 'Events/(0.2)'
    },
}

b_tag_bin = '2orMoreBtags'
b_tag_bin_ctl = '0orMoreBtag'
category = 'central'

variables = bin_edges.keys()

save_as = ['pdf']


def main():
    global measurement_config, histogram_files
    global electron_fit_variables, muon_fit_variables, fit_variable_properties
    global b_tag_bin, category, histogram_files, variables
    global b_tag_bin_ctl

    title_template = '$%.1f$ fb$^{-1}$(%d TeV)'
    e_title = title_template % (measurement_config.new_luminosity / 1000.,
                                measurement_config.centre_of_mass_energy)
    met_type = 'patType1CorrectedPFMet'
    for variable in variables:
예제 #4
0
import json
from config import XSectionConfig
from config.variable_binning import bin_edges, bin_edges_vis
from tools.file_utilities import make_folder_if_not_exists

com = 13
fitVars = "M3_angle_bl"

config = XSectionConfig( com )

make_folder_if_not_exists('config/unfolding/FullPS/')
make_folder_if_not_exists('config/unfolding/VisiblePS/')

for channel in config.analysis_types.keys():
	for variable in bin_edges.keys():

		histogramTemplate = "unfolding_%s_analyser_%s_channel" % ( variable, channel )
		outputJson = {
		    "output_folder": "plots/%sTeV/unfolding_tests/FullPS" % com, 
		    "output_format": ["png", "pdf"], 
		    "centre-of-mass energy" : com,
		    "channel": "%s" % channel,
		    "variable": "%s" % variable,
		    "phaseSpace" : "FullPS",
			"truth" : { 
				"file" : "%s" % config.unfolding_central,
				# "histogram": "%s/truth" % ( histogramTemplate ),
				},
			"gen_vs_reco" : { 
				"file" : "%s" % config.unfolding_central,
				# "histogram": "%s/response_without_fakes" % ( histogramTemplate ),
muon_fit_variables = copy( common_fit_variables )
muon_fit_variables.append( 'muon_absolute_eta' )

fit_variable_properties = {
                       'M3': {'min':0, 'max':1000, 'rebin':5, 'x-title': 'M3 [GeV]', 'y-title': 'Events/25 GeV'},
                       'M_bl': {'min':0, 'max':400, 'rebin':2, 'x-title': 'M(b,l) [GeV]', 'y-title': 'Events/10 GeV'},
                       'angle_bl': {'min':0, 'max':3.5, 'rebin':2, 'x-title': 'angle(b,l)', 'y-title': 'Events/(0.2)'},
                       'electron_absolute_eta': {'min':0, 'max':2.6, 'rebin':2, 'x-title': '$\left|\eta(e)\\right|$', 'y-title': 'Events/(0.2)'},
                       'muon_absolute_eta': {'min':0, 'max':2.6, 'rebin':2, 'x-title': '$\left|\eta(\mu)\\right|$', 'y-title': 'Events/(0.2)'},
                       }

b_tag_bin = '2orMoreBtags'
b_tag_bin_ctl = '0orMoreBtag'
category = 'central'

variables = bin_edges.keys()

save_as = ['pdf']
    
def main():
    global measurement_config, histogram_files
    global electron_fit_variables, muon_fit_variables, fit_variable_properties
    global b_tag_bin, category, histogram_files, variables
    global b_tag_bin_ctl
    
    title_template = '$%.1f$ fb$^{-1}$(%d TeV)'
    e_title = title_template % ( measurement_config.new_luminosity / 1000., measurement_config.centre_of_mass_energy )
    met_type = 'patType1CorrectedPFMet'
    for variable in variables:
        variable_bins = variable_bins_ROOT[variable]
        histogram_template = get_histogram_template( variable )
예제 #6
0
def main():
    '''
    Step 1: Get the 2D histogram for every sample (channel and/or centre of mass energy)
    Step 2: Change the size of the first bin until it fulfils the minimal criteria
    Step 3: Check if it is true for all other histograms. If not back to step 2
    Step 4: Repeat step 2 & 3 until no mo bins can be created
    '''

    parser = OptionParser()
    parser.add_option( '-v', dest = "visiblePhaseSpace", action = "store_true",
                      help = "Consider visible phase space or not" )
    parser.add_option( '-c', dest = "combined", action = "store_true",
                      help = "Combine channels" )
    ( options, _ ) = parser.parse_args()

    p_min = 0.6
    s_min = 0.6
    # we also want the statistical error to be larger than 5%
    # this translates (error -= 1/sqrt(N)) to (1/0.05)^2 = 400
    n_min = 200
    n_min_lepton = 500
#     n_min = 200 # N = 200 -> 7.1 % stat error
     
    bin_choices = {}
    variables = bin_edges.keys()
    for variable in variables:
        print('--- Doing variable',variable)
        variableToUse = variable
        if 'Rap' in variable:
            variableToUse = 'abs_%s' % variable
        histogram_information = get_histograms( variableToUse, options )

        if variable == 'HT':
            best_binning, histogram_information = get_best_binning( histogram_information , p_min, s_min, n_min, minimum_bin_width[variable], x_min=100. )
        elif variable == 'ST':
            best_binning, histogram_information = get_best_binning( histogram_information , p_min, s_min, n_min, minimum_bin_width[variable], x_min=123. )
        elif variable == 'NJets':
            best_binning, histogram_information = get_best_binning( histogram_information , p_min, s_min, n_min, minimum_bin_width[variable], x_min=3.5 )
        elif variable == 'lepton_pt':
            best_binning, histogram_information = get_best_binning( histogram_information , p_min, s_min, n_min_lepton, minimum_bin_width[variable], x_min=23. )
        elif variable == 'abs_lepton_eta':
            best_binning, histogram_information = get_best_binning( histogram_information , p_min, s_min, n_min_lepton, minimum_bin_width[variable] )
        else:
            best_binning, histogram_information = get_best_binning( histogram_information , p_min, s_min, n_min, minimum_bin_width[variable], )

        if 'Rap' in variable:
            for b in list(best_binning):
                if b != 0.0:
                    best_binning.append(-1.0*b)
            best_binning.sort()

        # Make last bin smaller if huge
        # Won't change final results
        if len(best_binning) >= 4:
            lastBinWidth = best_binning[-1] - best_binning[-2]
            penultimateBinWidth = best_binning[-2] - best_binning[-3]
            if lastBinWidth / penultimateBinWidth > 5:
                newLastBinWidth = penultimateBinWidth * 5
                best_binning[-1] = best_binning[-2] + newLastBinWidth

        if variable == 'abs_lepton_eta':
            best_binning = [ round(i,2) for i in best_binning ]
        elif variable != 'NJets' :
            best_binning = [ round(i) for i in best_binning ]

        bin_choices[variable] = best_binning

        print('The best binning for', variable, 'is:')
        print('bin edges =', best_binning)
        print('N_bins    =', len( best_binning ) - 1)
        print('The corresponding purities and stabilities are:')
        for info in histogram_information:
            # print_latex_table(info, variable, best_binning)
            outputInfo = {}
            outputInfo['p_i'] = info['p_i']
            outputInfo['s_i'] = info['s_i']
            outputInfo['N'] = info['N']
            outputJsonFile = 'unfolding/13TeV/binningInfo_%s_%s_FullPS.txt' % ( variable, info['channel'] )
            if options.visiblePhaseSpace:
                outputJsonFile = 'unfolding/13TeV/binningInfo_%s_%s_VisiblePS.txt' % ( variable, info['channel'] )
            write_data_to_JSON( outputInfo, outputJsonFile )
        for key in outputInfo:
            print (key,outputInfo[key])
        print('-' * 120)
    print('=' * 120)
    print('For config/variable_binning.py')
    print('=' * 120)
    for variable in bin_choices:
        print('\''+variable+'\' : '+str(bin_choices[variable])+',')