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 + '/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 )
示例#3
0
 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 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_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 )
        amcatnlo_HERWIG_normalised_xsection = calculate_normalised_xsection( normalisation['amcatnlo_HERWIG'], 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 )

        madgraphMLM_normalised_xsection = calculate_normalised_xsection( normalisation['madgraphMLM'], 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['amcatnlo_HERWIG'] = amcatnlo_HERWIG_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])
def calculate_normalised_xsections( normalisation, category, channel, k_value = None, 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 )
    MADGRAPH_ptreweight_normalised_xsection = calculate_normalised_xsection( normalisation['MADGRAPH_ptreweight'], bin_widths[variable], normalise_to_one )
    POWHEG_PYTHIA_normalised_xsection = calculate_normalised_xsection( normalisation['POWHEG_PYTHIA'], bin_widths[variable], normalise_to_one )
    POWHEG_HERWIG_normalised_xsection = calculate_normalised_xsection( normalisation['POWHEG_HERWIG'], 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,
                           'MADGRAPH_ptreweight': MADGRAPH_ptreweight_normalised_xsection,
                           'POWHEG_PYTHIA': POWHEG_PYTHIA_normalised_xsection,
                           'POWHEG_HERWIG': POWHEG_HERWIG_normalised_xsection,
                           'MCATNLO': MCATNLO_normalised_xsection,
                           # systematics
                           'matchingdown': matchingdown_normalised_xsection,
                           'matchingup': matchingup_normalised_xsection,
                           'scaledown': scaledown_normalised_xsection,
                           'scaleup': scaleup_normalised_xsection
                           }
    
    if not channel == 'combined':
        filename = path_to_JSON + '/xsection_measurement_results/%s/kv%d/%s/normalised_xsection_%s.txt' % ( channel, k_value, category, met_type )        
    else:
        filename = path_to_JSON + '/xsection_measurement_results/%s/%s/normalised_xsection_%s.txt' % ( channel, category, met_type )
    
    if normalise_to_one:
        filename = filename.replace( 'normalised_xsection', 'normalised_to_one_xsection' )
    write_data_to_JSON( normalised_xsection, filename )
                                    'scaleup': scaleup_results_electron
                                    }
 write_data_to_JSON(normalisation_electron_unfolded, 'data/normalisation_electron_unfolded.txt')
 
 # calculate the x-sections and
 bin_widths = [25, 20, 25, 30, 150]
 TTJet_xsection = calculate_xsection(TTJet_fit_results_electron, 5050, 0.15)  # L in pb1
 TTJet_xsection_unfolded = calculate_xsection(TTJet_fit_results_electron_unfolded, 5050, 0.15)  # L in pb1
 MADGRAPH_xsection = calculate_xsection(MADGRAPH_results_electron, 5050, 0.15)  # L in pb1
 
 xsection_electron_unfolded = {'TTJet' : TTJet_xsection_unfolded,
                                    'MADGRAPH': MADGRAPH_xsection
                                    }
 write_data_to_JSON(xsection_electron_unfolded, 'data/xsection_electron_unfolded.txt')
 
 TTJet_normalised_to_one_xsection = calculate_normalised_xsection(TTJet_fit_results_electron, bin_widths, normalise_to_one=True)
 TTJet_normalised_to_one_xsection_unfolded = calculate_normalised_xsection(TTJet_fit_results_electron_unfolded, bin_widths, normalise_to_one=True)
 MADGRAPH_normalised_to_one_xsection = calculate_normalised_xsection(MADGRAPH_results_electron, bin_widths, normalise_to_one=True)
 
 normalised_to_one_xsection_electron_unfolded = {'TTJet' : TTJet_normalised_to_one_xsection_unfolded,
                                    'MADGRAPH': MADGRAPH_normalised_to_one_xsection
                                    }
 write_data_to_JSON(normalised_to_one_xsection_electron_unfolded, 'data/normalised_to_one_xsection_electron_unfolded.txt')
 
 TTJet_normalised_xsection = calculate_normalised_xsection(TTJet_fit_results_electron, bin_widths, normalise_to_one=False)
 TTJet_normalised_xsection_unfolded = calculate_normalised_xsection(TTJet_fit_results_electron_unfolded, bin_widths, normalise_to_one=False)
 MADGRAPH__normalised_xsection = calculate_normalised_xsection(MADGRAPH_results_electron, bin_widths, normalise_to_one=False)
 
 normalised_xsection_electron_unfolded = {'TTJet' : TTJet_normalised_xsection_unfolded,
                                    'MADGRAPH': MADGRAPH__normalised_xsection
                                    }
示例#9
0
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)
        amcatnlo_HERWIG_normalised_xsection = calculate_normalised_xsection(
            normalisation['amcatnlo_HERWIG'], 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)

        madgraphMLM_normalised_xsection = calculate_normalised_xsection(
            normalisation['madgraphMLM'], 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[
            'amcatnlo_HERWIG'] = amcatnlo_HERWIG_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 get_normalised_xsection(normalisation_unfolded, normalise_to_one):
    bin_widths = [25, 20, 25, 30, 150]
    result = {}
    for sample in normalisation_unfolded.keys():
        result[sample] = calculate_normalised_xsection(normalisation_unfolded[sample], bin_widths, normalise_to_one)
    return result