def make_eff_pt2(): #efficiency vs. pT^2 ptbin = 0.005 ptmin = 0. ptmax = 0.12 # 0.3 mmin = 2.8 mmax = 3.2 strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax) can = ut.box_canvas() nbins, ptmax = ut.get_nbins(ptbin, ptmin, ptmax) hPtRec = TH1D("hPtRec", "hPtRec", nbins, ptmin, ptmax) hPtGen = TH1D("hPtGen", "hPtGen", nbins, ptmin, ptmax) #hPtRec = ut.prepare_TH1D("hPtRec", ptbin, ptmin, ptmax) #hPtGen = ut.prepare_TH1D("hPtGen", ptbin, ptmin, ptmax) hPtRec.Sumw2() hPtGen.Sumw2() ut.set_margin_lbtr(gPad, 0.11, 0.09, 0.01, 0.02) #generated trees tree_coh_gen = inp_coh.Get("jGenTree") tree_incoh_gen = inp_incoh.Get("jGenTree") tree_coh.Draw("jGenPt*jGenPt >> hPtRec", strsel) tree_coh_gen.Draw("jGenPt*jGenPt >> hPtGen") #tree_incoh.Draw("jGenPt*jGenPt >>+ hPtRec", strsel) #tree_incoh_gen.Draw("jGenPt*jGenPt >>+ hPtGen") #tree_incoh.Draw("jGenPt*jGenPt >> hPtRec", strsel) #tree_incoh_gen.Draw("jGenPt*jGenPt >> hPtGen") #calculate the efficiency hEff = TGraphAsymmErrors(hPtRec, hPtGen) #hPtRec.Divide(hPtGen) #hPtRec.Draw() #hPtGen.Draw("same") hEff.Draw() ut.invert_col(rt.gPad) can.SaveAs("01fig.pdf")
def make_fit(): adc_bin = 12 #18 for low-m gg, 24 for jpsi adc_min = 0. #10. adc_max = 400. #adc_max = 1200 ptmax = 0.18 #mmin = 1.6 #mmin = 2.1 #mmax = 2.6 #mmin = 1.5 #mmax = 5. mmin = 2.9 mmax = 3.2 #mmin = 3.4 #mmax = 4.6 #east/west projections and 2D plot ew = 1 p2d = 2 # 0: single projection by 'ew', 1: 2D plot, 2: both projections #plot colors model_col = rt.kMagenta model_col = rt.kBlue out = open("out.txt", "w") lmg = 6 ut.log_results(out, "in " + infile, lmg) strlog = "adc_bin " + str(adc_bin) + " adc_min " + str( adc_min) + " adc_max " + str(adc_max) strlog += " ptmax " + str(ptmax) + " mmin " + str(mmin) + " mmax " + str( mmax) ut.log_results(out, strlog, lmg) #adc distributions adc_east = RooRealVar("jZDCUnAttEast", "ZDC ADC east", adc_min, adc_max) adc_west = RooRealVar("jZDCUnAttWest", "ZDC ADC west", adc_min, adc_max) #kinematics variables m = RooRealVar("jRecM", "e^{+}e^{-} mass (GeV)", 0., 10.) y = RooRealVar("jRecY", "rapidity", -1., 1.) pT = RooRealVar("jRecPt", "pT", 0., 10.) #adc distributions #adc_east = RooRealVar("zdce", "ZDC ADC east", adc_min, adc_max) #adc_west = RooRealVar("zdcw", "ZDC ADC west", adc_min, adc_max) #kinematics variables #m = RooRealVar("mee", "e^{+}e^{-} mass (GeV)", 0., 10.) #y = RooRealVar("rapee", "rapidity", -1., 1.) #pT = RooRealVar("ptpair", "pT", 0., 10.) strsel = "jRecPt<{0:.3f} && jRecM>{1:.3f} && jRecM<{2:.3f}".format( ptmax, mmin, mmax) #strsel = "ptpair<{0:.3f} && mee>{1:.3f} && mee<{2:.3f}".format(ptmax, mmin, mmax) data_all = RooDataSet("data", "data", tree, RooArgSet(adc_east, adc_west, m, y, pT)) print "All input:", data_all.numEntries() data = data_all.reduce(strsel) print "Sel input:", data.numEntries() model = Model2D(adc_east, adc_west) r1 = model.model.fitTo(data, rf.Save()) ut.log_results(out, ut.log_fit_result(r1), lmg) ut.log_results(out, "Fit parameters:\n", lmg) out.write(ut.log_fit_parameters(r1, lmg + 2) + "\n") #out.write(ut.table_fit_parameters(r1)) #print ut.table_fit_parameters(r1) #create the plot if p2d != 2: can = ut.box_canvas() nbins, adc_max = ut.get_nbins(adc_bin, adc_min, adc_max) adc_east.setMax(adc_max) adc_west.setMax(adc_max) frame_east = adc_east.frame(rf.Bins(nbins), rf.Title("")) frame_west = adc_west.frame(rf.Bins(nbins), rf.Title("")) data.plotOn(frame_east, rf.Name("data")) model.model.plotOn(frame_east, rf.Precision(1e-6), rf.Name("model"), rf.LineColor(model_col)) data.plotOn(frame_west, rf.Name("data")) model.model.plotOn(frame_west, rf.Precision(1e-6), rf.Name("model"), rf.LineColor(model_col)) #reduced chi^2 in east and west projections ut.log_results(out, "chi2/ndf:\n", lmg) ut.log_results( out, " East chi2/ndf: " + str(frame_east.chiSquare("model", "data", 16)), lmg) ut.log_results( out, " West chi2/ndf: " + str(frame_west.chiSquare("model", "data", 16)), lmg) ut.log_results(out, "", 0) ytit = "Events / ({0:.0f} ADC units)".format(adc_bin) frame_east.SetYTitle(ytit) frame_west.SetYTitle(ytit) frame_east.SetTitle("") frame_west.SetTitle("") frame = [frame_east, frame_west] if p2d == 0: plot_projection(frame[ew], ew) plot_pdf = PlotPdf(model, adc_east, adc_west) if p2d == 1: plot_2d(plot_pdf) if p2d == 2: frame2 = ut.prepare_TH1D("frame2", adc_bin, adc_min, 2. * adc_max + 4.1 * adc_bin) plot_proj_both(frame2, frame_east, frame_west, adc_bin, adc_min, adc_max, ptmax, mmin, mmax) lhead = ["east ZDC", "west ZDC"] if p2d == 1: leg = ut.prepare_leg(0.003, 0.9, 0.3, 0.1, 0.035) else: leg = ut.prepare_leg(0.66, 0.8, 0.32, 0.13, 0.03) if p2d == 0: leg.AddEntry(None, "#bf{Projection to " + lhead[ew] + "}", "") leg.SetMargin(0.05) leg.AddEntry(None, "#bf{#it{p}_{T} < " + "{0:.2f}".format(ptmax) + " GeV/c}", "") mmin_fmt = "{0:.1f}".format(mmin) mmax_fmt = "{0:.1f}".format(mmax) leg.AddEntry( None, "#bf{" + mmin_fmt + " < #it{m}_{e^{+}e^{-}} < " + mmax_fmt + " GeV/c^{2}}", "") leg.Draw("same") pleg = ut.prepare_leg(0.99, 0.87, -0.4, 0.11, 0.035) pleg.SetFillStyle(1001) #pleg.AddEntry(None, "STAR Preliminary", "") pleg.AddEntry(None, "AuAu@200 GeV", "") pleg.AddEntry(None, "UPC sample", "") #pleg.Draw("same") #ut.print_pad(gPad) #b3d = TBuffer3D(0) #b3d = None #gPad.GetViewer3D().OpenComposite(b3d) #print b3d #print "All input: ", data.numEntries() #print "All input: 858" #all input data nall = float(tree.Draw("", strsel)) print "All input: ", nall n_1n1n = float(model.num_1n1n.getVal()) print "1n1n events: ", n_1n1n ratio_1n1n = n_1n1n / nall sigma_ratio_1n1n = ratio_1n1n * TMath.Sqrt( (nall - n_1n1n) / (nall * n_1n1n)) print "Ratio 1n1n / all: ", ratio_1n1n, "+/-", sigma_ratio_1n1n ut.log_results(out, "Fraction of 1n1n events:\n", lmg) ut.log_results(out, "All input: " + str(nall), lmg) ut.log_results(out, "1n1n events: " + str(model.num_1n1n.getVal()), lmg) ratio_str = "Ratio 1n1n / all: " + str(ratio_1n1n) + " +/- " + str( sigma_ratio_1n1n) ut.log_results(out, ratio_str, lmg) if p2d != 2: #ut.print_pad(gPad) ut.invert_col(gPad) can.SaveAs("01fig.pdf") if interactive == True: start_interactive()
def pdf_logPt2_prelim(): #PDF fit to log_10(pT^2) for preliminary figure #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 #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", "Dielectron log_{10}( #it{p}_{T}^{2} ) ((GeV/c)^{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) hPtCoh = ut.prepare_TH1D("hPtCoh", ptbin, ptmin, ptmax) hPtCoh.SetLineWidth(2) #fill in binned data tree_in.Draw(draw + " >> hPt", strsel) tree_coh.Draw(draw + " >> hPtCoh", 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()) #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)) print "a =", a #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 + 1) print "Int GG:", hPtGG.Integral() #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 ut.norm_to_data(hPtCoh, hPt, rt.kBlue, -5., -2.2) # norm for coh hSum.Add(hPtCoh) #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.1, 0.01, 0.01) frame = x.frame(rf.Bins(nbins), rf.Title("")) frame.SetTitle("") frame.SetYTitle("J/#psi candidates / ({0:.3f}".format(ptbin) + " (GeV/c)^{2})") frame.GetXaxis().SetTitleOffset(1.2) frame.GetYaxis().SetTitleOffset(1.6) 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() leg = ut.prepare_leg(0.61, 0.77, 0.16, 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, 2) leg.AddEntry(hx, "Data", "p") leg.AddEntry(hSum, "Sum", "l") leg.AddEntry(hPtCoh, "Coherent J/#psi", "l") leg.AddEntry(ln, "Incoherent parametrization", "l") leg.AddEntry(hPtGG, "#gamma#gamma#rightarrow e^{+}e^{-}", "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.Draw("same") l0 = ut.cut_line(fitran[0], 0.9, frame) l1 = ut.cut_line(fitran[1], 0.9, frame) #l0.Draw() #l1.Draw() pleg = ut.prepare_leg(0.12, 0.75, 0.14, 0.22, 0.03) pleg.AddEntry(None, "#bf{|#kern[0.3]{#it{y}}| < 1}", "") ut.add_leg_mass(pleg, mmin, mmax) pleg.AddEntry(None, "STAR Preliminary", "") pleg.AddEntry(None, "AuAu@200 GeV", "") pleg.AddEntry(None, "UPC sample", "") pleg.Draw("same") desc = pdesc(frame, 0.14, 0.9, 0.057) 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") frame.Draw("same") #put gamma-gamma and coherent J/psi hPtGG.Draw("same") hPtCoh.Draw("same") #ut.invert_col(rt.gPad) can.SaveAs("01fig.pdf")
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")
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) dataH = RooDataHist("dataH", "dataH", RooArgList(m), hMass) #make the fit if binned == True:
def fit(): #fit to log_10(pT^2) with components and plot of plain pT^2 #range in log_10(pT^2) ptbin = 0.12 ptmin = -5. ptmax = 0.99 # 1.01 #range in pT^2 ptsq_bin = 0.03 ptsq_min = 1e-5 ptsq_max = 1 mmin = 2.8 mmax = 3.2 #range for incoherent fit fitran = [-0.9, 0.1] #number of gamma-gamma events ngg = 131 #number of psi' events npsiP = 20 #input data pT = RooRealVar("jRecPt", "pT", 0, 10) m = RooRealVar("jRecM", "mass", 0, 10) data_all = RooDataSet("data", "data", tree, RooArgSet(pT, m)) #select for mass range strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax) data = data_all.reduce(strsel) #create log(pT^2) from pT ptsq_draw = "jRecPt*jRecPt" # will be used for pT^2 logPtSq_draw = "TMath::Log10(" + ptsq_draw + ")" logPtSq_form = RooFormulaVar("logPtSq", "logPtSq", logPtSq_draw, RooArgList(pT)) logPtSq = data.addColumn(logPtSq_form) logPtSq.setRange("fitran", fitran[0], fitran[1]) #bins and range for the plot nbins, ptmax = ut.get_nbins(ptbin, ptmin, ptmax) logPtSq.setMin(ptmin) logPtSq.setMax(ptmax) logPtSq.setRange("plotran", ptmin, ptmax) #range for pT^2 ptsq_nbins, ptsq_max = ut.get_nbins(ptsq_bin, ptsq_min, ptsq_max) #incoherent parametrization bval = RooRealVar("bval", "bval", 3.3, 0, 10) inc_form = "log(10.)*pow(10.,logPtSq)*exp(-bval*pow(10.,logPtSq))" incpdf = RooGenericPdf("incpdf", inc_form, RooArgList(logPtSq, bval)) #make the incoherent fit res = incpdf.fitTo(data, rf.Range("fitran"), rf.Save()) #get incoherent norm to the number of events lset = RooArgSet(logPtSq) iinc = incpdf.createIntegral(lset, rf.NormSet(lset), rf.Range("fitran")) inc_nevt = data.sumEntries("logPtSq", "fitran") incpdf.setNormRange("fitran") aval = RooRealVar("aval", "aval", inc_nevt / incpdf.getNorm(lset)) #print "A =", aval.getVal() #print "b =", bval.getVal() #incoherent distribution from log_10(pT^2) function for the sum with gamma-gamma hIncPdf = ut.prepare_TH1D_n("hGG", nbins, ptmin, ptmax) func_incoh_logPt2 = TF1("func_incoh_logPt2", "[0]*log(10.)*pow(10.,x)*exp(-[1]*pow(10.,x))", -10., 10.) func_incoh_logPt2.SetNpx(1000) func_incoh_logPt2.SetLineColor(rt.kMagenta) func_incoh_logPt2.SetParameters( aval.getVal(), bval.getVal()) # 4.9 from incoherent mc, 3.3 from data fit ut.fill_h1_tf(hIncPdf, func_incoh_logPt2, rt.kMagenta) #gamma-gamma contribution hGG = ut.prepare_TH1D_n("hGG", nbins, ptmin, ptmax) tree_gg.Draw(logPtSq_draw + " >> hGG", strsel) ut.norm_to_num(hGG, ngg, rt.kGreen + 1) #sum of incoherent distribution and gamma-gamma hSumIncGG = ut.prepare_TH1D_n("hSumIncGG", nbins, ptmin, ptmax) hSumIncGG.Add(hIncPdf) hSumIncGG.Add(hGG) ut.line_h1(hSumIncGG, rt.kMagenta) #gamma-gamma in pT^2 hGG_ptsq = ut.prepare_TH1D_n("hGG_ptsq", ptsq_nbins, ptsq_min, ptsq_max) tree_gg.Draw(ptsq_draw + " >> hGG_ptsq", strsel) ut.norm_to_num(hGG_ptsq, ngg, rt.kGreen + 1) #psi' contribution psiP_file = TFile.Open(basedir_mc + "/ana_slight14e4x1_s6_sel5z.root") psiP_tree = psiP_file.Get("jRecTree") hPsiP = ut.prepare_TH1D_n("hPsiP", nbins, ptmin, ptmax) psiP_tree.Draw(logPtSq_draw + " >> hPsiP", strsel) ut.norm_to_num(hPsiP, npsiP, rt.kViolet) #psi' in pT^2 hPsiP_ptsq = ut.prepare_TH1D_n("hPsiP_ptsq", ptsq_nbins, ptsq_min, ptsq_max) psiP_tree.Draw(ptsq_draw + " >> hPsiP_ptsq", strsel) ut.norm_to_num(hPsiP_ptsq, npsiP, rt.kViolet) #create canvas frame gStyle.SetPadTickY(1) can = ut.box_canvas(1086, 543) # square area is still 768^2 can.SetMargin(0, 0, 0, 0) can.Divide(2, 1, 0, 0) gStyle.SetLineWidth(1) can.cd(1) ut.set_margin_lbtr(gPad, 0.11, 0.1, 0.01, 0) frame = logPtSq.frame(rf.Bins(nbins)) frame.SetTitle("") frame.SetMaximum(80) frame.SetYTitle("Events / ({0:.3f}".format(ptbin) + " GeV^{2})") frame.SetXTitle("log_{10}( #it{p}_{T}^{2} ) (GeV^{2})") frame.GetXaxis().SetTitleOffset(1.2) frame.GetYaxis().SetTitleOffset(1.6) #plot the data data.plotOn(frame, rf.Name("data"), rf.LineWidth(2)) #incoherent parametrization incpdf.plotOn(frame, rf.Range("fitran"), rf.LineColor(rt.kRed), rf.Name("incpdf"), rf.LineWidth(2)) incpdf.plotOn(frame, rf.Range("plotran"), rf.LineColor(rt.kRed), rf.Name("incpdf_full"), rf.LineStyle(rt.kDashed), rf.LineWidth(2)) frame.Draw() #add gamma-gamma contribution hGG.Draw("same") #sum of incoherent distribution and gamma-gamma #hSumIncGG.Draw("same") #add psi' #hPsiP.Draw("same") #legend for log_10(pT^2) leg = ut.prepare_leg(0.15, 0.77, 0.28, 0.19, 0.035) hxl = ut.prepare_TH1D("hxl", 1, 0, 1) hxl.Draw("same") ilin = ut.col_lin(rt.kRed, 2) ilin2 = ut.col_lin(rt.kRed, 2) ilin2.SetLineStyle(rt.kDashed) leg.AddEntry(ilin, "Incoherent parametrization, fit region", "l") leg.AddEntry(ilin2, "Incoherent parametrization, extrapolation region", "l") leg.AddEntry(hGG, "#gamma#gamma#rightarrow e^{+}e^{-}", "l") #leg.AddEntry(hxl, "Data", "lp") leg.AddEntry(hxl, "Data, log_{10}( #it{p}_{T}^{2} )", "lp") leg.Draw("same") #----- plot pT^2 on the right ----- #pT^2 variable from pT ptsq_form = RooFormulaVar("ptsq", "ptsq", ptsq_draw, RooArgList(pT)) ptsq = data.addColumn(ptsq_form) #range for pT^2 plot ptsq.setMin(ptsq_min) ptsq.setMax(ptsq_max) #make the pT^2 plot can.cd(2) gPad.SetLogy() #gPad.SetLineWidth(3) #gPad.SetFrameLineWidth(1) ut.set_margin_lbtr(gPad, 0, 0.1, 0.01, 0.15) ptsq_frame = ptsq.frame(rf.Bins(ptsq_nbins), rf.Title("")) #print type(ptsq_frame), type(ptsq) ptsq_frame.SetTitle("") ptsq_frame.SetXTitle("#it{p}_{T}^{2} (GeV^{2})") ptsq_frame.GetXaxis().SetTitleOffset(1.2) data.plotOn(ptsq_frame, rf.Name("data"), rf.LineWidth(2)) ptsq_frame.SetMaximum(9e2) ptsq_frame.SetMinimum(0.8) # 0.101 ptsq_frame.Draw() #incoherent parametrization in pT^2 over the fit region, scaled to the plot inc_ptsq = TF1("inc_ptsq", "[0]*exp(-[1]*x)", 10**fitran[0], 10**fitran[1]) inc_ptsq.SetParameters(aval.getVal() * ptsq_bin, bval.getVal()) #incoherent parametrization in the extrapolation region, below and above the fit region inc_ptsq_ext1 = TF1("inc_ptsq_ext1", "[0]*exp(-[1]*x)", 0., 10**fitran[0]) inc_ptsq_ext2 = TF1("inc_ptsq_ext2", "[0]*exp(-[1]*x)", 10**fitran[1], 10) inc_ptsq_ext1.SetParameters(aval.getVal() * ptsq_bin, bval.getVal()) inc_ptsq_ext1.SetLineStyle(rt.kDashed) inc_ptsq_ext2.SetParameters(aval.getVal() * ptsq_bin, bval.getVal()) inc_ptsq_ext2.SetLineStyle(rt.kDashed) inc_ptsq.Draw("same") inc_ptsq_ext1.Draw("same") inc_ptsq_ext2.Draw("same") #add gamma-gamma in pT^2 hGG_ptsq.Draw("same") #add psi' in pT^2 #hPsiP_ptsq.Draw("same") #redraw the frame #ptsq_frame.Draw("same") ptsq_frame.GetXaxis().SetLimits(-9e-3, ptsq_frame.GetXaxis().GetXmax()) #vertical axis for pT^2 plot xpos = ptsq_frame.GetXaxis().GetXmax() ypos = ptsq_frame.GetMaximum() ymin = ptsq_frame.GetMinimum() ptsq_axis = TGaxis(xpos, 0, xpos, ypos, ymin, ypos, 510, "+GL") ut.set_axis(ptsq_axis) ptsq_axis.SetMoreLogLabels() ptsq_axis.SetTitle("Events / ({0:.3f}".format(ptsq_bin) + " GeV^{2})") ptsq_axis.SetTitleOffset(2.2) ptsq_axis.Draw() #legend for input data #dleg = ut.prepare_leg(0.4, 0.77, 0.14, 0.18, 0.035) dleg = ut.prepare_leg(0.4, 0.71, 0.16, 0.24, 0.035) dleg.AddEntry(None, "#bf{|#kern[0.3]{#it{y}}| < 1}", "") ut.add_leg_mass(dleg, mmin, mmax) dleg.AddEntry(None, "AuAu@200 GeV", "") dleg.AddEntry(None, "UPC sample", "") dleg.AddEntry(hxl, "Data, #it{p}_{T}^{2}", "lp") dleg.Draw("same") #ut.invert_col_can(can) can.SaveAs("01fig.pdf")
def resolution(): #relative energy resolution #ALICE PHOS has 3% in 0.2 - 10 GeV, PHOS TDR page 113 (127) emin = -0.4 emax = 0.4 ebin = 0.01 #reconstruct the energy from detected optical photons gRec = rec(False) #construct the relative energy resolution nbins, emax = ut.get_nbins(ebin, emin, emax) hRes = ut.prepare_TH1D_n("hRes", nbins, emin, emax) egen = rt.Double() erec = rt.Double() for i in xrange(gRec.GetN()): gRec.GetPoint(i, egen, erec) hRes.Fill( (erec-egen)/egen ) #fit the resolution with Breit-Wigner pdf x = RooRealVar("x", "x", -0.5, 0.5) x.setRange("fitran", -0.21, 0.21) rfRes = RooDataHist("rfRes", "rfRes", RooArgList(x), hRes) #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) rfres = bwpdf.fitTo(rfRes, rf.Range("fitran"), rf.Save()) #log the results to a file out = open("out.txt", "w") out.write(ut.log_fit_result(rfres)) #plot the resolution can = ut.box_canvas() frame = x.frame(rf.Bins(nbins), rf.Title("")) frame.SetTitle("") frame.SetXTitle("Relative energy resolution (#it{E}_{rec}-#it{E}_{gen})/#it{E}_{gen}") frame.GetXaxis().SetTitleOffset(1.4) frame.GetYaxis().SetTitleOffset(1.6) ut.set_margin_lbtr(gPad, 0.11, 0.1, 0.01, 0.03) rfRes.plotOn(frame, rf.Name("data")) bwpdf.plotOn(frame, rf.Precision(1e-6), rf.Name("bwpdf")) frame.Draw() leg = ut.prepare_leg(0.65, 0.78, 0.28, 0.15, 0.035) leg.SetMargin(0.17) hx = ut.prepare_TH1D("hx", 1, 0, 1) hx.Draw("same") leg.AddEntry(hx, "#frac{#it{E}_{rec} - #it{E}_{gen}}{#it{E}_{gen}}") lx = ut.col_lin(rt.kBlue) leg.AddEntry(lx, "Breit-Wigner fit", "l") leg.Draw("same") #fit parameters on the plot desc = pdesc(frame, 0.67, 0.7, 0.05); #x, y, sep #desc.set_text_size(0.03) desc.itemD("#chi^{2}/ndf", frame.chiSquare("bwpdf", "data", 2), -1, rt.kBlue) desc.prec = 4 desc.itemR("mean", mean, rt.kBlue) desc.itemR("#sigma", sigma, rt.kBlue) desc.draw() #ut.invert_col(rt.gPad) can.SaveAs("01fig.pdf")
def plot_rec_minus_gen_pt2(): #reconstructed pT^2 vs. generated pT^2 for resolution #distribution range ptbin = 0.001 ptmin = -0.1 ptmax = 0.15 #generated pT^2 selection to input data ptlo = 0.04 pthi = 0.1 #mass selection mmin = 2.8 mmax = 3.2 fitran = [-0.003, 0.05] #fitran = [-0.003, 0.003] strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax) strsel += " && (jGenPt*jGenPt)>{0:.3f}".format(ptlo) strsel += " && (jGenPt*jGenPt)<{0:.3f}".format(pthi) print strsel nbins, ptmax = ut.get_nbins(ptbin, ptmin, ptmax) hPt2 = ut.prepare_TH1D("hPt2", ptbin, ptmin, ptmax) ytit = "Events / ({0:.3f}".format(ptbin) + " GeV^{2})" xtit = "#it{p}_{T, reconstructed}^{2} - #it{p}_{T, generated}^{2} (GeV^{2})" ut.put_yx_tit(hPt2, ytit, xtit) draw = "(jRecPt*jRecPt)-(jGenPt*jGenPt)" mctree.Draw(draw + " >> hPt2", strsel) #roofit binned data x = RooRealVar("x", "x", -1, 1) dataH = RooDataHist("dataH", "dataH", RooArgList(x), hPt2) x.setRange("fitran", fitran[0], fitran[1]) #reversed Crystal Ball mean = RooRealVar("mean", "mean", 0., -0.1, 0.1) sigma = RooRealVar("sigma", "sigma", 0.0011, 0., 0.1) alpha = RooRealVar("alpha", "alpha", -1.046, -10., 0.) n = RooRealVar("n", "n", 1.403, 0., 20.) pdf = RooCBShape("pdf", "pdf", x, mean, sigma, alpha, n) #gaus = RooGaussian("gaus", "gaus", x, mean, sigma) #make the fit #res = pdf.fitTo(dataH, rf.Range("fitran"), rf.Save()) #res = gaus.fitTo(dataH, rf.Range("fitran"), rf.Save()) can = ut.box_canvas() ut.set_margin_lbtr(gPad, 0.12, 0.1, 0.015, 0.03) frame = x.frame(rf.Bins(nbins), rf.Title("")) frame.SetTitle("") frame.SetYTitle(ytit) frame.SetXTitle(xtit) frame.GetXaxis().SetTitleOffset(1.2) frame.GetYaxis().SetTitleOffset(1.7) dataH.plotOn(frame, rf.Name("data")) pdf.plotOn(frame, rf.Precision(1e-6), rf.Name("pdf")) #gaus.plotOn(frame, rf.Precision(1e-6), rf.Name("gaus")) frame.Draw() ut.invert_col(rt.gPad) can.SaveAs("01fig.pdf")
#predictions gSlight = load_starlight(dy) gMS = load_ms() gCCK = load_cck() #gSartre = load_sartre() #open the inputs inp = TFile.Open(basedir + "/" + infile) tree = inp.Get("jRecTree") inp_gg = TFile.Open(basedir_gg + "/" + infile_gg) tree_gg = inp_gg.Get("jRecTree") inp_coh = TFile.Open(basedir_coh + "/" + infile_coh) tree_coh_gen = inp_coh.Get("jGenTree") #evaluate binning print "bins:", ut.get_nbins(ptbin, ptmin, ptmax) bins = vector(rt.double)() #bins.push_back(ptmin) #while True: # if bins[bins.size()-1] < ptmid: # increment = ptbin # else: # increment = ptlon # bins.push_back( bins[bins.size()-1] + increment ) # if bins[bins.size()-1] > ptmax: break bins = ut.get_bins_vec_2pt(ptbin, ptlon, ptmin, ptmax, ptmid) print "bins2:", bins.size() - 1 #data and gamma-gamma histograms
def plot_rec_minus_gen_pt(): #reconstructed pT vs. generated pT for resolution #distribution range ptbin = 0.005 ptmin = -0.2 ptmax = 0.4 #generated pT selection to input data ptlo = 0 pthi = 0.1 #mass selection mmin = 2.8 mmax = 3.2 #range for the fit fitran = [-0.02, 0.2] 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) hPtDiff = ut.prepare_TH1D("hPtDiff", ptbin, ptmin, ptmax) ytit = "Events / ({0:.3f}".format(ptbin) + " GeV)" xtit = "#it{p}_{T, reconstructed} - #it{p}_{T, generated} (GeV)" mctree.Draw("jRecPt-jGenPt >> hPtDiff", strsel) #roofit binned data x = RooRealVar("x", "x", -1, 1) x.setRange("fitran", fitran[0], fitran[1]) rfPt = RooDataHist("rfPt", "rfPt", RooArgList(x), hPtDiff) #reversed Crystal Ball mean = RooRealVar("mean", "mean", 0., -0.1, 0.1) sigma = RooRealVar("sigma", "sigma", 0.01, 0., 0.1) alpha = RooRealVar("alpha", "alpha", -1.046, -10., 0.) n = RooRealVar("n", "n", 1.403, 0., 20.) pdf = RooCBShape("pdf", "pdf", x, mean, sigma, alpha, n) #make the fit res = pdf.fitTo(rfPt, rf.Range("fitran"), rf.Save()) 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) rfPt.plotOn(frame, rf.Name("data")) pdf.plotOn(frame, rf.Precision(1e-6), rf.Name("pdf")) frame.Draw() 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_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_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")
#get input inp = TFile.Open(basedir + "/" + infile) tree = inp.Get("jAllTree") gROOT.SetBatch() #output log file out = open("out.txt", "w") #log fit parameters loglist1 = [(x, eval(x)) for x in ["infile", "vbin", "vmin", "vmax"]] loglist2 = [(x, eval(x)) for x in ["fitran", "binned", "f_4s"]] strlog = ut.make_log_string(loglist1, loglist2) ut.log_results(out, strlog + "\n") #input data nbins, vmax = ut.get_nbins(vbin, vmin, vmax) z = RooRealVar("jZDCVtxZ", "z", vmin, vmax) z.setRange("fitran", fitran[0], fitran[1]) data = RooDataSet("data", "data", tree, RooArgSet(z)) hZdc = TH1D("hZdc", "hZdc", nbins, vmin, vmax) tree.Draw("jZDCVtxZ >> hZdc") dataH = RooDataHist("dataH", "dataH", RooArgList(z), hZdc) #fit model #middle Gaussian m0 = RooRealVar("m0", "m0", 27, vmin, vmax) sig0 = RooRealVar("sig0", "sig0", 20, vmin, vmax) g0 = RooGaussian("g0", "g0", z, m0, sig0) #left Gaussian mL = RooRealVar("mL", "mL", -36, vmin, vmax) sigL = RooRealVar("sigL", "sigL", 25, vmin, vmax)