コード例 #1
0
ファイル: alphatEtaDependence.py プロジェクト: aharel/supy
    def conclude(self) :
        for configId, tag in enumerate(self.sideBySideAnalysisTags()) :
            org=organizer.organizer( self.sampleSpecs(tag) )
            org.mergeSamples(targetSpec = {"name":"g_jets_mg", "color":r.kGreen},
                             sources = ["g_jets_mg_pt%s"%bin for bin in ["40_100","100_200","200"] ])
            org.scale(10)

            pl = plotter.plotter(org, psFileName = self.psFileName(tag))
            pl.plotAll()

            def drawCut(hist,cut) :
                line = r.TLine(cut,0,cut,hist.GetMaximum())
                line.SetLineColor(r.kBlue)
                line.SetLineStyle(r.kDashed)
                r.SetOwnership( line, False )
                line.Draw("same")
            def drawOne() :
                one = r.TF1("one","1",0,5)
                one.SetLineColor(r.kRed)
                one.SetLineStyle(r.kDashed)
                one.SetLineWidth(1)
                r.SetOwnership(one,False)
                one.Draw("same")

            import utils
            r.gStyle.SetOptStat(0)
            c = r.TCanvas("c","",800,1000)
            outDir = self.outputDirectory(configId)+"/"
            for s in org.samples : c.Print(outDir+s["name"]+".ps[")
            iSelection = -4
            for key in sorted(org.selections[iSelection]):
                if key == "counts" : continue
                for hist,sample in zip(org.selections[iSelection][key],org.samples) :
                    if not hist : continue
                    ctr = hist.ProjectionX(hist.GetName()+"_ctr",0,2)
                    fwd = hist.ProjectionX(hist.GetName()+"_fwd",3)
                    if min(ctr.GetEntries(),fwd.GetEntries()) < 10: continue

                    leg = r.TLegend(0.52,0.7,0.9,0.9);
                    ctr.Scale(1/ctr.Integral());  ctr.SetLineColor(r.kBlack);  ctr.SetMarkerColor(r.kBlack); leg.AddEntry(ctr,"Central","lp")
                    fwd.Scale(1/fwd.Integral());  fwd.SetLineColor(r.kRed);    fwd.SetMarkerColor(r.kRed); leg.AddEntry(fwd,"Forward","lp")
                    ratio = utils.ratioHistogram(fwd,ctr)

                    m = 2*max(fwd.GetMaximum(),ctr.GetMaximum())
                    fwd.SetMaximum(m)
                    ctr.SetMaximum(m)
                    ratio.SetMinimum(0); ratio.SetMaximum(2)
                    ratio.SetTitle("fwd/ctr")

                    c.Clear(); c.Divide(1,2); 
                    c.cd(1).SetLogy(); ctr.Draw(); fwd.Draw("same"); drawCut(ctr,0.55); leg.Draw()
                    c.cd(2); ratio.Draw(); drawOne(); drawCut(ratio,0.55)
                    c.Print(outDir+sample["name"]+".ps")

            for s in org.samples :
                fileName = outDir+s["name"]+".ps]"
                c.Print(fileName)
                fileNamePDF = fileName.replace(".ps]",".pdf")
                os.system("ps2pdf "+fileName[:-1] + " " + fileNamePDF)
                print fileNamePDF, "has been printed."
コード例 #2
0
ファイル: photonSelection.py プロジェクト: aharel/supy
    def conclude(self) :
        for tag in self.sideBySideAnalysisTags() :
            #organize
            org=organizer.organizer( self.sampleSpecs(tag) )
            org.mergeSamples(targetSpec = {"name":"g_jets_mg",     "color":r.kGreen},   sources = ["g_jets_mg_pt%s"%bin for bin in ["40_100","100_200","200"] ])
            #org.mergeSamples(targetSpec = {"name":"qcd_py"   ,     "color":r.kBlue},    sources = ["qcd_py_pt%d"%i         for i in [30,80,170,300,470,800,1400] ])
            #org.mergeSamples(targetSpec = {"name":"standard_model","color":r.kGreen+3},
            #                 sources = ["g_jets_mg","qcd_py","tt_tauola_mg","z_inv_mg_skim","z_jets_mg_skim","w_jets_mg_skim"], keepSources = True
            #                 )
            org.scale(100)

            #plot
            pl = plotter.plotter(org,
                                 psFileName = self.psFileName(tag),
                                 samplesForRatios=("JetMET_skim","standard_model"),
                                 sampleLabelsForRatios=("ctr","fwd"),
                                 )
            pl.plotAll()

            import utils
            c = r.TCanvas("c","",800,1000)
            for key in org.selections[-1]:
                if key == "counts" : continue
                for hist,sample in zip(org.selections[-1][key],org.samples) :
                    if not hist : continue
                    c.Clear()
                    c.Divide(1,2)
                    c.cd(1).SetLogy()
                    div = 1 if "z" in key else 2
                    ctr = hist.ProjectionX(hist.GetName()+"_ctr",0,div)
                    fwd = hist.ProjectionX(hist.GetName()+"_fwd",div+1)
                    if max(ctr.GetEntries(),fwd.GetEntries()) < 10: continue

                    ctr.Scale(1/ctr.Integral())
                    fwd.Scale(1/fwd.Integral())

                    ctr.SetLineColor(r.kBlack);  ctr.SetMarkerColor(r.kBlack)
                    fwd.SetLineColor(r.kRed);    fwd.SetMarkerColor(r.kRed)

                    leg = r.TLegend(0.52,0.7,0.9,0.9);
                    leg.AddEntry(ctr,"Central","lp")
                    leg.AddEntry(fwd,"Forward","lp")
                    m = 2*max(fwd.GetMaximum(),ctr.GetMaximum())
                    fwd.SetMaximum(m)
                    ctr.SetMaximum(m)
                    ctr.Draw("")
                    fwd.Draw("same")
                    leg.Draw()
                    c.cd(2)
                    ratio = utils.ratioHistogram(fwd,ctr)
                    ratio.SetMaximum(2)
                    one = r.TF1("one","1",0,5)
                    one.SetLineColor(r.kRed)
                    one.SetLineStyle(r.kDashed)
                    one.SetLineWidth(1)
                    ratio.Draw()
                    one.Draw("same")
                    c.Print(sample["name"]+'_'+key+"normSlice.eps")
コード例 #3
0
ファイル: plotter.py プロジェクト: aharel/supy
    def plotRatio(self,histos,dimension) :
        numLabel,denomLabel = self.sampleLabelsForRatios
        numSampleName,denomSampleNames = self.samplesForRatios
        if type(denomSampleNames)!=list: denomSampleNames = [denomSampleNames]

        ratios = []

        numIndex = self.someOrganizer.indexOfSampleWithName(numSampleName)
        if numIndex==None : return ratios
        
        numHisto = histos[numIndex]
        try:
            denomHistos = map(lambda name: histos[self.someOrganizer.indexOfSampleWithName(name)], denomSampleNames)
        except TypeError:
            return ratios

        same = ""
        for denomHisto in denomHistos :
            ratio = None
            if numHisto and denomHisto and numHisto.GetEntries() and denomHisto.GetEntries() :
                try:
                    ratio = utils.ratioHistogram(numHisto,denomHisto)
                    ratio.SetMinimum(0.0)
                    ratio.SetMaximum(2.0)
                    ratio.GetYaxis().SetTitle(numLabel+"/"+denomLabel)
                    self.canvas.cd(2)
                    adjustPad(r.gPad, self.anMode)
                    r.gPad.SetGridy()
                    ratio.SetStats(False)
                    ratio.GetXaxis().SetLabelSize(0.0)
                    ratio.GetXaxis().SetTickLength(3.5*ratio.GetXaxis().GetTickLength())
                    ratio.GetYaxis().SetLabelSize(0.2)
                    ratio.GetYaxis().SetNdivisions(502,True)
                    ratio.GetXaxis().SetTitleOffset(0.2)
                    ratio.GetYaxis().SetTitleSize(0.2)
                    ratio.GetYaxis().SetTitleOffset(0.2)
                    if len(denomHistos)==1: ratio.SetMarkerStyle(numHisto.GetMarkerStyle())
                    color = numHisto.GetLineColor() if len(denomHistos)==1 else denomHisto.GetLineColor()
                    ratio.SetLineColor(color)
                    ratio.SetMarkerColor(color)
                    ratio.Draw(same)
                    same = "same"
                except:
                    print "failed to make ratio for plot",numHisto.GetName()
            else :
                self.canvas.cd(2)
            ratios.append(ratio)
        return ratios
コード例 #4
0
ファイル: controls.py プロジェクト: gerbaudo/statsTA
def getRatio(data,hists):
    den = data.Clone()
    den.Reset()
    for h in filter(None,hists.values()) : den.Add(h)
    ratio = utils.ratioHistogram(data,den,0.08)
    ratio.SetTitle(';'+data.GetXaxis().GetTitle()+';'+'Ratio')
    ratio.SetMarkerSize(0)
    ratio.SetMinimum(0.7)
    ratio.SetMaximum(1.3)
    ratio.SetLabelSize(0.21)
    ratio.SetLabelOffset(0.04)
    ratio.GetXaxis().SetTitleSize(0.25)
    ratio.GetXaxis().SetTitleOffset(0.92)
    ratio.SetTickLength(0.1)
    ratio.SetTickLength(0.01,'Y')
    ratio.GetYaxis().SetLabelSize(0.1)
    ratio.GetYaxis().SetTitleSize(0.1)
    ratio.GetYaxis().SetTitleOffset(0.4)
    return ratio