def combine(self, other):
        if not self.have_normalisation or not other.have_normalisation:
            mylog.warn(
                'One of the TTJetNormalisations does not have a normalisation, aborting.')
            return

        self.normalisation = combine_complex_results(
            self.normalisation, other.normalisation)
        self.initial_normalisation = combine_complex_results(
            self.initial_normalisation, other.initial_normalisation)
        self.templates = combine_complex_results(
            self.templates, other.templates)
        self.channel = 'combined'
    def combine(self, other):
        if not self.have_normalisation or not other.have_normalisation:
            mylog.warn(
                'One of the TTJetNormalisations does not have a normalisation, aborting.'
            )
            return

        self.normalisation = combine_complex_results(self.normalisation,
                                                     other.normalisation)
        self.initial_normalisation = combine_complex_results(
            self.initial_normalisation, other.initial_normalisation)
        self.templates = combine_complex_results(self.templates,
                                                 other.templates)
        self.channel = 'combined'
        fit_results_electron = None
        fit_results_muon = None
        
        if category == 'Muon_up' or category == 'Muon_down':
            # fit_results_electron = read_data_from_JSON( path_to_JSON + '/central/initial_normalisation_electron_' + met_type + '.txt' )
            fit_results_electron = read_data_from_JSON( path_to_JSON + '/central/normalisation_electron_' + met_type + '.txt' )
            fit_results_muon = read_data_from_JSON( muon_file )
        elif category == 'Electron_up' or category == 'Electron_down':
            fit_results_electron = read_data_from_JSON( electron_file )
            # fit_results_muon = read_data_from_JSON( path_to_JSON + '/central/initial_normalisation_muon_' + met_type + '.txt' )
            fit_results_muon = read_data_from_JSON( path_to_JSON + '/central/normalisation_muon_' + met_type + '.txt' )
        else:
            fit_results_electron = read_data_from_JSON( electron_file )
            fit_results_muon = read_data_from_JSON( muon_file )
        fit_results_combined = combine_complex_results(fit_results_electron, fit_results_muon)
        TTJet_fit_results_electron = fit_results_electron['TTJet']
        TTJet_fit_results_muon = fit_results_muon['TTJet']
        TTJet_fit_results_combined = fit_results_combined['TTJet']

    #     # change back to original MET type for the unfolding
        met_type = translate_options[options.metType]
    #     # ad-hoc switch for PFMET -> patMETsPFlow
    #     if met_type == 'PFMET':
    #         met_type = 'patMETsPFlow'

        file_template = '{path_to_JSON}/{category}/unfolded_normalisation_{channel}_{method}.txt'
        filename = ''

    #     # get unfolded normalisation
        unfolded_normalisation_electron = {}
        
        # change back to original MET type for the unfolding
        met_type = translate_options[options.metType]
        # ad-hoc switch for PFMET -> patMETsPFlow
        if met_type == 'PFMET':
            met_type = 'patMETsPFlow'
        
        filename = ''

        # get unfolded normalisation
        unfolded_normalisation_electron = get_unfolded_normalisation( TTJet_fit_results_electron, category, 'electron', k_value_electron )
        unfolded_normalisation_muon = get_unfolded_normalisation( TTJet_fit_results_muon, category, 'muon', k_value_muon )
        if combine_before_unfolding:
            unfolded_normalisation_combined = get_unfolded_normalisation( TTJet_fit_results_combined, category, 'combined', k_value_combined )
        else:
            unfolded_normalisation_combined = combine_complex_results( unfolded_normalisation_electron, unfolded_normalisation_muon )

        filename = path_to_JSON + '/xsection_measurement_results/electron/kv%d/%s/normalisation_%s.txt' % ( k_value_electron, category, met_type )
        write_data_to_JSON( unfolded_normalisation_electron, filename )
        filename = path_to_JSON + '/xsection_measurement_results/muon/kv%d/%s/normalisation_%s.txt' % ( k_value_muon, category, met_type )
        write_data_to_JSON( unfolded_normalisation_muon, filename )
        filename = path_to_JSON + '/xsection_measurement_results/combined/%s/normalisation_%s.txt' % ( category, met_type )
        write_data_to_JSON( unfolded_normalisation_combined, filename )
        
        if measurement_config.include_higgs:
            # now the same for the Higgs
            Higgs_fit_results_electron = fit_results_electron['Higgs']
            Higgs_fit_results_muon = fit_results_muon['Higgs']
            Higgs_fit_results_combined = fit_results_combined['Higgs']
            unfolded_normalisation_electron_higgs = get_unfolded_normalisation( fit_results_electron['Higgs'], category, 'electron', k_value_electron )
            unfolded_normalisation_muon_higgs = get_unfolded_normalisation( fit_results_muon['Higgs'], category, 'muon', k_value_muon )
        fit_results_muon, initial_values_muon, templates_muon = get_fitted_normalisation_from_ROOT( 'muon',
                      input_files = {
                                   'TTJet': TTJet_file,
                                   'SingleTop': SingleTop_file,
                                   'V+Jets': VJets_file,
                                   'data': data_file_muon,
                                   'Higgs' : Higgs_file,
                                   },
                      variable = variable,
                      met_type = met_type,
                      b_tag_bin = b_tag_bin,
                      )

        write_fit_results_and_initial_values( 'electron', vjets_theory_systematic_prefix + systematic, fit_results_electron, initial_values_electron, templates_electron )
        write_fit_results_and_initial_values( 'muon', vjets_theory_systematic_prefix + systematic, fit_results_muon, initial_values_muon, templates_muon )
        write_fit_results( 'combined', vjets_theory_systematic_prefix + systematic, combine_complex_results( fit_results_electron, fit_results_muon ) )
        VJets_file.Close()

    VJets_file = File( measurement_config.VJets_category_templates['central'] )

    # central measurement and the rest of the systematics
    last_systematic = ''
    for category, prefix in categories_and_prefixes.iteritems():
        if run_just_central and not category == 'central': 
            continue
        TTJet_file = File( measurement_config.ttbar_category_templates[category] )
        SingleTop_file = File( measurement_config.SingleTop_category_templates[category] )
        VJets_file = File( measurement_config.VJets_category_templates[category] )
        data_file_electron = File( measurement_config.data_electron_category_templates['central'] )
        data_file_muon = File( measurement_config.data_muon_category_templates['central'] )
        if measurement_config.include_higgs:
Exemplo n.º 6
0
        if category == 'Muon_up' or category == 'Muon_down':
            # fit_results_electron = read_data_from_JSON( path_to_JSON + '/central/initial_normalisation_electron_' + met_type + '.txt' )
            fit_results_electron = read_data_from_JSON(
                path_to_JSON + '/central/normalisation_electron_' + met_type +
                '.txt')
            fit_results_muon = read_data_from_JSON(muon_file)
        elif category == 'Electron_up' or category == 'Electron_down':
            fit_results_electron = read_data_from_JSON(electron_file)
            # fit_results_muon = read_data_from_JSON( path_to_JSON + '/central/initial_normalisation_muon_' + met_type + '.txt' )
            fit_results_muon = read_data_from_JSON(
                path_to_JSON + '/central/normalisation_muon_' + met_type +
                '.txt')
        else:
            fit_results_electron = read_data_from_JSON(electron_file)
            fit_results_muon = read_data_from_JSON(muon_file)
        fit_results_combined = combine_complex_results(fit_results_electron,
                                                       fit_results_muon)
        TTJet_fit_results_electron = fit_results_electron['TTJet']
        TTJet_fit_results_muon = fit_results_muon['TTJet']
        TTJet_fit_results_combined = fit_results_combined['TTJet']

        #     # change back to original MET type for the unfolding
        met_type = translate_options[options.metType]
        #     # ad-hoc switch for PFMET -> patMETsPFlow
        #     if met_type == 'PFMET':
        #         met_type = 'patMETsPFlow'

        file_template = '{path_to_JSON}/{category}/unfolded_normalisation_{channel}_{method}.txt'
        filename = ''

        #     # get unfolded normalisation
        unfolded_normalisation_electron = {}
Exemplo n.º 7
0
            met_systematic=met_systematic,
            met_type=met_type,
            b_tag_bin=b_tag_bin,
            treePrefix=treePrefix,
            weightBranch=weightBranch,
            scale_factors=scaleFactor,
        )
        write_fit_results_and_initial_values('electron', category,
                                             fit_results_electron,
                                             initial_values_electron,
                                             templates_electron)
        write_fit_results_and_initial_values('muon', category,
                                             fit_results_muon,
                                             initial_values_muon,
                                             templates_muon)
        fit_results_combined = combine_complex_results(fit_results_electron,
                                                       fit_results_muon)
        initial_values_combined = combine_complex_results(
            initial_values_electron, initial_values_muon)
        write_fit_results_and_initial_values('combined', category,
                                             fit_results_combined,
                                             initial_values_combined)
        last_systematic = category

        # TTJet_file.Close()
        # SingleTop_file.Close()
        # VJets_file.Close()
        # data_file_electron.Close()
        # data_file_muon.Close()
        # if Higgs_file:
        #     Higgs_file.Close()
                                   'SingleTop': SingleTop_file,
                                   'V+Jets': VJets_file,
                                   'QCD' : QCD_muon_file,
                                   'data': data_file_muon,
                                   },
                      variable = variable,
                      met_systematic = met_systematic,
                      met_type = met_type,
                      b_tag_bin = b_tag_bin,
                      treePrefix = treePrefix,
                      weightBranch = weightBranch,
                      scale_factors = scaleFactor,
                      )
        write_fit_results_and_initial_values( 'electron', category, fit_results_electron, initial_values_electron, templates_electron )
        write_fit_results_and_initial_values( 'muon', category, fit_results_muon, initial_values_muon, templates_muon )
        fit_results_combined = combine_complex_results( fit_results_electron, fit_results_muon )
        initial_values_combined = combine_complex_results( initial_values_electron, initial_values_muon)
        write_fit_results_and_initial_values( 'combined', category, fit_results_combined, initial_values_combined)
        last_systematic = category
 
        # TTJet_file.Close()
        # SingleTop_file.Close()
        # VJets_file.Close()
        # data_file_electron.Close()
        # data_file_muon.Close()
        # if Higgs_file:
        #     Higgs_file.Close()
 


    # data_file_electron = File( measurement_config.data_electron_category_templates_trees )