Ejemplo n.º 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())
Ejemplo n.º 2
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")
Ejemplo n.º 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")
Ejemplo n.º 4
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")
Ejemplo n.º 5
0
def gPadSet():
    gPad.SetTickx(1)
    gPad.SetTicky(1)
    gPad.SetLeftMargin(0.12)
    gPad.SetRightMargin(1.4)
    gPad.SetBottomMargin(0.10)
    gPad.SetFrameLineWidth(2)
    gPad.RedrawAxis()
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
 def draw(self):
     self.canvas = TCanvas('can' + self.name, self.name, 1000, 800)
     if self.histo == None:
         self.bookCorrelationHisto()
     self.histo.Draw('boxtext')
     gPad.SetBottomMargin(0.3)
     gPad.SetLeftMargin(0.3)
     gPad.SetRightMargin(0.2)
     gPad.SaveAs('cutCorr_' + self.name + '_' +
                 varStringToFileName(self.addtlCut) + '.png')
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 11
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)
Ejemplo n.º 12
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")
Ejemplo n.º 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")
Ejemplo n.º 14
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()
Ejemplo n.º 15
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()
Ejemplo n.º 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")
Ejemplo n.º 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
Ejemplo n.º 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")
Ejemplo n.º 19
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")
Ejemplo n.º 20
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")
Ejemplo n.º 21
0
   # 
   deltaE_f.append( (reso[0] - energyNominal)/energyNominal )

   # resolution (relative error)
   relEnergyErrorVec.append( reso[1]/reso[0] )

   #
   relEnergyErrorErrorVec.append( reso[3]/reso[0] )

small=1.e-5
c1.Divide(1,2,small,small)

c1.cd(1)
gPad.SetPad(small, 0.3, 1.-small, 1.-small)
gPad.SetBottomMargin(small)

labelSize=10
makerSize = 0.3

gStyle.SetEndErrorSize(0)

gr = TGraphErrors( n, energyVec, recoEnergyVec, energyErrorVec, recoEnergyErrorVec )
gr.SetName('gr')
gr.SetLineColor( 1 )
gr.SetLineWidth( 1 )
gr.SetLineStyle( 2 )
gr.SetMarkerColor( 2 )
gr.SetMarkerStyle( 20 )
gr.SetMarkerSize( makerSize )
textsize = labelSize/(gPad.GetWh()*gPad.GetAbsHNDC())
Ejemplo n.º 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")
Ejemplo n.º 23
0
######################################################
gROOT.SetStyle("Plain")
gStyle.SetLabelSize(0.035, "xyz")

######################################################
gROOT.SetStyle("Plain")
gStyle.SetLabelSize(0.035, "xyz")
c1 = TCanvas("c_massjj", "BPRE", 10, 10, 600, 500)
c1.Divide(1, 1, 0.008, 0.007)
ps1 = TPostScript(epsfig, 113)
c1.SetGrid()

c1.cd(1)
gPad.SetLogy(0)
gPad.SetTopMargin(0.05)
gPad.SetBottomMargin(0.14)
gPad.SetLeftMargin(0.15)
gPad.SetRightMargin(0.05)

print "Read:\ndata/test.data\ndata/neuralnet.data"
data1_in, data1_out = getData("data/test.data")
data2_in, data2_out = getData("data/neuralnet.data")

xmin = -4000 - 1
xmax = 4000 - 1
bins = 100
print "Calculate histogram ranges"
data = []
for i in xrange(len(data1_in)):
    inputs1 = data1_in[i]
    output1 = data1_out[i]
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))
Ejemplo n.º 25
0
    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))
    frame.Draw()
Ejemplo n.º 26
0
            eff = reco / geant
            error = math.sqrt((eff * (1 - eff)) / geant)
            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")
Ejemplo n.º 27
0
for i in range(0, N):
    graph_MEM.SetPoint(i, mA[i], mH[i], AUC_MEM[i])
    graph_DNN.SetPoint(i, mA[i], mH[i], AUC_DNN[i])

graph_MEM.SetNpx(500)
graph_MEM.SetNpy(500)
graph_DNN.SetNpx(500)
graph_DNN.SetNpy(500)

canvas = TCanvas('c1', 'c1', 1800, 700)
canvas.Divide(2, 1, 0.005)

canvas.cd(1)
gPad.SetRightMargin(0.2)
gPad.SetLeftMargin(0.15)
gPad.SetBottomMargin(0.15)
base_hist = TH2F('', '', 500, 50, 850, 500, 200, 1000)
graph_MEM.SetHistogram(base_hist)
graph_MEM.SetMinimum(np.amin(AUC_MEM))
graph_MEM.SetMaximum(np.amax(AUC_MEM))
graph_MEM.GetHistogram().GetXaxis().SetLabelSize(0.04)
graph_MEM.GetHistogram().GetYaxis().SetLabelSize(0.04)
graph_MEM.GetHistogram().GetZaxis().SetLabelSize(0.04)
graph_MEM.GetHistogram().GetXaxis().SetTitleSize(0.06)
graph_MEM.GetHistogram().GetYaxis().SetTitleSize(0.06)
graph_MEM.GetHistogram().GetZaxis().SetTitleSize(0.06)
graph_MEM.GetHistogram().GetXaxis().SetTitleOffset(1.1)
graph_MEM.GetHistogram().GetYaxis().SetTitleOffset(1.2)
graph_MEM.GetHistogram().GetZaxis().SetTitleOffset(1.1)
graph_MEM.Draw("colz")
graph_MEM.SetTitle(
Ejemplo n.º 28
0
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()
def main(argv):

    P0DBANFFStyle = INTERFACE.GetThisStyle()
    INTERFACE.SetStyle(P0DBANFFStyle.GetName())
    OUTPUTFILENAME = "BANFFReactionCodeStacksOfficial_Joint2018_Numode_Prefit_P0DOnly_Momentum.pdf"
    inputFile = TFile(sys.argv[0])
    dataFile = TFile(sys.argv[1])
    dummyPage = TCanvas()
    dummyPage.Print(OUTPUTFILENAME + "[")
    sampleNames = [
        "P0D_Air_NuMu_CC_CC1Track", "P0D_Air_NuMu_CC_CCNTracks",
        "P0D_Water_NuMu_CC1Track", "P0D_Water_NuMu_CCNTracks"
    ]
    fileNameRoots = [
        "P0D_Air_NuMu_CC1Track", "P0D_Air_NuMu_CCNTracks",
        "P0D_Water_NuMu_CC1Track", "P0D_Water_NuMu_CCNTracks"
    ]

    stackHistos = [
        "#nu CCQE", "#nu CC 2p-2h", "#nu CC Res 1#pi", "#nu CC Coh 1#pi",
        "#nu CC Other", "#nu NC modes", "#bar{#nu} modes"
    ]

    P0DBANFFStyle.SetTitleBorderSize(0)
    P0DBANFFStyle.SetTitleX(0.02)
    P0DBANFFStyle.SetTitleY(0.95)
    P0DBANFFStyle.SetTitleW(0.3)
    P0DBANFFStyle.SetTitleH(0.07)

    # Align left, centered in y)
    P0DBANFFStyle.SetTitleAlign(11)

    stackColours = [1300, 1302, 1303, 1304, 1305, 1308, 1310]
    stackFillStyle = [1001, 1001, 1001, 1001, 1001, 1001, 1001]

    """
    The graphs will be of the form <sampleName>_rxnPredMC_<rxnCode+100>
    So for each sample, we'll loop from 0-200, and if the THnD is not NULL when we
    try and get it, add it to a list for stacking.
    for sampleName in sampleNames:
    """
    for ii in xrange(0, len(sampleNames)):
        sampleName = sampleNames[ii]

        # Total the number of events for this sample going into the histogram.
        # (Remember: Sand is excluded here.)
        mcSampleTotal = 0.0

        # Now make the set of histograms to show, which combine several interaction
        # types.
        # Load in the data histogram and use it to assemble the TH2Ds for the MC, as
        # well as making it one of the histograms on the stack.
        dataHist = dataFile.Get(sampleName + "_data").Projection(1, 0)

        dataMomProj = dataFile.Get(sampleName + "_data").Projection(
            1, 0).ProjectionX("dataratio" + sampleName + "_px", 1,
                              dataHist.GetNbinsX())
        dataMomProj.SetDirectory(0)
        dataMomProj.SetTitle("")

        prefitMomProj = inputFile.Get(sampleName + "_prefit").Projection(
            1, 0).ProjectionX("prefitratio" + sampleName + "_px", 1,
                              dataHist.GetNbinsX())
        prefitMomProj.SetDirectory(0)

        postfitMomProj = inputFile.Get(sampleName + "_postfit_0_0").Projection(
            1, 0).ProjectionX("postfitratio" + sampleName + "_px", 1,
                              dataHist.GetNbinsX())
        postfitMomProj.SetDirectory(0)

        for ibx in xrange(1, dataMomProj.GetNbinsX() + 1):
            dataMomProj.SetBinContent(
                ibx,
                dataMomProj.GetBinContent(ibx) / prefitMomProj.GetBinContent(ibx))
            dataMomProj.SetBinError(
                ibx,
                ROOT.Math.sqrt(dataMomProj.GetBinContent(ibx)) /
                prefitMomProj.GetBinContent(ibx))
            print "Data = " + str(
                dataMomProj.GetBinContent(ibx)) + "  MC = " + str(
                    prefitMomProj.GetBinContent(ibx)) + " Ratio = " + str(
                        dataMomProj.GetBinContent(ibx) /
                        prefitMomProj.GetBinContent(ibx))

        dataMomProj.GetYaxis().SetRangeUser(0.75, 1.25)
        dataMomProj.GetXaxis().SetRangeUser(MINMOMENTUM, MAXMOMENTUM)

        dataMomProj.GetXaxis().SetTitle("Reconstructed muon momentum (MeV/c)")
        dataMomProj.GetYaxis().SetTitle("Data / Sim.")

        # There is only one data plot for each stack, so:
        # Momentum projection
        # Assemble them here.
        dataOneDimPlots = []
        dataOneDimPlots.append(
            dataHist.ProjectionX("data" + sampleName + "_px", 1,
                                 dataHist.GetNbinsY()))
        dataNXBins = dataHist.GetXaxis().GetNbins()
        dataxarray = dataHist.GetXaxis().GetXbins().GetArray()

        # Now, loop through all the theta bins and add the slices in.
        for iby in xrange(1, dataHist.GetNbinsY() + 1):

            thetaLow = dataHist.GetYaxis().GetBinLowEdge(iby)
            thetaHigh = dataHist.GetYaxis().GetBinUpEdge(iby)

            thetaString = " < cos# theta < "
            thetaString = str(thetaLow) + thetaString + str(thetaHigh)
            dataOneDimPlots.append(
                TH1D("dataslice_" + sampleName + str(iby), thetaString, dataNXBins,
                     dataxarray))

            # Now, go through the x bins in this slice and fill the plot we
            # just created.
            for ibx in xrange(1, dataHist.GetNbinsX() + 1):

                # Get the bin dimensions for dividing purposes to area
                # normalize.
                dataOneDimPlots[len(dataOneDimPlots) - 1].SetBinContent(
                    ibx, dataHist.GetBinContent(ibx, iby))

        # Now that the dataOneDimPlots array is filled, loop through a area
        # normalize the bins.
        for dataOneDimHist in dataOneDimPlots:
            for ibx in xrange(1, dataOneDimHist.GetNbinsX() + 1):
                mpdim = (dataOneDimHist.GetXaxis().GetBinUpEdge(ibx) -
                         dataOneDimHist.GetXaxis().GetBinLowEdge(ibx)) / 100.0
                dataOneDimHist.SetBinError(
                    ibx,
                    math.sqrt(dataOneDimHist.GetBinContent(ibx)) / mpdim)
                dataOneDimHist.SetBinContent(
                    ibx,
                    dataOneDimHist.GetBinContent(ibx) / mpdim)

        histosToStack = []
        for histo in stackHistos:

            histosToStack.append(
                TH2D(sampleName + "_" + histo, sampleName + "_" + histo,
                     dataHist.GetXaxis().GetNbins(),
                     dataHist.GetXaxis().GetXbins().GetArray(),
                     dataHist.GetYaxis().GetNbins(),
                     dataHist.GetYaxis().GetXbins().GetArray()))

        # Now pull the histograms from the file, and add their content to the
        # relevant combined histogram.
        for i in xrange(0, 200):

            if inputFile.Get(sampleName + "_rxnPredMC_" + str(i)):

                histosToStack[CorrespondingIndex(i)].Add(
                    inputFile.Get(sampleName + "_rxnPredMC_" + str(i)).Projection(
                        1, 0))

        """
        # OK, so now we have an array of 2D histograms for this sample that we'd
        # like to stack.  Need to divide it up into individual ones.  Do Momentum
        # Projection, then momentum in theta slices.  Normalize by bin area.
        # For storing all the one dimensional plots for this sample.
        """
        oneDimPlots = []

        # Add nothing for the momentum projection, will append the thetaStrings as
        # needed.
        stackTitles = []
        for i in xrange(0, len(stackHistos)):

            # For storing all the one dimensional plots for this reaction code.
            oneDimPlotsThisReac = []
            nameBase = histosToStack[i].GetTitle()
            oneDimPlotsThisReac.append(histosToStack[i].ProjectionX(
                nameBase + "_px", 1, histosToStack[i].GetNbinsY()))

            stackTitles.append("Momentum projection")
            # Area normalize this now.
            NXBins = histosToStack[i].GetXaxis().GetNbins()

            for ibx in xrange(1, NXBins + 1):
                mpdim = (histosToStack[i].GetXaxis().GetBinUpEdge(ibx) -
                         histosToStack[i].GetXaxis().GetBinLowEdge(ibx)) / 100.0
                oneDimPlotsThisReac[0].SetBinContent(
                    ibx, oneDimPlotsThisReac[0].GetBinContent(ibx) / mpdim)

            mcSampleTotal += oneDimPlotsThisReac[0].GetSumOfWeights()
            # Now that the x bins are filled, loop on to the next histogram.

            # With all the y-slices done, oneDimPlotsThisReac is now full.  Append
            # it to oneDimPlots.
            oneDimPlots.append(oneDimPlotsThisReac)

        """"
        At this point in time, oneDimPlots has a momentum projection and theta
        slices for each reaction code grouping in this sample. So now we just need
        to make TStacks for them and print them out to PDF.
        The stack contains the plot from the same index of each entry of
        oneDimPlots.
        They should all have the same length, so use the first one to loop
        through (number of slices plus 1 full momenutm projection.)
        """
        for odi in xrange(0, len(oneDimPlots[0])):

            # For each one create a TStack
            sampleStack = THStack(
                "mpStack_" + sampleName + str(odi),
                ";Reconstructed muon momentum (MeV/c);Events/(100 MeV/c)")

            leg = TLegend(0.7, 0.15, 0.94, 0.93)
            leg.SetFillColor(0)

            # Make data the first entry.
            leg.AddEntry(dataOneDimPlots[odi], "Data", "LEP")
            dataOneDimPlots[odi].SetMarkerStyle(20)
            dataOneDimPlots[odi].SetMarkerColor(kBlack)
            dataOneDimPlots[odi].SetLineColor(kBlack)

            for odj in xrange(0, len(oneDimPlots)):

                # Apply the appropriate plot options from the beginning.
                oneDimPlots[odj][odi].SetFillColor(stackColours[odj])
                oneDimPlots[odj][odi].SetFillStyle(stackFillStyle[odj])
                oneDimPlots[odj][odi].SetMarkerStyle(1)  # Don't want P0DBANFFStyle to interfere.
                sampleStack.Add(oneDimPlots[odj][odi])
                print oneDimPlots[odj][odi].GetTitle() + " " + str(
                    oneDimPlots[odj][odi].GetSumOfWeights())

                leg.AddEntry(oneDimPlots[odj][odi], stackHistos[odj], "F")

            c1 = TCanvas()

            upperPad = TPad("upperPad", "upperPad", .05, .35, .96, .95)
            lowerPad = TPad("lowerPad", "lowerPad", .05, .1, .96, .35)

            upperPad.Draw()
            lowerPad.Draw()

            upperPad.cd()

            gPad.SetBottomMargin(1e-5)

            c1.SetTicks(1, 1)
            sampleStack.Draw("")

            dataOneDimPlots[odi].Draw("PEsame")
            sampleStack.SetMaximum(
                max(sampleStack.GetMaximum(),
                    FindPlotMax(dataOneDimPlots[odi], dataOneDimPlots[odi])))
            leg.Draw()
            sampleStack.GetXaxis().SetRangeUser(MINMOMENTUM, MAXMOMENTUM)
            sampleStack.GetXaxis().SetTitle("")
            sampleStack.GetXaxis().SetTickLength(0)
            sampleStack.GetXaxis().SetLabelSize(0)
            sampleStack.SetTitle("# nu-mode")

            lowerPad.cd()

            ROOT.gPad.SetTopMargin(1e-5)
            ROOT.gPad.SetBottomMargin(0.35)
            ROOT.gPad.SetTickx()
            dataMomProj.SetLineColor(2)
            dataMomProj.SetMarkerColor(2)
            dataMomProj.GetYaxis().SetNdivisions(8, 1)
            dataMomProj.GetYaxis().SetLabelSize(
                dataMomProj.GetYaxis().GetLabelSize() + 0.07)
            dataMomProj.GetYaxis().SetTitleSize(
                dataMomProj.GetYaxis().GetLabelSize() + 0.05)
            dataMomProj.GetYaxis().SetTitleOffset(0.335)
            dataMomProj.GetXaxis().SetLabelSize(
                dataMomProj.GetXaxis().GetLabelSize() + 0.08)
            dataMomProj.GetXaxis().SetTitleSize(
                dataMomProj.GetXaxis().GetLabelSize() + 0.04)
            dataMomProj.GetXaxis().SetTitleOffset(0.9)
            dataMomProj.GetXaxis().SetTickLength(0.04)
            dataMomProj.Draw("PE")
            line = TLine(0.0, 1.0, 5000.0, 1.0)
            line.SetLineWidth(2)
            line.SetLineColor(1)
            line.Draw("SAME")

            c1.Modified()
            c1.Update()
            c1.Print(OUTPUTFILENAME)
            outFileName = fileNameRoots[sampleNames.index(
                sampleName)] + "_mumom_rxn_postfit"
            c1.Print(outFileName + ".pdf")
            c1.Print(outFileName + ".png")
            c1.Print(outFileName + ".eps")

    dummyPage.Print(OUTPUTFILENAME + ']')
Ejemplo n.º 30
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")