def hit_en(): #hit energy infile = "/home/jaroslav/sim/lmon/data/beam-gas/bg3d/rc.root" emin = -9 emax = 9 ebin = 0.1 inp = TFile.Open(infile) htree = inp.Get("htree") #can = ut.box_canvas() hE = ut.prepare_TH1D("hE", ebin, emin, emax) htree.Draw("TMath::Log10(en*1e6) >> hE", "zpos<150.") xp, yp = ut.h1_to_arrays(hE) infile2 = "/home/jaroslav/sim/lmon/data/beam-gas/bg3e/rc.root" inp2 = TFile.Open(infile2) htree2 = inp2.Get("htree") hE2 = ut.prepare_TH1D("hE2", ebin, emin, emax) htree2.Draw("TMath::Log10(en*1e6) >> hE2", "zpos<150.") xp2, yp2 = ut.h1_to_arrays(hE2) #plot #plt.style.use("dark_background") #col = "lime" col = "black" fig = plt.figure() 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(xp2, yp2, "-", color="red", lw=1) ax.set_xlabel("Incident hit energy (keV)") ax.set_ylabel("Counts") leg = legend() leg.add_entry(leg_lin("red"), "$E_\gamma$ > 10 keV") leg.add_entry(leg_lin("blue"), "$E_\gamma$ > 100 keV") leg.draw(plt, col) ax.set_yscale("log") plt.xticks(ax.get_xticks()[1:-1], ["$10^{"+"{0:.0f}".format(i)+"}$" for i in ax.get_xticks()[1:-1]]) fig.savefig("01fig.pdf", bbox_inches = "tight") plt.close()
def make_h1(infile, tnam, val, xbin, xmin, xmax): inp = TFile.Open(infile) tree = inp.Get(tnam) #tree.Print() hx = ut.prepare_TH1D("hx", xbin, xmin, xmax) tree.Draw(val + " >> hx") #ut.norm_to_integral(hx, 1.) return ut.h1_to_arrays(hx)
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 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()