Esempio n. 1
0
def h1_invmass(counts, cent_class, pt_range, ct_range, name=''):
    th1 = aghast.to_root(
        counts,
        f'ct{ct_range[0]}{ct_range[1]}_pT{pt_range[0]}{pt_range[1]}_cen{cent_class[0]}{cent_class[1]}_{name}'
    )

    for index in range(0, len(counts)):
        th1.SetBinContent(index + 1, counts[index])
        th1.SetBinError(index + 1, math.sqrt(counts[index]))

    th1.SetDirectory(0)

    return th1
Esempio n. 2
0
def mass_fitter(hist, score, efficiency):
    aghast_hist = aghast.from_numpy(hist)
    root_hist = aghast.to_root(aghast_hist,
                               'Efficiency ' + str(np.round(efficiency, 4)))

    root_hist.SetTitle('Counts as a function of mass;m [GeV/c^{2}];Counts')

    canvas = ROOT.TCanvas()
    root_hist.Draw()
    canvas.Draw()

    #gaus = ROOT.TF1('gaus','gaus',2.96,3.04)
    #bkg = ROOT.TF1('poly','pol 2',2.96,3.04)
    total = ROOT.TF1('total', 'pol1(0) + gaus(2)', 2.96, 3.04)
    total.SetParameter(3, 2.992)
    total.SetParLimits(3, 2.99, 2.995)
    total.SetParameter(2, 100)  #26
    total.SetParameter(4, 0.0032)
    total.SetParLimits(4, 0.001, 0.01)
    '''
    gaus.SetLineColor( 1 )
    bkg.SetLineColor( 2 )
    total.SetLineColor( 3 )

    root_hist.Fit('gaus','R','',2.985,3.005)
    root_hist.Fit('poly','R+','',2.96,3.04)

    par = array( 'd', 6*[0.] )
    gaus_par = gaus.GetParameters()
    poly_par = bkg.GetParameters()
    par[0], par[1], par[2] = gaus_par[0], gaus_par[1], gaus_par[2]
    par[3], par[4], par[5] = poly_par[0], poly_par[1], poly_par[2]
    '''
    #total.SetParameters(par)

    total.SetNpx(1000)
    #root_hist.Fit('total', 'R+', '',2.96,3.04)

    ROOT.gStyle.SetOptFit(1111)
    canvas.SaveAs('../analysis/images/mass_distr_LS/LS_hist_eff_' +
                  str(np.round(efficiency, 4)) + '.png')

    count = total.GetParameters()[2]
    error = total.GetParError(2)
    return count, error
Esempio n. 3
0
def test_root_oned(cls):
    before = cls(rootname(), "title", 5, -2.0, 2.0)
    before.GetXaxis().SetTitle("title2")
    after = aghast.to_root(aghast.from_root(before), rootname())
    check1d(before, after)

    before = cls(rootname(), "title", 5, -2.0, 2.0)
    before.GetXaxis().SetTitle("title2")
    for x in data:
        before.Fill(x)
    after = aghast.to_root(aghast.from_root(before), rootname())
    check1d(before, after)

    before = cls(rootname(), "title", 5, -2.0, 2.0)
    before.GetXaxis().SetTitle("title2")
    for i, x in enumerate(["one", "two", "three", "four", "five"]):
        before.GetXaxis().SetBinLabel(i + 1, x)
    after = aghast.to_root(aghast.from_root(before), rootname())
    check1d(before, after)

    before = cls(rootname(), "title", 5, -5.0, 5.0)
    before.GetXaxis().SetTitle("title2")
    for i, x in enumerate(["one", "two", "three", "four", "five"]):
        before.GetXaxis().SetBinLabel(i + 1, x)
    for x in data:
        before.Fill(x)
    after = aghast.to_root(aghast.from_root(before), rootname())
    check1d(before, after)

    edges = numpy.array([-5.0, -3.0, 0.0, 5.0, 10.0, 100.0], dtype=numpy.float64)
    before = cls(rootname(), "title", 5, edges)
    before.GetXaxis().SetTitle("title2")
    after = aghast.to_root(aghast.from_root(before), rootname())
    check1d(before, after)

    edges = numpy.array([-5.0, -3.0, 0.0, 5.0, 10.0, 100.0], dtype=numpy.float64)
    before = cls(rootname(), "title", 5, edges)
    before.GetXaxis().SetTitle("title2")
    for x in data:
        before.Fill(x)
    after = aghast.to_root(aghast.from_root(before), rootname())
    check1d(before, after)
df_rec2 = uproot.open("../../Tables/SignalTable_20l2_mtexp.root")["SignalTable"].arrays(library='pd')
df_sim2 = uproot.open("../../Tables/SignalTable_20l2_mtexp.root")["GenTable"].arrays(library='pd')


pt_bins = np.linspace(0.5, 9, 40)

rec_hist = np.histogram(df_rec['pt'], pt_bins)
sim_hist = np.histogram(df_sim['pt'], pt_bins)


rec_hist2 = np.histogram(df_rec2['pt'], pt_bins)
sim_hist2 = np.histogram(df_sim2['pt'], pt_bins)

ghost_hist = aghast.from_numpy(rec_hist)
rec_hist = aghast.to_root(ghost_hist, 'Efficiency_vs_pt')
rec_hist.GetXaxis().SetTitle("#it{p}_{T} GeV/c");
ghost_hist = aghast.from_numpy(sim_hist)
sim_hist = aghast.to_root(ghost_hist, 'sim_hist')
rec_hist.Divide(sim_hist)

ghost_hist2 = aghast.from_numpy(rec_hist2)
rec_hist2 = aghast.to_root(ghost_hist2, 'Efficiency_vs_pt_2')
rec_hist2.GetXaxis().SetTitle("#it{p}_{T} GeV/c");
ghost_hist2 = aghast.from_numpy(sim_hist2)
sim_hist2 = aghast.to_root(ghost_hist2, 'sim_hist2')
rec_hist2.Divide(sim_hist2)
rec_hist2.SetLineColor(ROOT.kRed)

leg = ROOT.TLegend(0.15,0.75,0.7,0.85)
leg.AddEntry(rec_hist)
Esempio n. 5
0
input_dir = os.environ['HYPERML_DATA_2'] + "/splines_trees"
output_dir = os.environ['HYPERML_TABLES_2'] + "/splines_tables"

ct_bins = np.array([0, 1, 2, 4, 6, 8, 10, 14, 18, 23, 35], "d")

pt_shape_list = ["bol", "mtexp", "bw"]

hist_list = []

for pt_shape in pt_shape_list:
    GenerateTableFromMC(True, input_dir, output_dir, pt_shape)
    rec = np.histogram(
        uproot.open(output_dir +
                    "/SignalTable.root")["SignalTable"].array("ct"),
        bins=ct_bins)
    sim = np.histogram(
        uproot.open(output_dir + "/SignalTable.root")["GenTable"].array("ct"),
        bins=ct_bins)
    th1_rec = aghast.to_root(rec, "PreselEff_" + pt_shape)
    th1_rec.SetTitle(";c#it{t} (cm);Preselection efficiency")
    th1_sim = aghast.to_root(sim, "Sim_" + pt_shape)
    th1_rec.Divide(th1_sim)
    hist_list.append(th1_rec)

tfile = TFile(os.environ['HYPERML_EFFICIENCIES_2'] + "/pt_shape_comparison",
              "recreate")
for hist in hist_list:
    hist.Write()
tfile.Close()
Esempio n. 6
0
signal_array040 = np.array(signal_list040)
error_array040 = np.array(error_list040)

bdt_eff_array = np.repeat(bdt_eff_array, 3)

corrected_counts = signal_array040 / n_events040 / branching_ratio / presel_eff / bdt_eff_array
corrected_error = error_array040 / n_events040 / branching_ratio / presel_eff / bdt_eff_array
Yield = corrected_counts / 2 / 0.98
Yield_error = corrected_error / 2 / 0.98

print('Systemtic uncertainty: ', 100 * (np.std(Yield) / 6.27e-07), '%')

numpy_hist = np.histogram(Yield, bins=15)
ghost_hist = aghast.from_numpy(numpy_hist)
root_hist = aghast.to_root(ghost_hist, 'multi_trial')

Fcn1 = ROOT.TLine(6.27e-07, root_hist.GetMinimum(), 6.27e-07,
                  root_hist.GetMaximum())
Fcn1.SetLineWidth(1)
Fcn1.SetLineStyle(2)
Fcn1.SetLineColor(ROOT.kRed - 3)

cv = ROOT.TCanvas(f"syst_multi_trial")

root_hist.Draw()
Fcn1.Draw('lsame')
leg1 = ROOT.TLegend(.68, 0.26, .78, 0.43)
leg1.SetFillStyle(0)
leg1.SetMargin(0.2)
leg1.SetBorderSize(0)