def make_py(): #Pythia6 total cross section sigma_py = 54.700142803416348 # micro barn infile = "../data/lmon_py_18x275_Q2all_beff2_5Mevt.root" lqbin = 0.2 lqmin = -11 lqmax = 5 inp = TFile.Open(infile) tree = inp.Get("DetectorTree") #can = ut.box_canvas() hQ2 = ut.prepare_TH1D("hQ2", lqbin, lqmin, lqmax) tree.Draw("TMath::Log10(true_Q2) >> hQ2") ut.norm_to_integral(hQ2, sigma_py) gPy = ut.h1_to_graph(hQ2) gPy.SetLineColor(rt.kRed) gPy.SetLineWidth(3) gPy.SetLineStyle(rt.kDashed) return gPy #print hQ2.Integral("width") hQ2.Draw() ut.invert_col(rt.gPad) can.SaveAs("01fig.pdf")
def make_qr_5x41(): #quasi-real total cross section for 5x41 beams sigma_qr = 65.0648514567 # micro barn infile = "../../lgen/data/lgen_5x41_qr_Qe_5Mevt.root" lqbin = 0.2 lqmin = -11 lqmax = 5 inp = TFile.Open(infile) tree = inp.Get("ltree") hQ2 = ut.prepare_TH1D("hQ2", lqbin, lqmin, lqmax) tree.Draw("TMath::Log10(true_Q2) >> hQ2") ut.norm_to_integral(hQ2, sigma_qr) gQr = ut.h1_to_graph(hQ2) gQr.SetLineColor(rt.kBlue) gQr.SetLineWidth(3) return gQr
def make_qr(): #quasi-real total cross section #sigma_qr = 53.839868617 # micro barn #infile = "../data/lmon_18x275_qr_Qd_beff2_5Mevt.root" sigma_qr = 55.1027755249 # micro barn infile = "../../lgen/data/lgen_18x275_qr_Qe_beff2_5Mevt.root" lqbin = 0.2 lqmin = -11 lqmax = 5 inp = TFile.Open(infile) #tree = inp.Get("DetectorTree") tree = inp.Get("ltree") #can = ut.box_canvas() hQ2 = ut.prepare_TH1D("hQ2", lqbin, lqmin, lqmax) tree.Draw("TMath::Log10(true_Q2) >> hQ2") ut.norm_to_integral(hQ2, sigma_qr) gQr = ut.h1_to_graph(hQ2) gQr.SetLineColor(rt.kRed) gQr.SetLineWidth(3) return gQr hQ2.Draw() ut.invert_col(rt.gPad) can.SaveAs("01fig.pdf")
def make_sigma_2(inp, plot, xbin, xmin, xmax, sigma, tnam="ltree"): #cross section in two binning intervals from the tree infile = TFile.Open(inp) tree = infile.Get(tnam) #point to start longer bins xmid = 1 bin2 = xbin * 10. # 4. hx = ut.prepare_TH1D_vec("hx", ut.get_bins_vec_2pt(xbin, bin2, xmin, xmax, xmid)) tree.Draw(plot + " >> hx") #normalize to the width of each bin, necessary for variable binning for ibin in range(hx.GetNbinsX() + 1): hx.SetBinContent(ibin, hx.GetBinContent(ibin) / hx.GetBinWidth(ibin)) ut.norm_to_integral(hx, sigma) gx = ut.h1_to_graph(hx) gx.SetLineWidth(3) return gx
def make_qr_10x100(): #quasi-real total cross section for 10x100 beams sigma_qr = 56.3121075698 # micro barn infile = "../../lgen/data/lgen_10x100_qr_Qe_5Mevt.root" lqbin = 0.2 lqmin = -11 lqmax = 5 inp = TFile.Open(infile) tree = inp.Get("ltree") hQ2 = ut.prepare_TH1D("hQ2", lqbin, lqmin, lqmax) tree.Draw("TMath::Log10(true_Q2) >> hQ2") ut.norm_to_integral(hQ2, sigma_qr) gQr = ut.h1_to_graph(hQ2) gQr.SetLineColor(rt.kYellow + 1) gQr.SetLineWidth(3) return gQr
def get_en(infile, ebin=0.5): emax = 100. inp_lmon = TFile.Open(infile) tree = inp_lmon.Get("bunch") hE = ut.prepare_TH1D("hE", ebin, 0, emax) #tree.Draw("bun_up_en+bun_down_en >> hE", "(bun_up_en>1)&&(bun_down_en>1)", "", 1000) tree.Draw("bun_up_en+bun_down_en >> hE", "(bun_up_en>1)&&(bun_down_en>1)") ut.norm_to_integral(hE, 1.) return ut.h1_to_arrays(hE)
def lq_rec(): #spectrum of reconstructed log_10(Q^2) #infile = "/home/jaroslav/sim/lmon/data/taggers/tag1a/Q2rec_s1.root" #infile = "/home/jaroslav/sim/lmon/data/taggers/tag1a/Q2rec_s2.root" #infile = "/home/jaroslav/sim/lmon/data/taggers/tag1ax1/Q2rec_s1.root" #infile = "/home/jaroslav/sim/lmon/data/taggers/tag1ax1/Q2rec_s2.root" #infile = "/home/jaroslav/sim/lmon/data/luminosity/lm2ax2/Q2rec_s1.root" infile = "/home/jaroslav/sim/lmon/data/luminosity/lm2ax2/Q2rec_s2.root" #range along x in log_10(Q^2) (GeV^2) xmin = -10 xmax = -1 xbin = 0.1 inp = TFile.Open(infile) tree = inp.Get("Q2rec") hx = ut.prepare_TH1D("hx", xbin, xmin, xmax) tree.Draw("rec_lq >> hx") ut.norm_to_integral(hx, 1) xp, yp = ut.h1_to_arrays(hx) #plot plt.style.use("dark_background") col = "lime" #col = "black" fig = plt.figure() fig.set_size_inches(5, 5) ax = fig.add_subplot(1, 1, 1) set_axes_color(ax, col) set_grid(plt, col) plt.plot(xp, yp, "-", color="blue", lw=1) ax.set_xlabel("lQ2 (GeV2)") ax.set_ylabel("Normalized counts") ax.set_yscale("log") #plt.xticks(ax.get_xticks()[1:-1], ["$10^{"+"{0:.0f}".format(i+6)+"}$" for i in ax.get_xticks()[1:-1]]) fig.savefig("01fig.pdf", bbox_inches="tight") plt.close()
def loat_flat_pt2(): bgen = TFile.Open( "/home/jaroslav/sim/bgen_tx/bgen_pTsq0p14_eta1p2_6Mevt.root") bgen_tree = bgen.Get("bgen_tree") hFlat = ut.prepare_TH1D("hFlat", 0.002, 0., 0.12) bgen_tree.Draw("pT2rec >> hFlat") ut.norm_to_integral(hFlat, 0.025) # norm to Starlight gFlat = ut.h1_to_graph(hFlat) gFlat.SetLineColor(rt.kViolet) gFlat.SetLineWidth(3) gFlat.SetLineStyle(rt.kDashed) return gFlat
def make_sigma(inp, plot, xbin, xmin, xmax, sigma, tnam="ltree"): #cross section plot from the tree infile = TFile.Open(inp) tree = infile.Get(tnam) hx = ut.prepare_TH1D("hx", xbin, xmin, xmax) tree.Draw(plot + " >> hx") ut.norm_to_integral(hx, sigma) #gx = ut.h1_to_graph(hx) gx = ut.h1_to_graph_nz(hx) gx.SetLineWidth(3) return gx
def make_sigma(inp, sigma): lqbin = 0.2 lqmin = -11 lqmax = 5 infile = TFile.Open(inp) tree = infile.Get("ltree") hx = ut.prepare_TH1D("hx", lqbin, lqmin, lqmax) tree.Draw("TMath::Log10(true_Q2) >> hx") ut.norm_to_integral(hx, sigma) gx = ut.h1_to_graph(hx) #gx.SetLineColor(rt.kYellow+1) gx.SetLineWidth(3) return gx
def load_sartre(): sartre = TFile.Open( "/home/jaroslav/sim/sartre_tx/sartre_AuAu_200GeV_Jpsi_coh_2p7Mevt.root" ) sartre_tree = sartre.Get("sartre_tree") hSartre = ut.prepare_TH1D("hSartre", 0.002, 0., 0.12) sartre_tree.Draw("-tval >> hSartre", "rapidity>-1 && rapidity<1") ut.norm_to_integral(hSartre, 0.025) # now same as Starlight gSartre = TGraphErrors(hSartre.GetNbinsX()) for ibin in xrange(1, hSartre.GetNbinsX() + 1): gSartre.SetPoint(ibin - 1, hSartre.GetBinCenter(ibin), hSartre.GetBinContent(ibin)) gSartre.SetLineColor(rt.kYellow + 1) gSartre.SetLineWidth(3) #gSartre.SetLineStyle(rt.kDashDotted) return gSartre
def load_starlight(dy): slight = TFile.Open( "/home/jaroslav/sim/starlight_tx/slight_AuAu_200GeV_Jpsi_coh_intmax0p34_6Mevt.root" ) slight_tree = slight.Get("slight_tree") #hSlight = ut.prepare_TH1D("hSlight", 0.002, 0., 0.12) hSlight = ut.prepare_TH1D_vec( "hSlight", ut.get_bins_vec_2pt(0.0002, 0.002, 0, 0.12, 0.004)) nall = float(slight_tree.GetEntries()) ny = float( slight_tree.Draw("pT*pT >> hSlight", "rapidity>-1 && rapidity<1")) #normalize to the width of each bin, necessary for variable binning for ibin in xrange(hSlight.GetNbinsX() + 1): hSlight.SetBinContent( ibin, hSlight.GetBinContent(ibin) / hSlight.GetBinWidth(ibin)) sigma_sl_tot = 67.958 # total Starlight cross section, ub sigma_sl = (ny / nall) * sigma_sl_tot / 1000. # ub to mb sigma_sl = sigma_sl / dy # rapidity interval print "sigma_sl:", sigma_sl #normalize to Starlight total cross section ut.norm_to_integral(hSlight, sigma_sl) #convert to graph gSlight = ut.h1_to_graph(hSlight) gSlight.SetLineColor(rt.kBlue) gSlight.SetLineWidth(3) gSlight.SetLineStyle(9) # kDashDotted return gSlight
def xres(): #position resolution #mm xmin = -20 xmax = 20 xbin = 2 infile = "bpc.root" inp = TFile.Open(infile) tree = inp.Get("bpc") hx = ut.prepare_TH1D("hx", xbin, xmin, xmax) tree.Draw("xrec >> hx") ut.norm_to_integral(hx, 1) xp, yp = ut.h1_to_arrays(hx) #Gaussian fit cen = [] val = [] for i in range(1, hx.GetNbinsX()+1): cen.append( hx.GetBinCenter(i) ) val.append( hx.GetBinContent(i) ) pars, cov = curve_fit(lambda x, mu, sig : norm.pdf(x, loc=mu, scale=sig), cen, val) #print(cen, val) #fit function x = np.linspace(cen[0], cen[-1], 300) y = norm.pdf(x, pars[0], pars[1]) #plot plt.style.use("dark_background") col = "lime" #col = "black" fig = plt.figure() fig.set_size_inches(5, 5) ax = fig.add_subplot(1, 1, 1) set_axes_color(ax, col) set_grid(plt, col) plt.plot(xp, yp, "-", color="blue", lw=1) plt.plot(x, y, "-", color="red", lw=1) ax.set_xlabel("x (mm)") ax.set_ylabel("counts") #ax.set_yscale("log") leg = legend() leg.add_entry(leg_lin("red"), "Gaussian fit") leg.add_entry(leg_txt(), "mean: {0:.3f}".format(pars[0])) leg.add_entry(leg_txt(), "sigma: {0:.3f}".format(pars[1])) leg.draw(plt, col) fig.savefig("01fig.pdf", bbox_inches = "tight") plt.close()
def lq_compare(): #input, color, rate in MHz by taggers/hit_rate.py #Tagger 1 inp_s1 = [\ {"in": "/home/jaroslav/sim/lmon/data/luminosity/lm2ax2/Q2rec_s1.root", "col": "red", "rate": 19.1405, "lab": "Bremsstrahlung"}, \ {"in": "/home/jaroslav/sim/lmon/data/taggers/tag1a/Q2rec_s1.root", "col": "blue", "rate": 0.002905, "lab": "Quasi-real"}, \ {"in": "/home/jaroslav/sim/lmon/data/taggers/tag1ax1/Q2rec_s1.root", "col": "orange", "rate": 0.004053, "lab": "Pythia6"} \ ] #Tagger 2 inp_s2 = [\ {"in": "/home/jaroslav/sim/lmon/data/luminosity/lm2ax2/Q2rec_s2.root", "col": "red", "rate": 22.0011, "lab": "Bremsstrahlung"}, \ {"in": "/home/jaroslav/sim/lmon/data/taggers/tag1a/Q2rec_s2.root", "col": "blue", "rate": 0.005642, "lab": "Quasi-real"}, \ {"in": "/home/jaroslav/sim/lmon/data/taggers/tag1ax1/Q2rec_s2.root", "col": "orange", "rate": 0.008656, "lab": "Pythia6"} \ ] #tnam = "Tagger 1" #inp = inp_s1 tnam = "Tagger 2" inp = inp_s2 #range along x in log_10(Q^2) (GeV^2) xmin = -10 xmax = -1 xbin = 0.1 #plot #plt.style.use("dark_background") #col = "lime" col = "black" fig = plt.figure() fig.set_size_inches(5, 5) ax = fig.add_subplot(1, 1, 1) set_axes_color(ax, col) set_grid(plt, col) leg = legend() leg.add_entry(leg_txt(), tnam) #inputs loop for i in inp: infile = TFile.Open(i["in"]) tree = infile.Get("Q2rec") hx = ut.prepare_TH1D("hx_" + i["col"], xbin, xmin, xmax) tree.Draw("rec_lq >> hx_" + i["col"]) ut.norm_to_integral(hx, i["rate"]) xp, yp = ut.h1_to_arrays(hx) leg.add_entry(leg_lin(i["col"]), i["lab"]) plt.plot(xp, yp, "-", color=i["col"], lw=1) ax.set_xlabel("Reconstructed log$_{10}(Q^2)$ (GeV$^2$)") ax.set_ylabel("Counts normalized to event rate in MHz") ax.set_yscale("log") #plt.xticks(ax.get_xticks()[1:-1], ["$10^{"+"{0:.0f}".format(i+6)+"}$" for i in ax.get_xticks()[1:-1]]) leg.draw(plt, col) fig.savefig("01fig.pdf", bbox_inches="tight") plt.close()