예제 #1
0
def run_scan(datafn,
             reffn,
             treen,
             ref_range=[-0.3, 1],
             n_points=250,
             n_bins=32):
    """
    Run a scan using n_points in ref_range
    """
    datah, refh = get_histos(datafn, reffn, treen, n_bins=n_bins)

    ref_scan_points = np.linspace(ref_range[0], ref_range[1], n_points)
    fit_results = []

    for lth_ref in ref_scan_points:
        fit_rlt, _ = do_fit(datah,
                            refh,
                            chic1_limits=False,
                            fix_ref=lth_ref,
                            fit_range=False,
                            run_quiet=True,
                            fix_norm=False)
        fit_results.append(extract_par_from_result(fit_rlt))

    return fit_results
예제 #2
0
def get_ratio_hist(dataf, reff, treen, n_bins, bin_thresh=0):
    """Get the 'cleaned up' ratio hist"""
    from run_ratio_histo_fit import get_histos, divide, set_bins_to_zero

    logging.debug('Creating histogram from datafile \'{}\' and '
                 'reffile \'{}\' using {} bins'.format(dataf, reff, n_bins))
    datah, refh = get_histos(dataf, reff, treen, n_bins)

    set_bins_to_zero(datah, bin_thresh, True)
    set_bins_to_zero(refh, bin_thresh, True)

    return divide(datah, refh)
def main(datafn,
         reffn,
         outbase,
         treen,
         n_bins,
         bin_thresh=0,
         scan_plot=True,
         use_center=False):
    # first run a scan to check how stable the normalization is
    # mean_norm = calc_mean_norm(datafn, reffn, treen, n_bins)
    mean_norm = get_free_norm(datafn, reffn, treen, n_bins)

    fit_func = r.TF1(
        'fit_func',
        '[0] * (3 + [1]) / (3 + [1] + [2]) * (1 + ([1] + [2]) * x[0]*x[0]) / (1 + [1] * x[0]*x[0])',
        -1, 1)

    datah, refh = get_histos(datafn, reffn, treen, n_bins)
    # for (i,b) in enumerate(datah):
    #     print('{}, data = {}, ref = {}'.format(i, b, refh.GetBinContent(i))

    set_bins_to_zero(datah, bin_thresh, True)
    set_bins_to_zero(refh, bin_thresh, True)

    ratioh = divide(datah, refh)
    ratio_fit = CosthRatioFit(ratioh,
                              fit_func,
                              fix_params=[(0, mean_norm)],
                              use_center=use_center)
    fit_results = ratio_fit.get_results(error_levels)

    plotbase = '_'.join([outbase, str(n_bins)])
    make_fit_plot(ratioh, fit_results[0], fit_func, plotbase)

    if scan_plot:
        x_ran, y_ran = get_plotting_range(fit_results[-1])
        scan_fit_result = make_paed_plot(ratioh,
                                         fit_func,
                                         error_levels,
                                         fit_results,
                                         '.'.join([plotbase, 'pdf']),
                                         n_grid=250,
                                         x_ran=x_ran,
                                         y_ran=y_ran)
        fit_results += scan_fit_result

    for result in fit_results:
        print_result(result)

    cfile_name = '_'.join([plotbase, 'contours']) + '.root'
    write_result_file(cfile_name, fit_results)
예제 #4
0
def run_one_fit(datafn, reffn, treen, n_bins):
    """Run fit for one data and reference file"""
    import ROOT as r
    norm = get_free_norm(datafn, reffn, treen, n_bins)

    if norm is None:
        return None

    fit_func = r.TF1('fit_func',
                     '[0] * (3 + [1]) / (3 + [1] + [2]) * (1 + ([1] + [2]) * x[0]*x[0]) / (1 + [1] * x[0]*x[0])',
                     -1, 1)

    datah, refh = get_histos(datafn, reffn, treen, n_bins)
    ratioh = divide(datah, refh)
    ratio_fit = CosthRatioFit(ratioh, fit_func, fix_params=[(0, norm)])

    return ratio_fit.get_results(error_levels)