def setUp(self):
        self.acc_map = create_histogram(np.random.uniform(0, 1, (10000, 2)),
                                        (20, 0, 1, 10, 0, 1))
        self.acc_map.Scale(1.0 / self.acc_map.Integral())

        self.acc_map3 = create_histogram(np.random.uniform(0, 1, (100000, 3)),
                                         (10, 0, 1, 10, 0, 1, 5, 0, 1))
        self.acc_map3.Scale(1.0 / self.acc_map3.Integral())
Exemplo n.º 2
0
def make_pt_eta_plot(plotvar, cuts, cut_plot_set, savename):
    """
    Make pt-eta plot (2D) for passed variables and overlay the passed cuts
    """
    pt_eta_hist = (50, 0, 20, 24, 0, 2.4)
    pt_eta = create_histogram(plotvar, pt_eta_hist)

    pt_eta.SetXTitle('p_{T}')
    pt_eta.SetYTitle('|#eta|')

    can = r.TCanvas(create_random_str(), 'c', 600, 600)
    can.cd()
    pt_eta.Draw('colz')

    # lines = {c: [] for c in cuts} # keep the TLines alive long enough for saving
    lines = []
    for cut in cuts.values():
        lines.append(draw_line(cut()))

    for i, cut in enumerate(lines):
        plot_on_canvas(can, cut, attr=(cut_plot_set[i], ))

    leg = r.TLegend(0.5, 0.3, 0.8, 0.4)
    leg.SetTextColor(0)
    leg.SetBorderSize(0)
    leg.SetFillStyle(0)

    for i, cut in enumerate(cuts.keys()):
        leg.AddEntry(lines[i][0], cut, 'l')
    leg.Draw()

    can.Update()
    # can.SaveAs(savename)

    return can, pt_eta, lines  # for ipython so that they survive
Exemplo n.º 3
0
def _get_hist(ndim):
    """Create a histogram of a given dimensionality"""
    if ndim == 3:
        return hu.create_histogram(np.random.uniform(0, 1, (10000, 3)),
                                   (10, 0, 1, 20, 0, 1, 30, 0, 1))
    if ndim == 2:
        return hu.create_histogram(np.random.uniform(0, 1, (10000, 2)),
                                   (10, 0, 1, 20, 0, 1))
    if ndim == 1:
        return hu.create_histogram(np.random.uniform(0, 1, 10000),
                                   (10, 0, 1))
    if ndim >= 4:
        hist = r.THnD('hist4d', '', ndim, np.arange(2, ndim + 2, 1, dtype='i4'),
                      np.zeros(ndim), np.ones(ndim))
        fill_vals = np.random.uniform(0, 1, (10000, ndim))
        for i in xrange(len(fill_vals)):
            hist.Fill(fill_vals[i, :])
        hist.Sumw2()
        return hist
def create_mass_hist(dfr, costh_bin=None):
    """
    Create a mass histogram in a given costh_bin (or integrated if None)
    """
    if costh_bin is not None:
        plot_data = dfr[get_bin_cut_df(dfr, lambda d: d.costh_HX.abs(),
                                       *costh_bin)]
    else:
        plot_data = dfr

    return create_histogram(plot_data.chicMass, (75, 3.325, 3.725))
def create_hist(dfr, variable, hist_sett, get_weights=None):
    """
    Create a histogram from the passed dataframe
    """
    weights = None
    if get_weights is not None and hasattr(get_weights, '__call__'):
        weights = get_weights(dfr)

    if hasattr(variable, '__call__'):
        var = variable(dfr)
    else:
        var = dfr.loc[:, variable]
    hist = create_histogram(var, hist_sett, weights=weights)

    return hist
def main(args):
    """Main"""
    # While loading also disregard the events with JpsiRap > 1.2 which have been
    # accidentally stored for parts of the generations
    data = get_dataframe(args.toymcfile,
                         columns=['costh_HX', '*eff_sm'],
                         where='TMath::Abs(JpsiRap) < 1.2')
    # per-event efficiency as product of photon x muon efficiencies
    eff = lambda d: d.gamma_eff_sm * 0.01 * d.lepP_eff_sm * d.lepN_eff_sm

    costh_binning = read_costh_binning(args.binningfile)
    hist = create_histogram(data.costh_HX.abs(),
                            costh_binning,
                            weights=eff(data),
                            name=args.name,
                            x_axis='|cos#vartheta^{HX}|')

    outfile = r.TFile.Open(args.output, 'update')
    hist.Write()
    outfile.Close()
Exemplo n.º 7
0
def create_store_dist(outfile,
                      df,
                      variable,
                      hist_sett,
                      get_weights=None,
                      **kwargs):
    """
    Create the distribution and store it to the output file
    """
    weights = None
    if get_weights is not None:
        weights = get_weights(df)

    if hasattr(variable, '__call__'):
        var = variable(df)
    else:
        var = df.loc[:, variable]
    hist = create_histogram(var, hist_sett, weights=weights, **kwargs)

    outfile.cd()
    hist.Write()