def basic_sel(df, jpsiPt, photonPt=0):
    """
    Do a basic selection that mimics analysis and acceptance cuts
    """
    return (df.muP_pt > 3) & (df.muN_pt > 3) \
        & (df.muP_eta.abs() < 1.6) & (df.muN_eta.abs() < 1.6) \
        & (df.jpsiRap.abs() < 1.2) \
        & get_bin_cut_df(df, 'jpsiPt', *jpsiPt) \
        & (df.photonPt > photonPt)
Beispiel #2
0
def jpsi_kin_sel(df, jpsiPt, noPt=False, noRap=False):
    ptname = 'JpsiPt'
    rapname = 'JpsiRap'
    selection = np.ones(df.shape[0], dtype=bool)
    if not noPt:
        selection &= get_bin_cut_df(df, ptname, *jpsiPt)
    if not noRap:
        selection &= df[rapname].abs() < 1.2
    return selection
Beispiel #3
0
def basic_sel(df, mc=False, gen=False):
    selection = np.ones(df.shape[0], dtype=bool)
    if not gen:
        selection &= get_bin_cut_df(df, 'chicMass', 3.325, 3.725)
    if not mc and not gen:
        selection &= df.vtxProb > 0.01

    # selection &= (df.costh_HX.abs() < 0.5)
    # selection &= (df.wChic1 == 1)
    return selection
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))
Beispiel #5
0
def do_chic_ratio(args):
    """
    Make the chic ratio plot
    """
    ffile = r.TFile.Open(args.fitfile)
    ws = ffile.Get('ws_mass_fit')
    outdir = get_outdir(args.outdir, args.fitfile)

    bin_sel_info = get_bin_sel_info(args.pklfile, args.fitfile)
    costh_bins = bin_sel_info['costh_bins']
    costh_means = bin_sel_info['costh_means']

    graph = get_ratio_graph(ws, 'Nchic2', ws, 'Nchic1', costh_bins,
                            costh_means)

    ptmin, ptmax = get_pt_range(bin_sel_info['basic_sel'])

    mcdf = get_dataframe(args.mcfile, 'chic_mc_tuple')
    mc_sel = (np.abs(mcdf.JpsiRap) < 1.2) & ((mcdf.trigger & 2) == 2) & \
             (mcdf.vtxProb > 0.01) & \
             (get_bin_cut_df(mcdf, 'chicPt', 0, 990)) & \
             (get_bin_cut_df(mcdf, 'JpsiPt', ptmin, ptmax))

    unpol = get_mc_ratio_graph(mcdf[mc_sel], mcdf[mc_sel], 'wChic2', 'wChic1',
                               costh_bins, costh_means, None, None)
    nrqcd = get_mc_ratio_graph(mcdf[mc_sel], mcdf[mc_sel], 'wChic2', 'wChic1',
                               costh_bins, costh_means, -0.3, 0.5)
    extreme = get_mc_ratio_graph(mcdf[mc_sel], mcdf[mc_sel], 'wChic2',
                                 'wChic1', costh_bins, costh_means, -0.6, 1)

    mc_graphs = {'unpol': unpol, 'nrqcd': nrqcd, 'extreme': extreme}

    plot_sett = {
        'range': [0, 0, 1, 0.75],
        'xtitle': '|cos#theta^{HX}|',
        'ytitle': '#chi_{c2} / #chi_{c1}'
    }

    plot_name = '{}/chic2_chic1_pt{}_{}_nbins{}_costh_HX.pdf'.format(
        outdir, ptmin, ptmax, len(costh_bins))
    make_plot(graph, mc_graphs, plot_name, plot_sett)
Beispiel #6
0
def get_mc_vals(dfr, state, costh_bins, pol=None):
    """
    Get the number of events in each costh_bin for a given pol scenario
    """
    if pol is None:
        weight = state
    else:
        weight = get_storable_name('wPol_HX_lth_{:.2f}'.format(pol))

    state_sel = dfr[state] == 1  # select the events for a given state

    vals = []
    for ctbin in costh_bins:
        costh_sel = get_bin_cut_df(dfr, lambda d: np.abs(d.costh_HX), *ctbin)
        bin_events = dfr[costh_sel & state_sel][weight].sum()
        vals.append((
            bin_events,
            np.sqrt(bin_events),
        ))

    return vals
Beispiel #7
0
def create_costh_binned_hists(dfr, hist_func, selection_weights, binning):
    """
    Create the histograms in costh bins
    """
    hists = OrderedDict()
    for name in selection_weights:
        sel_f, sel_w = selection_weights[name]
        hists[name] = OrderedDict()

        # Apply the selections as soon as possible and don't repeat them
        sel_dfr = apply_selections(dfr, sel_f)

        for bin_low, bin_high in zip(binning[:-1], binning[1:]):
            binname = '{:.2f}_{:.2f}'.format(bin_low, bin_high)
            bin_f = lambda d: get_bin_cut_df(d, lambda d: d.costh_HX.abs(),
                                             bin_low, bin_high),
            hists[name][binname] = hist_func(sel_dfr, bin_f, sel_w)

    # Rearrange histograms so that the dictionary is flat
    flat_hists = OrderedDict()
    for sel in hists:
        for cbin in hists[sel]:
            flat_hists['_'.join([sel, cbin])] = hists[sel][cbin]
    return flat_hists
Beispiel #8
0
def do_jpsi_ratios(args):
    """
    Make the jpsi ratio plots
    """
    chic_ff = r.TFile.Open(args.chic_ff)
    chic_ws = chic_ff.Get('ws_mass_fit')
    jpsi_ff = r.TFile.Open(args.jpsi_ff)
    jpsi_ws = jpsi_ff.Get('ws_mass_fit')
    outdir = get_outdir(args.outdir, args.chic_ff)

    # Only need the chic information here, since the information in the J/psi
    # file that is needed here is redundant
    bin_info = get_bin_sel_info(args.pklfile, args.chic_ff)
    costh_bins = bin_info['costh_bins']
    costh_means = bin_info['costh_means']

    chic1_graph = get_ratio_graph(chic_ws, 'Nchic1', jpsi_ws, 'Njpsi',
                                  costh_bins, costh_means)
    chic2_graph = get_ratio_graph(chic_ws, 'Nchic2', jpsi_ws, 'Njpsi',
                                  costh_bins, costh_means)

    ptmin, ptmax = get_pt_range(bin_info['basic_sel'])

    chic_df = get_dataframe(args.mc_chic, 'chic_mc_tuple')
    chic_sel_mc = (np.abs(chic_df.JpsiRap) < 1.2) & \
                  ((chic_df.trigger & 2) == 2) & (chic_df.vtxProb > 0.01) & \
                  (get_bin_cut_df(chic_df, 'chicPt', 0, 990)) & \
                  (get_bin_cut_df(chic_df, 'JpsiPt', ptmin, ptmax))

    jpsi_df = get_dataframe(args.mc_jpsi, 'jpsi_mc_tuple')
    jpsi_sel_mc = (np.abs(jpsi_df.JpsiRap) < 1.2) & (jpsi_df.trigger == 1) & \
                  (jpsi_df.vtxProb > 0.01) & \
                  (get_bin_cut_df(jpsi_df, 'JpsiPt', ptmin, ptmax))

    unpol = get_mc_ratio_graph(chic_df[chic_sel_mc], jpsi_df[jpsi_sel_mc],
                               'wChic1', 'wJpsi', costh_bins, costh_means,
                               None, None)
    nrqcd = get_mc_ratio_graph(chic_df[chic_sel_mc], jpsi_df[jpsi_sel_mc],
                               'wChic1', 'wJpsi', costh_bins, costh_means, 0.5,
                               None)
    extreme = get_mc_ratio_graph(chic_df[chic_sel_mc], jpsi_df[jpsi_sel_mc],
                                 'wChic1', 'wJpsi', costh_bins, costh_means, 1,
                                 None)
    can = r.TCanvas('rcan', 'rcan', 50, 50, 600, 600)
    frame = can.DrawFrame(0, 0, 1, 0.1)

    mc_graphs = {'unpol': unpol, 'nrqcd': nrqcd, 'extreme': extreme}
    plot_sett = {
        'range': [0, 0, 1, 0.125],
        'xtitle': '|cos#theta^{HX}|',
        'ytitle': '#chi_{c1} / J/#psi'
    }
    plot_name = '{}/chic1_jpsi_pt{}_{}_nbins{}_costh_HX.pdf'.format(
        outdir, ptmin, ptmax, len(costh_bins))
    make_plot(chic1_graph, mc_graphs, plot_name, plot_sett)

    unpol = get_mc_ratio_graph(chic_df[chic_sel_mc], jpsi_df[jpsi_sel_mc],
                               'wChic2', 'wJpsi', costh_bins, costh_means,
                               None, None)
    nrqcd = get_mc_ratio_graph(chic_df[chic_sel_mc], jpsi_df[jpsi_sel_mc],
                               'wChic2', 'wJpsi', costh_bins, costh_means,
                               -0.3, None)
    extreme = get_mc_ratio_graph(chic_df[chic_sel_mc], jpsi_df[jpsi_sel_mc],
                                 'wChic2', 'wJpsi', costh_bins, costh_means,
                                 -0.6, None)
    mc_graphs = {'unpol': unpol, 'nrqcd': nrqcd, 'extreme': extreme}

    plot_sett['range'] = [0, 0, 1, 0.075]
    plot_sett['ytitle'] = '#chi_{c2} / J/#psi'
    plot_name = plot_name.replace('chic1', 'chic2')
    make_plot(chic2_graph, mc_graphs, plot_name, plot_sett)
Beispiel #9
0
def jpsi_pt_M_sel(dfr, min_ptM=2.3, max_ptM=5.2, gen=False):
    """Kinematic J/psi selection using a Jpsi pT / chicMass selection"""
    jpsi_pt = sf.get_gen_name('JpsiPt', gen)
    chic_mass = sf.get_gen_name('chicMass', gen)
    pt_M = lambda d: _get_var(d, jpsi_pt) / _get_var(d, chic_mass)
    return get_bin_cut_df(dfr, pt_M, min_ptM, max_ptM)