Ejemplo n.º 1
0
def plot(params, rates):
    canvas = Canvas(width=500, height=500)
    draw_axes(params)
    draw_rates(params, rates)
    HGCAL_label(text='HGCAL Simulation', pad=canvas)
    canvas.SetLogy()
    canvas.RedrawAxis()
    canvas.Print('%s.png' % params.name)
    canvas.Print('%s.pdf' % params.name)
    canvas.Print('%s.C' % params.name)
Ejemplo n.º 2
0
def plot(params, efficiency):
    canvas = Canvas(width=500, height=500)
    draw_axes(params)
    draw_efficiency(params, efficiency)
    draw_lines(params)
    HGCAL_label(text='HGCAL Simulation', pad=canvas)
    draw_legends(params)
    canvas.RedrawAxis()
    canvas.Print('%s.png' % params.name)
    canvas.Print('%s.pdf' % params.name)
    canvas.Print('%s.C' % params.name)
    return canvas
Ejemplo n.º 3
0
def main(args):

    fileName = '/data/nawoods/lepsForSIP/lepsForSIP_M2500.root'

    checker = MuonCandMatchChecker('Check PF cand matching', [fileName])

    checker.processSample()

    h = checker.hists['pfCandPt']

    h.Sumw2()
    h.drawstyle = 'HIST'
    h.legendstyle = 'L'
    h.linewidth = 2
    h.color = 'red'

    c = Canvas(1000, 1000)
    (xax, yax), lims = draw(
        h,
        c,
        ytitle='PF Cands',
        xtitle='PF Cand p_T',
    )
    xax.SetTitleSize(0.4 * xax.GetTitleSize())
    xax.SetTitleOffset(1.6)
    xax.SetLabelSize(0.7 * xax.GetLabelSize())
    c.Print('/afs/cern.ch/user/n/nawoods/www/ptStudy/matchedCandPt.png')

    h2 = checker.hists['pfCandPtVsGenPt']
    c2 = Canvas(1000, 1000)
    h2.xaxis.SetTitleOffset(1.8)
    h2.yaxis.SetTitleOffset(1.7)
    h2.xaxis.SetTitleSize(0.5 * h2.xaxis.GetTitleSize())
    h2.yaxis.SetTitleSize(0.5 * h2.yaxis.GetTitleSize())
    h2.xaxis.SetLabelSize(0.6 * h2.xaxis.GetLabelSize())
    h2.yaxis.SetLabelSize(0.6 * h2.yaxis.GetLabelSize())
    h2.xaxis.SetTitle("Gen #mu p_{T}")
    h2.yaxis.SetTitle("PF cand p_{T}")
    h2.Draw("COLZ")
    c2.Print(
        '/afs/cern.ch/user/n/nawoods/www/ptStudy/matchedCandPtVsGenPt.png')

    print "Out of {} good muons, {} failed PF ID ({}%).".format(
        checker.nTot, checker.nFailPF,
        100. * float(checker.nFailPF) / checker.nTot)
    print(
        "Out of those failing PF, {} shared a track with a PF charged hadron "
        "({}%, {}% of the total)").format(
            checker.nPFMatched, 100. * checker.nPFMatched / checker.nFailPF,
            100. * checker.nPFMatched / checker.nTot)
Ejemplo n.º 4
0
def plotSummary(name, closure, xmin=0, xmax=1, xTitle='m_{vis} [GeV]'):
    histoSmoothRatios = []
    for hname, graph in closure.data['True/Est'].items():
        if 'Histo' in hname and 'Smooth' in hname and not 'Error' in hname:
            histoSmoothRatios.append(graph)
    ################ Plot ratios
    histoDummyRatio = Hist(1, xmin, xmax, type='F')
    values = []
    for ratio in histoSmoothRatios:
        for p in xrange(ratio.GetN()):
            values.append(ratio.GetY()[p])
    maxi = max(values)
    mini = min(values)
    maxi = maxi * 1.1 if maxi > 0 else maxi * 0.9
    mini = mini * 1.1 if mini < 0 else mini * 0.9
    histoDummyRatio.SetAxisRange(mini, maxi, 'Y')
    ##
    for ratio in histoSmoothRatios:
        ratio.SetLineColor(ROOT.kGray + 3)
        ratio.SetLineWidth(1)
    ##
    canvasRatio = Canvas(800, 800)
    canvasRatio.SetName('Ratio_Summary_Canvas')
    histoDummyRatio.SetXTitle(xTitle)
    histoDummyRatio.SetYTitle('Ratio')
    histoDummyRatio.Draw()
    for ratio in histoSmoothRatios:
        ratio.Draw('l same')
    canvasRatio.Print(
        'results/{NAME}_NonClosure_Ratio_Summary.png'.format(NAME=name))
Ejemplo n.º 5
0
def plot_comparisons(input_file, comparison_plots):
  with root_open(input_file) as file:
    for name,histo_config in comparison_plots.items():
      canvas = Canvas(1200,700)
      canvas.SetLeftMargin(0.08)
      canvas.SetRightMargin(0.12)
      histogram = file.Get(histo_config.name)
      if len(histo_config.range)==2:
        histogram.SetAxisRange(histo_config.range[0], histo_config.range[1], 'X')
      histogram.color = histo_config.color
      histogram.markerstyle = histo_config.marker
      histogram.Draw()
      canvas.Print('./plots/{}.png'.format(name))
Ejemplo n.º 6
0
def plot_event(name, canvas):
  primitives = canvas.GetListOfPrimitives()
  histo = None
  point = None
  for primitive in primitives:
    if primitive.InheritsFrom(TH2Poly.Class()):
      histo = primitive
    if primitive.InheritsFrom(TMarker.Class()):
      point = primitive
  histo.SetXTitle('x [cm]')
  histo.SetYTitle('y [cm]')
  canvas_new = Canvas(700, 700)
  histo.SetAxisRange(77,100,'X')
  histo.Draw('colz')
  point.Draw()
  canvas_new.SetLogz()
  canvas_new.Print('./plots/event_{}.png'.format(name))
Ejemplo n.º 7
0
def plot_distributions(input_file, distribution_plots):
  with root_open(input_file) as file:
    for name,histo_configs in distribution_plots.items():
      canvas = Canvas(700,700)
      legend = Legend(len(histo_configs), leftmargin=0.4, margin=0.3)
      histograms = []
      for histo_config in histo_configs:
        histogram = file.Get(histo_config.name)
        if len(histo_config.range)==2:
          histogram.SetAxisRange(histo_config.range[0], histo_config.range[1], 'X')
        histogram.color = histo_config.color
        histogram.markerstyle = histo_config.marker
        legend.AddEntry(histogram, label=histo_config.legend, style='ep')
        histograms.append(histogram)
      xmin, xmax, ymin, ymax = get_limits(histograms, logy=False)
      option = ''
      for histogram in histograms:
        histogram.SetAxisRange(ymin,ymax,'Y')
        histogram.Draw(option)
        option += ' same'
      legend.Draw()
      canvas.Print('plots/{}.png'.format(name))
Ejemplo n.º 8
0
                        histname.yaxis.SetTitle(title)
                        histname.xaxis.set_label_size(20)
                        histname.yaxis.set_label_size(20)
                        histname.zaxis.set_title_size(20)
                        histname.zaxis.set_label_size(10)
                        histname.set_title_size(20)
                        label = ROOT.TLatex(.17, .97,
                                            signalprocess + signaljets)
                        label.SetTextFont(43)
                        label.SetTextSize(18)
                        label.SetNDC()
                        label.Draw()
                        canvas.Modified()
                        canvas.Update()
                        canvas.Print(outputfolder + "/" + xvariable + "_" +
                                     variable + "_" + background_name +
                                     "_2D_2L.png")

for (rootfile, data_weight, data_legend,
     data_bool) in zip(data_list, data_weight_list, data_legend_list,
                       data_bool_list):
    if data_bool == "Plot":
        data = root_open(data_location + "/" + rootfile)
        compressed = data.CompressedAnalysis
        for (variable, min, max, nbins, title, ytitle,
             yplot) in zip(variable_list, min_list, max_list, nbins_list,
                           title_list, ytitle_list, yplot_list):
            if yplot == "Plot":
                print variable + " " + min + " " + max + " " + nbins + " " + title + " " + ytitle
                for (xvariable, xmin, xmax, xnbins, xtitle, xytitle,
                     xplot) in zip(xvariable_list, xmin_list, xmax_list,
Ejemplo n.º 9
0
    #pad2.Draw()
    #pad2.cd()
    #pad2.SetGrid()

    #    dataobject.SetMinimum(0.0001)
    #    dataobject.SetMaximum(2)
    #    dataobject.xaxis.SetTextSize(10)

    #    dataobject.xaxis.SetTitle(xtitle)
    #    dataobject.yaxis.SetTitle("Data/MC")

    #    dataobject.yaxis.divisions = 5

    #    dataobject.Divide(sum(stack))
    ##    dataobject.xaxis.getTitle().Center()
    #    dataobject.xaxis.set_label_size(25)
    #    dataobject.yaxis.set_label_size(25)

    #    object.SetLineColor("black")
    #    dataobject.SetLineWidth(0)
    #    dataobject.drawstyle = "hist"
    #    dataobject.SetLineStyle(linestyle)
    #    dataobject.SetFillColor("goldenrod")
    #dataobject.set
    #    dataobject.Draw()

    #pad2.Modified()
    #pad2.Update()

    canvas.Print(outputfolder + "/" + variable + "_3L.png")
def plotDataMC(name, closureData, closureMC, bins, xTitle='m_{vis} [GeV]'):
    binid = hash(str(bins))
    #
    histoRatioData = closureData.data['True/Est']['Histo_{H}'.format(H=binid)]
    histoSmoothRatioData = closureData.data['True/Est'][
        'Histo_{H}_Smooth'.format(H=binid)]
    histoSmoothRatioErrorData = closureData.data['True/Est'][
        'Histo_{H}_SmoothError'.format(H=binid)]
    histoRatioMC = closureMC.data['True/Est']['Histo_{H}'.format(H=binid)]
    histoSmoothRatioMC = closureMC.data['True/Est']['Histo_{H}_Smooth'.format(
        H=binid)]
    histoSmoothRatioErrorMC = closureMC.data['True/Est'][
        'Histo_{H}_SmoothError'.format(H=binid)]
    #
    ################ Plot ratios
    histoDummyRatio = Hist(1, bins[0], bins[-1], type='F')
    values = []
    values.append(histoRatioData.GetMaximum())
    values.append(histoRatioData.GetMinimum())
    values.append(histoRatioMC.GetMaximum())
    values.append(histoRatioMC.GetMinimum())
    maxi = max(values)
    mini = min(values)
    maxi = maxi * 1.1 if maxi > 0 else maxi * 0.9
    mini = mini * 1.1 if mini < 0 else mini * 0.9
    histoDummyRatio.SetAxisRange(mini, maxi, 'Y')
    ##
    histoRatioData.SetMarkerColor(ROOT.kBlack)
    histoSmoothRatioData.SetLineColor(ROOT.kGray + 3)
    histoSmoothRatioData.SetLineWidth(2)
    histoSmoothRatioErrorData.SetLineColor(ROOT.kGray + 1)
    histoSmoothRatioErrorData.SetFillColor(ROOT.kGray + 1)
    ##
    histoRatioMC.SetMarkerColor(ROOT.kRed)
    histoRatioMC.SetMarkerStyle(21)
    histoSmoothRatioMC.SetLineColor(ROOT.kRed)
    histoSmoothRatioMC.SetLineWidth(2)
    histoSmoothRatioErrorMC.SetLineColor(ROOT.kRed - 7)
    #histoSmoothRatioErrorMC.SetFillColorAlpha(ROOT.kRed-7, 0.35)
    histoSmoothRatioErrorMC.SetFillStyle(3344)
    histoSmoothRatioErrorMC.SetFillColor(ROOT.kRed - 7)
    ##
    canvasRatio = Canvas(800, 800)
    canvasRatio.SetName('{NAME}_Ratio_Canvas'.format(NAME=name))
    histoDummyRatio.SetXTitle(xTitle)
    histoDummyRatio.SetYTitle('Ratio')
    histoDummyRatio.Draw()
    histoSmoothRatioErrorData.Draw('fl same')
    histoSmoothRatioData.Draw('pl same')
    histoSmoothRatioErrorMC.Draw('fl same')
    histoSmoothRatioMC.Draw('pl same')
    histoRatioData.Draw('E1 same')
    histoRatioMC.Draw('E1 same')
    #
    legend = ROOT.TLegend(0.15, 0.75, 0.45, 0.9)
    legend.SetFillColor(0)
    legend.SetLineColor(0)
    legend.AddEntry(histoRatioMC, 'MC', 'lp')
    legend.AddEntry(histoRatioData, 'Data', 'lp')
    legend.Draw()
    canvasRatio.Print('results/{NAME}_NonClosure_Ratio.png'.format(NAME=name))
Ejemplo n.º 11
0
    histpad.cd()
    drawXandYlabels(stack,histRatio,xlabel,ylabel,defaultlabelsize,ratiopad,histpad,doRatio,labelmargin)
    drawPlotInformation(DataPeriods,atlasStatus,RegionLabel,histpad,defaultlabelsize,labelmargin,donminus1)
    drawTopLeftInformation(Region,CRlist,VVCRlist,TOPCRlist,ABCDlist,donminus1,backgroundstacks,datastack,defaultlabelsize,labelmargin)


    drawDataLegend(datastack,stack,plotData,BLINDEDLIST,defaultlabelsize,Region)
    drawBackgroundLegend(backgroundstacks,stack,LegendExtraInformation,defaultlabelsize,Region) 

   
    dataoutputfolder = os.path.join(outputfolder,"Data" + DataPeriods )

    os.system("mkdir -p " +	dataoutputfolder  )
    os.system("mkdir -p " + os.path.join(dataoutputfolder,Region) )
    os.system("mkdir -p " + os.path.join(dataoutputfolder,Region,"N-1") )


    filenamevariable = variable.replace("/","_").replace("_1000","")
    if donminus1:
        canvas.Print(dataoutputfolder + "/" + Region + "/N-1/log_"+ filenamevariable+ "_" + Region + "_"+systematics+".png")
    else:
        canvas.Print(dataoutputfolder + "/" + Region + "/log_"+ filenamevariable+ "_" + Region + "_"+systematics+".png")

    histpad.SetLogy(0)
    stack.SetMinimum(0.0)
    stack.SetMaximum(3*stack.sum.GetMaximum())

    canvas.Print(dataoutputfolder + "/" + Region + "/lin_"+ filenamevariable+ "_" + Region + "_"+systematics+".png")

    print "[CANVAS][PLOTTED]" + str(round(time.time() - t0,0)) + "seconds"
Ejemplo n.º 12
0
    #pad2.Draw()
    #pad2.cd()
    #pad2.SetGrid()

    #    dataobject.SetMinimum(0.0001)
    #    dataobject.SetMaximum(2)
    #    dataobject.xaxis.SetTextSize(10)

    #    dataobject.xaxis.SetTitle(xtitle)
    #    dataobject.yaxis.SetTitle("Data/MC")

    #    dataobject.yaxis.divisions = 5

    #    dataobject.Divide(sum(stack))
    ##    dataobject.xaxis.getTitle().Center()
    #    dataobject.xaxis.set_label_size(25)
    #    dataobject.yaxis.set_label_size(25)

    #    object.SetLineColor("black")
    #    dataobject.SetLineWidth(0)
    #    dataobject.drawstyle = "hist"
    #    dataobject.SetLineStyle(linestyle)
    #    dataobject.SetFillColor("goldenrod")
    #dataobject.set
    #    dataobject.Draw()

    #pad2.Modified()
    #pad2.Update()

    canvas.Print(outputfolder + "/" + variable + "_2LNJ_SRZ.png")
Ejemplo n.º 13
0
def plotClosure(name,
                closure,
                bins,
                smoothWidth=0.1,
                kernelDistance='Adapt',
                doErrors=False,
                xTitle='m_{vis} [GeV]'):
    binid = hash(str(bins))
    closure.computeHisto('True', bins)
    closure.computeHisto('Est', bins)
    closure.computeRatio('Est', 'True', 'Histo_{H}'.format(H=binid),
                         smoothWidth, kernelDistance, doErrors)
    #
    histoTrue = closure.data['True']['Histo_{H}'.format(H=binid)]
    histoEst = closure.data['Est']['Histo_{H}'.format(H=binid)]
    histoRatio = closure.data['True/Est']['Histo_{H}'.format(H=binid)]
    histoSmoothRatio = closure.data['True/Est']['Histo_{H}_Smooth'.format(
        H=binid)]
    histoSmoothRatioError = closure.data['True/Est'][
        'Histo_{H}_SmoothError'.format(H=binid)]
    #
    ############ plot raw distributions
    histoDummy = Hist(1, bins[0], bins[-1], type='F')
    values = []
    values.append(histoTrue.GetMaximum())
    values.append(histoTrue.GetMinimum())
    values.append(histoEst.GetMaximum())
    values.append(histoEst.GetMinimum())
    maxi = max(values) * 1.1
    mini = min(values)
    histoDummy.SetAxisRange(mini, maxi, 'Y')
    ##
    histoTrue.SetMarkerColor(ROOT.kBlack)
    histoEst.SetMarkerStyle(24)
    histoEst.SetMarkerColor(ROOT.kGray + 3)
    ##
    canvas = Canvas(800, 800)
    canvas.SetName('{NAME}_Canvas'.format(NAME=name))
    histoDummy.SetXTitle(xTitle)
    histoDummy.SetYTitle('Events')
    histoDummy.Draw()
    histoTrue.Draw('same')
    histoEst.Draw('same')
    legend = ROOT.TLegend(0.4, 0.7, 0.9, 0.9)
    legend.SetFillColor(0)
    legend.SetLineColor(0)
    legend.AddEntry(histoTrue, 'True background', 'lp')
    legend.AddEntry(histoEst, 'Estimated background', 'lp')
    legend.Draw()
    canvas.Print('results/{NAME}_NonClosure.png'.format(NAME=name))

    ################ Plot ratios
    histoDummyRatio = Hist(1, bins[0], bins[-1], type='F')
    values = []
    values.append(histoRatio.GetMaximum())
    values.append(histoRatio.GetMinimum())
    maxi = max(values)
    mini = min(values)
    maxi = maxi * 1.1 if maxi > 0 else maxi * 0.9
    mini = mini * 1.1 if mini < 0 else mini * 0.9
    histoDummyRatio.SetAxisRange(mini, maxi, 'Y')
    ##
    histoRatio.SetMarkerColor(ROOT.kBlack)
    histoSmoothRatio.SetLineColor(ROOT.kGray + 3)
    histoSmoothRatio.SetLineWidth(2)
    histoSmoothRatioError.SetLineColor(ROOT.kGray + 1)
    histoSmoothRatioError.SetFillColor(ROOT.kGray + 1)
    ##
    canvasRatio = Canvas(800, 800)
    canvasRatio.SetName('{NAME}_Ratio_Canvas'.format(NAME=name))
    histoDummyRatio.SetXTitle(xTitle)
    histoDummyRatio.SetYTitle('Ratio')
    histoDummyRatio.Draw()
    histoSmoothRatioError.Draw('fl same')
    histoSmoothRatio.Draw('pl same')
    histoRatio.Draw('same')
    canvasRatio.Print('results/{NAME}_NonClosure_Ratio.png'.format(NAME=name))
Ejemplo n.º 14
0
                    histogram2D.yaxis.SetTitle(xtitle2)
                    histogram2D.yaxis.SetTitleOffset(1.5)
                    histogram2D.yaxis.set_label_size(
                        int(canvasheight * labelscale * 1.5))
                    #canvas.cd()
                    canvas.Update()
                    canvas.Modified()

                    #os.system("mkdir -p " +	dataoutputfolder  )
                    dataoutputfolder = os.path.join(outputfolder,
                                                    "Data" + DataPeriods,
                                                    Region)
                    os.system("mkdir -p " + dataoutputfolder)
                    canvas.Print(dataoutputfolder + "/log_" +
                                 variable.replace("/", "_") + "_" +
                                 variable2.replace("/", "_") + "_" + Region +
                                 "_" + systematics + ".png")

                #backgroundstacks[LegendEntry].Add(temphist.Clone())

        #plotzjets(hist)

    #  skimmed = 1

    # stack.yaxis.SetTitle(ytitle)
    # stack.yaxis.SetTitleOffset(2)
    # stack.yaxis.set_label_size(int(canvasheight*labelscale*1.5))

    # canvas.cd()

    #dataoutputfolder = os.path.join(outputfolder,"Data" + DataPeriods )
Ejemplo n.º 15
0
                 xytitle) in zip(xvariable_list, xmin_list, xmax_list,
                                 xnbins_list, xtitle_list, xytitle_list):

                # Canvas Variables and declaration
                print xvariable + " " + xmin + " " + xmax + " " + xnbins + " " + xtitle + " " + xytitle
                canvas = Canvas(width=700, height=500)

                #    pad.SetTopMargin(0.2)
                canvas.Draw()

                #canvas.SetLogy()
                canvas.SetGrid()

                histname = "hist" + variable + "_" + xvariable + background_name
                print histname
                histogram = histname + "(" + xnbins + "," + xmin + "," + xmax + "," + nbins + "," + min + "," + max + ")"
                print histogram
                histname = compressed.Draw(xvariable + ":" + variable + ">>" +
                                           histogram,
                                           selection=total & weight,
                                           drawstyle='COLZ')
                histname.SetTitle(background_name)
                #histname.zaxis.SetTitle(
                histname.xaxis.SetTitle(xtitle)
                histname.yaxis.SetTitle(title)
                histname.xaxis.set_label_size(15)
                histname.yaxis.set_label_size(20)
                canvas.Update()
                canvas.Print(outputfolder + "/" + xvariable + "_" + variable +
                             background_name + "2L.png")
Ejemplo n.º 16
0
def main(args):

    fileName = '/data/nawoods/lepsForSIP/lepsForSIP_M2500.root'

    checker = MuonPtMatchChecker('Check Pt', [fileName])

    checker.processSample()
    
    hs = checker.hists.copy()

    for var, h in hs.iteritems():

        h.Sumw2()
        h.drawstyle = 'HIST'
        h.legendstyle = 'L'
        h.linewidth = 2
        h.color = 'red'

    cRes = Canvas(1000,1000)
    hs['pfPtRes'].color = 'black'
    hs['pfPtRes'].title = 'PF'
    hs['tunePPtResUncor'].title = 'Tune P'

    (xax,yax), lims = draw([hs['pfPtRes'], hs['tunePPtResUncor']], cRes, 
                           xtitle='#frac{reco p_T - gen p_T}{gen p_T}', 
                           ytitle='Muons')
    xax.SetTitleSize(0.4 * xax.GetTitleSize())
    xax.SetTitleOffset(1.6)
    xax.SetLabelSize(0.7 * xax.GetLabelSize())
    legRes = Legend([hs['pfPtRes'], hs['tunePPtResUncor']], cRes)
    legRes.Draw("same")
    cRes.Print('/afs/cern.ch/user/n/nawoods/www/ptStudy/ptRes.png')

    cResComp = Canvas(1000,1000)
    (xax,yax), lims = draw(hs['resCompare'], cResComp, ytitle='Muons',
                           xtitle='#frac{|PF p_T - gen p_T|}{gen p_T} - #frac{|tuneP p_T - gen p_T|}{gen p_T}')
    xax.SetTitleSize(0.4 * xax.GetTitleSize())
    xax.SetTitleOffset(1.6)
    xax.SetLabelSize(0.7 * xax.GetLabelSize())
    cResComp.Print('/afs/cern.ch/user/n/nawoods/www/ptStudy/ptResComp.png')
    
    
    cResCor = Canvas(1000,1000)
    hs['pfPtRes'].color = 'black'
    hs['pfPtRes'].title = 'PF'
    hs['tunePPtRes'].title = 'Tune P'

    (xax,yax), lims = draw([hs['pfPtRes'], hs['tunePPtRes']], cResCor, 
                           xtitle='#frac{reco p_T - gen p_T}{gen p_T}', 
                           ytitle='Muons')
    xax.SetTitleSize(0.4 * xax.GetTitleSize())
    xax.SetTitleOffset(1.6)
    xax.SetLabelSize(0.7 * xax.GetLabelSize())
    legResCor = Legend([hs['pfPtRes'], hs['tunePPtRes']], cResCor)
    legResCor.Draw("same")
    cResCor.Print('/afs/cern.ch/user/n/nawoods/www/ptStudy/ptResCor.png')

    cResCompCor = Canvas(1000,1000)
    (xax,yax), lims = draw(hs['resCompareBothCor'], cResCompCor, ytitle='Muons',
                           xtitle='#frac{|PF p_T - gen p_T|}{gen p_T} - #frac{|tuneP p_T - gen p_T|}{gen p_T}')
    xax.SetTitleSize(0.4 * xax.GetTitleSize())
    xax.SetTitleOffset(1.6)
    xax.SetLabelSize(0.7 * xax.GetLabelSize())
    cResCompCor.Print('/afs/cern.ch/user/n/nawoods/www/ptStudy/ptResCompCor.png')
    
    
    cResUncor = Canvas(1000,1000)
    hs['pfPtResUncor'].color = 'black'
    hs['pfPtResUncor'].title = 'PF'
    hs['tunePPtResUncor'].title = 'Tune P'

    (xax,yax), lims = draw([hs['pfPtResUncor'], hs['tunePPtResUncor']], cResUncor, 
                           xtitle='#frac{reco p_T - gen p_T}{gen p_T}', 
                           ytitle='Muons')
    xax.SetTitleSize(0.4 * xax.GetTitleSize())
    xax.SetTitleOffset(1.6)
    xax.SetLabelSize(0.7 * xax.GetLabelSize())
    legResUncor = Legend([hs['pfPtResUncor'], hs['tunePPtResUncor']], cResUncor)
    legResUncor.Draw("same")
    cResUncor.Print('/afs/cern.ch/user/n/nawoods/www/ptStudy/ptResUncor.png')

    cResCompUncor = Canvas(1000,1000)
    (xax,yax), lims = draw(hs['resCompareUncor'], cResCompUncor, ytitle='Muons',
                           xtitle='#frac{|PF p_T - gen p_T|}{gen p_T} - #frac{|tuneP p_T - gen p_T|}{gen p_T}')
    xax.SetTitleSize(0.4 * xax.GetTitleSize())
    xax.SetTitleOffset(1.6)
    xax.SetLabelSize(0.7 * xax.GetLabelSize())
    cResCompUncor.Print('/afs/cern.ch/user/n/nawoods/www/ptStudy/ptResCompUncor.png')
    
    
    hs2 = checker.hists2D.copy()

    hs2['pfPtResVsPt'].yaxis.title = '#frac{PF p_T - gen p_T}{gen p_T}'
    hs2['tunePPtResVsPt'].yaxis.title = '#frac{tuneP p_T - gen p_T}{gen p_T}'
    hs2['pfPtResVsPt'].yaxis.title = '#frac{|PF p_T - gen p_T|}{gen p_T} - #frac{|tuneP p_T - gen p_T|}{gen p_T}'

    for var, h in hs2.iteritems():
        c = Canvas(1000,1000)
        h.xaxis.title = 'gen p_T'
        h.drawstyle = 'COLZ'
        h.xaxis.SetTitleSize(0.5 * h.xaxis.GetTitleSize())
        h.xaxis.SetLabelSize(0.7 * h.xaxis.GetLabelSize())
        h.xaxis.SetTitleOffset(1.4)
        h.yaxis.SetTitleSize(0.5 * h.yaxis.GetTitleSize())
        h.yaxis.SetLabelSize(0.7 * h.yaxis.GetLabelSize())
        h.yaxis.SetTitleOffset(1.4)
        h.draw()
        c.Print('/afs/cern.ch/user/n/nawoods/www/ptStudy/{}.png'.format(var))
Ejemplo n.º 17
0
    # randomly choose starting bin
    start = randint(1, h.nbins(axis) - 1)
    end = randint(start + 1, min(start + 5 * h.GetDimension(), h.nbins(axis)))
    return h.merge_bins([(start, end)], axis=axis)

# create an animation of a 1D histogram
c1 = Canvas()
if not BATCH and os.path.isfile('binmerge1d.gif'):
    os.unlink('binmerge1d.gif')
a = Hist(100, -5, 5)
a.fill_array(np.random.randn(10000))
while a.nbins(0) > 1:
    a = random_bin_merge(a)
    a.Draw('hist')
    if not BATCH:
        c1.Print('binmerge1d.gif+20')
        time.sleep(.1)
if not BATCH:
    c1.Print('binmerge1d.gif++')

# create an animation of a 2D histogram
c2 = Canvas()
if not BATCH and os.path.isfile('binmerge2d.gif'):
    os.unlink('binmerge2d.gif')
c2.SetRightMargin(0.1)
b = Hist2D(100, -5, 5, 100, -5, 5)
b.fill_array(np.random.randn(10000, 2))
while b.nbins(0) > 1 or b.nbins(1) > 1:
    b = random_bin_merge(b)
    b.Draw('LEGO20')
    if not BATCH:
Ejemplo n.º 18
0
def main(args):

    fileList = glob('/data/nawoods/lepsForSIP/*.root')
    files = {int(f.split('_M')[1].split('.')[0]) : f for f in fileList}

    checkers = {m : MuonSIPChecker('m={}'.format(m), [f]) for m,f in files.iteritems()}
    sipRMS = Graph(len(fileList), type='errors')
    sipHists = []
    dxyRMS = Graph(len(fileList), type='errors')
    dxyHists = []
    dzRMS = Graph(len(fileList), type='errors')
    dzHists = []

    ipHists = []
    ipErrHists = []

    fracFailing = Graph(len(fileList), type='errors')
    for i, m in enumerate(sorted(files.keys())):

        checkers[m].processSample()

        checkers[m].hists['sip'].Sumw2()
        sipRMS.SetPoint(i, float(m), checkers[m].hists['sip'].GetRMS())
        sipRMS.SetPointError(i, 0., checkers[m].hists['sip'].GetRMSError())
        sipHists.append(checkers[m].hists['sip'])
        sipHists[-1].color = getColor(m)
        sipHists[-1].title = "m_{{H}} = {}".format(m)
        sipHists[-1].drawstyle = 'hist'
        sipHists[-1].legendstyle = 'L'
        sipHists[-1].linewidth = 2
        sipHists[-1].scale(1./sipHists[-1].integral())

        ipHists.append(checkers[m].hists['ip'])
        ipHists[-1].color = getColor(m)
        ipHists[-1].title = "m_{{H}} = {}".format(m)
        ipHists[-1].drawstyle = 'hist'
        ipHists[-1].legendstyle = 'L'
        ipHists[-1].linewidth = 2
        ipHists[-1].scale(1./ipHists[-1].integral())

        ipErrHists.append(checkers[m].hists['ipErr'])
        ipErrHists[-1].color = getColor(m)
        ipErrHists[-1].title = "m_{{H}} = {}".format(m)
        ipErrHists[-1].drawstyle = 'hist'
        ipErrHists[-1].legendstyle = 'L'
        ipErrHists[-1].linewidth = 2
        ipErrHists[-1].scale(1./ipErrHists[-1].integral())

        checkers[m].hists['dxy'].Sumw2()
        dxyRMS.SetPoint(i, float(m), checkers[m].hists['dxy'].GetRMS())
        dxyRMS.SetPointError(i, 0., checkers[m].hists['dxy'].GetRMSError())
        dxyHists.append(checkers[m].hists['dxy'])
        dxyHists[-1].color = getColor(m)
        dxyHists[-1].title = "m_{{H}} = {}".format(m)
        dxyHists[-1].drawstyle = 'hist'
        dxyHists[-1].legendstyle = 'L'
        dxyHists[-1].linewidth = 2
        dxyHists[-1].scale(1./dxyHists[-1].integral())
        
        checkers[m].hists['dz'].Sumw2()
        dzRMS.SetPoint(i, float(m), checkers[m].hists['dz'].GetRMS())
        dzRMS.SetPointError(i, 0., checkers[m].hists['dz'].GetRMSError())
        dzHists.append(checkers[m].hists['dz'])
        dzHists[-1].color = getColor(m)
        dzHists[-1].title = "m_{{H}} = {}".format(m)
        dzHists[-1].drawstyle = 'hist'
        dzHists[-1].legendstyle = 'L'
        dzHists[-1].linewidth = 2
        dzHists[-1].scale(1./dzHists[-1].integral())

        fracFailing.SetPoint(i, float(m),
                             1. - float(checkers[m].nPassSIP) / checkers[m].nTot)

    
    cSIP = Canvas(1000,1000)
    draw(sipHists, cSIP, xtitle='#frac{IP_{3D}}{#sigma_{IP_{3D}}}',
         ytitle='arb.')
    legSIP = Legend(sipHists, cSIP, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legSIP.Draw("same")
    cSIP.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/sips.png')
    cSIPLog = Canvas(1000,1000)
    draw(sipHists, cSIPLog, xtitle='#frac{IP_{3D}}{#sigma_{IP_{3D}}}',
         ytitle='arb.', logy=True)
    legSIPLog = Legend(sipHists, cSIPLog, textsize=.027, entrysep=0.012, leftmargin=0.6, entryheight=0.03)
    legSIPLog.Draw("same")
    cSIPLog.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/sipsLog.png')
    
    cSIPRMS = Canvas(1000, 1000)
    sipRMS.color = 'b'
    sipRMS.drawstyle = 'PE'
    sipRMS.legendstyle = 'PE'
    draw(sipRMS, cSIPRMS, xtitle="m_{H}", ytitle="RMS(SIP_{3D})", xlimits=(0.,2600.))
    cSIPRMS.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/sipRMS.png')
    
    cIP = Canvas(1000,1000)
    draw(ipHists, cIP, xtitle='IP_{3D}',
         ytitle='arb.')
    legIP = Legend(ipHists, cIP, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legIP.Draw("same")
    cIP.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/ips.png')
    cIPLog = Canvas(1000,1000)
    draw(ipHists, cIPLog, xtitle='#frac{IP_{3D}}{#sigma_{IP_{3D}}}',
         ytitle='arb.', logy=True)
    legIPLog = Legend(ipHists, cIPLog, textsize=.027, entrysep=0.012, leftmargin=0.6, entryheight=0.03)
    legIPLog.Draw("same")
    cIPLog.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/ipsLog.png')
    
    cIPErr = Canvas(1000,1000)
    draw(ipErrHists, cIPErr, xtitle='#sigma_{IP_{3D}}',
         ytitle='arb.')
    legIPErr = Legend(ipErrHists, cIPErr, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legIPErr.Draw("same")
    cIPErr.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/ipErrs.png')
    cIPErrLog = Canvas(1000,1000)
    draw(ipErrHists, cIPErrLog, xtitle='#sigma_{IP_{3D}}',
         ytitle='arb.', logy=True)
    legIPErrLog = Legend(ipErrHists, cIPErrLog, textsize=.027, entrysep=0.012, leftmargin=0.6, entryheight=0.03)
    legIPErrLog.Draw("same")
    cIPErrLog.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/ipErrsLog.png')
    
    cFail = Canvas(1000, 1000)
    fracFailing.color = 'b'
    fracFailing.drawstyle = 'PE'
    fracFailing.legendstyle = 'PE'
    draw(fracFailing, cSIPRMS, xtitle="m_{H}", ytitle="Fraction failing SIP", xlimits=(0.,2600.))
    cSIPRMS.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/fracFailing.png')
    
    cDXY = Canvas(1000,1000)
    draw(dxyHists, cDXY, xtitle='#Delta_{xy}',
         ytitle='arb.')
    legDXY = Legend(dxyHists, cDXY, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legDXY.Draw("same")
    cDXY.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/dxys.png')

    cDXYRMS = Canvas(1000, 1000)
    dxyRMS.color = 'b'
    dxyRMS.drawstyle = 'PE'
    dxyRMS.legendstyle = 'PE'
    draw(dxyRMS, cDXYRMS, xtitle="m_{H}", ytitle="RMS(#Delta_{xy})", xlimits=(0.,2600.))
    cDXYRMS.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/dxyRMS.png')
    
    cDZ = Canvas(1000,1000)
    draw(dzHists, cDZ, xtitle='#Delta_{z}',
         ytitle='arb.')
    legDZ = Legend(dzHists, cDZ, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legDZ.Draw("same")
    cDZ.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/dzs.png')

    cDZRMS = Canvas(1000, 1000)
    dzRMS.color = 'b'
    dzRMS.drawstyle = 'PE'
    dzRMS.legendstyle = 'PE'
    draw(dzRMS, cDZRMS, xtitle="m_{H}", ytitle="RMS(#Delta_{z})", xlimits=(0.,2600.))
    cDZRMS.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/dzRMS.png')
Ejemplo n.º 19
0
    sys.stdout.flush()
    # resample with replacement
    # http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.random.choice.html
    sample_idx = np.random.choice(len(array), size=len(array), replace=True)
    array_bootstrapped = array[sample_idx]
    # convert back to a TTree and write it out
    tree_bootstrapped = array2tree(
        array_bootstrapped,
        name='bootstrap_{0}'.format(bootstrap_idx))
    tree_bootstrapped.Write()
    tree_bootstrapped.Delete()
    # fill the ROOT histogram with the numpy array
    hist.Reset()
    fill_hist(hist, rec2array(array_bootstrapped))
    hist.Draw()
    hist.xaxis.title = 'x'
    hist.yaxis.title = 'y'
    hist.zaxis.title = 'Events'
    hist.xaxis.limits = (-2.5, 2.5)
    hist.yaxis.limits = (-2.5, 2.5)
    hist.zaxis.range_user = (0, 60)
    hist.xaxis.divisions = 5
    hist.yaxis.divisions = 5
    hist.zaxis.divisions = 5
    canvas.Print('bootstrap.gif+50')

# loop the gif
canvas.Print('bootstrap.gif++')
output.Close()
print
Ejemplo n.º 20
0
stackError.fillcolor = 'black'
stackError.drawstyle = '2'
# stack.Draw('HIST')
# stackError.Draw('2 [] same')
objects.append(stackError)

import ROOT

from FireROOT.Analysis.Utils import *

ROOT.gPad.SetLogy(True)
draw(objects,
     xtitle='Some Variable [Units]',
     ytitle='Events',
     ypadding=0.05,
     logy=True,
     ylimits=(1e-3, 1e3))

print(ROOT.gStyle.GetPadTopMargin())
label = ROOT.TLatex(ROOT.gStyle.GetPadLeftMargin(),
                    0.9 + ROOT.gStyle.GetPadTopMargin(), 'This is a title')
label.SetTextFont(43)
label.SetTextAlign(11)
label.SetTextSize(25)
label.SetNDC()
label.Draw()
# canvas.Modified()
# canvas.Update()

canvas.Print('test2.pdf')