def calculate_normalised_xsections(normalisation, category, channel, normalise_to_one = False):
    global variable, met_type, path_to_JSON
    TTJet_normalised_xsection = calculate_normalised_xsection(normalisation['TTJet_measured'], bin_widths[variable], normalise_to_one)
    TTJet_normalised_xsection_unfolded = calculate_normalised_xsection(normalisation['TTJet_unfolded'], bin_widths[variable], normalise_to_one)
    MADGRAPH_normalised_xsection = calculate_normalised_xsection(normalisation['MADGRAPH'], bin_widths[variable], normalise_to_one)
    POWHEG_normalised_xsection = calculate_normalised_xsection(normalisation['POWHEG'], bin_widths[variable], normalise_to_one)
    MCATNLO_normalised_xsection = calculate_normalised_xsection(normalisation['MCATNLO'], bin_widths[variable], normalise_to_one)
    matchingdown_normalised_xsection = calculate_normalised_xsection(normalisation['matchingdown'], bin_widths[variable], normalise_to_one)
    matchingup_normalised_xsection = calculate_normalised_xsection(normalisation['matchingup'], bin_widths[variable], normalise_to_one)
    scaledown_normalised_xsection = calculate_normalised_xsection(normalisation['scaledown'], bin_widths[variable], normalise_to_one)
    scaleup_normalised_xsection = calculate_normalised_xsection(normalisation['scaleup'], bin_widths[variable], normalise_to_one)
    
    normalised_xsection = {'TTJet_measured' : TTJet_normalised_xsection,
                           'TTJet_unfolded' : TTJet_normalised_xsection_unfolded,
                           'MADGRAPH': MADGRAPH_normalised_xsection,
                           'POWHEG': POWHEG_normalised_xsection,
                           'MCATNLO': MCATNLO_normalised_xsection,
                           #systematics
                           'matchingdown': matchingdown_normalised_xsection,
                           'matchingup': matchingup_normalised_xsection,
                           'scaledown': scaledown_normalised_xsection,
                           'scaleup': scaleup_normalised_xsection
                           }
    
    filename = path_to_JSON + '/' + variable + '/xsection_measurement_results' + '/kv' + str(unfoldCfg.SVD_k_value) + '/' + category + '/normalised_xsection_' + channel + '_' + met_type + '.txt'
    if normalise_to_one:
        filename = filename.replace('normalised_xsection', 'normalised_to_one_xsection')
    write_data_to_JSON(normalised_xsection, filename)
 def setUp( self ):
     self.n_events = [1, 2, 3]
     self.n_events_errors = [1, 1, 1]
     self.u_n_events = [ufloat( 1, 1 ), ufloat( 2, 1 ), ufloat( 3, 1 )]
     self.n_total = sum( self.n_events )
     self.inputs = zip( self.n_events, self.n_events_errors ) 
     self.bin_widths = [2, 5, 7]
     self.results = calculate_normalised_xsection( self.inputs,
                                            self.bin_widths )
 def setUp(self):
     self.n_events = [1, 2, 3]
     self.n_events_errors = [1, 1, 1]
     self.u_n_events = [ufloat(1, 1), ufloat(2, 1), ufloat(3, 1)]
     self.n_total = sum(self.n_events)
     self.inputs = zip(self.n_events, self.n_events_errors)
     self.bin_widths = [2, 5, 7]
     self.results = calculate_normalised_xsection(self.inputs,
                                                  self.bin_widths)
示例#4
0
def calculate_normalised_xsections(normalisation,
                                   category,
                                   channel,
                                   normalise_to_one=False):
    global variable, met_type, path_to_JSON
    TTJet_normalised_xsection = calculate_normalised_xsection(
        normalisation['TTJet_measured'], bin_widths[variable],
        normalise_to_one)
    TTJet_normalised_xsection_unfolded = calculate_normalised_xsection(
        normalisation['TTJet_unfolded'], bin_widths[variable],
        normalise_to_one)
    MADGRAPH_normalised_xsection = calculate_normalised_xsection(
        normalisation['MADGRAPH'], bin_widths[variable], normalise_to_one)
    POWHEG_normalised_xsection = calculate_normalised_xsection(
        normalisation['POWHEG'], bin_widths[variable], normalise_to_one)
    MCATNLO_normalised_xsection = calculate_normalised_xsection(
        normalisation['MCATNLO'], bin_widths[variable], normalise_to_one)
    matchingdown_normalised_xsection = calculate_normalised_xsection(
        normalisation['matchingdown'], bin_widths[variable], normalise_to_one)
    matchingup_normalised_xsection = calculate_normalised_xsection(
        normalisation['matchingup'], bin_widths[variable], normalise_to_one)
    scaledown_normalised_xsection = calculate_normalised_xsection(
        normalisation['scaledown'], bin_widths[variable], normalise_to_one)
    scaleup_normalised_xsection = calculate_normalised_xsection(
        normalisation['scaleup'], bin_widths[variable], normalise_to_one)

    normalised_xsection = {
        'TTJet_measured': TTJet_normalised_xsection,
        'TTJet_unfolded': TTJet_normalised_xsection_unfolded,
        'MADGRAPH': MADGRAPH_normalised_xsection,
        'POWHEG': POWHEG_normalised_xsection,
        'MCATNLO': MCATNLO_normalised_xsection,
        #systematics
        'matchingdown': matchingdown_normalised_xsection,
        'matchingup': matchingup_normalised_xsection,
        'scaledown': scaledown_normalised_xsection,
        'scaleup': scaleup_normalised_xsection
    }

    filename = path_to_JSON + '/' + variable + '/xsection_measurement_results' + '/kv' + str(
        unfoldCfg.SVD_k_value
    ) + '/' + category + '/normalised_xsection_' + channel + '_' + met_type + '.txt'
    if normalise_to_one:
        filename = filename.replace('normalised_xsection',
                                    'normalised_to_one_xsection')
    write_data_to_JSON(normalised_xsection, filename)
def calculate_xsection( nEventsHistogram, variable ):
    resultsAsTuple = hist_to_value_error_tuplelist( nEventsHistogram )
    normalised_xsection = calculate_normalised_xsection( resultsAsTuple, bin_widths_visiblePS[variable], False )
    return value_error_tuplelist_to_hist(normalised_xsection, bin_edges_vis[variable])
def calculate_normalised_xsections( normalisation, category, channel, normalise_to_one = False, covariance_matrix=None ):
    '''
    Calculate the normalised cross sections
    '''
    global variable, path_to_DF, phase_space

    binWidths = None
    if phase_space == 'VisiblePS':
        binWidths = bin_widths_visiblePS
    elif phase_space == 'FullPS':
        binWidths = bin_widths
    
    normalised_xsection = {}
    normalised_xsection['TTJet_measured'], _, _ = calculate_normalised_xsection( 
        normalisation['TTJet_measured'], 
        binWidths[variable], 
        normalise_to_one 
    )
    normalised_xsection['TTJet_measured_withoutFakes'], _, _ = calculate_normalised_xsection( 
        normalisation['TTJet_measured_withoutFakes'], 
        binWidths[variable], 
        normalise_to_one 
    )
    normalised_xsection['TTJet_unfolded'], normalised_covariance_matrix, normalised_correlation_matrix = calculate_normalised_xsection( 
        normalisation['TTJet_unfolded'], 
        binWidths[variable], 
        normalise_to_one,
        covariance_matrix 
    )
    
    if not covariance_matrix is None:
        covariance_output_template = '{path_to_DF}/central/covarianceMatrices/{cat}_{label}_{channel}.txt'
        # Unfolded number of events
        table_outfile=covariance_output_template.format( path_to_DF=path_to_DF, channel = channel, label='Covariance', cat='Stat_normalisedXsection' )
        create_covariance_matrix( normalised_covariance_matrix, table_outfile)
        table_outfile=covariance_output_template.format( path_to_DF=path_to_DF, channel = channel, label='Correlation', cat='Stat_normalisedXsection' )
        create_covariance_matrix( normalised_correlation_matrix, table_outfile )

    if category == 'central':
        normalised_xsection['powhegPythia8'], _, _ = calculate_normalised_xsection( 
            normalisation['powhegPythia8'], 
            binWidths[variable], 
            normalise_to_one, 
        )
        # normalised_xsection['amcatnlo'], _, _ = calculate_normalised_xsection( 
        #     normalisation['amcatnlo'], 
        #     binWidths[variable], 
        #     normalise_to_one, 
        # )
        normalised_xsection['powhegHerwig'], _, _ = calculate_normalised_xsection( 
            normalisation['powhegHerwig'], 
            binWidths[variable], 
            normalise_to_one, 
        )
        # normalised_xsection['madgraphMLM'], _, _ = calculate_normalised_xsection( 
        #     normalisation['madgraphMLM'], 
        #     binWidths[variable], 
        #     normalise_to_one, 
        # )

        normalised_xsection['massdown'], _, _ = calculate_normalised_xsection( 
            normalisation['massdown'], 
            binWidths[variable], 
            normalise_to_one, 
        )
        normalised_xsection['massup'], _, _ = calculate_normalised_xsection( 
            normalisation['massup'], 
            binWidths[variable], 
            normalise_to_one, 
        )
        normalised_xsection['isrdown'], _, _ = calculate_normalised_xsection( 
            normalisation['isrdown'], 
            binWidths[variable], 
            normalise_to_one, 
        )
        normalised_xsection['isrup'], _, _ = calculate_normalised_xsection( 
            normalisation['isrup'], 
            binWidths[variable], 
            normalise_to_one, 
        )
        # normalised_xsection['fsrdown'], _, _ = calculate_normalised_xsection( 
        #     normalisation['fsrdown'], 
        #     binWidths[variable], 
        #     normalise_to_one, 
        # )
        normalised_xsection['fsrup'], _, _ = calculate_normalised_xsection( 
            normalisation['fsrup'], 
            binWidths[variable], 
            normalise_to_one, 
        )
        normalised_xsection['uedown'], _, _ = calculate_normalised_xsection( 
            normalisation['uedown'], 
            binWidths[variable], 
            normalise_to_one, 
        )
        normalised_xsection['ueup'], _, _ = calculate_normalised_xsection( 
            normalisation['ueup'], 
            binWidths[variable], 
            normalise_to_one, 
        )

    file_template = '{path_to_DF}/{category}/xsection_normalised_{channel}_{method}.txt'
    if normalise_to_one:
        file_template = file_template.replace( 'xsection_normalised', 'xsection_normalised_to_one' )
    write_02(normalised_xsection, file_template, path_to_DF, category, channel, method)
def calculate_normalised_xsections( normalisation, category, channel, normalise_to_one = False ):
    global variable, met_type, path_to_JSON, phase_space

    binWidths = None
    if phase_space == 'VisiblePS':
        binWidths = bin_widths_visiblePS
    elif phase_space == 'FullPS':
        binWidths = bin_widths

    TTJet_normalised_xsection = calculate_normalised_xsection( normalisation['TTJet_measured'], binWidths[variable], normalise_to_one )
    TTJet_withoutFakes_normalised_xsection = calculate_normalised_xsection( normalisation['TTJet_measured_withoutFakes'], binWidths[variable], normalise_to_one )
    TTJet_normalised_xsection_unfolded = calculate_normalised_xsection( normalisation['TTJet_unfolded'], binWidths[variable], normalise_to_one )

    normalised_xsection = {'TTJet_measured' : TTJet_normalised_xsection,
                           'TTJet_measured_withoutFakes' : TTJet_withoutFakes_normalised_xsection,
                           'TTJet_unfolded' : TTJet_normalised_xsection_unfolded
                           }

    if category == 'central':
        powhegPythia8_normalised_xsection = calculate_normalised_xsection( normalisation['powhegPythia8'], binWidths[variable], normalise_to_one )
        amcatnlo_normalised_xsection = calculate_normalised_xsection( normalisation['amcatnlo'], binWidths[variable], normalise_to_one )
        powhegHerwig_normalised_xsection = calculate_normalised_xsection( normalisation['powhegHerwig'], binWidths[variable], normalise_to_one )
        # amcatnloHerwig_normalised_xsection = calculate_normalised_xsection( normalisation['amcatnloHerwig'], binWidths[variable], normalise_to_one )
        madgraphMLM_normalised_xsection = calculate_normalised_xsection( normalisation['madgraphMLM'], binWidths[variable], normalise_to_one )

        scaledown_normalised_xsection = calculate_normalised_xsection( normalisation['scaledown'], binWidths[variable], normalise_to_one )
        scaleup_normalised_xsection = calculate_normalised_xsection( normalisation['scaleup'], binWidths[variable], normalise_to_one )
        massdown_normalised_xsection = calculate_normalised_xsection( normalisation['massdown'], binWidths[variable], normalise_to_one )
        massup_normalised_xsection = calculate_normalised_xsection( normalisation['massup'], binWidths[variable], normalise_to_one )

        normalised_xsection['powhegPythia8'] = powhegPythia8_normalised_xsection
        normalised_xsection['amcatnlo'] = amcatnlo_normalised_xsection
        normalised_xsection['madgraphMLM' ] = madgraphMLM_normalised_xsection
        normalised_xsection['powhegHerwig'] = powhegHerwig_normalised_xsection
        # normalised_xsection['amcatnloHerwig'] = amcatnloHerwig_normalised_xsection

        normalised_xsection['scaledown'] = scaledown_normalised_xsection
        normalised_xsection['scaleup'] = scaleup_normalised_xsection
        normalised_xsection['massdown'] = massdown_normalised_xsection
        normalised_xsection['massup'] = massup_normalised_xsection

    file_template = '{path_to_JSON}/{category}/normalised_xsection_{channel}_{method}.txt'
    filename = file_template.format(
                path_to_JSON = path_to_JSON,
                category = category,
                channel = channel,
                method = method,
                )

    if normalise_to_one:
        filename = filename.replace( 'normalised_xsection', 'normalised_to_one_xsection' )
    write_data_to_JSON( normalised_xsection, filename )
def calculate_xsection( nEventsHistogram, variable ):
    resultsAsTuple = hist_to_value_error_tuplelist( nEventsHistogram )
    normalised_xsection, _, _, _ = calculate_normalised_xsection( resultsAsTuple, bin_widths_visiblePS[variable], False )

    return value_error_tuplelist_to_hist(normalised_xsection, bin_edges_vis[variable])