Пример #1
0
def plotRatio(var,name,hist1,hist2):
  """Plot minimal ratio of two histograms."""
  
  canvas = TCanvas('canvas','canvas',100,100,800,800)
  canvas.Divide(2)
  canvas.cd(1)
  gPad.SetPad('pad1','pad1',0,0.42,1,1,0,-1,0)
  gPad.SetTopMargin(  0.10 ); gPad.SetBottomMargin( 0.01 )
  
  hist1.Draw()
  hist2.Draw('SAME')
  
  hist1.SetLineColor(kBlue)
  hist2.SetLineColor(kRed)
  hist1.SetLineWidth(2)
  hist2.SetLineWidth(2)
  hist1.SetLineStyle(1)
  hist2.SetLineStyle(2)
  hist1.Draw('HIST')
  hist2.Draw('HIST SAMES')
  gPad.Update()
  
  stats1 = hist1.GetListOfFunctions().FindObject('stats')
  stats2 = hist2.GetListOfFunctions().FindObject('stats')
  stats1.SetY1NDC(.74); stats1.SetY2NDC(.94)
  stats2.SetY1NDC(.50); stats2.SetY2NDC(.70)
  stats1.Draw()
  stats2.Draw()
  
  canvas.cd(2)
  gPad.SetPad('pad2','pad2',0,0,1,0.41,0,-1,0)
  gPad.SetTopMargin(  0.05 ); gPad.SetBottomMargin( 0.24 )
  ratio = hist1.Clone('ratio')
  ratio.Divide(hist2)
  for i, (y1, y2, r) in enumerate(zip(hist1,hist2,ratio),0):
    if hist1.GetBinContent(i)==0 and hist2.GetBinContent(i)==0:
      ratio.SetBinContent(i,1)
  
  ratio.GetXaxis().SetTitle(var)
  ratio.GetXaxis().SetLabelSize(0.045)
  ratio.GetYaxis().SetLabelSize(0.045)
  ratio.GetXaxis().SetTitleSize(0.060)
  ratio.SetMinimum(0.2)
  ratio.SetMaximum(1.8)
  ratio.Draw()
  
  statsr = ratio.GetListOfFunctions().FindObject('stats')
  statsr.SetY1NDC(.65); statsr.SetY2NDC(.98)
  
  canvas.SaveAs(name)
  canvas.Close()
  gDirectory.Delete(hist1.GetName())
  gDirectory.Delete(hist2.GetName())
  gDirectory.Delete(ratio.GetName())
Пример #2
0
def plot(obj, plot_name, plot_notes=[]):
    canvas = TCanvas('canvas' + plot_name, "Canvas", 450, 450)
    gPad.SetLeftMargin(.13)
    gPad.SetTopMargin(.05)

    gStyle.SetOptStat(11)
    gStyle.SetOptFit(1111)

    if 'TH2' in obj.ClassName():
        gPad.SetRightMargin(.13)
        draw_options = 'COLZ'

    if 'profile' in obj.GetName():
        gPad.SetRightMargin(.05)
        draw_options = ''

    if 'graph' in obj.GetName():
        gPad.SetRightMargin(.05)
        draw_options = 'APE'
        obj.SetMarkerSize(.7)
        obj.SetMarkerStyle(21)

    note = TPaveText(.2, .7, .5, .9, "brNDC")
    note.SetFillStyle(0)
    note.SetFillColor(0)
    note.SetBorderSize(0)
    note.SetTextColor(1)
    note.SetTextFont(42)
    note.SetTextAlign(11)
    for note_text in plot_notes:
        note.AddText(note_text)

    obj.Draw(draw_options)
    note.Draw()
    canvas.Print('output/' + plot_name + '.pdf')
Пример #3
0
def plot_en():

    #energy distribution of generated photons

    ebin = 0.1
    emin = 4
    emax = 28

    can = ut.box_canvas()

    hE = ut.prepare_TH1D("hE", ebin, emin, emax)

    tree.Draw("phot_en >> hE")

    hE.SetYTitle("Events / ({0:.3f}".format(ebin) + " GeV)")
    hE.SetXTitle("#it{E}_{#gamma} (GeV)")

    hE.SetTitleOffset(1.9, "Y")
    hE.SetTitleOffset(1.3, "X")

    gPad.SetTopMargin(0.02)
    gPad.SetRightMargin(0.01)
    gPad.SetBottomMargin(0.1)
    gPad.SetLeftMargin(0.14)

    hE.GetYaxis().SetMoreLogLabels()

    hE.Draw()

    gPad.SetLogy()

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Пример #4
0
def phot_xy():

    #photon detector first point in xy

    xbin = 0.1
    xmin = -12
    xmax = 12

    can = ut.box_canvas()

    hX = ut.prepare_TH2D("hX", xbin, xmin, xmax, xbin, xmin, xmax)

    #tree.Draw("phot_y/10:phot_x/10 >> hX")#, "phot_en<1000")
    tree.Draw("phot_hy/10:phot_hx/10 >> hX")  #, "phot_en<1000")

    hX.SetXTitle("Horizontal #it{x} (cm)")
    hX.SetYTitle("Vertical #it{y} (cm)")

    hX.GetXaxis().CenterTitle()
    hX.GetYaxis().CenterTitle()

    hX.SetTitleOffset(1.2, "Y")
    hX.SetTitleOffset(1.2, "X")

    gPad.SetTopMargin(0.01)
    gPad.SetRightMargin(0.11)
    gPad.SetBottomMargin(0.09)
    gPad.SetLeftMargin(0.09)

    hX.Draw()

    gPad.SetLogz()

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Пример #5
0
def plot_theta():

    #polar angle of generated photons

    tbin = 0.01
    tmax = 3

    can = ut.box_canvas()

    ht = ut.prepare_TH1D("ht", tbin, 0, tmax)

    tree.Draw("(TMath::Pi()-phot_theta)*1000 >> ht")

    ht.SetYTitle("Events / ({0:.3f}".format(tbin) + " mrad)")
    ht.SetXTitle("#vartheta (mrad)")

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

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

    ht.Draw()

    leg = ut.prepare_leg(0.2, 0.87, 0.18, 0.08, 0.035)
    leg.AddEntry(None, "Angular distribution of Bethe-Heitler photons", "")
    #leg.Draw("same")

    gPad.SetLogy()

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Пример #6
0
def plot_dSigDtheta():

    # dSigma / dTheta according to ZEUS parametrization

    Ee = 18

    gen = gen_zeus(Ee, 275)  # Ee, Ep, GeV
    sig = gen.dSigDtheta

    can = ut.box_canvas()

    sig.SetLineWidth(3)
    sig.SetNpx(1000)
    sig.SetTitle("")
    sig.Draw()

    sig.GetXaxis().SetTitle("#theta_{#gamma} (rad)")
    sig.GetYaxis().SetTitle("a. u.")

    sig.GetYaxis().SetTitleOffset(1.5)
    sig.GetXaxis().SetTitleOffset(1.3)

    gPad.SetTopMargin(0.01)
    gPad.SetRightMargin(0.08)

    leg = ut.prepare_leg(0.58, 0.78, 0.24, 0.15, 0.035)  # x, y, dx, dy, tsiz
    leg.AddEntry(sig, "#frac{d#sigma}{d#theta_{#gamma}}", "l")
    leg.AddEntry(None, "E_{e} = 18 GeV", "")
    leg.Draw("same")

    gPad.SetLogy()

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Пример #7
0
 def setPadStyle():
     gPad.SetLeftMargin(0.05)
     gPad.SetRightMargin(0.08)
     gPad.SetTopMargin(0.10)
     gPad.SetBottomMargin(0.10)
     gPad.SetLogz(plots[plot].zLog)
     gPad.SetFillColor(kWhite)
     gPad.SetBorderMode(0)
Пример #8
0
def phot_theta():

    #polar angle of generated photons

    tbin = 0.01
    tmax = 4

    gdir = "/home/jaroslav/sim/GETaLM/cards/"
    inp = "bg.root"

    infile = TFile.Open(gdir + inp)
    tree = infile.Get("ltree")

    can = ut.box_canvas()

    ht1 = ut.prepare_TH1D("ht1", tbin, 0, tmax)
    ht2 = ut.prepare_TH1D("ht2", tbin, 0, tmax)
    ht2.SetMarkerColor(rt.kRed)
    ht2.SetLineColor(rt.kRed)

    #tree.Draw("(TMath::Pi()-true_phot_theta)*1000 >> ht")
    tree.Draw("(TMath::Pi()-phot_theta)*1000 >> ht1",
              "vtx_z>5000 && vtx_z<12000")
    tree.Draw("(TMath::Pi()-phot_theta)*1000 >> ht2",
              "vtx_z>-5000 && vtx_z<5000")

    #ht.SetYTitle("Events / ({0:.3f}".format(tbin)+" mrad)")
    #ht.SetYTitle("Counts")
    #ht.SetXTitle("Photon #it{#theta} (mrad)")

    #ht.SetTitleOffset(1.5, "Y")
    #ht.SetTitleOffset(1.3, "X")

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

    gPad.SetGrid()

    ht1.Draw()
    ht2.Draw("e1same")

    #leg = ut.prepare_leg(0.2, 0.87, 0.18, 0.08, 0.035)
    #leg.AddEntry(None, "Angular distribution of Bethe-Heitler photons", "")
    #leg.Draw("same")

    gPad.SetLogy()

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Пример #9
0
def plot_zdc_vtx():

    #ZDC vertex from selected events and from all triggered events

    vbin = 0.1
    vmin = -5.
    vmax = 7.

    mmin = 1.5
    mmax = 5.

    can = ut.box_canvas()

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

    #make the histograms
    hZdcVtx = ut.prepare_TH1D("hZdcVtx", vbin, vmin, vmax)
    hZdcVtxAll = ut.prepare_TH1D("hZdcVtxAll", vbin / 10., vmin, vmax)

    #convert to meters for plot
    tree.Draw("jZDCVtxZ/100. >> hZdcVtx", strsel)
    treeAll = inp.Get("jAllTree")
    treeAll.Draw("jZDCVtxZ/100. >> hZdcVtxAll")
    ut.norm_to_data(hZdcVtxAll, hZdcVtx, rt.kRed)

    hZdcVtx.SetYTitle("Events / {0:.0f} cm".format(vbin * 100.))
    hZdcVtx.SetXTitle("ZDC vertex along #it{z} (meters)")

    hZdcVtx.SetTitleOffset(1.5, "Y")
    hZdcVtx.SetTitleOffset(1.1, "X")

    gPad.SetTopMargin(0.01)
    gPad.SetRightMargin(0.04)
    gPad.SetBottomMargin(0.08)
    gPad.SetLeftMargin(0.1)

    leg = ut.prepare_leg(0.67, 0.8, 0.28, 0.14, 0.025)
    leg.SetMargin(0.17)
    ut.add_leg_mass(leg, mmin, mmax)
    leg.AddEntry(hZdcVtx, "Selected events")
    leg.AddEntry(hZdcVtxAll, "All UPC-JpsiB triggers", "l")

    #gPad.SetLogy()

    hZdcVtx.Draw()
    hZdcVtxAll.Draw("same")
    leg.Draw("same")

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Пример #10
0
def plot_vtx_z():

    #primary vertex position along z from data and MC
    vbin = 4.
    vmax = 120.

    mmin = 1.5
    mmax = 5

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

    can = ut.box_canvas()

    hVtx = ut.prepare_TH1D("hVtx", vbin, -vmax, vmax)
    hVtxMC = ut.prepare_TH1D("hVtxMC", vbin/2., -vmax, vmax)

    tree.Draw("jVtxZ >> hVtx", strsel)
    mctree.Draw("jVtxZ >> hVtxMC", strsel)
    ut.norm_to_data(hVtxMC, hVtx, rt.kBlue, -40, 40)

    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)

    cut_lo = ut.cut_line(-30, 0.8, hVtx)
    cut_hi = ut.cut_line(30, 0.8, hVtx)

    leg = ut.prepare_leg(0.16, 0.82, 0.26, 0.12, 0.025)
    #leg.SetMargin(0.15)
    #leg.SetBorderSize(1)
    ut.add_leg_mass(leg, mmin, mmax)
    leg.AddEntry(hVtx, "Data")
    #leg.AddEntry(hVtxMC, "MC, coherent J/#it{#psi}", "l")
    leg.AddEntry(hVtxMC, "MC, #it{#gamma}#it{#gamma} #rightarrow e^{+}e^{-}", "l")
    leg.AddEntry(cut_lo, "Cut at #pm30 cm", "l")

    hVtx.Draw()
    hVtxMC.Draw("same")
    leg.Draw("same")
    cut_lo.Draw("same")
    cut_hi.Draw("same")

    #ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Пример #11
0
def plot_zdc():

    #ZDC ADC counts east or west 1D

    ew = 0

    zbin = 10.
    zmin = 0.
    zmax = 1300.

    znam = ["jZDCUnAttEast", "jZDCUnAttWest"]
    xtit = ["ZDC East ADC", "ZDC West ADC"]
    lhead = ["East ZDC", "West ZDC"]

    #global gPad
    can = ut.box_canvas()

    hZdc = ut.prepare_TH1D("hZdc", zbin, zmin, zmax)
    hZdcAll = ut.prepare_TH1D("hZdcAll", zbin, zmin, zmax)

    tree.Draw(znam[ew] + " >> hZdc")
    treeAll = inp.Get("jAllTree")
    treeAll.Draw(znam[ew] + " >> hZdcAll")
    ut.norm_to_data(hZdcAll, hZdc, rt.kRed)

    hZdc.SetYTitle("Events / {0:.1f}".format(zbin))
    hZdc.SetXTitle(xtit[ew])

    hZdc.SetTitleOffset(1.5, "Y")
    hZdc.SetTitleOffset(1.1, "X")

    gPad.SetTopMargin(0.01)
    gPad.SetRightMargin(0.08)
    gPad.SetBottomMargin(0.08)
    gPad.SetLeftMargin(0.1)

    leg = ut.prepare_leg(0.5, 0.76, 0.39, 0.16, 0.035)
    leg.SetMargin(0.17)
    leg.AddEntry(None, lhead[ew], "")
    leg.AddEntry(hZdc, "Selected events")
    leg.AddEntry(hZdcAll, "All UPC-JpsiB triggers", "l")

    hZdc.Draw()
    hZdcAll.Draw("same")
    leg.Draw("same")

    #ut.print_pad(rt.gPad)
    ut.invert_col(rt.gPad)

    can.SaveAs("01fig.pdf")
Пример #12
0
def setpad(left, right, top, bottom):
    gPad.SetFillColor(10)
    gPad.SetBorderMode(0)
    gPad.SetBorderSize(0)
    gPad.SetFrameFillColor(10)
    gPad.SetFrameBorderMode(0)
    gPad.SetFrameBorderSize(0)
    gPad.SetLeftMargin(left)
    gPad.SetRightMargin(right)
    gPad.SetTopMargin(top)
    gPad.SetBottomMargin(bottom)
    gPad.SetGridx(0)
    gPad.SetGridy(0)
    gStyle.SetOptStat(0)
Пример #13
0
def plot_zdc_vtx_alltrg():

    #ZDC vertex from all triggered events

    vbin = 0.01
    #vmin = -20.
    #vmax = 20.
    #vmin = -26
    #vmax = -12
    vmin = -800
    vmax = 800

    can = ut.box_canvas()

    #make the histogram
    hZdcVtx = ut.prepare_TH1D("hZdcVtxAll", vbin, vmin, vmax)
    hZdcVtx.SetOption("L")

    #convert to meters for plot
    treeAll = inp.Get("jAllTree")
    print("Number of all trg events:", treeAll.GetEntries())
    treeAll.Draw("jZDCVtxZ/100. >> hZdcVtxAll")

    hZdcVtx.SetYTitle("Events / {0:.0f} cm".format(vbin * 100.))
    hZdcVtx.SetXTitle("ZDC vertex along #it{z} (meters)")

    hZdcVtx.SetTitleOffset(1.5, "Y")
    hZdcVtx.SetTitleOffset(1.1, "X")

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

    leg = ut.prepare_leg(0.67, 0.8, 0.28, 0.14, 0.025)
    leg.SetMargin(0.17)
    #leg.AddEntry(None, "UPC-JpsiB 2014", "")
    #leg.AddEntry(None, "UPC-main 2010+2011", "")
    #leg.AddEntry(None, "UPC-main 2014", "")
    leg.AddEntry(None, "Zero bias 2014", "")
    #leg.AddEntry(None, "VPD-ZDC-novtx-mon", "")

    #gPad.SetLogy()

    hZdcVtx.Draw()
    leg.Draw("same")

    #ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Пример #14
0
def plot_2d(plot_pdf):

    plot_pdf.pdf.GetXaxis().SetTitleOffset(2.3)
    plot_pdf.pdf.GetYaxis().SetTitleOffset(1.9)
    plot_pdf.pdf.GetZaxis().SetTitleOffset(1.7)

    gPad.SetTopMargin(0.01)
    gPad.SetRightMargin(0.05)
    gPad.SetBottomMargin(0.11)
    gPad.SetLeftMargin(0.12)

    plot_pdf.plot()

    gPad.SetPhi(-125.)
    gPad.Update()
Пример #15
0
def plot_projection(frame, ew):

    xtit = ["ZDC East ADC", "ZDC West ADC"]

    frame.SetXTitle(xtit[ew])

    frame.GetXaxis().SetTitleOffset(1.2)
    frame.GetYaxis().SetTitleOffset(1.4)

    gPad.SetTopMargin(0.01)
    gPad.SetRightMargin(0.01)
    gPad.SetBottomMargin(0.1)
    gPad.SetLeftMargin(0.1)

    frame.Draw()
Пример #16
0
def up_down_en():

    #up and down spectrometers energy sum

    ebin = 0.1
    emin = 0
    emax = 20

    edet = 1

    can = ut.box_canvas()

    hE = ut.prepare_TH1D("hE", ebin, emin, emax)

    sel = "up_en>" + str(edet * 1e3) + " && down_en>" + str(edet * 1e3)

    #tree.Draw("(up_en+down_en)/1000. >> hE", sel)
    #tree.Draw("up_en/1000. >> hE")#, sel)
    #tree.Draw("down_en/1000. >> hE")
    #tree.Draw("up_en >> hE")#, sel)
    tree.Draw("down_en >> hE")

    print "Entries:", hE.GetEntries()

    hE.SetYTitle("Events / ({0:.3f}".format(ebin) + " GeV)")
    hE.SetXTitle("#it{E}_{#gamma} = #it{E}_{up} + #it{E}_{down} (GeV)")

    hE.SetTitleOffset(1.4, "Y")
    hE.SetTitleOffset(1.3, "X")

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

    #hE.GetYaxis().SetMoreLogLabels()

    hE.Draw()

    gPad.SetLogy()

    leg = ut.prepare_leg(0.58, 0.8, 0.2, 0.15, 0.035)  # x, y, dx, dy, tsiz
    leg.AddEntry(hE, "#it{E}_{up} + #it{E}_{down}", "lp")
    leg.AddEntry(None, "#it{E}_{up}>1 #bf{and} #it{E}_{down}>1 GeV", "")
    leg.Draw("same")

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Пример #17
0
def draw_canvas_2d(name):

    f_mc = TFile("plots/mc/%s_mcc7.root" % name)
    h_mc = gDirectory.Get("h_%s_reco" % name)
    f = TFile("plots/data/e_%s_pandoraCosmic.root" % name)
    h = gDirectory.Get("h_%s" % name)
    h.Divide(h_mc)
    h.GetZaxis().SetRangeUser(0.5, 1.5)
    #h.GetZaxis().SetTitle("Data/Monte Carlo")
    #h.GetZaxis().RotateTitle()
    h.SetMarkerSize(2)
    x_minbin = h.FindFirstBinAbove(0, 1)
    low_x = h.GetXaxis().GetBinLowEdge(x_minbin)
    x_maxbin = h.FindLastBinAbove(0, 1)
    high_x = h.GetXaxis().GetBinUpEdge(x_maxbin)

    y_minbin = h.FindFirstBinAbove(0, 2)
    low_y = h.GetYaxis().GetBinLowEdge(y_minbin)
    y_maxbin = h.FindLastBinAbove(0, 2)
    high_y = h.GetYaxis().GetBinUpEdge(y_maxbin)

    h.GetXaxis().SetRangeUser(low_x, high_x)
    h.GetYaxis().SetRangeUser(low_y, high_y)

    c = TCanvas("c_%s" % name)
    h.SetMarkerSize(2.5)
    gPad.SetBottomMargin(0.17)
    gPad.SetLeftMargin(0.13)
    gPad.SetTopMargin(0.15)
    gPad.SetRightMargin(0.15)

    h.GetYaxis().SetTitleSize(0.07)
    h.GetXaxis().SetTitleSize(0.07)
    h.GetYaxis().SetTitleOffset(0.8)

    pt = TPaveText(0.13, 0.855, 0.42, 0.98, "ndc")
    pt.AddText("MicroBooNE")
    pt.SetFillColor(0)
    pt.SetBorderSize(0)
    pt.SetShadowColor(0)
    h.Draw("colz texte")

    pt.Draw()
    c.Update()
    c.SaveAs("plots/%s.pdf" % name)
    c.SaveAs("plots/%s.p" % name)

    return c
Пример #18
0
def plot_zdc_tpc_vtx():

    #2D ZDC and TPC vertices

    zbin = 2.
    #zmin = -50.
    #zmax = 100.
    zmin = -100
    zmax = 150

    tbin = 2.
    #tmin = -55.
    #tmax = 55.
    tmin = -110
    tmax = 110

    mmin = 1.5
    mmax = 5.

    can = ut.box_canvas()

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

    hVtx = ut.prepare_TH2D("hVtx", tbin, tmin, tmax, zbin, zmin, zmax)

    tree.Draw("jZDCVtxZ:jVtxZ >> hVtx", strsel)
    hVtx.SetXTitle("TPC vertex along #it{z} / " + "{0:.0f} cm".format(zbin))
    hVtx.SetYTitle("ZDC vertex along #it{z} / " + "{0:.0f} cm".format(zbin))

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

    gPad.SetTopMargin(0.02)
    gPad.SetRightMargin(0.09)
    gPad.SetBottomMargin(0.08)
    gPad.SetLeftMargin(0.11)

    leg = ut.prepare_leg(0.16, 0.82, 0.23, 0.05, 0.025)
    leg.SetMargin(0.02)
    leg.SetBorderSize(1)
    ut.add_leg_mass(leg, mmin, mmax)

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

    #ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Пример #19
0
def plot_dSigDe():

    # dSigma / dEgamma according to ZEUS parametrization

    parse = ConfigParser.RawConfigParser()
    parse.add_section("main")
    parse.set("main", "emin", "6")
    parse.set("main", "Ee", "18")
    parse.set("main", "Ep", "275")
    gen = gen_zeus(parse)
    sig = gen.dSigDe

    gStyle.SetPadTickY(1)
    can = ut.box_canvas()

    #frame = gPad.DrawFrame(6, 0, 29, 6)
    frame = gPad.DrawFrame(5, 0, 19, 7.2)

    sig.SetLineWidth(3)
    sig.SetNpx(1000)
    sig.SetTitle("")
    sig.Draw("same")

    frame.GetXaxis().SetTitle("#it{E}_{#gamma} (GeV)")
    frame.GetYaxis().SetTitle("d#sigma / d#it{E}_{#gamma} (mb/GeV)")

    frame.GetYaxis().SetTitleOffset(1.1)
    frame.GetXaxis().SetTitleOffset(1.3)

    frame.SetTickLength(0.015, "X")
    frame.SetTickLength(0.015, "Y")

    gPad.SetTopMargin(0.02)
    gPad.SetRightMargin(0.01)
    gPad.SetLeftMargin(0.09)

    leg = ut.prepare_leg(0.65, 0.73, 0.24, 0.2, 0.035)  # x, y, dx, dy, tsiz
    leg.AddEntry(sig, "#frac{d#sigma}{d#it{E}_{#gamma}}", "l")
    leg.AddEntry(None, "", "")
    #leg.AddEntry(None, "#it{E}_{e} = 27.6 GeV", "")
    #leg.AddEntry(None, "#it{E}_{p} = 920 GeV", "")
    leg.AddEntry(None, "#it{E}_{e} = 18 GeV", "")
    leg.AddEntry(None, "#it{E}_{p} = 275 GeV", "")
    leg.Draw("same")

    ut.invert_col(gPad)
    can.SaveAs("01fig.pdf")
Пример #20
0
def up_xy():

    #up spectrometer first point in xy

    xbin = 0.1

    xmin = -12
    xmax = 12

    ymin = 3
    ymax = 25

    emin = 0.7

    can = ut.box_canvas()

    hX = ut.prepare_TH2D("hX", xbin, xmin, xmax, xbin, ymin, ymax)

    sel = "up_en>" + str(emin * 1e3)

    #tree.Draw("up_y/10:up_x/10 >> hX", sel)
    tree.Draw("up_hy/10:up_hx/10 >> hX")

    hX.SetXTitle("Horizontal #it{x} (cm)")
    hX.SetYTitle("Vertical #it{y} (cm)")

    hX.GetXaxis().CenterTitle()
    hX.GetYaxis().CenterTitle()

    hX.SetTitleOffset(1.2, "Y")
    hX.SetTitleOffset(1.2, "X")

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

    hX.Draw()

    gPad.SetLogz()

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Пример #21
0
    def draw(self, elements):

        gROOT.SetBatch()

        gStyle.SetPadTickY(1)
        gStyle.SetPadTickX(1)

        c1 = TCanvas("c1", "c1", 1000, 700)
        frame = gPad.DrawFrame(self.zmin, self.xmin, self.zmax,
                               self.xmax)  # xmin, ymin, xmax, ymax in ROOT
        frame.SetTitle(";Length #it{z} (m);Horizontal #it{x} (cm)")
        siz = 0.035
        frame.SetTitleSize(siz)
        frame.SetLabelSize(siz)
        frame.SetTitleSize(siz, "Y")
        frame.SetLabelSize(siz, "Y")

        frame.GetYaxis().SetTitleOffset(1)
        frame.GetXaxis().SetTitleOffset(1.2)
        frame.GetYaxis().CenterTitle()
        frame.GetXaxis().CenterTitle()
        gPad.SetLeftMargin(0.07)
        gPad.SetRightMargin(0.01)
        gPad.SetTopMargin(0.02)
        gPad.SetBottomMargin(0.09)

        #loop over elements
        for el in elements.itervalues():
            if not hasattr(el, "draw_2d"): continue
            el.draw_2d()

        #redraw these elements on the top
        #draw_top = ["Q0EF", "beam_electron", "beam_hadron"]
        draw_top = ["ew"]
        for i in draw_top:
            el = elements.get(i)
            if el is not None: el.draw_2d()

        gPad.SetGrid()

        #self.invert_col(gPad)

        c1.SaveAs("01fig.pdf")
Пример #22
0
def plot_proj_both(frame2, frame_east, frame_west, adc_bin, adc_min, adc_max,
                   ptmax, mmin, mmax):

    can = ut.box_canvas(800, 700)  #900, 700

    xp = Double(0)
    yp = Double(0)

    #east data on the left
    hEast = frame_east.getHist("data")
    plot_east = frame2.Clone("plot_east")
    plot_east.SetMarkerStyle(22)
    plot_east.SetMarkerSize(1.4)
    ut.set_H1D_col(plot_east, rt.kBlue)
    for ibin in xrange(hEast.GetN()):
        hEast.GetPoint(ibin, xp, yp)
        plot_east.SetBinContent(ibin + 1, yp)
        plot_east.SetBinError(ibin + 1, hEast.GetErrorY(ibin))

    frame2.SetMaximum(1.2 * plot_east.GetMaximum())  # 1.15

    #west data on the right
    hWest = frame_west.getHist("data")
    plot_west = frame2.Clone("plot_west")
    plot_west.SetMarkerStyle(21)
    ut.set_H1D_col(plot_west, rt.kRed)
    for i in xrange(hWest.GetN()):
        hWest.GetPoint(i, xp, yp)
        ibin = frame2.GetNbinsX() - i
        plot_west.SetBinContent(ibin, yp)
        plot_west.SetBinError(ibin, hWest.GetErrorY(i))

    #east fit
    cEast = frame_east.getCurve("model")
    gEast = TGraph(cEast.GetN() - 1)
    for i in xrange(cEast.GetN() - 1):
        cEast.GetPoint(i, xp, yp)
        gEast.SetPoint(i, xp, yp)

    gEast.SetLineColor(rt.kBlue)
    gEast.SetLineWidth(3)
    gEast.SetLineStyle(rt.kDashed)
    #gEast.SetLineStyle(rt.kDashDotted)

    #west fit on the left
    cWest = frame_west.getCurve("model")
    gWest = TGraph(cWest.GetN() - 1)
    xmax = frame2.GetBinCenter(
        frame2.GetNbinsX()) + frame2.GetBinWidth(frame2.GetNbinsX()) / 2.
    for i in xrange(cWest.GetN() - 1):
        cWest.GetPoint(i, xp, yp)
        xplot = xmax - xp
        gWest.SetPoint(i, xplot, yp)

    gWest.SetLineColor(rt.kRed)
    gWest.SetLineWidth(3)
    #gWest.SetLineStyle(rt.kDashDotted)
    #gWest.SetLineStyle(rt.kDashed)

    #horizontal axis
    frame2.SetMinimum(0)
    #frame2.SetMinimum(0.98)
    frame2.GetXaxis().SetNdivisions(0, rt.kFALSE)
    #east axis
    ypos = frame2.GetYaxis().GetXmin()
    axisE = TGaxis(adc_min, ypos, adc_max, ypos, adc_min, adc_max)
    ut.set_axis(axisE)
    axisE.SetWmin(axisE.GetWmin() * 0.01)
    axisE.SetWmax(axisE.GetWmax() * 0.01)
    axisE.SetTitle("ZDC East #times100")
    axisE.SetTitleOffset(1.1)
    #west axis
    xpos = frame2.GetXaxis().GetXmax()
    axisW = TGaxis(xpos, ypos, xpos - adc_max, ypos, adc_min, adc_max, 510,
                   "-")
    ut.set_axis(axisW)
    axisW.SetWmin(axisW.GetWmin() * 0.01)
    axisW.SetWmax(axisW.GetWmax() * 0.01)
    axisW.SetLabelOffset(-0.024)
    axisW.SetTitle("ZDC West #times100")
    axisW.SetTitleOffset(1.1)

    #vertical axis
    yvpos = 1. * frame2.GetMaximum()
    axisV = TGaxis(xpos, 0, xpos, yvpos, 0, yvpos, 510, "+L")
    #axisV = TGaxis(xpos, 0, xpos, yvpos, 0.98, yvpos, 510, "+G")
    ut.set_axis(axisV)

    frame2.SetYTitle("ZDC East / ({0:.0f} ADC units)".format(adc_bin))
    axisV.SetTitle("ZDC West / ({0:.0f} ADC units)".format(adc_bin))

    frame2.GetYaxis().SetTitleOffset(1.5)
    axisV.SetTitleOffset(1.5)

    gPad.SetTopMargin(0.05)  # 0.01
    gPad.SetRightMargin(0.1)
    gPad.SetBottomMargin(0.08)
    gPad.SetLeftMargin(0.1)

    frame2.Draw()
    plot_east.Draw("e1same")
    plot_west.Draw("e1same")
    gEast.Draw("lsame")
    gWest.Draw("lsame")

    axisE.Draw()
    axisW.Draw()
    axisV.Draw()

    #kinematics legend
    #kleg = ut.prepare_leg(0.16, 0.78, 0.32, 0.2, 0.035)
    kleg = ut.prepare_leg(0.16, 0.73, 0.32, 0.2, 0.035)
    kleg.AddEntry(None, "AuAu@200 GeV", "")
    kleg.AddEntry(None, "UPC sample", "")
    ut.add_leg_pt_mass(kleg, ptmax, mmin, mmax)
    kleg.Draw("same")

    #data legend
    dleg = ut.prepare_leg(0.6, 0.8, 0.15, 0.08, 0.03)
    dleg.AddEntry(plot_east, "ZDC East", "p")
    dleg.AddEntry(plot_west, "ZDC West", "p")
    #dleg.Draw("same")

    #projections legend
    #pleg = ut.prepare_leg(0.24, 0.56, 0.25, 0.2, 0.035)
    pleg = ut.prepare_leg(0.24, 0.51, 0.25, 0.2, 0.035)
    pleg.AddEntry(plot_east, "ZDC East", "p")
    pleg.AddEntry(plot_west, "ZDC West", "p")
    pleg.AddEntry(gEast, "Fit projection to east", "l")
    pleg.AddEntry(gWest, "Fit projection to west", "l")
    pleg.Draw("same")

    #gPad.SetLogy()
    #gPad.SetGrid()

    #ut.invert_col(gPad)
    can.SaveAs("01fig.pdf")
Пример #23
0
gr.GetYaxis().SetLabelSize(textsize)
gr.GetYaxis().SetTitleOffset(1.4)
gr.GetYaxis().SetRangeUser(2, 100)
gPad.SetLeftMargin(0.15)
gr.Draw( 'AP' )

func1 = TF1('fun1', 'x', 0., 100.)
func1.SetLineColor(4)
func1.SetLineStyle(2)
func1.Draw('same')
####


c1.cd(2)
gPad.SetPad(small, small, 1.-small, 0.3-small)
gPad.SetTopMargin(small)
gPad.SetLeftMargin(0.15)
gPad.SetBottomMargin(0.3)
gPad.SetTickx()

gr1 = TGraph( n, energyVec, deltaE_f )
gr1.SetLineColor( 1 )
gr1.SetLineWidth( 1 )
gr1.SetMarkerStyle( 20 )
gr1.SetMarkerSize( makerSize )
gr1.SetMarkerColor( 2 )
gr1.SetTitle( '' )
textsize = labelSize/(gPad.GetWh()*gPad.GetAbsHNDC())
gr1.GetXaxis().SetTitle( 'E_{particle} (GeV)' )
gr1.GetYaxis().SetTitle( '#DeltaE/E_{particle}' )
gr1.GetXaxis().SetTitleOffset(1.2)
Пример #24
0
def plot_en(det):

    #energy per detector cell

    ncells = 7

    dx = 10.5

    if det == "phot":
        dy = [-10.5, 10.5]
    if det == "up":
        dy = [4.2, 25.2]
    if det == "down":
        dy = [-25.2, -4.2]

    nevt = 1000

    can = ut.box_canvas()

    hCells = ut.prepare_TH2D_n("hCells", ncells, -dx, dx, ncells, dy[0], dy[1])

    #cells loop
    gROOT.ProcessLine("struct Entry {Double_t val;};")
    entry = rt.Entry()
    for ix in xrange(ncells):
        for iy in xrange(ncells):
    #for ix in xrange(0,1):
    #    for iy in xrange(0,1):

            #branch for the cell
            xform = "{0:02d}".format(ix)
            yform = "{0:02d}".format(iy)
            bnam = det + "_" + xform + "x" + yform + "_en"

            #energy in the cell
            tree.ResetBranchAddresses()
            tree.SetBranchStatus("*", 0)
            tree.SetBranchStatus(bnam, 1)
            tree.SetBranchAddress(bnam, AddressOf(entry, "val"))
            ecell = 0.
            for i in xrange(nevt):
                tree.GetEntry(i)
                ecell += entry.val

            #print xform, yform, ecell/1000./nevt

            hCells.SetBinContent(ix+1, ncells-iy, ecell/1000./nevt)

    hCells.SetXTitle("Horizontal #it{x} (cm)")
    hCells.SetYTitle("Vertical #it{y} (cm)")

    hCells.GetXaxis().CenterTitle()
    hCells.GetYaxis().CenterTitle()

    hCells.SetTitleOffset(1.2, "Y")
    hCells.SetTitleOffset(1.2, "X")

    gPad.SetTopMargin(0.01)
    gPad.SetRightMargin(0.12)
    gPad.SetBottomMargin(0.09)
    gPad.SetLeftMargin(0.09)

    hCells.Draw()

    gPad.SetLogz()

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Пример #25
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")
Пример #26
0
def main():

    zmin = -40000.
    zmax = -10100.
    xmin = -1300.
    xmax = 800.

    c1 = TCanvas("c1", "c1", 1000, 700)
    frame = gPad.DrawFrame(zmin, xmin, zmax,
                           xmax)  # xmin, ymin, xmax, ymax in ROOT
    frame.SetTitle(";Length #it{z} (mm);Horizontal #it{x} (mm)")
    siz = 0.035
    frame.SetTitleSize(siz)
    frame.SetLabelSize(siz)
    frame.SetTitleSize(siz, "Y")
    frame.SetLabelSize(siz, "Y")

    frame.GetYaxis().SetTitleOffset(1.3)
    frame.GetXaxis().SetTitleOffset(1.2)
    frame.GetYaxis().CenterTitle()
    frame.GetXaxis().CenterTitle()
    gPad.SetLeftMargin(0.09)
    gPad.SetRightMargin(0.01)
    gPad.SetTopMargin(0.02)
    gPad.SetBottomMargin(0.09)

    #geometry
    geo = rt.GeoParser("../../config/pro1/geom_all.in")

    #spectrometer magnet
    mag = magnet("lumi_dipole", geo)
    mag.label = "Spectr. dipole"
    mag.draw()

    #B2BeR magnet
    b2b = magnet("B2BeR", geo)
    b2b.label = "B2BeR"
    b2b.draw()

    #Q3eR magnet
    q3 = magnet("Q3eR", geo)
    q3.label = "Q3eR"
    q3.draw()

    #beam vacuum
    bvac = vacuum(geo)
    bvac.add_point("vac_b2b_drift", "zQB", "xQB")
    bvac.add_point("vac_b2b_drift", "zQT", "xQT")
    bvac.add_point("vac_b2b_drift", "zW", "xW")
    bvac.add_point("vac_b2b_window", "win_z", "win_xmax")
    bvac.add_point_2("vac_b2b_window.b2b_end_z", "B2BeR.r2")
    bvac.add_point("vac_tag1_win", "zB", "xB")
    bvac.draw()

    #vacuum in front of Tagger 1
    vac_t1 = vacuum(geo)
    vac_t1.add_point("vac_tag1_win", "zTB", "xTB")
    vac_t1.add_point("vac_tag1_win", "zT", "xT")
    vac_t1.add_point("vac_tag1_win", "zB", "xB")
    vac_t1.draw()

    #vacuum in front of Tagger 2
    vac_t2 = vacuum(geo)
    vac_t2.add_point("vac_tag2_win", "zTB", "xTB")
    vac_t2.add_point("vac_tag2_win", "zT", "xT")
    vac_t2.add_point("vac_tag2_win", "zB", "xB")
    vac_t2.draw()

    #vacuum from exit window to spectrometer magnet
    vac_win = vacuum(geo)
    vac_win.add_point("vac_lumi_win_mag", "z1", "dX1", -1.)
    vac_win.add_point("vac_lumi_win_mag", "z1", "dX1")
    vac_win.add_point("vac_lumi_win_mag", "z0", "dX0")
    vac_win.add_point("vac_lumi_win_mag", "z0", "dX0", -1.)
    #vac_win.add_point("", "", "")
    #vac_win.draw()

    #vacuum from spectrometer magnet to spectrometer detectors
    vac_mag = vacuum(geo)
    vac_mag.add_point("vac_lumi_mag_spec", "z1", "dX1", -1.)
    vac_mag.add_point("vac_lumi_mag_spec", "z1", "dX1")
    vac_mag.add_point("vac_lumi_mag_spec", "z0", "dX0")
    vac_mag.add_point("vac_lumi_mag_spec", "z0", "dX0", -1.)
    #vac_mag.draw()

    #vacuum section from spectrometers to direct photon detector
    vac_phot = vacuum(geo)
    vac_phot.add_point("vac_lumi_spec_phot", "z1", "dX1", -1.)
    vac_phot.add_point("vac_lumi_spec_phot", "z1", "dX1")
    vac_phot.add_point("vac_lumi_spec_phot", "z0", "dX0")
    vac_phot.add_point("vac_lumi_spec_phot", "z0", "dX0", -1.)
    #vac_phot.draw()

    #Tagger1
    tag1 = segment("Tagger1box", geo)
    tag1.label = "Tagger 1"
    tag1.draw()

    #Tagger2
    tag2 = segment("Tagger2box", geo)
    tag2.label = "Tagger 2"
    tag2.draw()

    #Luminosity exit window
    ew = segment("ExitWinBox", geo)
    ew.label = "Exit window"
    ew.fill_col = rt.kGreen + 1
    ew.draw()

    #up spectrometer for both spectrometers
    up = segment("LumiSUbox", geo)
    up.theta = 0
    up.label = "Spectrometers"
    up.draw()

    #Luminosity direct photon detector
    phot = segment("LumiDbox", geo)
    phot.label = "Photon detector"
    phot.draw()

    leg = ut.prepare_leg(0.8, 0.21, 0.25, 0.15,
                         0.03)  #, 0.027) # x, y, dx, dy, tsiz
    leg.AddEntry(tag1.gbox, "Detector", "f")
    leg.AddEntry(b2b.gbox, "Magnet", "f")
    leg.AddEntry(bvac.gbox, "Vacuum", "f")
    leg.Draw("same")

    gPad.SetGrid()

    ut.invert_col(gPad)
    c1.SaveAs("01fig.pdf")
Пример #27
0
    ut.log_results(out, ut.log_fit_result(r1))
    ut.log_results(out, "Alpha and n in 3-digits:")
    ut.log_results(
        out, "{0:6} {1:.3f} +/- {2:.3f}".format("alpha:", alpha.getVal(),
                                                alpha.getError()))
    ut.log_results(
        out, "{0:6} {1:.3f} +/- {2:.3f}".format("n:", n.getVal(),
                                                n.getError()))

    #create the plot
    gStyle.SetPadTickX(1)
    gStyle.SetFrameLineWidth(2)

    can = ut.box_canvas()
    gPad.SetRightMargin(0.02)
    gPad.SetTopMargin(0.04)
    gPad.SetBottomMargin(0.09)
    gPad.SetLeftMargin(0.11)

    frame = m.frame(rf.Bins(nbins), rf.Title(""))
    frame.SetTitle("")
    frame.GetXaxis().SetTitleOffset(1.2)
    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))
def plot_data_histogram(fits, name):
    return
    test_canvas = TCanvas("TestCanvas", "Ds Fit", 0, 0, 800, 575)

    gStyle.SetPadBorderMode(0)
    gStyle.SetFrameBorderMode(0)

    test_canvas.Divide(1, 2, 0, 0)
    upper_pad = test_canvas.GetPad(1)
    lower_pad = test_canvas.GetPad(2)
    low, high = 0.05, 0.95
    upper_pad.SetPad(low, 0.4, high, high)
    lower_pad.SetPad(low, low, high, 0.4)

    test_canvas.cd(1)

    ROOT.IABstyles.canvas_style(test_canvas, 0.25, 0.05, 0.02, 0.15, 0, 0)

    h_Mjj = TH1D("h_Mjj", "Mass Spectrum", 100, 0.2, 12)
    h_Mjj.GetYaxis().SetTitle("num. events")
    h_Mjj.GetXaxis().SetTitle("M [Tev/c^{-2}]")

    ROOT.IABstyles.h1_style(h_Mjj, ROOT.IABstyles.lWidth // 2,
                            ROOT.IABstyles.Scolor, 1, 0, 0, -1111.0, -1111.0,
                            508, 508, 8, ROOT.IABstyles.Scolor, 0.1, 0)

    h_Mjj.GetYaxis().SetRangeUser(0.1, 1e6)
    h_Mjj.GetXaxis().SetRangeUser(1, 10)
    h_Mjj.GetXaxis().SetTitleOffset(1)
    h_Mjj.GetYaxis().SetTitleOffset(1.1)

    upper_pad.SetLogy(1)
    upper_pad.SetLogx(1)
    lower_pad.SetLogx(1)

    gr = TGraphErrors(fits.num_bins, array("d", fits.xmiddle),
                      array("d", fits.data), array("d", fits.xwidth),
                      array("d", fits.errors))
    ROOT.IABstyles.h1_style(gr, ROOT.IABstyles.lWidth // 2,
                            ROOT.IABstyles.Scolor, 1, 0, 0, -1111, -1111, 505,
                            505, 8, ROOT.IABstyles.Scolor, 0.1, 0)

    grFit = TGraph(fits.num_bins, array("d", fits.xmiddle),
                   array("d", fits.data_fits))
    ROOT.IABstyles.h1_style(grFit, ROOT.IABstyles.lWidth // 2, 632, 1, 0, 0,
                            -1111, -1111, 505, 505, 8, 632, 0.1, 0)

    h_Mjj.Draw("axis")
    gr.Draw("P")
    grFit.Draw("c")

    test_canvas.Update()

    gPad.SetBottomMargin(1e-5)

    test_canvas.cd(2)
    gPad.SetTopMargin(1e-5)

    h2 = TH1D("h2", "", 100, 0.2, 12)
    h2.GetXaxis().SetRangeUser(1, 10)
    h2.GetYaxis().SetRangeUser(-10, 10)
    h2.SetStats(False)  # don't show stats box
    h2.Draw("axis")
    sig_values = [(data - theory) / theory if
                  (data != 0 and theory != 0) else -100
                  for data, theory in zip(fits.data, fits.data_fits)]
    sig = TGraph(fits.num_bins, array("d", fits.xmiddle),
                 array("d", sig_values))
    #ROOT.IABstyles.h1_style(sig, ROOT.IABstyles.lWidth/2, 632, 1, 0, 0, -1111, -1111, 505, 505, 8, 632, 0.1, 0)
    ROOT.IABstyles.h1_style(gr, ROOT.IABstyles.lWidth // 2,
                            ROOT.IABstyles.Scolor, 1, 0, 0, -1111, -1111, 505,
                            505, 8, ROOT.IABstyles.Scolor, 0.1, 0)
    sig.SetMarkerStyle(22)  # triangle
    sig.SetMarkerColor(2)  # red
    sig.SetMarkerSize(0.8)
    sig.Draw("P")
    #lower_pad.Draw()

    label = ROOT.TText()
    label.SetNDC()
    label.SetTextSize(0.03)
    label.DrawText(0.5, 0.7, "{0}GeV q*".format(MASS_FILE))

    # test_canvas.SaveAs("output_qstar.pdf")
    test_canvas.SaveAs("plots/{0}/{2}/plot-{1}-{2}-hist.png".format(
        CLUSTER_ID, name, MASS_FILE))
Пример #29
0
            h_theta_phi_reco.SetBinContent(i, j, eff)
            h_theta_phi_reco.SetBinError(i, j, error)

pt = TPaveText(0.10, 0.905, 0.40, 0.98, "ndc")
#pt.AddText("MicroBooNE in progress")
pt.SetFillColor(0)
pt.SetBorderSize(0)
pt.SetShadowColor(0)
h_theta_phi_reco.GetXaxis().SetRangeUser(60, 120)
h_theta_phi_reco.GetYaxis().SetRangeUser(-90, -45)
h_theta_phi_reco.GetZaxis().SetRangeUser(0, 1)

h_theta_phi_reco.SetMarkerSize(2.5)
gPad.SetBottomMargin(0.17)
gPad.SetLeftMargin(0.13)
gPad.SetTopMargin(0.15)
gPad.SetRightMargin(0.15)

h_theta_phi_reco.GetYaxis().SetTitleSize(0.07)
h_theta_phi_reco.GetXaxis().SetTitleSize(0.07)
h_theta_phi_reco.GetYaxis().SetTitleOffset(0.8)

pt = TPaveText(0.13, 0.855, 0.42, 0.98, "ndc")
pt.AddText("MicroBooNE")
pt.SetFillColor(0)
pt.SetBorderSize(0)
pt.SetShadowColor(0)
h_theta_phi_reco.Draw("colz texte")

pt.Draw()
def rooFit109():

    print ">>> setup model..."
    x = RooRealVar("x", "x", -10, 10)
    sigma = RooRealVar("sigma", "sigma", 3, 0.1, 10)
    mean = RooRealVar("mean", "mean", 0, -10, 10)
    gauss = RooGaussian("gauss", "gauss", x, RooConst(0),
                        sigma)  # RooConst(0) gives segfaults
    data = gauss.generate(RooArgSet(x), 100000)  # RooDataSet
    #sigma = 3.15 # overwrites RooRealVar with a float
    sigma.setVal(3.15)

    print ">>> plot data and slightly distorted model..."
    frame1 = x.frame(Title("Data with distorted Gaussian pdf"),
                     Bins(40))  # RooPlot
    data.plotOn(frame1, DataError(RooAbsData.SumW2))
    gauss.plotOn(frame1)

    print ">>> calculate chi^2..."
    # Show the chi^2 of the curve w.r.t. the histogram
    # If multiple curves or datasets live in the frame you can specify
    # the name of the relevant curve and/or dataset in chiSquare()
    print ">>>   chi^2 = %.2f" % frame1.chiSquare()

    print ">>> construct histograms with the residuals and pull of the data wrt the curve"
    hresid = frame1.residHist()  # RooHist
    hpull = frame1.pullHist()  # RooHist
    frame2 = x.frame(Title("Residual Distribution"))  # RooPlot
    frame2.addPlotable(hresid, "P")
    frame3 = x.frame(Title("Pull Distribution"))  # RooPlot
    frame3.addPlotable(hpull, "P")

    print ">>> draw functions and toy data on canvas..."
    canvas = TCanvas("canvas", "canvas", 100, 100, 2000, 400)
    canvas.Divide(3)
    for i, frame in enumerate([frame1, frame2, frame3], 1):
        canvas.cd(i)
        gPad.SetLeftMargin(0.14)
        gPad.SetRightMargin(0.04)
        frame.GetYaxis().SetTitleOffset(1.5)
        frame.GetYaxis().SetLabelOffset(0.010)
        frame.GetYaxis().SetTitleSize(0.045)
        frame.GetYaxis().SetLabelSize(0.042)
        frame.GetXaxis().SetTitleSize(0.045)
        frame.GetXaxis().SetLabelSize(0.042)
        frame.Draw()
    canvas.SaveAs("rooFit109.png")
    canvas.Close()

    # ratio/pull/residual plot
    print ">>> draw with pull plot..."
    canvas = TCanvas("canvas", "canvas", 100, 100, 1000, 1000)
    canvas.Divide(2)
    canvas.cd(1)
    gPad.SetPad("pad1", "pad1", 0, 0.33, 1, 1, 0, -1, 0)
    gPad.SetTopMargin(0.10)
    gPad.SetBottomMargin(0.03)
    gPad.SetLeftMargin(0.14)
    gPad.SetRightMargin(0.04)
    gPad.SetBorderMode(0)
    gStyle.SetTitleFontSize(0.062)
    frame1.GetYaxis().SetTitle("Events / %.3g GeV" % frame1.getFitRangeBinW())
    frame1.GetYaxis().SetTitleSize(0.059)
    frame1.GetYaxis().SetTitleOffset(1.21)
    #frame1.GetYaxis().SetLabelOffset(0.010)
    frame1.GetXaxis().SetLabelSize(0)
    frame1.GetYaxis().SetLabelSize(0.045)
    frame1.Draw()
    canvas.cd(2)
    gPad.SetPad("pad2", "pad2", 0, 0, 1, 0.33, 0, -1, 0)
    gPad.SetTopMargin(0.01)
    gPad.SetBottomMargin(0.30)
    gPad.SetLeftMargin(0.14)
    gPad.SetRightMargin(0.04)
    gPad.SetBorderMode(0)
    gPad.SetGridy(kTRUE)
    line1 = TLine(frame3.GetXaxis().GetXmin(), 0,
                  frame3.GetXaxis().GetXmax(), 0)
    line2 = TLine(frame3.GetXaxis().GetXmin(), 0,
                  frame3.GetXaxis().GetXmax(), 0)
    line1.SetLineColor(0)  # white to clear dotted grid lines
    line2.SetLineColor(12)  # dark grey
    line2.SetLineStyle(2)
    frame3.SetTitle("")
    frame3.GetYaxis().SetTitle("pull")
    frame3.GetXaxis().SetTitle("#Deltam^{2}_{ll} [GeV]")
    frame3.GetXaxis().SetTitleSize(0.13)
    frame3.GetYaxis().SetTitleSize(0.12)
    frame3.GetXaxis().SetTitleOffset(1.0)
    frame3.GetYaxis().SetTitleOffset(0.58)
    frame3.GetXaxis().SetLabelSize(0.10)
    frame3.GetYaxis().SetLabelSize(0.10)
    frame3.GetXaxis().SetLabelOffset(0.02)
    frame3.GetYaxis().SetLabelOffset(0.01)
    frame3.GetYaxis().SetRangeUser(-5, 5)
    frame3.GetYaxis().CenterTitle(True)
    frame3.GetYaxis().SetNdivisions(505)
    frame3.Draw("")
    line1.Draw("SAME")
    line2.Draw("SAME")
    frame3.Draw("SAME")
    canvas.SaveAs("rooFit109_ratiolike.png")
    canvas.Close()