示例#1
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")
示例#2
0
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()
示例#3
0
    #-- end of config --


    #get the 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", "inLS"]]
    loglist2 = [(x,eval(x)) for x in ["mbin", "mmin", "mmax", "ymin", "ymax", "ptmax", "binned"]]
    loglist3 = [(x,eval(x)) for x in ["alphafix", "nfix", "fitran", "intran"]]
    strlog = ut.make_log_string(loglist1, loglist2, loglist3)
    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])
    m.setRange("intran", intran[0], intran[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)
示例#4
0
    #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)
    dataH = RooDataHist("dataH", "dataH", RooArgList(m), hMass)
示例#5
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")
示例#6
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")
示例#7
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")
示例#8
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")
示例#9
0
    #-- end of config --

    #load the 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", "fitran", "binned"]]
    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)
示例#10
0
    #-- end of config --


    gROOT.SetBatch()

    #output temporary file
    outnam = "tmp.root"
    #input and output
    inp = TFile.Open(basedir+"/"+infile)
    outfile = TFile.Open(outnam, "recreate")

    #output log file
    out = open("out.txt", "w")
    strlog = "in "+infile+" precision "+str(precision)+" onset "+str(onset)
    strlog += " delta "+str(delta)
    ut.log_results(out, strlog+"\n")

    #get input tree, apply the selection
    tree = inp.Get("jRecTree").CopyTree(strsel)

    # bin edges
    bins = get_bins(tree, bnam, bmatch, precision, onset, delta)

    #momenta and efficiency histograms
    nbins = len(bins)-1
    hAll = TH1D("hAll", "hAll", nbins, bins.data())
    hSel = TH1D("hSel", "hSel", nbins, bins.data())
    hAll.Sumw2()
    hSel.Sumw2()
    tree.Draw(bnam[0]+" >>  hAll")
    tree.Draw(bnam[1]+" >>+ hAll")
示例#11
0
    #colLR = rt.kGreen
    colLR = rt.kGreen + 1

    #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)