def pdf_logPt2_incoh(): #PDF fit to log_10(pT^2) #tree_in = tree_incoh tree_in = tree #ptbin = 0.04 ptbin = 0.12 ptmin = -5. ptmax = 1. mmin = 2.8 mmax = 3.2 #fitran = [-5., 1.] fitran = [-0.9, 0.1] binned = False #gamma-gamma 131 evt for pT<0.18 #output log file out = open("out.txt", "w") ut.log_results( out, "in " + infile + " in_coh " + infile_coh + " in_gg " + infile_gg) loglist = [(x, eval(x)) for x in ["ptbin", "ptmin", "ptmax", "mmin", "mmax", "fitran", "binned"]] strlog = ut.make_log_string(loglist) ut.log_results(out, strlog + "\n") #input data pT = RooRealVar("jRecPt", "pT", 0, 10) m = RooRealVar("jRecM", "mass", 0, 10) dataIN = RooDataSet("data", "data", tree_in, RooArgSet(pT, m)) strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax) data = dataIN.reduce(strsel) #x is RooRealVar for log(Pt2) draw = "TMath::Log10(jRecPt*jRecPt)" draw_func = RooFormulaVar("x", "log_{10}( #it{p}_{T}^{2} ) (GeV^{2})", draw, RooArgList(pT)) x = data.addColumn(draw_func) x.setRange("fitran", fitran[0], fitran[1]) #binned data nbins, ptmax = ut.get_nbins(ptbin, ptmin, ptmax) hPt = TH1D("hPt", "hPt", nbins, ptmin, ptmax) tree_in.Draw(draw + " >> hPt", strsel) dataH = RooDataHist("dataH", "dataH", RooArgList(x), hPt) #range for plot x.setMin(ptmin) x.setMax(ptmax) x.setRange("plotran", ptmin, ptmax) #create the pdf b = RooRealVar("b", "b", 5., 0., 10.) pdf_func = "log(10.)*pow(10.,x)*exp(-b*pow(10.,x))" pdf_logPt2 = RooGenericPdf("pdf_logPt2", pdf_func, RooArgList(x, b)) #make the fit if binned == True: r1 = pdf_logPt2.fitTo(dataH, rf.Range("fitran"), rf.Save()) else: r1 = pdf_logPt2.fitTo(data, rf.Range("fitran"), rf.Save()) ut.log_results(out, ut.log_fit_result(r1)) #calculate norm to number of events xset = RooArgSet(x) ipdf = pdf_logPt2.createIntegral(xset, rf.NormSet(xset), rf.Range("fitran")) print "PDF integral:", ipdf.getVal() if binned == True: nevt = tree_incoh.Draw( "", strsel + " && " + draw + ">{0:.3f}".format(fitran[0]) + " && " + draw + "<{1:.3f}".format(fitran[0], fitran[1])) else: nevt = data.sumEntries("x", "fitran") print "nevt:", nevt pdf_logPt2.setNormRange("fitran") print "PDF norm:", pdf_logPt2.getNorm(RooArgSet(x)) #a = nevt/ipdf.getVal() a = nevt / pdf_logPt2.getNorm(RooArgSet(x)) ut.log_results(out, "log_10(pT^2) parametrization:") ut.log_results(out, "A = {0:.2f}".format(a)) ut.log_results(out, ut.log_fit_parameters(r1, 0, 2)) print "a =", a #Coherent contribution hPtCoh = ut.prepare_TH1D("hPtCoh", ptbin, ptmin, ptmax) hPtCoh.Sumw2() #tree_coh.Draw(draw + " >> hPtCoh", strsel) tree_coh.Draw("TMath::Log10(jGenPt*jGenPt) >> hPtCoh", strsel) ut.norm_to_data(hPtCoh, hPt, rt.kBlue, -5., -2.2) # norm for coh #ut.norm_to_data(hPtCoh, hPt, rt.kBlue, -5, -2.1) #ut.norm_to_num(hPtCoh, 405, rt.kBlue) print "Coherent integral:", hPtCoh.Integral() #TMath::Log10(jRecPt*jRecPt) #Sartre generated coherent shape 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", ptbin, ptmin, ptmax) sartre_tree.Draw("TMath::Log10(pT*pT) >> hSartre", "rapidity>-1 && rapidity<1") ut.norm_to_data(hSartre, hPt, rt.kViolet, -5, -2) # norm for Sartre #gamma-gamma contribution hPtGG = ut.prepare_TH1D("hPtGG", ptbin, ptmin, ptmax) tree_gg.Draw(draw + " >> hPtGG", strsel) #ut.norm_to_data(hPtGG, hPt, rt.kGreen, -5., -2.9) ut.norm_to_num(hPtGG, 131., rt.kGreen) print "Int GG:", hPtGG.Integral() #psi' contribution psiP = TFile.Open(basedir_mc + "/ana_slight14e4x1_s6_sel5z.root") psiP_tree = psiP.Get("jRecTree") hPtPsiP = ut.prepare_TH1D("hPtPsiP", ptbin, ptmin, ptmax) psiP_tree.Draw(draw + " >> hPtPsiP", strsel) ut.norm_to_num(hPtPsiP, 12, rt.kViolet) #sum of all contributions hSum = ut.prepare_TH1D("hSum", ptbin, ptmin, ptmax) hSum.SetLineWidth(3) #add ggel to the sum hSum.Add(hPtGG) #add incoherent contribution func_logPt2 = TF1("pdf_logPt2", "[0]*log(10.)*pow(10.,x)*exp(-[1]*pow(10.,x))", -10., 10.) func_logPt2.SetParameters(a, b.getVal()) hInc = ut.prepare_TH1D("hInc", ptbin, ptmin, ptmax) ut.fill_h1_tf(hInc, func_logPt2) hSum.Add(hInc) #add coherent contribution hSum.Add(hPtCoh) #add psi(2S) contribution #hSum.Add(hPtPsiP) #set to draw as a lines ut.line_h1(hSum, rt.kBlack) #create canvas frame can = ut.box_canvas() ut.set_margin_lbtr(gPad, 0.11, 0.09, 0.01, 0.01) frame = x.frame(rf.Bins(nbins), rf.Title("")) frame.SetTitle("") frame.SetMaximum(75) frame.SetYTitle("Events / ({0:.3f}".format(ptbin) + " GeV^{2})") print "Int data:", hPt.Integral() #plot the data if binned == True: dataH.plotOn(frame, rf.Name("data")) else: data.plotOn(frame, rf.Name("data")) pdf_logPt2.plotOn(frame, rf.Range("fitran"), rf.LineColor(rt.kRed), rf.Name("pdf_logPt2")) pdf_logPt2.plotOn(frame, rf.Range("plotran"), rf.LineColor(rt.kRed), rf.Name("pdf_logPt2_full"), rf.LineStyle(rt.kDashed)) frame.Draw() amin = TMath.Power(10, ptmin) amax = TMath.Power(10, ptmax) - 1 print amin, amax pt2func = TF1("f1", "TMath::Power(10, x)", amin, amax) #TMath::Power(x, 10) aPt2 = TGaxis(-5, 75, 1, 75, "f1", 510, "-") ut.set_axis(aPt2) aPt2.SetTitle("pt2") #aPt2.Draw(); leg = ut.prepare_leg(0.57, 0.78, 0.14, 0.19, 0.03) ut.add_leg_mass(leg, mmin, mmax) hx = ut.prepare_TH1D("hx", 1, 0, 1) hx.Draw("same") ln = ut.col_lin(rt.kRed) leg.AddEntry(hx, "Data") leg.AddEntry(hPtCoh, "Sartre MC", "l") leg.AddEntry(hPtGG, "#gamma#gamma#rightarrow e^{+}e^{-} MC", "l") #leg.AddEntry(ln, "ln(10)*#it{A}*10^{log_{10}#it{p}_{T}^{2}}exp(-#it{b}10^{log_{10}#it{p}_{T}^{2}})", "l") #leg.AddEntry(ln, "Incoherent fit", "l") leg.Draw("same") l0 = ut.cut_line(fitran[0], 0.9, frame) l1 = ut.cut_line(fitran[1], 0.9, frame) #l0.Draw() #l1.Draw() desc = pdesc(frame, 0.14, 0.8, 0.054) desc.set_text_size(0.03) desc.itemD("#chi^{2}/ndf", frame.chiSquare("pdf_logPt2", "data", 2), -1, rt.kRed) desc.itemD("#it{A}", a, -1, rt.kRed) desc.itemR("#it{b}", b, rt.kRed) desc.draw() #put the sum #hSum.Draw("same") #gPad.SetLogy() frame.Draw("same") #put gamma-gamma hPtGG.Draw("same") #put coherent J/psi hPtCoh.Draw("same") #put Sartre generated coherent shape #hSartre.Draw("same") #put psi(2S) contribution #hPtPsiP.Draw("same") leg2 = ut.prepare_leg(0.14, 0.9, 0.14, 0.08, 0.03) leg2.AddEntry( ln, "ln(10)*#it{A}*10^{log_{10}#it{p}_{T}^{2}}exp(-#it{b}10^{log_{10}#it{p}_{T}^{2}})", "l") #leg2.AddEntry(hPtCoh, "Sartre MC reconstructed", "l") #leg2.AddEntry(hSartre, "Sartre MC generated", "l") leg2.Draw("same") ut.invert_col(rt.gPad) can.SaveAs("01fig.pdf")
#-- end of config -- #get input gROOT.SetBatch() inp = TFile.Open(basedir + "/" + infile) tree = inp.Get("jRecTree") #output log file out = open("out.txt", "w") #log fit parameters loglist1 = [(x, eval(x)) for x in ["infile", "mbin", "mmin", "mmax"]] loglist2 = [ (x, eval(x)) for x in ["ymin", "ymax", "ptmax", "binned", "fitran[0]", "fitran[1]"] ] strlog = ut.make_log_string(loglist1, loglist2) ut.log_results(out, strlog + "\n") #unbinned and binned input data nbins, mmax = ut.get_nbins(mbin, mmin, mmax) strsel = "jRecY>{0:.3f} && jRecY<{1:.3f} && jRecPt<{2:.3f}".format( ymin, ymax, ptmax) #unbinned data m.setMin(mmin) m.setMax(mmax) m.setRange("fitran", fitran[0], fitran[1]) dataIN = RooDataSet("data", "data", tree, RooArgSet(m, y, pT)) data = dataIN.reduce(strsel) #binned data hMass = TH1D("hMass", "hMass", nbins, mmin, mmax) tree.Draw("jRecM >> hMass", strsel)
def plot_rec_gen_track_pt(): #track pT resolution as ( pT_track_rec - pT_track_gen )/pT_track_gen ptbin = 0.001 ptmin = -0.3 ptmax = 0.1 #generated dielectron pT selection to input data ptlo = 0.2 pthi = 1 fitran = [-0.15, 0.018] mmin = 2.8 mmax = 3.2 ccb = rt.kBlue #output log file out = open("out.txt", "w") #log fit parameters loglist1 = [(x, eval(x)) for x in ["infile_mc", "ptbin", "ptmin", "ptmax"]] loglist2 = [(x, eval(x)) for x in ["ptlo", "pthi", "fitran", "mmin", "mmax"]] strlog = ut.make_log_string(loglist1, loglist2) ut.log_results(out, strlog + "\n") strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax) strsel += " && jGenPt>{0:.3f}".format(ptlo) strsel += " && jGenPt<{0:.3f}".format(pthi) #strsel = "" nbins, ptmax = ut.get_nbins(ptbin, ptmin, ptmax) hPtTrackRel = ut.prepare_TH1D_n("hPtTrackRel", nbins, ptmin, ptmax) ytit = "Events / ({0:.3f})".format(ptbin) xtit = "(#it{p}_{T, rec}^{track} - #it{p}_{T, gen}^{track})/#it{p}_{T, gen}^{track}" mctree.Draw("(jT0pT-jGenP0pT)/jGenP0pT >> hPtTrackRel", strsel) # positive charge mctree.Draw("(jT1pT-jGenP1pT)/jGenP1pT >>+hPtTrackRel", strsel) # add negative charge x = RooRealVar("x", "x", ptmin, ptmax) x.setRange("fitran", fitran[0], fitran[1]) rfPtTrackRel = RooDataHist("rfPtTrackRel", "rfPtTrackRel", RooArgList(x), hPtTrackRel) #standard Crystal Ball mean = RooRealVar("mean", "mean", -0.003, -0.1, 0.1) sigma = RooRealVar("sigma", "sigma", 0.01, 0., 0.9) alpha = RooRealVar("alpha", "alpha", 1.2, 0., 10.) n = RooRealVar("n", "n", 1.3, 0., 20.) cbpdf = RooCBShape("cbpdf", "cbpdf", x, mean, sigma, alpha, n) res = cbpdf.fitTo(rfPtTrackRel, rf.Range("fitran"), rf.Save()) #log fit results ut.log_results(out, ut.log_fit_result(res)) #generate new distribution according to the fit gROOT.LoadMacro("cb_gen.h") #Crystal Ball generator, min, max, mean, sigma, alpha, n #cbgen = rt.cb_gen(-0.18, 0.05, -0.00226, 0.00908, 1.40165, 1.114) # -0.18, 0.05 ptmin, ptmax cbgen = rt.cb_gen(-0.5, 0.05, -0.00226, 0.00908, 0.2, 2.) # -0.18, 0.05 ptmin, ptmax hRelGen = ut.prepare_TH1D_n("hRelGen", nbins, ptmin, ptmax) ut.set_H1D_col(hRelGen, rt.kBlue) #rt.cb_generate_n(cbgen, hRelGen, int(hPtTrackRel.GetEntries())) rfRelGen = RooDataHist("rfRelGen", "rfRelGen", RooArgList(x), hRelGen) #generate distribution with additional smearing applied hRelSmear = ut.prepare_TH1D_n("hRelSmear", nbins, ptmin, ptmax) ut.set_H1D_col(hRelSmear, rt.kOrange) #tcopy = mctree.CopyTree(strsel) #rt.cb_apply_smear(cbgen, mctree, hRelSmear) can = ut.box_canvas() ut.set_margin_lbtr(gPad, 0.12, 0.1, 0.05, 0.03) frame = x.frame(rf.Bins(nbins), rf.Title("")) ut.put_frame_yx_tit(frame, ytit, xtit) rfPtTrackRel.plotOn(frame, rf.Name("data")) #rfRelGen.plotOn(frame, rf.Name("data")) cbpdf.plotOn(frame, rf.Precision(1e-6), rf.Name("cbpdf"), rf.LineColor(ccb)) frame.Draw() #hRelGen.Draw("e1same") #hRelSmear.Draw("e1same") desc = pdesc(frame, 0.2, 0.8, 0.057) #x, y, sep desc.set_text_size(0.03) desc.itemD("#chi^{2}/ndf", frame.chiSquare("cbpdf", "data", 4), -1, ccb) desc.prec = 5 desc.itemR("mean", mean, ccb) desc.itemR("#sigma", sigma, ccb) desc.itemR("#alpha", alpha, ccb) desc.prec = 3 desc.itemR("#it{n}", n, ccb) desc.draw() leg = ut.prepare_leg(0.2, 0.82, 0.21, 0.12, 0.03) # x, y, dx, dy, tsiz leg.SetMargin(0.05) leg.AddEntry(0, "#bf{%.1f < #it{p}_{T}^{pair} < %.1f GeV}" % (ptlo, pthi), "") leg.Draw("same") #ut.invert_col(rt.gPad) can.SaveAs("01fig.pdf")
def plot_rec_gen_pt_relative(): # relative dielectron pT resolution as ( pT_rec - pT_gen )/pT_gen ptbin = 0.01 ptmin = -1.2 ptmax = 4 #generated pT selection to input data ptlo = 0.2 pthi = 1. fitran = [-0.1, 3] mmin = 2.8 mmax = 3.2 #output log file out = open("out.txt", "w") #log fit parameters loglist1 = [(x, eval(x)) for x in ["infile_mc", "ptbin", "ptmin", "ptmax"]] loglist2 = [(x, eval(x)) for x in ["ptlo", "pthi", "fitran", "mmin", "mmax"]] strlog = ut.make_log_string(loglist1, loglist2) ut.log_results(out, strlog + "\n") strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax) strsel += " && jGenPt>{0:.3f}".format(ptlo) strsel += " && jGenPt<{0:.3f}".format(pthi) nbins, ptmax = ut.get_nbins(ptbin, ptmin, ptmax) hPtRel = ut.prepare_TH1D("hPtRel", ptbin, ptmin, ptmax) ytit = "Events / ({0:.3f})".format(ptbin) xtit = "(#it{p}_{T, rec} - #it{p}_{T, gen})/#it{p}_{T, gen}" mctree.Draw("(jRecPt-jGenPt)/jGenPt >> hPtRel", strsel) x = RooRealVar("x", "x", ptmin, ptmax) x.setRange("fitran", fitran[0], fitran[1]) rfPtRel = RooDataHist("rfPtRel", "rfPtRel", RooArgList(x), hPtRel) #reversed Crystal Ball mean = RooRealVar("mean", "mean", 0., -0.1, 0.1) sigma = RooRealVar("sigma", "sigma", 0.2, 0., 0.9) alpha = RooRealVar("alpha", "alpha", -1.2, -10., 0.) n = RooRealVar("n", "n", 1.3, 0., 20.) cbpdf = RooCBShape("cbpdf", "cbpdf", x, mean, sigma, alpha, n) res = cbpdf.fitTo(rfPtRel, rf.Range("fitran"), rf.Save()) #log fit results ut.log_results(out, ut.log_fit_result(res)) can = ut.box_canvas() ut.set_margin_lbtr(gPad, 0.12, 0.1, 0.05, 0.03) frame = x.frame(rf.Bins(nbins), rf.Title("")) ut.put_frame_yx_tit(frame, ytit, xtit) rfPtRel.plotOn(frame, rf.Name("data")) cbpdf.plotOn(frame, rf.Precision(1e-6), rf.Name("cbpdf")) frame.Draw() desc = pdesc(frame, 0.65, 0.8, 0.057) #x, y, sep desc.set_text_size(0.03) desc.itemD("#chi^{2}/ndf", frame.chiSquare("cbpdf", "data", 4), -1, rt.kBlue) desc.prec = 5 desc.itemR("mean", mean, rt.kBlue) desc.prec = 4 desc.itemR("#sigma", sigma, rt.kBlue) desc.itemR("#alpha", alpha, rt.kBlue) desc.prec = 3 desc.itemR("#it{n}", n, rt.kBlue) desc.draw() leg = ut.prepare_leg(0.6, 0.82, 0.21, 0.12, 0.03) # x, y, dx, dy, tsiz leg.SetMargin(0.05) leg.AddEntry(0, "#bf{%.1f < #it{p}_{T}^{pair} < %.1f GeV}" % (ptlo, pthi), "") leg.Draw("same") #ut.invert_col(rt.gPad) can.SaveAs("01fig.pdf")
def plot_rec_gen_track_phi(): #track azimuthal angle phi resolution as ( phi_track_rec - phi_track_gen )/phi_track_gen phibin = 0.0001 phimin = -0.02 phimax = 0.02 #ptlo = 0. #pthi = 0.9 fitran = [-0.01, 0.01] mmin = 2.8 mmax = 3.2 cbw = rt.kBlue #output log file out = open("out.txt", "w") #log fit parameters loglist1 = [(x, eval(x)) for x in ["infile_mc", "phibin", "phimin", "phimax"]] loglist2 = [(x, eval(x)) for x in ["fitran", "mmin", "mmax"]] strlog = ut.make_log_string(loglist1, loglist2) ut.log_results(out, strlog + "\n") strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax) #strsel += " && jGenPt>{0:.3f}".format(ptlo) #strsel += " && jGenPt<{0:.3f}".format(pthi) nbins, phimax = ut.get_nbins(phibin, phimin, phimax) hPhiRel = ut.prepare_TH1D_n("hPhiRel", nbins, phimin, phimax) ytit = "Events / ({0:.4f})".format(phibin) xtit = "(#phi_{rec} - #phi_{gen})/#phi_{gen}" mctree.Draw("(jT0phi-jGenP0phi)/jGenP0phi >> hPhiRel", strsel) # positive charge mctree.Draw("(jT1phi-jGenP1phi)/jGenP1phi >>+hPhiRel", strsel) # add negative charge x = RooRealVar("x", "x", phimin, phimax) x.setRange("fitran", fitran[0], fitran[1]) rfPhiRel = RooDataHist("rfPhiRel", "rfPhiRel", RooArgList(x), hPhiRel) #Breit-Wigner pdf mean = RooRealVar("mean", "mean", 0., -0.1, 0.1) sigma = RooRealVar("sigma", "sigma", 0.01, 0., 0.9) bwpdf = RooBreitWigner("bwpdf", "bwpdf", x, mean, sigma) res = bwpdf.fitTo(rfPhiRel, rf.Range("fitran"), rf.Save()) #log fit results ut.log_results(out, ut.log_fit_result(res)) can = ut.box_canvas() ut.set_margin_lbtr(gPad, 0.12, 0.1, 0.05, 0.03) frame = x.frame(rf.Bins(nbins), rf.Title("")) ut.put_frame_yx_tit(frame, ytit, xtit) rfPhiRel.plotOn(frame, rf.Name("data")) bwpdf.plotOn(frame, rf.Precision(1e-6), rf.Name("bwpdf")) frame.Draw() desc = pdesc(frame, 0.12, 0.93, 0.057) #x, y, sep desc.set_text_size(0.03) desc.itemD("#chi^{2}/ndf", frame.chiSquare("bwpdf", "data", 2), -1, cbw) desc.prec = 2 desc.fmt = "e" desc.itemR("mean", mean, cbw) desc.itemR("#sigma", sigma, cbw) desc.draw() leg = ut.make_uo_leg(hPhiRel, 0.5, 0.8, 0.2, 0.2) #leg.Draw("same") #print "Entries: ", hPhiRel.GetEntries() #ut.invert_col(rt.gPad) can.SaveAs("01fig.pdf")