예제 #1
0
def fit_pt2_incoh():

    #fit to incoherent MC pT^2

    ptbin = 0.008
    ptmin = 0.
    ptmax = 1.

    mmin = 2.8
    mmax = 3.2

    strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax)

    can = ut.box_canvas()

    hPtIncoh = ut.prepare_TH1D("hPtIncoh", ptbin, ptmin, ptmax)

    ut.put_yx_tit(hPtIncoh, "Events / ({0:.3f}".format(ptbin) + " GeV^{2})",
                  "#it{p}_{T}^{2} (GeV^{2})")

    tree_incoh.Draw("jRecPt*jRecPt >> hPtIncoh", strsel)

    #hPtIncoh.Sumw2()
    #hPtIncoh.Scale(1./hPtIncoh.Integral("width"))

    ut.set_margin_lbtr(gPad, 0.11, 0.09, 0.01, 0.01)

    func_incoh_pt2 = TF1("func_incoh", "[0]*exp(-[1]*x)", 0., 10.)
    func_incoh_pt2.SetParName(0, "A")
    func_incoh_pt2.SetParName(1, "b")
    func_incoh_pt2.SetNpx(1000)
    func_incoh_pt2.SetLineColor(rt.kRed)

    func_incoh_pt2.SetParameters(3000., 5.)

    r1 = (hPtIncoh.Fit(func_incoh_pt2, "RS")).Get()

    hPtIncoh.Draw()
    func_incoh_pt2.Draw("same")

    leg = ut.prepare_leg(0.67, 0.84, 0.14, 0.12, 0.03)
    ut.add_leg_mass(leg, mmin, mmax)
    leg.AddEntry(hPtIncoh, "Incoherent MC")
    leg.AddEntry(func_incoh_pt2, "#it{A}*exp(-#it{b}*#it{p}_{T}^{2})", "l")
    leg.Draw("same")

    desc = pdesc(hPtIncoh, 0.72, 0.84, 0.057)
    desc.set_text_size(0.03)
    desc.itemD("#chi^{2}/ndf", r1.Chi2() / r1.Ndf(), -1, rt.kRed)
    desc.itemRes("#it{A}", r1, 0, rt.kRed)
    desc.itemRes("#it{b}", r1, 1, rt.kRed)
    desc.draw()

    #gPad.SetLogy()

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
예제 #2
0
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")
예제 #3
0
def fit_logPt2_incoh():

    #fit to incoherent log_10(pT^2)

    ptbin = 0.12
    ptmin = -5.
    ptmax = 1.

    mmin = 2.8
    mmax = 3.2

    fitran = [-1., -0.1]

    strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax)

    can = ut.box_canvas()

    hPtIncoh = ut.prepare_TH1D("hPtIncoh", ptbin / 3., ptmin, ptmax)

    ut.put_yx_tit(hPtIncoh, "Events / ({0:.3f}".format(ptbin) + " GeV^{2})",
                  "log_{10}( #it{p}_{T}^{2} ) (GeV^{2})")

    ut.set_margin_lbtr(gPad, 0.11, 0.09, 0.01, 0.01)

    draw = "TMath::Log10(jRecPt*jRecPt)"
    tree_incoh.Draw(draw + " >> hPtIncoh", strsel)

    #hPtIncoh.Sumw2()
    #hPtIncoh.Scale(1./hPtIncoh.Integral("width"))

    func_incoh_logPt2 = TF1("func_incoh_logPt2",
                            "[0]*log(10.)*pow(10.,x)*exp(-[1]*pow(10.,x))",
                            -10., 10.)
    func_incoh_logPt2.SetParName(0, "A")
    func_incoh_logPt2.SetParName(1, "b")
    func_incoh_logPt2.SetNpx(1000)
    func_incoh_logPt2.SetLineColor(rt.kRed)

    func_incoh_logPt2.SetParameters(3000., 5.)

    r1 = (hPtIncoh.Fit(func_incoh_logPt2, "RS", "", fitran[0],
                       fitran[1])).Get()

    #create pdf normalized to number of events
    pdf_logPt2 = TF1("pdf_logPt2",
                     "[0]*log(10.)*pow(10.,x)*exp(-[1]*pow(10.,x))", -10., 10.)
    nevt = tree_incoh.Draw(
        "", strsel + " && " + draw + ">{0:.3f}".format(fitran[0]) + " && " +
        draw + "<{1:.3f}".format(fitran[0], fitran[1]))
    k_norm = nevt / func_incoh_logPt2.Integral(fitran[0], fitran[1])
    pdf_logPt2.SetParameter(0, k_norm * func_incoh_logPt2.GetParameter(0))
    pdf_logPt2.SetParameter(1, func_incoh_logPt2.GetParameter(1))
    #verify the normalization:
    print "PDF integral", pdf_logPt2.Integral(-10., 10.)

    hPtIncoh.Draw()
    func_incoh_logPt2.Draw("same")

    leg = ut.prepare_leg(0.18, 0.78, 0.14, 0.15, 0.03)
    ut.add_leg_mass(leg, mmin, mmax)
    leg.AddEntry(hPtIncoh, "Incoherent MC")
    leg.AddEntry(
        func_incoh_logPt2,
        "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")

    desc = pdesc(hPtIncoh, 0.18, 0.78, 0.057)
    desc.set_text_size(0.03)
    desc.itemD("#chi^{2}/ndf", r1.Chi2() / r1.Ndf(), -1, rt.kRed)
    desc.itemRes("#it{A}", r1, 0, rt.kRed)
    desc.itemD("#it{A}", pdf_logPt2.GetParameter(0), -1, rt.kRed)
    desc.itemRes("#it{b}", r1, 1, rt.kRed)
    desc.draw()

    uoleg = ut.make_uo_leg(hPtIncoh, 0.14, 0.9, 0.01, 0.1)
    uoleg.Draw("same")

    l0 = ut.cut_line(fitran[0], 0.9, hPtIncoh)
    l1 = ut.cut_line(fitran[1], 0.9, hPtIncoh)
    l0.Draw()
    l1.Draw()

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
예제 #4
0
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")
예제 #5
0
    frame.GetYaxis().SetTitleOffset(1.6)

    if binned == True:
        dataH.plotOn(frame, rf.Name("data"))
    else:
        data.plotOn(frame, rf.Name("data"))

    cb.plotOn(frame, rf.Precision(1e-6), rf.Name("CrystalBall"),
              rf.LineColor(ccb))
    frame.Draw()

    frame.SetXTitle("#it{m}_{e^{+}e^{-}} (GeV)")
    frame.SetYTitle("Dielectron counts / ({0:.0f} MeV)".format(1000. * mbin))

    #fit parameters on the plot
    desc = pdesc(frame, 0.18, 0.8, 0.057)
    #x, y, sep
    desc.set_text_size(0.03)

    desc.itemD("#chi^{2}/ndf", frame.chiSquare("CrystalBall", "data", 4), -1,
               ccb)
    desc.prec = 4
    desc.itemR("#it{m}_{0}", m0, ccb)
    desc.itemR("#sigma", sig, ccb)
    desc.prec = 3
    desc.itemR("#alpha", alpha, ccb)
    desc.itemR("#it{n}", n, ccb)
    desc.draw()

    leg = ut.prepare_leg(0.16, 0.85, 0.35, 0.08, 0.029)  # x, y, dx, dy, tsiz
    leg.SetMargin(0.14)
예제 #6
0
def calib_graph():

    #calibration graph from number of detected photons to generated energy

    #get the tree
    gROOT.ProcessLine("struct EntryD {Double_t val;};")
    gROOT.ProcessLine("struct EntryL {ULong64_t val;};")

    gen_energy = rt.EntryD()
    nphot = rt.EntryL()

    tree.SetBranchStatus("*", 0)

    tree.SetBranchStatus("phot_gen", 1)
    tree.SetBranchAddress("phot_gen", AddressOf(gen_energy, "val"))

    tree.SetBranchStatus("phot_nphotDet", 1)
    tree.SetBranchAddress("phot_nphotDet", AddressOf(nphot, "val"))

    nev = tree.GetEntries()

    #fill the graph of generated energy as a function of number of detected photons
    gGenNphot = TGraph(nev)

    for i in xrange(nev):
        tree.GetEntry(i)
        gGenNphot.SetPoint(i, float(nphot.val)/1e3, gen_energy.val) # /1e3

    #verify values in the graph
    gx = rt.Double()
    gy = rt.Double()
    for i in xrange(gGenNphot.GetN()):
        gGenNphot.GetPoint(i, gx, gy)
        #print i, gx, gy

    #calibration function
    calib = TF1("calib", "[0]+[1]*x + [2]*x*x", 0, 100) # 1, 82   0 100
    calib.SetParameter(0, 0)
    calib.SetParameter(1, 0.2)
    calib.SetParameter(2, -1e-5)

    #calib.FixParameter(2, 0)

    #make the fit
    res = ( gGenNphot.Fit(calib, "RS") ).Get()

    #log the results to a file
    out = open("out.txt", "w")
    out.write(ut.log_tfit_result(res))

    can = ut.box_canvas()
    frame = gPad.DrawFrame(0, 0, 100, 21)

    ut.set_margin_lbtr(gPad, 0.1, 0.1, 0.01, 0.03)

    frame.SetXTitle("Number of photoelectrons #it{N}_{phot} #times 1000")
    frame.SetYTitle("Generated energy #it{E}_{gen} (GeV)")

    frame.SetTitleOffset(1.4, "Y")
    frame.SetTitleOffset(1.4, "X")

    gGenNphot.SetMarkerStyle(7)
    #gGenNphot.SetMarkerSize(1)

    gGenNphot.Draw("psame")

    calib.Draw("same")

    leg = ut.prepare_leg(0.15, 0.8, 0.3, 0.1, 0.04)
    leg.SetMargin(0.17)
    leg.AddEntry(calib, "#it{c}_{0} + #it{c}_{1}#kern[0.05]{#it{N}_{phot}} + #it{c}_{2}#it{N}_{phot}^{2}", "l")
    leg.Draw("same")

    #fit parameters on the plot
    desc = pdesc(frame, 0.64, 0.35, 0.057)
    #desc.set_text_size(0.03)
    desc.itemD("#chi^{2}/ndf", res.Chi2()/res.Ndf(), -1, rt.kRed)
    desc.itemRes("#it{c}_{0}", res, 0, rt.kRed)
    desc.itemRes("#it{c}_{1}", res, 1, rt.kRed)
    desc.prec = 5
    desc.itemRes("#it{c}_{2}", res, 2, rt.kRed)
    desc.draw()

    #ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
예제 #7
0
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")
예제 #8
0
    hEff.GetXaxis().SetTitleOffset(1.5)

    hEff.GetXaxis().SetTitle("Track momentum #it{p}_{tot} at BEMC (GeV)")
    hEff.GetYaxis().SetTitle("BEMC efficiency")
    hEff.SetTitle("")

    hEff.GetXaxis().SetMoreLogLabels()

    leg = ut.prepare_leg(0.15, 0.82, 0.34, 0.12, 0.03)
    leg.SetMargin(0.17)
    #fitform = "#epsilon_{0} + #it{n}#left[1 + erf#left(#frac{#it{p}_{tot} - #it{p}_{tot}^{thr}}{#sqrt{2}#sigma}#right)#right]"
    fitform = "#it{n}#left[1 + erf#left(#frac{#it{p}_{tot} - #it{p}_{tot}^{thr}}{#sqrt{2}#sigma}#right)#right]"
    leg.AddEntry(fitFunc, fitform, "l")

    #fit parameters on the plot
    desc = pdesc(hEff, 0.035, 0.7, 0.05, 0.002)
    desc.set_text_size(0.03)
    desc.itemD("#chi^{2}/ndf", r1.Chi2()/r1.Ndf(), -1, clin)
    desc.itemRes("#it{n}", r1, 0, clin)
    desc.itemRes("#it{p}_{tot}^{thr}", r1, 1, clin)
    desc.itemRes("#sigma", r1, 2, clin)
    #desc.itemRes("#epsilon_{0}", r1, 3, clin)

    #print "#####", fitFunc.Eval(0.7)

    hEff.Draw("AP")
    #hEff.Draw()
    fitFunc.Draw("same")
    desc.draw()
    leg.Draw("same")
예제 #9
0
    #legend for data and kinematics interval
    leg2 = ut.prepare_leg(0.73, 0.78, 0.22, 0.17, 0.03)
    leg2.SetMargin(0.17)
    ut.add_leg_y_pt(leg2, ymin, ymax, ptmax)
    hx = ut.prepare_TH1D("hx", 1, 0, 1)
    hx.Draw("same")
    hxLS = ut.prepare_TH1D("hxLS", 1, 0, 1)
    hxLS.SetMarkerColor(rt.kRed)
    hxLS.SetMarkerStyle(21)
    leg2.AddEntry(hx, "unlike sign")
    leg2.AddEntry(hxLS, "like sign", "p")
    leg2.Draw("same")

    #show fit parameters
    desc = pdesc(frame, 0.15, 0.78, 0.045)
    desc.set_text_size(0.03)
    desc.itemD("#chi^{2}/ndf", frame.chiSquare("Model", "data", 7), -1, cmodel)
    desc.prec = 0
    desc.itemR("#it{N}_{CB}", ncb, ccb)
    #desc.itemR("#it{N}_{bkg}", nbkg, cbkg)
    desc.itemR("#it{N}_{#gamma#gamma}", nbkg, cbkg)
    desc.prec = 3
    desc.itemR("#it{m}_{0}", m0, ccb)
    desc.itemR("#sigma", sig, ccb)
    if alphafix > 0.:
        desc.itemD("#alpha", alpha.getVal(), -1, ccb)
    else:
        desc.itemR("#alpha", alpha, ccb)
    if nfix > 0.:
        desc.itemD("#it{n}", n.getVal(), -1, ccb)
예제 #10
0
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")
예제 #11
0
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")
예제 #12
0
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")
예제 #13
0
def plot_zdc_tpc_vtx_diff():

    #difference between TPC and ZDC vertex

    dbin = 2.5
    dmin = -90
    dmax = 130
    #dmin = -1500
    #dmax = 2000

    mmin = 1.5
    mmax = 5.

    fitcol = rt.kBlue

    out = open("out.txt", "w")
    ut.log_results(out, "in " + infile)
    strlog = "dbin " + str(dbin) + " dmin " + str(dmin) + " dmax " + str(dmax)
    strlog += " mmin " + str(mmin) + " mmax " + str(mmax) + "\n"
    ut.log_results(out, strlog)

    can = ut.box_canvas()

    strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax)

    hDVtx = ut.prepare_TH1D("hDVtx", dbin, dmin, dmax)

    tree.Draw("jZDCVtxZ-jVtxZ >> hDVtx", strsel)

    #fit function
    f1 = TF1("f1", "gaus+[3]", -50, 105)
    f1.SetNpx(1000)
    f1.SetLineColor(fitcol)
    f1.SetParameter(0, 77)
    f1.SetParameter(1, 25)
    f1.SetParameter(2, 13)
    f1.SetParameter(3, 5)
    f1.SetParName(0, "norm")
    f1.SetParName(1, "mean")
    f1.SetParName(2, "sigma")
    f1.SetParName(3, "ofs")

    #make the fit
    r1 = (hDVtx.Fit(f1, "RS")).Get()
    out.write(ut.log_tfit_result(r1))

    #r1.Print()

    #fraction of events within +/- 4 sigma
    t1 = tree.CopyTree(strsel)
    nall = t1.GetEntries()
    lo = f1.GetParameter(1) - 4. * f1.GetParameter(2)
    hi = f1.GetParameter(1) + 4. * f1.GetParameter(2)
    nsel = t1.Draw(
        "",
        "(jZDCVtxZ-jVtxZ)>{0:.3f} && (jZDCVtxZ-jVtxZ)<{1:.3f}".format(lo, hi))
    fraction = float(nsel) / float(nall)
    err = fraction * ma.sqrt(float(nall - nsel) / (nall * nsel))
    ut.log_results(out, "Fraction of events within +/- 4 sigma")
    ut.log_results(out, "4sigma interval: " + str(lo) + " " + str(hi))
    ut.log_results(out, "nall: " + str(nall))
    ut.log_results(out, "nsel: " + str(nsel))
    ut.log_results(out, "f_4s: {0:.3f} +/- {1:.3f}".format(fraction, err))
    print("4sigma interval:", lo, hi)
    print("nall:", nall)
    print("nsel:", nsel)
    print("f_4s: {0:.3f} +/- {1:.3f}".format(fraction, err))

    hDVtx.SetYTitle("Events / {0:.1f} cm".format(dbin))
    hDVtx.SetXTitle("Vertex #it{z}_{ZDC} - #it{z}_{TPC} (cm)")

    hDVtx.SetTitleOffset(1.5, "Y")
    hDVtx.SetTitleOffset(1.3, "X")

    gPad.SetTopMargin(0.012)
    gPad.SetRightMargin(0.04)
    gPad.SetBottomMargin(0.1)
    gPad.SetLeftMargin(0.1)

    #fit parameters on the plot
    desc = pdesc(hDVtx, 0.16, 0.84, 0.057)
    desc.set_text_size(0.03)
    desc.itemD("#chi^{2}/ndf", r1.Chi2() / r1.Ndf(), -1, fitcol)
    desc.prec = 2
    desc.itemRes("norm", r1, 0, fitcol)
    desc.itemRes("mean", r1, 1, fitcol)
    desc.itemRes("#it{#sigma}", r1, 2, fitcol)
    desc.itemRes("ofs", r1, 3, fitcol)

    #cut lines at mean +/- 4sigma
    #cut_lo = ut.cut_line(-20, 0.5, hDVtx)
    #cut_hi = ut.cut_line(70, 0.5, hDVtx)

    leg = ut.prepare_leg(0.14, 0.82, 0.28, 0.136, 0.025)
    leg.SetMargin(0.17)
    ut.add_leg_mass(leg, mmin, mmax)
    leg.AddEntry(hDVtx, "Data")
    leg.AddEntry(f1, "Gaussian + offset", "l")
    #leg.AddEntry(cut_lo, "4#it{#sigma} at -20 and 70 cm", "l")

    hDVtx.Draw()
    leg.Draw("same")
    desc.draw()
    #cut_lo.Draw("same")
    #cut_hi.Draw("same")

    #ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
예제 #14
0
    #c1f.setVal(1.338)
    #c2f.setVal(0.172)
    lamF.setVal(-1.0517)
    c1f.setVal(1.3399)
    c2f.setVal(0.16973)
    bkgd_f.plotOn(frame, rf.Range("fitran"), rf.LineColor(rt.kRed),
                  rf.Name("Background_f"))

    frame.Draw()

    frame.SetXTitle("#it{m}_{e^{+}e^{-}} (GeV/#it{c}^{2})")
    frame.SetYTitle("Dielectron counts / (%.0f MeV/#it{c}^{2})" %
                    (1000. * mbin))

    #fit parameters on the plot
    desc = pdesc(frame, 0.75, 0.78, 0.045)
    #x, y, sep
    desc.set_text_size(0.03)
    desc.itemD("#chi^{2}/ndf", frame.chiSquare("Background", "data", 3), -1,
               cbkg)
    desc.itemR("#lambda", lam, cbkg)
    desc.itemR("#it{c}_{1}", c1, cbkg)
    desc.itemR("#it{c}_{2}", c2, cbkg)
    desc.draw()

    #legend for data and fit function
    bkgfunc = "(#it{m}-#it{c}_{1})#it{e}^{#lambda(#it{m}-#it{c}_{1})^{2}+#it{c}_{2}(#it{m}-#it{c}_{1})^{3}}"
    hx = ut.prepare_TH1D("hx", 1, 0, 1)
    lx = ut.col_lin(cbkg)
    leg = ut.prepare_leg(0.58, 0.82, 0.39, 0.1, 0.029)  # x, y, dx, dy, tsiz
    leg.SetMargin(0.1)
예제 #15
0
def fit_vtx_z():

    #gaussian fit to vertex z-position
    datamc = False  #true - data, false - mc

    if datamc:
        vbin = 4.
    else:
        vbin = 2
    vmax = 120.

    mmin = 1.5
    mmax = 5.

    if datamc:
        fit_lo = -30.
        fit_hi = 35.
    else:
        fit_lo = -40.
        fit_hi = 45.
    fitcol = rt.kBlue

    strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax)

    out = open("out.txt", "w")

    can = ut.box_canvas()

    hVtx = ut.prepare_TH1D("hVtx", vbin, -vmax, vmax)
    if datamc:
        tree.Draw("jVtxZ >> hVtx", strsel)
    else:
        mctree.Draw("jVtxZ >> hVtx", strsel)

    f1 = TF1("f1", "gaus", fit_lo, fit_hi)
    f1.SetNpx(1000)
    f1.SetLineColor(fitcol)

    #make the fit
    r1 = (hVtx.Fit(f1, "RS")).Get()
    out.write(ut.log_tfit_result(r1))

    hVtx.SetYTitle("Counts / {0:.0f} cm".format(vbin));
    hVtx.SetXTitle("#it{z} of primary vertex (cm)");

    hVtx.SetTitleOffset(1.5, "Y")
    hVtx.SetTitleOffset(1.3, "X")

    gPad.SetTopMargin(0.02)
    gPad.SetRightMargin(0.02)
    gPad.SetBottomMargin(0.1)
    gPad.SetLeftMargin(0.11)

    leg = ut.prepare_leg(0.15, 0.82, 0.28, 0.12, 0.025)
    leg.SetMargin(0.17)
    ut.add_leg_mass(leg, mmin, mmax)
    if datamc:
        leg.AddEntry(hVtx, "Data")
    else:
        leg.AddEntry(hVtx, "Embedding MC #gamma#gamma")
    leg.AddEntry(f1, "Gaussian fit", "l")

    #fit parameters on the plot
    desc = pdesc(hVtx, 0.14, 0.82, 0.057)
    desc.set_text_size(0.03)
    desc.itemD("#chi^{2}/ndf", r1.Chi2()/r1.Ndf(), -1, fitcol)
    desc.prec = 2
    desc.itemRes("mean", r1, 1, fitcol)
    desc.itemRes("#it{#sigma}", r1, 2, fitcol)
    desc.itemRes("norm", r1, 0, fitcol)

    hVtx.Draw()
    leg.Draw("same")
    desc.draw()

    #ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
예제 #16
0
def fit_pt_incoh():

    #fit to incoherent MC pT

    ptbin = 0.015
    #ptbin = math.sqrt(0.005)
    ptmin = 0.
    ptmax = 1.4

    mmin = 2.8
    mmax = 3.2

    fitran = [0.4, 1.]

    strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax)

    can = ut.box_canvas()

    hPtIncoh = ut.prepare_TH1D("hPtIncoh", ptbin, ptmin, ptmax)
    ut.put_yx_tit(hPtIncoh, "Events / ({0:.3f}".format(ptbin) + " GeV)",
                  "#it{p}_{T} (GeV)")

    tree_incoh.Draw("jRecPt >> hPtIncoh", strsel)

    print "Input events:", hPtIncoh.GetEntries()
    print "Histogram integral:", hPtIncoh.Integral()
    print "Histogram integral (w):", hPtIncoh.Integral("width")

    #hPtIncoh.Sumw2()
    #hPtIncoh.Scale(1./hPtIncoh.Integral("width"))

    ut.set_margin_lbtr(gPad, 0.11, 0.09, 0.01, 0.02)

    func_incoh = TF1("func_incoh", "2*[0]*x*exp(-[1]*x*x)", 0., 10.)
    func_incoh.SetParName(0, "A")
    func_incoh.SetParName(1, "b")
    func_incoh.SetNpx(1000)
    func_incoh.SetLineColor(rt.kRed)

    func_incoh.SetParameters(3000., 5.)

    r1 = (hPtIncoh.Fit(func_incoh, "RS", "", fitran[0], fitran[1])).Get()

    print "Fit integral:", func_incoh.Integral(0., 10.)

    hPtIncoh.Draw()
    func_incoh.Draw("same")

    #normalize fit function to number of events
    pdf_incoh = TF1("pdf_incoh", "2*[0]*x*exp(-[1]*x*x)", 0., 10.)
    pdf_incoh.SetParName(0, "A")
    pdf_incoh.SetParName(1, "b")
    #    tree_incoh.Draw("jRecPt >> hPtIncoh", strsel)
    #strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax)
    nevt = tree_incoh.Draw(
        "", strsel +
        " && jRecPt>{0:.3f} && jRecPt<{1:.3f}".format(fitran[0], fitran[1]))
    k_norm = nevt / func_incoh.Integral(fitran[0], fitran[1])
    pdf_incoh.SetParameter(0, k_norm * func_incoh.GetParameter(0))
    pdf_incoh.SetParameter(1, func_incoh.GetParameter(1))
    #verify the normalization:
    print "Function integral after norm:", pdf_incoh.Integral(0., 10.)

    #create pdf for pT^2 and verify normalization
    pdf_pt2 = TF1("pdf_pt2", "[0]*exp(-[1]*x)", 0., 10.)
    pdf_pt2.SetParameter(0, pdf_incoh.GetParameter(0))
    pdf_pt2.SetParameter(1, pdf_incoh.GetParameter(1))
    print "PDF for pT^2 integral:", pdf_pt2.Integral(0., 10.)

    leg = ut.prepare_leg(0.67, 0.84, 0.14, 0.12, 0.03)
    ut.add_leg_mass(leg, mmin, mmax)
    leg.AddEntry(hPtIncoh, "Incoherent MC")
    leg.AddEntry(func_incoh, "2#it{A}*#it{p}_{T}exp(-#it{b}*#it{p}_{T}^{2})",
                 "l")
    leg.Draw("same")

    desc = pdesc(hPtIncoh, 0.72, 0.84, 0.057)
    desc.set_text_size(0.03)
    desc.itemD("#chi^{2}/ndf", r1.Chi2() / r1.Ndf(), -1, rt.kRed)
    desc.prec = 2
    desc.itemRes("#it{A}", r1, 0, rt.kRed)
    desc.itemD("#it{A}", pdf_incoh.GetParameter(0), -1, rt.kRed)
    desc.prec = 3
    desc.itemRes("#it{b}", r1, 1, rt.kRed)
    desc.draw()

    l0 = ut.cut_line(fitran[0], 0.9, hPtIncoh)
    l1 = ut.cut_line(fitran[1], 0.9, hPtIncoh)
    l0.Draw()
    l1.Draw()

    uoleg = ut.make_uo_leg(hPtIncoh, 0.14, 0.9, 0.01, 0.1)
    uoleg.Draw("same")

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
예제 #17
0
    model.plotOn(frame, rf.Name("g0"), rf.Components("g0"), rf.LineColor(col0))
    model.plotOn(frame, rf.Name("gL"), rf.Components("gL"),
                 rf.LineColor(colLR))
    model.plotOn(frame, rf.Name("gR"), rf.Components("gR"),
                 rf.LineColor(colLR))
    model.plotOn(frame, rf.Name("Model"), rf.LineColor(colM))

    frame.SetXTitle("ZDC vertex along #it{z} (cm)")
    frame.SetYTitle("Events / {0:.1f} cm".format(vbin))

    print "chi2/ndf:", frame.chiSquare("Model", "data", 9)

    frame.Draw()

    #put fit parameters
    desc = pdesc(frame, 0.15, 0.9, 0.045)
    desc.set_text_size(0.03)
    desc.itemD("#chi^{2}/ndf", frame.chiSquare("Model", "data", 9), -1, colM)
    desc.prec = 0
    desc.itemR("norm", n0, col0)
    desc.prec = 2
    desc.itemR("#mu", m0, col0)
    desc.itemR("#sigma", sig0, col0)
    desc.draw()

    #side gaussians
    desc2 = pdesc(frame, 0.7, 0.92, 0.045)
    desc2.prec = 0
    desc2.itemR("norm_{lo}", nL, colLR)
    desc2.itemR("norm_{hi}", nR, colLR)
    desc2.prec = 2