def plot_correction_graph(calib_file, eta_min, eta_max, oDir, oFormat='pdf'):
    """Plot the graph of correction value vs pT"""
    gname = generate_eta_graph_name(eta_min, eta_max)
    gr = cu.get_from_file(calib_file, gname)
    c = generate_canvas()
    gr.Draw("ALP")
    y_min = ROOT.TMath.MinElement(gr.GetN(), gr.GetY())
    y_max = ROOT.TMath.MaxElement(gr.GetN(), gr.GetY())
    if y_max > 5:
        y_max = 5
    gr.GetYaxis().SetRangeUser(y_min * 0.7, y_max * 1.1)
    c.SaveAs('%s/%s.%s' % (oDir, gname, oFormat))
Exemplo n.º 2
0
def get_functions_graphs_params_rootfile(root_filename):
    """Get function parameters from ROOT file

    Gets object based on name in runCalibration.py

    Parameters
    ----------
    root_filename : str
        Name of ROOT file to get things from

    Returns
    -------
    all_fits : list[TF1]
        Collection of TF1 objects, one per line of file ( = 1 eta bin)
    all_fit_params : list[list[float]]
        Collection of fit parameters, one per line of file ( = 1 eta bin)
    all_graphs : list[TGraphErrors]
        Colleciton of correction graphs, one per eta bin
    """
    print 'Reading functions from ROOT file'
    in_file = cu.open_root_file(root_filename)
    all_fit_params = []
    all_fits = []
    all_graphs = []
    # Get all the fit functions from file and their corresponding graphs
    etaBins = binning.eta_bins
    for i, (eta_min, eta_max) in enumerate(izip(etaBins[:-1], etaBins[1:])):
        print "Eta bin:", eta_min, "-", eta_max

        # get the fitted TF1
        try:
            fit_func = cu.get_from_file(in_file, "fitfcneta_%g_%g" % (eta_min, eta_max))
            fit_params = [fit_func.GetParameter(par) for par in range(fit_func.GetNumberFreeParameters())]
            print "Fit fn evaluated at 5 GeV:", fit_func.Eval(5)
        except IOError:
            print "No fit func"
            fit_func = None
            fit_params = []
        all_fits.append(fit_func)
        all_fit_params.append(fit_params)
        # print "Fit parameters:", fit_params

        # get the corresponding fit graph
        fit_graph = cu.get_from_file(in_file, generate_eta_graph_name(eta_min, eta_max))
        all_graphs.append(fit_graph)

    in_file.Close()
    return all_fits, all_fit_params, all_graphs
def process_file(filename, eta_bins=binning.eta_bins_forward):
    """Process a ROOT file with graphs, print a mean & mean histogram for each.

    Parameters
    ----------
    filename : str
        Name of ROOT file to process (from runCalibration.py)
    eta_bins : list[[float, float]]
        Eta bin edges.
    """
    f = cu.open_root_file(filename)

    for eta_min, eta_max in binning.pairwise(eta_bins):
        gr = cu.get_from_file(f, generate_eta_graph_name(eta_min, eta_max))
        if not gr:
            raise RuntimeError("Can't get graph")

        xarr, yarr = cu.get_xy(gr)
        xarr, yarr = np.array(xarr), np.array(
            yarr)  # use numpy array for easy slicing

        # Loop over all possible subgraphs, and calculate a mean for each
        end = len(yarr)
        means = []
        while end > 0:
            start = 0
            while start < end:
                means.append(yarr[start:end].mean())
                start += 1
            end -= 1

        # Jackknife means
        jack_means = [np.delete(yarr, i).mean() for i in range(len(yarr))]

        # Do plotting & peak finding in both ROOT and MPL...not sure which is better?
        # peak = plot_find_peak_mpl(means, eta_min, eta_max, os.path.dirname(os.path.realpath(filename)))
        peak = plot_find_peak_root(means, eta_min, eta_max,
                                   os.path.dirname(os.path.realpath(filename)))
        jackpeak = plot_jacknife_root(
            jack_means, eta_min, eta_max,
            os.path.dirname(os.path.realpath(filename)))
        print 'Eta bin:', eta_min, '-', eta_max
        print peak
        print 'jackknife mean:'
        print np.array(jack_means).mean()

    f.Close()
def process_file(filename, eta_bins=binning.eta_bins_forward):
    """Process a ROOT file with graphs, print a mean & mean histogram for each.

    Parameters
    ----------
    filename : str
        Name of ROOT file to process (from runCalibration.py)
    eta_bins : list[[float, float]]
        Eta bin edges.
    """
    f = cu.open_root_file(filename)

    for eta_min, eta_max in binning.pairwise(eta_bins):
        gr = cu.get_from_file(f, generate_eta_graph_name(eta_min, eta_max))
        if not gr:
            raise RuntimeError("Can't get graph")

        xarr, yarr = cu.get_xy(gr)
        xarr, yarr = np.array(xarr), np.array(yarr)  # use numpy array for easy slicing

        # Loop over all possible subgraphs, and calculate a mean for each
        end = len(yarr)
        means = []
        while end > 0:
            start = 0
            while start < end:
                means.append(yarr[start:end].mean())
                start += 1
            end -= 1

        # Jackknife means
        jack_means = [np.delete(yarr, i).mean() for i in range(len(yarr))]

        # Do plotting & peak finding in both ROOT and MPL...not sure which is better?
        # peak = plot_find_peak_mpl(means, eta_min, eta_max, os.path.dirname(os.path.realpath(filename)))
        peak = plot_find_peak_root(means, eta_min, eta_max, os.path.dirname(os.path.realpath(filename)))
        jackpeak = plot_jacknife_root(jack_means, eta_min, eta_max, os.path.dirname(os.path.realpath(filename)))
        print 'Eta bin:', eta_min, '-', eta_max
        print peak
        print 'jackknife mean:'
        print np.array(jack_means).mean()

    f.Close()